Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/eclipse/builder/RefreshAllAction.java


1   package com.port80.eclipse.builder;
2   
3   import java.lang.reflect.InvocationTargetException;
4   
5   import org.eclipse.core.internal.resources.Project;
6   import org.eclipse.core.internal.utils.Policy;
7   import org.eclipse.core.resources.IProject;
8   import org.eclipse.core.resources.IResource;
9   import org.eclipse.core.resources.IWorkspaceRoot;
10  import org.eclipse.core.resources.ResourcesPlugin;
11  import org.eclipse.core.runtime.IProgressMonitor;
12  import org.eclipse.core.runtime.SubProgressMonitor;
13  import org.eclipse.jface.action.IAction;
14  import org.eclipse.jface.dialogs.ProgressMonitorDialog;
15  import org.eclipse.jface.operation.IRunnableWithProgress;
16  import org.eclipse.jface.viewers.ISelection;
17  import org.eclipse.ui.IWorkbenchWindow;
18  import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19  
20  /**
21   * Insert the type's description here.
22   * @see IWorkbenchWindowActionDelegate
23   */
24  public class RefreshAllAction implements IWorkbenchWindowActionDelegate {
25  
26      private IWorkbenchWindow window;
27  
28      /**
29       * The constructor.
30       */
31      public RefreshAllAction() {
32      }
33  
34      /**
35       * Insert the method's description here.
36       * @see IWorkbenchWindowActionDelegate#run
37       */
38      public void run(IAction action) {
39          try {
40              IRunnableWithProgress op = new IRunnableWithProgress() {
41                  public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
42                      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
43                      IProject[] projects = workspaceRoot.getProjects();
44                      monitor.beginTask("Refresh all projects ...", projects.length*100);
45                      for (int i = 0; i < projects.length; ++i) {
46                          IProject project = projects[i];
47                          monitor.subTask(project.getName());
48                          //Thread.sleep(1000);
49                          try {
50                              ((Project) project).refreshLocal(
51                                  IResource.DEPTH_INFINITE,
52                                  Policy.subMonitorFor(
53                                      monitor,
54                                      100,
55                                      SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
56                          } catch (Exception e) {
57                          } finally {
58                              //Thread.sleep(1000);
59                          }
60                      }
61                      monitor.done();
62                  }
63              };
64              new ProgressMonitorDialog(window.getShell()).run(true, true, op);
65          } catch (InvocationTargetException e) {
66              // handle exception
67          } catch (InterruptedException e) {
68              // handle cancelation
69          }
70      }
71      /**
72        * Insert the method's description here.
73        * @see IWorkbenchWindowActionDelegate#selectionChanged
74        */
75      public void selectionChanged(IAction action, ISelection select) {
76      }
77  
78      /**
79       * Insert the method's description here.
80       * @see IWorkbenchWindowActionDelegate#dispose
81       */
82      public void dispose() {
83      }
84  
85      /**
86       * Insert the method's description here.
87       * @see IWorkbenchWindowActionDelegate#init
88       */
89      public void init(IWorkbenchWindow window) {
90          this.window = window;
91      }
92  }