KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.core.ICompilationUnit;
21 import org.eclipse.jdt.core.IJavaElement;
22 import org.eclipse.jdt.core.IJavaProject;
23 import org.eclipse.jdt.core.JavaModelException;
24
25 import org.eclipse.jdt.internal.corext.util.Messages;
26
27 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
28 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
29
30
31 /**
32  * Operation to exclude objects of type <code>IJavaElement</code>.
33  *
34  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#exclude(List, IJavaProject, IProgressMonitor)
35  * @see org.eclipse.jdt.internal.corext.buildpath.UnexcludeOperation
36  */

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

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

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

89     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
90         if (elements.size() == 0)
91             return false;
92         for(int i= 0; i < elements.size(); i++) {
93             Object JavaDoc element= elements.get(i);
94             int type= types[i];
95             if (!(type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT ||
96                     type == DialogPackageExplorerActionGroup.INCLUDED_FOLDER ||
97                     element instanceof ICompilationUnit))
98                 return false;
99         }
100         return true;
101     }
102     
103     /**
104      * Get a description for this operation. The description depends on
105      * the provided type parameter, which must be a constant of
106      * <code>DialogPackageExplorerActionGroup</code>. If the type is
107      * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
108      * description will be very general to describe the situation of
109      * all the different selected objects as good as possible.
110      *
111      * @param type the type of the selected object, must be a constant of
112      * <code>DialogPackageExplorerActionGroup</code>.
113      * @return a string describing the operation
114      */

115     public String JavaDoc getDescription(int type) {
116         IJavaElement elem= (IJavaElement) getSelectedElements().get(0);
117         String JavaDoc name= escapeSpecialChars(elem.getElementName());
118         if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT)
119             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludePackage, name);
120         if (type == DialogPackageExplorerActionGroup.INCLUDED_FOLDER)
121             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludePackage, name);
122         if (type == DialogPackageExplorerActionGroup.COMPILATION_UNIT)
123             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludeFile, name);
124         if (type == DialogPackageExplorerActionGroup.INCLUDED_FILE)
125             return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludeFile, name);
126         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Exclude;
127     }
128 }
129
Popular Tags