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

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/navigator/CommonNavigatorManager.java (-42 / +47 lines)
Lines 35-45 Link Here
35
import org.eclipse.ui.IWorkbenchActionConstants;
35
import org.eclipse.ui.IWorkbenchActionConstants;
36
import org.eclipse.ui.actions.ActionContext;
36
import org.eclipse.ui.actions.ActionContext;
37
import org.eclipse.ui.actions.RetargetAction;
37
import org.eclipse.ui.actions.RetargetAction;
38
import org.eclipse.ui.navigator.CommonNavigator;
39
import org.eclipse.ui.navigator.CommonViewer;
38
import org.eclipse.ui.navigator.CommonViewer;
40
import org.eclipse.ui.navigator.CommonViewerSiteFactory;
41
import org.eclipse.ui.navigator.ICommonActionConstants;
39
import org.eclipse.ui.navigator.ICommonActionConstants;
42
import org.eclipse.ui.navigator.ICommonViewerSite;
40
import org.eclipse.ui.navigator.ICommonNavigator;
43
import org.eclipse.ui.navigator.IDescriptionProvider;
41
import org.eclipse.ui.navigator.IDescriptionProvider;
44
import org.eclipse.ui.navigator.INavigatorContentService;
42
import org.eclipse.ui.navigator.INavigatorContentService;
45
import org.eclipse.ui.navigator.NavigatorActionService;
43
import org.eclipse.ui.navigator.NavigatorActionService;
Lines 62-68 Link Here
62
	// delay for updating the action bars (in ms)
60
	// delay for updating the action bars (in ms)
63
	private static final long DELAY = 200;
61
	private static final long DELAY = 200;
64
62
65
	private final CommonNavigator commonNavigator;
63
	private final ICommonNavigator commonNavigator;
66
64
67
	private final INavigatorContentService contentService;
65
	private final INavigatorContentService contentService;
68
66
Lines 75-94 Link Here
75
	private final ILabelProvider labelProvider;
73
	private final ILabelProvider labelProvider;
76
74
77
	private UpdateActionBarsJob updateActionBars;
75
	private UpdateActionBarsJob updateActionBars;
78
	
76
79
	private ISelectionChangedListener statusBarListener = new ISelectionChangedListener() {
77
	private ISelectionChangedListener statusBarListener = new ISelectionChangedListener() {
80
78
81
		public void selectionChanged(SelectionChangedEvent anEvent) { 
79
		public void selectionChanged(SelectionChangedEvent anEvent) {
82
			updateStatusBar(anEvent.getSelection());
80
			updateStatusBar(anEvent.getSelection());
83
		}
81
		}
84
		
82
85
	};
83
	};
86
	
84
87
	private class UpdateActionBarsJob extends UIJob {
85
	private class UpdateActionBarsJob extends UIJob {
88
		public UpdateActionBarsJob(String label) {
86
		public UpdateActionBarsJob(String label) {
89
			super(label);
87
			super(label);
90
		}
88
		}
91
		  
89
92
		public IStatus runInUIThread(IProgressMonitor monitor) {
90
		public IStatus runInUIThread(IProgressMonitor monitor) {
93
91
94
			SafeRunner.run(new ISafeRunnable() {
92
			SafeRunner.run(new ISafeRunnable() {
Lines 98-120 Link Here
98
				 * @see org.eclipse.core.runtime.ISafeRunnable#run()
96
				 * @see org.eclipse.core.runtime.ISafeRunnable#run()
99
				 */
97
				 */
100
				public void run() throws Exception {
98
				public void run() throws Exception {
101
					if(commonNavigator.getCommonViewer().getInput() != null) {
99
					if (commonNavigator.getCommonViewer().getInput() != null) {
102
						IStructuredSelection selection = new StructuredSelection(commonNavigator.getCommonViewer().getInput());
100
						IStructuredSelection selection = new StructuredSelection(
101
								commonNavigator.getCommonViewer().getInput());
103
						actionService.setContext(new ActionContext(selection));
102
						actionService.setContext(new ActionContext(selection));
104
						actionService.fillActionBars(commonNavigator.getViewSite().getActionBars());
103
						actionService.fillActionBars(commonNavigator
104
								.getActionBars());
105
					}
105
					}
106
				}
106
				}
107
107
				/*
108
				/*
108
				 * (non-Javadoc)
109
				 * (non-Javadoc)
109
				 * 
110
				 * 
110
				 * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
111
				 * @see
112
				 * org.eclipse.core.runtime.ISafeRunnable#handleException(java
113
				 * .lang.Throwable)
111
				 */
114
				 */
112
				public void handleException(Throwable exception) {
115
				public void handleException(Throwable exception) {
113
					NavigatorPlugin.logError(0, exception.getMessage(), exception);
116
					NavigatorPlugin.logError(0, exception.getMessage(),
117
							exception);
114
				}
118
				}
115
			});
119
			});
116
			return Status.OK_STATUS;
120
			return Status.OK_STATUS;
117
		} 
121
		}
118
	}
122
	}
119
123
120
	/**
124
	/**
Lines 127-136 Link Here
127
	 *            The CommonNavigator managed by this class. Requires a non-null
131
	 *            The CommonNavigator managed by this class. Requires a non-null
128
	 *            value.
132
	 *            value.
129
	 */
133
	 */
130
	public CommonNavigatorManager(CommonNavigator aNavigator) {
134
	public CommonNavigatorManager(ICommonNavigator aNavigator) {
131
		this(aNavigator, null);
135
		this(aNavigator, null);
132
	}
136
	}
133
	
137
134
	/**
138
	/**
135
	 * <p>
139
	 * <p>
136
	 * Adds listeners to aNavigator to listen for selection changes and respond
140
	 * Adds listeners to aNavigator to listen for selection changes and respond
Lines 140-193 Link Here
140
	 * @param aNavigator
144
	 * @param aNavigator
141
	 *            The CommonNavigator managed by this class. Requires a non-null
145
	 *            The CommonNavigator managed by this class. Requires a non-null
142
	 *            value.
146
	 *            value.
143
	 * @param aMemento a memento for restoring state, or <code>null</code>
147
	 * @param aMemento
148
	 *            a memento for restoring state, or <code>null</code>
144
	 */
149
	 */
145
	public CommonNavigatorManager(CommonNavigator aNavigator, IMemento aMemento) {
150
	public CommonNavigatorManager(ICommonNavigator aNavigator, IMemento aMemento) {
146
		super();
151
		super();
147
		commonNavigator = aNavigator;
152
		commonNavigator = aNavigator;
148
		contentService = commonNavigator.getNavigatorContentService();
153
		contentService = commonNavigator.getNavigatorContentService();
149
		statusLineManager = commonNavigator.getViewSite().getActionBars()
154
		statusLineManager = commonNavigator.getActionBars()
150
				.getStatusLineManager();
155
				.getStatusLineManager();
151
		commonDescriptionProvider = contentService
156
		commonDescriptionProvider = contentService
152
				.createCommonDescriptionProvider();
157
				.createCommonDescriptionProvider();
153
		labelProvider = (ILabelProvider) commonNavigator.getCommonViewer()
158
		labelProvider = (ILabelProvider) commonNavigator.getCommonViewer()
154
				.getLabelProvider();
159
				.getLabelProvider();
155
	
160
156
		init(aMemento);
161
		init(aMemento);
157
	}
162
	}
158
163
159
160
	private void init(IMemento memento) {
164
	private void init(IMemento memento) {
161
		
165
162
		updateActionBars = new UpdateActionBarsJob(commonNavigator.getTitle());
166
		updateActionBars = new UpdateActionBarsJob(commonNavigator.getTitle());
163
		
167
164
		CommonViewer commonViewer = commonNavigator.getCommonViewer();
168
		CommonViewer commonViewer = commonNavigator.getCommonViewer();
165
		commonViewer.addSelectionChangedListener(this);
169
		commonViewer.addSelectionChangedListener(this);
166
		commonViewer.addPostSelectionChangedListener(statusBarListener);
170
		commonViewer.addPostSelectionChangedListener(statusBarListener);
167
		updateStatusBar(commonViewer.getSelection());
171
		updateStatusBar(commonViewer.getSelection());
168
172
169
		ICommonViewerSite commonViewerSite = CommonViewerSiteFactory
173
		actionService = new NavigatorActionService(commonNavigator
170
				.createCommonViewerSite(commonNavigator.getViewSite());
174
				.getCommonViewerSite(), commonViewer, commonViewer
171
		actionService = new NavigatorActionService(commonViewerSite,
175
				.getNavigatorContentService());
172
				commonViewer, commonViewer.getNavigatorContentService()); 
173
176
174
		final RetargetAction openAction = new RetargetAction(
177
		final RetargetAction openAction = new RetargetAction(
175
				ICommonActionConstants.OPEN,
178
				ICommonActionConstants.OPEN,
176
				CommonNavigatorMessages.Open_action_label);
179
				CommonNavigatorMessages.Open_action_label);
177
		commonNavigator.getViewSite().getPage().addPartListener(openAction);
180
		commonNavigator.getWorkbenchSite().getPage()
181
				.addPartListener(openAction);
178
		openAction.setActionDefinitionId(ICommonActionConstants.OPEN);
182
		openAction.setActionDefinitionId(ICommonActionConstants.OPEN);
179
183
180
		commonNavigator.getCommonViewer().addOpenListener(new IOpenListener() {
184
		commonNavigator.getCommonViewer().addOpenListener(new IOpenListener() {
181
			public void open(OpenEvent event) {
185
			public void open(OpenEvent event) {
182
				actionService.setContext(new ActionContext(commonNavigator.getCommonViewer().getSelection()));		
186
				actionService.setContext(new ActionContext(commonNavigator
183
				actionService.fillActionBars(commonNavigator.getViewSite().getActionBars());							
187
						.getCommonViewer().getSelection()));
188
				actionService.fillActionBars(commonNavigator.getActionBars());
184
				openAction.run();
189
				openAction.run();
185
			}
190
			}
186
		});  
191
		});
187
192
188
		if(memento != null)
193
		if (memento != null)
189
			restoreState(memento);
194
			restoreState(memento);
190
		
195
191
		initContextMenu();
196
		initContextMenu();
192
		initViewMenu();
197
		initViewMenu();
193
198
Lines 195-206 Link Here
195
200
196
	/**
201
	/**
197
	 * <p>
202
	 * <p>
198
	 * Called by {@link CommonNavigator} when the View Part is disposed.
203
	 * Called by {@link ICommonNavigator} when the View Part is disposed.
199
	 * 
204
	 * 
200
	 */
205
	 */
201
	public void dispose() {
206
	public void dispose() {
202
		commonNavigator.getCommonViewer().removeSelectionChangedListener(this);
207
		commonNavigator.getCommonViewer().removeSelectionChangedListener(this);
203
		commonNavigator.getCommonViewer().removeSelectionChangedListener(statusBarListener);
208
		commonNavigator.getCommonViewer().removeSelectionChangedListener(
209
				statusBarListener);
204
		actionService.dispose();
210
		actionService.dispose();
205
	}
211
	}
206
212
Lines 217-224 Link Here
217
			IStructuredSelection structuredSelection = (IStructuredSelection) anEvent
223
			IStructuredSelection structuredSelection = (IStructuredSelection) anEvent
218
					.getSelection();
224
					.getSelection();
219
			actionService.setContext(new ActionContext(structuredSelection));
225
			actionService.setContext(new ActionContext(structuredSelection));
220
			actionService.fillActionBars(commonNavigator.getViewSite()
226
			actionService.fillActionBars(commonNavigator.getActionBars());
221
					.getActionBars());
222
		}
227
		}
