KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.jface.viewers.IStructuredSelection;
21
22 import org.eclipse.jdt.core.IJavaElement;
23 import org.eclipse.jdt.core.IJavaProject;
24 import org.eclipse.jdt.core.IPackageFragmentRoot;
25 import org.eclipse.jdt.core.JavaModelException;
26
27 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
28 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IInclusionExclusionQuery;
30 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.EditFilterAction;
31
32 /**
33  * Operation to edit the inclusion / exclusion filters of an
34  * <code>IJavaElement</code>.
35  *
36  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#editFilters(IJavaElement, IJavaProject, IInclusionExclusionQuery, IProgressMonitor)
37  */

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

54     public EditFiltersOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
55         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Edit_tooltip, IClasspathInformationProvider.EDIT_FILTERS);
56         fListener= listener;
57         fCPInformationProvider= informationProvider;
58         
59     }
60     
61     /**
62      * Method which runs the actions with a progress monitor.<br>
63      *
64      * This operation requires the following query:
65      * <li>IInclusionExclusionQuery</li>
66      *
67      * @param monitor a progress monitor, can be <code>null</code>
68      */

69     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
70         EditFilterAction action= new EditFilterAction();
71         IStructuredSelection selection= fCPInformationProvider.getSelection();
72         Object JavaDoc firstElement= selection.getFirstElement();
73         action.selectionChanged(selection);
74         action.run();
75         List JavaDoc l= new ArrayList JavaDoc();
76         l.add(firstElement);
77         if (fListener != null) {
78             List JavaDoc entries= action.getCPListElements();
79             fListener.classpathEntryChanged(entries);
80         }
81         fCPInformationProvider.handleResult(l, null, IClasspathInformationProvider.EDIT_FILTERS);
82     }
83     
84     /**
85      * Find out whether this operation can be executed on
86      * the provided list of elements.
87      *
88      * @param elements a list of elements
89      * @param types an array of types for each element, that is,
90      * the type at position 'i' belongs to the selected element
91      * at position 'i'
92      *
93      * @return <code>true</code> if the operation can be
94      * executed on the provided list of elements, <code>
95      * false</code> otherwise.
96      * @throws JavaModelException
97      */

98     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
99         if (elements.size() != 1)
100             return false;
101         IJavaProject project= fInformationProvider.getJavaProject();
102         Object JavaDoc element= elements.get(0);
103         
104         if (element instanceof IJavaProject) {
105             if (isSourceFolder(project))
106                 return true;
107         } else if (element instanceof IPackageFragmentRoot) {
108             return ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
109         }
110         return false;
111     }
112     
113     /**
114      * Get a description for this operation. The description depends on
115      * the provided type parameter, which must be a constant of
116      * <code>DialogPackageExplorerActionGroup</code>. If the type is
117      * <code>DialogPackageExplorerActionGroup.MULTI</code>, then the
118      * description will be very general to describe the situation of
119      * all the different selected objects as good as possible.
120      *
121      * @param type the type of the selected object, must be a constant of
122      * <code>DialogPackageExplorerActionGroup</code>.
123      * @return a string describing the operation
124      */

125     public String JavaDoc getDescription(int type) {
126         if (type == DialogPackageExplorerActionGroup.JAVA_PROJECT)
127             return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
128         if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT_ROOT)
129             return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
130         if (type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT)
131             return NewWizardMessages.PackageExplorerActionGroup_FormText_Edit;
132         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Edit;
133     }
134 }
135
Popular Tags