KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > gui > model > NodeModel


1 package org.sapia.regis.gui.model;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashSet JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.Set JavaDoc;
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 JavaDoc _props = new ArrayList JavaDoc();
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 JavaDoc getProperties(){
42     Collection JavaDoc keyColl = node.getPropertyKeys();
43     Iterator JavaDoc keys = keyColl.iterator();
44     List JavaDoc properties = new ArrayList JavaDoc(keyColl.size());
45     Set JavaDoc addedKeys = new HashSet JavaDoc();
46     while(keys.hasNext()){
47       Property prop = node.getProperty((String JavaDoc)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 JavaDoc{
65     NodePanel panel = (NodePanel)GlobalContext.getInstance()
66       .getRenderContext().getEnv().get(NODE_PANE);
67     RenderContext child = GlobalContext.getInstance().getRenderContext().newChildInstance();
68     List JavaDoc 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 JavaDoc toString(){
77     if(node.isRoot()){
78       return "ROOT";
79     }
80     return node.getName();
81   }
82   
83 }
84
Popular Tags