KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > displaycomponents > table > TableEntry


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.him.displaycomponents.table;
21
22 import java.awt.*;
23 import java.awt.dnd.*;
24 import java.awt.event.*;
25 import java.util.*;
26
27 import javax.swing.*;
28
29 import org.openharmonise.commons.xml.namespace.*;
30 import org.openharmonise.him.configuration.*;
31 import org.openharmonise.him.context.StateHandler;
32 import org.openharmonise.him.dnd.*;
33 import org.openharmonise.him.editors.*;
34 import org.openharmonise.him.harmonise.*;
35 import org.openharmonise.him.window.menus.*;
36 import org.openharmonise.him.window.messages.*;
37 import org.openharmonise.swing.FontManager;
38 import org.openharmonise.vfs.*;
39 import org.openharmonise.vfs.context.*;
40 import org.openharmonise.vfs.event.*;
41 import org.openharmonise.vfs.gui.*;
42 import org.openharmonise.vfs.metadata.*;
43 import org.openharmonise.vfs.metadata.value.*;
44
45
46 /**
47  * Component for displaying resource information in the table view.
48  *
49  * @author Matthew Large
50  * @version $Revision: 1.3 $
51  *
52  */

53 public class TableEntry extends JPanel implements MouseListener, VirtualFileListener, ContextListener {
54
55     /**
56      * Expand entry icon.
57      */

58     private JLabel m_expandIcon = null;
59     
60     /**
61      * Icon in the top right.
62      */

63     private JLabel m_topRightIcon = null;
64     
65     /**
66      * Title.
67      */

68     private JLabel m_title = null;
69     
70     /**
71      * Icon in the bottom right.
72      */

73     private JLabel m_bottomRightIcon = null;
74     
75     /**
76      * Name and date panel.
77      */

78     private JPanel m_dateInfo = null;
79     
80     /**
81      * Version information panel.
82      */

83     private JPanel m_versionInfo = null;
84     
85     /**
86      * Version panel in scroller.
87      */

88     private JPanel m_versionInnerPane = null;
89     
90     /**
91      * true if the table entry has been expaned to show version information.
92      */

93     private boolean m_bExpanded = false;
94     
95     /**
96      * Virtual file system for resource.
97      */

98     private AbstractVirtualFileSystem m_vfs = null;
99     
100     /**
101      * Full path to resource.
102      */

103     private String JavaDoc m_sFilePath;
104     
105     /**
106      * Resource name.
107      */

108     private String JavaDoc m_sFilename;
109     
110     /**
111      * Resource icon.
112      */

113     private Icon m_iFileIcon;
114     
115     /**
116      * Resource date.
117      */

118     private String JavaDoc m_sFileDate;
119     
120     /**
121      * Table view that this entry is in.
122      */

123     private TableView m_table = null;
124     
125     /**
126      * Selected highlight colour.
127      */

128     private Color m_selectedColor = new Color(173,169,143);
129     
130     /**
131      * List of {@link VersionEntry} objects.
132      */

133     private ArrayList m_versionEntries = new ArrayList();
134     
135     /**
136      * true if the resource has been deleted.
137      */

138     private boolean m_bDeleted = false;
139     
140     private boolean m_bArchive = false;
141
142     /**
143      *
144      */

145     private TableEntry() {
146         super();
147     }
148
149     /**
150      * @param arg0
151      */

152     private TableEntry(boolean arg0) {
153         super(arg0);
154     }
155
156     /**
157      * @param arg0
158      */

159     private TableEntry(LayoutManager arg0) {
160         super(arg0);
161     }
162
163     /**
164      * @param arg0
165      * @param arg1
166      */

167     private TableEntry(LayoutManager arg0, boolean arg1) {
168         super(arg0, arg1);
169     }
170
171     /**
172      * Constructs a new table entry.
173      *
174      * @param vfs Virtual file system for resource
175      * @param sFilePath Full path to resource
176      * @param table Table view this entry is in
177      */

178     public TableEntry(AbstractVirtualFileSystem vfs, String JavaDoc sFilePath, TableView table) {
179         super(true);
180         this.m_vfs = vfs;
181         this.m_sFilePath = sFilePath;
182         this.m_table = table;
183         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
184         
185         if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_LIVE) && ((VersionedVirtualFile)vfFile).hasPendingVersion()) {
186             vfFile = vfFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfFile).getPendingVersionPath() ).getResource();
187             this.m_vfs = vfFile.getVFS();
188             this.m_sFilePath = vfFile.getFullPath();
189         }
190         
191         vfFile.addVirtualFileListener(this);
192         this.setup();
193     }
194     
195     /**
196      * Clears all resources that this class is holding onto making it
197      * ready to be destroyed.
198      *
199      */

