Introduce OSGi Explorer
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 4 Sep 2011 18:23:02 +0000 (18:23 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 4 Sep 2011 18:23:02 +0000 (18:23 +0000)
Improve RAP

git-svn-id: https://svn.argeo.org/commons/trunk@4712 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

30 files changed:
demo/argeo_node_web.properties
eclipse/features/org.argeo.eclipse.dep.rap/pom.xml
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/.classpath [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/.project [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/META-INF/MANIFEST.MF [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/build.properties [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/pom.xml
osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java [new file with mode: 0644]
osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java [new file with mode: 0644]
osgi/pom.xml
security/features/org.argeo.security.dep.node.rap/pom.xml
security/features/org.argeo.security.dep.node.rcp/pom.xml
security/plugins/org.argeo.security.ui.rap/branding/default.htm
security/plugins/org.argeo.security.ui.rap/plugin.xml
security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureEntryPoint.java
security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureRapActivator.java
security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureWorkbenchAdvisor.java
security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureWorkbenchWindowAdvisor.java

index 900e31ef75bdafce8528200530d2327ff9e1c0ac..e602fa8a04d141d8009fb8134aee284bcbdf9583 100644 (file)
@@ -12,14 +12,11 @@ org.eclipse.equinox.launcher,\
 org.argeo.dep.osgi.catalina.start,\
 org.argeo.jackrabbit.webapp,\
 org.argeo.server.rap.webapp,\
-org.argeo.jcr.ui.explorer,\
-org.argeo.security.ui,\
-org.argeo.security.ui.rap,\
-org.argeo.security.ui.admin,\
 org.argeo.server.ads.server,\
 org.springframework.osgi.web.extender,\
 
-org.argeo.security.ui.initialPerspective=org.argeo.jcr.ui.explorer.perspective
+#org.argeo.security.ui.initialPerspective=org.argeo.jcr.ui.explorer.perspective
+org.argeo.security.ui.initialPerspective=org.argeo.osgi.ui.explorer.perspective
 
 argeo.node.repo.home=~/.argeo/server_noderepo
 argeo.node.repo.dburl=jdbc:h2:file:~/.argeo/h2/server_noderepo_db
index 9fb76a5408adf60468f17f5447cb960470feb0c3..fcd6a56a3453e4fc2c648b889b4b88bb4885b92c 100644 (file)
@@ -94,7 +94,7 @@
                        <artifactId>org.eclipse.rap.ui</artifactId>
                </dependency>
 
-               <!-- Jetty (TO BE REMOVED and replaced by Tomcat -->
+               <!-- Jetty (TO BE REMOVED and replaced by Tomcat
                <dependency>
                        <groupId>org.eclipse.equinox</groupId>
                        <artifactId>org.eclipse.equinox.http.jetty</artifactId>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>org.mortbay.jetty.util</artifactId>
                </dependency>
+                -->
+                
                <!-- Eclipse -->
                <dependency>
                        <groupId>org.eclipse.core</groupId>
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java
new file mode 100644 (file)
index 0000000..dd7df8d
--- /dev/null
@@ -0,0 +1,82 @@
+package org.argeo.eclipse.ui;
+
+import java.util.Comparator;
+
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+
+/** Generic column viewer sortter */
+public class ColumnViewerComparator<T> extends ViewerComparator {
+       public static final int ASC = 1;
+
+       public static final int NONE = 0;
+
+       public static final int DESC = -1;
+
+       private int direction = 0;
+
+       private TableViewerColumn column;
+
+       private ColumnViewer viewer;
+
+       public ColumnViewerComparator(TableViewerColumn column,
+                       Comparator<T> comparator) {
+               super(comparator);
+               this.column = column;
+               this.viewer = column.getViewer();
+               this.column.getColumn().addSelectionListener(new SelectionAdapter() {
+
+                       public void widgetSelected(SelectionEvent e) {
+                               if (ColumnViewerComparator.this.viewer.getComparator() != null) {
+                                       if (ColumnViewerComparator.this.viewer.getComparator() == ColumnViewerComparator.this) {
+                                               int tdirection = ColumnViewerComparator.this.direction;
+
+                                               if (tdirection == ASC) {
+                                                       setSortDirection(DESC);
+                                               } else if (tdirection == DESC) {
+                                                       setSortDirection(NONE);
+                                               }
+                                       } else {
+                                               setSortDirection(ASC);
+                                       }
+                               } else {
+                                       setSortDirection(ASC);
+                               }
+                       }
+               });
+       }
+
+       private void setSortDirection(int direction) {
+               if (direction == NONE) {
+                       column.getColumn().getParent().setSortColumn(null);
+                       column.getColumn().getParent().setSortDirection(SWT.NONE);
+                       viewer.setComparator(null);
+               } else {
+                       column.getColumn().getParent().setSortColumn(column.getColumn());
+                       this.direction = direction;
+
+                       if (direction == ASC) {
+                               column.getColumn().getParent().setSortDirection(SWT.DOWN);
+                       } else {
+                               column.getColumn().getParent().setSortDirection(SWT.UP);
+                       }
+
+                       if (viewer.getComparator() == this) {
+                               viewer.refresh();
+                       } else {
+                               viewer.setComparator(this);
+                       }
+
+               }
+       }
+
+       @SuppressWarnings("unchecked")
+       public int compare(Viewer viewer, Object e1, Object e2) {
+               return direction * getComparator().compare((T) e1, (T) e2);
+       }
+}
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.classpath b/osgi/plugins/org.argeo.osgi.ui.explorer/.classpath
new file mode 100644 (file)
index 0000000..92f19d2
--- /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/J2SE-1.5"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.project b/osgi/plugins/org.argeo.osgi.ui.explorer/.project
new file mode 100644 (file)
index 0000000..1a4f4d3
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.osgi.ui.explorer</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs b/osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..9916a22
--- /dev/null
@@ -0,0 +1,8 @@
+#Sun Sep 04 16:04:00 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/META-INF/MANIFEST.MF b/osgi/plugins/org.argeo.osgi.ui.explorer/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..c37dfbc
--- /dev/null
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OSGi Explorer
+Bundle-SymbolicName: org.argeo.osgi.ui.explorer;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.argeo.osgi.ui.explorer.OsgiExplorerPlugin
+Require-Bundle: org.eclipse.ui;resolution:=optional,
+ org.eclipse.rap.ui;resolution:=optional,
+ org.eclipse.core.runtime
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.apache.commons.logging;version="1.1.1",
+ org.argeo.eclipse.ui
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/build.properties b/osgi/plugins/org.argeo.osgi.ui.explorer/build.properties
new file mode 100644 (file)
index 0000000..4f799f2
--- /dev/null
@@ -0,0 +1,6 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+               .,\
+               icons/,\
+               plugin.xml
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif
new file mode 100644 (file)
index 0000000..7d24707
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif
new file mode 100644 (file)
index 0000000..e9a6bd9
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif
new file mode 100644 (file)
index 0000000..2988716
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif
new file mode 100644 (file)
index 0000000..27bf10e
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif
new file mode 100644 (file)
index 0000000..f4a1ea1
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif
new file mode 100644 (file)
index 0000000..563743d
Binary files /dev/null and b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif differ
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml b/osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml
new file mode 100644 (file)
index 0000000..825d43b
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.ui.perspectives">
+      <perspective
+            name="OSGi Explorer"
+            class="org.argeo.osgi.ui.explorer.OsgiExplorerPerspective"
+            id="org.argeo.osgi.ui.explorer.perspective"
+            icon="icons/osgi_explorer.gif">
+      </perspective>
+   </extension>
+    <extension point="org.eclipse.ui.perspectiveExtensions"> 
+        <perspectiveExtension 
+            targetID="org.argeo.osgi.ui.explorer.perspective"> 
+            <view id="org.argeo.osgi.ui.explorer.modulesView" minimized="false"
+             ratio="0.5" relationship="left" relative="org.eclipse.ui.editorss"/> 
+            <view id="org.argeo.osgi.ui.explorer.bundlesView" minimized="false"
+             relationship="stack" relative="org.argeo.osgi.ui.explorer.modulesView"/> 
+        </perspectiveExtension> 
+    </extension> 
+   <extension
+         point="org.eclipse.ui.views">
+      <view
+            class="org.argeo.osgi.ui.explorer.views.ModulesView"
+            icon="icons/bundles.gif"
+            id="org.argeo.osgi.ui.explorer.modulesView"
+            name="Modules">
+      </view>
+      <view
+            class="org.argeo.osgi.ui.explorer.views.BundlesView"
+            icon="icons/bundles.gif"
+            id="org.argeo.osgi.ui.explorer.bundlesView"
+            name="Bundles">
+      </view>
+   </extension>
+  <extension
+           point="org.eclipse.ui.activities">
+        <activity
+              description="Only for admins"
+              id="org.argeo.osgi.ui.explorer.adminActivity"
+              name="Admin">
+                 <enabledWhen>
+                   <with variable="roles">
+                     <iterate ifEmpty="false" operator="or">
+                       <equals value="ROLE_ADMIN" />
+                     </iterate>
+                   </with>
+                 </enabledWhen>
+        </activity>
+        <activityPatternBinding
+              activityId="org.argeo.osgi.ui.explorer.adminActivity"
+              isEqualityPattern="true"
+              pattern="org.argeo.osgi.ui.explorer/org.argeo.osgi.ui.explorer.perspective">
+        </activityPatternBinding>
+     </extension>
+</plugin>
index c955ad9f9b4594951cdcbf72e70c8b20f00bcd97..9571ff057be7a3095c095191d95abf3d990ff2a4 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.osgi</groupId>
@@ -9,6 +10,11 @@
        <artifactId>org.argeo.osgi.ui.explorer</artifactId>
        <name>Commons OSGi Explorer</name>
        <dependencies>
+               <dependency>
+                       <groupId>org.argeo.commons.eclipse</groupId>
+                       <artifactId>org.argeo.eclipse.ui</artifactId>
+                       <version>0.3.4-SNAPSHOT</version>
+               </dependency>
 
                <!-- RCP only dependency, needed at compile time -->
                <dependency>
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java
new file mode 100644 (file)
index 0000000..3e16a76
--- /dev/null
@@ -0,0 +1,15 @@
+package org.argeo.osgi.ui.explorer;
+
+import org.eclipse.swt.graphics.Image;
+
+/** Shared icons. */
+public class OsgiExplorerImages {
+       public final static Image INSTALLED = OsgiExplorerPlugin
+                       .getImageDescriptor("icons/installed.gif").createImage();
+       public final static Image RESOLVED = OsgiExplorerPlugin.getImageDescriptor(
+                       "icons/resolved.gif").createImage();
+       public final static Image STARTING = OsgiExplorerPlugin.getImageDescriptor(
+                       "icons/starting.gif").createImage();
+       public final static Image ACTIVE = OsgiExplorerPlugin.getImageDescriptor(
+                       "icons/active.gif").createImage();
+}
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java
new file mode 100644 (file)
index 0000000..2665929
--- /dev/null
@@ -0,0 +1,15 @@
+package org.argeo.osgi.ui.explorer;
+
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+/** OSGi explorer perspective (to be enriched declaratively) */
+public class OsgiExplorerPerspective implements IPerspectiveFactory {
+
+       public void createInitialLayout(IPageLayout layout) {
+               layout.setEditorAreaVisible(true);
+               layout.setFixed(false);
+
+       }
+
+}
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java
new file mode 100644 (file)
index 0000000..42c3433
--- /dev/null
@@ -0,0 +1,61 @@
+package org.argeo.osgi.ui.explorer;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class OsgiExplorerPlugin extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String PLUGIN_ID = "org.argeo.osgi.ui.explorer"; //$NON-NLS-1$
+
+       // The shared instance
+       private static OsgiExplorerPlugin plugin;
+
+       /**
+        * The constructor
+        */
+       public OsgiExplorerPlugin() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+        * )
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+        * )
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        * 
+        * @return the shared instance
+        */
+       public static OsgiExplorerPlugin getDefault() {
+               return plugin;
+       }
+
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+
+}
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java
new file mode 100644 (file)
index 0000000..1669411
--- /dev/null
@@ -0,0 +1,187 @@
+package org.argeo.osgi.ui.explorer.views;
+
+import java.util.Comparator;
+
+import org.argeo.eclipse.ui.ColumnViewerComparator;
+import org.argeo.osgi.ui.explorer.OsgiExplorerImages;
+import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.part.ViewPart;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+/**
+ * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
+ * command.
+ */
+public class BundlesView extends ViewPart {
+       private TableViewer viewer;
+
+       @Override
+       public void createPartControl(Composite parent) {
+               viewer = new TableViewer(parent);
+               viewer.setContentProvider(new BundleContentProvider());
+               viewer.getTable().setHeaderVisible(true);
+
+               // FIXME methodNotFound issue in RAP when built in Maven against RCP
+               try {
+                       ColumnViewerToolTipSupport.enableFor(viewer);
+               } catch (Exception e) {
+                       viewer.getControl()
+                                       .setData(Table.ENABLE_CELL_TOOLTIP, Boolean.TRUE);
+               }
+
+               // ID
+               TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+               column.getColumn().setWidth(30);
+               column.getColumn().setText("ID");
+               column.getColumn().setAlignment(SWT.RIGHT);
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       public String getText(Object element) {
+                               return Long.toString(((Bundle) element).getBundleId());
+                       }
+               });
+               new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
+                       public int compare(Bundle o1, Bundle o2) {
+                               return (int) (o1.getBundleId() - o2.getBundleId());
+                       }
+               });
+
+               // State
+               column = new TableViewerColumn(viewer, SWT.NONE);
+               column.getColumn().setWidth(16);
+               column.getColumn().setText("State");
+               column.setLabelProvider(new StateLabelProvider());
+               new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
+                       public int compare(Bundle o1, Bundle o2) {
+                               return o1.getState() - o2.getState();
+                       }
+               });
+
+               // Symbolic name
+               column = new TableViewerColumn(viewer, SWT.NONE);
+               column.getColumn().setWidth(300);
+               column.getColumn().setText("Symbolic Name");
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       public String getText(Object element) {
+                               return ((Bundle) element).getSymbolicName();
+                       }
+               });
+               new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
+                       public int compare(Bundle o1, Bundle o2) {
+                               return o1.getSymbolicName().compareTo(o2.getSymbolicName());
+                       }
+               });
+
+               // Version
+               column = new TableViewerColumn(viewer, SWT.NONE);
+               column.getColumn().setWidth(150);
+               column.getColumn().setText("Version");
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       public String getText(Object element) {
+                               return ((Bundle) element).getVersion().toString();
+                       }
+               });
+               new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
+                       public int compare(Bundle o1, Bundle o2) {
+                               return o1.getVersion().compareTo(o2.getVersion());
+                       }
+               });
+
+               viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle()
+                               .getBundleContext());
+
+       }
+
+       @Override
+       public void setFocus() {
+               if (viewer != null)
+                       viewer.getControl().setFocus();
+       }
+
+       /** Content provider managing the array of bundles */
+       private static class BundleContentProvider implements
+                       IStructuredContentProvider {
+               public Object[] getElements(Object inputElement) {
+                       if (inputElement instanceof BundleContext) {
+                               BundleContext bc = (BundleContext) inputElement;
+                               return bc.getBundles();
+                       }
+                       return null;
+               }
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+
+       }
+
+       /** Label provider for the state column */
+       private static class StateLabelProvider extends ColumnLabelProvider {
+               @Override
+               public Image getImage(Object element) {
+                       Integer state = ((Bundle) element).getState();
+                       switch (state) {
+                       case Bundle.UNINSTALLED:
+                               return OsgiExplorerImages.INSTALLED;
+                       case Bundle.INSTALLED:
+                               return OsgiExplorerImages.INSTALLED;
+                       case Bundle.RESOLVED:
+                               return OsgiExplorerImages.RESOLVED;
+                       case Bundle.STARTING:
+                               return OsgiExplorerImages.STARTING;
+                       case Bundle.STOPPING:
+                               return OsgiExplorerImages.STARTING;
+                       case Bundle.ACTIVE:
+                               return OsgiExplorerImages.ACTIVE;
+                       default:
+                               return null;
+                       }
+               }
+
+               @Override
+               public String getText(Object element) {
+                       return null;
+               }
+
+               @Override
+               public String getToolTipText(Object element) {
+                       Bundle bundle = (Bundle) element;
+                       Integer state = bundle.getState();
+                       switch (state) {
+                       case Bundle.UNINSTALLED:
+                               return "UNINSTALLED";
+                       case Bundle.INSTALLED:
+                               return "INSTALLED";
+                       case Bundle.RESOLVED:
+                               return "RESOLVED";
+                       case Bundle.STARTING:
+                               String activationPolicy = bundle.getHeaders()
+                                               .get(Constants.BUNDLE_ACTIVATIONPOLICY).toString();
+                               if (activationPolicy != null
+                                               && activationPolicy.equals(Constants.ACTIVATION_LAZY))
+                                       return "<<LAZY>>";
+                               return "STARTING";
+                       case Bundle.STOPPING:
+                               return "STOPPING";
+                       case Bundle.ACTIVE:
+                               return "ACTIVE";
+                       default:
+                               return null;
+                       }
+               }
+
+       }
+}
diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java
new file mode 100644 (file)
index 0000000..1293506
--- /dev/null
@@ -0,0 +1,364 @@
+package org.argeo.osgi.ui.explorer.views;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/** <b>Experimental</b> The OSGi runtime from a module perspective. */
+public class ModulesView extends ViewPart {
+       private final static Log log = LogFactory.getLog(ModulesView.class);
+
+       private TreeViewer viewer;
+
+       private PackageAdmin packageAdmin;
+
+       private Comparator<ExportedPackage> exportedPackageComparator = new Comparator<ExportedPackage>() {
+
+               public int compare(ExportedPackage o1, ExportedPackage o2) {
+                       if (!o1.getName().equals(o2.getName()))
+                               return o1.getName().compareTo(o2.getName());
+                       else
+                               return o1.getVersion().compareTo(o2.getVersion());
+               }
+       };
+
+       @Override
+       public void createPartControl(Composite parent) {
+               viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+               viewer.setContentProvider(new ModulesContentProvider());
+               viewer.setLabelProvider(new ModulesLabelProvider());
+               viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle()
+                               .getBundleContext());
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTree().setFocus();
+       }
+
+       private class ModulesContentProvider implements ITreeContentProvider {
+
+               public Object[] getElements(Object inputElement) {
+                       return getChildren(inputElement);
+               }
+
+               public Object[] getChildren(Object parentElement) {
+                       if (parentElement instanceof BundleContext) {
+                               BundleContext bundleContext = (BundleContext) parentElement;
+                               Bundle[] bundles = bundleContext.getBundles();
+
+                               TreeParent bundlesNode = new TreeParent("Bundles");
+                               for (Bundle bundle : bundles) {
+                                       if (bundle.getState() == Bundle.ACTIVE)
+                                               bundlesNode.addChild(new BundleNode(bundle));
+                               }
+
+                               // scan packages
+                               ServiceReference paSr = bundleContext
+                                               .getServiceReference(PackageAdmin.class.getName());
+                               // TODO: make a cleaner referencing
+                               packageAdmin = (PackageAdmin) bundleContext.getService(paSr);
+
+                               Bundle bundle1 = null;
+                               Bundle bundle2 = null;
+
+                               Map<Bundle, Set<ExportedPackage>> importedPackages = new HashMap<Bundle, Set<ExportedPackage>>();
+                               Map<String, Set<ExportedPackage>> packages = new TreeMap<String, Set<ExportedPackage>>();
+                               for (Bundle bundle : bundles) {
+                                       if (bundle.getSymbolicName()
+                                                       .equals("org.argeo.security.ui"))
+                                               bundle1 = bundle;
+                                       if (bundle.getSymbolicName().equals(
+                                                       "org.argeo.security.equinox"))
+                                               bundle2 = bundle;
+
+                                       ExportedPackage[] pkgs = packageAdmin
+                                                       .getExportedPackages(bundle);
+                                       if (pkgs != null)
+                                               for (ExportedPackage pkg : pkgs) {
+                                                       if (!packages.containsKey(pkg.getName()))
+                                                               packages.put(pkg.getName(),
+                                                                               new TreeSet<ExportedPackage>(
+                                                                                               exportedPackageComparator));
+                                                       Set<ExportedPackage> expPackages = (Set<ExportedPackage>) packages
+                                                                       .get(pkg.getName());
+                                                       expPackages.add(pkg);
+
+                                                       // imported
+                                                       for (Bundle b : pkg.getImportingBundles()) {
+                                                               if (bundle.getBundleId() != b.getBundleId()) {
+                                                                       if (!importedPackages.containsKey(b))
+                                                                               importedPackages
+                                                                                               .put(b,
+                                                                                                               new TreeSet<ExportedPackage>(
+                                                                                                                               exportedPackageComparator));
+                                                                       Set<ExportedPackage> impPackages = (Set<ExportedPackage>) importedPackages
+                                                                                       .get(b);
+                                                                       impPackages.add(pkg);
+                                                               }
+                                                       }
+                                               }
+                               }
+
+                               TreeParent mPackageNode = new TreeParent("Multiple Packages");
+                               // TreeParent aPackageNode = new TreeParent("All Packages");
+                               for (String packageName : packages.keySet()) {
+                                       Set<ExportedPackage> pkgs = packages.get(packageName);
+                                       if (pkgs.size() > 1) {
+                                               MultiplePackagesNode mpn = new MultiplePackagesNode(
+                                                               packageName, pkgs);
+                                               mPackageNode.addChild(mpn);
+                                               // aPackageNode.addChild(mpn);
+                                       } else {
+                                               // aPackageNode.addChild(new ExportedPackageNode(pkgs
+                                               // .iterator().next()));
+                                       }
+                               }
+
+                               return new Object[] { bundlesNode, mPackageNode };// ,
+                                                                                                                                       // aPackageNode
+                                                                                                                                       // };
+                       } else if (parentElement instanceof TreeParent) {
+                               return ((TreeParent) parentElement).getChildren();
+                       } else {
+                               return null;
+                       }
+               }
+
+               public Object getParent(Object element) {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+               public boolean hasChildren(Object element) {
+                       if (element instanceof TreeParent) {
+                               return ((TreeParent) element).hasChildren();
+                       }
+                       return false;
+               }
+
+               public void dispose() {
+                       // TODO Auto-generated method stub
+
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                       // TODO Auto-generated method stub
+
+               }
+
+       }
+
+       protected Map<String, ExportedPackage> dependencySpace(Bundle bundle,
+                       Map<Bundle, Set<ExportedPackage>> importedPackages,
+                       Map<String, Set<String>> traces) {
+               log.debug("Dependency space for " + bundle.getSymbolicName());
+               Map<String, ExportedPackage> space = new TreeMap<String, ExportedPackage>();
+               fillDependencySpace(space, bundle, importedPackages,
+                               bundle.getSymbolicName(), traces);
+               return space;
+       }
+
+       /** Recursive */
+       protected void fillDependencySpace(Map<String, ExportedPackage> space,
+                       Bundle bundle, Map<Bundle, Set<ExportedPackage>> importedPackages,
+                       String currTrace, Map<String, Set<String>> traces) {
+               if (importedPackages.containsKey(bundle)) {
+                       Set<ExportedPackage> imports = importedPackages.get(bundle);
+                       // log.debug("## Fill dependency space for " + bundle + " : ");
+                       for (ExportedPackage pkg : imports) {
+                               if (!traces.containsKey(pkg.getName()))
+                                       traces.put(pkg.getName(), new TreeSet<String>());
+                               traces.get(pkg.getName()).add(currTrace);
+                               if (!space.containsKey(pkg.getName())) {
+                                       space.put(pkg.getName(), pkg);
+                                       Bundle exportingBundle = pkg.getExportingBundle();
+                                       // if (bundle.getBundleId() !=
+                                       // exportingBundle.getBundleId())
+                                       fillDependencySpace(space, exportingBundle,
+                                                       importedPackages, currTrace + " > "
+                                                                       + exportingBundle.getSymbolicName(), traces);
+                               }
+                       }
+               }
+       }
+
+       private class ModulesLabelProvider extends LabelProvider implements
+                       ITableLabelProvider {
+
+               public Image getColumnImage(Object element, int columnIndex) {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+               public String getColumnText(Object element, int columnIndex) {
+                       return getText(element);
+               }
+
+       }
+
+       class BundleNode extends TreeParent {
+               private final Bundle bundle;
+
+               public BundleNode(Bundle bundle) {
+                       super(bundle.getSymbolicName());
+                       this.bundle = bundle;
+
+                       // Registered services
+                       ServiceReference[] registeredServices = bundle
+                                       .getRegisteredServices();
+                       if (registeredServices != null) {
+                               TreeParent registeredServicesNode = new TreeParent(
+                                               "Registered Services");
+                               addChild(registeredServicesNode);
+                               for (ServiceReference sr : registeredServices) {
+                                       if (sr != null)
+                                               registeredServicesNode
+                                                               .addChild(new ServiceReferenceNode(sr));
+                               }
+                       }
+
+                       // Used services
+                       ServiceReference[] usedServices = bundle.getRegisteredServices();
+                       if (usedServices != null) {
+                               TreeParent usedServicesNode = new TreeParent("Used Services");
+                               addChild(usedServicesNode);
+                               for (ServiceReference sr : usedServices) {
+                                       if (sr != null)
+                                               usedServicesNode.addChild(new ServiceReferenceNode(sr));
+                               }
+                       }
+               }
+
+               public Bundle getBundle() {
+                       return bundle;
+               }
+
+       }
+
+       class ServiceReferenceNode extends TreeParent {
+               private final ServiceReference serviceReference;
+
+               public ServiceReferenceNode(ServiceReference serviceReference) {
+                       super(serviceReference.toString());
+                       this.serviceReference = serviceReference;
+
+                       Bundle[] usedBundles = serviceReference.getUsingBundles();
+                       if (usedBundles != null) {
+                               TreeParent usingBundles = new TreeParent("Using Bundles");
+                               addChild(usingBundles);
+                               for (Bundle b : usedBundles) {
+                                       if (b != null)
+                                               usingBundles.addChild(new TreeParent(b
+                                                               .getSymbolicName()));
+                               }
+                       }
+
+                       TreeParent properties = new TreeParent("Properties");
+                       addChild(properties);
+                       for (String key : serviceReference.getPropertyKeys()) {
+                               properties.addChild(new TreeParent(key + "="
+                                               + serviceReference.getProperty(key)));
+                       }
+
+               }
+
+               public ServiceReference getServiceReference() {
+                       return serviceReference;
+               }
+
+       }
+
+       class MultiplePackagesNode extends TreeParent {
+               private String packageName;
+               private Set<ExportedPackage> exportedPackages;
+
+               public MultiplePackagesNode(String packageName,
+                               Set<ExportedPackage> exportedPackages) {
+                       super(packageName);
+                       this.packageName = packageName;
+                       this.exportedPackages = exportedPackages;
+                       for (ExportedPackage pkg : exportedPackages) {
+                               addChild(new ExportedPackageNode(pkg));
+                       }
+               }
+
+       }
+
+       class ConflictingPackageNode extends TreeParent {
+               private ExportedPackage exportedPackage;
+
+               public ConflictingPackageNode(ExportedPackage exportedPackage) {
+                       super(exportedPackage.getName() + " - "
+                                       + exportedPackage.getVersion() + " ("
+                                       + exportedPackage.getExportingBundle() + ")");
+                       this.exportedPackage = exportedPackage;
+
+                       TreeParent bundlesNode = new TreeParent("Dependent Bundles");
+                       this.addChild(bundlesNode);
+                       Map<String, Bundle> bundles = new TreeMap<String, Bundle>();
+                       for (Bundle b : exportedPackage.getImportingBundles()) {
+                               bundles.put(b.getSymbolicName(), b);
+                       }
+                       for (String key : bundles.keySet()) {
+                               addDependentBundles(bundlesNode, bundles.get(key));
+                       }
+               }
+       }
+
+       protected void addDependentBundles(TreeParent parent, Bundle bundle) {
+               TreeParent bundleNode = new TreeParent(bundle.toString());
+               parent.addChild(bundleNode);
+               Map<String, Bundle> bundles = new TreeMap<String, Bundle>();
+               ExportedPackage[] pkgs = packageAdmin.getExportedPackages(bundle);
+               if (pkgs != null)
+                       for (ExportedPackage pkg : pkgs) {
+                               for (Bundle b : pkg.getImportingBundles()) {
+                                       if (!bundles.containsKey(b.getSymbolicName())
+                                                       && b.getBundleId() != bundle.getBundleId()) {
+                                               bundles.put(b.getSymbolicName(), b);
+                                       }
+                               }
+                       }
+
+               for (String key : bundles.keySet()) {
+                       addDependentBundles(bundleNode, bundles.get(key));
+               }
+       }
+
+       class ExportedPackageNode extends TreeParent {
+               private ExportedPackage exportedPackage;
+
+               public ExportedPackageNode(ExportedPackage exportedPackage) {
+                       super(exportedPackage.getName() + " - "
+                                       + exportedPackage.getVersion() + " ("
+                                       + exportedPackage.getExportingBundle() + ")");
+                       this.exportedPackage = exportedPackage;
+                       for (Bundle bundle : exportedPackage.getImportingBundles()) {
+                               addChild(new BundleNode(bundle));
+                       }
+               }
+       }
+}
index 9873b55875a7a3b147d836f96581d3b526b16647..5fb919ac2e89255da0c9d71ce20a217c14597842 100644 (file)
@@ -12,6 +12,7 @@
        <packaging>pom</packaging>
        <modules>
                <module>runtime</module>
+               <module>plugins</module>
                <module>dep</module>
        </modules>
 </project>
\ No newline at end of file
index 8c167d4ae51f65bb2c4d62f036ee013d6e6cafe0..af69f1b393ebea091bc87ba0e54fc6ba05e0bd1e 100644 (file)
                        <artifactId>org.argeo.jcr.ui.explorer</artifactId>
                        <version>0.3.4-SNAPSHOT</version>
                </dependency>
+               <dependency>
+                       <groupId>org.argeo.commons.osgi</groupId>
+                       <artifactId>org.argeo.osgi.ui.explorer</artifactId>
+                       <version>0.3.4-SNAPSHOT</version>
+               </dependency>
                <dependency>
                        <groupId>org.argeo.commons.security</groupId>
                        <artifactId>org.argeo.security.ui.admin</artifactId>
index d786a7f6257688111c455b8dd7fef1ea1ad2d3fd..8994fe15ec3c14ab5e1821c5a3c99bab51c78505 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.security</groupId>
                        <artifactId>org.argeo.jcr.ui.explorer</artifactId>
                        <version>0.3.4-SNAPSHOT</version>
                </dependency>
+               <dependency>
+                       <groupId>org.argeo.commons.osgi</groupId>
+                       <artifactId>org.argeo.osgi.ui.explorer</artifactId>
+                       <version>0.3.4-SNAPSHOT</version>
+               </dependency>
                <dependency>
                        <groupId>org.argeo.commons.security</groupId>
                        <artifactId>org.argeo.security.ui.admin</artifactId>
index 67c89f4fe3eb40008d3d2c7f30d8ee636eed4b7b..6de7eb21644c31ccc6d1d4c50a172c69920ac86a 100644 (file)
@@ -5,7 +5,11 @@
 <table height="100%">
 <tr>
        <td style="vertical-align:middle">
-               <a style="font-family:sans-serif;color:#0066CC;text-decoration:none;" href="./secureWebUi">Login...</a>
+               <a 
+                       style="font-family:sans-serif;color:#0066CC;text-decoration:none;" 
+                       href="javascript:location.reload(true);" 
+                       title="Click to log in"
+               >Login...</a>
        </td>
 </tr>
 </table>
index 7e192647dff2e82f8813bd68a250a26125837274..9b284c251757d56b68175c6f68651270a769044d 100644 (file)
@@ -9,26 +9,14 @@
             parameter="secureWebUi">
       </entrypoint>
    </extension>
-   <extension
-         id="secureWebapp"
-         name="Argeo Secure Web App"
-         point="org.eclipse.core.runtime.applications">
-      <application cardinality="singleton-global"
-         thread="main"
-         visible="true">
-         <run
-               class="org.argeo.security.ui.rap.SecureEntryPoint">
-         </run>
-      </application>
-   </extension>
 
        <extension
          point="org.eclipse.rap.ui.branding">
        <branding
                        id="org.argeo.security.ui.rap.branding"
-            servletName="secureWebUi"
+            servletName="node"
             defaultEntrypointId="org.argeo.security.ui.rap.secureEntryPoint"
-            title="Argeo Secure Web UI"
+            title="Argeo Web UI"
             favicon="branding/favicon.ico"
             body="branding/default.htm">
        </branding>
index 2ddfe07057f63a166ff7e1b89be2641bc237561b..9f54e4c752c3918c536a2f6df92923c045344c60 100644 (file)
@@ -33,7 +33,6 @@ public class SecureEntryPoint implements IEntryPoint {
        private Integer loginTimeout = 1 * 60;
        private Integer sessionTimeout = 15 * 60;
 
-       @SuppressWarnings("unchecked")
        @Override
        public int createUI() {
                // Short login timeout so that the modal dialog login doesn't hang
@@ -73,29 +72,6 @@ public class SecureEntryPoint implements IEntryPoint {
                                        throw td;
                                }
 
-                               // if (e.getCause() != null) {
-                               // Throwable firstCause = e.getCause();
-                               // // log.error("Cause", firstCause);
-                               // if (firstCause instanceof LoginException
-                               // && firstCause.getCause() != null) {
-                               // Throwable secondCause = firstCause.getCause();
-                               // if (secondCause instanceof BadCredentialsException) {
-                               // MessageDialog.openInformation(
-                               // display.getActiveShell(),
-                               // "Bad Credentials",
-                               // "Your credentials are incorrect");
-                               // // retry login
-                               // continue tryLogin;
-                               // } else if (secondCause instanceof ThreadDeath) {
-                               // // rethrow thread death caused by dialog UI timeout
-                               // throw (ThreadDeath) secondCause;
-                               // }
-                               //
-                               // } else if (firstCause instanceof ThreadDeath) {
-                               // throw (ThreadDeath) firstCause;
-                               // }
-                               // }
-
                                if (!display.isDisposed()) {
                                        org.argeo.eclipse.ui.Error.show(
                                                        "Unexpected exception during authentication", e);
index 2a29ba7e0e480420266da5c7e2814b592cdbcb25..762b227830f1d5b120a461f6958560a1ff63371b 100644 (file)
@@ -7,33 +7,22 @@ import org.eclipse.equinox.security.auth.LoginContextFactory;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
+/** Configure Equinox login context from the bundle context. */
 public class SecureRapActivator implements BundleActivator {
 
        public final static String ID = "org.argeo.security.ui.rap";
        public final static String CONTEXT_SPRING = "SPRING";
        private static final String JAAS_CONFIG_FILE = "/META-INF/jaas_default.txt";
 
-       //private static ILoginContext loginContext = null;
-       
        private static BundleContext bundleContext;
 
        public void start(BundleContext bundleContext) throws Exception {
                SecureRapActivator.bundleContext = bundleContext;
-//             URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
-//             loginContext = LoginContextFactory.createContext(CONTEXT_SPRING,
-//                             configUrl);
        }
 
        public void stop(BundleContext context) throws Exception {
        }
 
-//     static ILoginContext getLoginContext() {
-//             if (loginContext == null)
-//                     throw new ArgeoException(
-//                                     "No Equinox login context available, check your configuration");
-//             return loginContext;
-//     }
-
        static ILoginContext createLoginContext() {
                URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
                return LoginContextFactory.createContext(CONTEXT_SPRING, configUrl);
index 072d7de5e9aafcb1d638be1cba4d79d9c9e3ac47..06a83306db794940db3d05f3e27308b281d4c472 100644 (file)
@@ -1,16 +1,15 @@
 package org.argeo.security.ui.rap;
 
+import org.eclipse.ui.IPerspectiveDescriptor;
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
 import org.eclipse.ui.application.WorkbenchAdvisor;
 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
 
 public class SecureWorkbenchAdvisor extends WorkbenchAdvisor {
-
-       static final String DEFAULT_PERSPECTIVE_ID = "org.argeo.security.ui.adminSecurityPerspective"; //$NON-NLS-1$
-
+       //static final String DEFAULT_PERSPECTIVE_ID = "org.argeo.security.ui.adminSecurityPerspective"; //$NON-NLS-1$
        public final static String INITIAL_PERSPECTIVE_PROPERTY = "org.argeo.security.ui.initialPerspective";
        private String initialPerspective = System.getProperty(
-                       INITIAL_PERSPECTIVE_PROPERTY, DEFAULT_PERSPECTIVE_ID);
+                       INITIAL_PERSPECTIVE_PROPERTY, null);
 
        public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
                        IWorkbenchWindowConfigurer configurer) {
@@ -18,6 +17,16 @@ public class SecureWorkbenchAdvisor extends WorkbenchAdvisor {
        }
 
        public String getInitialWindowPerspectiveId() {
+               if (initialPerspective != null) {
+                       // check whether this user can see the declared perspective
+                       // (typically the perspective won't be listed if this user doesn't
+                       // have the right to see it)
+                       IPerspectiveDescriptor pd = getWorkbenchConfigurer().getWorkbench()
+                                       .getPerspectiveRegistry()
+                                       .findPerspectiveWithId(initialPerspective);
+                       if(pd==null)
+                               return null;
+               }
                return initialPerspective;
        }
 }
index f4c07a84ac21c98988dc7464cc1de6db068ff215..c2675d58b8398c37a2f2802a5f87dd12caf059f4 100644 (file)
@@ -1,6 +1,9 @@
 package org.argeo.security.ui.rap;
 
 import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
 import org.eclipse.ui.application.ActionBarAdvisor;
 import org.eclipse.ui.application.IActionBarConfigurer;
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
@@ -26,7 +29,22 @@ public class SecureWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
 
                configurer.setShowPerspectiveBar(true);
                configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$
+       }
 
+       @Override
+       public void postWindowOpen() {
+               String defaultPerspective = getWindowConfigurer()
+                               .getWorkbenchConfigurer().getWorkbench()
+                               .getPerspectiveRegistry().getDefaultPerspective();
+               if (defaultPerspective == null) {
+                       IWorkbenchWindow window = getWindowConfigurer().getWindow();
+                       if (window == null)
+                               return;
+
+                       IWorkbenchAction openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
+                                       .create(window);
+                       openPerspectiveDialogAction.run();
+               }
        }
 
 }