KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > common > command > IdentityCommand


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: IdentityCommand.java,v 1.2 2005/06/08 05:44:08 nickb Exp $
16  */

17 package org.eclipse.emf.common.command;
18
19
20 import java.util.Collection JavaDoc;
21 import java.util.Collections JavaDoc;
22
23 import org.eclipse.emf.common.CommonPlugin;
24
25
26 /**
27  * A command that always produces the same result.
28  */

29 public class IdentityCommand extends AbstractCommand
30 {
31   /**
32    * An empty instance of this object.
33    */

34   public static final IdentityCommand INSTANCE = new IdentityCommand();
35
36   /**
37    * Keeps track of the result returned from {@link #getResult}.
38    */

39   protected Collection JavaDoc result;
40
41   {
42     // This ensures that these useless state variables at least reflect the right value.
43
//
44
isPrepared = true;
45     isExecutable = true;
46   }
47
48   /**
49    * Creates an empty instance.
50    */

51   public IdentityCommand()
52   {
53     super();
54     this.result = Collections.EMPTY_LIST;
55   }
56
57   /**
58    * Creates an instance with a result collection containing the given result object.
59    * @param result the one object in the result collection.
60    */

61   public IdentityCommand(Object JavaDoc result)
62   {
63     super();
64     this.result = Collections.singleton(result);
65   }
66
67   /**
68    * Creates an instance with the given result collection.
69    * @param result the result collection.
70    */

71   public IdentityCommand(Collection JavaDoc result)
72   {
73     super();
74     this.result = result;
75   }
76
77   /**
78    * Creates an instance with the given label.
79    * @param label the label.
80    */

81   public IdentityCommand(String JavaDoc label)
82   {
83     this.label = label;
84     this.result = Collections.EMPTY_LIST;
85   }
86
87   /**
88    * Creates an instance with the given label and a result collection containing the given result object.
89    * @param label the label.
90    * @param result the one object in the result collection.
91    */

92   public IdentityCommand(String JavaDoc label, Object JavaDoc result)
93   {
94     this.label = label;
95     this.result = Collections.singleton(result);
96   }
97
98   /**
99    * Creates an instance with the given label the result collection.
100    * @param label the label.
101    * @param result the result collection.
102    */

103   public IdentityCommand(String JavaDoc label, Collection JavaDoc result)
104   {
105     this.label = label;
106     this.result = result;
107   }
108
109   /**
110    * Creates an instance with the given label and description.
111    * @param label the label.
112    * @param description the description.
113    */

114   public IdentityCommand(String JavaDoc label, String JavaDoc description)
115   {
116     this.label = label;
117     this.description = description;
118     this.result = Collections.EMPTY_LIST;
119   }
120
121   /**
122    * Creates an instance with the given label, description, and a result collection containing the given result object.
123    * @param label the label.
124    * @param description the description.
125    * @param result the one object in the result collection.
126    */

127   public IdentityCommand(String JavaDoc label, String JavaDoc description, Object JavaDoc result)
128   {
129     this.label = label;
130     this.description = description;
131     this.result = Collections.singleton(result);
132   }
133
134   /**
135    * Creates an instance with the given label, description, result collection.
136    * @param label the label.
137    * @param description the description.
138    * @param result the result collection.
139    */

140   public IdentityCommand(String JavaDoc label, String JavaDoc description, Collection JavaDoc result)
141   {
142     this.label = label;
143     this.description = description;
144     this.result = result;
145   }
146
147   /**
148    * Returns <code>true</code>.
149    * @return <code>true</code>.
150    */

151   public boolean canExecute()
152   {
153     return true;
154   }
155
156   /**
157    * Do nothing.
158    */

159   public void execute()
160   {
161   }
162
163   /**
164    * Do nothing.
165    */

166   public void undo()
167   {
168   }
169
170   /**
171    * Do nothing.
172    */

173   public void redo()
174   {
175   }
176
177   /*
178    * Javadoc copied from base class.
179    */

180   public String JavaDoc getLabel()
181   {
182     return label == null ? CommonPlugin.INSTANCE.getString("_UI_IdentityCommand_label") : label;
183   }
184
185   /*
186    * Javadoc copied from base class.
187    */

188   public String JavaDoc getDescription()
189   {
190     return description == null ? CommonPlugin.INSTANCE.getString("_UI_IdentityCommand_description") : description;
191   }
192
193   /**
194    * Return the identity result.
195    * @return the identity result.
196    */

197   public Collection JavaDoc getResult()
198   {
199     return result;
200   }
201 }
202
Popular Tags