KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > CompareRemoteResourcesAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 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 package org.eclipse.team.internal.ccvs.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.CompareUI;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.team.internal.ccvs.core.CVSException;
18 import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
19 import org.eclipse.team.internal.ccvs.ui.CVSCompareEditorInput;
20 import org.eclipse.team.internal.ccvs.ui.ResourceEditionNode;
21 import org.eclipse.team.internal.ccvs.ui.operations.RemoteCompareOperation;
22
23 /**
24  * This action is used for comparing two arbitrary remote resources. This is
25  * enabled in the repository explorer.
26  */

27 public class CompareRemoteResourcesAction extends CVSAction {
28
29     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
30         ICVSRemoteResource[] editions = getSelectedRemoteResources();
31         if (editions == null || editions.length != 2) {
32             return;
33         }
34         try {
35             if (isSameFolder(editions)) {
36                 RemoteCompareOperation.create(null, editions[0], RemoteCompareOperation.getTag(editions[1])).run();
37             } else {
38                 ResourceEditionNode left = new ResourceEditionNode(editions[0]);
39                 ResourceEditionNode right = new ResourceEditionNode(editions[1]);
40                 CompareUI.openCompareEditorOnPage(new CVSCompareEditorInput(left, right), getTargetPage());
41             }
42         } catch (CVSException e) {
43             throw new InvocationTargetException JavaDoc(e);
44         }
45     }
46
47     protected boolean isSameFolder(ICVSRemoteResource[] editions) {
48         return editions[0].isContainer() && editions[0].getRepository().equals(editions[1].getRepository())
49                 && editions[0].getRepositoryRelativePath().equals(editions[1].getRepositoryRelativePath());
50     }
51     
52     /*
53      * @see TeamAction#isEnabled()
54      */

55     public boolean isEnabled() {
56         ICVSRemoteResource[] resources = getSelectedRemoteResources();
57         if (resources.length != 2) return false;
58         if (resources[0].isContainer() != resources[1].isContainer()) return false;
59         // Don't allow comparisons of two unrelated remote projects
60
return !resources[0].isContainer() || isSameFolder(resources);
61     }
62
63 }
64
Popular Tags