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

(-)src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java (-268 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.navigator.resources.actions;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.Iterator;
16
17
import org.eclipse.osgi.util.NLS;
18
19
import org.eclipse.swt.widgets.Shell;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.core.runtime.jobs.ISchedulingRule;
27
28
import org.eclipse.core.resources.ICommand;
29
import org.eclipse.core.resources.IProject;
30
import org.eclipse.core.resources.IncrementalProjectBuilder;
31
import org.eclipse.core.resources.ResourcesPlugin;
32
import org.eclipse.core.resources.WorkspaceJob;
33
34
import org.eclipse.jface.action.IMenuManager;
35
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.viewers.StructuredViewer;
38
import org.eclipse.jface.window.IShellProvider;
39
40
import org.eclipse.ui.IActionBars;
41
import org.eclipse.ui.IWorkbenchCommandConstants;
42
import org.eclipse.ui.actions.ActionFactory;
43
import org.eclipse.ui.actions.BuildAction;
44
import org.eclipse.ui.actions.CloseResourceAction;
45
import org.eclipse.ui.actions.CloseUnrelatedProjectsAction;
46
import org.eclipse.ui.actions.OpenResourceAction;
47
import org.eclipse.ui.actions.RefreshAction;
48
import org.eclipse.ui.actions.WorkspaceModifyOperation;
49
import org.eclipse.ui.ide.IDEActionFactory;
50
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
51
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
52
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
53
import org.eclipse.ui.navigator.CommonActionProvider;
54
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
55
import org.eclipse.ui.navigator.ICommonMenuConstants;
56
57
/**
58
 * @since 3.2
59
 * 
60
 */
61
public class ResourceMgmtActionProvider extends CommonActionProvider {
62
63
	private BuildAction buildAction;
64
65
	private OpenResourceAction openProjectAction;
66
67
	private CloseResourceAction closeProjectAction;
68
69
	private CloseUnrelatedProjectsAction closeUnrelatedProjectsAction;
70
71
	private RefreshAction refreshAction;
72
73
	private Shell shell;
74
75
	/*
76
	 * (non-Javadoc)
77
	 * 
78
	 * @see
79
	 * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator
80
	 * .ICommonActionExtensionSite)
81
	 */
82
	public void init(ICommonActionExtensionSite aSite) {
83
		super.init(aSite);
84
		shell = aSite.getViewSite().getShell();
85
		makeActions();
86
	}
87
88
	public void fillActionBars(IActionBars actionBars) {
89
		actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
90
		actionBars.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), buildAction);
91
		actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), openProjectAction);
92
		actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), closeProjectAction);
93
		actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(), closeUnrelatedProjectsAction);
94
		updateActionBars();
95
	}
96
97
	/**
98
	 * Adds the build, open project, close project and refresh resource actions
99
	 * to the context menu.
100
	 * <p>
101
	 * The following conditions apply: build-only projects selected, auto build
102
	 * disabled, at least one builder present open project-only projects
103
	 * selected, at least one closed project close project-only projects
104
	 * selected, at least one open project refresh-no closed project selected
105
	 * </p>
106
	 * <p>
107
	 * Both the open project and close project action may be on the menu at the
108
	 * same time.
109
	 * </p>
110
	 * <p>
111
	 * No disabled action should be on the context menu.
112
	 * </p>
113
	 * 
114
	 * @param menu
115
	 *            context menu to add actions to
116
	 */
117
	public void fillContextMenu(IMenuManager menu) {
118
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
119
		boolean isProjectSelection = true;
120
		boolean hasOpenProjects = false;
121
		boolean hasClosedProjects = false;
122
		boolean hasBuilder = true; // false if any project is closed or does not
123
									// have builder
124
		Iterator resources = selection.iterator();
125
126
		while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
127
			Object next = resources.next();
128
			IProject project = null;
129
130
			if (next instanceof IProject) {
131
				project = (IProject) next;
132
			} else if (next instanceof IAdaptable) {
133
				project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
134
			}
135
136
			if (project == null) {
137
				isProjectSelection = false;
138
				continue;
139
			}
140
			if (project.isOpen()) {
141
				hasOpenProjects = true;
142
				if (hasBuilder && !hasBuilder(project)) {
143
					hasBuilder = false;
144
				}
145
			} else {
146
				hasClosedProjects = true;
147
				hasBuilder = false;
148
			}
149
		}
