Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 173095 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/dialogs/EditorSelectionDialog.java (-105 / +143 lines)
Lines 24-35 Link Here
24
import org.eclipse.jface.viewers.ArrayContentProvider;
24
import org.eclipse.jface.viewers.ArrayContentProvider;
25
import org.eclipse.jface.viewers.ColumnLabelProvider;
25
import org.eclipse.jface.viewers.ColumnLabelProvider;
26
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
26
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
27
import org.eclipse.jface.viewers.DoubleClickEvent;
28
import org.eclipse.jface.viewers.IDoubleClickListener;
27
import org.eclipse.jface.viewers.ILabelDecorator;
29
import org.eclipse.jface.viewers.ILabelDecorator;
28
import org.eclipse.jface.viewers.TableViewer;
30
import org.eclipse.jface.viewers.TableViewer;
29
import org.eclipse.osgi.util.TextProcessor;
31
import org.eclipse.osgi.util.TextProcessor;
30
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.graphics.Cursor;
33
import org.eclipse.swt.graphics.Cursor;
32
import org.eclipse.swt.graphics.Font;
33
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.layout.GridLayout;
Lines 41-46 Link Here
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Listener;
43
import org.eclipse.swt.widgets.Listener;
43
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.swt.widgets.TabFolder;
46
import org.eclipse.swt.widgets.TabItem;
44
import org.eclipse.swt.widgets.Table;
47
import org.eclipse.swt.widgets.Table;
45
import org.eclipse.swt.widgets.TableItem;
48
import org.eclipse.swt.widgets.TableItem;
46
import org.eclipse.ui.IEditorDescriptor;
49
import org.eclipse.ui.IEditorDescriptor;
Lines 63-75 Link Here
63
public final class EditorSelectionDialog extends Dialog {
66
public final class EditorSelectionDialog extends Dialog {
64
	private EditorDescriptor selectedEditor;
67
	private EditorDescriptor selectedEditor;
65
68
66
	private Button externalButton;
69
	/**
70
	 * The tab folder that holds the tabs for the listing of internal and
71
	 * external editors.
72
	 */
73
	private TabFolder editorsFolder;
67
74
68
	private Table editorTable;
75
	/**
76
	 * The table that renders the list of internal editors to the user.
77
	 */
78
	private Table internalEditorsTable;
69
79
70
	private Button browseExternalEditorsButton;
80
	/**
81
	 * The table that renders the list of external editors to the user.
82
	 */
83
	private Table externalEditorsTable;
71
84
72
	private Button internalButton;
85
	/**
86
	 * The button for browsing to an external application for opening a file.
87
	 */
88
	private Button browseExternalEditorsButton;
73
89
74
	private Button okButton;
90
	private Button okButton;
75
91
Lines 88-94 Link Here
88
104
89
	private ResourceManager resourceManager;
105
	private ResourceManager resourceManager;
90
106
91
	private TableViewer editorTableViewer;
107
	private TableViewer internalEditorsTableViewer;
108
109
	private TableViewer externalEditorsTableViewer;
110
111
	private ColumnLabelProvider labelProvider;
92
112
93
	private static final String[] Executable_Filters;
113
	private static final String[] Executable_Filters;
94
114
Lines 154-207 Link Here
154
	 * @return the dialog area control
174
	 * @return the dialog area control
155
	 */
175
	 */
156
	protected Control createDialogArea(Composite parent) {
176
	protected Control createDialogArea(Composite parent) {
157
		Font font = parent.getFont();
158
		// create main group
177
		// create main group
159
		Composite contents = (Composite) super.createDialogArea(parent);
178
		Composite contents = (Composite) super.createDialogArea(parent);
160
		((GridLayout) contents.getLayout()).numColumns = 2;
161
179
162
		// begin the layout
180
		// begin the layout
163
		Label textLabel = new Label(contents, SWT.NONE);
181
		Label textLabel = new Label(contents, SWT.NONE);
164
		textLabel.setText(message);
182
		textLabel.setText(message);
165
		GridData data = new GridData();
183
166
		data.horizontalSpan = 2;
184
		editorsFolder = new TabFolder(contents, SWT.TOP);
167
		textLabel.setLayoutData(data);
185
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
168
		textLabel.setFont(font);
169
170
		internalButton = new Button(contents, SWT.RADIO | SWT.LEFT);
171
		internalButton.setText(WorkbenchMessages.EditorSelection_internal);
172
		internalButton.addListener(SWT.Selection, listener);
173
		data = new GridData();
174
		data.horizontalSpan = 1;
175
		internalButton.setLayoutData(data);
176
		internalButton.setFont(font);
177
178
		externalButton = new Button(contents, SWT.RADIO | SWT.LEFT);
179
		externalButton.setText(WorkbenchMessages.EditorSelection_external);
180
		externalButton.addListener(SWT.Selection, listener);
181
		data = new GridData();
182
		data.horizontalSpan = 1;
183
		externalButton.setLayoutData(data);
184
		externalButton.setFont(font);
185
186
		editorTable = new Table(contents, SWT.SINGLE | SWT.BORDER);
187
		editorTable.addListener(SWT.Selection, listener);
188
		editorTable.addListener(SWT.DefaultSelection, listener);
189
		editorTable.addListener(SWT.MouseDoubleClick, listener);
190
		data = new GridData();
191
		data.widthHint = convertHorizontalDLUsToPixels(TABLE_WIDTH);
186
		data.widthHint = convertHorizontalDLUsToPixels(TABLE_WIDTH);
192
		data.horizontalAlignment = GridData.FILL;
187
		editorsFolder.setLayoutData(data);
193
		data.grabExcessHorizontalSpace = true;
188
194
		data.verticalAlignment = GridData.FILL;
195
		data.grabExcessVerticalSpace = true;
196
		data.horizontalSpan = 2;
197
		editorTable.setLayoutData(data);
198
		editorTable.setFont(font);
199
		data.heightHint = editorTable.getItemHeight() * 12;
200
		editorTableViewer = new TableViewer(editorTable);
201
		editorTableViewer.setContentProvider(ArrayContentProvider.getInstance());
202
		final ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager()
189
		final ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager()
203
				.getLabelDecorator(ContributingPluginDecorator.ID);
190
				.getLabelDecorator(ContributingPluginDecorator.ID);
204
		editorTableViewer.setLabelProvider(new ColumnLabelProvider() {
191
		labelProvider = new ColumnLabelProvider() {
205
			public String getText(Object element) {
192
			public String getText(Object element) {
206
				IEditorDescriptor d = (IEditorDescriptor) element;
193
				IEditorDescriptor d = (IEditorDescriptor) element;
207
				return TextProcessor.process(d.getLabel(), "."); //$NON-NLS-1$
194
				return TextProcessor.process(d.getLabel(), "."); //$NON-NLS-1$
Lines 216-254 Link Here
216
				if (decorator == null || !(element instanceof EditorDescriptor)) {
203
				if (decorator == null || !(element instanceof EditorDescriptor)) {
217
					return null;
204
					return null;
218
				}
205
				}
206
219
				EditorDescriptor d = (EditorDescriptor) element;
207
				EditorDescriptor d = (EditorDescriptor) element;
220
				return decorator.decorateText(getText(element), d.getConfigurationElement());
208
				return decorator.decorateText(getText(element), d.getConfigurationElement());
221
			}
209
			}
222
		});
210
		};
211
223
		if (decorator != null) {
212
		if (decorator != null) {
224
			ColumnViewerToolTipSupport.enableFor(editorTableViewer);
213
			ColumnViewerToolTipSupport.enableFor(internalEditorsTableViewer);
214
			ColumnViewerToolTipSupport.enableFor(externalEditorsTableViewer);
225
		}
215
		}
226
216
227
		browseExternalEditorsButton = new Button(contents, SWT.PUSH);
217
		createInternalEditorsTable();
228
		browseExternalEditorsButton
218
		createExternalEditorsTable();
229
				.setText(WorkbenchMessages.EditorSelection_browse);
230
		browseExternalEditorsButton.addListener(SWT.Selection, listener);
231
		data = new GridData();
232
		int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
233
		data.widthHint = Math.max(widthHint, browseExternalEditorsButton
234
				.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
235
		browseExternalEditorsButton.setLayoutData(data);
236
		browseExternalEditorsButton.setFont(font);
237
219
238
		restoreWidgetValues(); // Place buttons to the appropriate state
220
		restoreWidgetValues(); // Place buttons to the appropriate state
239
221
240
		fillEditorTable();
222
		internalEditorsTableViewer.setInput(getInternalEditors());
223
		handleTabSelection();
241
224
242
		updateEnableState();
225
		editorsFolder.addListener(SWT.Selection, listener);
226
		editorsFolder.addListener(SWT.DefaultSelection, listener);
227
228
		Dialog.applyDialogFont(contents);
229
230
		((GridData) internalEditorsTable.getLayoutData()).heightHint = internalEditorsTable
231
				.getItemHeight() * 12;
232
		((GridData) externalEditorsTable.getLayoutData()).heightHint = externalEditorsTable
233
				.getItemHeight() * 12;
243
234
244
		return contents;
235
		return contents;
245
	}
236
	}
246
237
247
	protected void fillEditorTable() {
238
	private void createInternalEditorsTable() {
248
		if (internalButton.getSelection()) {
239
		TabItem internalEditorsItem = new TabItem(editorsFolder, SWT.LEAD);
249
			editorTableViewer.setInput(getInternalEditors());
240
		internalEditorsItem.setText(WorkbenchMessages.EditorSelection_internal);
241
242
		Composite internalComposite = new Composite(editorsFolder, SWT.NONE);
243
		GridLayout layout = new GridLayout(1, false);
244
		layout.marginWidth = 0;
245
		layout.marginHeight = 0;
246
		internalComposite.setLayout(layout);
247
248
		internalEditorsTable = new Table(internalComposite, SWT.SINGLE | SWT.BORDER);
249
		internalEditorsTable.addListener(SWT.Selection, listener);
250
		internalEditorsTable.addListener(SWT.DefaultSelection, listener);
251
		internalEditorsTable.addListener(SWT.MouseDoubleClick, listener);
252
		internalEditorsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
253
254
		internalEditorsTableViewer = new TableViewer(internalEditorsTable);
255
		internalEditorsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
256
		internalEditorsTableViewer.setLabelProvider(labelProvider);
257
		internalEditorsTableViewer.addDoubleClickListener(new IDoubleClickListener() {
258
			public void doubleClick(DoubleClickEvent event) {
259
				handleDoubleClickEvent();
260
			}
261
		});
262
263
		internalEditorsItem.setControl(internalComposite);
264
	}
265
266
	private void createExternalEditorsTable() {
267
		Composite externalComposite = new Composite(editorsFolder, SWT.NONE);
268
		GridLayout layout = new GridLayout(1, false);
269
		layout.marginWidth = 0;
270
		layout.marginHeight = 0;
271
		externalComposite.setLayout(layout);
272
273
		TabItem externalEditorsItem = new TabItem(editorsFolder, SWT.LEAD);
274
		externalEditorsItem.setText(WorkbenchMessages.EditorSelection_external);
275
276
		externalEditorsTable = new Table(externalComposite, SWT.SINGLE | SWT.BORDER);
277
		externalEditorsTable.addListener(SWT.Selection, listener);
278
		externalEditorsTable.addListener(SWT.DefaultSelection, listener);
279
		externalEditorsTable.addListener(SWT.MouseDoubleClick, listener);
280
		externalEditorsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
281
282
		externalEditorsTableViewer = new TableViewer(externalEditorsTable);
283
		externalEditorsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
284
		externalEditorsTableViewer.setLabelProvider(labelProvider);
285
		externalEditorsTableViewer.addDoubleClickListener(new IDoubleClickListener() {
286
			public void doubleClick(DoubleClickEvent event) {
287
				handleDoubleClickEvent();
288
			}
289
		});
290
291
		browseExternalEditorsButton = new Button(externalComposite, SWT.PUSH);
292
		browseExternalEditorsButton.setText(WorkbenchMessages.EditorSelection_browse);
293
		browseExternalEditorsButton.addListener(SWT.Selection, listener);
294
295
		externalEditorsItem.setControl(externalComposite);
296
	}
297
298
	private void handleTabSelection() {
299
		if (editorsFolder.getSelectionIndex() == 0) {
300
			internalEditorsTable.setFocus();
250
		} else {
301
		} else {
251
			editorTableViewer.setInput(getExternalEditors());
302
			externalEditorsTableViewer.setInput(getExternalEditors());
303
			externalEditorsTable.setFocus();
252
		}
304
		}
253
	}
305
	}
254
306
Lines 360-366 Link Here
360
		if (result != null) {
412
		if (result != null) {
361
			EditorDescriptor editor = EditorDescriptor.createForProgram(result);
413
			EditorDescriptor editor = EditorDescriptor.createForProgram(result);
362
			// pretend we had obtained it from the list of os registered editors
414
			// pretend we had obtained it from the list of os registered editors
363
			TableItem ti = new TableItem(editorTable, SWT.NULL);
415
			TableItem ti = new TableItem(externalEditorsTable, SWT.NULL);
364
			ti.setData(editor);
416
			ti.setData(editor);
365
			ti.setText(editor.getLabel());
417
			ti.setText(editor.getLabel());
366
			Image image = editor.getImageDescriptor().createImage();
418
			Image image = editor.getImageDescriptor().createImage();
Lines 368-376 Link Here
368
420
369
			// need to pass an array to setSelection -- 1FSKYVO: SWT:ALL -
421
			// need to pass an array to setSelection -- 1FSKYVO: SWT:ALL -
370
			// inconsistent setSelection api on Table
422
			// inconsistent setSelection api on Table
371
			editorTable.setSelection(new TableItem[] { ti });
423
			externalEditorsTable.setSelection(ti);
372
			editorTable.showSelection();
424
			externalEditorsTable.showSelection();
373
			editorTable.setFocus();
425
			externalEditorsTable.setFocus();
374
			selectedEditor = editor;
426
			selectedEditor = editor;
375
427
376
			/*
428
			/*
Lines 399-406 Link Here
399
	protected void restoreWidgetValues() {
451
	protected void restoreWidgetValues() {
400
		IDialogSettings settings = getDialogSettings();
452
		IDialogSettings settings = getDialogSettings();
401
		boolean wasExternal = settings.getBoolean(STORE_ID_INTERNAL_EXTERNAL);
453
		boolean wasExternal = settings.getBoolean(STORE_ID_INTERNAL_EXTERNAL);
402
		internalButton.setSelection(!wasExternal);
454
		editorsFolder.setSelection(wasExternal ? 1 : 0);
403
		externalButton.setSelection(wasExternal);
404
	}
455
	}
405
456
406
	/**
457
	/**
Lines 410-417 Link Here
410
	protected void saveWidgetValues() {
461
	protected void saveWidgetValues() {
411
		IDialogSettings settings = getDialogSettings();
462
		IDialogSettings settings = getDialogSettings();
412
		// record whether use was viewing internal or external editors
463
		// record whether use was viewing internal or external editors
413
		settings
464
		settings.put(STORE_ID_INTERNAL_EXTERNAL, editorsFolder.getSelectionIndex() == 1);
414
				.put(STORE_ID_INTERNAL_EXTERNAL, !internalButton.getSelection());
415
	}
465
	}
416
466
417
	/**
467
	/**
Lines 434-453 Link Here
434
		editorsToFilter = editors;
484
		editorsToFilter = editors;
435
	}
485
	}
436
486
437
	/**
438
	 * Update enabled state.
439
	 */
440
	protected void updateEnableState() {
441
		boolean enableExternal = externalButton.getSelection();
442
		browseExternalEditorsButton.setEnabled(enableExternal);
443
		updateOkButton();
444
	}
445
446
	protected void createButtonsForButtonBar(Composite parent) {
487
	protected void createButtonsForButtonBar(Composite parent) {
447
		okButton = createButton(parent, IDialogConstants.OK_ID,
488
		super.createButtonsForButtonBar(parent);
448
				IDialogConstants.OK_LABEL, true);
489
		okButton = getButton(IDialogConstants.OK_ID);
449
		createButton(parent, IDialogConstants.CANCEL_ID,
450
				IDialogConstants.CANCEL_LABEL, false);
451
		// initially there is no selection so OK button should not be enabled
490
		// initially there is no selection so OK button should not be enabled
452
		okButton.setEnabled(false);
491
		okButton.setEnabled(false);
453
492
Lines 458-473 Link Here
458
	 */
497
	 */
459
	protected void updateOkButton() {
498
	protected void updateOkButton() {
460
		// Buttons are null during dialog creation
499
		// Buttons are null during dialog creation
461
		if (okButton == null) {
500
		if (okButton != null) {
462
			return;
501
			if (editorsFolder.getSelectionIndex() == 0) {
463
		}
502
				okButton.setEnabled(internalEditorsTable.getSelectionIndex() != -1);
464
		// If there is no selection, do not enable OK button
503
			} else {
465
		if (editorTable.getSelectionCount() == 0) {
504
				okButton.setEnabled(externalEditorsTable.getSelectionIndex() != -1);
466
			okButton.setEnabled(false);
505
			}
467
			return;
468
		}
506
		}
469
		// At this point, there is a selection
470
		okButton.setEnabled(selectedEditor != null);
471
	}
507
	}
472
508
473
	private class DialogListener implements Listener {
509
	private class DialogListener implements Listener {
Lines 478-501 Link Here
478
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
514
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
479
		 */
515
		 */
480
		public void handleEvent(Event event) {
516
		public void handleEvent(Event event) {
481
			if (event.type == SWT.MouseDoubleClick) {
517
			if (event.widget == editorsFolder) {
482
				handleDoubleClickEvent();
518
				handleTabSelection();
483
				return;
484
			}
485
			if (event.widget == externalButton) {
486
				fillEditorTable();
487
			} else if (event.widget == browseExternalEditorsButton) {
519
			} else if (event.widget == browseExternalEditorsButton) {
488
				promptForExternalEditor();
520
				promptForExternalEditor();
489
			} else if (event.widget == editorTable) {
521
			} else if (event.widget == internalEditorsTable) {
490
				if (editorTable.getSelectionIndex() != -1) {
522
				if (internalEditorsTable.getSelectionIndex() != -1) {
491
					selectedEditor = (EditorDescriptor) editorTable
523
					selectedEditor = (EditorDescriptor) internalEditorsTable.getSelection()[0]
492
							.getSelection()[0].getData();
524
							.getData();
525
				} else {
526
					selectedEditor = null;
527
				}
528
			} else if (event.widget == externalEditorsTable) {
529
				if (externalEditorsTable.getSelectionIndex() != -1) {
530
					selectedEditor = (EditorDescriptor) externalEditorsTable.getSelection()[0]
531
							.getData();
493
				} else {
532
				} else {
494
					selectedEditor = null;
533
					selectedEditor = null;
495
					okButton.setEnabled(false);
496
				}
534
				}
497
			}
535
			}
498
			updateEnableState();
536
			updateOkButton();
499
		}
537
		}
500
538
501
	}
539
	}

Return to bug 173095