View | Details | Raw Unified | Return to bug 120602
Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+1 lines)
Lines 1161-1166 Link Here
1161
	public static String CVSHistoryPage_CompareModeToggleAction;
1161
	public static String CVSHistoryPage_CompareModeToggleAction;
1162
	public static String CVSHistoryPage_FilterHistoryTooltip;
1162
	public static String CVSHistoryPage_FilterHistoryTooltip;
1163
	public static String CVSHistoryPage_OpenAction;
1163
	public static String CVSHistoryPage_OpenAction;
1164
	public static String CVSHistoryPage_OpenWithMenu;
1164
	public static String CVSHistoryPage_GroupByDate;
1165
	public static String CVSHistoryPage_GroupByDate;
1165
	public static String CVSHistoryPage_Today;
1166
	public static String CVSHistoryPage_Today;
1166
	public static String CVSHistoryPage_Yesterday;
1167
	public static String CVSHistoryPage_Yesterday;
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+1 lines)
Lines 1086-1091 Link Here
1086
CVSHistoryTableProvider_base=<base>
1086
CVSHistoryTableProvider_base=<base>
1087
CVSHistoryPage_LocalModeAction=Local Mode
1087
CVSHistoryPage_LocalModeAction=Local Mode
1088
CVSHistoryPage_OpenAction=&Open
1088
CVSHistoryPage_OpenAction=&Open
1089
CVSHistoryPage_OpenWithMenu=Open &With
1089
CVSHistoryPage_GroupByDate=Group Revisions by Date
1090
CVSHistoryPage_GroupByDate=Group Revisions by Date
1090
CVSHistoryPage_Today=Today
1091
CVSHistoryPage_Today=Today
1091
CVSHistoryPage_Yesterday=Yesterday
1092
CVSHistoryPage_Yesterday=Yesterday
(-)src/org/eclipse/team/internal/ccvs/ui/CVSHistoryPage.java (-2 / +16 lines)
Lines 61-68 Link Here
61
import org.eclipse.team.internal.core.history.LocalFileRevision;
61
import org.eclipse.team.internal.core.history.LocalFileRevision;
62
import org.eclipse.team.internal.ui.TeamUIMessages;
62
import org.eclipse.team.internal.ui.TeamUIMessages;
63
import org.eclipse.team.internal.ui.Utils;
63
import org.eclipse.team.internal.ui.Utils;
64
import org.eclipse.team.internal.ui.actions.CompareRevisionAction;
64
import org.eclipse.team.internal.ui.actions.*;
65
import org.eclipse.team.internal.ui.actions.OpenRevisionAction;
66
import org.eclipse.team.internal.ui.history.*;
65
import org.eclipse.team.internal.ui.history.*;
67
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
66
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
68
import org.eclipse.team.ui.history.*;
67
import org.eclipse.team.ui.history.*;
Lines 101-106 Link Here
101
100
102
	/* private */CompareRevisionAction compareAction;
101
	/* private */CompareRevisionAction compareAction;
103
	/* private */OpenRevisionAction openAction;
102
	/* private */OpenRevisionAction openAction;
103
	private OpenWithMenu openWithMenu;
104
	
104
	
105
	private CVSHistoryFilterAction  cvsHistoryFilter;
105
	private CVSHistoryFilterAction  cvsHistoryFilter;
106
	private IAction toggleTextAction;
106
	private IAction toggleTextAction;
Lines 529-534 Link Here
529
			}
529
			}
530
		});
530
		});
531
		
531
		
532
		// Add 'Open With...'  sub-menu
533
		openWithMenu = new OpenWithMenu(this);
534
		treeViewer.getTree().addSelectionListener(new SelectionAdapter(){
535
			public void widgetSelected(SelectionEvent e) {
536
				openWithMenu.selectionChanged((IStructuredSelection) treeViewer.getSelection());
537
			}
538
		});
539
		