150
		if (!selection.isEmpty() && isProjectSelection && !ResourcesPlugin.getWorkspace().isAutoBuilding() && hasBuilder) {
151
			// Allow manual incremental build only if auto build is off.
152
			buildAction.selectionChanged(selection);
153
			menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, buildAction);
154
		}
155
		if (!hasClosedProjects) {
156
			refreshAction.selectionChanged(selection);
157
			menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, refreshAction);
158
		}
159
		if (isProjectSelection) {
160
			if (hasClosedProjects) {
161
				openProjectAction.selectionChanged(selection);
162
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, openProjectAction);
163
			}
164
			if (hasOpenProjects) {
165
				closeProjectAction.selectionChanged(selection);
166
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, closeProjectAction);
167
				closeUnrelatedProjectsAction.selectionChanged(selection);
168
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, closeUnrelatedProjectsAction);
169
			}
170
		}
171
	}
172
173
	/**
174
	 * Returns whether there are builders configured on the given project.
175
	 * 
176
	 * @return <code>true</code> if it has builders, <code>false</code> if not,
177
	 *         or if this could not be determined
178
	 */
179
	boolean hasBuilder(IProject project) {
180
		try {
181
			ICommand[] commands = project.getDescription().getBuildSpec();
182
			if (commands.length > 0) {
183
				return true;
184
			}
185
		} catch (CoreException e) {
186
			// Cannot determine if project has builders. Project is closed
187
			// or does not exist. Fall through to return false.
188
		}
189
		return false;
190
	}
191
192
	protected void makeActions() {
193
		IShellProvider sp = new IShellProvider() {
194
			public Shell getShell() {
195
				return shell;
196
			}
197
		};
198
199
		openProjectAction = new OpenResourceAction(sp);
200
201
		closeProjectAction = new CloseResourceAction(sp);
202
203
		closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
204
205
		refreshAction = new RefreshAction(sp) {
206
			public void run() {
207
				final IStatus[] errorStatus = new IStatus[1];
208
				errorStatus[0] = Status.OK_STATUS;
209
				final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
210
				WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$
211
212
					public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
213
						try {
214
							op.run(monitor);
215
							if (shell != null && !shell.isDisposed()) {
216
								shell.getDisplay().asyncExec(new Runnable() {
217
									public void run() {
218
										StructuredViewer viewer = getActionSite().getStructuredViewer();
219
										if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
220
											viewer.refresh();
221
										}
222
									}
223
								});
224
							}
225
						} catch (InvocationTargetException e) {
226
							String msg = NLS.bind(WorkbenchNavigatorMessages.ResourceMgmtActionProvider_logTitle, getClass().getName(), e.getTargetException());
227
							throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e.getTargetException()));
228
						} catch (InterruptedException e) {
229
							return Status.CANCEL_STATUS;
230
						}
231
						return errorStatus[0];
232
					}
233
234
				};
235
				ISchedulingRule rule = op.getRule();
236
				if (rule != null) {
237
					job.setRule(rule);
238
				}
239
				job.setUser(true);
240
				job.schedule();
241
			}
242
		};
243
		refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));//$NON-NLS-1$
244
		refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));//$NON-NLS-1$
245
		refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
246
247
		buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
248
		buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
249
	}
250
251
	/**
252
	 * Returns the image descriptor with the given relative path.
253
	 */
254
	protected ImageDescriptor getImageDescriptor(String relativePath) {
255
		return IDEWorkbenchPlugin.getIDEImageDescriptor(relativePath);
256
257
	}
258
259
	public void updateActionBars() {
260
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
261
		refreshAction.selectionChanged(selection);
262
		buildAction.selectionChanged(selection);
263
		openProjectAction.selectionChanged(selection);
264
		closeUnrelatedProjectsAction.selectionChanged(selection);
265
		closeProjectAction.selectionChanged(selection);
266
	}
267
268
}
(-)plugin.xml (-1 / +1 lines)
Lines 221-227 Link Here
221
        </actionProvider>
