1 19 package org.openharmonise.him.metadata.range.swing.domain; 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.*; 31 import org.openharmonise.him.swing.resourcetree.*; 32 import org.openharmonise.him.window.messages.*; 33 import org.openharmonise.vfs.*; 34 import org.openharmonise.vfs.gui.*; 35 import org.openharmonise.vfs.metadata.*; 36 import org.openharmonise.vfs.metadata.value.*; 37 import org.openharmonise.vfs.servers.*; 38 39 40 45 public class DomainRangeDisplay 46 extends AbstractRangeDisplay 47 implements RangeDisplay, LayoutManager, ActionListener { 48 49 private JLabel m_domainLabel = null; 50 private JLabel m_domainLabel2 = null; 51 52 private ResourceTree m_tree = null; 53 54 private JButton m_addButton = null; 55 private JButton m_removeButton = null; 56 57 private DomainSelectionList m_selectionList = null; 58 59 private int m_nHeight = 400; 60 61 private static List m_hiddenRootPaths = new ArrayList(); 62 63 static { 64 m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE); 65 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS); 66 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS); 67 m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES); 68 } 69 70 73 public DomainRangeDisplay(PropertyInstance propInstance) { 74 super(propInstance); 75 this.setup(); 76 } 77 78 private void setup() { 79 this.setLayout(this); 80 81 m_tree = new ResourceTree(); 82 this.m_tree.setBorder(BorderFactory.createEtchedBorder()); 83 m_tree.setShowLeafNodes(false); 84 this.add(m_tree); 85 86 this.m_domainLabel = new JLabel("The Domain applies to all the children of the collection i.e. all the collections or resources under the selected"); 87 this.add(m_domainLabel); 88 this.m_domainLabel2 = new JLabel("collection, not to the collection itself."); 89 this.add(m_domainLabel2); 90 91 this.m_addButton = new JButton(); 92 this.m_addButton.setIcon( 93 IconManager.getInstance().getIcon("16-command-value-plus.gif")); 94 this.m_addButton.setActionCommand("ADD"); 95 this.m_addButton.setToolTipText("Add"); 96 this.m_addButton.addActionListener(this); 97 this.add(this.m_addButton); 98 this.m_removeButton = new JButton(); 99 this.m_removeButton.setIcon( 100 IconManager.getInstance().getIcon("16-command-value-minus.gif")); 101 this.m_removeButton.setActionCommand("REMOVE"); 102 this.m_removeButton.setToolTipText("Remove"); 103 this.m_removeButton.addActionListener(this); 104 this.add(this.m_removeButton); 105 106 Server server = ServerList.getInstance().getHarmoniseServer(); 107 VirtualFile vfFile = 108 server.getVFS().getVirtualFile( 109 "/" + server.getVFS().getRootPathSegment() + "/").getResource(); 110 List children = vfFile.getChildren(); 111 Iterator itor2 = children.iterator(); 112 while (itor2.hasNext()) { 113 VirtualFile vfDir = 114 server.getVFS().getVirtualFile((String ) itor2.next()).getResource(); 115 if (vfDir.isDirectory() && !this.isPathHiddenRoot(vfDir.getFullPath())) { 116 this.m_tree.addCollection(vfDir); 117 } 118 } 119 120 this.m_selectionList = new DomainSelectionList(this); 121 this.m_selectionList.setBorder(BorderFactory.createEtchedBorder()); 122 this.add(this.m_selectionList); 123 this.m_selectionList.setListenToCombo(false); 124 Iterator itor = this.getPropertyInstance().getValues().iterator(); 125 while (itor.hasNext()) { 126 DomainValue value = (DomainValue) itor.next(); 127 this.m_selectionList.addDomain(value); 128 } 129 this.m_selectionList.setListenToCombo(true); 130 131 } 132 133 private boolean isPathHiddenRoot(String sPath) { 134 boolean bHidden = false; 135 136 Iterator itor = DomainRangeDisplay.m_hiddenRootPaths.iterator(); 137 while (itor.hasNext()) { 138 String sRootPath = (String ) itor.next(); 139 if(sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) { 140 bHidden=true; 141 } 142 } 143 144 return bHidden; 145 } 146 147 150 public JPanel getPanel() { 151 return this; 152 } 153 154 157 public Dimension getPreferredSize() { 158 return new Dimension(580, 300); 159 } 160 161 164 public void removeLayoutComponent(Component arg0) { 165 } 166 167 170 public void layoutContainer(Container arg0) { 171 int nHeight = 0; 172 173 this.m_domainLabel.setSize(this.m_domainLabel.getPreferredSize()); 174 this.m_domainLabel.setLocation(20, nHeight); 175 nHeight = nHeight + 15; 176 177 this.m_domainLabel2.setSize(this.m_domainLabel2.getPreferredSize()); 178 this.m_domainLabel2.setLocation(20, nHeight); 179 180 this.m_tree.setSize(150, 250); 181 this.m_tree.setLocation(20, nHeight + 20); 182 183 this.m_addButton.setSize(30,30); 184 this.m_addButton.setLocation(180, nHeight + 40); 185 this.m_removeButton.setSize(30,30); 186 this.m_removeButton.setLocation(180, nHeight + 90); 187 188 this.m_selectionList.setSize( this.m_selectionList.getPreferredSize() ); 189 this.m_selectionList.setLocation(220, nHeight + 20); 190 191 } 192 193 196 public void addLayoutComponent(String arg0, Component arg1) { 197 } 198 199 202 public Dimension minimumLayoutSize(Container arg0) { 203 return this.getPreferredSize(); 204 } 205 206 209 public Dimension preferredLayoutSize(Container arg0) { 210 return this.getPreferredSize(); 211 } 212 213 protected void domainValuesChanged() { 214 List aValues = this.m_selectionList.getValues(); 215 this.getPropertyInstance().setValues(aValues); 216 } 217 218 protected DomainValue getNewValueInstance() { 219 return (DomainValue) this.getPropertyInstance().getNewValueInstance(); 220 } 221 222 225 public void actionPerformed(ActionEvent ae) { 226 if(ae.getActionCommand().equals("ADD")) { 227 VirtualFile vfFile = this.m_tree.getSelectedResource(); 228 boolean bFound = false; 229 if(vfFile.isVirtualDirectory()) { 230 MessageHandler.getInstance().fireMessageEvent("The collection " + vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile) + " cannot be used as a Domain as it is a virtual collection. Try using child collections of this one.", MessageHandler.TYPE_ERROR); 231 bFound=true; 232 } 233 Iterator itor = this.getPropertyInstance().getValues().iterator(); 234 while (itor.hasNext()) { 235 DomainValue element = (DomainValue) itor.next(); 236 if(element.getPath().equals(vfFile.getFullPath())) { 237 bFound=true; 238 break; 239 } 240 } 241 if(!bFound) { 242 DomainValue value = (DomainValue) this.getPropertyInstance().getNewValueInstance(); 243 value.setPath(vfFile.getFullPath()); 244 this.getPropertyInstance().addValue(value); 245 this.m_selectionList.addDomain(value); 246 } 247 } else if(ae.getActionCommand().equals("REMOVE")) { 248 this.m_selectionList.removeSelectedCell(); 249 this.revalidate(); 250 this.repaint(); 251 this.domainValuesChanged(); 252 } 253 } 254 255 258 public boolean isMetadataValid() { 259 return true; 260 } 261 262 265 public boolean isResizeWidthEnabled() { 266 return false; 267 } 268 269 } 270 | Popular Tags |