01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.data;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.osgi.util.NLS;
14: import org.eclipse.ui.internal.cheatsheets.CommandRunner;
15: import org.eclipse.ui.internal.cheatsheets.Messages;
16: import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
17: import org.w3c.dom.Node;
18:
19: /**
20: * A command which can be executed from the cheatsheet
21: */
22:
23: public class CheatSheetCommand extends AbstractExecutable {
24:
25: private String serialization;
26: private String returns;
27: private boolean serializationFound;
28:
29: public void setSerialization(String serialization) {
30: this .serialization = serialization;
31: }
32:
33: public String getSerialization() {
34: return serialization;
35: }
36:
37: public boolean isCheatSheetManagerUsed() {
38: return true;
39: }
40:
41: public IStatus execute(CheatSheetManager csm) {
42: return new CommandRunner().executeCommand(this , csm);
43: }
44:
45: public boolean hasParams() {
46: return false;
47: }
48:
49: public boolean handleAttribute(Node attribute) {
50: if (IParserTags.SERIALIZATION.equals(attribute.getNodeName())) {
51: setSerialization(attribute.getNodeValue());
52: serializationFound = true;
53: return true;
54: } else if (IParserTags.RETURNS.equals(attribute.getNodeName())) {
55: setReturns(attribute.getNodeValue());
56: return true;
57: }
58: return false;
59: }
60:
61: public String checkAttributes(Node node) {
62: if (!serializationFound) {
63: return NLS.bind(Messages.ERROR_PARSING_NO_SERIALIZATION,
64: (new Object[] { node.getNodeName() }));
65: }
66: if (isConfirm() && !isRequired()) {
67: return NLS.bind(Messages.ERROR_PARSING_REQUIRED_CONFIRM,
68: (new Object[] { node.getNodeName() }));
69: }
70: return null;
71: }
72:
73: public void setReturns(String returns) {
74: this .returns = returns;
75: }
76:
77: public String getReturns() {
78: return returns;
79: }
80:
81: }
|