FILE COMPARISON
Produced: 2/18/2011 1:28:10 PM
   
Mode:  All Lines  
   
Left file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\original\Command.java  
Right file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\Command.java  
1 /******************************************************************************* = 1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.   2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials   3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0   4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at   5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html   6 * http://www.eclipse.org/legal/epl-v10.html
7 *   7 *
8 * Contributors:   8 * Contributors:
9 *     IBM Corporation - initial API and implementation   9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/   10 *******************************************************************************/
    <> 11 /*******************************************************************************
      12 * Additions/modifications to this source file by Oracle America, Inc. 2011
      13 *******************************************************************************/
11 package org.eclipse.ercp.swt.mobile; = 14 package org.eclipse.ercp.swt.mobile;
12     15  
13 import java.util.Enumeration;   16 import java.util.Enumeration;
14 import java.util.Iterator;   17 import java.util.Iterator;
15 import java.util.Locale;   18 import java.util.Locale;
16 import java.util.ResourceBundle;   19 import java.util.ResourceBundle;
17 import java.util.Vector;   20 import java.util.Vector;
18     21  
19 import org.eclipse.ercp.swt.mobile.CommandHandle.CommandNode;   22 import org.eclipse.ercp.swt.mobile.CommandHandle.CommandNode;
20 import org.eclipse.ercp.swt.mobile.MultiPageDialog.MultiPageShell;   23 import org.eclipse.ercp.swt.mobile.MultiPageDialog.MultiPageShell;
21 import org.eclipse.swt.SWT;   24 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.SWTException;   25 import org.eclipse.swt.SWTException;
23 import org.eclipse.swt.events.DisposeEvent;   26 import org.eclipse.swt.events.DisposeEvent;
24 import org.eclipse.swt.events.DisposeListener;   27 import org.eclipse.swt.events.DisposeListener;
25 import org.eclipse.swt.events.SelectionEvent;   28 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;   29 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.graphics.GC;   30 import org.eclipse.swt.graphics.GC;
28 import org.eclipse.swt.graphics.Rectangle;   31 import org.eclipse.swt.graphics.Rectangle;
29 import org.eclipse.swt.widgets.Canvas;   32 import org.eclipse.swt.widgets.Canvas;
30 import org.eclipse.swt.widgets.Composite;   33 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;   34 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Event;   35 import org.eclipse.swt.widgets.Event;
33 import org.eclipse.swt.widgets.Item;   36 import org.eclipse.swt.widgets.Item;
34 import org.eclipse.swt.widgets.Listener;   37 import org.eclipse.swt.widgets.Listener;
35 import org.eclipse.swt.widgets.Menu;   38 import org.eclipse.swt.widgets.Menu;
36 import org.eclipse.swt.widgets.MenuItem;   39 import org.eclipse.swt.widgets.MenuItem;
37 import org.eclipse.swt.widgets.Shell;   40 import org.eclipse.swt.widgets.Shell;
38 import org.eclipse.swt.widgets.TypedListener;   41 import org.eclipse.swt.widgets.TypedListener;
39     42  
    <> 43  
