Author: fmancinelli
Date: 2007-11-19 12:23:45 +0100 (Mon, 19 Nov 2007)
New Revision: 6006
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSet.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetFilter.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetManager.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/IXWikiConnection.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/XWikiPlainConnection.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/views/XWikiExplorerView.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewConnectionWizard.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewPageWizard.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewSpaceWizard.java
Log:
* Refactored working sets handling. Now newly created resources are
automatically added to the active working set.
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSet.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSet.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSet.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -28,85 +28,164 @@
import org.xwiki.eclipse.model.IXWikiPage;
import org.xwiki.eclipse.model.IXWikiSpace;
+/**
+ * A class representing a working set, i.e., a set of resources (connections,
spaces and pages)
+ */
public class WorkingSet implements Serializable
{
private static final long serialVersionUID = 2374252363910602198L;
private String name;
+ /**
+ * The ids of the resources belonging to this working set.
+ */
private Set<String> ids;
+ /**
+ * Constructor.
+ *
+ * @param name The working set symbolic name.
+ */
public WorkingSet(String name)
{
this.name = name;
ids = new HashSet<String>();
}
+ /**
+ * Add a connection to the working set.
+ *
+ * @param xwikiConnection The connection to be added.
+ */
public void add(IXWikiConnection xwikiConnection)
{
ids.add(getId(xwikiConnection));
}
+ /**
+ * Add a space to the working set.
+ *
+ * @param xwikiSpace The space to be added.
+ */
public void add(IXWikiSpace xwikiSpace)
{
ids.add(getId(xwikiSpace));
}
+ /**
+ * Add a page to the working set.
+ *
+ * @param xwikiPage The page to be added.
+ */
public void add(IXWikiPage xwikiPage)
{
ids.add(getId(xwikiPage));
}
+ /**
+ * Remove a connection from the working set.
+ *
+ * @param xwikiConnection The connection to be removed.
+ */
public void remove(IXWikiConnection xwikiConnection)
{
ids.remove(getId(xwikiConnection));
}
+ /**
+ * Remove a space from the working set.
+ *
+ * @param xwikiSpace The space to be removed.
+ */
public void remove(IXWikiSpace xwikiSpace)
{
ids.remove(getId(xwikiSpace));
}
+ /**
+ * Remove a page from the working set.
+ *
+ * @param xwikiPage The page to be removed.
+ */
public void remove(IXWikiPage xwikiPage)
{
ids.remove(getId(xwikiPage));
}
+ /**
+ * Check for membership.
+ *
+ * @param xwikiConnection An xwiki connection.
+ * @return true if the connection belongs to the working set, false
otherwise.
+ */
public boolean contains(IXWikiConnection xwikiConnection)
{
return ids.contains(getId(xwikiConnection));
}
+ /**
+ * Check for membership.
+ *
+ * @param xwikiSpace An xwiki space.
+ * @return true if the space belongs to the working set, false otherwise.
+ */
public boolean contains(IXWikiSpace xwikiSpace)
{
return ids.contains(getId(xwikiSpace));
}
+ /**
+ * Check for membership.
+ *
+ * @param xwikiPage An xwiki page.
+ * @return true if the page belongs to the working set, false otherwise.
+ */
public boolean contains(IXWikiPage xwikiPage)
{
return ids.contains(getId(xwikiPage));
}
+ /**
+ * @param xwikiConnection An xwiki connection.
+ * @return A synthesized id for the connection.
+ */
private String getId(IXWikiConnection xwikiConnection)
{
return xwikiConnection.getId();
}
+ /**
+ * @param xwikiSpace An xwiki space.
+ * @return A synthesized id for the space.
+ */
private String getId(IXWikiSpace xwikiSpace)
{
return String.format("%s#%s", xwikiSpace.getConnection().getId(),
xwikiSpace.getKey());
}
+ /**
+ * @param xwikiPage An xwiki page.
+ * @return A synthesized id for the page.
+ */
private String getId(IXWikiPage xwikiPage)
{
return String.format("%s#%s", xwikiPage.getConnection().getId(),
xwikiPage.getId());
}
+ /**
+ * @return The working set symbolic name.
+ */
public String getName()
{
return name;
}
+ /**
+ * Set the working set symbolic name.
+ *
+ * @param name The working set symbolic name.
+ */
public void setName(String name)
{
this.name = name;
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetFilter.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetFilter.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetFilter.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -26,6 +26,9 @@
import org.xwiki.eclipse.model.IXWikiPage;
import org.xwiki.eclipse.model.IXWikiSpace;
+/**
+ * A filter for displaying only the resources that belong to a given working
set.
+ */
public class WorkingSetFilter extends ViewerFilter
{
private WorkingSet workingSet;
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetManager.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetManager.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/WorkingSetManager.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -28,22 +28,39 @@
import java.util.HashSet;
import java.util.Set;
+/**
+ * A singleton for managing working sets.
+ */
public class WorkingSetManager
{
private Set<WorkingSet> workingSets;
private static WorkingSetManager sharedInstance;
+ /**
+ * The currently selected working set.
+ */
+ private WorkingSet activeWorkingSet;
+
private WorkingSetManager()
{
workingSets = new HashSet<WorkingSet>();
+ activeWorkingSet = null;
}
+ /**
+ * Constructor for restoring a previously saved working set list
+ *
+ * @param workingSets A set containing working sets.
+ */
private WorkingSetManager(Set<WorkingSet> workingSets)
{
this.workingSets = workingSets;
}
+ /**
+ * @return The shared instance.
+ */
@SuppressWarnings("unchecked")
public static WorkingSetManager getDefault()
{
@@ -54,21 +71,40 @@
return sharedInstance;
}
+ /**
+ * Add a working set to the manager.
+ *
+ * @param workingSet The working set to be added.
+ */
public void add(WorkingSet workingSet)
{
workingSets.add(workingSet);
}
+ /**
+ * Remove a working set from the manager.
+ *
+ * @param workingSet The working set to be removed.
+ */
public void remove(WorkingSet workingSet)
{
workingSets.remove(workingSet);
}
+ /**
+ * @return All the currently registered working set.
+ */
public Set<WorkingSet> getWorkingSets()
{
return workingSets;
}
+ /**
+ * Restore a previously saved working set list from a file.
+ *
+ * @param inputFile The file with the serialized stream containing the
working sets.
+ * @throws Exception
+ */
public void restoreWorkingSets(File inputFile) throws Exception
{
ObjectInputStream ois = new ObjectInputStream(new
FileInputStream(inputFile));
@@ -76,10 +112,36 @@
ois.close();
}
+ /**
+ * Store the currently registered working set on a file.
+ *
+ * @param outputFile The file where the serialized stream containing the
working sets will be
+ * stored.
+ * @throws Exception
+ */
public void saveWorkingSets(File outputFile) throws Exception
{
ObjectOutputStream oos = new ObjectOutputStream(new
FileOutputStream(outputFile));
oos.writeObject(workingSets);
oos.close();
}
+
+ /**
+ * @return The active working set. null if no working is active.
+ */
+ public WorkingSet getActiveWorkingSet()
+ {
+ return activeWorkingSet;
+ }
+
+ /**
+ * Set the active working set.
+ *
+ * @param workingSet A working set to be activated.
+ */
+ public void setActiveWorkingSet(WorkingSet workingSet)
+ {
+ this.activeWorkingSet = workingSet;
+ }
+
}
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/IXWikiConnection.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/IXWikiConnection.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/IXWikiConnection.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -105,7 +105,7 @@
* @param description
* @throws XWikiConnectionException
*/
- public void createSpace(String key, String name, String description)
+ public IXWikiSpace createSpace(String key, String name, String description)
throws XWikiConnectionException;
/**
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-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiCachedConnection.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -509,14 +509,15 @@
return cacheDAO.isCached(pageId);
}
- public void createSpace(String key, String name, String description)
+ public IXWikiSpace createSpace(String key, String name, String description)
throws XWikiConnectionException
{
if (isConnected()) {
try {
- remoteDAO.createSpace(key, name, description);
+ Space space = remoteDAO.createSpace(key, name, description);
XWikiEclipseNotificationCenter.getDefault().fireEvent(this,
XWikiEclipseEvent.SPACE_CREATED, this);
+ return new XWikiSpace(this, space.getKey(), space.toMap());
} catch (XWikiDAOException e) {
e.printStackTrace();
throw new XWikiConnectionException(e);
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPlainConnection.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPlainConnection.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/model/impl/XWikiPlainConnection.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -291,13 +291,14 @@
return false;
}
- public void createSpace(String key, String name, String description)
+ public IXWikiSpace createSpace(String key, String name, String description)
throws XWikiConnectionException
{
try {
- remoteDAO.createSpace(key, name, description);
+ Space space = remoteDAO.createSpace(key, name, description);
XWikiEclipseNotificationCenter.getDefault().fireEvent(this,
XWikiEclipseEvent.SPACE_CREATED, this);
+ return new XWikiSpace(this, space.getKey(), space.toMap());
} catch (XWikiDAOException e) {
e.printStackTrace();
throw new XWikiConnectionException(e);
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/views/XWikiExplorerView.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/views/XWikiExplorerView.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/views/XWikiExplorerView.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -98,11 +98,12 @@
private IHandlerActivation deleteCommandActivation;
- private WorkingSet currentWorkingSet;
+ // private WorkingSet currentWorkingSet;
private Form form;
-
- private class RefreshHandler extends AbstractHandler {
+
+ private class RefreshHandler extends AbstractHandler
+ {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
@@ -111,15 +112,14 @@
Object selectedObject =
XWikiEclipseUtil.getSingleSelectedObjectInStructuredSelection(selection);
- if (selectedObject instanceof IXWikiConnection) {
+ if (selectedObject instanceof IXWikiConnection) {
treeViewer.refresh(selectedObject);
- }
- else if (selectedObject instanceof IXWikiSpace) {
+ } else if (selectedObject instanceof IXWikiSpace) {
treeViewer.refresh(selectedObject);
}
return null;
- }
+ }
}
private class SelectWorkingSetAction extends Action
@@ -132,7 +132,7 @@
{
super(null, Action.AS_CHECK_BOX);
setText(workingSet != null ? workingSet.getName() : "No working
set");
- setChecked(workingSet == currentWorkingSet);
+ setChecked(workingSet ==
WorkingSetManager.getDefault().getActiveWorkingSet());
this.workingSet = workingSet;
this.treeViewer = treeViewer;
@@ -146,7 +146,7 @@
@Override
public void run()
{
- currentWorkingSet = workingSet;
+ WorkingSetManager.getDefault().setActiveWorkingSet(workingSet);
treeViewer.resetFilters();
if (workingSet != null) {
form.setText(workingSet.getName());
@@ -246,8 +246,8 @@
* set to null
*/
if
(!WorkingSetManager.getDefault().getWorkingSets().contains(
- currentWorkingSet)) {
- currentWorkingSet = null;
+
WorkingSetManager.getDefault().getActiveWorkingSet())) {
+
WorkingSetManager.getDefault().setActiveWorkingSet(null);
treeViewer.resetFilters();
}
}
@@ -344,7 +344,7 @@
SWT.NONE));
menuManager.add(new Separator());
-
+
menuManager.add(new CommandContributionItem(getSite(),
null,
XWikiEclipseConstants.REFRESH_COMMAND,
@@ -356,7 +356,7 @@
null,
null,
SWT.NONE));
-
+
menuManager.add(new Separator());
menuManager.add(new CommandContributionItem(getSite(),
@@ -578,7 +578,7 @@
return EvaluationResult.FALSE;
}
});
-
+
handlerService.activateHandler(XWikiEclipseConstants.REFRESH_COMMAND,
new RefreshHandler(), new Expression()
{
@@ -593,14 +593,14 @@
{
Object selection =
context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
-
+
Object selectedObject =
XWikiEclipseUtil.getSingleSelectedObjectInStructuredSelection(selection);
- if(selectedObject instanceof IXWikiConnection) {
+ if (selectedObject instanceof IXWikiConnection) {
return EvaluationResult.TRUE;
}
-
+
if (selectedObject instanceof IXWikiSpace) {
return EvaluationResult.TRUE;
}
@@ -609,7 +609,6 @@
}
});
-
}
public void handleEvent(final Object sender, final XWikiEclipseEvent
event, final Object data)
@@ -670,6 +669,7 @@
{
IHandlerService handlerService =
(IHandlerService) getSite().getService(IHandlerService.class);
+
if (deleteCommandActivation != null) {
handlerService.deactivateHandler(deleteCommandActivation);
}
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewConnectionWizard.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewConnectionWizard.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewConnectionWizard.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -30,6 +30,8 @@
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.xwiki.eclipse.WorkingSet;
+import org.xwiki.eclipse.WorkingSetManager;
import org.xwiki.eclipse.XWikiConnectionManager;
import org.xwiki.eclipse.model.IXWikiConnection;
import org.xwiki.eclipse.model.XWikiConnectionFactory;
@@ -86,6 +88,12 @@
.getDefault().getStateLocation().toFile(),
"cache"));
XWikiConnectionManager.getDefault().addConnection(connection,
newConnectionWizardState.getPassword());
+
+ WorkingSet currentWorkingSet =
WorkingSetManager.getDefault().getActiveWorkingSet();
+ if(currentWorkingSet != null) {
+ currentWorkingSet.add(connection);
+ }
+
connection.connect(newConnectionWizardState.getPassword());
} catch (Exception e) {
e.printStackTrace();
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewPageWizard.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewPageWizard.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewPageWizard.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -32,6 +32,8 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
+import org.xwiki.eclipse.WorkingSet;
+import org.xwiki.eclipse.WorkingSetManager;
import org.xwiki.eclipse.editors.XWikiPageEditor;
import org.xwiki.eclipse.editors.XWikiPageEditorInput;
import org.xwiki.eclipse.model.IXWikiPage;
@@ -69,6 +71,12 @@
xwikiSpace.createPage(newPageWizardState.getTitle(),
"Write here content");
+ WorkingSet currentWorkingSet =
+
WorkingSetManager.getDefault().getActiveWorkingSet();
+ if (currentWorkingSet != null) {
+ currentWorkingSet.add(xwikiPage);
+ }
+
Display.getDefault().asyncExec(new Runnable()
{
public void run()
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewSpaceWizard.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewSpaceWizard.java
2007-11-19 11:05:33 UTC (rev 6005)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/eclipse/wizards/NewSpaceWizard.java
2007-11-19 11:23:45 UTC (rev 6006)
@@ -29,7 +29,10 @@
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.xwiki.eclipse.WorkingSet;
+import org.xwiki.eclipse.WorkingSetManager;
import org.xwiki.eclipse.model.IXWikiConnection;
+import org.xwiki.eclipse.model.IXWikiSpace;
public class NewSpaceWizard extends Wizard implements INewWizard
{
@@ -57,8 +60,14 @@
try {
monitor.beginTask("Creating space...",
IProgressMonitor.UNKNOWN);
String spaceKey =
newSpaceWizardState.getName().trim().replace(' ', '_');
- xwikiConnection.createSpace(spaceKey,
newSpaceWizardState.getName(),
+ IXWikiSpace space =
xwikiConnection.createSpace(spaceKey, newSpaceWizardState.getName(),
newSpaceWizardState.getDescription());
+
+ WorkingSet currentWorkingSet =
WorkingSetManager.getDefault().getActiveWorkingSet();
+ if(currentWorkingSet != null) {
+ currentWorkingSet.add(space);
+ }
+
monitor.done();
} catch (Exception e) {
e.printStackTrace();
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications