Add Site Map to studio/mvc.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 10 Sep 2020 08:11:36 +0000 (10:11 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 10 Sep 2020 08:11:36 +0000 (10:11 +0200)
systems/org.argeo.suite.studio/.classpath [new file with mode: 0644]
systems/org.argeo.suite.studio/.project
systems/org.argeo.suite.studio/bnd.bnd
systems/org.argeo.suite.studio/e4xmi/mvc.e4xmi
systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/RwtAppElem.java [new file with mode: 0644]
systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/ServletElem.java [new file with mode: 0644]
systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteElem.java [new file with mode: 0644]
systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteMapPart.java [new file with mode: 0644]

diff --git a/systems/org.argeo.suite.studio/.classpath b/systems/org.argeo.suite.studio/.classpath
new file mode 100644 (file)
index 0000000..e801ebf
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
index ea4f91d1e762e1ce4e1af321ffd0bb0fca77abde..fa5c615e89764aaa21c394ed512a713499edeb07 100644 (file)
@@ -5,6 +5,11 @@
        <projects>
        </projects>
        <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.pde.ManifestBuilder</name>
                        <arguments>
@@ -23,5 +28,6 @@
        </buildSpec>
        <natures>
                <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
 </projectDescription>
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2b2a02fac7c343c455f83ad14ba7af048785c386 100644 (file)
@@ -0,0 +1 @@
+Bundle-ActivationPolicy: lazy
index 2faa633517238ae2662c053eaf85f7b9d4196d15..1e7204008760ccff9c0f2d1828bc3365939da83a 100644 (file)
@@ -5,7 +5,9 @@
     <tags>shellMaximized</tags>
     <tags>auth.cn=org.argeo.office.coworker,ou=roles,ou=node</tags>
     <children xsi:type="basic:PartSashContainer" xmi:id="__LhVQMlHEeic2PiQZ6_KRg" elementId="org.argeo.suite.e4.partsashcontainer.1" selectedElement="_8xaqAP3vEeia6ei0NV0Yrw" horizontal="true">
-      <children xsi:type="basic:Part" xmi:id="_xi1k0DDzEeiUfOa4rxEKwQ" elementId="org.argeo.suite.e4.part.documents" containerData="2000" contributionURI="bundleclass://org.argeo.connect.e4/org.argeo.documents.e4.parts.MyFilesView" label="%documents" iconURI="platform:/plugin/org.argeo.theme.argeo2/icons/types/documents.png"/>
+      <children xsi:type="basic:PartStack" xmi:id="_jfxwIPM8Eeqinoi2-PNjfw" elementId="org.argeo.suite.studio.partstack.0">
+        <children xsi:type="basic:Part" xmi:id="_xi1k0DDzEeiUfOa4rxEKwQ" elementId="org.argeo.suite.e4.part.siteMap" containerData="2000" contributionURI="bundleclass://org.argeo.suite.studio/org.argeo.suite.studio.parts.SiteMapPart" label="Site Map" iconURI="platform:/plugin/org.argeo.theme.argeo2/icons/types/documents.png"/>
+      </children>
       <children xsi:type="basic:PartStack" xmi:id="_8xaqAP3vEeia6ei0NV0Yrw" elementId="org.argeo.suite.e4.partstack.entityEditorArea" containerData="8000">
         <tags>entityEditorArea</tags>
         <children xsi:type="basic:Part" xmi:id="_EQBUIP3xEeia6ei0NV0Yrw" elementId="org.argeo.suite.e4.part.defaultDashboard" contributionURI="bundleclass://org.argeo.connect.e4/org.argeo.documents.e4.parts.DocumentsDashboard" label="" iconURI="platform:/plugin/org.argeo.theme.argeo2/icons/types/dashboard.png" tooltip="%dashboard">
diff --git a/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/RwtAppElem.java b/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/RwtAppElem.java
new file mode 100644 (file)
index 0000000..635d350
--- /dev/null
@@ -0,0 +1,21 @@
+package org.argeo.suite.studio.parts;
+
+import org.eclipse.rap.rwt.application.ApplicationConfiguration;
+import org.osgi.framework.ServiceReference;
+
+/** Site map element representing an RWT application. */
+class RwtAppElem extends SiteElem {
+       private final static String CONTEXT_NAME = "contextName";
+
+       private final ServiceReference<ApplicationConfiguration> serviceReference;
+
+       public RwtAppElem(ServiceReference<ApplicationConfiguration> serviceReference) {
+               super(serviceReference.getProperties().get(CONTEXT_NAME).toString());
+               this.serviceReference = serviceReference;
+       }
+
+       public ServiceReference<ApplicationConfiguration> getServiceReference() {
+               return serviceReference;
+       }
+
+}
diff --git a/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/ServletElem.java b/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/ServletElem.java
new file mode 100644 (file)
index 0000000..5165795
--- /dev/null
@@ -0,0 +1,62 @@
+package org.argeo.suite.studio.parts;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.servlet.Servlet;
+
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/** Site map element which is a plain servlet. */
+class ServletElem extends SiteElem {
+       private final ServiceReference<Servlet> serviceReference;
+
+       public ServletElem(ServiceReference<Servlet> serviceReference) {
+               super(extractPath(serviceReference));
+               this.serviceReference = serviceReference;
+       }
+       
+       
+
+       public ServiceReference<Servlet> getServiceReference() {
+               return serviceReference;
+       }
+
+
+
+       private static String extractPath(ServiceReference<Servlet> serviceReference) {
+               Object servletPattern = serviceReference.getProperties()
+                               .get(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
+               Object servletContextSelect = serviceReference.getProperties()
+                               .get(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+               String servletContextPath = "";
+               if (servletContextSelect != null) {
+                       try {
+                               Collection<ServiceReference<ServletContextHelper>> scSr = serviceReference.getBundle()
+                                               .getBundleContext()
+                                               .getServiceReferences(ServletContextHelper.class, servletContextSelect.toString());
+                               if (scSr.size() > 0) {
+                                       servletContextPath = scSr.iterator().next()
+                                                       .getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH).toString();
+                                       if (servletContextPath.equals("/"))// default servlet context
+                                               servletContextPath = "";
+                               }
+                       } catch (InvalidSyntaxException e) {
+                               throw new IllegalArgumentException(e);
+                       }
+               }
+
+               if (servletPattern instanceof String)
+                       return servletContextPath + servletPattern.toString();
+               else if (servletPattern instanceof String[]) {
+                       String[] patterns = (String[]) servletPattern;
+                       if (patterns.length == 2 && patterns[1].equals(patterns[0] + "/*")) // RAP servlets
+                               return servletContextPath + patterns[0];
+                       return servletContextPath + Arrays.asList(patterns).toString();
+               } else
+                       throw new IllegalArgumentException("Cannot interpret servlet pattern " + servletPattern.getClass());
+       }
+}
diff --git a/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteElem.java b/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteElem.java
new file mode 100644 (file)
index 0000000..4931eab
--- /dev/null
@@ -0,0 +1,37 @@
+package org.argeo.suite.studio.parts;
+
+import org.argeo.eclipse.ui.TreeParent;
+
+/** Base class for site map elements. */
+abstract class SiteElem extends TreeParent {
+
+       private final String path;
+
+       public SiteElem(String path) {
+               super(extractLastSegment(path));
+               this.path = path;
+       }
+
+       public String getPath() {
+               return path;
+       }
+
+       static String extractLastSegment(String path) {
+               if (path == null || path.equals(""))
+                       throw new IllegalArgumentException("Path should not be null or empty.");
+               if (path.equals("/"))
+                       return path;
+               String[] segments = path.split("/");
+               for (int i = segments.length - 1; i >= 0; i--) {
+                       if (!segments[i].equals("") && !segments[i].equals("*"))
+                               return segments[i];
+               }
+               return "/";
+       }
+
+       @Override
+       public String toString() {
+               return path;
+       }
+
+}
diff --git a/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteMapPart.java b/systems/org.argeo.suite.studio/src/org/argeo/suite/studio/parts/SiteMapPart.java
new file mode 100644 (file)
index 0000000..db7911f
--- /dev/null
@@ -0,0 +1,96 @@
+package org.argeo.suite.studio.parts;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.servlet.Servlet;
+
+import org.argeo.eclipse.ui.AbstractTreeContentProvider;
+import org.eclipse.e4.core.di.extensions.OSGiBundle;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.rap.rwt.application.ApplicationConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/** Overview of the URL paths provides by the system. */
+@SuppressWarnings("restriction")
+public class SiteMapPart {
+//     private final static BundleContext bc = FrameworkUtil.getBundle(SiteMapPart.class).getBundleContext();
+
+       private TreeViewer viewer;
+
+       @Inject
+       @OSGiBundle
+       BundleContext bc;
+
+       @PostConstruct
+       public void createPartControl(Composite parent) {
+//             new Label(parent, SWT.NONE).setText("TEST");
+//             
+               viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+//             viewer.getTree().setHeaderVisible(true);
+
+//             viewer.setLabelProvider(new ColumnLabelProvider());
+
+               TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
+               column.getColumn().setWidth(200);
+               column.getColumn().setText("Path");
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       private static final long serialVersionUID = -3122136344359358605L;
+
+                       public String getText(Object element) {
+                               return ((SiteElem) element).getPath();
+                       }
+
+                       @Override
+                       public Image getImage(Object element) {
+                               return super.getImage(element);
+                       }
+
+               });
+
+               viewer.setContentProvider(new SitePathContentProvider());
+               viewer.setInput(bc);
+
+       }
+
+       class SitePathContentProvider extends AbstractTreeContentProvider {
+               private static final long serialVersionUID = -5650173256183322051L;
+
+               @Override
+               public Object[] getElements(Object inputElement) {
+                       if (inputElement instanceof BundleContext) {
+                               BundleContext bundleContext = (BundleContext) inputElement;
+                               Map<String, SiteElem> siteElems = new TreeMap<>();
+                               try {
+                                       Collection<ServiceReference<ApplicationConfiguration>> rwtApps = bundleContext
+                                                       .getServiceReferences(ApplicationConfiguration.class, null);
+                                       for (ServiceReference<ApplicationConfiguration> sr : rwtApps) {
+                                               RwtAppElem elem = new RwtAppElem(sr);
+                                               siteElems.put(elem.getPath(), elem);
+                                       }
+                                       Collection<ServiceReference<Servlet>> plainServlets = bundleContext
+                                                       .getServiceReferences(Servlet.class, null);
+                                       for (ServiceReference<Servlet> sr : plainServlets) {
+                                               ServletElem elem = new ServletElem(sr);
+                                               siteElems.put(elem.getPath(), elem);
+                                       }
+                               } catch (InvalidSyntaxException e) {
+                                       throw new IllegalArgumentException(e);
+                               }
+                               return siteElems.values().toArray();
+                       }
+                       return null;
+               }
+
+       }
+}