200     public void clearToDestroy() {
201         ContextHandler.getInstance().removeListener(ContextType.CONTEXT_FILENAME_DISPLAY, this);
202         if(!this.m_bDeleted) {
203             VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
204             if(vfFile!=null) {
205                 vfFile.removeVirtualFileListener(this);
206             }
207             for (Iterator iter = this.m_versionEntries.iterator(); iter.hasNext();) {
208                 VersionEntry element = (VersionEntry) iter.next();
209                 element.clearToDestroy();
210             }
211         }
212     }
213     
214     /**
215      * Returns the logical path, which is what we need to use when
216      * dragging a resource.
217      *
218      * @return Full path
219      */

220     public String JavaDoc getDragVirtualFilePath() {
221         String JavaDoc sPath = null;
222         
223         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
224         sPath = vfFile.getFullPath();
225         if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) {
226             sPath = ((VersionedVirtualFile)vfFile).getLiveVersionPath();
227         }
228         
229         return sPath;
230     }
231
232     /**
233      * Configures this table entry.
234      *
235      */

236     private void setup() {
237         ContextHandler.getInstance().addListener(ContextType.CONTEXT_FILENAME_DISPLAY, this);
238         
239         VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
240         VirtualFile vfActualFile = vfFile;
241         if(vfFile.getFullPath().startsWith(HarmonisePaths.PATH_ARCHIVE)){
242             m_bArchive = true;
243         }
244         
245         if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) {
246             vfFile = vfFile.getVFS().getVirtualFile(((VersionedVirtualFile)vfFile).getLiveVersionPath()).getResource();
247         }
248         
249         VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView();
250         this.m_sFilename = vfsView.getDisplayName(vfFile);
251         this.m_iFileIcon = vfsView.getIcon(vfFile);
252         if(m_bArchive){
253             m_sFileDate = vfsView.getArchiveDate(vfActualFile);
254         } else {
255             m_sFileDate = vfsView.getModificationDate(vfActualFile);
256         }
257         
258         this.setBackground(Color.WHITE);
259         this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
260         this.addMouseListener(this);
261
262         FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
263         fl.setHgap(5);
264         fl.setVgap(1);
265         this.setLayout(fl);
266
267         this.setMinimumSize(new Dimension(200, 50));
268         this.setMaximumSize(new Dimension(200, 50));
269         this.setPreferredSize(new Dimension(200, 50));
270 //
271
// String fontName = "Arial Unicode MS";
272
// int fontSize = 11;
273
// Font font = new Font(fontName, Font.PLAIN, fontSize);
274
// Font boldFont = new Font(fontName, Font.BOLD, fontSize);
275

