1 19 package org.openharmonise.him.metadata.range.swing.resourcehandling; 20 import java.awt.*; 21 import java.awt.event.*; 22 import java.util.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.*; 27 import org.openharmonise.him.metadata.range.swing.*; 28 import org.openharmonise.him.swing.resourcetree.*; 29 import org.openharmonise.vfs.*; 30 import org.openharmonise.vfs.gui.*; 31 import org.openharmonise.vfs.metadata.*; 32 import org.openharmonise.vfs.servers.*; 33 34 35 40 public class ResourceRangeDisplay 41 extends AbstractRangeDisplay 42 implements RangeDisplay, LayoutManager, ActionListener { 43 44 private ArrayList m_aPropertyInstances = new ArrayList(); 45 46 private ResourceTree m_tree = null; 47 48 private JButton m_addButton = null; 49 private JButton m_removeButton = null; 50 51 private ResourceSelectionList m_selectionList = null; 52 53 private JLabel m_warningHeader = null; 54 private ArrayList m_aWarnings = new ArrayList(); 55 private ArrayList m_aReasons = new ArrayList(); 56 57 60 public ResourceRangeDisplay(PropertyInstance propInstance) { 61 super(propInstance); 62 this.setup(); 63 this.addRelationship(propInstance); 64 } 65 66 public void setup() { 67 this.setLayout(this); 68 m_tree = new ResourceTree(); 69 m_tree.setShowLeafNodes(true); 70 m_tree.setShowApprovedOnly(true); 71 m_tree.setBorder(BorderFactory.createEtchedBorder()); 72 73 this.m_addButton = new JButton(); 74 this.m_addButton.setIcon( IconManager.getInstance().getIcon("16-command-value-plus.gif") ); 75 this.m_addButton.setActionCommand("ADD"); 76 this.m_addButton.setToolTipText("Add"); 77 this.m_addButton.addActionListener(this); 78 this.add(this.m_addButton); 79 this.m_removeButton = new JButton(); 80 this.m_removeButton.setIcon( IconManager.getInstance().getIcon("16-command-value-minus.gif") ); 81 this.m_removeButton.setActionCommand("REMOVE"); 82 this.m_removeButton.setToolTipText("Remove"); 83 this.m_removeButton.addActionListener(this); 84 this.add(this.m_removeButton); 85 86 String [] data = new String [0]; 87 88 this.m_selectionList = new ResourceSelectionList(this); 89 m_selectionList.setBorder(BorderFactory.createEtchedBorder()); 90 this.add(this.m_selectionList); 91 92 this.add(m_tree); 93 } 94 95 98 public JPanel getPanel() { 99 100 101 102 return this; 103 } 104 105 108 public void addRelationship(PropertyInstance propInstance) { 109 Reason reason = new Reason(propInstance, this); 110 111 Iterator itor = reason.getHREFs().iterator(); 112 while(itor.hasNext()) { 113 String sPath = (String )itor.next(); 115 if(sPath.trim().equals(".")) { 116 Server server = ServerList.getInstance().getHarmoniseServer(); 117 118 VersionedVirtualFile vfLogicalFile = (VersionedVirtualFile) propInstance.getVirtualFile(); 119 if(vfLogicalFile.getState()==VirtualFile.STATE_PENDING && vfLogicalFile.getLiveVersionPath()!=null) { 120 vfLogicalFile = (VersionedVirtualFile) vfLogicalFile.getVFS().getVirtualFile(vfLogicalFile.getLiveVersionPath()).getResource(); 121 } 122 123 VirtualFile vfFile = server.getVFS().getVirtualFile( vfLogicalFile.getFilePath() ).getResource(); 124 125 this.m_tree.addCollection(vfFile); 126 } else { 127 Server server = ServerList.getInstance().getHarmoniseServer(); 128 129 VirtualFile vfFile = server.getVFS().getVirtualFile(sPath).getResource(); 130 131 this.m_tree.addCollection(vfFile); 132 } 133 } 134 135 WarningsLabel warning = reason.buildWarning(); 136 this.m_aWarnings.add(warning); 137 this.add(warning); 138 this.m_selectionList.addReason(reason); 139 } 140 141 144 public void addRelationship(ResourceRangeDisplay display) { 145 this.addRelationship(display.getPropertyInstance()); 146 } 147 148 151 public void removeLayoutComponent(Component arg0) { 152 } 153 154 157 public void layoutContainer(Container arg0) { 158 int nHeight = 0; 159 160 this.m_tree.setSize(200,300); 161 this.m_tree.setLocation(20,nHeight); 162 163 this.m_addButton.setSize(this.m_addButton.getPreferredSize()); 164 this.m_addButton.setLocation(240, nHeight+120); 165 this.m_removeButton.setSize(this.m_addButton.getPreferredSize()); 166 this.m_removeButton.setLocation(240, nHeight+150); 167 168 this.m_selectionList.setSize(290,300); 169 this.m_selectionList.setLocation(300 ,nHeight); 170 } 171 172 175 public void addLayoutComponent(String arg0, Component arg1) { 176 } 177 178 181 public Dimension minimumLayoutSize(Container arg0) { 182 return this.getPreferredSize(); 183 } 184 185 188 public Dimension preferredLayoutSize(Container arg0) { 189 return this.getPreferredSize(); 190 } 191 192 195 public Dimension getPreferredSize() { 196 return new Dimension(600, 330); 197 } 198 199 202 public void actionPerformed(ActionEvent ae) { 203 if(ae.getActionCommand().equals("ADD")) { 204 VirtualFile vfFile = this.m_tree.getSelectedResource(); 205 this.m_selectionList.addResource(vfFile); 206 } else if(ae.getActionCommand().equals("REMOVE")) { 207 this.m_selectionList.removeSelectedCell(); 208 } 209 this.validateTree(); 210 super.validateTab(); 211 } 212 213 216 public boolean isMetadataValid() { 217 return this.m_selectionList.isValid(); 218 } 219 220 public void validateTab() { 221 super.validateTab(); 222 } 223 224 227 public boolean isResizeWidthEnabled() { 228 return false; 229 } 230 231 } 232 | Popular Tags |