18 package com.generalrobotix.ui;
21 import java.lang.reflect.Field;
22 import java.util.ArrayList;
23 import java.util.Enumeration;
24 import java.util.ListIterator;
25 import java.util.Vector;
27 import org.eclipse.jface.action.Action;
28 import org.eclipse.jface.action.MenuManager;
29 import org.eclipse.jface.dialogs.InputDialog;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.resource.ImageRegistry;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.swt.widgets.Display;
34 import org.w3c.dom.Document;
35 import org.w3c.dom.Element;
36 import org.w3c.dom.Node;
37 import org.w3c.dom.NodeList;
46 @SuppressWarnings(
"serial")
55 private boolean selected_ =
true;
56 private boolean isExclusive_=
false;
61 private Vector<Action> menu_ =
new Vector<Action>();
62 private Vector<MenuManager> subMenu_ =
new Vector<MenuManager>();
68 protected final static String ITEM_TAG =
"item";
69 protected final static String VIEW_TAG =
"view";
70 protected final static String PROPERTY_TAG =
"property";
71 protected final static String INDENT4 =
" ";
73 protected static final String[] booleanComboItem_ =
new String[] {
"true",
"false" };
75 private ArrayList<GrxObserver> observers_ =
new ArrayList<GrxObserver>();
85 ireg_ =
new ImageRegistry();
87 Action
a =
new Action(){
88 public String getText(){
98 Action
item =
new Action(){
99 public String getText(){
103 InputDialog dialog =
new InputDialog(
null, getText(),
105 if ( dialog.open() == InputDialog.OK && dialog.getValue() !=
null)
106 rename( dialog.getValue() );
116 if (element_ ==
null) {
121 setProperty(
"url", url_);
123 setProperty(
"name", name_);
124 NodeList props = element_.getElementsByTagName(PROPERTY_TAG);
125 for (
int j = 0; j < props.getLength(); j++) {
126 Element propEl = (Element) props.item(j);
127 String key = propEl.getAttribute(
"name");
128 String
val = propEl.getAttribute(
"value");
129 if (!propertyChanged(key,
val)){
130 setProperty(key,
val);
143 if (element_ !=
null) {
144 Node
n = element_.getParentNode();
146 n.removeChild(element_);
149 String tag = (
this instanceof
GrxBaseItem) ? ITEM_TAG:VIEW_TAG;
150 element_ = doc_.createElement(tag);
152 element_.setAttribute(
"class",getClass().getName());
153 element_.setAttribute(
"name", getName());
154 element_.setAttribute(
"select", String.valueOf(isSelected()));
157 element_.appendChild(doc_.createTextNode(
"\n"));
159 Enumeration<?> keys = propertyNames();
160 while (keys.hasMoreElements()) {
161 String key = (String)keys.nextElement();
162 String
val = getProperty(key);
163 if (key ==
null ||
val ==
null || key.equals(
"name") || key.equals(
"url"))
166 if(key.equals(
"setupDirectory"))
168 if(key.equals(
"setupCommand")){
170 val =
val.replace(s,
"$(BIN_SFX)");
173 propEl.setAttribute(
"name", key);
174 propEl.setAttribute(
"value",
val);
176 element_.appendChild(doc_.createTextNode(INDENT4+INDENT4+INDENT4));
177 element_.appendChild(propEl);
178 element_.appendChild(doc_.createTextNode(
"\n"));
180 element_.appendChild(doc_.createTextNode(INDENT4+INDENT4));
192 setProperty(
"name",
name);
229 doc_ = element.getOwnerDocument();
277 iconName_ = iconName;
278 if( ireg_.get( iconName_ ) ==
null )
279 ireg_.put( iconName_, ImageDescriptor.createFromURL( getClass().getResource(
"/resources/images/"+iconName_ ) ) );
288 return ireg_.get( iconName_ );
337 Display display = Display.getDefault();
338 if (display !=
null && !display.isDisposed()) {
379 url = url.replace(
'\\',
'/');
380 setProperty(
"url", url);
399 public static Object
getField(Class<? extends GrxBasePlugin> cls, String field, Object defaultValue) {
401 Field
f = cls.getField(field);
402 return (Object)
f.get(
new Object());
403 }
catch (Exception e) {
464 if (property.equals(
"name")){
479 Object o = super.setProperty(key,
value);
480 notifyObservers(
"PropertyChange", key,
value);
496 observers_.remove(v);
504 ListIterator<GrxObserver> it = observers_.listIterator();
505 while (it.hasNext()) {