221
        </actionProvider>
222
        
222
        
223
        <actionProvider
223
        <actionProvider
224
              class="org.eclipse.ui.internal.navigator.resources.actions.ResourceMgmtActionProvider"
224
              class="org.eclipse.ui.navigator.resources.actions.ResourceMgmtActionProvider"
225
              id="org.eclipse.ui.navigator.resources.ResourceMgmtActions">
225
              id="org.eclipse.ui.navigator.resources.ResourceMgmtActions">
226
           <enablement>
226
           <enablement>
227
                <or>
227
                <or>
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 11-17 Link Here
11
 org.eclipse.ui.internal.navigator.resources.plugin;x-internal:=true,
11
 org.eclipse.ui.internal.navigator.resources.plugin;x-internal:=true,
12
 org.eclipse.ui.internal.navigator.resources.workbench;x-internal:=true,
12
 org.eclipse.ui.internal.navigator.resources.workbench;x-internal:=true,
13
 org.eclipse.ui.internal.navigator.workingsets;x-internal:=true,
13
 org.eclipse.ui.internal.navigator.workingsets;x-internal:=true,
14
 org.eclipse.ui.navigator.resources
14
 org.eclipse.ui.navigator.resources,
15
 org.eclipse.ui.navigator.resources.actions
15
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
16
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
16
 org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
17
 org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
17
 org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
18
 org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
(-)src/org/eclipse/ui/navigator/resources/actions/RefreshResourceAction.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.navigator.resources.actions;
13
14
import java.lang.reflect.InvocationTargetException;
15
16
import org.eclipse.core.resources.WorkspaceJob;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.jobs.ISchedulingRule;
22
import org.eclipse.jface.viewers.StructuredViewer;
23
import org.eclipse.jface.window.IShellProvider;
24
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.actions.RefreshAction;
27
import org.eclipse.ui.actions.WorkspaceModifyOperation;
28
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
29
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
30
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
31
import org.eclipse.ui.navigator.resources.ProjectExplorer;
32
33
/**
34
 * The default refresh action of the {@link ProjectExplorer}
35
 * 
36
 * @since 3.6
37
 */
38
public class RefreshResourceAction extends RefreshAction {
39
40
	private Shell shell;
41
	private ICommonActionExtensionSite actionSite;
42
43
	public RefreshResourceAction(IShellProvider provider, ICommonActionExtensionSite commonActionSite) {
44
		super(provider);
45
		shell = provider.getShell();
46
		this.actionSite = commonActionSite;
47
	}
48
49
	public void run() {
50
		final IStatus[] errorStatus = new IStatus[1];
51
		errorStatus[0] = Status.OK_STATUS;
52
		final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
53
		WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$
54
55
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
56
				try {
57
					op.run(monitor);
58
					if (shell != null && !shell.isDisposed()) {
59
						shell.getDisplay().asyncExec(new Runnable() {
60
							public void run() {
61
								StructuredViewer viewer = actionSite.getStructuredViewer();
62
								if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
63
									viewer.refresh();
64
								}
65
							}
66
						});
67
					}
68
				} catch (InvocationTargetException e) {
69
					String msg = NLS.bind(WorkbenchNavigatorMessages.ResourceMgmtActionProvider_logTitle, getClass()
70
							.getName(), e.getTargetException());
71
					throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e
72
							.getTargetException()));
73
				} catch (InterruptedException e) {
74
					return Status.CANCEL_STATUS;
75
				}
76
				return errorStatus[0];
77
			}
78
79
		};
80
		ISchedulingRule rule = op.getRule();
81
		if (rule != null) {
82
			job.setRule(rule);
83
		}
84
		job.setUser(true);
85
		job.schedule();
86
	}
