Move to Commons Base
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 17 Jul 2012 12:29:27 +0000 (12:29 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 17 Jul 2012 12:29:27 +0000 (12:29 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5475 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

40 files changed:
base/runtime/org.argeo.eclipse.ui/.classpath [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/.project [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/build.properties [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/pom.xml [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java [new file with mode: 0644]
base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java [new file with mode: 0644]
eclipse/runtime/org.argeo.eclipse.ui/.classpath [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/.project [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/build.properties [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/pom.xml [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java [deleted file]

diff --git a/base/runtime/org.argeo.eclipse.ui/.classpath b/base/runtime/org.argeo.eclipse.ui/.classpath
new file mode 100644 (file)
index 0000000..a507434
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/base/runtime/org.argeo.eclipse.ui/.project b/base/runtime/org.argeo.eclipse.ui/.project
new file mode 100644 (file)
index 0000000..53e9b32
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.eclipse.ui</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/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..f441c90
--- /dev/null
@@ -0,0 +1,8 @@
+#Thu Jul 29 10:54:11 CEST 2010
+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/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs
new file mode 100644 (file)
index 0000000..8e36e33
--- /dev/null
@@ -0,0 +1,3 @@
+#Thu Jul 29 11:00:39 CEST 2010
+eclipse.preferences.version=1
+resolve.requirebundle=false
diff --git a/base/runtime/org.argeo.eclipse.ui/build.properties b/base/runtime/org.argeo.eclipse.ui/build.properties
new file mode 100644 (file)
index 0000000..5fc538b
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+               .
diff --git a/base/runtime/org.argeo.eclipse.ui/pom.xml b/base/runtime/org.argeo.eclipse.ui/pom.xml
new file mode 100644 (file)
index 0000000..1be829d
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><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.eclipse</groupId>
+               <version>1.1.4-SNAPSHOT</version>
+               <artifactId>runtime</artifactId>
+               <relativePath>..</relativePath>
+       </parent>
+       <artifactId>org.argeo.eclipse.ui</artifactId>
+       <name>Commons Eclipse UI</name>
+       <packaging>jar</packaging>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-source-plugin</artifactId>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-jar-plugin</artifactId>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
+                                               <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+                                               <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
+                                               <Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
+                                               <Import-Package>
+                                                       org.springframework.beans.factory,
+                                                       org.springframework.core.io.support,
+                                                       !org.eclipse.core.runtime,
+                                                       !org.eclipse.core.commands,
+                                                       !org.eclipse.ui.plugin,
+                                                       *
+                                               </Import-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+       <dependencies>
+               <!-- JCR -->
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>javax.jcr</artifactId>
+               </dependency>
+
+               <!-- RCP only dependency, needed at compile time -->
+               <dependency>
+                       <groupId>org.argeo.commons.eclipse</groupId>
+                       <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
+                       <version>1.1.4-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+
+               <!-- Commons -->
+               <dependency>
+                       <groupId>org.argeo.commons.basic</groupId>
+                       <artifactId>org.argeo.basic.nodeps</artifactId>
+                       <version>1.1.4-SNAPSHOT</version>
+               </dependency>
+
+               <!-- Spring -->
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>org.springframework.context</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>org.springframework.osgi.extender</artifactId>
+               </dependency>
+
+               <!-- Others -->
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>slf4j.org.apache.commons.logging</artifactId>
+               </dependency>
+
+       </dependencies>
+</project>
\ No newline at end of file
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java
new file mode 100644 (file)
index 0000000..fcd42ba
--- /dev/null
@@ -0,0 +1,138 @@
+/*\r
+ * Copyright (C) 2007-2012 Mathieu Baudier\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.eclipse.spring;\r
+\r
+import static java.text.MessageFormat.format;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.BundleException;\r
+import org.osgi.framework.FrameworkUtil;\r
+import org.osgi.framework.InvalidSyntaxException;\r
+import org.osgi.util.tracker.ServiceTracker;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * Tracks Spring application context published as services.\r
+ * \r
+ * @author Heiko Seeberger\r
+ * @author Mathieu Baudier\r
+ */\r
+class ApplicationContextTracker {\r
+       private final static Log log = LogFactory\r
+                       .getLog(ApplicationContextTracker.class);\r
+\r
+       private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
+                       + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
+\r
+       public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout";\r
+\r
+       private static Long defaultTimeout = Long.parseLong(System.getProperty(\r
+                       APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000"));\r
+\r
+       private ServiceTracker applicationContextServiceTracker;\r
+\r
+       /**\r
+        * @param contributorBundle\r
+        *            OSGi bundle for which the Spring application context is to be\r
+        *            tracked. Must not be null!\r
+        * @param factoryBundleContext\r
+        *            BundleContext object which can be used to track services\r
+        * @throws IllegalArgumentException\r
+        *             if the given bundle is null.\r
+        */\r
+       public ApplicationContextTracker(final Bundle contributorBundle,\r
+                       final BundleContext factoryBundleContext) {\r
+               final String filter = format(FILTER,\r
+                               contributorBundle.getSymbolicName());\r
+               try {\r
+                       applicationContextServiceTracker = new ServiceTracker(\r
+                                       factoryBundleContext, FrameworkUtil.createFilter(filter),\r
+                                       null);\r
+                       // applicationContextServiceTracker.open();\r
+               } catch (final InvalidSyntaxException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+       public void open() {\r
+               if (applicationContextServiceTracker != null) {\r
+                       applicationContextServiceTracker.open();\r
+               }\r
+       }\r
+\r
+       public void close() {\r
+               if (applicationContextServiceTracker != null) {\r
+                       applicationContextServiceTracker.close();\r
+               }\r
+       }\r
+\r
+       public ApplicationContext getApplicationContext() {\r
+               ApplicationContext applicationContext = null;\r
+               if (applicationContextServiceTracker != null) {\r
+                       try {\r
+                               applicationContext = (ApplicationContext) applicationContextServiceTracker\r
+                                               .waitForService(defaultTimeout);\r
+                       } catch (InterruptedException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               return applicationContext;\r
+       }\r
+\r
+       @Override\r
+       protected void finalize() throws Throwable {\r
+               close();\r
+               super.finalize();\r
+       }\r
+\r
+       static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
+               Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
+               return getApplicationContext(contributorBundle);\r
+       }\r
+\r
+       static ApplicationContext getApplicationContext(Bundle contributorBundle) {\r
+               if (log.isTraceEnabled())\r
+                       log.trace("Get application context for bundle " + contributorBundle);\r
+\r
+               if (contributorBundle.getState() != Bundle.ACTIVE\r
+                               && contributorBundle.getState() != Bundle.STARTING) {\r
+                       try {\r
+                               if (log.isTraceEnabled())\r
+                                       log.trace("Starting bundle: "\r
+                                                       + contributorBundle.getSymbolicName());\r
+                               contributorBundle.start();\r
+                       } catch (BundleException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+\r
+               final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
+                               contributorBundle, contributorBundle.getBundleContext());\r
+               ApplicationContext applicationContext = null;\r
+               try {\r
+                       applicationContextTracker.open();\r
+                       applicationContext = applicationContextTracker\r
+                                       .getApplicationContext();\r
+               } finally {\r
+                       applicationContextTracker.close();\r
+               }\r
+               return applicationContext;\r
+       }\r
+}\r
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java
new file mode 100644 (file)
index 0000000..dc045c9
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.spring;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.springframework.context.ApplicationContext;
+
+/** Allows to declare Eclipse commands as Spring beans */
+public class SpringCommandHandler implements IHandler {
+       private final static Log log = LogFactory
+                       .getLog(SpringCommandHandler.class);
+
+       public void addHandlerListener(IHandlerListener handlerListener) {
+       }
+
+       public void dispose() {
+       }
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               String commandId = event.getCommand().getId();
+               String bundleSymbolicName = commandId.substring(0,
+                               commandId.lastIndexOf('.'));
+               try {
+                       if (log.isTraceEnabled())
+                               log.trace("Execute " + event + " via spring command handler "
+                                               + this);
+                       // TODO: make it more flexible and robust
+                       ApplicationContext applicationContext = ApplicationContextTracker
+                                       .getApplicationContext(bundleSymbolicName);
+                       if (applicationContext == null)
+                               throw new ArgeoException("No application context found for "
+                                               + bundleSymbolicName);
+
+                       // retrieve the command via its id
+                       String beanName = event.getCommand().getId();
+
+                       if (!applicationContext.containsBean(beanName)) {
+                               if (beanName.startsWith(bundleSymbolicName))
+                                       beanName = beanName
+                                                       .substring(bundleSymbolicName.length() + 1);
+                       }
+
+                       if (!applicationContext.containsBean(beanName))
+                               throw new ExecutionException("No bean found with name "
+                                               + beanName + " in bundle " + bundleSymbolicName);
+                       Object bean = applicationContext.getBean(beanName);
+
+                       if (!(bean instanceof IHandler))
+                               throw new ExecutionException("Bean with name " + beanName
+                                               + " and class " + bean.getClass()
+                                               + " does not implement the IHandler interface.");
+
+                       IHandler handler = (IHandler) bean;
+                       return handler.execute(event);
+               } catch (Exception e) {
+                       // TODO: use eclipse error management
+                       // log.error(e);
+                       throw new ExecutionException("Cannot execute Spring command "
+                                       + commandId + " in bundle " + bundleSymbolicName, e);
+               }
+       }
+
+       public boolean isEnabled() {
+               return true;
+       }
+
+       public boolean isHandled() {
+               return true;
+       }
+
+       public void removeHandlerListener(IHandlerListener handlerListener) {
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java
new file mode 100644 (file)
index 0000000..d8ec9d7
--- /dev/null
@@ -0,0 +1,114 @@
+/*\r
+ * Copyright (C) 2007-2012 Mathieu Baudier\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.eclipse.spring;\r
+\r
+import org.argeo.ArgeoException;\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
+import org.eclipse.core.runtime.IExecutableExtension;\r
+import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
+import org.eclipse.core.runtime.IExtension;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * The Spring Extension Factory builds a bridge between the Eclipse Extension\r
+ * Registry and the Spring Framework (especially Spring Dynamic Modules).\r
+ * \r
+ * It allows you to define your extension as a spring bean within the spring\r
+ * application context of your bundle. If you would like to use this bean as an\r
+ * instance of an extension (an Eclipse RCP view, for example) you define the\r
+ * extension with this spring extension factory as the class to be created.\r
+ * \r
+ * To let the spring extension factory pick the right bean from your application\r
+ * context you need to set the bean id to the same value as the id of the view\r
+ * within the view definition, for example. This is important if your extension\r
+ * definition contains more than one element, where each element has its own id.\r
+ * \r
+ * If the extension definition elements themselves have no id attribute the\r
+ * spring extension factory uses the id of the extension itself to identify the\r
+ * bean.\r
+ * \r
+ * original code from: <a href=\r
+ * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
+ * >Blog entry</a>\r
+ * \r
+ * @author Martin Lippert\r
+ * @author mbaudier\r
+ */\r
+public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
+               IExecutableExtension {\r
+\r
+       private Object bean;\r
+\r
+       public Object create() throws CoreException {\r
+               if (bean == null)\r
+                       throw new ArgeoException("No underlying bean for extension");\r
+               return bean;\r
+       }\r
+\r
+       public void setInitializationData(IConfigurationElement config,\r
+                       String propertyName, Object data) throws CoreException {\r
+               String bundleSymbolicName = config.getContributor().getName();\r
+               ApplicationContext applicationContext = ApplicationContextTracker\r
+                               .getApplicationContext(bundleSymbolicName);\r
+               if (applicationContext == null)\r
+                       throw new ArgeoException(\r
+                                       "Cannot find application context for bundle "\r
+                                                       + bundleSymbolicName);\r
+\r
+               String beanName = getBeanName(data, config);\r
+               if (beanName == null)\r
+                       throw new ArgeoException("Cannot find bean name for extension "\r
+                                       + config);\r
+\r
+               if (!applicationContext.containsBean(beanName)) {\r
+                       if (beanName.startsWith(bundleSymbolicName))\r
+                               beanName = beanName.substring(bundleSymbolicName.length() + 1);\r
+               }\r
+\r
+               if (!applicationContext.containsBean(beanName))\r
+                       throw new ArgeoException("No bean with name '" + beanName + "'");\r
+\r
+               this.bean = applicationContext.getBean(beanName);\r
+               if (this.bean instanceof IExecutableExtension) {\r
+                       ((IExecutableExtension) this.bean).setInitializationData(config,\r
+                                       propertyName, data);\r
+               }\r
+       }\r
+\r
+       private String getBeanName(Object data, IConfigurationElement config) {\r
+\r
+               // try the specific bean id the extension defines\r
+               if (data != null && data.toString().length() > 0) {\r
+                       return data.toString();\r
+               }\r
+\r
+               // try the id of the config element\r
+               if (config.getAttribute("id") != null) {\r
+                       return config.getAttribute("id");\r
+               }\r
+\r
+               // try the id of the extension element itself\r
+               if (config.getParent() != null\r
+                               && config.getParent() instanceof IExtension) {\r
+                       IExtension extensionDefinition = (IExtension) config.getParent();\r
+                       return extensionDefinition.getSimpleIdentifier();\r
+               }\r
+\r
+               return null;\r
+       }\r
+\r
+}\r
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java
new file mode 100644 (file)
index 0000000..a89fbcc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Tree content provider dealing with tree objects and providing reasonable
+ * defaults.
+ */
+public abstract class AbstractTreeContentProvider implements
+               ITreeContentProvider {
+
+       /** Does nothing */
+       public void dispose() {
+       }
+
+       /** Does nothing */
+       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+       }
+
+       public Object[] getChildren(Object element) {
+               if (element instanceof TreeParent) {
+                       return ((TreeParent) element).getChildren();
+               }
+               return new Object[0];
+       }
+
+       public Object getParent(Object element) {
+               if (element instanceof TreeParent) {
+                       return ((TreeParent) element).getParent();
+               }
+               return null;
+       }
+
+       public boolean hasChildren(Object element) {
+               if (element instanceof TreeParent) {
+                       return ((TreeParent) element).hasChildren();
+               }
+               return false;
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java
new file mode 100644 (file)
index 0000000..d34deb0
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener {
+       public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
+       private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class);
+       // The shared instance
+       private static ArgeoUiPlugin plugin;
+
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               // weirdly, the start method is called twice...
+               if (plugin == null) {
+                       plugin = this;
+                       Platform.addLogListener(this);
+                       log.debug("Eclipse logging now directed to standard logging");
+               }
+       }
+
+       public void stop(BundleContext context) throws Exception {
+               try {
+                       // weirdly, the stop method is called twice...
+                       if (plugin != null) {
+                               Platform.removeLogListener(this);
+                               log.debug("Eclipse logging not directed anymore to standard logging");
+                               plugin = null;
+                       }
+               } finally {
+                       super.stop(context);
+               }
+       }
+
+       /** Returns the shared instance */
+       public static ArgeoUiPlugin getDefault() {
+               return plugin;
+       }
+
+       public void logging(IStatus status, String plugin) {
+               Log pluginLog = LogFactory.getLog(plugin);
+               Integer severity = status.getSeverity();
+               if (severity == IStatus.ERROR)
+                       pluginLog.error(status.getMessage(), status.getException());
+               else if (severity == IStatus.WARNING)
+                       pluginLog.warn(status.getMessage(), status.getException());
+               else if (severity == IStatus.INFO)
+                       pluginLog.info(status.getMessage(), status.getException());
+               else if (severity == IStatus.CANCEL)
+                       if (pluginLog.isDebugEnabled())
+                               pluginLog.debug(status.getMessage(), status.getException());
+
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java
new file mode 100644 (file)
index 0000000..64edf72
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java
new file mode 100644 (file)
index 0000000..03d0c38
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/** Utilities to simplify UI development. */
+public class EclipseUiUtils {
+       /**
+        * Create a label and a text field for a grid layout, the text field grabing
+        * excess horizontal
+        * 
+        * @param parent
+        *            the parent composite
+        * @param label
+        *            the lable to display
+        * @param modifyListener
+        *            a {@link ModifyListener} to listen on events on the text, can
+        *            be null
+        * @return the created text
+        * 
+        * @deprecated use {@link #createGridLT(Composite, String)} instead
+        */
+       @Deprecated
+       public static Text createGridLT(Composite parent, String label,
+                       ModifyListener modifyListener) {
+               Label lbl = new Label(parent, SWT.LEAD);
+               lbl.setText(label);
+               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+               Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
+               txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+               if (modifyListener != null)
+                       txt.addModifyListener(modifyListener);
+               return txt;
+       }
+
+       public static Text createGridLT(Composite parent, String label) {
+               return createGridLT(parent, label, null);
+       }
+
+       /**
+        * Creates one label and a text field not editable with background color of
+        * the parent (like a label but with selectable text)
+        */
+       public static Text createGridLL(Composite parent, String label, String text) {
+               Text txt = createGridLT(parent, label);
+               txt.setText(text);
+               txt.setEditable(false);
+               txt.setBackground(parent.getBackground());
+               return txt;
+       }
+
+       public static Text createGridLP(Composite parent, String label,
+                       ModifyListener modifyListener) {
+               Label lbl = new Label(parent, SWT.LEAD);
+               lbl.setText(label);
+               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+               Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
+               txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+               if (txt != null)
+                       txt.addModifyListener(modifyListener);
+               return txt;
+       }
+
+       public static Font getItalicFont(Composite parent) {
+               return JFaceResources.getFontRegistry().defaultFontDescriptor()
+                               .setStyle(SWT.ITALIC).createFont(parent.getDisplay());
+       }
+
+       public static Font getBoldFont(Composite parent) {
+               return JFaceResources.getFontRegistry().defaultFontDescriptor()
+                               .setStyle(SWT.BOLD).createFont(parent.getDisplay());
+       }
+
+       public static Font getBoldItalicFont(Composite parent) {
+               return JFaceResources.getFontRegistry().defaultFontDescriptor()
+                               .setStyle(SWT.BOLD | SWT.ITALIC)
+                               .createFont(parent.getDisplay());
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java
new file mode 100644 (file)
index 0000000..d35c699
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @deprecated deprecated because of poor naming, use {@link ErrorFeedback}
+ *             instead
+ */
+@Deprecated
+public class Error extends ErrorFeedback {
+
+       public Error(Shell parentShell, String message, Throwable e) {
+               super(parentShell, message, e);
+               // TODO Auto-generated constructor stub
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java
new file mode 100644 (file)
index 0000000..618d708
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+/** Generic error dialog to be used in try/catch blocks */
+public class ErrorFeedback extends TitleAreaDialog {
+       private final static Log log = LogFactory.getLog(ErrorFeedback.class);
+
+       private final String message;
+       private final Throwable exception;
+
+       public static void show(String message, Throwable e) {
+               // rethrow ThreaDeath in order to make sure that RAP will properly clean
+               // up the UI thread
+               if (e instanceof ThreadDeath)
+                       throw (ThreadDeath) e;
+               
+               new ErrorFeedback(getDisplay().getActiveShell(), message, e).open();
+       }
+
+       public static void show(String message) {
+               new ErrorFeedback(getDisplay().getActiveShell(), message, null).open();
+       }
+
+       /** Tries to find a display */
+       private static Display getDisplay() {
+               try {
+                       Display display = PlatformUI.getWorkbench().getDisplay();
+                       if (display != null)
+                               return display;
+                       else
+                               return Display.getDefault();
+               } catch (Exception e) {
+                       return Display.getCurrent();
+               }
+       }
+
+       public ErrorFeedback(Shell parentShell, String message, Throwable e) {
+               super(parentShell);
+               this.message = message;
+               this.exception = e;
+               log.error(message, e);
+       }
+
+       protected Point getInitialSize() {
+               if (exception != null)
+                       return new Point(800, 600);
+               else
+                       return new Point(400, 300);
+       }
+
+       @Override
+       protected Control createDialogArea(Composite parent) {
+               Composite dialogarea = (Composite) super.createDialogArea(parent);
+               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               Composite composite = new Composite(dialogarea, SWT.NONE);
+               composite.setLayout(new GridLayout(2, false));
+               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+               setMessage(message != null ? message
+                               + (exception != null ? ": " + exception.getMessage() : "")
+                               : exception != null ? exception.getMessage() : "Unkown Error",
+                               IMessageProvider.ERROR);
+
+               if (exception != null) {
+                       Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER
+                                       | SWT.V_SCROLL | SWT.H_SCROLL);
+                       stack.setEditable(false);
+                       stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+                       StringWriter sw = new StringWriter();
+                       exception.printStackTrace(new PrintWriter(sw));
+                       stack.setText(sw.toString());
+               }
+
+               parent.pack();
+               return composite;
+       }
+
+       protected void configureShell(Shell shell) {
+               super.configureShell(shell);
+               shell.setText("Error");
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java
new file mode 100644 (file)
index 0000000..fabeb5d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+public abstract class GenericTableComparator extends ViewerComparator {
+
+       protected int propertyIndex;
+       public static final int ASCENDING = 0, DESCENDING = 1;
+       protected int direction = DESCENDING;
+
+       /**
+        * Creates an instance of a sorter for TableViewer.
+        * 
+        * @param defaultColumn
+        *            the default sorter column
+        */
+
+       public GenericTableComparator(int defaultColumnIndex, int direction) {
+               propertyIndex = defaultColumnIndex;
+               this.direction = direction;
+       }
+
+       public void setColumn(int column) {
+               if (column == this.propertyIndex) {
+                       // Same column as last sort; toggle the direction
+                       direction = 1 - direction;
+               } else {
+                       // New column; do a descending sort
+                       this.propertyIndex = column;
+                       direction = DESCENDING;
+               }
+       }
+
+       /**
+        * Must be Overriden in each view.
+        */
+       public abstract int compare(Viewer viewer, Object e1, Object e2);
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java
new file mode 100644 (file)
index 0000000..26bdbe6
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Parent / children semantic to be used for simple UI Tree structure */
+public class TreeParent {
+       private String name;
+       private TreeParent parent;
+
+       private List<Object> children;
+
+       /** False until at least one child has been added, then true until cleared */
+       private boolean loaded = false;
+
+       public TreeParent(String name) {
+               this.name = name;
+               children = new ArrayList<Object>();
+       }
+
+       public synchronized void addChild(Object child) {
+               loaded = true;
+               children.add(child);
+               if (child instanceof TreeParent)
+                       ((TreeParent) child).setParent(this);
+       }
+
+       /**
+        * Remove this child. The child is disposed.
+        */
+       public synchronized void removeChild(Object child) {
+               children.remove(child);
+               if (child instanceof TreeParent) {
+                       ((TreeParent) child).dispose();
+               }
+       }
+
+       public synchronized void clearChildren() {
+               for (Object obj : children) {
+                       if (obj instanceof TreeParent)
+                               ((TreeParent) obj).dispose();
+               }
+               loaded = false;
+               children.clear();
+       }
+
+       /**
+        * If overridden, <code>super.dispose()</code> must be called, typically
+        * after custom cleaning.
+        */
+       public synchronized void dispose() {
+               clearChildren();
+               parent = null;
+               children = null;
+       }
+
+       public synchronized Object[] getChildren() {
+               return children.toArray(new Object[children.size()]);
+       }
+
+       @SuppressWarnings("unchecked")
+       public synchronized <T> List<T> getChildrenOfType(Class<T> clss) {
+               List<T> lst = new ArrayList<T>();
+               for (Object obj : children) {
+                       if (clss.isAssignableFrom(obj.getClass()))
+                               lst.add((T) obj);
+               }
+               return lst;
+       }
+
+       public synchronized boolean hasChildren() {
+               return children.size() > 0;
+       }
+
+       public Object getChildByName(String name) {
+               for (Object child : children) {
+                       if (child.toString().equals(name))
+                               return child;
+               }
+               return null;
+       }
+
+       public synchronized Boolean isLoaded() {
+               return loaded;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setParent(TreeParent parent) {
+               this.parent = parent;
+       }
+
+       public TreeParent getParent() {
+               return parent;
+       }
+
+       public String toString() {
+               return getName();
+       }
+
+       public int compareTo(TreeParent o) {
+               return name.compareTo(o.name);
+       }
+
+       @Override
+       public int hashCode() {
+               return name.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               return name.equals(obj.toString());
+       }
+
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java
new file mode 100644 (file)
index 0000000..b5b50b1
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.dialogs;
+
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Generic error dialog to be used in try/catch blocks
+ * 
+ * @deprecated use {@link org.argeo.eclipse.ui.ErrorFeedback} instead.
+ */
+public class Error extends org.argeo.eclipse.ui.ErrorFeedback {
+       public Error(Shell parentShell, String message, Throwable e) {
+               super(parentShell, message, e);
+       }
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java
new file mode 100644 (file)
index 0000000..5c27b06
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/** Dialog retrieve a single value. */
+public class SingleValue extends TitleAreaDialog {
+       private Text valueT;
+       private String value;
+       private final String title, message, label;
+       private final Boolean multiline;
+
+       public static String ask(String label, String message) {
+               SingleValue svd = new SingleValue(label, message);
+               if (svd.open() == Dialog.OK)
+                       return svd.getString();
+               else
+                       return null;
+       }
+
+       public static Long askLong(String label, String message) {
+               SingleValue svd = new SingleValue(label, message);
+               if (svd.open() == Dialog.OK)
+                       return svd.getLong();
+               else
+                       return null;
+       }
+
+       public static Double askDouble(String label, String message) {
+               SingleValue svd = new SingleValue(label, message);
+               if (svd.open() == Dialog.OK)
+                       return svd.getDouble();
+               else
+                       return null;
+       }
+
+       public SingleValue(String label, String message) {
+               this(Display.getDefault().getActiveShell(), label, message, label,
+                               false);
+       }
+
+       public SingleValue(Shell parentShell, String title, String message,
+                       String label, Boolean multiline) {
+               super(parentShell);
+               this.title = title;
+               this.message = message;
+               this.label = label;
+               this.multiline = multiline;
+       }
+
+       protected Point getInitialSize() {
+               return new Point(300, 250);
+       }
+
+       protected Control createDialogArea(Composite parent) {
+               Composite dialogarea = (Composite) super.createDialogArea(parent);
+               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               Composite composite = new Composite(dialogarea, SWT.NONE);
+               composite.setLayout(new GridLayout(2, false));
+               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+               valueT = createLT(composite, label);
+
+               setMessage(message, IMessageProvider.NONE);
+
+               parent.pack();
+               return composite;
+       }
+
+       @Override
+       protected void okPressed() {
+               value = valueT.getText();
+               super.okPressed();
+       }
+
+       /** Creates label and text. */
+       protected Text createLT(Composite parent, String label) {
+               new Label(parent, SWT.NONE).setText(label);
+               Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER
+                               | (multiline ? SWT.MULTI : SWT.NONE));
+               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               return text;
+       }
+
+       protected void configureShell(Shell shell) {
+               super.configureShell(shell);
+               shell.setText(title);
+       }
+
+       public String getString() {
+               return value;
+       }
+
+       public Long getLong() {
+               return Long.valueOf(getString());
+       }
+
+       public Double getDouble() {
+               return Double.valueOf(getString());
+       }
+}
diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java
new file mode 100644 (file)
index 0000000..eb0de93
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.utils;
+
+import java.util.ArrayList;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.ArgeoUiPlugin;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+
+/**
+ * Centralizes useful and generic methods concerning eclipse commands.
+ * 
+ */
+public class CommandUtils {
+
+       /**
+        * Factorizes command call that is quite verbose and always the same
+        * 
+        * NOTE that none of the parameter can be null
+        */
+       public static void CallCommandWithOneParameter(String commandId,
+                       String paramId, String paramValue) {
+               try {
+                       IWorkbench iw = ArgeoUiPlugin.getDefault().getWorkbench();
+
+                       IHandlerService handlerService = (IHandlerService) iw
+                                       .getService(IHandlerService.class);
+
+                       // get the command from plugin.xml
+                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
+                       ICommandService cmdService = (ICommandService) window
+                                       .getService(ICommandService.class);
+
+                       Command cmd = cmdService.getCommand(commandId);
+
+                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+
+                       // get the parameter
+                       IParameter iparam = cmd.getParameter(paramId);
+
+                       Parameterization params = new Parameterization(iparam, paramValue);
+                       parameters.add(params);
+
+                       // build the parameterized command
+                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
+                                       parameters.toArray(new Parameterization[parameters.size()]));
+
+                       // execute the command
+                       handlerService = (IHandlerService) window
+                                       .getService(IHandlerService.class);
+                       handlerService.executeCommand(pc, null);
+               } catch (Exception e) {
+                       throw new ArgeoException("Error while calling command of id :"
+                                       + commandId, e);
+               }
+       }
+}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.classpath b/eclipse/runtime/org.argeo.eclipse.ui/.classpath
deleted file mode 100644 (file)
index a507434..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-       <classpathentry kind="src" path="src/main/java"/>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>>
-       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-       <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.project b/eclipse/runtime/org.argeo.eclipse.ui/.project
deleted file mode 100644 (file)
index 53e9b32..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>org.argeo.eclipse.ui</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/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs b/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644 (file)
index f441c90..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#Thu Jul 29 10:54:11 CEST 2010
-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/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs b/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs
deleted file mode 100644 (file)
index 8e36e33..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#Thu Jul 29 11:00:39 CEST 2010
-eclipse.preferences.version=1
-resolve.requirebundle=false
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/build.properties b/eclipse/runtime/org.argeo.eclipse.ui/build.properties
deleted file mode 100644 (file)
index 5fc538b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-source.. = src/main/java/
-output.. = target/classes/
-bin.includes = META-INF/,\
-               .
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/pom.xml b/eclipse/runtime/org.argeo.eclipse.ui/pom.xml
deleted file mode 100644 (file)
index 1be829d..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><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.eclipse</groupId>
-               <version>1.1.4-SNAPSHOT</version>
-               <artifactId>runtime</artifactId>
-               <relativePath>..</relativePath>
-       </parent>
-       <artifactId>org.argeo.eclipse.ui</artifactId>
-       <name>Commons Eclipse UI</name>
-       <packaging>jar</packaging>
-       <build>
-               <plugins>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-compiler-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-source-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-jar-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.felix</groupId>
-                               <artifactId>maven-bundle-plugin</artifactId>
-
-                               <configuration>
-                                       <instructions>
-                                               <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
-                                               <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
-                                               <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
-                                               <Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
-                                               <Import-Package>
-                                                       org.springframework.beans.factory,
-                                                       org.springframework.core.io.support,
-                                                       !org.eclipse.core.runtime,
-                                                       !org.eclipse.core.commands,
-                                                       !org.eclipse.ui.plugin,
-                                                       *
-                                               </Import-Package>
-                                       </instructions>
-                               </configuration>
-                       </plugin>
-               </plugins>
-       </build>
-       <dependencies>
-               <!-- JCR -->
-               <dependency>
-                       <groupId>org.argeo.tp</groupId>
-                       <artifactId>javax.jcr</artifactId>
-               </dependency>
-
-               <!-- RCP only dependency, needed at compile time -->
-               <dependency>
-                       <groupId>org.argeo.commons.eclipse</groupId>
-                       <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
-                       <version>1.1.4-SNAPSHOT</version>
-                       <scope>provided</scope>
-               </dependency>
-
-               <!-- Commons -->
-               <dependency>
-                       <groupId>org.argeo.commons.basic</groupId>
-                       <artifactId>org.argeo.basic.nodeps</artifactId>
-                       <version>1.1.4-SNAPSHOT</version>
-               </dependency>
-
-               <!-- Spring -->
-               <dependency>
-                       <groupId>org.argeo.tp</groupId>
-                       <artifactId>org.springframework.context</artifactId>
-               </dependency>
-               <dependency>
-                       <groupId>org.argeo.tp</groupId>
-                       <artifactId>org.springframework.osgi.extender</artifactId>
-               </dependency>
-
-               <!-- Others -->
-               <dependency>
-                       <groupId>org.argeo.tp</groupId>
-                       <artifactId>slf4j.org.apache.commons.logging</artifactId>
-               </dependency>
-
-       </dependencies>
-</project>
\ No newline at end of file
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java
deleted file mode 100644 (file)
index fcd42ba..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.eclipse.spring;\r
-\r
-import static java.text.MessageFormat.format;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.BundleException;\r
-import org.osgi.framework.FrameworkUtil;\r
-import org.osgi.framework.InvalidSyntaxException;\r
-import org.osgi.util.tracker.ServiceTracker;\r
-import org.springframework.context.ApplicationContext;\r
-\r
-/**\r
- * Tracks Spring application context published as services.\r
- * \r
- * @author Heiko Seeberger\r
- * @author Mathieu Baudier\r
- */\r
-class ApplicationContextTracker {\r
-       private final static Log log = LogFactory\r
-                       .getLog(ApplicationContextTracker.class);\r
-\r
-       private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
-                       + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
-\r
-       public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout";\r
-\r
-       private static Long defaultTimeout = Long.parseLong(System.getProperty(\r
-                       APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000"));\r
-\r
-       private ServiceTracker applicationContextServiceTracker;\r
-\r
-       /**\r
-        * @param contributorBundle\r
-        *            OSGi bundle for which the Spring application context is to be\r
-        *            tracked. Must not be null!\r
-        * @param factoryBundleContext\r
-        *            BundleContext object which can be used to track services\r
-        * @throws IllegalArgumentException\r
-        *             if the given bundle is null.\r
-        */\r
-       public ApplicationContextTracker(final Bundle contributorBundle,\r
-                       final BundleContext factoryBundleContext) {\r
-               final String filter = format(FILTER,\r
-                               contributorBundle.getSymbolicName());\r
-               try {\r
-                       applicationContextServiceTracker = new ServiceTracker(\r
-                                       factoryBundleContext, FrameworkUtil.createFilter(filter),\r
-                                       null);\r
-                       // applicationContextServiceTracker.open();\r
-               } catch (final InvalidSyntaxException e) {\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
-\r
-       public void open() {\r
-               if (applicationContextServiceTracker != null) {\r
-                       applicationContextServiceTracker.open();\r
-               }\r
-       }\r
-\r
-       public void close() {\r
-               if (applicationContextServiceTracker != null) {\r
-                       applicationContextServiceTracker.close();\r
-               }\r
-       }\r
-\r
-       public ApplicationContext getApplicationContext() {\r
-               ApplicationContext applicationContext = null;\r
-               if (applicationContextServiceTracker != null) {\r
-                       try {\r
-                               applicationContext = (ApplicationContext) applicationContextServiceTracker\r
-                                               .waitForService(defaultTimeout);\r
-                       } catch (InterruptedException e) {\r
-                               e.printStackTrace();\r
-                       }\r
-               }\r
-               return applicationContext;\r
-       }\r
-\r
-       @Override\r
-       protected void finalize() throws Throwable {\r
-               close();\r
-               super.finalize();\r
-       }\r
-\r
-       static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
-               Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
-               return getApplicationContext(contributorBundle);\r
-       }\r
-\r
-       static ApplicationContext getApplicationContext(Bundle contributorBundle) {\r
-               if (log.isTraceEnabled())\r
-                       log.trace("Get application context for bundle " + contributorBundle);\r
-\r
-               if (contributorBundle.getState() != Bundle.ACTIVE\r
-                               && contributorBundle.getState() != Bundle.STARTING) {\r
-                       try {\r
-                               if (log.isTraceEnabled())\r
-                                       log.trace("Starting bundle: "\r
-                                                       + contributorBundle.getSymbolicName());\r
-                               contributorBundle.start();\r
-                       } catch (BundleException e) {\r
-                               e.printStackTrace();\r
-                       }\r
-               }\r
-\r
-               final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
-                               contributorBundle, contributorBundle.getBundleContext());\r
-               ApplicationContext applicationContext = null;\r
-               try {\r
-                       applicationContextTracker.open();\r
-                       applicationContext = applicationContextTracker\r
-                                       .getApplicationContext();\r
-               } finally {\r
-                       applicationContextTracker.close();\r
-               }\r
-               return applicationContext;\r
-       }\r
-}\r
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java
deleted file mode 100644 (file)
index dc045c9..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.spring;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.commands.IHandlerListener;
-import org.springframework.context.ApplicationContext;
-
-/** Allows to declare Eclipse commands as Spring beans */
-public class SpringCommandHandler implements IHandler {
-       private final static Log log = LogFactory
-                       .getLog(SpringCommandHandler.class);
-
-       public void addHandlerListener(IHandlerListener handlerListener) {
-       }
-
-       public void dispose() {
-       }
-
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               String commandId = event.getCommand().getId();
-               String bundleSymbolicName = commandId.substring(0,
-                               commandId.lastIndexOf('.'));
-               try {
-                       if (log.isTraceEnabled())
-                               log.trace("Execute " + event + " via spring command handler "
-                                               + this);
-                       // TODO: make it more flexible and robust
-                       ApplicationContext applicationContext = ApplicationContextTracker
-                                       .getApplicationContext(bundleSymbolicName);
-                       if (applicationContext == null)
-                               throw new ArgeoException("No application context found for "
-                                               + bundleSymbolicName);
-
-                       // retrieve the command via its id
-                       String beanName = event.getCommand().getId();
-
-                       if (!applicationContext.containsBean(beanName)) {
-                               if (beanName.startsWith(bundleSymbolicName))
-                                       beanName = beanName
-                                                       .substring(bundleSymbolicName.length() + 1);
-                       }
-
-                       if (!applicationContext.containsBean(beanName))
-                               throw new ExecutionException("No bean found with name "
-                                               + beanName + " in bundle " + bundleSymbolicName);
-                       Object bean = applicationContext.getBean(beanName);
-
-                       if (!(bean instanceof IHandler))
-                               throw new ExecutionException("Bean with name " + beanName
-                                               + " and class " + bean.getClass()
-                                               + " does not implement the IHandler interface.");
-
-                       IHandler handler = (IHandler) bean;
-                       return handler.execute(event);
-               } catch (Exception e) {
-                       // TODO: use eclipse error management
-                       // log.error(e);
-                       throw new ExecutionException("Cannot execute Spring command "
-                                       + commandId + " in bundle " + bundleSymbolicName, e);
-               }
-       }
-
-       public boolean isEnabled() {
-               return true;
-       }
-
-       public boolean isHandled() {
-               return true;
-       }
-
-       public void removeHandlerListener(IHandlerListener handlerListener) {
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java
deleted file mode 100644 (file)
index d8ec9d7..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.eclipse.spring;\r
-\r
-import org.argeo.ArgeoException;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.core.runtime.IExecutableExtension;\r
-import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
-import org.eclipse.core.runtime.IExtension;\r
-import org.springframework.context.ApplicationContext;\r
-\r
-/**\r
- * The Spring Extension Factory builds a bridge between the Eclipse Extension\r
- * Registry and the Spring Framework (especially Spring Dynamic Modules).\r
- * \r
- * It allows you to define your extension as a spring bean within the spring\r
- * application context of your bundle. If you would like to use this bean as an\r
- * instance of an extension (an Eclipse RCP view, for example) you define the\r
- * extension with this spring extension factory as the class to be created.\r
- * \r
- * To let the spring extension factory pick the right bean from your application\r
- * context you need to set the bean id to the same value as the id of the view\r
- * within the view definition, for example. This is important if your extension\r
- * definition contains more than one element, where each element has its own id.\r
- * \r
- * If the extension definition elements themselves have no id attribute the\r
- * spring extension factory uses the id of the extension itself to identify the\r
- * bean.\r
- * \r
- * original code from: <a href=\r
- * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
- * >Blog entry</a>\r
- * \r
- * @author Martin Lippert\r
- * @author mbaudier\r
- */\r
-public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
-               IExecutableExtension {\r
-\r
-       private Object bean;\r
-\r
-       public Object create() throws CoreException {\r
-               if (bean == null)\r
-                       throw new ArgeoException("No underlying bean for extension");\r
-               return bean;\r
-       }\r
-\r
-       public void setInitializationData(IConfigurationElement config,\r
-                       String propertyName, Object data) throws CoreException {\r
-               String bundleSymbolicName = config.getContributor().getName();\r
-               ApplicationContext applicationContext = ApplicationContextTracker\r
-                               .getApplicationContext(bundleSymbolicName);\r
-               if (applicationContext == null)\r
-                       throw new ArgeoException(\r
-                                       "Cannot find application context for bundle "\r
-                                                       + bundleSymbolicName);\r
-\r
-               String beanName = getBeanName(data, config);\r
-               if (beanName == null)\r
-                       throw new ArgeoException("Cannot find bean name for extension "\r
-                                       + config);\r
-\r
-               if (!applicationContext.containsBean(beanName)) {\r
-                       if (beanName.startsWith(bundleSymbolicName))\r
-                               beanName = beanName.substring(bundleSymbolicName.length() + 1);\r
-               }\r
-\r
-               if (!applicationContext.containsBean(beanName))\r
-                       throw new ArgeoException("No bean with name '" + beanName + "'");\r
-\r
-               this.bean = applicationContext.getBean(beanName);\r
-               if (this.bean instanceof IExecutableExtension) {\r
-                       ((IExecutableExtension) this.bean).setInitializationData(config,\r
-                                       propertyName, data);\r
-               }\r
-       }\r
-\r
-       private String getBeanName(Object data, IConfigurationElement config) {\r
-\r
-               // try the specific bean id the extension defines\r
-               if (data != null && data.toString().length() > 0) {\r
-                       return data.toString();\r
-               }\r
-\r
-               // try the id of the config element\r
-               if (config.getAttribute("id") != null) {\r
-                       return config.getAttribute("id");\r
-               }\r
-\r
-               // try the id of the extension element itself\r
-               if (config.getParent() != null\r
-                               && config.getParent() instanceof IExtension) {\r
-                       IExtension extensionDefinition = (IExtension) config.getParent();\r
-                       return extensionDefinition.getSimpleIdentifier();\r
-               }\r
-\r
-               return null;\r
-       }\r
-\r
-}\r
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java
deleted file mode 100644 (file)
index a89fbcc..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Tree content provider dealing with tree objects and providing reasonable
- * defaults.
- */
-public abstract class AbstractTreeContentProvider implements
-               ITreeContentProvider {
-
-       /** Does nothing */
-       public void dispose() {
-       }
-
-       /** Does nothing */
-       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-       }
-
-       public Object[] getChildren(Object element) {
-               if (element instanceof TreeParent) {
-                       return ((TreeParent) element).getChildren();
-               }
-               return new Object[0];
-       }
-
-       public Object getParent(Object element) {
-               if (element instanceof TreeParent) {
-                       return ((TreeParent) element).getParent();
-               }
-               return null;
-       }
-
-       public boolean hasChildren(Object element) {
-               if (element instanceof TreeParent) {
-                       return ((TreeParent) element).hasChildren();
-               }
-               return false;
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java
deleted file mode 100644 (file)
index d34deb0..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.core.runtime.ILogListener;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener {
-       public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
-       private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class);
-       // The shared instance
-       private static ArgeoUiPlugin plugin;
-
-       public void start(BundleContext context) throws Exception {
-               super.start(context);
-               // weirdly, the start method is called twice...
-               if (plugin == null) {
-                       plugin = this;
-                       Platform.addLogListener(this);
-                       log.debug("Eclipse logging now directed to standard logging");
-               }
-       }
-
-       public void stop(BundleContext context) throws Exception {
-               try {
-                       // weirdly, the stop method is called twice...
-                       if (plugin != null) {
-                               Platform.removeLogListener(this);
-                               log.debug("Eclipse logging not directed anymore to standard logging");
-                               plugin = null;
-                       }
-               } finally {
-                       super.stop(context);
-               }
-       }
-
-       /** Returns the shared instance */
-       public static ArgeoUiPlugin getDefault() {
-               return plugin;
-       }
-
-       public void logging(IStatus status, String plugin) {
-               Log pluginLog = LogFactory.getLog(plugin);
-               Integer severity = status.getSeverity();
-               if (severity == IStatus.ERROR)
-                       pluginLog.error(status.getMessage(), status.getException());
-               else if (severity == IStatus.WARNING)
-                       pluginLog.warn(status.getMessage(), status.getException());
-               else if (severity == IStatus.INFO)
-                       pluginLog.info(status.getMessage(), status.getException());
-               else if (severity == IStatus.CANCEL)
-                       if (pluginLog.isDebugEnabled())
-                               pluginLog.debug(status.getMessage(), status.getException());
-
-       }
-
-}
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
deleted file mode 100644 (file)
index 64edf72..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java
deleted file mode 100644 (file)
index 03d0c38..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-/** Utilities to simplify UI development. */
-public class EclipseUiUtils {
-       /**
-        * Create a label and a text field for a grid layout, the text field grabing
-        * excess horizontal
-        * 
-        * @param parent
-        *            the parent composite
-        * @param label
-        *            the lable to display
-        * @param modifyListener
-        *            a {@link ModifyListener} to listen on events on the text, can
-        *            be null
-        * @return the created text
-        * 
-        * @deprecated use {@link #createGridLT(Composite, String)} instead
-        */
-       @Deprecated
-       public static Text createGridLT(Composite parent, String label,
-                       ModifyListener modifyListener) {
-               Label lbl = new Label(parent, SWT.LEAD);
-               lbl.setText(label);
-               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
-               txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               if (modifyListener != null)
-                       txt.addModifyListener(modifyListener);
-               return txt;
-       }
-
-       public static Text createGridLT(Composite parent, String label) {
-               return createGridLT(parent, label, null);
-       }
-
-       /**
-        * Creates one label and a text field not editable with background color of
-        * the parent (like a label but with selectable text)
-        */
-       public static Text createGridLL(Composite parent, String label, String text) {
-               Text txt = createGridLT(parent, label);
-               txt.setText(text);
-               txt.setEditable(false);
-               txt.setBackground(parent.getBackground());
-               return txt;
-       }
-
-       public static Text createGridLP(Composite parent, String label,
-                       ModifyListener modifyListener) {
-               Label lbl = new Label(parent, SWT.LEAD);
-               lbl.setText(label);
-               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
-               txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               if (txt != null)
-                       txt.addModifyListener(modifyListener);
-               return txt;
-       }
-
-       public static Font getItalicFont(Composite parent) {
-               return JFaceResources.getFontRegistry().defaultFontDescriptor()
-                               .setStyle(SWT.ITALIC).createFont(parent.getDisplay());
-       }
-
-       public static Font getBoldFont(Composite parent) {
-               return JFaceResources.getFontRegistry().defaultFontDescriptor()
-                               .setStyle(SWT.BOLD).createFont(parent.getDisplay());
-       }
-
-       public static Font getBoldItalicFont(Composite parent) {
-               return JFaceResources.getFontRegistry().defaultFontDescriptor()
-                               .setStyle(SWT.BOLD | SWT.ITALIC)
-                               .createFont(parent.getDisplay());
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java
deleted file mode 100644 (file)
index d35c699..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * @deprecated deprecated because of poor naming, use {@link ErrorFeedback}
- *             instead
- */
-@Deprecated
-public class Error extends ErrorFeedback {
-
-       public Error(Shell parentShell, String message, Throwable e) {
-               super(parentShell, message, e);
-               // TODO Auto-generated constructor stub
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java
deleted file mode 100644 (file)
index 618d708..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-
-/** Generic error dialog to be used in try/catch blocks */
-public class ErrorFeedback extends TitleAreaDialog {
-       private final static Log log = LogFactory.getLog(ErrorFeedback.class);
-
-       private final String message;
-       private final Throwable exception;
-
-       public static void show(String message, Throwable e) {
-               // rethrow ThreaDeath in order to make sure that RAP will properly clean
-               // up the UI thread
-               if (e instanceof ThreadDeath)
-                       throw (ThreadDeath) e;
-               
-               new ErrorFeedback(getDisplay().getActiveShell(), message, e).open();
-       }
-
-       public static void show(String message) {
-               new ErrorFeedback(getDisplay().getActiveShell(), message, null).open();
-       }
-
-       /** Tries to find a display */
-       private static Display getDisplay() {
-               try {
-                       Display display = PlatformUI.getWorkbench().getDisplay();
-                       if (display != null)
-                               return display;
-                       else
-                               return Display.getDefault();
-               } catch (Exception e) {
-                       return Display.getCurrent();
-               }
-       }
-
-       public ErrorFeedback(Shell parentShell, String message, Throwable e) {
-               super(parentShell);
-               this.message = message;
-               this.exception = e;
-               log.error(message, e);
-       }
-
-       protected Point getInitialSize() {
-               if (exception != null)
-                       return new Point(800, 600);
-               else
-                       return new Point(400, 300);
-       }
-
-       @Override
-       protected Control createDialogArea(Composite parent) {
-               Composite dialogarea = (Composite) super.createDialogArea(parent);
-               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               Composite composite = new Composite(dialogarea, SWT.NONE);
-               composite.setLayout(new GridLayout(2, false));
-               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
-               setMessage(message != null ? message
-                               + (exception != null ? ": " + exception.getMessage() : "")
-                               : exception != null ? exception.getMessage() : "Unkown Error",
-                               IMessageProvider.ERROR);
-
-               if (exception != null) {
-                       Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER
-                                       | SWT.V_SCROLL | SWT.H_SCROLL);
-                       stack.setEditable(false);
-                       stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-                       StringWriter sw = new StringWriter();
-                       exception.printStackTrace(new PrintWriter(sw));
-                       stack.setText(sw.toString());
-               }
-
-               parent.pack();
-               return composite;
-       }
-
-       protected void configureShell(Shell shell) {
-               super.configureShell(shell);
-               shell.setText("Error");
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java
deleted file mode 100644 (file)
index fabeb5d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-
-public abstract class GenericTableComparator extends ViewerComparator {
-
-       protected int propertyIndex;
-       public static final int ASCENDING = 0, DESCENDING = 1;
-       protected int direction = DESCENDING;
-
-       /**
-        * Creates an instance of a sorter for TableViewer.
-        * 
-        * @param defaultColumn
-        *            the default sorter column
-        */
-
-       public GenericTableComparator(int defaultColumnIndex, int direction) {
-               propertyIndex = defaultColumnIndex;
-               this.direction = direction;
-       }
-
-       public void setColumn(int column) {
-               if (column == this.propertyIndex) {
-                       // Same column as last sort; toggle the direction
-                       direction = 1 - direction;
-               } else {
-                       // New column; do a descending sort
-                       this.propertyIndex = column;
-                       direction = DESCENDING;
-               }
-       }
-
-       /**
-        * Must be Overriden in each view.
-        */
-       public abstract int compare(Viewer viewer, Object e1, Object e2);
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java
deleted file mode 100644 (file)
index 26bdbe6..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/** Parent / children semantic to be used for simple UI Tree structure */
-public class TreeParent {
-       private String name;
-       private TreeParent parent;
-
-       private List<Object> children;
-
-       /** False until at least one child has been added, then true until cleared */
-       private boolean loaded = false;
-
-       public TreeParent(String name) {
-               this.name = name;
-               children = new ArrayList<Object>();
-       }
-
-       public synchronized void addChild(Object child) {
-               loaded = true;
-               children.add(child);
-               if (child instanceof TreeParent)
-                       ((TreeParent) child).setParent(this);
-       }
-
-       /**
-        * Remove this child. The child is disposed.
-        */
-       public synchronized void removeChild(Object child) {
-               children.remove(child);
-               if (child instanceof TreeParent) {
-                       ((TreeParent) child).dispose();
-               }
-       }
-
-       public synchronized void clearChildren() {
-               for (Object obj : children) {
-                       if (obj instanceof TreeParent)
-                               ((TreeParent) obj).dispose();
-               }
-               loaded = false;
-               children.clear();
-       }
-
-       /**
-        * If overridden, <code>super.dispose()</code> must be called, typically
-        * after custom cleaning.
-        */
-       public synchronized void dispose() {
-               clearChildren();
-               parent = null;
-               children = null;
-       }
-
-       public synchronized Object[] getChildren() {
-               return children.toArray(new Object[children.size()]);
-       }
-
-       @SuppressWarnings("unchecked")
-       public synchronized <T> List<T> getChildrenOfType(Class<T> clss) {
-               List<T> lst = new ArrayList<T>();
-               for (Object obj : children) {
-                       if (clss.isAssignableFrom(obj.getClass()))
-                               lst.add((T) obj);
-               }
-               return lst;
-       }
-
-       public synchronized boolean hasChildren() {
-               return children.size() > 0;
-       }
-
-       public Object getChildByName(String name) {
-               for (Object child : children) {
-                       if (child.toString().equals(name))
-                               return child;
-               }
-               return null;
-       }
-
-       public synchronized Boolean isLoaded() {
-               return loaded;
-       }
-
-       public String getName() {
-               return name;
-       }
-
-       public void setParent(TreeParent parent) {
-               this.parent = parent;
-       }
-
-       public TreeParent getParent() {
-               return parent;
-       }
-
-       public String toString() {
-               return getName();
-       }
-
-       public int compareTo(TreeParent o) {
-               return name.compareTo(o.name);
-       }
-
-       @Override
-       public int hashCode() {
-               return name.hashCode();
-       }
-
-       @Override
-       public boolean equals(Object obj) {
-               return name.equals(obj.toString());
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java
deleted file mode 100644 (file)
index b5b50b1..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.dialogs;
-
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * Generic error dialog to be used in try/catch blocks
- * 
- * @deprecated use {@link org.argeo.eclipse.ui.ErrorFeedback} instead.
- */
-public class Error extends org.argeo.eclipse.ui.ErrorFeedback {
-       public Error(Shell parentShell, String message, Throwable e) {
-               super(parentShell, message, e);
-       }
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java
deleted file mode 100644 (file)
index 5c27b06..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.dialogs;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-/** Dialog retrieve a single value. */
-public class SingleValue extends TitleAreaDialog {
-       private Text valueT;
-       private String value;
-       private final String title, message, label;
-       private final Boolean multiline;
-
-       public static String ask(String label, String message) {
-               SingleValue svd = new SingleValue(label, message);
-               if (svd.open() == Dialog.OK)
-                       return svd.getString();
-               else
-                       return null;
-       }
-
-       public static Long askLong(String label, String message) {
-               SingleValue svd = new SingleValue(label, message);
-               if (svd.open() == Dialog.OK)
-                       return svd.getLong();
-               else
-                       return null;
-       }
-
-       public static Double askDouble(String label, String message) {
-               SingleValue svd = new SingleValue(label, message);
-               if (svd.open() == Dialog.OK)
-                       return svd.getDouble();
-               else
-                       return null;
-       }
-
-       public SingleValue(String label, String message) {
-               this(Display.getDefault().getActiveShell(), label, message, label,
-                               false);
-       }
-
-       public SingleValue(Shell parentShell, String title, String message,
-                       String label, Boolean multiline) {
-               super(parentShell);
-               this.title = title;
-               this.message = message;
-               this.label = label;
-               this.multiline = multiline;
-       }
-
-       protected Point getInitialSize() {
-               return new Point(300, 250);
-       }
-
-       protected Control createDialogArea(Composite parent) {
-               Composite dialogarea = (Composite) super.createDialogArea(parent);
-               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               Composite composite = new Composite(dialogarea, SWT.NONE);
-               composite.setLayout(new GridLayout(2, false));
-               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               valueT = createLT(composite, label);
-
-               setMessage(message, IMessageProvider.NONE);
-
-               parent.pack();
-               return composite;
-       }
-
-       @Override
-       protected void okPressed() {
-               value = valueT.getText();
-               super.okPressed();
-       }
-
-       /** Creates label and text. */
-       protected Text createLT(Composite parent, String label) {
-               new Label(parent, SWT.NONE).setText(label);
-               Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER
-                               | (multiline ? SWT.MULTI : SWT.NONE));
-               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               return text;
-       }
-
-       protected void configureShell(Shell shell) {
-               super.configureShell(shell);
-               shell.setText(title);
-       }
-
-       public String getString() {
-               return value;
-       }
-
-       public Long getLong() {
-               return Long.valueOf(getString());
-       }
-
-       public Double getDouble() {
-               return Double.valueOf(getString());
-       }
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java
deleted file mode 100644 (file)
index eb0de93..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.utils;
-
-import java.util.ArrayList;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ArgeoUiPlugin;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.IParameter;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
-
-/**
- * Centralizes useful and generic methods concerning eclipse commands.
- * 
- */
-public class CommandUtils {
-
-       /**
-        * Factorizes command call that is quite verbose and always the same
-        * 
-        * NOTE that none of the parameter can be null
-        */
-       public static void CallCommandWithOneParameter(String commandId,
-                       String paramId, String paramValue) {
-               try {
-                       IWorkbench iw = ArgeoUiPlugin.getDefault().getWorkbench();
-
-                       IHandlerService handlerService = (IHandlerService) iw
-                                       .getService(IHandlerService.class);
-
-                       // get the command from plugin.xml
-                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
-                       ICommandService cmdService = (ICommandService) window
-                                       .getService(ICommandService.class);
-
-                       Command cmd = cmdService.getCommand(commandId);
-
-                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
-
-                       // get the parameter
-                       IParameter iparam = cmd.getParameter(paramId);
-
-                       Parameterization params = new Parameterization(iparam, paramValue);
-                       parameters.add(params);
-
-                       // build the parameterized command
-                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
-                                       parameters.toArray(new Parameterization[parameters.size()]));
-
-                       // execute the command
-                       handlerService = (IHandlerService) window
-                                       .getService(IHandlerService.class);
-                       handlerService.executeCommand(pc, null);
-               } catch (Exception e) {
-                       throw new ArgeoException("Error while calling command of id :"
-                                       + commandId, e);
-               }
-       }
-}