Skip to main content
summaryrefslogtreecommitdiffstats
blob: 98e43b92c011de659337d34a7faa4e484a29ff55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
 * Copyright (c) 2002, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.data;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.internal.cheatsheets.ActionRunner;
import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
import org.w3c.dom.Node;

/**
 * Class that represents an <ACTION> element in a cheatsheet. This class stores all
 * of the attributes associated with an Action and is capable of executing that Action.
 */
public class Action extends AbstractExecutable {
	private String actionClass;
	private String pluginID;
	private boolean hasClassAttr = false;
	private boolean hasPluginId = false;

	public Action() {
		super();
	}
	
 	
	/**
	 * This method returns the class specified to be run when the "click to perform" button is pressed for this item.
	 * @return the class name to be run for the item
	 */
	public String getActionClass() {
		return actionClass;
	}

	/**
	 * This method returns the string id of the plugin that contains the action class to be run.
	 * @return the id of the plugin that has the action class
	 */
	public String getPluginID() {
		return pluginID;
	}

	/**
	 *  This method allows you to specify the class to be run when the perform button is pressed for this 
	 * item in the cheat sheet. 
	 * @param classname the class to be run by the item in the cheat sheet
	 */
	public void setClass(String aclass) {
		this.actionClass = aclass;
	}

	/**
	 * This method allows to set the plugin id of the action to be run by this item in the cheat sheet.
	 * @param pluginId the id of the plugin containing the action class specified for this item
	 */
	public void setPluginID(String pluginId) {
		this.pluginID = pluginId;
	}

	public boolean handleAttribute(Node attribute) {
		if (attribute.getNodeName().equals(IParserTags.PLUGINID)) {
			hasPluginId = true;
			setPluginID(attribute.getNodeValue());
			return true;
		} else if (attribute.getNodeName().equals(IParserTags.CLASS)) {
			hasClassAttr = true;
			setClass(attribute.getNodeValue());
			return true;
		}
		return false;
	}

	public String checkAttributes(Node node) {
		if(!hasClassAttr) {
			return NLS.bind(Messages.ERROR_PARSING_NO_CLASS, (new Object[] {node.getNodeName()}));
		}
		if(!hasPluginId) {
			return NLS.bind(Messages.ERROR_PARSING_NO_PLUGINID, (new Object[] {node.getNodeName()}));
		}
		if(isConfirm() && !isRequired()) {
			return NLS.bind(Messages.ERROR_PARSING_REQUIRED_CONFIRM, (new Object[] {node.getNodeName()}));
		}
		return null;
	}

	public boolean isCheatSheetManagerUsed() {
		return true;
	}


	public IStatus execute(CheatSheetManager csm) {
		return new ActionRunner().runAction(this, csm);
	}

	public boolean hasParams() {
		return true;
	}

}

Back to the top