87
}
(-)src/org/eclipse/ui/navigator/resources/actions/ResourceMgmtActionProvider.java (+262 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.navigator.resources.actions;
13
14
import java.util.Iterator;
15
16
import org.eclipse.core.resources.ICommand;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IncrementalProjectBuilder;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.jface.action.IMenuManager;
23
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.window.IShellProvider;
26
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IWorkbenchCommandConstants;
29
import org.eclipse.ui.actions.ActionFactory;
30
import org.eclipse.ui.actions.BuildAction;
31
import org.eclipse.ui.actions.CloseResourceAction;
32
import org.eclipse.ui.actions.CloseUnrelatedProjectsAction;
33
import org.eclipse.ui.actions.OpenResourceAction;
34
import org.eclipse.ui.actions.SelectionListenerAction;
35
import org.eclipse.ui.ide.IDEActionFactory;
36
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
37
import org.eclipse.ui.navigator.CommonActionProvider;
38
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
39
import org.eclipse.ui.navigator.ICommonMenuConstants;
40
import org.eclipse.ui.navigator.resources.ProjectExplorer;
41
42
/**
43
 * The default resource action provider of the {@link ProjectExplorer}.<br>
44
 * <br>
45
 * It provides : refresh, open, close, and build action on a project.
46
 * 
47
 * @since 3.2
48
 */
49
public class ResourceMgmtActionProvider extends CommonActionProvider {
50
51
	protected static final String DISABLE_REFRESH_ACTION_RELATIVE_PATH = "dlcl16/refresh_nav.gif";//$NON-NLS-1$
52
53
	protected static final String ENABLE_REFRESH_ACTION_RELATIVE_PATH = "elcl16/refresh_nav.gif";//$NON-NLS-1$
54
55
	private BuildAction buildAction;
56
57
	private SelectionListenerAction openProjectAction;
58
59
	private SelectionListenerAction closeProjectAction;
60
61
	private SelectionListenerAction closeUnrelatedProjectsAction;
62
63
	private SelectionListenerAction refreshAction;
64
65
	private Shell shell;
66
67
	/*
68
	 * (non-Javadoc)
69
	 * 
70
	 * @see
71
	 * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator
72
	 * .ICommonActionExtensionSite)
73
	 */
74
	public void init(ICommonActionExtensionSite aSite) {
75
		super.init(aSite);
76
		shell = aSite.getViewSite().getShell();
77
		makeActions();
78
	}
79
80
	public void fillActionBars(IActionBars actionBars) {
81
		actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
82
		actionBars.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), buildAction);
83
		actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), openProjectAction);
84
		actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), closeProjectAction);
85
		actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(),
86
				closeUnrelatedProjectsAction);
87
		updateActionBars();
88
	}
89
90
	/**
91
	 * Adds the build, open project, close project and refresh resource actions
92
	 * to the context menu.
93
	 * <p>
94
	 * The following conditions apply: build-only projects selected, auto build
95
	 * disabled, at least one builder present open project-only projects
96
	 * selected, at least one closed project close project-only projects
97
	 * selected, at least one open project refresh-no closed project selected
98
	 * </p>
99
	 * <p>
100
	 * Both the open project and close project action may be on the menu at the
101
	 * same time.
102
	 * </p>
103
	 * <p>
104
	 * No disabled action should be on the context menu.
105
	 * </p>
106
	 * 
107
	 * @param menu
108
	 *            context menu to add actions to
109
	 */
110
	public void fillContextMenu(IMenuManager menu) {
111
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
112
		boolean isProjectSelection = true;
113
		boolean hasOpenProjects = false;
114
		boolean hasClosedProjects = false;
115
		boolean hasBuilder = true; // false if any project is closed or does not
116
		// have builder
117
		Iterator resources = selection.iterator();
118
119
		while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
120
			Object next = resources.next();
121
			IProject project = null;
122
123
			if (next instanceof IProject) {
124
				project = (IProject) next;
125
			} else if (next instanceof IAdaptable) {
126
				project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
127
			}
128
129
			if (project == null) {
130
				isProjectSelection = false;
131
				continue;
132
			}
133
			if (project.isOpen()) {
134
				hasOpenProjects = true;
135
				if (hasBuilder && !hasBuilder(project)) {
136
					hasBuilder = false;
137
				}
138
			} else {
139
				hasClosedProjects = true;
140
				hasBuilder = false;
141
			}
142
		}
