Author: fmancinelli Date: 2007-11-15 15:09:57 +0100 (Thu, 15 Nov 2007) New Revision: 5883
Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndex.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/dialogs/OpenPageDialog.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/AbstractXWikiConnection.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiCachedConnection.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPage.java xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java Log: * Refactored page indexer. Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndex.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndex.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndex.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -46,12 +46,12 @@ return instance; } - public void addPage(IXWikiPage page) + public synchronized void addPage(IXWikiPage page) { pages.add(page); } - public void removePage(IXWikiPage page) + public synchronized void removePage(IXWikiPage page) { pages.remove(page); } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -1,6 +1,8 @@ package org.xwiki.eclipse; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -11,17 +13,20 @@ import org.xwiki.eclipse.model.IXWikiSpace; import org.xwiki.plugins.eclipse.XWikiEclipsePlugin; -public class XWikiEclipsePageIndexer +public class XWikiEclipsePageIndexer implements IXWikiEclipseEventListener { private static XWikiEclipsePageIndexer instance; - private Job indexer; - + + private Map<IXWikiConnection, Job> connectionToIndexerMapping; + private class IndexerJob extends Job { + private IXWikiConnection connection; - public IndexerJob(String name) + public IndexerJob(IXWikiConnection connection) { - super(name); + super("Connection page indexer"); + this.connection = connection; } @Override @@ -29,39 +34,36 @@ { try { XWikiEclipsePageIndex pageIndex = XWikiEclipsePageIndex.getDefault(); - - monitor.beginTask(String.format("Indexing connections..."), - XWikiConnectionManager.getDefault().getConnections().size()); - for (IXWikiConnection xwikiConnection : XWikiConnectionManager.getDefault() - .getConnections()) { - - if(monitor.isCanceled()) { + monitor.beginTask(String.format("Indexing connection..."), + IProgressMonitor.UNKNOWN); + + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + + Collection<IXWikiSpace> spaces = connection.getSpaces(); + + for (IXWikiSpace space : spaces) { + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } - - Collection<IXWikiSpace> spaces = xwikiConnection.getSpaces(); - - for(IXWikiSpace space : spaces) { - if(monitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - - Collection<IXWikiPage> pages = space.getPages(); - for(IXWikiPage page : pages) { - pageIndex.addPage(page); - } + + Collection<IXWikiPage> pages = space.getPages(); + for (IXWikiPage page : pages) { + pageIndex.addPage(page); } - monitor.worked(1); } + } catch (Exception e) { e.printStackTrace(); - return new Status(IStatus.ERROR, XWikiEclipsePlugin.PLUGIN_ID, String.format("Error while indexing\n%s", e.getMessage())); + return new Status(IStatus.ERROR, XWikiEclipsePlugin.PLUGIN_ID, String.format( + "Error while indexing\n%s", e.getMessage())); } finally { monitor.done(); schedule(600000); } - + return Status.OK_STATUS; } @@ -69,9 +71,9 @@ private XWikiEclipsePageIndexer() { - // TODO Auto-generated constructor stub + connectionToIndexerMapping = new HashMap<IXWikiConnection, Job>(); } - + public static XWikiEclipsePageIndexer getDefault() { if (instance == null) { @@ -80,24 +82,57 @@ return instance; } - - public void start() { - if(indexer != null) { - return; + + public void start() + { + XWikiEclipseNotificationCenter.getDefault().addListener( + XWikiEclipseEvent.CONNECTION_ESTABLISHED, this); + XWikiEclipseNotificationCenter.getDefault().addListener( + XWikiEclipseEvent.CONNECTION_CLOSED, this); + } + + public void stop() + { + XWikiEclipseNotificationCenter.getDefault().removeListener( + XWikiEclipseEvent.CONNECTION_ESTABLISHED, this); + XWikiEclipseNotificationCenter.getDefault().removeListener( + XWikiEclipseEvent.CONNECTION_CLOSED, this); + + for(Job indexerJob : connectionToIndexerMapping.values()) { + indexerJob.cancel(); } - - indexer = new IndexerJob("Page indexer"); - indexer.setSystem(true); - indexer.setPriority(Job.DECORATE); - indexer.schedule(); } - - public void stop() { - if(indexer == null) { - return; + + public void handleEvent(Object sender, XWikiEclipseEvent event, Object data) + { + IXWikiConnection connection; + + switch (event) { + case CONNECTION_ESTABLISHED: + connection = (IXWikiConnection) data; + if (XWikiConnectionManager.getDefault().getConnections().contains(connection)) { + if (connectionToIndexerMapping.get(connection) != null) { + connectionToIndexerMapping.get(connection).cancel(); + connectionToIndexerMapping.remove(connection); + } + + IndexerJob indexerJob = new IndexerJob(connection); + connectionToIndexerMapping.put(connection, indexerJob); + indexerJob.setSystem(true); + indexerJob.setPriority(Job.DECORATE); + indexerJob.schedule(); + } + break; + case CONNECTION_CLOSED: + connection = (IXWikiConnection) data; + if (XWikiConnectionManager.getDefault().getConnections().contains(connection)) { + if (connectionToIndexerMapping.get(connection) != null) { + connectionToIndexerMapping.get(connection).cancel(); + connectionToIndexerMapping.remove(connection); + } + } + break; } - - indexer.cancel(); - indexer = null; + } } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/dialogs/OpenPageDialog.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/dialogs/OpenPageDialog.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/dialogs/OpenPageDialog.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -140,7 +140,7 @@ { super(shell); setTitle("Open page"); - setListLabelProvider(new OpenPageLabelProvider(new WorkbenchLabelProvider())); + setListLabelProvider(new OpenPageLabelProvider(new WorkbenchLabelProvider())); setListSelectionLabelDecorator(new SelectionLabelDecorator()); setDetailsLabelProvider(new WorkbenchLabelProvider()); } @@ -209,10 +209,12 @@ { return new Comparator() { - public int compare(Object o1, Object o2) { - return o1.toString().compareTo(o2.toString()); + IXWikiPage page1 = (IXWikiPage) o1; + IXWikiPage page2 = (IXWikiPage) o2; + + return page1.getTitle().compareTo(page2.getTitle()); } }; } @@ -223,5 +225,4 @@ // TODO Auto-generated method stub return Status.OK_STATUS; } - } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/AbstractXWikiConnection.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/AbstractXWikiConnection.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/AbstractXWikiConnection.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -113,7 +113,8 @@ { final int prime = 31; int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((serverUrl == null) ? 0 : serverUrl.hashCode()); + result = prime * result + ((userName == null) ? 0 : userName.hashCode()); return result; } @@ -127,12 +128,19 @@ if (getClass() != obj.getClass()) return false; final AbstractXWikiConnection other = (AbstractXWikiConnection) obj; - if (id == null) { - if (other.id != null) + if (serverUrl == null) { + if (other.serverUrl != null) return false; - } else if (!id.equals(other.id)) + } else if (!serverUrl.equals(other.serverUrl)) return false; + if (userName == null) { + if (other.userName != null) + return false; + } else if (!userName.equals(other.userName)) + return false; return true; } + + } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiCachedConnection.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiCachedConnection.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiCachedConnection.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -592,4 +592,6 @@ Set<IXWikiPage> result = new HashSet<IXWikiPage>(); return result; } + + } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPage.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPage.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPage.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -234,11 +234,51 @@ return connection.isPageCached(page.getId()); } +// @Override +// public int hashCode() +// { +// final int prime = 31; +// int result = 1; +// result = prime * result + ((id == null) ? 0 : id.hashCode()); +// return result; +// } +// +// @Override +// public boolean equals(Object obj) +// { +// if (this == obj) +// return true; +// if (obj == null) +// return false; +// if (getClass() != obj.getClass()) +// return false; +// final XWikiPage other = (XWikiPage) obj; +// if (id == null) { +// if (other.id != null) +// return false; +// } else if (!id.equals(other.id)) +// return false; +// return true; +// } + + + + public IXWikiSpace getSpace() throws XWikiConnectionException + { + return space; + } + + public void remove() throws XWikiConnectionException + { + connection.removePage(this); + } + @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((connection == null) ? 0 : connection.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @@ -253,6 +293,11 @@ if (getClass() != obj.getClass()) return false; final XWikiPage other = (XWikiPage) obj; + if (connection == null) { + if (other.connection != null) + return false; + } else if (!connection.equals(other.connection)) + return false; if (id == null) { if (other.id != null) return false; @@ -260,14 +305,4 @@ return false; return true; } - - public IXWikiSpace getSpace() throws XWikiConnectionException - { - return space; - } - - public void remove() throws XWikiConnectionException - { - connection.removePage(this); - } } Modified: xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java =================================================================== --- xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java 2007-11-15 12:15:25 UTC (rev 5882) +++ xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java 2007-11-15 14:09:57 UTC (rev 5883) @@ -26,7 +26,6 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import org.xwiki.eclipse.XWikiEclipsePageIndex; import org.xwiki.eclipse.XWikiEclipsePageIndexer; import org.xwiki.plugins.eclipse.model.IXWikiConnection; import org.xwiki.plugins.eclipse.model.impl.XWikiConnectionManager; _______________________________________________ notifications mailing list notifications@xwiki.org http://lists.xwiki.org/mailman/listinfo/notifications