532
		treeViewer.addOpenListener(new IOpenListener() {
540
		treeViewer.addOpenListener(new IOpenListener() {
533
			public void open(OpenEvent e) {
541
			public void open(OpenEvent e) {
534
				if (getSite() != null) {
542
				if (getSite() != null) {
Lines 839-844 Link Here
839
		
847
		
840
		if (file != null && !parentSite.isModal()){
848
		if (file != null && !parentSite.isModal()){
841
			manager.add(openAction);
849
			manager.add(openAction);
850
			
851
			MenuManager openWithSubmenu = new MenuManager(
852
					CVSUIMessages.CVSHistoryPage_OpenWithMenu);
853
			openWithSubmenu.add(openWithMenu);
854
			manager.add(openWithSubmenu);
855
			
842
			manager.add(compareAction);
856
			manager.add(compareAction);
843
			manager.add(new Separator("openCompare")); //$NON-NLS-1$
857
			manager.add(new Separator("openCompare")); //$NON-NLS-1$
844
		}
858
		}
(-)src/org/eclipse/team/internal/ui/messages.properties (+5 lines)
Lines 454-459 Link Here
454
LocalHistoryPage_openRevision=Open Revision
454
LocalHistoryPage_openRevision=Open Revision
455
LocalHistoryPage_CompareAction=&Compare
455
LocalHistoryPage_CompareAction=&Compare
456
LocalHistoryPage_OpenAction=&Open
456
LocalHistoryPage_OpenAction=&Open
457
LocalHistoryPage_OpenWithMenu=Open &With
458
LocalHistoryPage_OpenWithMenu_Other=Other...
459
LocalHistoryPage_OpenWithMenu_OtherDialogDescription=Choose the editor for opening {0}:
460
LocalHistoryPage_OpenWithMenu_DefaultEditorDescription=&Default Editor
461
LocalHistoryPage_OpenEditorError=A problem occurred while opening the editor
457
LocalHistoryPage_0=Local History ({0})
462
LocalHistoryPage_0=Local History ({0})
458
LocalHistoryPage_1=Workspace File
463
LocalHistoryPage_1=Workspace File
459
LocalHistoryPage_GetContents=Get Contents
464
LocalHistoryPage_GetContents=Get Contents
(-)src/org/eclipse/team/internal/ui/TeamUIMessages.java (+10 lines)
Lines 159-164 Link Here
159
	public static String LocalHistoryPage_NoRevisionsFound;
159
	public static String LocalHistoryPage_NoRevisionsFound;
160
160
161
	public static String LocalHistoryPage_OpenAction;
161
	public static String LocalHistoryPage_OpenAction;
162
	
163
	public static String LocalHistoryPage_OpenWithMenu;
164
	
165
	public static String LocalHistoryPage_OpenWithMenu_Other;
166
	
167
	public static String LocalHistoryPage_OpenWithMenu_OtherDialogDescription;
168
	
169
	public static String LocalHistoryPage_OpenWithMenu_DefaultEditorDescription;
170
	
171
	public static String LocalHistoryPage_OpenEditorError;
162
172
163
	public static String LocalHistoryPage_OverwriteMessage;
173
	public static String LocalHistoryPage_OverwriteMessage;
164
174
(-)src/org/eclipse/team/internal/ui/Utils.java (-5 / +29 lines)
Lines 1069-1095 Link Here
1069
		}
1069
		}
1070
	}
1070
	}
1071
	
1071
	
1072
	public static IEditorPart openEditor(IWorkbenchPage page, FileRevisionEditorInput editorInput) throws PartInitException {
1072
	public static IEditorPart openEditor(IWorkbenchPage page,
1073
			FileRevisionEditorInput editorInput) throws PartInitException {
1073
		String id = getEditorId(editorInput);
1074
		String id = getEditorId(editorInput);
1075
		return openEditor(page, editorInput, id);
1076
	}
1077
1078
	public static IEditorPart openEditor(IWorkbenchPage page,
1079
			FileRevisionEditorInput editorInput, String editorId)
1080
			throws PartInitException {
1074
		try {
1081
		try {
1075
			IEditorPart part= page.openEditor(editorInput, id, OpenStrategy.activateOnOpen());
1082
			IEditorPart part = page.openEditor(editorInput, editorId,
1083
					OpenStrategy.activateOnOpen());
1076
			// See bug 90582 for the reasons behind this discouraged access
1084
			// See bug 90582 for the reasons behind this discouraged access
1077
			if (part instanceof ErrorEditorPart) {
1085
			if (part instanceof ErrorEditorPart) {
1078
				page.closeEditor(part, false);
1086
				page.closeEditor(part, false);
1079
				part = null;
1087
				part = null;
1080
			}
1088
			}
1081
			if (part == null) {
1089
			if (part == null) {
1082
				throw new PartInitException(NLS.bind(TeamUIMessages.Utils_17, id));
1090
				throw new PartInitException(NLS.bind(TeamUIMessages.Utils_17,
1091
						editorId));
1083
			}
1092
			}
1084
			return part;
1093
			return part;
1085
		} catch (PartInitException e) {
1094
		} catch (PartInitException e) {
1086
			if (id.equals("org.eclipse.ui.DefaultTextEditor")) { //$NON-NLS-1$
1095
			if (editorId.equals("org.eclipse.ui.DefaultTextEditor")) { //$NON-NLS-1$
1087
				throw e;
1096
				throw e;
1088
			} else {
1097
			} else {
1089
				return page.openEditor(editorInput,"org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
1098
				return page.openEditor(editorInput,
1099
						"org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
1090
			}
1100
			}
1091
		}
1101
		}
1092
	}
1102
	}
1103
	
1104
	public static IEditorDescriptor[] getEditors(IFileRevision revision) {
1105
		IEditorRegistry registry = PlatformUI.getWorkbench()
1106
				.getEditorRegistry();
1107
		// so far only the revision name is used to find editors
1108
		return registry.getEditors(revision.getName()/*, getContentType(revision) */);
1109
	}
1110
	
1111
	public static IEditorDescriptor getDefaultEditor(IFileRevision revision) {
1112
		// so far only the revision name is used to find the default editor
1113
		IEditorRegistry registry = PlatformUI.getWorkbench()
1114
				.getEditorRegistry();
1115
		return registry.getDefaultEditor(revision.getName()/*, getContentType(revision) */);
1116
	}
1093
1117
1094
	private static String getEditorId(FileRevisionEditorInput editorInput) {
1118
	private static String getEditorId(FileRevisionEditorInput editorInput) {
1095
		String id = getEditorId(editorInput.getFileRevision().getName(), getContentType(editorInput));
1119
		String id = getEditorId(editorInput.getFileRevision().getName(), getContentType(editorInput));
(-)src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java (-2 / +16 lines)
Lines 42-49 Link Here
42
import org.eclipse.team.internal.core.history.LocalFileHistory;
42
import org.eclipse.team.internal.core.history.LocalFileHistory;
43
import org.eclipse.team.internal.core.history.LocalFileRevision;
43
import org.eclipse.team.internal.core.history.LocalFileRevision;
44
import org.eclipse.team.internal.ui.*;
44
import org.eclipse.team.internal.ui.*;
45
import org.eclipse.team.internal.ui.actions.CompareRevisionAction;
45
import org.eclipse.team.internal.ui.actions.*;
46
import org.eclipse.team.internal.ui.actions.OpenRevisionAction;
47
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
46
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
48
import org.eclipse.team.ui.history.*;
47
import org.eclipse.team.ui.history.*;
49
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
48
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
Lines 85-90 Link Here
85
	private Action getContentsAction;
84
	private Action getContentsAction;
86
	private CompareRevisionAction compareAction;
85
	private CompareRevisionAction compareAction;
87
	private OpenRevisionAction openAction;
86
	private OpenRevisionAction openAction;
87
	private OpenWithMenu openWithMenu;
88
	
88
	
89
	private HistoryResourceListener resourceListener;
89
	private HistoryResourceListener resourceListener;
90
	
90
	
Lines 393-398 Link Here
393
						openAction.selectionChanged((IStructuredSelection) treeViewer.getSelection());
393
						openAction.selectionChanged((IStructuredSelection) treeViewer.getSelection());
394
					}
394
					}
395
				});
395
				});
396
				
397
				// Add 'Open With...'  sub-menu
398
				openWithMenu = new OpenWithMenu(this);
399
				treeViewer.getTree().addSelectionListener(new SelectionAdapter(){
400
					public void widgetSelected(SelectionEvent e) {
401
						openWithMenu.selectionChanged((IStructuredSelection) treeViewer.getSelection());
402
					}
403
				});
396
			}
404
			}
