001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.metadata.swing;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.him.*;
027: import org.openharmonise.him.harmonise.*;
028: import org.openharmonise.vfs.*;
029: import org.openharmonise.vfs.context.*;
030: import org.openharmonise.vfs.event.*;
031: import org.openharmonise.vfs.servers.ServerList;
032:
033: /**
034:
035: * @author Matthew Large
036: *
037: */
038: public class MetadataPanel extends JPanel implements
039: VirtualFileListener, ComponentListener, LayoutManager,
040: ContextListener {
041:
042: private AbstractVirtualFileSystem m_vfs = null;
043: private String m_sPath = null;
044:
045: private FileDetails m_fileDetails = null;
046:
047: private MetadataTabs m_tabs = null;
048:
049: /**
050: *
051: */
052: public MetadataPanel() {
053: super (true);
054: this .setup();
055: }
056:
057: /**
058: * @param arg0
059: */
060: private MetadataPanel(boolean arg0) {
061: super (arg0);
062: }
063:
064: /**
065: * @param arg0
066: */
067: private MetadataPanel(LayoutManager arg0) {
068: super (arg0);
069: }
070:
071: /**
072: * @param arg0
073: * @param arg1
074: */
075: private MetadataPanel(LayoutManager arg0, boolean arg1) {
076: super (arg0, arg1);
077: }
078:
079: private void setup() {
080: this .setPreferredSize(new Dimension(10, 10));
081: this .setLayout(this );
082: ContextHandler.getInstance().addListener(
083: ContextType.CONTEXT_FILES, this );
084: ContextHandler.getInstance().addListener(
085: ContextType.CONTEXT_CLEAR_METADATA, this );
086:
087: }
088:
089: public void clearMetadataPanel() {
090: this .clearPanel();
091: this .validate();
092: this .repaint();
093: }
094:
095: private void clearPanel() {
096: if (this .m_vfs != null && this .m_sPath != null) {
097: VirtualFile vfFile = this .m_vfs
098: .getVirtualFile(this .m_sPath).getResource();
099: if (vfFile != null) {
100: vfFile.removeVirtualFileListener(this );
101: }
102: }
103:
104: if (this .m_fileDetails != null) {
105: this .m_fileDetails.clearToDestroy();
106: }
107: if (this .m_tabs != null) {
108: this .m_tabs.clearToDestroy();
109: }
110:
111: this .m_vfs = null;
112: this .m_sPath = null;
113: this .removeAll();
114: }
115:
116: /* (non-Javadoc)
117: * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
118: */
119: public void contextMessage(ContextEvent ce) {
120: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_FILES
121: && (this .m_vfs == null || this .m_sPath == null
122: || this .m_vfs != ce.getVFS() || !this .m_sPath
123: .equals(ce.getPath()))) {
124:
125: String sSelectedTabTitle = null;
126: if (this .m_tabs != null) {
127: sSelectedTabTitle = this .m_tabs.getSelectedTabTitle();
128: }
129:
130: this .clearPanel();
131:
132: this .m_vfs = ce.getVFS();
133: this .m_sPath = ce.getPath();
134:
135: VirtualFile vfFile = this .m_vfs
136: .getVirtualFile(this .m_sPath).getResource();
137:
138: if (vfFile != null) {
139: vfFile.addVirtualFileListener(this );
140:
141: m_fileDetails = new FileDetails(this .m_vfs,
142: this .m_sPath);
143: this .add(m_fileDetails);
144:
145: m_tabs = new MetadataTabs(this .m_vfs, this .m_sPath);
146: this .add(m_tabs);
147:
148: this .checkEnabled();
149:
150: this .m_tabs.setSelectedTab(sSelectedTabTitle);
151: } else {
152: this .clearPanel();
153: this .m_vfs = null;
154: this .m_sPath = null;
155: }
156:
157: this .validate();
158: this .repaint();
159: } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_CLEAR_METADATA) {
160: SwingUtilities.invokeLater(new Runnable() {
161: public void run() {
162: clear();
163: }
164: });
165: }
166: }
167:
168: private void clear() {
169: this .m_vfs = null;
170: this .m_sPath = null;
171: this .removeAll();
172: this .revalidate();
173: this .getParent().repaint();
174: }
175:
176: private void checkEnabled() {
177: VirtualFile vfFile = this .m_vfs.getVirtualFile(this .m_sPath)
178: .getResource();
179: if (vfFile.isVersionable()
180: && vfFile.getState().equals(VirtualFile.STATE_LIVE)
181: && ((VersionedVirtualFile) vfFile).hasPendingVersion()) {
182: this .m_tabs.setEnabled(false);
183: } else if (vfFile.getFullPath().startsWith(
184: HarmonisePaths.PATH_ARCHIVE)) {
185: this .m_tabs.setEnabled(false);
186: } else if (vfFile.getState().equals(
187: VirtualFile.STATE_HISTORICAL)) {
188: this .m_tabs.setEnabled(false);
189: } else if (vfFile.isLocked()
190: && ServerList.getInstance().getHarmoniseServer()
191: .getVFS().getVirtualFile(vfFile.getLockOwner())
192: .getResource() != null
193: && !ServerList.getInstance().getHarmoniseServer()
194: .getVFS().getVirtualFile(vfFile.getLockOwner())
195: .getResource().getFileName().trim().equals(
196: ServerList.getInstance()
197: .getHarmoniseServer().getVFS()
198: .getAuthentication()
199: .getUsername().trim())) {
200: this .m_tabs.setEnabled(false);
201: } else if (vfFile.isLocked()
202: && ServerList.getInstance().getHarmoniseServer()
203: .getVFS().getVirtualFile(vfFile.getLockOwner())
204: .getResource() == null) {
205: this .m_tabs.setEnabled(false);
206: } else if (!vfFile.getAllowedMethods().contains(
207: VirtualFile.METHOD_SYNC)) {
208: this .m_tabs.setEnabled(false);
209: } else {
210: this .m_tabs.setEnabled(true);
211: }
212: }
213:
214: /* (non-Javadoc)
215: * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
216: */
217: public void virtualFileChanged(VirtualFileEvent vfe) {
218: if (vfe.getEventType().equals(
219: VirtualFileEvent.FILE_CHANGES_DISCARDED)) {
220: if (this .m_fileDetails != null) {
221: this .m_fileDetails.clearToDestroy();
222: }
223:
224: this .removeAll();
225: this .m_vfs = vfe.getVFS();
226: this .m_sPath = vfe.getPath();
227: m_fileDetails = new FileDetails(this .m_vfs, this .m_sPath);
228: this .add(m_fileDetails);
229:
230: m_tabs = new MetadataTabs(this .m_vfs, this .m_sPath);
231: this .add(m_tabs);
232: this .validate();
233: this .repaint();
234: } else if (vfe.getEventType().equals(
235: VirtualFileEvent.FILE_SYNCHED)) {
236: this .clear();
237: } else if (vfe.getEventType().equals(
238: VirtualFileEvent.FILE_CHECKED_IN)) {
239: this .clear();
240: } else if (vfe.getEventType().equals(
241: VirtualFileEvent.FILE_DELETED)) {
242: this .clear();
243: }
244: }
245:
246: /* (non-Javadoc)
247: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
248: */
249: public void removeLayoutComponent(Component arg0) {
250: }
251:
252: /* (non-Javadoc)
253: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
254: */
255: public void layoutContainer(Container arg0) {
256: if (m_fileDetails != null) {
257: m_fileDetails.setLocation(0, 0);
258: m_fileDetails.setSize(this .getParent().getParent()
259: .getWidth(), 50);
260: }
261:
262: if (m_tabs != null) {
263: m_tabs.setLocation(1, 50);
264: m_tabs.setSize(this .getParent().getParent().getWidth(),
265: this .getParent().getParent().getParent()
266: .getHeight() - 55);
267: }
268: this .setPreferredSize(new Dimension(this .getParent()
269: .getParent().getWidth(), this .getParent().getParent()
270: .getParent().getHeight() - 20));
271: }
272:
273: /* (non-Javadoc)
274: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
275: */
276: public void addLayoutComponent(String arg0, Component arg1) {
277: }
278:
279: /* (non-Javadoc)
280: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
281: */
282: public Dimension minimumLayoutSize(Container arg0) {
283: return null;
284: }
285:
286: /* (non-Javadoc)
287: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
288: */
289: public Dimension preferredLayoutSize(Container arg0) {
290: return null;
291: }
292:
293: /* (non-Javadoc)
294: * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
295: */
296: public void componentHidden(ComponentEvent arg0) {
297: }
298:
299: /* (non-Javadoc)
300: * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
301: */
302: public void componentMoved(ComponentEvent arg0) {
303: }
304:
305: /* (non-Javadoc)
306: * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
307: */
308: public void componentResized(ComponentEvent arg0) {
309: this .doLayout();
310: this .validateTree();
311: }
312:
313: /* (non-Javadoc)
314: * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
315: */
316: public void componentShown(ComponentEvent arg0) {
317: }
318:
319: }
|