class="org.argeo.slc.client.ui.dist.commands.RefreshDistributionsView"
scope="prototype">
</bean>
+ <bean id="org.argeo.slc.client.ui.dist.deleteArtifacts"
+ class="org.argeo.slc.client.ui.dist.commands.DeleteArtifacts"
+ scope="prototype">
+ <property name="repository" ref="javaRepository" />
+ </bean>
+ <bean id="refreshDistributionOverviewPage"
+ class="org.argeo.slc.client.ui.dist.commands.RefreshDistributionOverviewPage"
+ scope="prototype">
+ </bean>
</beans>
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Refresh Distributions View">
</command>
+ <command
+ id="org.argeo.slc.client.ui.dist.refreshDistributionOverviewPage"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Refresh distribution overview page">
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.deleteArtifacts"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Remove selected artifacts">
+ </command>
</extension>
<extension
id="menu:org.eclipse.ui.main.menu"
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import org.apache.commons.logging.Log;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
+import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.ui.IWorkbenchWindow;
/**
* Create a copy of the chosen workspace in the current repository.
if (log.isTraceEnabled())
log.debug("WORKSPACE " + srcWorkspaceName + " About to be copied");
- MessageDialog.openWarning(DistPlugin.getDefault()
- .getWorkbench().getDisplay().getActiveShell(),
- "WARNING", "Not yet implemented");
- return null;
- //
- //
- // IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- // .getActiveWorkbenchWindow();
- // InputDialog inputDialog = new InputDialog(iww.getShell(),
- // "New copy of the current workspace",
- // "Choose a name for the workspace to create", "", null);
- // inputDialog.open();
- // String newWorkspaceName = inputDialog.getValue();
- // Session srcSession = null;
- // Session newSession = null;
- // try {
- // srcSession = repository.login(srcWorkspaceName);
- // // FIXME: simple call to Workspace.create(newName, oldName) does not
- // // work
- //
- // srcSession.getWorkspace().createWorkspace(newWorkspaceName,
- // srcWorkspaceName);
- //
- // // // Create the workspace
- // // srcSession.getWorkspace().createWorkspace(newWorkspaceName);
- // // Node srcRootNode = srcSession.getRootNode();
- // // // log in the newly created workspace
- // // newSession = repository.login(newWorkspaceName);
- // // newSession.save();
- // // Node newRootNode = newSession.getRootNode();
- // // copy(srcRootNode, newRootNode);
- // // newSession.save();
- //
- // CommandHelpers.callCommand(RefreshDistributionsView.ID);
- // } catch (RepositoryException re) {
- // throw new ArgeoException(
- // "Unexpected error while creating the new workspace.", re);
- // } finally {
- // if (srcSession != null)
- // srcSession.logout();
- // if (newSession != null)
- // newSession.logout();
- // }
+ // MessageDialog.openWarning(DistPlugin.getDefault()
+ // .getWorkbench().getDisplay().getActiveShell(),
+ // "WARNING", "Not yet implemented");
// return null;
+
+ IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow();
+ InputDialog inputDialog = new InputDialog(iww.getShell(),
+ "New copy of the current workspace",
+ "Choose a name for the workspace to create", "", null);
+ inputDialog.open();
+ String newWorkspaceName = inputDialog.getValue();
+ Session srcSession = null;
+ Session newSession = null;
+ try {
+ srcSession = repository.login(srcWorkspaceName);
+
+ // Create the workspace
+ srcSession.getWorkspace().createWorkspace(newWorkspaceName);
+ Node srcRootNode = srcSession.getRootNode();
+ // log in the newly created workspace
+ newSession = repository.login(newWorkspaceName);
+ newSession.save();
+ Node newRootNode = newSession.getRootNode();
+ copy(srcRootNode, newRootNode);
+ newSession.save();
+
+ CommandHelpers.callCommand(RefreshDistributionsView.ID);
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while creating the new workspace.", re);
+ } finally {
+ if (srcSession != null)
+ srcSession.logout();
+ if (newSession != null)
+ newSession.logout();
+ }
+ return null;
}
// FIXME : commons is frozen, cannot fix the problem directly there.
// test and report corresponding patch
private void copy(Node fromNode, Node toNode) {
-
try {
- // cannot manipulate security nodes this way:
- if (fromNode.isNodeType("rep:ACL"))
+ if (log.isDebugEnabled())
+ log.debug("copy node :" + fromNode.getPath());
+
+
+ // FIXME : small hack to enable specific workspace copy
+ if (fromNode.isNodeType("rep:ACL") || fromNode.isNodeType("rep:system")){
+ if (log.isTraceEnabled())
+ log.trace("node skipped");
return;
+ }
+
+ // add mixins
+ for (NodeType mixinType : fromNode.getMixinNodeTypes()) {
+ toNode.addMixin(mixinType.getName());
+ }
+
+ // Double check
+ for (NodeType mixinType : toNode.getMixinNodeTypes()) {
+ log.debug(mixinType.getName());
+ }
+
// process properties
PropertyIterator pit = fromNode.getProperties();
properties: while (pit.hasNext()) {
Property fromProperty = pit.nextProperty();
+ String propName = fromProperty.getName();
+ try{
String propertyName = fromProperty.getName();
if (toNode.hasProperty(propertyName)
&& toNode.getProperty(propertyName).getDefinition()
} else {
toNode.setProperty(propertyName, fromProperty.getValue());
}
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot property " + propName, e);
+ }
}
- // update jcr:lastModified and jcr:lastModifiedBy in toNode in case
- // they existed, before adding the mixins
- if (!toNode.getDefinition().isProtected())
- JcrUtils.updateLastModified(toNode);
-
- // add mixins
- for (NodeType mixinType : fromNode.getMixinNodeTypes()) {
- toNode.addMixin(mixinType.getName());
- }
-
- // process children nodes
+ // recursively process children nodes
NodeIterator nit = fromNode.getNodes();
while (nit.hasNext()) {
Node fromChild = nit.nextNode();
copy(fromChild, toChild);
}
- toNode.getSession().save();
+ // update jcr:lastModified and jcr:lastModifiedBy in toNode in case
+ // they existed
+ if (!toNode.getDefinition().isProtected()
+ && toNode.isNodeType(NodeType.MIX_LAST_MODIFIED))
+ JcrUtils.updateLastModified(toNode);
+
+ // Workaround to reduce session size: artifact is a saveable unity
+ if (toNode.isNodeType(SlcTypes.SLC_ARTIFACT))
+ toNode.getSession().save();
+
} catch (RepositoryException e) {
throw new ArgeoException("Cannot copy " + fromNode + " to "
+ toNode, e);
--- /dev/null
+package org.argeo.slc.client.ui.dist.commands;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Delete chosen artifacts from the current workspace.
+ */
+
+public class DeleteArtifacts extends AbstractHandler {
+ // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
+ public final static String ID = DistPlugin.ID + ".deleteArtifacts";
+ public final static String DEFAULT_LABEL = "Delete selected items";
+ public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
+
+ /* DEPENDENCY INJECTION */
+ private Repository repository;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String msg = "Your are about to definitively remove these artifacts.\n"
+ + "Do you really want to proceed ?";
+
+ boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
+ .getWorkbench().getDisplay().getActiveShell(),
+ "Confirm deletion", msg);
+ if (result) {
+ Session session = null;
+ try {
+ session = repository.login();
+ IWorkbenchPart activePart = DistPlugin.getDefault()
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().getActivePart();
+
+ if (activePart instanceof IEditorPart) {
+ ISelection selector = ((IEditorPart) activePart)
+ .getEditorSite().getSelectionProvider()
+ .getSelection();
+ if (selector != null
+ && selector instanceof IStructuredSelection) {
+ Iterator<?> it = ((IStructuredSelection) selector)
+ .iterator();
+ while (it.hasNext()) {
+ Node node = (Node) it.next();
+ node.remove();
+ }
+ }
+ session.save();
+ }
+ CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while deleting artifacts.", re);
+ } finally {
+ if (session != null)
+ session.logout();
+ }
+ }
+ return null;
+ }
+
+ /* DEPENDENCY INJECTION */
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist.commands;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.editors.DistributionEditor;
+import org.argeo.slc.client.ui.dist.editors.DistributionOverviewPage;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.forms.editor.IFormPage;
+
+/**
+ * Force refresh of the DistributionsView
+ */
+
+public class RefreshDistributionOverviewPage extends AbstractHandler {
+ private static final Log log = LogFactory
+ .getLog(RefreshDistributionOverviewPage.class);
+ public final static String ID = DistPlugin.ID
+ + ".refreshDistributionOverviewPage";
+ public final static String DEFAULT_LABEL = "Refresh the distribution overview";
+ public final static String DEFAULT_ICON_PATH = "icons/refresh.png";
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActivePart();
+ if (activePart instanceof DistributionEditor) {
+ IFormPage ifp = ((DistributionEditor) activePart)
+ .getActivePageInstance();
+ if (ifp instanceof DistributionOverviewPage)
+ ((DistributionOverviewPage) ifp).refresh();
+ }
+ return null;
+ }
+}
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.commands.DeleteArtifacts;
+import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.osgi.framework.Constants;
/** Table giving an overview of an OSGi distribution */
-class DistributionOverviewPage extends FormPage implements SlcNames {
+public class DistributionOverviewPage extends FormPage implements SlcNames {
private TableViewer viewer;
private Session session;
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.setContentProvider(new DistributionsContentProvider());
+ getSite().setSelectionProvider(viewer);
+
viewer.setInput(session);
comparator = new NodeViewerComparator(1,
NodeViewerComparator.DESCENDING, propertiesList,
propertyTypesList);
viewer.setComparator(comparator);
+
+ MenuManager menuManager = new MenuManager();
+ Menu menu = menuManager.createContextMenu(viewer.getTable());
+ menuManager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ contextMenuAboutToShow(manager);
+ }
+ });
+ viewer.getTable().setMenu(menu);
+ getSite().registerContextMenu(menuManager, viewer);
+
}
@Override
viewer.getTable().setFocus();
}
+ /** force refresh of the artifact list */
+ public void refresh() {
+ viewer.refresh();
+ }
+
+ /** Programatically configure the context menu */
+ protected void contextMenuAboutToShow(IMenuManager menuManager) {
+ IWorkbenchWindow window = DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow();
+
+ // Build conditions depending on element type (repo or workspace)
+
+ // Delete selected artifacts
+ CommandHelpers.refreshCommand(menuManager, window, DeleteArtifacts.ID,
+ DeleteArtifacts.DEFAULT_LABEL,
+ DeleteArtifacts.DEFAULT_ICON_PATH, true);
+
+ }
+
static NodeIterator listBundleArtifacts(Session session)
throws RepositoryException {
QueryManager queryManager = session.getWorkspace().getQueryManager();
}
}
-
}
\ No newline at end of file