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

« back to all changes in this revision

Viewing changes to src/org/vcs/bazaar/eclipse/team/ActionDiff.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 Jan 31, 2006
3
 
 * Created by zingo
4
 
 */
5
 
package org.vcs.bazaar.eclipse.team;
6
 
 
7
 
import java.util.ArrayList;
8
 
import java.util.Arrays;
9
 
import java.util.Iterator;
10
 
import java.util.List;
11
 
 
12
 
import org.eclipse.core.resources.IContainer;
13
 
import org.eclipse.core.resources.IProject;
14
 
import org.eclipse.core.resources.IResource;
15
 
import org.eclipse.core.resources.IStorage;
16
 
import org.eclipse.core.runtime.CoreException;
17
 
import org.eclipse.core.runtime.IProgressMonitor;
18
 
import org.eclipse.jface.action.IAction;
19
 
import org.eclipse.jface.viewers.ISelection;
20
 
import org.eclipse.jface.viewers.IStructuredSelection;
21
 
import org.eclipse.team.core.TeamException;
22
 
import org.eclipse.team.core.subscribers.Subscriber;
23
 
import org.eclipse.team.core.synchronize.SyncInfo;
24
 
import org.eclipse.team.core.variants.IResourceVariant;
25
 
import org.eclipse.team.core.variants.IResourceVariantComparator;
26
 
import org.eclipse.team.ui.synchronize.SyncInfoCompareInput;
27
 
import org.eclipse.ui.IWorkbenchWindow;
28
 
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
29
 
import org.eclipse.compare.CompareUI;
30
 
/**
31
 
 * @author zingo
32
 
 * 
33
 
 */
34
 
public class ActionDiff implements IWorkbenchWindowActionDelegate {
35
 
 
36
 
 
37
 
  public class FileHistoryVariant implements IResourceVariant {
38
 
    private final IStorage myIStorage;
39
 
 
40
 
    public FileHistoryVariant(IStorage res) 
41
 
    {
42
 
     this.myIStorage = res;
43
 
//     System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::FileHistoryVariant()" );
44
 
    }
45
 
 
46
 
    
47
 
    public String getName() 
48
 
    {
49
 
//      System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::getName()" );
50
 
      return myIStorage.getName();
51
 
    }
52
 
 
53
 
    public boolean isContainer() 
54
 
    {
55
 
//      System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::isContainer()" );
56
 
      return false;
57
 
    }
58
 
 
59
 
    public IStorage getStorage(IProgressMonitor monitor) throws TeamException 
60
 
    {
61
 
//      System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::getStorage()" );
62
 
      return myIStorage;
63
 
    }
64
 
 
65
 
    public String getContentIdentifier() 
66
 
    {
67
 
//      System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::getContentIdentifier()" );
68
 
      return myIStorage.getFullPath().toString();
69
 
    }
70
 
 
71
 
    public byte[] asBytes() 
72
 
    {
73
 
//      System.out.println("FileHistoryVariant(" + myIStorage.getName() +")::asBytes() what is this for?" );
74
 
      return null;
75
 
    }
76
 
  }
77
 
  
78
 
   
79
 
  public class MyRepositorySubscriber extends Subscriber 
80
 
