KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.team.internal.ccvs.core.CVSException;
19 import org.eclipse.team.internal.ccvs.core.ICVSResource;
20 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
21 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
22 import org.eclipse.team.internal.ccvs.ui.operations.AddOperation;
23 import org.eclipse.team.internal.ccvs.ui.wizards.AddWizard;
24
25 /**
26  * AddAction performs a 'cvs add' command on the selected resources. If a
27  * container is selected, its children are recursively added.
28  */

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

34     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
35         if (!promptForAddOfIgnored()) return;
36         AddOperation op = new AddOperation(getTargetPart(), getCVSResourceMappings());
37         AddWizard.run(getShell(), op);
38     }
39
40     /*
41      * Prompt whether explicitly selected ignored resources should be added
42      */

43     private boolean promptForAddOfIgnored() {
44         // Prompt if any of the traversal roots are ignored
45
// TODO: What about non-root resources that are part of the model but would be ignored?
46
IResource[] resources = getSelectedResourcesWithOverlap();
47         boolean prompt = false;
48         for (int i = 0; i < resources.length; i++) {
49             ICVSResource resource = getCVSResourceFor(resources[i]);
50             try {
51                 if (resource.isIgnored()) {
52                     prompt = true;
53                     break;
54                 }
55             } catch (CVSException e) {
56                 handle(e);
57             }
58         }
59         if (prompt) {
60             return MessageDialog.openQuestion(getShell(), CVSUIMessages.AddAction_addIgnoredTitle, CVSUIMessages.AddAction_addIgnoredQuestion); //
61
}
62         return true;
63     }
64     
65     /**
66      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForManagedResources()
67      */

68     protected boolean isEnabledForManagedResources() {
69         return false;
70     }
71
72     /**
73      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForUnmanagedResources()
74      */

75     protected boolean isEnabledForUnmanagedResources() {
76         return true;
77     }
78
79     /**
80      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForIgnoredResources()
81      */

82     protected boolean isEnabledForIgnoredResources() {
83         return true;
84     }
85
86     /**
87      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForCVSResource(org.eclipse.team.internal.ccvs.core.ICVSResource)
88      */

89     protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
90         // Add to version control should never be enabled for linked resources
91
IResource resource = cvsResource.getIResource();
92         if (resource.isLinked()) return false;
93         return super.isEnabledForCVSResource(cvsResource);
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
98      */

99     public String JavaDoc getId() {
100         return ICVSUIConstants.CMD_ADD;
101     }
102 }
103
Popular Tags