KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > repo > AddToBranchAction


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.repo;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.dialogs.IInputValidator;
18 import org.eclipse.jface.dialogs.InputDialog;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.team.internal.ccvs.core.*;
23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
24 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
25 import org.eclipse.team.internal.ccvs.ui.actions.CVSAction;
26
27 /**
28  * Action to add a root remote folder to a branch
29  */

30 public class AddToBranchAction extends CVSAction {
31
32     IInputValidator validator = new IInputValidator() {
33         public String JavaDoc isValid(String JavaDoc newText) {
34             IStatus status = CVSTag.validateTagName(newText);
35             if (status.isOK()) return null;
36             return status.getMessage();
37         }
38     };
39     
40     /**
41      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#execute(org.eclipse.jface.action.IAction)
42      */

43     protected void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
44         run(new IRunnableWithProgress() {
45             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
46                 final ICVSRemoteFolder folder = getSelectedRootFolder();
47                 if (folder == null) return;
48                 Shell shell = getShell();
49                 final CVSException[] exception = new CVSException[] { null };
50                 shell.getDisplay().syncExec(new Runnable JavaDoc() {
51                     public void run() {
52                         InputDialog dialog = new InputDialog(getShell(), CVSUIMessages.AddToBranchAction_enterTag, CVSUIMessages.AddToBranchAction_enterTagLong, null, validator); //
53
if (dialog.open() == Window.OK) {
54                             CVSTag tag = new CVSTag(dialog.getValue(), CVSTag.BRANCH);
55                             try {
56                                 CVSUIPlugin.getPlugin().getRepositoryManager().addTags(folder, new CVSTag[] {tag});
57                             } catch (CVSException e) {
58                                 exception[0] = e;
59                             }
60                         }
61                     }
62                 });
63                 if (exception[0] != null)
64                     throw new InvocationTargetException JavaDoc(exception[0]);
65             }
66         }, false, PROGRESS_BUSYCURSOR);
67     }
68
69     /**
70      * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
71      */

72     public boolean isEnabled() {
73         return getSelectedRootFolder() != null;
74     }
75
76     protected ICVSRemoteFolder getSelectedRootFolder() {
77         ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
78         ICVSRemoteFolder selectedFolder = null;
79         for (int i = 0; i < folders.length; i++) {
80             ICVSRemoteFolder folder = folders[i];
81             if (folder.isDefinedModule() || new Path(null, folder.getRepositoryRelativePath()).segmentCount()==1) {
82                 // only return a folder if one valid one is selected.
83
if (selectedFolder != null) return null;
84                 selectedFolder = folder;
85             }
86         }
87         return selectedFolder;
88     }
89 }
90
Popular Tags