blob: 731afce9cade95debd15aecaa4866a6d94ca0999 (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.action.IAction;
import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
import org.eclipse.team.internal.ccvs.ui.operations.BranchOperation;
/**
* BranchAction tags the selected resources with a branch tag specified by the user,
* and optionally updates the local resources to point to the new branch.
*/
public class BranchAction extends WorkspaceTraversalAction {
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#execute(org.eclipse.jface.action.IAction)
*/
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
ResourceMapping[] resourceMappings = getCVSResourceMappings();
if (resourceMappings == null || resourceMappings.length == 0) {
// Could be a sync element tat is selected
IResource[] resources = getSelectedResources();
resourceMappings = getResourceMappings(resources);
}
if (resourceMappings == null || resourceMappings.length == 0) {
// Nothing is select so just return
return;
}
new BranchOperation(getTargetPart(), resourceMappings).run();
}
private ResourceMapping[] getResourceMappings(IResource[] resources) {
List mappings = new ArrayList();
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
Object o = getAdapter(resource, ResourceMapping.class);
if (o instanceof ResourceMapping) {
ResourceMapping mapping = (ResourceMapping) o;
mappings.add(mapping);
}
}
return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
*/
public String getId() {
return ICVSUIConstants.CMD_BRANCH;
}
}
|