1 26 27 package org.objectweb.openccm.explorer.CORBA; 28 29 import org.objectweb.util.explorer.api.MenuItem; 30 import org.objectweb.util.explorer.api.MenuItemTreeView; 31 import org.objectweb.util.explorer.api.TreeView; 32 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 33 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 34 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 35 import org.objectweb.util.explorer.swing.gui.lib.LabelBox; 36 37 44 public class ChangeAttributeValue 45 implements MenuItem, DialogAction 46 { 47 48 54 55 protected org.omg.CORBA.Object object_ = null; 56 57 58 protected String name_ = null; 59 60 61 protected LabelBox attributeLabel_ = null; 62 63 69 75 82 public Object fromString(String value, Class type){ 83 String typeName = type.getName(); 84 if(type.equals(Integer.TYPE)) 85 return new Integer (value); 86 else if(type.equals(Character.TYPE)) 87 return new Character (value.charAt(0)); 88 else if(type.equals(Double.TYPE)) 89 return new Double (value); 90 else if(type.equals(Boolean.TYPE)) 91 return new Boolean (value); 92 else if(type.equals(Short.TYPE)) 93 return new Short (value); 94 else if(type.equals(Long.TYPE)) 95 return new Long (value); 96 else if(type.equals(Float.TYPE)) 97 return new Float (value); 98 return value; 99 } 100 101 107 110 public int getStatus(TreeView treeView) { 111 ViewAttributeWrapper viewAttr = (ViewAttributeWrapper)treeView.getSelectedObject(); 112 org.omg.CORBA.Object o = viewAttr.getObject(); 113 String attrName = viewAttr.getName(); 114 try{ 115 Class c = o.getClass(); 116 c.getMethod(attrName,new Class []{c.getMethod(attrName,null).getReturnType()}); 117 return MenuItem.ENABLED_STATUS; 118 } catch(NoSuchMethodException e) { 119 return MenuItem.DISABLED_STATUS; 120 } 121 } 122 123 126 public void actionPerformed(MenuItemTreeView treeView) throws Exception { 127 ViewAttributeWrapper viewAttr = (ViewAttributeWrapper)treeView.getSelectedObject(); 128 object_ = viewAttr.getObject(); 129 name_ = viewAttr.getName(); 130 DialogBox dialog = new DefaultDialogBox("Change the value of this attribute"); 131 Class c = object_.getClass(); 132 attributeLabel_ = new LabelBox(name_,c.getMethod(name_,null).invoke(object_,null).toString()); 133 dialog.addElementBox(attributeLabel_); 134 dialog.setValidateAction(this); 135 dialog.show(); 136 } 137 138 144 147 public void executeAction() throws Exception { 148 String value = attributeLabel_.getLabel(); 149 Class c = object_.getClass(); 150 Class type = c.getMethod(name_,null).getReturnType(); 151 java.lang.reflect.Method method = c.getMethod(name_,new Class []{type}); 152 method.invoke(object_,new Object []{fromString(value,type)}); 153 } 154 155 } 156 | Popular Tags |