~piastucki/bzr-eclipse/history-view-enhancements

« back to all changes in this revision

Viewing changes to src/org/vcs/bazaar/eclipse/team/ActionRevert.java

  • Committer: Guillermo Gonzalez
  • Date: 2007-03-14 12:15:50 UTC
  • Revision ID: guillo.gonzo@gmail.com-20070314121550-tltk3b6f3zblf0dh
Initial commit with the new code layout.
Now starts the real work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * org.vcs.bazaar.eclipse (c) Vectrace Sep 12, 2006
3
 
 * Created by zingo
4
 
 */
5
 
package org.vcs.bazaar.eclipse.team;
6
 
 
7
 
 
8
 
import java.util.Iterator;
9
 
 
10
 
import org.eclipse.core.resources.IMarkerDelta;
11
 
import org.eclipse.core.resources.IProject;
12
 
import org.eclipse.core.resources.IResource;
13
 
import org.eclipse.core.resources.IResourceChangeEvent;
14
 
import org.eclipse.core.resources.IResourceDelta;
15
 
import org.eclipse.core.resources.IWorkspace;
16
 
import org.eclipse.core.resources.IWorkspaceRunnable;
17
 
import org.eclipse.core.resources.ResourcesPlugin;
18
 
import org.eclipse.core.runtime.CoreException;
19
 
import org.eclipse.core.runtime.IProgressMonitor;
20
 
import org.eclipse.jface.action.IAction;
21
 
import org.eclipse.jface.viewers.ISelection;
22
 
import org.eclipse.jface.viewers.IStructuredSelection;
23
 
import org.eclipse.ui.IWorkbenchWindow;
24
 
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
25
 
 
26
 
 
27
 
/**
28
 
 * @author zingo
29
 
 *
30
 
 */
31
 
 
32
 
public class ActionRevert implements IWorkbenchWindowActionDelegate {
33
 
 
34
 
//  private IWorkbenchWindow window;
35
 
//    private IWorkbenchPart targetPart;
36
 
    private IStructuredSelection selection;
37
 
    
38
 
  public ActionRevert() {
39
 
    super();
40
 
  }
41
 
 
42
 
  /**
43
 
   * We can use this method to dispose of any system
44
 
   * resources we previously allocated.
45
 
   * @see IWorkbenchWindowActionDelegate#dispose
46
 
   */
47
 
  public void dispose() {
48
 
 
49
 
  }
50
 
 
51
 
 
52
 
  /**
53
 
   * We will cache window object in order to
54
 
   * be able to provide parent shell for the message dialog.
55
 
   * @see IWorkbenchWindowActionDelegate#init
56
 
   */
57
 
  public void init(IWorkbenchWindow window) {
58
 
    System.out.println("ActionAdd:init(window)");
59
 
//    this.window = window;
60
 
  }
61
 
 
62
 
  /**
63
 
   * The action has been activated. The argument of the
64
 
   * method represents the 'real' action sitting
65
 
   * in the workbench UI.
66
 
   * @see IWorkbenchWindowActionDelegate#run
67
 
   */
68
 
  
69
 
 
70
 
  public void run(IAction action) 
71
 
  {
72
 
    IProject proj;
73
 
    proj=BazaarUtilities.getProject(selection);
74
 
    
75
 
    System.out.println("Revert:");
76
 
 
77
 
   
78
 
//    IWorkspaceRunnable myRunnable = new IWorkspaceRunnable() 
79
 
    {
80
 
//      public void run(IProgressMonitor monitor) throws CoreException 
81
 
      {
82
 
        Object obj;
83
 
        Iterator itr; 
84
 
        String FullPath;
85
 
        String Repository;
86
 
//        IProject proj;
87
 
        System.out.println("Revert in runnable");
88
 
        proj=BazaarUtilities.getProject(selection);
89
 
        Repository=BazaarUtilities.getRepositoryPath(proj);
90
 
        if(Repository==null)
91
 
        {
92
 
          Repository="."; //never leave this empty add a . to point to current path
93
 
        }
94
 
 
95
 
        // the last argument will be replaced with a path
96
 
        String launchCmd[] = { BazaarUtilities.getBzrExecutable(), "revert", "" };
97
 
 
98
 
        
99
 
        //do the actual work in here
100
 
        itr=selection.iterator();
101
 
        while(itr.hasNext())
102
 
        {
103
 
          obj=itr.next();
104
 
          if (obj instanceof IResource)
105
 
          {
106
 
            IResource resource=(IResource) obj;
107
 
          //Setup and run command
108
 
            FullPath=resource.getLocation().toString();
109
 
            launchCmd[2]=FullPath;
110
 
            System.out.println("Revert = " + FullPath);
111
 
//            IResourceChangeEvent event = new IResourceChangeEvent();
112
 
      
113
 
            try
114
 
            {
115
 
              resource.touch(null);
116
 
            }
117
 
            catch (CoreException e)
118
 
            {
119
 
              e.printStackTrace();
120
 
            } 
121
 
            BazaarUtilities.ExecuteCommand(launchCmd,true);          
122
 
            try
123
 
            {
124
 
              resource.touch(null);
125
 
            }
126
 
            catch (CoreException e)
127
 
            {
128
 
              e.printStackTrace();
129
 
            } 
130
 
          }
131
 
        }
132
 
//        notify();
133
 
        DecoratorStatus.refresh();
134
 
        
135
 
    }
136
 
  } //;
137
 
//  IWorkspace workspace = ResourcesPlugin.getWorkspace();
138
 
//  try
139
 
//  {
140
 
//    workspace.run(myRunnable, proj, IWorkspace.AVOID_UPDATE, null);
141
 
//    try
142
 
//    {
143
 
//      myRunnable.wait();
144
 
//    }
145
 
//    catch (InterruptedException e)
146
 
//    {
147
 
//      e.printStackTrace();
148
 
//    }
149
 
//  }
150
 
//  catch (CoreException e)
151
 
//  {
152
 
//    e.printStackTrace();
153
 
//  }
154
 
 
155
 
  }
156
 
  /**
157
 
   * Selection in the workbench has been changed. We 
158
 
   * can change the state of the 'real' action here
159
 
   * if we want, but this can only happen after 
160
 
   * the delegate has been created.
161
 
   * @see IWorkbenchWindowActionDelegate#selectionChanged
162
 
   */
163
 
  public void selectionChanged(IAction action, ISelection in_selection) 
164
 
  {
165
 
    if( in_selection != null && in_selection instanceof IStructuredSelection )
166
 
    {
167
 
      selection = ( IStructuredSelection )in_selection;
168
 
    }
169
 
  }
170
 
 
171
 
 
172
 
  
173
 
}