From: Mathieu Baudier Date: Tue, 17 Jul 2012 12:29:27 +0000 (+0000) Subject: Move to Commons Base X-Git-Tag: argeo-commons-2.1.30~887 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=07b21659cba964ffdc81403718d0962c2d09175d;p=lgpl%2Fargeo-commons.git Move to Commons Base git-svn-id: https://svn.argeo.org/commons/trunk@5475 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/base/runtime/org.argeo.eclipse.ui/.classpath b/base/runtime/org.argeo.eclipse.ui/.classpath new file mode 100644 index 000000000..a50743442 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/.classpath @@ -0,0 +1,7 @@ + + + + > + + + diff --git a/base/runtime/org.argeo.eclipse.ui/.project b/base/runtime/org.argeo.eclipse.ui/.project new file mode 100644 index 000000000..53e9b324c --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/.project @@ -0,0 +1,28 @@ + + + org.argeo.eclipse.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..f441c9045 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Thu Jul 29 10:54:11 CEST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..8e36e3304 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +#Thu Jul 29 11:00:39 CEST 2010 +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/base/runtime/org.argeo.eclipse.ui/build.properties b/base/runtime/org.argeo.eclipse.ui/build.properties new file mode 100644 index 000000000..5fc538bc8 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + . diff --git a/base/runtime/org.argeo.eclipse.ui/pom.xml b/base/runtime/org.argeo.eclipse.ui/pom.xml new file mode 100644 index 000000000..1be829d4b --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + + org.argeo.commons.eclipse + 1.1.4-SNAPSHOT + runtime + .. + + org.argeo.eclipse.ui + Commons Eclipse UI + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + + + + ${project.artifactId};singleton:=true + lazy + org.argeo.eclipse.ui.ArgeoUiPlugin + org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime + + org.springframework.beans.factory, + org.springframework.core.io.support, + !org.eclipse.core.runtime, + !org.eclipse.core.commands, + !org.eclipse.ui.plugin, + * + + + + + + + + + + org.argeo.tp + javax.jcr + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rcp + 1.1.4-SNAPSHOT + provided + + + + + org.argeo.commons.basic + org.argeo.basic.nodeps + 1.1.4-SNAPSHOT + + + + + org.argeo.tp + org.springframework.context + + + org.argeo.tp + org.springframework.osgi.extender + + + + + org.argeo.tp + slf4j.org.apache.commons.logging + + + + \ No newline at end of file diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java new file mode 100644 index 000000000..fcd42bab6 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.spring; + +import 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(Bundle contributorBundle) { + if (log.isTraceEnabled()) + log.trace("Get application context for bundle " + contributorBundle); + + if (contributorBundle.getState() != Bundle.ACTIVE + && contributorBundle.getState() != Bundle.STARTING) { + try { + if (log.isTraceEnabled()) + log.trace("Starting bundle: " + + contributorBundle.getSymbolicName()); + contributorBundle.start(); + } catch (BundleException e) { + e.printStackTrace(); + } + } + + 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/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java new file mode 100644 index 000000000..dc045c982 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.spring; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.springframework.context.ApplicationContext; + +/** Allows to declare Eclipse commands as Spring beans */ +public class SpringCommandHandler implements IHandler { + private final static Log log = LogFactory + .getLog(SpringCommandHandler.class); + + public void addHandlerListener(IHandlerListener handlerListener) { + } + + public void dispose() { + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + String commandId = event.getCommand().getId(); + String bundleSymbolicName = commandId.substring(0, + commandId.lastIndexOf('.')); + try { + if (log.isTraceEnabled()) + log.trace("Execute " + event + " via spring command handler " + + this); + // TODO: make it more flexible and robust + ApplicationContext applicationContext = ApplicationContextTracker + .getApplicationContext(bundleSymbolicName); + if (applicationContext == null) + throw new ArgeoException("No application context found for " + + bundleSymbolicName); + + // retrieve the command via its id + String beanName = event.getCommand().getId(); + + if (!applicationContext.containsBean(beanName)) { + if (beanName.startsWith(bundleSymbolicName)) + beanName = beanName + .substring(bundleSymbolicName.length() + 1); + } + + if (!applicationContext.containsBean(beanName)) + throw new ExecutionException("No bean found with name " + + beanName + " in bundle " + bundleSymbolicName); + Object bean = applicationContext.getBean(beanName); + + if (!(bean instanceof IHandler)) + throw new ExecutionException("Bean with name " + beanName + + " and class " + bean.getClass() + + " does not implement the IHandler interface."); + + IHandler handler = (IHandler) bean; + return handler.execute(event); + } catch (Exception e) { + // TODO: use eclipse error management + // log.error(e); + throw new ExecutionException("Cannot execute Spring command " + + commandId + " in bundle " + bundleSymbolicName, e); + } + } + + public boolean isEnabled() { + return true; + } + + public boolean isHandled() { + return true; + } + + public void removeHandlerListener(IHandlerListener handlerListener) { + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java new file mode 100644 index 000000000..d8ec9d77a --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.spring; + +import org.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/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java new file mode 100644 index 000000000..a89fbccec --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Tree content provider dealing with tree objects and providing reasonable + * defaults. + */ +public abstract class AbstractTreeContentProvider implements + ITreeContentProvider { + + /** Does nothing */ + public void dispose() { + } + + /** Does nothing */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public Object[] getChildren(Object element) { + if (element instanceof TreeParent) { + return ((TreeParent) element).getChildren(); + } + return new Object[0]; + } + + public Object getParent(Object element) { + if (element instanceof TreeParent) { + return ((TreeParent) element).getParent(); + } + return null; + } + + public boolean hasChildren(Object element) { + if (element instanceof TreeParent) { + return ((TreeParent) element).hasChildren(); + } + return false; + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java new file mode 100644 index 000000000..d34deb0ea --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.core.runtime.ILogListener; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener { + public static final String PLUGIN_ID = "org.argeo.eclipse.ui"; + private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class); + // The shared instance + private static ArgeoUiPlugin plugin; + + public void start(BundleContext context) throws Exception { + super.start(context); + // weirdly, the start method is called twice... + if (plugin == null) { + plugin = this; + Platform.addLogListener(this); + log.debug("Eclipse logging now directed to standard logging"); + } + } + + public void stop(BundleContext context) throws Exception { + try { + // weirdly, the stop method is called twice... + if (plugin != null) { + Platform.removeLogListener(this); + log.debug("Eclipse logging not directed anymore to standard logging"); + plugin = null; + } + } finally { + super.stop(context); + } + } + + /** Returns the shared instance */ + public static ArgeoUiPlugin getDefault() { + return plugin; + } + + public void logging(IStatus status, String plugin) { + Log pluginLog = LogFactory.getLog(plugin); + Integer severity = status.getSeverity(); + if (severity == IStatus.ERROR) + pluginLog.error(status.getMessage(), status.getException()); + else if (severity == IStatus.WARNING) + pluginLog.warn(status.getMessage(), status.getException()); + else if (severity == IStatus.INFO) + pluginLog.info(status.getMessage(), status.getException()); + else if (severity == IStatus.CANCEL) + if (pluginLog.isDebugEnabled()) + pluginLog.debug(status.getMessage(), status.getException()); + + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java new file mode 100644 index 000000000..64edf72da --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import java.util.Comparator; + +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; + +/** Generic column viewer sortter */ +public class ColumnViewerComparator extends ViewerComparator { + public static final int ASC = 1; + + public static final int NONE = 0; + + public static final int DESC = -1; + + private int direction = 0; + + private TableViewerColumn column; + + private ColumnViewer viewer; + + public ColumnViewerComparator(TableViewerColumn column, + Comparator comparator) { + super(comparator); + this.column = column; + this.viewer = column.getViewer(); + this.column.getColumn().addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + if (ColumnViewerComparator.this.viewer.getComparator() != null) { + if (ColumnViewerComparator.this.viewer.getComparator() == ColumnViewerComparator.this) { + int tdirection = ColumnViewerComparator.this.direction; + + if (tdirection == ASC) { + setSortDirection(DESC); + } else if (tdirection == DESC) { + setSortDirection(NONE); + } + } else { + setSortDirection(ASC); + } + } else { + setSortDirection(ASC); + } + } + }); + } + + private void setSortDirection(int direction) { + if (direction == NONE) { + column.getColumn().getParent().setSortColumn(null); + column.getColumn().getParent().setSortDirection(SWT.NONE); + viewer.setComparator(null); + } else { + column.getColumn().getParent().setSortColumn(column.getColumn()); + this.direction = direction; + + if (direction == ASC) { + column.getColumn().getParent().setSortDirection(SWT.DOWN); + } else { + column.getColumn().getParent().setSortDirection(SWT.UP); + } + + if (viewer.getComparator() == this) { + viewer.refresh(); + } else { + viewer.setComparator(this); + } + + } + } + + @SuppressWarnings("unchecked") + public int compare(Viewer viewer, Object e1, Object e2) { + return direction * getComparator().compare((T) e1, (T) e2); + } +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java new file mode 100644 index 000000000..03d0c3883 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** Utilities to simplify UI development. */ +public class EclipseUiUtils { + /** + * Create a label and a text field for a grid layout, the text field grabing + * excess horizontal + * + * @param parent + * the parent composite + * @param label + * the lable to display + * @param modifyListener + * a {@link ModifyListener} to listen on events on the text, can + * be null + * @return the created text + * + * @deprecated use {@link #createGridLT(Composite, String)} instead + */ + @Deprecated + public static Text createGridLT(Composite parent, String label, + ModifyListener modifyListener) { + Label lbl = new Label(parent, SWT.LEAD); + lbl.setText(label); + lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + Text txt = new Text(parent, SWT.LEAD | SWT.BORDER); + txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (modifyListener != null) + txt.addModifyListener(modifyListener); + return txt; + } + + public static Text createGridLT(Composite parent, String label) { + return createGridLT(parent, label, null); + } + + /** + * Creates one label and a text field not editable with background color of + * the parent (like a label but with selectable text) + */ + public static Text createGridLL(Composite parent, String label, String text) { + Text txt = createGridLT(parent, label); + txt.setText(text); + txt.setEditable(false); + txt.setBackground(parent.getBackground()); + return txt; + } + + public static Text createGridLP(Composite parent, String label, + ModifyListener modifyListener) { + Label lbl = new Label(parent, SWT.LEAD); + lbl.setText(label); + lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD); + txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (txt != null) + txt.addModifyListener(modifyListener); + return txt; + } + + public static Font getItalicFont(Composite parent) { + return JFaceResources.getFontRegistry().defaultFontDescriptor() + .setStyle(SWT.ITALIC).createFont(parent.getDisplay()); + } + + public static Font getBoldFont(Composite parent) { + return JFaceResources.getFontRegistry().defaultFontDescriptor() + .setStyle(SWT.BOLD).createFont(parent.getDisplay()); + } + + public static Font getBoldItalicFont(Composite parent) { + return JFaceResources.getFontRegistry().defaultFontDescriptor() + .setStyle(SWT.BOLD | SWT.ITALIC) + .createFont(parent.getDisplay()); + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java new file mode 100644 index 000000000..d35c699aa --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import org.eclipse.swt.widgets.Shell; + +/** + * @deprecated deprecated because of poor naming, use {@link ErrorFeedback} + * instead + */ +@Deprecated +public class Error extends ErrorFeedback { + + public Error(Shell parentShell, String message, Throwable e) { + super(parentShell, message, e); + // TODO Auto-generated constructor stub + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java new file mode 100644 index 000000000..618d708cc --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +/** Generic error dialog to be used in try/catch blocks */ +public class ErrorFeedback extends TitleAreaDialog { + private final static Log log = LogFactory.getLog(ErrorFeedback.class); + + private final String message; + private final Throwable exception; + + public static void show(String message, Throwable e) { + // rethrow ThreaDeath in order to make sure that RAP will properly clean + // up the UI thread + if (e instanceof ThreadDeath) + throw (ThreadDeath) e; + + new ErrorFeedback(getDisplay().getActiveShell(), message, e).open(); + } + + public static void show(String message) { + new ErrorFeedback(getDisplay().getActiveShell(), message, null).open(); + } + + /** Tries to find a display */ + private static Display getDisplay() { + try { + Display display = PlatformUI.getWorkbench().getDisplay(); + if (display != null) + return display; + else + return Display.getDefault(); + } catch (Exception e) { + return Display.getCurrent(); + } + } + + public ErrorFeedback(Shell parentShell, String message, Throwable e) { + super(parentShell); + this.message = message; + this.exception = e; + log.error(message, e); + } + + protected Point getInitialSize() { + if (exception != null) + return new Point(800, 600); + else + return new Point(400, 300); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite dialogarea = (Composite) super.createDialogArea(parent); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + setMessage(message != null ? message + + (exception != null ? ": " + exception.getMessage() : "") + : exception != null ? exception.getMessage() : "Unkown Error", + IMessageProvider.ERROR); + + if (exception != null) { + Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER + | SWT.V_SCROLL | SWT.H_SCROLL); + stack.setEditable(false); + stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + stack.setText(sw.toString()); + } + + parent.pack(); + return composite; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Error"); + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java new file mode 100644 index 000000000..fabeb5d88 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; + +public abstract class GenericTableComparator extends ViewerComparator { + + protected int propertyIndex; + public static final int ASCENDING = 0, DESCENDING = 1; + protected int direction = DESCENDING; + + /** + * Creates an instance of a sorter for TableViewer. + * + * @param defaultColumn + * the default sorter column + */ + + public GenericTableComparator(int defaultColumnIndex, int direction) { + propertyIndex = defaultColumnIndex; + this.direction = direction; + } + + public void setColumn(int column) { + if (column == this.propertyIndex) { + // Same column as last sort; toggle the direction + direction = 1 - direction; + } else { + // New column; do a descending sort + this.propertyIndex = column; + direction = DESCENDING; + } + } + + /** + * Must be Overriden in each view. + */ + public abstract int compare(Viewer viewer, Object e1, Object e2); +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java new file mode 100644 index 000000000..26bdbe615 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui; + +import java.util.ArrayList; +import java.util.List; + +/** Parent / children semantic to be used for simple UI Tree structure */ +public class TreeParent { + private String name; + private TreeParent parent; + + private List children; + + /** False until at least one child has been added, then true until cleared */ + private boolean loaded = false; + + public TreeParent(String name) { + this.name = name; + children = new ArrayList(); + } + + public synchronized void addChild(Object child) { + loaded = true; + children.add(child); + if (child instanceof TreeParent) + ((TreeParent) child).setParent(this); + } + + /** + * Remove this child. The child is disposed. + */ + public synchronized void removeChild(Object child) { + children.remove(child); + if (child instanceof TreeParent) { + ((TreeParent) child).dispose(); + } + } + + public synchronized void clearChildren() { + for (Object obj : children) { + if (obj instanceof TreeParent) + ((TreeParent) obj).dispose(); + } + loaded = false; + children.clear(); + } + + /** + * If overridden, super.dispose() must be called, typically + * after custom cleaning. + */ + public synchronized void dispose() { + clearChildren(); + parent = null; + children = null; + } + + public synchronized Object[] getChildren() { + return children.toArray(new Object[children.size()]); + } + + @SuppressWarnings("unchecked") + public synchronized List getChildrenOfType(Class clss) { + List lst = new ArrayList(); + for (Object obj : children) { + if (clss.isAssignableFrom(obj.getClass())) + lst.add((T) obj); + } + return lst; + } + + public synchronized boolean hasChildren() { + return children.size() > 0; + } + + public Object getChildByName(String name) { + for (Object child : children) { + if (child.toString().equals(name)) + return child; + } + return null; + } + + public synchronized Boolean isLoaded() { + return loaded; + } + + public String getName() { + return name; + } + + public void setParent(TreeParent parent) { + this.parent = parent; + } + + public TreeParent getParent() { + return parent; + } + + public String toString() { + return getName(); + } + + public int compareTo(TreeParent o) { + return name.compareTo(o.name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return name.equals(obj.toString()); + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java new file mode 100644 index 000000000..b5b50b114 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.dialogs; + +import org.eclipse.swt.widgets.Shell; + +/** + * Generic error dialog to be used in try/catch blocks + * + * @deprecated use {@link org.argeo.eclipse.ui.ErrorFeedback} instead. + */ +public class Error extends org.argeo.eclipse.ui.ErrorFeedback { + public Error(Shell parentShell, String message, Throwable e) { + super(parentShell, message, e); + } +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java new file mode 100644 index 000000000..5c27b0644 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.dialogs; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** Dialog retrieve a single value. */ +public class SingleValue extends TitleAreaDialog { + private Text valueT; + private String value; + private final String title, message, label; + private final Boolean multiline; + + public static String ask(String label, String message) { + SingleValue svd = new SingleValue(label, message); + if (svd.open() == Dialog.OK) + return svd.getString(); + else + return null; + } + + public static Long askLong(String label, String message) { + SingleValue svd = new SingleValue(label, message); + if (svd.open() == Dialog.OK) + return svd.getLong(); + else + return null; + } + + public static Double askDouble(String label, String message) { + SingleValue svd = new SingleValue(label, message); + if (svd.open() == Dialog.OK) + return svd.getDouble(); + else + return null; + } + + public SingleValue(String label, String message) { + this(Display.getDefault().getActiveShell(), label, message, label, + false); + } + + public SingleValue(Shell parentShell, String title, String message, + String label, Boolean multiline) { + super(parentShell); + this.title = title; + this.message = message; + this.label = label; + this.multiline = multiline; + } + + protected Point getInitialSize() { + return new Point(300, 250); + } + + protected Control createDialogArea(Composite parent) { + Composite dialogarea = (Composite) super.createDialogArea(parent); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + valueT = createLT(composite, label); + + setMessage(message, IMessageProvider.NONE); + + parent.pack(); + return composite; + } + + @Override + protected void okPressed() { + value = valueT.getText(); + super.okPressed(); + } + + /** Creates label and text. */ + protected Text createLT(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER + | (multiline ? SWT.MULTI : SWT.NONE)); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + return text; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(title); + } + + public String getString() { + return value; + } + + public Long getLong() { + return Long.valueOf(getString()); + } + + public Double getDouble() { + return Double.valueOf(getString()); + } +} diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java new file mode 100644 index 000000000..eb0de934f --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.utils; + +import java.util.ArrayList; + +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.ArgeoUiPlugin; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; + +/** + * Centralizes useful and generic methods concerning eclipse commands. + * + */ +public class CommandUtils { + + /** + * Factorizes command call that is quite verbose and always the same + * + * NOTE that none of the parameter can be null + */ + public static void CallCommandWithOneParameter(String commandId, + String paramId, String paramValue) { + try { + IWorkbench iw = ArgeoUiPlugin.getDefault().getWorkbench(); + + IHandlerService handlerService = (IHandlerService) iw + .getService(IHandlerService.class); + + // get the command from plugin.xml + IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); + ICommandService cmdService = (ICommandService) window + .getService(ICommandService.class); + + Command cmd = cmdService.getCommand(commandId); + + ArrayList parameters = new ArrayList(); + + // get the parameter + IParameter iparam = cmd.getParameter(paramId); + + Parameterization params = new Parameterization(iparam, paramValue); + parameters.add(params); + + // build the parameterized command + ParameterizedCommand pc = new ParameterizedCommand(cmd, + parameters.toArray(new Parameterization[parameters.size()])); + + // execute the command + handlerService = (IHandlerService) window + .getService(IHandlerService.class); + handlerService.executeCommand(pc, null); + } catch (Exception e) { + throw new ArgeoException("Error while calling command of id :" + + commandId, e); + } + } +} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.classpath b/eclipse/runtime/org.argeo.eclipse.ui/.classpath deleted file mode 100644 index a50743442..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - > - - - diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.project b/eclipse/runtime/org.argeo.eclipse.ui/.project deleted file mode 100644 index 53e9b324c..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.eclipse.ui - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs b/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index f441c9045..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Thu Jul 29 10:54:11 CEST 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs b/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index 8e36e3304..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Jul 29 11:00:39 CEST 2010 -eclipse.preferences.version=1 -resolve.requirebundle=false diff --git a/eclipse/runtime/org.argeo.eclipse.ui/build.properties b/eclipse/runtime/org.argeo.eclipse.ui/build.properties deleted file mode 100644 index 5fc538bc8..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = META-INF/,\ - . diff --git a/eclipse/runtime/org.argeo.eclipse.ui/pom.xml b/eclipse/runtime/org.argeo.eclipse.ui/pom.xml deleted file mode 100644 index 1be829d4b..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - 4.0.0 - - org.argeo.commons.eclipse - 1.1.4-SNAPSHOT - runtime - .. - - org.argeo.eclipse.ui - Commons Eclipse UI - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - - - - ${project.artifactId};singleton:=true - lazy - org.argeo.eclipse.ui.ArgeoUiPlugin - org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime - - org.springframework.beans.factory, - org.springframework.core.io.support, - !org.eclipse.core.runtime, - !org.eclipse.core.commands, - !org.eclipse.ui.plugin, - * - - - - - - - - - - org.argeo.tp - javax.jcr - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rcp - 1.1.4-SNAPSHOT - provided - - - - - org.argeo.commons.basic - org.argeo.basic.nodeps - 1.1.4-SNAPSHOT - - - - - org.argeo.tp - org.springframework.context - - - org.argeo.tp - org.springframework.osgi.extender - - - - - org.argeo.tp - slf4j.org.apache.commons.logging - - - - \ No newline at end of file diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java deleted file mode 100644 index fcd42bab6..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.spring; - -import 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(Bundle contributorBundle) { - if (log.isTraceEnabled()) - log.trace("Get application context for bundle " + contributorBundle); - - if (contributorBundle.getState() != Bundle.ACTIVE - && contributorBundle.getState() != Bundle.STARTING) { - try { - if (log.isTraceEnabled()) - log.trace("Starting bundle: " - + contributorBundle.getSymbolicName()); - contributorBundle.start(); - } catch (BundleException e) { - e.printStackTrace(); - } - } - - 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/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java deleted file mode 100644 index dc045c982..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.spring; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.commands.IHandlerListener; -import org.springframework.context.ApplicationContext; - -/** Allows to declare Eclipse commands as Spring beans */ -public class SpringCommandHandler implements IHandler { - private final static Log log = LogFactory - .getLog(SpringCommandHandler.class); - - public void addHandlerListener(IHandlerListener handlerListener) { - } - - public void dispose() { - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - String commandId = event.getCommand().getId(); - String bundleSymbolicName = commandId.substring(0, - commandId.lastIndexOf('.')); - try { - if (log.isTraceEnabled()) - log.trace("Execute " + event + " via spring command handler " - + this); - // TODO: make it more flexible and robust - ApplicationContext applicationContext = ApplicationContextTracker - .getApplicationContext(bundleSymbolicName); - if (applicationContext == null) - throw new ArgeoException("No application context found for " - + bundleSymbolicName); - - // retrieve the command via its id - String beanName = event.getCommand().getId(); - - if (!applicationContext.containsBean(beanName)) { - if (beanName.startsWith(bundleSymbolicName)) - beanName = beanName - .substring(bundleSymbolicName.length() + 1); - } - - if (!applicationContext.containsBean(beanName)) - throw new ExecutionException("No bean found with name " - + beanName + " in bundle " + bundleSymbolicName); - Object bean = applicationContext.getBean(beanName); - - if (!(bean instanceof IHandler)) - throw new ExecutionException("Bean with name " + beanName - + " and class " + bean.getClass() - + " does not implement the IHandler interface."); - - IHandler handler = (IHandler) bean; - return handler.execute(event); - } catch (Exception e) { - // TODO: use eclipse error management - // log.error(e); - throw new ExecutionException("Cannot execute Spring command " - + commandId + " in bundle " + bundleSymbolicName, e); - } - } - - public boolean isEnabled() { - return true; - } - - public boolean isHandled() { - return true; - } - - public void removeHandlerListener(IHandlerListener handlerListener) { - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java deleted file mode 100644 index d8ec9d77a..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.spring; - -import org.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/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java deleted file mode 100644 index a89fbccec..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/AbstractTreeContentProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * Tree content provider dealing with tree objects and providing reasonable - * defaults. - */ -public abstract class AbstractTreeContentProvider implements - ITreeContentProvider { - - /** Does nothing */ - public void dispose() { - } - - /** Does nothing */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public Object[] getChildren(Object element) { - if (element instanceof TreeParent) { - return ((TreeParent) element).getChildren(); - } - return new Object[0]; - } - - public Object getParent(Object element) { - if (element instanceof TreeParent) { - return ((TreeParent) element).getParent(); - } - return null; - } - - public boolean hasChildren(Object element) { - if (element instanceof TreeParent) { - return ((TreeParent) element).hasChildren(); - } - return false; - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java deleted file mode 100644 index d34deb0ea..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ArgeoUiPlugin.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.core.runtime.ILogListener; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class ArgeoUiPlugin extends AbstractUIPlugin implements ILogListener { - public static final String PLUGIN_ID = "org.argeo.eclipse.ui"; - private final static Log log = LogFactory.getLog(ArgeoUiPlugin.class); - // The shared instance - private static ArgeoUiPlugin plugin; - - public void start(BundleContext context) throws Exception { - super.start(context); - // weirdly, the start method is called twice... - if (plugin == null) { - plugin = this; - Platform.addLogListener(this); - log.debug("Eclipse logging now directed to standard logging"); - } - } - - public void stop(BundleContext context) throws Exception { - try { - // weirdly, the stop method is called twice... - if (plugin != null) { - Platform.removeLogListener(this); - log.debug("Eclipse logging not directed anymore to standard logging"); - plugin = null; - } - } finally { - super.stop(context); - } - } - - /** Returns the shared instance */ - public static ArgeoUiPlugin getDefault() { - return plugin; - } - - public void logging(IStatus status, String plugin) { - Log pluginLog = LogFactory.getLog(plugin); - Integer severity = status.getSeverity(); - if (severity == IStatus.ERROR) - pluginLog.error(status.getMessage(), status.getException()); - else if (severity == IStatus.WARNING) - pluginLog.warn(status.getMessage(), status.getException()); - else if (severity == IStatus.INFO) - pluginLog.info(status.getMessage(), status.getException()); - else if (severity == IStatus.CANCEL) - if (pluginLog.isDebugEnabled()) - pluginLog.debug(status.getMessage(), status.getException()); - - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java deleted file mode 100644 index 64edf72da..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ColumnViewerComparator.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import java.util.Comparator; - -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; - -/** Generic column viewer sortter */ -public class ColumnViewerComparator extends ViewerComparator { - public static final int ASC = 1; - - public static final int NONE = 0; - - public static final int DESC = -1; - - private int direction = 0; - - private TableViewerColumn column; - - private ColumnViewer viewer; - - public ColumnViewerComparator(TableViewerColumn column, - Comparator comparator) { - super(comparator); - this.column = column; - this.viewer = column.getViewer(); - this.column.getColumn().addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - if (ColumnViewerComparator.this.viewer.getComparator() != null) { - if (ColumnViewerComparator.this.viewer.getComparator() == ColumnViewerComparator.this) { - int tdirection = ColumnViewerComparator.this.direction; - - if (tdirection == ASC) { - setSortDirection(DESC); - } else if (tdirection == DESC) { - setSortDirection(NONE); - } - } else { - setSortDirection(ASC); - } - } else { - setSortDirection(ASC); - } - } - }); - } - - private void setSortDirection(int direction) { - if (direction == NONE) { - column.getColumn().getParent().setSortColumn(null); - column.getColumn().getParent().setSortDirection(SWT.NONE); - viewer.setComparator(null); - } else { - column.getColumn().getParent().setSortColumn(column.getColumn()); - this.direction = direction; - - if (direction == ASC) { - column.getColumn().getParent().setSortDirection(SWT.DOWN); - } else { - column.getColumn().getParent().setSortDirection(SWT.UP); - } - - if (viewer.getComparator() == this) { - viewer.refresh(); - } else { - viewer.setComparator(this); - } - - } - } - - @SuppressWarnings("unchecked") - public int compare(Viewer viewer, Object e1, Object e2) { - return direction * getComparator().compare((T) e1, (T) e2); - } -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java deleted file mode 100644 index 03d0c3883..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -/** Utilities to simplify UI development. */ -public class EclipseUiUtils { - /** - * Create a label and a text field for a grid layout, the text field grabing - * excess horizontal - * - * @param parent - * the parent composite - * @param label - * the lable to display - * @param modifyListener - * a {@link ModifyListener} to listen on events on the text, can - * be null - * @return the created text - * - * @deprecated use {@link #createGridLT(Composite, String)} instead - */ - @Deprecated - public static Text createGridLT(Composite parent, String label, - ModifyListener modifyListener) { - Label lbl = new Label(parent, SWT.LEAD); - lbl.setText(label); - lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - Text txt = new Text(parent, SWT.LEAD | SWT.BORDER); - txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - if (modifyListener != null) - txt.addModifyListener(modifyListener); - return txt; - } - - public static Text createGridLT(Composite parent, String label) { - return createGridLT(parent, label, null); - } - - /** - * Creates one label and a text field not editable with background color of - * the parent (like a label but with selectable text) - */ - public static Text createGridLL(Composite parent, String label, String text) { - Text txt = createGridLT(parent, label); - txt.setText(text); - txt.setEditable(false); - txt.setBackground(parent.getBackground()); - return txt; - } - - public static Text createGridLP(Composite parent, String label, - ModifyListener modifyListener) { - Label lbl = new Label(parent, SWT.LEAD); - lbl.setText(label); - lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD); - txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - if (txt != null) - txt.addModifyListener(modifyListener); - return txt; - } - - public static Font getItalicFont(Composite parent) { - return JFaceResources.getFontRegistry().defaultFontDescriptor() - .setStyle(SWT.ITALIC).createFont(parent.getDisplay()); - } - - public static Font getBoldFont(Composite parent) { - return JFaceResources.getFontRegistry().defaultFontDescriptor() - .setStyle(SWT.BOLD).createFont(parent.getDisplay()); - } - - public static Font getBoldItalicFont(Composite parent) { - return JFaceResources.getFontRegistry().defaultFontDescriptor() - .setStyle(SWT.BOLD | SWT.ITALIC) - .createFont(parent.getDisplay()); - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java deleted file mode 100644 index d35c699aa..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/Error.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import org.eclipse.swt.widgets.Shell; - -/** - * @deprecated deprecated because of poor naming, use {@link ErrorFeedback} - * instead - */ -@Deprecated -public class Error extends ErrorFeedback { - - public Error(Shell parentShell, String message, Throwable e) { - super(parentShell, message, e); - // TODO Auto-generated constructor stub - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java deleted file mode 100644 index 618d708cc..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; - -/** Generic error dialog to be used in try/catch blocks */ -public class ErrorFeedback extends TitleAreaDialog { - private final static Log log = LogFactory.getLog(ErrorFeedback.class); - - private final String message; - private final Throwable exception; - - public static void show(String message, Throwable e) { - // rethrow ThreaDeath in order to make sure that RAP will properly clean - // up the UI thread - if (e instanceof ThreadDeath) - throw (ThreadDeath) e; - - new ErrorFeedback(getDisplay().getActiveShell(), message, e).open(); - } - - public static void show(String message) { - new ErrorFeedback(getDisplay().getActiveShell(), message, null).open(); - } - - /** Tries to find a display */ - private static Display getDisplay() { - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - if (display != null) - return display; - else - return Display.getDefault(); - } catch (Exception e) { - return Display.getCurrent(); - } - } - - public ErrorFeedback(Shell parentShell, String message, Throwable e) { - super(parentShell); - this.message = message; - this.exception = e; - log.error(message, e); - } - - protected Point getInitialSize() { - if (exception != null) - return new Point(800, 600); - else - return new Point(400, 300); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite dialogarea = (Composite) super.createDialogArea(parent); - dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - Composite composite = new Composite(dialogarea, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - setMessage(message != null ? message - + (exception != null ? ": " + exception.getMessage() : "") - : exception != null ? exception.getMessage() : "Unkown Error", - IMessageProvider.ERROR); - - if (exception != null) { - Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER - | SWT.V_SCROLL | SWT.H_SCROLL); - stack.setEditable(false); - stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - StringWriter sw = new StringWriter(); - exception.printStackTrace(new PrintWriter(sw)); - stack.setText(sw.toString()); - } - - parent.pack(); - return composite; - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText("Error"); - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java deleted file mode 100644 index fabeb5d88..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; - -public abstract class GenericTableComparator extends ViewerComparator { - - protected int propertyIndex; - public static final int ASCENDING = 0, DESCENDING = 1; - protected int direction = DESCENDING; - - /** - * Creates an instance of a sorter for TableViewer. - * - * @param defaultColumn - * the default sorter column - */ - - public GenericTableComparator(int defaultColumnIndex, int direction) { - propertyIndex = defaultColumnIndex; - this.direction = direction; - } - - public void setColumn(int column) { - if (column == this.propertyIndex) { - // Same column as last sort; toggle the direction - direction = 1 - direction; - } else { - // New column; do a descending sort - this.propertyIndex = column; - direction = DESCENDING; - } - } - - /** - * Must be Overriden in each view. - */ - public abstract int compare(Viewer viewer, Object e1, Object e2); -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java deleted file mode 100644 index 26bdbe615..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui; - -import java.util.ArrayList; -import java.util.List; - -/** Parent / children semantic to be used for simple UI Tree structure */ -public class TreeParent { - private String name; - private TreeParent parent; - - private List children; - - /** False until at least one child has been added, then true until cleared */ - private boolean loaded = false; - - public TreeParent(String name) { - this.name = name; - children = new ArrayList(); - } - - public synchronized void addChild(Object child) { - loaded = true; - children.add(child); - if (child instanceof TreeParent) - ((TreeParent) child).setParent(this); - } - - /** - * Remove this child. The child is disposed. - */ - public synchronized void removeChild(Object child) { - children.remove(child); - if (child instanceof TreeParent) { - ((TreeParent) child).dispose(); - } - } - - public synchronized void clearChildren() { - for (Object obj : children) { - if (obj instanceof TreeParent) - ((TreeParent) obj).dispose(); - } - loaded = false; - children.clear(); - } - - /** - * If overridden, super.dispose() must be called, typically - * after custom cleaning. - */ - public synchronized void dispose() { - clearChildren(); - parent = null; - children = null; - } - - public synchronized Object[] getChildren() { - return children.toArray(new Object[children.size()]); - } - - @SuppressWarnings("unchecked") - public synchronized List getChildrenOfType(Class clss) { - List lst = new ArrayList(); - for (Object obj : children) { - if (clss.isAssignableFrom(obj.getClass())) - lst.add((T) obj); - } - return lst; - } - - public synchronized boolean hasChildren() { - return children.size() > 0; - } - - public Object getChildByName(String name) { - for (Object child : children) { - if (child.toString().equals(name)) - return child; - } - return null; - } - - public synchronized Boolean isLoaded() { - return loaded; - } - - public String getName() { - return name; - } - - public void setParent(TreeParent parent) { - this.parent = parent; - } - - public TreeParent getParent() { - return parent; - } - - public String toString() { - return getName(); - } - - public int compareTo(TreeParent o) { - return name.compareTo(o.name); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(Object obj) { - return name.equals(obj.toString()); - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java deleted file mode 100644 index b5b50b114..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.dialogs; - -import org.eclipse.swt.widgets.Shell; - -/** - * Generic error dialog to be used in try/catch blocks - * - * @deprecated use {@link org.argeo.eclipse.ui.ErrorFeedback} instead. - */ -public class Error extends org.argeo.eclipse.ui.ErrorFeedback { - public Error(Shell parentShell, String message, Throwable e) { - super(parentShell, message, e); - } -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java deleted file mode 100644 index 5c27b0644..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.dialogs; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** Dialog retrieve a single value. */ -public class SingleValue extends TitleAreaDialog { - private Text valueT; - private String value; - private final String title, message, label; - private final Boolean multiline; - - public static String ask(String label, String message) { - SingleValue svd = new SingleValue(label, message); - if (svd.open() == Dialog.OK) - return svd.getString(); - else - return null; - } - - public static Long askLong(String label, String message) { - SingleValue svd = new SingleValue(label, message); - if (svd.open() == Dialog.OK) - return svd.getLong(); - else - return null; - } - - public static Double askDouble(String label, String message) { - SingleValue svd = new SingleValue(label, message); - if (svd.open() == Dialog.OK) - return svd.getDouble(); - else - return null; - } - - public SingleValue(String label, String message) { - this(Display.getDefault().getActiveShell(), label, message, label, - false); - } - - public SingleValue(Shell parentShell, String title, String message, - String label, Boolean multiline) { - super(parentShell); - this.title = title; - this.message = message; - this.label = label; - this.multiline = multiline; - } - - protected Point getInitialSize() { - return new Point(300, 250); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogarea = (Composite) super.createDialogArea(parent); - dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - Composite composite = new Composite(dialogarea, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - valueT = createLT(composite, label); - - setMessage(message, IMessageProvider.NONE); - - parent.pack(); - return composite; - } - - @Override - protected void okPressed() { - value = valueT.getText(); - super.okPressed(); - } - - /** Creates label and text. */ - protected Text createLT(Composite parent, String label) { - new Label(parent, SWT.NONE).setText(label); - Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER - | (multiline ? SWT.MULTI : SWT.NONE)); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return text; - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(title); - } - - public String getString() { - return value; - } - - public Long getLong() { - return Long.valueOf(getString()); - } - - public Double getDouble() { - return Double.valueOf(getString()); - } -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java b/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java deleted file mode 100644 index eb0de934f..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.utils; - -import java.util.ArrayList; - -import org.argeo.ArgeoException; -import org.argeo.eclipse.ui.ArgeoUiPlugin; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.IParameter; -import org.eclipse.core.commands.Parameterization; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; - -/** - * Centralizes useful and generic methods concerning eclipse commands. - * - */ -public class CommandUtils { - - /** - * Factorizes command call that is quite verbose and always the same - * - * NOTE that none of the parameter can be null - */ - public static void CallCommandWithOneParameter(String commandId, - String paramId, String paramValue) { - try { - IWorkbench iw = ArgeoUiPlugin.getDefault().getWorkbench(); - - IHandlerService handlerService = (IHandlerService) iw - .getService(IHandlerService.class); - - // get the command from plugin.xml - IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); - ICommandService cmdService = (ICommandService) window - .getService(ICommandService.class); - - Command cmd = cmdService.getCommand(commandId); - - ArrayList parameters = new ArrayList(); - - // get the parameter - IParameter iparam = cmd.getParameter(paramId); - - Parameterization params = new Parameterization(iparam, paramValue); - parameters.add(params); - - // build the parameterized command - ParameterizedCommand pc = new ParameterizedCommand(cmd, - parameters.toArray(new Parameterization[parameters.size()])); - - // execute the command - handlerService = (IHandlerService) window - .getService(IHandlerService.class); - handlerService.executeCommand(pc, null); - } catch (Exception e) { - throw new ArgeoException("Error while calling command of id :" - + commandId, e); - } - } -}