1 19 package org.openharmonise.him.metadata.range.swing.valuehandling; 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.metadata.range.swing.*; 28 import org.openharmonise.him.swing.resourcetree.*; 29 import org.openharmonise.him.swing.resourcetree.formresourcetree.*; 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.gui.*; 32 import org.openharmonise.vfs.metadata.*; 33 import org.openharmonise.vfs.metadata.range.*; 34 import org.openharmonise.vfs.metadata.value.*; 35 36 37 41 public class ValueRangeDisplay 42 extends AbstractRangeDisplay 43 implements RangeDisplay, LayoutManager, FormResourceTreeListener { 44 45 private int m_nHeight = 30; 46 47 private WarningsLabel m_warnings = null; 48 49 protected JLabel m_errorLabel = null; 50 51 private int m_nMinOccurs = 0; 52 private int m_nMaxOccurs = 1000; 53 54 private FormResourceTree m_resourceTree = null; 55 56 59 public ValueRangeDisplay(PropertyInstance propInstance) { 60 super(propInstance); 61 } 62 63 66 public JPanel getPanel() { 67 this.setLayout(this); 68 69 ValueRange range = 70 (ValueRange) this 71 .getPropertyInstance() 72 .getDefinition() 73 .getRange(); 74 List domains = this.getPropertyInstance().getDefinition().getDomains(); 75 Iterator itor = domains.iterator(); 76 77 while (itor.hasNext()) { 78 Domain domain = (Domain) itor.next(); 79 boolean bApplicableDomain = false; 80 String sFilePath = ((VersionedVirtualFile)this.getPropertyInstance().getVirtualFile()).getLogicalPath(); 81 Iterator itor2 = domain.getPaths().iterator(); 82 while (itor2.hasNext()) { 83 String sDomainPath = (String ) itor2.next(); 84 if(sFilePath.startsWith(sDomainPath)) { 85 bApplicableDomain=true; 86 } 87 } 88 89 if(bApplicableDomain) { 90 if (this.m_nMinOccurs < domain.getMinOccurs()) { 91 this.m_nMinOccurs = domain.getMinOccurs(); 92 } 93 if (this.m_nMaxOccurs > domain.getMaxOccurs()) { 94 this.m_nMaxOccurs = domain.getMaxOccurs(); 95 } 96 } 97 98 } 99 100 this.m_errorLabel = new JLabel(); 101 this.m_errorLabel.setIcon( 102 IconManager.getInstance().getIcon("16-message-confirm.gif")); 103 this.add(this.m_errorLabel); 104 105 String sWarning = ""; 106 107 if (this.m_nMinOccurs==1 && this.m_nMaxOccurs==1) { 108 sWarning = 109 "Please select {1} option."; 110 } else if (this.m_nMinOccurs>0 && this.m_nMaxOccurs>this.m_nMinOccurs) { 111 sWarning = 112 "Please select between {" 113 + this.m_nMinOccurs 114 + "} and {" 115 + this.m_nMaxOccurs 116 + "} options."; 117 } else if (this.m_nMinOccurs>0 && this.m_nMinOccurs==this.m_nMinOccurs) { 118 sWarning = 119 "Please select {" 120 + this.m_nMinOccurs 121 + "} options."; 122 } else if (this.m_nMinOccurs>0) { 123 sWarning = 124 "Please select more than {" 125 + this.m_nMinOccurs 126 + "} options."; 127 } else { 128 sWarning = "Please select from the options."; 129 } 130 131 m_warnings = new WarningsLabel(sWarning); 132 this.add(m_warnings); 133 134 PropertyInstance propInst = this.getPropertyInstance(); 135 List vals = propInst.getValues(); 136 137 List pathValues = new ArrayList(); 138 Iterator valItor = vals.iterator(); 139 while (valItor.hasNext()) { 140 ValueValue valVal = (ValueValue) valItor.next(); 141 pathValues.add(valVal.getValue()); 142 } 143 144 List valGroups = range.getValueGroups(); 145 146 this.m_resourceTree = new FormResourceTree(false, pathValues); 147 this.m_resourceTree.setIsMultiSelect(!(this.m_nMaxOccurs==1)); 148 this.m_resourceTree.addFormResourceTreeListener(this); 149 this.m_resourceTree.setResourceFilter(createResourceTreeFilter()); 150 151 itor = valGroups.iterator(); 152 while(itor.hasNext()) { 153 ValueGroup group = (ValueGroup)itor.next(); 154 if(group!=null) { 155 String sHREF = group.getHREF(); 156 if(sHREF!=null) { 157 VirtualFile groupToAdd = this.getPropertyInstance().getVirtualFile().getVFS().getVirtualFile(group.getHREF()).getResource(); 158 if(groupToAdd!=null) { 159 this.m_resourceTree.addCollection(groupToAdd); 160 } 161 } 162 } 163 } 164 165 this.add(this.m_resourceTree); 166 167 168 this.m_nHeight = this.m_nHeight + this.m_resourceTree.getPreferredSize().height; 169 170 this.m_resourceTree.setVisible(true); 171 172 this.checkWarnings(); 173 174 return this; 175 } 176 177 180 public Dimension getPreferredSize() { 181 int nWidth = this.getParent().getWidth() - 40; 182 int nHeight = 170; 183 if(!this.m_resourceTree.isUsingScrollPane()) { 184 nHeight = this.m_resourceTree.getPreferredSize().height; 185 } 186 return new Dimension(nWidth, nHeight); 187 } 188 189 192 public void removeLayoutComponent(Component arg0) { 193 } 194 195 198 public void layoutContainer(Container arg0) { 199 m_resourceTree.setSize(this.getPreferredSize().width-40,this.getPreferredSize().height); 200 m_resourceTree.setLocation(20,0); 201 202 this.m_errorLabel.setSize(15,15); 203 this.m_errorLabel.setLocation(0, 0); 204 } 205 206 209 public void addLayoutComponent(String arg0, Component arg1) { 210 } 211 212 215 public Dimension minimumLayoutSize(Container arg0) { 216 return this.getPreferredSize(); 217 } 218 219 222 public Dimension preferredLayoutSize(Container arg0) { 223 return this.getPreferredSize(); 224 } 225 226 227 228 public void checkWarnings() { 229 this.m_warnings.setHighlight(String.valueOf(this.m_nMinOccurs), false); 230 this.m_warnings.setHighlight(String.valueOf(this.m_nMaxOccurs), false); 231 this.m_errorLabel.setIcon(IconManager.getInstance().getIcon("16-message-confirm.gif")); 232 233 List vals = this.getPropertyInstance().getValues(); 234 if(vals.size()<this.m_nMinOccurs) { 235 this.m_warnings.setHighlight(String.valueOf(this.m_nMinOccurs), true); 236 this.m_errorLabel.setIcon(IconManager.getInstance().getIcon("16-message-error.gif")); 237 } 238 if(this.m_nMaxOccurs!=-1 && vals.size()>this.m_nMaxOccurs) { 239 this.m_warnings.setHighlight(String.valueOf(this.m_nMaxOccurs), true); 240 this.m_errorLabel.setIcon(IconManager.getInstance().getIcon("16-message-error.gif")); 241 } 242 super.validateTab(); 243 } 244 247 public void setEnabled(boolean bEnabled) { 248 super.setEnabled(bEnabled); 249 } 250 251 254 public boolean isMetadataValid() { 255 return !this.m_errorLabel.getIcon().toString().equals(IconManager.getInstance().getIcon("16-message-error.gif").toString()); 256 } 257 258 261 public void pathValuesChanged(List pathValues) { 262 this.getPropertyInstance().clearAllValues(); 263 264 Iterator itor = pathValues.iterator(); 265 while (itor.hasNext()) { 266 String sFullPath = (String ) itor.next(); 267 ValueValue value = (ValueValue) this.getPropertyInstance().getNewValueInstance(); 268 value.setValue(sFullPath); 269 this.getPropertyInstance().addValue(value); 270 } 271 this.checkWarnings(); 272 } 273 274 protected AbstractResourceFilter createResourceTreeFilter() { 275 return new BasicResourceFilter(); 276 } 277 278 } 279 | Popular Tags |