223
	}
228
	}
224
229
Lines 229-235 Link Here
229
	 */
234
	 */
230
	public void restoreState(IMemento aMemento) {
235
	public void restoreState(IMemento aMemento) {
231
		actionService.restoreState(aMemento);
236
		actionService.restoreState(aMemento);
232
		 
237
233
	}
238
	}
234
239
235
	/**
240
	/**
Lines 284-297 Link Here
284
	}
289
	}
285
290
286
	protected void initViewMenu() {
291
	protected void initViewMenu() {
287
		IMenuManager viewMenu = commonNavigator.getViewSite().getActionBars()
292
		IMenuManager viewMenu = commonNavigator.getActionBars()
288
				.getMenuManager();
293
				.getMenuManager();
289
		viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
294
		viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
290
		viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS
295
		viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS
291
				+ "-end"));//$NON-NLS-1$	
296
				+ "-end"));//$NON-NLS-1$	
292
		
297
293
		updateActionBars.schedule(DELAY);
298
		updateActionBars.schedule(DELAY);
294
		
299
295
	}
300
	}
296
301
297
	/**
302
	/**
(-)src/org/eclipse/ui/internal/navigator/CommonNavigatorActionGroup.java (-44 / +27 lines)
Lines 10-29 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.navigator;
11
package org.eclipse.ui.internal.navigator;
12
12
13
import org.eclipse.jface.action.IMenuManager;
14
import org.eclipse.jface.commands.ActionHandler;
15
import org.eclipse.jface.resource.ImageDescriptor;
13
import org.eclipse.jface.resource.ImageDescriptor;
16
import org.eclipse.ui.IActionBars;
14
import org.eclipse.ui.IActionBars;
17
import org.eclipse.ui.IWorkbenchActionConstants;
18
import org.eclipse.ui.actions.ActionGroup;
15
import org.eclipse.ui.actions.ActionGroup;
19
import org.eclipse.ui.handlers.CollapseAllHandler;
16
import org.eclipse.ui.handlers.CollapseAllHandler;
20
import org.eclipse.ui.handlers.IHandlerService;
17
import org.eclipse.ui.handlers.IHandlerService;
21
import org.eclipse.ui.internal.navigator.actions.CollapseAllAction;
18
import org.eclipse.ui.internal.navigator.actions.CollapseAllAction;
22
import org.eclipse.ui.internal.navigator.actions.LinkEditorAction;
23
import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
24
import org.eclipse.ui.internal.navigator.filters.FilterActionGroup;
19
import org.eclipse.ui.internal.navigator.filters.FilterActionGroup;
25
import org.eclipse.ui.navigator.CommonNavigator;
26
import org.eclipse.ui.navigator.CommonViewer;
20
import org.eclipse.ui.navigator.CommonViewer;
21
import org.eclipse.ui.navigator.ICommonNavigator;
27
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
22
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
28
23
29
/**
24
/**
Lines 33-49 Link Here
33
 */
28
 */
34
public class CommonNavigatorActionGroup extends ActionGroup {
29
public class CommonNavigatorActionGroup extends ActionGroup {
35
30
36
	private LinkEditorAction toggleLinkingAction;
37
38
	private CollapseAllAction collapseAllAction;
31
	private CollapseAllAction collapseAllAction;
39
32
40
	private FilterActionGroup filterGroup;
33
	private FilterActionGroup filterGroup;
41
34
42
	private final CommonViewer commonViewer;
35
	private final CommonViewer commonViewer;
43
36
44
	private CommonNavigator commonNavigator;
37
	private ICommonNavigator commonNavigator;
45
46
	private final LinkHelperService linkHelperService;
47
38
48
	private CollapseAllHandler collapseAllHandler;
39
	private CollapseAllHandler collapseAllHandler;
49
40
Lines 52-68 Link Here
52
	 * Filters.
43
	 * Filters.
53
	 * 
44
	 * 
54
	 * @param aNavigator
45
	 * @param aNavigator
55
	 *            The IViewPart for this action group
46
	 *            The ICommonNavigator for this action group
56
	 * @param aViewer
47
	 * @param aViewer
57
	 *            The Viewer for this action group
48
	 *            The Viewer for this action group
58
	 * @param linkHelperService the link service helper
59
	 */
49
	 */
60
	public CommonNavigatorActionGroup(CommonNavigator aNavigator,
50
	public CommonNavigatorActionGroup(ICommonNavigator aNavigator,
61
			CommonViewer aViewer, LinkHelperService linkHelperService) {
51
			CommonViewer aViewer) {
62
		super();
52
		super();
63
		commonNavigator = aNavigator;
53
		commonNavigator = aNavigator;
64
		commonViewer = aViewer;
54
		commonViewer = aViewer;
65
		this.linkHelperService = linkHelperService;
66
		makeActions();
55
		makeActions();
67
	}
56
	}
68
57
Lines 75-99 Link Here
75
	}
64
	}
76
65
77
	/**
66
	/**
67
	 * @return The ICommonNavigator for this action group
68
	 */
69
	protected ICommonNavigator getCommonNavigator() {
70
		return commonNavigator;
71
	}
72
73
	/**
74
	 * @return The viewer for this action group
75
	 */
76
	protected CommonViewer getCommonViewer() {
77
		return commonViewer;
78
	}
79
80
	/**
78
	 * 
81
	 * 
79
	 */
82
	 */
80
	private void makeActions() {
83
	private void makeActions() {
81
		IHandlerService service = (IHandlerService) commonNavigator.getSite()
84
		IHandlerService service = (IHandlerService) commonNavigator
82
				.getService(IHandlerService.class);
85
				.getWorkbenchSite().getService(IHandlerService.class);
83
86
84
		INavigatorViewerDescriptor viewerDescriptor = commonViewer
87
		INavigatorViewerDescriptor viewerDescriptor = commonViewer
85
				.getNavigatorContentService().getViewerDescriptor();
88
				.getNavigatorContentService().getViewerDescriptor();
86
		boolean hideLinkWithEditorAction = viewerDescriptor
87
				.getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION);
88
		if (!hideLinkWithEditorAction) {
89
			toggleLinkingAction = new LinkEditorAction(commonNavigator,
90
					commonViewer, linkHelperService);
91
			ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$
92
			toggleLinkingAction.setImageDescriptor(syncIcon);
93
			toggleLinkingAction.setHoverImageDescriptor(syncIcon);
94
			service.activateHandler(toggleLinkingAction.getActionDefinitionId(),
95
					new ActionHandler(toggleLinkingAction));
96
		}
97
89
98
		boolean hideCollapseAllAction = viewerDescriptor
90
		boolean hideCollapseAllAction = viewerDescriptor
99
				.getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_COLLAPSE_ALL_ACTION);
91
				.getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_COLLAPSE_ALL_ACTION);
Lines 103-109 Link Here
103
			collapseAllAction.setImageDescriptor(collapseAllIcon);
95
			collapseAllAction.setImageDescriptor(collapseAllIcon);
104
			collapseAllAction.setHoverImageDescriptor(collapseAllIcon);
96
			collapseAllAction.setHoverImageDescriptor(collapseAllIcon);
105
			collapseAllHandler = new CollapseAllHandler(commonViewer);
97
			collapseAllHandler = new CollapseAllHandler(commonViewer);
106
			service.activateHandler(CollapseAllHandler.COMMAND_ID, collapseAllHandler);
98
			service.activateHandler(CollapseAllHandler.COMMAND_ID,
99
					collapseAllHandler);
107
		}
100
		}
108
101
109
		filterGroup = new FilterActionGroup(commonViewer);
102
		filterGroup = new FilterActionGroup(commonViewer);
Lines 113-122 Link Here
113
	/*
106
	/*
114
	 * (non-Javadoc)
107
	 * (non-Javadoc)
115
	 * 
108
	 * 
116
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
109
	 * @see
110
	 * org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars
111
	 * )
117
	 */
112
	 */
118
	public void fillActionBars(IActionBars theActionBars) {
113
	public void fillActionBars(IActionBars theActionBars) {
119
		IMenuManager menu = theActionBars.getMenuManager();
120
114
121
		filterGroup.fillActionBars(theActionBars);
115
		filterGroup.fillActionBars(theActionBars);
122
116
Lines 124-137 Link Here
124
			theActionBars.getToolBarManager().add(collapseAllAction);
118
			theActionBars.getToolBarManager().add(collapseAllAction);
125
		}
119
		}
