#slc.executionModules=org.argeo.infra.slc.rpmfactory,\
#org.argeo.elgis.rpmfactory,\
-org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.slcExecutionPerspective
-#org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.distributionPerspective
+#org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.slcExecutionPerspective
+org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.distributionPerspective
# JCR
#argeo.node.repo.home=data/node/repo
org.argeo.jcr,
org.argeo.jcr.security,
org.argeo.jcr.spring,
- org.argeo.jcr.ui.explorer.utils,
org.argeo.slc.jcr,
org.argeo.slc.repo,
org.eclipse.ui.forms,
<bean id="queryArtifactsForm" class="org.argeo.slc.client.ui.dist.views.QueryArtifactsForm"
scope="prototype">
<property name="session" ref="slcSession" />
+ <property name="columnProperties">
+ <list>
+ <value>slc:artifactVersion.jcr:uuid</value>
+ <value>slc:artifactVersion.slc:groupId</value>
+ <value>slc:artifactVersion.slc:artifactId</value>
+ <value>slc:artifactVersion.slc:artifactVersion</value>
+ </list>
+ </property>
</bean>
<bean id="queryBundlesForm" class="org.argeo.slc.client.ui.dist.views.QueryBundlesForm"
scope="prototype">
<property name="session" ref="slcSession" />
+ <property name="columnProperties">
+ <list>
+ <value>slc:artifactVersion.jcr:uuid</value>
+ <value>slc:bundleArtifact.slc:symbolic-name</value>
+ <value>slc:artifactVersion.slc:groupId</value>
+ <value>slc:bundleArtifact.slc:bundle-version</value>
+ <!-- <value>slc:bundleArtifact.slc:Fragment-Host</value> -->
+ </list>
+ </property>
</bean>
<bean id="queryArtifactsText" class="org.argeo.slc.client.ui.dist.views.QueryArtifactsText"
scope="prototype">
<property name="session" ref="slcSession" />
</bean>
-
- <util:list id="columnProperties" scope="prototype">
- <util:constant static-field="org.argeo.slc.jcr.SlcNames.SLC_ARTIFACT_ID" />
- <util:constant static-field="org.argeo.slc.jcr.SlcNames.SLC_GROUP_ID" />
- <util:constant static-field="org.argeo.slc.jcr.SlcNames.SLC_ARTIFACT_VERSION" />
- <util:constant static-field="org.argeo.slc.jcr.SlcNames.SLC_ARTIFACT_EXTENSION" />
- <util:constant static-field="org.argeo.slc.jcr.SlcNames.SLC_ARTIFACT_CLASSIFIER" />
- </util:list>
</beans>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
id="org.argeo.slc.client.ui.dist.artifactsBrowser"
+ icon="icons/packageBrowser.gif"
name="Artifacts browser">
</view>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
id="org.argeo.slc.client.ui.dist.queryArtifactsForm"
- name="Query Artifacts Form">
+ icon="icons/searchForm.gif"
+ name="Artifacts Form">
</view>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
id="org.argeo.slc.client.ui.dist.queryBundlesForm"
- name="Query Bundles Form">
+ icon="icons/searchForm.gif"
+ name="Bundles Form">
</view>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
id="org.argeo.slc.client.ui.dist.queryArtifactsText"
- name="Artifacts query builder">
+ icon="icons/search.gif"
+ name="Query builder">
</view>
</extension>
<!-- Editors -->
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.argeo.eclipse.spring.SpringExtensionFactory"
- id="org.argeo.slc.client.ui.dist.genericJcrQueryEditor"
- name="JCR Query"
- icon="icons/distribution_perspective.gif"
+ class="org.argeo.slc.client.ui.dist.editors.GenericArtifactEditor"
+ id="org.argeo.slc.client.ui.dist.genericArtifactEditor"
+ name="Artifact editor"
+ icon="icons/artifactVersionBase.gif"
default="false">
</editor>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
- defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- id="org.argeo.slc.client.ui.dist.openGenericJcrQueryEditor"
- name="OpenGenericJcrQueryEditor ">
+ defaultHandler="org.argeo.slc.client.ui.dist.commands.ShowSizeColumn"
+ id="org.argeo.slc.client.ui.dist.showSizeColumn"
+ name="Show size column">
+ <state
+ id="org.argeo.slc.client.ui.dist.showSizeColumn.toggleState">
+ <class class="org.eclipse.jface.commands.ToggleState">
+ <parameter
+ name="default"
+ value="true" />
+ </class>
+ </state>
+ </command>
+ <command
+ defaultHandler="org.argeo.slc.client.ui.dist.commands.RefreshArtifactBrowser"
+ id="org.argeo.slc.client.ui.dist.refreshArtifactBrowser"
+ name="Refresh Artifact Browser">
</command>
</extension>
<extension
id="menu:org.eclipse.ui.main.menu"
point="org.eclipse.ui.menus">
+
+ <!-- View Specific Menus -->
+ <menuContribution
+ locationURI="toolbar:org.argeo.slc.client.ui.dist.artifactsBrowser">
+ <command
+ commandId="org.argeo.slc.client.ui.dist.showSizeColumn"
+ icon="icons/showSize.gif"
+ style="toggle"
+ label="Show sizes"
+ tooltip="Warning: showing size column might reduce overall browser reactivity">
+ </command>
+ <command
+ commandId="org.argeo.slc.client.ui.dist.refreshArtifactBrowser"
+ icon="icons/refresh.png"
+ label="Refresh"
+ tooltip="Refresh the whole browser">
+ </command>
+ </menuContribution>
+
<!-- Queries -->
<!-- <menuContribution
allPopups="false"
<version>${version.argeo-commons}</version>
</dependency>
<dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.jcr.ui.explorer</artifactId>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.ui.jcr</artifactId>
<version>${version.argeo-commons}</version>
</dependency>
<dependency>
*/
public final static String DATE_TIME_FORMAT = "MM/dd/yyyy, HH:mm";
public final static String DATE_FORMAT = "MM/dd/yyyy";
+ // this should be directly got in JCR
+ public final static String JCR_IDENTIFIER = "jcr:uuid";
- /*
- * Architecture specific constants
- */
- public final static String BASE_ARTIFACTS_NODE_PATH = "/slc/repo/artifacts";
+
+
}
--- /dev/null
+package org.argeo.slc.client.ui.dist;
+
+import org.eclipse.swt.graphics.Image;
+
+/** Shared icons. */
+public class DistImages {
+ public final static Image IMG_ARTIFACT_BASE = DistPlugin
+ .getImageDescriptor("icons/artifactBase.gif").createImage();
+ public final static Image IMG_ARTIFACT_VERSION_BASE = DistPlugin
+ .getImageDescriptor("icons/artifactVersionBase.gif").createImage();
+ public final static Image IMG_FILE = DistPlugin.getImageDescriptor(
+ "icons/file.gif").createImage();
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist;
+
+public class DistLabels {
+
+ public static String getLabel(String jcrName){
+ String label = null;
+
+
+ return label;
+ }
+}
package org.argeo.slc.client.ui.dist;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
private static BundleContext bundleContext;
public final static String ID = "org.argeo.slc.client.ui.dist";
- @Override
+ private static DistPlugin plugin;
+
public void start(BundleContext context) throws Exception {
- bundleContext = context;
+ super.start(context);
+ plugin = this;
+ }
+
+ public static DistPlugin getDefault() {
+ return plugin;
}
public static BundleContext getBundleContext() {
return bundleContext;
}
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(ID, path);
+ }
+
}
--- /dev/null
+package org.argeo.slc.client.ui.dist.commands;
+
+import org.argeo.slc.client.ui.dist.views.ArtifactsBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Change visible state of the ArtifactBrower size column
+ */
+public class RefreshArtifactBrowser extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ArtifactsBrowser view = (ArtifactsBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(ArtifactsBrowser.ID);
+ view.refresh(null);
+ return null;
+ }
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist.commands;
+
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.views.ArtifactsBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.State;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Change visible state of the ArtifactBrower size column
+ */
+public class ShowSizeColumn extends AbstractHandler {
+ public final static String ID = DistPlugin.ID + ".showSizeColumn";
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ArtifactsBrowser view = (ArtifactsBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(ArtifactsBrowser.ID);
+
+ ICommandService service = (ICommandService) PlatformUI.getWorkbench()
+ .getService(ICommandService.class);
+ Command command = service.getCommand(ID);
+ State state = command.getState(ID + ".toggleState");
+
+ boolean wasVisible = (Boolean) state.getValue();
+ view.setSizeVisible(!wasVisible);
+ state.setValue(!wasVisible);
+ return null;
+ }
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist.editors;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.slc.client.ui.dist.DistImages;
+import org.argeo.slc.client.ui.dist.utils.DistUiHelpers;
+import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * Generic editor property page. Lists all properties of current node as a
+ * complex tree. TODO: enable editing
+ */
+
+public class ArtifactDetailsPage extends FormPage implements SlcNames, SlcTypes {
+ private final static Log log = LogFactory.getLog(ArtifactDetailsPage.class);
+
+ // Main business Objects
+ private Node currentNode;
+
+ // This page widgets
+ private FormToolkit tk;
+ private TreeViewer complexTree;
+ private Text mavenSnippet;
+
+ public ArtifactDetailsPage(FormEditor editor, String title, Node currentNode) {
+ super(editor, "id", title);
+ this.currentNode = currentNode;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ tk = managedForm.getToolkit();
+ ScrolledForm form = managedForm.getForm();
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 5;
+ form.getBody().setLayout(layout);
+
+ complexTree = createComplexTree(form.getBody());
+ createMavenSnipet(form.getBody());
+ }
+
+ private TreeViewer createComplexTree(Composite parent) {
+ int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION;
+ Tree tree = new Tree(parent, style);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = true;
+ tree.setLayoutData(gd);
+ createColumn(tree, "Attribute", SWT.LEFT, 200);
+ createColumn(tree, "Value", SWT.LEFT, 200);
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
+
+ TreeViewer result = new TreeViewer(tree);
+ result.setContentProvider(new TreeContentProvider());
+ result.setLabelProvider(new TreeLabelProvider());
+
+ result.setInput(currentNode);
+ result.expandToLevel(2);
+
+ result.addDoubleClickListener(new GenericDoubleClickListener(result));
+ // result.expandAll();
+ return result;
+ }
+
+ private void createMavenSnipet(Composite parent) {
+ mavenSnippet = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ gd.heightHint = 75;
+ mavenSnippet.setLayoutData(gd);
+ mavenSnippet.setText(generateXmlSnippet());
+ }
+
+ // Helpers
+ private String generateXmlSnippet() {
+ try {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<dependency>\n");
+ sb.append("\t<groupeId>");
+ sb.append(currentNode.getProperty(SLC_GROUP_ID).getString());
+ sb.append("</groupeId>\n");
+ sb.append("\t<artifactId>");
+ sb.append(currentNode.getProperty(SLC_ARTIFACT_ID).getString());
+ sb.append("</artifactId>\n");
+ sb.append("\t<version>");
+ sb.append(currentNode.getProperty(SLC_ARTIFACT_VERSION).getString());
+ sb.append("</version>\n");
+ sb.append("</dependency>");
+ return sb.toString();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "unexpected error while generating maven snippet");
+ }
+ }
+
+ private static TreeColumn createColumn(Tree parent, String name, int style,
+ int width) {
+ TreeColumn result = new TreeColumn(parent, style);
+ result.setText(name);
+ result.setWidth(width);
+ result.setMoveable(true);
+ result.setResizable(true);
+ return result;
+ }
+
+ // View specific object
+ private class ViewSpecificItems {
+ private String key;
+ private Object value;
+ private boolean isFolder;
+ private Node curNode;
+
+ public ViewSpecificItems(String key, Object value, boolean isFolder) {
+ this.key = key;
+ this.value = value;
+ this.isFolder = isFolder;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setNode(Node node) {
+ this.curNode = node;
+ }
+
+ public Node getNode() {
+ return curNode;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public boolean isFolder() {
+ return isFolder;
+ }
+
+ }
+
+ // providers
+ private class TreeLabelProvider extends ColumnLabelProvider implements
+ SlcTypes, SlcNames {
+
+ public void update(ViewerCell cell) {
+ try {
+
+ int colIndex = cell.getColumnIndex();
+ Object element = cell.getElement();
+ if (element instanceof Property) {
+ Property prop = (Property) element;
+ if (colIndex == 0)
+ cell.setText(DistUiHelpers.getLabelJcrName(prop
+ .getName()));
+ else if (colIndex == 1)
+ cell.setText(DistUiHelpers.formatValueAsString(prop
+ .getValue()));
+
+ } else if (element instanceof ViewSpecificItems) {
+ if (colIndex == 0)
+ cell.setText(((ViewSpecificItems) element).getKey());
+ else if (colIndex == 1)
+ cell.setText(DistUiHelpers
+ .formatAsString(((ViewSpecificItems) element)
+ .getValue()));
+
+ } else if (element instanceof Node) {
+ Node node = (Node) element;
+ if (colIndex == 0) {
+ if (node.isNodeType(NodeType.NT_FILE)) {
+ cell.setImage(DistImages.IMG_FILE);
+ cell.setText(node.getName());
+ } else if (node.isNodeType(SLC_IMPORTED_PACKAGE))
+ cell.setText("Import package");
+ else if (node.isNodeType(SLC_EXPORTED_PACKAGE))
+ cell.setText("Export package");
+
+ } else if (colIndex == 1) {
+ if (node.isNodeType(SLC_ARTIFACT)) {
+ StringBuffer sb = new StringBuffer("");
+ if (node.hasProperty(SLC_ARTIFACT_CLASSIFIER)) {
+ sb.append(node.getProperty(
+ SLC_ARTIFACT_CLASSIFIER).getString());
+ sb.append(" ");
+ }
+ if (node.hasProperty(SLC_ARTIFACT_EXTENSION))
+ sb.append(node.getProperty(
+ SLC_ARTIFACT_EXTENSION).getString());
+ cell.setText(sb.toString());
+ } else if (node.isNodeType(SLC_IMPORTED_PACKAGE)
+ || node.isNodeType(SLC_EXPORTED_PACKAGE))
+ cell.setText(node.getProperty(SLC_NAME).getString());
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "unexpected error while getting artifact information",
+ e);
+ }
+ }
+ }
+
+ private class TreeContentProvider implements ITreeContentProvider {
+ public Object[] getElements(Object parent) {
+ List<Object> elements = new ArrayList<Object>();
+
+ try {
+ Node node = (Node) parent;
+ elements = new ArrayList<Object>();
+
+ // Maven coordinates
+ elements.add(node.getProperty(SLC_GROUP_ID));
+ elements.add(node.getProperty(SLC_ARTIFACT_ID));
+ elements.add(node.getProperty(SLC_ARTIFACT_VERSION));
+
+ // Meta information
+ // boolean gotSource = false;
+ // // TODO: implement this check
+ // elements.add(new ViewSpecificItems("Sources available",
+ // gotSource));
+
+ // Jars
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext()) {
+ Node child = ni.nextNode();
+ if (child.isNodeType(SLC_ARTIFACT)) {
+ // we skip sha1 files for the time being.
+ elements.add(child);
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while listing node properties", e);
+ }
+ return elements.toArray();
+ }
+
+ public Object getParent(Object child) {
+ return null;
+ }
+
+ public Object[] getChildren(Object parent) {
+ Object[] result = null;
+ try {
+ if (parent instanceof Property) {
+ Property prop = (Property) parent;
+ if (prop.isMultiple()) {
+ Value[] values = prop.getValues();
+ return values;
+ }
+ } else if (parent instanceof Node) {
+ Node node = (Node) parent;
+ if (node.hasNodes()) {
+ List<Object> elements = new ArrayList<Object>();
+ PropertyIterator pi = node.getProperties();
+ while (pi.hasNext()) {
+ Property curProp = pi.nextProperty();
+ if (!curProp.getName().startsWith("jcr:")
+ && !curProp.isMultiple())
+ elements.add(curProp);
+ }
+
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext()) {
+ Node curNode = ni.nextNode();
+ if (curNode.isNodeType(SLC_IMPORTED_PACKAGE)
+ || curNode.isNodeType(SLC_EXPORTED_PACKAGE)) {
+ ViewSpecificItems vsi = new ViewSpecificItems(
+ "Bundle dependencies", "", true);
+ vsi.setNode(node);
+ elements.add(vsi);
+ break;
+ }
+ }
+ return elements.toArray();
+ }
+ } else if (parent instanceof ViewSpecificItems
+ && ((ViewSpecificItems) parent).isFolder()) {
+ NodeIterator ni = ((ViewSpecificItems) parent).getNode()
+ .getNodes();
+ List<Node> elements = new ArrayList<Node>();
+ while (ni.hasNext()) {
+ Node curNode = ni.nextNode();
+ if (curNode.isNodeType(SLC_IMPORTED_PACKAGE)
+ || curNode.isNodeType(SLC_EXPORTED_PACKAGE)) {
+ elements.add(curNode);
+ }
+ }
+ return elements.toArray();
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected error getting multiple values property.", e);
+ }
+ return result;
+ }
+
+ public boolean hasChildren(Object parent) {
+ try {
+ if (parent instanceof Property
+ && ((Property) parent).isMultiple()) {
+ return true;
+ } else if (parent instanceof Node && ((Node) parent).hasNodes()
+ && ((Node) parent).isNodeType(SLC_BUNDLE_ARTIFACT)) {
+ return true;
+ } else if (parent instanceof ViewSpecificItems
+ && ((ViewSpecificItems) parent).isFolder()) {
+ return true;
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while checking if property is multiple",
+ e);
+ }
+ return false;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+ }
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist.editors;
+
+import javax.jcr.Node;
+
+import org.argeo.ArgeoException;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+/**
+ *
+ * Container for the node editor page. At creation time, it takes a JCR Node
+ * that cannot be changed afterwards.
+ *
+ */
+public class GenericArtifactEditor extends FormEditor {
+
+ // private final static Log log =
+ // LogFactory.getLog(GenericNodeEditor.class);
+ public final static String ID = DistPlugin.ID + ".genericArtifactEditor";
+
+ // business objects
+ private Node artifactNode;
+
+ // This Editor widgets
+ private ArtifactDetailsPage artifactDetailsPage;
+
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ super.init(site, input);
+ GenericArtifactEditorInput gaei = (GenericArtifactEditorInput) getEditorInput();
+ artifactNode = gaei.getArtifactNode();
+ this.setPartName(gaei.getArtifactId());
+ }
+
+ @Override
+ protected void addPages() {
+ try {
+
+ artifactDetailsPage = new ArtifactDetailsPage(this, "Main",
+ artifactNode);
+ addPage(artifactDetailsPage);
+ } catch (PartInitException e) {
+ throw new ArgeoException("Not able to add an empty page ", e);
+ }
+ }
+
+ @Override
+ public void doSaveAs() {
+ // unused compulsory method
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ try {
+ // Automatically commit all pages of the editor
+ commitPages(true);
+ firePropertyChange(PROP_DIRTY);
+ } catch (Exception e) {
+ throw new ArgeoException("Error while saving node", e);
+ }
+
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ Node getArtifactNode() {
+ return artifactNode;
+ }
+}
--- /dev/null
+package org.argeo.slc.client.ui.dist.editors;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.slc.jcr.SlcNames;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input based the JCR node object.
+ * */
+
+public class GenericArtifactEditorInput implements IEditorInput, SlcNames {
+
+ private final Node artifactNode;
+ // cache key properties at creation time to avoid Exception at recoring time
+ // when the session has been closed
+ private String artifactId;
+ private String groupId;
+ private String version;
+
+ public GenericArtifactEditorInput(Node artifactNode) {
+ this.artifactNode = artifactNode;
+ try {
+ artifactId = artifactNode.getProperty(SLC_ARTIFACT_ID).getString();
+ groupId = artifactNode.getProperty(SLC_GROUP_ID).getString();
+ version = artifactNode.getProperty(SLC_ARTIFACT_VERSION)
+ .getString();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "unexpected error while getting node key values at creation time",
+ re);
+ }
+ }
+
+ public Node getArtifactNode() {
+ return artifactNode;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ // Dummy compulsory methods
+ public String getToolTipText() {
+ return artifactId + ":" + groupId + ":" + version;
+ }
+
+ public String getName() {
+ return artifactId + ":" + groupId + ":" + version;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /**
+ * equals method based on coordinates
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ GenericArtifactEditorInput other = (GenericArtifactEditorInput) obj;
+ if (!getGroupId().equals(other.getGroupId()))
+ return false;
+ if (!getArtifactId().equals(other.getArtifactId()))
+ return false;
+ if (!getVersion().equals(other.getVersion()))
+ return false;
+ return true;
+ }
+}
import javax.jcr.Node;
import javax.jcr.Property;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
-import javax.jcr.Value;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.client.ui.dist.DistImages;
+import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.graphics.Image;
public class ArtifactLabelProvider extends ColumnLabelProvider implements
- DistConstants {
+ DistConstants, SlcTypes {
// To be able to change column order easily
public static final int COLUMN_TREE = 0;
public static final int COLUMN_SIZE = 2;
// Utils
- protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
+ protected static DateFormat timeFormatter = new SimpleDateFormat(
+ DATE_TIME_FORMAT);
public void update(ViewerCell cell) {
+ int colIndex = cell.getColumnIndex();
Object element = cell.getElement();
- cell.setText(getColumnText(element, cell.getColumnIndex()));
- // Image image = getImage(element);
- // cell.setImage(image);
- // cell.setBackground(getBackground(element));
- // cell.setForeground(getForeground(element));
- // cell.setFont(getFont(element));
+ cell.setText(getColumnText(element, colIndex));
+ if (element instanceof Node && colIndex == 0) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_BASE);
+ else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_VERSION_BASE);
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ }
+
+ @Override
+ public Image getImage(Object element) {
+
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE)) {
+ return DistImages.IMG_ARTIFACT_BASE;
+ } else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
+ return DistImages.IMG_ARTIFACT_VERSION_BASE;
+ }
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ return null;
}
public String getColumnText(Object element, int columnIndex) {
else
return size + " KB";
case COLUMN_DATE:
- if (node.hasProperty(Property.JCR_CREATED))
+ if (node.hasProperty(Property.JCR_LAST_MODIFIED))
return timeFormatter.format(node
- .getProperty(Property.JCR_CREATED).getDate()
- .getTime());
+ .getProperty(Property.JCR_LAST_MODIFIED)
+ .getDate().getTime());
else
return null;
}
}
return null;
}
-
- private String formatValueAsString(Value value) {
- // TODO enhance this method
- try {
- String strValue;
-
- if (value.getType() == PropertyType.BINARY)
- strValue = "<binary>";
- else if (value.getType() == PropertyType.DATE)
- strValue = timeFormatter.format(value.getDate().getTime());
- else
- strValue = value.getString();
- return strValue;
- } catch (RepositoryException e) {
- throw new ArgeoException("unexpected error while formatting value",
- e);
- }
- }
}
package org.argeo.slc.client.ui.dist.providers;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
+import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
-public class ArtifactsTreeContentProvider implements ITreeContentProvider {
+public class ArtifactsTreeContentProvider implements ITreeContentProvider,
+ SlcTypes {
+
+ // Utils
+ private boolean sortChildren = true;
+ private JcrItemsComparator itemComparator = new JcrItemsComparator();
+
public Object[] getElements(Object parent) {
return getChildren(parent);
}
while (ni.hasNext()) {
nodesList.add(ni.nextNode());
}
- elements = nodesList.toArray();
+ if (sortChildren) {
+ Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList
+ .size()]);
+ Arrays.sort(arr, itemComparator);
+ return arr;
+ } else
+ return nodesList.toArray();
+
}
} catch (RepositoryException e) {
throw new ArgeoException(
public boolean hasChildren(Object parent) {
try {
- if (parent instanceof Node && ((Node) parent).hasNodes()) {
- return true;
+ if (parent instanceof Node) {
+ Node curNode = (Node) parent;
+ // We manually stop digging at this level
+ if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE))
+ return false;
+ else if (curNode.hasNodes())
+ return true;
}
} catch (RepositoryException e) {
throw new ArgeoException(
return false;
}
+ public void setSortChildren(boolean sortChildren) {
+ this.sortChildren = sortChildren;
+ }
+
+ public boolean getSortChildren() {
+ return sortChildren;
+ }
+
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
getSelectionAdapter(column.getColumn(), columnIndex));
indexToName.put(new Integer(columnIndex), jcrColumnName);
}
- Object[] objs = getColumnLabelAndWidth(jcrColumnName);
- column.getColumn().setWidth((Integer) objs[0]);
- column.getColumn().setText((String) objs[1]);
+ Object[] objs = DistUiHelpers
+ .getLabelAndDefaultValueWidth(jcrColumnName);
+ column.getColumn().setWidth((Integer) objs[1]);
+ column.getColumn().setText((String) objs[0]);
}
/**
- * Returns corresponding default width ( (int) object[0] ) and the header
- * label ( (String) object[1] ) depending on the property name.
- */
- public static Object[] getColumnLabelAndWidth(String propertyName) {
- // to avoid npe :
- if (propertyName == null)
- return new Object[] { 60, "(No name)" };
-
- if (propertyName.equals(SLC_ARTIFACT + "." + SLC_ARTIFACT_ID)) {
- return new Object[] { 140, "Artifact ID" };
- } else if (propertyName.equals(SLC_ARTIFACT + "." + SLC_GROUP_ID)) {
- return new Object[] { 120, "Group ID" };
- } else if (propertyName.equals(SLC_ARTIFACT + "."
- + SLC_ARTIFACT_VERSION)) {
- return new Object[] { 60, "Version" };
- } else if (propertyName.equals(SLC_ARTIFACT + "."
- + SLC_ARTIFACT_CLASSIFIER)) {
- return new Object[] { 60, "Classifier" };
- } else if (propertyName.equals(SLC_ARTIFACT + "."
- + SLC_ARTIFACT_EXTENSION)) {
- return new Object[] { 40, "Type" };
- } else if (propertyName.equals(SLC_ARTIFACT + ".jcr:uuid")) {
- return new Object[] { 20, "UUID" };
- } else {
- if (log.isTraceEnabled())
- log.trace("No Column label provider defined for property: ["
- + propertyName + "]");
- return new Object[] { 60, propertyName };
- }
- }
-
- /**
- * Might be used by client classes to sort columns.
+ * Might be used by client classes to sort the table with based on selected
+ * columns.
*
* @param column
* @param index
--- /dev/null
+package org.argeo.slc.client.ui.dist.utils;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+
+public class DistUiHelpers implements DistConstants, SlcTypes, SlcNames {
+ private final static Log log = LogFactory.getLog(DistUiHelpers.class);
+ private final static DateFormat df = new SimpleDateFormat(DATE_TIME_FORMAT);
+
+ /**
+ * Returns a user-friendly label for a given jcr property name. If the
+ * corresponding mapping is not found, the input String is returned. If
+ * input String is null "(No name)" is returned
+ */
+ public static String getLabelJcrName(String jcrName) {
+ return (String) getLabelAndDefaultValueWidth(jcrName)[0];
+ }
+
+ /**
+ * Returns a label ( (String) object[0] )and default value width ( (int)
+ * object[1] ) for a given property name
+ */
+ public static Object[] getLabelAndDefaultValueWidth(String propertyName) {
+ // to avoid npe :
+ if (propertyName == null)
+ return new Object[] { "(No name)", 60 };
+
+ // ArtifactId
+ if (propertyName.equals(SLC_ARTIFACT + "." + SLC_ARTIFACT_ID)
+ || propertyName.equals(SLC_ARTIFACT_BASE + "."
+ + SLC_ARTIFACT_ID)
+ || propertyName.equals(SLC_ARTIFACT_VERSION_BASE + "."
+ + SLC_ARTIFACT_ID)
+ || propertyName.equals(SLC_ARTIFACT_ID)) {
+ return new Object[] { "Artifact ID", 200 };
+ } // GroupId
+ else if (propertyName.equals(SLC_ARTIFACT + "." + SLC_GROUP_ID)
+ || propertyName.equals(SLC_ARTIFACT_BASE + "." + SLC_GROUP_ID)
+ || propertyName.equals(SLC_ARTIFACT_VERSION_BASE + "."
+ + SLC_GROUP_ID) || propertyName.equals(SLC_GROUP_ID)) {
+ return new Object[] { "Group ID", 120 };
+ } // Version
+ else if (propertyName.equals(SLC_ARTIFACT + "." + SLC_ARTIFACT_VERSION)
+ || propertyName.equals(SLC_ARTIFACT_VERSION_BASE + "."
+ + SLC_ARTIFACT_VERSION)
+ || propertyName.equals(SLC_ARTIFACT_VERSION)) {
+ return new Object[] { "Version", 60 };
+ } else if (propertyName.equals(SLC_ARTIFACT + "."
+ + SLC_ARTIFACT_CLASSIFIER)
+ || propertyName.equals(SLC_ARTIFACT_CLASSIFIER)) {
+ return new Object[] { "Classifier", 60 };
+ } else if (propertyName.equals(SLC_ARTIFACT + "."
+ + SLC_ARTIFACT_EXTENSION)
+ || propertyName.equals(SLC_ARTIFACT_EXTENSION)) {
+ return new Object[] { "Type", 40 };
+ } else if (propertyName.equals(SLC_BUNDLE_ARTIFACT + "."
+ + SLC_SYMBOLIC_NAME)
+ || propertyName.equals(SLC_SYMBOLIC_NAME)) {
+ return new Object[] { "Symbolic name", 180 };
+ } else if (propertyName.equals(SLC_BUNDLE_ARTIFACT + "."
+ + SLC_BUNDLE_VERSION)
+ || propertyName.equals(SLC_BUNDLE_VERSION)) {
+ return new Object[] { "Bundle version", 120 };
+ } else if (propertyName
+ .equals(SLC_BUNDLE_ARTIFACT + "." + SLC_MANIFEST)
+ || propertyName.equals(SLC_MANIFEST)) {
+ return new Object[] { "Manifest", 60 };
+ } // TODO remove hard coded strings
+ else if (propertyName.equals("slc:Bundle-ManifestVersion")) {
+ return new Object[] { "Bundle Manifest Version", 60 };
+ } else if (propertyName.equals("slc:Manifest-Version")) {
+ return new Object[] { "Manifest Version", 60 };
+ } else if (propertyName.equals("slc:Bundle-Vendor")) {
+ return new Object[] { "Bundle Vendor", 60 };
+ } else if (propertyName.equals("slc:Bundle-SymbolicName")) {
+ return new Object[] { "Bundle symbolic name", 60 };
+ } else if (propertyName.equals("slc:Bundle-Name")) {
+ return new Object[] { "Bundle name", 60 };
+ } else if (propertyName.equals("slc:Bundle-DocURL")) {
+ return new Object[] { "Doc URL", 120 };
+ } else if (propertyName.equals("slc:Bundle-Licence")) {
+ return new Object[] { "Bundle licence", 120 };
+ } else if (propertyName.equals(SLC_ARTIFACT_VERSION_BASE + "."
+ + JCR_IDENTIFIER)) {
+ return new Object[] { "UUID", 0 };
+ } else {
+ if (log.isTraceEnabled())
+ log.trace("No Column label provider defined for property: ["
+ + propertyName + "]");
+ return new Object[] { propertyName, 60 };
+ }
+ }
+
+ public static String formatValueAsString(Value value) {
+ try {
+ String strValue;
+
+ if (value.getType() == PropertyType.BINARY)
+ strValue = "<binary>";
+ else if (value.getType() == PropertyType.DATE)
+ strValue = df.format(value.getDate().getTime());
+ else
+ strValue = value.getString();
+ return strValue;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("unexpected error while formatting value",
+ e);
+ }
+ }
+
+ public static String formatAsString(Object value) {
+ String strValue;
+ if (value instanceof Calendar)
+ strValue = df.format(((Calendar) value).getTime());
+ else
+ strValue = value.toString();
+ return strValue;
+ }
+}
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.query.Row;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.jcr.utils.JcrFileProvider;
import org.argeo.eclipse.ui.specific.FileHandler;
-import org.argeo.jcr.ui.explorer.utils.JcrFileProvider;
+import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.editors.GenericArtifactEditor;
+import org.argeo.slc.client.ui.dist.editors.GenericArtifactEditorInput;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.PartInitException;
/**
* Centralizes the management of double click on an ArtifactTreeViewer
*/
-public class GenericDoubleClickListener implements IDoubleClickListener {
+public class GenericDoubleClickListener implements IDoubleClickListener,
+ SlcTypes, SlcNames, DistConstants {
- // private final static Log log = LogFactory
- // .getLog(GenericNodeDoubleClickListener.class);
+ private final static Log log = LogFactory
+ .getLog(GenericDoubleClickListener.class);
private TreeViewer viewer;
+
private JcrFileProvider jfp;
private FileHandler fileHandler;
return;
Object obj = ((IStructuredSelection) event.getSelection())
.getFirstElement();
- if (obj instanceof Node) {
- Node node = (Node) obj;
- try {
- if (node.isNodeType(NodeType.NT_FILE)) {
- // double click on a file node triggers its opening
+ try {
+ if (obj instanceof Node) {
+ Node node = (Node) obj;
+ if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
+ GenericArtifactEditorInput gaei = new GenericArtifactEditorInput(
+ node);
+ DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .openEditor(gaei, GenericArtifactEditor.ID);
+ } else if (node.isNodeType(NodeType.NT_FILE)) {
String name = node.getName();
String id = node.getIdentifier();
-
- // For the file provider to be able to browse the
- // various
- // repository.
- // TODO : enhanced that.
- // ITreeContentProvider itcp = (ITreeContentProvider)
- // nodeViewer
- // .getContentProvider();
- // jfp.setRootNodes((Object[]) itcp.getElements(null));
+ jfp.setReferenceNode(node);
fileHandler.openFile(name, id);
}
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Repository error while getting node info", re);
+
+ } else if (obj instanceof Row) {
+ Row row = (Row) obj;
+ // String uuid;
+ // try {
+ // uuid = row.getValue(
+ // SLC_ARTIFACT_VERSION_BASE + "." + JCR_IDENTIFIER)
+ // .getString();
+ // } catch (ItemNotFoundException infe) {
+ // MessageDialog.openError(DistPlugin.getDefault()
+ // .getWorkbench().getActiveWorkbenchWindow()
+ // .getShell(), "Invalid request",
+ // "The request must return a value for "
+ // + SLC_ARTIFACT_VERSION_BASE + "."
+ // + JCR_IDENTIFIER
+ // + " in order to open the artifact editor");
+ // return;
+ // }
+ // Node node =
+ // row.getNode(SLC_ARTIFACT_VERSION_BASE).getSession()
+ // .getNodeByIdentifier(uuid);
+
+ Node node = row.getNode(SLC_ARTIFACT_VERSION_BASE);
+ if (node == null)
+ MessageDialog.openError(DistPlugin.getDefault()
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getShell(), "Invalid request",
+ "The request must return a "
+ + SLC_ARTIFACT_VERSION_BASE + " node "
+ + " in order to open the artifact editor");
+ else {
+ GenericArtifactEditorInput gaei = new GenericArtifactEditorInput(
+ node);
+ DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .openEditor(gaei, GenericArtifactEditor.ID);
+ }
}
- // catch (PartInitException pie) {
- // throw new ArgeoException(
- // "Unexepected exception while opening node editor", pie);
- // }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Repository error while getting node info", re);
+ } catch (PartInitException pie) {
+ throw new ArgeoException(
+ "Unexepected exception while opening artifact editor", pie);
}
}
}
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.Iterator;
import java.util.List;
import javax.jcr.RepositoryException;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.GenericTableComparator;
import org.argeo.slc.client.ui.dist.utils.ArtifactsTableConfigurer;
+import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
private static final Log log = LogFactory
.getLog(AbstractQueryArtifactsView.class);
+ // shortcuts
+ final protected static String SAVB = "[" + SLC_ARTIFACT_VERSION_BASE + "]";
+ final protected static String SBA = "[" + SLC_BUNDLE_ARTIFACT + "]";
+ final protected static String SIP = "[" + SLC_IMPORTED_PACKAGE + "]";
+ final protected static String SEP = "[" + SLC_EXPORTED_PACKAGE + "]";
+
/* DEPENDENCY INJECTION */
private Session session;
+ private List<String> columnProperties;
// This page widgets
private TableViewer viewer;
private ArtifactsTableConfigurer tableConfigurer;
private GenericTableComparator comparator;
+ // to be set by client to display all columns
+ private boolean displayAllColumns = false;
+
protected void createResultPart(Composite parent) {
viewer = new TableViewer(parent);
Table table = viewer.getTable();
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setContentProvider(new ViewContentProvider());
- // viewer.addDoubleClickListener(new ViewDoubleClickListener());
+ viewer.addDoubleClickListener(new GenericDoubleClickListener(null));
+
tableConfigurer = new ArtifactsTableConfigurer(viewer, 1,
GenericTableComparator.DESCENDING);
// remove previous columns
for (TableViewerColumn tvc : tableViewerColumns)
tvc.getColumn().dispose();
- int i = 0;
- for (final String columnName : qr.getColumnNames()) {
- TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
- // Small hack to remove prefix from the column name
- String tmpStr = columnName.substring(columnName
- .lastIndexOf(".")+1);
- tableConfigurer.configureColumn(tmpStr, tvc, i);
- tvc.setLabelProvider(tableConfigurer
- .getLabelProvider(columnName));
- tableViewerColumns.add(tvc);
- i++;
- }
+ // If a pre(-defined list of columns has been injected, we use it,
+ // otherwise we display all results of the resultSet
+ if (!displayAllColumns && columnProperties != null) {
+ int i = 0;
+
+ Iterator<String> it = columnProperties.iterator();
+ while (it.hasNext()) {
+ String columnName = it.next();
+
+ TableViewerColumn tvc = new TableViewerColumn(viewer,
+ SWT.NONE);
+ tableConfigurer.configureColumn(columnName, tvc, i);
+ tvc.setLabelProvider(tableConfigurer
+ .getLabelProvider(columnName));
+ tableViewerColumns.add(tvc);
+ i++;
+ }
+ } else {
+ int i = 0;
+ for (final String columnName : qr.getColumnNames()) {
+ TableViewerColumn tvc = new TableViewerColumn(viewer,
+ SWT.NONE);
+ // Small hack to remove prefix from the column name
+ // String tmpStr = columnName.substring(columnName
+ // .lastIndexOf(".") + 1);
+ tableConfigurer.configureColumn(columnName, tvc, i);
+ tvc.setLabelProvider(tableConfigurer
+ .getLabelProvider(columnName));
+ tableViewerColumns.add(tvc);
+ i++;
+ }
+ }
// We must create a local list because query result can be read only
// once.
try {
}
}
+ /**
+ * Client must use this method to display all columns of the result set
+ * instead of a limited predifined and injected set
+ **/
+ public void displayAllColumns(boolean flag) {
+ displayAllColumns = flag;
+ }
+
// Can be overridden by subclasses.
protected String generateSelectStatement() {
- StringBuffer sb = new StringBuffer("select * ");
+ StringBuffer sb = new StringBuffer("select " + SAVB + ".* ");
return sb.toString();
}
protected String generateFromStatement() {
- StringBuffer sb = new StringBuffer(" from [");
- sb.append(SLC_ARTIFACT);
- sb.append("] ");
+ StringBuffer sb = new StringBuffer(" from ");
+ sb.append(SAVB);
+ sb.append(" ");
return sb.toString();
}
public void setSession(Session session) {
this.session = session;
}
+
+ public void setColumnProperties(List<String> columnProperties) {
+ this.columnProperties = columnProperties;
+ }
}
\ No newline at end of file
package org.argeo.slc.client.ui.dist.views;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.Value;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
+import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.DistPlugin;
-import org.argeo.slc.client.ui.dist.providers.ArtifactLabelProvider;
import org.argeo.slc.client.ui.dist.providers.ArtifactsTreeContentProvider;
import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
+import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.RepoConstants;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.part.ViewPart;
/**
- * Basic View to browse a maven base repository
+ * Basic View to browse a maven based repository.
+ *
+ * By Default size of the various bundles is not computed but it can be
+ * activated the view command.
*/
public class ArtifactsBrowser extends ViewPart implements DistConstants,
/* DEPENDENCY INJECTION */
private Session jcrSession;
+
// Business objects
private Node rootNode;
// This page widgets
private TreeViewer artifactTreeViewer;
+ private boolean isSizeVisible = false;
+
+ // To be able to configure columns easily
+ public static final int COLUMN_TREE = 0;
+ public static final int COLUMN_DATE = 1;
+ public static final int COLUMN_SIZE = 2;
+ private static final int SIZE_COL_WIDTH = 55;
@Override
public void createPartControl(Composite parent) {
- GridLayout gl = new GridLayout(1, false);
- parent.setLayout(gl);
+ // Enable the different parts to fill the whole page when the tab is
+ // maximized
+ parent.setLayout(new FillLayout());
artifactTreeViewer = createArtifactsTreeViewer(parent);
// context menu : it is completely defined in the plugin.xml file.
-
// Nothing in the context menu for the time being
// MenuManager menuManager = new MenuManager();
// Menu menu =
Tree tree = new Tree(parent, style);
createColumn(tree, "Artifacts", SWT.LEFT, 300);
createColumn(tree, "Date created", SWT.LEFT, 105);
- createColumn(tree, "Size", SWT.RIGHT, 55);
+ createColumn(tree, "Size", SWT.RIGHT, 0);
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
viewer.setContentProvider(new ArtifactsTreeContentProvider());
viewer.setLabelProvider(new ArtifactLabelProvider());
+ viewer.addSelectionChangedListener(new ArtifactTreeSelectionListener());
viewer.addDoubleClickListener(new GenericDoubleClickListener(viewer));
viewer.setInput(rootNode);
+
return viewer;
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Refresh the given element of the tree browser. If null is passed as a
+ * parameter, it refreshes the whole tree
+ */
+ public void refresh(Object element) {
+ if (element == null) {
+ artifactTreeViewer.refresh(rootNode);
+ } else
+ artifactTreeViewer.refresh(element);
+ }
+
+ /** Returns wether size column is visible or not */
+ public boolean isSizeVisible() {
+ return isSizeVisible;
+ }
+
+ /** Sets the visibility of the size column */
+ public void setSizeVisible(boolean visible) {
+ if (isSizeVisible == visible)
+ return; // nothing has changed
+ else
+ isSizeVisible = visible;
+
+ if (visible) {
+ artifactTreeViewer.getTree().getColumn(COLUMN_SIZE)
+ .setWidth(SIZE_COL_WIDTH);
+ } else {
+ // we just hide the column, we don't refresh the whole tree.
+ artifactTreeViewer.getTree().getColumn(COLUMN_SIZE).setWidth(0);
+ }
+ }
+
+ private class ArtifactLabelProvider extends ColumnLabelProvider implements
+ DistConstants, SlcTypes {
+
+ // Utils
+ protected DateFormat timeFormatter = new SimpleDateFormat(
+ DATE_TIME_FORMAT);
+
+ public void update(ViewerCell cell) {
+ int colIndex = cell.getColumnIndex();
+ Object element = cell.getElement();
+ cell.setText(getColumnText(element, colIndex));
+
+ if (element instanceof Node && colIndex == 0) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_BASE);
+ else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_VERSION_BASE);
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ }
+
+ @Override
+ public Image getImage(Object element) {
+
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE)) {
+ return DistImages.IMG_ARTIFACT_BASE;
+ } else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
+ return DistImages.IMG_ARTIFACT_VERSION_BASE;
+ }
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ try {
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ switch (columnIndex) {
+ case COLUMN_TREE:
+ return node.getName();
+ case COLUMN_SIZE:
+ if (isSizeVisible) {
+ long size = JcrUtils.getNodeApproxSize(node) / 1024;
+ if (size > 1024)
+ return size / 1024 + " MB";
+ else
+ return size + " KB";
+ } else
+ return "";
+ case COLUMN_DATE:
+ if (node.hasProperty(Property.JCR_CREATED))
+ return timeFormatter.format(node
+ .getProperty(Property.JCR_CREATED)
+ .getDate().getTime());
+ else
+ return null;
+ }
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexepected error while getting property values", re);
+ }
+ return null;
+ }
+
+ private String formatValueAsString(Value value) {
+ // TODO enhance this method
+ try {
+ String strValue;
+
+ if (value.getType() == PropertyType.BINARY)
+ strValue = "<binary>";
+ else if (value.getType() == PropertyType.DATE)
+ strValue = timeFormatter.format(value.getDate().getTime());
+ else
+ strValue = value.getString();
+ return strValue;
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "unexpected error while formatting value", e);
+ }
+ }
+ }
+
+ private class ArtifactTreeSelectionListener implements
+ ISelectionChangedListener {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection != null && selection instanceof IStructuredSelection) {
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ if (iss.size() == 1) {
+ artifactTreeViewer.refresh(iss.getFirstElement());
+ }
+ }
+
+ }
+
}
/* DEPENDENCY INJECTION */
import org.argeo.slc.jcr.SlcNames;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setSashWidth(4);
- sashForm.setLayout(new GridLayout(1, false));
+ // Enable the different parts to fill the whole page when the tab is
+ // maximized
+ sashForm.setLayout(new FillLayout());
top = new Composite(sashForm, SWT.NONE);
top.setLayout(new GridLayout(1, false));
gl.marginTop = 5;
parent.setLayout(gl);
- lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Query by coordinates");
- gd = new GridData();
- gd.horizontalSpan = 2;
- lbl.setLayoutData(gd);
+ // lbl = new Label(parent, SWT.SINGLE);
+ // lbl.setText("Query by coordinates");
+ // gd = new GridData();
+ // gd.horizontalSpan = 2;
+ // lbl.setLayoutData(gd);
// Group ID
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Group ID:");
+ lbl.setText("Group ID");
groupId = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ groupId.setLayoutData(gd);
// Artifact ID
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Artifact ID:");
+ lbl.setText("Artifact ID");
artifactId = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ artifactId.setLayoutData(gd);
// Version
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Version:");
+ lbl.setText("Version");
version = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ version.setLayoutData(gd);
executeBtn = new Button(parent, SWT.PUSH);
executeBtn.setText("Search");
import org.argeo.slc.jcr.SlcNames;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setSashWidth(4);
- sashForm.setLayout(new GridLayout(1, false));
+ // Enable the different parts to fill the whole page when the tab is
+ // maximized
+ sashForm.setLayout(new FillLayout());
top = new Composite(sashForm, SWT.NONE);
top.setLayout(new GridLayout(1, false));
import org.argeo.ArgeoException;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
/** Query SLC Repo to get some artifacts given some predefined parameters */
public class QueryBundlesForm extends AbstractQueryArtifactsView implements
- SlcNames {
+ SlcNames, SlcTypes {
private static final Log log = LogFactory.getLog(QueryBundlesForm.class);
public static final String ID = DistPlugin.ID + ".queryBundlesForm";
private Text exportedPackage;
private SashForm sashForm;
- // shortcuts
- final static String SBA = "sba";
- final static String SIP = "sip";
- final static String SEP = "sep";
-
private Composite top, bottom;
@Override
sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setSashWidth(4);
- sashForm.setLayout(new GridLayout(1, false));
+ // Enable the different parts to fill the whole page when the tab is
+ // maximized
+ sashForm.setLayout(new FillLayout());
top = new Composite(sashForm, SWT.NONE);
top.setLayout(new GridLayout(1, false));
// Bundle Name
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Bundle name: ");
+ lbl.setText("Symbolic name");
symbolicName = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ symbolicName.setLayoutData(gd);
// imported package
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Imported package: ");
+ lbl.setText("Imported package");
importedPackage = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ importedPackage.setLayoutData(gd);
// exported package
lbl = new Label(parent, SWT.SINGLE);
- lbl.setText("Exported package: ");
+ lbl.setText("Exported package");
exportedPackage = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.grabExcessHorizontalSpace = true;
+ exportedPackage.setLayoutData(gd);
executeBtn = new Button(parent, SWT.PUSH);
executeBtn.setText("Search");
StringBuffer sb = new StringBuffer();
// Select
- sb.append("select " + SBA + ".* ");
- if (ipClause)
- sb.append(", " + SIP + ".* ");
- if (epClause)
- sb.append(", " + SEP + ".* ");
-
- sb.append(" from [");
- sb.append(SLC_BUNDLE_ARTIFACT);
- sb.append("] as " + SBA + " ");
+ sb.append("select " + SBA + ".*, " + SAVB + ".* ");
+ sb.append(" from " + SAVB);
// join
+ sb.append(" inner join ");
+ sb.append(SBA);
+ sb.append(" on isdescendantnode(" + SBA + ", " + SAVB + ") ");
if (ipClause) {
- sb.append(" inner join [");
- sb.append(SLC_IMPORTED_PACKAGE);
- sb.append("] as " + SIP + " on isdescendantnode(" + SIP + ", "
- + SBA + ") ");
+ sb.append(" inner join ");
+ sb.append(SIP);
+ sb.append(" on isdescendantnode(" + SIP + ", " + SBA + ") ");
}
if (epClause) {
- sb.append(" inner join [");
- sb.append(SLC_EXPORTED_PACKAGE);
- sb.append("] as " + SEP + " on isdescendantnode(" + SEP + ", "
- + SBA + ") ");
+ sb.append(" inner join ");
+ sb.append(SEP);
+ sb.append(" on isdescendantnode(" + SEP + ", " + SBA + ") ");
}
// where
sb.append(" where ");
if (symbolicName.getText() != null
&& !symbolicName.getText().trim().equals("")) {
- sb.append("sba.[" + SLC_SYMBOLIC_NAME + "] like '"
+ sb.append(SBA + ".[" + SLC_SYMBOLIC_NAME + "] like '"
+ symbolicName.getText().replace('*', '%') + "'");
hasFirstClause = true;
}
sb.append(SEP + ".[" + SLC_NAME + "] like '"
+ exportedPackage.getText().replace('*', '%') + "'");
}
-
- if (log.isDebugEnabled())
- log.debug("Statement : " + sb.toString());
-
return sb.toString();
} catch (Exception e) {
throw new ArgeoException(