Debian Codegraph @

doc/org.eclipse.emf.cheatsheets/src/org/eclipse/emf/cheatsheets/actions/BuildAllProjectsAction.java

raw
1 /**
2 * Copyright (c) 2006 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 v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.cheatsheets.actions;
12
13 import java.lang.reflect.InvocationTargetException;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IWorkspace;
17 import org.eclipse.core.resources.IWorkspaceRoot;
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.IProgressMonitor;
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
24 import org.eclipse.jface.operation.IRunnableWithProgress;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.ui.actions.WorkspaceModifyOperation;
27 import org.eclipse.ui.cheatsheets.ICheatSheetAction;
28 import org.eclipse.ui.cheatsheets.ICheatSheetManager;
29
30 import org.eclipse.emf.cheatsheets.CheatSheetsPlugin;
31 import org.eclipse.emf.common.util.BasicMonitor;
32
33
34 /**
35 * <p>Action that builds all projects on Workspace.</p>
36 * @since 2.2.0
37 */
38
39 public class BuildAllProjectsAction extends Action implements ICheatSheetAction
40 {
41 /**
42 * Execution of the action
43 * @param params Array of parameters
44 * @param manager Cheatsheet Manager
45 */
46 public void run(String[] params, ICheatSheetManager manager)
47 {
48 run();
49 }
50
51 /**
52 * Run the action
53 */
54 @Override
55 public void run()
56 {
57 WorkspaceModifyOperation operation = new WorkspaceModifyOperation()
58 {
59 @Override
60 protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException
61 {
62 buildAllProjects(monitor);
63 }
64 };
65 try
66 {
67 runWithProgress(operation);
68 notifyResult(true);
69 return;
70 }
71 catch (Exception e)
72 {
73 CheatSheetsPlugin.INSTANCE.log(e);
74 }
75 notifyResult(false);
76 }
77
78 /**
79 * Run with progress
80 * @param runnable
81 * @throws InvocationTargetException
82 * @throws InterruptedException
83 */
84 protected void runWithProgress(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
85 {
86 new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(false, false, runnable);
87 }
88
89 /**
90 * Build all projects in the workspace
91 * @param monitor Monitoring the action
92 * @throws CoreException
93 */
94 protected void buildAllProjects(IProgressMonitor monitor) throws CoreException
95 {
96 IWorkspace workspace = ResourcesPlugin.getWorkspace();
97 IWorkspaceRoot root = workspace.getRoot();
98 IProject[] projects = root.getProjects();
99 monitor.beginTask(CheatSheetsPlugin.INSTANCE.getString("_UI_BuildProject_message"), projects.length);
100 for (int i = 0; i < projects.length; i++)
101 {
102 projects[i].build(IncrementalProjectBuilder.INCREMENTAL_BUILD, BasicMonitor.subProgress(monitor, 1));
103 }
104 monitor.done();
105 }
106 }