KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaProject;
21 import org.eclipse.jdt.core.JavaModelException;
22
23 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
24 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
25
26
27 /**
28  * Operation to uninclude objects of type <code>IJavaElement</code>
29  * (this is the reverse action to include).
30  *
31  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#unInclude(List, IJavaProject, IProgressMonitor)
32  * @see org.eclipse.jdt.internal.corext.buildpath.IncludeOperation
33  */

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

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

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

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

110     public String JavaDoc getDescription(int type) {
111         if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT ||
112                 type == DialogPackageExplorerActionGroup.INCLUDED_FOLDER)
113             return NewWizardMessages.PackageExplorerActionGroup_FormText_UnincludeFolder;
114         if (type == DialogPackageExplorerActionGroup.COMPILATION_UNIT ||
115                 type == DialogPackageExplorerActionGroup.INCLUDED_FILE)
116             return NewWizardMessages.PackageExplorerActionGroup_FormText_UnincludeFile;
117         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Uninclude;
118     }
119 }
120
Popular Tags