1 19 package org.openharmonise.him.window; 20 21 import java.awt.*; 22 import java.util.*; 23 import java.util.List ; 24 25 import javax.swing.*; 26 27 import org.openharmonise.him.*; 28 import org.openharmonise.him.authentication.*; 29 import org.openharmonise.him.configuration.*; 30 import org.openharmonise.him.context.StateHandler; 31 import org.openharmonise.him.displaycomponents.*; 32 import org.openharmonise.him.displaycomponents.table.*; 33 import org.openharmonise.him.files.*; 34 import org.openharmonise.him.harmonise.*; 35 import org.openharmonise.him.window.messages.*; 36 import org.openharmonise.localfilesystem.*; 37 import org.openharmonise.localversioningfilesystem.*; 38 import org.openharmonise.vfs.*; 39 import org.openharmonise.vfs.authentication.*; 40 import org.openharmonise.vfs.context.*; 41 import org.openharmonise.vfs.gui.*; 42 import org.openharmonise.vfs.servers.*; 43 import org.openharmonise.webdav.client.*; 44 45 46 50 public class DisplayController implements ContextListener { 51 52 private DisplayManager m_displayManager = null; 53 54 private AbstractAuthenticationStore m_authStore = null; 55 56 private ArrayList m_displayComponents = new ArrayList(3); 57 58 61 public DisplayController(DisplayManager displayManager) { 62 super(); 63 this.m_displayManager = displayManager; 64 this.setup(); 65 } 66 67 protected void shutdown() { 68 } 70 71 private boolean syncAllFiles() { 72 return this.syncAllFiles(false); 73 } 74 75 private boolean syncAllFiles(boolean bForceSync) { 76 boolean bShutDownOK = true; 77 78 String sValue = ConfigStore.getInstance().getPropertyValue("AUTO_SYNC_ON_EXIT"); 79 FilesSynchroniser filesSyncer = new FilesSynchroniser(); 80 if(sValue==null || bForceSync || sValue.equals("Yes")) { 81 StateHandler.getInstance().addWait("SYNC-ACTION"); 82 try { 83 Iterator itor = ServerList.getInstance().getServers().iterator(); 84 while (itor.hasNext()) { 85 Server element = (Server) itor.next(); 86 List aFiles = element.getVFS().getChangedVirtualFiles(); 87 if( !filesSyncer.syncFiles(aFiles) ) { 88 bShutDownOK = false; 89 } 90 } 91 } catch (Exception e) { 92 e.printStackTrace(System.err); 93 } finally { 94 StateHandler.getInstance().removeWait("SYNC-ACTION"); 95 } 96 } 97 98 return bShutDownOK; 99 } 100 101 private void setup() { 102 StateHandler.getInstance().addWait("DISPLAYMANAGER-SETUP"); 103 104 this.m_authStore = new HarmoniseAuthenticationStore(); 105 106 this.addDefaultTabs(); 107 108 this.m_displayManager.setVisible(true); 109 110 this.addServer(ServerList.getInstance().getHarmoniseServer()); 111 112 113 ContextHandler.getInstance().addListener(ContextType.CONTEXT_TABS, this); 114 ContextHandler.getInstance().addListener(ContextType.CONTEXT_SHUTDOWN, this); 115 ContextHandler.getInstance().addListener(ContextType.CONTEXT_SYNC_ALL_FILES_AND_SHUTDOWN, this); 116 117 StateHandler.getInstance().removeWait("DISPLAYMANAGER-SETUP"); 118 } 119 120 private void addDefaultTabs() { 121 SearchDisplayComponent searchDisplay = new SearchDisplayComponent(this.m_displayManager); 122 this.m_displayComponents.add(searchDisplay); 123 this.m_displayManager.addOutlookBar(searchDisplay.getTitle(), IconManager.getInstance().getIcon( searchDisplay.getIcon()), searchDisplay.getSearchTab()); 124 this.m_displayManager.setTable(searchDisplay.getTableView()); 125 } 126 127 private void addServer(Server server) { 128 if(server.getVFS() instanceof WebDAVFileSystem 129 || server.getVFS() instanceof LocalVersioningFileSystem 130 || server.getVFS() instanceof LocalFileSystem) { 131 132 String sRootPath = "/" + server.getVFS().getRootPathSegment() + "/"; 133 134 VirtualFile vfRoot = server.getVFS().getVirtualFile( sRootPath ).getResource(); 135 136 ContentDisplayComponent contentDisplay = new ContentDisplayComponent(this.m_displayManager); 137 138 String sPath = sRootPath + "Content/Documents"; 139 VirtualFile vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 140 if(vfFile!=null && vfFile.exists() ) { 141 contentDisplay.addServerAndPath(server, sPath); 142 } 143 this.m_displayManager.addOutlookBar(contentDisplay.getTitle(), IconManager.getInstance().getIcon( contentDisplay.getIcon()), contentDisplay.getTreeView()); 144 this.m_displayComponents.add(contentDisplay); 145 146 sPath = sRootPath + "Content/Assets"; 147 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 148 if(vfFile!=null && vfFile.exists() ) { 149 contentDisplay.addServerAndPath(server, sPath); 150 } 151 152 sPath = sRootPath + "Users"; 153 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 154 if(vfFile!=null && vfFile.exists() ) { 155 UserDisplayComponent userDisplay = new UserDisplayComponent(this.m_displayManager); 156 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 157 this.m_displayComponents.add(userDisplay); 158 List children = vfFile.getChildren(); 159 Iterator itor = children.iterator(); 160 while(itor.hasNext()) { 161 String sChildPath = (String )itor.next(); 162 VirtualFile vfChild = server.getVFS().getVirtualFile( sChildPath ).getResource(); 163 if(vfChild!=null && vfChild.exists() ) { 164 userDisplay.addServerAndPath(server, vfChild.getFullPath()); 165 } 166 } 167 } 168 169 sPath = sRootPath + "Newsletter"; 170 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 171 if(vfFile!=null && vfFile.exists() ) { 172 NewsletterDisplayComponent userDisplay = new NewsletterDisplayComponent(this.m_displayManager); 173 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 174 this.m_displayComponents.add(userDisplay); 175 List children = vfFile.getChildren(); 176 Iterator itor = children.iterator(); 177 while(itor.hasNext()) { 178 String sChildPath = (String )itor.next(); 179 VirtualFile vfChild = server.getVFS().getVirtualFile( sChildPath ).getResource(); 180 if(vfChild!=null && vfChild.exists() ) { 181 userDisplay.addServerAndPath(server, vfChild.getFullPath()); 182 } 183 } 184 } 185 186 sPath = sRootPath + "Metadata"; 187 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 188 if(vfFile!=null && vfFile.exists() ) { 189 MetadataDisplayComponent userDisplay = new MetadataDisplayComponent(this.m_displayManager); 190 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 191 this.m_displayComponents.add(userDisplay); 192 List children = vfFile.getChildren(); 193 Iterator itor = children.iterator(); 194 while(itor.hasNext()) { 195 String sChildPath = (String )itor.next(); 196 VirtualFile vfChild = server.getVFS().getVirtualFile( sChildPath ).getResource(); 197 if(vfChild!=null && vfChild.exists() ) { 198 userDisplay.addServerAndPath(server, vfChild.getFullPath()); 199 } 200 } 201 } 202 203 sPath = sRootPath + "Reports"; 204 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 205 if(vfFile!=null && vfFile.exists() ) { 206 SystemReportsDisplayComponent userDisplay = new SystemReportsDisplayComponent(this.m_displayManager); 207 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 208 this.m_displayComponents.add(userDisplay); 209 List children = vfFile.getChildren(); 210 Iterator itor = children.iterator(); 211 while(itor.hasNext()) { 212 String sChildPath = (String )itor.next(); 213 VirtualFile vfChild = server.getVFS().getVirtualFile( sChildPath ).getResource(); 214 if(vfChild!=null && vfChild.exists() ) { 215 userDisplay.addServerAndPath(server, vfChild.getFullPath()); 216 } 217 } 218 } 219 220 sPath = sRootPath + "Workflow"; 221 vfFile = server.getVFS().getVirtualFile( HarmonisePaths.PATH_WORKFLOW_PROPS ).getResource(); 222 if(vfFile!=null && vfFile.exists() ) { 223 WorkflowDisplayComponent userDisplay = new WorkflowDisplayComponent(this.m_displayManager); 224 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 225 this.m_displayComponents.add(userDisplay); 226 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_WORKFLOW_PROPS); 227 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_WORKFLOW_STAGES); 228 } 229 230 sPath = sRootPath + "Website"; 231 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 232 if(vfFile!=null && vfFile.exists() ) { 233 TemplatesDisplayComponent userDisplay = new TemplatesDisplayComponent(this.m_displayManager); 234 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 235 this.m_displayComponents.add(userDisplay); 236 List children = vfFile.getChildren(); 237 Iterator itor = children.iterator(); 238 while(itor.hasNext()) { 239 String sChildPath = (String )itor.next(); 240 VirtualFile vfChild = server.getVFS().getVirtualFile( sChildPath ).getResource(); 241 if(vfChild!=null && vfChild.exists() ) { 242 userDisplay.addServerAndPath(server, vfChild.getFullPath()); 243 } 244 } 245 } 246 247 sPath = sRootPath + "Archive"; 248 vfFile = server.getVFS().getVirtualFile( sPath ).getResource(); 249 if(vfFile!=null && vfFile.exists() ) { 250 ArchiveDisplayComponent userDisplay = new ArchiveDisplayComponent(this.m_displayManager); 251 this.m_displayManager.addOutlookBar(userDisplay.getTitle(), IconManager.getInstance().getIcon( userDisplay.getIcon()), userDisplay.getTreeView()); 252 this.m_displayComponents.add(userDisplay); 253 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Content"); 254 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Users"); 255 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Newsletter"); 256 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Metadata"); 257 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Reports"); 258 userDisplay.addServerAndPath(server, HarmonisePaths.PATH_ARCHIVE + "/Website"); 259 } 260 this.m_displayManager.setSelectedOutlookBar("Content"); 261 this.m_displayManager.setTable(contentDisplay.getTableView()); 262 } 263 } 264 265 private AbstractDisplayComponent getDisplayComponent(String sTitle) { 266 Iterator itor = this.m_displayComponents.iterator(); 267 while(itor.hasNext()) { 268 AbstractDisplayComponent comp = (AbstractDisplayComponent )itor.next(); 269 if( comp.getTitle().equals(sTitle) ) { 270 return comp; 271 } 272 } 273 return null; 274 } 275 276 279 public void contextMessage(ContextEvent ce) { 280 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_TABS) { 281 AbstractDisplayComponent comp = this.getDisplayComponent(ce.getMessage()); 282 if( comp instanceof AbstractTreeTableDisplayComponent) { 283 TableView table = ((AbstractTreeTableDisplayComponent)comp).getTableView(); 284 this.m_displayManager.setTable( table ); 285 ((TableLayout)table.getLayout()).reflowContainer(table); 286 table.getParent().validate(); 287 table.repaint(); 288 } else if( comp instanceof SearchDisplayComponent) { 289 TableView table = ((SearchDisplayComponent)comp).getTableView(); 290 this.m_displayManager.setTable( table ); 291 ((TableLayout)table.getLayout()).reflowContainer(table); 292 table.getParent().validate(); 293 table.repaint(); 294 } else { 295 JPanel tempPanel = new JPanel(); 296 tempPanel.setBackground(Color.WHITE); 297 this.m_displayManager.setTable(tempPanel); 298 } 299 } else if(ce.CONTEXT_TYPE==ContextType.CONTEXT_SHUTDOWN) { 300 String sValue = ConfigStore.getInstance().getPropertyValue("AUTO_SYNC_ON_EXIT"); 301 if(sValue==null || sValue.equals("Yes")) { 302 MessageHandler.getInstance().fireMessageEvent("Closing down and synchronising changes with the server", MessageHandler.TYPE_INFORMATION); 303 } else { 304 305 MessageHandler.getInstance().fireMessageEvent("Closing down", MessageHandler.TYPE_INFORMATION); 306 } 307 this.shutdown(); 308 } else if(ce.CONTEXT_TYPE==ContextType.CONTEXT_SYNC_ALL_FILES_AND_SHUTDOWN) { 309 if(ce.getMessage()!=null && ce.getMessage().trim().equals("FORCE_SYNC")) { 310 if( this.syncAllFiles(true) ) { 311 ContextEvent ceShutdown = new ContextEvent(ContextType.CONTEXT_SHUTDOWN); 312 ContextHandler.getInstance().fireContextEvent(ceShutdown); 313 } 314 } else { 315 if( this.syncAllFiles() ) { 316 ContextEvent ceShutdown = new ContextEvent(ContextType.CONTEXT_SHUTDOWN); 317 ContextHandler.getInstance().fireContextEvent(ceShutdown); 318 } 319 } 320 } 321 } 322 323 } 324
| Popular Tags
|