40 // Command test code = 44 // Command test code
41 /*   45 /*
42 import org.eclipse.swt.graphics.Color;   46 import org.eclipse.swt.graphics.Color;
43 import org.eclipse.swt.graphics.Image;   47 import org.eclipse.swt.graphics.Image;
44 import org.eclipse.swt.layout.FormAttachment;   48 import org.eclipse.swt.layout.FormAttachment;
45 import org.eclipse.swt.layout.FormData;   49 import org.eclipse.swt.layout.FormData;
46 import org.eclipse.swt.layout.FormLayout;   50 import org.eclipse.swt.layout.FormLayout;
47 import org.eclipse.swt.widgets.Button;   51 import org.eclipse.swt.widgets.Button;
48 import org.eclipse.swt.widgets.Combo;   52 import org.eclipse.swt.widgets.Combo;
49 import org.eclipse.swt.widgets.Composite;   53 import org.eclipse.swt.widgets.Composite;
50 import org.eclipse.swt.widgets.Display;   54 import org.eclipse.swt.widgets.Display;
51 import org.eclipse.swt.widgets.Label;   55 import org.eclipse.swt.widgets.Label;
52 import org.eclipse.swt.widgets.List;   56 import org.eclipse.swt.widgets.List;
53 import org.eclipse.swt.widgets.MessageBox;   57 import org.eclipse.swt.widgets.MessageBox;
54 import org.eclipse.swt.widgets.Text;   58 import org.eclipse.swt.widgets.Text;
55 */   59 */
56     60  
57 /**   61 /**
58 *   62 *
59 * Command is a metaphor that represents a general action. Command contains no   63 * Command is a metaphor that represents a general action. Command contains no
60 * information about the behavior that happens when a command is activated. The   64 * information about the behavior that happens when a command is activated. The
61 * concrete action is defined in a SelectionListener. Commands may be   65 * concrete action is defined in a SelectionListener. Commands may be
62 * implemented using any user interface construct that has semantics for activating   66 * implemented using any user interface construct that has semantics for activating
63 * a single action. Some implementations may implement commands as widgets, such   67 * a single action. Some implementations may implement commands as widgets, such
64 * as buttons or menu items, or voice tags. However, the implementation should   68 * as buttons or menu items, or voice tags. However, the implementation should
65 * not adversely affect an application's layout when realizing commands.   69 * not adversely affect an application's layout when realizing commands.
66 *   70 *
67 * <p>   71 * <p>
68 * A Command must be associated with a control and only becomes accessible   72 * A Command must be associated with a control and only becomes accessible
69 * when that control is in the current <i>focus context</i>. The current   73 * when that control is in the current <i>focus context</i>. The current
70 * focus context includes the control that currently has focus and all of   74 * focus context includes the control that currently has focus and all of
71 * its visible ancestor controls up through the lowest level Shell.   75 * its visible ancestor controls up through the lowest level Shell.
72 * The term <i>visible</i> above refers to widgets which   76 * The term <i>visible</i> above refers to widgets which
73 * are not explicitly hidden by calling <code>setVisible(false)</code>.   77 * are not explicitly hidden by calling <code>setVisible(false)</code>.
74 * The focus contenxt does not include siblings of the control with focus   78 * The focus contenxt does not include siblings of the control with focus
75 * or ancestors of the lowest level Shell.   79 * or ancestors of the lowest level Shell.
76 * </p>   80 * </p>
77 *   81 *
78 * <p>   82 * <p>
79 * The implementation guarantees that all commands within the current   83 * The implementation guarantees that all commands within the current
80 * focus context are accessible. However, the concrete method for doing this   84 * focus context are accessible. However, the concrete method for doing this
81 * is device-specific and implementation-dependent.   85 * is device-specific and implementation-dependent.
82 * Commands may be bound to hardware keys or device softkeys.   86 * Commands may be bound to hardware keys or device softkeys.
83 * As various devices have a different number of keys, the conventional way to   87 * As various devices have a different number of keys, the conventional way to
84 * place commands by indexing is not appropriate, especially as there may be   88 * place commands by indexing is not appropriate, especially as there may be
85 * more commands than available keys. The placement of commands is   89 * more commands than available keys. The placement of commands is
86 * also dynamic. For example, new commands can be added by the implementation   90 * also dynamic. For example, new commands can be added by the implementation
87 * at run-time in order to facilitate some context-related operations.   91 * at run-time in order to facilitate some context-related operations.
88 * Therefore, the implementation uses various information to place commands:   92 * Therefore, the implementation uses various information to place commands:
89 * </p>   93 * </p>
90 *   94 *
91 * <ul>   95 * <ul>
92 * <li><code>Command type</code> is a hint used by the   96 * <li><code>Command type</code> is a hint used by the
93 * implementation to associate commands with specific keys.   97 * implementation to associate commands with specific keys.
94 * It is common to bind more than one command of the same type to a control.   98 * It is common to bind more than one command of the same type to a control.
95 * In such cases, command precedence rules are used to determine which   99 * In such cases, command precedence rules are used to determine which
96 * command is assigned to a key and which others are placed on a menu.   100 * command is assigned to a key and which others are placed on a menu.
97 * <code>Command type</code> is not used for ordering within menus.   101 * <code>Command type</code> is not used for ordering within menus.
98 * </li>   102 * </li>
99 * <br>&nbsp;   103 * <br>&nbsp;
100 * <li>   104 * <li>
101 * When multiple commands are in competition for key or menu assignment, the   105 * When multiple commands are in competition for key or menu assignment, the
102 * <code>priority</code> argument is used to help determine assignment and order.   106 * <code>priority</code> argument is used to help determine assignment and order.
103 * The lowest value (zero) has the lowest precedence (and appears visually   107 * The lowest value (zero) has the lowest precedence (and appears visually
104 * lowest in menus). If priority values of competing commands are the same,   108 * lowest in menus). If priority values of competing commands are the same,
105 * higher precedence is given to commands created first. Commands bound to   109 * higher precedence is given to commands created first. Commands bound to
106 * the currently focused control are always given higher   110 * the currently focused control are always given higher
107 * precedence than commands bounds to ancestor controls regardless of their   111 * precedence than commands bounds to ancestor controls regardless of their
108 * <code>priority</code> value. Commands and CommandGroups within the same   112 * <code>priority</code> value. Commands and CommandGroups within the same
109 * command menu are ordered by priority value.   113 * command menu are ordered by priority value.
110 * </li>   114 * </li>
111 * </ul>   115 * </ul>
112 *   116 *
113 * <p>   117 * <p>
114 * A default command means that a command can be activated via a device   118 * A default command means that a command can be activated via a device
115 * selection key or any other "short-cut" like the concept of default button in   119 * selection key or any other "short-cut" like the concept of default button in
116 * a shell. Usually the default command has a different visual style to   120 * a shell. Usually the default command has a different visual style to
117 * make it distinguishable from other commands. Within a focus context, there   121 * make it distinguishable from other commands. Within a focus context, there
118 * can only be one default command at any time. A command becomes the default   122 * can only be one default command at any time. A command becomes the default
119 * one via the method "setDefaultCommand", and any previous default command   123 * one via the method "setDefaultCommand", and any previous default command
120 * becomes non-default.   124 * becomes non-default.
121 * </p>   125 * </p>
122 *   126 *
123 * <p>   127 * <p>
124 * When pressing the key associated with a command, a SelectionEvent will be   128 * When pressing the key associated with a command, a SelectionEvent will be
125 * delivered to all the command's SelectionListeners, if any.   129 * delivered to all the command's SelectionListeners, if any.
126 * </p>   130 * </p>
127 *   131 *
128 * <p>   132 * <p>
129 * Commands can have a long label (<code>setLongLabel(String)</code>), which   133 * Commands can have a long label (<code>setLongLabel(String)</code>), which
130 * is typically used for when a command is assigned to a menu.   134 * is typically used for when a command is assigned to a menu.
131 * The long label is optional. If the long label is not present on a command,   135 * The long label is optional. If the long label is not present on a command,
132 * the default text label (<code>setText(String)</code>) is used. The   136 * the default text label (<code>setText(String)</code>) is used. The
133 * default label should be as short as possible so that it consumes a   137 * default label should be as short as possible so that it consumes a
134 * minimum of screen real estate. The long label can be longer and more   138 * minimum of screen real estate. The long label can be longer and more
135 * descriptive, but it should be no longer than a few words. For example, a   139 * descriptive, but it should be no longer than a few words. For example, a
136 * command's default label might be "Play", and its long label might be "Play   140 * command's default label might be "Play", and its long label might be "Play
137 * Sound Clip".   141 * Sound Clip".
138 * Labeling of command menus is implementation-dependent.   142 * Labeling of command menus is implementation-dependent.
139 * </p>   143 * </p>
140 *   144 *
141 * <p>   145 * <p>
142 * Note that although this class is a subclass of   146 * Note that although this class is a subclass of
143 * {@link org.eclipse.swt.widgets.Item Item} and allows setting the image even   147 * {@link org.eclipse.swt.widgets.Item Item} and allows setting the image even
144 * if the underlying platform does not. But in this case the image is not   148 * if the underlying platform does not. But in this case the image is not
145 * displayed.   149 * displayed.
146 * </p>   150 * </p>
147 * <h3>Example 1: Single Command per Control (within a focus context of List and   151 * <h3>Example 1: Single Command per Control (within a focus context of List and
148 * its parent)</h3>   152 * its parent)</h3>
149 * <code><pre>   153 * <code><pre>
150 * List list = new List(parent, SWT.SINGLE); // a single selection list   154 * List list = new List(parent, SWT.SINGLE); // a single selection list
151 * Command cmd1 = new Command(list, Command.SELECT, 1);   155 * Command cmd1 = new Command(list, Command.SELECT, 1);
152 * cmd1.setText(&quot;Open&quot;);   156 * cmd1.setText(&quot;Open&quot;);
153 * cmd1.addSelectionListener(new SelectionListener() {   157 * cmd1.addSelectionListener(new SelectionListener() {
154 *      public void widgetSelected(SelectionEvent e) {   158 *      public void widgetSelected(SelectionEvent e) {
155 *              System.out.println(&quot;Command &quot; + e.data + &quot; pressed.&quot;);   159 *              System.out.println(&quot;Command &quot; + e.data + &quot; pressed.&quot;);
156 *              // e.widget contains the Command object.   160 *              // e.widget contains the Command object.
157 *      }   161 *      }
158 * });   162 * });
159 * Command cmd2 = new Command(parent, Command.GENERAL, 0);   163 * Command cmd2 = new Command(parent, Command.GENERAL, 0);
160 * cmd2.setText(&quot;New&quot;);   164 * cmd2.setText(&quot;New&quot;);
161 * cmd2.addSelectionListener(new SelectionListener() {   165 * cmd2.addSelectionListener(new SelectionListener() {
162 *      public void widgetSelected(SelectionEvent e) {   166 *      public void widgetSelected(SelectionEvent e) {
163 *              System.out.println(&quot;Command &quot; + e.data + &quot; pressed.&quot;);   167 *              System.out.println(&quot;Command &quot; + e.data + &quot; pressed.&quot;);
164 *              // e.widget contains the Command object.   168 *              // e.widget contains the Command object.
165 *      }   169 *      }
166 * });   170 * });
167 * </pre></code>   171 * </pre></code>
168 *   172 *
169 * <h3>Example 2: Multiple Commands per Control and DefaultCommand</h3>   173 * <h3>Example 2: Multiple Commands per Control and DefaultCommand</h3>
170 * <code><pre>   174 * <code><pre>
171 * List list = new List(composite1, SWT.SINGLE);   175 * List list = new List(composite1, SWT.SINGLE);
172 * Command cmd1 = new Command(list, Command.SELECT, 0);   176 * Command cmd1 = new Command(list, Command.SELECT, 0);
173 * cmd1.setText(&quot;Open&quot;);   177 * cmd1.setText(&quot;Open&quot;);
174 * cmd1.setDefaultCommand();   178 * cmd1.setDefaultCommand();
175 * Command cmd2 = new Command(list, Command.SELECT, 0);   179 * Command cmd2 = new Command(list, Command.SELECT, 0);
176 * cmd2.setText(&quot;Edit&quot;);   180 * cmd2.setText(&quot;Edit&quot;);
177 * Command cmd3 = new Command(list, Command.SELECT, 0);   181 * Command cmd3 = new Command(list, Command.SELECT, 0);
178 * cmd3.setText(&quot;Delete&quot;);   182 * cmd3.setText(&quot;Delete&quot;);
179 * Command cmd4 = new Command(composite1, Command.EXIT, 0); // create a EXIT type   183 * Command cmd4 = new Command(composite1, Command.EXIT, 0); // create a EXIT type
180 * cmd4.setText(&quot;Exit&quot;);   184 * cmd4.setText(&quot;Exit&quot;);
181 * </pre></code>   185 * </pre></code>
182 *   186 *
183 * <dl>   187 * <dl>
184 * <dt><b>Command types: </b></dt>   188 * <dt><b>Command types: </b></dt>
185 * <dd>COMMANDGROUP: represents a special command that contains sub-commands   189 * <dd>COMMANDGROUP: represents a special command that contains sub-commands
186 * </dd>   190 * </dd>
187 * <dd>GENERAL, SELECT, OK, CANCEL, DELETE, BACK, EXIT, STOP, HELP: Logical   191 * <dd>GENERAL, SELECT, OK, CANCEL, DELETE, BACK, EXIT, STOP, HELP: Logical
188 * command types</dd>   192 * command types</dd>
189 * <dt><b>Events: </b></dt>   193 * <dt><b>Events: </b></dt>
190 * <dd>Selection</dd>   194 * <dd>Selection</dd>
191 * </dl>   195 * </dl>
192 * <p>   196 * <p>
193 * IMPORTANT: This class is <em>not</em> intended to be subclassed.   197 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
194 * </p>   198 * </p>
195 */   199 */
196 public class Command extends Item {   200 public class Command extends Item {
197         Control control;   201         Control control;
198         int type;   202         int type;
199         int priority;   203         int priority;
200         int accelerator;   204         int accelerator;
201         boolean enabled;   205         boolean enabled;
202         boolean defaultCommand;   206         boolean defaultCommand;
203         String label;   207         String label;
204         Vector listeners = null;   208         Vector listeners = null;
205         private static CommandHandle cmdHandle = new CommandHandle();   209         private static CommandHandle cmdHandle = new CommandHandle();
206         private boolean dispose = false;   210         private boolean dispose = false;
207         private static boolean hasHandleFocusIn = false;   211         private static boolean hasHandleFocusIn = false;
208         int selectionListenerCount = 0;   212         int selectionListenerCount = 0;
209     213  
210         /**   214         /**
211          * A command that can be bound to any hardware keys or softkeys.   215          * A command that can be bound to any hardware keys or softkeys.
212          *   216          *
213          * <P>   217          * <P>
214          * Value <code>1</code> is assigned to <code>GENERAL</code>.   218          * Value <code>1</code> is assigned to <code>GENERAL</code>.
215          * </P>   219          * </P>
216          *    220          * 
217          */   221          */
218         public static final int GENERAL = 1;   222         public static final int GENERAL = 1;
219     223  
220         /**   224         /**
221          * A command that represents the context-sensitive action.   225          * A command that represents the context-sensitive action.
222          *   226          *
223          * <P>   227          * <P>
224          * Value <code>2</code> is assigned to <code>SELECT</code>.   228          * Value <code>2</code> is assigned to <code>SELECT</code>.
225          * </P>   229          * </P>
226          *    230          * 
227          */   231          */
228         public static final int SELECT = 2;   232         public static final int SELECT = 2;
229     233  
230         /**   234         /**
231          * A special command used for grouping commands. This command does not fire   235          * A special command used for grouping commands. This command does not fire
232          * SelectionEvents if there are any commands associated. Instead, pressing   236          * SelectionEvents if there are any commands associated. Instead, pressing
233          * down the command results in displaying sub-commands.   237          * down the command results in displaying sub-commands.
234          * <P>   238          * <P>
235          * Value <code>10</code> is assigned to <code>COMMANDGROUP</code>.   239          * Value <code>10</code> is assigned to <code>COMMANDGROUP</code>.
236          * </P>   240          * </P>
237          * </DL>   241          * </DL>
238          *    242          * 
239          */   243          */
240         public static final int COMMANDGROUP = 10;   244         public static final int COMMANDGROUP = 10;
241     245  
242         /**   246         /**
243          * A navigation command that returns the user to the logical OK action.   247          * A navigation command that returns the user to the logical OK action.
244          *   248          *
245          * <P>   249          * <P>
246          * Value <code>3</code> is assigned to <code>OK</code>.   250          * Value <code>3</code> is assigned to <code>OK</code>.
247          * </P>   251          * </P>
248          *    252          * 
249          */   253          */
250         public static final int OK = 3;   254         public static final int OK = 3;
251     255  
252         /**   256         /**
253          * A command that is a standard negative answer to an action.   257          * A command that is a standard negative answer to an action.
254          *   258          *
255          * <p>   259          * <p>
256          * With this command type, the application hints to the implementation that   260          * With this command type, the application hints to the implementation that
257          * the user wants to dismiss the current action.   261          * the user wants to dismiss the current action.
258          * </p>   262          * </p>
259          * <P>   263          * <P>
260          * Value <code>4</code> is assigned to <code>CANCEL</code>.   264          * Value <code>4</code> is assigned to <code>CANCEL</code>.
261          * </P>   265          * </P>
262          *    266          * 
263          */   267          */
264         public static final int CANCEL = 4;   268         public static final int CANCEL = 4;
265     269  
266         /**   270         /**
267          * This command hints to the implementation to destroy data.   271          * This command hints to the implementation to destroy data.
268          * </p>   272          * </p>
269          * <P>   273          * <P>
270          * Value <code>5</code> is assigned to <code>DELETE</code>.   274          * Value <code>5</code> is assigned to <code>DELETE</code>.
271          * </P>   275          * </P>
272          *    276          * 
273          */   277          */
274         public static final int DELETE = 5;   278         public static final int DELETE = 5;
275     279  
276         /**   280         /**
277          * A command that hints to the implementation to navigate backward.   281          * A command that hints to the implementation to navigate backward.
278          *   282          *
279          * <P>   283          * <P>
280          * Value <code>6</code> is assigned to <code>BACK</code>.   284          * Value <code>6</code> is assigned to <code>BACK</code>.
281          * </P>   285          * </P>
282          *    286          * 
283          */   287          */
284         public static final int BACK = 6;   288         public static final int BACK = 6;
285     289  
286         /**   290         /**
287          * A command that indicates an exiting action.   291          * A command that indicates an exiting action.
288          * <P>   292          * <P>
289          * Value <code>7</code> is assigned to <code>EXIT</code>.   293          * Value <code>7</code> is assigned to <code>EXIT</code>.
290          * </P>   294          * </P>
291          * </DL>   295          * </DL>
292          *    296          * 
293          */   297          */
294         public static final int EXIT = 7;   298         public static final int EXIT = 7;
295     299  
296         /**   300         /**
297          * A command that stops some currently running process, operation, etc.   301          * A command that stops some currently running process, operation, etc.
298          * Nothing is stopped automatically by the implementation.   302          * Nothing is stopped automatically by the implementation.
299          *   303          *
300          * <P>   304          * <P>
301          * Value <code>8</code> is assigned to <code>STOP</code>.   305          * Value <code>8</code> is assigned to <code>STOP</code>.
302          * </P>   306          * </P>
303          *    307          * 
304          */   308          */
305         public static final int STOP = 8;   309         public static final int STOP = 8;
306     310  
307         /**   311         /**
308          * A command that specifies a request for on-line help. No help information   312          * A command that specifies a request for on-line help. No help information
309          * is shown automatically by the implementation. The application is   313          * is shown automatically by the implementation. The application is
310          * responsible for answering the event.   314          * responsible for answering the event.
311          *   315          *
312          * <P>   316          * <P>
313          * Value <code>9</code> is assigned to <code>HELP</code>.   317          * Value <code>9</code> is assigned to <code>HELP</code>.
314          * </P>   318          * </P>
315          *    319          * 
316          */   320          */
317         public static final int HELP = 9;   321         public static final int HELP = 9;
318     322  
319         /**   323         /**
320          * Constructs a new instance of this class given an associated Command, a   324          * Constructs a new instance of this class given an associated Command, a
321          * type value describing its behaviour and priority for positioning hints.   325          * type value describing its behaviour and priority for positioning hints.
322          * <p>   326          * <p>
323          * The constructor creates a command associated with a Command (cannot be   327          * The constructor creates a command associated with a Command (cannot be
324          * null and must be COMMANDGROUP type). The implementation must group   328          * null and must be COMMANDGROUP type). The implementation must group
325          * commands within the same command group.   329          * commands within the same command group.
326          * </p>   330          * </p>
327          *   331          *
328          * @param command   332          * @param command
329          *            the associated Command. It must be COMMANDGROUP type.   333          *            the associated Command. It must be COMMANDGROUP type.
330          *            Otherwise throw an exception.   334          *            Otherwise throw an exception.
331          * @param type   335          * @param type
332          *            the type of Command to construct   336          *            the type of Command to construct
333          * @param priority   337          * @param priority
334          *            the priority value. The lowest value (zero) has the lowest   338          *            the priority value. The lowest value (zero) has the lowest
335          *            precedence.   339          *            precedence.
336          *   340          *
337          * @exception IllegalArgumentException   341          * @exception IllegalArgumentException
338          *                <ul>   342          *                <ul>
339          *                <li>ERROR_INVALID_ARGUMENT - if the command type is not   343          *                <li>ERROR_INVALID_ARGUMENT - if the command type is not
340          *                COMMANDGROUP</li>   344          *                COMMANDGROUP</li>
341          *                <li>ERROR_INVALID_ARGUMENT - if the type is not one of   345          *                <li>ERROR_INVALID_ARGUMENT - if the type is not one of
342          *                the valid command types</li>   346          *                the valid command types</li>
343          *                <li>ERROR_INVALID_ARGUMENT - if the priority is less than   347          *                <li>ERROR_INVALID_ARGUMENT - if the priority is less than
344          *                zero</li>   348          *                zero</li>
345          *                <li>ERROR_NULL_ARGUMENT - if the command is null</li>   349          *                <li>ERROR_NULL_ARGUMENT - if the command is null</li>
346          *                </ul>   350          *                </ul>
347          * @exception SWTException   351          * @exception SWTException
348          *                <ul>   352          *                <ul>
349          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   353          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
350          *                thread that created the parent</li>   354          *                thread that created the parent</li>
351          *                <li>ERROR_INVALID_SUBCLASS - if this class is not an   355          *                <li>ERROR_INVALID_SUBCLASS - if this class is not an
352          *                allowed subclass</li>   356          *                allowed subclass</li>
353          *                </ul>   357          *                </ul>
354          *   358          *
355          * @see #GENERAL   359          * @see #GENERAL
356          * @see #SELECT   360          * @see #SELECT
357          * @see #OK   361          * @see #OK
358          * @see #CANCEL   362          * @see #CANCEL
359          * @see #DELETE   363          * @see #DELETE
360          * @see #BACK   364          * @see #BACK
361          * @see #EXIT   365          * @see #EXIT
362          * @see #STOP   366          * @see #STOP
363          * @see #HELP   367          * @see #HELP
364          */   368          */
365           369        
366         boolean isValidSubclass() {   370         boolean isValidSubclass() {
367                 return isValidClass(getClass());   371                 return isValidClass(getClass());
368         }   372         }
369           373        
370         boolean isValidClass(Class clazz) {   374         boolean isValidClass(Class clazz) {
371                 String name = clazz.getName();   375                 String name = clazz.getName();
372                 int index = name.lastIndexOf('.');   376                 int index = name.lastIndexOf('.');
373                   377                
374                 // allow mobile extensions   378                 // allow mobile extensions
375                 if (name.substring(0, index + 1).equals("org.eclipse.ercp.swt.mobile.")) return true;   379                 if (name.substring(0, index + 1).equals("org.eclipse.ercp.swt.mobile.")) return true;
376     380  
377                 return false;     381                 return false;  
378         }   382         }
379           383        
380         public Command(Command command, int type, int priority) {   384         public Command(Command command, int type, int priority) {
381                 super(cmdHandle.findControl(command), 0);   385                 super(cmdHandle.findControl(command), 0);
382                 if(command == null)   386                 if(command == null)
383                         SWT.error(SWT.ERROR_NULL_ARGUMENT);   387                         SWT.error(SWT.ERROR_NULL_ARGUMENT);
384                 if ((priority < 0) || (command.type != COMMANDGROUP))   388                 if ((priority < 0) || (command.type != COMMANDGROUP))
385                         SWT.error(SWT.ERROR_INVALID_ARGUMENT);   389                         SWT.error(SWT.ERROR_INVALID_ARGUMENT);
386                 if ((type <0) || (type > COMMANDGROUP)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   390                 if ((type <0) || (type > COMMANDGROUP)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
387                 if (!isValidSubclass()) SWT.error(SWT.ERROR_INVALID_SUBCLASS);   391                 if (!isValidSubclass()) SWT.error(SWT.ERROR_INVALID_SUBCLASS);
388                 final Command c = this;   392                 final Command c = this;
389                 command.addDisposeListener(new DisposeListener(){   393                 command.addDisposeListener(new DisposeListener(){
390     394  
391                         public void widgetDisposed(DisposeEvent e) {   395                         public void widgetDisposed(DisposeEvent e) {
392                                 c.internal_sendEvent(SWT.Dispose);   396                                 c.internal_sendEvent(SWT.Dispose);
393 //mdr                           c.dispose();   397 //mdr                           c.dispose();
394                         }});              398                         }});           
395                   399                
396                 Control control = cmdHandle.findControl(command);   400                 Control control = cmdHandle.findControl(command);
397                 this.control = control;   401                 this.control = control;
398                 this.type = type;   402                 this.type = type;
399                 this.priority = priority;   403                 this.priority = priority;
400                 this.accelerator = 0;   404                 this.accelerator = 0;
401                 this.enabled = true;   405                 this.enabled = true;
402                 cmdHandle.add(command, this);   406                 cmdHandle.add(command, this);
403         }   407         }
404     408  
405         /**   409         /**
406          * Constructs a new instance of this class given an associated Control, a   410          * Constructs a new instance of this class given an associated Control, a
407          * type value describing its behaviour and priority for positioning hints.   411          * type value describing its behaviour and priority for positioning hints.
408          * <p>   412          * <p>
409          * The type value is one of the type constants defined in class   413          * The type value is one of the type constants defined in class
410          * <code>Command</code>   414          * <code>Command</code>
411          * </p>   415          * </p>
412          *   416          *
413          * @param control   417          * @param control
414          *            the associated Control   418          *            the associated Control
415          * @param type   419          * @param type
416          *            the type of Command to construct   420          *            the type of Command to construct
417          * @param priority   421          * @param priority
418          *            the priority value. The lowest value (zero) has the lowest   422          *            the priority value. The lowest value (zero) has the lowest
419          *            precedence.   423          *            precedence.
420          * @exception IllegalArgumentException   424          * @exception IllegalArgumentException
421          *                <ul>   425          *                <ul>
422          *                <li>ERROR_INVALID_ARGUMENT - if the type is not one of   426          *                <li>ERROR_INVALID_ARGUMENT - if the type is not one of
423          *                the valid command types</li>   427          *                the valid command types</li>
424          *                <li>ERROR_INVALID_ARGUMENT - if the priority is less than   428          *                <li>ERROR_INVALID_ARGUMENT - if the priority is less than
425          *                zero</li>   429          *                zero</li>
426          *                <li>ERROR_NULL_ARGUMENT - if the control is null</li>   430          *                <li>ERROR_NULL_ARGUMENT - if the control is null</li>
427          *                </ul>   431          *                </ul>
428          * @exception SWTException   432          * @exception SWTException
429          *                <ul>   433          *                <ul>
430          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   434          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
431          *                thread that created the parent</li>   435          *                thread that created the parent</li>
432          *                <li>ERROR_INVALID_SUBCLASS - if this class is not an   436          *                <li>ERROR_INVALID_SUBCLASS - if this class is not an
433          *                allowed subclass</li>   437          *                allowed subclass</li>
434          *                </ul>   438          *                </ul>
435          *   439          *
436          * @see #GENERAL   440          * @see #GENERAL
437          * @see #SELECT   441          * @see #SELECT
438          * @see #OK   442          * @see #OK
439          * @see #CANCEL   443          * @see #CANCEL
440          * @see #DELETE   444          * @see #DELETE
441          * @see #BACK   445          * @see #BACK
442          * @see #EXIT   446          * @see #EXIT
443          * @see #STOP   447          * @see #STOP
444          * @see #HELP   448          * @see #HELP
445          */   449          */
446         public Command(Control control, int type, int priority) {   450         public Command(Control control, int type, int priority) {
447                 super(control, 0);   451                 super(control, 0);
448                 if (control == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);   452                 if (control == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);
449                 if ((type <0) || (type > COMMANDGROUP)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   453                 if ((type <0) || (type > COMMANDGROUP)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
450                 if ((priority < 0)) {   454                 if ((priority < 0)) {
451                         if (priority != -1 || type != Command.EXIT) {   455                         if (priority != -1 || type != Command.EXIT) {
452                                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);   456                                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
453                         }   457                         }
454                 }   458                 }
455                 if (!isValidSubclass()) SWT.error(SWT.ERROR_INVALID_SUBCLASS);   459                 if (!isValidSubclass()) SWT.error(SWT.ERROR_INVALID_SUBCLASS);
456                 final Command c = this;   460                 final Command c = this;
457                 control.addDisposeListener(new DisposeListener(){   461                 control.addDisposeListener(new DisposeListener(){
458     462  
459                         public void widgetDisposed(DisposeEvent e) {   463                         public void widgetDisposed(DisposeEvent e) {
460                                 c.internal_sendEvent(SWT.Dispose);   464                                 c.internal_sendEvent(SWT.Dispose);
461                                 c.dispose();   465                                 c.dispose();
462                         }});              466                         }});           
463                   467                
464                 if(!hasHandleFocusIn) {   468                 if(!hasHandleFocusIn) {
465                         control.getDisplay().addFilter(SWT.FocusIn, cmdHandle);   469                         control.getDisplay().addFilter(SWT.FocusIn, cmdHandle);
466                         control.getDisplay().addFilter(SWT.FocusOut, cmdHandle);   470                         control.getDisplay().addFilter(SWT.FocusOut, cmdHandle);
467                         hasHandleFocusIn = true;   471                         hasHandleFocusIn = true;
468                 }   472                 }
469                 this.control = control;   473                 this.control = control;
470                 this.type = type;   474                 this.type = type;
471                 this.priority = priority;   475                 this.priority = priority;
472                 this.accelerator = 0;   476                 this.accelerator = 0;
473                 this.enabled = true;   477                 this.enabled = true;
474                 cmdHandle.add(control, this);   478                 cmdHandle.add(control, this);
475         }   479         }
476           480        
477         /**   481         /**
478          * Adds the listener to the collection of listeners who will be notified   482          * Adds the listener to the collection of listeners who will be notified
479          * when the command is activated, by sending it one of the messages defined   483          * when the command is activated, by sending it one of the messages defined
480          * in the <code>SelectionListener</code> interface.   484          * in the <code>SelectionListener</code> interface.
481          * <p>   485          * <p>
482          * When <code>widgetSelected</code> is called, the stateMask field of the   486          * When <code>widgetSelected</code> is called, the stateMask field of the
483          * event object is valid. <code>widgetDefaultSelected</code> is not   487          * event object is valid. <code>widgetDefaultSelected</code> is not
484          * called.   488          * called.
485          * </p>   489          * </p>
486          *   490          *
487          * @param listener   491          * @param listener
488          *            the listener which should be notified   492          *            the listener which should be notified
489          *   493          *
490          * @exception IllegalArgumentException   494          * @exception IllegalArgumentException
491          *                <ul>   495          *                <ul>
492          *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   496          *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
493          *                </ul>   497          *                </ul>
494          * @exception SWTException   498          * @exception SWTException
495          *                <ul>   499          *                <ul>
496          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   500          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
497          *                disposed</li>   501          *                disposed</li>
498          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   502          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
499          *                thread that created the parent</li>   503          *                thread that created the parent</li>
500          *                </ul>   504          *                </ul>
501          *   505          *
502          * @see SelectionListener   506          * @see SelectionListener
503          * @see #removeSelectionListener   507          * @see #removeSelectionListener
504          */   508          */
505         public void addSelectionListener(SelectionListener listener) {   509         public void addSelectionListener(SelectionListener listener) {
506                 checkWidget();   510                 checkWidget();
507                 if (listener == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);   511                 if (listener == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);
508                   512                
509                 TypedListener typedListener = new TypedListener(listener);   513                 TypedListener typedListener = new TypedListener(listener);
510                 addListener(SWT.Selection, typedListener);   514                 addListener(SWT.Selection, typedListener);
511                 addListener(SWT.DefaultSelection, typedListener);   515                 addListener(SWT.DefaultSelection, typedListener);
512                 selectionListenerCount ++;   516                 selectionListenerCount ++;
513         }   517         }
514     518  
515         /**   519         /**
516          * Returns <code>true</code> if the receiver is enabled, and   520          * Returns <code>true</code> if the receiver is enabled, and
517          * <code>false</code> otherwise. A disabled control is typically not   521          * <code>false</code> otherwise. A disabled control is typically not
518          * selectable from the user interface and draws with an inactive or "grayed"   522          * selectable from the user interface and draws with an inactive or "grayed"
519          * look.   523          * look.
520          *   524          *
521          * @return the receiver's enabled state   525          * @return the receiver's enabled state
522          *   526          *
523          * @exception SWTException   527          * @exception SWTException
524          *                <ul>   528          *                <ul>
525          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   529          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
526          *                disposed</li>   530          *                disposed</li>
527          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   531          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
528          *                thread that created the parent</li>   532          *                thread that created the parent</li>
529          *                </ul>   533          *                </ul>
530          *   534          *
531          * @see #isEnabled   535          * @see #isEnabled
532          */   536          */
533         public boolean getEnabled() {   537         public boolean getEnabled() {
534                 checkWidget();   538                 checkWidget();
535                 return enabled;   539                 return enabled;
536         }   540         }
537     541  
538         /**   542         /**
539          * Returns the command's long label, which shall be null if it has never   543          * Returns the command's long label, which shall be null if it has never
540          * been set.   544          * been set.
541          *   545          *
542          * @return the receiver's text. Can be null.   546          * @return the receiver's text. Can be null.
543          *   547          *
544          * @exception SWTException   548          * @exception SWTException
545          *                <ul>   549          *                <ul>
546          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   550          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
547          *                disposed</li>   551          *                disposed</li>
548          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   552          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
549          *                thread that created the parent</li>   553          *                thread that created the parent</li>
550          *                </ul>   554          *                </ul>
551          * @see #setLongLabel(String)   555          * @see #setLongLabel(String)
552          */   556          */
553         public String getLongLabel() {   557         public String getLongLabel() {
554                 checkWidget();   558                 checkWidget();
555                 return label;   559                 return label;
556         }   560         }
557     561  
558         /**   562         /**
559          * Returns the command's priority value.   563          * Returns the command's priority value.
560          *   564          *
561          * @return the priority value.   565          * @return the priority value.
562          *   566          *
563          * @exception SWTException   567          * @exception SWTException
564          *                <ul>   568          *                <ul>
565          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   569          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
566          *                disposed</li>   570          *                disposed</li>
567          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   571          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
568          *                thread that created the parent</li>   572          *                thread that created the parent</li>
569          *                </ul>   573          *                </ul>
570          */   574          */
571         public int getPriority() {   575         public int getPriority() {
572                 checkWidget();   576                 checkWidget();
573                 return priority;   577                 return priority;
574         }   578         }
575     579  
576         /**   580         /**
577          * Returns <code>true</code> if the command is a Default Command, and   581          * Returns <code>true</code> if the command is a Default Command, and
578          * <code>false</code> otherwise. By default a command is not a default   582          * <code>false</code> otherwise. By default a command is not a default
579          * one.   583          * one.
580          *   584          *
581          * @return boolean the command's state   585          * @return boolean the command's state
582          * @exception SWTException   586          * @exception SWTException
583          *                <ul>   587          *                <ul>
584          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   588          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
585          *                disposed</li>   589          *                disposed</li>
586          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   590          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
587          *                thread that created the parent</li>   591          *                thread that created the parent</li>
588          *                </ul>   592          *                </ul>
589          * @see #setDefaultCommand()   593          * @see #setDefaultCommand()
590          */   594          */
591         public boolean isDefaultCommand() {   595         public boolean isDefaultCommand() {
592                 checkWidget();   596                 checkWidget();
593                 return defaultCommand;   597                 return defaultCommand;
594         }   598         }
595     599  
596         /**   600         /**
597          * Returns <code>true</code> if the receiver is enabled and all of the   601          * Returns <code>true</code> if the receiver is enabled and all of the
598          * receiver's ancestors are enabled, and <code>false</code> otherwise. A   602          * receiver's ancestors are enabled, and <code>false</code> otherwise. A
599          * disabled control is typically not selectable from the user interface and   603          * disabled control is typically not selectable from the user interface and
600          * draws with an inactive or "grayed" look.   604          * draws with an inactive or "grayed" look.
601          *   605          *
602          * @return boolean the receiver's enabled state   606          * @return boolean the receiver's enabled state
603          * @exception SWTException   607          * @exception SWTException
604          *                <ul>   608          *                <ul>
605          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   609          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
606          *                disposed</li>   610          *                disposed</li>
607          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   611          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
608          *                thread that created the parent</li>   612          *                thread that created the parent</li>
609          *                </ul>   613          *                </ul>
610          * @see #getEnabled   614          * @see #getEnabled
611          */   615          */
612         public boolean isEnabled() {   616         public boolean isEnabled() {
613                 checkWidget();   617                 checkWidget();
614                 if(control == null || control.isDisposed())   618                 if(control == null || control.isDisposed())
615                         return false;   619                         return false;
616                 return (cmdHandle.isEnabled(this) && control.isEnabled());   620                 return (cmdHandle.isEnabled(this) && control.isEnabled());
617         }   621         }
618     622  
619         /**   623         /**
620          * Removes the listener from the collection of listeners who will be   624          * Removes the listener from the collection of listeners who will be
621          * notified when the command is activated.   625          * notified when the command is activated.
622          *   626          *
623          * @param listener   627          * @param listener
624          *            the listener which should be notified   628          *            the listener which should be notified
625          *   629          *
626          * @exception IllegalArgumentException   630          * @exception IllegalArgumentException
627          *                <ul>   631          *                <ul>
628          *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   632          *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
629          *                </ul>   633          *                </ul>
630          * @exception SWTException   634          * @exception SWTException
631          *                <ul>   635          *                <ul>
632          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   636          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
633          *                disposed</li>   637          *                disposed</li>
634          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   638          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
635          *                thread that created the parent</li>   639          *                thread that created the parent</li>
636          *                </ul>   640          *                </ul>
637          *   641          *
638          * @see SelectionListener   642          * @see SelectionListener
639          * @see #addSelectionListener   643          * @see #addSelectionListener
640          */   644          */
641         public void removeSelectionListener(SelectionListener listener) {   645         public void removeSelectionListener(SelectionListener listener) {
642                 checkWidget();   646                 checkWidget();
643                 if (listener == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);   647                 if (listener == null)  SWT.error(SWT.ERROR_NULL_ARGUMENT);
644                   648                
645                 removeListener(SWT.Selection, listener);          649                 removeListener(SWT.Selection, listener);       
646                 removeListener(SWT.DefaultSelection, listener);   650                 removeListener(SWT.DefaultSelection, listener);
647                 selectionListenerCount--;   651                 selectionListenerCount--;
648         }   652         }
649     653  
650         /**   654         /**
651          * Sets the command accelerator. An accelerator is the bit-wise OR of zero   655          * Sets the command accelerator. An accelerator is the bit-wise OR of zero
652          * or more modifier masks and a key. Examples:   656          * or more modifier masks and a key. Examples:
653          * <code>SWT.MOD1 | SWT.MOD2 | 'T'</code>,   657          * <code>SWT.MOD1 | SWT.MOD2 | 'T'</code>,
654          * <code>SWT.CONTROL | SWT.SHIFT | 'T'</code>.   658          * <code>SWT.CONTROL | SWT.SHIFT | 'T'</code>.
655          *   659          *
656          * This requires fullkeyboard or computer keyboard-like support and is an   660          * This requires fullkeyboard or computer keyboard-like support and is an
657          * implementation-dependent feature. It will be gracefully ignored if the   661          * implementation-dependent feature. It will be gracefully ignored if the
658          * implementation does not support keyboard accelerator.   662          * implementation does not support keyboard accelerator.
659          *   663          *
660          * @param accelerator   664          * @param accelerator
661          *            an integer that is the bit-wise OR of masks and a key   665          *            an integer that is the bit-wise OR of masks and a key
662          *   666          *
663          * @exception IllegalArgumentException   667          * @exception IllegalArgumentException
664          *                <ul>   668          *                <ul>
665          *                <li>ERROR_INVALID_ARGUMENT - if accelerator value is   669          *                <li>ERROR_INVALID_ARGUMENT - if accelerator value is
666          *                invalid</li>   670          *                invalid</li>
667          *                </ul>   671          *                </ul>
668          * @exception SWTException   672          * @exception SWTException
669          *                <ul>   673          *                <ul>
670          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   674          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
671          *                disposed</li>   675          *                disposed</li>
672          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   676          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
673          *                thread that created the parent</li>   677          *                thread that created the parent</li>
674          *                </ul>   678          *                </ul>
675          *    679          * 
676          */   680          */
677         public void setAccelerator(int accelerator) {   681         public void setAccelerator(int accelerator) {
678                 checkWidget();   682                 checkWidget();
679                 boolean remakemenu = false;   683                 boolean remakemenu = false;
680                 if(this.accelerator != accelerator && isFocusControl())   684                 if(this.accelerator != accelerator && isFocusControl())
681                         remakemenu = true;   685                         remakemenu = true;
682                 this.accelerator = accelerator;   686                 this.accelerator = accelerator;
683                 if(remakemenu)   687                 if(remakemenu)
684                         cmdHandle.makeMenu(this);   688                         cmdHandle.makeMenu(this);
685         }   689         }
686     690  
687         /**   691         /**
688          * Sets the default command.   692          * Sets the default command.
689          *    693          * 
690          */   694          */
691         public void setDefaultCommand() {   695         public void setDefaultCommand() {
692                 checkWidget();   696                 checkWidget();
693                 defaultCommand = true;   697                 defaultCommand = true;
694                 cmdHandle.setDefaultCommand(this);   698                 cmdHandle.setDefaultCommand(this);
695         }   699         }
696     700  
697         /**   701         /**
698          * Enables the command if the argument is <code>true</code>, and disables   702          * Enables the command if the argument is <code>true</code>, and disables
699          * it otherwise. A disabled control is typically not selectable from the   703          * it otherwise. A disabled control is typically not selectable from the
700          * user interface and draws with an inactive or "grayed" look; or even   704          * user interface and draws with an inactive or "grayed" look; or even
701          * completely removed from the user interface.   705          * completely removed from the user interface.
702          *   706          *
703          * @param enabled   707          * @param enabled
704          *            the new enabled state   708          *            the new enabled state
705          *   709          *
706          * @exception SWTException   710          * @exception SWTException
707          *                <ul>   711          *                <ul>
708          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   712          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
709          *                disposed</li>   713          *                disposed</li>
710          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   714          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
711          *                thread that created the parent</li>   715          *                thread that created the parent</li>
712          *                </ul>   716          *                </ul>
713          */   717          */
714         public void setEnabled(boolean enabled) {   718         public void setEnabled(boolean enabled) {
715                 checkWidget();   719                 checkWidget();
716                 boolean remakemenu = false;   720                 boolean remakemenu = false;
717                 if(this.enabled != enabled && isFocusControl())   721                 if(this.enabled != enabled && isFocusControl())
718                         remakemenu = true;   722                         remakemenu = true;
719                 this.enabled = enabled;   723                 this.enabled = enabled;
720                 if(remakemenu){   724                 if(remakemenu){
721                         cmdHandle.makeMenu(this);   725                         cmdHandle.makeMenu(this);
722                 }   726                 }
723         }   727         }
724     728  
725         /**   729         /**
726          * Sets the command's long label text.   730          * Sets the command's long label text.
727          *   731          *
728          * Commands may optionally have long labels, enabling the application to   732          * Commands may optionally have long labels, enabling the application to
729          * specify a short form for button or softkey, and a more verbose form when   733          * specify a short form for button or softkey, and a more verbose form when
730          * realized as menu item.   734          * realized as menu item.
731          *   735          *
732          * @param label   736          * @param label
733          *            the long descriptive label text. Can be null.   737          *            the long descriptive label text. Can be null.
734          *   738          *
735          * @exception SWTException   739          * @exception SWTException
736          *                <ul>   740          *                <ul>
737          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been   741          *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
738          *                disposed</li>   742          *                disposed</li>
739          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the   743          *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
740          *                thread that created the parent</li>   744          *                thread that created the parent</li>
741          *                </ul>   745          *                </ul>
742          * @see #getLongLabel()   746          * @see #getLongLabel()
743          */   747          */
744         public void setLongLabel(String label) {   748         public void setLongLabel(String label) {
745                 checkWidget();   749                 checkWidget();
746                 boolean remakemenu = false;   750                 boolean remakemenu = false;
747                 if(isFocusControl()) {   751                 if(isFocusControl()) {
748                         if(this.label == null) {   752                         if(this.label == null) {
749                                 if(label != null)   753                                 if(label != null)
750                                         remakemenu = true;   754                                         remakemenu = true;
751                         } else {   755                         } else {
752                                 if(label == null)   756                                 if(label == null)
753                                         remakemenu = true;   757                                         remakemenu = true;
754                                 else if(!this.label.equals(label))   758                                 else if(!this.label.equals(label))
755                                         remakemenu = true;   759                                         remakemenu = true;
756                         }   760                         }
757                 }   761                 }
758                 this.label = label;   762                 this.label = label;
759                 if(remakemenu)   763                 if(remakemenu)
760                         cmdHandle.makeMenu(this);   764                         cmdHandle.makeMenu(this);
761         }   765         }
762           766        
763         public void setText (String string) {   767         public void setText (String string) {
764                 checkWidget ();   768                 checkWidget ();
765                 boolean remakemenu = false;   769                 boolean remakemenu = false;
766                 if(!super.getText().equals(string) && isFocusControl())   770                 if(!super.getText().equals(string) && isFocusControl())
767                         remakemenu = true;   771                         remakemenu = true;
768                 super.setText(string);   772                 super.setText(string);
769                 if(remakemenu)   773                 if(remakemenu)
770                         cmdHandle.makeMenu(this);   774                         cmdHandle.makeMenu(this);
771         }   775         }
772           776        
773         public void dispose() {   777         public void dispose() {
774                 if(listeners != null) {   778                 if(listeners != null) {
775                         CommandNode node = cmdHandle.findCommandNode(this);   779                         CommandNode node = cmdHandle.findCommandNode(this);
776                         Enumeration elements = listeners.elements();   780                         Enumeration elements = listeners.elements();
777                         while(elements.hasMoreElements()) {   781                         while(elements.hasMoreElements()) {
778                                 CommandListener cmdListener = (CommandListener)elements.nextElement();   782                                 CommandListener cmdListener = (CommandListener)elements.nextElement();
779                                 if(node != null && !node.isDispose()) {   783                                 if(node != null && !node.isDispose()) {
780                                         if(node.item != null && !node.item.isDisposed()) {   784                                         if(node.item != null && !node.item.isDisposed()) {
781                                                 node.item.removeListener(cmdListener.getEventType(), cmdListener);   785                                                 node.item.removeListener(cmdListener.getEventType(), cmdListener);
782                                         }   786                                         }
783                                 }   787                                 }
784                                 cmdListener = null;   788                                 cmdListener = null;
785                         }   789                         }
786                         this.listeners.clear();   790                         this.listeners.clear();
787                 }   791                 }
788                 this.listeners = null;   792                 this.listeners = null;
789                 cmdHandle.removeCommand(this);   793                 cmdHandle.removeCommand(this);
790                 dispose = true;   794                 dispose = true;
791         }   795         }
792     796  
793         public boolean isDisposed() {   797         public boolean isDisposed() {
794                 return dispose;   798                 return dispose;
795         }   799         }
796           800        
797         public void addListener(int eventType, Listener listener) {   801         public void addListener(int eventType, Listener listener) {
798                 checkWidget();   802                 checkWidget();
799                 if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);   803                 if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
800                   804                
801                 if(listeners == null)   805                 if(listeners == null)
802                         listeners = new Vector();   806                         listeners = new Vector();
803                 CommandListener commandListener = new CommandListener(this, eventType, listener);   807                 CommandListener commandListener = new CommandListener(this, eventType, listener);
804                 CommandNode node = cmdHandle.findCommandNode(this);   808                 CommandNode node = cmdHandle.findCommandNode(this);
805                 if(node != null && !node.isDispose()) {   809                 if(node != null && !node.isDispose()) {
806                         if(node.item != null && !node.item.isDisposed())   810                         if(node.item != null && !node.item.isDisposed())
807                                 node.item.addListener(eventType, commandListener);   811                                 node.item.addListener(eventType, commandListener);
808                 }   812                 }
809                 Enumeration elements = listeners.elements();   813                 Enumeration elements = listeners.elements();
810                 while(elements.hasMoreElements()) {   814                 while(elements.hasMoreElements()) {
811                         CommandListener cmdListener = (CommandListener)elements.nextElement();   815                         CommandListener cmdListener = (CommandListener)elements.nextElement();
812                         if(cmdListener.getEventType() == eventType && cmdListener.getListener() == listener) {   816                         if(cmdListener.getEventType() == eventType && cmdListener.getListener() == listener) {
813                                 return;   817                                 return;
814                         }   818                         }
815                 }   819                 }
816                 this.listeners.add(commandListener);   820                 this.listeners.add(commandListener);
817         }   821         }
818     822  
819         public void removeListener(int eventType, Listener listener) {   823         public void removeListener(int eventType, Listener listener) {
820                 checkWidget();   824                 checkWidget();
821                 if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);   825                 if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
822                   826                
823                 if(listeners == null)   827                 if(listeners == null)
824                         return;   828                         return;
825                 Enumeration elements = listeners.elements();   829                 Enumeration elements = listeners.elements();
826                 while(elements.hasMoreElements()) {   830                 while(elements.hasMoreElements()) {
827                         CommandListener cmdListener = (CommandListener)elements.nextElement();   831                         CommandListener cmdListener = (CommandListener)elements.nextElement();
828                         if(cmdListener.getEventType() == eventType && cmdListener.getListener() == listener) {   832                         if(cmdListener.getEventType() == eventType && cmdListener.getListener() == listener) {
829                                 CommandNode node = cmdHandle.findCommandNode(this);   833                                 CommandNode node = cmdHandle.findCommandNode(this);
830                                 if(node != null && !node.isDispose()) {   834                                 if(node != null && !node.isDispose()) {
831                                         if(node.item != null && !node.item.isDisposed()) {   835                                         if(node.item != null && !node.item.isDisposed()) {
832                                                 node.item.removeListener(eventType, cmdListener);   836                                                 node.item.removeListener(eventType, cmdListener);
833                                         }   837                                         }
834                                 }   838                                 }
835                                 this.listeners.remove(cmdListener);   839                                 this.listeners.remove(cmdListener);
836                                 cmdListener = null;   840                                 cmdListener = null;
837                                 break;   841                                 break;
838                         }   842                         }
839                 }   843                 }
840         }   844         }
841           845        
842         public void Command_SendEvent(int event){   846         public void Command_SendEvent(int event){
843                 this.internal_sendEvent(event);   847                 this.internal_sendEvent(event);
844         }   848         }
845           849        
846         public String toString() {   850         public String toString() {
847                 return "Command {label:"+this.getText()+", long label:"+ label +", type:"+type+", priority:"+priority+"}";   851                 return "Command {label:"+this.getText()+", long label:"+ label +", type:"+type+", priority:"+priority+"}";
848         }   852         }
849           853        
850         // fix bug 99158 problem 2   854         // fix bug 99158 problem 2
851         // check control has focus or shell has active   855         // check control has focus or shell has active
852         private boolean isFocusControl() {   856         private boolean isFocusControl() {
853                 if(control.isFocusControl() ||   857                 if(control.isFocusControl() ||
854                         (control instanceof Shell && control.getDisplay().getActiveShell() == control))   858                         (control instanceof Shell && control.getDisplay().getActiveShell() == control))
855                         return true;   859                         return true;
856                 // fix against 101554   860                 // fix against 101554
857                 if (control instanceof Composite)       {         861                 if (control instanceof Composite)       {      
858                           862                        
859                         return isChildFocusControl((Composite)control);   863                         return isChildFocusControl((Composite)control);
860                 }   864                 }
861                 return false;   865                 return false;
862         }   866         }
863     867  
864         // fix against 101554   868         // fix against 101554
865         // look for all possible children to see if anyone contains focus   869         // look for all possible children to see if anyone contains focus
866         private boolean isChildFocusControl(Composite c) {   870         private boolean isChildFocusControl(Composite c) {
867                   871                
868                   872                
869                 if (c == null) return false;   873                 if (c == null) return false;
870                 Control[] children = c.getChildren();   874                 Control[] children = c.getChildren();
871                 if (children == null) return false; //no   875                 if (children == null) return false; //no
872     876  
873                 for (int i=0;i<children.length;i++) {   877                 for (int i=0;i<children.length;i++) {
874                         if (children[i] == null) continue;   878                         if (children[i] == null) continue;
875                         if (children[i].isFocusControl()){   879                         if (children[i].isFocusControl()){
876                                 return true;   880                                 return true;
877                         }   881                         }
878                         if(children[i] instanceof Canvas || children[i] instanceof CaptionedControl || children[i] instanceof Composite) {   882                         if(children[i] instanceof Canvas || children[i] instanceof CaptionedControl || children[i] instanceof Composite) {
879                                   883                                
880                                 if(isChildFocusControl((Composite)children[i]))   884                                 if(isChildFocusControl((Composite)children[i]))
881                                         return true;   885                                         return true;
882                         }   886                         }
883                         if(children[i] instanceof SortedList){   887                         if(children[i] instanceof SortedList){
884                                 Control child = ((SortedList) children[i]).getchild();   888                                 Control child = ((SortedList) children[i]).getchild();
885                                 if(child.isFocusControl()){   889                                 if(child.isFocusControl()){
886                                         return true;   890                                         return true;
887                                 }   891                                 }
888                         }   892                         }
889                 }   893                 }
890                 return false;   894                 return false;
891         }   895         }
892     896  
893           897        
894 // Command test code   898 // Command test code
895 /*   899 /*
896         public final static void main(String[] args){   900         public final static void main(String[] args){
897                 final Display display = new Display();   901                 final Display display = new Display();
898                 final Shell shell = new Shell(display, SWT.DIALOG_TRIM);   902                 final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
899                 shell.setToolTipText("Shell 1");   903                 shell.setToolTipText("Shell 1");
900                 Command command = new Command(shell, Command.OK, 1);   904                 Command command = new Command(shell, Command.OK, 1);
901                 command.setText("OK");   905                 command.setText("OK");
902                 Button button = new Button(shell, SWT.BORDER);   906                 Button button = new Button(shell, SWT.BORDER);
903                 button.setText("open");   907                 button.setText("open");
904                 button.pack();   908                 button.pack();
905                   909                
906                 button.addSelectionListener(new SelectionListener() {   910                 button.addSelectionListener(new SelectionListener() {
907                         public void widgetSelected(SelectionEvent e) {   911                         public void widgetSelected(SelectionEvent e) {
908                                 Shell s = new Shell(shell, SWT.DIALOG_TRIM);   912                                 Shell s = new Shell(shell, SWT.DIALOG_TRIM);
909                                 s.setToolTipText("Shell 2");   913                                 s.setToolTipText("Shell 2");
910                                 Command c = new Command(s, Command.EXIT, 1);   914                                 Command c = new Command(s, Command.EXIT, 1);
911                                 c.setText("EXIT");   915                                 c.setText("EXIT");
912     916  
913                                 Button b = new Button(s, SWT.BORDER);   917                                 Button b = new Button(s, SWT.BORDER);
914                                 Command c2 = new Command(b, Command.GENERAL, 1);   918                                 Command c2 = new Command(b, Command.GENERAL, 1);
915                                 c2.setText("AAA");   919                                 c2.setText("AAA");
916                                 b.setText("sssss");   920                                 b.setText("sssss");
917                                 b.pack();   921                                 b.pack();
918                                 s.setSize(240, 320);   922                                 s.setSize(240, 320);
919                                 s.open();   923                                 s.open();
920                                 while( !s.isDisposed() ) {   924                                 while( !s.isDisposed() ) {
921                                         if( !display.readAndDispatch() )   925                                         if( !display.readAndDispatch() )
922                                                 display.sleep();   926                                                 display.sleep();
923                                 }   927                                 }
924                         }   928                         }
925                         public void widgetDefaultSelected(SelectionEvent e) {   929                         public void widgetDefaultSelected(SelectionEvent e) {
926                         }   930                         }
927                 });   931                 });
928                   932                
929                 shell.setSize(240, 320);   933                 shell.setSize(240, 320);
930                 shell.open();   934                 shell.open();
931                 while( !shell.isDisposed() ) {   935                 while( !shell.isDisposed() ) {
932                         if( !display.readAndDispatch() )   936                         if( !display.readAndDispatch() )
933                                 display.sleep();   937                                 display.sleep();
934                 }   938                 }
935                 display.dispose();        939                 display.dispose();     
936         }   940         }
937 */   941 */
938 /*   942 /*
939         public final static void main(String[] args){   943         public final static void main(String[] args){
940                 final String RESOURCE_DIRECTORY = "/resources/";    944                 final String RESOURCE_DIRECTORY = "/resources/"; 
941                 final Display display = new Display();   945                 final Display display = new Display();
942                 final Shell shell = new Shell(display, SWT.DIALOG_TRIM);   946                 final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
943                   947                
944                 Composite composite1 = new Composite(shell, SWT.NONE);   948                 Composite composite1 = new Composite(shell, SWT.NONE);
945                 Button com1Button1 = new Button(composite1, SWT.BORDER);   949                 Button com1Button1 = new Button(composite1, SWT.BORDER);
946                 com1Button1.setText("Compo1 Button1");   950                 com1Button1.setText("Compo1 Button1");
947                 com1Button1.pack();   951                 com1Button1.pack();
948 //              Command com1Button1Cmd1 = new Command(com1Button1, Command.OK, 0);   952 //              Command com1Button1Cmd1 = new Command(com1Button1, Command.OK, 0);
949 //              com1Button1Cmd1.setText("Compo1 Button1 Cmd1");   953 //              com1Button1Cmd1.setText("Compo1 Button1 Cmd1");
950 //              com1Button1Cmd1.addSelectionListener(new SelectionListener() {   954 //              com1Button1Cmd1.addSelectionListener(new SelectionListener() {
951 //                      public void widgetSelected(SelectionEvent e) {   955 //                      public void widgetSelected(SelectionEvent e) {
952 //                              System.out.println("Compo1 Button1 Cmd1 widgetSelected");   956 //                              System.out.println("Compo1 Button1 Cmd1 widgetSelected");
953 //                      }   957 //                      }
954 //                      public void widgetDefaultSelected(SelectionEvent e) {   958 //                      public void widgetDefaultSelected(SelectionEvent e) {
955 //                              System.out.println("Compo1 Button1 Cmd1 widgetDefaultSelected");   959 //                              System.out.println("Compo1 Button1 Cmd1 widgetDefaultSelected");
956 //                      }   960 //                      }
957 //              });   961 //              });
958                   962                
959                 Text com1Text1 = new Text(composite1, SWT.BORDER);   963                 Text com1Text1 = new Text(composite1, SWT.BORDER);
960                 com1Text1.setText("Compo1 Text1");   964                 com1Text1.setText("Compo1 Text1");
961                 com1Text1.pack();   965                 com1Text1.pack();
962                 composite1.pack();   966                 composite1.pack();
963                 composite1.setBackground(new Color(display, 0,0,255));   967                 composite1.setBackground(new Color(display, 0,0,255));
964     968  
965                 FormLayout com1Layout = new FormLayout();   969                 FormLayout com1Layout = new FormLayout();
966                 com1Layout.marginWidth = 3;   970                 com1Layout.marginWidth = 3;
967                 com1Layout.marginHeight = 3;   971                 com1Layout.marginHeight = 3;
968                 com1Layout.spacing = 3;   972                 com1Layout.spacing = 3;
969                 composite1.setLayout(com1Layout);   973                 composite1.setLayout(com1Layout);
970                   974                
971                 FormData com1fd11 = new FormData();   975                 FormData com1fd11 = new FormData();
972                 com1fd11.left = new FormAttachment(0, 0);   976                 com1fd11.left = new FormAttachment(0, 0);
973                 com1fd11.top = new FormAttachment(0, 0);   977                 com1fd11.top = new FormAttachment(0, 0);
974                 com1Button1.setLayoutData(com1fd11);   978                 com1Button1.setLayoutData(com1fd11);
975     979  
976                 FormData com1fd21 = new FormData();   980                 FormData com1fd21 = new FormData();
977                 com1fd21.left = new FormAttachment(com1Button1, 0);   981                 com1fd21.left = new FormAttachment(com1Button1, 0);
978                 com1fd21.top = new FormAttachment(0, 0);   982                 com1fd21.top = new FormAttachment(0, 0);
979                 com1Text1.setLayoutData(com1fd21);   983                 com1Text1.setLayoutData(com1fd21);
980     984  
981     985  
982                 Command com1Cmd1 = new Command(com1Text1, Command.OK, 0);   986                 Command com1Cmd1 = new Command(com1Text1, Command.OK, 0);
983                 com1Cmd1.setText("Compo1 Text1 Cmd1");   987                 com1Cmd1.setText("Compo1 Text1 Cmd1");
984                   988                
985     989  
986     990  
987                   991                
988                 Composite composite2 = new Composite(shell, SWT.NONE);   992                 Composite composite2 = new Composite(shell, SWT.NONE);
989                 composite2.setBackground(new Color(display, 255, 0, 0));   993                 composite2.setBackground(new Color(display, 255, 0, 0));
990     994  
991                 Command com2Cmd0 = new Command(composite2, Command.OK, 0);   995                 Command com2Cmd0 = new Command(composite2, Command.OK, 0);
992                 com2Cmd0.setText("Compo2 Cmd1");   996                 com2Cmd0.setText("Compo2 Cmd1");
993                 com2Cmd0.setImage(new Image(display, RESOURCE_DIRECTORY + "001.gif"));   997                 com2Cmd0.setImage(new Image(display, RESOURCE_DIRECTORY + "001.gif"));
994                   998                
995                 Button com2Button2 = new Button(composite2, SWT.BORDER);   999                 Button com2Button2 = new Button(composite2, SWT.BORDER);
996                 com2Button2.setText("Compo2 Button2");   1000                 com2Button2.setText("Compo2 Button2");
997                 com2Button2.pack();   1001                 com2Button2.pack();
998     1002  
999                 Command com2Cmd1 = new Command(com2Button2, Command.OK, 2);   1003                 Command com2Cmd1 = new Command(com2Button2, Command.OK, 2);
1000                 com2Cmd1.setText("Compo2 Button2 Cmd1");   1004                 com2Cmd1.setText("Compo2 Button2 Cmd1");
1001                 com2Cmd1.setImage(new Image(display, RESOURCE_DIRECTORY + "005.gif"));   1005                 com2Cmd1.setImage(new Image(display, RESOURCE_DIRECTORY + "005.gif"));
1002     1006  
1003                 Command com2Cmd2 = new Command(com2Button2, Command.COMMANDGROUP, 0);   1007                 Command com2Cmd2 = new Command(com2Button2, Command.COMMANDGROUP, 0);
1004                 com2Cmd2.setText("Compo2 Button2 Cmd2");   1008                 com2Cmd2.setText("Compo2 Button2 Cmd2");
1005                 com2Cmd2.setImage(new Image(display, RESOURCE_DIRECTORY + "iMac.JPG"));   1009                 com2Cmd2.setImage(new Image(display, RESOURCE_DIRECTORY + "iMac.JPG"));
1006                 com2Cmd2.addSelectionListener(new SelectionListener() {   1010                 com2Cmd2.addSelectionListener(new SelectionListener() {
1007                         public void widgetSelected(SelectionEvent e) {   1011                         public void widgetSelected(SelectionEvent e) {
1008 System.out.println("com2Cmd2 widgetSelected");   1012 System.out.println("com2Cmd2 widgetSelected");
1009                         }   1013                         }
1010                         public void widgetDefaultSelected(SelectionEvent e) {   1014                         public void widgetDefaultSelected(SelectionEvent e) {
1011 System.out.println("com2Cmd2 widgetDefaultSelected");   1015 System.out.println("com2Cmd2 widgetDefaultSelected");
1012                         }   1016                         }
1013                 });   1017                 });
1014 //              com2Cmd2.setEnabled(false);   1018 //              com2Cmd2.setEnabled(false);
1015     1019  
1016                 Command com2Cmd21 = new Command(com2Cmd2, Command.COMMANDGROUP, 1);   1020                 Command com2Cmd21 = new Command(com2Cmd2, Command.COMMANDGROUP, 1);
1017                 com2Cmd21.setText("Compo2 Button2 Cmd2-1");   1021                 com2Cmd21.setText("Compo2 Button2 Cmd2-1");
1018                 Command com2Cmd22 = new Command(com2Cmd2, Command.CANCEL, 1);   1022                 Command com2Cmd22 = new Command(com2Cmd2, Command.CANCEL, 1);
1019                 com2Cmd22.setText("Compo2 Button2 Cmd2-2");   1023                 com2Cmd22.setText("Compo2 Button2 Cmd2-2");
1020                 Command com2Cmd23 = new Command(com2Cmd2, Command.GENERAL, 0);   1024                 Command com2Cmd23 = new Command(com2Cmd2, Command.GENERAL, 0);
1021                 com2Cmd23.setText("Compo2 Button2 Cmd2-3");   1025                 com2Cmd23.setText("Compo2 Button2 Cmd2-3");
1022 //              com2Cmd21.setEnabled(false);   1026 //              com2Cmd21.setEnabled(false);
1023                 com2Cmd22.addSelectionListener(new SelectionListener() {   1027                 com2Cmd22.addSelectionListener(new SelectionListener() {
1024                         public void widgetSelected(SelectionEvent e) {   1028                         public void widgetSelected(SelectionEvent e) {
1025 System.out.println("com2Cmd22 widgetSelected");   1029 System.out.println("com2Cmd22 widgetSelected");
1026                         }   1030                         }
1027                         public void widgetDefaultSelected(SelectionEvent e) {   1031                         public void widgetDefaultSelected(SelectionEvent e) {
1028 System.out.println("com2Cmd22 widgetDefaultSelected");   1032 System.out.println("com2Cmd22 widgetDefaultSelected");
1029                         }   1033                         }
1030                 });   1034                 });
1031     1035  
1032                 Command com2Cmd211 = new Command(com2Cmd21, Command.EXIT, 0);   1036                 Command com2Cmd211 = new Command(com2Cmd21, Command.EXIT, 0);
1033                 com2Cmd211.setText("Compo2 Button2 Cmd2-1-1");   1037                 com2Cmd211.setText("Compo2 Button2 Cmd2-1-1");
1034                 com2Cmd211.setLongLabel("loooooooooooooooooooong label");   1038                 com2Cmd211.setLongLabel("loooooooooooooooooooong label");
1035                 Command com2Cmd212 = new Command(com2Cmd21, Command.COMMANDGROUP, 0);   1039                 Command com2Cmd212 = new Command(com2Cmd21, Command.COMMANDGROUP, 0);
1036                 com2Cmd212.setText("Compo2 Button2 Cmd2-1-2");   1040                 com2Cmd212.setText("Compo2 Button2 Cmd2-1-2");
1037     1041  
1038                 Command com2Cmd2121 = new Command(com2Cmd212, Command.OK, 0);   1042                 Command com2Cmd2121 = new Command(com2Cmd212, Command.OK, 0);
1039                 com2Cmd2121.setText("Compo2 Button2 Cmd2-1-2-1");   1043                 com2Cmd2121.setText("Compo2 Button2 Cmd2-1-2-1");
1040                 com2Cmd2121.setLongLabel("looooooooooooooooooooooooooooooong label");   1044                 com2Cmd2121.setLongLabel("looooooooooooooooooooooooooooooong label");
1041     1045  
1042                 Command com2Cmd3 = new Command(com2Button2, Command.HELP, 1);   1046                 Command com2Cmd3 = new Command(com2Button2, Command.HELP, 1);
1043                 com2Cmd3.setText("Compo2 Button2 Cmd3");   1047                 com2Cmd3.setText("Compo2 Button2 Cmd3");
1044                 com2Cmd3.setLongLabel("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong label");   1048                 com2Cmd3.setLongLabel("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong label");
1045                   1049                
1046                   1050                
1047                 SortedList com2SortedList1 = new SortedList(composite2, SWT.MULTI);   1051                 SortedList com2SortedList1 = new SortedList(composite2, SWT.MULTI);
1048                 com2SortedList1.add("abc");   1052                 com2SortedList1.add("abc");
1049                 com2SortedList1.add("def");   1053                 com2SortedList1.add("def");
1050                 com2SortedList1.add("ghi");   1054                 com2SortedList1.add("ghi");
1051                 com2SortedList1.pack();   1055                 com2SortedList1.pack();
1052 //              com2SortedList1.setLocation(100, 100);   1056 //              com2SortedList1.setLocation(100, 100);
1053                 Command com2SortedList1Cmd1 = new Command(com2SortedList1, Command.HELP, 1);   1057                 Command com2SortedList1Cmd1 = new Command(com2SortedList1, Command.HELP, 1);
1054                 com2SortedList1Cmd1.setText("Compo2 SortedList1 Cmd1");   1058                 com2SortedList1Cmd1.setText("Compo2 SortedList1 Cmd1");
1055     1059  
1056                 Combo com2combo1 = new Combo(composite2, SWT.DROP_DOWN);   1060                 Combo com2combo1 = new Combo(composite2, SWT.DROP_DOWN);
1057                 com2combo1.add("123");   1061                 com2combo1.add("123");
1058                 com2combo1.add("456");   1062                 com2combo1.add("456");
1059                 com2combo1.add("789");   1063                 com2combo1.add("789");
1060                 com2combo1.pack();   1064                 com2combo1.pack();
1061                 composite2.pack();   1065                 composite2.pack();
1062                 Command com2combo1Cmd1 = new Command(com2combo1, Command.HELP, 1);   1066                 Command com2combo1Cmd1 = new Command(com2combo1, Command.HELP, 1);
1063                 com2combo1Cmd1.setText("Compo2 Combo1 Cmd1");   1067                 com2combo1Cmd1.setText("Compo2 Combo1 Cmd1");
1064     1068  
1065                 FormLayout com2Layout = new FormLayout();   1069                 FormLayout com2Layout = new FormLayout();
1066                 com2Layout.marginWidth = 3;   1070                 com2Layout.marginWidth = 3;
1067                 com2Layout.marginHeight = 3;   1071                 com2Layout.marginHeight = 3;
1068                 com2Layout.spacing = 3;   1072                 com2Layout.spacing = 3;
1069                 composite2.setLayout(com2Layout);   1073                 composite2.setLayout(com2Layout);
1070     1074  
1071                 FormData com2fd11 = new FormData();   1075                 FormData com2fd11 = new FormData();
1072                 com2fd11.left = new FormAttachment(0, 0);   1076                 com2fd11.left = new FormAttachment(0, 0);
1073                 com2fd11.top = new FormAttachment(0, 0);   1077                 com2fd11.top = new FormAttachment(0, 0);
1074                 com2Button2.setLayoutData(com2fd11);   1078                 com2Button2.setLayoutData(com2fd11);
1075     1079  
1076                 FormData com2fd21 = new FormData();   1080                 FormData com2fd21 = new FormData();
1077                 com2fd21.left = new FormAttachment(0, 0);   1081                 com2fd21.left = new FormAttachment(0, 0);
1078                 com2fd21.top = new FormAttachment(com2Button2, 0);   1082                 com2fd21.top = new FormAttachment(com2Button2, 0);
1079                 com2fd21.bottom = new FormAttachment(com2Button2, 50);   1083                 com2fd21.bottom = new FormAttachment(com2Button2, 50);
1080                 com2SortedList1.setLayoutData(com2fd21);   1084                 com2SortedList1.setLayoutData(com2fd21);
1081     1085  
1082                 FormData com2fd22 = new FormData();   1086                 FormData com2fd22 = new FormData();
1083                 com2fd22.left = new FormAttachment(com2SortedList1, 0);   1087                 com2fd22.left = new FormAttachment(com2SortedList1, 0);
1084                 com2fd22.top = new FormAttachment(com2Button2, 0);   1088                 com2fd22.top = new FormAttachment(com2Button2, 0);
1085                 com2combo1.setLayoutData(com2fd22);   1089                 com2combo1.setLayoutData(com2fd22);
1086     1090  
1087                   1091                
1088                 Composite composite3 = new Composite(shell, SWT.NONE | SWT.BORDER);   1092                 Composite composite3 = new Composite(shell, SWT.NONE | SWT.BORDER);
1089                 Text com3Text1 = new Text(composite3, SWT.MULTI | SWT.BORDER);   1093                 Text com3Text1 = new Text(composite3, SWT.MULTI | SWT.BORDER);
1090                   1094                
1091                 List com3List1 = new List(composite3, SWT.MULTI);   1095                 List com3List1 = new List(composite3, SWT.MULTI);
1092                 com3List1.add("List 1");   1096                 com3List1.add("List 1");
1093                 com3List1.add("List 2");   1097                 com3List1.add("List 2");
1094                 com3List1.add("List 3");   1098                 com3List1.add("List 3");
1095                 com3List1.pack();   1099                 com3List1.pack();
1096                   1100                
1097                 FormLayout com3Layout = new FormLayout();   1101                 FormLayout com3Layout = new FormLayout();
1098                 com3Layout.marginWidth = 3;   1102                 com3Layout.marginWidth = 3;
1099                 com3Layout.marginHeight = 3;   1103                 com3Layout.marginHeight = 3;
1100                 com3Layout.spacing = 3;   1104                 com3Layout.spacing = 3;
1101                 composite3.setLayout(com3Layout);   1105                 composite3.setLayout(com3Layout);
1102                   1106                
1103                 FormData com3fd11 = new FormData();   1107                 FormData com3fd11 = new FormData();
1104                 com3fd11.left = new FormAttachment(0, 0);   1108                 com3fd11.left = new FormAttachment(0, 0);
1105                 com3fd11.top = new FormAttachment(0, 0);   1109                 com3fd11.top = new FormAttachment(0, 0);
1106                 com3fd11.right = new FormAttachment(0, 40);   1110                 com3fd11.right = new FormAttachment(0, 40);
1107                 com3fd11.bottom = new FormAttachment(0, 30);   1111                 com3fd11.bottom = new FormAttachment(0, 30);
1108                 com3Text1.setLayoutData(com3fd11);   1112                 com3Text1.setLayoutData(com3fd11);
1109     1113  
1110                 FormData com3fd12 = new FormData();   1114                 FormData com3fd12 = new FormData();
1111                 com3fd12.left = new FormAttachment(com3Text1, 0);   1115                 com3fd12.left = new FormAttachment(com3Text1, 0);
1112                 com3fd12.top = new FormAttachment(0, 0);   1116                 com3fd12.top = new FormAttachment(0, 0);
1113                 com3List1.setLayoutData(com3fd12);   1117                 com3List1.setLayoutData(com3fd12);
1114     1118  
1115                 composite3.pack();   1119                 composite3.pack();
1116                 composite3.setBackground(new Color(display, 0, 255, 0));   1120                 composite3.setBackground(new Color(display, 0, 255, 0));
1117     1121  
1118                 Command com3Cmd1 = new Command(composite3, Command.OK, 2);   1122                 Command com3Cmd1 = new Command(composite3, Command.OK, 2);
1119                 com3Cmd1.setText("Compo3 Cmd1");   1123                 com3Cmd1.setText("Compo3 Cmd1");
1120 //              com3Cmd1.setImage(new Image(display, "/resource/020.gif"));   1124 //              com3Cmd1.setImage(new Image(display, "/resource/020.gif"));
1121     1125  
1122                 final Command com3Cmd2 = new Command(composite3, Command.CANCEL, 1);   1126                 final Command com3Cmd2 = new Command(composite3, Command.CANCEL, 1);
1123                 com3Cmd2.setText("Compo3 Cmd2");   1127                 com3Cmd2.setText("Compo3 Cmd2");
1124                 com3Cmd2.addSelectionListener(new SelectionListener() {   1128                 com3Cmd2.addSelectionListener(new SelectionListener() {
1125                         public void widgetSelected(SelectionEvent e) {   1129                         public void widgetSelected(SelectionEvent e) {
1126                                 System.out.println("Dispose Composite3 Cmd2");   1130                                 System.out.println("Dispose Composite3 Cmd2");
1127                                 System.out.println("--- before dispose ---");   1131                                 System.out.println("--- before dispose ---");
1128                                 System.out.println(Command.cmdHandle.toString());   1132                                 System.out.println(Command.cmdHandle.toString());
1129                                 System.out.println("--- before dispose ---");   1133                                 System.out.println("--- before dispose ---");
1130                                 com3Cmd2.dispose();   1134                                 com3Cmd2.dispose();
1131                                 System.out.println("--- after dispose ---");   1135                                 System.out.println("--- after dispose ---");
1132                                 System.out.println(Command.cmdHandle.toString());   1136                                 System.out.println(Command.cmdHandle.toString());
1133                                 System.out.println("-----------------------");   1137                                 System.out.println("-----------------------");
1134                         }   1138                         }
1135                         public void widgetDefaultSelected(SelectionEvent e) {   1139                         public void widgetDefaultSelected(SelectionEvent e) {
1136                         }   1140                         }
1137                 });   1141                 });
1138                 final Command com3Cmd3 = new Command(composite3, Command.DELETE, 1);   1142                 final Command com3Cmd3 = new Command(composite3, Command.DELETE, 1);
1139                 com3Cmd3.setText("Compo3 Cmd3");   1143                 com3Cmd3.setText("Compo3 Cmd3");
1140                 SelectionListener com3Cmd3Listener = new SelectionListener() {   1144                 SelectionListener com3Cmd3Listener = new SelectionListener() {
1141                         public void widgetSelected(SelectionEvent e) {   1145                         public void widgetSelected(SelectionEvent e) {
1142 System.out.println("Compo3 Cmd3 SelectionListener");   1146 System.out.println("Compo3 Cmd3 SelectionListener");
1143 System.out.println("now, remove SelectionListener");   1147 System.out.println("now, remove SelectionListener");
1144                                 com3Cmd3.removeSelectionListener(this);   1148                                 com3Cmd3.removeSelectionListener(this);
1145                         }   1149                         }
1146                         public void widgetDefaultSelected(SelectionEvent e) {   1150                         public void widgetDefaultSelected(SelectionEvent e) {
1147                         }   1151                         }
1148                 };   1152                 };
1149                   1153                
1150                 com3Cmd3.addSelectionListener(com3Cmd3Listener);   1154                 com3Cmd3.addSelectionListener(com3Cmd3Listener);
1151     1155  
1152                 Command com3Text1Cmd1 = new Command(com3Text1, Command.COMMANDGROUP, 1);   1156                 Command com3Text1Cmd1 = new Command(com3Text1, Command.COMMANDGROUP, 1);
1153                 com3Text1Cmd1.setText("Compo3 Text1 Cmd1");   1157                 com3Text1Cmd1.setText("Compo3 Text1 Cmd1");
1154                 Command com3Text1Cmd11 = new Command(com3Text1Cmd1, Command.COMMANDGROUP, 1);   1158                 Command com3Text1Cmd11 = new Command(com3Text1Cmd1, Command.COMMANDGROUP, 1);
1155                 com3Text1Cmd11.setText("Compo3 Text1 Cmd1-1");   1159                 com3Text1Cmd11.setText("Compo3 Text1 Cmd1-1");
1156 //              com3Text1Cmd1.setEnabled(false);   1160 //              com3Text1Cmd1.setEnabled(false);
1157     1161  
1158                 Command com3Text1Cmd2 = new Command(com3Text1, Command.COMMANDGROUP, 1);   1162                 Command com3Text1Cmd2 = new Command(com3Text1, Command.COMMANDGROUP, 1);
1159                 com3Text1Cmd2.setText("Compo3 Text1 Cmd2");   1163                 com3Text1Cmd2.setText("Compo3 Text1 Cmd2");
1160                   1164                
1161                 Command com3List1Cmd1 = new Command(com3List1, Command.COMMANDGROUP, 1);   1165                 Command com3List1Cmd1 = new Command(com3List1, Command.COMMANDGROUP, 1);
1162                 com3List1Cmd1.setText("Compo3 Lis1 Cmd1");   1166                 com3List1Cmd1.setText("Compo3 Lis1 Cmd1");
1163 //              com3List1Cmd1.setImage(new Image(display, "/resource/iMac.JPG"));   1167 //              com3List1Cmd1.setImage(new Image(display, "/resource/iMac.JPG"));
1164     1168  
1165     1169  
1166                 Composite composite31 = new Composite(composite3, SWT.NONE);   1170                 Composite composite31 = new Composite(composite3, SWT.NONE);
1167                 Label com31Label1 = new Label(composite31, SWT.NONE);   1171                 Label com31Label1 = new Label(composite31, SWT.NONE);
1168                 com31Label1.setText("Compo31 Labe1");   1172                 com31Label1.setText("Compo31 Labe1");
1169                 com31Label1.pack();   1173                 com31Label1.pack();
1170                 Text com31Text1 = new Text(composite31, SWT.BORDER);   1174                 Text com31Text1 = new Text(composite31, SWT.BORDER);
1171                 com31Text1.setText("Text1");   1175                 com31Text1.setText("Text1");
1172                 com31Text1.pack();   1176                 com31Text1.pack();
1173                 Button com31Button1 = new Button(composite31, SWT.BORDER);   1177                 Button com31Button1 = new Button(composite31, SWT.BORDER);
1174                 com31Button1.setText("Button1");   1178                 com31Button1.setText("Button1");
1175                 com31Button1.pack();   1179                 com31Button1.pack();
1176     1180  
1177                 FormLayout com31Layout = new FormLayout();   1181                 FormLayout com31Layout = new FormLayout();
1178                 com31Layout.marginWidth = 3;   1182                 com31Layout.marginWidth = 3;
1179                 com31Layout.marginHeight = 3;   1183                 com31Layout.marginHeight = 3;
1180                 com31Layout.spacing = 3;   1184                 com31Layout.spacing = 3;
1181                 composite31.setLayout(com31Layout);   1185                 composite31.setLayout(com31Layout);
1182                   1186                
1183                 FormData com31fd11 = new FormData();   1187                 FormData com31fd11 = new FormData();
1184                 com31fd11.left = new FormAttachment(0, 0);   1188                 com31fd11.left = new FormAttachment(0, 0);
1185                 com31fd11.top = new FormAttachment(0, 0);   1189                 com31fd11.top = new FormAttachment(0, 0);
1186                 com31Label1.setLayoutData(com31fd11);   1190                 com31Label1.setLayoutData(com31fd11);
1187     1191  
1188                 FormData com31fd21 = new FormData();   1192                 FormData com31fd21 = new FormData();
1189                 com31fd21.left = new FormAttachment(0, 0);   1193                 com31fd21.left = new FormAttachment(0, 0);
1190                 com31fd21.top = new FormAttachment(com31Label1, 0);   1194                 com31fd21.top = new FormAttachment(com31Label1, 0);
1191                 com31Text1.setLayoutData(com31fd21);   1195                 com31Text1.setLayoutData(com31fd21);
1192     1196  
1193                 FormData com31fd22 = new FormData();   1197                 FormData com31fd22 = new FormData();
1194                 com31fd22.left = new FormAttachment(com31Text1, 0);   1198                 com31fd22.left = new FormAttachment(com31Text1, 0);
1195                 com31fd22.top = new FormAttachment(com31Label1, 0);   1199                 com31fd22.top = new FormAttachment(com31Label1, 0);
1196                 com31Button1.setLayoutData(com31fd22);   1200                 com31Button1.setLayoutData(com31fd22);
1197                   1201                
1198                   1202                
1199                 FormData com3fd21 = new FormData();   1203                 FormData com3fd21 = new FormData();
1200                 com3fd21.left = new FormAttachment(com3List1, 0);   1204                 com3fd21.left = new FormAttachment(com3List1, 0);
1201                 com3fd21.top = new FormAttachment(0, 0);   1205                 com3fd21.top = new FormAttachment(0, 0);
1202                 composite31.setLayoutData(com3fd21);   1206                 composite31.setLayoutData(com3fd21);
1203     1207  
1204                 composite31.setBackground(new Color(display, 128, 0, 255));   1208                 composite31.setBackground(new Color(display, 128, 0, 255));
1205     1209  
1206                   1210                
1207                 Command com31Cmd1 = new Command(composite31, Command.COMMANDGROUP, 1);   1211                 Command com31Cmd1 = new Command(composite31, Command.COMMANDGROUP, 1);
1208                 com31Cmd1.setText("Compo31 Cmd1");   1212                 com31Cmd1.setText("Compo31 Cmd1");
1209                 com31Cmd1.addSelectionListener(new SelectionListener() {   1213                 com31Cmd1.addSelectionListener(new SelectionListener() {
1210                         public void widgetSelected(SelectionEvent e) {   1214                         public void widgetSelected(SelectionEvent e) {
1211 System.out.println("Compo31 Cmd1 widgetSelected");   1215 System.out.println("Compo31 Cmd1 widgetSelected");
1212                         }   1216                         }
1213                         public void widgetDefaultSelected(SelectionEvent e) {   1217                         public void widgetDefaultSelected(SelectionEvent e) {
1214                         }   1218                         }
1215                 });   1219                 });
1216                 Command com31Cmd11 = new Command(com31Cmd1, Command.COMMANDGROUP, 1);   1220                 Command com31Cmd11 = new Command(com31Cmd1, Command.COMMANDGROUP, 1);
1217                 com31Cmd11.setText("Compo31 Text1 Cmd1-1");   1221                 com31Cmd11.setText("Compo31 Text1 Cmd1-1");
1218     1222  
1219                 Command com31Text1Cmd1 = new Command(com31Text1, Command.COMMANDGROUP, 1);   1223                 Command com31Text1Cmd1 = new Command(com31Text1, Command.COMMANDGROUP, 1);
1220                 com31Text1Cmd1.setText("Compo31 Text1 Cmd1");   1224                 com31Text1Cmd1.setText("Compo31 Text1 Cmd1");
1221                 Command com31Text1Cmd11 = new Command(com31Text1Cmd1, Command.COMMANDGROUP, 1);   1225                 Command com31Text1Cmd11 = new Command(com31Text1Cmd1, Command.COMMANDGROUP, 1);
1222                 com31Text1Cmd11.setText("Compo31 Text1 Cmd1-1");   1226                 com31Text1Cmd11.setText("Compo31 Text1 Cmd1-1");
1223     1227  
1224                 Command com31Button1Cmd1 = new Command(com31Button1, Command.COMMANDGROUP, 1);   1228                 Command com31Button1Cmd1 = new Command(com31Button1, Command.COMMANDGROUP, 1);
1225                 com31Button1Cmd1.setText("Compo31 Button1 Cmd1");   1229                 com31Button1Cmd1.setText("Compo31 Button1 Cmd1");
1226     1230  
1227                   1231                
1228                 // Composite 4   1232                 // Composite 4
1229                 Composite composite4 = new Composite(shell, SWT.BORDER);   1233                 Composite composite4 = new Composite(shell, SWT.BORDER);
1230                 composite4.setBackground(new Color(display, 128, 128, 255));   1234                 composite4.setBackground(new Color(display, 128, 128, 255));
1231                 Command com4Cmd1 = new Command(composite4, Command.COMMANDGROUP, 1);   1235                 Command com4Cmd1 = new Command(composite4, Command.COMMANDGROUP, 1);
1232                 com4Cmd1.setText("Compo4 Cmd1");   1236                 com4Cmd1.setText("Compo4 Cmd1");
1233     1237  
1234                 final Button com4Button1 = new Button(composite4, SWT.BORDER);   1238                 final Button com4Button1 = new Button(composite4, SWT.BORDER);
1235                 com4Button1.setText("Compo4 Button1");   1239                 com4Button1.setText("Compo4 Button1");
1236                 com4Button1.pack();   1240                 com4Button1.pack();
1237                 com4Button1.setLocation(0, 0);   1241                 com4Button1.setLocation(0, 0);
1238     1242  
1239                 final Button com4Button2 = new Button(composite4, SWT.BORDER);   1243                 final Button com4Button2 = new Button(composite4, SWT.BORDER);
1240                 com4Button2.setText("Button2");   1244                 com4Button2.setText("Button2");
1241                 com4Button2.setToolTipText("composite4 Button2");   1245                 com4Button2.setToolTipText("composite4 Button2");
1242                 com4Button2.pack();   1246                 com4Button2.pack();
1243                 com4Button2.setLocation(com4Button1.getSize().x, 0);   1247                 com4Button2.setLocation(com4Button1.getSize().x, 0);
1244     1248  
1245                 final Button com4Button3 = new Button(composite4, SWT.BORDER);   1249                 final Button com4Button3 = new Button(composite4, SWT.BORDER);
1246                 com4Button3.setText("Button3");   1250                 com4Button3.setText("Button3");
1247                 com4Button3.setToolTipText("composite4 Button3");   1251                 com4Button3.setToolTipText("composite4 Button3");
1248                 com4Button3.pack();   1252                 com4Button3.pack();
1249                 com4Button3.setLocation(com4Button2.getLocation().x + com4Button2.getSize().x, 0);   1253                 com4Button3.setLocation(com4Button2.getLocation().x + com4Button2.getSize().x, 0);
1250     1254  
1251                 Command com4Button3Cmd1 = new Command(com4Button3, Command.COMMANDGROUP, 1);   1255                 Command com4Button3Cmd1 = new Command(com4Button3, Command.COMMANDGROUP, 1);
1252                 com4Button3Cmd1.setText("Compo4 Button3 Cmd1");   1256                 com4Button3Cmd1.setText("Compo4 Button3 Cmd1");
1253                 com4Button3Cmd1.addSelectionListener(new SelectionListener() {   1257                 com4Button3Cmd1.addSelectionListener(new SelectionListener() {
1254                         public void widgetSelected(SelectionEvent e) {   1258                         public void widgetSelected(SelectionEvent e) {
1255                                 System.out.println("Compo4 Button3 Cmd1(Group) widgetSelected");   1259                                 System.out.println("Compo4 Button3 Cmd1(Group) widgetSelected");
1256                         }   1260                         }
1257                         public void widgetDefaultSelected(SelectionEvent e) {   1261                         public void widgetDefaultSelected(SelectionEvent e) {
1258                         }   1262                         }
1259                 });   1263                 });
1260 //              Command com4Button3Cmd11 = new Command(com4Button3Cmd1, Command.OK, 1);   1264 //              Command com4Button3Cmd11 = new Command(com4Button3Cmd1, Command.OK, 1);
1261 //              com4Button3Cmd11.setText("Compo4 Button3 Cmd1-1");   1265 //              com4Button3Cmd11.setText("Compo4 Button3 Cmd1-1");
1262     1266  
1263                 Command com4Button1Cmd1 = new Command(com4Button1, Command.COMMANDGROUP, 1);   1267                 Command com4Button1Cmd1 = new Command(com4Button1, Command.COMMANDGROUP, 1);
1264                 com4Button1Cmd1.setText("Compo4 Button1 Cmd1");   1268                 com4Button1Cmd1.setText("Compo4 Button1 Cmd1");
1265     1269  
1266                 final Command com4Button1Cmd11 = new Command(com4Button1Cmd1, Command.EXIT, 2);   1270                 final Command com4Button1Cmd11 = new Command(com4Button1Cmd1, Command.EXIT, 2);
1267                 com4Button1Cmd11.setText("Compo4 Button1 Cmd1-1");   1271                 com4Button1Cmd11.setText("Compo4 Button1 Cmd1-1");
1268                 com4Button1Cmd11.addSelectionListener(new SelectionListener() {   1272                 com4Button1Cmd11.addSelectionListener(new SelectionListener() {
1269                         public void widgetSelected(SelectionEvent e) {   1273                         public void widgetSelected(SelectionEvent e) {
1270                                 System.out.println(e.widget);   1274                                 System.out.println(e.widget);
1271                                 MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION);   1275                                 MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION);
1272                                 mb.setText(com4Button1Cmd11.getText());   1276                                 mb.setText(com4Button1Cmd11.getText());
1273                                 mb.setMessage("Select Composite4 Button1 Command 1-1");   1277                                 mb.setMessage("Select Composite4 Button1 Command 1-1");
1274                                 mb.open();   1278                                 mb.open();
1275                                 mb = null;   1279                                 mb = null;
1276                         }   1280                         }
1277                         public void widgetDefaultSelected(SelectionEvent e) {   1281                         public void widgetDefaultSelected(SelectionEvent e) {
1278                         }   1282                         }
1279                 });   1283                 });
1280                 Command com4Button1Cmd12 = new Command(com4Button1Cmd1, Command.COMMANDGROUP, 1);   1284                 Command com4Button1Cmd12 = new Command(com4Button1Cmd1, Command.COMMANDGROUP, 1);
1281                 com4Button1Cmd12.setText("Compo4 Button1 Cmd1-2");   1285                 com4Button1Cmd12.setText("Compo4 Button1 Cmd1-2");
1282                 Command com4Button1Cmd13 = new Command(com4Button1Cmd1, Command.DELETE, 0);   1286                 Command com4Button1Cmd13 = new Command(com4Button1Cmd1, Command.DELETE, 0);
1283                 com4Button1Cmd13.setText("Compo4 Button1 Cmd1-3");   1287                 com4Button1Cmd13.setText("Compo4 Button1 Cmd1-3");
1284     1288  
1285                 Command com4Button1Cmd121 = new Command(com4Button1Cmd12, Command.CANCEL, 1);   1289                 Command com4Button1Cmd121 = new Command(com4Button1Cmd12, Command.CANCEL, 1);
1286                 com4Button1Cmd121.setText("Compo4 Button1 Cmd1-2-1");   1290                 com4Button1Cmd121.setText("Compo4 Button1 Cmd1-2-1");
1287                 Command com4Button1Cmd122 = new Command(com4Button1Cmd12, Command.OK, 0);   1291                 Command com4Button1Cmd122 = new Command(com4Button1Cmd12, Command.OK, 0);
1288                 com4Button1Cmd122.setText("Compo4 Button1 Cmd1-2-2");   1292                 com4Button1Cmd122.setText("Compo4 Button1 Cmd1-2-2");
1289     1293  
1290                 // Composite 5   1294                 // Composite 5
1291                 Composite composite5 = new Composite(shell, SWT.NONE);   1295                 Composite composite5 = new Composite(shell, SWT.NONE);
1292                 Composite composite6 = new Composite(composite5, SWT.NONE);   1296                 Composite composite6 = new Composite(composite5, SWT.NONE);
1293                 composite6.setBackground(new Color(display, 255, 128, 128));   1297                 composite6.setBackground(new Color(display, 255, 128, 128));
1294     1298  
1295                 final Button com5Button1 = new Button(composite6, SWT.BORDER);   1299                 final Button com5Button1 = new Button(composite6, SWT.BORDER);
1296                 com5Button1.setText("Compo5 Button1");   1300                 com5Button1.setText("Compo5 Button1");
1297                 com5Button1.pack();   1301                 com5Button1.pack();
1298                 com5Button1.addSelectionListener(new SelectionListener() {   1302                 com5Button1.addSelectionListener(new SelectionListener() {
1299                         public void widgetSelected(SelectionEvent e) {   1303                         public void widgetSelected(SelectionEvent e) {
1300                                 Command cmd = new Command(com5Button1, Command.OK, 1);   1304                                 Command cmd = new Command(com5Button1, Command.OK, 1);
1301                                 cmd.setText("Compo5 Button1");   1305                                 cmd.setText("Compo5 Button1");
1302                         }   1306                         }
1303                         public void widgetDefaultSelected(SelectionEvent e) {   1307                         public void widgetDefaultSelected(SelectionEvent e) {
1304                         }   1308                         }
1305                 });   1309                 });
1306                 Command cmdCom5Button1 = new Command(composite5, Command.OK, 0);   1310                 Command cmdCom5Button1 = new Command(composite5, Command.OK, 0);
1307                 cmdCom5Button1.setText("Compo5 Cmd1");   1311                 cmdCom5Button1.setText("Compo5 Cmd1");
1308                   1312                
1309                 FormLayout com6Layout = new FormLayout();   1313                 FormLayout com6Layout = new FormLayout();
1310                 com6Layout.marginWidth = 3;   1314                 com6Layout.marginWidth = 3;
1311                 com6Layout.marginHeight = 3;   1315                 com6Layout.marginHeight = 3;
1312                 com6Layout.spacing = 3;   1316                 com6Layout.spacing = 3;
1313                 composite6.setLayout(com6Layout);   1317                 composite6.setLayout(com6Layout);
1314     1318  
1315                 FormData com6fd11 = new FormData();   1319                 FormData com6fd11 = new FormData();
1316                 com6fd11.left = new FormAttachment(0, 0);   1320                 com6fd11.left = new FormAttachment(0, 0);
1317                 com6fd11.top = new FormAttachment(0, 0);   1321                 com6fd11.top = new FormAttachment(0, 0);
1318                 composite5.setLayoutData(com6fd11);   1322                 composite5.setLayoutData(com6fd11);
1319                   1323                
1320     1324  
1321                 FormLayout com5Layout = new FormLayout();   1325                 FormLayout com5Layout = new FormLayout();
1322                 com5Layout.marginWidth = 3;   1326                 com5Layout.marginWidth = 3;
1323                 com5Layout.marginHeight = 3;   1327                 com5Layout.marginHeight = 3;
1324                 com5Layout.spacing = 3;   1328                 com5Layout.spacing = 3;
1325                 composite5.setLayout(com5Layout);   1329                 composite5.setLayout(com5Layout);
1326                   1330                
1327                 FormData com5fd11 = new FormData();   1331                 FormData com5fd11 = new FormData();
1328                 com5fd11.left = new FormAttachment(0, 0);   1332                 com5fd11.left = new FormAttachment(0, 0);
1329                 com5fd11.top = new FormAttachment(0, 0);   1333                 com5fd11.top = new FormAttachment(0, 0);
1330                 com5Button1.setLayoutData(com5fd11);   1334                 com5Button1.setLayoutData(com5fd11);
1331     1335  
1332                 FormData com5fd12 = new FormData();   1336                 FormData com5fd12 = new FormData();
1333                 com5fd12.left = new FormAttachment(0, 0);   1337                 com5fd12.left = new FormAttachment(0, 0);
1334                 com5fd12.top = new FormAttachment(com5Button1, 0);   1338                 com5fd12.top = new FormAttachment(com5Button1, 0);
1335                   1339                
1336                 com4Button1.setParent(composite6);   1340                 com4Button1.setParent(composite6);
1337                 com4Button1.setLayoutData(com5fd12);   1341                 com4Button1.setLayoutData(com5fd12);
1338     1342  
1339                   1343                
1340     1344  
1341                 Text text1 = new Text(shell, SWT.BORDER);   1345                 Text text1 = new Text(shell, SWT.BORDER);
1342                 text1.setText("No command");   1346                 text1.setText("No command");
1343                 text1.pack();   1347                 text1.pack();
1344     1348  
1345                   1349                
1346                 FormLayout layout = new FormLayout();   1350                 FormLayout layout = new FormLayout();
1347                 layout.marginWidth = 3;   1351                 layout.marginWidth = 3;
1348                 layout.marginHeight = 3;   1352                 layout.marginHeight = 3;
1349                 layout.spacing = 3;   1353                 layout.spacing = 3;
1350                 shell.setLayout(layout);   1354                 shell.setLayout(layout);
1351                   1355                
1352                 FormData fd11 = new FormData();   1356                 FormData fd11 = new FormData();
1353                 fd11.left = new FormAttachment(0, 0);   1357                 fd11.left = new FormAttachment(0, 0);
1354                 fd11.top = new FormAttachment(0, 0);   1358                 fd11.top = new FormAttachment(0, 0);
1355                 composite1.setLayoutData(fd11);   1359                 composite1.setLayoutData(fd11);
1356     1360  
1357                 FormData fd21 = new FormData();   1361                 FormData fd21 = new FormData();
1358                 fd21.left = new FormAttachment(0, 0);   1362                 fd21.left = new FormAttachment(0, 0);
1359                 fd21.top = new FormAttachment(composite1, 0);   1363                 fd21.top = new FormAttachment(composite1, 0);
1360                 composite2.setLayoutData(fd21);   1364                 composite2.setLayoutData(fd21);
1361     1365  
1362                 FormData fd31 = new FormData();   1366                 FormData fd31 = new FormData();
1363                 fd31.left = new FormAttachment(0, 0);   1367                 fd31.left = new FormAttachment(0, 0);
1364                 fd31.top = new FormAttachment(composite2, 0);   1368                 fd31.top = new FormAttachment(composite2, 0);
1365                 composite3.setLayoutData(fd31);   1369                 composite3.setLayoutData(fd31);
1366     1370  
1367                 FormData fd41 = new FormData();   1371                 FormData fd41 = new FormData();
1368                 fd41.left = new FormAttachment(0, 0);   1372                 fd41.left = new FormAttachment(0, 0);
1369                 fd41.top = new FormAttachment(composite3, 0);   1373                 fd41.top = new FormAttachment(composite3, 0);
1370                 composite4.setLayoutData(fd41);   1374                 composite4.setLayoutData(fd41);
1371     1375  
1372                 FormData fd51 = new FormData();   1376                 FormData fd51 = new FormData();
1373                 fd51.left = new FormAttachment(0, 0);   1377                 fd51.left = new FormAttachment(0, 0);
1374                 fd51.top = new FormAttachment(composite4, 0);   1378                 fd51.top = new FormAttachment(composite4, 0);
1375                 composite5.setLayoutData(fd51);   1379                 composite5.setLayoutData(fd51);
1376     1380  
1377                 FormData fd91 = new FormData();   1381                 FormData fd91 = new FormData();
1378                 fd91.left = new FormAttachment(0, 0);   1382                 fd91.left = new FormAttachment(0, 0);
1379                 fd91.top = new FormAttachment(composite5, 0);   1383                 fd91.top = new FormAttachment(composite5, 0);
1380                 fd91.right = new FormAttachment(100, 0);   1384                 fd91.right = new FormAttachment(100, 0);
1381                 text1.setLayoutData(fd91);   1385                 text1.setLayoutData(fd91);
1382                   1386                
1383                   1387                
1384     1388  
1385                 // shell menu   1389                 // shell menu
1386                 final Menu menu = new Menu(shell,SWT.BAR);   1390                 final Menu menu = new Menu(shell,SWT.BAR);
1387                 final MenuItem fileMenuItem = new MenuItem(menu,SWT.CASCADE);   1391                 final MenuItem fileMenuItem = new MenuItem(menu,SWT.CASCADE);
1388                 fileMenuItem.setText("File");   1392                 fileMenuItem.setText("File");
1389     1393  
1390                 final Menu fileMenu = new Menu(shell,SWT.DROP_DOWN);   1394                 final Menu fileMenu = new Menu(shell,SWT.DROP_DOWN);
1391                 fileMenuItem.setMenu(fileMenu);   1395                 fileMenuItem.setMenu(fileMenu);
1392                   1396                
1393                 MenuItem textCommand1 = new MenuItem(fileMenu,SWT.PUSH);   1397                 MenuItem textCommand1 = new MenuItem(fileMenu,SWT.PUSH);
1394                 textCommand1.setText("Text Command 1");   1398                 textCommand1.setText("Text Command 1");
1395                   1399                
1396                 MenuItem textCommand2 = new MenuItem(fileMenu,SWT.PUSH);   1400                 MenuItem textCommand2 = new MenuItem(fileMenu,SWT.PUSH);
1397                 textCommand2.setText("Text Command 1");   1401                 textCommand2.setText("Text Command 1");
1398                   1402                
1399                 MenuItem groupItem1 = new MenuItem(fileMenu,SWT.CASCADE);   1403                 MenuItem groupItem1 = new MenuItem(fileMenu,SWT.CASCADE);
1400                 groupItem1.setText("Group");   1404                 groupItem1.setText("Group");
1401                 Menu subMenu = new Menu(shell, SWT.DROP_DOWN);   1405                 Menu subMenu = new Menu(shell, SWT.DROP_DOWN);
1402                 groupItem1.setMenu(subMenu);   1406                 groupItem1.setMenu(subMenu);
1403                 MenuItem grou1_1 = new MenuItem(subMenu, SWT.PUSH);   1407                 MenuItem grou1_1 = new MenuItem(subMenu, SWT.PUSH);
1404                 grou1_1.setText("Text Group 1");   1408                 grou1_1.setText("Text Group 1");
1405                 MenuItem grou1_2 = new MenuItem(subMenu, SWT.PUSH);   1409                 MenuItem grou1_2 = new MenuItem(subMenu, SWT.PUSH);
1406                 grou1_2.setText("Text Group 2");   1410                 grou1_2.setText("Text Group 2");
1407                 MenuItem itemBar = new MenuItem(fileMenu,SWT.BAR);   1411                 MenuItem itemBar = new MenuItem(fileMenu,SWT.BAR);
1408                   1412                
1409                 MenuItem item2 = new MenuItem(fileMenu,SWT.PUSH);   1413                 MenuItem item2 = new MenuItem(fileMenu,SWT.PUSH);
1410                 item2.setText("Compo Command 1");   1414                 item2.setText("Compo Command 1");
1411                   1415                
1412                 MenuItem item3 = new MenuItem(fileMenu,SWT.PUSH);   1416                 MenuItem item3 = new MenuItem(fileMenu,SWT.PUSH);
1413                 item3.setText("Compo Command 2");   1417                 item3.setText("Compo Command 2");
1414                 MenuItem itemBar2 = new MenuItem(fileMenu,SWT.BAR);   1418                 MenuItem itemBar2 = new MenuItem(fileMenu,SWT.BAR);
1415                   1419                
1416                 MenuItem item4 = new MenuItem(fileMenu,SWT.PUSH);   1420                 MenuItem item4 = new MenuItem(fileMenu,SWT.PUSH);
1417                 item4.setText("Shell Command");   1421                 item4.setText("Shell Command");
1418                 //item2.setEnabled(false);   1422                 //item2.setEnabled(false);
1419     1423  
1420                 MenuItem helpMenuItem = new MenuItem(menu,SWT.CASCADE);   1424                 MenuItem helpMenuItem = new MenuItem(menu,SWT.CASCADE);
1421                 helpMenuItem.setText("Help1");   1425                 helpMenuItem.setText("Help1");
1422                   1426                
1423                 Menu helpMenu = new Menu(shell,SWT.DROP_DOWN);   1427                 Menu helpMenu = new Menu(shell,SWT.DROP_DOWN);
1424                 helpMenuItem.setMenu(helpMenu);   1428                 helpMenuItem.setMenu(helpMenu);
1425     1429  
1426                 MenuItem helpMenuItem1 = new MenuItem(helpMenu,SWT.PUSH);   1430                 MenuItem helpMenuItem1 = new MenuItem(helpMenu,SWT.PUSH);
1427                 helpMenuItem1.setText("Help");   1431                 helpMenuItem1.setText("Help");
1428     1432  
1429                 com4Button2.addSelectionListener(new SelectionListener() {   1433                 com4Button2.addSelectionListener(new SelectionListener() {
1430                         public void widgetSelected(SelectionEvent e) {   1434                         public void widgetSelected(SelectionEvent e) {
1431                         }   1435                         }
1432                         public void widgetDefaultSelected(SelectionEvent e) {   1436                         public void widgetDefaultSelected(SelectionEvent e) {
1433                         }   1437                         }
1434                 });   1438                 });
1435                   1439                
1436                 shell.setMenuBar(menu);   1440                 shell.setMenuBar(menu);
1437     1441  
1438 //System.out.println(Command.cmdHandle.toString());   1442 //System.out.println(Command.cmdHandle.toString());
1439     1443  
1440                 shell.setSize(240, 320);   1444                 shell.setSize(240, 320);
1441                 shell.open();   1445                 shell.open();
1442                 shell.addDisposeListener(new DisposeListener() {   1446                 shell.addDisposeListener(new DisposeListener() {
1443                         public void widgetDisposed(DisposeEvent e) {   1447                         public void widgetDisposed(DisposeEvent e) {
1444 //                              System.out.println(Command.cmdHandle.toString());   1448 //                              System.out.println(Command.cmdHandle.toString());
1445                         }   1449                         }
1446                 });   1450                 });
1447     1451  
1448                 while( !shell.isDisposed() ) {   1452                 while( !shell.isDisposed() ) {
1449                         if( !display.readAndDispatch() )   1453                         if( !display.readAndDispatch() )
1450                                 display.sleep();   1454                                 display.sleep();
1451                 }   1455                 }
1452                 display.dispose();        1456                 display.dispose();     
1453         }   1457         }
1454 */   1458 */
1455 }   1459 }
1456     1460  
1457 class CommandListener implements Listener {   1461 class CommandListener implements Listener {
1458         private int eventType;   1462         private int eventType;
1459         private Command command;   1463         private Command command;
1460         private Listener listener;   1464         private Listener listener;
1461         public CommandListener(Command command, int eventType, Listener listener) {   1465         public CommandListener(Command command, int eventType, Listener listener) {
1462                 setCommand(command);   1466                 setCommand(command);
1463                 setEventType(eventType);   1467                 setEventType(eventType);
1464                 setListener(listener);   1468                 setListener(listener);
1465         }   1469         }
1466         public void setCommand(Command command) {   1470         public void setCommand(Command command) {
1467                 this.command = command;   1471                 this.command = command;
1468         }   1472         }
1469         public Command getCommand() {   1473         public Command getCommand() {
1470                 return command;   1474                 return command;
1471         }   1475         }
1472         public void setEventType(int eventType) {   1476         public void setEventType(int eventType) {
1473                 this.eventType = eventType;   1477                 this.eventType = eventType;
1474         }   1478         }
1475         public int getEventType() {   1479         public int getEventType() {
1476                 return eventType;   1480                 return eventType;
1477         }   1481         }
1478         public void setListener(Listener listener) {   1482         public void setListener(Listener listener) {
1479                 this.listener = listener;   1483                 this.listener = listener;
1480         }   1484         }
1481         public Listener getListener() {   1485         public Listener getListener() {
1482                 return listener;   1486                 return listener;
1483         }   1487         }
1484         public void handleEvent(Event event) {   1488         public void handleEvent(Event event) {
1485                 if(listener == null || command == null)   1489                 if(listener == null || command == null)
1486                         return;   1490                         return;
1487                 Event e = new Event();   1491                 Event e = new Event();
1488                 e.button = event.button;   1492                 e.button = event.button;
1489                 e.character = event.character;   1493                 e.character = event.character;
1490                 e.count = event.count;   1494                 e.count = event.count;
1491                 e.data = event.data;   1495                 e.data = event.data;
1492                 e.detail = event.detail;   1496                 e.detail = event.detail;
1493                 e.display = event.display;   1497                 e.display = event.display;
1494                 e.doit = event.doit;   1498                 e.doit = event.doit;
1495                 e.end = event.end;   1499                 e.end = event.end;
1496                 e.gc = event.gc;   1500                 e.gc = event.gc;
1497                 e.height = event.height;   1501                 e.height = event.height;
1498                 e.item = event.item;   1502                 e.item = event.item;
1499                 e.keyCode = event.keyCode;   1503                 e.keyCode = event.keyCode;
1500                 e.start = event.start;   1504                 e.start = event.start;
1501                 e.stateMask  =event.stateMask;   1505                 e.stateMask  =event.stateMask;
1502                 e.text = event.text;   1506                 e.text = event.text;
1503                 e.time = event.time;   1507                 e.time = event.time;
1504                 e.type = event.type;   1508                 e.type = event.type;
1505                 e.width = event.width;   1509                 e.width = event.width;
1506                 e.x = event.x;   1510                 e.x = event.x;
1507                 e.y = event.y;   1511                 e.y = event.y;
1508                 e.setBounds(event.getBounds());   1512                 e.setBounds(event.getBounds());
1509                 e.widget = command;   1513                 e.widget = command;
1510                 listener.handleEvent(e);   1514                 listener.handleEvent(e);
1511         }   1515         }
1512           1516        
1513 }   1517 }
1514     1518  
1515 /*   1519 /*
1516 * @author daniel   1520 * @author daniel
1517 *   1521 *
1518 * This class handle ControlNode tree   1522 * This class handle ControlNode tree
1519 * 1. bring up menu when Control gaine focus   1523 * 1. bring up menu when Control gaine focus
1520 * 2. dispose menu when Control lost focus   1524 * 2. dispose menu when Control lost focus
1521 * 3. dispose ControlNode when Control dispose   1525 * 3. dispose ControlNode when Control dispose
1522   1526
1523 * Provide Command class access ControlNode tree   1527 * Provide Command class access ControlNode tree
1524 * 1. add new control's command   1528 * 1. add new control's command
1525 * 2. add sub command   1529 * 2. add sub command
1526 * 3. remove command when Command dispose   1530 * 3. remove command when Command dispose
1527 * 4. add command SelectionListener   1531 * 4. add command SelectionListener
1528 * 5. remove command SelectionListener   1532 * 5. remove command SelectionListener
1529 * 6. find control by command   1533 * 6. find control by command
1530 *   1534 *
1531 */   1535 */
1532 class CommandHandle implements Listener { <> 1536 class CommandHandle implements org.eclipse.swt.widgets.Listener {
1533 //       if COMMAND_MENU_EXPAND_LEVEL set -1, expand all sub menu = 1537 //       if COMMAND_MENU_EXPAND_LEVEL set -1, expand all sub menu
1534 //       otherwise, expand sub menu to specify level   1538 //       otherwise, expand sub menu to specify level
1535         private static final int COMMAND_MENU_EXPAND_LEVEL = -1;   1539         private static final int COMMAND_MENU_EXPAND_LEVEL = -1;
1536         private static final String COMMAND_MENU_NAME_KEY = "Command_Menu_Name";   1540         private static final String COMMAND_MENU_NAME_KEY = "Command_Menu_Name";
1537         private static final String MOBILE_PROPERTY_NAME = "mobile";   1541         private static final String MOBILE_PROPERTY_NAME = "mobile";
1538         private static String cmdMenuName;   1542         private static String cmdMenuName;
1539         private ControlNode root;   1543         private ControlNode root;
1540         private GC gc;   1544         private GC gc;
1541         private int displayWidth;   1545         private int displayWidth;
1542         private Vector commandList = new Vector(4, 4);   1546         private Vector commandList = new Vector(4, 4);
1543     1547  
1544         // for softkey support   1548         // for softkey support
1545         static boolean supportSoftkey = false;   1549         static boolean supportSoftkey = false;
1546         static {   1550         static {
1547                 switch(org.eclipse.swt.internal.Platform.IDENTIFY_CODE) {   1551                 switch(org.eclipse.swt.internal.Platform.IDENTIFY_CODE) {
1548                         case org.eclipse.swt.internal.Platform.WM2005 :   1552                         case org.eclipse.swt.internal.Platform.WM2005 :
1549                         case org.eclipse.swt.internal.Platform.WM6PRO :   1553                         case org.eclipse.swt.internal.Platform.WM6PRO :
1550                         case org.eclipse.swt.internal.Platform.SP2005 :   1554                         case org.eclipse.swt.internal.Platform.SP2005 :
1551                         case org.eclipse.swt.internal.Platform.WM6STD :   1555                         case org.eclipse.swt.internal.Platform.WM6STD :
1552                                 supportSoftkey = true;   1556                                 supportSoftkey = true;
1553                         case org.eclipse.swt.internal.Platform.WM2003 :   1557                         case org.eclipse.swt.internal.Platform.WM2003 :
1554                         case org.eclipse.swt.internal.Platform.SP2003 :   1558                         case org.eclipse.swt.internal.Platform.SP2003 :
1555                                 if(org.eclipse.swt.internal.Platform.MAJOR_VERSION >= 5) {   1559                                 if(org.eclipse.swt.internal.Platform.MAJOR_VERSION >= 5) {
1556                                         supportSoftkey = true;   1560                                         supportSoftkey = true;
1557                                 }   1561                                 }
1558                 }   1562                 }
1559         }   1563         }
1560         private boolean skipSeparateMenuItem = false;   1564         private boolean skipSeparateMenuItem = false;
1561         private Vector needDisposeMenuItems = new Vector();   1565         private Vector needDisposeMenuItems = new Vector();
1562     1566  
1563         public CommandHandle() {   1567         public CommandHandle() {
1564                 root = new ControlNode();   1568                 root = new ControlNode();
1565                 ResourceBundle rb = ResourceBundle.getBundle(MOBILE_PROPERTY_NAME, Locale.getDefault());   1569                 ResourceBundle rb = ResourceBundle.getBundle(MOBILE_PROPERTY_NAME, Locale.getDefault());
1566                 cmdMenuName = rb.getString(COMMAND_MENU_NAME_KEY);   1570                 cmdMenuName = rb.getString(COMMAND_MENU_NAME_KEY);
1567                 rb = null;   1571                 rb = null;
1568         }   1572         }
1569     1573  
1570         // add sub command   1574         // add sub command
1571         public ControlNode add(Command parent, Command command) {   1575         public ControlNode add(Command parent, Command command) {
1572                 if(parent == null || command == null)   1576                 if(parent == null || command == null)
1573                         return null;   1577                         return null;
1574     1578  
1575                 ControlNode ctrlode = findControlNode(parent);   1579                 ControlNode ctrlode = findControlNode(parent);
1576                 if(ctrlode == null)   1580                 if(ctrlode == null)
1577                         return null;   1581                         return null;
1578                 CommandNode cmdNode = ctrlode.commandNode.findCommandNode(parent);   1582                 CommandNode cmdNode = ctrlode.commandNode.findCommandNode(parent);
1579                 cmdNode.addChild(new CommandNode(command));   1583                 cmdNode.addChild(new CommandNode(command));
1580                   1584                
1581                 commandList.add(command);   1585                 commandList.add(command);
1582                 return ctrlode;   1586                 return ctrlode;
1583         }   1587         }
1584     1588  
1585         // add control and command   1589         // add control and command
1586         public ControlNode add(Control control, Command command) {   1590         public ControlNode add(Control control, Command command) {
1587                 if(control == null || command == null)   1591                 if(control == null || command == null)
1588                         return null;   1592                         return null;
1589     1593  
1590                 ControlNode node = add(control);   1594                 ControlNode node = add(control);
1591                 if(node != null)   1595                 if(node != null)
1592                         node.addCommand(command);   1596                         node.addCommand(command);
1593     1597  
1594                 // fix bug 99158 problem 2   1598                 // fix bug 99158 problem 2
1595                 if(control.isFocusControl() ||   1599                 if(control.isFocusControl() ||
1596                         (control instanceof Shell && control.getDisplay().getActiveShell() == control)) {   1600                         (control instanceof Shell && control.getDisplay().getActiveShell() == control)) {
1597                         Control child = null;   1601                         Control child = null;
1598                         if(control instanceof Composite) {   1602                         if(control instanceof Composite) {
1599                                 child = getFocusChild((Composite)control);   1603                                 child = getFocusChild((Composite)control);
1600                         }   1604                         }
1601                         if(child != null)   1605                         if(child != null)
1602                                 makeMenu(child);   1606                                 makeMenu(child);
1603                         else   1607                         else
1604                                 makeMenu(control);   1608                                 makeMenu(control);
1605                 }   1609                 }
1606     1610  
1607                 commandList.add(command);   1611                 commandList.add(command);
1608                 return node;   1612                 return node;
1609         }   1613         }
1610     1614  
1611         // remove command   1615         // remove command
1612         public void removeCommand(Command command) {   1616         public void removeCommand(Command command) {
1613                 if(command == null)   1617                 if(command == null)
1614                         return;   1618                         return;
1615                 ControlNode node = root.findControlNode(command);   1619                 ControlNode node = root.findControlNode(command);
1616                 if(node == null)   1620                 if(node == null)
1617                         return;   1621                         return;
1618                 node.commandNode.removeCommand(command);   1622                 node.commandNode.removeCommand(command);
1619     1623  
1620                 Shell shell = node.control.getShell();   1624                 Shell shell = node.control.getShell();
1621                 ControlNode shellNode = root.findControlNode(shell);   1625                 ControlNode shellNode = root.findControlNode(shell);
1622                 Control focusControl = getFocusChild(shell);   1626                 Control focusControl = getFocusChild(shell);
1623                 ControlNode focusNode = root.findControlNode(focusControl);   1627                 ControlNode focusNode = root.findControlNode(focusControl);
1624                 // no control has focus or control(and parent) no command   1628                 // no control has focus or control(and parent) no command
1625                 if(focusControl == null || focusNode == null || !focusNode.hasCommand()) {   1629                 if(focusControl == null || focusNode == null || !focusNode.hasCommand()) {
1626                         if(shellNode != null) {   1630                         if(shellNode != null) {
1627                                 if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())   1631                                 if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())
1628                                         shellNode.commandMenuItem.dispose();   1632                                         shellNode.commandMenuItem.dispose();
1629                                 shellNode.commandMenuItem = null;   1633                                 shellNode.commandMenuItem = null;
1630                         }   1634                         }
1631                 } else {   1635                 } else {
1632                         makeMenu(focusControl);   1636                         makeMenu(focusControl);
1633                 }   1637                 }
1634     1638  
1635                 /*   1639                 /*
1636                 // fix bug 99158 problem 1   1640                 // fix bug 99158 problem 1
1637                 if(!node.hasCommand()) {   1641                 if(!node.hasCommand()) {
1638                         if(node.control == null)   1642                         if(node.control == null)
1639                                 return;   1643                                 return;
1640                         ControlNode shellNode = root.findControlNode(node.control.getShell());   1644                         ControlNode shellNode = root.findControlNode(node.control.getShell());
1641                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())   1645                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())
1642                                 shellNode.commandMenuItem.dispose();   1646                                 shellNode.commandMenuItem.dispose();
1643                         shellNode.commandMenuItem = null;   1647                         shellNode.commandMenuItem = null;
1644                 }   1648                 }
1645 */   1649 */
1646         }   1650         }
1647           1651        
1648         // check command and parent(s) are enabled   1652         // check command and parent(s) are enabled
1649         public boolean isEnabled(Command command) {   1653         public boolean isEnabled(Command command) {
1650                 ControlNode ctrlNode = root.findControlNode(command);   1654                 ControlNode ctrlNode = root.findControlNode(command);
1651                 CommandNode cmdNode = ctrlNode.commandNode.findCommandNode(command);   1655                 CommandNode cmdNode = ctrlNode.commandNode.findCommandNode(command);
1652                 return cmdNode.isEnabled();   1656                 return cmdNode.isEnabled();
1653         }   1657         }
1654     1658  
1655         // find command's control in ControlNode tree   1659         // find command's control in ControlNode tree
1656         public Control findControl(Command command) {   1660         public Control findControl(Command command) {
1657                 if(command == null)   1661                 if(command == null)
1658                         return null;   1662                         return null;
1659                 ControlNode node = root.findControlNode(command);   1663                 ControlNode node = root.findControlNode(command);
1660                 if(node == null || node.control == null)   1664                 if(node == null || node.control == null)
1661                         return null;              1665                         return null;           
1662                 return node.control;   1666                 return node.control;
1663         }   1667         }
1664         public CommandNode findCommandNode(Command command) {   1668         public CommandNode findCommandNode(Command command) {
1665                 ControlNode ctrlNode = root.findControlNode(command);   1669                 ControlNode ctrlNode = root.findControlNode(command);
1666                 if(ctrlNode == null)   1670                 if(ctrlNode == null)
1667                         return null;   1671                         return null;
1668                 return ctrlNode.commandNode.findCommandNode(command);   1672                 return ctrlNode.commandNode.findCommandNode(command);
1669         }   1673         }
1670         public void handleEvent(Event event) {   1674         public void handleEvent(Event event) {
1671                 if(event.type != SWT.FocusIn &&   1675                 if(event.type != SWT.FocusIn &&
1672                         event.type != SWT.FocusOut)   1676                         event.type != SWT.FocusOut)
1673                         return;   1677                         return;
1674     1678  
1675                 if(!(event.widget instanceof Control))   1679                 if(!(event.widget instanceof Control))
1676                         return;   1680                         return;
1677     1681  
1678                 Control control = (Control)event.widget;   1682                 Control control = (Control)event.widget;
1679                 Shell shell = control.getShell();   1683                 Shell shell = control.getShell();
1680                 Rectangle oldClientArea = new Rectangle(0, 0, 0, 0);   1684                 Rectangle oldClientArea = new Rectangle(0, 0, 0, 0);
1681                 if(shell != null){   1685                 if(shell != null){
1682                         oldClientArea = shell.getClientArea();   1686                         oldClientArea = shell.getClientArea();
1683                 }   1687                 }
1684                 if(event.type == SWT.FocusOut) {   1688                 if(event.type == SWT.FocusOut) {
1685                         if(supportSoftkey) {   1689                         if(supportSoftkey) {
1686                                 for(Iterator iterator = needDisposeMenuItems.iterator();iterator.hasNext();) {   1690                                 for(Iterator iterator = needDisposeMenuItems.iterator();iterator.hasNext();) {
1687                                         MenuItem item = (MenuItem)iterator.next();   1691                                         MenuItem item = (MenuItem)iterator.next();
1688                                         if(item != null && !item.isDisposed()) {   1692                                         if(item != null && !item.isDisposed()) {
1689                                                 item.dispose();   1693                                                 item.dispose();
1690                                         }   1694                                         }
1691                                 }   1695                                 }
1692                                 needDisposeMenuItems.clear();   1696                                 needDisposeMenuItems.clear();
1693                         } else {   1697                         } else {
1694                                 ControlNode shellNode = root.findControlNode(shell);   1698                                 ControlNode shellNode = root.findControlNode(shell);
1695                                 if(shellNode == null)   1699                                 if(shellNode == null)
1696                                         return;   1700                                         return;
1697                                 if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())   1701                                 if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())
1698                                         shellNode.commandMenuItem.dispose();   1702                                         shellNode.commandMenuItem.dispose();
1699                                 shellNode.commandMenuItem = null;   1703                                 shellNode.commandMenuItem = null;
1700                                 shellNode.trigger = null;   1704                                 shellNode.trigger = null;
1701                         }   1705                         }
1702                           1706                        
1703                         //if OS == WIN32, check if command causes the client area to expand or shrink then re-layout   1707                         //if OS == WIN32, check if command causes the client area to expand or shrink then re-layout
1704                         if(org.eclipse.swt.internal.Platform.isWin32()) {   1708                         if(org.eclipse.swt.internal.Platform.isWin32()) {
1705                                 if(shell != null && !oldClientArea.equals(shell.getClientArea())){   1709                                 if(shell != null && !oldClientArea.equals(shell.getClientArea())){
1706                                         shell.layout(true);   1710                                         shell.layout(true);
1707                                 }   1711                                 }
1708                         }   1712                         }
1709                           1713                        
1710                 } else {   1714                 } else {
1711                         if (!control.isVisible()) return;   1715                         if (!control.isVisible()) return;
1712                         ControlNode node = root.findControlNode(control);   1716                         ControlNode node = root.findControlNode(control);
1713                         if(node == null) {   1717                         if(node == null) {
1714                                 node = findParentControlNode(control);   1718                                 node = findParentControlNode(control);
1715                                 if(node == null)   1719                                 if(node == null)
1716                                         return;   1720                                         return;
1717                                 else   1721                                 else
1718                                         node = add(control);   1722                                         node = add(control);
1719                         } else {   1723                         } else {
1720                                 if(node.parent.control != control.getParent())   1724                                 if(node.parent.control != control.getParent())
1721                                         processParentChanged(control);   1725                                         processParentChanged(control);
1722                         }   1726                         }
1723                         if(node.hasCommand()) {   1727                         if(node.hasCommand()) {
1724                                 makeMenu(node.control);   1728                                 makeMenu(node.control);
1725                                   1729                                
1726                                 //if OS == WIN32, check if command causes the client area to expand or shrink then re-layout   1730                                 //if OS == WIN32, check if command causes the client area to expand or shrink then re-layout
1727                                 if(org.eclipse.swt.internal.Platform.isWin32()){   1731                                 if(org.eclipse.swt.internal.Platform.isWin32()){
1728                                         if(shell != null && !oldClientArea.equals(shell.getClientArea())){   1732                                         if(shell != null && !oldClientArea.equals(shell.getClientArea())){
1729                                                 shell.layout(true);   1733                                                 shell.layout(true);
1730                                         }   1734                                         }
1731                                 }   1735                                 }
1732                         }   1736                         }
1733                 }   1737                 }
1734         }   1738         }
1735     1739  
1736         // add control and parent(s) to node   1740         // add control and parent(s) to node
1737         private ControlNode add(Control control) {   1741         private ControlNode add(Control control) {
1738                 if(control == null)   1742                 if(control == null)
1739                         return null;   1743                         return null;
1740     1744  
1741                 Vector controls, unhandles;   1745                 Vector controls, unhandles;
1742                 ControlNode node;   1746                 ControlNode node;
1743                 Control c;   1747                 Control c;
1744     1748  
1745                 // get control and parent(s)   1749                 // get control and parent(s)
1746                 controls = new Vector();   1750                 controls = new Vector();
1747                 c = control;   1751                 c = control;
1748                 while(c != null) {   1752                 while(c != null) {
1749                         controls.add(c);   1753                         controls.add(c);
1750 //                      if(c == control.getShell())   1754 //                      if(c == control.getShell())
1751 //                              break;   1755 //                              break;
1752                         c = c.getParent();   1756                         c = c.getParent();
1753                 }   1757                 }
1754     1758  
1755                 // get control if control not in Control tree   1759                 // get control if control not in Control tree
1756                 unhandles = new Vector();   1760                 unhandles = new Vector();
1757                 for(Iterator iterator = controls.iterator();iterator.hasNext();) {   1761                 for(Iterator iterator = controls.iterator();iterator.hasNext();) {
1758                         c = (Control)iterator.next();   1762                         c = (Control)iterator.next();
1759                         node = root.findControlNode(c);   1763                         node = root.findControlNode(c);
1760                         if(node == null)   1764                         if(node == null)
1761                                 unhandles.add(c);   1765                                 unhandles.add(c);
1762                 }   1766                 }
1763                   1767                
1764                 // add all control and parent to ControlNode tree   1768                 // add all control and parent to ControlNode tree
1765                 node = root;   1769                 node = root;
1766                 for(int i=controls.size()-1; i>=0; i--) {   1770                 for(int i=controls.size()-1; i>=0; i--) {
1767                         c = (Control)controls.elementAt(i);   1771                         c = (Control)controls.elementAt(i);
1768                         node = add(node, c);   1772                         node = add(node, c);
1769                 }   1773                 }
1770                   1774                
1771                 for(Iterator iterator = unhandles.iterator();iterator.hasNext();)   1775                 for(Iterator iterator = unhandles.iterator();iterator.hasNext();)
1772                         addDisposeListener((Control)iterator.next());   1776                         addDisposeListener((Control)iterator.next());
1773     1777  
1774                 return node;   1778                 return node;
1775         }   1779         }
1776     1780  
1777         // add control to parent node, return control's node   1781         // add control to parent node, return control's node
1778         private ControlNode add(ControlNode parent, Control control) {   1782         private ControlNode add(ControlNode parent, Control control) {
1779                 if(parent == null || control == null)   1783                 if(parent == null || control == null)
1780                         return null;   1784                         return null;
1781                 ControlNode node = root.findControlNode(control);   1785                 ControlNode node = root.findControlNode(control);
1782                 if(node == null) {   1786                 if(node == null) {
1783                         node = new ControlNode(control);   1787                         node = new ControlNode(control);
1784                         parent.addChild(node);   1788                         parent.addChild(node);
1785                 }   1789                 }
1786                 return node;   1790                 return node;
1787         }   1791         }
1788     1792  
1789         // dispose ControlNode when control dispose   1793         // dispose ControlNode when control dispose
1790         private void addDisposeListener(Control control) {   1794         private void addDisposeListener(Control control) {
1791                 if(control == null)   1795                 if(control == null)
1792                         return;   1796                         return;
1793                 control.addDisposeListener(new DisposeListener() {   1797                 control.addDisposeListener(new DisposeListener() {
1794                         public void widgetDisposed(DisposeEvent e) {   1798                         public void widgetDisposed(DisposeEvent e) {
1795                                 ControlNode node = (ControlNode)root.findControlNode((Control)e.widget);   1799                                 ControlNode node = (ControlNode)root.findControlNode((Control)e.widget);
1796                                 if(node != null && !node.isDispose())   1800                                 if(node != null && !node.isDispose())
1797                                         node.dispose();   1801                                         node.dispose();
1798                                 node = null;   1802                                 node = null;
1799                         }   1803                         }
1800                 });   1804                 });
1801         }   1805         }
1802           1806        
1803         // process Control parent has changed   1807         // process Control parent has changed
1804         private ControlNode processParentChanged(Control control) {   1808         private ControlNode processParentChanged(Control control) {
1805                 if(control == null || control.getParent() == null)   1809                 if(control == null || control.getParent() == null)
1806                         return null;   1810                         return null;
1807     1811  
1808                 ControlNode current, node;   1812                 ControlNode current, node;
1809     1813  
1810                 current = root.findControlNode(control);   1814                 current = root.findControlNode(control);
1811                 // clean no command(s) or no child(s) ControlNode   1815                 // clean no command(s) or no child(s) ControlNode
1812                 if(current.parent != null) {   1816                 if(current.parent != null) {
1813                         node = current;   1817                         node = current;
1814                         node.parent.removeChild(node);   1818                         node.parent.removeChild(node);
1815                         node = node.parent;   1819                         node = node.parent;
1816                         while(node.control != null) {   1820                         while(node.control != null) {
1817                                 if(!node.hasCommand() && !node.hasChild()) {   1821                                 if(!node.hasCommand() && !node.hasChild()) {
1818                                         node.dispose();   1822                                         node.dispose();
1819                                 }   1823                                 }
1820                                 node = node.parent;   1824                                 node = node.parent;
1821                         }   1825                         }
1822                 }   1826                 }
1823     1827  
1824                 // add all parent(s) control   1828                 // add all parent(s) control
1825                 node = add(control.getParent());   1829                 node = add(control.getParent());
1826                 node.addChild(current);   1830                 node.addChild(current);
1827                   1831                
1828                 return current;           1832                 return current;        
1829         }   1833         }
1830     1834  
1831         // find command's ControlNode in ControlNode tree   1835         // find command's ControlNode in ControlNode tree
1832         private ControlNode findControlNode(Command command) {   1836         private ControlNode findControlNode(Command command) {
1833                 if(command == null)   1837                 if(command == null)
1834                         return null;   1838                         return null;
1835                 return root.findControlNode(command);   1839                 return root.findControlNode(command);
1836         }   1840         }
1837     1841  
1838         // find control or parent(s) if exist ControlNode tree   1842         // find control or parent(s) if exist ControlNode tree
1839         private ControlNode findParentControlNode(Control control) {   1843         private ControlNode findParentControlNode(Control control) {
1840                 if(control == null)   1844                 if(control == null)
1841                         return null;   1845                         return null;
1842     1846  
1843                 ControlNode node = null;   1847                 ControlNode node = null;
1844                 Control c = control;   1848                 Control c = control;
1845                 while(c != null) {   1849                 while(c != null) {
1846                         node = root.findControlNode(c);   1850                         node = root.findControlNode(c);
1847                         if(node != null)   1851                         if(node != null)
1848                                 break;   1852                                 break;
1849 //                      if(c == control.getShell())   1853 //                      if(c == control.getShell())
1850 //                              break;   1854 //                              break;
1851                         c = c.getParent();   1855                         c = c.getParent();
1852                 }   1856                 }
1853                 return node;   1857                 return node;
1854         }   1858         }
1855     1859  
1856         // bring up menu by Command   1860         // bring up menu by Command
1857         public void makeMenu(Command command) {   1861         public void makeMenu(Command command) {
1858                 if(command == null)   1862                 if(command == null)
1859                         return;   1863                         return;
1860                 Control control = findControl(command);   1864                 Control control = findControl(command);
1861                 if(control == null)   1865                 if(control == null)
1862                         return;   1866                         return;
1863                   1867                
1864                 Control child = null;   1868                 Control child = null;
1865                 if(control instanceof Composite) {   1869                 if(control instanceof Composite) {
1866                         child = getFocusChild((Composite)control);   1870                         child = getFocusChild((Composite)control);
1867                 }   1871                 }
1868                 if(child != null)   1872                 if(child != null)
1869                         makeMenu(child);   1873                         makeMenu(child);
1870                 else   1874                 else
1871                         makeMenu(control);   1875                         makeMenu(control);
1872         }   1876         }
1873           1877        
1874         // bring up menu by Control   1878         // bring up menu by Control
1875         private void makeMenu(Control control) {   1879         private void makeMenu(Control control) {
1876                 if(control == null)   1880                 if(control == null)
1877                         return;   1881                         return;
1878                 ControlNode node = root.findControlNode(control);   1882                 ControlNode node = root.findControlNode(control);
1879                 if(node == null)   1883                 if(node == null)
1880                         return;   1884                         return;
1881     1885  
1882                 if(gc == null) {   1886                 if(gc == null) {
1883                         gc = new GC(control.getDisplay());   1887                         gc = new GC(control.getDisplay());
1884                         displayWidth = control.getDisplay().getBounds().width;   1888                         displayWidth = control.getDisplay().getBounds().width;
1885                 }   1889                 }
1886     1890  
1887                 Shell shell = control.getShell();   1891                 Shell shell = control.getShell();
1888                 Menu mainMenu = shell.getMenuBar();   1892                 Menu mainMenu = shell.getMenuBar();
1889                 // if shell menu not exist, create shell menu   1893                 // if shell menu not exist, create shell menu
1890                 if (mainMenu == null) {   1894                 if (mainMenu == null) {
1891                         mainMenu = new Menu(shell,SWT.BAR);   1895                         mainMenu = new Menu(shell,SWT.BAR);
1892                         shell.setMenuBar(mainMenu);   1896                         shell.setMenuBar(mainMenu);
1893                 }   1897                 }
1894                 if(supportSoftkey) {   1898                 if(supportSoftkey) {
1895                         makeSoftkeyMenu(node, mainMenu);   1899                         makeSoftkeyMenu(node, mainMenu);
1896                 } else {   1900                 } else {
1897                         makeMenu(control, node, mainMenu);   1901                         makeMenu(control, node, mainMenu);
1898                 }   1902                 }
1899         }   1903         }
1900     1904  
1901         private void makeMenu(Control control, ControlNode controlNode, Menu mainMenu) {   1905         private void makeMenu(Control control, ControlNode controlNode, Menu mainMenu) {
1902                 ControlNode shellNode = root.findControlNode(control.getShell());   1906                 ControlNode shellNode = root.findControlNode(control.getShell());
1903                 if(shellNode.commandMenuItem != null && shellNode.commandMenuItem.isDisposed()) {   1907                 if(shellNode.commandMenuItem != null && shellNode.commandMenuItem.isDisposed()) {
1904                         return;   1908                         return;
1905                 }   1909                 }
1906                 if(shellNode.trigger == control) {   1910                 if(shellNode.trigger == control) {
1907                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed()) {   1911                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed()) {
1908                                 Menu m = shellNode.commandMenuItem.getMenu();   1912                                 Menu m = shellNode.commandMenuItem.getMenu();
1909                                 if(m != null && !m.isDisposed())   1913                                 if(m != null && !m.isDisposed())
1910                                         m.dispose();   1914                                         m.dispose();
1911                         }   1915                         }
1912                 } else {   1916                 } else {
1913                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())   1917                         if(shellNode.commandMenuItem != null && !shellNode.commandMenuItem.isDisposed())
1914                                 shellNode.commandMenuItem.dispose();   1918                                 shellNode.commandMenuItem.dispose();
1915                         shellNode.commandMenuItem = null;   1919                         shellNode.commandMenuItem = null;
1916                         shellNode.trigger = control;   1920                         shellNode.trigger = control;
1917                 }   1921                 }
1918                 if(shellNode.commandMenuItem == null) {   1922                 if(shellNode.commandMenuItem == null) {
1919                         shellNode.commandMenuItem = new MenuItem(mainMenu, SWT.CASCADE);   1923                         shellNode.commandMenuItem = new MenuItem(mainMenu, SWT.CASCADE);
1920                         shellNode.commandMenuItem.setText(cmdMenuName);   1924                         shellNode.commandMenuItem.setText(cmdMenuName);
1921                 }   1925                 }
1922                   1926                
1923                 Menu commandMenu = new Menu(shellNode.commandMenuItem);   1927                 Menu commandMenu = new Menu(shellNode.commandMenuItem);
1924                 shellNode.commandMenuItem.setMenu(commandMenu);   1928                 shellNode.commandMenuItem.setMenu(commandMenu);
1925     1929  
1926                 controlNode.makeMenu(commandMenu);   1930                 controlNode.makeMenu(commandMenu);
1927         }   1931         }
1928         private void makeSoftkeyMenu(ControlNode controlNode, Menu mainMenu) {   1932         private void makeSoftkeyMenu(ControlNode controlNode, Menu mainMenu) {
1929                 for(Iterator iterator = needDisposeMenuItems.iterator();iterator.hasNext();) {   1933                 for(Iterator iterator = needDisposeMenuItems.iterator();iterator.hasNext();) {
1930                         MenuItem item = (MenuItem)iterator.next();   1934                         MenuItem item = (MenuItem)iterator.next();
1931                         if(item != null && !item.isDisposed()) {   1935                         if(item != null && !item.isDisposed()) {
1932                                 item.dispose();   1936                                 item.dispose();
1933                         }   1937                         }
1934                 }   1938                 }
1935                 needDisposeMenuItems.clear();   1939                 needDisposeMenuItems.clear();
1936                 if(controlNode.hasCommand()) {   1940                 if(controlNode.hasCommand()) {
1937                         controlNode.makeMenu(mainMenu);   1941                         controlNode.makeMenu(mainMenu);
1938                 }   1942                 }
1939                 ControlNode tmp = controlNode;   1943                 ControlNode tmp = controlNode;
1940                 while(tmp != null) {   1944                 while(tmp != null) {
1941                         for(Iterator iterator = tmp.commandNode.childs.iterator(); iterator.hasNext();) {   1945                         for(Iterator iterator = tmp.commandNode.childs.iterator(); iterator.hasNext();) {
1942                                 CommandNode commandNode = (CommandNode)iterator.next();   1946                                 CommandNode commandNode = (CommandNode)iterator.next();
1943                                 needDisposeMenuItems.add(commandNode.item);   1947                                 needDisposeMenuItems.add(commandNode.item);
1944                         }   1948                         }
1945                         if(tmp.separateMenuItem != null) {   1949                         if(tmp.separateMenuItem != null) {
1946                                 needDisposeMenuItems.add(tmp.separateMenuItem);   1950                                 needDisposeMenuItems.add(tmp.separateMenuItem);
1947                         }   1951                         }
1948                         tmp = tmp.parent;   1952                         tmp = tmp.parent;
1949                 }   1953                 }
1950         }   1954         }
1951     1955  
1952         private Control getFocusChild(Composite c) {   1956         private Control getFocusChild(Composite c) {
1953                 if (c == null) return null;   1957                 if (c == null) return null;
1954                 Control[] children = c.getChildren();   1958                 Control[] children = c.getChildren();
1955                 if (children == null) return null; //no   1959                 if (children == null) return null; //no
1956     1960  
1957                 for (int i=0;i<children.length;i++) {   1961                 for (int i=0;i<children.length;i++) {
1958                         if (children[i] == null) continue;   1962                         if (children[i] == null) continue;
1959                         if (children[i].isFocusControl())   1963                         if (children[i].isFocusControl())
1960                                 return children[i];   1964                                 return children[i];
1961                         if(children[i] instanceof Canvas || children[i] instanceof CaptionedControl || children[i] instanceof Composite) {   1965                         if(children[i] instanceof Canvas || children[i] instanceof CaptionedControl || children[i] instanceof Composite) {
1962                                 Control child = getFocusChild((Composite)children[i]);   1966                                 Control child = getFocusChild((Composite)children[i]);
1963                                 if(child != null)   1967                                 if(child != null)
1964                                         return child;   1968                                         return child;
1965                         }   1969                         }
1966                 }   1970                 }
1967                 return null;   1971                 return null;
1968         }   1972         }
1969     1973  
1970 /* debug method start   1974 /* debug method start
1971         public String toString() {   1975         public String toString() {
1972                 return root.toString();   1976                 return root.toString();
1973         }   1977         }
1974 debug method end */   1978 debug method end */
1975           1979        
1976         /*   1980         /*
1977          * @author daniel   1981          * @author daniel
1978          * This class produce control and child(s) tree   1982          * This class produce control and child(s) tree
1979          * this tree include all control if has command   1983          * this tree include all control if has command
1980          *   1984          *
1981          * example :   1985          * example :
1982          * root +-- Shell1 +-- Button11   1986          * root +-- Shell1 +-- Button11
1983          *      |          +-- Composite12   1987          *      |          +-- Composite12
1984          *      |          +-- Composite13 +-- Text131   1988          *      |          +-- Composite13 +-- Text131
1985          *      |                          +-- Labe132   1989          *      |                          +-- Labe132
1986          *      |   1990          *      |
1987          *      +-- Shell2 +-- Composite21 +-- Composite211 +-- Combo2111   1991          *      +-- Shell2 +-- Composite21 +-- Composite211 +-- Combo2111
1988          *      |          +-- List22      +-- Button212   1992          *      |          +-- List22      +-- Button212
1989          *      |          +-- Labe23   1993          *      |          +-- Labe23
1990          *      |   1994          *      |
1991          *      +-- Shell3 +-- Shell31 +-- Text311   1995          *      +-- Shell3 +-- Shell31 +-- Text311
1992          *      |   1996          *      |
1993          *      +-- Shell4 +-- MultiPageShell41 +-- MultiPageComposite411 +-- Composite4111 +-- Text41111   1997          *      +-- Shell4 +-- MultiPageShell41 +-- MultiPageComposite411 +-- Composite4111 +-- Text41111
1994          *                                                                                  +-- Button41112   1998          *                                                                                  +-- Button41112
1995          *                                                                +-- Composite4112 +-- Button41121   1999          *                                                                +-- Composite4112 +-- Button41121
1996          *     ...   2000          *     ...
1997          *   2001          *
1998          * When Control focus, Control make menu,   2002          * When Control focus, Control make menu,
1999          * continue call parent node make menu until Shell.   2003          * continue call parent node make menu until Shell.
2000          *   2004          *
2001          * example 1 :   2005          * example 1 :
2002          * 1. Text131 focus   2006          * 1. Text131 focus
2003          * 2. Text131 make menu   2007          * 2. Text131 make menu
2004          * 3. Text131 call parent make menu   2008          * 3. Text131 call parent make menu
2005          * 4. Composite13 make menu   2009          * 4. Composite13 make menu
2006          * 5. Composite13 call parent make menu   2010          * 5. Composite13 call parent make menu
2007          * 6. Shell1 make menu   2011          * 6. Shell1 make menu
2008          *   2012          *
2009          * example 2 :   2013          * example 2 :
2010          * 1. Combo2111 focus   2014          * 1. Combo2111 focus
2011          * 2. Combo2111 make menu   2015          * 2. Combo2111 make menu
2012          * 3. Combo2111 call parent make menu   2016          * 3. Combo2111 call parent make menu
2013          * 4. Composite211 make menu   2017          * 4. Composite211 make menu
2014          * 5. Composite211 call parent make menu   2018          * 5. Composite211 call parent make menu
2015          * 6. Composite21 make menu   2019          * 6. Composite21 make menu
2016          * 7. Composite21 call parent make menu   2020          * 7. Composite21 call parent make menu
2017          * 8. Shell2 make menu   2021          * 8. Shell2 make menu
2018          *   2022          *
2019          * example 3 :   2023          * example 3 :
2020          * 1. Text311 focus   2024          * 1. Text311 focus
2021          * 2. Text311 make menu   2025          * 2. Text311 make menu
2022          * 3. Text311 call parent make menu   2026          * 3. Text311 call parent make menu
2023          * 4. Shell31 make menu   2027          * 4. Shell31 make menu
2024          *   2028          *
2025          * example 4(MultiPageDialog) :   2029          * example 4(MultiPageDialog) :
2026          * 1. Text41111 focus   2030          * 1. Text41111 focus
2027          * 2. Text41111 make menu   2031          * 2. Text41111 make menu
2028          * 3. Text41111 call parent make menu   2032          * 3. Text41111 call parent make menu
2029          * 4. Composite4111 make menu   2033          * 4. Composite4111 make menu
2030          * 5. Composite4111 call parent make menu   2034          * 5. Composite4111 call parent make menu
2031          * 6. MultiPageComposite411 make menu   2035          * 6. MultiPageComposite411 make menu
2032          * 7. MultiPageComposite411 call parent make menu   2036          * 7. MultiPageComposite411 call parent make menu
2033          * 8. MultiPageShell41 make menu   2037          * 8. MultiPageShell41 make menu
2034          * 9. MultiPageShell41 call parent make menu   2038          * 9. MultiPageShell41 call parent make menu
2035          * 10.Shell4 make menu   2039          * 10.Shell4 make menu
2036          */   2040          */
2037         class ControlNode {   2041         class ControlNode {
2038                 ControlNode parent;   2042                 ControlNode parent;
2039                 Vector childs;                          // put ControlNode   2043                 Vector childs;                          // put ControlNode
2040                 Control control;   2044                 Control control;
2041                 CommandNode commandNode;        // Command   2045                 CommandNode commandNode;        // Command
2042                 boolean dispose = false;   2046                 boolean dispose = false;
2043                 MenuItem commandMenuItem = null;   2047                 MenuItem commandMenuItem = null;
2044                 MenuItem separateMenuItem = null;   2048                 MenuItem separateMenuItem = null;
2045                 Control trigger = null;   2049                 Control trigger = null;
2046                   2050                
2047                 // root node constructs   2051                 // root node constructs
2048                 public ControlNode() {   2052                 public ControlNode() {
2049                         parent = null;   2053                         parent = null;
2050                         control = null;   2054                         control = null;
2051                         childs = new Vector();   2055                         childs = new Vector();
2052                         commandNode = new CommandNode();   2056                         commandNode = new CommandNode();
2053                 }   2057                 }
2054           2058        
2055                 // leaf node constructs   2059                 // leaf node constructs
2056                 public ControlNode(Control control) {   2060                 public ControlNode(Control control) {
2057                         this.control = control;   2061                         this.control = control;
2058                         childs = new Vector();   2062                         childs = new Vector();
2059                         commandNode = new CommandNode();   2063                         commandNode = new CommandNode();
2060                 }   2064                 }
2061           2065        
2062                 // add child node   2066                 // add child node
2063                 public ControlNode addChild(ControlNode node) {   2067                 public ControlNode addChild(ControlNode node) {
2064                         node.parent = this;   2068                         node.parent = this;
2065                         childs.add(node);   2069                         childs.add(node);
2066                         return node;   2070                         return node;
2067                 }   2071                 }
2068                 public ControlNode removeChild(ControlNode child) {   2072                 public ControlNode removeChild(ControlNode child) {
2069                         childs.remove(child);   2073                         childs.remove(child);
2070                         return child;   2074                         return child;
2071                 }   2075                 }
2072           2076        
2073                 // check this node has command   2077                 // check this node has command
2074                 public boolean contains(Command command) {   2078                 public boolean contains(Command command) {
2075                         return commandNode.contains(command);             2079                         return commandNode.contains(command);          
2076                 }   2080                 }
2077                   2081                
2078                 // add command   2082                 // add command
2079                 public void addCommand(Command command) {   2083                 public void addCommand(Command command) {
2080                         commandNode.addChild(new CommandNode(command));   2084                         commandNode.addChild(new CommandNode(command));
2081                 }   2085                 }
2082                   2086                
2083                 // find command's ControlNode in this or child(s)   2087                 // find command's ControlNode in this or child(s)
2084                 public ControlNode findControlNode(Command command) {   2088                 public ControlNode findControlNode(Command command) {
2085                         if(commandNode.contains(command))   2089                         if(commandNode.contains(command))
2086                                 return this;   2090                                 return this;
2087                         return findControlNode(command, true);   2091                         return findControlNode(command, true);
2088                 }   2092                 }
2089           2093        
2090                 // recursion find command's ControlNode   2094                 // recursion find command's ControlNode
2091                 private ControlNode findControlNode(Command command, boolean recursion) {   2095                 private ControlNode findControlNode(Command command, boolean recursion) {
2092                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2096                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2093                                 ControlNode node = (ControlNode)iterator.next();   2097                                 ControlNode node = (ControlNode)iterator.next();
2094                                 if(node.isDispose())   2098                                 if(node.isDispose())
2095                                         continue;   2099                                         continue;
2096                                 if(node.commandNode.contains(command))   2100                                 if(node.commandNode.contains(command))
2097                                         return node;   2101                                         return node;
2098                                 if(recursion) {   2102                                 if(recursion) {
2099                                         node = node.findControlNode(command, recursion);   2103                                         node = node.findControlNode(command, recursion);
2100                                         if(node != null)   2104                                         if(node != null)
2101                                                 return node;   2105                                                 return node;
2102                                 }   2106                                 }
2103                         }   2107                         }
2104           2108        
2105                         return null;              2109                         return null;           
2106                 }   2110                 }
2107                   2111                
2108                 // find control's ControlNode in this or child(s)   2112                 // find control's ControlNode in this or child(s)
2109                 public ControlNode findControlNode(Control control) {   2113                 public ControlNode findControlNode(Control control) {
2110                         if(control == null)   2114                         if(control == null)
2111                                 return null;   2115                                 return null;
2112                         return findControlNode(control, control.getShell());   2116                         return findControlNode(control, control.getShell());
2113                 }   2117                 }
2114                   2118                
2115                 private ControlNode findControlNode(Control control, Shell shell) {   2119                 private ControlNode findControlNode(Control control, Shell shell) {
2116                         return findControlNode(control, shell, true);   2120                         return findControlNode(control, shell, true);
2117                 }   2121                 }
2118                   2122                
2119                 // recursion find control's ControlNode   2123                 // recursion find control's ControlNode
2120                 private ControlNode findControlNode(Control control, Shell shell, boolean recursion) {   2124                 private ControlNode findControlNode(Control control, Shell shell, boolean recursion) {
2121                         if(control == null)   2125                         if(control == null)
2122                                 return null;   2126                                 return null;
2123           2127        
2124                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2128                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2125                                 ControlNode node = (ControlNode)iterator.next();   2129                                 ControlNode node = (ControlNode)iterator.next();
2126                                 if(node.isDispose())   2130                                 if(node.isDispose())
2127                                         continue;   2131                                         continue;
2128                                 if(node.control == control)   2132                                 if(node.control == control)
2129                                         return node;   2133                                         return node;
2130                                 if(recursion) {   2134                                 if(recursion) {
2131                                         node = node.findControlNode(control, shell, recursion);   2135                                         node = node.findControlNode(control, shell, recursion);
2132                                         if(node != null && node.control == control)   2136                                         if(node != null && node.control == control)
2133                                                 return node;   2137                                                 return node;
2134                                 }   2138                                 }
2135                         }   2139                         }
2136           2140        
2137                         return null;              2141                         return null;           
2138                 }   2142                 }
2139                 // has child(s)   2143                 // has child(s)
2140                 public boolean hasChild() {   2144                 public boolean hasChild() {
2141                         return (childs.size() > 0);   2145                         return (childs.size() > 0);
2142                 }   2146                 }
2143                   2147                
2144                 // this node has command   2148                 // this node has command
2145                 public boolean hasCommand() {   2149                 public boolean hasCommand() {
2146                         return hasCommand(true);   2150                         return hasCommand(true);
2147                 }   2151                 }
2148     2152  
2149                 // this node and parent(s) has command   2153                 // this node and parent(s) has command
2150                 private boolean hasCommand(boolean recursion) {   2154                 private boolean hasCommand(boolean recursion) {
2151                         if(commandNode.hasCommand())   2155                         if(commandNode.hasCommand())
2152                                 return true;   2156                                 return true;
2153                         if(recursion && parent != null && !isLast())   2157                         if(recursion && parent != null && !isLast())
2154                                 if(parent.hasCommand(recursion))   2158                                 if(parent.hasCommand(recursion))
2155                                         return true;   2159                                         return true;
2156                                   2160                                
2157                         return false;   2161                         return false;
2158                 }   2162                 }
2159                   2163                
2160                 // make this node command(and command child) menu, expand all sub menu   2164                 // make this node command(and command child) menu, expand all sub menu
2161                 public void makeMenu(Menu menu) {   2165                 public void makeMenu(Menu menu) {
2162                         skipSeparateMenuItem = false;   2166                         skipSeparateMenuItem = false;
2163                         makeMenu(menu, COMMAND_MENU_EXPAND_LEVEL);   2167                         makeMenu(menu, COMMAND_MENU_EXPAND_LEVEL);
2164                 }   2168                 }
2165                   2169                
2166                 // make this node command(and command child) menu, expand specify level sub menu   2170                 // make this node command(and command child) menu, expand specify level sub menu
2167                 private void makeMenu(Menu menu, int level) {   2171                 private void makeMenu(Menu menu, int level) {
2168                         if(control == null || parent == null)   2172                         if(control == null || parent == null)
2169                                 return;   2173                                 return;
2170                         if(commandNode.childs.size() > 0) {   2174                         if(commandNode.childs.size() > 0) {
2171                                 commandNode.makeMenu(menu, level);   2175                                 commandNode.makeMenu(menu, level);
2172                                 if(insertSeparateMenuItem()) {   2176                                 if(insertSeparateMenuItem()) {
2173                                         separateMenuItem = new MenuItem(menu, SWT.SEPARATOR);   2177                                         separateMenuItem = new MenuItem(menu, SWT.SEPARATOR);
2174                                 }   2178                                 }
2175                         }   2179                         }
2176                         if(parent.hasCommand() && !isLast())   2180                         if(parent.hasCommand() && !isLast())
2177                                 parent.makeMenu(menu, level);   2181                                 parent.makeMenu(menu, level);
2178                 }   2182                 }
2179                   2183                
2180                 private boolean insertSeparateMenuItem() {   2184                 private boolean insertSeparateMenuItem() {
2181                         if(!parent.hasCommand()) {   2185                         if(!parent.hasCommand()) {
2182                                 return false;   2186                                 return false;
2183                         }   2187                         }
2184                         if(isLast()) {   2188                         if(isLast()) {
2185                                 return false;   2189                                 return false;
2186                         }   2190                         }
2187                         if(supportSoftkey) {   2191                         if(supportSoftkey) {
2188                                 if(skipSeparateMenuItem) {   2192                                 if(skipSeparateMenuItem) {
2189                                         return true;   2193                                         return true;
2190                                 }   2194                                 }
2191                                 boolean hasChild = false;   2195                                 boolean hasChild = false;
2192                                 for(Iterator iterator = commandNode.childs.iterator();iterator.hasNext();) {   2196                                 for(Iterator iterator = commandNode.childs.iterator();iterator.hasNext();) {
2193                                         CommandNode node = (CommandNode)iterator.next();   2197                                         CommandNode node = (CommandNode)iterator.next();
2194                                         if(node.childs.size() > 0) {   2198                                         if(node.childs.size() > 0) {
2195                                                 hasChild = true;   2199                                                 hasChild = true;
2196                                                 break;   2200                                                 break;
2197                                         }   2201                                         }
2198                                 }   2202                                 }
2199                                 if(hasChild) {   2203                                 if(hasChild) {
2200                                         return true;   2204                                         return true;
2201                                 }   2205                                 }
2202                                 if(commandNode.childs.size() == 1) {   2206                                 if(commandNode.childs.size() == 1) {
2203                                         skipSeparateMenuItem = true;   2207                                         skipSeparateMenuItem = true;
2204                                         return false;   2208                                         return false;
2205                                 }   2209                                 }
2206                         }   2210                         }
2207                           2211                        
2208                         return true;   2212                         return true;
2209                 }   2213                 }
2210                   2214                
2211                 private boolean isLast() {   2215                 private boolean isLast() {
2212                         if(parent == null)   2216                         if(parent == null)
2213                                 return true;   2217                                 return true;
2214                         if(control == null)   2218                         if(control == null)
2215                                 return true;   2219                                 return true;
2216                         if(control instanceof MultiPageShell)   2220                         if(control instanceof MultiPageShell)
2217                                 return true;   2221                                 return true;
2218                         if(!(control instanceof Shell))   2222                         if(!(control instanceof Shell))
2219                                 return false;   2223                                 return false;
2220                         Shell s = (Shell)control;   2224                         Shell s = (Shell)control;
2221                         if(s == s.getDisplay().getActiveShell())   2225                         if(s == s.getDisplay().getActiveShell())
2222                                 return true;   2226                                 return true;
2223                         if(control instanceof Shell && parent.control instanceof Shell)   2227                         if(control instanceof Shell && parent.control instanceof Shell)
2224                                 return true;   2228                                 return true;
2225                         return false;   2229                         return false;
2226                           2230                        
2227                 }   2231                 }
2228                   2232                
2229                 // dispose this node and child(s) node   2233                 // dispose this node and child(s) node
2230                 public void dispose() {   2234                 public void dispose() {
2231                         if(dispose)   2235                         if(dispose)
2232                                 return;   2236                                 return;
2233                         // dispose command   2237                         // dispose command
2234                         commandNode.dispose();   2238                         commandNode.dispose();
2235                         commandNode = null;   2239                         commandNode = null;
2236                           2240                        
2237                         // dispose menu   2241                         // dispose menu
2238                         if(commandMenuItem != null && !commandMenuItem.isDisposed())   2242                         if(commandMenuItem != null && !commandMenuItem.isDisposed())
2239                                 commandMenuItem.dispose();   2243                                 commandMenuItem.dispose();
2240                         commandMenuItem = null;   2244                         commandMenuItem = null;
2241                           2245                        
2242                         // dispose child(s)   2246                         // dispose child(s)
2243                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2247                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2244                                 ControlNode node = (ControlNode)iterator.next();   2248                                 ControlNode node = (ControlNode)iterator.next();
2245                                 if(node.isDispose())   2249                                 if(node.isDispose())
2246                                         continue;   2250                                         continue;
2247                                 node.dispose();   2251                                 node.dispose();
2248                                 node = null;   2252                                 node = null;
2249                         }   2253                         }
2250                         childs.clear();   2254                         childs.clear();
2251                         childs = null;   2255                         childs = null;
2252                         dispose = true;   2256                         dispose = true;
2253                 }   2257                 }
2254                   2258                
2255                 public boolean isDispose() {   2259                 public boolean isDispose() {
2256                         return dispose;   2260                         return dispose;
2257                 }   2261                 }
2258 /* debug method start   2262 /* debug method start
2259                 public String toString() {   2263                 public String toString() {
2260                         return toString("");   2264                         return toString("");
2261                 }   2265                 }
2262                 public String toString(boolean reverse) {   2266                 public String toString(boolean reverse) {
2263                         if(reverse) {   2267                         if(reverse) {
2264                                 return toStringReverse("");   2268                                 return toStringReverse("");
2265                         } else {   2269                         } else {
2266                                 return toString("");   2270                                 return toString("");
2267                         }   2271                         }
2268                 }   2272                 }
2269                 // child -> parent, like menu   2273                 // child -> parent, like menu
2270                 private String toStringReverse(String pre) {   2274                 private String toStringReverse(String pre) {
2271                         if(dispose)   2275                         if(dispose)
2272                                 return "";   2276                                 return "";
2273                         StringBuffer sb = new StringBuffer();   2277                         StringBuffer sb = new StringBuffer();
2274                         if(control != null) {   2278                         if(control != null) {
2275                                 sb.append(pre+control.toString() + "{handle="+control.internal_handle+"}");   2279                                 sb.append(pre+control.toString() + "{handle="+control.internal_handle+"}");
2276                         }   2280                         }
2277                         sb.append(pre+"command(s) : \n");   2281                         sb.append(pre+"command(s) : \n");
2278                         sb.append(commandNode.toString(pre));   2282                         sb.append(commandNode.toString(pre));
2279                         if(parent == null)   2283                         if(parent == null)
2280                                 sb.append("root");   2284                                 sb.append("root");
2281                         else   2285                         else
2282                                 sb.append(parent.toStringReverse(pre + "   "));   2286                                 sb.append(parent.toStringReverse(pre + "   "));
2283                         return sb.toString();   2287                         return sb.toString();
2284                 }   2288                 }
2285                 // parent -> child, tree data   2289                 // parent -> child, tree data
2286                 private String toString(String pre) {   2290                 private String toString(String pre) {
2287                         if(dispose)   2291                         if(dispose)
2288                                 return "";   2292                                 return "";
2289                         StringBuffer sb = new StringBuffer();   2293                         StringBuffer sb = new StringBuffer();
2290                         if(control != null) {   2294                         if(control != null) {
2291                                 sb.append(pre+control.toString() + "{handle="+control.internal_handle+"}");   2295                                 sb.append(pre+control.toString() + "{handle="+control.internal_handle+"}");
2292                         }   2296                         }
2293                         sb.append("[");   2297                         sb.append("[");
2294                         if(parent == null) {   2298                         if(parent == null) {
2295                                 sb.append("root");   2299                                 sb.append("root");
2296                         } else {   2300                         } else {
2297                                 if(parent.control == null)   2301                                 if(parent.control == null)
2298                                         sb.append("root");   2302                                         sb.append("root");
2299                                 else   2303                                 else
2300                                         sb.append(parent.control.toString());   2304                                         sb.append(parent.control.toString());
2301                         }   2305                         }
2302                         sb.append("]\n");   2306                         sb.append("]\n");
2303                         sb.append(pre+"   command(s) : \n");   2307                         sb.append(pre+"   command(s) : \n");
2304                         sb.append(commandNode.toString(pre));   2308                         sb.append(commandNode.toString(pre));
2305                         if(hasChild()) {   2309                         if(hasChild()) {
2306                                 sb.append(pre+"   child(s) : \n");   2310                                 sb.append(pre+"   child(s) : \n");
2307                                 for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2311                                 for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2308                                         ControlNode node = (ControlNode)iterator.next();   2312                                         ControlNode node = (ControlNode)iterator.next();
2309                                         sb.append(node.toString(pre + "   "));   2313                                         sb.append(node.toString(pre + "   "));
2310                                 }   2314                                 }
2311                         }   2315                         }
2312           2316        
2313                         return sb.toString();   2317                         return sb.toString();
2314                 }   2318                 }
2315 debug method end */   2319 debug method end */
2316         }   2320         }
2317           2321        
2318         /*   2322         /*
2319          * @author daniel   2323          * @author daniel
2320          * This class provide command and sub command(s) tree in every ControlNode   2324          * This class provide command and sub command(s) tree in every ControlNode
2321          */   2325          */
2322         class CommandNode {   2326         class CommandNode {
2323                 CommandNode parent;   2327                 CommandNode parent;
2324                 Command command;   2328                 Command command;
2325                 Vector childs;                  // put CommandNode   2329                 Vector childs;                  // put CommandNode
2326                 MenuItem item;   2330                 MenuItem item;
2327                 boolean dispose = false;   2331                 boolean dispose = false;
    -+ 2332                 final static boolean SKIP_CLOSE_MENU_CREATION = true;          
2328         = 2333        
2329                 // root node constructs   2334                 // root node constructs
2330                 public CommandNode() {   2335                 public CommandNode() {
2331                         parent = null;   2336                         parent = null;
2332                         command = null;   2337                         command = null;
2333                         childs = new Vector();   2338                         childs = new Vector();
2334                 }   2339                 }
2335           2340        
2336                 // leaf node constructs   2341                 // leaf node constructs
2337                 public CommandNode(Command command) {   2342                 public CommandNode(Command command) {
2338                         parent = null;   2343                         parent = null;
2339                         this.command = command;   2344                         this.command = command;
2340                         childs = new Vector();   2345                         childs = new Vector();
2341                 }   2346                 }
2342           2347        
2343                 // add child command   2348                 // add child command
2344                 public CommandNode addChild(CommandNode child) {   2349                 public CommandNode addChild(CommandNode child) {
2345                         int insert = childs.size();   2350                         int insert = childs.size();
2346                         for(int i=0; i<childs.size(); i++) {   2351                         for(int i=0; i<childs.size(); i++) {
2347                                 CommandNode node = (CommandNode)childs.elementAt(i);   2352                                 CommandNode node = (CommandNode)childs.elementAt(i);
2348                                 if(node.isDispose())   2353                                 if(node.isDispose())
2349                                         continue;   2354                                         continue;
2350                                 if(child.command.priority > node.command.priority) {   2355                                 if(child.command.priority > node.command.priority) {
2351                                         insert = i;   2356                                         insert = i;
2352                                         break;   2357                                         break;
2353                                 }   2358                                 }
2354                         }   2359                         }
2355                         childs.insertElementAt(child, insert);   2360                         childs.insertElementAt(child, insert);
2356                         child.parent = this;   2361                         child.parent = this;
2357                         return child;   2362                         return child;
2358                 }   2363                 }
2359           2364        
2360                 // has child(s)   2365                 // has child(s)
2361                 public boolean hasChild() {   2366                 public boolean hasChild() {
2362                         return (childs.size() > 0);   2367                         return (childs.size() > 0);
2363                 }   2368                 }
2364           2369        
2365                 // check command already in this or child(s)   2370                 // check command already in this or child(s)
2366                 public boolean contains(Command command) {   2371                 public boolean contains(Command command) {
2367                         return contains(command, true);   2372                         return contains(command, true);
2368                 }   2373                 }
2369           2374        
2370                 // recursion check command already in this or child(s)   2375                 // recursion check command already in this or child(s)
2371                 private boolean contains(Command command, boolean recursion) {   2376                 private boolean contains(Command command, boolean recursion) {
2372                         if(this.command == command)   2377                         if(this.command == command)
2373                                 return true;   2378                                 return true;
2374                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2379                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2375                                 CommandNode node = (CommandNode)iterator.next();   2380                                 CommandNode node = (CommandNode)iterator.next();
2376                                 if(node.isDispose())   2381                                 if(node.isDispose())
2377                                         continue;   2382                                         continue;
2378                                 if(recursion) {   2383                                 if(recursion) {
2379                                         if(node.contains(command, recursion))   2384                                         if(node.contains(command, recursion))
2380                                                 return true;   2385                                                 return true;
2381                                 }   2386                                 }
2382                         }   2387                         }
2383                         return false;   2388                         return false;
2384                 }   2389                 }
2385                   2390                
2386                 // check this and parent(s) node is enabled   2391                 // check this and parent(s) node is enabled
2387                 public boolean isEnabled() {   2392                 public boolean isEnabled() {
2388                         return isEnabled(true);   2393                         return isEnabled(true);
2389                 }   2394                 }
2390     2395  
2391                 // recursion check this and parent(s) node is enabled   2396                 // recursion check this and parent(s) node is enabled
2392                 private boolean isEnabled(boolean recursion) {   2397                 private boolean isEnabled(boolean recursion) {
2393                         if(command != null && !command.getEnabled())   2398                         if(command != null && !command.getEnabled())
2394                                 return false;   2399                                 return false;
2395                         if(recursion && parent != null)   2400                         if(recursion && parent != null)
2396                                 if(!parent.isEnabled(recursion))   2401                                 if(!parent.isEnabled(recursion))
2397                                         return false;   2402                                         return false;
2398     2403  
2399                         return true;   2404                         return true;
2400                 }   2405                 }
2401     2406  
2402                 // check this and child(s) node has command   2407                 // check this and child(s) node has command
2403                 public boolean hasCommand() {   2408                 public boolean hasCommand() {
2404                         return hasCommand(true);   2409                         return hasCommand(true);
2405                 }   2410                 }
2406                   2411                
2407                 // recursion check this and child(s) node has command   2412                 // recursion check this and child(s) node has command
2408                 private boolean hasCommand(boolean recursion) {   2413                 private boolean hasCommand(boolean recursion) {
2409                         if(command != null)   2414                         if(command != null)
2410                                 return true;   2415                                 return true;
2411                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2416                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2412                                 CommandNode node = (CommandNode)iterator.next();   2417                                 CommandNode node = (CommandNode)iterator.next();
2413                                 if(node.isDispose())   2418                                 if(node.isDispose())
2414                                         continue;   2419                                         continue;
2415                                 if(node.command != null)   2420                                 if(node.command != null)
2416                                         return true;   2421                                         return true;
2417                                 if(node.hasCommand(recursion))   2422                                 if(node.hasCommand(recursion))
2418                                         return true;   2423                                         return true;
2419                         }   2424                         }
2420                         return false;   2425                         return false;
2421                 }   2426                 }
2422           2427        
2423                 // find command's ControlNode in this or child(s)   2428                 // find command's ControlNode in this or child(s)
2424                 public CommandNode findCommandNode(Command child) {   2429                 public CommandNode findCommandNode(Command child) {
2425                         return findCommandNode(child, true);   2430                         return findCommandNode(child, true);
2426                 }   2431                 }
2427           2432        
2428                 // find command's ControlNode in child(s) when recursion is true   2433                 // find command's ControlNode in child(s) when recursion is true
2429                 private CommandNode findCommandNode(Command child, boolean recursion) {   2434                 private CommandNode findCommandNode(Command child, boolean recursion) {
2430                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2435                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2431                                 CommandNode node = (CommandNode)iterator.next();   2436                                 CommandNode node = (CommandNode)iterator.next();
2432                                 if(node.isDispose())   2437                                 if(node.isDispose())
2433                                         continue;   2438                                         continue;
2434                                 if(node.command == child)   2439                                 if(node.command == child)
2435                                         return node;   2440                                         return node;
2436                                 if(recursion) {   2441                                 if(recursion) {
2437                                         node = node.findCommandNode(child, recursion);   2442                                         node = node.findCommandNode(child, recursion);
2438                                         if(node != null && node.command == child)   2443                                         if(node != null && node.command == child)
2439                                                 return node;   2444                                                 return node;
2440                                 }   2445                                 }
2441                         }   2446                         }
2442                         return null;   2447                         return null;
2443                 }   2448                 }
2444           2449        
2445                 // bring up this node command(and command child) menu, expand all sub menu   2450                 // bring up this node command(and command child) menu, expand all sub menu
2446                 public void makeMenu(Menu menu) {   2451                 public void makeMenu(Menu menu) {
2447                         makeMenu(menu, true, -1);   2452                         makeMenu(menu, true, -1);
2448                 }   2453                 }
2449           2454        
2450                 // bring up this node command(and command child) menu, expand specify level sub menu   2455                 // bring up this node command(and command child) menu, expand specify level sub menu
2451                 public void makeMenu(Menu menu, int level) {   2456                 public void makeMenu(Menu menu, int level) {
2452                         makeMenu(menu, true, level);   2457                         makeMenu(menu, true, level);
2453                 }   2458                 }
2454           2459        
2455                 // bring up this node command(and command child if recursion is true) menu, expand specify level sub menu   2460                 // bring up this node command(and command child if recursion is true) menu, expand specify level sub menu
2456                 private void makeMenu(Menu menu, boolean recursion, int level) {   2461                 private void makeMenu(Menu menu, boolean recursion, int level) {
    <> 2462                         if (SKIP_CLOSE_MENU_CREATION)
      2463                         {
      2464                                 // jmiers - don't automatically add the Close submenu
      2465                                 return;
      2466                         }
      2467                                
2457                         if(!hasChild()) = 2468                         if(!hasChild())
2458                                 return;   2469                                 return;
2459           2470        
2460                         Vector hasChild = new Vector();   2471                         Vector hasChild = new Vector();
2461                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2472                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2462                                 CommandNode node = (CommandNode)iterator.next();   2473                                 CommandNode node = (CommandNode)iterator.next();
2463                                 if(node.isDispose())   2474                                 if(node.isDispose())
2464                                         continue;   2475                                         continue;
2465                                 if(node.hasChild()) {   2476                                 if(node.hasChild()) {
2466                                         MenuItem item = new MenuItem(menu, SWT.CASCADE);   2477                                         MenuItem item = new MenuItem(menu, SWT.CASCADE);
2467                                         setMenuItem(item, node.command);   2478                                         setMenuItem(item, node.command);
2468                                         implementListener(item, node.command);   2479                                         implementListener(item, node.command);
2469                                         node.item = item;   2480                                         node.item = item;
2470                                         if(!node.command.enabled)   2481                                         if(!node.command.enabled)
2471                                                 continue;   2482                                                 continue;
2472                                         if(!recursion)   2483                                         if(!recursion)
2473                                                 continue;   2484                                                 continue;
2474                                         if(level != 0) {   2485                                         if(level != 0) {
2475                                                 Menu subMenu = new Menu(item);   2486                                                 Menu subMenu = new Menu(item);
2476                                                 item.setMenu(subMenu);   2487                                                 item.setMenu(subMenu);
2477                                                 node.makeMenu(subMenu, recursion, level-1);   2488                                                 node.makeMenu(subMenu, recursion, level-1);
2478                                         } else {   2489                                         } else {
2479                                                 hasChild.add(node);   2490                                                 hasChild.add(node);
2480                                         }   2491                                         }
2481                                 } else {   2492                                 } else {
2482                                         MenuItem item = new MenuItem(menu, SWT.PUSH);   2493                                         MenuItem item = new MenuItem(menu, SWT.PUSH);
2483                                         setMenuItem(item, node.command);   2494                                         setMenuItem(item, node.command);
2484                                         implementListener(item, node.command);   2495                                         implementListener(item, node.command);
2485                                         node.item = item;   2496                                         node.item = item;
2486                                         itemAddSelectionListener(item, node.command);   2497                                         itemAddSelectionListener(item, node.command);
2487                                 }   2498                                 }
2488                         }   2499                         }
2489                         // has child command   2500                         // has child command
2490                         for(Iterator iterator = hasChild.iterator();iterator.hasNext();) {   2501                         for(Iterator iterator = hasChild.iterator();iterator.hasNext();) {
2491                                 CommandNode node = (CommandNode)iterator.next();   2502                                 CommandNode node = (CommandNode)iterator.next();
2492                                 if(node.isDispose())   2503                                 if(node.isDispose())
2493                                         continue;   2504                                         continue;
2494                                 MenuItem barItem = new MenuItem(menu, SWT.SEPARATOR);   2505                                 MenuItem barItem = new MenuItem(menu, SWT.SEPARATOR);
2495                                 node.makeMenu(menu, recursion, 0);   2506                                 node.makeMenu(menu, recursion, 0);
2496                         }   2507                         }
2497                 }   2508                 }
2498                   2509                
2499                 private void implementListener(MenuItem item, Command command) {   2510                 private void implementListener(MenuItem item, Command command) {
2500                         if(command.listeners == null)   2511                         if(command.listeners == null)
2501                                 return;   2512                                 return;
2502                         final MenuItem item_tmp = item;   2513                         final MenuItem item_tmp = item;
2503                         for(int i=0; i<command.listeners.size(); i++) {   2514                         for(int i=0; i<command.listeners.size(); i++) {
2504                                 final CommandListener cmdListener = (CommandListener)command.listeners.elementAt(i);   2515                                 final CommandListener cmdListener = (CommandListener)command.listeners.elementAt(i);
2505                                 item.addListener(cmdListener.getEventType(), cmdListener);   2516                                 item.addListener(cmdListener.getEventType(), cmdListener);
2506                                 item.addDisposeListener(new DisposeListener() {   2517                                 item.addDisposeListener(new DisposeListener() {
2507                                         public void widgetDisposed(DisposeEvent e) {   2518                                         public void widgetDisposed(DisposeEvent e) {
2508                                                 item_tmp.removeListener(cmdListener.getEventType(), cmdListener);   2519                                                 item_tmp.removeListener(cmdListener.getEventType(), cmdListener);
2509                                         }   2520                                         }
2510                                 });   2521                                 });
2511                         }   2522                         }
2512                 }   2523                 }
2513                   2524                
2514                 private void itemAddSelectionListener(MenuItem item, Command command) {   2525                 private void itemAddSelectionListener(MenuItem item, Command command) {
2515                         if(item == null || item.isDisposed() ||   2526                         if(item == null || item.isDisposed() ||
2516                            command == null || command.isDisposed())   2527                            command == null || command.isDisposed())
2517                                 return;   2528                                 return;
2518                         final Command nodeCommand = command;   2529                         final Command nodeCommand = command;
2519                         item.addSelectionListener(new SelectionListener(){   2530                         item.addSelectionListener(new SelectionListener(){
2520                                 public void widgetSelected(SelectionEvent e) {   2531                                 public void widgetSelected(SelectionEvent e) {
2521                                         if(nodeCommand.selectionListenerCount > 0)   2532                                         if(nodeCommand.selectionListenerCount > 0)
2522                                                 nodeCommand.Command_SendEvent(SWT.Selection);   2533                                                 nodeCommand.Command_SendEvent(SWT.Selection);
2523                                 }   2534                                 }
2524                                 public void widgetDefaultSelected(SelectionEvent e) {   2535                                 public void widgetDefaultSelected(SelectionEvent e) {
2525                                         if(nodeCommand.selectionListenerCount > 0)   2536                                         if(nodeCommand.selectionListenerCount > 0)
2526                                                 nodeCommand.Command_SendEvent(SWT.DefaultSelection);   2537                                                 nodeCommand.Command_SendEvent(SWT.DefaultSelection);
2527                                 }   2538                                 }
2528                         });   2539                         });
2529                 }   2540                 }
2530                   2541                
2531                 // set MenuItem data from Command   2542                 // set MenuItem data from Command
2532                 private void setMenuItem(MenuItem item, Command command) {   2543                 private void setMenuItem(MenuItem item, Command command) {
2533                         if(item == null || command == null)   2544                         if(item == null || command == null)
2534                                 return;   2545                                 return;
2535     2546  
2536                         String longLabel = command.getLongLabel();   2547                         String longLabel = command.getLongLabel();
2537                         if(longLabel != null && (gwtStringWidth(longLabel) < displayWidth || command.getText().equals("")))   2548                         if(longLabel != null && (gwtStringWidth(longLabel) < displayWidth || command.getText().equals("")))
2538                                 item.setText(longLabel);   2549                                 item.setText(longLabel);
2539                         else   2550                         else
2540                                 item.setText(command.getText());   2551                                 item.setText(command.getText());
2541                         item.setAccelerator(command.accelerator);   2552                         item.setAccelerator(command.accelerator);
2542                         if(command.getImage() != null)   2553                         if(command.getImage() != null)
2543                                 item.setImage(command.getImage());   2554                                 item.setImage(command.getImage());
2544                         item.setEnabled(command.enabled);   2555                         item.setEnabled(command.enabled);
2545                         item.setSelection(command.defaultCommand);   2556                         item.setSelection(command.defaultCommand);
2546                 }   2557                 }
2547                   2558                
2548                 private int gwtStringWidth(String str) {   2559                 private int gwtStringWidth(String str) {
2549                         if(str == null)   2560                         if(str == null)
2550                                 return 0;   2561                                 return 0;
2551                         int width = 0;   2562                         int width = 0;
2552                         for(int i=0; i<str.length(); i++)   2563                         for(int i=0; i<str.length(); i++)
2553                                 width += gc.getCharWidth(str.charAt(i));   2564                                 width += gc.getCharWidth(str.charAt(i));
2554                         return width;   2565                         return width;
2555                 }   2566                 }
2556                   2567                
2557                 // remove command   2568                 // remove command
2558                 public boolean removeCommand(Command command) {   2569                 public boolean removeCommand(Command command) {
2559                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2570                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2560                                 CommandNode node = (CommandNode)iterator.next();   2571                                 CommandNode node = (CommandNode)iterator.next();
2561                                 if(node.isDispose())   2572                                 if(node.isDispose())
2562                                         continue;   2573                                         continue;
2563                                 if(node.command == command) {   2574                                 if(node.command == command) {
2564                                         childs.remove(node);   2575                                         childs.remove(node);
2565                                         node.dispose();   2576                                         node.dispose();
2566                                         node = null;   2577                                         node = null;
2567                                         return true;   2578                                         return true;
2568                                 }   2579                                 }
2569                                 if(node.removeCommand(command))   2580                                 if(node.removeCommand(command))
2570                                         return true;   2581                                         return true;
2571                         }   2582                         }
2572                         return false;   2583                         return false;
2573                 }   2584                 }
2574           2585        
2575                 // dispose this node and child(s) node   2586                 // dispose this node and child(s) node
2576                 public void dispose() {   2587                 public void dispose() {
2577                         if(dispose)   2588                         if(dispose)
2578                                 return;   2589                                 return;
2579                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2590                         for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2580                                 CommandNode node = (CommandNode)iterator.next();   2591                                 CommandNode node = (CommandNode)iterator.next();
2581                                 if(node.isDispose())   2592                                 if(node.isDispose())
2582                                         continue;   2593                                         continue;
2583                                 node.dispose();   2594                                 node.dispose();
2584                                 node = null;   2595                                 node = null;
2585                         }   2596                         }
2586                         if(item != null && !item.isDisposed())   2597                         if(item != null && !item.isDisposed())
2587                                 item.dispose();   2598                                 item.dispose();
2588                         childs.clear();   2599                         childs.clear();
2589                         childs = null;   2600                         childs = null;
2590                         dispose = true;   2601                         dispose = true;
2591                 }   2602                 }
2592                 public boolean isDispose() {   2603                 public boolean isDispose() {
2593                         return dispose;   2604                         return dispose;
2594                 }   2605                 }
2595 /* debug method start   2606 /* debug method start
2596                 public String toString() {   2607                 public String toString() {
2597                         return toString("");   2608                         return toString("");
2598                 }   2609                 }
2599                 public String toString(String pre) {   2610                 public String toString(String pre) {
2600                         if(dispose)   2611                         if(dispose)
2601                                 return "";   2612                                 return "";
2602                         StringBuffer sb = new StringBuffer();   2613                         StringBuffer sb = new StringBuffer();
2603                         if(command != null) {   2614                         if(command != null) {
2604                                 sb.append(pre);   2615                                 sb.append(pre);
2605                                 sb.append(command.toString());   2616                                 sb.append(command.toString());
2606                                 sb.append("\n");   2617                                 sb.append("\n");
2607                         }   2618                         }
2608                           2619                        
2609                         if(hasChild()) {   2620                         if(hasChild()) {
2610                                 if(command != null)   2621                                 if(command != null)
2611                                         sb.append(pre+"child(s) : \n");   2622                                         sb.append(pre+"child(s) : \n");
2612                                 for(Iterator iterator = childs.iterator();iterator.hasNext();) {   2623                                 for(Iterator iterator = childs.iterator();iterator.hasNext();) {
2613                                         CommandNode node = (CommandNode)iterator.next();   2624                                         CommandNode node = (CommandNode)iterator.next();
2614                                         sb.append(node.toString(pre + "   "));   2625                                         sb.append(node.toString(pre + "   "));
2615                                 }   2626                                 }
2616                         }   2627                         }
2617                         return sb.toString();   2628                         return sb.toString();
2618                 }   2629                 }
2619 debug method end */   2630 debug method end */
2620         }   2631         }
2621           2632        
2622         public void setDefaultCommand(Command c){   2633         public void setDefaultCommand(Command c){
2623                 Command tempCommand;   2634                 Command tempCommand;
2624                 for(int i = 0; i<commandList.size(); i++){   2635                 for(int i = 0; i<commandList.size(); i++){
2625                         tempCommand = (Command) commandList.elementAt(i);   2636                         tempCommand = (Command) commandList.elementAt(i);
2626                         if(tempCommand.defaultCommand && !tempCommand.equals(c)){   2637                         if(tempCommand.defaultCommand && !tempCommand.equals(c)){
2627                                 tempCommand.defaultCommand = false;   2638                                 tempCommand.defaultCommand = false;
2628                         }   2639                         }
2629                 }                 2640                 }              
2630         }   2641         }
2631     2642  
2632 }   2643 }