KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > buildpath > UnexcludeOperation


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
12 package org.eclipse.jdt.internal.corext.buildpath;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IResource;
22
23 import org.eclipse.jdt.core.IJavaProject;
24 import org.eclipse.jdt.core.JavaModelException;
25
26 import org.eclipse.jdt.internal.corext.util.Messages;
27
28 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
30
31
32 /**
33  * Operation to unexclude objects of type <code>IResource</code>. This is the
34  * reverse action to exclude.
35  *
36  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#unExclude(List, IJavaProject, IProgressMonitor)
37  * @see org.eclipse.jdt.internal.corext.buildpath.ExcludeOperation
38  */

39 public class UnexcludeOperation extends ClasspathModifierOperation {
40
41     /**
42      * Constructor
43      *
44      * @param listener a <code>IClasspathModifierListener</code> that is notified about
45      * changes on classpath entries or <code>null</code> if no such notification is
46      * necessary.
47      * @param informationProvider a provider to offer information to the operation
48      *
49      * @see IClasspathInformationProvider
50      * @see ClasspathModifier
51      */

52     public UnexcludeOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
53         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Unexclude_tooltip, IClasspathInformationProvider.UNEXCLUDE);
54     }
55
56     /**
57      * Method which runs the actions with a progress monitor.<br>
58      *
59      * This operation does not require any queries from the provider.
60      *
61      * @param monitor a progress monitor, can be <code>null</code>
62      */

63     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
64         List JavaDoc result= null;
65         fException= null;
66         try {
67             List JavaDoc resources= getSelectedElements();
68             IJavaProject project= fInformationProvider.getJavaProject();
69             result= unExclude(resources, project, monitor);
70         } catch (CoreException e) {
71             fException= e;
72             result= null;
73         }
74         super.handleResult(result, monitor);
75     }
76
77     /**
78      * Find out whether this operation can be executed on
79      * the provided list of elements.
80      *
81      * @param elements a list of elements
82      * @param types an array of types for each element, that is,
83      * the type at position 'i' belongs to the selected element
84      * at position 'i'
85      *
86      * @return <code>true</code> if the operation can be
87      * executed on the provided list of elements, <code>
88      * false</code> otherwise.
89      * @throws JavaModelException
90      */

91     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
92         if (elements.size() == 0)
93             return false;
94         IJavaProject project= fInformationProvider.getJavaProject();
95         for(int i= 0; i < elements.size(); i++) {
96             Object JavaDoc element= elements.get(i);
97             switch (types[i]) {
98                 case DialogPackageExplorerActionGroup.FOLDER: if (!isValidFolder((IResource)element, project)) return false; break;
99                 case DialogPackageExplorerActionGroup.EXCLUDED_FOLDER: if (!isValidExcludedFolder((IResource)element, project)) return false; break;
100                 case DialogPackageExplorerActionGroup.EXCLUDED_FILE: if (!isValidExcludedFile((IFile)element, project)) return false; break;
101                 default: return false;
102             }
103         }
104         return true;
105     }
106
107     /**
108      * Find out whether the folder can be unexcluded or not.
109      *
110      * @param resource the resource to be checked
111      * @param project the Java project
112      * @return <code>true</code> if the folder can be unexcluded, <code>
113      * false</code> otherwise
114      * @throws JavaModelException
115      */

116     private boolean isValidFolder(IResource resource, IJavaProject project) throws JavaModelException {
117         return ClasspathModifier.isExcluded(resource, project);
118     }
119
120     /**
121      * Find out whether the excluded folder can be unexcluded or not.
122      *
123      * @param resource the resource to be checked
124      * @param project the Java project
125      * @return <code>true</code> if the folder can be unexcluded, <code>
126      * false</code> otherwise
127      * @throws JavaModelException
128      */

129     private boolean isValidExcludedFolder(IResource resource, IJavaProject project) throws JavaModelException {
130         return ClasspathModifier.isExcluded(resource, project);
131     }
132
133     /**
134      * Find out whether the file can be excluded or not.
135      *
136      * @param file the file to be checked
137      * @param project the Java project
138      * @return <code>true</code> if the file can be unexcluded, <code>
139      * false</code> otherwise
140      * @throws JavaModelException
141      */

142     private boolean isValidExcludedFile(IFile file, IJavaProject project) throws JavaModelException {
143         return ClasspathModifier.isExcluded(file, project);
144     }
145
146     /**
147      * Get a description for this operation. The description depends on
148      * the provided type parameter, which must be a constant of
149      * <code>DialogPackageExplorerActionGroup</code>. If the type is
150      * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
151      * description will be very general to describe the situation of
152      * all the different selected objects as good as possible.
153      *
154      * @param type the type of the selected object, must be a constant of
155      * <code>DialogPackageExplorerActionGroup</code>.
156      * @return a string describing the operation
157      */

158     public String JavaDoc getDescription(int type) {
159         IResource resource= (IResource) getSelectedElements().get(0);
160         String JavaDoc name= escapeSpecialChars(resource.getName());
161         
162         if (type == DialogPackageExplorerActionGroup.FOLDER)
163             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_UnexcludeFolder, name);
164         if (type == DialogPackageExplorerActionGroup.EXCLUDED_FILE)
165             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_UnexcludeFile, name);
166         
167         return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Unexclude, name);
168     }
169 }
170
Popular Tags