Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3540e4d14f3da38f7b4137f23de2f656d0e4ada2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.widgets.object;

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.command.internal.env.ui.widgets.SimpleWidgetDataContributor;
import org.eclipse.wst.command.internal.env.ui.widgets.WidgetDataEvents;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus;
import org.eclipse.wst.command.internal.provisional.env.core.common.Status;
import org.eclipse.wst.wsdl.validation.internal.IValidationMessage;


public class ValidationMessageViewerWidget extends SimpleWidgetDataContributor
{
  private int DEFAULT_TABLE_HEIGHT_HINT = 100;
  private int DEFAULT_COLUMN_WIDTH = 20;

//  private String[] columns_;
  private TableViewer tableViewer_;
  private Table table_;
  
  private Composite parent_;
  private Listener  statusListener_;

  private String message = null;
  static final String columns_[] = {"severity", "line", "column", "message"};
  static final int columnsWidth_[] = {10, 10, 10, 60};

  

  public ValidationMessageViewerWidget()
  {
  }

  public WidgetDataEvents addControls( Composite parent, Listener statusListener )
  { 
    parent_         = parent;
    statusListener_ = statusListener;
    
    String       pluginId = "org.eclipse.jst.ws.consumption.ui";
    MessageUtils msgUtils = new MessageUtils( pluginId + ".plugin", this );
    
	Composite  composite = new Composite(parent, SWT.NONE);
	GridLayout gl        = new GridLayout();
	
	gl.marginHeight = 0;
	gl.marginWidth = 0;
	composite.setLayout(gl);
	composite.setLayoutData(new GridData(GridData.FILL_BOTH));
	
    Label messageLabel = new Label( composite, SWT.WRAP);
    messageLabel.setText( msgUtils.getMessage("LABEL_VALIDATE_MESSAGES"));
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    messageLabel.setLayoutData(gd);
    messageLabel.setToolTipText( msgUtils.getMessage("TOOLTIP_VALIDATE_TEXT_MESSAGE") );

	table_ = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
	gd = new GridData(GridData.FILL_BOTH);
	gd.heightHint = DEFAULT_TABLE_HEIGHT_HINT;
	table_.setLayoutData(gd);
	table_.setHeaderVisible(true);
	table_.setLinesVisible(true);
	table_.setToolTipText(msgUtils.getMessage("TOOLTIP_TABLE_VALIDATE_MESSAGE") );
	TableLayout tableLayout = new TableLayout();
	for (int i = 0; i < columns_.length; i++)
	{
	  TableColumn tableColumn = new TableColumn(table_, SWT.NONE);
	  tableColumn.setText(columns_[i]);
	  tableColumn.pack();
	  ColumnWeightData columnData = new ColumnWeightData(columnsWidth_[i], columnsWidth_[i], true);
	  tableLayout.addColumnData(columnData);
	}
	table_.setLayout(tableLayout);

	tableViewer_ = new TableViewer(table_);

	tableViewer_.setContentProvider(new ListContentProvider());
	tableViewer_.setLabelProvider(new ListLabelProvider());

	Composite buttonComposite = new Composite(composite, SWT.NONE);
	gl = new GridLayout();
	gl.numColumns = 3;
	gl.makeColumnsEqualWidth = true;
	buttonComposite.setLayout(gl);
	buttonComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));

	
	return this;
  }

  public void setInput(IValidationMessage[] messages)
  {
  	tableViewer_.setInput(messages);
  	tableViewer_.refresh();
  }
  
  public void clearInput()
  {
	  IValidationMessage emptyMessages[] = {};
	  this.setInput(emptyMessages);
  }
  
  public IContentProvider getContentProvider()
  {
	  return tableViewer_.getContentProvider();
  }

  public Status getStatus()
  {
    return message == null ? new SimpleStatus("") : 
                             new SimpleStatus( "", message, Status.ERROR );
  }

  public void refresh()
  {
	tableViewer_.refresh();
  }

  public TableItem[] getItems()
  {
	//internalRefresh();
	return table_.getItems();
  }

  public void setEnabled(boolean enabled)
  {
  }

  public void dispose()
  {	
	if (table_ != null)
	  table_.dispose();
  }

  protected class ListContentProvider implements IStructuredContentProvider
  {
	public void dispose()
	{
	}

	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
	{
	  tableViewer_.add(getElements(newInput));
	}

	public Object[] getElements(Object inputElement)
	{
		if (inputElement instanceof IValidationMessage[])
	  {
			IValidationMessage[] valMessages = (IValidationMessage[]) inputElement;
		  return valMessages;
	  }
	  else
		return new Object[0];
	}
  }

  protected class ListLabelProvider implements ITableLabelProvider
  {
	public Image getColumnImage(Object element, int columnIndex)
	{
		if (element instanceof IValidationMessage)
		{
			IValidationMessage msg = (IValidationMessage) element;
			
			if (columnIndex == 0)
			{	
				int severity = msg.getSeverity();
				if (severity == 0) {
					return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
				} else if (severity == 1) {
					return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
				} else if (severity == 2) {
					return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
				}
			}
		}	
	  return null;
	}

	public String getColumnText(Object element, int columnIndex)
	{
		String text = "";
		if (element instanceof IValidationMessage)
		{
			IValidationMessage msg = (IValidationMessage) element;
			
			switch (columnIndex) {
			case 0:		
				// no text to display, only display severity as image
				break;
			case 1:
				text = (new Integer(msg.getLine())).toString();
				break;
			case 2:
				text = (new Integer(msg.getColumn())).toString();
				break;
			case 3:
				text = msg.getMessage();
				break;		
				
			default:
				break;
			} 
		}
		return text;
	}

	public void addListener(ILabelProviderListener listener)
	{
	}

	public void removeListener(ILabelProviderListener listener)
	{
	}

	public boolean isLabelProperty(Object element, String property)
	{
	  return true;
	}

	public void dispose()
	{
	}
  }
 }

Back to the top