276         
277         if(vfFile.isVersionable()) {
278             m_expandIcon = new JLabel();
279             m_expandIcon.setPreferredSize(new Dimension(10, 20));
280             m_expandIcon.setIcon(
281                 IconManager.getInstance().getIcon("16-tree-collapsed.gif"));
282             m_expandIcon.addMouseListener(this);
283             m_expandIcon.setToolTipText("Expand/collapse versions");
284             this.add(m_expandIcon);
285         } else {
286             m_expandIcon = new JLabel();
287             m_expandIcon.setPreferredSize(new Dimension(10, 20));
288             m_expandIcon.setIcon(
289                 IconManager.getInstance().getIcon("16-blank.gif"));
290             m_expandIcon.addMouseListener(this);
291             this.add(m_expandIcon);
292         }
293         TableDragSource source = new TableDragSource(this, m_expandIcon, DnDConstants.ACTION_COPY_OR_MOVE);
294
295         String JavaDoc sDisplayName = this.m_vfs.getVirtualFileSystemView().getDisplayName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
296         
297         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY");
298         
299         if(sValue!=null && sValue.length()>0 && (sValue.equals("FILENAME") || this.m_sFilePath.startsWith( HarmonisePaths.PATH_USERS ))) {
300             String JavaDoc sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
301             m_title =
302                 new JLabel( sFilename );
303         } else if(sValue!=null && sValue.length()>0 && (sValue.equals("ID") )) {
304             String JavaDoc sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
305             String JavaDoc sID = "";
306                 
307             PropertyInstance propInst = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource().getProperty(NamespaceType.OHRM.getURI(), "harmonise-id");
308             if(propInst!=null && propInst.getValues().size()>0) {
309                 if(propInst.getValues().get(0) instanceof StringValue) {
310                     StringValue value = (StringValue) propInst.getValues().get(0);
311                     if(value.getValue()!=null && value.getValue().length()>0) {
312                         sID = value.getValue() + ": ";
313                     }
314                 }
315             }
316             this.m_title= new JLabel( sID + sFilename );
317         } else {
318             m_title =
319                 new JLabel( sDisplayName );
320         }
321         m_title.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE_BOLD) );
322         m_title.setPreferredSize(new Dimension(149, 20));
323         m_title.addMouseListener(this);
324         m_title.setToolTipText( sDisplayName );
325         source = new TableDragSource(this, m_title, DnDConstants.ACTION_COPY_OR_MOVE);
326         this.add(m_title);
327
328         m_topRightIcon = new JLabel();
329         source = new TableDragSource(this, m_topRightIcon, DnDConstants.ACTION_COPY_OR_MOVE);
330         if(vfActualFile.getState().equals(VirtualFile.STATE_LIVE)) {
331             m_topRightIcon.setIcon(
332                 IconManager.getInstance().getIcon("16-command-sync-file.gif"));
333             m_topRightIcon.setToolTipText("Published Version");
334         } else if(vfActualFile.isVersionable()) {
335             if(vfActualFile.getState().equals(VirtualFile.STATE_PENDING)
336                 && ((VersionedVirtualFile)vfActualFile).getLiveVersionPath()!=null) {
337                     m_topRightIcon.setIcon(
338                         IconManager.getInstance().getIcon("16-command-sync-file.gif"));
339                     m_topRightIcon.setEnabled(false);
340                     String JavaDoc sText = "Published";
341                     if(m_bArchive) {
342                         sText = "Archived";
343                     }
344                     m_topRightIcon.setToolTipText(sText);
345             } else {
346                 m_topRightIcon.setIcon(
347                     IconManager.getInstance().getIcon("16-blank.gif"));
348             }
349         } else {
350             m_topRightIcon.setIcon(
351                 IconManager.getInstance().getIcon("16-blank.gif"));
352         }
353         m_topRightIcon.addMouseListener(this);
354         this.add(m_topRightIcon);
355
356         this.m_dateInfo = new JPanel();
357         this.m_dateInfo.setPreferredSize(new Dimension(190, 20));
358         this.m_dateInfo.setBackground(Color.WHITE);
359         FlowLayout fl2 = new FlowLayout(FlowLayout.LEFT);
360         fl2.setHgap(0);
361         fl2.setVgap(0);
362         this.m_dateInfo.setLayout(fl2);
363         this.m_dateInfo.addMouseListener(this);
364         source = new TableDragSource(this, m_dateInfo, DnDConstants.ACTION_COPY_OR_MOVE);
365
366         String JavaDoc sDate = "mod date";
367         if(m_sFileDate!=null) {
368             sDate = m_sFileDate;
369         }
370         
371         
372         if(vfActualFile.isVersionable()) {
373             String JavaDoc text = "";
374             if(this.m_bArchive){
375                 text = "Archived";
376             } else if(vfActualFile.getState().equals(VirtualFile.STATE_PENDING)) {
377                 if(((VersionedVirtualFile)vfActualFile).getLiveVersionPath()==null) {
378                     text = "New";
379                 } else {
380                     text = "Draft";
381                 }
382             } else if(vfActualFile.getState().equals(VirtualFile.STATE_LIVE)) {
383                 text = "Published";
384             }
385             sDate = text + " (" + sDate + ")";
386         }
387
388         JLabel dateIcon = new JLabel( sDate );
389         dateIcon.setFont( FontManager.getInstance().getFont(FontManager.FONT_STANDARD) );
390         dateIcon.setPreferredSize(new Dimension(165, 20));
391         dateIcon.setIcon( this.m_iFileIcon );
392         this.m_dateInfo.add(dateIcon);
393
394         m_bottomRightIcon = new JLabel();
395         source = new TableDragSource(this, m_bottomRightIcon, DnDConstants.ACTION_COPY_OR_MOVE);
396         if(vfActualFile.isChanged()) {
397             m_bottomRightIcon.setIcon(
398                 IconManager.getInstance().getIcon("16-command-sync-all.gif"));
399             m_bottomRightIcon.setToolTipText("Resource has changed, ready to submit");
400         } else {
401             m_bottomRightIcon.setIcon(
402                 IconManager.getInstance().getIcon("16-blank.gif"));
403         }
404         m_bottomRightIcon.addMouseListener(this);
405         this.m_dateInfo.add(m_bottomRightIcon);
406
407         this.add(this.m_dateInfo);
408     }
409     
410     /**
411      * Expands table entry to show version information.
412      *
413      */

