Update context menu, fix a NPE when cancelling a duplicate workspace action
authorBruno Sinou <bsinou@argeo.org>
Wed, 26 Feb 2014 13:38:16 +0000 (13:38 +0000)
committerBruno Sinou <bsinou@argeo.org>
Wed, 26 Feb 2014 13:38:16 +0000 (13:38 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6857 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CopyWorkspace.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeDistribution.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/PublishWorkspace.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RefreshArtifactBrowser.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java

index ef2a94a1e3a636401b69830466a229229aa72015..435410c46cf3d1a107e20bb77ac0df8354d2b313 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.window.Window;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 /**
@@ -44,7 +45,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 public class CopyWorkspace extends AbstractHandler {
        // private static final Log log = LogFactory.getLog(CopyWorkspace.class);
        public final static String ID = DistPlugin.ID + ".copyWorkspace";
-       public final static String DEFAULT_LABEL = "Duplicate";
+       public final static String DEFAULT_LABEL = "Duplicate...";
        public final static String PARAM_SOURCE_WORKSPACE_NAME = "srcWkspName";
        public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
        public final static ImageDescriptor DEFAULT_ICON = DistPlugin
@@ -75,21 +76,23 @@ public class CopyWorkspace extends AbstractHandler {
                                        .getActiveWorkbenchWindow(event).getShell(),
                                        "New copy of workspace " + wkspName,
                                        "Choose a name for the workspace to create", "", null);
-                       inputDialog.open();
-                       String newWorkspaceName = inputDialog.getValue();
-                       srcSession = repository.login(credentials, wkspName);
+                       int result = inputDialog.open();
+                       if (result == Window.OK) {
+                               String newWorkspaceName = inputDialog.getValue();
+                               srcSession = repository.login(credentials, wkspName);
 
-                       // Create the workspace
-                       srcSession.getWorkspace().createWorkspace(newWorkspaceName);
-                       Node srcRootNode = srcSession.getRootNode();
-                       // log in the newly created workspace
-                       newSession = repository.login(credentials, newWorkspaceName);
-                       Node newRootNode = newSession.getRootNode();
-                       RepoUtils.copy(srcRootNode, newRootNode);
-                       newSession.save();
-                       JcrUtils.addPrivilege(newSession, "/", SlcConstants.ROLE_SLC,
-                                       Privilege.JCR_ALL);
-                       CommandHelpers.callCommand(RefreshDistributionsView.ID);
+                               // Create the workspace
+                               srcSession.getWorkspace().createWorkspace(newWorkspaceName);
+                               Node srcRootNode = srcSession.getRootNode();
+                               // log in the newly created workspace
+                               newSession = repository.login(credentials, newWorkspaceName);
+                               Node newRootNode = newSession.getRootNode();
+                               RepoUtils.copy(srcRootNode, newRootNode);
+                               newSession.save();
+                               JcrUtils.addPrivilege(newSession, "/", SlcConstants.ROLE_SLC,
+                                               Privilege.JCR_ALL);
+                               CommandHelpers.callCommand(RefreshDistributionsView.ID);
+                       }
                } catch (RepositoryException re) {
                        throw new ArgeoException(
                                        "Unexpected error while creating the new workspace.", re);
index 5a697bc225fae22570b51f82b092ef64095c86ba..681e0fed79dd586dd9075d99108ab4e5b34556ca 100644 (file)
@@ -43,7 +43,6 @@ import org.eclipse.ui.handlers.HandlerUtil;
 /**
  * Create a new empty workspace in the current repository.
  */
-
 public class CreateWorkspace extends AbstractHandler {
        private static final Log log = LogFactory.getLog(CreateWorkspace.class);
 
index ea53d44931eaaf3780db0337540174a26c5ebdda..a01cd7e51f2e8f804cfe2b20e1f18f0a3a348aa5 100644 (file)
@@ -42,6 +42,7 @@ import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 import org.argeo.slc.repo.ArtifactIndexer;
 import org.argeo.slc.repo.JarFileIndexer;
+import org.argeo.slc.repo.RepoConstants;
 import org.argeo.slc.repo.RepoUtils;
 import org.argeo.slc.repo.maven.MavenConventionsUtils;
 import org.argeo.slc.repo.osgi.NormalizeGroup;
@@ -71,21 +72,20 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
 
-/** Make sure than Maven and OSGi metadata are consistent */
+/** Legacy - Make sure than Maven and OSGi metadata are consistent */
 public class NormalizeDistribution extends AbstractHandler implements SlcNames {
+       private final static Log log = LogFactory
+                       .getLog(NormalizeDistribution.class);
+
        public final static String ID = DistPlugin.ID + ".normalizeDistribution";
-       public final static String DEFAULT_LABEL = "Normalize...";
-       // public final static String DEFAULT_ICON_PATH = "icons/normalize.gif";
+       public final static String DEFAULT_LABEL = "Legacy Normalization...";
        public final static ImageDescriptor DEFAULT_ICON = DistPlugin
                        .getImageDescriptor("icons/normalize.gif");
 
        public final static String PARAM_WORKSPACE_NAME = "workspaceName";
        public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
 
-       private final static Log log = LogFactory
-                       .getLog(NormalizeDistribution.class);
-
-       private String artifactBasePath = "/";
+       private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH;
 
        private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
        private JarFileIndexer jarFileIndexer = new JarFileIndexer();
index a9abb5fe82bca38db6d58ead5dd45b5ce6e287e7..f6f9d06fea52412651de0080c99545ec112a8271 100644 (file)
@@ -60,26 +60,25 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
        private final static Log log = LogFactory.getLog(NormalizeWorkspace.class);
 
        public final static String ID = DistPlugin.ID + ".normalizeWorkspace";
+       public final static ImageDescriptor DEFAULT_ICON = DistPlugin
+                       .getImageDescriptor("icons/normalize.gif");
 
        public final static String PARAM_WORKSPACE_NAME = "workspaceName";
        public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
-       public final static ImageDescriptor DEFAULT_ICON = DistPlugin
-                       .getImageDescriptor("icons/normalize.gif");
 
        private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH;
 
-       private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
-       private JarFileIndexer jarFileIndexer = new JarFileIndexer();
-       private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer(
-                       artifactIndexer, jarFileIndexer);
-
        // DEPENDENCY INJECTION
        private RepositoryFactory repositoryFactory;
        private Keyring keyring;
        private Repository repository;
 
-       public Object execute(ExecutionEvent event) throws ExecutionException {
+       private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
+       private JarFileIndexer jarFileIndexer = new JarFileIndexer();
+       private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer(
+                       artifactIndexer, jarFileIndexer);
 
+       public Object execute(ExecutionEvent event) throws ExecutionException {
                String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
                String wkspName = event.getParameter(PARAM_WORKSPACE_NAME);
 
@@ -88,7 +87,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                try {
                        String msg = "Your are about to normalize workspace: " + wkspName
                                        + ".\nThis will index OSGi bundles and Maven artifacts, "
-                                       + "it will also generate pdeSources if needed.\n"
+                                       + "it will also convert Maven sources to PDE Sources if needed.\n"
                                        + "Note that no information will be overwritten: "
                                        + "all existing information are kept."
                                        + "\n\n Do you really want to proceed ?";
@@ -126,10 +125,9 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
 
                @Override
                protected IStatus run(IProgressMonitor progressMonitor) {
-
                        try {
                                ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
-                               // normalize artifacts
+                               // Normalize artifacts
                                Query countQuery = session
                                                .getWorkspace()
                                                .getQueryManager()
@@ -203,7 +201,6 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                @Override
                protected void leaving(Node node, int level) throws RepositoryException {
                }
-
        }
 
        /* DEPENDENCY INJECTION */
index a6f38e872b794c9aa0146d36d2fa936a393cd514..76b0586e980f3ffcea44896b705e9e215cf65a63 100644 (file)
@@ -25,6 +25,7 @@ import javax.jcr.security.Privilege;
 
 import org.argeo.ArgeoException;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcConstants;
 import org.argeo.slc.client.ui.dist.DistPlugin;
 import org.argeo.slc.repo.RepoUtils;
 import org.argeo.util.security.Keyring;
@@ -35,15 +36,13 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.resource.ImageDescriptor;
 
 /**
- * Publish the current workspace by giving REOD_ONLY rights to anonymous.
+ * Publish the current workspace by giving READ_ONLY rights to anonymous.
  */
-
 public class PublishWorkspace extends AbstractHandler {
        // private static final Log log = LogFactory.getLog(PublishWorkspace.class);
-       public final static String ID = DistPlugin.ID + ".publishWorkspace";
-       public final static String DEFAULT_LABEL = "Publish workspace";
        
-       // public final static String DEFAULT_ICON_PATH = "icons/publish.gif";
+       public final static String ID = DistPlugin.ID + ".publishWorkspace";
+       public final static String DEFAULT_LABEL = "Make Public";
        public final static ImageDescriptor DEFAULT_ICON = DistPlugin
                        .getImageDescriptor("icons/publish.gif");
 
@@ -55,7 +54,7 @@ public class PublishWorkspace extends AbstractHandler {
        private Keyring keyring;
        private Repository nodeRepository;
 
-       private String publicRole = "anonymous";
+       private String publicRole = SlcConstants.USER_ANONYMOUS;
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
@@ -79,12 +78,10 @@ public class PublishWorkspace extends AbstractHandler {
                                        "Confirm publication", msg);
 
                        if (result) {
-
                                session = repository.login(credentials, workspaceName);
                                JcrUtils.addPrivilege(session, "/", publicRole,
                                                Privilege.JCR_READ);
                                session.save();
-
                                JcrUtils.logoutQuietly(session);
                                // CommandHelpers.callCommand(RefreshDistributionsView.ID);
                        }
index e69205b6125138a24c3612113036719bf891ac90..b63481c9d93d4c5382ee26b308c6c12fdfa683ad 100644 (file)
@@ -22,7 +22,7 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 /**
- * Change visible state of the ArtifactBrower size column
+ * Force the refresh of the artifact browser view
  */
 public class RefreshArtifactBrowser extends AbstractHandler {
 
index f8431b09adfa8b6738c109b7ae7061b46882b5ca..bec66da3f0e86ff6f0b6909066b7e4310495ac76 100644 (file)
@@ -48,6 +48,7 @@ import org.argeo.slc.client.ui.dist.model.RepoElem;
 import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
 import org.argeo.slc.jcr.SlcNames;
+import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
@@ -71,12 +72,13 @@ import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.part.ViewPart;
 
 /**
- * Browse, manipulate and manage distributions accross multiple repositories
+ * Browse, manipulate and manage distributions across multiple repositories
  * (like fetch, merge, publish, etc.).
  */
 public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames {
        // private final static Log log =
        // LogFactory.getLog(DistributionsView.class);
+
        public final static String ID = DistPlugin.ID + ".distributionsView";
 
        /* DEPENDENCY INJECTION */
@@ -104,10 +106,10 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                viewer.addDoubleClickListener(new DistTreeDoubleClickListener());
                viewer.setComparator(new DistTreeComparator());
 
-               // Enable selection retrieving from outside the view
+               // Enable retrieving current tree selected items from outside the view
                getSite().setSelectionProvider(viewer);
 
-               // Drag'n drop
+               // Drag and drop
                Transfer[] tt = new Transfer[] { TextTransfer.getInstance() };
                int operations = DND.DROP_COPY | DND.DROP_MOVE;
                viewer.addDragSupport(operations, tt, new ViewDragListener());
@@ -195,16 +197,6 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                (isRepoElem || isDistribGroupElem) && singleElement
                                                                && !isReadOnly, params);
 
-                               // publish workspace
-                               params = new HashMap<String, String>();
-                               params.put(PublishWorkspace.PARAM_TARGET_REPO_PATH,
-                                               targetRepoPath);
-                               params.put(PublishWorkspace.PARAM_WORKSPACE_NAME, workspaceName);
-                               CommandUtils.refreshParametrizedCommand(menuManager, window,
-                                               PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL,
-                                               PublishWorkspace.DEFAULT_ICON, isDistribElem
-                                                               && singleElement && !isReadOnly, params);
-
                                // Register a remote repository
                                CommandUtils.refreshCommand(menuManager, window,
                                                RegisterRepository.ID,
@@ -229,18 +221,6 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                isRepoElem && isHomeRepo && singleElement
                                                                && !isReadOnly, params);
 
-                               // Normalize workspace
-                               params = new HashMap<String, String>();
-                               params.put(NormalizeDistribution.PARAM_TARGET_REPO_PATH,
-                                               targetRepoPath);
-                               params.put(NormalizeDistribution.PARAM_WORKSPACE_NAME,
-                                               workspaceName);
-                               CommandUtils.refreshParametrizedCommand(menuManager, window,
-                                               NormalizeDistribution.ID,
-                                               NormalizeDistribution.DEFAULT_LABEL,
-                                               NormalizeDistribution.DEFAULT_ICON, isDistribElem
-                                                               && singleElement && !isReadOnly, params);
-
                                // Normalize workspace
                                params = new HashMap<String, String>();
                                params.put(NormalizeWorkspace.PARAM_TARGET_REPO_PATH,
@@ -249,7 +229,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                workspaceName);
 
                                CommandUtils.refreshParametrizedCommand(menuManager, window,
-                                               NormalizeWorkspace.ID, "Normalize workspace...",
+                                               NormalizeWorkspace.ID, "Normalize...",
                                                NormalizeWorkspace.DEFAULT_ICON, isDistribElem
                                                                && singleElement && !isReadOnly, params);
 
@@ -273,6 +253,39 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                DeleteWorkspace.DEFAULT_ICON, isDistribElem
                                                                && singleElement && !isReadOnly, params);
 
+                               // Advanced submenu
+                               MenuManager submenu = new MenuManager("Advanced", DistPlugin.ID
+                                               + ".advancedSubmenu");
+                               IContributionItem ici = menuManager.find(DistPlugin.ID
+                                               + ".advancedSubmenu");
+                               if (ici != null)
+                                       menuManager.remove(ici);
+
+                               // Normalize distribution (Legacy)
+                               params = new HashMap<String, String>();
+                               params.put(NormalizeDistribution.PARAM_TARGET_REPO_PATH,
+                                               targetRepoPath);
+                               params.put(NormalizeDistribution.PARAM_WORKSPACE_NAME,
+                                               workspaceName);
+                               CommandUtils.refreshParametrizedCommand(submenu, window,
+                                               NormalizeDistribution.ID,
+                                               NormalizeDistribution.DEFAULT_LABEL,
+                                               NormalizeDistribution.DEFAULT_ICON, isDistribElem
+                                                               && singleElement && !isReadOnly, params);
+
+                               // publish workspace
+                               params = new HashMap<String, String>();
+                               params.put(PublishWorkspace.PARAM_TARGET_REPO_PATH,
+                                               targetRepoPath);
+                               params.put(PublishWorkspace.PARAM_WORKSPACE_NAME, workspaceName);
+                               CommandUtils.refreshParametrizedCommand(submenu, window,
+                                               PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL,
+                                               PublishWorkspace.DEFAULT_ICON, isDistribElem
+                                                               && singleElement && !isReadOnly, params);
+
+                               if (submenu.getSize() > 0)
+                                       menuManager.add(submenu);
+
                                // // Manage workspace authorizations
                                // params = new HashMap<String, String>();
                                // params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);