1 7 package org.openharmonise.him.metadata.swing; 8 9 import java.awt.*; 10 import java.util.*; 11 12 import javax.swing.*; 13 import javax.swing.event.*; 14 15 import org.openharmonise.commons.xml.namespace.*; 16 import org.openharmonise.him.*; 17 import org.openharmonise.him.authentication.*; 18 import org.openharmonise.him.harmonise.*; 19 import org.openharmonise.him.metadata.range.swing.*; 20 import org.openharmonise.him.metadata.range.swing.resourcehandling.*; 21 import org.openharmonise.vfs.*; 22 import org.openharmonise.vfs.gui.*; 23 import org.openharmonise.vfs.metadata.*; 24 import org.openharmonise.vfs.metadata.range.*; 25 import org.openharmonise.vfs.metadata.value.*; 26 import org.openharmonise.vfs.servers.ServerList; 27 28 29 37 public class MetadataTabs extends JTabbedPane implements ChangeListener, Runnable { 38 39 private AbstractVirtualFileSystem m_vfs = null; 40 private String m_sFilepath = null; 41 42 private HashMap m_PathToTab = new HashMap(5); 43 44 private ArrayList m_tabPanels = new ArrayList(); 45 46 private String m_sSelectedTabTitle = null; 47 48 51 public MetadataTabs(AbstractVirtualFileSystem vfs, String sFilepath) { 52 super(); 53 this.m_vfs = vfs; 54 this.m_sFilepath = sFilepath; 55 this.setup(); 56 } 57 58 protected void clearToDestroy() { 59 Iterator itor = this.m_tabPanels.iterator(); 60 while (itor.hasNext()) { 61 MetadataTabPanel tab = (MetadataTabPanel) itor.next(); 62 tab.clearToDestroy(); 63 } 64 this.m_tabPanels.clear(); 65 this.m_vfs = null; 66 this.m_sFilepath = null; 67 this.m_PathToTab.clear(); 68 this.removeAll(); 69 } 70 71 74 private MetadataTabs(int arg0) { 75 super(arg0); 76 } 77 78 82 private MetadataTabs(int arg0, int arg1) { 83 super(arg0, arg1); 84 } 85 86 private void setup() { 87 88 this.addChangeListener(this); 89 90 String fontName = "Dialog"; 91 int fontSize = 11; 92 Font font = new Font(fontName, Font.PLAIN, fontSize); 93 this.setFont(font); 94 95 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource(); 96 Iterator itor = vfFile.getProperties().iterator(); 97 while(itor.hasNext()) { 98 PropertyInstance propInstance = (PropertyInstance)itor.next(); 99 Property prop = propInstance.getDefinition(); 100 this.addPropToPanel(vfFile, prop, propInstance); 101 } 102 103 PropertyInstance propInst = new PropertyInstance(NamespaceType.OHRM.getURI(), "harmonise-path"); 104 propInst.setVirtualFile(vfFile); 105 StringValue value = (StringValue) propInst.getNewValueInstance(); 106 value.setValue(vfFile.getFullPath()); 107 propInst.addValueWithoutFiringVirtualFileEvent(value); 108 this.addPropToPanel(vfFile, propInst.getDefinition(), propInst); 109 110 this.validateTree(); 111 Iterator itor2 = this.m_tabPanels.iterator(); 112 while (itor2.hasNext()) { 113 MetadataTabPanel tab = (MetadataTabPanel) itor2.next(); 114 tab.checkValid(); 115 } 116 } 117 118 private void addPropToPanel(VirtualFile vfFile, Property prop, PropertyInstance propInstance) { 119 if( prop!=null && !(prop.getNamespace().equals(NamespaceType.DAV.getURI()) && !(prop.getName().equals("domain") || prop.getName().equals("range")) ) && !prop.getName().equals("creator-displayname")) { 120 String sPropPath = prop.getHREF(); 122 String sTabName = prop.getHREF(); 123 124 VirtualFile vfPropGroup = null; 125 126 if(prop.getHREF().startsWith( HarmonisePaths.PATH_WORKFLOW_PROPS )) { 127 sTabName = "Workflow"; 128 } else if(prop.getName().equals("REPORT_EXE_ROLES")) { 129 sTabName = "Execute Permissions"; 130 } else if(prop.getRange() instanceof ResourceRange || prop.getRange() instanceof CollectionRange) { 131 sTabName="Relationships"; 132 } else if(prop.getNamespace().equals(NamespaceType.DAV.getURI()) && prop.getName().equals("domain")) { 133 sTabName="Domain"; 134 } else if( ( (vfFile.isVersionable() && ((VersionedVirtualFile)vfFile).getLogicalPath().startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) ) || vfFile.getFullPath().startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) ) && prop.getNamespace().equals(NamespaceType.DAV.getURI()) && prop.getName().equals("range")) { 135 sTabName="EXCLUDE"; 136 } else if(prop.getNamespace().equals(NamespaceType.DAV.getURI()) && prop.getName().equals("range")) { 137 sTabName="Range"; 138 } else if(prop.getName().startsWith("WORKFLOW_") && prop.getHREF().startsWith("/webdav/SYSTEM_PROPS")) { 139 sTabName="Workflow Details"; 140 } else if(prop.getNamespace().equals(NamespaceType.OHRM.getURI()) && (prop.getName().equals("harmonise-id") || prop.getName().equals("harmonise-path"))) { 141 sTabName="Resource Information"; 142 } else if(prop.getNamespace().equals(NamespaceType.OHRM.getURI()) && prop.getName().equals("OUTPUT")) { 143 sTabName="Resource Information"; 144 } else if(prop.getNamespace().equals(NamespaceType.OHRM.getURI()) && prop.getName().equals("title")) { 145 sTabName="Resource Information"; 146 } else if(prop.getNamespace().equals(NamespaceType.OHRM.getURI()) && prop.getName().equals("description")) { 147 sTabName="Resource Information"; 148 } else if(prop.getNamespace().equals(NamespaceType.OHRM.getURI()) && prop.getName().equals("thumbnail")) { 149 sTabName="EXCLUDE"; 150 } else { 151 152 AbstractVirtualFileSystem vfsProps = ServerList.getInstance().getHarmoniseServer().getVFS(); 153 VirtualFile vfPropFile = vfsProps.getVirtualFile(sPropPath).getResource(); 154 155 if(vfPropFile!=null && vfsProps.getVirtualFile( vfPropFile.getFilePath() )!=null ) { 156 vfPropGroup = vfsProps.getVirtualFile( vfPropFile.getFilePath() ).getResource(); 157 sTabName = vfsProps.getVirtualFileSystemView().getDisplayName(vfPropGroup); 158 } else { 159 if(sTabName.endsWith("/")) { 160 sTabName = sTabName.substring(0, sTabName.length()-1); 161 } 162 if(sTabName.endsWith("/" + prop.getName().trim())) { 163 sTabName = sTabName.substring(0, sTabName.length()-(1+prop.getName().length())); 164 } 165 } 166 } 167 168 sTabName = sTabName.substring(sTabName.lastIndexOf("/")+1); 169 if(this.indexOfTab(sTabName)==-1 && !sTabName.equals("System") && !sTabName.equals("EXCLUDE") && !sTabName.equals("default") && !((sTabName.equals("RBS_PROPS")|| sTabName.equals("Security")) && !HarmoniseAuthenticationStore.isSuperUser())) { 171 MetadataTabPanel panel = null; 172 if(vfPropGroup!=null) { 173 panel = new MetadataTabPanel(vfPropGroup); 174 } else { 175 panel = new MetadataTabPanel(); 176 } 177 JScrollPane scoller = null; 178 179 if(sTabName.equalsIgnoreCase("Domain") || sTabName.equalsIgnoreCase("Range")) { 180 scoller = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 181 } else { 182 scoller = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 183 } 184 185 JScrollBar hBar = new JScrollBar(JScrollBar.HORIZONTAL); 186 hBar.setUnitIncrement(20); 187 hBar.setFocusable(false); 188 scoller.setHorizontalScrollBar(hBar); 189 JScrollBar vBar = new JScrollBar(JScrollBar.VERTICAL); 190 vBar.setUnitIncrement(20); 191 vBar.setFocusable(false); 192 scoller.setVerticalScrollBar(vBar); 193 scoller.setFocusable(false); 194 195 this.m_tabPanels.add(panel); 196 this.addTab(sTabName, IconManager.getInstance().getIcon("16-message-confirm.gif"), scoller); 197 this.m_PathToTab.put(sPropPath, sTabName); 198 } 199 201 if(sTabName.equals("RBS_PROPS") && !HarmoniseAuthenticationStore.isSuperUser()) { 202 } else if(sTabName.equals("EXCLUDE") || sTabName.equals("System") || sTabName.equals("default")) { 204 } else { 205 PropertyPanel propPanel = null; 206 207 RangeDisplay display = RangeDisplayFactory.getRangeDisplay(propInstance); 208 209 propPanel = new PropertyPanel(propInstance,display.isResizeWidthEnabled()); 210 211 try { 212 JScrollPane scroller = (JScrollPane)this.getComponentAt(this.indexOfTab(sTabName)); 213 scroller.setFocusable(false); 214 MetadataTabPanel metaPane = (MetadataTabPanel)scroller.getViewport().getComponent(0); 215 propPanel.setSize(200, 100); 216 217 218 if(display!=null && !(display instanceof ResourceRangeDisplay)) { 219 metaPane.addPropertyPanel(propPanel); 220 propPanel.add(display.getPanel()); 221 } else if((display instanceof ResourceRangeDisplay) && !metaPane.hasRelationships()) { 222 metaPane.setRelationships((ResourceRangeDisplay) display); 223 } else if((display instanceof ResourceRangeDisplay) && metaPane.hasRelationships()) { 224 metaPane.addRelationship((ResourceRangeDisplay) display); 225 } 226 } catch(ArrayIndexOutOfBoundsException indexEx) { 227 System.err.println("Array index exception for TAB: " + sTabName + " and prop: " + prop.getDisplayName()); 228 indexEx.printStackTrace(); 229 } 230 } 231 232 } 233 } 234 235 public void setSelectedTab(String sSelectedTabTitle) { 236 if(sSelectedTabTitle!=null) { 237 for(int i=0; i<this.getTabCount(); i++) { 238 if(this.getTitleAt(i).equals(sSelectedTabTitle)) { 239 this.setSelectedIndex(i); 240 break; 241 } 242 } 243 } 244 } 245 246 public String getSelectedTabTitle() { 247 return this.m_sSelectedTabTitle; 248 } 249 250 public void setValid(boolean bValid, MetadataTabPanel panel) { 251 int nIndex = -1; 252 for(int i=0; i<this.getTabCount(); i++) { 253 if(panel==((JScrollPane)this.getComponentAt(i)).getViewport().getComponent(0)) { 254 nIndex = i; 255 break; 256 } 257 } 258 if(nIndex!=-1) { 259 if(bValid) { 260 this.setIconAt(nIndex, IconManager.getInstance().getIcon("16-message-confirm.gif")); 261 } else { 262 this.setIconAt(nIndex, IconManager.getInstance().getIcon("16-message-error.gif")); 263 } 264 } 265 266 } 267 268 271 public void setEnabled(boolean bEnabled) { 272 for (Iterator iter = this.m_tabPanels.iterator(); iter.hasNext();) { 273 MetadataTabPanel element = (MetadataTabPanel) iter.next(); 274 element.setEnabled(bEnabled); 275 } 276 } 277 278 281 public void stateChanged(ChangeEvent ce) { 282 int nSelectedIndex = this.getSelectedIndex(); 283 if(nSelectedIndex>-1 && nSelectedIndex<=this.getTabCount()) { 284 this.m_sSelectedTabTitle = this.getTitleAt(this.getSelectedIndex()); 285 } else { 286 } 287 } 288 289 public void validateAllComponents() { 290 this.layout(); 291 SwingUtilities.invokeLater(this); 292 } 293 294 297 public void run() { 298 this.repaint(); 299 } 300 301 } 302 | Popular Tags |