Bug 308094 - Representing popups for context menus merged from HEAD
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/WorkbenchRendererFactory.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/WorkbenchRendererFactory.java index 95ba473..79b9279 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/WorkbenchRendererFactory.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/WorkbenchRendererFactory.java
@@ -1,5 +1,6 @@ package org.eclipse.e4.workbench.ui.renderers.swt; +import javax.annotation.PostConstruct; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.ui.MUIElement; @@ -137,6 +138,7 @@ ContextInjectionFactory.inject(renderer, context); } + @PostConstruct public void init(IEclipseContext context) { this.context = context; }
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/factories/IRendererFactory.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/factories/IRendererFactory.java index 34c0ecb..2d968f1 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/factories/IRendererFactory.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/factories/IRendererFactory.java
@@ -1,11 +1,10 @@ package org.eclipse.e4.ui.workbench.swt.factories; -import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.workbench.swt.internal.AbstractPartRenderer; public interface IRendererFactory { public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent); - public void init(IEclipseContext context); + // public void init(IEclipseContext context); }
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/E4Application.java index ed9c416..f0b60a9 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/E4Application.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/E4Application.java
@@ -39,6 +39,7 @@ import org.eclipse.e4.ui.workbench.swt.Activator; import org.eclipse.e4.workbench.modeling.EPartService; import org.eclipse.e4.workbench.ui.IExceptionHandler; +import org.eclipse.e4.workbench.ui.IModelResourceHandler; import org.eclipse.e4.workbench.ui.internal.ActiveChildLookupFunction; import org.eclipse.e4.workbench.ui.internal.ActivePartLookupFunction; import org.eclipse.e4.workbench.ui.internal.E4Workbench; @@ -61,7 +62,7 @@ public class E4Application implements IApplication { private String[] args; - private ResourceHandler handler; + private IModelResourceHandler handler; private Display display = null; public Display getApplicationDisplay() { @@ -103,6 +104,7 @@ IApplicationContext.APPLICATION_ARGS); IEclipseContext appContext = createDefaultContext(); + appContext.set(IApplicationContext.class, applicationContext); // Get the factory to create DI instances with IContributionFactory factory = (IContributionFactory) appContext @@ -187,10 +189,31 @@ final URI initialWorkbenchDefinitionInstance = URI .createPlatformPluginURI(appModelPath, true); - boolean saveAndRestore = true; - handler = new ResourceHandler(instanceLocation, - initialWorkbenchDefinitionInstance, saveAndRestore, - (Logger) eclipseContext.get(Logger.class.getName())); + boolean saveAndRestore; + String value = getArgValue(E4Workbench.SAVE_AND_RESTORE, appContext); + + saveAndRestore = value == null || Boolean.getBoolean(value); + + eclipseContext.set(E4Workbench.SAVE_AND_RESTORE, + Boolean.valueOf(saveAndRestore)); + eclipseContext.set(E4Workbench.INITIAL_WORKBENCH_MODEL_URI, + initialWorkbenchDefinitionInstance); + eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation); + + String resourceHandler = getArgValue( + E4Workbench.MODEL_RESOURCE_HANDLER, appContext); + + if (resourceHandler == null) { + resourceHandler = "platform:/plugin/org.eclipse.e4.ui.workbench/" + + ResourceHandler.class.getName(); + } + + IContributionFactory factory = eclipseContext + .get(IContributionFactory.class); + + handler = (IModelResourceHandler) factory.create(resourceHandler, + eclipseContext); + Resource resource = handler.loadMostRecentModel(); theApp = (MApplication) resource.getContents().get(0); @@ -229,10 +252,11 @@ appContext.set(IContributionFactory.class.getName(), contributionFactory); - appContext.set(Logger.class.getName(), ContextInjectionFactory.make( - WorkbenchLogger.class, appContext)); - appContext.set(Adapter.class.getName(), ContextInjectionFactory.make( - EclipseAdapter.class, appContext)); + appContext + .set(Logger.class.getName(), ContextInjectionFactory.make( + WorkbenchLogger.class, appContext)); + appContext.set(Adapter.class.getName(), + ContextInjectionFactory.make(EclipseAdapter.class, appContext)); // setup for commands and handlers appContext.set(ContextManager.class.getName(), new ContextManager());
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/PartRenderingEngine.java index 8830b89..5f3941f 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/PartRenderingEngine.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/PartRenderingEngine.java
@@ -14,15 +14,14 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.inject.Inject; +import javax.inject.Named; import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IContextConstants; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.IDisposable; import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.contributions.IContributionFactory; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.core.services.log.Logger; import org.eclipse.e4.core.services.statusreporter.StatusReporter; @@ -62,8 +61,10 @@ public static final String engineURI = "platform:/plugin/org.eclipse.e4.ui.workbench.swt/" + "org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine"; - private String defaultRenderingFactoryId = "org.eclipse.e4.ui.workbench.renderers.default"; - private String curFactoryId = defaultRenderingFactoryId; + private static final String defaultFactoryUrl = "platform:/plugin/org.eclipse.e4.ui.workbench.renderers.swt/" + + "org.eclipse.e4.workbench.ui.renderers.swt.WorkbenchRendererFactory"; + private String factoryUrl; + IRendererFactory curFactory = null; // Life Cycle handlers @@ -176,12 +177,13 @@ @Inject protected Logger logger; - public PartRenderingEngine() { - super(); - } - - public PartRenderingEngine(String curFactoryId) { - this.curFactoryId = curFactoryId; + @Inject + public PartRenderingEngine( + @Named(E4Workbench.RENDERER_FACTORY_URI) @Optional String factoryUrl) { + if (factoryUrl == null) { + factoryUrl = defaultFactoryUrl; + } + this.factoryUrl = defaultFactoryUrl; } /** @@ -198,31 +200,35 @@ KeyFormatterFactory.setDefault(SWTKeySupport .getKeyFormatterForPlatform()); - IExtensionRegistry registry = (IExtensionRegistry) context - .get(IExtensionRegistry.class.getName()); - IConfigurationElement[] factories = registry - .getConfigurationElementsFor("org.eclipse.e4.workbench.rendererfactory"); //$NON-NLS-1$ - for (int i = 0; i < factories.length; i++) { - String id = factories[i].getAttribute("id"); //$NON-NLS-1$ - if (!curFactoryId.equals(id)) - continue; + // Add the renderer to the context + context.set(IPresentationEngine.class.getName(), this); - IRendererFactory factory = null; + IRendererFactory factory = null; + IContributionFactory contribFactory = context + .get(IContributionFactory.class); + try { + factory = (IRendererFactory) contribFactory.create(factoryUrl, + context); + } catch (Exception e) { + logger.warn(e, "Could not create rendering factory"); + } + + // Try to load the default one + if (factory == null) { try { - factory = (IRendererFactory) factories[i] - .createExecutableExtension("class"); //$NON-NLS-1$ - } catch (CoreException e) { - e.printStackTrace(); - } - - if (factory != null) { - factory.init(context); - curFactory = factory; + factory = (IRendererFactory) contribFactory.create( + defaultFactoryUrl, context); + } catch (Exception e) { + logger.error(e, "Could not create default rendering factory"); } } - // Add the renderer to the context - context.set(IPresentationEngine.class.getName(), this); + if (factory == null) { + throw new IllegalStateException( + "Could not create any rendering factory. Aborting ..."); + } + + curFactory = factory; // Hook up the widget life-cycle subscriber if (eventBroker != null) {
diff --git a/bundles/org.eclipse.e4.ui.workbench/plugin.xml b/bundles/org.eclipse.e4.ui.workbench/plugin.xml index 171c203..97ccf7a 100644 --- a/bundles/org.eclipse.e4.ui.workbench/plugin.xml +++ b/bundles/org.eclipse.e4.ui.workbench/plugin.xml
@@ -4,7 +4,6 @@ <extension-point id="org.eclipse.e4.workbench.contributions" name="UI Contributions" schema="schema/org.eclipse.e4.workbench.contribution.exsd"/> <extension-point id="org.eclipse.e4.workbench.parts" name="e4 parts" schema="schema/org.eclipse.e4.workbench.parts.exsd"/> <extension-point id="org.eclipse.e4.workbench.model" name="Model extensions" schema="schema/org.eclipse.e4.workbench.model.exsd"/> - <extension-point id="org.eclipse.e4.workbench.rendererfactory" name="UI Renderer Factory" schema="schema/org.eclipse.e4.workbench.rendererfactory.exsd"/> <extension point="org.eclipse.core.runtime.adapters"> <factory
diff --git a/bundles/org.eclipse.e4.ui.workbench/schema/org.eclipse.e4.workbench.rendererfactory.exsd b/bundles/org.eclipse.e4.ui.workbench/schema/org.eclipse.e4.workbench.rendererfactory.exsd deleted file mode 100644 index cfd1938..0000000 --- a/bundles/org.eclipse.e4.ui.workbench/schema/org.eclipse.e4.workbench.rendererfactory.exsd +++ /dev/null
@@ -1,109 +0,0 @@ -<?xml version='1.0' encoding='UTF-8'?> -<!-- Schema file written by PDE --> -<schema targetNamespace="org.eclipse.e4.workbench.ui" xmlns="http://www.w3.org/2001/XMLSchema"> -<annotation> - <appinfo> - <meta.schema plugin="org.eclipse.e4.workbench.ui" id="org.eclipse.e4.workbench.rendererfactory" name="UI Renderer Factory"/> - </appinfo> - <documentation> - This extension allows for replacement of the mechanism used to define the renderer to use for a given UI element. - </documentation> - </annotation> - - <element name="extension"> - <annotation> - <appinfo> - <meta.element /> - </appinfo> - </annotation> - <complexType> - <choice> - <element ref="factory" minOccurs="1" maxOccurs="unbounded"/> - </choice> - <attribute name="point" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="id" type="string"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="name" type="string"> - <annotation> - <documentation> - - </documentation> - <appinfo> - <meta.attribute translatable="true"/> - </appinfo> - </annotation> - </attribute> - </complexType> - </element> - - <element name="factory"> - <complexType> - <attribute name="class" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appinfo> - <meta.attribute kind="java" basedOn=":org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory"/> - </appinfo> - </annotation> - </attribute> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - The id of this factory. The rendering engine will choose the factory to use based on the value of its 'currentRendererFactoryId' field. - </documentation> - </annotation> - </attribute> - </complexType> - </element> - - <annotation> - <appinfo> - <meta.section type="since"/> - </appinfo> - <documentation> - [Enter the first release in which this extension point appears.] - </documentation> - </annotation> - - <annotation> - <appinfo> - <meta.section type="examples"/> - </appinfo> - <documentation> - [Enter extension point usage example here.] - </documentation> - </annotation> - - <annotation> - <appinfo> - <meta.section type="apiinfo"/> - </appinfo> - <documentation> - [Enter API information here.] - </documentation> - </annotation> - - <annotation> - <appinfo> - <meta.section type="implementation"/> - </appinfo> - <documentation> - [Enter information about supplied implementation of this extension point.] - </documentation> - </annotation> - - -</schema>
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/IModelResourceHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/IModelResourceHandler.java new file mode 100644 index 0000000..0f00531 --- /dev/null +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/IModelResourceHandler.java
@@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 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.workbench.ui; + +import java.io.IOException; +import org.eclipse.emf.ecore.resource.Resource; + +/** + * + */ +public interface IModelResourceHandler { + + /** + * @return the most recent model state + */ + Resource loadMostRecentModel(); + + /** + * @throws IOException + * if storing fails + * + */ + void save() throws IOException; + +}
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/E4Workbench.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/E4Workbench.java index 5fa26a3..83cd586 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/E4Workbench.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/E4Workbench.java
@@ -47,6 +47,11 @@ public static final String CSS_RESOURCE_URI_ARG = "applicationCSSResources"; //$NON-NLS-1$ public static final String PRESENTATION_URI_ARG = "presentationURI"; //$NON-NLS-1$ public static final String LIFE_CYCLE_URI_ARG = "lifeCycleURI"; //$NON-NLS-1$ + public static final String SAVE_AND_RESTORE = "saveAndRestore"; //$NON-NLS-1$ + public static final String INITIAL_WORKBENCH_MODEL_URI = "initialWorkbenchModelURI"; //$NON-NLS-1$ + public static final String INSTANCE_LOCATION = "instanceLocation"; //$NON-NLS-1$ + public static final String MODEL_RESOURCE_HANDLER = "modelResourceHandler"; //$NON-NLS-1$ + public static final String RENDERER_FACTORY_URI = "rendererFactoryUri"; //$NON-NLS-1$ IEclipseContext appContext; IPresentationEngine renderer; @@ -141,12 +146,11 @@ IExtensionRegistry registry, IExceptionHandler exceptionHandler, IContributionFactory contributionFactory) { Activator - .trace( - Policy.DEBUG_CONTEXTS, + .trace(Policy.DEBUG_CONTEXTS, "createWorkbenchContext: initialize the workbench context with needed services", null); //$NON-NLS-1$ final IEclipseContext mainContext = applicationContext.createChild("WorkbenchContext"); //$NON-NLS-1$ - mainContext.set(Logger.class.getName(), ContextInjectionFactory.make(WorkbenchLogger.class, - mainContext)); + mainContext.set(Logger.class.getName(), + ContextInjectionFactory.make(WorkbenchLogger.class, mainContext)); // setup for commands and handlers if (contributionFactory != null) {
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ResourceHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ResourceHandler.java index 8c7bdb0..0429f86 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ResourceHandler.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ResourceHandler.java
@@ -18,6 +18,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import javax.inject.Inject; +import javax.inject.Named; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; @@ -36,6 +38,7 @@ import org.eclipse.e4.workbench.modeling.IModelReconcilingService; import org.eclipse.e4.workbench.modeling.ModelDelta; import org.eclipse.e4.workbench.modeling.ModelReconciler; +import org.eclipse.e4.workbench.ui.IModelResourceHandler; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -48,7 +51,7 @@ /** * This class is responsible to load and save the model */ -public class ResourceHandler { +public class ResourceHandler implements IModelResourceHandler { /** * Dictates whether the model should be stored using EMF or with the merging algorithm. @@ -64,13 +67,15 @@ private ModelReconciler reconciler; private Logger logger; - public ResourceHandler(Location instanceLocation, URI applicationDefinitionInstance, - boolean saveAndRestore, Logger logger) { + @Inject + public ResourceHandler(@Named(E4Workbench.INSTANCE_LOCATION) Location instanceLocation, + @Named(E4Workbench.INITIAL_WORKBENCH_MODEL_URI) URI applicationDefinitionInstance, + @Named(E4Workbench.SAVE_AND_RESTORE) boolean saveAndRestore, Logger logger) { this.applicationDefinitionInstance = applicationDefinitionInstance; this.logger = logger; resourceSetImpl = new ResourceSetImpl(); - resourceSetImpl.getResourceFactoryRegistry().getExtensionToFactoryMap().put( - Resource.Factory.Registry.DEFAULT_EXTENSION, new E4XMIResourceFactory()); + resourceSetImpl.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new E4XMIResourceFactory()); resourceSetImpl.getPackageRegistry().put(ApplicationPackageImpl.eNS_URI, ApplicationPackageImpl.eINSTANCE); @@ -85,8 +90,7 @@ AdvancedPackageImpl.eINSTANCE); resourceSetImpl .getPackageRegistry() - .put( - org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.eNS_URI, + .put(org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.eNS_URI, org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.eINSTANCE); // this.registry = registry; @@ -111,8 +115,8 @@ } public long getLastStoreDatetime() { - long restoreLastModified = restoreLocation == null ? 0L : new File(restoreLocation - .toFileString()).lastModified(); + long restoreLastModified = restoreLocation == null ? 0L : new File( + restoreLocation.toFileString()).lastModified(); return restoreLastModified; } @@ -244,8 +248,8 @@ Map<String, ?> attributes = resourceSetImpl.getURIConverter().getAttributes( applicationDefinitionInstance, - Collections.singletonMap(URIConverter.OPTION_REQUESTED_ATTRIBUTES, Collections - .singleton(URIConverter.ATTRIBUTE_TIME_STAMP))); + Collections.singletonMap(URIConverter.OPTION_REQUESTED_ATTRIBUTES, + Collections.singleton(URIConverter.ATTRIBUTE_TIME_STAMP))); Object timestamp = attributes.get(URIConverter.ATTRIBUTE_TIME_STAMP); if (timestamp instanceof Long) {
diff --git a/examples/org.eclipse.e4.demo.e4photo/e4photo.product b/examples/org.eclipse.e4.demo.e4photo/e4photo.product index a0887c0..a0a01f1 100644 --- a/examples/org.eclipse.e4.demo.e4photo/e4photo.product +++ b/examples/org.eclipse.e4.demo.e4photo/e4photo.product
@@ -60,7 +60,6 @@ <plugin id="org.eclipse.e4.ui.services"/> <plugin id="org.eclipse.e4.ui.workbench"/> <plugin id="org.eclipse.e4.ui.workbench.renderers.swt"/> - <plugin id="org.eclipse.e4.ui.workbench.renderers.swt.contributions"/> <plugin id="org.eclipse.e4.ui.workbench.swt"/> <plugin id="org.eclipse.e4.ui.workbench3"/> <plugin id="org.eclipse.emf.common"/>