1 19 package org.openharmonise.him.metadata.range.swing.propertyhandling; 20 21 import java.awt.*; 22 import java.util.*; 23 import java.util.List ; 24 25 import javax.swing.*; 26 27 import org.openharmonise.him.*; 28 import org.openharmonise.him.metadata.range.swing.*; 29 import org.openharmonise.him.metadata.swing.*; 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.metadata.*; 32 import org.openharmonise.vfs.metadata.range.*; 33 import org.openharmonise.vfs.metadata.value.*; 34 import org.openharmonise.vfs.servers.ServerList; 35 36 37 41 public class PropertyValuePanel 42 extends AbstractRangeDisplay 43 implements RangeDisplay, LayoutManager { 44 45 ArrayList m_propDiaplays = new ArrayList(3); 46 protected int m_nHeight = 300; 47 48 private HashMap m_pathOrderMapping = new HashMap(); 49 50 private SortedSet m_propPanels = new TreeSet(); 51 52 private int m_nNextOrderVal = 1; 53 54 private PropertyValue m_propValue = null; 55 56 private PropertyRangeDisplay m_display = null; 57 58 61 public PropertyValuePanel(PropertyRangeDisplay display, PropertyInstance propInstance, PropertyValue propValue) { 62 super(propInstance); 63 this.m_display = display; 64 this.m_propValue = propValue; 65 this.setup(); 66 } 67 68 public PropertyValue getValue() { 69 return this.m_propValue; 70 } 71 72 private void setup() { 73 this.setLayout(this); 74 75 PropertyRange propRange = (PropertyRange) this.getPropertyInstance().getDefinition().getRange(); 76 List aHREFs = propRange.getHREFs(); 77 AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 78 79 Iterator itor = aHREFs.iterator(); 80 while (itor.hasNext()) { 81 String sGroupPath = (String ) itor.next(); 82 VirtualFile vfPropGroup = vfs.getVirtualFile(sGroupPath).getResource(); 83 if(vfPropGroup!=null) { 84 int nCount = 1; 85 Iterator itor2 = vfPropGroup.getChildren().iterator(); 86 while (itor2.hasNext()) { 87 String sPath = (String ) itor2.next(); 88 this.m_pathOrderMapping.put(sPath, new Integer (nCount)); 89 nCount++; 90 } 91 this.m_nNextOrderVal = nCount; 92 } 93 } 94 } 95 96 99 public JPanel getPanel() { 100 PropertyRange range = (PropertyRange)this.getPropertyInstance().getDefinition().getRange(); 101 102 List props = range.getProperties(); 103 List propInstances = this.m_propValue.getValue(); 104 Iterator itor = props.iterator(); 105 106 ArrayList aFillingPropInstances = new ArrayList(); 107 aFillingPropInstances.addAll(propInstances); 108 109 while(itor.hasNext()) { 110 Property prop = (Property)itor.next(); 111 Iterator itor2 = propInstances.iterator(); 112 113 PropertyInstance propInst = null; 114 while(itor2.hasNext()) { 115 PropertyInstance propInstTemp = (PropertyInstance)itor2.next(); 116 if(prop.getName().equals(propInstTemp.getName()) && prop.getNamespace().equals(propInstTemp.getNamespaceURI())) { 117 propInst = propInstTemp; 118 } 119 } 120 121 if(propInst==null) { 122 propInst = new PropertyInstance(prop.getNamespace(), prop.getName()); 123 propInst.setDefinitionPath(prop.getHREF(), prop.getVersion()); 124 aFillingPropInstances.add(propInst); 125 126 propInst.setVirtualFile(this.getPropertyInstance().getVirtualFile()); 127 128 } 129 130 RangeDisplay display = RangeDisplayFactory.getRangeDisplay(propInst); 131 132 if(display instanceof PropertyRangeDisplay) { 133 PropertyPanel groupPanel = new PropertyPanel(propInst, true); 134 groupPanel.add(display.getPanel()); 135 PropNamePanel propPanel = new PropNamePanel(prop.getDisplayName(), groupPanel, true); 136 this.m_propDiaplays.add(propPanel); 137 138 if(prop!=null && this.m_pathOrderMapping.get(prop.getHREF())!=null) { 139 int nOrder = ((Integer )this.m_pathOrderMapping.get(prop.getHREF())).intValue(); 140 OrderedNamedProp orderedProp = new OrderedNamedProp(nOrder, propPanel); 141 this.m_propPanels.add(orderedProp); 142 } else { 143 OrderedNamedProp orderedProp = new OrderedNamedProp(this.m_nNextOrderVal, propPanel); 144 this.m_nNextOrderVal++; 145 this.m_propPanels.add(orderedProp); 146 } 147 } else { 148 PropNamePanel propPanel = new PropNamePanel(prop.getDisplayName(), display.getPanel(), false); 149 this.m_propDiaplays.add(propPanel); 150 151 if(prop!=null && this.m_pathOrderMapping.get(prop.getHREF())!=null) { 152 int nOrder = ((Integer )this.m_pathOrderMapping.get(prop.getHREF())).intValue(); 153 OrderedNamedProp orderedProp = new OrderedNamedProp(nOrder, propPanel); 154 this.m_propPanels.add(orderedProp); 155 } else { 156 OrderedNamedProp orderedProp = new OrderedNamedProp(this.m_nNextOrderVal, propPanel); 157 this.m_nNextOrderVal++; 158 this.m_propPanels.add(orderedProp); 159 } 160 } 161 } 162 163 if(aFillingPropInstances.size()>propInstances.size()) { 164 this.m_propValue.setValue(aFillingPropInstances); 165 } 166 167 itor = this.m_propDiaplays.iterator(); 168 while(itor.hasNext()) { 169 PropNamePanel display = (PropNamePanel)itor.next(); 170 this.add(display.getPanel()); 171 if(!display.isComplex()) { 172 this.add(display.getLabel()); 173 } 174 } 175 176 return this; 177 } 178 179 182 public void removeLayoutComponent(Component arg0) { 183 } 184 185 188 public void layoutContainer(Container arg0) { 189 this.setSize(this.getPreferredSize()); 190 191 int nHeight = 10; 192 193 Iterator itor = this.m_propPanels.iterator(); 194 while(itor.hasNext()) { 195 OrderedNamedProp propPanel = (OrderedNamedProp)itor.next();; 196 JPanel panel = propPanel.getPropPanel().getPanel(); 197 198 if(!propPanel.getPropPanel().isComplex()) { 199 JLabel label = propPanel.getPropPanel().getLabel(); 200 label.setSize(this.getWidth()-30,20); 201 label.setLocation(10, nHeight); 202 } 203 204 nHeight = nHeight + 20; 205 206 panel.setSize(panel.getPreferredSize()); 207 panel.setLocation(10, nHeight); 208 nHeight = nHeight + panel.getSize().height; 209 panel.repaint(); 210 } 211 212 this.m_nHeight = nHeight; 213 214 this.repaint(); 215 } 216 217 220 public void addLayoutComponent(String arg0, Component arg1) { 221 } 222 223 226 public Dimension minimumLayoutSize(Container arg0) { 227 return this.getPreferredSize(); 228 } 229 230 233 public Dimension preferredLayoutSize(Container arg0) { 234 return this.getPreferredSize(); 235 } 236 237 240 public Dimension getPreferredSize() { 241 int nWidth = this.getParent().getWidth()-50; 242 return new Dimension(nWidth, this.m_nHeight); 243 } 244 245 248 public boolean isMetadataValid() { 249 boolean bValid = true; 250 for (int i = 0; i < this.getComponentCount(); i++) { 251 Component comp = this.getComponent(i); 252 if(comp instanceof AbstractRangeDisplay) { 253 if(!((AbstractRangeDisplay)comp).isMetadataValid()) { 254 bValid=false; 255 } 256 } 257 } 258 return bValid; 259 } 260 261 } 262 | Popular Tags |