19 package com.generalrobotix.ui;
21 import java.awt.Toolkit;
22 import java.awt.datatransfer.Clipboard;
23 import java.awt.datatransfer.DataFlavor;
24 import java.awt.datatransfer.Transferable;
26 import java.lang.reflect.Method;
30 import org.eclipse.core.resources.ResourcesPlugin;
31 import org.eclipse.jface.action.Action;
32 import org.eclipse.jface.dialogs.MessageDialog;
33 import org.eclipse.jface.preference.IPreferenceStore;
34 import org.eclipse.jface.util.IPropertyChangeListener;
35 import org.eclipse.jface.util.PropertyChangeEvent;
36 import org.omg.PortableServer.POA;
38 import org.w3c.dom.Element;
59 import org.eclipse.osgi.util.NLS;
60 import org.eclipse.swt.SWT;
61 import org.eclipse.swt.widgets.Display;
62 import org.eclipse.swt.widgets.FileDialog;
63 import org.eclipse.ui.IPerspectiveDescriptor;
64 import org.eclipse.ui.IViewPart;
65 import org.eclipse.ui.IViewReference;
66 import org.eclipse.ui.IWorkbench;
67 import org.eclipse.ui.IWorkbenchPage;
68 import org.eclipse.ui.IWorkbenchWindow;
69 import org.eclipse.ui.PlatformUI;
88 private List<GrxBaseView>
viewList_ =
new ArrayList<GrxBaseView>();
94 new HashMap<Class<? extends GrxBaseItem>, List<GrxItemChangeListener>>();
127 dir = System.getenv(
"PROJECT_DIR");
129 homePath_ =
new File(dir);
132 System.out.println(
"[PM] WORKSPACE PATH=" + ResourcesPlugin.getWorkspace().getRoot().getLocation());
142 if (!rtcFile.exists()){
145 }
catch (IOException ex){
146 ex.printStackTrace();
153 String defaultProject = System.getProperty(
"PROJECT",
null);
159 if (serverManager !=
null){
164 if (processManager !=
null){
176 if (focusedItem_ != item) {
177 if (focusedItem_ !=
null){
203 IWorkbench workbench = PlatformUI.getWorkbench();
204 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
207 IWorkbenchPage page = window.getActivePage();
210 IPerspectiveDescriptor pers = page.getPerspective();
221 activeViewList_.clear();
223 Display display = Display.getDefault();
224 display.syncExec(
new Runnable(){
226 IWorkbench workbench = PlatformUI.getWorkbench();
227 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
230 IWorkbenchPage page = window.getActivePage();
234 IPerspectiveDescriptor pers = page.getPerspective();
240 for (IViewReference
i : page.getViewReferences()) {
242 IViewPart v =
i.getView(
true);
246 activeViewList_.add(view);
257 Display display = Display.getDefault();
258 display.syncExec(
new Runnable(){
260 IWorkbench workbench = PlatformUI.getWorkbench();
261 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
262 if (windows.length == 0)
264 for(IWorkbenchWindow window : windows){
265 IWorkbenchPage page = window.getActivePage();
267 IPerspectiveDescriptor pers = page.getPerspective();
269 for (IViewReference
i : page.getViewReferences()) {
271 IViewPart v =
i.getView(
true);
294 System.out.println(
"[PM] START GrxPluginManager");
299 poa_.the_POAManager().activate();
304 }
catch (Exception e) {
375 @SuppressWarnings(
"unchecked")
377 Class<?> cls = pluginLoader_.
loadClass(className);
387 @SuppressWarnings(
"unchecked")
390 Class<? extends GrxBasePlugin>
ret =
registerPlugin((Class<? extends GrxBasePlugin>) cls);
404 public Class<? extends GrxBasePlugin>
registerPlugin(Class<? extends GrxBasePlugin> cls) {
416 pi.filter =
"*." + ext;
437 baseName = baseName.toLowerCase().replaceAll(
" ",
"");
438 for (
int i = 0;;
i++) {
466 URL u =
new URL(_url);
467 f =
new File(u.getFile());
468 }
catch (Exception e) {
473 _url = f.getCanonicalPath();
475 }
catch (IOException e) {
482 String[] fe = { pi.filter };
483 fdlg.setText(_url+
" "+
MessageBundle.
get(
"GrxPluginManager.fileDialog.notFound"));
484 fdlg.setFilterExtensions(fe);
485 fdlg.setFilterPath(pi.lastDir.getAbsolutePath());
486 String fPath = fdlg.open();
495 String
basename = f.getName().split(
"[.]")[0];
499 name = basename + index.toString();
512 pinfoMap_.get(cls).lastDir = f.getParentFile();
560 @SuppressWarnings(
"unchecked")
567 HashMap<String, GrxBasePlugin> map =
pluginMap_.get(cls);
569 if ( plugin !=
null) {
571 ((GrxBaseItem)plugin).delete();
578 }
catch (Exception e) {
590 @SuppressWarnings(
"unchecked")
592 HashMap<String, GrxBasePlugin> map =
pluginMap_.get(instance.getClass());
594 if ( plugin !=
null) {
595 GrxDebugUtil.
println(
"[PM]@createPlugin Plugin instance named "+instance.getName()+
" is already registered.");
597 ((GrxBaseItem)plugin).delete();
598 map.put(instance.getName(), instance);
602 map.put(instance.getName(), instance);
614 Throwable cause = e.getCause();
615 StackTraceElement[] trace =
null;
616 String msg = m +
"\n\n";
618 msg = cause.toString() +
"\n\n";
619 trace = cause.getStackTrace();
621 trace = e.getStackTrace();
624 for (
int i = 0;
i < trace.length;
i++) {
625 msg +=
"at " + trace[
i].getClassName() +
"." + trace[
i].getMethodName() +
"(";
627 if (trace[
i].isNativeMethod()) {
628 msg +=
"(Native Method)\n";
629 }
else if (trace[
i].getFileName() ==
null) {
630 msg +=
"(No source code)\n";
632 msg += trace[
i].getFileName() +
":" + trace[
i].getLineNumber() +
")\n";
635 MessageDialog.openWarning(
null,
"Exception Occered", msg);
643 Map<?, ?> m =
pluginMap_.get(item.getClass());
659 List<GrxModelItem> modifiedModels =
new ArrayList<GrxModelItem>();
660 for (
int i = 0;
i < items.length;
i++){
664 modifiedModel.reload();
672 for (
int i = 0;
i < items.length;
i++)
698 System.out.println(
"map for " + item.getClass() +
" doesn't exist in pluginMap_");
701 if (m.get(newName) ==
null) {
702 if (!newName.equals(item.
getName())) {
704 m.
put(newName, item);
709 System.out.println(
"GrxPluginManager.renamePlugin() : " + newName +
" is already used");
720 ArrayList<GrxBaseItem> iList =
new ArrayList<GrxBaseItem>();
721 for (
int i = 0;
i < cList.size();
i++) {
722 Iterator it =
pluginMap_.get(cList.get(
i)).values().iterator();
723 while (it.hasNext()) {
738 Iterator it =
pluginMap_.get(cls).values().iterator();
739 while (it.hasNext()) {
756 Iterator<OrderedHashMap> it =
pluginMap_.values().iterator();
757 while (it.hasNext()) {
758 HashMap m = (HashMap) it.next();
759 Object o = m.get(name);
761 return (GrxBaseItem) o;
771 public Map<?, ?>
getItemMap(Class<? extends GrxBaseItem> cls) {
781 @SuppressWarnings(
"unchecked")
782 public <T> T getSelectedItem(Class<? extends GrxBaseItem> cls, String
name) {
783 Map<String, ? extends GrxBaseItem> oMap =
pluginMap_.get(cls);
793 if(
item.isSelected())
805 @SuppressWarnings(
"unchecked")
806 public <T> List<T> getSelectedItemList(Class<? extends GrxBaseItem> cls) {
807 ArrayList<T> list =
new ArrayList<T>();
808 Map<String, ? extends GrxBaseItem> oMap =
pluginMap_.get(cls);
809 if(oMap==
null)
return list;
811 if (
item.isSelected())
844 if (v.getClass() == cls)
849 if (v.getClass() == cls)
859 if (v.getName().equals(name)) {
866 if (v.getName().equals(name)) {
881 @SuppressWarnings(
"unchecked")
886 if (select &&
item.isExclusive()) {
889 i.setSelected(
false);
898 item.setSelected(select);
908 Iterator<OrderedHashMap>
i =
pluginMap_.values().iterator();
909 while (i.hasNext()) {
910 Iterator
j = (i.next()).values().iterator();
911 while (j.hasNext()) {
943 static final String VISIBLE =
"visible";
956 public Vector<Action>
getItemMenu(
final Class<? extends GrxBaseItem> cls) {
958 Vector<Action> menu = pi.menu;
963 menu = pi.menu =
new Vector<Action>();
966 Action
create =
new Action() {
980 Action load =
new Action() {
987 String[] fe = { pi.filter };
988 fdlg.setFilterExtensions(fe);
989 fdlg.setFilterPath(pi.lastDir.getAbsolutePath());
990 String fPath = fdlg.open();
997 pi.lastDir = f.getParentFile();
1005 Action
clear =
new Action() {
1011 String mes =
MessageBundle.
get(
"GrxPluginManager.dialog.message.removeItem");
1013 if (MessageDialog.openConfirm(
null,
MessageBundle.
get(
"GrxPluginManager.dialog.title.removeItem"), mes)){
1023 Action
delete =
new Action() {
1029 String mes =
MessageBundle.
get(
"GrxPluginManager.dialog.message.deletePlugin");
1031 if (MessageDialog.openConfirm(
null,
MessageBundle.
get(
"GrxPluginManager.dialog.title.deletePlugin"), mes))
1038 Method m = cls.getMethod(
"create", (Class[])
null);
1039 Class<?>
c = m.getDeclaringClass();
1042 m = cls.getMethod(
"load",
File.class);
1043 c = m.getDeclaringClass();
1045 m = cls.getMethod(
"paste", String.class);
1046 c = m.getDeclaringClass();
1048 Action paste =
new Action() {
1061 }
catch (Exception e) {
1062 e.printStackTrace();
1069 boolean found=
false;
1070 for(
int i=0;
i<itemClass.length;
i++){
1071 if(cls.getName().equals(itemClass[
i])){
1077 delete.setEnabled(
true);
1079 delete.setEnabled(
false);
1088 Method m = cls.getMethod(
"paste", String.class);
1089 Class<?>
c = m.getDeclaringClass();
1091 for (Action action : menu) {
1092 if (action.getText().equals(
"paste")) {
1098 }
catch (Exception e) {
1099 e.printStackTrace();
1117 Iterator<OrderedHashMap> it =
pluginMap_.values().iterator();
1118 for (; it.hasNext();) {
1119 Iterator it2 = (it.next()).values().iterator();
1120 for (; it2.hasNext();)
1126 orb_.shutdown(
false);
1226 Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
1227 Transferable
data = clp.getContents(
null);
1229 if (data !=
null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
1231 ret = (String) data.getTransferData(DataFlavor.stringFlavor);
1232 }
catch (Exception e) {
1261 List<GrxItemChangeListener> listenerList =
new ArrayList<GrxItemChangeListener>();
1263 while(it.hasNext()){
1265 Iterator<GrxItemChangeListener> itl = list.iterator();
1266 while(itl.hasNext()){
1268 if(!listenerList.contains(listener)){
1270 listenerList.add(listener);
1281 while(it.hasNext()){
1282 Class<? extends GrxBaseItem> cls = it.next();
1283 if(cls.isAssignableFrom(item.getClass())){
1285 Iterator<GrxItemChangeListener> itView = list.iterator();
1286 while(itView.hasNext())
1287 itView.next().registerItemChange(item, event);
1309 for(
int i=0;
i<mode.length;
i++){
1311 String[]
index=itemIndex[
i].split(
",",-1);
1312 for(
int j=0;
j<index.length;
j++){
1313 int k=Integer.valueOf(index[
j]);
1314 if(k<itemClass.length){
1316 Class<? extends GrxBasePlugin> plugin=
registerPlugin(itemClass[k]);
1317 if (plugin !=
null) {
1319 pi.visible = itemVisible[k].equals(
"true")?
true :
false;
1326 for(
int j=0;
j<userItemClass.length;
j++){
1327 if(!userItemClass[
j].equals(
"")){
1330 Class<? extends GrxBasePlugin> plugin=
registerPlugin(userItemClass[j]);
1331 if (plugin !=
null) {
1333 pi.visible = userItemVisible[j].equals(
"true")?
true :
false;
1341 store.addPropertyChangeListener(
this);
1353 if(version.equals(
"")){
1364 @SuppressWarnings(
"unchecked")
1366 if(event.getProperty().equals(
"userItemChange")){
1367 String newItemList = (String) event.getNewValue();
1369 String oldItemList = (String) event.getOldValue();
1376 Vector<Integer> delList =
new Vector<Integer>();
1377 for(
int i=0;
i<oldItems.length;
i++){
1379 for(String newItem : newItems){
1380 if(newItem.equals(oldItems[
i])){
1385 if(!flg && !oldItems[
i].equals(
""))
1386 delList.add(
new Integer(
i));
1391 for(Integer
i : delList){
1392 Class<? extends GrxBasePlugin> itemClass=
null;
1394 itemClass = (Class<? extends GrxBasePlugin>) Class.forName(oldItems[
i.intValue()],
false,
pluginLoader_);
1395 }
catch (ClassNotFoundException e) {
1399 removeItems((Class<? extends GrxBaseItem>) itemClass);
1400 Iterator<GrxModeInfoItem> it = modes.
values().iterator();
1401 while (it.hasNext()) {
1407 for(
int i=0;
i<newItems.length;
i++){
1409 Class<? extends GrxBasePlugin> itemClass=
null;
1411 itemClass = (Class<? extends GrxBasePlugin>) Class.forName(newItems[i],
false,
pluginLoader_);
1412 }
catch (ClassNotFoundException e) {
1415 Iterator<GrxModeInfoItem> it = modes.
values().iterator();
1416 while (it.hasNext()) {
1420 pi.visible = userItemVisible[
i].equals(
"true")?
true :
false;
1424 Class<? extends GrxBasePlugin> plugin=
registerPlugin(newItems[i]);
1425 if (plugin !=
null) {
1427 pi.visible = userItemVisible[
i].equals(
"true")?
true :
false;
1440 v.updateTableFont();
1447 v.updateEditerFont();
1453 @SuppressWarnings(
"unchecked")
1456 Class<? extends GrxBasePlugin> itemClass=
null;
1458 itemClass = (Class<? extends GrxBasePlugin>) Class.forName(className,
false,
pluginLoader_);
1459 }
catch (ClassNotFoundException e) {
1463 Iterator<GrxModeInfoItem> it = modes.
values().iterator();
1464 while (it.hasNext()) {
1469 if (plugin !=
null) {
1481 @SuppressWarnings(
"unchecked")
1486 Iterator<GrxModeInfoItem> it = modes.
values().iterator();
1487 while (it.hasNext()) {
1498 store.removePropertyChangeListener(
this);
1505 if(f.exists() && f.isFile())
static final int MODIFIED_OK
Map< Class<?extends GrxBasePlugin >, PluginInfo > pinfoMap_
Properties getViewProperties(String name)
static final String USERITEM
Class<?> loadClass(String cname)
static final String VISIBLE
static final String get(String key)
boolean acceptItemChange_
static Object getField(Class<?extends GrxBasePlugin > cls, String field, Object defaultValue)
get field
String getProjectName()
get project name
void showExceptionTrace(String m, Exception e)
synchronized void set(T val)
Vector< Action > getProjectMenu()
get project menu
boolean isPerspectiveVisible()
check if GrxUI perspective is visible or not
Class<?extends GrxBasePlugin > registerPlugin(String className)
ArrayList< GrxBaseItem > getActiveItemList()
void itemChange(GrxBaseItem item, int event)
boolean existClass(String cname)
String getCurrentModeName()
get current model name
void shutdown()
shutdown this manager
void removeAllItems()
remove all items which are instances of active classes in the current mode
boolean isItemVisible(Class<?extends GrxBasePlugin > cls)
check an item class is visible or not
void setName(String name)
set name
void clear(CorbaSequence &seq)
static void resourceToFile(Class<?extends GrxPluginManager > grxPluginManager, String srcName, File destFile)
void setProjectProperty(String key, String val)
set property associated to key
#define null
our own NULL pointer
static synchronized void shutDown()
GrxBaseItem getItem(Class<?extends GrxBaseItem > cls, String name)
void updateActiveViewList()
update list of views python script から呼ばれた場合、UIスレッド外からの呼び出しとなって、NGなのでsync...
GrxProjectItem getProject()
get current project
GrxBaseItem createItem(Class<?extends GrxBaseItem > cls, String name)
アイテムの作成. 指定したアイテムプラグインに、指定したアイテム名で新しいアイテムを作る。 ...
static final int MODIFIED_NG
png_infop png_charpp name
static final int SETNAME_ITEM
void clearItemSelection()
unselect all items
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
item corresponds to a robot model
HashMap< Class<?extends GrxBasePlugin >, OrderedHashMap > pluginMap_
static final int ADD_ITEM
GrxProjectItem currentProject_
static final String CURRENT_VERSION
void focusedItem(GrxBaseItem item)
set focused item
void setURL(String url)
set URL property
List< GrxBaseView > getViewList()
static SynchronizedAccessor< String > clipValue_
boolean isSelected()
check whether this is selected or not
boolean isEmptyClipBord()
void removeItems(Class<?extends GrxBaseItem > cls)
remove all items which are instances of specified class
static final String SEPARATOR
GrxBasePlugin createPlugin(Class cls, String name, GrxPluginManager manager)
GrxBaseItem getItem(String name)
static void printErr(String s)
static final int SELECTED_ITEM
static final String FONT_TABLE
std::string basename(const std::string name)
List< GrxBaseView > getActiveViewList()
Vector< Action > getItemMenu(final Class<?extends GrxBaseItem > cls)
static org.omg.CORBA.ORB getORB(String[] argv)
initialize and get ORB
boolean registerPluginInstance(GrxBasePlugin instance)
register instance of plugin to this manager
GrxModeInfoItem currentMode_
void removeItem(GrxBaseItem item)
remove item
static Shell getCurrentShell()
static Activator getDefault()
void setCurrentMode(GrxModeInfoItem mode)
static final String CLASSPATH
String getProjectProperty(String key)
get property of current project associated to key
static final int FOCUSED_ITEM
void addPlugin(String className, String classPath)
Object remove(Object key)
void setSelectedItem(GrxBaseItem item, boolean select)
select/unselect item
synchronized GrxBaseView getView(String name, boolean active)
def j(str, encoding="cp932")
void deletePlugin(Class<?extends GrxBasePlugin > cls)
boolean renamePlugin(GrxBasePlugin item, String newName)
rename plugin. If new name is already used, name is not changed.
void setDefaultDirectory(String dir)
static final int REMOVE_ITEM
static final int CHANGE_MODE
void addItemClassList(Class<?extends GrxBasePlugin > item)
information of plugin class
Map< Class<?extends GrxBaseItem >, List< GrxItemChangeListener > > itemChangeListener_
GrxBaseView getView(Class<?extends GrxBaseView > cls, boolean active)
static void println(String s)
static String expandEnvVal(String str)
List< GrxBaseView > viewList_
Object setProperty(String key, String value)
set property value associated with a keyword
GrxBaseItem focusedItem()
get current focused item
static final String ITEMINDEX
void load()
load a project
Class<?extends GrxBasePlugin > registerPlugin(Class<?extends GrxBasePlugin > cls)
List< GrxBaseView > activeViewList_
Map<?,?> getItemMap(Class<?extends GrxBaseItem > cls)
void loadInitialProject()
Object put(Object key, Object obj)
File getHomePath()
get home path
GrxBasePlugin createPlugin(Class<?extends GrxBasePlugin > cls, String name)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
final String toString()
convert to String. Currently, name is returned.
static void setClipBordVal()
Set clip board value GrxPluginManager.clipValue_.
void setProcessList(GrxServerManager serverManager)
static final String INITIALPROJECT
def getText(self, nodes=None)
static final String PROCESS
final String getName()
get name
static final String AUTOSTART
static String getClipBoardVal()
Get selected GrxBaseItem List on tree view.
void propertyChange(PropertyChangeEvent event)
static final String FONT_EDITER
GrxBaseItem pasteItem(Class<?extends GrxBaseItem > cls, GrxBaseItem item)
GrxModeInfoItem getMode()
get current mode
Properties getViewProperties(String viewName)
static final String USEORB
GrxBaseView createView(Class<?extends GrxBaseView > cls, String name)
static final int NOTSELECTED_ITEM
String getItemTitle(Class<?extends GrxBasePlugin > cls)
get title of item class
static final int NOTFOCUSED_ITEM
static final String CLASS
static BodyCustomizerHandle create(BodyHandle bodyHandle, const char *modelName)
GrxPluginLoader pluginLoader_
GrxPluginManager()
GrxPluginManagerのコンストラクタ. まず、プラグインローダ(GrxPluginLoader)のインスタンス::pluginLoad...
void dynamicChangeMenu(final Class<?extends GrxBaseItem > cls, Vector< Action > menu)
void removeItemChangeListener(GrxItemChangeListener view, Class<?extends GrxBaseItem > cls)
ArrayList< Class<?extends GrxBaseItem > > activeItemClassList_
GrxBaseItem loadItem(Class<?extends GrxBaseItem > cls, String name, String url)
static Boolean getBoolean(String[] path, String atr, boolean defaultValue)
void registerItemChangeListener(GrxItemChangeListener view, Class<?extends GrxBaseItem > cls)
static final String VERSION
void setFocused(boolean b)
set/unset focus on this plugin
Vector< Action > getMenu()