diff options
author | Thomas Schindl | 2010-06-03 16:13:16 +0000 |
---|---|---|
committer | Thomas Schindl | 2010-06-03 16:13:16 +0000 |
commit | c70e267c2049bfbed4a2f4252174eb70bea5609f (patch) | |
tree | f19b0ef76357fed9117d63deb13510897d4e01fc | |
parent | 287e35bb716ca5112ae7a4bc1acb2651af78912f (diff) | |
download | org.eclipse.e4.tools-c70e267c2049bfbed4a2f4252174eb70bea5609f.tar.gz org.eclipse.e4.tools-c70e267c2049bfbed4a2f4252174eb70bea5609f.tar.xz org.eclipse.e4.tools-c70e267c2049bfbed4a2f4252174eb70bea5609f.zip |
Bug 304584 - [Tooling] Implement Workbench-Model-Tooling
* factoring compat stuff
22 files changed, 844 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.compat/.classpath b/bundles/org.eclipse.e4.tools.compat/.classpath new file mode 100644 index 00000000..64c5e31b --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/bundles/org.eclipse.e4.tools.compat/.project b/bundles/org.eclipse.e4.tools.compat/.project new file mode 100644 index 00000000..e5e9a152 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.e4.tools.compat</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bundles/org.eclipse.e4.tools.compat/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.e4.tools.compat/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..4fe42718 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon May 31 09:52:05 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/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF new file mode 100644 index 00000000..6e43c8a7 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Compat +Bundle-SymbolicName: org.eclipse.e4.tools.compat;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.ui;bundle-version="3.6.0", + org.eclipse.core.runtime;bundle-version="3.6.0", + org.eclipse.e4.core.contexts;bundle-version="0.9.0", + org.eclipse.e4.core.services;bundle-version="0.9.1", + org.eclipse.e4.ui.services;bundle-version="0.9.1", + org.eclipse.e4.core.di;bundle-version="0.9.0", + org.eclipse.e4.tools.services;bundle-version="1.0.0", + org.eclipse.e4.ui.css.swt.theme;bundle-version="0.9.0" +Service-Component: OSGI-INF/selectionproviderfunction.xml +Export-Package: org.eclipse.e4.tools.compat.parts diff --git a/bundles/org.eclipse.e4.tools.compat/OSGI-INF/selectionproviderfunction.xml b/bundles/org.eclipse.e4.tools.compat/OSGI-INF/selectionproviderfunction.xml new file mode 100644 index 00000000..87903087 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/OSGI-INF/selectionproviderfunction.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.e4.tools.compat"> + <implementation class="org.eclipse.e4.tools.compat.internal.SelectionProviderContextFunction"/> + <service> + <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/> + </service> + <property name="service.context.key" type="String" value="org.eclipse.e4.tools.services.ISelectionProviderService"/> +</scr:component>
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.compat/build.properties b/bundles/org.eclipse.e4.tools.compat/build.properties new file mode 100644 index 00000000..4975ca25 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/selectionproviderfunction.xml +source.. = src/ diff --git a/bundles/org.eclipse.e4.tools.compat/plugin.xml b/bundles/org.eclipse.e4.tools.compat/plugin.xml new file mode 100644 index 00000000..a8396863 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/plugin.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.ui.services"> + <serviceFactory + factoryClass="org.eclipse.e4.tools.compat.internal.ContextServiceFactory"> + <service + serviceClass="org.eclipse.e4.core.contexts.IEclipseContext"></service> + </serviceFactory> + </extension> + +</plugin> diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java new file mode 100644 index 00000000..480448e4 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.internal; + +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.RegistryFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.contributions.IContributionFactory; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.internal.services.IWorkbenchLocationService; +import org.eclipse.ui.services.AbstractServiceFactory; +import org.eclipse.ui.services.IServiceLocator; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; + +@SuppressWarnings("restriction") +public class ContextServiceFactory extends AbstractServiceFactory { + + @Override + public Object create(Class serviceInterface, IServiceLocator parentLocator, + IServiceLocator locator) { + if( ! IEclipseContext.class.equals(serviceInterface) ) { + return null; + } + + + IWorkbenchLocationService wls = (IWorkbenchLocationService) locator.getService(IWorkbenchLocationService.class); + final IWorkbenchWindow window = wls.getWorkbenchWindow(); + final IWorkbenchPartSite site = wls.getPartSite(); + +// System.err.println("The locator: " + locator); +// System.err.println(" Window: " + window); +// System.err.println(" Site: " + site); + + Object o = parentLocator.getService(serviceInterface); + + // This happens when we run in plain 3.x + // We need to create a parent service context + if( window == null && site == null ) { + Bundle bundle = FrameworkUtil.getBundle(ContextServiceFactory.class); + BundleContext bundleContext = bundle.getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext); + + final IEclipseContext appContext = serviceContext.createChild("WorkbenchContext"); //$NON-NLS-1$ + IExtensionRegistry registry = RegistryFactory.getRegistry(); + ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(registry); + appContext.set(IContributionFactory.class.getName(),contributionFactory); + + return appContext; + } else if( o != null && site == null ) { + final IEclipseContext windowContext = ((IEclipseContext)o).createChild("WindowContext("+window+")"); + windowContext.set(ISelectionService.class, window.getSelectionService()); + windowContext.declareModifiable(IServiceConstants.SELECTION); + + window.getSelectionService().addSelectionListener(new ISelectionListener() { + + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if( ! selection.isEmpty() ) { + if( selection instanceof IStructuredSelection ) { + IStructuredSelection s = (IStructuredSelection) selection; + if( s.size() == 1 ) { + windowContext.set(IServiceConstants.SELECTION, s.getFirstElement()); + } else { + windowContext.set(IServiceConstants.SELECTION, s.toList()); + } + } else { + windowContext.set(IServiceConstants.SELECTION, selection); + } + } + } + }); + return windowContext; + } + + return o; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DirtyProviderFunction.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DirtyProviderFunction.java new file mode 100644 index 00000000..88d82f13 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DirtyProviderFunction.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.internal; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.compat.parts.DIEditorPart; +import org.eclipse.e4.tools.services.IDirtyProviderService; +import org.eclipse.ui.part.EditorPart; + +public class DirtyProviderFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context) { + DIEditorPart<?> part = (DIEditorPart<?>) context.get(EditorPart.class); + return new IDirtyProviderService() { + + public void setDirtyState(boolean dirtyState) { + // TODO Auto-generated method stub + + } + + }; + } + +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java new file mode 100644 index 00000000..3ac6b2d0 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.internal; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.InvalidRegistryObjectException; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.eclipse.e4.core.services.contributions.IContributionFactory; +import org.eclipse.e4.core.services.contributions.IContributionFactorySpi; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; + +/** + * Create the contribution factory. + */ +public class ReflectionContributionFactory implements IContributionFactory { + + private IExtensionRegistry registry; + private Map<String, Object> languages; + + static class URI { + private String[] segments; + + URI(String[] segments) { + this.segments = segments; + } + + public static URI createURI(String uriString) { + return new URI(uriString.split("/")); + } + + public int segmentCount() { + return segments.length; + } + + public String segment(int i) { + return segments[i]; + } + } + + /** + * Create a reflection factory. + * + * @param registry + * to read languages. + */ + public ReflectionContributionFactory(IExtensionRegistry registry) { + this.registry = registry; + processLanguages(); + } + + public Object call(Object object, String uriString, String methodName, IEclipseContext context, + Object defaultValue) { + if (uriString != null) { + URI uri = URI.createURI(uriString); + if (uri.segmentCount() > 3) { + String prefix = uri.segment(2); + IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix); + return factory.call(object, methodName, context, defaultValue); + } + } + + Method targetMethod = null; + + Method[] methods = object.getClass().getMethods(); + + // Optimization: if there's only one method, use it. + if (methods.length == 1) { + targetMethod = methods[0]; + } else { + ArrayList<Method> toSort = new ArrayList<Method>(); + + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + + // Filter out non-public constructors + if ((method.getModifiers() & Modifier.PUBLIC) != 0 + && method.getName().equals(methodName)) { + toSort.add(method); + } + } + + // Sort the methods by descending number of method + // arguments + Collections.sort(toSort, new Comparator<Method>() { + /* + * (non-Javadoc) + * + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(Method m1, Method m2) { + int l1 = m1.getParameterTypes().length; + int l2 = m2.getParameterTypes().length; + + return l1 - l2; + } + }); + + // Find the first satisfiable method + for (Iterator<Method> iter = toSort.iterator(); iter.hasNext() && targetMethod == null;) { + Method next = iter.next(); + + boolean satisfiable = true; + + Class<?>[] params = next.getParameterTypes(); + for (int i = 0; i < params.length && satisfiable; i++) { + Class<?> clazz = params[i]; + + if (!context.containsKey(clazz.getName()) + && !IEclipseContext.class.equals(clazz)) { + satisfiable = false; + } + } + + if (satisfiable) { + targetMethod = next; + } + } + } + + if (targetMethod == null) { + if (defaultValue != null) { + return defaultValue; + } + throw new RuntimeException( + "could not find satisfiable method " + methodName + " in class " + object.getClass()); //$NON-NLS-1$//$NON-NLS-2$ + } + + Class<?>[] paramKeys = targetMethod.getParameterTypes(); + + try { +// Activator.trace(Policy.DEBUG_CMDS, "calling: " + methodName, null); //$NON-NLS-1$ + Object[] params = new Object[paramKeys.length]; + for (int i = 0; i < params.length; i++) { + if (IEclipseContext.class.equals(paramKeys[i])) { + params[i] = context; + } else { + params[i] = context.get(paramKeys[i].getName()); + } + } + + return targetMethod.invoke(object, params); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + public Object create(String uriString, IEclipseContext context) { + if (uriString == null) { + return null; + } + URI uri = URI.createURI(uriString); + Bundle bundle = getBundle(uri); + Object contribution; + if (bundle != null) { + contribution = createFromBundle(bundle, context, uri); + } else { + contribution = null; +// Activator.log(LogService.LOG_ERROR, "Unable to retrive the bundle from the URI: " //$NON-NLS-1$ +// + uriString); + } + return contribution; + } + + protected Object createFromBundle(Bundle bundle, IEclipseContext context, URI uri) { + Object contribution; + if (uri.segmentCount() > 3) { + String prefix = uri.segment(2); + IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix); + StringBuffer resource = new StringBuffer(uri.segment(3)); + for (int i = 4; i < uri.segmentCount(); i++) { + resource.append('/'); + resource.append(uri.segment(i)); + } + contribution = factory.create(bundle, resource.toString(), context); + } else { + String clazz = uri.segment(2); + try { + Class<?> targetClass = bundle.loadClass(clazz); + contribution = ContextInjectionFactory.make(targetClass, context); + if (contribution == null) { + String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ +// Activator.log(LogService.LOG_ERROR, message, new Exception()); + } + } catch (ClassNotFoundException e) { + contribution = null; + String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ +// Activator.log(LogService.LOG_ERROR, message, e); + } catch (InjectionException e) { + contribution = null; + String message = "Unable to create class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ +// Activator.log(LogService.LOG_ERROR, message, e); + } + } + return contribution; + } + + protected void processLanguages() { + languages = new HashMap<String, Object>(); + String extId = "org.eclipse.e4.languages"; //$NON-NLS-1$ + IConfigurationElement[] languageElements = registry.getConfigurationElementsFor(extId); + for (int i = 0; i < languageElements.length; i++) { + IConfigurationElement languageElement = languageElements[i]; + try { + languages.put(languageElement.getAttribute("name"), //$NON-NLS-1$ + languageElement.createExecutableExtension("contributionFactory")); //$NON-NLS-1$ + } catch (InvalidRegistryObjectException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + protected Bundle getBundle(URI platformURI) { + return Util.getBundle(platformURI.segment(1)); + } + + public Bundle getBundle(String uriString) { + URI uri = URI.createURI(uriString); + return getBundle(uri); + } + +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/SelectionProviderContextFunction.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/SelectionProviderContextFunction.java new file mode 100644 index 00000000..901627cd --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/SelectionProviderContextFunction.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.internal; + +import java.util.List; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.services.ISelectionProviderService; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; + + +public class SelectionProviderContextFunction extends ContextFunction { + + @Override + public Object compute(final IEclipseContext context) { + return new ISelectionProviderService() { + public void setSelection(Object selection) { + ISelectionProvider pv = context.get(ISelectionProvider.class); + + if( selection instanceof List<?> ) { + pv.setSelection(new StructuredSelection((List<?>)selection)); + } else { + pv.setSelection(new StructuredSelection(selection)); + } + + } + }; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java new file mode 100644 index 00000000..567fcc2b --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java @@ -0,0 +1,26 @@ +package org.eclipse.e4.tools.compat.internal; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; + +public class Util { + public static Bundle getBundle(String bundleName) { + Bundle bundle = FrameworkUtil.getBundle(Util.class); + BundleContext ctx = bundle.getBundleContext(); + ServiceReference ref = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName()); + PackageAdmin bundleAdmin = (PackageAdmin) ctx.getService(ref); + Bundle[] bundles = bundleAdmin.getBundles(bundleName, null); + if (bundles == null) + return null; + // Return the first bundle that is not installed or uninstalled + for (int i = 0; i < bundles.length; i++) { + if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { + return bundles[i]; + } + } + return null; + } +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIEditorPart.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIEditorPart.java new file mode 100644 index 00000000..a154d288 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIEditorPart.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.parts; + +import java.lang.reflect.Method; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.compat.internal.Util; +import org.eclipse.e4.ui.services.IStylingEngine; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.EditorPart; + +public abstract class DIEditorPart<C> extends EditorPart { + private IEclipseContext context; + private C component; + private Class<C> clazz; + private boolean dirtyState; + + public DIEditorPart(Class<C> clazz) { + this.clazz = clazz; + } + +//FIXME once @Persist is out of ui.workbench +// @Override +// public void doSave(IProgressMonitor monitor) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void doSaveAs() { +// // TODO Auto-generated method stub +// } + + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + setSite(site); + setInput(input); + + IEclipseContext parentContext = (IEclipseContext) getSite().getService(IEclipseContext.class); + + // Check if running in 4.x + if( parentContext.get("org.eclipse.e4.workbench.ui.IPresentationEngine") != null ) { + // Hack to get the MPart-Context + try { + Class<?> clazz = Util.getBundle("org.eclipse.e4.ui.model").loadClass("org.eclipse.e4.ui.model.application.ui.basic.MPart"); + Object instance = getSite().getService(clazz); + Method m = clazz.getMethod("getContext", new Class[0]); + context = (IEclipseContext) m.invoke(instance); + } catch (Exception e) { + throw new PartInitException("Could not create context",e); + } + } else { + context = parentContext.createChild("EditPart('"+getPartName()+"')"); //$NON-NLS-1$ + } + + context.declareModifiable(IEditorInput.class); + context.declareModifiable(EditorPart.class); + + context.set(EditorPart.class,this); + context.set(IEditorInput.class, input); + } + + +// +// @Override +// public boolean isSaveAsAllowed() { +// // TODO Auto-generated method stub +// return false; +// } + + @Override + public void createPartControl(Composite parent) { + ISelectionProvider s = new SelectionProviderImpl(); + context.set(ISelectionProvider.class, s); + getSite().setSelectionProvider(s); + + IStylingEngine styleEngine = context.get(IStylingEngine.class); + Composite comp = new Composite(parent, SWT.NONE); + comp.setBackgroundMode(SWT.INHERIT_DEFAULT); + + FillLayout layout = new FillLayout(); + layout.marginWidth = 10; + layout.marginHeight = 10; + comp.setLayout(layout); + + context.set(Composite.class.getName(), comp); + component = ContextInjectionFactory.make(clazz, context); + + styleEngine.setClassname(comp, getSite().getId()); + } + + public C getComponent() { + return component; + } + + public void setDirtyState(boolean dirtyState) { + if( dirtyState != this.dirtyState ) { + this.dirtyState = dirtyState; + firePropertyChange(PROP_DIRTY); + } + } + + @Override + public boolean isDirty() { + return dirtyState; + } + +//FIXME Once we have an @Focus we can implement it +// @Override +// public void setFocus() { +// // TODO Auto-generated method stub +// +// } + + @Override + public void dispose() { + context.dispose(); + context = null; + super.dispose(); + } + + private class SelectionProviderImpl implements ISelectionProvider { + private ISelection currentSelection = StructuredSelection.EMPTY; + + private ListenerList listeners = new ListenerList(); + + public void setSelection(ISelection selection) { + currentSelection = selection; + SelectionChangedEvent evt = new SelectionChangedEvent(this, selection); + + for( Object l : listeners.getListeners() ) { + ((ISelectionChangedListener)l).selectionChanged(evt); + } + } + + public void removeSelectionChangedListener( + ISelectionChangedListener listener) { + listeners.remove(listener); + } + + public ISelection getSelection() { + return currentSelection; + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + listeners.add(listener); + } + } +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DISaveableViewPart.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DISaveableViewPart.java new file mode 100644 index 00000000..a55efc86 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DISaveableViewPart.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.parts; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.ui.ISaveablePart; + +public class DISaveableViewPart extends DIViewPart implements ISaveablePart { + + public void doSave(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + public void doSaveAs() { + // TODO Auto-generated method stub + + } + + public boolean isDirty() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveAsAllowed() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveOnCloseNeeded() { + // TODO Auto-generated method stub + return false; + } +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIViewPart.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIViewPart.java new file mode 100644 index 00000000..876f05db --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIViewPart.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.parts; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; + +public class DIViewPart extends ViewPart { + + @Override + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + + } + +} diff --git a/bundles/org.eclipse.e4.tools.services/.classpath b/bundles/org.eclipse.e4.tools.services/.classpath new file mode 100644 index 00000000..64c5e31b --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/bundles/org.eclipse.e4.tools.services/.project b/bundles/org.eclipse.e4.tools.services/.project new file mode 100644 index 00000000..15c52ba1 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.e4.tools.services</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bundles/org.eclipse.e4.tools.services/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.e4.tools.services/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..199694e6 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Wed Jun 02 16:01:21 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/bundles/org.eclipse.e4.tools.services/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.services/META-INF/MANIFEST.MF new file mode 100644 index 00000000..664eaddc --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Services +Bundle-SymbolicName: org.eclipse.e4.tools.services +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Export-Package: org.eclipse.e4.tools.services diff --git a/bundles/org.eclipse.e4.tools.services/build.properties b/bundles/org.eclipse.e4.tools.services/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/IDirtyProviderService.java b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/IDirtyProviderService.java new file mode 100644 index 00000000..52dc1936 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/IDirtyProviderService.java @@ -0,0 +1,5 @@ +package org.eclipse.e4.tools.services; + +public interface IDirtyProviderService { + public void setDirtyState(boolean dirtyState); +} diff --git a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/ISelectionProviderService.java b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/ISelectionProviderService.java new file mode 100644 index 00000000..e90d0f60 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/ISelectionProviderService.java @@ -0,0 +1,5 @@ +package org.eclipse.e4.tools.services; + +public interface ISelectionProviderService { + public void setSelection(Object selection); +} |