KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.ui.internal.cheatsheets.data;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.ui.internal.cheatsheets.CommandRunner;
17 import org.eclipse.ui.internal.cheatsheets.Messages;
18 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
19 import org.w3c.dom.Node JavaDoc;
20
21 /**
22  * A command which can be executed from the cheatsheet
23  */

24
25 public class CheatSheetCommand extends AbstractExecutable {
26
27     private String JavaDoc serialization;
28     private String JavaDoc returns;
29     private boolean serializationFound;
30     
31     public void setSerialization(String JavaDoc serialization) {
32         this.serialization = serialization;
33     }
34     
35     public String JavaDoc getSerialization() {
36         return serialization;
37     }
38
39     public boolean isCheatSheetManagerUsed() {
40         return true;
41     }
42
43     public IStatus execute(CheatSheetManager csm) {
44         return new CommandRunner().executeCommand(this, csm);
45     }
46
47     public boolean hasParams() {
48         return false;
49     }
50
51     public boolean handleAttribute(Node JavaDoc attribute) {
52         if (IParserTags.SERIALIZATION.equals(attribute.getNodeName())) {
53             setSerialization(attribute.getNodeValue());
54             serializationFound = true;
55             return true;
56         } else if (IParserTags.RETURNS.equals(attribute.getNodeName())) {
57             setReturns(attribute.getNodeValue());
58             return true;
59         }
60         return false;
61     }
62
63     public String JavaDoc checkAttributes(Node JavaDoc node) {
64         if(!serializationFound) {
65             return NLS.bind(Messages.ERROR_PARSING_NO_SERIALIZATION, (new Object JavaDoc[] {node.getNodeName()}));
66         }
67         if(isConfirm() && !isRequired()) {
68             return NLS.bind(Messages.ERROR_PARSING_REQUIRED_CONFIRM, (new Object JavaDoc[] {node.getNodeName()}));
69         }
70         return null;
71     }
72
73     public void setReturns(String JavaDoc returns) {
74         this.returns = returns;
75     }
76
77     public String JavaDoc getReturns() {
78         return returns;
79     }
80
81 }
82
Popular Tags