1 19 package org.openharmonise.him.metadata.range.swing.relatedevents; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import org.openharmonise.him.editors.report.swing.*; 27 import org.openharmonise.vfs.*; 28 import org.openharmonise.vfs.metadata.*; 29 import org.openharmonise.vfs.metadata.range.*; 30 import org.openharmonise.vfs.metadata.value.*; 31 32 33 39 public class RelatedEventRelationship extends JComboTree { 40 41 private static final String COMMAND_RECOMBO = "RECOMBO"; 42 private static final String INVALID_TEXT = "--Invalid--"; 43 private PropertyInstance m_propInst = null; 44 45 private int m_nMinOccurs = -1; 46 private int m_nMaxOccurs = -1; 47 48 51 public RelatedEventRelationship(PropertyInstance propInst) { 52 super(); 53 m_propInst = propInst; 54 setup(propInst); 55 } 56 57 60 protected void setup(PropertyInstance propInst) { 61 62 Property prop = m_propInst.getDefinition(); 63 64 List hrefs = ((ValueRange) prop.getRange()).getHREFs(); 65 66 addCollectionPaths(hrefs); 67 68 List vals = propInst.getValues(); 69 70 if(vals.size() > 0) { 71 AbstractVirtualFileSystem vfs = propInst.getVirtualFile().getVFS(); 72 73 List paths = new ArrayList(); 74 75 Iterator iter = vals.iterator(); 76 77 while (iter.hasNext()) { 78 ValueValue val = (ValueValue) iter.next(); 79 paths.add(val.getValue()); 80 } 81 82 this.setPaths(vfs, paths); 83 } 84 85 setActionCommand(COMMAND_RECOMBO); 86 addActionListener(this); 87 } 88 89 92 public void actionPerformed(ActionEvent ae) { 93 94 if(ae.getActionCommand().equals(COMMAND_RECOMBO)) { 95 List paths = getPaths(); 96 setValues(paths); 97 } else { 98 super.actionPerformed(ae); 99 } 100 } 101 102 105 private void setValues(List paths) { 106 this.m_propInst.clearAllValues(); 107 Iterator iter = paths.iterator(); 108 109 while (iter.hasNext()) { 110 String sPath = (String ) iter.next(); 111 if(sPath != null && sPath.length() > 0) { 112 ValueValue val = (ValueValue)m_propInst.getNewValueInstance(); 113 val.setValue(sPath); 114 m_propInst.addValue(val); 115 } 116 } 117 118 firePropertyChange(RelatedEventValueDisplay.PROPERTY_METADATA_CHANGE, null, null); 119 } 120 121 124 private void setValue(String sHREF) { 125 List vals = m_propInst.getValues(); 126 ValueValue val = null; 127 if(vals.size()>0) { 128 val = (ValueValue) vals.get(0); 129 } else { 130 val = (ValueValue)m_propInst.getNewValueInstance(); 131 m_propInst.setValue(val); 132 } 133 134 val.setValue(sHREF); 135 136 } 137 138 141 public boolean isMetadataValid() { 142 boolean bIsValid = true; 143 144 Property prop = m_propInst.getDefinition(); 145 146 ValueRange range = (ValueRange)prop.getRange(); 147 148 List vals = m_propInst.getValues(); 149 150 bIsValid = range.validate(vals).isValid(); 151 152 if(bIsValid == true && m_nMinOccurs > 0) { 153 bIsValid = (vals.size() >= m_nMinOccurs); 154 if(vals.size() == 0) { 155 getLabel().setText(INVALID_TEXT); 156 } 157 } 158 159 if(bIsValid == true && m_nMaxOccurs > 0) { 160 bIsValid = vals.size() <= m_nMaxOccurs; 161 } 162 163 if(bIsValid == false) { 164 getLabel().setForeground(Color.RED); 165 } else { 166 getLabel().setForeground(Color.BLACK); 167 } 168 169 this.revalidate(); 170 171 return bIsValid; 172 } 173 174 public void setMinOccurs(int nMin) { 175 m_nMinOccurs = nMin; 176 } 177 178 public void setMaxOccurs(int nMax) { 179 m_nMaxOccurs = nMax; 180 } 181 182 185 public void clear() { 186 super.clear(); 187 if(m_nMinOccurs > 0) { 188 setInvalid(); 189 } 190 191 } 192 193 void setInvalid() { 194 getLabel().setForeground(Color.RED); 195 getLabel().setText(INVALID_TEXT); 196 revalidate(); 197 } 198 199 } 200 | Popular Tags |