1 package org.sapia.regis.gui.model; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashSet ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import java.util.Set ; 9 10 import org.sapia.gumby.RenderContext; 11 import org.sapia.regis.Node; 12 import org.sapia.regis.Property; 13 import org.sapia.regis.gui.GlobalContext; 14 import org.sapia.regis.gui.GuiConsts; 15 import org.sapia.regis.gui.command.NodeUpdateCommand; 16 import org.sapia.regis.gui.widgets.NodePanel; 17 18 public class NodeModel implements GuiConsts{ 19 20 protected Node node; 21 22 protected List _props = new ArrayList (); 23 24 public NodeModel(Node node){ 25 this.node = node; 26 } 27 28 public Node getNode(){ 29 return this.node; 30 } 31 32 public synchronized void setNode(Node node){ 33 _props.clear(); 34 this.node = node; 35 } 36 37 public synchronized void addProperty(Property prop){ 38 _props.add(prop); 39 } 40 41 public synchronized List getProperties(){ 42 Collection keyColl = node.getPropertyKeys(); 43 Iterator keys = keyColl.iterator(); 44 List properties = new ArrayList (keyColl.size()); 45 Set addedKeys = new HashSet (); 46 while(keys.hasNext()){ 47 Property prop = node.getProperty((String )keys.next()); 48 if(!addedKeys.contains(prop.getKey())){ 49 properties.add(prop); 50 addedKeys.add(prop.getKey()); 51 } 52 53 } 54 for(int i = 0; i < _props.size(); i++){ 55 Property prop = (Property)_props.get(i); 56 if(!addedKeys.contains(prop.getKey())){ 57 properties.add(prop); 58 addedKeys.add(prop.getKey()); 59 } 60 } 61 return properties; 62 } 63 64 public synchronized void update() throws Exception { 65 NodePanel panel = (NodePanel)GlobalContext.getInstance() 66 .getRenderContext().getEnv().get(NODE_PANE); 67 RenderContext child = GlobalContext.getInstance().getRenderContext().newChildInstance(); 68 List properties = panel.getProperties(); 69 properties.addAll(_props); 70 child.getEnv().put("properties", properties, "local"); 71 NodeUpdateCommand command = new NodeUpdateCommand(this); 72 command.execute(child); 73 _props.clear(); 74 } 75 76 public String toString(){ 77 if(node.isRoot()){ 78 return "ROOT"; 79 } 80 return node.getName(); 81 } 82 83 } 84 | Popular Tags |