From: Bruno Sinou Date: Fri, 12 Dec 2014 14:16:39 +0000 (+0000) Subject: Refactoring: move all code needing the workbench from eclipse.ui to eclipse.ui.workbe... X-Git-Tag: argeo-commons-2.1.30~490 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=ebc46b310bf1f44c4acbeae3d2ab8c1aeaef5eb5;p=lgpl%2Fargeo-commons.git Refactoring: move all code needing the workbench from eclipse.ui to eclipse.ui.workbench bundle, in order to be able to use the base ui bundle to factorise common patterns. git-svn-id: https://svn.argeo.org/commons/trunk@7569 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.cms/bnd.bnd b/org.argeo.cms/bnd.bnd index 6af318a2d..969fc94ac 100644 --- a/org.argeo.cms/bnd.bnd +++ b/org.argeo.cms/bnd.bnd @@ -1,197 +1,7 @@ -# 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 diff --git a/org.argeo.eclipse.ui.rap/bnd.bnd b/org.argeo.eclipse.ui.rap/bnd.bnd index 3e0cb3cab..83a2036d4 100644 --- a/org.argeo.eclipse.ui.rap/bnd.bnd +++ b/org.argeo.eclipse.ui.rap/bnd.bnd @@ -1,5 +1,3 @@ -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,\ diff --git a/org.argeo.eclipse.ui.workbench/bnd.bnd b/org.argeo.eclipse.ui.workbench/bnd.bnd index cc75c057e..d6c44eeb9 100644 --- a/org.argeo.eclipse.ui.workbench/bnd.bnd +++ b/org.argeo.eclipse.ui.workbench/bnd.bnd @@ -8,10 +8,10 @@ Require-Bundle: org.eclipse.ui;resolution:=optional,\ 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,\ * diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/ApplicationContextTracker.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/ApplicationContextTracker.java new file mode 100644 index 000000000..070c70826 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/ApplicationContextTracker.java @@ -0,0 +1,150 @@ +/* + * 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 static java.text.MessageFormat.format; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.util.tracker.ServiceTracker; +import org.springframework.context.ApplicationContext; + +/** + * Tracks Spring application context published as services. + * + * @author Heiko Seeberger + * @author Mathieu Baudier + */ +class ApplicationContextTracker { + private final static Log log = LogFactory + .getLog(ApplicationContextTracker.class); + + private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$ + + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$ + + public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout"; + + private static Long defaultTimeout = Long.parseLong(System.getProperty( + APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000")); + + private ServiceTracker applicationContextServiceTracker; + + /** + * @param contributorBundle + * OSGi bundle for which the Spring application context is to be + * tracked. Must not be null! + * @param factoryBundleContext + * BundleContext object which can be used to track services + * @throws IllegalArgumentException + * if the given bundle is null. + */ + public ApplicationContextTracker(final Bundle contributorBundle, + final BundleContext factoryBundleContext) { + final String filter = format(FILTER, + contributorBundle.getSymbolicName()); + try { + applicationContextServiceTracker = new ServiceTracker( + factoryBundleContext, FrameworkUtil.createFilter(filter), + null); + // applicationContextServiceTracker.open(); + } catch (final InvalidSyntaxException e) { + e.printStackTrace(); + } + } + + public void open() { + if (applicationContextServiceTracker != null) { + applicationContextServiceTracker.open(); + } + } + + public void close() { + if (applicationContextServiceTracker != null) { + applicationContextServiceTracker.close(); + } + } + + public ApplicationContext getApplicationContext() { + ApplicationContext applicationContext = null; + if (applicationContextServiceTracker != null) { + try { + applicationContext = (ApplicationContext) applicationContextServiceTracker + .waitForService(defaultTimeout); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return applicationContext; + } + + @Override + protected void finalize() throws Throwable { + close(); + super.finalize(); + } + + static ApplicationContext getApplicationContext(String bundleSymbolicName) { + Bundle contributorBundle = Platform.getBundle(bundleSymbolicName); + return getApplicationContext(contributorBundle); + } + + static ApplicationContext getApplicationContext( + final Bundle contributorBundle) { + if (log.isTraceEnabled()) + log.trace("Get application context for bundle " + contributorBundle); + + // Start if not yet started (also if in STARTING state, may be lazy) + if (contributorBundle.getState() != Bundle.ACTIVE) { + if (log.isTraceEnabled()) + log.trace("Starting bundle: " + + contributorBundle.getSymbolicName()); + // Thread startBundle = new Thread("Start bundle " + // + contributorBundle.getSymbolicName()) { + // public void run() { + try { + contributorBundle.start(); + } catch (BundleException e) { + log.error("Cannot start bundle " + contributorBundle, e); + } + // } + // }; + // startBundle.start(); + // try { + // startBundle.join(10 * 1000l); + // } catch (InterruptedException e) { + // // silent + // } + } + + final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker( + contributorBundle, contributorBundle.getBundleContext()); + ApplicationContext applicationContext = null; + try { + applicationContextTracker.open(); + applicationContext = applicationContextTracker + .getApplicationContext(); + } finally { + applicationContextTracker.close(); + } + return applicationContext; + } +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java new file mode 100644 index 000000000..4c7a152df --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java @@ -0,0 +1,93 @@ +/* + * 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) { + } + +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java new file mode 100644 index 000000000..7a0486fd2 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java @@ -0,0 +1,114 @@ +/* + * 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.argeo.ArgeoException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.IExecutableExtensionFactory; +import org.eclipse.core.runtime.IExtension; +import org.springframework.context.ApplicationContext; + +/** + * The Spring Extension Factory builds a bridge between the Eclipse Extension + * Registry and the Spring Framework (especially Spring Dynamic Modules). + * + * It allows you to define your extension as a spring bean within the spring + * application context of your bundle. If you would like to use this bean as an + * instance of an extension (an Eclipse RCP view, for example) you define the + * extension with this spring extension factory as the class to be created. + * + * To let the spring extension factory pick the right bean from your application + * context you need to set the bean id to the same value as the id of the view + * within the view definition, for example. This is important if your extension + * definition contains more than one element, where each element has its own id. + * + * If the extension definition elements themselves have no id attribute the + * spring extension factory uses the id of the extension itself to identify the + * bean. + * + * original code from: Blog entry + * + * @author Martin Lippert + * @author mbaudier + */ +public class SpringExtensionFactory implements IExecutableExtensionFactory, + IExecutableExtension { + + private Object bean; + + public Object create() throws CoreException { + if (bean == null) + throw new ArgeoException("No underlying bean for extension"); + return bean; + } + + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { + String bundleSymbolicName = config.getContributor().getName(); + ApplicationContext applicationContext = ApplicationContextTracker + .getApplicationContext(bundleSymbolicName); + if (applicationContext == null) + throw new ArgeoException( + "Cannot find application context for bundle " + + bundleSymbolicName); + + String beanName = getBeanName(data, config); + if (beanName == null) + throw new ArgeoException("Cannot find bean name for extension " + + config); + + if (!applicationContext.containsBean(beanName)) { + if (beanName.startsWith(bundleSymbolicName)) + beanName = beanName.substring(bundleSymbolicName.length() + 1); + } + + if (!applicationContext.containsBean(beanName)) + throw new ArgeoException("No bean with name '" + beanName + "'"); + + this.bean = applicationContext.getBean(beanName); + if (this.bean instanceof IExecutableExtension) { + ((IExecutableExtension) this.bean).setInitializationData(config, + propertyName, data); + } + } + + private String getBeanName(Object data, IConfigurationElement config) { + + // try the specific bean id the extension defines + if (data != null && data.toString().length() > 0) { + return data.toString(); + } + + // try the id of the config element + if (config.getAttribute("id") != null) { + return config.getAttribute("id"); + } + + // try the id of the extension element itself + if (config.getParent() != null + && config.getParent() instanceof IExtension) { + IExtension extensionDefinition = (IExtension) config.getParent(); + return extensionDefinition.getSimpleIdentifier(); + } + + return null; + } + +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java new file mode 100644 index 000000000..3670efbe5 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java @@ -0,0 +1,180 @@ +/* + * 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 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 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 params = new HashMap(); + 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 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 parameters = null; + ParameterizedCommand pc; + + if (paramMap != null) { + // Set parameters of the command to launch : + parameters = new ArrayList(); + 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 diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/ErrorFeedback.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/ErrorFeedback.java new file mode 100644 index 000000000..692d8a4b9 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/ErrorFeedback.java @@ -0,0 +1,115 @@ +/* + * 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 diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddFolderNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddFolderNode.java index 3ac711665..291df2ccc 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddFolderNode.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddFolderNode.java @@ -19,9 +19,9 @@ import javax.jcr.Node; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java index 6f5f6ccad..7100d8f18 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java @@ -19,8 +19,8 @@ import javax.jcr.Node; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java index 8c4536a5a..50e286179 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java @@ -25,8 +25,8 @@ import javax.jcr.Session; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java index 024601de5..82db51321 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java @@ -17,8 +17,8 @@ package org.argeo.eclipse.ui.workbench.commands; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java index e3518e53c..ff05c631f 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java @@ -21,8 +21,8 @@ import javax.jcr.Node; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java index e919eb26b..79d807625 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java @@ -30,7 +30,7 @@ import javax.jcr.RepositoryException; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java index c02187751..4c9553484 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java @@ -21,8 +21,8 @@ import java.util.Map; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/GetNodeSize.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/GetNodeSize.java index c31f4d6b3..1caf11482 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/GetNodeSize.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/GetNodeSize.java @@ -21,7 +21,7 @@ import java.util.List; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/ImportFileSystem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/ImportFileSystem.java index 0531c3a18..fa2da1dc5 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/ImportFileSystem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/ImportFileSystem.java @@ -17,8 +17,8 @@ package org.argeo.eclipse.ui.workbench.commands; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java index f6e57c368..123f089b8 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java @@ -16,11 +16,11 @@ 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/GenericJcrQueryEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/GenericJcrQueryEditor.java index dcb14ead5..73b8be61b 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/GenericJcrQueryEditor.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/GenericJcrQueryEditor.java @@ -15,8 +15,8 @@ */ 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java new file mode 100644 index 000000000..b317e12bc --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java @@ -0,0 +1,165 @@ +/* + * 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.
+ * TODO: better integrate JCR and Eclipse:
+ * - typing
+ * - use eclipse preferences
+ * - 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; + } + +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/model/RepositoriesElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/model/RepositoriesElem.java index 0f5ca6e3e..c0fc0c5e4 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/model/RepositoriesElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/model/RepositoriesElem.java @@ -25,8 +25,8 @@ import javax.jcr.RepositoryFactory; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/AbstractJcrQueryEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/AbstractJcrQueryEditor.java new file mode 100644 index 000000000..d16ff06bb --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/AbstractJcrQueryEditor.java @@ -0,0 +1,354 @@ +/* + * 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 tableViewerColumns = new ArrayList(); + 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 rows = new ArrayList(); + 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 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 rows = new ArrayList(); + RowIterator rit = queryResult.getRows(); + while (rit.hasNext()) { + rows.add(rit.nextRow()); + } + + // List elems = new ArrayList(); + // 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; + } +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ImportFileSystemWizard.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ImportFileSystemWizard.java index cded3a49d..ea3bf56c7 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ImportFileSystemWizard.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ImportFileSystemWizard.java @@ -28,9 +28,9 @@ import org.apache.commons.io.IOUtils; 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; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/JcrQueryEditorInput.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/JcrQueryEditorInput.java new file mode 100644 index 000000000..baa7e62c9 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/JcrQueryEditorInput.java @@ -0,0 +1,68 @@ +/* + * 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; + } + +} diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/NodeEditorInput.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/NodeEditorInput.java new file mode 100644 index 000000000..bdd4afa7a --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/NodeEditorInput.java @@ -0,0 +1,61 @@ +/* + * 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; + } +} diff --git a/org.argeo.eclipse.ui/bnd.bnd b/org.argeo.eclipse.ui/bnd.bnd index ca6aaf028..1c68f758d 100644 --- a/org.argeo.eclipse.ui/bnd.bnd +++ b/org.argeo.eclipse.ui/bnd.bnd @@ -1,15 +1,19 @@ -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,\ diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/ApplicationContextTracker.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/ApplicationContextTracker.java deleted file mode 100644 index 070c70826..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/ApplicationContextTracker.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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 static java.text.MessageFormat.format; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.util.tracker.ServiceTracker; -import org.springframework.context.ApplicationContext; - -/** - * Tracks Spring application context published as services. - * - * @author Heiko Seeberger - * @author Mathieu Baudier - */ -class ApplicationContextTracker { - private final static Log log = LogFactory - .getLog(ApplicationContextTracker.class); - - private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$ - + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$ - - public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout"; - - private static Long defaultTimeout = Long.parseLong(System.getProperty( - APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000")); - - private ServiceTracker applicationContextServiceTracker; - - /** - * @param contributorBundle - * OSGi bundle for which the Spring application context is to be - * tracked. Must not be null! - * @param factoryBundleContext - * BundleContext object which can be used to track services - * @throws IllegalArgumentException - * if the given bundle is null. - */ - public ApplicationContextTracker(final Bundle contributorBundle, - final BundleContext factoryBundleContext) { - final String filter = format(FILTER, - contributorBundle.getSymbolicName()); - try { - applicationContextServiceTracker = new ServiceTracker( - factoryBundleContext, FrameworkUtil.createFilter(filter), - null); - // applicationContextServiceTracker.open(); - } catch (final InvalidSyntaxException e) { - e.printStackTrace(); - } - } - - public void open() { - if (applicationContextServiceTracker != null) { - applicationContextServiceTracker.open(); - } - } - - public void close() { - if (applicationContextServiceTracker != null) { - applicationContextServiceTracker.close(); - } - } - - public ApplicationContext getApplicationContext() { - ApplicationContext applicationContext = null; - if (applicationContextServiceTracker != null) { - try { - applicationContext = (ApplicationContext) applicationContextServiceTracker - .waitForService(defaultTimeout); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - return applicationContext; - } - - @Override - protected void finalize() throws Throwable { - close(); - super.finalize(); - } - - static ApplicationContext getApplicationContext(String bundleSymbolicName) { - Bundle contributorBundle = Platform.getBundle(bundleSymbolicName); - return getApplicationContext(contributorBundle); - } - - static ApplicationContext getApplicationContext( - final Bundle contributorBundle) { - if (log.isTraceEnabled()) - log.trace("Get application context for bundle " + contributorBundle); - - // Start if not yet started (also if in STARTING state, may be lazy) - if (contributorBundle.getState() != Bundle.ACTIVE) { - if (log.isTraceEnabled()) - log.trace("Starting bundle: " - + contributorBundle.getSymbolicName()); - // Thread startBundle = new Thread("Start bundle " - // + contributorBundle.getSymbolicName()) { - // public void run() { - try { - contributorBundle.start(); - } catch (BundleException e) { - log.error("Cannot start bundle " + contributorBundle, e); - } - // } - // }; - // startBundle.start(); - // try { - // startBundle.join(10 * 1000l); - // } catch (InterruptedException e) { - // // silent - // } - } - - final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker( - contributorBundle, contributorBundle.getBundleContext()); - ApplicationContext applicationContext = null; - try { - applicationContextTracker.open(); - applicationContext = applicationContextTracker - .getApplicationContext(); - } finally { - applicationContextTracker.close(); - } - return applicationContext; - } -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringCommandHandler.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringCommandHandler.java deleted file mode 100644 index 4c7a152df..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringCommandHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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) { - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringExtensionFactory.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringExtensionFactory.java deleted file mode 100644 index 7a0486fd2..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/spring/SpringExtensionFactory.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.argeo.ArgeoException; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IExecutableExtensionFactory; -import org.eclipse.core.runtime.IExtension; -import org.springframework.context.ApplicationContext; - -/** - * The Spring Extension Factory builds a bridge between the Eclipse Extension - * Registry and the Spring Framework (especially Spring Dynamic Modules). - * - * It allows you to define your extension as a spring bean within the spring - * application context of your bundle. If you would like to use this bean as an - * instance of an extension (an Eclipse RCP view, for example) you define the - * extension with this spring extension factory as the class to be created. - * - * To let the spring extension factory pick the right bean from your application - * context you need to set the bean id to the same value as the id of the view - * within the view definition, for example. This is important if your extension - * definition contains more than one element, where each element has its own id. - * - * If the extension definition elements themselves have no id attribute the - * spring extension factory uses the id of the extension itself to identify the - * bean. - * - * original code from: Blog entry - * - * @author Martin Lippert - * @author mbaudier - */ -public class SpringExtensionFactory implements IExecutableExtensionFactory, - IExecutableExtension { - - private Object bean; - - public Object create() throws CoreException { - if (bean == null) - throw new ArgeoException("No underlying bean for extension"); - return bean; - } - - public void setInitializationData(IConfigurationElement config, - String propertyName, Object data) throws CoreException { - String bundleSymbolicName = config.getContributor().getName(); - ApplicationContext applicationContext = ApplicationContextTracker - .getApplicationContext(bundleSymbolicName); - if (applicationContext == null) - throw new ArgeoException( - "Cannot find application context for bundle " - + bundleSymbolicName); - - String beanName = getBeanName(data, config); - if (beanName == null) - throw new ArgeoException("Cannot find bean name for extension " - + config); - - if (!applicationContext.containsBean(beanName)) { - if (beanName.startsWith(bundleSymbolicName)) - beanName = beanName.substring(bundleSymbolicName.length() + 1); - } - - if (!applicationContext.containsBean(beanName)) - throw new ArgeoException("No bean with name '" + beanName + "'"); - - this.bean = applicationContext.getBean(beanName); - if (this.bean instanceof IExecutableExtension) { - ((IExecutableExtension) this.bean).setInitializationData(config, - propertyName, data); - } - } - - private String getBeanName(Object data, IConfigurationElement config) { - - // try the specific bean id the extension defines - if (data != null && data.toString().length() > 0) { - return data.toString(); - } - - // try the id of the config element - if (config.getAttribute("id") != null) { - return config.getAttribute("id"); - } - - // try the id of the extension element itself - if (config.getParent() != null - && config.getParent() instanceof IExtension) { - IExtension extensionDefinition = (IExtension) config.getParent(); - return extensionDefinition.getSimpleIdentifier(); - } - - return null; - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ArgeoUiPlugin.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ArgeoUiPlugin.java deleted file mode 100644 index 6befdf7d4..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ArgeoUiPlugin.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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()); - - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/Error.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/Error.java deleted file mode 100644 index 03b047001..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/Error.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ErrorFeedback.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ErrorFeedback.java deleted file mode 100644 index 895e8b866..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/ErrorFeedback.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrPreferenceStore.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrPreferenceStore.java deleted file mode 100644 index ef14d175e..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrPreferenceStore.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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.
- * TODO: better integrate JCR and Eclipse:
- * - typing
- * - use eclipse preferences
- * - 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; - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/AbstractJcrQueryEditor.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/AbstractJcrQueryEditor.java deleted file mode 100644 index 5e7d69644..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/AbstractJcrQueryEditor.java +++ /dev/null @@ -1,354 +0,0 @@ -/* - * 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 tableViewerColumns = new ArrayList(); - 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 rows = new ArrayList(); - 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 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 rows = new ArrayList(); - RowIterator rit = queryResult.getRows(); - while (rit.hasNext()) { - rows.add(rit.nextRow()); - } - - // List elems = new ArrayList(); - // 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; - } -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/JcrQueryEditorInput.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/JcrQueryEditorInput.java deleted file mode 100644 index eedccc85b..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/JcrQueryEditorInput.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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; - } - -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/NodeEditorInput.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/NodeEditorInput.java deleted file mode 100644 index a55884f2e..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/editors/NodeEditorInput.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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; - } -} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/utils/CommandUtils.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/utils/CommandUtils.java deleted file mode 100644 index 0979bace0..000000000 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/utils/CommandUtils.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 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 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 params = new HashMap(); - 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 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 parameters = null; - ParameterizedCommand pc; - - if (paramMap != null) { - // Set parameters of the command to launch : - parameters = new ArrayList(); - 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 diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java index a7437156d..0afc409bb 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java @@ -24,7 +24,7 @@ import javax.jcr.observation.EventIterator; 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; diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java index c2d041f56..df16aeab4 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java @@ -21,7 +21,7 @@ import javax.jcr.Session; 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; diff --git a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java index 288ca623b..a635de186 100644 --- a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java +++ b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java @@ -25,7 +25,7 @@ import javax.servlet.http.HttpSession; 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; diff --git a/org.argeo.security.ui/bnd.bnd b/org.argeo.security.ui/bnd.bnd index 176c72a71..6dbb1d4e4 100644 --- a/org.argeo.security.ui/bnd.bnd +++ b/org.argeo.security.ui/bnd.bnd @@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.ui;resolution:=optional,\ 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.*,\ diff --git a/org.argeo.security.ui/pom.xml b/org.argeo.security.ui/pom.xml index 848fc26c1..06778ec71 100644 --- a/org.argeo.security.ui/pom.xml +++ b/org.argeo.security.ui/pom.xml @@ -22,7 +22,7 @@ org.argeo.commons - org.argeo.eclipse.ui + org.argeo.eclipse.ui.workbench 2.1.12-SNAPSHOT diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java index d56498a15..6cc16c79a 100644 --- a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java +++ b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java @@ -15,7 +15,7 @@ */ 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; diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/dialogs/ChangePasswordDialog.java b/org.argeo.security.ui/src/org/argeo/security/ui/dialogs/ChangePasswordDialog.java index fe9b6ae9d..3e3af5bf6 100644 --- a/org.argeo.security.ui/src/org/argeo/security/ui/dialogs/ChangePasswordDialog.java +++ b/org.argeo.security.ui/src/org/argeo/security/ui/dialogs/ChangePasswordDialog.java @@ -16,7 +16,7 @@ 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;