KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.team.internal.ccvs.core.CVSTag;
22 import org.eclipse.team.internal.ccvs.ui.*;
23 import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;
24
25 /**
26  * Action for replace with tag.
27  */

28 public abstract class ReplaceWithTagAction extends WorkspaceTraversalAction {
29     
30     /*
31      * Method declared on IActionDelegate.
32      */

33     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
34         
35         // Setup the holders
36
final CVSTag[] tag = new CVSTag[] {null};
37         
38         final ReplaceOperation replaceOperation = new ReplaceOperation(getTargetPart(), getCVSResourceMappings(), tag[0]);
39         if (hasOutgoingChanges(replaceOperation)) {
40             final boolean[] keepGoing = new boolean[] { true };
41             Display.getDefault().syncExec(new Runnable JavaDoc() {
42                 public void run() {
43                     OutgoingChangesDialog dialog = new OutgoingChangesDialog(getShell(), replaceOperation.getScopeManager(),
44                             CVSUIMessages.ReplaceWithTagAction_2,
45                             CVSUIMessages.ReplaceWithTagAction_0,
46                             CVSUIMessages.ReplaceWithTagAction_1);
47                     dialog.setHelpContextId(IHelpContextIds.REPLACE_OUTGOING_CHANGES_DIALOG);
48                     int result = dialog.open();
49                     keepGoing[0] = result == Window.OK;
50                 }
51             });
52             if (!keepGoing[0])
53                 return;
54         }
55         
56         // Show a busy cursor while display the tag selection dialog
57
run(new IRunnableWithProgress() {
58             public void run(IProgressMonitor monitor) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
59                 monitor = Policy.monitorFor(monitor);
60                 tag[0] = getTag(replaceOperation);
61                 
62                 // For non-projects determine if the tag being loaded is the same as the resource's parent
63
// If it's not, warn the user that they will have strange sync behavior
64
try {
65                     if(!CVSAction.checkForMixingTags(getShell(), replaceOperation.getScope().getRoots(), tag[0])) {
66                         tag[0] = null;
67                         return;
68                     }
69                 } catch (CoreException e) {
70                     throw new InvocationTargetException JavaDoc(e);
71                 }
72             }
73         }, false /* cancelable */, PROGRESS_BUSYCURSOR);
74         
75         if (tag[0] == null) return;
76         
77         // Perform the replace in the background
78
replaceOperation.setTag(tag[0]);
79         replaceOperation.run();
80     }
81     
82     /**
83      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
84      */

85     protected String JavaDoc getErrorTitle() {
86         return CVSUIMessages.ReplaceWithTagAction_replace;
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
91      */

92     protected boolean isEnabledForNonExistantResources() {
93         return true;
94     }
95     
96     /**
97      * This function should obtain a tag which user wants to load.
98      * @param replaceOperation
99      * replaceOperation is an operation for which the tag is obtained
100      * @return tag
101      * marks the resources revision the user wants to load
102      */

103     abstract protected CVSTag getTag(final ReplaceOperation replaceOperation);
104     
105 }
106
Popular Tags