]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java
Work on the modular distribution - generate binaries, work on layout.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / views / DistributionsView.java
index 908aff571be7285c915bd833f9a09addec45e19c..2838863173137385986c2816d043bc8193b2fecc 100644 (file)
@@ -34,17 +34,21 @@ import org.argeo.slc.client.ui.dist.commands.Fetch;
 import org.argeo.slc.client.ui.dist.commands.MergeWorkspaces;
 import org.argeo.slc.client.ui.dist.commands.NormalizeDistribution;
 import org.argeo.slc.client.ui.dist.commands.NormalizeWorkspace;
+import org.argeo.slc.client.ui.dist.commands.OpenGenerateBinariesWizard;
 import org.argeo.slc.client.ui.dist.commands.PublishWorkspace;
 import org.argeo.slc.client.ui.dist.commands.RefreshDistributionsView;
 import org.argeo.slc.client.ui.dist.commands.RegisterRepository;
+import org.argeo.slc.client.ui.dist.commands.RunInOsgi;
 import org.argeo.slc.client.ui.dist.commands.UnregisterRemoteRepo;
 import org.argeo.slc.client.ui.dist.controllers.DistTreeComparator;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeComparer;
 import org.argeo.slc.client.ui.dist.controllers.DistTreeContentProvider;
 import org.argeo.slc.client.ui.dist.controllers.DistTreeDoubleClickListener;
 import org.argeo.slc.client.ui.dist.controllers.DistTreeLabelProvider;
 import org.argeo.slc.client.ui.dist.model.DistParentElem;
-import org.argeo.slc.client.ui.dist.model.GroupElem;
+import org.argeo.slc.client.ui.dist.model.ModularDistBaseElem;
 import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.client.ui.dist.model.WkspGroupElem;
 import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
 import org.argeo.slc.jcr.SlcNames;
@@ -57,6 +61,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.jface.viewers.ViewerDropAdapter;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.DND;
@@ -103,9 +108,14 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
 
                // viewer.setContentProvider(new DistTreeContentProvider());
                viewer.setContentProvider(treeContentProvider);
-               viewer.addDoubleClickListener(new DistTreeDoubleClickListener());
+               viewer.addDoubleClickListener(new DistTreeDoubleClickListener(viewer));
+               viewer.setComparer(new DistTreeComparer());
+
                viewer.setComparator(new DistTreeComparator());
 
+               @SuppressWarnings("unused")
+               ViewerComparator vc = viewer.getComparator();
+
                // Enable retrieving current tree selected items from outside the view
                getSite().setSelectionProvider(viewer);
 
@@ -149,30 +159,39 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                String targetRepoPath = null, workspaceName = null, workspacePrefix = null;
                                // String targetRepoUri = null;
                                // Build conditions depending on element type
-                               boolean isDistribElem = false, isRepoElem = false, isDistribGroupElem = false;
-                               boolean isHomeRepo = false, isReadOnly = true;
+                               boolean isDistribElem = false, isModularDistBaseElem = false, isRepoElem = false, isDistribGroupElem = false;
+                               boolean isLocal = false, isReadOnly = true;
 
                                RepoElem re = null;
 
                                if (firstElement instanceof WorkspaceElem) {
                                        WorkspaceElem de = (WorkspaceElem) firstElement;
-                                       re = de.getRepoElem();
+                                       re = (RepoElem) de.getParent().getParent();
                                        isDistribElem = true;
                                        isReadOnly = de.isReadOnly();
                                        workspaceName = de.getWorkspaceName();
+                                       isLocal = de.inHome();
                                } else if (firstElement instanceof RepoElem) {
                                        re = (RepoElem) firstElement;
                                        isRepoElem = true;
-                                       isHomeRepo = re.inHome();
+                                       isLocal = re.inHome();
+                                       isReadOnly = re.isReadOnly();
+                               } else if (firstElement instanceof ModularDistBaseElem) {
+                                       ModularDistBaseElem mdbe = (ModularDistBaseElem) firstElement;
+                                       re = (RepoElem) mdbe.getParent().getParent().getParent();
+                                       isModularDistBaseElem = true;
+                                       isLocal = re.inHome();
                                        isReadOnly = re.isReadOnly();
-                               } else if (firstElement instanceof GroupElem) {
-                                       GroupElem dge = (GroupElem) firstElement;
-                                       isReadOnly = dge.isReadOnly();
+                               } else if (firstElement instanceof WkspGroupElem) {
+                                       WkspGroupElem wge = (WkspGroupElem) firstElement;
+                                       isReadOnly = wge.isReadOnly();
                                        isDistribGroupElem = true;
-                                       re = dge.getRepoElem();
-                                       workspacePrefix = dge.getLabel();
+                                       re = (RepoElem) wge.getParent();
+                                       workspacePrefix = wge.getName();
                                }
 
+                               // TODO add case for goups
+
                                if (re != null) {
                                        // targetRepoUri = re.getUri();
                                        targetRepoPath = re.getRepoNode().getPath();
@@ -211,15 +230,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                UnregisterRemoteRepo.ID,
                                                UnregisterRemoteRepo.DEFAULT_LABEL,
                                                UnregisterRemoteRepo.DEFAULT_ICON, isRepoElem
-                                                               && !isHomeRepo && singleElement, params);
+                                                               && !isLocal && singleElement, params);
 
                                // Fetch repository
                                params = new HashMap<String, String>();
                                params.put(Fetch.PARAM_TARGET_REPO_PATH, targetRepoPath);
                                CommandUtils.refreshParametrizedCommand(menuManager, window,
                                                Fetch.ID, Fetch.DEFAULT_LABEL, Fetch.DEFAULT_ICON,
-                                               isRepoElem && isHomeRepo && singleElement
-                                                               && !isReadOnly, params);
+                                               isRepoElem && isLocal && singleElement && !isReadOnly,
+                                               params);
 
                                // Normalize workspace
                                params = new HashMap<String, String>();
