First version of dist UI
authorBruno Sinou <bsinou@argeo.org>
Fri, 14 Oct 2011 21:11:15 +0000 (21:11 +0000)
committerBruno Sinou <bsinou@argeo.org>
Fri, 14 Oct 2011 21:11:15 +0000 (21:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@4844 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

36 files changed:
demo/slc_demo_rap.properties
eclipse/plugins/org.argeo.slc.client.ui.dist/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/views.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactBase.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactVersionBase.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/file.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packageBrowser.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/package_obj.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packages.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/refresh.png [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/searchForm.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search_decl_obj.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/showSize.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/icons/sinfocenter_obj.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/plugin.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/pom.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistConstants.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistImages.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistLabels.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistPlugin.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RefreshArtifactBrowser.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/ShowSizeColumn.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactDetailsPage.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditor.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/providers/ArtifactLabelProvider.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/providers/ArtifactsTreeContentProvider.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/ArtifactsTableConfigurer.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/DistUiHelpers.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/GenericDoubleClickListener.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/AbstractQueryArtifactsView.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/ArtifactsBrowser.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryArtifactsForm.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryArtifactsText.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryBundlesForm.java

index 4affb74848e3e949737de1e29596ad65d0ae4345..17695cdf1f2d630822d3c9fc96b1b45171e401a9 100644 (file)
@@ -33,8 +33,8 @@ org.argeo.slc.demo.basic,\
 #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
index 13fbda16b377e2cb0cff3b08685b37e10790e866..e37df992c284207b4a21a23a7eb252fd026162eb 100644 (file)
@@ -29,7 +29,6 @@ Import-Package: aQute.lib.osgi;resolution:=optional,
  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,
index cd31b7bb6b464ba38be6749c47fd84bfeefe625c..5b93dc562202eedc68438feff0a5697f55c9d0a0 100644 (file)
        <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>
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactBase.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactBase.gif
new file mode 100644 (file)
index 0000000..fca9c53
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactBase.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactVersionBase.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactVersionBase.gif
new file mode 100644 (file)
index 0000000..b6096e2
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/artifactVersionBase.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/file.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/file.gif
new file mode 100644 (file)
index 0000000..ef30288
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/file.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packageBrowser.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packageBrowser.gif
new file mode 100644 (file)
index 0000000..983932f
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packageBrowser.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/package_obj.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/package_obj.gif
new file mode 100644 (file)
index 0000000..131c28d
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/package_obj.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packages.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packages.gif
new file mode 100644 (file)
index 0000000..22f78af
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/packages.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/refresh.png b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/refresh.png
new file mode 100644 (file)
index 0000000..a3884fb
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/refresh.png differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search.gif
new file mode 100644 (file)
index 0000000..d540a01
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/searchForm.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/searchForm.gif
new file mode 100644 (file)
index 0000000..cbbb3af
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/searchForm.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search_decl_obj.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search_decl_obj.gif
new file mode 100644 (file)
index 0000000..f31a02a
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/search_decl_obj.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/showSize.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/showSize.gif
new file mode 100644 (file)
index 0000000..2df4b45
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/showSize.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/sinfocenter_obj.gif b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/sinfocenter_obj.gif
new file mode 100644 (file)
index 0000000..b867103
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.client.ui.dist/icons/sinfocenter_obj.gif differ
index d97ab5215bd2ff8cd9d41fd43b67600733a8f6f2..cea5a492e3af3048ff53be4cf054b3cdd0736be0 100644 (file)
       <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"
index 1012be5cee502816648db713958882be502a193d..5070b0c54909fd56683f3a6956be8b936c73bd6d 100644 (file)
@@ -35,8 +35,8 @@
                        <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>
index 062113eb23184ce21b7d2ca14eae07596cd585a3..fc5fec065874feda19a25bf7883e356994e3c87b 100644 (file)
@@ -7,9 +7,9 @@ public interface DistConstants {
         */
        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";
+       
+       
 }
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistImages.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistImages.java
new file mode 100644 (file)
index 0000000..6a46d68
--- /dev/null
@@ -0,0 +1,13 @@
+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();
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistLabels.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistLabels.java
new file mode 100644 (file)
index 0000000..954a049
--- /dev/null
@@ -0,0 +1,11 @@
+package org.argeo.slc.client.ui.dist;
+
+public class DistLabels {
+
+       public static String getLabel(String jcrName){
+               String label = null;
+               
+               
+               return label;
+       }
+}
index fa98f18a2814db8e978bd68ba450d72c5d64b5e4..e0ae967d1ee734725c35f7e60a08c205160bb9c4 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.client.ui.dist;
 
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -7,13 +8,23 @@ public class DistPlugin extends AbstractUIPlugin {
        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);
+       }
+
 }
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RefreshArtifactBrowser.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RefreshArtifactBrowser.java
new file mode 100644 (file)
index 0000000..13aa65f
--- /dev/null
@@ -0,0 +1,21 @@
+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;
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/ShowSizeColumn.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/ShowSizeColumn.java
new file mode 100644 (file)
index 0000000..a79e542
--- /dev/null
@@ -0,0 +1,35 @@
+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;
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactDetailsPage.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactDetailsPage.java
new file mode 100644 (file)
index 0000000..5a8774e
--- /dev/null
@@ -0,0 +1,355 @@
+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() {
+               }
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditor.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditor.java
new file mode 100644 (file)
index 0000000..7194fd3
--- /dev/null
@@ -0,0 +1,76 @@
+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;
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/GenericArtifactEditorInput.java
new file mode 100644 (file)
index 0000000..18f435d
--- /dev/null
@@ -0,0 +1,100 @@
+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;
+       }
+}
index ec4728d885b022349f7259e833461b842aa9ff13..155baf1c2a5201f7ff74949a7f175a2c80372bc0 100644 (file)
@@ -5,18 +5,19 @@ import java.text.SimpleDateFormat;
 
 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;
