001: package vicazh.hyperpool;
002:
003: import java.util.*;
004: import javax.swing.tree.*;
005:
006: /**
007: * The editor
008: *
009: * @author Victor Zhigunov
010: * @version 0.4.0
011: */
012: public class Editor extends AbstractEditor {
013:
014: private Reader reader;
015:
016: private List<Integer> list;
017:
018: /**
019: * @param reader
020: * reader
021: * @param list
022: * objects id list
023: */
024: public Editor(Reader reader, List<Integer> list) {
025: this .reader = reader;
026: this .list = list;
027: }
028:
029: private List<Integer> plist = new ArrayList<Integer>();
030:
031: void set(ComData data) throws Exception {
032: node = map.get(data.currentID);
033: plist.clear();
034: reader.getObject(data.b);
035: data.objectID = new int[plist.size()];
036: for (int i = 0; i < data.objectID.length; i++) {
037: data.objectID[i] = plist.get(i);
038: Start.logger.finest("objectID[" + i + "]="
039: + data.objectID[i]);
040: }
041: }
042:
043: void remove(int currentID) throws Exception {
044: node = map.get(currentID);
045: remove();
046: stop(node);
047: parent.remove(node);
048: }
049:
050: void changed(ComData data) {
051: ((LineMBean) ((DefaultMutableTreeNode) map.get(data.currentID))
052: .getUserObject()).setName(new String(data.b));
053: }
054:
055: protected void move(DefaultMutableTreeNode node1,
056: DefaultMutableTreeNode node2) {
057: node = node1;
058: remove();
059: Unit unit = (Unit) node1.getUserObject();
060: list.remove(Integer.valueOf(unit.getID()));
061: parent.remove(node);
062: node = node2;
063: super .put(unit);
064: list
065: .add(
066: list.indexOf(((Unit) node.getUserObject())
067: .getID()) + 1, unit.getID());
068: parent.insert(node1, i);
069: }
070:
071: public void put(Unit unit) {
072: DefaultMutableTreeNode n = new DefaultMutableTreeNode(unit);
073: if (node == null)
074: list.add(unit.getID());
075: else {
076: super .put(unit);
077: list
078: .add(list.indexOf(((Unit) node.getUserObject())
079: .getID()) + 1, unit.getID());
080: parent.insert(n, i);
081: }
082: node = n;
083: map.put(unit.getID(), n);
084: plist.add(unit.getID());
085: }
086:
087: private void stop(DefaultMutableTreeNode node) throws Exception {
088: for (int i = 0; i < node.getChildCount(); i++)
089: stop((DefaultMutableTreeNode) node.getChildAt(i));
090: Unit unit = (Unit) node.getUserObject();
091: if (unit instanceof Element)
092: ((Element) unit).stop();
093: map.remove(unit.getID());
094: list.remove(Integer.valueOf(unit.getID()));
095: }
096:
097: public void stop() throws Exception {
098: for (DefaultMutableTreeNode n : map.values()) {
099: Object o = n.getUserObject();
100: if (o instanceof Element)
101: ((Element) o).stop();
102: }
103: list.clear();
104: map.clear();
105: super.stop();
106: }
107: }
|