@@ -270,7 +289,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL,
                                                PublishWorkspace.DEFAULT_ICON, isDistribElem
                                                                && singleElement && !isReadOnly, params);
-                               
+
                                // Normalize distribution (Legacy)
                                params = new HashMap<String, String>();
                                params.put(NormalizeDistribution.PARAM_TARGET_REPO_PATH,
@@ -283,7 +302,19 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                                NormalizeDistribution.DEFAULT_ICON, isDistribElem
                                                                && singleElement && !isReadOnly, params);
 
-                       
+                               // Run in OSGi
+                               params = new HashMap<String, String>();
+                               params.put(RunInOsgi.PARAM_WORKSPACE_NAME, workspaceName);
+                               CommandUtils.refreshParametrizedCommand(submenu, window,
+                                               RunInOsgi.ID, RunInOsgi.DEFAULT_LABEL,
+                                               RunInOsgi.DEFAULT_ICON, isDistribElem && singleElement
+                                                               && isLocal, params);// Run in OSGi
+
+                               CommandUtils.refreshCommand(submenu, window,
+                                               OpenGenerateBinariesWizard.ID,
+                                               OpenGenerateBinariesWizard.DEFAULT_LABEL,
+                                               OpenGenerateBinariesWizard.DEFAULT_ICON,
+                                               isModularDistBaseElem && !isReadOnly);
 
                                if (submenu.getSize() > 0)
                                        menuManager.add(submenu);
@@ -324,8 +355,8 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                        if (selection.getFirstElement() instanceof WorkspaceElem) {
                                WorkspaceElem de = (WorkspaceElem) selection.getFirstElement();
                                if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
-                                       event.data = de.getRepoElem().getUri() + "/"
-                                                       + de.getWorkspaceName();
+                                       event.data = ((RepoElem) de.getParent().getParent())
+                                                       .getUri() + "/" + de.getWorkspaceName();
                                }
                        }
                }
@@ -340,14 +371,18 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
 
                @Override
                public boolean performDrop(Object data) {
-                       WorkspaceElem sourceDist = (WorkspaceElem) getSelectedObject();
+                       WorkspaceElem sourceWksp = (WorkspaceElem) getSelectedObject();
                        RepoElem targetRepo = (RepoElem) getCurrentTarget();
 
-                       Boolean ok = MessageDialog.openConfirm(getSite().getShell(),
-                                       "Confirm distribution merge", "Do you want to merge "
-                                                       + sourceDist.getWorkspaceName() + " (from repo "
-                                                       + sourceDist.getRepoElem().getLabel()
-                                                       + ") to repo " + targetRepo.getLabel() + "?");
+                       Boolean ok = MessageDialog.openConfirm(
+                                       getSite().getShell(),
+                                       "Confirm distribution merge",
+                                       "Do you want to merge "
+                                                       + sourceWksp.getWorkspaceName()
+                                                       + " (from repo "
+                                                       + ((RepoElem) sourceWksp.getParent().getParent())
+                                                                       .getLabel() + ") to repo "
+                                                       + targetRepo.getLabel() + "?");
                        if (!ok)
                                return false;
 
@@ -355,14 +390,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                                Map<String, String> params = new HashMap<String, String>();
                                params.put(MergeWorkspaces.PARAM_TARGET_REPO_PATH, targetRepo
                                                .getRepoNode().getPath());
-                               params.put(MergeWorkspaces.PARAM_SOURCE_REPO_PATH, sourceDist
-                                               .getRepoElem().getRepoNode().getPath());
+                               params.put(MergeWorkspaces.PARAM_SOURCE_REPO_PATH,
+                                               ((RepoElem) sourceWksp.getParent().getParent())
+                                                               .getRepoNode().getPath());
                                params.put(MergeWorkspaces.PARAM_SOURCE_WORKSPACE_NAME,
-                                               sourceDist.getWorkspaceName());
+                                               sourceWksp.getWorkspaceName());
                                CommandHelpers.callCommand(RefreshDistributionsView.ID, params);
                                return true;
                        } catch (RepositoryException e) {
-                               throw new SlcException("Cannot process drop from " + sourceDist
+                               throw new SlcException("Cannot process drop from " + sourceWksp
                                                + " to " + targetRepo, e);
                        }
                }
@@ -373,8 +409,8 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames
                        if (target instanceof RepoElem) {
                                if (getSelectedObject() instanceof WorkspaceElem) {
                                        // check if not same repository
-                                       String srcRepoUri = ((WorkspaceElem) getSelectedObject())
-                                                       .getRepoElem().getUri();
+                                       String srcRepoUri = ((RepoElem) ((WorkspaceElem) getSelectedObject())
+                                                       .getParent().getParent()).getUri();
                                        String targetRepoUri = ((RepoElem) target).getUri();
                                        return !targetRepoUri.equals(srcRepoUri);
                                }