Improve slc client ui dist, fix bugs #109, 110, 111
authorBruno Sinou <bsinou@argeo.org>
Sun, 1 Jul 2012 10:17:40 +0000 (10:17 +0000)
committerBruno Sinou <bsinou@argeo.org>
Sun, 1 Jul 2012 10:17:40 +0000 (10:17 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5397 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteArtifacts.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/ManageWorkspaceAuth.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RefreshDistributionOverviewPage.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistributionEditor.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistributionOverviewPage.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java

index a0b0b517c2484711c964f05cbf09d48224b96465..ccdc80714f2aad58af4468db6324d3c5fbc80853 100644 (file)
@@ -37,13 +37,17 @@ public class CreateWorkspace extends AbstractHandler {
                                "", null);
                inputDialog.open();
                String workspaceName = inputDialog.getValue();
+               Session session = null;
                try {
-                       Session session = repository.login();
+                       session = repository.login();
                        session.getWorkspace().createWorkspace(workspaceName);
                        CommandHelpers.callCommand(RefreshDistributionsView.ID);
                } catch (RepositoryException re) {
                        throw new ArgeoException(
                                        "Unexpected error while creating the new workspace.", re);
+               } finally {
+                       if (session != null)
+                               session.logout();
                }
                if (log.isTraceEnabled())
                        log.debug("WORKSPACE " + workspaceName + " CREATED");
@@ -54,4 +58,4 @@ public class CreateWorkspace extends AbstractHandler {
        public void setRepository(Repository repository) {
                this.repository = repository;
        }
-}
+}
\ No newline at end of file
index 5e67975fc7e830222d5bbf3f9442b549837a9fed..88e9bdad277d74e58cf9bbf4695506c8ba4e03b8 100644 (file)
@@ -28,28 +28,28 @@ public class DeleteArtifacts extends AbstractHandler {
        public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               String msg = "Your are about to definitively remove these artifacts.\n"
-                               + "Do you really want to proceed ?";
+               try {
+                       IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
+                                       .getActiveWorkbenchWindow().getActivePage().getActivePart();
 
-               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();
 
-                               if (activePart instanceof IEditorPart) {
-                                       ISelection selector = ((IEditorPart) activePart)
-                                                       .getEditorSite().getSelectionProvider()
-                                                       .getSelection();
-                                       if (selector != null
-                                                       && selector instanceof IStructuredSelection) {
-                                               Iterator<?> it = ((IStructuredSelection) selector)
-                                                               .iterator();
+                                       String msg = "Your are about to definitively remove the "
+                                                       + ((IStructuredSelection) selector).size()
+                                                       + " selected artifacts.\n"
+                                                       + "Are you sure you want to proceed ?";
+
+                                       boolean result = MessageDialog.openConfirm(DistPlugin
+                                                       .getDefault().getWorkbench().getDisplay()
+                                                       .getActiveShell(), "Confirm Delete", msg);
+
+                                       if (result) {
                                                while (it.hasNext()) {
                                                        Node node = (Node) it.next();
                                                        // we remove the artifactVersion, that is the parent
@@ -57,17 +57,13 @@ public class DeleteArtifacts extends AbstractHandler {
                                                        node.getSession().save();
                                                }
                                        }
-                                       // session.save();
                                }
-                               CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
-                       } catch (RepositoryException re) {
-                               throw new ArgeoException(
-                                               "Unexpected error while deleting artifacts.", re);
-                       } finally {
-                               // if (session != null)
-                               // session.logout();
                        }
+                       CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
+               } catch (RepositoryException re) {
+                       throw new ArgeoException(
+                                       "Unexpected error while deleting artifacts.", re);
                }
                return null;
        }
-}
+}
\ No newline at end of file
index a0e940d38feec54ac19103ac3141e3db4a8726fd..39ba79e48be4c9abebc7e5000ead613695c3cd7e 100644 (file)
@@ -1,12 +1,8 @@
 package org.argeo.slc.client.ui.dist.commands;
 
 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;
@@ -28,15 +24,16 @@ public class DeleteWorkspace extends AbstractHandler {
        private Repository repository;
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
-               String msg = "Your are about to definitively delete this workspace ["
-                               + workspaceName + "].\n Do you really want to proceed ?";
-
+       
                MessageDialog.openWarning(DistPlugin.getDefault()
                                .getWorkbench().getDisplay().getActiveShell(),
                                "WARNING", "Not yet implemented");
                return null;
-               
+       
+//             String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
+//             String msg = "Your are about to definitively delete this workspace ["
+//                             + workspaceName + "].\n Do you really want to proceed ?";
+
 //             boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
 //                             .getWorkbench().getDisplay().getActiveShell(),
 //                             "Confirm deletion", msg);
@@ -62,4 +59,4 @@ public class DeleteWorkspace extends AbstractHandler {
        public void setRepository(Repository repository) {
                this.repository = repository;
        }
-}
+}
\ No newline at end of file
index 09ece2f5c0acfa62bd68656529d9d83f2ab9cafa..292a35ee5b5dab8e9d76d8f99235c4f25c137a0d 100644 (file)
@@ -3,7 +3,6 @@ package org.argeo.slc.client.ui.dist.commands;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.security.Privilege;
 
 import org.argeo.ArgeoException;
 import org.argeo.slc.client.ui.dist.DistPlugin;
@@ -54,4 +53,4 @@ public class ManageWorkspaceAuth extends AbstractHandler {
        public void setRepository(Repository repository) {
                this.repository = repository;
        }
-}
+}
\ No newline at end of file
index d6d86e1d4238706ce59f7d5550e2a0a198636db1..243d12b4e7200bc3dda4b7b76fff52d80362c9ea 100644 (file)
@@ -1,7 +1,5 @@
 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;
