KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.jdt.internal.corext.buildpath;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.core.resources.IResource;
21
22 import org.eclipse.jface.viewers.StructuredSelection;
23
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.GenerateBuildPathActionGroup.CreateLocalSourceFolderAction;
30
31 public class CreateFolderOperation extends ClasspathModifierOperation {
32     
33     private final IClasspathModifierListener fListener;
34     private final IClasspathInformationProvider fCPInformationProvider;
35
36     /**
37      * Creates a new <code>AddFolderOperation</code>.
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 information to the action
43      *
44      * @see IClasspathInformationProvider
45      * @see ClasspathModifier
46      */

47     public CreateFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
48         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddLibCP_tooltip, IClasspathInformationProvider.CREATE_FOLDER);
49         fListener= listener;
50         fCPInformationProvider= informationProvider;
51     }
52
53     /**
54      * {@inheritDoc}
55      */

56     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
57         CreateLocalSourceFolderAction action= new CreateLocalSourceFolderAction();
58         action.selectionChanged(new StructuredSelection(fCPInformationProvider.getJavaProject()));
59         action.run();
60         IPackageFragmentRoot createdElement= (IPackageFragmentRoot)action.getCreatedElement();
61         if (createdElement == null) {
62             //Wizard was cancled.
63
return;
64         }
65         try {
66             IResource correspondingResource= createdElement.getCorrespondingResource();
67             List JavaDoc result= new ArrayList JavaDoc();
68             result.add(correspondingResource);
69             if (fListener != null) {
70                 List JavaDoc entries= action.getCPListElements();
71                 fListener.classpathEntryChanged(entries);
72             }
73             fCPInformationProvider.handleResult(result, null, IClasspathInformationProvider.CREATE_FOLDER);
74         } catch (JavaModelException e) {
75             if (monitor == null) {
76                 fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, IClasspathInformationProvider.CREATE_FOLDER);
77             } else {
78                 throw new InvocationTargetException JavaDoc(e);
79             }
80         }
81     }
82
83     /**
84      * {@inheritDoc}
85      */

86     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
87         return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.JAVA_PROJECT;
88     }
89
90     /**
91      * {@inheritDoc}
92      */

93     public String JavaDoc getDescription(int type) {
94         return NewWizardMessages.PackageExplorerActionGroup_FormText_createNewSourceFolder;
95     }
96 }
97
Popular Tags