1 19 package org.openharmonise.him.metadata.swing; 20 21 import java.awt.*; 22 import java.util.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.metadata.range.swing.resourcehandling.*; 27 import org.openharmonise.vfs.*; 28 import org.openharmonise.vfs.metadata.*; 29 30 31 35 public class MetadataTabPanel extends JPanel implements LayoutManager { 36 37 private ResourceRangeDisplay m_relationships = null; 38 39 private VirtualFile m_vfPropGroup = null; 40 41 private HashMap m_pathOrderMapping = new HashMap(); 42 43 private SortedSet m_propPanels = new TreeSet(); 44 45 private int m_nNextOrderVal = 1; 46 47 50 public MetadataTabPanel() { 51 super(); 52 this.setup(); 53 } 54 55 58 public MetadataTabPanel(VirtualFile vfPropGroup) { 59 super(); 60 this.m_vfPropGroup = vfPropGroup; 61 this.setup(); 62 } 63 64 private void setup() { 65 this.setLayout(this); 66 67 this.m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/title", new Integer (1)); 68 this.m_pathOrderMapping.put("/webdav/SYSTEM_PROPS/description", new Integer (2)); 69 int nCount = 3; 70 71 if(this.m_vfPropGroup!=null) { 72 Iterator itor = this.m_vfPropGroup.getChildren().iterator(); 73 while (itor.hasNext()) { 74 String sPath = (String ) itor.next(); 75 this.m_pathOrderMapping.put(sPath, new Integer (nCount)); 76 nCount++; 77 } 78 } 79 this.m_nNextOrderVal = nCount; 80 } 81 82 public void addPropertyPanel(PropertyPanel propPanel) { 83 Property prop = propPanel.getProperty(); 84 if(prop!=null && this.m_pathOrderMapping.get(prop.getHREF())!=null) { 85 int nOrder = ((Integer )this.m_pathOrderMapping.get(prop.getHREF())).intValue(); 86 OrderedProp orderedProp = new OrderedProp(nOrder, propPanel); 87 this.m_propPanels.add(orderedProp); 88 } else { 89 OrderedProp orderedProp = new OrderedProp(this.m_nNextOrderVal, propPanel); 90 this.m_nNextOrderVal++; 91 this.m_propPanels.add(orderedProp); 92 } 93 this.add(propPanel); 94 } 95 96 protected void clearToDestroy() { 97 this.m_relationships = null; 98 this.removeAll(); 99 } 100 101 104 private MetadataTabPanel(boolean arg0) { 105 super(arg0); 106 } 107 108 111 private MetadataTabPanel(LayoutManager arg0) { 112 super(arg0); 113 } 114 115 119 private MetadataTabPanel(LayoutManager arg0, boolean arg1) { 120 super(arg0, arg1); 121 } 122 123 126 public ResourceRangeDisplay getRelationships() { 127 return m_relationships; 128 } 129 130 public boolean hasRelationships() { 131 return (this.m_relationships!=null); 132 } 133 134 137 public void layoutContainer(Container arg0) { 138 int nHeight = 0; 139 Iterator itor = this.m_propPanels.iterator(); 140 while (itor.hasNext()) { 141 OrderedProp orderedProp = (OrderedProp) itor.next(); 142 PropertyPanel propPanel = orderedProp.getPropPanel(); 143 144 145 propPanel.setSize(propPanel.getPreferredSize()); 146 propPanel.setLocation(0, nHeight); 147 nHeight = nHeight + propPanel.getSize().height; 148 } 149 } 150 151 154 public void setRelationships(ResourceRangeDisplay display) { 155 if( this.m_relationships==null ) { 156 m_relationships = display; 157 PropertyPanel propPanel = new PropertyPanel("Relationships", false); 158 propPanel.add(m_relationships); 159 OrderedProp orderedProp = new OrderedProp(this.m_nNextOrderVal, propPanel); 160 this.m_nNextOrderVal++; 161 this.m_propPanels.add(orderedProp); 162 this.add(propPanel); 163 } 164 } 165 166 public void addRelationship(ResourceRangeDisplay display) { 167 this.m_relationships.addRelationship(display); 168 } 169 170 171 172 175 public void setEnabled(boolean bEnabled) { 176 for (int i = 0; i < this.getComponentCount(); i++) { 177 Component comp = this.getComponent(i); 178 comp.setEnabled(bEnabled); 179 } 180 super.setEnabled(bEnabled); 181 } 182 183 public void checkValid() { 184 boolean bValid = true; 185 for (int i = 0; i < this.getComponentCount() && bValid == true; i++) { 186 Component comp = this.getComponent(i); 187 if(comp instanceof PropertyPanel) { 188 if(!((PropertyPanel)comp).getRangeDisplay().isMetadataValid()) { 189 bValid=false; 190 } 191 } 192 } 193 194 MetadataTabs tabs = this.getTabs(); 195 tabs.setValid(bValid, this); 196 } 197 198 private MetadataTabs getTabs() { 199 Component comp = this; 200 while(comp!=null && !(comp instanceof MetadataTabs)) { 201 comp = comp.getParent(); 202 } 203 204 if(comp!=null && comp instanceof MetadataTabs) { 205 return (MetadataTabs) comp; 206 } else { 207 return null; 208 } 209 } 210 211 214 public void removeLayoutComponent(Component arg0) { 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 nHeight = 0; 242 int nCount = this.getComponentCount(); 243 int nWidth = 0; 244 for(int i=0; i<nCount; i++) { 245 Component comp = this.getComponent(i); 246 int nDepth = comp.getLocation().y + comp.getPreferredSize().height; 247 int nCurrWidth = comp.getLocation().x + comp.getPreferredSize().width; 248 if(nDepth > nHeight) { 249 nHeight = nDepth; 250 } 251 if(nCurrWidth > nWidth) { 252 nWidth = nCurrWidth; 253 } 254 } 255 256 return new Dimension( nWidth, nHeight+5); 257 } 258 259 } 260 | Popular Tags |