@@ -24,16 +25,42 @@ public class ArtifactLabelProvider extends ColumnLabelProvider implements
        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) {
@@ -50,10 +77,10 @@ public class ArtifactLabelProvider extends ColumnLabelProvider implements
                                        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;
                                }
@@ -64,22 +91,4 @@ public class ArtifactLabelProvider extends ColumnLabelProvider implements
                }
                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);
-               }
-       }
 }
index 289fef5e038f5ca87ce23aafa329c818a441e8bc..ebc61d3428c3cbac60fdf284fc05631a97b71610 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.slc.client.ui.dist.providers;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -8,10 +9,18 @@ import javax.jcr.NodeIterator;
 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);
        }
@@ -30,7 +39,14 @@ public class ArtifactsTreeContentProvider implements ITreeContentProvider {
                                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(
@@ -41,8 +57,13 @@ public class ArtifactsTreeContentProvider implements ITreeContentProvider {
 
        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(
@@ -52,6 +73,14 @@ public class ArtifactsTreeContentProvider implements ITreeContentProvider {
                return false;
        }
 
+       public void setSortChildren(boolean sortChildren) {
+               this.sortChildren = sortChildren;
+       }
+
+       public boolean getSortChildren() {
+               return sortChildren;
+       }
+
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
 
index f213b3dd22775ffe3aa377efc2fcbb7def49a848..628c1a17076489a5c40bfa36d8e3d8a9a7505187 100644 (file)
@@ -75,45 +75,15 @@ public class ArtifactsTableConfigurer implements SlcNames, SlcTypes,
                                        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
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/DistUiHelpers.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/DistUiHelpers.java
new file mode 100644 (file)
index 0000000..cf5f915
--- /dev/null
@@ -0,0 +1,131 @@
+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;
+       }
+}
index e053146d8c4f262fda0cd67f8669c3b0ad29a9dc..9ed4c066a73a2a41a02b55eab58ebdd36bea11d7 100644 (file)
@@ -3,24 +3,37 @@ package org.argeo.slc.client.ui.dist.utils;
 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;
 
@@ -35,32 +48,65 @@ public class GenericDoubleClickListener implements IDoubleClickListener {
                        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);
                }
        }
 }
index 2605cff8ca53d44f1850aa4ba2ee886fd9525976..a81139b2bb6cd74fa6ebf67de1300a62a71206d3 100644 (file)
@@ -3,6 +3,7 @@ package org.argeo.slc.client.ui.dist.views;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.jcr.RepositoryException;
@@ -17,6 +18,7 @@ import org.apache.commons.logging.LogFactory;
 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;
@@ -41,8 +43,15 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
        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;
@@ -50,6 +59,9 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
        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();
@@ -60,7 +72,8 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
 
                viewer.setLabelProvider(new ViewLabelProvider());
                viewer.setContentProvider(new ViewContentProvider());
-               // viewer.addDoubleClickListener(new ViewDoubleClickListener());
+               viewer.addDoubleClickListener(new GenericDoubleClickListener(null));
+
                tableConfigurer = new ArtifactsTableConfigurer(viewer, 1,
                                GenericTableComparator.DESCENDING);
 
@@ -87,19 +100,39 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
                        // 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 {
@@ -120,16 +153,24 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
                }
        }
 
+       /**
+        * 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();
        }
 
@@ -168,4 +209,8 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements
        public void setSession(Session session) {
                this.session = session;
        }
+
+       public void setColumnProperties(List<String> columnProperties) {
+               this.columnProperties = columnProperties;
+       }
 }
\ No newline at end of file
index 8c1da64dc74d0aa72b149e2152979301a291544e..c5ca1986fab95ec013f278a2f78ea3f32394fec5 100644 (file)
@@ -1,28 +1,46 @@
 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,
@@ -32,20 +50,28 @@ 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 =
@@ -72,7 +98,7 @@ public class ArtifactsBrowser extends ViewPart implements DistConstants,
                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);
 
@@ -80,8 +106,10 @@ public class ArtifactsBrowser extends ViewPart implements DistConstants,
 
                viewer.setContentProvider(new ArtifactsTreeContentProvider());
                viewer.setLabelProvider(new ArtifactLabelProvider());
+               viewer.addSelectionChangedListener(new ArtifactTreeSelectionListener());
                viewer.addDoubleClickListener(new GenericDoubleClickListener(viewer));
                viewer.setInput(rootNode);
+
                return viewer;
        }
 
@@ -102,6 +130,149 @@ public class ArtifactsBrowser extends ViewPart implements DistConstants,
        @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 */
index a0b442246e2edbe34e91491b7322caf3fb209bd7..9d5451430c34bfe98a38a27da35919bbc387661b 100644 (file)
@@ -7,6 +7,7 @@ import org.argeo.slc.client.ui.dist.DistPlugin;
 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;
@@ -36,7 +37,9 @@ public class QueryArtifactsForm extends AbstractQueryArtifactsView implements
 
                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));
@@ -58,26 +61,35 @@ public class QueryArtifactsForm extends AbstractQueryArtifactsView implements
                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");
index c73dcbecacd4009d5a83f50f3257e955727d572a..5e71380f1e92f3780aa6449608100e797b3a8f60 100644 (file)
@@ -6,6 +6,7 @@ import org.argeo.slc.client.ui.dist.DistPlugin;
 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;
@@ -33,7 +34,9 @@ public class QueryArtifactsText extends AbstractQueryArtifactsView implements
 
                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));
index 9c2993462285abf14d34d11bc07d389facf2bc0c..b5afd66c0fa14cc948599cd523f53d0b327e1223 100644 (file)
@@ -5,8 +5,10 @@ import org.apache.commons.logging.LogFactory;
 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;
@@ -18,7 +20,7 @@ import org.eclipse.swt.widgets.Text;
 
 /** 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";
 
@@ -29,11 +31,6 @@ public class QueryBundlesForm extends AbstractQueryArtifactsView implements
        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
@@ -41,7 +38,9 @@ public class QueryBundlesForm extends AbstractQueryArtifactsView implements
 
                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));
@@ -65,18 +64,27 @@ public class QueryBundlesForm extends AbstractQueryArtifactsView implements
 
                // 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");
@@ -110,36 +118,30 @@ public class QueryBundlesForm extends AbstractQueryArtifactsView implements
 
                        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;
                        }
@@ -158,10 +160,6 @@ public class QueryBundlesForm extends AbstractQueryArtifactsView implements
                                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(