KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.action.IAction;
16 import org.eclipse.jface.window.Window;
17 import org.eclipse.swt.widgets.Display;
18 import org.eclipse.team.internal.ccvs.core.CVSException;
19 import org.eclipse.team.internal.ccvs.core.ICVSResource;
20 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
22 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
23 import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;
24
25 public class ReplaceWithRemoteAction extends WorkspaceTraversalAction {
26     
27     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
28         
29         final ReplaceOperation replaceOperation = new ReplaceOperation(getTargetPart(), getCVSResourceMappings(), null);
30         if (hasOutgoingChanges(replaceOperation)) {
31             final boolean[] keepGoing = new boolean[] { true };
32             Display.getDefault().syncExec(new Runnable JavaDoc() {
33                 public void run() {
34                     OutgoingChangesDialog dialog = new OutgoingChangesDialog(getShell(), replaceOperation.getScopeManager(),
35                             CVSUIMessages.ReplaceWithTagAction_2,
36                             CVSUIMessages.ReplaceWithTagAction_0,
37                             CVSUIMessages.ReplaceWithTagAction_1);
38                     dialog.setHelpContextId(IHelpContextIds.REPLACE_OUTGOING_CHANGES_DIALOG);
39                     int result = dialog.open();
40                     keepGoing[0] = result == Window.OK;
41                 }
42             });
43             if (!keepGoing[0])
44                 return;
45         }
46         replaceOperation.run();
47     }
48     
49     /**
50      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
51      */

52     protected String JavaDoc getErrorTitle() {
53         return CVSUIMessages.ReplaceWithRemoteAction_problemMessage;
54     }
55
56     /**
57      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForAddedResources()
58      */

59     protected boolean isEnabledForAddedResources() {
60         return false;
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
65      */

66     protected boolean isEnabledForNonExistantResources() {
67         return true;
68     }
69     
70     /**
71      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForCVSResource(org.eclipse.team.internal.ccvs.core.ICVSResource)
72      */

73     protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
74         if (super.isEnabledForCVSResource(cvsResource)) {
75             // Don't enable if there are sticky file revisions in the lineup
76
if (!cvsResource.isFolder()) {
77                 ResourceSyncInfo info = cvsResource.getSyncInfo();
78                 if (info != null && info.getTag() != null) {
79                     String JavaDoc revision = info.getRevision();
80                     String JavaDoc tag = info.getTag().getName();
81                     if (revision.equals(tag)) return false;
82                 }
83             }
84             return true;
85         } else {
86             return false;
87         }
88     }
89
90     /*
91      * Update the text label for the action based on the tags in the
92      * selection.
93      *
94      * @see TeamAction#setActionEnablement(org.eclipse.jface.action.IAction)
95      */

96     protected void setActionEnablement(IAction action) {
97         super.setActionEnablement(action);
98         
99         action.setText(calculateActionTagValue());
100     }
101 }
102
Popular Tags