1 19 20 package org.openharmonise.him.displaycomponents.table; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 25 import javax.swing.*; 26 27 import org.openharmonise.commons.xml.namespace.*; 28 import org.openharmonise.him.configuration.*; 29 import org.openharmonise.him.editors.*; 30 import org.openharmonise.him.harmonise.*; 31 import org.openharmonise.him.window.menus.*; 32 import org.openharmonise.him.window.messages.*; 33 import org.openharmonise.swing.FontManager; 34 import org.openharmonise.vfs.*; 35 import org.openharmonise.vfs.context.*; 36 import org.openharmonise.vfs.event.*; 37 import org.openharmonise.vfs.gui.*; 38 import org.openharmonise.vfs.metadata.*; 39 import org.openharmonise.vfs.metadata.value.*; 40 41 42 50 public class VersionEntry 51 extends JPanel 52 implements MouseListener, VirtualFileListener, ContextListener { 53 54 57 protected VersionEntry() { 58 super(); 59 } 60 61 64 private TableView m_table = null; 65 66 69 private TableEntry m_parentEntry = null; 70 71 74 private String m_sFilepath = null; 75 76 79 private AbstractVirtualFileSystem m_vfs = null; 80 81 84 private Color m_selectedColor = new Color(173, 169, 143); 85 86 89 private JLabel m_rightIcon = null; 90 91 94 private JLabel m_title = null; 95 96 104 public VersionEntry( 105 TableEntry parentEntry, 106 AbstractVirtualFileSystem vfs, 107 String sFilepath, 108 String sTitle) { 109 super(); 110 this.m_sFilepath = sFilepath; 111 this.m_vfs = vfs; 112 this.m_parentEntry = parentEntry; 113 this.m_table = parentEntry.getTableView(); 114 this.setup(sTitle, true); 115 } 116 117 126 public VersionEntry( 127 TableEntry parentEntry, 128 AbstractVirtualFileSystem vfs, 129 String sFilepath, 130 String sTitle, 131 boolean bDisplayIcon) { 132 super(); 133 this.m_sFilepath = sFilepath; 134 this.m_vfs = vfs; 135 this.m_parentEntry = parentEntry; 136 this.m_table = parentEntry.getTableView(); 137 this.setup(sTitle, bDisplayIcon); 138 } 139 140 145 public TableEntry getParentTableEntry() { 146 return this.m_parentEntry; 147 } 148 149 154 public void clearToDestroy() { 155 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_FILENAME_DISPLAY, this); 156 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource(); 157 if (vfFile != null) { 158 vfFile.removeVirtualFileListener(this); 159 } 160 } 161 162 168 private void setup(String sTitle, boolean bDisplayIcon) { 169 ContextHandler.getInstance().addListener(ContextType.CONTEXT_FILENAME_DISPLAY, this); 170 this.addMouseListener(this); 171 172 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource(); 173 VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView(); 174 175 vfFile.addVirtualFileListener(this); 176 177 Icon iIcon = null; 178 if (bDisplayIcon) { 179 iIcon = vfsView.getIcon(vfFile); 180 } else { 181 iIcon = IconManager.getInstance().getIcon("16-blank.gif"); 182 } 183 String sRawDate = vfsView.getModificationDate(vfFile); 184 190 this.setPreferredSize(new Dimension(160, 40)); 191 this.setSize(new Dimension(160, 40)); 192 this.setBackground(Color.WHITE); 193 FlowLayout fl2 = new FlowLayout(FlowLayout.LEFT); 194 fl2.setHgap(0); 195 fl2.setVgap(0); 196 this.setLayout(fl2); 197 198 String sDisplayName = this.m_vfs.getVirtualFileSystemView().getDisplayName(vfFile); 199 String sValue = ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY"); 200 if(sValue!=null && sValue.length()>0 && (sValue.equals("FILENAME") || this.m_sFilepath.startsWith( HarmonisePaths.PATH_USERS ))) { 201 String sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilepath).getResource()); 202 m_title = 203 new JLabel( sFilename ); 204 } else if(sValue!=null && sValue.length()>0 && (sValue.equals("ID"))) { 205 String sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilepath).getResource()); 206 String sID = ""; 207 208 PropertyInstance propInst = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource().getProperty(NamespaceType.OHRM.getURI(), "harmonise-id"); 209 if(propInst!=null && propInst.getValues().size()>0) { 210 if(propInst.getValues().get(0) instanceof StringValue) { 211 StringValue value = (StringValue) propInst.getValues().get(0); 212 if(value.getValue()!=null && value.getValue().length()>0) { 213 sID = value.getValue() + ": "; 214 } 215 } 216 } 217 this.m_title= new JLabel( sID + sFilename ); 218 } else { 219 m_title = 220 new JLabel( sDisplayName ); 221 } 222 if(vfFile.getState().equals(VirtualFile.STATE_LIVE)) { 223 m_title.setFont(FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE_BOLD)); 224 } else { 225 m_title.setFont(FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE)); 226 } 227 228 m_title.setPreferredSize(new Dimension(129, 16)); 229 m_title.setIcon(iIcon); 230 if(vfFile.getState().equals(VirtualFile.STATE_LIVE)) { 231 m_title.setToolTipText(sDisplayName+" (published)"); 232 } else if(vfFile.getState().equals(VirtualFile.STATE_HISTORICAL)) { 233 m_title.setToolTipText(sDisplayName+" (historical)"); 234 } else { 235 m_title.setToolTipText(sDisplayName); 236 } 237 m_title.addMouseListener(this); 238 this.add(m_title); 239 240 m_rightIcon = new JLabel(); 241 m_rightIcon.setPreferredSize(new Dimension(16, 16)); 242 if (vfFile.isChanged()) { 243 m_rightIcon.setIcon( 244 IconManager.getInstance().getIcon("16-command-sync-all.gif")); 245 } else { 246 m_rightIcon.setIcon( 247 IconManager.getInstance().getIcon("16-blank.gif")); 248 } 249 m_rightIcon.addMouseListener(this); 250 this.add(m_rightIcon); 251 252 JLabel date = new JLabel(sRawDate); 253 date.setFont(FontManager.getInstance().getFont(FontManager.FONT_STANDARD)); 254 date.setPreferredSize(new Dimension(145, 16)); 255 date.setIcon(IconManager.getInstance().getIcon("16-blank.gif")); 256 date.addMouseListener(this); 257 this.add(date); 258 this.doLayout(); 259 } 260 261 264 public void mouseClicked(MouseEvent me) { 265 if(me.getClickCount()>1) { 266 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource(); 267 if(vfFile.isDirectory()) { 268 if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) { 269 this.m_table.openPathInTree(((VersionedVirtualFile)vfFile).getLiveVersionPath()); 270 } else { 271 this.m_table.openPathInTree(this.m_sFilepath); 272 } 273 } else if(vfFile.getFullPath().startsWith(HarmonisePaths.PATH_REPORTS_OUTPUT)) { 274 EditorController.getInstance().preview(this.m_sFilepath, this.m_vfs); 275 } else if(vfFile.isLocked() && vfFile.getVFS().getVirtualFile(vfFile.getLockOwner())!=null && !vfFile.getVFS().getVirtualFile(vfFile.getLockOwner()).getResource().getFileName().trim().equals(vfFile.getVFS().getAuthentication().getUsername().trim())) { 276 MessageHandler.getInstance().fireMessageEvent("Cannot open resource \"" + vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile) + "\" for editing, previewing instead.", MessageHandler.TYPE_INFORMATION); 277 EditorController.getInstance().preview(this.m_sFilepath, this.m_vfs); 278 } else if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_LIVE) && ((VersionedVirtualFile)vfFile).getPendingVersionPath()!=null) { 279 MessageHandler.getInstance().fireMessageEvent("Cannot open resource \"" + vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile) + "\" for editing, previewing instead.", MessageHandler.TYPE_INFORMATION); 280 EditorController.getInstance().preview(this.m_sFilepath, this.m_vfs); 281 } else { 282 EditorController.getInstance().open(this.m_sFilepath, this.m_vfs); 283 } 284 } else { 285 if (me.getSource() == this 286 || this.isChildComponent( 287 (Component) me.getSource()) ) { 288 if (this.getBackground() == m_selectedColor) { 289 this.selectEntry(); 290 } else { 291 this.selectEntry(); 292 } 293 this.m_table.entrySelected(this); 294 } 295 } 296 if(me.getButton()==MouseEvent.BUTTON3) { 297 FileContextMenu menu = new FileContextMenu(this.m_sFilepath, this.m_vfs); 298 Point pt = me.getPoint(); 299 menu.show(this, pt.x, pt.y); 300 } 301 } 302 303 307 protected void selectEntry() { 308 this.setBackground(m_selectedColor); 309 this.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 310 this.m_parentEntry.deselectOtherEntries(this); 311 } 312 313 317 protected void deselectEntry() { 318 this.setBackground(Color.WHITE); 319 320 this.setBorder(BorderFactory.createLineBorder(Color.WHITE)); 321 } 322 323 329 private boolean isChildComponent(Component comp) { 330 Component[] comps = this.getComponents(); 331 for (int i = 0; i < comps.length; i++) { 332 if (comp == comps[i]) { 333 return true; 334 } 335 } 336 return false; 337 } 338 339 344 public String getPath() { 345 return this.m_sFilepath; 346 } 347 348 353 public AbstractVirtualFileSystem getVFS() { 354 return this.m_vfs; 355 } 356 357 360 public void mouseEntered(MouseEvent arg0) { 361 } 362 363 366 public void mouseExited(MouseEvent arg0) { 367 } 368 369 372 public void mousePressed(MouseEvent arg0) { 373 } 374 375 378 public void mouseReleased(MouseEvent arg0) { 379 } 380 381 384 public void virtualFileChanged(VirtualFileEvent vfe) { 385 if (vfe.getEventType() == VirtualFileEvent.FILE_CONTENT_CHANGED 386 || vfe.getEventType() == VirtualFileEvent.FILE_METADATA_CHANGED) { 387 if (this.m_vfs.getVirtualFile(this.m_sFilepath).getResource().isChanged()) { 388 this.m_rightIcon.setIcon( 389 IconManager.getInstance().getIcon( 390 "16-command-sync-all.gif")); 391 ContextEvent ce = 392 new ContextEvent( 393 ContextType.CONTEXT_FILES, 394 null, 395 this.m_vfs, 396 this.m_sFilepath); 397 ContextHandler.getInstance().fireContextEvent(ce); 398 } 399 } else if ( 400 vfe.getEventType() == VirtualFileEvent.FILE_SYNCHED) { 401 this.m_rightIcon.setIcon( 402 IconManager.getInstance().getIcon("16-blank.gif")); 403 } else if ( 404 vfe.getEventType() == VirtualFileEvent.FILE_CHANGES_DISCARDED) { 405 this.m_rightIcon.setIcon( 406 IconManager.getInstance().getIcon("16-blank.gif")); 407 } 408 this.validate(); 409 } 410 411 414 public void contextMessage(ContextEvent ce) { 415 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILENAME_DISPLAY) { 416 String sValue = ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY"); 417 if(sValue!=null && sValue.length()>0 && (sValue.equals("FILENAME") || this.m_sFilepath.startsWith( HarmonisePaths.PATH_USERS ))) { 418 String sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilepath).getResource()); 419 this.m_title.setText( sFilename ); 420 } else if(sValue!=null && sValue.length()>0 && sValue.equals("ID")) { 421 String sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilepath).getResource()); 422 String sID = ""; 423 424 PropertyInstance propInst = this.m_vfs.getVirtualFile(this.m_sFilepath).getResource().getProperty(NamespaceType.OHRM.getURI(), "harmonise-id"); 425 if(propInst!=null && propInst.getValues().size()>0) { 426 if(propInst.getValues().get(0) instanceof StringValue) { 427 StringValue value = (StringValue) propInst.getValues().get(0); 428 if(value.getValue()!=null && value.getValue().length()>0) { 429 sID = value.getValue() + ": "; 430 } 431 } 432 } 433 this.m_title.setText( sID + sFilename ); 434 } else { 435 String sDisplayName = this.m_vfs.getVirtualFileSystemView().getDisplayName(this.m_vfs.getVirtualFile(this.m_sFilepath).getResource()); 436 this.m_title.setText( sDisplayName ); 437 } 438 this.revalidate(); 439 this.repaint(); 440 } 441 } 442 443 } 444 | Popular Tags |