126
120
127
		if (toggleLinkingAction != null) {
128
			menu
129
					.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS
130
							+ "-end", toggleLinkingAction); //$NON-NLS-1$
131
132
			theActionBars.getToolBarManager().add(toggleLinkingAction);
133
		}
134
135
		theActionBars.updateActionBars();
121
		theActionBars.updateActionBars();
136
	}
122
	}
137
123
Lines 142-151 Link Here
142
	 */
128
	 */
143
	public void dispose() {
129
	public void dispose() {
144
		super.dispose();
130
		super.dispose();
145
		if (toggleLinkingAction != null) {
131
		if (collapseAllHandler != null) {
146
			toggleLinkingAction.dispose();
147
		}
148
		if (collapseAllHandler!=null) {
149
			collapseAllHandler.dispose();
132
			collapseAllHandler.dispose();
150
		}
133
		}
151
	}
134
	}
(-)src/org/eclipse/ui/internal/navigator/messages.properties (-3 / +4 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2005, 2008 IBM Corporation and others.
2
# Copyright (c) 2005, 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 20-26 Link Here
20
Navigator_statusLineMultiSelect={0} items selected
20
Navigator_statusLineMultiSelect={0} items selected
21
SelectFiltersActionDelegate_1=Select and deselect filters to apply to the content in the tree
21
SelectFiltersActionDelegate_1=Select and deselect filters to apply to the content in the tree
22
CommonFilterSelectionDialog_Select_the_available_extensions=Select the available extensions to show (unchecked extensions will not display content)\:
22
CommonFilterSelectionDialog_Select_the_available_extensions=Select the available extensions to show (unchecked extensions will not display content)\:
23
SelectFiltersActionDelegate_0=&Customize View...
23
SelectFiltersActionDelegate_0=Customize View...
24
CollapseAllActionDelegate_0=Collapse All 
24
CollapseAllActionDelegate_0=Collapse All 
25
Too_many_elements_Warning=Too many elements of type\: {0} in extension "{1}" defined in bundle "{2}".
25
Too_many_elements_Warning=Too many elements of type\: {0} in extension "{1}" defined in bundle "{2}".
26
NewProjectAction_text=P&roject...
26
NewProjectAction_text=P&roject...
Lines 33-39 Link Here
33
CommonFilterSelectionDialog_Available_Filters=Filters
33
CommonFilterSelectionDialog_Available_Filters=Filters
34
StructuredViewerManager_0=Refresh Common Viewer Tree
34
StructuredViewerManager_0=Refresh Common Viewer Tree
35
LinkEditorActionDelegate_1=Link open editors with content in the Navigator
35
LinkEditorActionDelegate_1=Link open editors with content in the Navigator
36
LinkEditorActionDelegate_0=&Link Editor
36
LinkEditorActionDelegate_0=Link Editor
37
Copy=Copy 
37
Copy=Copy 
38
Cut=Cut
38
Cut=Cut
39
NavigatorViewerDescriptor_Popup_Menu_Overridden=Warning\: popupMenuId of "{0}" was overridden\: old value \= "{1}", new value \= "{2}".
39
NavigatorViewerDescriptor_Popup_Menu_Overridden=Warning\: popupMenuId of "{0}" was overridden\: old value \= "{1}", new value \= "{2}".
Lines 43-45 Link Here
43
CommonSorterDescriptorManager_A_navigatorContent_extesnion_in_0_=A navigatorContent extesnion in {0} is missing an id.
43
CommonSorterDescriptorManager_A_navigatorContent_extesnion_in_0_=A navigatorContent extesnion in {0} is missing an id.
44
FilterDialogSelectionListener_Enable_the_0_filter_=Enable the {0} filter.
44
FilterDialogSelectionListener_Enable_the_0_filter_=Enable the {0} filter.
45
NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_=Error: no label provider for {0}
45
NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_=Error: no label provider for {0}
46
CommonNavigatorOutline_DefaultTitle=Common Navigator Outline
(-)src/org/eclipse/ui/internal/navigator/CommonNavigatorMessages.java (-3 / +5 lines)
Lines 15-23 Link Here
15
/**
15
/**
16
 * 
16
 * 
17
 * <p>
17
 * <p>
18
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
18
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
19
 * part of a work in progress. There is a guarantee neither that this API will
19
 * of a work in progress. There is a guarantee neither that this API will work
20
 * work nor that it will remain the same. Please do not use this API without
20
 * nor that it will remain the same. Please do not use this API without
21
 * consulting with the Platform/UI team.
21
 * consulting with the Platform/UI team.
22
 * </p>
22
 * </p>
23
 * 
23
 * 
Lines 123-128 Link Here
123
123
124
	/** */
124
	/** */
125
	public static String NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_;
125
	public static String NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_;
126
	/** */
127
	public static String CommonNavigatorOutline_DefaultTitle;
126
128
127
	static {
129
	static {
128
		NLS.initializeMessages(BUNDLE_NAME, CommonNavigatorMessages.class);
130
		NLS.initializeMessages(BUNDLE_NAME, CommonNavigatorMessages.class);
(-)src/org/eclipse/ui/navigator/CommonNavigator.java (-137 / +151 lines)
Lines 25-47 Link Here
25
import org.eclipse.jface.viewers.ViewerFilter;
25
import org.eclipse.jface.viewers.ViewerFilter;
26
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IMemento;
30
import org.eclipse.ui.IMemento;
30
import org.eclipse.ui.ISaveablePart;
31
import org.eclipse.ui.ISaveablePart;
31
import org.eclipse.ui.ISaveablesLifecycleListener;
32
import org.eclipse.ui.ISaveablesLifecycleListener;
32
import org.eclipse.ui.ISaveablesSource;
33
import org.eclipse.ui.ISaveablesSource;
33
import org.eclipse.ui.IViewSite;
34
import org.eclipse.ui.IViewSite;
35
import org.eclipse.ui.IWorkbenchSite;
34
import org.eclipse.ui.PartInitException;
36
import org.eclipse.ui.PartInitException;
35
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.Saveable;
38
import org.eclipse.ui.Saveable;
37
import org.eclipse.ui.SaveablesLifecycleEvent;
39
import org.eclipse.ui.SaveablesLifecycleEvent;
38
import org.eclipse.ui.actions.ActionGroup;
40
import org.eclipse.ui.actions.ActionGroup;
39
import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup;
40
import org.eclipse.ui.internal.navigator.CommonNavigatorManager;
41
import org.eclipse.ui.internal.navigator.CommonNavigatorManager;
42
import org.eclipse.ui.internal.navigator.CommonNavigatorViewActionGroup;
41
import org.eclipse.ui.internal.navigator.NavigatorContentService;
43
import org.eclipse.ui.internal.navigator.NavigatorContentService;
42
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
44
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
43
import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
45
import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
44
import org.eclipse.ui.part.ISetSelectionTarget;
45
import org.eclipse.ui.part.IShowInTarget;
46
import org.eclipse.ui.part.IShowInTarget;
46
import org.eclipse.ui.part.ShowInContext;
47
import org.eclipse.ui.part.ShowInContext;
47
import org.eclipse.ui.part.ViewPart;
48
import org.eclipse.ui.part.ViewPart;
Lines 50-120 Link Here
50
 * <p>
51
 * <p>
51
 * This class provides the IViewPart for the Common Navigator framework in the
52
 * This class provides the IViewPart for the Common Navigator framework in the
52
 * Eclipse workbench. This class also serves as the backbone for navigational
53
 * Eclipse workbench. This class also serves as the backbone for navigational
53
 * viewers. The following types are used by this class to render the Common
54
 * viewers.
54
 * Navigator:
55
 * <ul>
56
 * <li>
57
 * <p>
58
 * {@link org.eclipse.ui.navigator.CommonViewer}: The viewer that renders the
59
 * extensible tree. Creates and manages the lifecylce of the Navigator Content
60
 * Service (described below).
61
 * </p>
62
 * </li>
63
 * <li>
64
 * <p>
65
 * {@link org.eclipse.ui.navigator.NavigatorActionService}: Manages instances
66
 * of {@link org.eclipse.ui.navigator.CommonActionProvider}s provided by
67
 * individual extensions and content extensions.
68
 * </p>
69
 * </li>
70
 * <li>
71
 * <p>
72
 * {@link org.eclipse.ui.navigator.INavigatorContentService}: Manages instances
73
 * of Navigator Content Extensions. Instances are created as needed, and
74
 * disposed of upon the disposal of the Navigator Content Service.
75
 * </p>
76
 * </li>
77
 * </ul>
78
 * <p>
79
 * Clients are not expected to subclass CommonNavigator. Clients that wish to
80
 * define their own custom extensible navigator view need to specify an instance
81
 * of the <b>org.eclipse.ui.views</b> extension point:
82
 * 
55
 * 
83
 * <pre>
56
 * </p>
84
 *   
85
 *          &lt;extension
86
 *          		point=&quot;org.eclipse.ui.views&quot;&gt;
87
 *          	&lt;view
88
 *          		name=&quot;My Custom View&quot;
89
 *          		icon=&quot;relative/path/to/icon.gif&quot;
90
 *          		category=&quot;org.acme.mycategory&quot;
91
 *          		class=&quot;org.eclipse.ui.navigator.CommonNavigator&quot;
92
 *          		id=&quot;org.acme.MyCustomNavigatorID&quot;&gt;
93
 *          	&lt;/view&gt;
94
 *          &lt;/extension&gt; 
95
 *    
96
 * </pre>
97
 * 
98
 * </p> 
99
 * Clients that wish to extend the view menu provided via the
57
 * Clients that wish to extend the view menu provided via the
100
 * <b>org.eclipse.ui.popupMenu</b>s extension may specify the the <i>popupMenuId</i>
58
 * <b>org.eclipse.ui.popupMenu</b>s extension may specify the the
101
 * specified by <b>org.eclipse.ui.navigator.viewer</b> (or a nested <b>popupMenu</b> element) of their target viewer
59
 * <i>popupMenuId</i> specified by <b>org.eclipse.ui.navigator.viewer</b> (or a
102
 * as their target menu id.
60
 * nested <b>popupMenu</b> element) of their target viewer as their target menu
61
 * id.
103
 * 
62
 * 
104
 * <p>
63
 * <p>
105
 * This class may be instantiated; it is not intended to be subclassed.
64
 * This class may be instantiated; it is not intended to be subclassed.
106
 * </p>
65
 * </p>
66
 * 
107
 * @noextend This class is not intended to be subclassed by clients.
67
 * @noextend This class is not intended to be subclassed by clients.
108
 *  
68
 * 
109
 * @since 3.2
69
 * @since 3.2
110
 */
70
 */
111
public class CommonNavigator extends ViewPart implements ISetSelectionTarget, ISaveablePart, ISaveablesSource, IShowInTarget {
71
public class CommonNavigator extends ViewPart implements ICommonNavigator,
112
 
72
		ISaveablePart, ISaveablesSource, IShowInTarget {
73
113
	private static final Class INAVIGATOR_CONTENT_SERVICE = INavigatorContentService.class;
74
	private static final Class INAVIGATOR_CONTENT_SERVICE = INavigatorContentService.class;
114
	private static final Class COMMON_VIEWER_CLASS = CommonViewer.class;
75
	private static final Class COMMON_VIEWER_CLASS = CommonViewer.class;
115
	private static final Class ISHOW_IN_TARGET_CLASS = IShowInTarget.class;
76
	private static final Class ISHOW_IN_TARGET_CLASS = IShowInTarget.class;
116
	
77
117
	private static final String HELP_CONTEXT =  NavigatorPlugin.PLUGIN_ID + ".common_navigator"; //$NON-NLS-1$
78
	private static final String HELP_CONTEXT = NavigatorPlugin.PLUGIN_ID
79
			+ ".common_navigator"; //$NON-NLS-1$
118
80
119
	/**
81
	/**
120
	 * <p>
82
	 * <p>
Lines 136-142 Link Here
136
	private String LINKING_ENABLED = "CommonNavigator.LINKING_ENABLED"; //$NON-NLS-1$ 
98
	private String LINKING_ENABLED = "CommonNavigator.LINKING_ENABLED"; //$NON-NLS-1$ 
137
99
138
	private LinkHelperService linkService;
100
	private LinkHelperService linkService;
139
	
101
140
	/**
102
	/**
141
	 * 
103
	 * 
142
	 */
104
	 */
Lines 155-184 Link Here
155
	 */
117
	 */
156
	public void createPartControl(Composite aParent) {
118
	public void createPartControl(Composite aParent) {
157
119
158
		commonViewer = createCommonViewer(aParent);	
120
		commonViewer = createCommonViewer(aParent);
159
121
160
		try {
122
		try {
161
			commonViewer.getControl().setRedraw(false);
123
			commonViewer.getControl().setRedraw(false);
162
			
124
163
			INavigatorFilterService filterService = commonViewer
125
			INavigatorFilterService filterService = commonViewer
164
					.getNavigatorContentService().getFilterService();
126
					.getNavigatorContentService().getFilterService();
165
			ViewerFilter[] visibleFilters = filterService.getVisibleFilters(true);
127
			ViewerFilter[] visibleFilters = filterService
128
					.getVisibleFilters(true);
166
			for (int i = 0; i < visibleFilters.length; i++) {
129
			for (int i = 0; i < visibleFilters.length; i++) {
167
				commonViewer.addFilter(visibleFilters[i]);
130
				commonViewer.addFilter(visibleFilters[i]);
168
			}
131
			}
169
	
132
170
			commonViewer.setSorter(new CommonViewerSorter());
133
			commonViewer.setSorter(new CommonViewerSorter());
171
	
134
172
			/*
135
			/*
173
			 * make sure input is set after sorters and filters to avoid unnecessary
136
			 * make sure input is set after sorters and filters to avoid
174
			 * refreshes
137
			 * unnecessary refreshes
175
			 */
138
			 */
176
			commonViewer.setInput(getInitialInput()); 
139
			commonViewer.setInput(getInitialInput());
177
	
140
178
			getSite().setSelectionProvider(commonViewer);
141
			getSite().setSelectionProvider(commonViewer);
179
	
142
180
			updateTitle();
143
			updateTitle();
181
		} finally { 
144
		} finally {
182
			commonViewer.getControl().setRedraw(true);
145
			commonViewer.getControl().setRedraw(true);
183
		}
146
		}
184
147
Lines 188-200 Link Here
188
		 * the CommonNavigatorManager
151
		 * the CommonNavigatorManager
189
		 */
152
		 */
190
		commonManager = createCommonManager();
153
		commonManager = createCommonManager();
191
		if (memento != null) {			
154
		if (memento != null) {
192
			commonViewer.getNavigatorContentService().restoreState(memento);
155
			commonViewer.getNavigatorContentService().restoreState(memento);
193
		}
156
		}
194
157
195
		commonActionGroup = createCommonActionGroup();
158
		commonActionGroup = createCommonActionGroup();
196
		commonActionGroup.fillActionBars(getViewSite().getActionBars());
159
		commonActionGroup.fillActionBars(getViewSite().getActionBars());
197
		
160
198
		ISaveablesLifecycleListener saveablesLifecycleListener = new ISaveablesLifecycleListener() {
161
		ISaveablesLifecycleListener saveablesLifecycleListener = new ISaveablesLifecycleListener() {
199
			ISaveablesLifecycleListener siteSaveablesLifecycleListener = (ISaveablesLifecycleListener) getSite()
162
			ISaveablesLifecycleListener siteSaveablesLifecycleListener = (ISaveablesLifecycleListener) getSite()
200
					.getService(ISaveablesLifecycleListener.class);
163
					.getService(ISaveablesLifecycleListener.class);
Lines 206-222 Link Here
206
				siteSaveablesLifecycleListener.handleLifecycleEvent(event);
169
				siteSaveablesLifecycleListener.handleLifecycleEvent(event);
207
			}
170
			}
208
		};
171
		};
209
		commonViewer.getNavigatorContentService()
172
		commonViewer.getNavigatorContentService().getSaveablesService().init(
210
				.getSaveablesService().init(this, getCommonViewer(),
173
				this, getCommonViewer(), saveablesLifecycleListener);
211
						saveablesLifecycleListener);
174
212
		
175
		commonViewer
213
		commonViewer.addSelectionChangedListener(new ISelectionChangedListener() {
176
				.addSelectionChangedListener(new ISelectionChangedListener() {
214
177
215
			public void selectionChanged(SelectionChangedEvent event) {
178
					public void selectionChanged(SelectionChangedEvent event) {
216
				firePropertyChange(PROP_DIRTY);
179
						firePropertyChange(PROP_DIRTY);
217
			}});
180
					}
218
		
181
				});
219
	      PlatformUI.getWorkbench().getHelpSystem().setHelp(commonViewer.getControl(),  HELP_CONTEXT);
182
183
		PlatformUI.getWorkbench().getHelpSystem().setHelp(
184
				commonViewer.getControl(), HELP_CONTEXT);
220
	}
185
	}
221
186
222
	/**
187
	/**
Lines 235-241 Link Here
235
		if (commonManager != null) {
200
		if (commonManager != null) {
236
			commonManager.dispose();
201
			commonManager.dispose();
237
		}
202
		}
238
		if(commonActionGroup != null) {
203
		if (commonActionGroup != null) {
239
			commonActionGroup.dispose();
204
			commonActionGroup.dispose();
240
		}
205
		}
241
		super.dispose();
206
		super.dispose();
Lines 303-315 Link Here
303
	 */
268
	 */
304
	public void selectReveal(ISelection selection) {
269
	public void selectReveal(ISelection selection) {
305
		if (commonViewer != null) {
270
		if (commonViewer != null) {
306
			if(selection instanceof IStructuredSelection) {
271
			if (selection instanceof IStructuredSelection) {
307
				Object[] newSelection = ((IStructuredSelection)selection).toArray();
272
				Object[] newSelection = ((IStructuredSelection) selection)
273
						.toArray();
308
				Object[] expandedElements = commonViewer.getExpandedElements();
274
				Object[] expandedElements = commonViewer.getExpandedElements();
309
				Object[] newExpandedElements = new Object[newSelection.length + expandedElements.length];
275
				Object[] newExpandedElements = new Object[newSelection.length
310
				System.arraycopy(expandedElements, 0, newExpandedElements, 0, expandedElements.length);
276
						+ expandedElements.length];
311
				System.arraycopy(newSelection, 0, newExpandedElements, expandedElements.length, newSelection.length);
277
				System.arraycopy(expandedElements, 0, newExpandedElements, 0,
312
 				commonViewer.setExpandedElements(newExpandedElements);
278
						expandedElements.length);
279
				System.arraycopy(newSelection, 0, newExpandedElements,
280
						expandedElements.length, newSelection.length);
281
				commonViewer.setExpandedElements(newExpandedElements);
313
			}
282
			}
314
			commonViewer.setSelection(selection, true);
283
			commonViewer.setSelection(selection, true);
315
		}
284
		}
Lines 317-325 Link Here
317
286
318
	/**
287
	/**
319
	 * <p>
288
	 * <p>
320
	 * Linking is handled by an action which listens for
289
	 * Linking is handled by an action which listens for changes to the
321
	 * changes to the {@link CommonNavigator#IS_LINKING_ENABLED_PROPERTY}.
290
	 * {@link CommonNavigator#IS_LINKING_ENABLED_PROPERTY}. Custom
322
	 * Custom implementations that wish to override this functionality, need to
291
	 * implementations that wish to override this functionality, need to
323
	 * override the action used by the default ActionGroup and listen for
292
	 * override the action used by the default ActionGroup and listen for
324
	 * changes to the above property.
293
	 * changes to the above property.
325
	 * 
294
	 * 
Lines 341-382 Link Here
341
310
342
	/**
311
	/**
343
	 * <p>
312
	 * <p>
344
	 * Provides access to the commonViewer used by the current CommonNavigator.
345
	 * The field will not be valid until after
313
	 * The field will not be valid until after
346
	 * {@link #init(IViewSite, IMemento)}&nbsp;has been called by the
314
	 * {@link #init(IViewSite, IMemento)}&nbsp;has been called by the Workbench.
347
	 * Workbench.
348
	 * </p>
315
	 * </p>
349
	 *  
316
	 * 
350
	 * @return The (already created) instance of Common Viewer.
317
	 * @return The (already created) instance of Common Viewer.
318
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewer()
351
	 */
319
	 */
352
	public CommonViewer getCommonViewer() {
320
	public CommonViewer getCommonViewer() {
353
		return commonViewer;
321
		return commonViewer;
354
	}
322
	}
355
323
356
	/**
324
	/**
357
	 * @return The Navigator Content Service which populates this instance of
325
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getNavigatorContentService()
358
	 *         Common Navigator
359
	 */
326
	 */
360
	public INavigatorContentService getNavigatorContentService() {
327
	public INavigatorContentService getNavigatorContentService() {
361
		return getCommonViewer().getNavigatorContentService();
328
		return getCommonViewer().getNavigatorContentService();
362
	}
329
	}
363
330
364
	/**
331
	/**
365
	 * Returns an object which is an instance of the given class
332
	 * Returns an object which is an instance of the given class associated with
366
	 * associated with this object. Returns <code>null</code> if
333
	 * this object. Returns <code>null</code> if no such object can be found.
367
	 * no such object can be found.
334
	 * 
368
	 *
335
	 * @param adapter
369
	 * @param adapter the adapter class to look up
336
	 *            the adapter class to look up
370
	 * @return a object castable to the given class, 
337
	 * @return a object castable to the given class, or <code>null</code> if
371
	 *    or <code>null</code> if this object does not
338
	 *         this object does not have an adapter for the given class
372
	 *    have an adapter for the given class
373
	 */
339
	 */
374
	public Object getAdapter(Class adapter) {
340
	public Object getAdapter(Class adapter) {
375
		if (adapter == COMMON_VIEWER_CLASS) {
341
		if (adapter == COMMON_VIEWER_CLASS) {
376
			return getCommonViewer();
342
			return getCommonViewer();
377
		} else if (adapter == INAVIGATOR_CONTENT_SERVICE) {
343
		} else if (adapter == INAVIGATOR_CONTENT_SERVICE) {
378
			return getCommonViewer().getNavigatorContentService();
344
			return getCommonViewer().getNavigatorContentService();
379
		} else if ( adapter == ISHOW_IN_TARGET_CLASS) {
345
		} else if (adapter == ISHOW_IN_TARGET_CLASS) {
380
			return this;
346
			return this;
381
		}
347
		}
382
		return super.getAdapter(adapter);
348
		return super.getAdapter(adapter);
Lines 392-401 Link Here
392
358
393
	/**
359
	/**
394
	 * <p>
360
	 * <p>
395
	 * Constructs and returns an instance of {@link CommonViewer}. The ID of
361
	 * Constructs and returns an instance of {@link CommonViewer}. The ID of the
396
	 * the Eclipse view part will be used to create the viewer. The ID is
362
	 * Eclipse view part will be used to create the viewer. The ID is important
397
	 * important as some extensions indicate they should only be used with a
363
	 * as some extensions indicate they should only be used with a particular
398
	 * particular viewer ID.
364
	 * viewer ID.
399
	 * <p>
365
	 * <p>
400
	 * 
366
	 * 
401
	 * @param aParent
367
	 * @param aParent
Lines 444-459 Link Here
444
	 */
410
	 */
445
	protected void handleDoubleClick(DoubleClickEvent anEvent) {
411
	protected void handleDoubleClick(DoubleClickEvent anEvent) {
446
412
447
		IAction openHandler = getViewSite().getActionBars().getGlobalActionHandler(ICommonActionConstants.OPEN);
413
		IAction openHandler = getViewSite().getActionBars()
448
		
414
				.getGlobalActionHandler(ICommonActionConstants.OPEN);
449
		if(openHandler == null) {
415
416
		if (openHandler == null) {
450
			IStructuredSelection selection = (IStructuredSelection) anEvent
417
			IStructuredSelection selection = (IStructuredSelection) anEvent
451
					.getSelection();
418
					.getSelection();
452
			Object element = selection.getFirstElement();
419
			Object element = selection.getFirstElement();
453
	
420
454
			TreeViewer viewer = getCommonViewer();
421
			TreeViewer viewer = getCommonViewer();
455
			if (viewer.isExpandable(element)) {
422
			if (viewer.isExpandable(element)) {
456
				viewer.setExpandedState(element, !viewer.getExpandedState(element));
423
				viewer.setExpandedState(element, !viewer
424
						.getExpandedState(element));
457
			}
425
			}
458
		}
426
		}
459
	}
427
	}
Lines 461-469 Link Here
461
	/**
429
	/**
462
	 * <p>
430
	 * <p>
463
	 * The Common Navigator Manager handles the setup of the Common Navigator
431
	 * The Common Navigator Manager handles the setup of the Common Navigator
464
	 * Menu, manages updates to the ActionBars from
432
	 * Menu, manages updates to the ActionBars from {@link CommonActionProvider}
465
	 * {@link CommonActionProvider}&nbsp; extensions as the user's selection
433
	 * &nbsp; extensions as the user's selection changes, and also updates the
466
	 * changes, and also updates the status bar based on the current selection.
434
	 * status bar based on the current selection.
467
	 * 
435
	 * 
468
	 * @return The Common Navigator Manager class which handles menu population
436
	 * @return The Common Navigator Manager class which handles menu population
469
	 *         and ActionBars
437
	 *         and ActionBars
Lines 476-482 Link Here
476
	 * <p>
444
	 * <p>
477
	 * The ActionGroup is used to populate the ActionBars of Common Navigator
445
	 * The ActionGroup is used to populate the ActionBars of Common Navigator
478
	 * View Part, and the returned implementation will have an opportunity to
446
	 * View Part, and the returned implementation will have an opportunity to
479
	 * fill the ActionBars of the view as soon as it is created. ({@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}.
447
	 * fill the ActionBars of the view as soon as it is created. (
448
	 * {@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}.
480
	 * </p>
449
	 * </p>
481
	 * <p>
450
	 * <p>
482
	 * The default implementation returns an action group which will add the
451
	 * The default implementation returns an action group which will add the
Lines 503-509 Link Here
503
	 *         Part.
472
	 *         Part.
504
	 */
473
	 */
505
	protected ActionGroup createCommonActionGroup() {
474
	protected ActionGroup createCommonActionGroup() {
506
		return new CommonNavigatorActionGroup(this, commonViewer, getLinkHelperService());
475
		return new CommonNavigatorViewActionGroup(this, commonViewer,
476
				getLinkHelperService());
507
	}
477
	}
508
478
509
	/**
479
	/**
Lines 555-576 Link Here
555
		return ""; //$NON-NLS-1$
525
		return ""; //$NON-NLS-1$
556
	}
526
	}
557
527
558
	/* (non-Javadoc)
528
	/*
529
	 * (non-Javadoc)
530
	 * 
559
	 * @see org.eclipse.ui.ISaveablesSource#getSaveables()
531
	 * @see org.eclipse.ui.ISaveablesSource#getSaveables()
560
	 */
532
	 */
561
	public Saveable[] getSaveables() {
533
	public Saveable[] getSaveables() {
562
		return getNavigatorContentService().getSaveablesService().getSaveables();
534
		return getNavigatorContentService().getSaveablesService()
535
				.getSaveables();
563
	}
536
	}
564
537
565
	/* (non-Javadoc)
538
	/*
539
	 * (non-Javadoc)
540
	 * 
566
	 * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables()
541
	 * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables()
567
	 */
542
	 */
568
	public Saveable[] getActiveSaveables() {
543
	public Saveable[] getActiveSaveables() {
569
		return getNavigatorContentService().getSaveablesService().getActiveSaveables();
544
		return getNavigatorContentService().getSaveablesService()
545
				.getActiveSaveables();
570
	}
546
	}
571
547
572
	/* (non-Javadoc)
548
	/*
573
	 * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
549
	 * (non-Javadoc)
550
	 * 
551
	 * @see
552
	 * org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor
553
	 * )
574
	 */
554
	 */
575
	public void doSave(IProgressMonitor monitor) {
555
	public void doSave(IProgressMonitor monitor) {
576
		// Ignore. This method is not called because CommonNavigator implements
556
		// Ignore. This method is not called because CommonNavigator implements
Lines 578-626 Link Here
578
		// Saveable protocol.
558
		// Saveable protocol.
579
	}
559
	}
580
560
581
	/* (non-Javadoc)
561
	/*
562
	 * (non-Javadoc)
563
	 * 
582
	 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
564
	 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
583
	 */
565
	 */
584
	public void doSaveAs() {
566
	public void doSaveAs() {
585
		// ignore
567
		// ignore
586
	}
568
	}
587
569
588
	/* (non-Javadoc)
570
	/*
571
	 * (non-Javadoc)
572
	 * 
589
	 * @see org.eclipse.ui.ISaveablePart#isDirty()
573
	 * @see org.eclipse.ui.ISaveablePart#isDirty()
590
	 */
574
	 */
591
	public boolean isDirty() {
575
	public boolean isDirty() {
592
		Saveable[] saveables = getSaveables();
576
		Saveable[] saveables = getSaveables();
593
		for (int i = 0; i < saveables.length; i++) {
577
		for (int i = 0; i < saveables.length; i++) {
594
			if(saveables[i].isDirty()) {
578
			if (saveables[i].isDirty()) {
595
				return true;
579
				return true;
596
			}
580
			}
597
		}
581
		}
598
		return false;
582
		return false;
599
	}
583
	}
600
584
601
	/* (non-Javadoc)
585
	/*
586
	 * (non-Javadoc)
587
	 * 
602
	 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
588
	 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
603
	 */
589
	 */
604
	public boolean isSaveAsAllowed() {
590
	public boolean isSaveAsAllowed() {
605
		return false;
591
		return false;
606
	}
592
	}
607
593
608
	/* (non-Javadoc)
594
	/*
595
	 * (non-Javadoc)
596
	 * 
609
	 * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
597
	 * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
610
	 */
598
	 */
611
	public boolean isSaveOnCloseNeeded() {
599
	public boolean isSaveOnCloseNeeded() {
612
		return isDirty();
600
		return isDirty();
613
	}
601
	}
614
602
615
	/* (non-Javadoc)
603
	/*
616
	 * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
604
	 * (non-Javadoc)
605
	 * 
606
	 * @see
607
	 * org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
617
	 */
608
	 */
618
	public boolean show(ShowInContext context) {
609
	public boolean show(ShowInContext context) {
619
		IStructuredSelection selection = getSelection(context);
610
		IStructuredSelection selection = getSelection(context);
620
		if (selection != null && !selection.isEmpty()) {
611
		if (selection != null && !selection.isEmpty()) {
621
			selectReveal(selection);
612
			selectReveal(selection);
622
			return true;
613
			return true;
623
		} 
614
		}
624
		return false;
615
		return false;
625
	}
616
	}
626
617
Lines 628-635 Link Here
628
		if (context == null)
619
		if (context == null)
629
			return StructuredSelection.EMPTY;
620
			return StructuredSelection.EMPTY;
630
		ISelection selection = context.getSelection();
621
		ISelection selection = context.getSelection();
631
		if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection)
622
		if (selection != null && !selection.isEmpty()
632
			return (IStructuredSelection)selection;
623
				&& selection instanceof IStructuredSelection)
624
			return (IStructuredSelection) selection;
633
		Object input = context.getInput();
625
		Object input = context.getInput();
634
		if (input instanceof IEditorInput) {
626
		if (input instanceof IEditorInput) {
635
			LinkHelperService lhs = getLinkHelperService();
627
			LinkHelperService lhs = getLinkHelperService();
Lines 643-650 Link Here
643
635
644
	private synchronized LinkHelperService getLinkHelperService() {
636
	private synchronized LinkHelperService getLinkHelperService() {
645
		if (linkService == null)
637
		if (linkService == null)
646
			linkService = new LinkHelperService((NavigatorContentService)getCommonViewer().getNavigatorContentService());
638
			linkService = new LinkHelperService(
639
					(NavigatorContentService) getCommonViewer()
640
							.getNavigatorContentService());
647
		return linkService;
641
		return linkService;
648
	}
642
	}
649
 
643
644
	/**
645
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getActionBars()
646
	 */
647
	public IActionBars getActionBars() {
648
		return getViewSite().getActionBars();
649
	}
650
651
	/**
652
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getWorkbenchSite()
653
	 */
654
	public IWorkbenchSite getWorkbenchSite() {
655
		return getViewSite();
656
	}
657
658
	/**
659
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewerSite()
660
	 */
661
	public ICommonViewerSite getCommonViewerSite() {
662
		return CommonViewerSiteFactory.createCommonViewerSite(getViewSite());
663
	}
650
}
664
}
(-)src/org/eclipse/ui/navigator/NavigatorActionService.java (-1 / +1 lines)
Lines 60-66 Link Here
60
 * specify an Action Provider.
60
 * specify an Action Provider.
61
 * </p>
61
 * </p>
62
 * <p>
62
 * <p>
63
 * Clients that reuse this service outside of an instance of {@link CommonNavigator} must be sure
63
 * Clients that reuse this service outside of an instance of {@link ICommonNavigator} must be sure
64
 * that {{@link #fillActionBars(IActionBars)} is called whenever the selection changes. The
64
 * that {{@link #fillActionBars(IActionBars)} is called whenever the selection changes. The
65
 * retargetable actions for each selection could change, based on who contributed the items.
65
 * retargetable actions for each selection could change, based on who contributed the items.
66
 * 
66
 * 
(-)src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java (-12 / +13 lines)
Lines 69-76 Link Here
69
						ILinkHelper[] helpers = linkService
69
						ILinkHelper[] helpers = linkService
70
								.getLinkHelpersFor(sSelection.getFirstElement());
70
								.getLinkHelpersFor(sSelection.getFirstElement());
71
						if (helpers.length > 0) {
71
						if (helpers.length > 0) {
72
							helpers[0].activateEditor(commonNavigator.getSite()
72
							helpers[0].activateEditor(commonNavigator
73
									.getPage(), sSelection);
73
									.getWorkbenchSite().getPage(), sSelection);
74
						}
74
						}
75
					}
75
					}
76
				}
76
				}
Lines 87-94 Link Here
87
				SafeRunner.run(new ISafeRunnable() {
87
				SafeRunner.run(new ISafeRunnable() {
88
88
89
					public void run() throws Exception {
89
					public void run() throws Exception {
90
						IWorkbenchPage page = commonNavigator.getSite()
90
						IWorkbenchPage page = commonNavigator
91
								.getPage();
91
								.getWorkbenchSite().getPage();
92
						if (page != null) {
92
						if (page != null) {
93
							IEditorPart editor = page.getActiveEditor();
93
							IEditorPart editor = page.getActiveEditor();
94
							if (editor != null) {
94
							if (editor != null) {
Lines 168-174 Link Here
168
168
169
		updateLinkingEnabled(commonNavigator.isLinkingEnabled());
169
		updateLinkingEnabled(commonNavigator.isLinkingEnabled());
170
170
171
		commonNavigator.addPropertyListener(this);
171
		// commonNavigator.addPropertyListener(this);
172
172
173
		// linkHelperRegistry = new
173
		// linkHelperRegistry = new
174
		// LinkHelperManager(commonViewer.getNavigatorContentService());
174
		// LinkHelperManager(commonViewer.getNavigatorContentService());
Lines 178-188 Link Here
178
	 * 
178
	 * 
179
	 */
179
	 */
180
	public void dispose() {
180
	public void dispose() {
181
		commonNavigator.removePropertyListener(this);
181
		// commonNavigator.removePropertyListener(this);
182
		if (isChecked()) {
182
		if (isChecked()) {
183
			commonViewer.removePostSelectionChangedListener(this);
183
			commonViewer.removePostSelectionChangedListener(this);
184
			commonNavigator.getSite().getPage()
184
			commonNavigator.getWorkbenchSite().getPage().removePartListener(
185
					.removePartListener(partListener);
185
					partListener);
186
		}
186
		}
187
187
188
	}
188
	}
Lines 225-231 Link Here
225
	 * (non-Javadoc)
225
	 * (non-Javadoc)
226
	 * 
226
	 * 
227
	 * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object,
227
	 * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object,
228
	 *      int)
228
	 * int)
229
	 */
229
	 */
230
	public void propertyChanged(Object aSource, int aPropertyId) {
230
	public void propertyChanged(Object aSource, int aPropertyId) {
231
		switch (aPropertyId) {
231
		switch (aPropertyId) {
Lines 245-255 Link Here
245
			updateSelectionJob.schedule(BRIEF_DELAY);
245
			updateSelectionJob.schedule(BRIEF_DELAY);
246
246
247
			commonViewer.addPostSelectionChangedListener(this);
247
			commonViewer.addPostSelectionChangedListener(this);
248
			commonNavigator.getSite().getPage().addPartListener(partListener);
248
			commonNavigator.getWorkbenchSite().getPage().addPartListener(
249
					partListener);
249
		} else {
250
		} else {
250
			commonViewer.removePostSelectionChangedListener(this);
251
			commonViewer.removePostSelectionChangedListener(this);
251
			commonNavigator.getSite().getPage()
252
			commonNavigator.getWorkbenchSite().getPage().removePartListener(
252
					.removePartListener(partListener);
253
					partListener);
253
		}
254
		}
254
	}
255
	}
255
256
(-)META-INF/MANIFEST.MF (-9 / +2 lines)
Lines 6-23 Link Here
6
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
6
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
7
Bundle-Vendor: %Plugin.providerName
7
Bundle-Vendor: %Plugin.providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.ui.internal.navigator;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources",
10
 org.eclipse.ui.internal.navigator.actions;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources",
11
 org.eclipse.ui.internal.navigator.dnd;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources",
12
 org.eclipse.ui.internal.navigator.extensions;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources",
13
 org.eclipse.ui.internal.navigator.filters;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources,org.eclipse.ui.tests.navigator",
14
 org.eclipse.ui.internal.navigator.sorters;x-internal:=true,
15
 org.eclipse.ui.internal.navigator.wizards;x-internal:=true,
16
 org.eclipse.ui.navigator
17
Require-Bundle: org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
9
Require-Bundle: org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
18
 org.eclipse.ui.workbench;bundle-version="[3.2.1,4.0.0)",
10
 org.eclipse.ui.workbench;bundle-version="[3.2.1,4.0.0)",
19
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
11
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
20
 org.eclipse.ui;bundle-version="[3.2.1,4.0.0)",
12
 org.eclipse.ui;bundle-version="[3.2.1,4.0.0)",
21
 org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)"
13
 org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
14
 org.eclipse.ui.views;bundle-version="[3.3.0,4.0.0)"
22
Bundle-RequiredExecutionEnvironment: J2SE-1.4
15
Bundle-RequiredExecutionEnvironment: J2SE-1.4
23
Bundle-ActivationPolicy: lazy
16
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/ui/navigator/ICommonNavigator.java (+122 lines)
Added Link Here
1
/***********************************************************************
2
 * Copyright (c) 2008 Anyware Technologies
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 *
12
 * $Id$
13
 **********************************************************************/
14
15
package org.eclipse.ui.navigator;
16
17
import org.eclipse.ui.IActionBars;
18
import org.eclipse.ui.IWorkbenchSite;
19
import org.eclipse.ui.part.ISetSelectionTarget;
20
21
/**
22
 * <p>
23
 * This interface defines the API for common navigators. Common navigators can
24
 * be used in views or outlines. The following types are used by this class to
25
 * render a Common Navigator:
26
 * <ul>
27
 * <li>
28
 * <p>
29
 * {@link org.eclipse.ui.navigator.CommonViewer}: The viewer that renders the
30
 * extensible tree. Creates and manages the lifecylce of the Navigator Content
31
 * Service (described below).
32
 * </p>
33
 * </li>
34
 * <li>
35
 * <p>
36
 * {@link org.eclipse.ui.navigator.NavigatorActionService}: Manages instances of
37
 * {@link org.eclipse.ui.navigator.CommonActionProvider}s provided by individual
38
 * extensions and content extensions.
39
 * </p>
40
 * </li>
41
 * <li>
42
 * <p>
43
 * {@link org.eclipse.ui.navigator.INavigatorContentService}: Manages instances
44
 * of Navigator Content Extensions. Instances are created as needed, and
45
 * disposed of upon the disposal of the Navigator Content Service.
46
 * </p>
47
 * </li>
48
 * </ul>
49
 * <p>
50
 * Clients are not expected to subclass CommonNavigator. Clients that wish to
51
 * define their own custom extensible navigator view need to specify an instance
52
 * of the <b>org.eclipse.ui.views</b> extension point:
53
 * 
54
 * <pre>
55
 * 
56
 *          &lt;extension
57
 *          		point=&quot;org.eclipse.ui.views&quot;&gt;
58
 *          	&lt;view
59
 *          		name=&quot;My Custom View&quot;
60
 *          		icon=&quot;relative/path/to/icon.gif&quot;
61
 *          		category=&quot;org.acme.mycategory&quot;
62
 *          		class=&quot;org.eclipse.ui.navigator.CommonNavigator&quot;
63
 *          		id=&quot;org.acme.MyCustomNavigatorID&quot;&gt;
64
 *          	&lt;/view&gt;
65
 *          &lt;/extension&gt;
66
 * 
67
 * </pre>
68
 * 
69
 * @since 3.5
70
 */
71
public interface ICommonNavigator extends ISetSelectionTarget {
72
73
	/**
74
	 * <p>
75
	 * Provides access to the commonViewer used by the current CommonNavigator.
76
	 * </p>
77
	 * 
78
	 * @return The (already created) instance of Common Viewer.
79
	 */
80
	public CommonViewer getCommonViewer();
81
82
	/**
83
	 * @return The Navigator Content Service which populates this instance of
84
	 *         Common Navigator
85
	 */
86
	public INavigatorContentService getNavigatorContentService();
87
88
	/**
89
	 * <p>
90
	 * Provides access to the Workbench Site of the current Common Navigator.
91
	 * The workbench site is used to access to the Workbench Page or services.
92
	 * </p>
93
	 * 
94
	 * @return the Workbench site of the Common Navigator
95
	 */
96
	public IWorkbenchSite getWorkbenchSite();
97
98
	/**
99
	 * <p>
100
	 * Return or creates a valid context for this Common Navigator
101
	 * </p>
102
	 * 
103
	 * @return the context of this Common Navigator
104
	 */
105
	public ICommonViewerSite getCommonViewerSite();
106
107
	/**
108
	 * @return the title of this Common Navigator
109
	 */
110
	public String getTitle();
111
112
	/**
113
	 * <p>
114
	 * Provides access to the ActionBars of this Common Navigator. This method
115
	 * is an abstraction to access to ActionBars from IViewPart,
116
	 * IContentOutlinePage...
117
	 * </p>
118
	 * 
119
	 * @return the ActionBar of this Common Navigator
120
	 */
121
	public IActionBars getActionBars();
122
}
(-)src/org/eclipse/ui/internal/navigator/CommonNavigatorViewActionGroup.java (+114 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 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.navigator;
12
13
import org.eclipse.jface.action.IMenuManager;
14
import org.eclipse.jface.commands.ActionHandler;
15
import org.eclipse.jface.resource.ImageDescriptor;
16
import org.eclipse.ui.IActionBars;
17
import org.eclipse.ui.IWorkbenchActionConstants;
18
import org.eclipse.ui.handlers.IHandlerService;
19
import org.eclipse.ui.internal.navigator.actions.LinkEditorAction;
20
import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
21
import org.eclipse.ui.navigator.CommonNavigator;
22
import org.eclipse.ui.navigator.CommonViewer;
23
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
24
25
/**
26
 * 
27
 * 
28
 * @since 3.5
29
 */
30
public class CommonNavigatorViewActionGroup extends CommonNavigatorActionGroup {
31
32
	private LinkEditorAction toggleLinkingAction;
33
34
	private final LinkHelperService linkHelperService;
35
36
	/**
37
	 * Create a action group for Collapse All, Link with editor, and Select
38
	 * Filters.
39
	 * 
40
	 * @param aNavigator
41
	 *            The IViewPart for this action group
42
	 * @param aViewer
43
	 *            The Viewer for this action group
44
	 * @param linkHelperService
45
	 *            the link service helper
46
	 */
47
	public CommonNavigatorViewActionGroup(CommonNavigator aNavigator,
48
			CommonViewer aViewer, LinkHelperService linkHelperService) {
49
		super(aNavigator, aViewer);
50
		this.linkHelperService = linkHelperService;
51
		makeViewActions();
52
	}
53
54
	/**
55
	 * 
56
	 */
57
	private void makeViewActions() {
58
		IHandlerService service = (IHandlerService) getCommonNavigator()
59
				.getWorkbenchSite().getService(IHandlerService.class);
60
61
		INavigatorViewerDescriptor viewerDescriptor = getCommonViewer()
62
				.getNavigatorContentService().getViewerDescriptor();
63
		boolean hideLinkWithEditorAction = viewerDescriptor
64
				.getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION);
65
		if (!hideLinkWithEditorAction) {
66
			toggleLinkingAction = new LinkEditorAction(
67
					(CommonNavigator) getCommonNavigator(), getCommonViewer(),
68
					linkHelperService);
69
			ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$
70
			toggleLinkingAction.setImageDescriptor(syncIcon);
71
			toggleLinkingAction.setHoverImageDescriptor(syncIcon);
72
			service.activateHandler(
73
					toggleLinkingAction.getActionDefinitionId(),
74
					new ActionHandler(toggleLinkingAction));
75
		}
76
77
	}
78
79
	/*
80
	 * (non-Javadoc)
81
	 * 
82
	 * @see
83
	 * org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars
84
	 * )
85
	 */
86
	public void fillActionBars(IActionBars theActionBars) {
87
		super.fillActionBars(theActionBars);
88
89
		IMenuManager menu = theActionBars.getMenuManager();
90
91
		if (toggleLinkingAction != null) {
92
			menu
93
					.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS
94
							+ "-end", toggleLinkingAction); //$NON-NLS-1$
95
96
			theActionBars.getToolBarManager().add(toggleLinkingAction);
97
		}
98
99
		theActionBars.updateActionBars();
100
	}
101
102
	/*
103
	 * (non-Javadoc)
104
	 * 
105
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
106
	 */
107
	public void dispose() {
108
		super.dispose();
109
		if (toggleLinkingAction != null) {
110
			toggleLinkingAction.dispose();
111
		}
112
	}
113
114
}
(-)src/org/eclipse/ui/navigator/CommonNavigatorOutline.java (+406 lines)
Added Link Here
1
/***********************************************************************
2
 * Copyright (c) 2008 Anyware Technologies
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 *
12
 * $Id$
13
 **********************************************************************/
14
15
package org.eclipse.ui.navigator;
16
17
import org.eclipse.jface.viewers.DoubleClickEvent;
18
import org.eclipse.jface.viewers.IDoubleClickListener;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.ISelectionChangedListener;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.TreeViewer;
23
import org.eclipse.jface.viewers.ViewerFilter;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IMemento;
29
import org.eclipse.ui.IWorkbenchSite;
30
import org.eclipse.ui.actions.ActionGroup;
31
import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup;
32
import org.eclipse.ui.internal.navigator.CommonNavigatorManager;
33
import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
34
import org.eclipse.ui.part.Page;
35
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
36
37
/**
38
 * <p>
39
 * This class provides an implementation of Common Navigator hosted in an
40
 * IContentOutlinePage.
41
 * 
42
 * </p>
43
 * Clients that wish to extend the view menu provided via the
44
 * <b>org.eclipse.ui.popupMenu</b>s extension may specify the the
45
 * <i>popupMenuId</i> specified by <b>org.eclipse.ui.navigator.viewer</b> (or a
46
 * nested <b>popupMenu</b> element) of their target viewer as their target menu
47
 * id.
48
 * 
49
 * @since 3.5
50
 */
51
public abstract class CommonNavigatorOutline extends Page implements
52
		IContentOutlinePage, ICommonNavigator {
53
54
	private static final Class INAVIGATOR_CONTENT_SERVICE = INavigatorContentService.class;
55
	private static final Class COMMON_VIEWER_CLASS = CommonViewer.class;
56
57
	private CommonViewer commonViewer;
58
59
	private CommonNavigatorManager commonManager;
60
61
	private ActionGroup commonActionGroup;
62
63
	private IMemento memento;
64
65
	/**
66
	 * 
67
	 */
68
	public CommonNavigatorOutline() {
69
		super();
70
	}
71
72
	/**
73
	 * <p>
74
	 * Returns The id used to initialize the Common Viewer from extensions. It
75
	 * is recommended to use the same id as the editor providing this Outline.
76
	 * </p>
77
	 * 
78
	 * @return The Id of the Common Viewer
79
	 */
80
	protected abstract String getCommonViewerId();
81
82
	/**
83
	 * <p>
84
	 * Constructs and returns an instance of {@link CommonViewer}. The ID from
85
	 * <code>getCommonViewer()</code> will be used to create the viewer. The ID
86
	 * is important as some extensions indicate they should only be used with a
87
	 * particular viewer ID.
88
	 * <p>
89
	 * 
90
	 * @param aParent
91
	 *            A composite parent to contain the Common Viewer
92
	 * @return An initialized instance of CommonViewer
93
	 */
94
	protected CommonViewer createCommonViewer(Composite aParent) {
95
		CommonViewer aViewer = new CommonViewer(getCommonViewerId(), aParent,
96
				SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
97
		initListeners(aViewer);
98
		aViewer.getNavigatorContentService().restoreState(memento);
99
		return aViewer;
100
	}
101
102
	/**
103
	 * <p>
104
	 * Adds the listeners to the Common Viewer.
105
	 * </p>
106
	 * 
107
	 * @param viewer
108
	 *            The viewer
109
	 * @since 2.0
110
	 */
111
	protected void initListeners(TreeViewer viewer) {
112
113
		viewer.addDoubleClickListener(new IDoubleClickListener() {
114
115
			public void doubleClick(DoubleClickEvent event) {
116
				try {
117
					handleDoubleClick(event);
118
				} catch (RuntimeException re) {
119
					re.printStackTrace();
120
				}
121
			}
122
		});
123
	}
124
125
	/**
126
	 * <p>
127
	 * This method can be overridden to customize the behavior of the double
128
	 * click.
129
	 * </p>
130
	 * 
131
	 * @param anEvent
132
	 *            Supplied by the DoubleClick listener.
133
	 */
134
	protected void handleDoubleClick(DoubleClickEvent anEvent) {
135
136
		IStructuredSelection selection = (IStructuredSelection) anEvent
137
				.getSelection();
138
		Object element = selection.getFirstElement();
139
140
		TreeViewer viewer = getCommonViewer();
141
		if (viewer.isExpandable(element)) {
142
			viewer.setExpandedState(element, !viewer.getExpandedState(element));
143
		}
144
	}
145
146
	/**
147
	 * <p>
148
	 * The Common Navigator Manager handles the setup of the Common Navigator
149
	 * Menu, manages updates to the ActionBars from {@link CommonActionProvider}
150
	 * &nbsp; extensions as the user's selection changes, and also updates the
151
	 * status bar based on the current selection.
152
	 * 
153
	 * @return The Common Navigator Manager class which handles menu population
154
	 *         and ActionBars
155
	 */
156
	protected CommonNavigatorManager createCommonManager() {
157
		return new CommonNavigatorManager(this, memento);
158
	}
159
160
	/**
161
	 * <p>
162
	 * The ActionGroup is used to populate the ActionBars of Common Navigator ,
163
	 * and the returned implementation will have an opportunity to fill the
164
	 * ActionBars of the outline as soon as it is created. (
165
	 * {@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}.
166
	 * </p>
167
	 * <p>
168
	 * The default implementation returns an action group which will add the
169
	 * following actions:
170
	 * <ul>
171
	 * <li>
172
	 * <li>
173
	 * <p>
174
	 * Collapse all. Collapses all expanded nodes.
175
	 * </p>
176
	 * <li>
177
	 * <p>
178
	 * Select Filters. Provides access to the "Select Filters" dialog that
179
	 * allows users to enable/disable filters and also the Content Extension
180
	 * activations.
181
	 * </p>
182
	 * </ul>
183
	 * 
184
	 * @return The Action Group to be associated with the Common Navigator View
185
	 *         Part.
186
	 */
187
	protected ActionGroup createCommonActionGroup() {
188
		return new CommonNavigatorActionGroup(this, commonViewer);
189
	}
190
191
	/**
192
	 * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
193
	 */
194
	public void createControl(Composite parent) {
195
		commonViewer = createCommonViewer(parent);
196
197
		try {
198
			commonViewer.getControl().setRedraw(false);
199
200
			INavigatorFilterService filterService = commonViewer
201
					.getNavigatorContentService().getFilterService();
202
			ViewerFilter[] visibleFilters = filterService
203
					.getVisibleFilters(true);
204
			for (int i = 0; i < visibleFilters.length; i++) {
205
				commonViewer.addFilter(visibleFilters[i]);
206
			}
207
208
			commonViewer.setSorter(new CommonViewerSorter());
209
210
			/*
211
			 * make sure input is set after sorters and filters to avoid
212
			 * unnecessary refreshes
213
			 */
214
			commonViewer.setInput(getInitialInput());
215
216
			getSite().setSelectionProvider(commonViewer);
217
218
		} finally {
219
			commonViewer.getControl().setRedraw(true);
220
		}
221
222
		/*
223
		 * Create the CommonNavigatorManager last because information about the
224
		 * state of the CommonNavigator is required for the initialization of
225
		 * the CommonNavigatorManager
226
		 */
227
		commonManager = createCommonManager();
228
		if (memento != null) {
229
			commonViewer.getNavigatorContentService().restoreState(memento);
230
		}
231
232
		commonActionGroup = createCommonActionGroup();
233
		commonActionGroup.fillActionBars(getActionBars());
234
235
	}
236
237
	/**
238
	 * <p>
239
	 * Note: This method is for internal use only. Clients should not call this
240
	 * method.
241
	 * </p>
242
	 * <p>
243
	 * This method will be invoked when the DisposeListener is notified of the
244
	 * disposal of the Eclipse view part.
245
	 * </p>
246
	 * 
247
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
248
	 */
249
	public void dispose() {
250
		if (commonManager != null) {
251
			commonManager.dispose();
252
		}
253
		if (commonActionGroup != null) {
254
			commonActionGroup.dispose();
255
		}
256
		super.dispose();
257
	}
258
259
	/**
260
	 * @see org.eclipse.ui.part.Page#getControl()
261
	 */
262
	public Control getControl() {
263
		return commonViewer.getControl();
264
	}
265
266
	/**
267
	 * Returns an object which is an instance of the given class associated with
268
	 * this object. Returns <code>null</code> if no such object can be found.
269
	 * 
270
	 * @param adapter
271
	 *            the adapter class to look up
272
	 * @return a object castable to the given class, or <code>null</code> if
273
	 *         this object does not have an adapter for the given class
274
	 */
275
	public Object getAdapter(Class adapter) {
276
		if (adapter == COMMON_VIEWER_CLASS) {
277
			return getCommonViewer();
278
		} else if (adapter == INAVIGATOR_CONTENT_SERVICE) {
279
			return getCommonViewer().getNavigatorContentService();
280
		}
281
		return null;
282
	}
283
284
	/**
285
	 * @see org.eclipse.ui.part.Page#setFocus()
286
	 */
287
	public void setFocus() {
288
		if (commonViewer != null) {
289
			commonViewer.getTree().setFocus();
290
		}
291
	}
292
293
	/**
294
	 * <p>
295
	 * Subclasses should override this method to define the initial input of the
296
	 * Common Navigator Outline.
297
	 * </p>
298
	 * 
299
	 * @return The initial input for the viewer. Defaults to
300
	 *         getSite().getPage().getInput()
301
	 */
302
	protected Object getInitialInput() {
303
		return getSite().getPage().getInput();
304
	}
305
306
	/**
307
	 * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
308
	 */
309
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
310
		getCommonViewer().addSelectionChangedListener(listener);
311
	}
312
313
	/**
314
	 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
315
	 */
316
	public ISelection getSelection() {
317
		return getCommonViewer().getSelection();
318
	}
319
320
	/**
321
	 * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
322
	 */
323
	public void removeSelectionChangedListener(
324
			ISelectionChangedListener listener) {
325
		getCommonViewer().removeSelectionChangedListener(listener);
326
	}
327
328
	/**
329
	 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
330
	 */
331
	public void setSelection(ISelection selection) {
332
		getCommonViewer().setSelection(selection);
333
	}
334
335
	/**
336
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getActionBars()
337
	 */
338
	public IActionBars getActionBars() {
339
		return getSite().getActionBars();
340
	}
341
342
	/**
343
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewer()
344
	 */
345
	public CommonViewer getCommonViewer() {
346
		return commonViewer;
347
	}
348
349
	/**
350
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewerSite()
351
	 */
352
	public ICommonViewerSite getCommonViewerSite() {
353
		return CommonViewerSiteFactory.createCommonViewerSite(
354
				getCommonViewerId(), getSite());
355
	}
356
357
	/**
358
	 * @return The Navigator Content Service which populates this instance of
359
	 *         Common Navigator
360
	 */
361
	public INavigatorContentService getNavigatorContentService() {
362
		return getCommonViewer().getNavigatorContentService();
363
	}
364
365
	/**
366
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getTitle()
367
	 */
368
	public String getTitle() {
369
		return CommonNavigatorMessages.CommonNavigatorOutline_DefaultTitle;
370
	}
371
372
	/**
373
	 * @see org.eclipse.ui.navigator.ICommonNavigator#getWorkbenchSite()
374
	 */
375
	public IWorkbenchSite getWorkbenchSite() {
376
		return getSite();
377
	}
378
379
	/**
380
	 * <p>
381
	 * Set the selection to the Common Navigator tree, and expand nodes if
382
	 * necessary. Use caution when invoking this method as it can cause
383
	 * Navigator Content Extensions to load, thus causing plugin activation.
384
	 * </p>
385
	 * 
386
	 * @see org.eclipse.ui.part.ISetSelectionTarget#selectReveal(org.eclipse.jface.viewers.ISelection)
387
	 */
388
	public void selectReveal(ISelection selection) {
389
		if (commonViewer != null) {
390
			if (selection instanceof IStructuredSelection) {
391
				Object[] newSelection = ((IStructuredSelection) selection)
392
						.toArray();
393
				Object[] expandedElements = commonViewer.getExpandedElements();
394
				Object[] newExpandedElements = new Object[newSelection.length
395
						+ expandedElements.length];
396
				System.arraycopy(expandedElements, 0, newExpandedElements, 0,
397
						expandedElements.length);
398
				System.arraycopy(newSelection, 0, newExpandedElements,
399
						expandedElements.length, newSelection.length);
400
				commonViewer.setExpandedElements(newExpandedElements);
401
			}
402
			commonViewer.setSelection(selection, true);
403
		}
404
	}
405
406
}

Return to bug 235768