414     private synchronized void expand() {
415         StateHandler.getInstance().addWait("TABLE-ENTRY-EXPAND");
416         
417         try {
418             this.deselectEntry();
419         
420             this.m_bExpanded = true;
421             this.m_expandIcon.setIcon(IconManager.getInstance().getIcon("16-tree-expanded.gif"));
422             this.remove(this.m_dateInfo);
423             this.addVersionInfo();
424             this.doLayout();
425             this.m_table.entryHeightChange(this);
426         } catch(Exception JavaDoc e) {
427             e.printStackTrace(System.err);
428         } finally {
429             StateHandler.getInstance().removeWait("TABLE-ENTRY-EXPAND");
430         }
431     }
432     
433     /**
434      * Collapses table entry to hide version information.
435      *
436      */

437     private synchronized void collapse() {
438         StateHandler.getInstance().addWait("TABLE-ENTRY-COLLAPSE");
439         
440         try {
441             this.deselectEntry();
442             
443             this.m_bExpanded = false;
444             this.m_expandIcon.setIcon(IconManager.getInstance().getIcon("16-tree-collapsed.gif"));
445             this.removeVersionInfo();
446             this.add(this.m_dateInfo);
447             this.doLayout();
448             this.m_table.entryHeightChange(this);
449             
450             this.selectEntry();
451             this.m_table.entrySelected(this);
452         } catch(Exception JavaDoc e) {
453             e.printStackTrace(System.err);
454         } finally {
455             StateHandler.getInstance().removeWait("TABLE-ENTRY-COLLAPSE");
456         }
457     }
458     
459     /**
460      * Returns the table view this entry is in.
461      *
462      * @return Table view
463      */

464     protected TableView getTableView() {
465         return this.m_table;
466     }
467     
468     /**
469      * Adds the version information to this entry.
470      *
471      */

