From a5aee512a4db104dd6b733e7f56607b056164fab Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Fri, 21 Mar 2014 21:04:32 +0000 Subject: [PATCH] enrich the modular distribution's module list to display if a given module exists in the current workspace. git-svn-id: https://svn.argeo.org/slc/trunk@6909 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../ui/dist/editors/DistWkspBrowserPage.java | 50 +++++----- .../ModularDistVersionOverviewPage.java | 95 ++++++++++++++----- 2 files changed, 98 insertions(+), 47 deletions(-) diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWkspBrowserPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWkspBrowserPage.java index 3656019fd..b04d1cf3d 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWkspBrowserPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWkspBrowserPage.java @@ -86,41 +86,22 @@ public class DistWkspBrowserPage extends FormPage implements DistConstants, ScrolledForm form = managedForm.getForm(); Composite parent = form.getBody(); parent.setLayout(new FillLayout()); - createExportPackageSection(parent); + createMavenBrowserPart(parent); getEditor().getSite().setSelectionProvider(artifactTreeViewer); } catch (RepositoryException e) { throw new SlcException("Cannot create artifact browser page", e); } } - private NodeIterator listNodes(String nodeType, String orderBy) - throws RepositoryException { - QueryManager queryManager = session.getWorkspace().getQueryManager(); - QueryObjectModelFactory factory = queryManager.getQOMFactory(); - - final String nodeSelector = "nodes"; - Selector source = factory.selector(nodeType, nodeSelector); - - Ordering order = factory.ascending(factory.propertyValue(nodeSelector, - orderBy)); - Ordering[] orderings = { order }; - - QueryObjectModel query = factory.createQuery(source, null, orderings, - null); - - QueryResult result = query.execute(); - - return result.getNodes(); - } - - /** Export Package Section */ - private void createExportPackageSection(Composite parent) + /** Aether specific browser for the current workspace */ + private void createMavenBrowserPart(Composite parent) throws RepositoryException { int style = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER; + Tree tree = new Tree(parent, style); - createColumn(tree, "Artifacts", SWT.LEFT, 450); + createColumn(tree, "Maven browser", SWT.LEFT, 450); tree.setLinesVisible(true); tree.setHeaderVisible(true); @@ -290,4 +271,25 @@ public class DistWkspBrowserPage extends FormPage implements DistConstants, return result; } + private NodeIterator listNodes(String nodeType, String orderBy) + throws RepositoryException { + QueryManager queryManager = session.getWorkspace().getQueryManager(); + QueryObjectModelFactory factory = queryManager.getQOMFactory(); + + final String nodeSelector = "nodes"; + Selector source = factory.selector(nodeType, nodeSelector); + + Ordering order = factory.ascending(factory.propertyValue(nodeSelector, + orderBy)); + Ordering[] orderings = { order }; + + QueryObjectModel query = factory.createQuery(source, null, orderings, + null); + + QueryResult result = query.execute(); + + return result.getNodes(); + } + + } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java index da537380a..069ce94d5 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java @@ -48,6 +48,7 @@ import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; +import org.argeo.slc.repo.maven.MavenConventionsUtils; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -80,6 +81,8 @@ import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.sonatype.aether.artifact.Artifact; +import org.sonatype.aether.util.artifact.DefaultArtifact; /** * Show all modules contained in a given modular distribution as filter-able @@ -371,6 +374,21 @@ public class ModularDistVersionOverviewPage extends FormPage implements propertiesList.add(SLC_VERSION); propertyTypesList.add(PropertyType.STRING); + // Exists in workspace + col = new TableViewerColumn(viewer, SWT.NONE); + col.getColumn().setWidth(160); + col.getColumn().setText("Exists in workspace"); + col.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return getRealizedModule((Node) element) != null ? "Yes" : "No"; + // return JcrUtils.get((Node) element, SLC_VERSION); + } + }); + // col.getColumn().addSelectionListener(getSelectionAdapter(2)); + // propertiesList.add(SLC_VERSION); + // propertyTypesList.add(PropertyType.STRING); + final Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); @@ -383,21 +401,49 @@ public class ModularDistVersionOverviewPage extends FormPage implements propertyTypesList); viewer.setComparator(comparator); -// // Context Menu -// 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); + // // Context Menu + // 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); // Double click viewer.addDoubleClickListener(new DoubleClickListener()); } + private Node getRealizedModule(Node moduleCoordinates) { + try { + String category = JcrUtils.get(moduleCoordinates, SLC_CATEGORY); + String name = JcrUtils.get(moduleCoordinates, SLC_NAME); + String version = JcrUtils.get(moduleCoordinates, SLC_VERSION); + Artifact artifact = new DefaultArtifact(category + ":" + name + + ":" +version); + String parentPath = MavenConventionsUtils.artifactParentPath( + RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, artifact); + + Session session = modularDistribution.getSession(); + if (session.nodeExists(parentPath)) { + Node parent = session.getNode(parentPath); + NodeIterator nit = parent.getNodes(); + while (nit.hasNext()) { + Node currN = nit.nextNode(); + if (currN.isNodeType(SlcTypes.SLC_ARTIFACT)) + return currN; + } + } + } catch (RepositoryException re) { + throw new SlcException( + "unable to retrieve realized module with coordinates " + + moduleCoordinates, re); + } + return null; + } + private void refresh() { final List result = JcrUtils .nodeIteratorToList(listBundleArtifacts()); @@ -528,25 +574,28 @@ public class ModularDistVersionOverviewPage extends FormPage implements if (obj instanceof Node) { Node node = (Node) obj; try { - if (node.isNodeType(SlcTypes.SLC_ARTIFACT)) { - ModuleEditorInput dwip = (ModuleEditorInput) getEditorInput(); - Map params = new HashMap(); - params.put(OpenModuleEditor.PARAM_REPO_NODE_PATH, - dwip.getRepoNodePath()); - params.put(OpenModuleEditor.PARAM_REPO_URI, - dwip.getUri()); - params.put(OpenModuleEditor.PARAM_WORKSPACE_NAME, - dwip.getWorkspaceName()); - String path = node.getPath(); - params.put(OpenModuleEditor.PARAM_MODULE_PATH, path); - CommandUtils.callCommand(OpenModuleEditor.ID, params); + if (node.isNodeType(SlcTypes.SLC_MODULE_COORDINATES)) { + Node realizedModule = getRealizedModule(node); + if (realizedModule != null) { + ModuleEditorInput dwip = (ModuleEditorInput) getEditorInput(); + Map params = new HashMap(); + params.put(OpenModuleEditor.PARAM_REPO_NODE_PATH, + dwip.getRepoNodePath()); + params.put(OpenModuleEditor.PARAM_REPO_URI, + dwip.getUri()); + params.put(OpenModuleEditor.PARAM_WORKSPACE_NAME, + dwip.getWorkspaceName()); + String path = realizedModule.getPath(); + params.put(OpenModuleEditor.PARAM_MODULE_PATH, path); + CommandUtils.callCommand(OpenModuleEditor.ID, + params); + } } } catch (RepositoryException re) { throw new SlcException("Cannot get path for node " + node + " while setting parameters for " + "command OpenModuleEditor", re); } - } } } -- 2.39.2