  {
81
 
 
82
 
    public class LocalHistoryVariantComparator implements IResourceVariantComparator {
83
 
      public boolean compare(IResource local, IResourceVariant remote) {
84
 
        return false;
85
 
      }
86
 
 
87
 
      public boolean compare(IResourceVariant base, IResourceVariant remote) {
88
 
        return false;
89
 
      }
90
 
 
91
 
      public boolean isThreeWay() {
92
 
        return false;
93
 
      }
94
 
    }
95
 
 
96
 
    
97
 
    LocalHistoryVariantComparator comparatorObj; 
98
 
    
99
 
    public MyRepositorySubscriber()
100
 
    {
101
 
      comparatorObj = new LocalHistoryVariantComparator();
102
 
    }
103
 
    
104
 
    public String getName()
105
 
    {
106
 
      // TODO Auto-generated method stub
107
 
      return "MyRepositorySubscriber";
108
 
    }
109
 
 
110
 
    public boolean isSupervised(IResource resource) throws TeamException
111
 
    {
112
 
      // TODO Auto-generated method stub
113
 
      return false;
114
 
    }
115
 
 
116
 
    public IResource[] members(IResource resource) throws TeamException {
117
 
      try {
118
 
        if(resource.getType() == IResource.FILE)
119
 
          return new IResource[0];
120
 
        IContainer container = (IContainer)resource;
121
 
        List existingChildren = new ArrayList(Arrays.asList(container.members()));
122
 
        existingChildren.addAll(Arrays.asList(container.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, null)));
123
 
        return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]);
124
 
      } catch (CoreException e) {
125
 
        throw TeamException.asTeamException(e);
126
 
      }
127
 
    }
128
 
 
129
 
    public IResource[] roots()
130
 
    {
131
 
      // TODO Auto-generated method stub
132
 
      return null;
133
 
    }
134
 
 
135
 
    /* (non-Javadoc)
136
 
     * @see org.eclipse.team.core.subscribers.Subscriber#getSyncInfo(org.eclipse.core.resources.IResource)
137
 
     */
138
 
    public SyncInfo getSyncInfo(IResource resource) throws TeamException
139
 
    {
140
 
      // TODO Auto-generated method stub
141
 
      return getSyncInfo(resource,null,null);
142
 
    }
143
 
 
144
 
    public SyncInfo getSyncInfo(IResource resource, IStorage r1, IStorage r2) throws TeamException {
145
 
      try {
146
 
  /*
147
 
        IResourceVariant variant = null;
148
 
        if(resource.getType() == IResource.FILE) {
149
 
          IFile file = (IFile)resource;
150
 
          IFileState[] states = file.getHistory(null);
151
 
          if(states.length > 0) {
152
 
            // last state only
153
 
            variant = new LocalHistoryVariant(states[0]);
154
 
          } 
155
 
        }
156
 
        */
157
 
        FileHistoryVariant fileHist1=null;
158
 
        FileHistoryVariant fileHist2=null;
159
 
        if(r1 != null)
160
 
        {
161
 
          fileHist1 = new FileHistoryVariant(r1);
162
 
        }
163
 
        if(r2 != null)
164
 
        {
165
 
          fileHist2 = new FileHistoryVariant(r2);
166
 
        }
167
 
        
168
 
        SyncInfo info = new SyncInfo(resource, fileHist1,fileHist2, comparatorObj);
169
 
        info.init();
170
 
        return info;
171
 
      } catch (CoreException e) {
172
 
        throw TeamException.asTeamException(e);
173
 
      }
174
 
    }
175
 
 
176
 
    public IResourceVariantComparator getResourceComparator()
177
 
    {
178
 
      // TODO Auto-generated method stub
179
 
      return comparatorObj;
180
 
    }
181
 
 
182
 
    public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException
183
 
    {
184
 
      // TODO Auto-generated method stub
185
 
      
186
 
    }
187
 
 
188
 
  }
189
 
 
190
 
  private IWorkbenchWindow window;
191
 
//    private IWorkbenchPart targetPart;
192
 
    private IStructuredSelection selection;
193
 
    
194
 
        public ActionDiff() {
195
 
                super();
196
 
        }
197
 
 
198
 
        /**
199
 
         * We can use this method to dispose of any system
200
 
         * resources we previously allocated.
201
 
         * @see IWorkbenchWindowActionDelegate#dispose
202
 
         */
203
 
        public void dispose() {
204
 
 
205
 
        }
206
 
 
207
 
 
208
 
        /**
209
 
         * We will cache window object in order to
210
 
         * be able to provide parent shell for the message dialog.
211
 
         * @see IWorkbenchWindowActionDelegate#init
212
 
         */
