-# BND instructions
-#-----------------------------------------------------------------------
-#Tue Nov 25 13:15:11 CET 2014
-pom.id=org.argeo.commons\:org.argeo.cms\:jar\:2.1.12-SNAPSHOT
-env.DESKTOP_SESSION=gnome
-env.OLDPWD=/home/mbaudier/dev/src/commons
-file.encoding.pkg=sun.io
-java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre
-env.GDM_LANG=en_GB.utf8
-env.DISPLAY=\:0.0
-env.LS_COLORS=rs\=0\:di\=01;34\:ln\=01;36\:mh\=00\:pi\=40;33\:so\=01;35\:do\=01;35\:bd\=40;33;01\:cd\=40;33;01\:or\=40;31;01\:mi\=01;05;37;41\:su\=37;41\:sg\=30;43\:ca\=30;41\:tw\=30;42\:ow\=34;42\:st\=37;44\:ex\=01;32\:*.tar\=01;31\:*.tgz\=01;31\:*.arj\=01;31\:*.taz\=01;31\:*.lzh\=01;31\:*.lzma\=01;31\:*.tlz\=01;31\:*.txz\=01;31\:*.zip\=01;31\:*.z\=01;31\:*.Z\=01;31\:*.dz\=01;31\:*.gz\=01;31\:*.lz\=01;31\:*.xz\=01;31\:*.bz2\=01;31\:*.tbz\=01;31\:*.tbz2\=01;31\:*.bz\=01;31\:*.tz\=01;31\:*.deb\=01;31\:*.rpm\=01;31\:*.jar\=01;31\:*.rar\=01;31\:*.ace\=01;31\:*.zoo\=01;31\:*.cpio\=01;31\:*.7z\=01;31\:*.rz\=01;31\:*.jpg\=01;35\:*.jpeg\=01;35\:*.gif\=01;35\:*.bmp\=01;35\:*.pbm\=01;35\:*.pgm\=01;35\:*.ppm\=01;35\:*.tga\=01;35\:*.xbm\=01;35\:*.xpm\=01;35\:*.tif\=01;35\:*.tiff\=01;35\:*.png\=01;35\:*.svg\=01;35\:*.svgz\=01;35\:*.mng\=01;35\:*.pcx\=01;35\:*.mov\=01;35\:*.mpg\=01;35\:*.mpeg\=01;35\:*.m2v\=01;35\:*.mkv\=01;35\:*.ogm\=01;35\:*.mp4\=01;35\:*.m4v\=01;35\:*.mp4v\=01;35\:*.vob\=01;35\:*.qt\=01;35\:*.nuv\=01;35\:*.wmv\=01;35\:*.asf\=01;35\:*.rm\=01;35\:*.rmvb\=01;35\:*.flc\=01;35\:*.avi\=01;35\:*.fli\=01;35\:*.flv\=01;35\:*.gl\=01;35\:*.dl\=01;35\:*.xcf\=01;35\:*.xwd\=01;35\:*.yuv\=01;35\:*.cgm\=01;35\:*.emf\=01;35\:*.axv\=01;35\:*.anx\=01;35\:*.ogv\=01;35\:*.ogx\=01;35\:*.aac\=01;36\:*.au\=01;36\:*.flac\=01;36\:*.mid\=01;36\:*.midi\=01;36\:*.mka\=01;36\:*.mp3\=01;36\:*.mpc\=01;36\:*.ogg\=01;36\:*.ra\=01;36\:*.wav\=01;36\:*.axa\=01;36\:*.oga\=01;36\:*.spx\=01;36\:*.xspf\=01;36\:
-pom.contributors=
-project.build.developers=
-classworlds.conf=/opt/apache-maven/bin/m2.conf
-env.XDG_SESSION_COOKIE=9bf883dac7be1df0f982e1dd0000003a-1416578122.683229-877522490
-pom.pomFile=/home/mbaudier/dev/src/commons/org.argeo.cms/pom.xml
-java.endorsed.dirs=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/endorsed
-project.build.groupId=org.argeo.commons
-env.LOGNAME=mbaudier
-env.USERNAME=mbaudier
-project.build.scm=org.apache.maven.model.Scm@2d98cc8d
-env.SESSION_MANAGER=local/unix\:@/tmp/.ICE-unix/17546,unix/unix\:/tmp/.ICE-unix/17546
-env.KDEDIRS=/usr
-sun.os.patch.level=unknown
-java.vendor.url=http\://java.oracle.com/
-pom.profiles=
-env.G_BROKEN_FILENAMES=1
-maven-symbolicname=org.argeo.commons.org.argeo.cms
-java.version=1.7.0_71
-env.ORBIT_SOCKETDIR=/tmp/orbit-mbaudier
-project.build.contributors=
-version.argeo-commons=2.1.12-SNAPSHOT
-java.vendor.url.bug=http\://bugreport.sun.com/bugreport/
-user.name=mbaudier
-env.LANG=en_GB.utf8
-env.CVS_RSH=ssh
-project.build.pomFile=/home/mbaudier/dev/src/commons/org.argeo.cms/pom.xml
-sun.io.unicode.encoding=UnicodeLittle
-sun.jnu.encoding=UTF-8
-env.DBUS_SESSION_BUS_ADDRESS=unix\:abstract\=/tmp/dbus-OazDk3vN1t,guid\=230af52c9acfa834ca05b3b0000059f6
-java.runtime.name=OpenJDK Runtime Environment
-project.build.outputdirectory=/home/mbaudier/dev/src/commons/org.argeo.cms/target/classes
-env.SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
-rpm.release=6
-project.version=2.1.12-SNAPSHOT
-java.specification.name=Java Platform API Specification
-user.timezone=
-env.LESSOPEN=||/usr/bin/lesspipe.sh %s
-pom.mailingLists=
-path.separator=\:
-project.contributors=
-project.inceptionYear=2007
-pom.artifactId=org.argeo.cms
-env.MAVEN_CMD_LINE_ARGS=-o clean install
-project.name=Argeo Content Management System
-env.XMODIFIERS=@im\=none
-file.encoding=UTF-8
-env.HOME=/home/mbaudier
-sun.java.command=org.codehaus.plexus.classworlds.launcher.Launcher -o clean install
-env.GTK_RC_FILES=/etc/gtk/gtkrc\:/home/mbaudier/.gtkrc-1.2-gnome2
-project.id=org.argeo.commons\:org.argeo.cms\:jar\:2.1.12-SNAPSHOT
-env.HOSTNAME=mostar
-Export-Package=org.argeo.cms;org.argeo.cms.text;org.argeo.cms.viewers;org.argeo.cms.widgets;-split-package\:\=merge-first
-Bundle-License=http\://www.apache.org/licenses/LICENSE-2.0.txt
-java.io.tmpdir=/tmp
-project.build.mailingLists=
-env.GNOME_KEYRING_PID=17536
-user.language=en
-Include-Resource=org/argeo/cms/cms.cnd\=src/org/argeo/cms/cms.cnd,org/argeo/cms/CmsMsg_fr.properties\=src/org/argeo/cms/CmsMsg_fr.properties,META-INF/spring/osgi.xml\=META-INF/spring/osgi.xml,META-INF/spring/backend.xml\=META-INF/spring/backend.xml,icons/noPic-goldenRatio-640px.png\=icons/noPic-goldenRatio-640px.png,icons/noPic-square-640px.png\=icons/noPic-square-640px.png,icons/loading.gif\=icons/loading.gif
-env.HISTCONTROL=ignoredups
-line.separator=\n
-project.build.directory=/home/mbaudier/dev/src/commons/org.argeo.cms/target
-env.HISTSIZE=1000
-java.vm.info=mixed mode
-developmentCycle.argeo-commons.startDate=2012-12-19
-sun.desktop=gnome
-java.vm.specification.name=Java Virtual Machine Specification
-project.modelEncoding=UTF-8
-env.COLORTERM=gnome-terminal
-project.build.id=org.argeo.commons\:org.argeo.cms\:jar\:2.1.12-SNAPSHOT
-project.build.licenses=org.apache.maven.model.License@a9d545e
-version.rap.addons=0.5.0.argeo.20141029
-pom.modelVersion=4.0.0
-project.licenses=org.apache.maven.model.License@a9d545e
-env.GDMSESSION=gnome
-project.developers=
-java.awt.printerjob=sun.print.PSPrinterJob
--removeheaders=Bnd-LastModified,Build-Jdk,Built-By,Tool,Created-By
-pom.version=2.1.12-SNAPSHOT
-env.WINDOWID=73400323
-pom.scm=org.apache.maven.model.Scm@2d98cc8d
--plugin=org.apache.felix.bundleplugin.BlueprintPlugin,aQute.lib.spring.SpringXMLType
-project.mailingLists=
-pom.packaging=jar
-project.build.parent=org.argeo.commons\:argeo-commons\:pom\:2.1.12-SNAPSHOT
-project.projectDirectory=/home/mbaudier/dev/src/commons/org.argeo.cms
-os.name=Linux
-project.build.modelVersion=4.0.0
-java.specification.vendor=Oracle Corporation
-env.TERM=xterm
-java.vm.name=OpenJDK 64-Bit Server VM
-env.QT_IM_MODULE=xim
-java.library.path=/usr/java/packages/lib/amd64\:/usr/lib64\:/lib64\:/lib\:/usr/lib
-project.build.build=org.apache.maven.model.Build@5f0decc3
-env.PATH=/usr/lib64/qt-3.3/bin\:/usr/local/bin\:/usr/bin\:/bin\:/usr/local/sbin\:/usr/sbin\:/sbin\:/home/mbaudier/bin
-pom.build=org.apache.maven.model.Build@5f0decc3
-java.class.version=51.0
-env.SHLVL=2
-project.build.version=2.1.12-SNAPSHOT
-env.GNOME_KEYRING_SOCKET=/tmp/keyring-YLbPHE/socket
-pom.parent=org.argeo.commons\:argeo-commons\:pom\:2.1.12-SNAPSHOT
-pom.projectDirectory=/home/mbaudier/dev/src/commons/org.argeo.cms
-project.modelVersion=4.0.0
-rpm.stagingRepository=/srv/rpmfactory/argeo-osgi-2-staging/6/x86_64
-Bundle-SymbolicName=org.argeo.cms
-sun.boot.library.path=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/amd64
-project.build.sourceEncoding=UTF-8
-Private-Package=org.argeo.cam.internal.*
-project.build.artifactId=org.argeo.cms
-sun.management.compiler=HotSpot 64-Bit Tiered Compilers
-java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
-pom.name=Argeo Content Management System
-env.USER=mbaudier
-pom.developers=
-project.build=org.apache.maven.model.Build@5f0decc3
-project.scm=org.apache.maven.model.Scm@2d98cc8d
-project.baseDir=/home/mbaudier/dev/src/commons/org.argeo.cms
-project.build.name=Argeo Content Management System
-java.vm.specification.version=1.7
-env.KDE_IS_PRELINKED=1
-project.build.inceptionYear=2007
-env.GDM_KEYBOARD_LAYOUT=de
-project.groupId=org.argeo.commons
-Bundle-Version=2.1.12-SNAPSHOT-r${tstamp}
-env.NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat
-awt.toolkit=sun.awt.X11.XToolkit
-project.build.profiles=
-sun.cpu.isalist=
-developmentCycle.argeo-commons=2.1
-project.profiles=
-java.ext.dirs=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/ext\:/usr/java/packages/lib/ext
-Import-Package=org.springframework.core,org.eclipse.core.commands,org.eclipse.swt,javax.jcr.security,*
-os.version=2.6.32-504.1.3.el6.x86_64
-user.home=/home/mbaudier
-java.vm.vendor=Oracle Corporation
-env.JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64
-SLC-Category=org.argeo.commons
-env.XAUTHORITY=/var/run/gdm/auth-for-mbaudier-7t5RHJ/database
-user.dir=/home/mbaudier/dev/src/commons
-env.XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt
-env.WINDOWPATH=1
-env.MAIL=/var/spool/mail/mbaudier
-project.build.modelEncoding=UTF-8
-env.PWD=/home/mbaudier/dev/src/commons
-project.parent=org.argeo.commons\:argeo-commons\:pom\:2.1.12-SNAPSHOT
-sun.cpu.endian=little
-env.QTLIB=/usr/lib64/qt-3.3/lib
-pom.licenses=org.apache.maven.model.License@a9d545e
-project.dir=/home/mbaudier/dev/src/commons/org.argeo.cms
-classifier=
-version.argeo-distribution=1.4.0
-java.vm.version=24.65-b04
-java.class.path=/opt/apache-maven/boot/plexus-classworlds-2.5.1.jar
-env.QTDIR=/usr/lib64/qt-3.3
-os.arch=amd64
-maven.build.version=Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T22\:58\:10+02\:00)
-project.build.projectDirectory=/home/mbaudier/dev/src/commons/org.argeo.cms
-version.rap=2.2.0-R-20131204-0942
-sun.java.launcher=SUN_STANDARD
-pom.inceptionYear=2007
-env.IMSETTINGS_INTEGRATE_DESKTOP=yes
-project.packaging=jar
-java.vm.specification.vendor=Oracle Corporation
-file.separator=/
-java.runtime.version=1.7.0_71-mockbuild_2014_10_17_22_23-b00
-project.pomFile=/home/mbaudier/dev/src/commons/org.argeo.cms/pom.xml
-env.SSH_AUTH_SOCK=/tmp/keyring-YLbPHE/socket.ssh
-sun.boot.class.path=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/resources.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/rt.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/sunrsasign.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/jsse.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/jce.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/charsets.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/rhino.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/lib/jfr.jar\:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre/classes
-project.build.packaging=jar
-maven.version=3.2.3
-project.artifactId=org.argeo.cms
-env.QTINC=/usr/lib64/qt-3.3/include
-user.country=GB
-pom.modelEncoding=UTF-8
-maven.home=/opt/apache-maven
-env.SHELL=/bin/bash
-Bundle-RequiredExecutionEnvironment=JavaSE-1.6
--sourcepath=/home/mbaudier/dev/src/commons/org.argeo.cms/src,/home/mbaudier/dev/src/commons/org.argeo.cms/target/classes
-pom.groupId=org.argeo.commons
-java.vendor=Oracle Corporation
-env.GPG_AGENT_INFO=/tmp/seahorse-CQZHIM/S.gpg-agent\:17621\:1;
-env.IMSETTINGS_MODULE=none
-Bundle-Name=Argeo Content Management System
-java.specification.version=1.7
-env.GNOME_DESKTOP_SESSION_ID=this-is-deprecated
-sun.arch.data.model=64
-#-----------------------------------------------------------------------
+Import-Package: org.springframework.core,\
+ org.eclipse.core.commands,\
+ org.eclipse.swt,\
+ javax.jcr.security,\
+ *
+# Useless
+#Private-Package: org.argeo.cms.internal.*
\ No newline at end of file
-Bundle-ActivationPolicy: lazy
-Bundle-Activator: org.argeo.eclipse.ui.ArgeoUiPlugin
Require-Bundle: org.eclipse.rap.ui,org.eclipse.core.runtime
Import-Package: org.apache.commons.io,\
org.argeo,\
org.eclipse.rap.ui.workbench;resolution:=optional
Import-Package: org.argeo.eclipse.ui.specific,\
- org.argeo.eclipse.spring,\
org.eclipse.swt.widgets;version="[0,1)",\
org.osgi.framework;version="[1.5,2)",\
org.osgi.service.packageadmin,\
+ org.osgi.util.tracker;version="[1.4,2)",\
org.springframework.beans.factory,\
org.springframework.core.io.support,\
*
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\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(\r
+ final Bundle contributorBundle) {\r
+ if (log.isTraceEnabled())\r
+ log.trace("Get application context for bundle " + contributorBundle);\r
+\r
+ // Start if not yet started (also if in STARTING state, may be lazy)\r
+ if (contributorBundle.getState() != Bundle.ACTIVE) {\r
+ if (log.isTraceEnabled())\r
+ log.trace("Starting bundle: "\r
+ + contributorBundle.getSymbolicName());\r
+ // Thread startBundle = new Thread("Start bundle "\r
+ // + contributorBundle.getSymbolicName()) {\r
+ // public void run() {\r
+ try {\r
+ contributorBundle.start();\r
+ } catch (BundleException e) {\r
+ log.error("Cannot start bundle " + contributorBundle, e);\r
+ }\r
+ // }\r
+ // };\r
+ // startBundle.start();\r
+ // try {\r
+ // startBundle.join(10 * 1000l);\r
+ // } catch (InterruptedException e) {\r
+ // // silent\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
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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) {
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\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
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.argeo.ArgeoException;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.menus.CommandContributionItem;
+import org.eclipse.ui.menus.CommandContributionItemParameter;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * Centralises useful and generic methods when dealing with commands in an
+ * Eclipse Workbench context
+ */
+public class CommandUtils {
+
+ /**
+ * Commodities the refresh of a single command with no parameter in a
+ * Menu.aboutToShow method to simplify further development
+ *
+ * Note: that this method should be called with a false show command flag to
+ * remove a contribution that have been previously contributed
+ *
+ * @param menuManager
+ * @param locator
+ * @param cmdId
+ * @param label
+ * @param icon
+ * @param showCommand
+ */
+ public static void refreshCommand(IMenuManager menuManager,
+ IServiceLocator locator, String cmdId, String label,
+ ImageDescriptor icon, boolean showCommand) {
+ refreshParameterizedCommand(menuManager, locator, cmdId, label, icon,
+ showCommand, null);
+ }
+
+ /**
+ * Commodities the refresh the contribution of a command with a map of
+ * parameters in a context menu
+ *
+ * The command ID is used has contribution item ID
+ *
+ * @param menuManager
+ * @param locator
+ * @param cmdId
+ * @param label
+ * @param iconPath
+ * @param showCommand
+ */
+ public static void refreshParameterizedCommand(IMenuManager menuManager,
+ IServiceLocator locator, String cmdId, String label,
+ ImageDescriptor icon, boolean showCommand,
+ Map<String, String> params) {
+ refreshParameterizedCommand(menuManager, locator, cmdId, cmdId, label,
+ icon, showCommand, params);
+ }
+
+ /**
+ * Commodities the refresh the contribution of a command with a map of
+ * parameters in a context menu
+ *
+ * @param menuManager
+ * @param locator
+ * @param contributionId
+ * @param commandId
+ * @param label
+ * @param icon
+ * @param showCommand
+ * @param params
+ */
+ public static void refreshParameterizedCommand(IMenuManager menuManager,
+ IServiceLocator locator, String contributionId, String commandId,
+ String label, ImageDescriptor icon, boolean showCommand,
+ Map<String, String> params) {
+ IContributionItem ici = menuManager.find(contributionId);
+ if (ici != null)
+ menuManager.remove(ici);
+ if (showCommand) {
+ CommandContributionItemParameter contributionItemParameter = new CommandContributionItemParameter(
+ locator, null, commandId, SWT.PUSH);
+
+ // Set Params
+ contributionItemParameter.label = label;
+ contributionItemParameter.icon = icon;
+
+ if (params != null)
+ contributionItemParameter.parameters = params;
+
+ CommandContributionItem cci = new CommandContributionItem(
+ contributionItemParameter);
+ cci.setId(contributionId);
+ menuManager.add(cci);
+ }
+ }
+
+ /** Helper to call a command without parameter easily */
+ public static void callCommand(String commandID) {
+ callCommand(commandID, null);
+ }
+
+ /** Helper to call a command with a single parameter easily */
+ public static void callCommand(String commandID, String parameterID,
+ String parameterValue) {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(parameterID, parameterValue);
+ callCommand(commandID, params);
+ }
+
+ /**
+ * Helper to call a command with a map of parameters easily
+ *
+ * @param paramMap
+ * a map that links various command IDs with corresponding String
+ * values.
+ */
+ public static void callCommand(String commandID,
+ Map<String, String> paramMap) {
+ try {
+ IWorkbench iw = WorkbenchUiPlugin.getDefault().getWorkbench();
+ IHandlerService handlerService = (IHandlerService) iw
+ .getService(IHandlerService.class);
+ ICommandService cmdService = (ICommandService) iw
+ .getActiveWorkbenchWindow().getService(
+ ICommandService.class);
+ Command cmd = cmdService.getCommand(commandID);
+
+ ArrayList<Parameterization> parameters = null;
+ ParameterizedCommand pc;
+
+ if (paramMap != null) {
+ // Set parameters of the command to launch :
+ parameters = new ArrayList<Parameterization>();
+ Parameterization parameterization;
+
+ for (String id : paramMap.keySet()) {
+ parameterization = new Parameterization(
+ cmd.getParameter(id), paramMap.get(id));
+ parameters.add(parameterization);
+ }
+ pc = new ParameterizedCommand(cmd,
+ parameters.toArray(new Parameterization[parameters
+ .size()]));
+ } else
+ pc = new ParameterizedCommand(cmd, null);
+
+ // execute the command
+ handlerService.executeCommand(pc, null);
+ } catch (Exception e) {
+ throw new ArgeoException("Unexpected error while"
+ + " calling the command " + commandID, e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench;
+
+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 */
+@SuppressWarnings("serial")
+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");
+ }
+}
\ No newline at end of file
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.dialogs.SingleValue;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import javax.jcr.RepositoryException;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
import javax.jcr.SimpleCredentials;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
-import org.argeo.eclipse.ui.utils.CommandUtils;
+import org.argeo.eclipse.ui.workbench.CommandUtils;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.ArgeoNames;
import java.util.Arrays;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.dialogs.SingleValue;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
import javax.jcr.RepositoryException;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.specific.OpenFile;
-import org.argeo.eclipse.ui.utils.CommandUtils;
+import org.argeo.eclipse.ui.workbench.CommandUtils;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.jcr.JcrUtils;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import javax.jcr.Property;
import javax.jcr.nodetype.NodeType;
-import org.argeo.eclipse.ui.ErrorFeedback;
-import org.argeo.eclipse.ui.jcr.editors.NodeEditorInput;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import javax.jcr.Node;
-import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.jcr.JcrUtils;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import javax.jcr.Node;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
package org.argeo.eclipse.ui.workbench.commands;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.jcr.editors.JcrQueryEditorInput;
-import org.argeo.eclipse.ui.jcr.editors.NodeEditorInput;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
import org.argeo.eclipse.ui.workbench.jcr.GenericJcrQueryEditor;
import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
+import org.argeo.eclipse.ui.workbench.jcr.internal.parts.JcrQueryEditorInput;
+import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
*/
package org.argeo.eclipse.ui.workbench.jcr;
-import org.argeo.eclipse.ui.jcr.editors.AbstractJcrQueryEditor;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.jcr.internal.parts.AbstractJcrQueryEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench.jcr;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.version.VersionManager;
+
+import org.apache.commons.io.IOUtils;
+import org.argeo.ArgeoException;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.jcr.ArgeoTypes;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
+import org.eclipse.jface.preference.PreferenceStore;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Persist preferences as key/value pairs under ~/argeo:preferences.<br>
+ * TODO: better integrate JCR and Eclipse:<br>
+ * - typing<br>
+ * - use eclipse preferences<br>
+ * - better integrate with {@link ScopedPreferenceStore} provided by RAP
+ */
+public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames {
+ private static final long serialVersionUID = 1854011367784598758L;
+
+ private Session session;
+ private BundleContext bundleContext;
+
+ /** Retrieves the preference node */
+ protected Node getPreferenceNode() {
+ try {
+ if (session.hasPendingChanges())
+ session.save();
+ Node userHome = UserJcrUtils.getUserHome(session);
+ if (userHome == null)
+ throw new ArgeoException("No user home for "
+ + session.getUserID());
+ Node preferences;
+ if (!userHome.hasNode(ARGEO_PREFERENCES)) {
+ preferences = userHome.addNode(ARGEO_PREFERENCES);
+ preferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
+ session.save();
+ } else
+ preferences = userHome.getNode(ARGEO_PREFERENCES);
+
+ String pluginPreferencesName = bundleContext.getBundle()
+ .getSymbolicName();
+ Node pluginPreferences;
+ if (!preferences.hasNode(pluginPreferencesName)) {
+ VersionManager vm = session.getWorkspace().getVersionManager();
+ vm.checkout(preferences.getPath());
+ pluginPreferences = preferences.addNode(pluginPreferencesName);
+ pluginPreferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
+ session.save();
+ vm.checkin(preferences.getPath());
+ } else
+ pluginPreferences = preferences.getNode(pluginPreferencesName);
+ return pluginPreferences;
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ JcrUtils.discardQuietly(session);
+ throw new ArgeoException("Cannot retrieve preferences", e);
+ }
+
+ }
+
+ @Override
+ public void load() throws IOException {
+ ByteArrayOutputStream out = null;
+ ByteArrayInputStream in = null;
+ try {
+ Properties props = new Properties();
+ PropertyIterator it = getPreferenceNode().getProperties();
+ while (it.hasNext()) {
+ Property p = it.nextProperty();
+ if (!p.isMultiple() && !p.getDefinition().isProtected()) {
+ props.setProperty(p.getName(), p.getValue().getString());
+ }
+ }
+ out = new ByteArrayOutputStream();
+ props.store(out, "");
+ in = new ByteArrayInputStream(out.toByteArray());
+ load(in);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ArgeoException("Cannot load preferences", e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ }
+
+ @Override
+ public void save() throws IOException {
+ ByteArrayOutputStream out = null;
+ ByteArrayInputStream in = null;
+ Node pluginPreferences = null;
+ try {
+ out = new ByteArrayOutputStream();
+ save(out, "");
+ in = new ByteArrayInputStream(out.toByteArray());
+ Properties props = new Properties();
+ props.load(in);
+ pluginPreferences = getPreferenceNode();
+ VersionManager vm = pluginPreferences.getSession().getWorkspace()
+ .getVersionManager();
+ vm.checkout(pluginPreferences.getPath());
+ for (Object key : props.keySet()) {
+ String name = key.toString();
+ String value = props.getProperty(name);
+ pluginPreferences.setProperty(name, value);
+ }
+ JcrUtils.updateLastModified(pluginPreferences);
+ pluginPreferences.getSession().save();
+ vm.checkin(pluginPreferences.getPath());
+ } catch (Exception e) {
+ JcrUtils.discardUnderlyingSessionQuietly(pluginPreferences);
+ throw new ArgeoException("Cannot save preferences", e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ }
+
+ public void init() {
+ try {
+ load();
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot initialize preference store", e);
+ }
+ }
+
+ public void setSession(Session session) {
+ this.session = session;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+}
import javax.jcr.Session;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.MaintainedRepository;
import org.argeo.jcr.RepositoryRegister;
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench.jcr.internal.parts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.GenericTableComparator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+
+/** Executes any JCR query. */
+public abstract class AbstractJcrQueryEditor extends EditorPart {
+ private final static Log log = LogFactory
+ .getLog(AbstractJcrQueryEditor.class);
+
+ protected String initialQuery;
+ protected String initialQueryType;
+
+ /* DEPENDENCY INJECTION */
+ private Session session;
+
+ // Widgets
+ private TableViewer viewer;
+ private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
+ private GenericTableComparator comparator;
+
+ /** Override to layout a form enabling the end user to build his query */
+ protected abstract void createQueryForm(Composite parent);
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
+ initialQuery = editorInput.getQuery();
+ initialQueryType = editorInput.getQueryType();
+ setSite(site);
+ setInput(editorInput);
+ }
+
+ @Override
+ public final void createPartControl(final Composite parent) {
+ parent.setLayout(new FillLayout());
+
+ SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
+ sashForm.setSashWidth(4);
+ sashForm.setLayout(new FillLayout());
+
+ Composite top = new Composite(sashForm, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ top.setLayout(gl);
+
+ createQueryForm(top);
+
+ Composite bottom = new Composite(sashForm, SWT.NONE);
+ bottom.setLayout(new GridLayout(1, false));
+ sashForm.setWeights(getWeights());
+
+ viewer = new TableViewer(bottom);
+ viewer.getTable().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.getTable().setHeaderVisible(true);
+ viewer.setContentProvider(getQueryResultContentProvider());
+ viewer.setInput(getEditorSite());
+
+ if (getComparator() != null) {
+ comparator = getComparator();
+ viewer.setComparator(comparator);
+ }
+ if (getTableDoubleClickListener() != null)
+ viewer.addDoubleClickListener(getTableDoubleClickListener());
+
+ }
+
+ protected void executeQuery(String statement) {
+ try {
+ if (log.isDebugEnabled())
+ log.debug("Query : " + statement);
+
+ QueryResult qr = session.getWorkspace().getQueryManager()
+ .createQuery(statement, initialQueryType).execute();
+
+ // remove previous columns
+ for (TableViewerColumn tvc : tableViewerColumns)
+ tvc.getColumn().dispose();
+
+ int i = 0;
+ for (final String columnName : qr.getColumnNames()) {
+ TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
+ configureColumn(columnName, tvc, i);
+ tvc.setLabelProvider(getLabelProvider(columnName));
+ tableViewerColumns.add(tvc);
+ i++;
+ }
+
+ // Must create a local list: QueryResults can only be read once.
+ try {
+ List<Row> rows = new ArrayList<Row>();
+ RowIterator rit = qr.getRows();
+ while (rit.hasNext()) {
+ rows.add(rit.nextRow());
+ }
+ viewer.setInput(rows);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot read query result", e);
+ }
+
+ } catch (RepositoryException e) {
+ ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
+ + statement, new Status(IStatus.ERROR,
+ "org.argeo.eclipse.ui.jcr", e.getMessage()));
+ }
+ }
+
+ /**
+ * To be overidden to adapt size of form and result frames.
+ *
+ * @return
+ */
+ protected int[] getWeights() {
+ return new int[] { 30, 70 };
+ }
+
+ /**
+ * To be overidden to implement a doubleclick Listener on one of the rows of
+ * the table.
+ *
+ * @return
+ */
+ protected IDoubleClickListener getTableDoubleClickListener() {
+ return null;
+ }
+
+ /**
+ * To be overiden in order to implement a specific
+ * QueryResultContentProvider
+ */
+ protected IStructuredContentProvider getQueryResultContentProvider() {
+ return new QueryResultContentProvider();
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected List<TableViewerColumn> getTableViewerColumns() {
+ return tableViewerColumns;
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected TableViewer getTableViewer() {
+ return viewer;
+ }
+
+ /**
+ * To be overridden in order to configure column label providers .
+ */
+ protected ColumnLabelProvider getLabelProvider(final String columnName) {
+ return new ColumnLabelProvider() {
+ public String getText(Object element) {
+ Row row = (Row) element;
+ try {
+ return row.getValue(columnName).getString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot display row " + row, e);
+ }
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ };
+ }
+
+ /**
+ * To be overridden in order to configure the columns.
+ *
+ * @deprecated use {@link
+ * org.argeo.eclipse.ui.jcr.editors.AbstractJcrQueryEditor.
+ * configureColumn(String jcrColumnName, TableViewerColumn
+ * column, int columnIndex)} instead
+ */
+ protected void configureColumn(String jcrColumnName,
+ TableViewerColumn column) {
+ column.getColumn().setWidth(50);
+ column.getColumn().setText(jcrColumnName);
+ }
+
+ /** To be overridden in order to configure the columns. */
+ protected void configureColumn(String jcrColumnName,
+ TableViewerColumn column, int columnIndex) {
+ column.getColumn().setWidth(50);
+ column.getColumn().setText(jcrColumnName);
+ }
+
+ private class QueryResultContentProvider implements
+ IStructuredContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+
+ if (inputElement instanceof List)
+ return ((List<?>) inputElement).toArray();
+
+ // Never reached might be deleted in future release
+ if (!(inputElement instanceof QueryResult))
+ return new String[] {};
+
+ try {
+ QueryResult queryResult = (QueryResult) inputElement;
+ List<Row> rows = new ArrayList<Row>();
+ RowIterator rit = queryResult.getRows();
+ while (rit.hasNext()) {
+ rows.add(rit.nextRow());
+ }
+
+ // List<Node> elems = new ArrayList<Node>();
+ // NodeIterator nit = queryResult.getNodes();
+ // while (nit.hasNext()) {
+ // elems.add(nit.nextNode());
+ // }
+ return rows.toArray();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot read query result", e);
+ }
+ }
+
+ }
+
+ /**
+ * Might be used by children classes to sort columns.
+ *
+ * @param column
+ * @param index
+ * @return
+ */
+ protected SelectionAdapter getSelectionAdapter(final TableColumn column,
+ final int index) {
+
+ // A comparator must be define
+ if (comparator == null)
+ return null;
+
+ SelectionAdapter selectionAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ try {
+
+ comparator.setColumn(index);
+ int dir = viewer.getTable().getSortDirection();
+ if (viewer.getTable().getSortColumn() == column) {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ } else {
+
+ dir = SWT.DOWN;
+ }
+ viewer.getTable().setSortDirection(dir);
+ viewer.getTable().setSortColumn(column);
+ viewer.refresh();
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ }
+ }
+ };
+ return selectionAdapter;
+ }
+
+ /**
+ * To be overridden to enable sorting.
+ */
+ protected GenericTableComparator getComparator() {
+ return null;
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ // TODO save the query in JCR?
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ /** Returns the injected current session */
+ protected Session getSession() {
+ return session;
+ }
+
+ /* DEPENDENCY INJECTION */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.specific.ImportToServerWizardPage;
import org.argeo.eclipse.ui.specific.UploadFileWizardPage;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench.jcr.internal.parts;
+
+import javax.jcr.query.Query;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+public class JcrQueryEditorInput implements IEditorInput {
+ private final String query;
+ private final String queryType;
+
+ public JcrQueryEditorInput(String query, String queryType) {
+ this.query = query;
+ if (queryType == null)
+ this.queryType = Query.JCR_SQL2;
+ else
+ this.queryType = queryType;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return query;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return query;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getQueryType() {
+ return queryType;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.workbench.jcr.internal.parts;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * A canonical editor input based on a path to a node. In a multirepository
+ * environment, path can be enriched with Repository Alias and workspace
+ */
+
+public class NodeEditorInput implements IEditorInput {
+ private final String path;
+
+ public NodeEditorInput(String path) {
+ this.path = path;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return path;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return path;
+ }
+
+ public String getPath() {
+ return path;
+ }
+}
-Bundle-ActivationPolicy: lazy
-#Bundle-SymbolicName: org.argeo.eclipse.ui;singleton:=true
-#Bundle-Activator: org.argeo.eclipse.ui.ArgeoUiPlugin
-Require-Bundle: org.eclipse.ui;resolution:=optional,\
- org.eclipse.rap.ui;resolution:=optional,\
- org.eclipse.core.runtime
-Import-Package: org.springframework.beans.factory,\
- org.springframework.core.io.support,\
+Require-Bundle: org.eclipse.core.runtime
+Import-Package: org.eclipse.core.commands,\
+ org.eclipse.swt,\
org.eclipse.swt.widgets;version="[0,1)",\
org.osgi.framework;version="[1.5,2)",\
org.osgi.util.tracker;version="[1.4,2)",\
- !org.eclipse.core.runtime,\
- !org.eclipse.core.commands,\
- !org.eclipse.ui.plugin,\
+ org.springframework.beans.factory,\
+ org.springframework.core.io.support,\
*
+
+
+# Was:
+#Bundle-ActivationPolicy: lazy
+#Bundle-SymbolicName: org.argeo.eclipse.ui;singleton:=true
+#Bundle-Activator: org.argeo.eclipse.ui.ArgeoUiPlugin
+
+#!org.eclipse.core.commands,\
+# !org.eclipse.core.runtime,\
+# !org.eclipse.ui.plugin,\
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\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(\r
- final Bundle contributorBundle) {\r
- if (log.isTraceEnabled())\r
- log.trace("Get application context for bundle " + contributorBundle);\r
-\r
- // Start if not yet started (also if in STARTING state, may be lazy)\r
- if (contributorBundle.getState() != Bundle.ACTIVE) {\r
- if (log.isTraceEnabled())\r
- log.trace("Starting bundle: "\r
- + contributorBundle.getSymbolicName());\r
- // Thread startBundle = new Thread("Start bundle "\r
- // + contributorBundle.getSymbolicName()) {\r
- // public void run() {\r
- try {\r
- contributorBundle.start();\r
- } catch (BundleException e) {\r
- log.error("Cannot start bundle " + contributorBundle, e);\r
- }\r
- // }\r
- // };\r
- // startBundle.start();\r
- // try {\r
- // startBundle.join(10 * 1000l);\r
- // } catch (InterruptedException e) {\r
- // // silent\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
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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) {
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\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
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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());
-
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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
- */
-@SuppressWarnings("serial")
-@Deprecated
-public class Error extends ErrorFeedback {
-
- public Error(Shell parentShell, String message, Throwable e) {
- super(parentShell, message, e);
- // TODO Auto-generated constructor stub
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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 */
-@SuppressWarnings("serial")
-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");
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.jcr;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.version.VersionManager;
-
-import org.apache.commons.io.IOUtils;
-import org.argeo.ArgeoException;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.ArgeoTypes;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.UserJcrUtils;
-import org.eclipse.jface.preference.PreferenceStore;
-import org.eclipse.ui.preferences.ScopedPreferenceStore;
-import org.osgi.framework.BundleContext;
-
-/**
- * Persist preferences as key/value pairs under ~/argeo:preferences.<br>
- * TODO: better integrate JCR and Eclipse:<br>
- * - typing<br>
- * - use eclipse preferences<br>
- * - better integrate with {@link ScopedPreferenceStore} provided by RAP
- */
-public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames {
- private static final long serialVersionUID = 1854011367784598758L;
-
- private Session session;
- private BundleContext bundleContext;
-
- /** Retrieves the preference node */
- protected Node getPreferenceNode() {
- try {
- if (session.hasPendingChanges())
- session.save();
- Node userHome = UserJcrUtils.getUserHome(session);
- if (userHome == null)
- throw new ArgeoException("No user home for "
- + session.getUserID());
- Node preferences;
- if (!userHome.hasNode(ARGEO_PREFERENCES)) {
- preferences = userHome.addNode(ARGEO_PREFERENCES);
- preferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
- session.save();
- } else
- preferences = userHome.getNode(ARGEO_PREFERENCES);
-
- String pluginPreferencesName = bundleContext.getBundle()
- .getSymbolicName();
- Node pluginPreferences;
- if (!preferences.hasNode(pluginPreferencesName)) {
- VersionManager vm = session.getWorkspace().getVersionManager();
- vm.checkout(preferences.getPath());
- pluginPreferences = preferences.addNode(pluginPreferencesName);
- pluginPreferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
- session.save();
- vm.checkin(preferences.getPath());
- } else
- pluginPreferences = preferences.getNode(pluginPreferencesName);
- return pluginPreferences;
- } catch (RepositoryException e) {
- e.printStackTrace();
- JcrUtils.discardQuietly(session);
- throw new ArgeoException("Cannot retrieve preferences", e);
- }
-
- }
-
- @Override
- public void load() throws IOException {
- ByteArrayOutputStream out = null;
- ByteArrayInputStream in = null;
- try {
- Properties props = new Properties();
- PropertyIterator it = getPreferenceNode().getProperties();
- while (it.hasNext()) {
- Property p = it.nextProperty();
- if (!p.isMultiple() && !p.getDefinition().isProtected()) {
- props.setProperty(p.getName(), p.getValue().getString());
- }
- }
- out = new ByteArrayOutputStream();
- props.store(out, "");
- in = new ByteArrayInputStream(out.toByteArray());
- load(in);
- } catch (Exception e) {
- e.printStackTrace();
- throw new ArgeoException("Cannot load preferences", e);
- } finally {
- IOUtils.closeQuietly(in);
- IOUtils.closeQuietly(out);
- }
- }
-
- @Override
- public void save() throws IOException {
- ByteArrayOutputStream out = null;
- ByteArrayInputStream in = null;
- Node pluginPreferences = null;
- try {
- out = new ByteArrayOutputStream();
- save(out, "");
- in = new ByteArrayInputStream(out.toByteArray());
- Properties props = new Properties();
- props.load(in);
- pluginPreferences = getPreferenceNode();
- VersionManager vm = pluginPreferences.getSession().getWorkspace()
- .getVersionManager();
- vm.checkout(pluginPreferences.getPath());
- for (Object key : props.keySet()) {
- String name = key.toString();
- String value = props.getProperty(name);
- pluginPreferences.setProperty(name, value);
- }
- JcrUtils.updateLastModified(pluginPreferences);
- pluginPreferences.getSession().save();
- vm.checkin(pluginPreferences.getPath());
- } catch (Exception e) {
- JcrUtils.discardUnderlyingSessionQuietly(pluginPreferences);
- throw new ArgeoException("Cannot save preferences", e);
- } finally {
- IOUtils.closeQuietly(in);
- IOUtils.closeQuietly(out);
- }
- }
-
- public void init() {
- try {
- load();
- } catch (IOException e) {
- throw new ArgeoException("Cannot initialize preference store", e);
- }
- }
-
- public void setSession(Session session) {
- this.session = session;
- }
-
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.jcr.editors;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.QueryResult;
-import javax.jcr.query.Row;
-import javax.jcr.query.RowIterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.GenericTableComparator;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-
-/** Executes any JCR query. */
-public abstract class AbstractJcrQueryEditor extends EditorPart {
- private final static Log log = LogFactory
- .getLog(AbstractJcrQueryEditor.class);
-
- protected String initialQuery;
- protected String initialQueryType;
-
- /* DEPENDENCY INJECTION */
- private Session session;
-
- // Widgets
- private TableViewer viewer;
- private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
- private GenericTableComparator comparator;
-
- /** Override to layout a form enabling the end user to build his query */
- protected abstract void createQueryForm(Composite parent);
-
- @Override
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
- JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
- initialQuery = editorInput.getQuery();
- initialQueryType = editorInput.getQueryType();
- setSite(site);
- setInput(editorInput);
- }
-
- @Override
- public final void createPartControl(final Composite parent) {
- parent.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
- sashForm.setSashWidth(4);
- sashForm.setLayout(new FillLayout());
-
- Composite top = new Composite(sashForm, SWT.NONE);
- GridLayout gl = new GridLayout(1, false);
- top.setLayout(gl);
-
- createQueryForm(top);
-
- Composite bottom = new Composite(sashForm, SWT.NONE);
- bottom.setLayout(new GridLayout(1, false));
- sashForm.setWeights(getWeights());
-
- viewer = new TableViewer(bottom);
- viewer.getTable().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- viewer.getTable().setHeaderVisible(true);
- viewer.setContentProvider(getQueryResultContentProvider());
- viewer.setInput(getEditorSite());
-
- if (getComparator() != null) {
- comparator = getComparator();
- viewer.setComparator(comparator);
- }
- if (getTableDoubleClickListener() != null)
- viewer.addDoubleClickListener(getTableDoubleClickListener());
-
- }
-
- protected void executeQuery(String statement) {
- try {
- if (log.isDebugEnabled())
- log.debug("Query : " + statement);
-
- QueryResult qr = session.getWorkspace().getQueryManager()
- .createQuery(statement, initialQueryType).execute();
-
- // remove previous columns
- for (TableViewerColumn tvc : tableViewerColumns)
- tvc.getColumn().dispose();
-
- int i = 0;
- for (final String columnName : qr.getColumnNames()) {
- TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
- configureColumn(columnName, tvc, i);
- tvc.setLabelProvider(getLabelProvider(columnName));
- tableViewerColumns.add(tvc);
- i++;
- }
-
- // Must create a local list: QueryResults can only be read once.
- try {
- List<Row> rows = new ArrayList<Row>();
- RowIterator rit = qr.getRows();
- while (rit.hasNext()) {
- rows.add(rit.nextRow());
- }
- viewer.setInput(rows);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot read query result", e);
- }
-
- } catch (RepositoryException e) {
- ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
- + statement, new Status(IStatus.ERROR,
- "org.argeo.eclipse.ui.jcr", e.getMessage()));
- }
- }
-
- /**
- * To be overidden to adapt size of form and result frames.
- *
- * @return
- */
- protected int[] getWeights() {
- return new int[] { 30, 70 };
- }
-
- /**
- * To be overidden to implement a doubleclick Listener on one of the rows of
- * the table.
- *
- * @return
- */
- protected IDoubleClickListener getTableDoubleClickListener() {
- return null;
- }
-
- /**
- * To be overiden in order to implement a specific
- * QueryResultContentProvider
- */
- protected IStructuredContentProvider getQueryResultContentProvider() {
- return new QueryResultContentProvider();
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected List<TableViewerColumn> getTableViewerColumns() {
- return tableViewerColumns;
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected TableViewer getTableViewer() {
- return viewer;
- }
-
- /**
- * To be overridden in order to configure column label providers .
- */
- protected ColumnLabelProvider getLabelProvider(final String columnName) {
- return new ColumnLabelProvider() {
- public String getText(Object element) {
- Row row = (Row) element;
- try {
- return row.getValue(columnName).getString();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot display row " + row, e);
- }
- }
-
- public Image getImage(Object element) {
- return null;
- }
- };
- }
-
- /**
- * To be overridden in order to configure the columns.
- *
- * @deprecated use {@link
- * org.argeo.eclipse.ui.jcr.editors.AbstractJcrQueryEditor.
- * configureColumn(String jcrColumnName, TableViewerColumn
- * column, int columnIndex)} instead
- */
- protected void configureColumn(String jcrColumnName,
- TableViewerColumn column) {
- column.getColumn().setWidth(50);
- column.getColumn().setText(jcrColumnName);
- }
-
- /** To be overridden in order to configure the columns. */
- protected void configureColumn(String jcrColumnName,
- TableViewerColumn column, int columnIndex) {
- column.getColumn().setWidth(50);
- column.getColumn().setText(jcrColumnName);
- }
-
- private class QueryResultContentProvider implements
- IStructuredContentProvider {
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
-
- if (inputElement instanceof List)
- return ((List<?>) inputElement).toArray();
-
- // Never reached might be deleted in future release
- if (!(inputElement instanceof QueryResult))
- return new String[] {};
-
- try {
- QueryResult queryResult = (QueryResult) inputElement;
- List<Row> rows = new ArrayList<Row>();
- RowIterator rit = queryResult.getRows();
- while (rit.hasNext()) {
- rows.add(rit.nextRow());
- }
-
- // List<Node> elems = new ArrayList<Node>();
- // NodeIterator nit = queryResult.getNodes();
- // while (nit.hasNext()) {
- // elems.add(nit.nextNode());
- // }
- return rows.toArray();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot read query result", e);
- }
- }
-
- }
-
- /**
- * Might be used by children classes to sort columns.
- *
- * @param column
- * @param index
- * @return
- */
- protected SelectionAdapter getSelectionAdapter(final TableColumn column,
- final int index) {
-
- // A comparator must be define
- if (comparator == null)
- return null;
-
- SelectionAdapter selectionAdapter = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
-
- try {
-
- comparator.setColumn(index);
- int dir = viewer.getTable().getSortDirection();
- if (viewer.getTable().getSortColumn() == column) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
-
- dir = SWT.DOWN;
- }
- viewer.getTable().setSortDirection(dir);
- viewer.getTable().setSortColumn(column);
- viewer.refresh();
- } catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- };
- return selectionAdapter;
- }
-
- /**
- * To be overridden to enable sorting.
- */
- protected GenericTableComparator getComparator() {
- return null;
- }
-
- @Override
- public boolean isDirty() {
- return false;
- }
-
- @Override
- public void doSave(IProgressMonitor monitor) {
- // TODO save the query in JCR?
- }
-
- @Override
- public void doSaveAs() {
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- /** Returns the injected current session */
- protected Session getSession() {
- return session;
- }
-
- /* DEPENDENCY INJECTION */
- public void setSession(Session session) {
- this.session = session;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.jcr.editors;
-
-import javax.jcr.query.Query;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-public class JcrQueryEditorInput implements IEditorInput {
- private final String query;
- private final String queryType;
-
- public JcrQueryEditorInput(String query, String queryType) {
- this.query = query;
- if (queryType == null)
- this.queryType = Query.JCR_SQL2;
- else
- this.queryType = queryType;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return query;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return query;
- }
-
- public String getQuery() {
- return query;
- }
-
- public String getQueryType() {
- return queryType;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.jcr.editors;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/**
- * A canonical editor input based on a path to a node. In a multirepository
- * environment, path can be enriched with Repository Alias and workspace
- */
-
-public class NodeEditorInput implements IEditorInput {
- private final String path;
-
- public NodeEditorInput(String path) {
- this.path = path;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return path;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return path;
- }
-
- public String getPath() {
- return path;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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 java.util.HashMap;
-import java.util.Map;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ArgeoUiPlugin;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.menus.CommandContributionItem;
-import org.eclipse.ui.menus.CommandContributionItemParameter;
-import org.eclipse.ui.services.IServiceLocator;
-
-/**
- * Centralises useful and generic methods when dealing with commands in an
- * Eclipse Workbench context
- */
-public class CommandUtils {
-
- /**
- * Commodities the refresh of a single command with no parameter in a
- * Menu.aboutToShow method to simplify further development
- *
- * Note: that this method should be called with a false show command flag to
- * remove a contribution that have been previously contributed
- *
- * @param menuManager
- * @param locator
- * @param cmdId
- * @param label
- * @param icon
- * @param showCommand
- */
- public static void refreshCommand(IMenuManager menuManager,
- IServiceLocator locator, String cmdId, String label,
- ImageDescriptor icon, boolean showCommand) {
- refreshParameterizedCommand(menuManager, locator, cmdId, label, icon,
- showCommand, null);
- }
-
- /**
- * Commodities the refresh the contribution of a command with a map of
- * parameters in a context menu
- *
- * The command ID is used has contribution item ID
- *
- * @param menuManager
- * @param locator
- * @param cmdId
- * @param label
- * @param iconPath
- * @param showCommand
- */
- public static void refreshParameterizedCommand(IMenuManager menuManager,
- IServiceLocator locator, String cmdId, String label,
- ImageDescriptor icon, boolean showCommand,
- Map<String, String> params) {
- refreshParameterizedCommand(menuManager, locator, cmdId, cmdId, label,
- icon, showCommand, params);
- }
-
- /**
- * Commodities the refresh the contribution of a command with a map of
- * parameters in a context menu
- *
- * @param menuManager
- * @param locator
- * @param contributionId
- * @param commandId
- * @param label
- * @param icon
- * @param showCommand
- * @param params
- */
- public static void refreshParameterizedCommand(IMenuManager menuManager,
- IServiceLocator locator, String contributionId, String commandId,
- String label, ImageDescriptor icon, boolean showCommand,
- Map<String, String> params) {
- IContributionItem ici = menuManager.find(contributionId);
- if (ici != null)
- menuManager.remove(ici);
- if (showCommand) {
- CommandContributionItemParameter contributionItemParameter = new CommandContributionItemParameter(
- locator, null, commandId, SWT.PUSH);
-
- // Set Params
- contributionItemParameter.label = label;
- contributionItemParameter.icon = icon;
-
- if (params != null)
- contributionItemParameter.parameters = params;
-
- CommandContributionItem cci = new CommandContributionItem(
- contributionItemParameter);
- cci.setId(contributionId);
- menuManager.add(cci);
- }
- }
-
- /** Helper to call a command without parameter easily */
- public static void callCommand(String commandID) {
- callCommand(commandID, null);
- }
-
- /** Helper to call a command with a single parameter easily */
- public static void callCommand(String commandID, String parameterID,
- String parameterValue) {
- Map<String, String> params = new HashMap<String, String>();
- params.put(parameterID, parameterValue);
- callCommand(commandID, params);
- }
-
- /**
- * Helper to call a command with a map of parameters easily
- *
- * @param paramMap
- * a map that links various command IDs with corresponding String
- * values.
- */
- public static void callCommand(String commandID,
- Map<String, String> paramMap) {
- try {
- IWorkbench iw = ArgeoUiPlugin.getDefault().getWorkbench();
- IHandlerService handlerService = (IHandlerService) iw
- .getService(IHandlerService.class);
- ICommandService cmdService = (ICommandService) iw
- .getActiveWorkbenchWindow().getService(
- ICommandService.class);
- Command cmd = cmdService.getCommand(commandID);
-
- ArrayList<Parameterization> parameters = null;
- ParameterizedCommand pc;
-
- if (paramMap != null) {
- // Set parameters of the command to launch :
- parameters = new ArrayList<Parameterization>();
- Parameterization parameterization;
-
- for (String id : paramMap.keySet()) {
- parameterization = new Parameterization(
- cmd.getParameter(id), paramMap.get(id));
- parameters.add(parameterization);
- }
- pc = new ParameterizedCommand(cmd,
- parameters.toArray(new Parameterization[parameters
- .size()]));
- } else
- pc = new ParameterizedCommand(cmd, null);
-
- // execute the command
- handlerService.executeCommand(pc, null);
- } catch (Exception e) {
- throw new ArgeoException("Unexpected error while"
- + " calling the command " + commandID, e);
- }
- }
-}
\ No newline at end of file
import javax.jcr.observation.EventListener;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.utils.CommandUtils;
+import org.argeo.eclipse.ui.workbench.CommandUtils;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.ArgeoTypes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.UserJcrUtils;
import org.argeo.security.UserAdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.util.LocaleUtils;
import org.eclipse.equinox.security.auth.ILoginContext;
import org.eclipse.jface.dialogs.MessageDialog;
Import-Package: org.argeo.eclipse.spring,\
org.apache.log4j;resolution:=optional,\
- org.eclipse.swt.widgets;version="[0,4.0)",\
+ org.eclipse.swt.widgets;version="[0,1.0)",\
+ org.osgi.framework;version="[1.4,2)",\
*
Export-Packages: !org.argeo.security.ui.internal.*,\
<!-- Generic Eclipse Utilities -->
<dependency>
<groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.eclipse.ui</artifactId>
+ <artifactId>org.argeo.eclipse.ui.workbench</artifactId>
<version>2.1.12-SNAPSHOT</version>
</dependency>
*/
package org.argeo.security.ui.commands;
-import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.argeo.security.ui.UserHomePerspective;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
package org.argeo.security.ui.dialogs;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.ErrorFeedback;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;