KickJava   Java API By Example, From Geeks To Geeks.

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


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.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20
21 import org.eclipse.jdt.core.IClasspathEntry;
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.CPListElement;
29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElementAttribute;
30 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IOutputLocationQuery;
31
32 /**
33  * Operation to edit the output folder property of a source folder.
34  *
35  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#editOutputFolder(CPListElement, IJavaProject, IOutputLocationQuery, IProgressMonitor)
36  */

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

51     public EditOutputFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
52         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_EditOutput_tooltip, IClasspathInformationProvider.EDIT_OUTPUT);
53         fShowOutputFolders= false;
54     }
55     
56     /**
57      * Method which runs the actions with a progress monitor.<br>
58      *
59      * This operation requires the following query:
60      * <li>IOutputLocationQuery</li>
61      *
62      * @param monitor a progress monitor, can be <code>null</code>
63      */

64     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
65         Object JavaDoc result= null;
66         fException= null;
67         try {
68             Object JavaDoc selection= getSelectedElements().get(0);
69             IJavaProject project= fInformationProvider.getJavaProject();
70             CPListElement selElement;
71             if (selection instanceof IJavaElement) {
72                 IJavaElement javaElement= (IJavaElement)selection;
73                 IClasspathEntry entry= ClasspathModifier.getClasspathEntryFor(javaElement.getPath(), project, IClasspathEntry.CPE_SOURCE);
74                 selElement= CPListElement.createFromExisting(entry, project);
75             } else {
76                 selElement= ((CPListElementAttribute)selection).getParent();
77             }
78             IOutputLocationQuery query= fInformationProvider.getOutputLocationQuery();
79             result= editOutputFolder(selElement, project, query, monitor);
80         } catch (CoreException e) {
81             fException= e;
82             result= null;
83         }
84         List JavaDoc resultList= new ArrayList JavaDoc();
85         if (result != null)
86             resultList.add(result);
87         super.handleResult(resultList, monitor);
88     }
89     
90     /**
91      * Method that is called whenever setting of
92      * output folders is allowed or forbidden (for example
93      * on changing a checkbox with this setting). Note that
94      * the validity state of this operation depends directly
95      * on this setting. Editing of an output folder is only
96      * possible, if output folders are shown, otherwise the
97      * operation is invalid.
98      *
99      * @param show <code>true</code> if output
100      * folders should be shown, <code>false</code> otherwise.
101      *
102      * @see #isValid(List, int[])
103      */

104     public void showOutputFolders(boolean show) {
105         fShowOutputFolders= show;
106     }
107     
108     /**
109      * Find out whether this operation can be executed on
110      * the provided list of elements.
111      *
112      * @param elements a list of elements
113      * @param types an array of types for each element, that is,
114      * the type at position 'i' belongs to the selected element
115      * at position 'i'
116      *
117      * @return <code>true</code> if the operation can be
118      * executed on the provided list of elements, <code>
119      * false</code> otherwise.
120      * @throws JavaModelException
121      */

122     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
123         if (elements.size() != 1 || !fShowOutputFolders)
124             return false;
125         IJavaProject project= fInformationProvider.getJavaProject();
126         Object JavaDoc element= elements.get(0);
127         
128         if (element instanceof IJavaProject) {
129             if (!isSourceFolder(project))
130                 return false;
131         } else if (element instanceof IPackageFragmentRoot) {
132             return ((IPackageFragmentRoot)element).getKind() == IPackageFragmentRoot.K_SOURCE;
133         }
134         return element instanceof CPListElementAttribute;
135     }
136     
137     /**
138      * Get a description for this operation. The description depends on
139      * the provided type parameter, which must be a constant of
140      * <code>DialogPackageExplorerActionGroup</code>. In this case, the
141      * type does not matter.
142      *
143      * @param type the type of the selected object, must be a constant of
144      * <code>DialogPackageExplorerActionGroup</code>.
145      * @return a string describing the operation
146      */

147     public String JavaDoc getDescription(int type) {
148         return NewWizardMessages.PackageExplorerActionGroup_FormText_EditOutputFolder;
149     }
150 }
151
Popular Tags