397
			
405
			
398
			treeViewer.addOpenListener(new IOpenListener() {
406
			treeViewer.addOpenListener(new IOpenListener() {
Lines 479-484 Link Here
479
		if (file != null && !parentSite.isModal()){
487
		if (file != null && !parentSite.isModal()){
480
			if (openAction != null)
488
			if (openAction != null)
481
				manager.add(openAction);
489
				manager.add(openAction);
490
			if (openWithMenu != null) {
491
				MenuManager openWithSubmenu = new MenuManager(
492
						TeamUIMessages.LocalHistoryPage_OpenWithMenu);
493
				openWithSubmenu.add(openWithMenu);
494
				manager.add(openWithSubmenu);
495
			}
482
			if (compareAction != null)
496
			if (compareAction != null)
483
				manager.add(compareAction);
497
				manager.add(compareAction);
484
			if (getContentsAction != null) {
498
			if (getContentsAction != null) {
(-)src/org/eclipse/team/internal/ui/actions/OpenWithMenu.java (+408 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.team.internal.ui.actions;
12
13
import java.util.*;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IStorage;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.jface.action.ContributionItem;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.jface.window.Window;
23
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.widgets.*;
27
import org.eclipse.team.core.history.IFileRevision;
28
import org.eclipse.team.internal.ui.TeamUIMessages;
29
import org.eclipse.team.internal.ui.Utils;
30
import org.eclipse.team.internal.ui.history.AbstractHistoryCategory;
31
import org.eclipse.team.internal.ui.history.FileRevisionEditorInput;
32
import org.eclipse.team.ui.history.HistoryPage;
33
import org.eclipse.ui.*;
34
import org.eclipse.ui.dialogs.EditorSelectionDialog;
35
import org.eclipse.ui.internal.WorkbenchPage;
36
import org.eclipse.ui.part.FileEditorInput;
37
import org.eclipse.ui.statushandlers.*;
38
39
import com.ibm.icu.text.Collator;
40
41
/**
42
 * A menu for opening file revisions in the workbench.
43
 * <p>
44
 * An <code>OpenWithMenu</code> is used to populate a menu with "Open With"
45
 * actions. One action is added for each editor which is applicable to the
46
 * selected file. If the user selects one of these items, the corresponding
47
 * editor is opened on the file.
48
 * </p>
49
 */
50
public class OpenWithMenu extends ContributionItem {
51
52
	private IStructuredSelection selection;
53
54
	private HistoryPage page;
55
56
	private IEditorRegistry registry = PlatformUI.getWorkbench()
57
			.getEditorRegistry();
58
59
	private static Hashtable imageCache = new Hashtable(11);
60
61
	/**
62
	 * The id of this action.
63
	 */
64
	public static final String ID = PlatformUI.PLUGIN_ID + ".OpenWithMenu";//$NON-NLS-1$
65
66
	/**
67
	 * Match both the input and id, so that different types of editor can be
68
	 * opened on the same input.
69
	 */
70
	private static final int MATCH_BOTH = IWorkbenchPage.MATCH_INPUT
71
			| IWorkbenchPage.MATCH_ID;
72
73
	/*
74
	 * Compares the labels from two IEditorDescriptor objects
75
	 */
76
	private static final Comparator comparer = new Comparator() {
77
		private Collator collator = Collator.getInstance();
78
79
		public int compare(Object arg0, Object arg1) {
80
			String s1 = ((IEditorDescriptor) arg0).getLabel();
81
			String s2 = ((IEditorDescriptor) arg1).getLabel();
82
			return collator.compare(s1, s2);
83
		}
84
	};
85
86
	/**
87
	 * Constructs a new instance of <code>OpenWithMenu</code>.
88
	 * 
89
	 * @param page
90
	 *            the page where the editor is opened if an item within the menu
91
	 *            is selected
92
	 */
93
	public OpenWithMenu(HistoryPage page) {
94
		super(ID);
95
		this.page = page;
96
	}
97
98
	/**
99
	 * Returns an image to show for the corresponding editor descriptor.
100
	 * 
101
	 * @param editorDesc
102
	 *            the editor descriptor, or null for the system editor
103
	 * @return the image or null
104
	 */
105
	private Image getImage(IEditorDescriptor editorDesc) {
106
		ImageDescriptor imageDesc = getImageDescriptor(editorDesc);
107
		if (imageDesc == null) {
108
			return null;
109
		}
110
		Image image = (Image) imageCache.get(imageDesc);
111
		if (image == null) {
112
			image = imageDesc.createImage();
113
			imageCache.put(imageDesc, image);
114
		}
115
		return image;
116
	}
117
118
	/**
119
	 * Returns the image descriptor for the given editor descriptor, or null if
120
	 * it has no image.
121
	 */
122
	private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) {
123
		ImageDescriptor imageDesc = null;
124
		if (editorDesc == null) {
125
			imageDesc = registry
126
					.getImageDescriptor(getFileRevision().getName());
127
			// TODO: is this case valid, and if so, what are the implications
128
			// for content-type editor bindings?
129
		} else {
130
			imageDesc = editorDesc.getImageDescriptor();
131
		}
132
		if (imageDesc == null) {
133
			if (editorDesc.getId().equals(
134
					IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID)) {
135
				imageDesc = registry
136
						.getSystemExternalEditorImageDescriptor(getFileRevision()
137
								.getName());
138
			}
139
		}
140
		return imageDesc;
141
	}
142
143
	/**
144
	 * Creates the menu item for the editor descriptor.
145
	 * 
146
	 * @param menu
147
	 *            the menu to add the item to
148
	 * @param descriptor
149
	 *            the editor descriptor, or null for the system editor
150
	 * @param preferredEditor
151
	 *            the descriptor of the preferred editor, or <code>null</code>
152
	 */
153
	private MenuItem createMenuItem(Menu menu,
154
			final IEditorDescriptor descriptor,
155
			final IEditorDescriptor preferredEditor) {
156
		// XXX: Would be better to use bold here, but SWT does not support it.
157
		final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
158
		boolean isPreferred = preferredEditor != null
159
				&& descriptor.getId().equals(preferredEditor.getId());
160
		menuItem.setSelection(isPreferred);
161
		menuItem.setText(descriptor.getLabel());
162
		Image image = getImage(descriptor);
163
		if (image != null) {
164
			menuItem.setImage(image);
165
		}
166
		Listener listener = new Listener() {
167
			public void handleEvent(Event event) {
168
				switch (event.type) {
169
				case SWT.Selection:
170
					if (menuItem.getSelection()) {
171
						openEditor(descriptor, false);
172
					}
173
					break;
174
				}
175
			}
176
		};
177
		menuItem.addListener(SWT.Selection, listener);
178
		return menuItem;
179
	}
180
181
	/**
182
	 * Creates the Other... menu item
183
	 * 
184
	 * @param menu
185
	 *            the menu to add the item to
186
	 */
187
	private void createOtherMenuItem(final Menu menu) {
188
		final IFileRevision fileResource = getFileRevision();
189
		if (fileResource == null) {
190
			return;
191
		}
192
		new MenuItem(menu, SWT.SEPARATOR);
193
		final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
194
		menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_Other);
195
		Listener listener = new Listener() {
196
			public void handleEvent(Event event) {
197
				switch (event.type) {
198
				case SWT.Selection:
199
					EditorSelectionDialog dialog = new EditorSelectionDialog(
200
							menu.getShell());
201
					dialog
202
							.setMessage(NLS
203
									.bind(
204
											TeamUIMessages.LocalHistoryPage_OpenWithMenu_OtherDialogDescription,
205
											fileResource.getName()));
206
					if (dialog.open() == Window.OK) {
207
						IEditorDescriptor editor = dialog.getSelectedEditor();
208
						if (editor != null) {
209
							openEditor(editor, editor.isOpenExternal());
210
						}
211
					}
212
					break;
213
				}
214
			}
215
		};
216
		menuItem.addListener(SWT.Selection, listener);
217
	}
218
219
	public void fill(Menu menu, int index) {
220
		final IFileRevision fileRevision = getFileRevision();
221
		if (fileRevision == null) {
222
			return;
223
		}
224
225
		IEditorDescriptor defaultTextEditor = registry
226
				.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
227
		IEditorDescriptor preferredEditor = Utils
228
				.getDefaultEditor(fileRevision);
229
230
		Object[] editors = Utils.getEditors(fileRevision);
231
		Collections.sort(Arrays.asList(editors), comparer);
232
		boolean defaultFound = false;
233
234
		// Check that we don't add it twice. This is possible
235
		// if the same editor goes to two mappings.
236
		ArrayList alreadyMapped = new ArrayList();
237
238
		for (int i = 0; i < editors.length; i++) {
239
			IEditorDescriptor editor = (IEditorDescriptor) editors[i];
240
			if (!alreadyMapped.contains(editor)) {
241
				createMenuItem(menu, editor, preferredEditor);
242
				if (defaultTextEditor != null
243
						&& editor.getId().equals(defaultTextEditor.getId())) {
244
					defaultFound = true;
245
				}
246
				alreadyMapped.add(editor);
247
			}
248
		}
249
250
		// Only add a separator if there is something to separate
251
		if (editors.length > 0) {
252
			new MenuItem(menu, SWT.SEPARATOR);
253
		}
254
255
		// Add default editor. Check it if it is saved as the preference.
256
		if (!defaultFound && defaultTextEditor != null) {
257
			createMenuItem(menu, defaultTextEditor, preferredEditor);
258
		}
259
260
		// TODO : We might perhaps enable inplace and system external editors menu items
261
		/*// Add system editor
262
		IEditorDescriptor descriptor = registry
263
				.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
264
		final MenuItem systemEditorMenuItem = createMenuItem(menu, descriptor,
265
				preferredEditor);
266
		systemEditorMenuItem.setEnabled(false);
267
268
		// Add system in-place editor
269
		descriptor = registry
270
				.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
271
272
		final MenuItem inPlaceEditorMenuItem = (descriptor != null) ? createMenuItem(
273
				menu, descriptor, preferredEditor)
274
				: null;
275
		if (inPlaceEditorMenuItem != null)
276
			inPlaceEditorMenuItem.setEnabled(false);
277
278
		Job job = new Job("updateOpenWithMenu") { //$NON-NLS-1$
279
			protected IStatus run(IProgressMonitor monitor) {
280
				try {
281
					final boolean isFile = fileRevision.getStorage(monitor) instanceof IFile;
282
					Display.getDefault().asyncExec(new Runnable() {
283
						public void run() {
284
							if (inPlaceEditorMenuItem != null
285
									&& !inPlaceEditorMenuItem.isDisposed())
286
								inPlaceEditorMenuItem.setEnabled(isFile);
287
							if (!systemEditorMenuItem.isDisposed())
288
								systemEditorMenuItem.setEnabled(isFile);
289
						}
290
					});
291
					return Status.OK_STATUS;
292
				} catch (CoreException e) {
293
					return new Status(IStatus.WARNING, TeamUIPlugin.ID, null, e);
294
				}
295
			};
296
		};
297
		job.setSystem(true);
298
		job.schedule();*/
299
300
		createDefaultMenuItem(menu, fileRevision);
301
302
		// add Other... menu item
303
		createOtherMenuItem(menu);
304
	}
305
306
	public void createDefaultMenuItem(Menu menu, final IFileRevision revision) {
307
		final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
308
		menuItem.setSelection(Utils.getDefaultEditor(revision) == null);
309
		menuItem
310
				.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_DefaultEditorDescription);
311
312
		Listener listener = new Listener() {
313
			public void handleEvent(Event event) {
314
				switch (event.type) {
315
				case SWT.Selection:
316
					if (menuItem.getSelection()) {
317
						openEditor(Utils.getDefaultEditor(revision), false);
318
					}
319
					break;
320
				}
321
			}
322
		};
323
324
		menuItem.addListener(SWT.Selection, listener);
325
	}
326
327
	/**
328
	 * Opens the given editor on the selected file revision.
329
	 */
330
	protected void openEditor(IEditorDescriptor editorDescriptor,
331
			boolean openUsingDescriptor) {
332
		IFileRevision fileRevision = getFileRevision();
333
		if (fileRevision == null) {
334
			return;
335
		}
336
		try {
337
			IProgressMonitor monitor = new NullProgressMonitor();
338
			IStorage storage = fileRevision.getStorage(monitor);
339
			boolean isFile = storage instanceof IFile;
340
341
			if (openUsingDescriptor) {
342
				// discouraged access to open system editors
343
				((WorkbenchPage) (page.getSite().getPage()))
344
						.openEditorFromDescriptor(isFile ? new FileEditorInput(
345
								(IFile) storage)
346
								: (IEditorInput) FileRevisionEditorInput
347
										.createEditorInputFor(fileRevision,
348
												monitor), editorDescriptor,
349
								true, null);
350
			} else {
351
				String editorId = editorDescriptor == null ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID
352
						: editorDescriptor.getId();
353
				page.getSite().getPage().openEditor(
354
						isFile ? new FileEditorInput((IFile) storage)
355
								: (IEditorInput) FileRevisionEditorInput
356
										.createEditorInputFor(fileRevision,
357
												monitor), editorId, true,
358
						MATCH_BOTH);
359
			}
360
		} catch (PartInitException e) {
361
			StatusAdapter sA = new StatusAdapter(e.getStatus());
362
			sA.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
363
					TeamUIMessages.LocalHistoryPage_OpenEditorError);
364
			StatusManager.getManager().handle(sA, StatusManager.SHOW);
365
		} catch (CoreException e) {
366
			StatusAdapter sA = new StatusAdapter(e.getStatus());
367
			sA.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
368
					TeamUIMessages.LocalHistoryPage_OpenEditorError);
369
			StatusManager.getManager().handle(sA, StatusManager.LOG);
370
		}
371
	}
372
373
	private IFileRevision getFileRevision() {
374
		IStructuredSelection structSel = selection;
375
376
		IFileRevision revision = null;
377
378
		if (structSel == null)
379
			return null;
380
381
		Object[] objArray = structSel.toArray();
382
383
		for (int i = 0; i < objArray.length; i++) {
384
			Object tempRevision = objArray[i];
385
			// If not a revision, don't try opening
386
			if (tempRevision instanceof AbstractHistoryCategory)
387
				continue;
388
389
			revision = (IFileRevision) tempRevision;
390
		}
391
		return revision;
392
	}
393
394
	/*
395
	 * (non-Javadoc) Returns whether this menu is dynamic.
396
	 */
397
	public boolean isDynamic() {
398
		return true;
399
	}
400
401
	public void selectionChanged(IStructuredSelection selection) {
402
		if (selection instanceof IStructuredSelection) {
403
			this.selection = selection;
404
		} else {
405
			this.selection = StructuredSelection.EMPTY;
406
		}
407
	}
408
}

Return to bug 120602