143
		if (!selection.isEmpty() && isProjectSelection && !ResourcesPlugin.getWorkspace().isAutoBuilding()
144
				&& hasBuilder) {
145
			// Allow manual incremental build only if auto build is off.
146
			buildAction.selectionChanged(selection);
147
			menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, buildAction);
148
		}
149
		if (!hasClosedProjects) {
150
			refreshAction.selectionChanged(selection);
151
			menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, refreshAction);
152
		}
153
		if (isProjectSelection) {
154
			if (hasClosedProjects) {
155
				openProjectAction.selectionChanged(selection);
156
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, openProjectAction);
157
			}
158
			if (hasOpenProjects) {
159
				closeProjectAction.selectionChanged(selection);
160
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, closeProjectAction);
161
				closeUnrelatedProjectsAction.selectionChanged(selection);
162
				menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, closeUnrelatedProjectsAction);
163
			}
164
		}
165
	}
166
167
	/**
168
	 * Returns whether there are builders configured on the given project.
169
	 * 
170
	 * @return <code>true</code> if it has builders, <code>false</code> if not,
171
	 *         or if this could not be determined
172
	 */
173
	boolean hasBuilder(IProject project) {
174
		try {
175
			ICommand[] commands = project.getDescription().getBuildSpec();
176
			if (commands.length > 0) {
177
				return true;
178
			}
179
		} catch (CoreException e) {
180
			// Cannot determine if project has builders. Project is closed
181
			// or does not exist. Fall through to return false.
182
		}
183
		return false;
184
	}
185
186
	protected void makeActions() {
187
		IShellProvider sp = new IShellProvider() {
188
			public Shell getShell() {
189
				return shell;
190
			}
191
		};
192
193
		openProjectAction = createOpenProjectAction(sp);
194
195
		closeProjectAction = createCloseProjectAction(sp);
196
197
		closeUnrelatedProjectsAction = createCloseUnrelatedProjectsAction(sp);
198
199
		refreshAction = createRefreshAction(sp);
200
201
		buildAction = createBuildAction(sp);
202
	}
203
204
	/**
205
	 * create the 'open project' action
206
	 */
207
	protected SelectionListenerAction createOpenProjectAction(IShellProvider sp) {
208
		return new OpenResourceAction(sp);
209
	}
210
211
	/**
212
	 * create 'close project' action
213
	 */
214
	private SelectionListenerAction createCloseProjectAction(IShellProvider sp) {
215
		return new CloseResourceAction(sp);
216
	}
217
218
	/**
219
	 * create the 'Close Unrelated projects' action
220
	 */
221
	private SelectionListenerAction createCloseUnrelatedProjectsAction(IShellProvider sp) {
222
		return new CloseUnrelatedProjectsAction(sp);
223
	}
224
225
	/**
226
	 * create 'refresh resource' action
227
	 */
228
	private SelectionListenerAction createRefreshAction(IShellProvider sp) {
229
		RefreshResourceAction refreshResourceAction = new RefreshResourceAction(sp, getActionSite());
230
		refreshResourceAction.setDisabledImageDescriptor(getImageDescriptor(DISABLE_REFRESH_ACTION_RELATIVE_PATH));
231
		refreshResourceAction.setImageDescriptor(getImageDescriptor(ENABLE_REFRESH_ACTION_RELATIVE_PATH));
232
		refreshResourceAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
233
		return refreshResourceAction;
234
	}
235
236
	/**
237
	 * create 'build project' action
238
	 */
239
	protected BuildAction createBuildAction(IShellProvider sp) {
240
		BuildAction buildProjectAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
241
		buildProjectAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
242
		return buildProjectAction;
243
	}
244
245
	/**
246
	 * Returns the image descriptor with the given relative path.
247
	 */
248
	protected ImageDescriptor getImageDescriptor(String relativePath) {
249
		return IDEWorkbenchPlugin.getIDEImageDescriptor(relativePath);
250
251
	}
252
253
	public void updateActionBars() {
254
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
255
		refreshAction.selectionChanged(selection);
256
		buildAction.selectionChanged(selection);
257
		openProjectAction.selectionChanged(selection);
258
		closeUnrelatedProjectsAction.selectionChanged(selection);
259
		closeProjectAction.selectionChanged(selection);
260
	}
261
262
}

Return to bug 298676