1 19 package org.openharmonise.him.metadata.swing; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.*; 27 import org.openharmonise.him.harmonise.*; 28 import org.openharmonise.vfs.*; 29 import org.openharmonise.vfs.context.*; 30 import org.openharmonise.vfs.event.*; 31 import org.openharmonise.vfs.servers.ServerList; 32 33 34 39 public class MetadataPanel extends JPanel implements VirtualFileListener, ComponentListener, LayoutManager, ContextListener { 40 41 private AbstractVirtualFileSystem m_vfs = null; 42 private String m_sPath = null; 43 44 private FileDetails m_fileDetails = null; 45 46 private MetadataTabs m_tabs = null; 47 48 51 public MetadataPanel() { 52 super(true); 53 this.setup(); 54 } 55 56 59 private MetadataPanel(boolean arg0) { 60 super(arg0); 61 } 62 63 66 private MetadataPanel(LayoutManager arg0) { 67 super(arg0); 68 } 69 70 74 private MetadataPanel(LayoutManager arg0, boolean arg1) { 75 super(arg0, arg1); 76 } 77 78 private void setup() { 79 this.setPreferredSize(new Dimension(10,10)); 80 this.setLayout(this); 81 ContextHandler.getInstance().addListener(ContextType.CONTEXT_FILES, this); 82 ContextHandler.getInstance().addListener(ContextType.CONTEXT_CLEAR_METADATA, this); 83 84 } 85 86 public void clearMetadataPanel() { 87 this.clearPanel(); 88 this.validate(); 89 this.repaint(); 90 } 91 92 private void clearPanel() { 93 if(this.m_vfs!=null && this.m_sPath!=null) { 94 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource(); 95 if(vfFile!=null) { 96 vfFile.removeVirtualFileListener(this); 97 } 98 } 99 100 if(this.m_fileDetails!=null) { 101 this.m_fileDetails.clearToDestroy(); 102 } 103 if(this.m_tabs!=null) { 104 this.m_tabs.clearToDestroy(); 105 } 106 107 this.m_vfs = null; 108 this.m_sPath = null; 109 this.removeAll(); 110 } 111 112 115 public void contextMessage(ContextEvent ce) { 116 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILES && ( this.m_vfs==null || this.m_sPath==null || this.m_vfs!=ce.getVFS() || !this.m_sPath.equals(ce.getPath() )) ) { 117 118 String sSelectedTabTitle = null; 119 if(this.m_tabs!=null) { 120 sSelectedTabTitle = this.m_tabs.getSelectedTabTitle(); 121 } 122 123 this.clearPanel(); 124 125 this.m_vfs = ce.getVFS(); 126 this.m_sPath = ce.getPath(); 127 128 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource(); 129 130 if(vfFile!=null) { 131 vfFile.addVirtualFileListener(this); 132 133 m_fileDetails = new FileDetails(this.m_vfs, this.m_sPath); 134 this.add(m_fileDetails); 135 136 m_tabs = new MetadataTabs(this.m_vfs, this.m_sPath); 137 this.add(m_tabs); 138 139 this.checkEnabled(); 140 141 this.m_tabs.setSelectedTab(sSelectedTabTitle); 142 } else { 143 this.clearPanel(); 144 this.m_vfs = null; 145 this.m_sPath = null; 146 } 147 148 this.validate(); 149 this.repaint(); 150 } else if(ce.CONTEXT_TYPE==ContextType.CONTEXT_CLEAR_METADATA) { 151 SwingUtilities.invokeLater( 152 new Runnable () { 153 public void run() { 154 clear(); 155 } 156 }); 157 } 158 } 159 160 private void clear() { 161 this.m_vfs=null; 162 this.m_sPath=null; 163 this.removeAll(); 164 this.revalidate(); 165 this.getParent().repaint(); 166 } 167 168 private void checkEnabled() { 169 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sPath).getResource(); 170 if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_LIVE) && ((VersionedVirtualFile)vfFile).hasPendingVersion()) { 171 this.m_tabs.setEnabled(false); 172 } else if(vfFile.getFullPath().startsWith(HarmonisePaths.PATH_ARCHIVE)) { 173 this.m_tabs.setEnabled(false); 174 } else if(vfFile.getState().equals(VirtualFile.STATE_HISTORICAL)) { 175 this.m_tabs.setEnabled(false); 176 } else if(vfFile.isLocked() 177 && ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(vfFile.getLockOwner()).getResource()!=null 178 && !ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(vfFile.getLockOwner()).getResource().getFileName().trim().equals(ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername().trim())) { 179 this.m_tabs.setEnabled(false); 180 } else if(vfFile.isLocked() 181 && ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(vfFile.getLockOwner()).getResource()==null) { 182 this.m_tabs.setEnabled(false); 183 } else if(!vfFile.getAllowedMethods().contains(VirtualFile.METHOD_SYNC)) { 184 this.m_tabs.setEnabled(false); 185 } else { 186 this.m_tabs.setEnabled(true); 187 } 188 } 189 190 193 public void virtualFileChanged(VirtualFileEvent vfe) { 194 if(vfe.getEventType().equals(VirtualFileEvent.FILE_CHANGES_DISCARDED)) { 195 if(this.m_fileDetails!=null) { 196 this.m_fileDetails.clearToDestroy(); 197 } 198 199 this.removeAll(); 200 this.m_vfs = vfe.getVFS(); 201 this.m_sPath = vfe.getPath(); 202 m_fileDetails = new FileDetails(this.m_vfs, this.m_sPath); 203 this.add(m_fileDetails); 204 205 m_tabs = new MetadataTabs(this.m_vfs, this.m_sPath); 206 this.add(m_tabs); 207 this.validate(); 208 this.repaint(); 209 } else if(vfe.getEventType().equals(VirtualFileEvent.FILE_SYNCHED)) { 210 this.clear(); 211 } else if(vfe.getEventType().equals(VirtualFileEvent.FILE_CHECKED_IN)) { 212 this.clear(); 213 } else if(vfe.getEventType().equals(VirtualFileEvent.FILE_DELETED)) { 214 this.clear(); 215 } 216 } 217 218 221 public void removeLayoutComponent(Component arg0) { 222 } 223 224 227 public void layoutContainer(Container arg0) { 228 if(m_fileDetails!=null) { 229 m_fileDetails.setLocation(0,0); 230 m_fileDetails.setSize(this.getParent().getParent().getWidth(), 50); 231 } 232 233 if(m_tabs!=null) { 234 m_tabs.setLocation(1,50); 235 m_tabs.setSize(this.getParent().getParent().getWidth(), this.getParent().getParent().getParent().getHeight()-55); 236 } 237 this.setPreferredSize(new Dimension( this.getParent().getParent().getWidth(), this.getParent().getParent().getParent().getHeight()-20) ); 238 } 239 240 243 public void addLayoutComponent(String arg0, Component arg1) { 244 } 245 246 249 public Dimension minimumLayoutSize(Container arg0) { 250 return null; 251 } 252 253 256 public Dimension preferredLayoutSize(Container arg0) { 257 return null; 258 } 259 260 263 public void componentHidden(ComponentEvent arg0) { 264 } 265 266 269 public void componentMoved(ComponentEvent arg0) { 270 } 271 272 275 public void componentResized(ComponentEvent arg0) { 276 this.doLayout(); 277 this.validateTree(); 278 } 279 280 283 public void componentShown(ComponentEvent arg0) { 284 } 285 286 } 287 | Popular Tags |