472     private void addVersionInfo() {
473         int nVersionCount=4;
474         
475         VersionedVirtualFile vfLiveFile = (VersionedVirtualFile) this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
476         
477         if(vfLiveFile.isVersionable() && vfLiveFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfLiveFile).getLiveVersionPath()!=null) {
478             vfLiveFile = (VersionedVirtualFile) vfLiveFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfLiveFile).getLiveVersionPath() ).getResource();
479         }
480         
481         this.m_versionInfo = new JPanel();
482         this.m_versionInfo.setPreferredSize(new Dimension(190, (5*40)));
483         this.m_versionInfo.setSize(new Dimension(190, (5*40)));
484         this.m_versionInfo.setBackground(Color.WHITE);
485         
486         this.setPreferredSize( new Dimension(200, (40+((5)*40) )) );
487         this.setSize(new Dimension(200, (40+((5)*40) )));
488
489         VersionEntry pendingVersion = null;
490
491         if(vfLiveFile.hasPendingVersion()) {
492             pendingVersion = new VersionEntry(this, this.m_vfs, vfLiveFile.getPendingVersionPath(), "Draft version");
493             this.m_versionInfo.add( pendingVersion );
494         } else {
495             pendingVersion = new BlankVersionEntry("No draft version");
496             this.m_versionInfo.add( pendingVersion );
497         }
498         VersionEntry liveEntry = new VersionEntry(this, this.m_vfs, vfLiveFile.getFullPath(), "Published version");
499         this.m_versionInfo.add( liveEntry );
500
501         m_versionInnerPane = new JPanel();
502         m_versionInnerPane.setBackground(Color.WHITE);
503         FlowLayout fl2 = new FlowLayout(FlowLayout.LEFT);
504         fl2.setHgap(0);
505         fl2.setVgap(0);
506         m_versionInnerPane.setLayout(fl2);
507         
508         if(vfLiveFile.getHistoricalVersions().size()>0) {
509
510             Iterator itor = vfLiveFile.getHistoricalVersions().iterator();
511             while(itor.hasNext()) {
512                 String JavaDoc sHistoricalPath = (String JavaDoc)itor.next();
513                 m_versionInnerPane.add( new VersionEntry(this, this.m_vfs, sHistoricalPath, "Historic version (" + this.m_vfs.getVirtualFile(sHistoricalPath).getResource().getFileName() + ")", false));
514             }
515         } else {
516             m_versionInnerPane.add( new BlankVersionEntry("No historical versions") );
517         }
518         
519         m_versionInnerPane.setPreferredSize(new Dimension(190, (10 *40)));
520         
521         JScrollPane scroll = new JScrollPane(m_versionInnerPane);
522         scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
523         scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
524         JScrollBar vBar = new JScrollBar(JScrollBar.VERTICAL);
525         vBar.setUnitIncrement(20);
526         scroll.setVerticalScrollBar(vBar);
527         scroll.getViewport().setPreferredSize(new Dimension(140, (3*40)-20));
528         this.m_versionInfo.add(scroll);
529
530         this.m_versionInfo.revalidate();
531
532         this.add(this.m_versionInfo);
533         if(pendingVersion!=null && !(pendingVersion instanceof BlankVersionEntry)) {
534             pendingVersion.selectEntry();
535             this.m_table.entrySelected(pendingVersion);
536         } else {
537             liveEntry.selectEntry();
538             this.m_table.entrySelected(liveEntry);
539         }
540     }
541     
542     /**
543      * Removes the version information from this entry.
544      */

545     private void removeVersionInfo() {
546         this.remove(this.m_versionInfo);
547         this.setPreferredSize( new Dimension(200,50) );
548         this.setSize( new Dimension(200,50) );
549     }
550
551     /* (non-Javadoc)
552      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
553      */

