View | Details | Raw Unified | Return to bug 231081 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-52 lines)
Lines 1850-1865 Link Here
1850
               mnemonic="%command.configureColumns.mnemonic"
1850
               mnemonic="%command.configureColumns.mnemonic"
1851
               style="push">
1851
               style="push">
1852
         </command>
1852
         </command>
1853
         <command
1854
               commandId="org.eclipse.ui.window.preferences"
1855
               label="%command.preferences.label"
1856
               mnemonic="%command.preferences.mnemonic"
1857
               style="push">
1858
            <parameter
1859
                  name="preferencePageId"
1860
                  value="org.eclipse.ui.ide.markers">
1861
            </parameter>
1862
         </command>
1863
      </menuContribution>
1853
      </menuContribution>
1864
      <menuContribution
1854
      <menuContribution
1865
            locationURI="menu:org.eclipse.ui.views.TaskList">
1855
            locationURI="menu:org.eclipse.ui.views.TaskList">
Lines 1913-1928 Link Here
1913
               mnemonic="%command.configureColumns.mnemonic"
1903
               mnemonic="%command.configureColumns.mnemonic"
1914
               style="push">
1904
               style="push">
1915
         </command>
1905
         </command>
1916
         <command
1917
               commandId="org.eclipse.ui.window.preferences"
1918
               label="%command.preferences.label"
1919
               mnemonic="%command.preferences.mnemonic"
1920
               style="push">
1921
            <parameter
1922
                  name="preferencePageId"
1923
                  value="org.eclipse.ui.ide.markers">
1924
            </parameter>
1925
         </command>
1926
      </menuContribution>
1906
      </menuContribution>
1927
      <menuContribution
1907
      <menuContribution
1928
            locationURI="menu:org.eclipse.ui.views.BookmarkView">
1908
            locationURI="menu:org.eclipse.ui.views.BookmarkView">
Lines 1986-2001 Link Here
1986
               mnemonic="%command.configureColumns.mnemonic"
1966
               mnemonic="%command.configureColumns.mnemonic"
1987
               style="push">
1967
               style="push">
1988
         </command>
1968
         </command>
1989
         <command
1990
               commandId="org.eclipse.ui.window.preferences"
1991
               label="%command.preferences.label"
1992
               mnemonic="%command.preferences.mnemonic"
1993
               style="push">
1994
            <parameter
1995
                  name="preferencePageId"
1996
                  value="org.eclipse.ui.ide.markers">
1997
            </parameter>
1998
         </command>
1999
      </menuContribution>
1969
      </menuContribution>
2000
      <menuContribution
1970
      <menuContribution
2001
            locationURI="menu:org.eclipse.ui.views.AllMarkersView">
1971
            locationURI="menu:org.eclipse.ui.views.AllMarkersView">
Lines 2049-2064 Link Here
2049
               mnemonic="%command.configureColumns.mnemonic"
2019
               mnemonic="%command.configureColumns.mnemonic"
2050
               style="push">
2020
               style="push">
2051
         </command>
2021
         </command>
2052
         <command
2053
               commandId="org.eclipse.ui.window.preferences"
2054
               label="%command.preferences.label"
2055
               mnemonic="%command.preferences.mnemonic"
2056
               style="push">
2057
            <parameter
2058
                  name="preferencePageId"
2059
                  value="org.eclipse.ui.ide.markers">
2060
            </parameter>
2061
         </command>
2062
      </menuContribution>
2022
      </menuContribution>
2063
   </extension>
2023
   </extension>
2064
   <extension
2024
   <extension
Lines 2240-2257 Link Here
2240
            </iterate>
2200
            </iterate>
2241
         </enabledWhen>
2201
         </enabledWhen>
2242
      </handler>
2202
      </handler>
2243
      <handler
2244
            class="org.eclipse.ui.internal.views.markers.MarkerPreferencesHandler"
2245
            commandId="org.eclipse.ui.window.preferences">
2246
         <activeWhen>
2247
            <with
2248
                  variable="activePart">
2249
               <instanceof
2250
                     value="org.eclipse.ui.views.markers.MarkerSupportView">
2251
               </instanceof>
2252
            </with>
2253
         </activeWhen>
2254
      </handler>
2255
   </extension>
2203
   </extension>
2256
   <extension
2204
   <extension
2257
         point="org.eclipse.core.expressions.propertyTesters">
2205
         point="org.eclipse.core.expressions.propertyTesters">
(-)src/org/eclipse/ui/internal/views/markers/ConfigureColumnsHandler.java (-2 / +1 lines)
Lines 12-18 Link Here
12
12
13
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.core.commands.IHandler;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.jface.util.ConfigureColumns;
16
import org.eclipse.ui.views.markers.MarkerViewHandler;
15
import org.eclipse.ui.views.markers.MarkerViewHandler;
17
16
18
/**
17
/**
Lines 33-39 Link Here
33
		ExtendedMarkersView view = getView(event);
32
		ExtendedMarkersView view = getView(event);
34
		if (view == null)
33
		if (view == null)
35
			return this;
34
			return this;
36
		ConfigureColumns.forTree(view.getViewer().getTree(), view.getSite());
35
		new MarkersViewSettingDialog(view).open();
37
		return this;
36
		return this;
38
	}
37
	}
39
38
(-)src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java (-32 / +54 lines)
Lines 117-127 Link Here
117
	 */
117
	 */
118
	public final Object MARKERSVIEW_UPDATE_JOB_FAMILY = new Object();
118
	public final Object MARKERSVIEW_UPDATE_JOB_FAMILY = new Object();
119
119
120
	static final String MARKER_FIELD = "MARKER_FIELD"; //$NON-NLS-1$
121
	
120
	private static int instanceCount = 1;
122
	private static int instanceCount = 1;
121
	private static final String TAG_GENERATOR = "markerContentGenerator"; //$NON-NLS-1$
123
	private static final String TAG_GENERATOR = "markerContentGenerator"; //$NON-NLS-1$
122
124
123
	private static final String MARKER_FIELD = "MARKER_FIELD"; //$NON-NLS-1$
124
125
	private static final String TAG_EXPANDED = "expanded"; //$NON-NLS-1$
125
	private static final String TAG_EXPANDED = "expanded"; //$NON-NLS-1$
126
126
127
	private static final String TAG_CATEGORY = "category"; //$NON-NLS-1$
127
	private static final String TAG_CATEGORY = "category"; //$NON-NLS-1$
Lines 240-246 Link Here
240
				/*| SWT.VIRTUAL */| SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION));
240
				/*| SWT.VIRTUAL */| SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION));
241
		viewer.getTree().setLinesVisible(true);
241
		viewer.getTree().setLinesVisible(true);
242
		viewer.setUseHashlookup(true);
242
		viewer.setUseHashlookup(true);
243
		createColumns(new TreeColumn[0]);
243
		createColumns(new TreeColumn[0], new int[0]);
244
		viewer.setContentProvider(getContentProvider());
244
		viewer.setContentProvider(getContentProvider());
245
	}
245
	}
246
246
Lines 249-270 Link Here
249
	 * 
249
	 * 
250
	 * @param currentColumns
250
	 * @param currentColumns
251
	 *            the columns to refresh
251
	 *            the columns to refresh
252
	 * @param widths 
252
	 */
253
	 */
