diff options
author | Thomas Schindl | 2010-06-03 17:52:09 +0000 |
---|---|---|
committer | Thomas Schindl | 2010-06-03 17:52:09 +0000 |
commit | 8ed068373413e0637b730165a8fe417d12515c42 (patch) | |
tree | 5b33307fb6cbb9e123e0bae4c0b4fb25df3fdf30 | |
parent | a8522b13887dc568ae485ce87b8e33e0e1c71203 (diff) | |
download | org.eclipse.e4.tools-8ed068373413e0637b730165a8fe417d12515c42.tar.gz org.eclipse.e4.tools-8ed068373413e0637b730165a8fe417d12515c42.tar.xz org.eclipse.e4.tools-8ed068373413e0637b730165a8fe417d12515c42.zip |
Bug 304584 - [Tooling] Implement Workbench-Model-Tooling
* slight changes to dirty propagation
7 files changed, 10 insertions, 308 deletions
diff --git a/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF index 356b567c..448e0f8a 100644 --- a/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF @@ -12,6 +12,6 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.6.0", 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, OSGI-INF/dirtyproviderfunction.xml +Service-Component: OSGI-INF/selectionproviderfunction.xml Export-Package: org.eclipse.e4.tools.compat.parts Bundle-ActivationPolicy: lazy diff --git a/bundles/org.eclipse.e4.tools.compat/OSGI-INF/dirtyproviderfunction.xml b/bundles/org.eclipse.e4.tools.compat/OSGI-INF/dirtyproviderfunction.xml deleted file mode 100644 index 99708206..00000000 --- a/bundles/org.eclipse.e4.tools.compat/OSGI-INF/dirtyproviderfunction.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?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.dirtyprovider"> - <implementation class="org.eclipse.e4.tools.compat.internal.DirtyProviderFunction"/> - <service> - <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/> - </service> - <property name="service.context.key" type="String" value="org.eclipse.e4.tools.services.IDirtyProviderService"/> -</scr:component> diff --git a/bundles/org.eclipse.e4.tools.compat/build.properties b/bundles/org.eclipse.e4.tools.compat/build.properties index e56d72ba..4975ca25 100644 --- a/bundles/org.eclipse.e4.tools.compat/build.properties +++ b/bundles/org.eclipse.e4.tools.compat/build.properties @@ -2,6 +2,5 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.xml,\ - OSGI-INF/selectionproviderfunction.xml,\ - OSGI-INF/dirtyproviderfunction.xml + OSGI-INF/selectionproviderfunction.xml source.. = src/ 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 index fa33b020..68dce242 100644 --- 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 @@ -10,11 +10,8 @@ ******************************************************************************/ 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.css.swt.theme.IThemeEngine; import org.eclipse.e4.ui.css.swt.theme.IThemeManager; import org.eclipse.e4.ui.services.IServiceConstants; @@ -39,7 +36,7 @@ import org.osgi.framework.FrameworkUtil; public class ContextServiceFactory extends AbstractServiceFactory { @Override - public Object create(Class serviceInterface, IServiceLocator parentLocator, + public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) { if( ! IEclipseContext.class.equals(serviceInterface) ) { return null; @@ -64,9 +61,9 @@ public class ContextServiceFactory extends AbstractServiceFactory { 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); +// IExtensionRegistry registry = RegistryFactory.getRegistry(); +// ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(registry); +// appContext.set(IContributionFactory.class.getName(),contributionFactory); IThemeManager manager = serviceContext.get(IThemeManager.class); final IThemeEngine engine = manager.getEngineForDisplay(Display.getCurrent()); 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 deleted file mode 100644 index 0a459f2a..00000000 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DirtyProviderFunction.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * 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) { - final DIEditorPart<?> part = (DIEditorPart<?>) context.get(EditorPart.class); - if( part == null ) { - return null; - } - - return new IDirtyProviderService() { - - public void setDirtyState(boolean dirtyState) { - part.setDirtyState(dirtyState); - } - }; - } - -} 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 deleted file mode 100644 index 3ac6b2d0..00000000 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * 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/parts/DIEditorPart.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIEditorPart.java index 3f2580cb..0556588d 100644 --- 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 @@ -16,6 +16,7 @@ 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.tools.services.IDirtyProviderService; import org.eclipse.e4.ui.services.IStylingEngine; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -30,7 +31,7 @@ import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; -public abstract class DIEditorPart<C> extends EditorPart { +public abstract class DIEditorPart<C> extends EditorPart implements IDirtyProviderService { private IEclipseContext context; private C component; private Class<C> clazz; @@ -77,8 +78,10 @@ public abstract class DIEditorPart<C> extends EditorPart { context.declareModifiable(IEditorInput.class); context.declareModifiable(EditorPart.class); + context.declareModifiable(IDirtyProviderService.class); context.set(EditorPart.class,this); + context.set(IDirtyProviderService.class,this); context.set(IEditorInput.class, input); } |