KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.osgi.util.NLS;
22 import org.eclipse.team.core.TeamException;
23 import org.eclipse.team.core.synchronize.SyncInfo;
24 import org.eclipse.team.internal.ccvs.core.*;
25 import org.eclipse.team.internal.ccvs.ui.*;
26 import org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation;
27 import org.eclipse.ui.IWorkbenchPart;
28
29 public class IgnoreAction extends WorkspaceTraversalAction {
30     
31     /**
32      * Define an operation that can be run in the background.
33      * We divide the ignores by provider to obtain project
34      * locks while modifying the .cvsignore files
35      */

36     class IgnoreOperation extends RepositoryProviderOperation {
37
38         private final IgnoreResourcesDialog dialog;
39
40         public IgnoreOperation(IWorkbenchPart part, IResource[] resources, IgnoreResourcesDialog dialog) {
41             super(part, resources);
42             this.dialog = dialog;
43         }
44
45         /* (non-Javadoc)
46          * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#getTaskName(org.eclipse.team.internal.ccvs.core.CVSTeamProvider)
47          */

48         protected String JavaDoc getTaskName(CVSTeamProvider provider) {
49             return NLS.bind(CVSUIMessages.IgnoreAction_0, new String JavaDoc[] { provider.getProject().getName() });
50         }
51
52         /* (non-Javadoc)
53          * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#execute(org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.core.resources.IResource[], org.eclipse.core.runtime.IProgressMonitor)
54          */

55         protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
56             try {
57                 monitor.beginTask(null, resources.length);
58                 for (int i = 0; i < resources.length; i++) {
59                     IResource resource = resources[i];
60                     String JavaDoc pattern = dialog.getIgnorePatternFor(resource);
61                     ICVSResource cvsResource = getCVSResourceFor(resource);
62                     cvsResource.setIgnoredAs(pattern);
63                     monitor.worked(1);
64                 }
65             } catch (TeamException e) {
66                 collectStatus(e.getStatus());
67                 return;
68             } finally {
69                 monitor.done();
70             }
71             collectStatus(Status.OK_STATUS);
72         }
73
74         /* (non-Javadoc)
75          * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getTaskName()
76          */

77         protected String JavaDoc getTaskName() {
78             return CVSUIMessages.IgnoreAction_1;
79         }
80         
81         /* (non-Javadoc)
82          * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#consultModelsForMappings()
83          */

84         public boolean consultModelsForMappings() {
85             return false;
86         }
87         
88     }
89     
90     protected void execute(final IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
91         run(new IRunnableWithProgress() {
92             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
93                 IResource[] resources = getSelectedResources();
94                 IgnoreResourcesDialog dialog = new IgnoreResourcesDialog(getShell(), resources);
95                 if (dialog.open() != Window.OK) return;
96                 new IgnoreOperation(getTargetPart(), resources, dialog).run();
97                 
98                 //if (action != null) action.setEnabled(isEnabled());
99
}
100         }, false /* cancelable */, PROGRESS_BUSYCURSOR);
101     }
102     /**
103      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
104      */

105     protected String JavaDoc getErrorTitle() {
106         return CVSUIMessages.IgnoreAction_ignore;
107     }
108
109     /**
110      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForManagedResources()
111      */

112     protected boolean isEnabledForManagedResources() {
113         return false;
114     }
115
116     /**
117      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForUnmanagedResources()
118      */

119     protected boolean isEnabledForUnmanagedResources() {
120         return true;
121     }
122     
123     /* (non-Javadoc)
124      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForCVSResource(org.eclipse.team.internal.ccvs.core.ICVSResource)
125      */

126     protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
127         if (super.isEnabledForCVSResource(cvsResource)) {
128             // Perform an extra check against the subscriber to ensure there is no conflict
129
CVSWorkspaceSubscriber subscriber = CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber();
130             IResource resource = cvsResource.getIResource();
131             if (resource == null) return false;
132             try {
133                 SyncInfo info = subscriber.getSyncInfo(resource);
134                 return ((info.getKind() & SyncInfo.DIRECTION_MASK) == SyncInfo.OUTGOING);
135             } catch (TeamException e) {
136                 // Let the enablement happen
137
return true;
138             }
139         }
140         return false;
141     }
142     
143     /* (non-Javadoc)
144      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
145      */

146     public String JavaDoc getId() {
147         return ICVSUIConstants.CMD_IGNORE;
148     }
149 }
150
Popular Tags