554     public void mouseClicked(MouseEvent me) {
555         if(me.getClickCount()>1) {
556             VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource();
557             if(vfFile.isDirectory()) {
558                 if(vfFile.isVersionable() && vfFile.getState()==VirtualFile.STATE_PENDING && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) {
559                     this.m_table.openPathInTree(((VersionedVirtualFile)vfFile).getLiveVersionPath());
560                 } else {
561                     this.m_table.openPathInTree(this.m_sFilePath);
562                 }
563             } else if(vfFile.getFullPath().startsWith(HarmonisePaths.PATH_REPORTS_OUTPUT)) {
564                 EditorController.getInstance().preview(this.m_sFilePath, this.m_vfs);
565             } else if(vfFile.isLocked() && vfFile.getVFS().getVirtualFile(vfFile.getLockOwner())!=null && !vfFile.getVFS().getVirtualFile(vfFile.getLockOwner()).getResource().getFileName().trim().equals(vfFile.getVFS().getAuthentication().getUsername().trim())) {
566                 MessageHandler.getInstance().fireMessageEvent("Cannot open resource \"" + vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile) + "\" for editing, previewing instead.", MessageHandler.TYPE_INFORMATION);
567                 EditorController.getInstance().preview(this.m_sFilePath, this.m_vfs);
568             } else {
569                 EditorController.getInstance().open(this.m_sFilePath, this.m_vfs);
570             }
571         } else {
572             if ( this.m_vfs.getVirtualFile(this.m_sFilePath).getResource().isVersionable() && me.getSource() == this.m_expandIcon) {
573                 if(this.m_bExpanded) {
574                     this.collapse();
575                 } else {
576                     this.expand();
577                 }
578             } else if (!this.m_bExpanded && (me.getSource() == this
579                 || me.getSource() == this.m_dateInfo
580                 || me.getSource() == this.m_title
581                 || me.getSource() == this.m_bottomRightIcon
582                 || me.getSource() == this.m_topRightIcon) ) {
583                     if( this.getBackground()==m_selectedColor) {
584                         this.selectEntry();
585                     } else {
586                         this.selectEntry();
587                     }
588                     this.m_table.entrySelected(this);
589             }
590         }
591         if(me.getButton()==MouseEvent.BUTTON3) {
592             FileContextMenu menu = new FileContextMenu(this.m_sFilePath, this.m_vfs);
593             Point pt = me.getPoint();
594             menu.show(this, pt.x, pt.y);
595         }
596     }
597     
598     /**
599      * Returns the resource name.
600      *
601      * @return Name
602      */

603     public String JavaDoc getName() {
604         return this.m_sFilename;
605     }
606     
607     /**
608      * Returns the resource date.
609      *
610      * @return Date
611      */

612     public String JavaDoc getDate() {
613         return this.m_sFileDate;
614     }
615     
616     /**
617      * Returns the full path to the resource.
618      *
619      * @return Full path
620      */

621     public String JavaDoc getPath() {
622         return this.m_sFilePath;
623     }
624     
625     /**
626      * Returns the virtual file system for the resource.
627      *
628      * @return Virtual file system
629      */

630     public AbstractVirtualFileSystem getVFS() {
631         return this.m_vfs;
632     }
633     
634     /**
635      * Selects this entry.
636      *
637      */

638     protected void selectEntry() {
639         this.setBackground(m_selectedColor);
640         this.m_dateInfo.setBackground(m_selectedColor);
641     }
642     
643     /**
644      * Deselects this entry.
645      *
646      */

647     protected void deselectEntry() {
648         this.setBackground(Color.WHITE);
649         this.m_dateInfo.setBackground(Color.WHITE);
650         
651         if(this.m_versionInfo!=null) {
652             for(int i=0; i<this.m_versionInfo.getComponentCount(); i++) {
653                 if(this.m_versionInfo.getComponent(i) instanceof VersionEntry) {
654                     VersionEntry entry = (VersionEntry)this.m_versionInfo.getComponent(i);
655                     entry.deselectEntry();
656                 }
657             }
658             if(this.m_versionInnerPane!=null) {
659                 for(int i=0; i<this.m_versionInnerPane.getComponentCount(); i++) {
660                     if(this.m_versionInnerPane.getComponent(i) instanceof VersionEntry) {
661                         VersionEntry currentEntry = (VersionEntry)this.m_versionInnerPane.getComponent(i);
662                         currentEntry.deselectEntry();
663                     }
664                 }
665             }
666         }
667     }
668     
669     /**
670      * Deselects all version entries except this one given.
671      *
672      * @param entry Version entry
673      */

674     protected void deselectOtherEntries(VersionEntry entry) {
675         for(int i=0; i<this.m_versionInfo.getComponentCount(); i++) {
676             if(this.m_versionInfo.getComponent(i) instanceof VersionEntry) {
677                 VersionEntry currentEntry = (VersionEntry)this.m_versionInfo.getComponent(i);
678                 if(currentEntry!=entry) {
679                     currentEntry.deselectEntry();
680                 }
681             }
682         }
683         for(int i=0; i<this.m_versionInnerPane.getComponentCount(); i++) {
684             if(this.m_versionInnerPane.getComponent(i) instanceof VersionEntry) {
685                 VersionEntry currentEntry = (VersionEntry)this.m_versionInnerPane.getComponent(i);
686                 if(currentEntry!=entry) {
687                     currentEntry.deselectEntry();
688                 }
689             }
690         }
691     }
692
693     /* (non-Javadoc)
694      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
695      */

