blob: 529f6d16322f42c148507ccf56e0374af297bbcf (
plain) (
blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package org.eclipse.team.internal.ccvs.ui.actions;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
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.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.ccvs.core.CVSTag;
import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.model.BranchCategory;
import org.eclipse.team.internal.ccvs.ui.model.BranchTag;
import org.eclipse.team.ui.actions.TeamAction;
/**
* DefineTagAction remembers a tag by name
*/
public class DefineBranchAction extends TeamAction {
IInputValidator validator = new IInputValidator() {
public String isValid(String newText) {
IStatus status = CVSTag.validateTagName(newText);
if (status.isOK()) return null;
return status.getMessage();
}
};
/**
* Returns the selected remote roots
*/
protected ICVSRepositoryLocation[] getSelectedRemoteRoots() {
ArrayList resources = null;
if (!selection.isEmpty()) {
resources = new ArrayList();
Iterator elements = ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
Object next = elements.next();
if (next instanceof ICVSRepositoryLocation) {
resources.add(next);
continue;
}
if (next instanceof BranchCategory) {
resources.add(((BranchCategory)next).getRepository(next));
continue;
}
if (next instanceof IAdaptable) {
IAdaptable a = (IAdaptable) next;
Object adapter = a.getAdapter(ICVSRepositoryLocation.class);
if (adapter instanceof ICVSRepositoryLocation) {
resources.add(adapter);
continue;
}
}
}
}
if (resources != null && !resources.isEmpty()) {
ICVSRepositoryLocation[] result = new ICVSRepositoryLocation[resources.size()];
resources.toArray(result);
return result;
}
return new ICVSRepositoryLocation[0];
}
/*
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
run(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
final ICVSRepositoryLocation[] roots = getSelectedRemoteRoots();
if (roots.length != 1) return;
Shell shell = getShell();
shell.getDisplay().syncExec(new Runnable() {
public void run() {
InputDialog dialog = new InputDialog(getShell(), Policy.bind("DefineBranchAction.enterTag"), Policy.bind("DefineBranchAction.enterTagLong"), null, validator);
if (dialog.open() == InputDialog.OK) {
CVSTag tag = new CVSTag(dialog.getValue(), CVSTag.BRANCH);
CVSUIPlugin.getPlugin().getRepositoryManager().addBranchTags(roots[0], new BranchTag[] {new BranchTag(tag, roots[0])});
}
}
});
}
}, Policy.bind("DefineBranchAction.tag"), this.PROGRESS_BUSYCURSOR);
}
/*
* @see TeamAction#isEnabled()
*/
protected boolean isEnabled() throws TeamException {
ICVSRepositoryLocation[] roots = getSelectedRemoteRoots();
if (roots.length != 1) return false;
return true;
}
}
|