1 19 20 package org.openharmonise.him.displaycomponents; 21 22 import java.util.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.*; 27 import org.openharmonise.him.context.StateHandler; 28 import org.openharmonise.him.displaycomponents.search.*; 29 import org.openharmonise.him.displaycomponents.table.*; 30 import org.openharmonise.him.window.*; 31 import org.openharmonise.him.window.messages.*; 32 import org.openharmonise.him.window.messages.builders.*; 33 import org.openharmonise.vfs.*; 34 import org.openharmonise.vfs.context.*; 35 import org.openharmonise.vfs.event.*; 36 import org.openharmonise.vfs.search.*; 37 import org.openharmonise.vfs.servers.ServerList; 38 import org.openharmonise.vfs.status.*; 39 40 41 48 public class SearchDisplayComponent extends AbstractTreeTableDisplayComponent implements ContextListener, VirtualFileListener { 49 50 53 private SearchTabPanel m_panel = null; 54 55 58 private TableView m_tableView = null; 59 60 63 private AbstractVirtualFileSystem m_SelectedFileVFS = null; 64 65 68 private String m_sSelectedFilePath = null; 69 70 73 private List m_aResults = null; 74 75 80 public SearchDisplayComponent(DisplayManager displayManager) { 81 super(displayManager); 82 this.setup(); 83 } 84 85 89 private void setup() { 90 ContextHandler.getInstance().addListener(ContextType.CONTEXT_TABS, this); 91 m_panel = new SearchTabPanel(this); 92 this.m_tableView = new TableView(this); 93 } 94 95 98 public String getIcon() { 99 return "16-command-search.gif"; 100 } 101 102 105 public String getTitle() { 106 return "Search"; 107 } 108 109 114 public JPanel getSearchTab() { 115 return this.m_panel; 116 } 117 118 121 public void virtualFileChanged(VirtualFileEvent vfe) { 122 if(vfe.getEventType()==VirtualFileEvent.FILE_DELETED) { 123 if(this.m_aResults!=null) { 124 this.m_aResults.remove(vfe.getPath()); 125 } 126 AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 127 Iterator itor = this.m_aResults.iterator(); 128 while (itor.hasNext()) { 129 String sPath = (String ) itor.next(); 130 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 131 if(vfFile!=null) { 132 vfFile.addVirtualFileListener(this); 133 if(vfFile.isVersionable() && ((VersionedVirtualFile)vfFile).hasPendingVersion()) { 134 String sPendingPath = ((VersionedVirtualFile)vfFile).getPendingVersionPath(); 135 VirtualFile vfPending = vfFile.getVFS().getVirtualFile(sPendingPath).getResource(); 136 if(vfPending!=null) { 137 vfPending.addVirtualFileListener(this); 138 } 139 } 140 } 141 } 142 this.m_tableView.setResources(ServerList.getInstance().getHarmoniseServer().getVFS(), this.m_aResults); 143 } else if(vfe.getEventType()==VirtualFileEvent.FILE_SYNCHED || vfe.getEventType()==VirtualFileEvent.FILE_CHECKED_IN) { 144 AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 145 Iterator itor = this.m_aResults.iterator(); 146 while (itor.hasNext()) { 147 String sPath = (String ) itor.next(); 148 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 149 if(vfFile!=null) { 150 vfFile.addVirtualFileListener(this); 151 if(vfFile.isVersionable() && ((VersionedVirtualFile)vfFile).hasPendingVersion()) { 152 String sPendingPath = ((VersionedVirtualFile)vfFile).getPendingVersionPath(); 153 VirtualFile vfPending = vfFile.getVFS().getVirtualFile(sPendingPath).getResource(); 154 if(vfPending!=null) { 155 vfPending.addVirtualFileListener(this); 156 } 157 } 158 } 159 } 160 this.m_tableView.setResources(ServerList.getInstance().getHarmoniseServer().getVFS(), this.m_aResults); 161 } 162 } 163 164 169 public void doSearch(Query query) { 170 this.m_displayManager.hideMetadata(); 171 this.clearSearchResults(); 172 173 AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 174 StatusData status = new VFSStatus(); 175 try { 176 ResourceListStatusWrapper statusWrapper = vfs.search(query); 177 status = statusWrapper.getStatus(); 178 if(status.isOK()) { 179 this.m_aResults = statusWrapper.getResources(); 180 } 181 } catch (Exception e) { 182 MessageHandler.getInstance().fireMessageEvent("Search failed, there was a problem contacting the server.", MessageHandler.TYPE_ERROR); 183 e.printStackTrace(); 184 } 185 186 if(status.isOK()) { 187 Iterator itor = this.m_aResults.iterator(); 188 while (itor.hasNext()) { 189 String sPath = (String ) itor.next(); 190 try { 191 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 192 if(vfFile!=null) { 193 vfFile.addVirtualFileListener(this); 194 if(vfFile.isVersionable() && ((VersionedVirtualFile)vfFile).hasPendingVersion()) { 195 String sPendingPath = ((VersionedVirtualFile)vfFile).getPendingVersionPath(); 196 VirtualFile vfPending = vfFile.getVFS().getVirtualFile(sPendingPath).getResource(); 197 if(vfPending!=null) { 198 vfPending.addVirtualFileListener(this); 199 } 200 } 201 } 202 } catch (Exception e) { 203 e.printStackTrace(); 204 } 205 } 206 this.m_tableView.setResources(ServerList.getInstance().getHarmoniseServer().getVFS(), this.m_aResults); 207 } 208 209 VFSMessageBuilder.getInstance().fireMessage("ACTION_SEARCH", status); 210 } 211 212 216 public void clearSearchResults() { 217 this.m_aResults = null; 218 this.m_SelectedFileVFS = null; 219 this.m_sSelectedFilePath = null; 220 this.m_tableView.clearTable(); 221 this.m_displayManager.clearMetadataPanel(); 222 } 223 224 228 public TableView getTableView() { 229 return this.m_tableView; 230 } 231 232 235 public void virtualFileSelected(AbstractVirtualFileSystem vfs, String sPath) { 236 237 } 238 239 242 public void fileSelection(TableEntry entry) { 243 StateHandler.getInstance().addWait("CONTENT-FILE-SELECTION"); 244 try { 245 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, entry.getVFS(), entry.getPath()); 246 ContextHandler.getInstance().fireContextEvent(ce); 247 this.m_SelectedFileVFS = entry.getVFS(); 248 this.m_sSelectedFilePath = entry.getPath(); 249 this.m_displayManager.openMetadata(); 250 this.m_displayManager.scrollTableTo( entry.getLocation().x ); 251 } catch (Exception e) { 252 e.printStackTrace(System.err); 253 } finally { 254 StateHandler.getInstance().removeWait("CONTENT-FILE-SELECTION"); 255 } 256 } 257 258 261 public void fileSelection(VersionEntry entry) { 262 StateHandler.getInstance().addWait("CONTENT-FILE-SELECTION"); 263 try { 264 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILES, null, entry.getVFS(), entry.getPath()); 265 ContextHandler.getInstance().fireContextEvent(ce); 266 this.m_SelectedFileVFS = entry.getVFS(); 267 this.m_sSelectedFilePath = entry.getPath(); 268 this.m_displayManager.openMetadata(); 269 this.m_displayManager.scrollTableTo( entry.getParentTableEntry().getLocation().x ); 270 } catch (Exception e) { 271 e.printStackTrace(System.err); 272 } finally { 273 StateHandler.getInstance().removeWait("CONTENT-FILE-SELECTION"); 274 } 275 } 276 277 280 public void contextMessage(ContextEvent ce) { 281 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_TABS && ce.getMessage().equalsIgnoreCase(this.getTitle())) { 282 if(this.m_SelectedFileVFS!=null && this.m_sSelectedFilePath!=null) { 283 ContextEvent ce2 = new ContextEvent(ContextType.CONTEXT_FILES, null, this.m_SelectedFileVFS, this.m_sSelectedFilePath); 284 ContextHandler.getInstance().fireContextEvent(ce2); 285 this.m_displayManager.openMetadata(); 286 } else { 287 this.m_displayManager.hideMetadata(); 288 } 289 } 290 } 291 292 } 293 | Popular Tags |