@@ -12,12 +10,12 @@ import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.forms.editor.IFormPage;
 
 /**
- * Force refresh of the DistributionsView
+ * Force refresh of the Distribution overview page of the corresponding editor
  */
 
 public class RefreshDistributionOverviewPage extends AbstractHandler {
-       private static final Log log = LogFactory
-                       .getLog(RefreshDistributionOverviewPage.class);
+       // 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";
index 6c6756c8950cc62128808242b5db0dbb37b60478..44825043782efc25b3ed5f5fffb8d1918ce67a8d 100644 (file)
@@ -64,6 +64,13 @@ public class DistributionEditor extends FormEditor implements SlcNames {
        public void doSave(IProgressMonitor arg0) {
        }
 
+       @Override
+       public void dispose() {
+               if (session != null)
+                       session.logout();
+               super.dispose();
+       }
+
        @Override
        public void doSaveAs() {
        }
index bdd243d8301a2575e10202d3252c219616d321aa..54d2c3c20d4b511cbff45afbd1022cf726cf6539 100644 (file)
@@ -72,7 +72,7 @@ public class DistributionOverviewPage extends FormPage implements SlcNames {
                viewer = new TableViewer(form.getBody(), SWT.MULTI | SWT.H_SCROLL
                                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
 
-               TableViewerColumn col = new TableViewerColumn(viewer, SWT.NONE);
+               TableViewerColumn col = new TableViewerColumn(viewer,  SWT.V_SCROLL);
                col.getColumn().setWidth(300);
                col.getColumn().setText("Symbolic name");
                col.setLabelProvider(new ColumnLabelProvider() {
@@ -132,7 +132,7 @@ public class DistributionOverviewPage extends FormPage implements SlcNames {
 
                viewer.setContentProvider(new DistributionsContentProvider());
                getSite().setSelectionProvider(viewer);
-               
+
                viewer.setInput(session);
                comparator = new NodeViewerComparator(1,
                                NodeViewerComparator.DESCENDING, propertiesList,
@@ -236,6 +236,73 @@ public class DistributionOverviewPage extends FormPage implements SlcNames {
                                return null;
                        }
                }
-
        }
+       //
+       // private class BoundedLayout extends Layout {
+       // protected Layout delegateLayout;
+       //
+       // protected Method computeSizeMethod;
+       // protected Method layoutMethod;
+       //
+       // protected boolean widthBound;
+       //
+       // public BoundedLayout(Layout delegateLayout, boolean widthBound) {
+       // setDelegateLayout(delegateLayout);
+       // this.widthBound = widthBound;
+       // }
+       //
+       // public Layout getDelegateLayout() {
+       // return delegateLayout;
+       // }
+       //
+       // public void setDelegateLayout(Layout delegateLayout) {
+       // this.delegateLayout = delegateLayout;
+       //
+       // try {
+       // computeSizeMethod = delegateLayout.getClass()
+       // .getDeclaredMethod("computeSize", Composite.class,
+       // int.class, int.class, boolean.class);
+       // computeSizeMethod.setAccessible(true);
+       //
+       // layoutMethod = delegateLayout.getClass().getDeclaredMethod(
+       // "layout", Composite.class, boolean.class);
+       // layoutMethod.setAccessible(true);
+       // } catch (Exception e) {
+       // throw new RuntimeException(e);
+       // }
+       // }
+       //
+       // @Override
+       // protected Point computeSize(Composite composite, int wHint, int hHint,
+       // boolean flushCache) {
+       // // get comp size to make sure we don't let any children exceed it
+       // Point compSize = composite.getSize();
+       //
+       // try {
+       // Point layoutComputedSize = (Point) computeSizeMethod.invoke(
+       // delegateLayout, composite, wHint, hHint, flushCache);
+       //
+       // if (widthBound) {
+       // layoutComputedSize.x = Math.min(compSize.x,
+       // layoutComputedSize.x);
+       // } else {
+       // layoutComputedSize.y = Math.min(compSize.y,
+       // layoutComputedSize.y);
+       // }
+       //
+       // return layoutComputedSize;
+       // } catch (Exception e) {
+       // throw new RuntimeException(e);
+       // }
+       // }
+       //
+       // @Override
+       // protected void layout(Composite composite, boolean flushCache) {
+       // try {
+       // layoutMethod.invoke(delegateLayout, composite, flushCache);
+       // } catch (Exception e) {
+       // throw new RuntimeException(e);
+       // }
+       // }
+       // }
 }
\ No newline at end of file
index e714a780bd62660d1c1d97e71ecaa701bc160c9e..f62707abe11c689ff3bd48397dbbbe797dbcf73c 100644 (file)
@@ -126,38 +126,49 @@ public class DistributionsView extends ViewPart implements SlcNames {
                // Get Current selected item :
                Object firstElement = ((IStructuredSelection) viewer.getSelection())
                                .getFirstElement();
-               String wsName = null;
+
                if (firstElement instanceof TreeParent) {
-                       wsName = ((TreeParent) firstElement).getName();
-               }
+                       TreeParent tp = (TreeParent) firstElement;
+                       String wsName = tp.getName();
+
+                       // Build conditions depending on element type (repo or distribution
+                       // for the time being)
+                       boolean isDistribElem = false; // , isRepoElem = false;
+
+                       // if (tp instanceof RepositoryElem){
+                       // isRepoElem = true;
+                       // } else
+                       if (tp instanceof DistributionElem) {
+                               isDistribElem = true;
+                       }
 
-               // Build conditions depending on element type (repo or workspace)
-
-               // create workspace
-               CommandHelpers.refreshCommand(menuManager, window, CreateWorkspace.ID,
-                               CreateWorkspace.DEFAULT_LABEL,
-                               CreateWorkspace.DEFAULT_ICON_PATH, true);
-
-               // Copy workspace
-               Map<String, String> params = new HashMap<String, String>();
-               params.put(CopyWorkspace.PARAM_WORKSPACE_NAME, wsName);
-               CommandHelpers.refreshParameterizedCommand(menuManager, window,
-                               CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL,
-                               CopyWorkspace.DEFAULT_ICON_PATH, true, params);
-
-               // Delete Workspace
-               params = new HashMap<String, String>();
-               params.put(DeleteWorkspace.PARAM_WORKSPACE_NAME, wsName);
-               CommandHelpers.refreshParameterizedCommand(menuManager, window,
-                               DeleteWorkspace.ID, DeleteWorkspace.DEFAULT_LABEL,
-                               DeleteWorkspace.DEFAULT_ICON_PATH, true, params);
-
-               // Manage workspace authorizations
-               params = new HashMap<String, String>();
-               params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);
-               CommandHelpers.refreshParameterizedCommand(menuManager, window,
-                               ManageWorkspaceAuth.ID, ManageWorkspaceAuth.DEFAULT_LABEL,
-                               ManageWorkspaceAuth.DEFAULT_ICON_PATH, true, params);
+                       // create workspace
+                       CommandHelpers.refreshCommand(menuManager, window,
+                                       CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL,
+                                       CreateWorkspace.DEFAULT_ICON_PATH, true);
+
+                       // Copy workspace
+                       Map<String, String> params = new HashMap<String, String>();
+                       params.put(CopyWorkspace.PARAM_WORKSPACE_NAME, wsName);
+                       CommandHelpers.refreshParameterizedCommand(menuManager, window,
+                                       CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL,
+                                       CopyWorkspace.DEFAULT_ICON_PATH, isDistribElem, params);
+
+                       // Delete Workspace
+                       params = new HashMap<String, String>();
+                       params.put(DeleteWorkspace.PARAM_WORKSPACE_NAME, wsName);
+                       CommandHelpers.refreshParameterizedCommand(menuManager, window,
+                                       DeleteWorkspace.ID, DeleteWorkspace.DEFAULT_LABEL,
+                                       DeleteWorkspace.DEFAULT_ICON_PATH, isDistribElem, params);
+
+                       // Manage workspace authorizations
+                       params = new HashMap<String, String>();
+                       params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);
+                       CommandHelpers.refreshParameterizedCommand(menuManager, window,
+                                       ManageWorkspaceAuth.ID, ManageWorkspaceAuth.DEFAULT_LABEL,
+                                       ManageWorkspaceAuth.DEFAULT_ICON_PATH, isDistribElem,
+                                       params);
+               }
        }
 
        private class DistributionsContentProvider extends
@@ -170,12 +181,12 @@ public class DistributionsView extends ViewPart implements SlcNames {
        }
 
        private static class RepositoryElem extends TreeParent {
-               private final Repository repository;
+               // private final Repository repository;
                private Session defaultSession;
 
                public RepositoryElem(String name, Repository repository) {
                        super(name);
-                       this.repository = repository;
+                       // this.repository = repository;
                        try {
                                defaultSession = repository.login();
                                String[] workspaceNames = defaultSession.getWorkspace()
@@ -187,6 +198,14 @@ public class DistributionsView extends ViewPart implements SlcNames {
                        }
                }
 
+               @Override
+               public synchronized void dispose() {
+                       if (log.isTraceEnabled())
+                               log.trace("Disposing RepositoryElement");
+                       if (defaultSession != null)
+                               defaultSession.logout();
+                       super.dispose();
+               }
        }
 
        private static class DistributionElem extends TreeParent {
@@ -206,7 +225,11 @@ public class DistributionsView extends ViewPart implements SlcNames {
                public Repository getRepository() {
                        return repository;
                }
+       }
 
+       @Override
+       public void dispose() {
+               super.dispose();
        }
 
        private class DistributionsDCL implements IDoubleClickListener {
@@ -231,7 +254,5 @@ public class DistributionsView extends ViewPart implements SlcNames {
                                }
                        }
                }
-
        }
-
-}
+}
\ No newline at end of file