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(){
98 Action
item =
new Action(){
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()) {
static final String PROPERTY_TAG
void setSelected(boolean b)
set selected flag
void rename(String newName)
rename this item
static final String get(String key)
static Object getField(Class<?extends GrxBasePlugin > cls, String field, Object defaultValue)
get field
ArrayList< GrxObserver > getObserver()
void notifyObservers(Object...arg)
boolean propertyChanged(String property, String value)
check validity of new value of property and update if valid
void update(GrxBasePlugin plugin, Object...arg)
void setName(String name)
set name
void clear(CorbaSequence &seq)
void addObserver(GrxObserver v)
#define null
our own NULL pointer
Element storeProperties()
store properties
static final String BIN_SFX
png_infop png_charpp name
GrxPluginManager manager_
void setMenuPath(String[] path)
set menu path
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void deleteObserver(GrxObserver v)
String getURL(boolean expand)
boolean equals(Object obj)
check whether obj equals to this
void setURL(String url)
set URL property
boolean isSelected()
check whether this is selected or not
void setSubMenu(MenuManager m)
add a submenu
Vector< MenuManager > getSubMenu()
get subMenu
GrxBasePlugin clone()
Override clone method.
boolean syncExec(Runnable r)
Transfer SWT UI thread.
ValueEditType GetValueEditType(String key)
Return editing type of the key item.
static Activator getDefault()
ValueEditCombo(String[] items)
Element getElement()
get element
void setIcon(String iconName)
set icon
void setDocument(Document doc)
set document
def j(str, encoding="cp932")
boolean renamePlugin(GrxBasePlugin item, String newName)
rename plugin. If new name is already used, name is not changed.
void setMenuItem(Action a)
add a menu item
static String expandEnvVal(String str)
Object setProperty(String key, String value)
set property value associated with a keyword
boolean isExclusive()
check whether this is exclusive or not
Vector< Action > getMenu()
get menu
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void setElement(Element element)
set element
final String toString()
convert to String. Currently, name is returned.
String[] getMenuPath()
get menu path
def getText(self, nodes=None)
final String getName()
get name
void restoreProperties()
restore properties. Called by menu item "restore Properties"
static String replaceEnvVal(File f)
void setExclusive(boolean b)
set exclusive flag
GrxBasePlugin(String name, GrxPluginManager manager)
constructor
void setFocused(boolean b)
set/unset focus on this plugin