696     public void mouseEntered(MouseEvent arg0) {
697     }
698
699     /* (non-Javadoc)
700      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
701      */

702     public void mouseExited(MouseEvent arg0) {
703     }
704
705     /* (non-Javadoc)
706      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
707      */

708     public void mousePressed(MouseEvent arg0) {
709     }
710
711     /* (non-Javadoc)
712      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
713      */

714     public void mouseReleased(MouseEvent arg0) {
715     }
716
717     /* (non-Javadoc)
718      * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
719      */

720     public void virtualFileChanged(VirtualFileEvent vfe) {
721         if(vfe.getEventType()==VirtualFileEvent.FILE_CONTENT_CHANGED || vfe.getEventType()==VirtualFileEvent.FILE_METADATA_CHANGED) {
722             if(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource().isChanged()) {
723                 this.m_bottomRightIcon.setIcon( IconManager.getInstance().getIcon("16-command-sync-all.gif") );
724                 m_bottomRightIcon.setToolTipText("Resource has changed, ready to submit");
725                 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_vfs, this.m_sFilePath);
726                 ContextHandler.getInstance().fireContextEvent(ce);
727             }
728         } else if(vfe.getEventType()==VirtualFileEvent.FILE_SYNCHED) {
729             this.m_bottomRightIcon.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
730             m_bottomRightIcon.setToolTipText("");
731             ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_vfs, this.m_sFilePath);
732             ContextHandler.getInstance().fireContextEvent(ce);
733         } else if(vfe.getEventType()==VirtualFileEvent.FILE_CHANGES_DISCARDED) {
734             this.m_bottomRightIcon.setIcon( IconManager.getInstance().getIcon("16-blank.gif") );
735             m_bottomRightIcon.setToolTipText("");
736             this.m_bottomRightIcon.paintImmediately(this.m_bottomRightIcon.getBounds());
737             ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_vfs, this.m_sFilePath);
738             ContextHandler.getInstance().fireContextEvent(ce);
739         } else if(vfe.getEventType()==VirtualFileEvent.FILE_CHECKED_IN) {
740             
741         } else if(vfe.getEventType()==VirtualFileEvent.FILE_DELETED) {
742             this.m_bDeleted = true;
743         }
744         this.revalidate();
745         this.doLayout();
746     }
747
748     /* (non-Javadoc)
749      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
750      */

751     public void contextMessage(ContextEvent ce) {
752         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILENAME_DISPLAY) {
753             String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY");
754             if(sValue!=null && sValue.length()>0 && (sValue.equals("FILENAME") || this.m_sFilePath.startsWith( HarmonisePaths.PATH_USERS ))) {
755                 String JavaDoc sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
756                 this.m_title.setText( sFilename );
757             } else if(sValue!=null && sValue.length()>0 && sValue.equals("ID")) {
758                 String JavaDoc sFilename = this.m_vfs.getVirtualFileSystemView().getLogicalFileName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
759                 String JavaDoc sID = "";
760                 
761                 PropertyInstance propInst = this.m_vfs.getVirtualFile(this.m_sFilePath).getResource().getProperty(NamespaceType.OHRM.getURI(), "harmonise-id");
762                 if(propInst!=null && propInst.getValues().size()>0) {
763                     if(propInst.getValues().get(0) instanceof StringValue) {
764                         StringValue value = (StringValue) propInst.getValues().get(0);
765                         if(value.getValue()!=null && value.getValue().length()>0) {
766                             sID = value.getValue() + ": ";
767                         }
768                     }
769                 }
770                 this.m_title.setText( sID + sFilename );
771             } else {
772                 String JavaDoc sDisplayName = this.m_vfs.getVirtualFileSystemView().getDisplayName(this.m_vfs.getVirtualFile(this.m_sFilePath).getResource());
773                 this.m_title.setText( sDisplayName );
774             }
775             this.revalidate();
776             this.repaint();
777         }
778     }
779
780 }
781
Popular Tags