1 19 package org.openharmonise.him.metadata.range.swing.range.details; 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.range.*; 29 import org.openharmonise.him.swing.resourcetree.formresourcetree.*; 30 import org.openharmonise.him.window.messages.*; 31 import org.openharmonise.vfs.*; 32 import org.openharmonise.vfs.metadata.*; 33 import org.openharmonise.vfs.metadata.range.*; 34 import org.openharmonise.vfs.metadata.value.*; 35 import org.openharmonise.vfs.servers.*; 36 37 38 43 public class CompoundDetails extends AbstractRangeDetails 44 implements LayoutManager, FormResourceTreeListener { 45 46 private FormResourceTree m_tree = null; 47 48 private int m_nHeight = 400; 49 50 private HashMap m_domainPathMapping = new HashMap(); 51 52 private RangeValue m_value = null; 53 private PropertyRange m_range = null; 54 55 59 public CompoundDetails(PropertyInstance propInst) { 60 super(propInst, "Compound Property details"); 61 this.setup(); 62 } 63 64 private void setup() { 65 66 this.setLayout(this); 67 68 List aSelectedPaths = new ArrayList(); 69 70 if(this.getPropertyInstance().getValues().size()>0) { 71 this.m_value = (RangeValue) this.getPropertyInstance().getValues().get(0); 72 this.m_range = (PropertyRange) this.m_value.getRange(); 73 if(this.m_range!=null) { 74 List aHREFs = this.m_range.getHREFs(); 75 Iterator itor = aHREFs.iterator(); 76 while (itor.hasNext()) { 77 String sHREF = (String ) itor.next(); 78 aSelectedPaths.add(sHREF); 79 } 80 } else { 81 this.m_range = new PropertyRange(); 82 } 83 } 84 85 m_tree = new FormResourceTree(false, aSelectedPaths); 86 m_tree.setShowLeafNodes(false); 87 m_tree.setBorder(BorderFactory.createEtchedBorder()); 88 m_tree.addFormResourceTreeListener(this); 89 90 this.add(m_tree); 91 92 String fontName = "Dialog"; 93 int fontSize = 11; 94 Font font = new Font(fontName, Font.PLAIN, fontSize); 95 96 Server server = ServerList.getInstance().getHarmoniseServer(); 97 VirtualFile vfFile = 98 server.getVFS().getVirtualFile( 99 "/" + server.getVFS().getRootPathSegment() + "/Metadata/Properties").getResource(); 100 this.m_tree.addCollection(vfFile); 101 } 102 103 106 public void removeLayoutComponent(Component arg0) { 107 } 108 109 112 public void layoutContainer(Container arg0) { 113 int nHeight = 0; 114 115 this.m_tree.setSize(this.m_tree.getPreferredSize()); 116 this.m_tree.setLocation(0, nHeight + 20); 117 } 118 119 122 public void addLayoutComponent(String arg0, Component arg1) { 123 } 124 125 128 public Dimension minimumLayoutSize(Container arg0) { 129 return this.getPreferredSize(); 130 } 131 132 135 public Dimension preferredLayoutSize(Container arg0) { 136 return this.getPreferredSize(); 137 } 138 139 private boolean checkForInfiniteLoop(String sPath) { 140 boolean bLoopFound = false; 141 if(this.getPropertyInstance().getVirtualFile().getFullPath().startsWith(sPath)) { 142 bLoopFound = true; 143 } else { 144 PropertyGroup propGroup = PropertyCache.getInstance().getPropertyGroup(sPath); 145 146 Iterator itor = propGroup.getChildren().iterator(); 147 148 while (itor.hasNext()) { 149 Property prop = (Property) itor.next(); 150 Range range = prop.getRange(); 151 if(range instanceof PropertyRange) { 152 if(prop.getHREF().equals(this.getPropertyInstance().getVirtualFile().getFullPath())) { 153 bLoopFound = true; 154 break; 155 } 156 Iterator itor2 = ((PropertyRange)range).getHREFs().iterator(); 157 while (itor2.hasNext()) { 158 String sHREF = (String ) itor2.next(); 159 if(this.checkForInfiniteLoop(sHREF)) { 160 bLoopFound = true; 161 break; 162 } 163 } 164 } 165 } 166 167 if(!bLoopFound) { 168 itor = propGroup.getSubGroups().iterator(); 169 while (itor.hasNext()) { 170 PropertyGroup subGroup = (PropertyGroup) itor.next(); 171 if(this.checkForInfiniteLoop(subGroup.getHREF())) { 172 bLoopFound = true; 173 break; 174 } 175 } 176 } 177 } 178 179 return bLoopFound; 180 } 181 182 185 public Dimension getPreferredSize() { 186 return new Dimension(this.m_tree.getPreferredSize().width, this.m_tree.getPreferredSize().height+20); 187 } 188 189 192 public void pathValuesChanged(List pathValues) { 193 List aPathsToAdd = new ArrayList(); 194 195 Iterator itor = pathValues.iterator(); 196 while (itor.hasNext()) { 197 String sPath = (String ) itor.next(); 198 if(!this.checkForInfiniteLoop(sPath)) { 199 aPathsToAdd.add(sPath); 200 } else { 201 VirtualFile vfFile = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(sPath).getResource(); 202 String sDisplayName = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFileSystemView().getDisplayName(vfFile); 203 MessageHandler.getInstance().fireMessageEvent("Warning! You cannot add the property group " + sDisplayName + " because it would create an infinite loop of Compound Properties.", MessageHandler.TYPE_ERROR); 204 this.m_tree.removePathValue(sPath); 205 } 206 } 207 208 this.m_range.setHREFs( aPathsToAdd); 209 RangeValue newValue = (RangeValue) this.getPropertyInstance().getNewValueInstance(); 210 newValue.setRange(this.m_range); 211 this.fireRangeDetailsChanged(newValue); 212 } 213 214 } 215 | Popular Tags |