1 19 package org.openharmonise.him.metadata.range.swing.range.details; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.him.*; 29 import org.openharmonise.him.harmonise.*; 30 import org.openharmonise.him.metadata.range.swing.range.*; 31 import org.openharmonise.him.swing.resourcetree.formresourcetree.*; 32 import org.openharmonise.vfs.*; 33 import org.openharmonise.vfs.metadata.*; 34 import org.openharmonise.vfs.metadata.range.*; 35 import org.openharmonise.vfs.metadata.value.*; 36 import org.openharmonise.vfs.servers.*; 37 38 39 44 public class RelationshipDetails extends AbstractRangeDetails 45 implements LayoutManager, FormResourceTreeListener, ActionListener { 46 47 private FormResourceTree m_tree = null; 48 49 private int m_nHeight = 400; 50 51 private HashMap m_domainPathMapping = new HashMap(); 52 53 private RangeValue m_value = null; 54 private Range m_range = null; 55 56 private JLabel m_collectionsOnlyLabel = null; 57 private JCheckBox m_collectionsOnlyCheck = null; 58 59 private static List m_hiddenRootPaths = new ArrayList(); 60 61 static { 62 m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE); 63 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS); 64 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS); 65 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES); 66 } 67 68 72 public RelationshipDetails(PropertyInstance propInst) { 73 super(propInst, "Relationship details"); 74 this.setup(); 75 } 76 77 private void setup() { 78 79 this.setLayout(this); 80 81 82 83 this.m_collectionsOnlyLabel = new JLabel("Collections only"); 84 this.add(this.m_collectionsOnlyLabel); 85 this.m_collectionsOnlyCheck = new JCheckBox(); 86 this.m_collectionsOnlyCheck.addActionListener(this); 87 this.add(this.m_collectionsOnlyCheck); 88 89 List selectedPaths = new ArrayList(); 90 91 if(this.getPropertyInstance().getValues().size()>0) { 92 this.m_value = (RangeValue) this.getPropertyInstance().getValues().get(0); 93 94 this.m_range = this.m_value.getRange(); 95 if(this.m_range!=null) { 96 List aHREFs = null; 97 if(this.m_range instanceof CollectionRange) { 98 aHREFs = ((CollectionRange)this.m_range).getHREFs(); 99 this.m_collectionsOnlyCheck.setSelected(true); 100 } else { 101 aHREFs = ((ResourceRange)this.m_range).getHREFs(); 102 this.m_collectionsOnlyCheck.setSelected(false); 103 } 104 Iterator itor = aHREFs.iterator(); 105 Vector vRemovals = new Vector(); 106 while (itor.hasNext()) { 107 String sHREF = (String ) itor.next(); 108 AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 109 VirtualFile vFile = vfs.getVirtualFile(sHREF).getResource(); 110 if(vFile == null) { 111 vRemovals.add(sHREF); 113 } else { 114 selectedPaths.add(sHREF); 115 } 116 } 117 for(int i=0;i<vRemovals.size();i++){ 119 String href = (String )vRemovals.get(i); 120 aHREFs.remove(href); 121 RangeValue val = new RangeValue(); 122 if(this.m_range instanceof CollectionRange) { 123 CollectionRange range = new CollectionRange(); 124 range.setHREFs(aHREFs); 125 m_range = range; 126 val.setRange(range); 127 } else { 128 ResourceRange range = new ResourceRange(); 129 range.setHREFs(aHREFs); 130 m_range = range; 131 val.setRange(range); 132 } 133 this.getPropertyInstance().removeValueWithoutFiringVirtualFileEvent(m_value); 134 m_value = val; 135 this.getPropertyInstance().addValueWithoutFiringVirtualFileEvent(val); 136 } 137 } else { 138 this.m_range = new ResourceRange(); 139 this.m_collectionsOnlyCheck.setSelected(false); 140 } 141 } 142 143 m_tree = new FormResourceTree(false, selectedPaths); 144 m_tree.setShowLeafNodes(false); 145 m_tree.setBorder(BorderFactory.createEtchedBorder()); 146 m_tree.addFormResourceTreeListener(this); 147 this.add(m_tree); 148 149 String fontName = "Dialog"; 150 int fontSize = 11; 151 Font font = new Font(fontName, Font.PLAIN, fontSize); 152 153 Server server = ServerList.getInstance().getHarmoniseServer(); 154 AbstractVirtualFileSystem vfs = server.getVFS(); 155 VirtualFile vfFile = 156 vfs.getVirtualFile( 157 "/" + server.getVFS().getRootPathSegment() + "/").getResource(); 158 Iterator itor = vfFile.getChildren().iterator(); 159 while (itor.hasNext()) { 160 String sChildPath = (String ) itor.next(); 161 VirtualFile vfChild = vfs.getVirtualFile(sChildPath).getResource(); 162 if(vfChild.isDirectory() && !this.isPathHiddenRoot(vfChild.getFullPath())) { 163 this.m_tree.addCollection(vfChild); 164 } 165 } 166 } 167 168 private boolean isPathHiddenRoot(String sPath) { 169 boolean bHidden = false; 170 171 Iterator itor = RelationshipDetails.m_hiddenRootPaths.iterator(); 172 while (itor.hasNext()) { 173 String sRootPath = (String ) itor.next(); 174 if(sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) { 175 bHidden=true; 176 } 177 } 178 179 return bHidden; 180 } 181 182 185 public void removeLayoutComponent(Component arg0) { 186 } 187 188 191 public void layoutContainer(Container arg0) { 192 int nHeight = 0; 193 194 this.m_collectionsOnlyCheck.setSize(this.m_collectionsOnlyCheck.getPreferredSize()); 195 this.m_collectionsOnlyCheck.setLocation(0, 20); 196 197 nHeight = nHeight + 20; 198 199 this.m_collectionsOnlyLabel.setSize(120, this.m_collectionsOnlyLabel.getPreferredSize().height); 200 this.m_collectionsOnlyLabel.setLocation(30, 20); 201 202 this.m_tree.setSize(this.m_tree.getPreferredSize()); 203 this.m_tree.setLocation(0, nHeight + 20); 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 229 public void actionPerformed(ActionEvent ae) { 230 if(ae.getSource()==this.m_collectionsOnlyCheck) { 231 Range currentRange = (Range) this.m_range; 232 Range newRange = null; 233 if(this.m_collectionsOnlyCheck.isSelected()) { 234 ResourceRange tempCurrRange = (ResourceRange)currentRange; 235 CollectionRange tempRange = new CollectionRange(); 236 if(tempCurrRange.getHREFs()!=null) { 237 tempRange.setHREFs(tempCurrRange.getHREFs()); 238 } 239 this.m_range = (Range) tempRange; 240 this.m_value.setRange((org.openharmonise.vfs.metadata.Range) this.m_range); 241 this.fireRangeDetailsChanged(m_value); 242 } else { 243 CollectionRange tempCurrRange = (CollectionRange)currentRange; 244 ResourceRange tempRange = new ResourceRange(); 245 if(tempCurrRange.getHREFs()!=null) { 246 tempRange.setHREFs(tempCurrRange.getHREFs()); 247 } 248 this.m_range = (Range) tempRange; 249 this.m_value.setRange((org.openharmonise.vfs.metadata.Range) this.m_range); 250 this.fireRangeDetailsChanged(m_value); 251 } 252 } 253 } 254 255 258 public Dimension getPreferredSize() { 259 return new Dimension(this.m_tree.getPreferredSize().width, this.m_collectionsOnlyCheck.getPreferredSize().height + 20 + this.m_tree.getPreferredSize().height+20); 260 } 261 262 265 public void pathValuesChanged(List pathValues) { 266 if(this.m_range instanceof CollectionRange) { 267 ((CollectionRange)this.m_range).setHREFs( pathValues); 268 } else { 269 ((ResourceRange)this.m_range).setHREFs( pathValues); 270 } 271 RangeValue newValue = (RangeValue) this.getPropertyInstance().getNewValueInstance(); 272 newValue.setRange(this.m_range); 273 this.fireRangeDetailsChanged(newValue); 274 } 275 276 } 277 | Popular Tags |