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.window;
020:
021: import java.awt.*;
022: import java.util.*;
023: import java.util.List;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.him.*;
028: import org.openharmonise.him.authentication.*;
029: import org.openharmonise.him.configuration.*;
030: import org.openharmonise.him.context.StateHandler;
031: import org.openharmonise.him.displaycomponents.*;
032: import org.openharmonise.him.displaycomponents.table.*;
033: import org.openharmonise.him.files.*;
034: import org.openharmonise.him.harmonise.*;
035: import org.openharmonise.him.window.messages.*;
036: import org.openharmonise.localfilesystem.*;
037: import org.openharmonise.localversioningfilesystem.*;
038: import org.openharmonise.vfs.*;
039: import org.openharmonise.vfs.authentication.*;
040: import org.openharmonise.vfs.context.*;
041: import org.openharmonise.vfs.gui.*;
042: import org.openharmonise.vfs.servers.*;
043: import org.openharmonise.webdav.client.*;
044:
045: /**
046: * @author Matthew Large
047: *
048: */
049: public class DisplayController implements ContextListener {
050:
051: private DisplayManager m_displayManager = null;
052:
053: private AbstractAuthenticationStore m_authStore = null;
054:
055: private ArrayList m_displayComponents = new ArrayList(3);
056:
057: /**
058: *
059: */
060: public DisplayController(DisplayManager displayManager) {
061: super ();
062: this .m_displayManager = displayManager;
063: this .setup();
064: }
065:
066: protected void shutdown() {
067: //NO-OP
068: }
069:
070: private boolean syncAllFiles() {
071: return this .syncAllFiles(false);
072: }
073:
074: private boolean syncAllFiles(boolean bForceSync) {
075: boolean bShutDownOK = true;
076:
077: String sValue = ConfigStore.getInstance().getPropertyValue(
078: "AUTO_SYNC_ON_EXIT");
079: FilesSynchroniser filesSyncer = new FilesSynchroniser();
080: if (sValue == null || bForceSync || sValue.equals("Yes")) {
081: StateHandler.getInstance().addWait("SYNC-ACTION");
082: try {
083: Iterator itor = ServerList.getInstance().getServers()
084: .iterator();
085: while (itor.hasNext()) {
086: Server element = (Server) itor.next();
087: List aFiles = element.getVFS()
088: .getChangedVirtualFiles();
089: if (!filesSyncer.syncFiles(aFiles)) {
090: bShutDownOK = false;
091: }
092: }
093: } catch (Exception e) {
094: e.printStackTrace(System.err);
095: } finally {
096: StateHandler.getInstance().removeWait("SYNC-ACTION");
097: }
098: }
099:
100: return bShutDownOK;
101: }
102:
103: private void setup() {
104: StateHandler.getInstance().addWait("DISPLAYMANAGER-SETUP");
105:
106: this .m_authStore = new HarmoniseAuthenticationStore();
107:
108: this .addDefaultTabs();
109:
110: this .m_displayManager.setVisible(true);
111:
112: this .addServer(ServerList.getInstance().getHarmoniseServer());
113:
114: ContextHandler.getInstance().addListener(
115: ContextType.CONTEXT_TABS, this );
116: ContextHandler.getInstance().addListener(
117: ContextType.CONTEXT_SHUTDOWN, this );
118: ContextHandler.getInstance().addListener(
119: ContextType.CONTEXT_SYNC_ALL_FILES_AND_SHUTDOWN, this );
120:
121: StateHandler.getInstance().removeWait("DISPLAYMANAGER-SETUP");
122: }
123:
124: private void addDefaultTabs() {
125: SearchDisplayComponent searchDisplay = new SearchDisplayComponent(
126: this .m_displayManager);
127: this .m_displayComponents.add(searchDisplay);
128: this .m_displayManager.addOutlookBar(searchDisplay.getTitle(),
129: IconManager.getInstance().getIcon(
130: searchDisplay.getIcon()), searchDisplay
131: .getSearchTab());
132: this .m_displayManager.setTable(searchDisplay.getTableView());
133: }
134:
135: private void addServer(Server server) {
136: if (server.getVFS() instanceof WebDAVFileSystem
137: || server.getVFS() instanceof LocalVersioningFileSystem
138: || server.getVFS() instanceof LocalFileSystem) {
139:
140: String sRootPath = "/"
141: + server.getVFS().getRootPathSegment() + "/";
142:
143: VirtualFile vfRoot = server.getVFS().getVirtualFile(
144: sRootPath).getResource();
145:
146: ContentDisplayComponent contentDisplay = new ContentDisplayComponent(
147: this .m_displayManager);
148:
149: String sPath = sRootPath + "Content/Documents";
150: VirtualFile vfFile = server.getVFS().getVirtualFile(sPath)
151: .getResource();
152: if (vfFile != null && vfFile.exists()) {
153: contentDisplay.addServerAndPath(server, sPath);
154: }
155: this .m_displayManager.addOutlookBar(contentDisplay
156: .getTitle(), IconManager.getInstance().getIcon(
157: contentDisplay.getIcon()), contentDisplay
158: .getTreeView());
159: this .m_displayComponents.add(contentDisplay);
160:
161: sPath = sRootPath + "Content/Assets";
162: vfFile = server.getVFS().getVirtualFile(sPath)
163: .getResource();
164: if (vfFile != null && vfFile.exists()) {
165: contentDisplay.addServerAndPath(server, sPath);
166: }
167:
168: sPath = sRootPath + "Users";
169: vfFile = server.getVFS().getVirtualFile(sPath)
170: .getResource();
171: if (vfFile != null && vfFile.exists()) {
172: UserDisplayComponent userDisplay = new UserDisplayComponent(
173: this .m_displayManager);
174: this .m_displayManager.addOutlookBar(userDisplay
175: .getTitle(), IconManager.getInstance().getIcon(
176: userDisplay.getIcon()), userDisplay
177: .getTreeView());
178: this .m_displayComponents.add(userDisplay);
179: List children = vfFile.getChildren();
180: Iterator itor = children.iterator();
181: while (itor.hasNext()) {
182: String sChildPath = (String) itor.next();
183: VirtualFile vfChild = server.getVFS()
184: .getVirtualFile(sChildPath).getResource();
185: if (vfChild != null && vfChild.exists()) {
186: userDisplay.addServerAndPath(server, vfChild
187: .getFullPath());
188: }
189: }
190: }
191:
192: sPath = sRootPath + "Newsletter";
193: vfFile = server.getVFS().getVirtualFile(sPath)
194: .getResource();
195: if (vfFile != null && vfFile.exists()) {
196: NewsletterDisplayComponent userDisplay = new NewsletterDisplayComponent(
197: this .m_displayManager);
198: this .m_displayManager.addOutlookBar(userDisplay
199: .getTitle(), IconManager.getInstance().getIcon(
200: userDisplay.getIcon()), userDisplay
201: .getTreeView());
202: this .m_displayComponents.add(userDisplay);
203: List children = vfFile.getChildren();
204: Iterator itor = children.iterator();
205: while (itor.hasNext()) {
206: String sChildPath = (String) itor.next();
207: VirtualFile vfChild = server.getVFS()
208: .getVirtualFile(sChildPath).getResource();
209: if (vfChild != null && vfChild.exists()) {
210: userDisplay.addServerAndPath(server, vfChild
211: .getFullPath());
212: }
213: }
214: }
215:
216: sPath = sRootPath + "Metadata";
217: vfFile = server.getVFS().getVirtualFile(sPath)
218: .getResource();
219: if (vfFile != null && vfFile.exists()) {
220: MetadataDisplayComponent userDisplay = new MetadataDisplayComponent(
221: this .m_displayManager);
222: this .m_displayManager.addOutlookBar(userDisplay
223: .getTitle(), IconManager.getInstance().getIcon(
224: userDisplay.getIcon()), userDisplay
225: .getTreeView());
226: this .m_displayComponents.add(userDisplay);
227: List children = vfFile.getChildren();
228: Iterator itor = children.iterator();
229: while (itor.hasNext()) {
230: String sChildPath = (String) itor.next();
231: VirtualFile vfChild = server.getVFS()
232: .getVirtualFile(sChildPath).getResource();
233: if (vfChild != null && vfChild.exists()) {
234: userDisplay.addServerAndPath(server, vfChild
235: .getFullPath());
236: }
237: }
238: }
239:
240: sPath = sRootPath + "Reports";
241: vfFile = server.getVFS().getVirtualFile(sPath)
242: .getResource();
243: if (vfFile != null && vfFile.exists()) {
244: SystemReportsDisplayComponent userDisplay = new SystemReportsDisplayComponent(
245: this .m_displayManager);
246: this .m_displayManager.addOutlookBar(userDisplay
247: .getTitle(), IconManager.getInstance().getIcon(
248: userDisplay.getIcon()), userDisplay
249: .getTreeView());
250: this .m_displayComponents.add(userDisplay);
251: List children = vfFile.getChildren();
252: Iterator itor = children.iterator();
253: while (itor.hasNext()) {
254: String sChildPath = (String) itor.next();
255: VirtualFile vfChild = server.getVFS()
256: .getVirtualFile(sChildPath).getResource();
257: if (vfChild != null && vfChild.exists()) {
258: userDisplay.addServerAndPath(server, vfChild
259: .getFullPath());
260: }
261: }
262: }
263:
264: sPath = sRootPath + "Workflow";
265: vfFile = server.getVFS().getVirtualFile(
266: HarmonisePaths.PATH_WORKFLOW_PROPS).getResource();
267: if (vfFile != null && vfFile.exists()) {
268: WorkflowDisplayComponent userDisplay = new WorkflowDisplayComponent(
269: this .m_displayManager);
270: this .m_displayManager.addOutlookBar(userDisplay
271: .getTitle(), IconManager.getInstance().getIcon(
272: userDisplay.getIcon()), userDisplay
273: .getTreeView());
274: this .m_displayComponents.add(userDisplay);
275: userDisplay.addServerAndPath(server,
276: HarmonisePaths.PATH_WORKFLOW_PROPS);
277: userDisplay.addServerAndPath(server,
278: HarmonisePaths.PATH_WORKFLOW_STAGES);
279: }
280:
281: sPath = sRootPath + "Website";
282: vfFile = server.getVFS().getVirtualFile(sPath)
283: .getResource();
284: if (vfFile != null && vfFile.exists()) {
285: TemplatesDisplayComponent userDisplay = new TemplatesDisplayComponent(
286: this .m_displayManager);
287: this .m_displayManager.addOutlookBar(userDisplay
288: .getTitle(), IconManager.getInstance().getIcon(
289: userDisplay.getIcon()), userDisplay
290: .getTreeView());
291: this .m_displayComponents.add(userDisplay);
292: List children = vfFile.getChildren();
293: Iterator itor = children.iterator();
294: while (itor.hasNext()) {
295: String sChildPath = (String) itor.next();
296: VirtualFile vfChild = server.getVFS()
297: .getVirtualFile(sChildPath).getResource();
298: if (vfChild != null && vfChild.exists()) {
299: userDisplay.addServerAndPath(server, vfChild
300: .getFullPath());
301: }
302: }
303: }
304:
305: sPath = sRootPath + "Archive";
306: vfFile = server.getVFS().getVirtualFile(sPath)
307: .getResource();
308: if (vfFile != null && vfFile.exists()) {
309: ArchiveDisplayComponent userDisplay = new ArchiveDisplayComponent(
310: this .m_displayManager);
311: this .m_displayManager.addOutlookBar(userDisplay
312: .getTitle(), IconManager.getInstance().getIcon(
313: userDisplay.getIcon()), userDisplay
314: .getTreeView());
315: this .m_displayComponents.add(userDisplay);
316: userDisplay.addServerAndPath(server,
317: HarmonisePaths.PATH_ARCHIVE + "/Content");
318: userDisplay.addServerAndPath(server,
319: HarmonisePaths.PATH_ARCHIVE + "/Users");
320: userDisplay.addServerAndPath(server,
321: HarmonisePaths.PATH_ARCHIVE + "/Newsletter");
322: userDisplay.addServerAndPath(server,
323: HarmonisePaths.PATH_ARCHIVE + "/Metadata");
324: userDisplay.addServerAndPath(server,
325: HarmonisePaths.PATH_ARCHIVE + "/Reports");
326: userDisplay.addServerAndPath(server,
327: HarmonisePaths.PATH_ARCHIVE + "/Website");
328: }
329: this .m_displayManager.setSelectedOutlookBar("Content");
330: this .m_displayManager.setTable(contentDisplay
331: .getTableView());
332: }
333: }
334:
335: private AbstractDisplayComponent getDisplayComponent(String sTitle) {
336: Iterator itor = this .m_displayComponents.iterator();
337: while (itor.hasNext()) {
338: AbstractDisplayComponent comp = (AbstractDisplayComponent) itor
339: .next();
340: if (comp.getTitle().equals(sTitle)) {
341: return comp;
342: }
343: }
344: return null;
345: }
346:
347: /* (non-Javadoc)
348: * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
349: */
350: public void contextMessage(ContextEvent ce) {
351: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_TABS) {
352: AbstractDisplayComponent comp = this .getDisplayComponent(ce
353: .getMessage());
354: if (comp instanceof AbstractTreeTableDisplayComponent) {
355: TableView table = ((AbstractTreeTableDisplayComponent) comp)
356: .getTableView();
357: this .m_displayManager.setTable(table);
358: ((TableLayout) table.getLayout())
359: .reflowContainer(table);
360: table.getParent().validate();
361: table.repaint();
362: } else if (comp instanceof SearchDisplayComponent) {
363: TableView table = ((SearchDisplayComponent) comp)
364: .getTableView();
365: this .m_displayManager.setTable(table);
366: ((TableLayout) table.getLayout())
367: .reflowContainer(table);
368: table.getParent().validate();
369: table.repaint();
370: } else {
371: JPanel tempPanel = new JPanel();
372: tempPanel.setBackground(Color.WHITE);
373: this .m_displayManager.setTable(tempPanel);
374: }
375: } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_SHUTDOWN) {
376: String sValue = ConfigStore.getInstance().getPropertyValue(
377: "AUTO_SYNC_ON_EXIT");
378: if (sValue == null || sValue.equals("Yes")) {
379: MessageHandler
380: .getInstance()
381: .fireMessageEvent(
382: "Closing down and synchronising changes with the server",
383: MessageHandler.TYPE_INFORMATION);
384: } else {
385:
386: MessageHandler.getInstance()
387: .fireMessageEvent("Closing down",
388: MessageHandler.TYPE_INFORMATION);
389: }
390: this .shutdown();
391: } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_SYNC_ALL_FILES_AND_SHUTDOWN) {
392: if (ce.getMessage() != null
393: && ce.getMessage().trim().equals("FORCE_SYNC")) {
394: if (this .syncAllFiles(true)) {
395: ContextEvent ceShutdown = new ContextEvent(
396: ContextType.CONTEXT_SHUTDOWN);
397: ContextHandler.getInstance().fireContextEvent(
398: ceShutdown);
399: }
400: } else {
401: if (this .syncAllFiles()) {
402: ContextEvent ceShutdown = new ContextEvent(
403: ContextType.CONTEXT_SHUTDOWN);
404: ContextHandler.getInstance().fireContextEvent(
405: ceShutdown);
406: }
407: }
408: }
409: }
410:
411: }
|