253
	private void createColumns(TreeColumn[] currentColumns) {
254
	private void createColumns(TreeColumn[] currentColumns, int[] widths) {
254
255
255
		Tree tree = viewer.getTree();
256
		Tree tree = viewer.getTree();
256
		TableLayout layout = new TableLayout();
257
		TableLayout layout = new TableLayout();
257
258
258
		MarkerField[] fields = generator.getVisibleFields();
259
		MarkerField[] fields = generator.getVisibleFields();
259
260
260
		IMemento columnWidths = null;
261
		if (memento != null)
262
			columnWidths = memento.getChild(TAG_COLUMN_WIDTHS);
263
264
		for (int i = 0; i < fields.length; i++) {
261
		for (int i = 0; i < fields.length; i++) {
265
			MarkerField markerField = fields[i];
262
			MarkerField markerField = fields[i];
266
263
			TreeViewerColumn column = null;
267
			TreeViewerColumn column;
268
			if (i < currentColumns.length)
264
			if (i < currentColumns.length)
269
				column = new TreeViewerColumn(viewer, currentColumns[i]);
265
				column = new TreeViewerColumn(viewer, currentColumns[i]);
270
			else {
266
			else {
Lines 289-315 Link Here
289
			if (builder.getPrimarySortField().equals(markerField))
285
			if (builder.getPrimarySortField().equals(markerField))
290
				updateDirectionIndicator(column.getColumn(), markerField);
286
				updateDirectionIndicator(column.getColumn(), markerField);
291
287
292
			int columnWidth = -1;
288
			IMemento columnWidths = null;
293
289
			if (memento != null){
294
			if (i == 0) {
290
				columnWidths = memento.getChild(TAG_COLUMN_WIDTHS);
295
				// Compute and store a font metric
296
				GC gc = new GC(tree);
297
				gc.setFont(tree.getFont());
298
				FontMetrics fontMetrics = gc.getFontMetrics();
299
				gc.dispose();
300
				columnWidth = Math.max(markerField.getDefaultColumnWidth(tree),
301
						fontMetrics.getAverageCharWidth() * 5);
302
			}
291
			}
303
292
			int columnWidth = -1;
304
			if (columnWidths != null) {
293
			if(i < widths.length){
305
				Integer value = columnWidths.getInteger(getFieldId(column
294
				columnWidth = widths[i];
306
						.getColumn()));
295
				if (columnWidths != null) {
307
296
					//save it
308
				// Make sure we get a useful value
297
					columnWidths.putInteger(markerField.getConfigurationElement().getAttribute(
309
				if (value != null && value.intValue() > 0)
298
							MarkerSupportInternalUtilities.ATTRIBUTE_ID), columnWidth);
310
					columnWidth = value.intValue();
299
				}
300
			}else{
301
				columnWidth = getFieldWidth(markerField, columnWidth);
311
			}
302
			}
312
313
			// Take trim into account if we are using the default value, but not
303
			// Take trim into account if we are using the default value, but not
314
			// if it is restored.
304
			// if it is restored.
315
			if (columnWidth < 0)
305
			if (columnWidth < 0)
Lines 324-330 Link Here
324
		if (currentColumns.length > fields.length) {
314
		if (currentColumns.length > fields.length) {
325
			for (int i = fields.length; i < currentColumns.length; i++) {
315
			for (int i = fields.length; i < currentColumns.length; i++) {
326
				currentColumns[i].dispose();
316
				currentColumns[i].dispose();
327
328
			}
317
			}
329
		}
318
		}
330
319
Lines 334-339 Link Here
334
		tree.layout(true);
323
		tree.layout(true);
335
324
336
	}
325
	}
326
	
327
	int getFieldWidth(MarkerField markerField, int columnWidth) {
328
		Tree tree = getViewer().getTree();
329
330
		if (columnWidth < 0 && memento != null) {
331
			IMemento columnWidths = memento.getChild(TAG_COLUMN_WIDTHS);
332
			if (columnWidths != null) {
333
				Integer value = columnWidths.getInteger(markerField
334
						.getConfigurationElement().getAttribute(
335
								MarkerSupportInternalUtilities.ATTRIBUTE_ID));
336
				// Make sure we get a useful value
337
				if (value != null && value.intValue() > 0)
338
					columnWidth = value.intValue();
339
			}
340
		}
341
		if (columnWidth <= 0) {
342
			// Compute and store a font metric
343
			GC gc = new GC(tree);
344
			gc.setFont(tree.getFont());
345
			FontMetrics fontMetrics = gc.getFontMetrics();
346
			gc.dispose();
347
			columnWidth = Math.max(markerField.getDefaultColumnWidth(tree),
348
					fontMetrics.getAverageCharWidth() * 5);
349
		}
350
		TreeColumn[] columns = tree.getColumns();
351
		for (int i = 0; i < columns.length; i++) {
352
			if (MARKER_FIELD.equals(columns[i].getData(MARKER_FIELD))) {
353
				columnWidth = Math.max(columnWidth, columns[i].getWidth());
354
				return columnWidth;
355
			}
356
		}
357
		return columnWidth;
358
	}
337
359
338
	/*
360
	/*
339
	 * (non-Javadoc)
361
	 * (non-Javadoc)
Lines 1460-1470 Link Here
1460
	/**
1482
	/**
1461
	 * @param visible
1483
	 * @param visible
1462
	 */
1484
	 */
1463
	void setVisibleFields(Collection visible) {
1485
	void setVisibleFields(Collection visible,int[] widths) {
1464
		generator.setVisibleFields(visible);
1486
		generator.setVisibleFields(visible);
1465
		//viewer.setSelection(new StructuredSelection());
1487
		//viewer.setSelection(new StructuredSelection());
1466
		//viewer.removeAndClearAll();
1488
		//viewer.removeAndClearAll();
1467
		createColumns(viewer.getTree().getColumns());
1489
		createColumns(viewer.getTree().getColumns(), widths);
1468
		scheduleUpdate(0L);
1490
		scheduleUpdate(0L);
1469
	}
1491
	}
1470
1492
(-)src/org/eclipse/ui/internal/views/markers/MarkerPreferencesDialog.java (-483 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.views.markers;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.preference.IntegerFieldEditor;
19
import org.eclipse.jface.resource.JFaceColors;
20
import org.eclipse.jface.viewers.IStructuredContentProvider;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.LabelProvider;
23
import org.eclipse.jface.viewers.ListViewer;
24
import org.eclipse.jface.viewers.Viewer;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.events.SelectionAdapter;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.layout.FormAttachment;
29
import org.eclipse.swt.layout.FormData;
30
import org.eclipse.swt.layout.FormLayout;
31
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.layout.GridLayout;
33
import org.eclipse.swt.widgets.Button;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Group;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Shell;
39
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
40
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
41
import org.eclipse.ui.preferences.ViewSettingsDialog;
42
import org.eclipse.ui.views.markers.MarkerField;
43
import org.eclipse.ui.views.markers.internal.MarkerMessages;
44
45
/**
46
 * MarkerPreferencesDialog is the dialog for showing marker preferences.
47
 * 
48
 * @since 3.4
49
 * 
50
 */
51
public class MarkerPreferencesDialog extends ViewSettingsDialog {
52
53
	private IntegerFieldEditor limitEditor;
54
55
	private Button enablementButton;
56
57
	private Composite editArea;
58
59
	private Label messageLabel;
60
61
	private ExtendedMarkersView extendedView;
62
63
	private ArrayList visible;
64
65
	private ArrayList hidden;
66
67
	private ListViewer visibleViewer;
68
69
	private ListViewer nonVisibleViewer;
70
71
	/**
72
	 * Create a new instance of the receiver.
73
	 * 
74
	 * @param view -
75
	 *            the view this is being launched from
76
	 */
77
	public MarkerPreferencesDialog(ExtendedMarkersView view) {
78
		super(view.getSite().getShell());
79
		this.extendedView = view;
80
81
		Object[] visibleFields = view.getVisibleFields();
82
		Object[] hiddenFields = view.getHiddenFields();
83
84
		visible = new ArrayList();
85
		hidden = new ArrayList();
86
87
		for (int i = 0; i < visibleFields.length; i++) {
88
			visible.add(visibleFields[i]);
89
		}
90
91
		for (int i = 0; i < hiddenFields.length; i++) {
92
			hidden.add(hiddenFields[i]);
93
		}
94
	}
95
96
	/*
97
	 * (non-Javadoc)
98
	 * 
99
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
100
	 */
101
	protected void configureShell(Shell newShell) {
102
		super.configureShell(newShell);
103
		newShell.setText(MarkerMessages.MarkerPreferences_DialogTitle);
104
	}
105
106
	/*
107
	 * (non-Javadoc)
108
	 * 
109
	 * @see org.eclipse.jface.window.Window#getShellStyle()
110
	 */
111
	protected int getShellStyle() {
112
		return super.getShellStyle() | SWT.RESIZE;
113
	}
114
115
	/*
116
	 * (non-Javadoc)
117
	 * 
118
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
119
	 */
120
	protected Control createDialogArea(Composite parent) {
121
122
		Composite dialogArea = (Composite) super.createDialogArea(parent);
123
124
		boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore()
125
				.getBoolean(IDEInternalPreferences.USE_MARKER_LIMITS);
126
		enablementButton = new Button(dialogArea, SWT.CHECK);
127
		enablementButton.setText(MarkerMessages.MarkerPreferences_MarkerLimits);
128
		enablementButton.setSelection(checked);
129
130
		editArea = new Composite(dialogArea, SWT.NONE);
131
		editArea.setLayout(new GridLayout());
132
		GridData editData = new GridData(GridData.FILL_BOTH
133
				| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
134
		editData.horizontalIndent = 10;
135
		editArea.setLayoutData(editData);
136
137
		limitEditor = new IntegerFieldEditor(
138
				"limit", MarkerMessages.MarkerPreferences_VisibleItems, editArea) { //$NON-NLS-1$
139
			/*
140
			 * (non-Javadoc)
141
			 * 
142
			 * @see org.eclipse.jface.preference.IntegerFieldEditor#checkState()
143
			 */
144
			protected boolean checkState() {
145
				boolean state = super.checkState();
146
				setValid(state, getErrorMessage());
147
				return state;
148
			}
149
		};
150
		limitEditor.setPreferenceStore(IDEWorkbenchPlugin.getDefault()
151
				.getPreferenceStore());
152
		limitEditor
153
				.setPreferenceName(IDEInternalPreferences.MARKER_LIMITS_VALUE);
154
		limitEditor.load();
155
156
		GridData checkedData = new GridData(SWT.FILL, SWT.NONE, true, false);
157
		checkedData.horizontalSpan = limitEditor.getNumberOfControls();
158
		enablementButton.setLayoutData(checkedData);
159
160
		enablementButton.addSelectionListener(new SelectionAdapter() {
161
			public void widgetSelected(SelectionEvent e) {
162
				setLimitEditorEnablement(editArea, enablementButton
163
						.getSelection());
164
			}
165
		});
166
167
		setLimitEditorEnablement(editArea, checked);
168
169
		messageLabel = new Label(dialogArea, SWT.NONE);
170
171
		messageLabel.setBackground(JFaceColors.getErrorBackground(dialogArea
172
				.getDisplay()));
173
		messageLabel.setForeground(JFaceColors.getErrorText(dialogArea
174
				.getDisplay()));
175
		messageLabel
176
				.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
177
178
		createColumnsArea(dialogArea);
179
180
		applyDialogFont(dialogArea);
181
		return dialogArea;
182
	}
183
184
	/**
185
	 * Create an area for the selected columns
186
	 * 
187
	 * @param dialogArea
188
	 */
189
	private void createColumnsArea(Composite dialogArea) {
190
191
		initializeDialogUnits(dialogArea);
192
		Group columnsComposite = new Group(dialogArea, SWT.NONE);
193
		columnsComposite.setText(MarkerMessages.MarkerPreferences_ColumnGroupTitle);
194
		FormLayout layout = new FormLayout();
195
		columnsComposite.setLayout(layout);
196
197
		columnsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
198
				true));
199
		Label visibleItemsLabel = new Label(columnsComposite, SWT.NONE);
200
		visibleItemsLabel.setText(MarkerMessages.MarkerPreferences_VisibleColumnsTitle);
201
		FormData visibleLabelData = new FormData();
202
		visibleLabelData.right = new FormAttachment(45, 0);
203
		visibleLabelData.left = new FormAttachment(
204
				IDialogConstants.BUTTON_MARGIN);
205
		visibleLabelData.top = new FormAttachment(0);
206
		visibleItemsLabel.setLayoutData(visibleLabelData);
207
208
		int rightMargin = IDialogConstants.BUTTON_MARGIN * -1;
209
210
		Label nonVisibleLabel = new Label(columnsComposite, SWT.NONE);
211
		nonVisibleLabel.setText(MarkerMessages.MarkerPreferences_HiddenColumnsTitle);
212
		FormData nonVisibleLabelData = new FormData();
213
		nonVisibleLabelData.right = new FormAttachment(100);
214
		nonVisibleLabelData.left = new FormAttachment(55, 0);
215
		nonVisibleLabelData.top = new FormAttachment(0);
216
		nonVisibleLabel.setLayoutData(nonVisibleLabelData);
217
218
		visibleViewer = new ListViewer(columnsComposite,
219
				SWT.BORDER);
220
221
		FormData visibleViewerData = new FormData();
222
		visibleViewerData.right = new FormAttachment(visibleItemsLabel, 0,
223
				SWT.RIGHT);
224
		visibleViewerData.left = new FormAttachment(visibleItemsLabel, 0,
225
				SWT.LEFT);
226
		visibleViewerData.top = new FormAttachment(visibleItemsLabel,
227
				IDialogConstants.BUTTON_MARGIN);
228
		visibleViewerData.bottom = new FormAttachment(100, rightMargin);
229
		visibleViewerData.height = convertHeightInCharsToPixels(15);
230
		visibleViewerData.width = convertWidthInCharsToPixels(25);
231
232
		visibleViewer.getControl().setLayoutData(visibleViewerData);
233
234
		visibleViewer.setContentProvider(new IStructuredContentProvider() {
235
236
			/*
237
			 * (non-Javadoc)
238
			 * 
239
			 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
240
			 */
241
			public Object[] getElements(Object inputElement) {
242
				return visible.toArray();
243
			}
244
245
			/*
246
			 * (non-Javadoc)
247
			 * 
248
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
249
			 */
250
			public void dispose() {
251
			}
252
253
			/*
254
			 * (non-Javadoc)
255
			 * 
256
			 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
257
			 *      java.lang.Object, java.lang.Object)
258
			 */
259
			public void inputChanged(Viewer viewer, Object oldInput,
260
					Object newInput) {
261
			}
262
263
		});
264
265
		visibleViewer.setLabelProvider(markerFieldLabelProvider());
266
267
		visibleViewer.setInput(this);
268
269
		nonVisibleViewer = new ListViewer(columnsComposite,
270
				SWT.BORDER);
271
272
		nonVisibleViewer.setLabelProvider(markerFieldLabelProvider());
273
274
		nonVisibleViewer.setContentProvider(new IStructuredContentProvider() {
275
276
			/*
277
			 * (non-Javadoc)
278
			 * 
279
			 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
280
			 */
281
			public Object[] getElements(Object inputElement) {
282
				return hidden.toArray();
283
			}
284
285
			/*
286
			 * (non-Javadoc)
287
			 * 
288
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
289
			 */
290
			public void dispose() {
291
			}
292
293
			/*
294
			 * (non-Javadoc)
295
			 * 
296
			 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
297
			 *      java.lang.Object, java.lang.Object)
298
			 */
299
			public void inputChanged(Viewer viewer, Object oldInput,
300
					Object newInput) {
301
			}
302
303
		});
304
		nonVisibleViewer.setInput(this);
305
306
		FormData nonVisibleViewerData = new FormData();
307
		nonVisibleViewerData.right = new FormAttachment(nonVisibleLabel, 0,
308
				SWT.RIGHT);
309
		nonVisibleViewerData.left = new FormAttachment(nonVisibleLabel, 0,
310
				SWT.LEFT);
311
		nonVisibleViewerData.top = new FormAttachment(nonVisibleLabel,
312
				IDialogConstants.BUTTON_MARGIN);
313
		nonVisibleViewerData.bottom = new FormAttachment(100, rightMargin);
314
		nonVisibleViewerData.height = convertHeightInCharsToPixels(15);
315
		nonVisibleViewerData.width = convertWidthInCharsToPixels(25);
316
317
		nonVisibleViewer.getControl().setLayoutData(nonVisibleViewerData);
318
319
		Button toNonVisibleButton = new Button(columnsComposite, SWT.PUSH);
320
		toNonVisibleButton
321
				.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveLeft
322
						: MarkerMessages.MarkerPreferences_MoveRight);
323
324
		FormData toNonVisibleButtonData = new FormData();
325
326
		toNonVisibleButtonData.top = new FormAttachment(visibleViewer
327
				.getControl(), IDialogConstants.BUTTON_BAR_HEIGHT, SWT.TOP);
328
		toNonVisibleButtonData.left = new FormAttachment(visibleViewer
329
				.getControl(), IDialogConstants.BUTTON_MARGIN);
330
		toNonVisibleButtonData.right = new FormAttachment(nonVisibleViewer
331
				.getControl(), rightMargin);
332
		toNonVisibleButton.setLayoutData(toNonVisibleButtonData);
333
334
		toNonVisibleButton.addSelectionListener(new SelectionAdapter() {
335
			/*
336
			 * (non-Javadoc)
337
			 * 
338
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
339
			 */
340
			public void widgetSelected(SelectionEvent e) {
341
				List selection = ((IStructuredSelection) visibleViewer
342
						.getSelection()).toList();
343
				hidden.addAll(selection);
344
				visible.removeAll(selection);
345
				visibleViewer.refresh();
346
				nonVisibleViewer.refresh();
347
				setValid(
348
						visible.size() > 0,
349
						MarkerMessages.MarkerPreferences_AtLeastOneVisibleColumn);
350
			}
351
		});
352
353
		Button toVisibleButton = new Button(columnsComposite, SWT.PUSH);
354
		toVisibleButton
355
				.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveRight
356
						: MarkerMessages.MarkerPreferences_MoveLeft);
357
358
		FormData toVisibleButtonData = new FormData();
359
360
		toVisibleButtonData.top = new FormAttachment(toNonVisibleButton,
361
				IDialogConstants.BUTTON_MARGIN);
362
		toVisibleButtonData.left = new FormAttachment(visibleViewer
363
				.getControl(), IDialogConstants.BUTTON_MARGIN);
364
		toVisibleButtonData.right = new FormAttachment(nonVisibleViewer
365
				.getControl(), rightMargin);
366
		toVisibleButton.setLayoutData(toVisibleButtonData);
367
368
		toVisibleButton.addSelectionListener(new SelectionAdapter() {
369
			/*
370
			 * (non-Javadoc)
371
			 * 
372
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
373
			 */
374
			public void widgetSelected(SelectionEvent e) {
375
				List selection = ((IStructuredSelection) nonVisibleViewer
376
						.getSelection()).toList();
377
				hidden.removeAll(selection);
378
				visible.addAll(selection);
379
				visibleViewer.refresh();
380
				nonVisibleViewer.refresh();
381
				setValid(
382
						visible.size() > 0,
383
						MarkerMessages.MarkerPreferences_AtLeastOneVisibleColumn);
384
			}
385
		});
386
387
	}
388
389
	/**
390
	 * Return a label provider for fields.
391
	 * @return LabelProvider
392
	 */
393
	private LabelProvider markerFieldLabelProvider() {
394
		return new LabelProvider() {
395
			/*
396
			 * (non-Javadoc)
397
			 * 
398
			 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
399
			 */
400
			public String getText(Object element) {
401
				return ((MarkerField) element).getName();
402
			}
403
		};
404
	}
405
406
	/**
407
	 * Set the enabled state of the OK button by state.
408
	 * 
409
	 * @param state
410
	 */
411
	protected void setValid(boolean state, String errorMessage) {
412
		Button okButton = getButton(IDialogConstants.OK_ID);
413
414
		if (okButton == null)
415
			return;
416
417
		if (state)
418
			messageLabel.setText(MarkerSupportInternalUtilities.EMPTY_STRING);
419
		else
420
			messageLabel.setText(errorMessage);
421
422
		okButton.setEnabled(state);
423
424
	}
425
426
	/**
427
	 * Enable the limitEditor based on checked.
428
	 * 
429
	 * @param control
430
	 *            The parent of the editor
431
	 * @param checked
432
	 */
433
	private void setLimitEditorEnablement(Composite control, boolean checked) {
434
		limitEditor.setEnabled(checked, control);
435
	}
436
437
	/*
438
	 * (non-Javadoc)
439
	 * 
440
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
441
	 */
442
	protected void okPressed() {
443
444
		limitEditor.store();
445
		IDEWorkbenchPlugin.getDefault().getPreferenceStore().setValue(
446
				IDEInternalPreferences.USE_MARKER_LIMITS,
447
				enablementButton.getSelection());
448
		IDEWorkbenchPlugin.getDefault().savePluginPreferences();
449
450
		extendedView.setVisibleFields(visible);
451
452
		super.okPressed();
453
	}
454
455
	/*
456
	 * (non-Javadoc)
457
	 * 
458
	 * @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults()
459
	 */
460
	protected void performDefaults() {
461
		super.performDefaults();
462
		limitEditor.loadDefault();
463
		boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore()
464
				.getDefaultBoolean(IDEInternalPreferences.USE_MARKER_LIMITS);
465
		enablementButton.setSelection(checked);
466
		setLimitEditorEnablement(editArea, checked);
467
468
		Object[] visibleFields=extendedView.getBuilder().getGenerator().getInitialVisible();
469
		Object[] allFields=extendedView.getBuilder().getGenerator().getAllFields();
470
		visible.clear();
471
		hidden.clear();
472
		for (int i = 0; i < allFields.length; i++) {
473
			hidden.add(allFields[i]);
474
		}
475
		for (int i = 0; i < visibleFields.length; i++) {
476
			hidden.remove(visibleFields[i]);
477
			visible.add(visibleFields[i]);
478
		}
479
		visibleViewer.refresh();
480
		nonVisibleViewer.refresh();
481
	}
482
483
}
(-)src/org/eclipse/ui/internal/views/markers/MarkerPreferencesHandler.java (-38 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.views.markers;
12
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.ui.views.markers.MarkerViewHandler;
16
17
/**
18
 * MarkerPreferencesHandler is the handler for opening the marker preferences dialog.
19
 * @since 3.4
20
 *
21
 */
22
public class MarkerPreferencesHandler extends MarkerViewHandler implements
23
		IHandler {
24
25
	/* (non-Javadoc)
26
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
27
	 */
28
	public Object execute(ExecutionEvent event) {
29
		
30
		ExtendedMarkersView view = getView(event);
31
		if(view == null)
32
			return this;
33
		
34
		new MarkerPreferencesDialog(view).open();
35
		return this;
36
	}
37
38
}
(-)src/org/eclipse/ui/internal/views/markers/MarkerSupportInternalUtilities.java (-8 / +5 lines)
Lines 317-331 Link Here
317
	 */
317
	 */
318
	static int getMarkerLimit() {
318
	static int getMarkerLimit() {
319
319
320
		// If limits are enabled return it. Otherwise return -1
320
		int value = IDEWorkbenchPlugin.getDefault().getPreferenceStore()
321
		if (IDEWorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(
321
				.getInt(IDEInternalPreferences.MARKER_LIMITS_VALUE);
322
				IDEInternalPreferences.USE_MARKER_LIMITS)) {
322
		if (value <= 0) {
323
			return IDEWorkbenchPlugin.getDefault().getPreferenceStore().getInt(
323
			return -1;
324
					IDEInternalPreferences.MARKER_LIMITS_VALUE);
325
326
		}
324
		}
327
		return -1;
325
		return value;
328
329
	}
326
	}
330
327
331
	/**
328
	/**
(-)src/org/eclipse/ui/internal/views/markers/Markers.java (-43 / +46 lines)
Lines 29-36 Link Here
29
import org.eclipse.ui.views.markers.internal.MarkerMessages;
29
import org.eclipse.ui.views.markers.internal.MarkerMessages;
30
30
31
/**
31
/**
32
 * The Markers object contains the MarkerEntry(s) collected and updated by the system,
32
 * The Markers object contains the MarkerEntry(s) collected and updated by the
33
 * also  maintains the categories that markers are grouped into.
33
 * system, also maintains the categories that markers are grouped into.
34
 * 
34
 * @since 3.6
35
 * @since 3.6
35
 * 
36
 * 
36
 */
37
 */
Lines 39-79 Link Here
39
	static final MarkerCategory[] EMPTY_CATEGORY_ARRAY = new MarkerCategory[0];
40
	static final MarkerCategory[] EMPTY_CATEGORY_ARRAY = new MarkerCategory[0];
40
	static final MarkerEntry[] EMPTY_ENTRY_ARRAY = new MarkerEntry[0];
41
	static final MarkerEntry[] EMPTY_ENTRY_ARRAY = new MarkerEntry[0];
41
42
42
	 //the marker entries
43
	// the marker entries
43
	private MarkerEntry[] markerEntryArray = EMPTY_ENTRY_ARRAY;
44
	private MarkerEntry[] markerEntryArray = EMPTY_ENTRY_ARRAY;
44
	//the categories
45
	// the categories
45
	private MarkerCategory[] categories = EMPTY_CATEGORY_ARRAY;
46
	private MarkerCategory[] categories = EMPTY_CATEGORY_ARRAY;
46
47
47
	
48
	private CachedMarkerBuilder builder;
48
	private CachedMarkerBuilder builder;
49
	
49
50
	private boolean inChange=false;
50
	private boolean inChange = false;
51
51
52
	// markerToEntryMap is a lazily created map from the markers to thier
52
	// markerToEntryMap is a lazily created map from the markers to thier
53
	// corresponding entry
53
	// corresponding entry
54
	private Map markerToEntryMap = null;
54
	private Map markerToEntryMap = null;
55
	private Integer[] markerCounts;
55
	private Integer[] markerCounts;
56
56
57
58
	Markers(CachedMarkerBuilder builder) {
57
	Markers(CachedMarkerBuilder builder) {
59
		this.builder = builder;
58
		this.builder = builder;
60
		inChange=false;
59
		inChange = false;
61
	}
60
	}
62
61
63
	/**
62
	/**
64
	 * Update with newly collected markers
63
	 * Update with newly collected markers
65
	 * 
64
	 * 
66
	 * @param markerEntries
65
	 * @param markerEntries
67
	 * 						the new marker entries 
66
	 *            the new marker entries
68
	 * @param sortAndGroup
67
	 * @param sortAndGroup
69
	 * 			true 	sort and group them
68
	 *            true sort and group them
70
	 * @param monitor
69
	 * @param monitor
71
	 */
70
	 */
72
	synchronized boolean updateWithNewMarkers(Collection markerEntries,
71
	synchronized boolean updateWithNewMarkers(Collection markerEntries,
73
			boolean sortAndGroup, IProgressMonitor monitor) {
72
			boolean sortAndGroup, IProgressMonitor monitor) {
74
		boolean initialVal=inChange;
73
		boolean initialVal = inChange;
75
		try {
74
		try {
76
			inChange=true;
75
			inChange = true;
77
			if (markerToEntryMap != null) {
76
			if (markerToEntryMap != null) {
78
				markerToEntryMap.clear();
77
				markerToEntryMap.clear();
79
				markerToEntryMap = null;
78
				markerToEntryMap = null;
Lines 103-109 Link Here
103
			}
102
			}
104
			return true;
103
			return true;
105
		} finally {
104
		} finally {
106
			inChange=initialVal;
105
			inChange = initialVal;
107
		}
106
		}
108
	}
107
	}
109
108
Lines 113-121 Link Here
113
	 * @param monitor
112
	 * @param monitor
114
	 */
113
	 */
115
	synchronized boolean sortAndMakeCategories(IProgressMonitor monitor) {
114
	synchronized boolean sortAndMakeCategories(IProgressMonitor monitor) {
116
		boolean initialVal=inChange;
115
		boolean initialVal = inChange;
117
		try {
116
		try {
118
			inChange=true;
117
			inChange = true;
119
			// Sort by Category first
118
			// Sort by Category first
120
			if (builder.isShowingHierarchy()) {
119
			if (builder.isShowingHierarchy()) {
121
				MarkerCategory[] markerCategories = groupIntoCategories(
120
				MarkerCategory[] markerCategories = groupIntoCategories(
Lines 132-138 Link Here
132
131
133
			return sortMarkerEntries(monitor);
132
			return sortMarkerEntries(monitor);
134
		} finally {
133
		} finally {
135
			inChange=initialVal;
134
			inChange = initialVal;
136
		}
135
		}
137
	}
136
	}
138
137
Lines 143-151 Link Here
143
		if (monitor.isCanceled()) {
142
		if (monitor.isCanceled()) {
144
			return false;
143
			return false;
145
		}
144
		}
146
		boolean initialVal=inChange;
145
		boolean initialVal = inChange;
147
		try {
146
		try {
148
			inChange=true;
147
			inChange = true;
149
			if (builder.isShowingHierarchy()) {
148
			if (builder.isShowingHierarchy()) {
150
				Comparator comparator = builder.getComparator()
149
				Comparator comparator = builder.getComparator()
151
						.getFieldsComparator();
150
						.getFieldsComparator();
Lines 168-175 Link Here
168
				}
167
				}
169
				int avaialble = markerEntryArray.length - 1;
168
				int avaialble = markerEntryArray.length - 1;
170
				int effLimit = getShowingLimit(avaialble);
169
				int effLimit = getShowingLimit(avaialble);
171
				MarkerSortUtil.sortStartingKElement(markerEntryArray, builder
170
				MarkerSortUtil.sortStartingKElement(markerEntryArray,
172
						.getComparator(), effLimit, monitor);
171
						builder.getComparator(), effLimit, monitor);
173
			}
172
			}
174
			if (monitor.isCanceled()) {
173
			if (monitor.isCanceled()) {
175
				return false;
174
				return false;
Lines 177-194 Link Here
177
			monitor.worked(50);
176
			monitor.worked(50);
178
			return true;
177
			return true;
179
		} finally {
178
		} finally {
180
			inChange=initialVal;
179
			inChange = initialVal;
181
		}
180
		}
182
	}
181
	}
183
182
184
	/**
183
	/**
185
	 * get marker limit to show, if any.
184
	 * get marker limit to show, if any.
185
	 * 
186
	 * @param avaliable
186
	 * @param avaliable
187
	 */
187
	 */
188
	private int getShowingLimit(int avaliable) {
188
	private int getShowingLimit(int avaliable) {
189
		int limit = MarkerSupportInternalUtilities.getMarkerLimit();
189
		int limit = MarkerSupportInternalUtilities.getMarkerLimit();
190
		int effLimit = limit;
190
		int effLimit = limit;
191
		if (avaliable < effLimit || limit == -1) {
191
		if (avaliable < effLimit || limit <= 0) {
192
			effLimit = avaliable;
192
			effLimit = avaliable;
193
		}
193
		}
194
		return effLimit;
194
		return effLimit;
Lines 203-210 Link Here
203
	 */
203
	 */
204
	MarkerCategory[] groupIntoCategories(IProgressMonitor monitor,
204
	MarkerCategory[] groupIntoCategories(IProgressMonitor monitor,
205
			MarkerEntry[] newMarkers) {
205
			MarkerEntry[] newMarkers) {
206
		Map boundaryInfoMap = groupMarkerEntries(newMarkers, builder
206
		Map boundaryInfoMap = groupMarkerEntries(newMarkers,
207
				.getCategoryGroup(), newMarkers.length - 1, monitor);
207
				builder.getCategoryGroup(), newMarkers.length - 1, monitor);
208
		Iterator iterator = boundaryInfoMap.keySet().iterator();
208
		Iterator iterator = boundaryInfoMap.keySet().iterator();
209
		int start = 0;
209
		int start = 0;
210
		MarkerCategory[] markerCategories = new MarkerCategory[boundaryInfoMap
210
		MarkerCategory[] markerCategories = new MarkerCategory[boundaryInfoMap
Lines 215-222 Link Here
215
			Object key = iterator.next();
215
			Object key = iterator.next();
216
			end = ((Integer) boundaryInfoMap.get(key)).intValue();
216
			end = ((Integer) boundaryInfoMap.get(key)).intValue();
217
			markerCategories[i++] = new MarkerCategory(this, start, end,
217
			markerCategories[i++] = new MarkerCategory(this, start, end,
218
					builder.getCategoryGroup().getMarkerField().getValue(
218
					builder.getCategoryGroup().getMarkerField()
219
							newMarkers[start]));
219
							.getValue(newMarkers[start]));
220
			start = end + 1;
220
			start = end + 1;
221
		}
221
		}
222
		return markerCategories;
222
		return markerCategories;
Lines 234-254 Link Here
234
	 * @return {@link Map}
234
	 * @return {@link Map}
235
	 * 
235
	 * 
236
	 */
236
	 */
237
	private Map groupMarkerEntries(MarkerEntry[] entries, MarkerGroup group, int k,
237
	private Map groupMarkerEntries(MarkerEntry[] entries, MarkerGroup group,
238
			IProgressMonitor monitor) {
238
			int k, IProgressMonitor monitor) {
239
		TreeMap map = new TreeMap(group.getEntriesComparator());
239
		TreeMap map = new TreeMap(group.getEntriesComparator());
240
		for (int i = 0; i <= k; i++) {
240
		for (int i = 0; i <= k; i++) {
241
			IMarker marker = entries[i].getMarker();
241
			IMarker marker = entries[i].getMarker();
242
			if (marker == null) {
242
			if (marker == null) {
243
				continue;// skip stale markers
243
				continue;// skip stale markers
244
			}
244
			}
245
			if(monitor.isCanceled()){
245
			if (monitor.isCanceled()) {
246
				map.clear();
246
				map.clear();
247
				return map;
247
				return map;
248
			}
248
			}
249
			try {
249
			try {
250
				MarkerGroupingEntry groupingEntry = group.findGroupValue(marker
250
				MarkerGroupingEntry groupingEntry = group.findGroupValue(
251
						.getType(), marker);
251
						marker.getType(), marker);
252
				List list = (List) map.get(groupingEntry);
252
				List list = (List) map.get(groupingEntry);
253
				if (list == null) {
253
				if (list == null) {
254
					list = new ArrayList();
254
					list = new ArrayList();
Lines 262-268 Link Here
262
		Iterator keys = map.keySet().iterator();
262
		Iterator keys = map.keySet().iterator();
263
		int i = 0;
263
		int i = 0;
264
		while (keys.hasNext()) {
264
		while (keys.hasNext()) {
265
			if(monitor.isCanceled()){
265
			if (monitor.isCanceled()) {
266
				map.clear();
266
				map.clear();
267
				return map;
267
				return map;
268
			}
268
			}
Lines 287-302 Link Here
287
	 */
287
	 */
288
	Integer[] getMarkerCounts() {
288
	Integer[] getMarkerCounts() {
289
		if (markerCounts == null) {
289
		if (markerCounts == null) {
290
			markerCounts=getMarkerCounts(markerEntryArray);
290
			markerCounts = getMarkerCounts(markerEntryArray);
291
291
292
		}
292
		}
293
		return markerCounts;
293
		return markerCounts;
294
	}
294
	}
295
295
296
	/**
296
	/**
297
	 * Returns an array of marker counts for the given MarkerEntry array
297
	 * Returns an array of marker counts for the given MarkerEntry array , where
298
	 * , where getMarkerCounts()[severity] is the number of markers in 
298
	 * getMarkerCounts()[severity] is the number of markers in the list with the
299
	 * the list with the given severity.
299
	 * given severity.
300
	 * 
300
	 * 
301
	 * @return an array of {@link Integer} where index indicates
301
	 * @return an array of {@link Integer} where index indicates
302
	 *         [errors,warnings,infos,others]
302
	 *         [errors,warnings,infos,others]
Lines 366-372 Link Here
366
	 * @return MarkerSupportItem[]
366
	 * @return MarkerSupportItem[]
367
	 */
367
	 */
368
	public MarkerSupportItem[] getElements() {
368
	public MarkerSupportItem[] getElements() {
369
		if(builder.isShowingHierarchy()){
369
		if (builder.isShowingHierarchy()) {
370
			return categories;
370
			return categories;
371
		}
371
		}
372
		return markerEntryArray;
372
		return markerEntryArray;
Lines 378-387 Link Here
378
	CachedMarkerBuilder getBuilder() {
378
	CachedMarkerBuilder getBuilder() {
379
		return builder;
379
		return builder;
380
	}
380
	}
381
	
381
382
	/**
382
	/**
383
	 * Use clone where thread safety is concerned.
383
	 * Use clone where thread safety is concerned. The method is non-blocking.
384
	 * The method is non-blocking.
385
	 */
384
	 */
386
	Markers getClone() {
385
	Markers getClone() {
387
		Markers markers = new Markers(builder);
386
		Markers markers = new Markers(builder);
Lines 399-405 Link Here
399
		return inChange;
398
		return inChange;
400
	}
399
	}
401
400
402
	/* (non-Javadoc)
401
	/*
402
	 * (non-Javadoc)
403
	 * 
403
	 * @see java.lang.Object#hashCode()
404
	 * @see java.lang.Object#hashCode()
404
	 */
405
	 */
405
	public int hashCode() {
406
	public int hashCode() {
Lines 409-415 Link Here
409
		return result;
410
		return result;
410
	}
411
	}
411
412
412
	/* (non-Javadoc)
413
	/*
414
	 * (non-Javadoc)
415
	 * 
413
	 * @see java.lang.Object#equals(java.lang.Object)
416
	 * @see java.lang.Object#equals(java.lang.Object)
414
	 */
417
	 */
415
	public boolean equals(Object obj) {
418
	public boolean equals(Object obj) {
(-)src/org/eclipse/ui/internal/views/markers/MarkersViewSettingDialog.java (+318 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.views.markers;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.jface.viewers.ITableLabelProvider;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
25
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
26
import org.eclipse.ui.views.markers.MarkerField;
27
import org.eclipse.ui.views.markers.internal.MarkerMessages;
28
29
/**
30
 * MarkersViewSettingDialog is the dialog for showing marker preferences.
31
 * 
32
 * 
33
 * @since 3.7
34
 * @author Hitesh Soliwal
35
 * 
36
 */
37
public class MarkersViewSettingDialog extends ViewerColumnsDialog {
38
39
	private ExtendedMarkersView extendedView;
40
41
	/**
42
	 * Create a new instance of the receiver.
43
	 * 
44
	 * @param view
45
	 *            - the view this is being launched from
46
	 */
47
	public MarkersViewSettingDialog(ExtendedMarkersView view) {
48
		super(view.getSite().getShell());
49
		this.extendedView = view;
50
		initialize(convert(extendedView.getBuilder().getGenerator()
51
				.getVisibleFields()), convert(extendedView.getBuilder()
52
				.getGenerator().getAllFields()), false);
53
		setLimitValue(IDEWorkbenchPlugin.getDefault().getPreferenceStore()
54
				.getInt(IDEInternalPreferences.MARKER_LIMITS_VALUE));
55
	}
56
57
	/*
58
	 * (non-Javadoc)
59
	 * 
60
	 * @see
61
	 * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
62
	 * .Shell)
63
	 */
64
	protected void configureShell(Shell newShell) {
65
		super.configureShell(newShell);
66
		newShell.setText(MarkerMessages.MarkerPreferences_DialogTitle);
67
	}
68
69
	/*
70
	 * (non-Javadoc)
71
	 * 
72
	 * @see org.eclipse.jface.window.Window#getShellStyle()
73
	 */
74
	protected int getShellStyle() {
75
		return super.getShellStyle() | SWT.RESIZE;
76
	}
77
78
	/*
79
	 * (non-Javadoc)
80
	 * 
81
	 * @see
82
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
83
	 * .Composite)
84
	 */
85
	protected Control createDialogArea(Composite parent) {
86
		Control control = super.createDialogArea(parent);
87
		return control;
88
	}
89
90
	/*
91
	 * (non-Javadoc)
92
	 * 
93
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
94
	 */
95
	protected void okPressed() {
96
		IDEWorkbenchPlugin
97
				.getDefault()
98
				.getPreferenceStore()
99
				.setValue(IDEInternalPreferences.MARKER_LIMITS_VALUE,
100
						getLimitValue());
101
		IDEWorkbenchPlugin.getDefault().savePluginPreferences();
102
		extendedView.setVisibleFields(getVisibleFields(), getNewWidths());
103
		super.okPressed();
104
	}
105
106
	/**
107
	 */
108
	private int[] getNewWidths() {
109
		List visible = getVisible();
110
		int[] widths = new int[visible.size()];
111
		int i = 0;
112
		Iterator iterator = visible.iterator();
113
		while (iterator.hasNext()) {
114
			widths[i++] = ((FieldEntry) iterator.next()).width;
115
		}
116
		return widths;
117
118
	}
119
120
	private Collection getVisibleFields() {
121
		List visible = getVisible();
122
		List list = new ArrayList(visible.size());
123
		Iterator iterator = visible.iterator();
124
		while (iterator.hasNext()) {
125
			list.add(((FieldEntry) iterator.next()).field);
126
		}
127
		return list;
128
	}
129
130
	/*
131
	 * (non-Javadoc)
132
	 * 
133
	 * @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults()
134
	 */
135
	protected void performDefaults() {
136
		initialize(convert(extendedView.getBuilder().getGenerator()
137
				.getInitialVisible()), convert(extendedView.getBuilder()
138
				.getGenerator().getAllFields()), true);
139
		setLimitValue(IDEWorkbenchPlugin.getDefault().getPreferenceStore()
140
				.getDefaultInt(IDEInternalPreferences.MARKER_LIMITS_VALUE));
141
		super.performDefaults();
142
	}
143
144
	/**
145
	 * @param visibleFields
146
	 * @param allFields
147
	 */
148
	void initialize(FieldEntry[] visibleFields, FieldEntry[] allFields,
149
			boolean defaultWidths) {
150
		List visible = getVisible();
151
		List nonVisible = getNonVisible();
152
		visible.clear();
153
		nonVisible.clear();
154
		for (int i = 0; i < allFields.length; i++) {
155
			nonVisible.add(allFields[i]);
156
		}
157
		for (int i = 0; i < visibleFields.length; i++) {
158
			nonVisible.remove(visibleFields[i]);
159
			visible.add(visibleFields[i]);
160
			visibleFields[i].visible = true;
161
			if (defaultWidths) {
162
				visibleFields[i].width = extendedView.getFieldWidth(
163
						visibleFields[i].field, 0);
164
			} else {
165
				// from a persistent store
166
				visibleFields[i].width = extendedView.getFieldWidth(
167
						visibleFields[i].field, -1);
168
			}
169
		}
170
	}
171
172
	/*
173
	 * (non-Javadoc)
174
	 * 
175
	 * @see
176
	 * org.eclipse.ui.internal.views.markers.ViewerColumnsDialog#getLabelProvider
177
	 * ()
178
	 */
179
	protected ITableLabelProvider getLabelProvider() {
180
		return new TableLabelProvider() {
181
			public String getText(Object element) {
182
				return ((FieldEntry) element).field.getName();
183
			}
184
		};
185
	}
186
187
	/*
188
	 * (non-Javadoc)
189
	 * 
190
	 * @see org.eclipse.ui.internal.views.markers.ViewerColumnsDialog#
191
	 * getColumnInfoProvider()
192
	 */
193
	protected IColumnInfoProvider getColumnInfoProvider() {
194
195
		return new IColumnInfoProvider() {
196
			public int getColumnIndex(Object columnObj) {
197
				return getVisible().indexOf(columnObj);
198
			}
199
200
			public int getColumnWidth(Object columnObj) {
201
				FieldEntry field = (FieldEntry) columnObj;
202
				return extendedView.getFieldWidth(field.field, field.width);
203
			}
204
205
			public boolean isColumnVisible(Object columnObj) {
206
				return ((FieldEntry) columnObj).visible;
207
			}
208
209
			public boolean isColumnMovable(Object columnObj) {
210
				return true;
211
			}
212
213
			public boolean isColumnResizable(Object columnObj) {
214
				return true;
215
			}
216
		};
217
	}
218
219
	/*
220
	 * (non-Javadoc)
221
	 * 
222
	 * @see
223
	 * org.eclipse.ui.internal.views.markers.ViewerColumnsDialog#getColumnUpdater
224
	 * ()
225
	 */
226
	protected IColumnUpdater getColumnUpdater() {
227
228
		return new IColumnUpdater() {
229
			public void setColumnVisible(Object columnObj, boolean visible) {
230
				((FieldEntry) columnObj).visible = visible;
231
			}
232
233
			public void setColumnMovable(Object columnObj, boolean movable) {
234
				// not implemented
235
			}
236
237
			public void setColumnIndex(Object columnObj, int index) {
238
				// ignore
239
			}
240
241
			public void setColumnResizable(Object columnObj, boolean resizable) {
242
				// ignore
243
			}
244
245
			public void setColumnWidth(Object columnObj, int newWidth) {
246
				((FieldEntry) columnObj).width = newWidth;
247
			}
248
		};
249
	}
250
251
	private static FieldEntry[] convert(Object[] fields) {
252
		FieldEntry[] entries = new FieldEntry[fields.length];
253
		for (int i = 0; i < entries.length; i++) {
254
			entries[i] = new FieldEntry((MarkerField) fields[i], -1);
255
		}
256
		return entries;
257
	}
258
259
	static class FieldEntry {
260
		final MarkerField field;
261
		int width;
262
		boolean visible;
263
264
		FieldEntry(MarkerField field, int width) {
265
			this.field = field;
266
			this.width = width;
267
			visible = false;
268
		}
269
270
		/*
271
		 * (non-Javadoc)
272
		 * 
273
		 * @see java.lang.Object#toString()
274
		 */
275
		public String toString() {
276
			// TODO Auto-generated method stub
277
			return super.toString();
278
		}
279
280
		/*
281
		 * (non-Javadoc)
282
		 * 
283
		 * @see java.lang.Object#hashCode()
284
		 */
285
		public int hashCode() {
286
			final int prime = 31;
287
			int result = 1;
288
			result = prime * result + ((field == null) ? 0 : field.hashCode());
289
			return result;
290
		}
291
292
		/*
293
		 * (non-Javadoc)
294
		 * 
295
		 * @see java.lang.Object#equals(java.lang.Object)
296
		 */
297
		public boolean equals(Object obj) {
298
			if (this == obj) {
299
				return true;
300
			}
301
			if (obj == null) {
302
				return false;
303
			}
304
			if (!(obj instanceof FieldEntry)) {
305
				return false;
306
			}
307
			FieldEntry other = (FieldEntry) obj;
308
			if (field == null) {
309
				if (other.field != null) {
310
					return false;
311
				}
312
			} else if (!field.equals(other.field)) {
313
				return false;
314
			}
315
			return true;
316
		}
317
	}
318
}
(-)src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java (+1208 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.views.markers;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Iterator;
17
import java.util.List;
18
import java.util.ListIterator;
19
import java.util.Random;
20
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.jface.dialogs.Dialog;
23
import org.eclipse.jface.resource.JFaceResources;
24
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.jface.viewers.IStructuredContentProvider;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.ITableLabelProvider;
29
import org.eclipse.jface.viewers.LabelProvider;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
31
import org.eclipse.jface.viewers.TableViewer;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.CLabel;
35
import org.eclipse.swt.graphics.Image;
36
import org.eclipse.swt.layout.FillLayout;
37
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Event;
44
import org.eclipse.swt.widgets.Group;
45
import org.eclipse.swt.widgets.Label;
46
import org.eclipse.swt.widgets.Listener;
47
import org.eclipse.swt.widgets.Shell;
48
import org.eclipse.swt.widgets.Table;
49
import org.eclipse.swt.widgets.TableColumn;
50
import org.eclipse.swt.widgets.Text;
51
import org.eclipse.ui.preferences.ViewSettingsDialog;
52
import org.eclipse.ui.views.markers.internal.MarkerMessages;
53
54
/**
55
 * This was introduced as a fix to Bug , as an effort to combine the columns and
56
 * preference dialogs into one. It should be noted that the class can be re-used
57
 * or turned into a tool for column viewers in general, but with some
58
 * modifications. See example attached at the end of this class
59
 * 
60
 * @since 3.7
61
 * 
62
 * @author Hitesh Soliwal
63
 * 
64
 * @noextend This class is not intended to be subclassed by clients.
65
 * 
66
 */
67
abstract class ViewerColumnsDialog extends ViewSettingsDialog {
68
69
	/** The list contains columns that are currently visible in viewer */
70
	private List visible;
71
72
	/** The list contains columns that are note shown in viewer */
73
	private List nonVisible;
74
75
	/**
76
	 * The number of elements to show at Max. A zero value may indicate
77
	 * disablement of limit
78
	 */
79
	private int limitValue;
80
81
	/** The message area */
82
	private CLabel messageLabel;
83
84
	private TableViewer visibleViewer, nonVisibleViewer;
85
86
	private Button upButton, downButton;
87
88
	private Button toVisibleBtt, toNonVisibleBtt;
89
90
	private Text widthText, limitEditor;
91
92
	/**
93
	 * A listener to validate positive integer numbers only
94
	 */
95
	Listener postivIntTextListener = new Listener() {
96
97
		private String intialValue;
98
99
		public void handleEvent(Event event) {
100
			intialValue = intialValue != null ? intialValue : Integer
101
					.toString(0);
102
			intialValue = handleIntegerFieldChange(event, intialValue);
103
		}
104
	};
105
106
	/**
107
	 * Create a new instance of the receiver.
108
	 * 
109
	 * @param parentShell
110
	 */
111
	ViewerColumnsDialog(Shell parentShell) {
112
		super(parentShell);
113
	}
114
115
	/**
116
	 * Initialize visible /non-visible columns.
117
	 * 
118
	 * @param columnObjs
119
	 */
120
	void setColumnsObjs(Object[] columnObjs) {
121
		IColumnInfoProvider columnInfo = doGetColumnInfoProvider();
122
		IColumnUpdater updater = doGetColumnUpdater();
123
		List visible = getVisible();
124
		List nonVisible = getNonVisible();
125
		visible.clear();
126
		nonVisible.clear();
127
		Object data = null;
128
		for (int i = 0; i < columnObjs.length; i++) {
129
			data = columnObjs[i];
130
			if (columnInfo.isColumnVisible(data)) {
131
				updater.setColumnVisible(data, true);
132
				updater.setColumnIndex(data, visible.size());
133
				visible.add(data);
134
			} else {
135
				updater.setColumnVisible(data, false);
136
				updater.setColumnIndex(data, nonVisible.size());
137
				nonVisible.add(data);
138
			}
139
		}
140
	}
141
142
	/*
143
	 * (non-Javadoc)
144
	 * 
145
	 * @see
146
	 * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
147
	 * .Shell)
148
	 */
149
	protected void configureShell(Shell newShell) {
150
		super.configureShell(newShell);
151
		newShell.setText(JFaceResources
152
				.getString("ConfigureColumnsDialog_Title")); //$NON-NLS-1$
153
	}
154
155
	/*
156
	 * (non-Javadoc)
157
	 * 
158
	 * @see org.eclipse.jface.window.Window#getShellStyle()
159
	 */
160
	protected int getShellStyle() {
161
		return super.getShellStyle() | SWT.RESIZE;
162
	}
163
164
	/*
165
	 * (non-Javadoc)
166
	 * 
167
	 * @see
168
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
169
	 * .Composite)
170
	 */
171
	protected Control createDialogArea(Composite parent) {
172
173
		Composite dialogArea = (Composite) super.createDialogArea(parent);
174
175
		dialogArea.setLayout(new GridLayout(1, true));
176
177
		initializeDialogUnits(dialogArea);
178
179
		createMessageArea(dialogArea);
180
181
		createLimitArea(dialogArea);
182
183
		createColumnsArea(dialogArea);
184
185
		applyDialogFont(dialogArea);
186
187
		initializeDlg();
188
189
		return dialogArea;
190
	}
191
192
	/**
193
	 * 
194
	 */
195
	void initializeDlg() {
196
		handleStatusUdpate(IStatus.INFO, getDefaultMessage());
197
	}
198
199
	/**
200
	 * Create message area.
201
	 * 
202
	 * @param parent
203
	 */
204
	void createMessageArea(Composite parent) {
205
		messageLabel = new CLabel(parent, SWT.NONE);
206
		messageLabel.setImage(JFaceResources
207
				.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
208
		messageLabel
209
				.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
210
	}
211
212
	/**
213
	 * Create element limit area.
214
	 * 
215
	 * @param parent
216
	 */
217
	void createLimitArea(Composite parent) {
218
		Composite composite = new Group(parent, SWT.NONE);
219
		composite.setLayout(new GridLayout(2, false));
220
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
221
222
		CLabel cLabel = new CLabel(composite, SWT.NONE);
223
		cLabel.setText(MarkerMessages.MarkerPreferences_VisibleItems);
224
		cLabel.setLayoutData(new GridData());
225
226
		limitEditor = new Text(composite, SWT.BORDER);
227
		limitEditor.setText(Integer.toString(getLimitValue()));
228
		limitEditor.setLayoutData(new GridData());
229
		limitEditor.addListener(SWT.FocusOut, postivIntTextListener);
230
		limitEditor.addListener(SWT.KeyDown, postivIntTextListener);
231
		limitEditor.addListener(SWT.Modify, new Listener() {
232
			public void handleEvent(Event event) {
233
				int limit = 0;
234
				try {
235
					limit = Integer.parseInt(limitEditor.getText().trim());
236
				} catch (Exception e) {
237
					return;// ignore this one
238
				}
239
				setLimitValue(limit);
240
			}
241
		});
242
		limitEditor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
243
	}
244
245
	/**
246
	 * Create the controls to configure columns.
247
	 * 
248
	 * @param dialogArea
249
	 */
250
	void createColumnsArea(Composite dialogArea) {
251
		Group columnArea = new Group(dialogArea, SWT.NONE);
252
		columnArea.setLayout(new GridLayout(4, false));
253
		GridData gData = new GridData(GridData.FILL_BOTH
254
				| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
255
		columnArea.setLayoutData(gData);
256
		columnArea.setText(MarkerMessages.MarkerPreferences_ColumnGroupTitle);
257
258
		createInvisibleTable(columnArea);
259
		createMoveButtons(columnArea);
260
		createVisibleTable(columnArea);
261
		createUpDownBtt(columnArea);
262
		createWidthArea(columnArea);
263
	}
264
265
	/**
266
	 * The Up and Down button to change column ordering.
267
	 * 
268
	 * @param parent
269
	 */
270
	void createUpDownBtt(Composite parent) {
271
		Composite composite = new Composite(parent, SWT.NONE);
272
		GridLayout layout = new GridLayout(1, true);
273
		layout.horizontalSpacing = 0;
274
		layout.marginRight = -1;
275
		layout.marginLeft = -1;
276
		layout.marginWidth = 0;
277
		composite.setLayout(layout);
278
		composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
279
				| GridData.VERTICAL_ALIGN_END));
280
		upButton = new Button(composite, SWT.PUSH);
281
		upButton.setText(JFaceResources.getString("ConfigureColumnsDialog_up")); //$NON-NLS-1$
282
		upButton.addListener(SWT.Selection, new Listener() {
283
			public void handleEvent(Event event) {
284
				handleUpButton(event);
285
			}
286
		});
287
		upButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
288
		upButton.setEnabled(false);
289
290
		downButton = new Button(composite, SWT.PUSH);
291
		downButton.setText(JFaceResources
292
				.getString("ConfigureColumnsDialog_down")); //$NON-NLS-1$
293
		downButton.addListener(SWT.Selection, new Listener() {
294
			public void handleEvent(Event event) {
295
				handleDownButton(event);
296
			}
297
		});
298
		downButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
299
		downButton.setEnabled(false);
300
	}
301
302
	/**
303
	 * Create the controls responsible to display/edit column widths.
304
	 * 
305
	 * @param parent
306
	 */
307
	void createWidthArea(Composite parent) {
308
		Label widthLabel = new Label(parent, SWT.NONE);
309
		widthLabel.setText(JFaceResources
310
				.getString("ConfigureColumnsDialog_WidthOfSelectedColumn")); //$NON-NLS-1$
311
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL
312
				| GridData.HORIZONTAL_ALIGN_END);
313
		gridData.horizontalSpan = 3;
314
		widthLabel.setLayoutData(gridData);
315
316
		widthText = new Text(parent, SWT.SINGLE | SWT.BORDER);
317
		widthText.setText(Integer.toString(0));
318
		gridData = new GridData(GridData.FILL_HORIZONTAL
319
				| GridData.HORIZONTAL_ALIGN_CENTER);
320
		gridData.widthHint = convertWidthInCharsToPixels(5);
321
		widthText.setLayoutData(gridData);
322
		widthText.addListener(SWT.KeyDown, postivIntTextListener);
323
		widthText.addListener(SWT.FocusOut, postivIntTextListener);
324
		widthText.addListener(SWT.Modify, new Listener() {
325
			public void handleEvent(Event event) {
326
				if (widthText.isEnabled()) {
327
					int width = 0;
328
					try {
329
						width = Integer.parseInt(widthText.getText().trim());
330
					} catch (Exception e) {
331
						return;// ignore this one
332
					}
333
					Object data = ((IStructuredSelection) visibleViewer
334
							.getSelection()).getFirstElement();
335
					if (data != null) {
336
						IColumnUpdater updater = getColumnUpdater();
337
						updater.setColumnWidth(data, width);
338
					}
339
				}
340
			}
341
		});
342
		widthText.setText(MarkerSupportInternalUtilities.EMPTY_STRING);
343
		widthText.setEditable(false);
344
	}
345
346
	/**
347
	 * Adapter to {@link IStructuredContentProvider}
348
	 */
349
	abstract class ContentProviderAdapter implements IStructuredContentProvider {
350
351
		public void dispose() {
352
		}
353
354
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
355
		}
356
	}
357
358
	/**
359
	 * Creates the table that lists out visible columns in the viewer
360
	 * 
361
	 * @param parent
362
	 */
363
	void createVisibleTable(Composite parent) {
364
		final Table table = new Table(parent, SWT.BORDER | SWT.MULTI);
365
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
366
		data.widthHint = convertWidthInCharsToPixels(30);
367
		data.heightHint = table.getItemHeight() * 15;
368
		table.setLayoutData(data);
369
		table.setHeaderVisible(true);
370
371
		final TableColumn column = new TableColumn(table, SWT.NONE);
372
		column.setText(MarkerMessages.MarkerPreferences_VisibleColumnsTitle);
373
		Listener columnResize = new Listener() {
374
			public void handleEvent(Event event) {
375
				column.setWidth(table.getClientArea().width);
376
			}
377
		};
378
		table.addListener(SWT.Resize, columnResize);
379
380
		visibleViewer = new TableViewer(table);
381
		visibleViewer.setLabelProvider(doGetLabelProvider());
382
		visibleViewer.setContentProvider(new ContentProviderAdapter() {
383
			public Object[] getElements(Object inputElement) {
384
				return getVisible().toArray();
385
			}
386
		});
387
		visibleViewer
388
				.addSelectionChangedListener(new ISelectionChangedListener() {
389
					public void selectionChanged(SelectionChangedEvent event) {
390
						handleVisibleSelection(event.getSelection());
391
					}
392
				});
393
		table.addListener(SWT.MouseDoubleClick, new Listener() {
394
			public void handleEvent(Event event) {
395
				handleToNonVisibleButton(event);
396
			}
397
		});
398
		visibleViewer.setInput(this);
399
	}
400
401
	/**
402
	 * Creates the table that lists out non-visible columns in the viewer
403
	 * 
404
	 * @param parent
405
	 */
406
	void createInvisibleTable(Composite parent) {
407
		final Table table = new Table(parent, SWT.BORDER | SWT.MULTI);
408
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
409
		data.widthHint = convertWidthInCharsToPixels(30);
410
		data.heightHint = table.getItemHeight() * 15;
411
		table.setLayoutData(data);
412
		table.setHeaderVisible(true);
413
414
		final TableColumn column = new TableColumn(table, SWT.NONE);
415
		column.setText(MarkerMessages.MarkerPreferences_HiddenColumnsTitle);
416
		Listener columnResize = new Listener() {
417
			public void handleEvent(Event event) {
418
				column.setWidth(table.getClientArea().width);
419
			}
420
		};
421
		table.addListener(SWT.Resize, columnResize);
422
423
		nonVisibleViewer = new TableViewer(table);
424
		nonVisibleViewer.setLabelProvider(doGetLabelProvider());
425
		nonVisibleViewer.setContentProvider(new ContentProviderAdapter() {
426
			public Object[] getElements(Object inputElement) {
427
				return getNonVisible().toArray();
428
			}
429
		});
430
		nonVisibleViewer
431
				.addSelectionChangedListener(new ISelectionChangedListener() {
432
					public void selectionChanged(SelectionChangedEvent event) {
433
						handleNonVisibleSelection(event.getSelection());
434
					}
435
				});
436
		table.addListener(SWT.MouseDoubleClick, new Listener() {
437
			public void handleEvent(Event event) {
438
				handleToVisibleButton(event);
439
			}
440
		});
441
		nonVisibleViewer.setInput(this);
442
	}
443
444
	/**
445
	 * Creates buttons for moving columns from non-visible to visible and
446
	 * vice-versa
447
	 * 
448
	 * @param parent
449
	 */
450
	void createMoveButtons(Composite parent) {
451
		Composite bttArea = new Composite(parent, SWT.NONE);
452
		bttArea.setLayout(new GridLayout(1, true));
453
		bttArea.setLayoutData(new GridData(GridData.FILL_VERTICAL));
454
455
		toNonVisibleBtt = new Button(bttArea, SWT.PUSH);
456
		toNonVisibleBtt
457
				.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveRight
458
						: MarkerMessages.MarkerPreferences_MoveLeft);
459
		toNonVisibleBtt.setLayoutData(new GridData());
460
461
		toNonVisibleBtt.addListener(SWT.Selection, new Listener() {
462
			public void handleEvent(Event event) {
463
				handleToNonVisibleButton(event);
464
			}
465
		});
466
		toNonVisibleBtt.setEnabled(false);
467
468
		toVisibleBtt = new Button(bttArea, SWT.PUSH);
469
		toVisibleBtt
470
				.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveLeft
471
						: MarkerMessages.MarkerPreferences_MoveRight);
472
		toVisibleBtt.setLayoutData(new GridData());
473
		toVisibleBtt.addListener(SWT.Selection, new Listener() {
474
			public void handleEvent(Event event) {
475
				handleToVisibleButton(event);
476
			}
477
		});
478
		toVisibleBtt.setEnabled(false);
479
	}
480
481
	/**
482
	 * Display the error message and an appropriate icon.
483
	 * 
484
	 * @param messgage
485
	 * @param severity
486
	 */
487
	protected void handleStatusUdpate(int severity, String messgage) {
488
		Image image = null;
489
		switch (severity) {
490
		case IStatus.ERROR: {
491
			if (messgage == null) {
492
				messgage = getErrorMessage();
493
			}
494
			image = getErrorImage();
495
			break;
496
		}
497
		case IStatus.WARNING: {
498
			image = getWarningImage();
499
			break;
500
		}
501
		case IStatus.OK:
502
		case IStatus.INFO:
503
		default:
504
			image = getInfoImage();
505
		}
506
		messageLabel.setImage(image);
507
		if (messgage == null) {
508
			messgage = getDefaultMessage();
509
		}
510
		if (messgage == null) {
511
			messgage = MarkerSupportInternalUtilities.EMPTY_STRING;
512
		}
513
		messageLabel.setText(messgage);
514
	}
515
516
	/**
517
	 * Return the message to display when dialog is opened.
518
	 */
519
	protected String getDefaultMessage() {
520
		return MarkerMessages.MarkerPreferences_ZeroOrBlankValueCanBeUsedToDisableTheLimit;
521
	}
522
523
	/**
524
	 * @return Returns the error message to display for a wrong limit value.
525
	 */
526
	protected String getErrorMessage() {
527
		return JFaceResources.getString("IntegerFieldEditor.errorMessage"); //$NON-NLS-1$
528
	}
529
530
	/**
531
	 */
532
	protected Image getInfoImage() {
533
		return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
534
	}
535
536
	/**
537
	 */
538
	protected Image getWarningImage() {
539
		return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
540
	}
541
542
	/**
543
	 */
544
	protected Image getErrorImage() {
545
		return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
546
	}
547
548
	/*
549
	 * (non-Javadoc)
550
	 * 
551
	 * @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults()
552
	 */
553
	protected void performDefaults() {
554
		refreshViewers();
555
		super.performDefaults();
556
	}
557
558
	/**
559
	 * 
560
	 * @param event
561
	 * @param intialvalue
562
	 * @return new integer value
563
	 */
564
	String handleIntegerFieldChange(Event event, String intialvalue) {
565
		Text text = (Text) event.widget;
566
		String value = text.getText().trim();
567
		switch (event.type) {
568
		case SWT.KeyDown:
569
			if (!Character.isDigit(event.character)) {
570
				if (!Character.isISOControl(event.character)) {
571
					handleStatusUdpate(IStatus.ERROR, getErrorMessage());
572
					event.doit = false;
573
					return intialvalue;
574
				}
575
			}
576
		case SWT.FocusOut:
577
			if (value.length() == 0) {
578
				value = Integer.toString(0);
579
				text.setText(value);
580
				text.selectAll();
581
				handleStatusUdpate(IStatus.INFO, null);
582
			} else {
583
				try {
584
					Integer.parseInt(value);
585
					handleStatusUdpate(IStatus.INFO, null);
586
				} catch (Exception e) {
587
					value = intialvalue;
588
					text.setText(value);
589
					text.selectAll();
590
					handleStatusUdpate(IStatus.ERROR, getErrorMessage());
591
					event.doit = false;
592
				}
593
			}
594
		}
595
		return value;
596
	}
597
598
	/**
599
	 * Handles a selection change in the viewer that lists out the non-visible
600
	 * columns
601
	 * 
602
	 * @param selection
603
	 */
604
	void handleNonVisibleSelection(ISelection selection) {
605
		Object[] nvKeys = ((IStructuredSelection) selection).toArray();
606
		toVisibleBtt.setEnabled(nvKeys.length > 0);
607
	}
608
609
	/**
610
	 * Handles a selection change in the viewer that lists out the visible
611
	 * columns. Takes care of various enablements.
612
	 * 
613
	 * @param selection
614
	 */
615
	void handleVisibleSelection(ISelection selection) {
616
		List selVCols = ((IStructuredSelection) selection).toList();
617
		List allVCols = getVisible();
618
		toNonVisibleBtt.setEnabled(selVCols.size() > 0
619
				&& allVCols.size() > selVCols.size());
620
621
		IColumnInfoProvider infoProvider = doGetColumnInfoProvider();
622
		boolean moveDown = !selVCols.isEmpty(), moveUp = !selVCols.isEmpty();
623
		Iterator iterator = selVCols.iterator();
624
		while (iterator.hasNext()) {
625
			Object columnObj = iterator.next();
626
			if (!infoProvider.isColumnMovable(columnObj)) {
627
				moveUp = false;
628
				moveDown = false;
629
				break;
630
			}
631
			int i = allVCols.indexOf(columnObj);
632
			if (i == 0) {
633
				moveUp = false;
634
				if (!moveDown) {
635
					break;
636
				}
637
			}
638
			if (i == (allVCols.size() - 1)) {
639
				moveDown = false;
640
				if (!moveUp) {
641
					break;
642
				}
643
			}
644
		}
645
		upButton.setEnabled(moveUp);
646
		downButton.setEnabled(moveDown);
647
648
		boolean edit = selVCols.size() == 1 ? infoProvider
649
				.isColumnResizable(selVCols.get(0)) : false;
650
		if (edit) {
651
			widthText.setText(Integer.toString(infoProvider
652
					.getColumnWidth(selVCols.get(0))));
653
		} else {
654
			widthText.setText(Integer.toString(0));
655
		}
656
		widthText.setEditable(edit);
657
	}
658
659
	/**
660
	 * Applies to visible columns, and handles the changes in the order of
661
	 * columns
662
	 * 
663
	 * @param e
664
	 *            event from the button click
665
	 */
666
	void handleDownButton(Event e) {
667
		IStructuredSelection selection = (IStructuredSelection) visibleViewer
668
				.getSelection();
669
		Object[] selVCols = selection.toArray();
670
		List allVCols = getVisible();
671
		IColumnUpdater updater = doGetColumnUpdater();
672
		for (int i = selVCols.length - 1; i >= 0; i--) {
673
			Object colObj = selVCols[i];
674
			int index = allVCols.indexOf(colObj);
675
			updater.setColumnIndex(colObj, index + 1);
676
			allVCols.remove(index);
677
			allVCols.add(index + 1, colObj);
678
		}
679
		visibleViewer.refresh();
680
		handleVisibleSelection(selection);
681
	}
682
683
	/**
684
	 * Applies to visible columns, and handles the changes in the order of
685
	 * columns
686
	 * 
687
	 * @param e
688
	 *            event from the button click
689
	 */
690
	void handleUpButton(Event e) {
691
		IStructuredSelection selection = (IStructuredSelection) visibleViewer
692
				.getSelection();
693
		Object[] selVCols = selection.toArray();
694
		List allVCols = getVisible();
695
		IColumnUpdater updater = doGetColumnUpdater();
696
		for (int i = 0; i < selVCols.length; i++) {
697
			Object colObj = selVCols[i];
698
			int index = allVCols.indexOf(colObj);
699
			updater.setColumnIndex(colObj, index - 1);
700
			allVCols.remove(index);
701
			allVCols.add(index - 1, colObj);
702
		}
703
		visibleViewer.refresh();
704
		handleVisibleSelection(selection);
705
	}
706
707
	/**
708
	 * Moves selected columns from non-visible to visible state
709
	 * 
710
	 * @param e
711
	 *            event from the button click
712
	 */
713
	void handleToVisibleButton(Event e) {
714
		IStructuredSelection selection = (IStructuredSelection) nonVisibleViewer
715
				.getSelection();
716
		List selVCols = selection.toList();
717
		List nonVisible = getNonVisible();
718
		nonVisible.removeAll(selVCols);
719
720
		List list = getVisible();
721
		list.addAll(selVCols);
722
723
		updateVisibility(selVCols, true);
724
		updateIndices(getVisible());
725
		updateIndices(getNonVisible());
726
727
		visibleViewer.refresh();
728
		visibleViewer.setSelection(selection);
729
		nonVisibleViewer.refresh();
730
		handleVisibleSelection(selection);
731
		handleNonVisibleSelection(nonVisibleViewer.getSelection());
732
	}
733
734
	/**
735
	 * Moves selected columns from visible to non-visible state
736
	 * 
737
	 * @param e
738
	 *            event from the button click
739
	 */
740
	protected void handleToNonVisibleButton(Event e) {
741
		if (getVisible().size() <= 1) {
742
			handleStatusUdpate(IStatus.INFO,
743
					MarkerMessages.MarkerPreferences_AtLeastOneVisibleColumn);
744
			return;
745
		}
746
		IStructuredSelection selection = (IStructuredSelection) visibleViewer
747
				.getSelection();
748
		List selVCols = selection.toList();
749
		getVisible().removeAll(selVCols);
750
		getNonVisible().addAll(selVCols);
751
752
		updateVisibility(selVCols, false);
753
		updateIndices(getVisible());
754
		updateIndices(getNonVisible());
755
756
		nonVisibleViewer.refresh();
757
		nonVisibleViewer.setSelection(selection);
758
		visibleViewer.refresh();
759
		handleVisibleSelection(visibleViewer.getSelection());
760
		handleNonVisibleSelection(nonVisibleViewer.getSelection());
761
		handleStatusUdpate(IStatus.INFO, getDefaultMessage());
762
	}
763
764
	void updateIndices(List list) {
765
		ListIterator iterator = list.listIterator();
766
		IColumnUpdater updater = doGetColumnUpdater();
767
		while (iterator.hasNext()) {
768
			updater.setColumnIndex(iterator.next(), iterator.previousIndex());
769
		}
770
	}
771
772
	void updateVisibility(List list, boolean visibility) {
773
		IColumnUpdater updater = doGetColumnUpdater();
774
		Iterator iterator = list.iterator();
775
		while (iterator.hasNext()) {
776
			updater.setColumnVisible(iterator.next(), visibility);
777
		}
778
	}
779
780
	/**
781
	 * Updates the UI based on values of the variable
782
	 */
783
	void refreshViewers() {
784
		if (limitEditor != null) {
785
			limitEditor.setText(Integer.toString(getLimitValue()));
786
		}
787
		if (nonVisibleViewer != null) {
788
			nonVisibleViewer.refresh();
789
		}
790
		if (visibleViewer != null) {
791
			visibleViewer.refresh();
792
		}
793
	}
794
795
	/*
796
	 * (non-Javadoc)
797
	 * 
798
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
799
	 */
800
	protected boolean isResizable() {
801
		return true;
802
	}
803
804
	/*
805
	 * (non-Javadoc)
806
	 * 
807
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
808
	 */
809
	protected void okPressed() {
810
		super.okPressed();
811
	}
812
813
	/**
814
	 * @return Returns the limitValue.
815
	 */
816
	public int getLimitValue() {
817
		return limitValue;
818
	}
819
820
	/**
821
	 * @param limitValue
822
	 *            The limitValue to set.
823
	 */
824
	void setLimitValue(int limitValue) {
825
		this.limitValue = limitValue;
826
	}
827
828
	/**
829
	 * @return List of visible columns
830
	 */
831
	public List getVisible() {
832
		if (visible == null) {
833
			visible = new ArrayList();
834
		}
835
		return visible;
836
	}
837
838
	/**
839
	 * @return List of non-visible columns
840
	 */
841
	public List getNonVisible() {
842
		if (nonVisible == null) {
843
			nonVisible = new ArrayList();
844
		}
845
		return nonVisible;
846
	}
847
848
	/**
849
	 * An adapter class to {@link ITableLabelProvider}
850
	 * 
851
	 */
852
	class TableLabelProvider extends LabelProvider implements
853
			ITableLabelProvider {
854
		public Image getColumnImage(Object element, int columnIndex) {
855
			return null;
856
		}
857
858
		public String getColumnText(Object element, int columnIndex) {
859
			return getText(element);
860
		}
861
	}
862
863
	/**
864
	 * Internal helper to @see {@link ViewerColumnsDialog#getLabelProvider()}
865
	 */
866
	ITableLabelProvider doGetLabelProvider() {
867
		return getLabelProvider();
868
	}
869
870
	/**
871
	 * The tables-columns need to be displayed appropriately. The supplied
872
	 * column objects are adapted to text and image as dictacted by this
873
	 * {@link ITableLabelProvider}
874
	 */
875
	protected abstract ITableLabelProvider getLabelProvider();
876
877
	/**
878
	 * Internal helper to @see
879
	 * {@link ViewerColumnsDialog#getColumnInfoProvider()}
880
	 */
881
	IColumnInfoProvider doGetColumnInfoProvider() {
882
		return getColumnInfoProvider();
883
	}
884
885
	/**
886
	 * To configure the columns we need further information. The supplied column
887
	 * objects are adapted for its properties via {@link IColumnInfoProvider}
888
	 */
889
	protected abstract IColumnInfoProvider getColumnInfoProvider();
890
891
	/**
892
	 * Internal helper to @see {@link ViewerColumnsDialog#getColumnUpdater()}
893
	 */
894
	IColumnUpdater doGetColumnUpdater() {
895
		return getColumnUpdater();
896
	}
897
898
	/**
899
	 * To configure properties/order of the columns is achieved via
900
	 * {@link IColumnUpdater}
901
	 */
902
	protected abstract IColumnUpdater getColumnUpdater();
903
904
	/**
905
	 * Update various aspects of a columns from a viewer such
906
	 * {@link TableViewer}
907
	 */
908
	public interface IColumnInfoProvider {
909
910
		/**
911
		 * Get corresponding index for the column
912
		 * 
913
		 * @param columnObj
914
		 */
915
		public int getColumnIndex(Object columnObj);
916
917
		/**
918
		 * Get the width of the column
919
		 * 
920
		 * @param columnObj
921
		 */
922
		public int getColumnWidth(Object columnObj);
923
924
		/**
925
		 * Returns true if the column represented by parameters is showing in
926
		 * the viewer
927
		 * 
928
		 * @param columnObj
929
		 */
930
		public boolean isColumnVisible(Object columnObj);
931
932
		/**
933
		 * Returns true if the column represented by parameters is configured as
934
		 * movable
935
		 * 
936
		 * @param columnObj
937
		 */
938
		public boolean isColumnMovable(Object columnObj);
939
940
		/**
941
		 * Returns true if the column represented by parameters is configured as
942
		 * resizable
943
		 * 
944
		 * @param columnObj
945
		 */
946
		public boolean isColumnResizable(Object columnObj);
947
948
	}
949
950
	/**
951
	 * Update various aspects of a columns from a viewer such
952
	 * {@link TableViewer}
953
	 */
954
	public interface IColumnUpdater {
955
956
		/**
957
		 * Set the column represented by parameters as visible
958
		 * 
959
		 * @param columnObj
960
		 * @param visible
961
		 */
962
		public void setColumnVisible(Object columnObj, boolean visible);
963
964
		/**
965
		 * Dummy method - more a result of symmetry
966
		 * 
967
		 * @param columnObj
968
		 * @param movable
969
		 */
970
		public void setColumnMovable(Object columnObj, boolean movable);
971
972
		/**
973
		 * Call back to notify change in the index of the column represented by
974
		 * columnObj
975
		 * 
976
		 * @param columnObj
977
		 * @param index
978
		 */
979
		public void setColumnIndex(Object columnObj, int index);
980
981
		/**
982
		 * Dummy method - more a result of symmetry
983
		 * 
984
		 * @param columnObj
985
		 * @param resizable
986
		 */
987
		public void setColumnResizable(Object columnObj, boolean resizable);
988
989
		/**
990
		 * Call back to notify change in the width of the column represented by
991
		 * columnObj
992
		 * 
993
		 * @param columnObj
994
		 * @param newWidth
995
		 */
996
		public void setColumnWidth(Object columnObj, int newWidth);
997
998
	}
999
1000
	// //////////////////////////////////////////////////////////////////////////////////
1001
	/**
1002
	 * Ignore the class below as it is simply meant to test the above. I intend
1003
	 * to retain this for a while.
1004
	 */
1005
	static class TestData {
1006
1007
		final Object key;
1008
1009
		final int keyIndex;
1010
1011
		int newIndex, width;
1012
1013
		boolean visibility, movable, resizable;
1014
1015
		TestData(Object key, int currIndex) {
1016
			this.key = key;
1017
			this.keyIndex = currIndex;
1018
		}
1019
1020
		public int hashCode() {
1021
			final int prime = 31;
1022
			int result = 1;
1023
			result = prime * result + ((key == null) ? 0 : key.hashCode());
1024
			result = prime * result + keyIndex;
1025
			return result;
1026
		}
1027
1028
		public boolean equals(Object obj) {
1029
			if (this == obj) {
1030
				return true;
1031
			}
1032
			if (obj == null) {
1033
				return false;
1034
			}
1035
			if (!(obj instanceof TestData)) {
1036
				return false;
1037
			}
1038
			TestData other = (TestData) obj;
1039
			if (key == null) {
1040
				if (other.key != null) {
1041
					return false;
1042
				}
1043
			} else if (!key.equals(other.key)) {
1044
				return false;
1045
			}
1046
			if (keyIndex != other.keyIndex) {
1047
				return false;
1048
			}
1049
			return true;
1050
		}
1051
1052
		public String toString() {
1053
			return key.toString();
1054
		}
1055
1056
		private static ViewerColumnsDialog getColumnsDialog(Shell shell,
1057
				final TestData[] colums) {
1058
			ViewerColumnsDialog dialog = new ViewerColumnsDialog(shell) {
1059
1060
				protected IColumnInfoProvider getColumnInfoProvider() {
1061
					return getInfoProvider(colums);
1062
				}
1063
1064
				protected ITableLabelProvider getLabelProvider() {
1065
					return new TableLabelProvider();
1066
				}
1067
1068
				protected IColumnUpdater getColumnUpdater() {
1069
					return getUpdater(colums);
1070
				}
1071
			};
1072
			dialog.setColumnsObjs(colums);
1073
			return dialog;
1074
		}
1075
1076
		private static IColumnUpdater getUpdater(final TestData[] data) {
1077
			return new IColumnUpdater() {
1078
1079
				public void setColumnWidth(Object columnObj, int newWidth) {
1080
					((TestData) columnObj).width = newWidth;
1081
				}
1082
1083
				public void setColumnVisible(Object columnObj, boolean visible) {
1084
					((TestData) columnObj).visibility = visible;
1085
				}
1086
1087
				public void setColumnResizable(Object columnObj,
1088
						boolean resizable) {
1089
1090
				}
1091
1092
				public void setColumnMovable(Object columnObj, boolean movable) {
1093
					((TestData) columnObj).movable = movable;
1094
1095
				}
1096
1097
				public void setColumnIndex(Object columnObj, int index) {
1098
					((TestData) columnObj).newIndex = index;
1099
				}
1100
			};
1101
		}
1102
1103
		private static IColumnInfoProvider getInfoProvider(
1104
				final TestData[] colData) {
1105
			return new IColumnInfoProvider() {
1106
1107
				public boolean isColumnVisible(Object columnObj) {
1108
					return ((TestData) columnObj).visibility;
1109
				}
1110
1111
				public boolean isColumnResizable(Object columnObj) {
1112
					return ((TestData) columnObj).resizable;
1113
				}
1114
1115
				public boolean isColumnMovable(Object columnObj) {
1116
					return ((TestData) columnObj).movable;
1117
				}
1118
1119
				public int getColumnWidth(Object columnObj) {
1120
					return ((TestData) columnObj).width;
1121
				}
1122
1123
				public int getColumnIndex(Object columnObj) {
1124
					return ((TestData) columnObj).newIndex;
1125
				}
1126
			};
1127
		}
1128
1129
		private static TestData[] genData(int count) {
1130
			String[] cols = new String[count];
1131
			for (int i = 0; i < cols.length; i++) {
1132
				cols[i] = new String("Column-" + (i + 1)); //$NON-NLS-1$
1133
			}
1134
			Random random = new Random();
1135
1136
			boolean[] visibility = new boolean[cols.length];
1137
			Arrays.fill(visibility, true);
1138
			int ranInt = random.nextInt() % cols.length;
1139
			for (int i = 0; i < ranInt; i++) {
1140
				visibility[random.nextInt(ranInt)] = false;
1141
			}
1142
1143
			boolean[] resizable = new boolean[cols.length];
1144
			Arrays.fill(resizable, true);
1145
			ranInt = random.nextInt() % cols.length;
1146
			for (int i = 0; i < ranInt; i++) {
1147
				resizable[random.nextInt(ranInt)] = false;
1148
			}
1149
1150
			boolean[] movable = new boolean[cols.length];
1151
			Arrays.fill(movable, true);
1152
			ranInt = random.nextInt() % cols.length;
1153
			for (int i = 0; i < ranInt; i++) {
1154
				movable[random.nextInt(ranInt)] = false;
1155
			}
1156
1157
			int[] widths = new int[cols.length];
1158
			Arrays.fill(widths, 100);
1159
			return TestData.generateColumnsData(cols, visibility, resizable,
1160
					movable, widths);
1161
		}
1162
1163
		public static TestData[] generateColumnsData(Object[] keys,
1164
				boolean[] visibility, boolean[] resizable, boolean[] movable,
1165
				int[] widths) {
1166
			TestData[] colData = new TestData[keys.length];
1167
			int m = 0, n = 0;
1168
			for (int i = 0; i < colData.length; i++) {
1169
				TestData data = new TestData(keys[i], i);
1170
				data.visibility = visibility[i];
1171
				data.resizable = resizable[i];
1172
				data.movable = movable[i];
1173
				data.width = widths[i];
1174
				if (data.visibility) {
1175
					data.newIndex = m++;
1176
				} else {
1177
					data.newIndex = n++;
1178
				}
1179
				colData[i] = data;
1180
			}
1181
			return colData;
1182
		}
1183
1184
		/**
1185
		 * Demo
1186
		 * 
1187
		 * @param args
1188
		 */
1189
		public static void main(String[] args) {
1190
			Display display = new Display();
1191
			final Shell shell = new Shell(display);
1192
			shell.setLayout(new FillLayout());
1193
			ViewerColumnsDialog dialog = getColumnsDialog(shell, genData(100));
1194
			dialog.open();
1195
			shell.dispose();
1196
			while (!shell.isDisposed()) {
1197
				if (!display.readAndDispatch()) {
1198
					display.sleep();
1199
				}
1200
			}
1201
			display.dispose();
1202
1203
		}
1204
1205
	}
1206
1207
	// //////////////////////////////////////////////////////////////////////////////////
1208
}
(-)src/org/eclipse/ui/views/markers/MarkerField.java (-1 / +1 lines)
Lines 255-261 Link Here
255
	 */
255
	 */
256
	public void update(ViewerCell cell) {
256
	public void update(ViewerCell cell) {
257
		cell.setText(getValue((MarkerItem) cell.getElement()));
257
		cell.setText(getValue((MarkerItem) cell.getElement()));
258
258
		cell.setImage(null);
259
	}
259
	}
260
260
261
}
261
}
(-)src/org/eclipse/ui/views/markers/internal/MarkerMessages.java (+1 lines)
Lines 219-224 Link Here
219
	public static String MarkerPreferences_VisibleColumnsTitle;
219
	public static String MarkerPreferences_VisibleColumnsTitle;
220
	public static String MarkerPreferences_HiddenColumnsTitle;
220
	public static String MarkerPreferences_HiddenColumnsTitle;
221
	public static String MarkerPreferences_AtLeastOneVisibleColumn;
221
	public static String MarkerPreferences_AtLeastOneVisibleColumn;
222
	public static String MarkerPreferences_ZeroOrBlankValueCanBeUsedToDisableTheLimit;
222
223
223
	public static String ProblemFilterDialog_System_Filters_Title;
224
	public static String ProblemFilterDialog_System_Filters_Title;
224
	public static String ProblemFilterDialog_All_Problems;
225
	public static String ProblemFilterDialog_All_Problems;
(-)src/org/eclipse/ui/views/markers/internal/messages.properties (-2 / +3 lines)
Lines 197-208 Link Here
197
MarkerPreferences_DialogTitle = Preferences
197
MarkerPreferences_DialogTitle = Preferences
198
MarkerPreferences_MarkerLimits = Use marker &limits
198
MarkerPreferences_MarkerLimits = Use marker &limits
199
MarkerPreferences_VisibleItems = Limit visible &items per group to:
199
MarkerPreferences_VisibleItems = Limit visible &items per group to:
200
MarkerPreferences_MoveLeft = <<
200
MarkerPreferences_MoveLeft = &<<
201
MarkerPreferences_MoveRight = >>
201
MarkerPreferences_MoveRight = &>>
202
MarkerPreferences_ColumnGroupTitle = Hide/Show Columns
202
MarkerPreferences_ColumnGroupTitle = Hide/Show Columns
203
MarkerPreferences_VisibleColumnsTitle = &Show
203
MarkerPreferences_VisibleColumnsTitle = &Show
204
MarkerPreferences_HiddenColumnsTitle = &Hide
204
MarkerPreferences_HiddenColumnsTitle = &Hide
205
MarkerPreferences_AtLeastOneVisibleColumn = There must be at least one visible column.
205
MarkerPreferences_AtLeastOneVisibleColumn = There must be at least one visible column.
206
MarkerPreferences_ZeroOrBlankValueCanBeUsedToDisableTheLimit = Please enter a positive number (zero or blank can be used to disable the limit).
206
207
207
ProblemFilterDialog_System_Filters_Title = System filte&rs:
208
ProblemFilterDialog_System_Filters_Title = System filte&rs:
208
ProblemFilterDialog_All_Problems = Enabled for all problems
209
ProblemFilterDialog_All_Problems = Enabled for all problems

Return to bug 231081