KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaProject;
22 import org.eclipse.jdt.core.IPackageFragmentRoot;
23
24 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
25 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElementAttribute;
26 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IOutputLocationQuery;
27
28 /**
29  * Operation to create an output folder
30  *
31  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#createOutputFolder(IPackageFragmentRoot, IOutputLocationQuery, IJavaProject, IProgressMonitor)
32  */

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

46     public CreateOutputFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
47         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_CreateOutput_tooltip, IClasspathInformationProvider.CREATE_OUTPUT);
48     }
49     
50     /**
51      * Method which runs the actions with a progress monitor.<br>
52      *
53      * This operation requires the following query from the provider:
54      * <li>IOutputLocationQuery</li>
55      *
56      * @param monitor a progress monitor, can be <code>null</code>
57      */

58     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
59         List JavaDoc result= new ArrayList JavaDoc();
60         fException= null;
61         try {
62             IPackageFragmentRoot root= (IPackageFragmentRoot)getSelectedElements().get(0);
63             IJavaProject project= fInformationProvider.getJavaProject();
64             IOutputLocationQuery query= fInformationProvider.getOutputLocationQuery();
65             CPListElementAttribute res= createOutputFolder(root, query, project, monitor);
66             if (res != null) {
67                 result.add(res);
68             }
69         } catch (CoreException e) {
70             fException= e;
71             result= null;
72         }
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      */

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

109     public String JavaDoc getDescription(int type) {
110         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_CreateOutput;
111     }
112 }
113
Popular Tags