Author: fmancinelli
Date: 2007-11-15 13:11:29 +0100 (Thu, 15 Nov 2007)
New Revision: 5881
Added:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java
Log:
* Added background page indexer
Added:
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
(rev 0)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/XWikiEclipsePageIndexer.java
2007-11-15 12:11:29 UTC (rev 5881)
@@ -0,0 +1,103 @@
+package org.xwiki.eclipse;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.xwiki.eclipse.model.IXWikiConnection;
+import org.xwiki.eclipse.model.IXWikiPage;
+import org.xwiki.eclipse.model.IXWikiSpace;
+import org.xwiki.plugins.eclipse.XWikiEclipsePlugin;
+
+public class XWikiEclipsePageIndexer
+{
+ private static XWikiEclipsePageIndexer instance;
+ private Job indexer;
+
+ private class IndexerJob extends Job
+ {
+
+ public IndexerJob(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ try {
+ XWikiEclipsePageIndex pageIndex =
XWikiEclipsePageIndex.getDefault();
+
+ monitor.beginTask(String.format("Indexing connections..."),
+
XWikiConnectionManager.getDefault().getConnections().size());
+
+ for (IXWikiConnection xwikiConnection :
XWikiConnectionManager.getDefault()
+ .getConnections()) {
+
+ 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);
+ }
+ }
+ 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()));
+ } finally {
+ monitor.done();
+ schedule(600000);
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ }
+
+ private XWikiEclipsePageIndexer()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ public static XWikiEclipsePageIndexer getDefault()
+ {
+ if (instance == null) {
+ instance = new XWikiEclipsePageIndexer();
+ }
+
+ return instance;
+ }
+
+ public void start() {
+ if(indexer != null) {
+ return;
+ }
+
+ indexer = new IndexerJob("Page indexer");
+ indexer.setSystem(true);
+ indexer.setPriority(Job.DECORATE);
+ indexer.schedule();
+ }
+
+ public void stop() {
+ if(indexer == null) {
+ return;
+ }
+
+ indexer.cancel();
+ indexer = null;
+ }
+}
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 10:50:59 UTC (rev 5880)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/XWikiEclipsePlugin.java
2007-11-15 12:11:29 UTC (rev 5881)
@@ -26,6 +26,8 @@
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;
@@ -75,6 +77,8 @@
if (workingSetsFile.exists()) {
org.xwiki.eclipse.WorkingSetManager.getDefault().restoreWorkingSets(workingSetsFile);
}
+
+ XWikiEclipsePageIndexer.getDefault().start();
}
/**
@@ -84,6 +88,8 @@
*/
public void stop(BundleContext context) throws Exception
{
+ XWikiEclipsePageIndexer.getDefault().stop();
+
for (IXWikiConnection con :
XWikiConnectionManager.getInstance().getAllConnections()) {
try {
con.disconnect();
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications