KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.mapping.ResourceMapping;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
21 import org.eclipse.team.internal.ccvs.ui.operations.BranchOperation;
22
23 /**
24  * BranchAction tags the selected resources with a branch tag specified by the user,
25  * and optionally updates the local resources to point to the new branch.
26  */

27 public class BranchAction extends WorkspaceTraversalAction {
28
29     /* (non-Javadoc)
30      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#execute(org.eclipse.jface.action.IAction)
31      */

32     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
33         ResourceMapping[] resourceMappings = getCVSResourceMappings();
34         if (resourceMappings == null || resourceMappings.length == 0) {
35             // Could be a sync element tat is selected
36
IResource[] resources = getSelectedResources();
37             resourceMappings = getResourceMappings(resources);
38         }
39         if (resourceMappings == null || resourceMappings.length == 0) {
40             // Nothing is select so just return
41
return;
42         }
43         new BranchOperation(getTargetPart(), resourceMappings).run();
44     }
45     
46     private ResourceMapping[] getResourceMappings(IResource[] resources) {
47         List JavaDoc mappings = new ArrayList JavaDoc();
48         for (int i = 0; i < resources.length; i++) {
49             IResource resource = resources[i];
50             Object JavaDoc o = getAdapter(resource, ResourceMapping.class);
51             if (o instanceof ResourceMapping) {
52                 ResourceMapping mapping = (ResourceMapping) o;
53                 mappings.add(mapping);
54             }
55         }
56         return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
61      */

62     public String JavaDoc getId() {
63         return ICVSUIConstants.CMD_BRANCH;
64     }
65 }
66
67
Popular Tags