Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 55a5610ff2ce33b752f5242a258d89b6da7d9a1e (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 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.wst.xml.ui.internal.validation.core.errorinfo;

import java.util.List;

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
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.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.ISharedImages;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
import org.eclipse.wst.xml.ui.internal.validation.XMLValidationUIMessages;



public class TaskListTableViewer extends TableViewer
{	
  protected static final int COLUMN_ICON = 0;
  protected static final int COLUMN_DESCRIPTION = 1;
  protected static final int COLUMN_RESOURCE = 3;
  protected static final int COLUMN_LOCATION = 2;

  protected static final String LABEL_ICON = ""; //$NON-NLS-1$
  protected static final String LABEL_DESCRIPTION = XMLValidationUIMessages.TaskListTableViewer_0;
  protected static final String LABEL_RESOURCE = XMLValidationUIMessages.TaskListTableViewer_1;
  protected static final String LABEL_LOCATION = XMLValidationUIMessages.TaskListTableViewer_2;

  protected int visibleRows = -1;

  protected int getColumnWidth(int column)
  {
    int result = 0;
    switch (column)
    {
      case COLUMN_ICON :
        {
          result = 1;
          break;
        }
      case COLUMN_DESCRIPTION :
        {
          result = 20;
          break;
        }
      case COLUMN_RESOURCE :
        {
          result = 3;
          break;
        }
      case COLUMN_LOCATION :
        {
          result = 3;
          break;
        }
    }
    return result;
  }

  public TaskListTableViewer(Composite parent, int visibleRows)
  {
    this(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER, visibleRows);
  }

  public TaskListTableViewer(Composite parent, int style, int visibleRows)
  {
    super(new Table(parent, style));
    getTable().setLinesVisible(true);

    Provider provider = new Provider();
    setContentProvider(provider);
    setLabelProvider(provider);

    String[] columnPropertiesArray = { LABEL_ICON, LABEL_DESCRIPTION, LABEL_LOCATION };
    setColumnProperties(columnPropertiesArray);

    Table table = getTable();
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    TableLayout layout = new TableLayout();

    for (int i = 0; i < columnPropertiesArray.length; i++)
    {
      TableColumn column = new TableColumn(table, i);
      column.setText(columnPropertiesArray[i]);
      column.setAlignment(SWT.LEFT);
      layout.addColumnData(new ColumnWeightData(getColumnWidth(i), true));
    }

    table.setLayout(layout);
   
    this.visibleRows = visibleRows;
  }

  /**
  	* NamespaceInfoTableLabelProvider
  	*/
  protected class Provider extends LabelProvider implements ITableLabelProvider, IStructuredContentProvider
  {
    Viewer viewer;
    Image errorImage; 
    Image warnImage;
    
    public Provider()
    {
      errorImage = XMLUIPlugin.getInstance().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
       
      warnImage = XMLUIPlugin.getInstance().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
    }

    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
    {
      this.viewer = viewer;
    }

    public Object[] getElements(Object inputElement)
    {
      List list = (List) viewer.getInput();
      return list != null ? list.toArray() : null;
    }

    public Image getColumnImage(Object object, int columnIndex)
    {
	  ValidationMessage validationMessage = (ValidationMessage) object;    	
      Image result = null; 
      if (columnIndex == 0)
      {
      	int severity = validationMessage.getSeverity();
      	if (severity == IMessage.HIGH_SEVERITY || 
      	    severity == IMessage.NORMAL_SEVERITY)      	    
      	{
			result = errorImage;
      	} 
      	else
      	{
      	  result = warnImage;
      	}
      }
      return result;
    }

    public String getColumnText(Object object, int column)
    {
      ValidationMessage errorMessage = (ValidationMessage) object;
      String result = ""; //$NON-NLS-1$
      switch (column)
      {
        case COLUMN_DESCRIPTION :
          {
            result = errorMessage.getMessage();
            break;
          }
        case COLUMN_LOCATION :
          {
            result = XMLValidationUIMessages.TaskListTableViewer_3 + errorMessage.getLineNumber();
            break;
          }
      }
      return result;
    }
  }
}

Back to the top