213
 
        public void init(IWorkbenchWindow window) {
214
 
//              System.out.println("ActionDiff:init(window)");
215
 
                this.window = window;
216
 
        }
217
 
 
218
 
        /**
219
 
         * The action has been activated. The argument of the
220
 
         * method represents the 'real' action sitting
221
 
         * in the workbench UI.
222
 
         * @see IWorkbenchWindowActionDelegate#run
223
 
         */
224
 
        
225
 
 
226
 
        public void run(IAction action) 
227
 
        {
228
 
                IProject proj;
229
 
                String Repository;
230
 
    
231
 
    proj=BazaarUtilities.getProject(selection);
232
 
                Repository=BazaarUtilities.getRepositoryPath(proj);
233
 
                if(Repository==null)
234
 
                {
235
 
                        Repository="."; //never leave this empty add a . to point to current path
236
 
                }
237
 
 
238
 
                Object obj;
239
 
          Iterator itr; 
240
 
    // the last argument will be replaced with a path
241
 
    itr=selection.iterator();
242
 
    while(itr.hasNext())
243
 
    {
244
 
        obj=itr.next();
245
 
        if (obj instanceof IResource)
246
 
        {
247
 
 
248
 
        //Setup and run command identify, this us used to get the base changeset to diff against
249
 
        //tip cant be used since work can be done in older reviison ( hg up <old rev> )
250
 
        String FullPath = ( ((IResource) obj).getLocation() ).toString();
251
 
        // TODO: Ver como lo hace bzr
252
 
        String launchCmd[] = { BazaarUtilities.getBzrExecutable(),"revno", FullPath};
253
 
        String revno = BazaarUtilities.ExecuteCommand(launchCmd,false).trim();
254
 
        // It consists of the revision id (hash), optionally a '+' sign
255
 
        // if the working tree has been modified, followed by a list of tags.
256
 
        //    => we need to strip it ...     
257
 
        System.out.println(revno);
258
 
//        if(changeset.indexOf(" ") != -1) //is there a space?
259
 
//        {
260
 
//          changeset = changeset.substring(0,changeset.indexOf(" ")); //take the begining until the first space
261
 
//        }
262
 
//        if(changeset.indexOf("+") != -1) //is there a +?
263
 
//        {
264
 
//          changeset = changeset.substring(0,changeset.indexOf("+")); //take the begining until the first +
265
 
//        }
266
 
 
267
 
        //Setup and run command diff
268
 
        
269
 
        MyRepositorySubscriber subscriber = new MyRepositorySubscriber();
270
 
        try
271
 
        {
272
 
          SyncInfo syncInfo = subscriber.getSyncInfo((IResource)obj,(IStorage)obj,new IStorageBazaarRevision(proj,(IResource)obj,revno));
273
 
          SyncInfoCompareInput comparedialog = new SyncInfoCompareInput("diffelidiff",syncInfo);
274
 
          CompareUI.openCompareEditor( comparedialog );
275
 
        }
276
 
        catch (TeamException e)
277
 
        {
278
 
          e.printStackTrace();
279
 
        }  
280
 
      }
281
 
    }
282
 
        }
283
 
  
284
 
  
285
 
        /**
286
 
         * Selection in the workbench has been changed. We 
287
 
         * can change the state of the 'real' action here
288
 
         * if we want, but this can only happen after 
289
 
         * the delegate has been created.
290
 
         * @see IWorkbenchWindowActionDelegate#selectionChanged
291
 
         */
292
 
        public void selectionChanged(IAction action, ISelection in_selection) 
293
 
        {
294
 
                if( in_selection != null && in_selection instanceof IStructuredSelection )
295
 
                {
296
 
                        selection = ( IStructuredSelection )in_selection;
297
 
                }
298
 
        }
299
 
        
300
 
}