KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaProject;
25 import org.eclipse.jdt.core.IPackageFragmentRoot;
26 import org.eclipse.jdt.core.JavaModelException;
27
28 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
30 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.ILinkToQuery;
31 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.CreateLinkedSourceFolderAction;
32
33 /**
34  * Operation create a link to a source folder.
35  *
36  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#createLinkedSourceFolder(ILinkToQuery, IJavaProject, IProgressMonitor)
37  */

38 public class LinkedSourceFolderOperation extends ClasspathModifierOperation {
39
40     private IClasspathModifierListener fListener;
41     private IClasspathInformationProvider fCPInformationProvider;
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 LinkedSourceFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
55         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Link_tooltip, IClasspathInformationProvider.CREATE_LINK);
56         fListener= listener;
57         fCPInformationProvider= informationProvider;
58     }
59     
60     /**
61      * Method which runs the actions with a progress monitor.<br>
62      *
63      * This operation requires the following query from the provider:
64      * <li>ILinkToQuery</li>
65      *
66      * @param monitor a progress monitor, can be <code>null</code>
67      */

68     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
69         CreateLinkedSourceFolderAction action= new CreateLinkedSourceFolderAction();
70         action.selectionChanged(new StructuredSelection(fCPInformationProvider.getJavaProject()));
71         action.run();
72         IPackageFragmentRoot createdElement= (IPackageFragmentRoot)action.getCreatedElement();
73         if (createdElement == null) {
74             //Wizard was cancled.
75
return;
76         }
77         try {
78             IResource correspondingResource= createdElement.getCorrespondingResource();
79             List JavaDoc result= new ArrayList JavaDoc();
80             result.add(correspondingResource);
81             if (fListener != null) {
82                 List JavaDoc entries= action.getCPListElements();
83                 fListener.classpathEntryChanged(entries);
84             }
85             fCPInformationProvider.handleResult(result, null, IClasspathInformationProvider.CREATE_LINK);
86         } catch (JavaModelException e) {
87             if (monitor == null) {
88                 fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, IClasspathInformationProvider.CREATE_LINK);
89             } else {
90                 throw new InvocationTargetException JavaDoc(e);
91             }
92         }
93     }
94
95     /**
96      * This particular operation is always valid.
97      *
98      * @param elements a list of elements
99      * @param types an array of types for each element, that is,
100      * the type at position 'i' belongs to the selected element
101      * at position 'i'
102      *
103      * @return <code>true</code> if the operation can be
104      * executed on the provided list of elements, <code>
105      * false</code> otherwise.
106      * @throws JavaModelException
107      */

108     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
109         return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.JAVA_PROJECT;
110     }
111
112     /**
113      * Get a description for this operation.
114      *
115      * @param type the type of the selected object, must be a constant of
116      * <code>DialogPackageExplorerActionGroup</code>.
117      * @return a string describing the operation
118      */

119     public String JavaDoc getDescription(int type) {
120         return NewWizardMessages.PackageExplorerActionGroup_FormText_createLinkedFolder;
121     }
122
123 }
124
Popular Tags