GrxBasePlugin.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxBasePlugin.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 package com.generalrobotix.ui;
19 
20 import java.io.File;
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;
26 
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;
38 
45 
46 @SuppressWarnings("serial") //$NON-NLS-1$
50 public class GrxBasePlugin extends GrxConfigBundle {
51  private String name_;
52  private String oldName_;
54  private String url_;
55  private boolean selected_ = true;
56  private boolean isExclusive_= false;
57 
58  private ImageRegistry ireg_;
59  private String iconName_;
60 
61  private Vector<Action> menu_ = new Vector<Action>();
62  private Vector<MenuManager> subMenu_ = new Vector<MenuManager>();
63  private String[] menuPath_;
64 
65  protected Document doc_;
66  protected Element element_;
67 
68  protected final static String ITEM_TAG = "item"; //$NON-NLS-1$
69  protected final static String VIEW_TAG = "view"; //$NON-NLS-1$
70  protected final static String PROPERTY_TAG = "property"; //$NON-NLS-1$
71  protected final static String INDENT4 = " "; //$NON-NLS-1$
72 
73  protected static final String[] booleanComboItem_ = new String[] {"true", "false" };
74 
75  private ArrayList<GrxObserver> observers_ = new ArrayList<GrxObserver>();
76 
82  protected GrxBasePlugin(String name, GrxPluginManager manager) {
83  manager_ = manager;
84  setName(name);
85  ireg_ = new ImageRegistry();
86  // menu item : restore Properties
87  Action a = new Action(){
88  public String getText(){
89  return MessageBundle.get("GrxBasePlugin.menu.restoreProperties"); //$NON-NLS-1$
90  }
91  public void run(){
92  restoreProperties();
93  }
94  };
95  setMenuItem(a);
96 
97  // menu item : rename
98  Action item = new Action(){
99  public String getText(){
100  return MessageBundle.get("GrxBasePlugin.menu.rename"); //$NON-NLS-1$
101  }
102  public void run(){
103  InputDialog dialog = new InputDialog( null, getText(),
104  MessageBundle.get("GrxBasePlugin.dialog.message.input"), getName(),null); //$NON-NLS-1$
105  if ( dialog.open() == InputDialog.OK && dialog.getValue() != null)
106  rename( dialog.getValue() );
107  }
108  };
109  setMenuItem(item);
110  }
111 
115  public void restoreProperties() {
116  if (element_ == null) {
117  return;
118  }
119  clear();
120  if(url_!=null)
121  setProperty("url", url_);
122  if(name_!=null)
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"); //$NON-NLS-1$
128  String val = propEl.getAttribute("value"); //$NON-NLS-1$
129  if (!propertyChanged(key, val)){
130  setProperty(key, val);
131  }
132  }
133  }
134 
139  public Element storeProperties() {
140  if (doc_ == null)
141  return null;
142 
143  if (element_ != null) {
144  Node n = element_.getParentNode();
145  if (n != null)
146  n.removeChild(element_);
147  }
148 
149  String tag = (this instanceof GrxBaseItem) ? ITEM_TAG:VIEW_TAG;
150  element_ = doc_.createElement(tag);
151 
152  element_.setAttribute("class",getClass().getName()); //$NON-NLS-1$
153  element_.setAttribute("name", getName()); //$NON-NLS-1$
154  element_.setAttribute("select", String.valueOf(isSelected())); //$NON-NLS-1$
155  if (url_ != null)
156  element_.setAttribute("url", GrxXmlUtil.replaceEnvVal(new File(url_))); //$NON-NLS-1$
157  element_.appendChild(doc_.createTextNode("\n")); //$NON-NLS-1$
158 
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"))
164  continue;
165 
166  if(key.equals("setupDirectory"))
168  if(key.equals("setupCommand")){
169  String s = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.BIN_SFX);
170  val = val.replace(s, "$(BIN_SFX)");
171  }
172  Element propEl = doc_.createElement(GrxProjectItem.PROPERTY_TAG);
173  propEl.setAttribute("name", key); //$NON-NLS-1$
174  propEl.setAttribute("value", val); //$NON-NLS-1$
175 
176  element_.appendChild(doc_.createTextNode(INDENT4+INDENT4+INDENT4));
177  element_.appendChild(propEl);
178  element_.appendChild(doc_.createTextNode("\n")); //$NON-NLS-1$
179  }
180  element_.appendChild(doc_.createTextNode(INDENT4+INDENT4));
181 
182  return element_;
183  }
184 
189  public void setName(String name) {
190  oldName_ = name_;
191  name_ = name;
192  setProperty("name", name); //$NON-NLS-1$
193  }
194 
199  public final String getName() {
200  return name_;
201  }
202 
207  public final String toString() {
208  return name_;
209  }
210 
211  public String getOldName(){
212  return oldName_;
213  }
214 
219  public void setDocument(Document doc) {
220  doc_ = doc;
221  }
222 
227  public void setElement(Element element) {
228  element_ = element;
229  doc_ = element.getOwnerDocument();
230  }
231 
236  public Element getElement() {
237  return element_;
238  }
239 
244  public void setSelected(boolean b) {
245  selected_ = b;
246  }
247 
252  public boolean isSelected() {
253  return selected_;
254  }
255 
260  public void setExclusive(boolean b) {
261  isExclusive_ = b;
262  }
263 
268  public boolean isExclusive() {
269  return isExclusive_;
270  }
271 
276  protected void setIcon(String iconName) {
277  iconName_ = iconName;
278  if( ireg_.get( iconName_ ) == null )
279  ireg_.put( iconName_, ImageDescriptor.createFromURL( getClass().getResource( "/resources/images/"+iconName_ ) ) ); //$NON-NLS-1$
280  //icon_ = icon;
281  }
282 
287  public Image getIcon() {
288  return ireg_.get( iconName_ );
289  }
290 
295  public void setMenuItem( Action a ) {
296  menu_.add(a);
297  }
298 
303  public void setSubMenu( MenuManager m ) {
304  subMenu_.add(m);
305  }
306 
311  public Vector<Action> getMenu() {
312  return menu_;
313  }
314 
319  public Vector<MenuManager> getSubMenu() {
320  return subMenu_;
321  }
322 
327  protected void setMenuPath(String[] path) {
328  menuPath_ = path;
329  }
330 
336  protected boolean syncExec(Runnable r) {
337  Display display = Display.getDefault();
338  if (display != null && !display.isDisposed()) {
339  display.syncExec(r);
340  return true;
341  } else
342  return false;
343  }
344 
349  public String[] getMenuPath() {
350  return menuPath_;
351  };
352 
357  public boolean equals(Object obj) {
358 
359  return this == obj;
360  }
361 
367  public String getURL(boolean expand) {
368  if (expand)
369  return GrxXmlUtil.expandEnvVal(url_);
370  else
371  return url_;
372  }
373 
378  public void setURL(String url) {
379  url = url.replace('\\','/');
380  setProperty("url", url); //$NON-NLS-1$
381  url_ =url;
382  }
383 
388  public void rename(String newName) {
389  manager_.renamePlugin(this, newName);
390  };
391 
399  public static Object getField(Class<? extends GrxBasePlugin> cls, String field, Object defaultValue) {
400  try {
401  Field f = cls.getField(field);
402  return (Object)f.get(new Object());
403  } catch (Exception e) {
404  //GrxDebugUtil.println(cls.getName() + ": " + field + " not defined");
405  }
406  return defaultValue;
407  }
408 
412  public void shutdown() {
413 
414  }
415 
419  public void unregisterCORBA() {
420 
421  }
422 
426  public boolean registerCORBA() {
427  return true;
428  }
429 
435  GrxBasePlugin ret = (GrxBasePlugin) super.clone();
436 
437 
438  ret.setName(name_);
439  ret.setURL(url_);
440 
441 /*
442  * Deep copy suspension list
443 
444  private ImageRegistry ireg_;
445  private String iconName_;
446 
447  private Vector<Action> menu_ = new Vector<Action>();
448  private String[] menuPath_;
449 
450  private Document doc_;
451  protected Element element_;
452 */
453 
454  return ret;
455  }
456 
463  public boolean propertyChanged(String property, String value) {
464  if (property.equals("name")){ //$NON-NLS-1$
465  rename(value);
466  return true;
467  }
468  return false;
469  }
470 
471 
477  public Object setProperty(String key, String value){
478  //System.out.println("GrxBasePlugin.setProperty("+key+","+value+")");
479  Object o = super.setProperty(key, value);
480  notifyObservers("PropertyChange", key, value); //$NON-NLS-1$
481  return o;
482  }
483 
488  public void setFocused(boolean b){
489  }
490 
491  public void addObserver(GrxObserver v){
492  observers_.add(v);
493  }
494 
495  public void deleteObserver(GrxObserver v){
496  observers_.remove(v);
497  }
498 
499  public ArrayList<GrxObserver> getObserver(){
500  return observers_;
501  }
502 
503  public void notifyObservers(Object... arg) {
504  ListIterator<GrxObserver> it = observers_.listIterator();
505  while (it.hasNext()) {
506  GrxObserver observer = it.next();
507  observer.update(this, arg);
508  }
509  }
510 
515  public ValueEditType GetValueEditType(String key) {
516  return new ValueEditText();
517  }
518 
519  public class ValueEditType{
520  private ValueEditType(){}
521  }
522  public class ValueEditText extends ValueEditType{
523  public ValueEditText(){}
524  }
525  public class ValueEditCombo extends ValueEditType{
526  private String[] items_;
527  public ValueEditCombo(String[] items){
528  items_ = items;
529  }
530  public String[] GetItems(){ return items_; }
531  }
532 }
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()
list keys
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)
#define null
our own NULL pointer
Definition: IceTypes.h:57
Element storeProperties()
store properties
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
void setMenuPath(String[] path)
set menu path
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
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
long b
Definition: jpegint.h:371
GrxBasePlugin clone()
Override clone method.
boolean syncExec(Runnable r)
Transfer SWT UI thread.
ValueEditType GetValueEditType(String key)
Return editing type of the key item.
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.
string a
def run(tree, args)
int val
Definition: jpeglib.h:956
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)
void restoreProperties()
restore properties. Called by menu item "restore Properties"
org
char * arg
Definition: cdjpeg.h:136
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


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21