1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.repo;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.actions.CVSAction;
/**
* Action to add a root remote folder to a branch
*/
public class AddToBranchAction extends CVSAction {
IInputValidator validator = new IInputValidator() {
public String isValid(String newText) {
IStatus status = CVSTag.validateTagName(newText);
if (status.isOK()) return null;
return status.getMessage();
}
};
/**
* @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#execute(org.eclipse.jface.action.IAction)
*/
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
run(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
final ICVSRemoteFolder folder = getSelectedRootFolder();
if (folder == null) return;
Shell shell = getShell();
final CVSException[] exception = new CVSException[] { null };
shell.getDisplay().syncExec(new Runnable() {
public void run() {
InputDialog dialog = new InputDialog(getShell(), CVSUIMessages.AddToBranchAction_enterTag, CVSUIMessages.AddToBranchAction_enterTagLong, null, validator); //
if (dialog.open() == Window.OK) {
CVSTag tag = new CVSTag(dialog.getValue(), CVSTag.BRANCH);
try {
CVSUIPlugin.getPlugin().getRepositoryManager().addTags(folder, new CVSTag[] {tag});
} catch (CVSException e) {
exception[0] = e;
}
}
}
});
if (exception[0] != null)
throw new InvocationTargetException(exception[0]);
}
}, false, PROGRESS_BUSYCURSOR);
}
/**
* @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
*/
public boolean isEnabled() {
return getSelectedRootFolder() != null;
}
protected ICVSRemoteFolder getSelectedRootFolder() {
ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
ICVSRemoteFolder selectedFolder = null;
for (int i = 0; i < folders.length; i++) {
ICVSRemoteFolder folder = folders[i];
if (folder.isDefinedModule() || new Path(null, folder.getRepositoryRelativePath()).segmentCount()==1) {
// only return a folder if one valid one is selected.
if (selectedFolder != null) return null;
selectedFolder = folder;
}
}
return selectedFolder;
}
}
|