KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > swing > MetadataPanel


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 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 /**
35
36  * @author Matthew Large
37  *
38  */

39 public class MetadataPanel extends JPanel implements VirtualFileListener, ComponentListener, LayoutManager, ContextListener {
40
41     private AbstractVirtualFileSystem m_vfs = null;
42     private String JavaDoc m_sPath = null;
43     
44     private FileDetails m_fileDetails = null;
45             
46     private MetadataTabs m_tabs = null;
47
48     /**
49      *
50      */

51     public MetadataPanel() {
52         super(true);
53         this.setup();
54     }
55
56     /**
57      * @param arg0
58      */

59     private MetadataPanel(boolean arg0) {
60         super(arg0);
61     }
62
63     /**
64      * @param arg0
65      */

66     private MetadataPanel(LayoutManager arg0) {
67         super(arg0);
68     }
69
70     /**
71      * @param arg0
72      * @param arg1
73      */

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     /* (non-Javadoc)
113      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
114      */

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 JavaDoc 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 JavaDoc() {
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     /* (non-Javadoc)
191      * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
192      */

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     /* (non-Javadoc)
219      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
220      */

221     public void removeLayoutComponent(Component arg0) {
222     }
223
224     /* (non-Javadoc)
225      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
226      */

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     /* (non-Javadoc)
241      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
242      */

243     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
244     }
245
246     /* (non-Javadoc)
247      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
248      */

249     public Dimension minimumLayoutSize(Container arg0) {
250         return null;
251     }
252
253     /* (non-Javadoc)
254      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
255      */

256     public Dimension preferredLayoutSize(Container arg0) {
257         return null;
258     }
259
260     /* (non-Javadoc)
261      * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
262      */

263     public void componentHidden(ComponentEvent arg0) {
264     }
265
266     /* (non-Javadoc)
267      * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
268      */

269     public void componentMoved(ComponentEvent arg0) {
270     }
271
272     /* (non-Javadoc)
273      * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
274      */

275     public void componentResized(ComponentEvent arg0) {
276         this.doLayout();
277         this.validateTree();
278     }
279
280     /* (non-Javadoc)
281      * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
282      */

283     public void componentShown(ComponentEvent arg0) {
284     }
285
286 }
287
Popular Tags