1 4 package org.oddjob.designer.model; 5 6 import java.util.Observable ; 7 import java.util.Observer ; 8 9 import org.oddjob.designer.Looks; 10 import org.oddjob.designer.arooa.DesignIH; 11 12 21 public class MultiTypeTable extends Observable 22 implements DesignDefinition { 23 24 private final String heading; 25 private final DesignElementType designElement; 26 private int visibleRows = Looks.LIST_ROWS; 27 private boolean named; 28 29 private final Observer observer = new Observer () { 30 public void update(Observable o, Object arg) { 31 setChanged(); 32 notifyObservers(); 33 } 34 }; 35 36 public MultiTypeTable(String heading, DesignElementType de) { 37 this.heading = heading; 38 this.designElement = de; 39 designElement.addObserver(observer); 40 for (int i = 0; i < de.childCount(); ++i) { 41 de.children()[i].addObserver(observer); 42 } 43 } 44 45 public String getTitle() { 46 return heading; 47 } 48 49 public DesignElementType getDesignElement() { 50 return designElement; 51 } 52 53 56 public void accept(DesignProcessor processor) { 57 processor.onMulipleTypeTable(this); 58 } 59 60 63 public boolean isNamed() { 64 return named; 65 } 66 67 70 public MultiTypeTable setNamed(boolean named) { 71 this.named = named; 72 return this; 73 } 74 75 78 public boolean isPopulated() { 79 DesignIH dih = DesignIH.getHelper(designElement.getClass()); 80 return dih.hasDetailData(designElement); 81 } 82 83 public int childCount() { 84 return designElement.childCount(); 85 } 86 87 public String getChildType(int index) { 88 return designElement.children(index).type(); 89 } 90 91 public void removeChild(int index) { 92 DesignElementType child = designElement.children()[index]; 93 child.deleteObserver(observer); 94 designElement.removeChild(index); 95 } 96 97 public void insertChild(int index, String type) { 98 DesignElementType nde = designElement.createType(type); 99 if (nde == null) { 100 throw new NullPointerException ("[" + designElement + "] couldn't create type [" 101 + type + "]"); 102 } 103 designElement.insertChild(index, nde); 104 nde.addObserver(observer); 105 } 106 107 public String getChildName(int index) { 108 return designElement.children()[index].getName().attribute(); 109 } 110 111 public void setChildName(int index, String name) { 112 designElement.children()[index].getName().attribute(name); 113 } 114 115 public DesignElement getChildValue(int index) { 116 return designElement.children()[index]; 117 } 118 119 public String [] getSupportedTypes() { 120 return designElement.supportedTypes(); 121 } 122 125 public int getVisibleRows() { 126 return visibleRows; 127 } 128 131 public MultiTypeTable setVisibleRows(int visibleRows) { 132 this.visibleRows = visibleRows; 133 return this; 134 } 135 } 136 | Popular Tags |