KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > buildpaths > newsourcepage > ClasspathModifierAction


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
12 package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.resource.ImageDescriptor;
19
20 import org.eclipse.jdt.core.JavaModelException;
21
22 import org.eclipse.jdt.internal.corext.buildpath.ClasspathModifierOperation;
23
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25
26 /**
27  * Action which is used when operations on the classpath
28  * are executed.
29  */

30 public class ClasspathModifierAction extends Action {
31     private ClasspathModifierOperation fOperation;
32     
33     /**
34      * Constructor to create a classpath modifier action.
35      *
36      * @param operation the operation to execute inside the action
37      * @param imageDescriptor the image descriptor for the icon
38      * @param disabledImageDescriptor the image descriptor for the disabled icon
39      * @param text the text to be set as label for the action
40      * @param tooltip the text to be set as tool tip
41      *
42      * @see ClasspathModifierOperation
43      */

44     public ClasspathModifierAction(ClasspathModifierOperation operation, ImageDescriptor imageDescriptor, ImageDescriptor disabledImageDescriptor, String JavaDoc text, String JavaDoc tooltip, int style) {
45         super(text, style);
46         setImageDescriptor(imageDescriptor);
47         setDisabledImageDescriptor(disabledImageDescriptor);
48         setText(text);
49         setToolTipText(tooltip);
50         fOperation= operation;
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.jface.action.Action#run()
55      */

56     public void run() {
57         try {
58             fOperation.run(null);
59             setEnabled(fOperation.isValid());
60         } catch (InvocationTargetException JavaDoc e) {
61             // nothing to do
62
} catch (InterruptedException JavaDoc e) {
63             // nothing to do
64
} catch (JavaModelException e) {
65             JavaPlugin.log(e);
66         }
67         // Remark: there is nothing to do because the operation that is executed
68
// ensures that the object receiving the result should do the exception handling
69
// because it needs to implement interface IClasspathInformationProvider
70
}
71     
72     /**
73      * Find out whether this operation can be executed on
74      * the provided list of elements.
75      *
76      * @param selectedElements a list of elements
77      * @param types an array of types for each element, that is,
78      * the type at position 'i' belongs to the selected element
79      * at position 'i'
80      *
81      * @return <code>true</code> if the operation can be
82      * executed on the provided list of elements, <code>
83      * false</code> otherwise.
84      *
85      * @throws JavaModelException
86      */

87     public boolean isValid(List JavaDoc selectedElements, int[] types) throws JavaModelException {
88         return fOperation.isValid(selectedElements, types);
89     }
90     
91     /**
92      * Getter for the operation.
93      *
94      * @return the operation that is executed within this action
95      *
96      * @see ClasspathModifierOperation
97      */

98     public ClasspathModifierOperation getOperation() {
99         return fOperation;
100     }
101         
102     /**
103      * Get the description suitable to the provided type
104      *
105      * @param type the type of the selected element(s), must be a constant of
106      * <code>DialogPackageActionGroup</code>.
107      * @return a short description of the operation.
108      *
109      * @see ClasspathModifierOperation#getDescription(int)
110      * @see DialogPackageExplorerActionGroup
111      */

112     public String JavaDoc getDescription(int type) {
113         return fOperation.getDescription(type);
114     }
115     
116     /* (non-Javadoc)
117      * @see org.eclipse.jface.action.Action#getId()
118      */

119     public String JavaDoc getId() {
120         return fOperation.getId();
121     }
122     
123     /**
124      * Get the action's name.
125      *
126      * @return a human readable name for the operation/action executed
127      */

128     public String JavaDoc getName() {
129         return fOperation.getName();
130     }
131 }
132
Popular Tags