KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > data > Action


1 /*******************************************************************************
2  * Copyright (c) 2002, 2007 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.ui.internal.cheatsheets.data;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.ui.internal.cheatsheets.ActionRunner;
16 import org.eclipse.ui.internal.cheatsheets.Messages;
17 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
18 import org.w3c.dom.Node JavaDoc;
19
20 /**
21  * Class that represents an <ACTION> element in a cheatsheet. This class stores all
22  * of the attributes associated with an Action and is capable of executing that Action.
23  */

24 public class Action extends AbstractExecutable {
25     private String JavaDoc actionClass;
26     private String JavaDoc pluginID;
27     private boolean hasClassAttr = false;
28     private boolean hasPluginId = false;
29
30     public Action() {
31         super();
32     }
33     
34     
35     /**
36      * This method returns the class specified to be run when the "click to perform" button is pressed for this item.
37      * @return the class name to be run for the item
38      */

39     public String JavaDoc getActionClass() {
40         return actionClass;
41     }
42
43     /**
44      * This method returns the string id of the plugin that contains the action class to be run.
45      * @return the id of the plugin that has the action class
46      */

47     public String JavaDoc getPluginID() {
48         return pluginID;
49     }
50
51     /**
52      * This method allows you to specify the class to be run when the perform button is pressed for this
53      * item in the cheat sheet.
54      * @param classname the class to be run by the item in the cheat sheet
55      */

56     public void setClass(String JavaDoc aclass) {
57         this.actionClass = aclass;
58     }
59
60     /**
61      * This method allows to set the plugin id of the action to be run by this item in the cheat sheet.
62      * @param pluginId the id of the plugin containing the action class specified for this item
63      */

64     public void setPluginID(String JavaDoc pluginId) {
65         this.pluginID = pluginId;
66     }
67
68     public boolean handleAttribute(Node JavaDoc attribute) {
69         if (attribute.getNodeName().equals(IParserTags.PLUGINID)) {
70             hasPluginId = true;
71             setPluginID(attribute.getNodeValue());
72             return true;
73         } else if (attribute.getNodeName().equals(IParserTags.CLASS)) {
74             hasClassAttr = true;
75             setClass(attribute.getNodeValue());
76             return true;
77         }
78         return false;
79     }
80
81     public String JavaDoc checkAttributes(Node JavaDoc node) {
82         if(!hasClassAttr) {
83             return NLS.bind(Messages.ERROR_PARSING_NO_CLASS, (new Object JavaDoc[] {node.getNodeName()}));
84         }
85         if(!hasPluginId) {
86             return NLS.bind(Messages.ERROR_PARSING_NO_PLUGINID, (new Object JavaDoc[] {node.getNodeName()}));
87         }
88         if(isConfirm() && !isRequired()) {
89             return NLS.bind(Messages.ERROR_PARSING_REQUIRED_CONFIRM, (new Object JavaDoc[] {node.getNodeName()}));
90         }
91         return null;
92     }
93
94     public boolean isCheatSheetManagerUsed() {
95         return true;
96     }
97
98
99     public IStatus execute(CheatSheetManager csm) {
100         return new ActionRunner().runAction(this, csm);
101     }
102
103     public boolean hasParams() {
104         return true;
105     }
106
107 }
108
Popular Tags