001: /*******************************************************************************
002: * Copyright (c) 2002, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.data;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.osgi.util.NLS;
014: import org.eclipse.ui.internal.cheatsheets.ActionRunner;
015: import org.eclipse.ui.internal.cheatsheets.Messages;
016: import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
017: import org.w3c.dom.Node;
018:
019: /**
020: * Class that represents an <ACTION> element in a cheatsheet. This class stores all
021: * of the attributes associated with an Action and is capable of executing that Action.
022: */
023: public class Action extends AbstractExecutable {
024: private String actionClass;
025: private String pluginID;
026: private boolean hasClassAttr = false;
027: private boolean hasPluginId = false;
028:
029: public Action() {
030: super ();
031: }
032:
033: /**
034: * This method returns the class specified to be run when the "click to perform" button is pressed for this item.
035: * @return the class name to be run for the item
036: */
037: public String getActionClass() {
038: return actionClass;
039: }
040:
041: /**
042: * This method returns the string id of the plugin that contains the action class to be run.
043: * @return the id of the plugin that has the action class
044: */
045: public String getPluginID() {
046: return pluginID;
047: }
048:
049: /**
050: * This method allows you to specify the class to be run when the perform button is pressed for this
051: * item in the cheat sheet.
052: * @param classname the class to be run by the item in the cheat sheet
053: */
054: public void setClass(String aclass) {
055: this .actionClass = aclass;
056: }
057:
058: /**
059: * This method allows to set the plugin id of the action to be run by this item in the cheat sheet.
060: * @param pluginId the id of the plugin containing the action class specified for this item
061: */
062: public void setPluginID(String pluginId) {
063: this .pluginID = pluginId;
064: }
065:
066: public boolean handleAttribute(Node attribute) {
067: if (attribute.getNodeName().equals(IParserTags.PLUGINID)) {
068: hasPluginId = true;
069: setPluginID(attribute.getNodeValue());
070: return true;
071: } else if (attribute.getNodeName().equals(IParserTags.CLASS)) {
072: hasClassAttr = true;
073: setClass(attribute.getNodeValue());
074: return true;
075: }
076: return false;
077: }
078:
079: public String checkAttributes(Node node) {
080: if (!hasClassAttr) {
081: return NLS.bind(Messages.ERROR_PARSING_NO_CLASS,
082: (new Object[] { node.getNodeName() }));
083: }
084: if (!hasPluginId) {
085: return NLS.bind(Messages.ERROR_PARSING_NO_PLUGINID,
086: (new Object[] { node.getNodeName() }));
087: }
088: if (isConfirm() && !isRequired()) {
089: return NLS.bind(Messages.ERROR_PARSING_REQUIRED_CONFIRM,
090: (new Object[] { node.getNodeName() }));
091: }
092: return null;
093: }
094:
095: public boolean isCheatSheetManagerUsed() {
096: return true;
097: }
098:
099: public IStatus execute(CheatSheetManager csm) {
100: return new ActionRunner().runAction(this , csm);
101: }
102:
103: public boolean hasParams() {
104: return true;
105: }
106:
107: }
|