summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhubner2008-10-23 08:21:06 (EDT)
committer dhubner2008-10-23 08:21:06 (EDT)
commit0f74d93e4d6456916abf5bdbaac97689d9804ef6 (patch)
tree31b204306a89e71877f8562605783cf4d7ee5953
parent9406ca96c9a66d75660cc7330fa5002f0ba7186d (diff)
downloadorg.eclipse.xpand-0f74d93e4d6456916abf5bdbaac97689d9804ef6.zip
org.eclipse.xpand-0f74d93e4d6456916abf5bdbaac97689d9804ef6.tar.gz
org.eclipse.xpand-0f74d93e4d6456916abf5bdbaac97689d9804ef6.tar.bz2
initial commit
-rw-r--r--examples/org.eclipse.emf.generic.editor/.classpath7
-rw-r--r--examples/org.eclipse.emf.generic.editor/.project28
-rw-r--r--examples/org.eclipse.emf.generic.editor/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF25
-rw-r--r--examples/org.eclipse.emf.generic.editor/build.properties6
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/common/down.gifbin0 -> 332 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/common/left.gifbin0 -> 541 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/common/right.gifbin0 -> 541 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/common/up.gifbin0 -> 323 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/complete_task.gifbin0 -> 344 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/det_pane_right.gifbin0 -> 374 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/det_pane_under.gifbin0 -> 352 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/synch_toc_nav.gifbin0 -> 166 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/plugin.properties2
-rw-r--r--examples/org.eclipse.emf.generic.editor/plugin.xml27
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java111
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java340
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MessageData.java86
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java112
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawFacade.java152
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawHelper.java41
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/WorkspaceResourceManager.java56
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolutionException.java12
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolver.java196
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java191
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java75
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/RegistryItemLabelProvider.java62
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEDetailsPageProvider.java60
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java148
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/GenericDetailsPage.java308
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/IPreferenceConstants.java24
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ImageRegistry.java184
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ProposalCreator.java95
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/EmfSwtBindingFactory.java204
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/MultipleFeatureControl.java229
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/SelectionProviderMultipleSelectionObservableList.java122
36 files changed, 2910 insertions, 0 deletions
diff --git a/examples/org.eclipse.emf.generic.editor/.classpath b/examples/org.eclipse.emf.generic.editor/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/.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/examples/org.eclipse.emf.generic.editor/.project b/examples/org.eclipse.emf.generic.editor/.project
new file mode 100644
index 0000000..1aa522f
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.generic.editor</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/examples/org.eclipse.emf.generic.editor/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.emf.generic.editor/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..95a4ac2
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Wed Oct 22 15:18:50 CEST 2008
+eclipse.preferences.version=1
+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/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF b/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..eb515dc
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF
@@ -0,0 +1,25 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.emf.generic.editor;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-Activator: org.eclipse.emf.editor.EEPlugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.emf.ecore.editor,
+ org.eclipse.ui.forms,
+ org.eclipse.core.resources,
+ org.eclipse.jface.databinding,
+ org.eclipse.emf.databinding,
+ org.eclipse.emf.databinding.edit,
+ org.eclipse.xtend;bundle-version="0.7.0",
+ org.eclipse.xtend.util.stdlib;bundle-version="0.7.0",
+ org.eclipse.xtend.typesystem.emf;bundle-version="0.7.0",
+ org.eclipse.jdt.core;bundle-version="3.4.2"
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.emf.editor,
+ org.eclipse.emf.editor.oaw,
+ org.eclipse.emf.editor.provider,
+ org.eclipse.emf.editor.ui,
+ org.eclipse.emf.editor.ui.binding
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
diff --git a/examples/org.eclipse.emf.generic.editor/build.properties b/examples/org.eclipse.emf.generic.editor/build.properties
new file mode 100644
index 0000000..6c480f3
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
diff --git a/examples/org.eclipse.emf.generic.editor/icons/common/down.gif b/examples/org.eclipse.emf.generic.editor/icons/common/down.gif
new file mode 100644
index 0000000..072b184
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/common/down.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/common/left.gif b/examples/org.eclipse.emf.generic.editor/icons/common/left.gif
new file mode 100644
index 0000000..740e8ca
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/common/left.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/common/right.gif b/examples/org.eclipse.emf.generic.editor/icons/common/right.gif
new file mode 100644
index 0000000..1956789
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/common/right.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/common/up.gif b/examples/org.eclipse.emf.generic.editor/icons/common/up.gif
new file mode 100644
index 0000000..0716475
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/common/up.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/complete_task.gif b/examples/org.eclipse.emf.generic.editor/icons/complete_task.gif
new file mode 100644
index 0000000..79a554e
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/complete_task.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/det_pane_right.gif b/examples/org.eclipse.emf.generic.editor/icons/det_pane_right.gif
new file mode 100644
index 0000000..d590470
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/det_pane_right.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/det_pane_under.gif b/examples/org.eclipse.emf.generic.editor/icons/det_pane_under.gif
new file mode 100644
index 0000000..dee0cbc
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/det_pane_under.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/synch_toc_nav.gif b/examples/org.eclipse.emf.generic.editor/icons/synch_toc_nav.gif
new file mode 100644
index 0000000..4353fd5
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/synch_toc_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/plugin.properties b/examples/org.eclipse.emf.generic.editor/plugin.properties
new file mode 100644
index 0000000..fd0ae15
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/plugin.properties
@@ -0,0 +1,2 @@
+pluginName=Generic EMF Form Editor Plug-in
+providerName=itemis AG \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/plugin.xml b/examples/org.eclipse.emf.generic.editor/plugin.xml
new file mode 100644
index 0000000..f908d6f
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/plugin.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.emf.editor.EEditor"
+ contributorClass="org.eclipse.emf.ecore.presentation.EcoreActionBarContributor"
+ icon="icons/synch_toc_nav.gif"
+ id="org.eclipse.emf.genericEditor"
+ name="Generic EMF Form Editor">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.emf.generic.editor.contentTypeBinding1">
+ </contentTypeBinding>
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.core.contenttype.contentTypes">
+ <content-type
+ file-extensions="xmi,dsl"
+ id="org.eclipse.emf.generic.editor.emf-instance"
+ name="Dynamic Ecore Instance"
+ priority="high">
+ </content-type>
+ </extension>
+
+</plugin>
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java
new file mode 100644
index 0000000..766dd97
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java
@@ -0,0 +1,111 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.editor.ui.ImageRegistry;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class EEPlugin extends AbstractUIPlugin {
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.openarchitectureware.emf.generic.editor";
+
+ // The shared instance
+ private static EEPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public EEPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public IPreferenceStore getPreferenceStore() {
+ // TODO Auto-generated method stub
+ return super.getPreferenceStore();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ if (getPreferenceStore().needsSaving())
+ ((ScopedPreferenceStore) getPreferenceStore()).save();
+ ImageRegistry.getDefault().dispose();
+ super.stop(context);
+
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static EEPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in
+ * relative path !Note, that you have to take care of disposing any images
+ * created by createImage()!
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ public static void logError(String string, Throwable e) {
+ getDefault().getLog().log(
+ new Status(IStatus.ERROR, PLUGIN_ID, string, e));
+ }
+
+ public static void logWarning(String string) {
+ getDefault().getLog().log(
+ new Status(IStatus.WARNING, EEPlugin.PLUGIN_ID, string));
+ }
+
+ public static void logError(String string) {
+ getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, string));
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java
new file mode 100644
index 0000000..9cd5087
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java
@@ -0,0 +1,340 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.presentation.EcoreEditor;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.editor.oaw.OawFacade;
+import org.eclipse.emf.editor.provider.ExtendedLabelProvider;
+import org.eclipse.emf.editor.provider.ExtendedReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.editor.provider.ExtendedReflectiveItemProviderAdapterFactory.ExtendedReflectiveItemProvider;
+import org.eclipse.emf.editor.ui.EEDetailsPageProvider;
+import org.eclipse.emf.editor.ui.EEMasterDetailsBlock;
+import org.eclipse.emf.editor.ui.ImageRegistry;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.forms.IMessage;
+import org.eclipse.ui.forms.IMessageManager;
+import org.eclipse.ui.forms.ManagedForm;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.xtend.expression.ExecutionContext;
+import org.eclipse.xtend.expression.ExecutionContextImpl;
+import org.eclipse.xtend.expression.TypeSystemImpl;
+import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class EEditor extends EcoreEditor implements ChangeListener {
+
+ private static final String ESTRUCTURALFEATURE_KEY = EcorePackage.Literals.ESTRUCTURAL_FEATURE.getName();
+ protected static final String MARKER_ID = null;
+ private ManagedForm managedForm;
+ private EEMasterDetailsBlock mdBlock;
+
+ private IProject project;
+ private OawFacade facade;
+ private ExtendedReflectiveItemProvider extendedReflectiveItemProvider;
+
+ public EEditor() {
+ super();
+ // editingDomain already created by superclass
+ ImageRegistry.getDefault().addChangeListener(this);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ ImageRegistry.getDefault().removeChangeListener(this);
+ }
+
+ /**
+ * To provide custom (oAW-Powered) labels and images
+ *
+ * @param caf
+ *
+ */
+ private void rejectFactory(ComposedAdapterFactory caf) {
+ // REMOVE reflective factory
+ caf.removeAdapterFactory(caf.getFactoryForType(EcorePackage.eINSTANCE.getEFactoryInstance().create(
+ EcorePackage.Literals.EOBJECT)));
+ // ADD extended factory
+ ExtendedLabelProvider customProvider = new ExtendedLabelProvider(facade);
+ ExtendedReflectiveItemProviderAdapterFactory extendedReflectiveItemProviderAdapterFactory = new ExtendedReflectiveItemProviderAdapterFactory(
+ customProvider);
+ caf.addAdapterFactory(extendedReflectiveItemProviderAdapterFactory);
+
+ // register item provider for details view
+ this.extendedReflectiveItemProvider = (ExtendedReflectiveItemProvider) extendedReflectiveItemProviderAdapterFactory
+ .createAdapter(null);
+ }
+
+ /**
+ * Model is already created by superclass. Provides a container for EMF's
+ * TreeViewer (currentViewer)
+ *
+ * @see org.eclipse.ui.part.MultiPageEditorPart#createPageContainer(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Composite createPageContainer(Composite parent) {
+ parent.setLayout(new FillLayout());
+ FormToolkit toolkit = new FormToolkit(parent.getDisplay());
+ ScrolledForm form = new ScrolledForm(parent) {
+ @Override
+ public void reflow(boolean flushCache) {
+ // super.reflow(flushCache);
+ }
+ };
+ form.setExpandHorizontal(true);
+ form.setExpandVertical(true);
+ form.setBackground(toolkit.getColors().getBackground());
+ form.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ form.setFont(JFaceResources.getHeaderFont());
+ toolkit.adapt(parent);
+ managedForm = new ManagedForm(toolkit, form);
+ managedForm.getForm().setText("Generic Editor - " + getFile().getName());
+ managedForm.getToolkit().decorateFormHeading(managedForm.getForm().getForm());
+ managedForm.getForm().getForm().setToolBarVerticalAlignment(SWT.TOP);
+ managedForm.getForm().getForm().addMessageHyperlinkListener(new HyperlinkAdapter() {
+ @Override
+ public void linkActivated(HyperlinkEvent event) {
+ try {
+ Object eventData = event.getHref();
+ if (eventData instanceof IMessage[]) {
+ final IMessage[] messages = (IMessage[]) eventData;
+
+ getSite().getShell().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ Object object = null;
+ Control c = null;
+ for (IMessage message : messages) {
+ object = ((List<?>) message.getData()).get(0);
+ if (object != null) {
+ getViewer().setSelection(new StructuredSelection(object), true);
+ }
+ if (message.getData() instanceof Map) {
+ EStructuralFeature f = (EStructuralFeature) ((List<?>) message.getData())
+ .get(1);
+ if (f != null) {
+ c = mdBlock.findControl(ESTRUCTURALFEATURE_KEY, f);
+ }
+ }
+ break;
+ }
+
+ if (c != null && !c.isDisposed()) {
+ c.forceFocus();
+ }
+ }
+ });
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ mdBlock = new EEMasterDetailsBlock(new EEDetailsPageProvider(this)) {
+ @Override
+ protected void createMoreToolBarActions(IToolBarManager toolBarManager) {
+ Action action = new Action("Check") {
+ @Override
+ public void run() {
+ checkModel();
+ }
+ };
+ action.setImageDescriptor(EEPlugin.getImageDescriptor("icons/complete_task.gif"));
+ toolBarManager.add(action);
+ }
+ };
+ mdBlock.createContent(managedForm);
+
+ final Composite c = (Composite) mdBlock.getMasterSectionPart().getSection().getClient();
+ //
+ this.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection() instanceof TreeSelection && !event.getSelection().isEmpty())
+ managedForm.fireSelectionChanged(mdBlock.getMasterSectionPart(), event.getSelection());
+ }
+
+ });
+ return c;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.ecore.presentation.EcoreEditor#createPages()
+ */
+ @Override
+ public void createPages() {
+ initInternal();
+ super.createPages();
+ }
+
+ /**
+ *
+ */
+ private void initInternal() {
+ project = getFile().getProject();
+ facade = createOawFacade();
+ if (editingDomain.getAdapterFactory() instanceof ComposedAdapterFactory) {
+ ComposedAdapterFactory caf = (ComposedAdapterFactory) editingDomain.getAdapterFactory();
+ rejectFactory(caf);
+ }
+ }
+
+ @Override
+ public void createModel() {
+ try {
+ super.createModel();
+ // checkModel();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void doSave(IProgressMonitor progressMonitor) {
+ try {
+ checkModel();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ super.doSave(progressMonitor);
+ }
+ }
+
+ /**
+ *
+ */
+ public void checkModel() {
+ final List<MessageData> messages = new ModelCheckor().check(getEditingDomain().getResourceSet());
+ getSite().getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IMessageManager messageManager = managedForm.getMessageManager();
+ messageManager.removeMessages();
+ messageManager.setAutoUpdate(false);
+ for (MessageData md : messages) {
+ messageManager.addMessage(md.getKey(), md.getMessage(), md.getData(), md.getStatus());
+ }
+ messageManager.update();
+ messageManager.setAutoUpdate(true);
+ }
+ });
+ }
+
+ private OawFacade createOawFacade() {
+ final List<EPackage> packs = findMetaModelPackages();
+ TypeSystemImpl ts = new TypeSystemImpl();
+ ts.registerMetaModel(new EmfRegistryMetaModel() {
+ @Override
+ protected EPackage[] allPackages() {
+ return packs.toArray(new EPackage[packs.size()]);
+ }
+ });
+ // FIXME new WorkspaceResourceManager(OawPlugin.getOawModelManager()
+ // .findProject(project)),
+ ExecutionContext context = new ExecutionContextImpl(ts, null);
+ return new OawFacade(project, context);
+ }
+
+ private List<EPackage> findMetaModelPackages() {
+ createModel(); // initialize resources
+ final List<EPackage> packs = new ArrayList<EPackage>();
+ EcoreUtil.resolveAll(getEditingDomain().getResourceSet());
+ EList<Resource> resources = getEditingDomain().getResourceSet().getResources();
+ if (resources != null) {
+ for (Resource res : resources) {
+ TreeIterator<EObject> allContents = res.getAllContents();
+ if (allContents.hasNext()) {
+ EObject rootObject = allContents.next();
+ if (rootObject instanceof EPackage)
+ packs.add((EPackage) rootObject);
+ }
+ }
+ }
+ return packs;
+ }
+
+ public IFile getFile() {
+ return (IFile) getEditorInput().getAdapter(IFile.class);
+ }
+
+ public ExtendedReflectiveItemProvider getExtendedReflectiveItemProvider() {
+
+ return extendedReflectiveItemProvider;
+ }
+
+ public void stateChanged(ChangeEvent e) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ currentViewer.refresh();
+ }
+ });
+ }
+
+ public OawFacade getOawFacade() {
+ return facade;
+ }
+
+ public static int formularOrientation() {
+ IPreferenceStore store = EEPlugin.getDefault().getPreferenceStore();
+ int pref = store.getInt(org.eclipse.emf.editor.ui.IPreferenceConstants.FORMULAR_ORIENTATION);
+ if (pref != SWT.VERTICAL && pref != SWT.HORIZONTAL)
+ return SWT.VERTICAL;
+ return pref;
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MessageData.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MessageData.java
new file mode 100644
index 0000000..857162a
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MessageData.java
@@ -0,0 +1,86 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor;
+
+import java.util.List;
+
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class MessageData {
+ private Object key;
+ private String message;
+ private List<?> data;
+ private int status;
+ private Control control;
+
+ public MessageData(Object key, String message, List<?> data, int status, Control control) {
+ super();
+ this.key = key;
+ this.message = message;
+ this.data = data;
+ this.status = status;
+ this.control = control;
+ }
+
+ public MessageData(Object key, String message, List<?> data, int status) {
+ this(key, message, data, status, null);
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public void setKey(Object key) {
+ this.key = key;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public List<?> getData() {
+ return data;
+ }
+
+ public void setData(List<?> data) {
+ this.data = data;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public Control getControl() {
+ return control;
+ }
+
+ public void setControl(Control c) {
+ this.control = c;
+ }
+
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java
new file mode 100644
index 0000000..b4a7e98
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java
@@ -0,0 +1,112 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
+import org.eclipse.jface.dialogs.IMessageProvider;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class ModelCheckor {
+
+ private EclipseResourcesUtil eclipseResourcesUtil = EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE ? new EclipseResourcesUtil()
+ : null;
+
+ public List<MessageData> check(ResourceSet toCheck) {
+ List<MessageData> messages = new ArrayList<MessageData>();
+
+ try {
+ // get copy
+ EList<Resource> resources = toCheck.getResources();
+ if (resources != null) {
+
+ for (Resource res : resources) {
+ TreeIterator<EObject> allContents = res.getAllContents();
+ if (!allContents.hasNext())
+ continue;
+
+ EObject rootObject = allContents.next();
+ messages.addAll(ecoreValidation(rootObject));
+ }
+ }
+ }
+ catch (Exception e) {
+ String erMes = e.getLocalizedMessage();
+ if (erMes == null) {
+ erMes = e.toString();
+ }
+ messages.add(new MessageData(":(", "An Error occured during checking: " + erMes, null,
+ IMessageProvider.WARNING));
+ }
+ return messages;
+ }
+
+ private List<MessageData> ecoreValidation(EObject rootObject) {
+ int status = IMessageProvider.INFORMATION;
+ // Clear Marker
+ if (eclipseResourcesUtil != null) {
+ eclipseResourcesUtil.deleteMarkers(rootObject);
+ }
+
+ Diagnostic diagnostic = Diagnostician.INSTANCE.validate(rootObject);
+
+ switch (diagnostic.getSeverity()) {
+ case Diagnostic.ERROR:
+ status = IMessageProvider.ERROR;
+ break;
+ case Diagnostic.WARNING:
+ status = IMessageProvider.WARNING;
+ break;
+ case Diagnostic.INFO:
+ status = IMessageProvider.INFORMATION;
+ default:
+ break;
+ }
+ return createMessagesFromDiagnostic(rootObject, diagnostic, status);
+ }
+
+ /**
+ * @param rootObject
+ * @param diagnostic
+ */
+ private List<MessageData> createMessagesFromDiagnostic(EObject rootObject, Diagnostic diagnostic, int status) {
+
+ List<MessageData> mds = new ArrayList<MessageData>();
+ for (Iterator<Diagnostic> i = diagnostic.getChildren().iterator(); i.hasNext();) {
+ Diagnostic childDiagnostic = i.next();
+ if (eclipseResourcesUtil != null)
+ eclipseResourcesUtil.createMarkers(rootObject.eResource(), childDiagnostic);
+ String message = childDiagnostic.getMessage();
+ MessageData md = new MessageData(childDiagnostic, message, childDiagnostic.getData(), status);
+ mds.add(md);
+ }
+ return mds;
+ }
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawFacade.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawFacade.java
new file mode 100644
index 0000000..66cbf77
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawFacade.java
@@ -0,0 +1,152 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.oaw;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.emf.mwe.core.issues.Issues;
+import org.eclipse.emf.mwe.core.issues.IssuesImpl;
+import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
+import org.eclipse.internal.xtend.xtend.ast.ExtensionFile;
+import org.eclipse.xtend.XtendFacade;
+import org.eclipse.xtend.check.CheckUtils;
+import org.eclipse.xtend.expression.EvaluationException;
+import org.eclipse.xtend.expression.ExecutionContext;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class OawFacade {
+
+ private IProject project;
+ private final ExecutionContext context;
+ public static final String CHECK_EXT = "Checks";
+ public static final String STYLE_EXT = "ItemLabelProvider";
+ public static final String PROPOSAL_EXT = "Proposals";
+
+ public OawFacade(IProject project, ExecutionContext context) {
+ this.project = project;
+ this.context = context;
+ }
+
+ public Object style(String extension, EObject object) {
+ String extendFile = path(object) + OawFacade.STYLE_EXT;
+ Object retVal = evaluate(extendFile, extension, object);
+ return retVal;
+ }
+
+ /**
+ * @param extensionFile
+ * @param extensionName
+ * @param params
+ * @return
+ */
+ private Object evaluate(String extensionFile, String extensionName, Object... params) {
+ Object retVal = null;
+ try {
+ XtendFacade facade = XtendFacade.create(context, extensionFile);
+ retVal = facade.call(extensionName, params);
+ }
+ catch (IllegalArgumentException e) {
+ // no extension specified
+ }
+ catch (EvaluationException e) {
+ EEPlugin.logError("Exception during extension evaluation", e);
+ }
+ catch (RuntimeException e) {
+ // TODO check file exists
+ // extension file not found
+ }
+ catch (Throwable e) {
+ EEPlugin.logError("Exception during extension evaluation", new RuntimeException(e));
+ }
+ return retVal;
+ }
+
+ // TODO split method
+ public List<?> proposals(EStructuralFeature feature, EObject ctx, List<?> fromList) {
+ String extFile = path(ctx) + OawFacade.PROPOSAL_EXT;
+ List<?> retVal = new ArrayList<Object>();
+ Object eval;
+ if (fromList != null) {
+ retVal = fromList;
+ eval = evaluate(extFile, feature.getName(), ctx, fromList);
+ }
+ else {
+ eval = evaluate(extFile, feature.getName(), ctx);
+ }
+ if (eval != null) {
+ if (eval instanceof List<?>) {
+ retVal = (List<?>) eval;
+ }
+ else {
+ EEPlugin.logError("Returned type must be a List! File:" + extFile + ", Extension:" + feature.getName());
+ }
+ }
+ return retVal;
+ }
+
+ public Issues check(EObject rootObject) {
+ String checkFile = path(rootObject) + OawFacade.CHECK_EXT;
+ List<EObject> all = new ArrayList<EObject>();
+ all.add(rootObject);
+ EObject rootContainer = EcoreUtil.getRootContainer(rootObject);
+ TreeIterator<EObject> iter = rootContainer.eAllContents();
+ while (iter.hasNext())
+ all.add(iter.next());
+
+ IssuesImpl issuesImpl = new IssuesImpl();
+ // FIXME IOawProject oAWProject =
+ // OawPlugin.getOawModelManager().findProject(project);
+ // if (oAWProject != null) {
+ // IOawResource oawResource = oAWProject.findOawResource(checkFile,
+ // CheckUtils.FILE_EXTENSION);
+ // if (oawResource != null) {
+ // ExtensionFile file = (ExtensionFile) oawResource.getOawResource();
+ // try {
+ // file.check(context, all, issuesImpl, false);
+ // }
+ // catch (IllegalArgumentException e) {
+ // // no extension specified
+ // }
+ // catch (Exception e) {
+ // EEPlugin.logError("Exception during check evaluation", e);
+ // }
+ // }
+ // }
+ // else {
+ // EEPlugin.logWarning("Enable oAW-Nature for '" + project.getName() +
+ // "' to check models.");
+ // }
+ return issuesImpl;
+ }
+
+ private String path(EObject object) {
+ return object.eClass().getEPackage().getName() + SyntaxConstants.NS_DELIM;
+ }
+
+ public IProject getProject() {
+ return project;
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawHelper.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawHelper.java
new file mode 100644
index 0000000..0e18287
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/OawHelper.java
@@ -0,0 +1,41 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.oaw;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.editor.MessageData;
+
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class OawHelper {
+ static public EStructuralFeature extractFeatureFromMessage(EObject eObject,
+ MessageData md) {
+ String message = md.getMessage();
+ int i = message.indexOf('#');
+ if (i > 0 && i < message.length() - 1) {
+ String featureName = message.substring(0, i);
+ message = message.substring(i + 1);
+ md.setMessage(message);
+ return eObject.eClass().getEStructuralFeature(featureName);
+ }
+ return null;
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/WorkspaceResourceManager.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/WorkspaceResourceManager.java
new file mode 100644
index 0000000..d41c88f
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/oaw/WorkspaceResourceManager.java
@@ -0,0 +1,56 @@
+///**
+// * <copyright>
+// *
+// * Copyright (c) 2008 itemis AG 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:
+// * itemis AG - Initial API and implementation
+// *
+// * </copyright>
+// *
+// */
+//package org.eclipse.emf.editor.oaw;
+//
+//import org.eclipse.core.resources.IProject;
+//import org.eclipse.core.resources.IResource;
+//import org.eclipse.xtend.expression.Resource;
+//import org.eclipse.xtend.expression.ResourceManager;
+//import org.eclipse.xtend.expression.ResourceParser;
+//
+//
+///**
+// * @author Dennis Huebner
+// *
+// */
+//public class WorkspaceResourceManager implements ResourceManager {
+//
+// private IProject project;
+//
+// public WorkspaceResourceManager(IProject p) {
+// this.project = p;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.xtend.expression.ResourceManager#loadResource(java.lang.String, java.lang.String)
+// */
+// public Resource loadResource(String fullyQualifiedName, String extension) {
+// IResource oawResource = project.findOawResource(fullyQualifiedName,
+// extension);
+// if (oawResource != null)
+// return oawResource.getOawResource();
+// return null;
+// }
+//
+// public void registerParser(String template_extension, ResourceParser parser) {
+// // not needed
+// }
+//
+// public void setFileEncoding(String fileEncoding) {
+// // not needed
+// }
+//
+//}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolutionException.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolutionException.java
new file mode 100644
index 0000000..ef3aeda
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolutionException.java
@@ -0,0 +1,12 @@
+package org.eclipse.emf.editor.provider;
+
+
+public class ClasspathUriResolutionException extends RuntimeException {
+
+ private static final long serialVersionUID = 1124765L;
+
+ public ClasspathUriResolutionException(Exception exc) {
+ super(exc);
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolver.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolver.java
new file mode 100644
index 0000000..bfea535
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ClasspathUriResolver.java
@@ -0,0 +1,196 @@
+package org.eclipse.emf.editor.provider;
+
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.framework.internal.core.BundleHost;
+import org.eclipse.osgi.framework.internal.core.BundleURLConnection;
+import org.osgi.framework.Bundle;
+
+/**
+ * Resolves a classpath URI to a file URI or platform:/resource URI.
+ *
+ * A classpath URI has the following form:
+ *
+ * <pre>
+ * classpath:/&lt;java package&gt;/&lt;resource file name&gt;
+ * &lt;pre&gt;
+ * </pre>
+ *
+ * A classpath URI can only be resolved in the context of a classpath. This can
+ * either be given
+ * <ul>
+ * <li>by a Java project in workspace
+ * <li>by the global classloader of a standalone Java application.
+ * </ul>
+ * It can only be resolved if the referenced resource file can be located. It
+ * does not matter if it is contained in a jar or exists as a plain file.
+ *
+ * @author koehnlein
+ */
+public class ClasspathUriResolver {
+
+ public static final String CLASSPATH_SCHEME = "classpath";
+
+ public URI resolve(ClassLoader classLoader, URI classpathUri) {
+ try {
+ if (isClassapthUri(classpathUri)) {
+ return findResourceOnClasspath(classLoader, classpathUri);
+ }
+ }
+ catch (Exception exc) {
+ throw new ClasspathUriResolutionException(exc);
+ }
+ return classpathUri;
+ }
+
+ public URI resolve(IResource resource, URI classpathUri) {
+ try {
+ if (isClassapthUri(classpathUri)) {
+ IProject project = resource.getProject();
+ IJavaProject javaProject = JavaCore.create(project);
+ return findResourceInWorkspace(javaProject, classpathUri);
+ }
+ }
+ catch (Exception exc) {
+ throw new ClasspathUriResolutionException(exc);
+ }
+ return classpathUri;
+ }
+
+ public URI resolve(IJavaElement javaElement, URI classpathUri) {
+ try {
+ if (isClassapthUri(classpathUri)) {
+ IJavaProject javaProject = javaElement.getJavaProject();
+ return findResourceInWorkspace(javaProject, classpathUri);
+ }
+ }
+ catch (Exception exc) {
+ throw new ClasspathUriResolutionException(exc);
+ }
+ return classpathUri;
+ }
+
+ public URI resolve(Bundle bundle, URI classpathUri) {
+ try {
+ if (isClassapthUri(classpathUri)) {
+ return findResourceInBundle(bundle, classpathUri);
+ }
+ }
+ catch (Exception exc) {
+ throw new ClasspathUriResolutionException(exc);
+ }
+ return classpathUri;
+ }
+
+ public static boolean isClassapthUri(URI uri) {
+ String scheme = uri.scheme();
+ return CLASSPATH_SCHEME.equals(scheme);
+ }
+
+ private URI findResourceOnClasspath(ClassLoader classLoader, URI classpathUri) throws URISyntaxException {
+ String pathAsString = classpathUri.path();
+ if (classpathUri.hasAbsolutePath()) {
+ pathAsString = pathAsString.substring(1);
+ }
+ URL resource = classLoader.getResource(pathAsString);
+ URI fileUri = URI.createURI(resource.toURI().toString());
+ return fileUri;
+ }
+
+ @SuppressWarnings("restriction")
+ private URI findResourceInBundle(Bundle bundle, URI classpathUri) throws MalformedURLException, IOException {
+ Path fullPath = new Path(classpathUri.path());
+ if (bundle != null) {
+ String projectRelativePath = "/" + fullPath;
+ URL resourceUrl = bundle.getResource(projectRelativePath);
+ if (resourceUrl != null) {
+ String baseUrl = ((BaseData) ((BundleHost) bundle).getBundleData()).getBundleFile().getBaseFile()
+ .toURL().toString();
+ if (baseUrl.endsWith(".jar")) {
+ baseUrl = "jar:" + baseUrl + "!/";
+ }
+ String localUrl = ((BundleURLConnection) resourceUrl.openConnection()).getLocalURL().toString();
+ String platformPluginUri = bundle.getSymbolicName() + "/" + localUrl.substring(baseUrl.length());
+ URI normalizedURI = URI.createPlatformPluginURI(platformPluginUri, true);
+ return normalizedURI;
+ }
+ }
+ return classpathUri;
+ }
+
+ @SuppressWarnings("restriction")
+ private URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws JavaModelException,
+ CoreException {
+ Path fullPath = new Path(classpathUri.path());
+ String projectRelativePath = fullPath.toString();
+ if (javaProject.exists()) {
+ IPackageFragmentRoot[] allPackageFragmentRoots = javaProject.getAllPackageFragmentRoots();
+ for (IPackageFragmentRoot packageFragmentRoot : allPackageFragmentRoots) {
+ IResource correspondingResource = packageFragmentRoot.getCorrespondingResource();
+ if (correspondingResource != null) {
+ if (correspondingResource instanceof IFile) {
+ // jar file
+ JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) JavaCore
+ .createJarPackageFragmentRootFrom((IFile) correspondingResource);
+ if (jarPackageFragmentRoot != null) {
+ ZipFile zipFile = jarPackageFragmentRoot.getJar();
+ if (zipFile != null) {
+ ZipEntry zipEntry = zipFile.getEntry(projectRelativePath.substring(1));
+ if (zipEntry != null) {
+ return URI.createURI("jar:" + "platform:/resource"
+ + correspondingResource.getFullPath() + "!" + projectRelativePath, true);
+ }
+ }
+ }
+ }
+ else {
+ // plain file
+ IFolder rootFolder = (IFolder) correspondingResource;
+ IResource modelFile = rootFolder.findMember(projectRelativePath);
+ if (modelFile != null && modelFile.exists() && modelFile instanceof IFile) {
+ URI platformResourceUri = URI.createPlatformResourceURI(modelFile.getFullPath().toString(),
+ true);
+ return platformResourceUri;
+ }
+ }
+ }
+ }
+ }
+ return classpathUri;
+ }
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java
new file mode 100644
index 0000000..a3ca32b
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java
@@ -0,0 +1,191 @@
+package org.eclipse.emf.editor.provider;
+
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.emf.editor.oaw.OawFacade;
+import org.eclipse.emf.editor.ui.ImageRegistry;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class ExtendedLabelProvider implements IItemLabelProvider {
+
+ private static final String ICONS_FOLDER = "icons";
+ private static final String ICON_EXTENSION_NAME = "icon";
+ private static final String LABEL_EXTENSION_NAME = "label";
+ private final OawFacade facade;
+ private IItemLabelProvider registryItemLabelProvider;
+
+ public ExtendedLabelProvider(OawFacade facade) {
+ this.facade = facade;
+ this.registryItemLabelProvider = new RegistryItemLabelProvider();
+ }
+
+ public Object getImage(Object element) {
+ Object retVal = null;
+ try {
+ if (element instanceof EObject) {
+ EObject eObject = (EObject) element;
+ String iconName = evaluate(eObject, ICON_EXTENSION_NAME);
+ Resource eResource = eObject.eClass().eResource();
+ // TODO try instance scope
+ // retVal = locateImage(iconName, eObject.eResource(), eObject);
+ // if not found try metamodel scope
+ if (retVal == null && iconName != null)
+ retVal = locateImage(iconName, eResource, eObject);
+ }
+ } catch (Throwable ex) {
+ EEPlugin.logError("ERROR", ex);
+ }
+ if (retVal != null)
+ return retVal;
+ // Fallback: Ask registry for image
+ return registryItemLabelProvider.getImage(element);
+
+ }
+
+ /**
+ * @param iconName
+ * @param eResource
+ * @param eObject
+ * @return
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ private Object locateImage(String iconName, Resource eResource,
+ EObject eObject) throws MalformedURLException, IOException {
+ // TODO understand the requirements :)
+ Object retVal = null;
+ if (eResource != null) {
+ URI metaModelURI = eResource.getURI();
+ URI iconURI = createIconURI(eObject, iconName, metaModelURI);
+
+ if (metaModelURI.isPlatform()) {
+ // platform resource... good
+ String platformString = metaModelURI.toPlatformString(true);
+
+ IFile metaModelFile = ResourcesPlugin.getWorkspace().getRoot()
+ .getFile(new Path(platformString));
+ if (metaModelFile != null) {
+ // using IFile to allow resource change listening
+ IFile f = metaModelFile.getProject()
+ .getFile(iconURI.path());
+ if (f != null && f.exists()) {
+ // ask registry
+ retVal = ImageRegistry.getDefault().getImage(f);
+ }
+ }
+ } else if (metaModelURI.isArchive()) {// archived
+ // handle archived resources
+ // return URI. Image will be stored in
+ // ExtendedImageRegistry
+ // which is not refreshable
+ if (checkAccessable(iconURI))
+ retVal = iconURI;
+ } else {
+ // eResource not present physically... bad
+ URI classpathURI = URI
+ .createURI(ClasspathUriResolver.CLASSPATH_SCHEME + ":"
+ + iconURI.path());
+ URI iconNormalizedURI = new ClasspathUriResolver().resolve(
+ facade.getProject(), classpathURI);
+ // return URI. Image will be stored in
+ // ExtendedImageRegistry
+ // which is not refreshable
+ if (!ClasspathUriResolver.isClassapthUri(iconNormalizedURI)
+ && checkAccessable(iconNormalizedURI))
+ retVal = iconNormalizedURI;
+ }
+ }
+ return retVal;
+ }
+
+ private boolean checkAccessable(URI iconURI) throws IOException {
+ URL url = new URL(iconURI.toString());
+ if (url != null) {
+ try {
+ InputStream in = url.openStream();// check readable
+ in.close();
+ return true;
+ } catch (FileNotFoundException e) {
+ // ignore no feedback to user
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param element
+ * @param iconName
+ * @param metaModelURI
+ * @return
+ */
+ private URI createIconURI(EObject eObject, String iconName, URI metaModelURI) {
+ String packageName = packageName(eObject);
+ return metaModelURI.trimSegments(metaModelURI.segmentCount())
+ .appendSegment(ICONS_FOLDER).appendSegment(packageName)
+ .appendSegment(iconName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.edit.provider.IItemLabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ String text = evaluate(element, LABEL_EXTENSION_NAME);
+ return text;
+ }
+
+ /**
+ * @param element
+ * @param retVal
+ * @return
+ */
+ private String evaluate(Object element, String name) {
+ String retVal = null;
+ if (element instanceof EObject && facade != null) {
+ EObject eO = (EObject) element;
+ retVal = (String) facade.style(name, eO);
+ }
+ return retVal;
+ }
+
+ /**
+ * @param object
+ * @return
+ */
+ private String packageName(EObject object) {
+ return object.eClass().getEPackage().getName();
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java
new file mode 100644
index 0000000..38d9ce7
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java
@@ -0,0 +1,75 @@
+package org.eclipse.emf.editor.provider;
+
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.provider.ReflectiveItemProvider;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class ExtendedReflectiveItemProviderAdapterFactory extends
+ ReflectiveItemProviderAdapterFactory {
+
+ public final class ExtendedReflectiveItemProvider extends
+ ReflectiveItemProvider {
+ private final ExtendedLabelProvider labelProvider;
+
+ private ExtendedReflectiveItemProvider(AdapterFactory adapterFactory,
+ ExtendedLabelProvider labelProvider) {
+ super(adapterFactory);
+ this.labelProvider = labelProvider;
+ }
+
+ public String getTextForFeature(EStructuralFeature feature) {
+ return getFeatureText(feature);
+ }
+
+ @Override
+ public String getText(Object object) {
+ String text = labelProvider.getText(object);
+ if (text == null) {
+ if (object instanceof EStructuralFeature) {
+ EStructuralFeature f = (EStructuralFeature) object;
+ text = super.getFeatureText(f);
+ }
+ text = super.getText(object);
+ }
+ return text;
+ }
+
+ @Override
+ public Object getImage(Object object) {
+ Object imURI = labelProvider.getImage(object);
+ if (imURI != null) {
+ return imURI;
+ }
+ return super.getImage(object);
+ }
+ }
+
+ public ExtendedReflectiveItemProviderAdapterFactory(
+ final ExtendedLabelProvider labelProvider) {
+ super();
+ reflectiveItemProviderAdapter = new ExtendedReflectiveItemProvider(
+ this, labelProvider);
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/RegistryItemLabelProvider.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/RegistryItemLabelProvider.java
new file mode 100644
index 0000000..e343445
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/RegistryItemLabelProvider.java
@@ -0,0 +1,62 @@
+package org.eclipse.emf.editor.provider;
+
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory.Descriptor;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory.Descriptor.Registry;
+
+/**
+ * @author Dennis Hübner - Initial contribution and API
+ *
+ */
+public class RegistryItemLabelProvider implements IItemLabelProvider {
+
+ private Map<String, AdapterFactory> _cache = new HashMap<String, AdapterFactory>();
+
+ public Object getImage(Object element) {
+ IItemLabelProvider itemlabelProvider = findItemLabelProvider(element);
+ if (itemlabelProvider != null) {
+ return itemlabelProvider.getImage(element);
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ IItemLabelProvider itemlabelProvider = findItemLabelProvider(element);
+ if (itemlabelProvider != null) {
+ return itemlabelProvider.getText(element);
+ }
+ return null;
+ }
+
+ private IItemLabelProvider findItemLabelProvider(Object element) {
+ String nsURI = ((EObject) element).eClass().getEPackage().getNsURI();
+ AdapterFactory adapterFactory = _cache.get(nsURI);
+ IItemLabelProvider itemlabelProvider;
+ if (adapterFactory == null) {
+ Registry composedAdapterFactoryRegistry = ComposedAdapterFactory.Descriptor.Registry.INSTANCE;
+ Descriptor descriptor = composedAdapterFactoryRegistry
+ .getDescriptor(Arrays
+ .asList(new Object[] { nsURI.toString(),
+ "org.eclipse.emf.edit.provider.IItemLabelProvider" }));
+ if (descriptor != null) {
+ adapterFactory = descriptor.createAdapterFactory();
+ _cache.put(nsURI, adapterFactory);
+ }
+ }
+ if (adapterFactory != null) {
+ itemlabelProvider = (IItemLabelProvider) adapterFactory.adapt(
+ element, IItemLabelProvider.class);
+ return itemlabelProvider;
+ }
+ return null;
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEDetailsPageProvider.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEDetailsPageProvider.java
new file mode 100644
index 0000000..726e070
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEDetailsPageProvider.java
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.ecore.impl.EObjectImpl;
+import org.eclipse.emf.editor.EEditor;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.ui.forms.IDetailsPage;
+import org.eclipse.ui.forms.IDetailsPageProvider;
+
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class EEDetailsPageProvider implements IDetailsPageProvider {
+ private GenericDetailsPage page;
+ private EEditor editor;
+
+ public EEDetailsPageProvider(EEditor editor) {
+ Assert.isNotNull(editor);
+ this.editor = editor;
+ // domain.getCommandStack().addCommandStackListener(this);
+ }
+
+ public IDetailsPage getPage(Object key) {
+ EObjectImpl input = null;
+ if (key instanceof EObjectImpl) {
+ EObjectImpl eModelElement = (EObjectImpl) key;
+ input = eModelElement;
+ }
+ page = new GenericDetailsPage(input, editor);
+ page.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ editor.setSelection(event.getSelection());
+ }
+ });
+ return page;
+ }
+
+ public Object getPageKey(Object object) {
+ return object;
+ }
+
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java
new file mode 100644
index 0000000..c3f2396
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java
@@ -0,0 +1,148 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.emf.editor.EEditor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.DetailsPart;
+import org.eclipse.ui.forms.IDetailsPageProvider;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.MasterDetailsBlock;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class EEMasterDetailsBlock extends MasterDetailsBlock {
+
+ private SectionPart masterSectionPart;
+ private IDetailsPageProvider pageProvider;
+
+ public EEMasterDetailsBlock(IDetailsPageProvider pageProvider) {
+ this.pageProvider = pageProvider;
+ }
+
+ public SectionPart getMasterSectionPart() {
+ return this.masterSectionPart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.ui.forms.IManagedForm,
+ * org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createMasterPart(IManagedForm managedForm, Composite parent) {
+ Composite container = managedForm.getToolkit().createComposite(parent);
+ container.setLayout(new GridLayout());
+ // container.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ Section section = managedForm.getToolkit().createSection(container,
+ ExpandableComposite.TITLE_BAR);
+ section.setLayout(new FillLayout());
+ section.setLayoutData(new GridData(GridData.FILL_BOTH));
+ section.setText("Model");
+ Composite mastersClientArea = managedForm.getToolkit().createComposite(
+ section);
+ section.setClient(mastersClientArea);
+ masterSectionPart = new SectionPart(section);
+ managedForm.addPart(masterSectionPart);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createToolBarActions(org.eclipse.ui.forms.IManagedForm)
+ */
+ @Override
+ protected void createToolBarActions(IManagedForm managedForm) {
+ sashForm.setOrientation(EEditor.formularOrientation());
+ final ScrolledForm form = managedForm.getForm();
+
+ Action haction = new Action("hor", IAction.AS_RADIO_BUTTON) {
+ @Override
+ public void run() {
+ sashForm.setOrientation(SWT.VERTICAL);
+ persistOrientation(SWT.VERTICAL);
+ }
+ };
+ haction.setChecked(sashForm.getOrientation() == SWT.VERTICAL);
+
+ haction.setToolTipText("Horizontal orientation");
+ haction.setImageDescriptor(EEPlugin
+ .getImageDescriptor("/icons/det_pane_under.gif"));
+ Action vaction = new Action("ver", IAction.AS_RADIO_BUTTON) {
+ @Override
+ public void run() {
+ sashForm.setOrientation(SWT.HORIZONTAL);
+ persistOrientation(SWT.HORIZONTAL);
+ }
+ };
+ vaction.setChecked(sashForm.getOrientation() == SWT.HORIZONTAL);
+
+ vaction.setToolTipText("Vertical orientation");
+ vaction.setImageDescriptor(EEPlugin
+ .getImageDescriptor("/icons/det_pane_right.gif"));
+ form.getToolBarManager().add(haction);
+ form.getToolBarManager().add(vaction);
+ createMoreToolBarActions(form.getToolBarManager());
+ form.getToolBarManager().update(true);
+
+ }
+
+ protected void persistOrientation(int orientation) {
+ IPreferenceStore store = EEPlugin.getDefault().getPreferenceStore();
+ store.setValue(IPreferenceConstants.FORMULAR_ORIENTATION, orientation);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
+ */
+ @Override
+ protected void registerPages(DetailsPart detailsPart) {
+ detailsPart.setPageProvider(this.pageProvider);
+ detailsPart.setPageLimit(1);// cache off!
+ }
+
+ public Control findControl(String key, Object data) {
+ if (detailsPart.getCurrentPage() instanceof GenericDetailsPage) {
+ return ((GenericDetailsPage) detailsPart.getCurrentPage())
+ .locateControl(key, data);
+ }
+ return null;
+ }
+
+ protected void createMoreToolBarActions(IToolBarManager toolBarManager) {
+ // does nothing
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/GenericDetailsPage.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/GenericDetailsPage.java
new file mode 100644
index 0000000..7df3042
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/GenericDetailsPage.java
@@ -0,0 +1,308 @@
+/**
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.impl.EObjectImpl;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
+import org.eclipse.emf.editor.EEditor;
+import org.eclipse.emf.editor.ui.binding.EmfSwtBindingFactory;
+import org.eclipse.emf.editor.ui.binding.MultipleFeatureControl;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+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.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.TextActionHandler;
+import org.eclipse.ui.forms.AbstractFormPart;
+import org.eclipse.ui.forms.IDetailsPage;
+import org.eclipse.ui.forms.IFormPart;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.Section;
+
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class GenericDetailsPage extends AbstractFormPart implements
+ ISelectionProvider, IDetailsPage {
+ private final class EStructuralfeatureComparator implements
+ Comparator<EStructuralFeature> {
+ public int compare(EStructuralFeature o1, EStructuralFeature o2) {
+ return nullSafe(o1).compareTo(nullSafe(o2));
+ }
+
+ /**
+ * @param o1
+ * @return
+ */
+ private String nullSafe(EStructuralFeature o) {
+ String name = o.getName();
+ return name != null ? name : new String();
+ }
+ }
+
+ private EObjectImpl input;
+
+ private Composite main;
+ private EEditor editor;
+
+ public GenericDetailsPage(EObjectImpl object, EEditor editor) {
+ this.input = object;
+ this.editor = editor;
+ }
+
+ public void createContents(Composite parent) {
+ parent.setLayout(new FillLayout());
+ Section sec = getManagedForm().getToolkit().createSection(parent,
+ ExpandableComposite.TITLE_BAR);
+ sec.marginWidth = 10;
+ sec.marginHeight = 5;
+ sec.setText("Properties");
+ main = getManagedForm().getToolkit().createComposite(sec);
+ main.setLayout(new GridLayout(2, false));
+ MenuManager mm = new MenuManager("#DetailsPartMenu");
+ mm.setRemoveAllWhenShown(false);
+ mm.add(new Action("Reset to default") {
+ @Override
+ public void run() {
+ main.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ if (getSelection() instanceof StructuredSelection) {
+ Object o = ((StructuredSelection) getSelection())
+ .getFirstElement();
+ // just single selection is allowed (which has
+ // focus)
+ if (o instanceof EStructuralFeature) {
+ EStructuralFeature feature = (EStructuralFeature) o;
+
+ // Reusing already implemented logic
+ IItemPropertyDescriptor desc = new ItemPropertyDescriptor(
+ editor.getAdapterFactory(), null,
+ feature.getName(), new String(),
+ feature, true);
+ if (desc.isPropertySet(input)) {
+ desc.resetPropertyValue(input);
+ if (feature.isMany()) {
+ // TODO work around for ListViewer in
+ // MultipleFeatureControl
+ Control locatedControl = locateControl(
+ EcorePackage.Literals.ESTRUCTURAL_FEATURE
+ .getName(), feature);
+ if (locatedControl instanceof MultipleFeatureControl) {
+ MultipleFeatureControl mfc = (MultipleFeatureControl) locatedControl;
+ mfc.quietClearSelection();
+ }
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+ });
+
+ // IActionBars actionBars = editor.getActionBars();
+ // IAction oldCopyAction = actionBars
+ // .getGlobalActionHandler(ActionFactory.COPY.getId());
+ // actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
+ // new ActionWrapper(oldCopyAction));
+ IWorkbenchWindow window = editor.getSite().getWorkbenchWindow();
+
+ mm.add(ActionFactory.COPY.create(window));
+ mm.add(new Separator("additions"));
+ Menu menu = mm.createContextMenu(main);
+
+ editor.getSite().registerContextMenu(mm.getId(), mm, this);
+ createGenericPart(menu);
+ sec.setClient(main);
+ }
+
+ private void createGenericPart(Menu menu) {
+ if (input != null) {
+ cleanUpMainComposite();
+ EList<EStructuralFeature> allStructuralFeatures = new BasicEList<EStructuralFeature>(
+ input.eClass().getEAllStructuralFeatures());
+ Collections.sort(allStructuralFeatures,
+ new EStructuralfeatureComparator());
+
+ factory = new EmfSwtBindingFactory(editor.getAdapterFactory(),
+ editor.getEditingDomain(), input, main, getManagedForm()
+ .getToolkit(), editor.getOawFacade());
+ final IActionBars actionBars = editor.getActionBars();
+
+ final IAction ecoreCopy = actionBars
+ .getGlobalActionHandler(ActionFactory.COPY.getId());
+ final IAction ecoreCut = actionBars
+ .getGlobalActionHandler(ActionFactory.CUT.getId());
+ final IAction ecorePaste = actionBars
+ .getGlobalActionHandler(ActionFactory.PASTE.getId());
+ final IAction ecoreDelete = actionBars
+ .getGlobalActionHandler(ActionFactory.DELETE.getId());
+
+ for (final EStructuralFeature feature : allStructuralFeatures) {
+ // derived, unchangeable, container and containment features
+ // ignored
+ if (feature.isChangeable()
+ && !feature.isDerived()
+ && !(feature instanceof EReference && (((EReference) feature)
+ .isContainment() || ((EReference) feature)
+ .isContainer()))) {
+ createLabel(editor.getExtendedReflectiveItemProvider()
+ .getTextForFeature(feature));
+
+ final Control contr = factory.create(feature);
+
+ contr.setMenu(menu);
+ contr.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(
+ org.eclipse.swt.events.FocusEvent e) {
+ // FIXME hook ecore's action contributor or create
+ // an own
+ if (contr instanceof Text) {
+ TextActionHandler textHandlerh = new TextActionHandler(
+ actionBars);
+ Text t = (Text) contr;
+ textHandlerh.addText(t);
+
+ textHandlerh.setCopyAction(ecoreCopy);
+ textHandlerh.setCutAction(ecoreCut);
+ textHandlerh.setPasteAction(ecorePaste);
+ textHandlerh.setDeleteAction(ecoreDelete);
+ actionBars.updateActionBars();
+
+ }
+ setSelection(new StructuredSelection(feature));
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ actionBars.setGlobalActionHandler(
+ ActionFactory.COPY.getId(), ecoreCopy);
+ actionBars.setGlobalActionHandler(ActionFactory.CUT
+ .getId(), ecoreCut);
+ actionBars.setGlobalActionHandler(
+ ActionFactory.DELETE.getId(), ecoreDelete);
+ actionBars.setGlobalActionHandler(
+ ActionFactory.PASTE.getId(), ecorePaste);
+ }
+ });
+
+ }
+ }
+
+ getManagedForm().getToolkit().paintBordersFor(main);
+ }
+ }
+
+ /**
+ *
+ */
+ private void cleanUpMainComposite() {
+ for (Control child : main.getChildren()) {
+ child.dispose();
+ }
+ }
+
+ private Label createLabel(String string) {
+ Label lab = getManagedForm().getToolkit().createLabel(main, string);
+ lab.setLayoutData(new GridData());
+ return lab;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.IFormPart#dispose()
+ */
+ @Override
+ public void dispose() {
+
+ if (factory != null) {
+ factory.dispose();
+ }
+ if (!main.isDisposed() && !main.getParent().isDisposed())
+ main.getParent().dispose();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.IFormPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ main.setFocus();
+ }
+
+ public Control locateControl(String key, Object data) {
+ for (Control c : main.getChildren()) {
+ Object controlsData = c.getData(key);
+ if (controlsData != null && controlsData.equals(data)) {
+ return c;
+ }
+ }
+ return null;
+ }
+
+ private List<ISelectionChangedListener> selListeners = new ArrayList<ISelectionChangedListener>();
+ private ISelection partSelection = null;
+ private EmfSwtBindingFactory factory;
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ this.selListeners.add(listener);
+ }
+
+ public ISelection getSelection() {
+ return partSelection;
+ }
+
+ public void removeSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ this.selListeners.remove(listener);
+ }
+
+ public void setSelection(ISelection selection) {
+ partSelection = selection;
+ for (ISelectionChangedListener listener : selListeners) {
+ listener
+ .selectionChanged(new SelectionChangedEvent(this, selection));
+ }
+ }
+
+ public void selectionChanged(IFormPart part, ISelection selection) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/IPreferenceConstants.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/IPreferenceConstants.java
new file mode 100644
index 0000000..02f0c09
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/IPreferenceConstants.java
@@ -0,0 +1,24 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public interface IPreferenceConstants {
+ public static final String FORMULAR_ORIENTATION = "eeditor.orientation";
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ImageRegistry.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ImageRegistry.java
new file mode 100644
index 0000000..beade28
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ImageRegistry.java
@@ -0,0 +1,184 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.services.IDisposable;
+
+/**
+ * Automatic refreshable ImageRegistry
+ *
+ * @author Dennis Hübner
+ *
+ */
+public class ImageRegistry implements IDisposable {
+ private static ImageRegistry imageRegistry;
+ private Map<String, Image> register = new HashMap<String, Image>();
+ private Set<Image> deletedImages = new HashSet<Image>();
+ private List<ChangeListener> registryChangedListeners = new ArrayList<ChangeListener>();
+
+ public static ImageRegistry getDefault() {
+ if (imageRegistry == null)
+ imageRegistry = new ImageRegistry();
+ return imageRegistry;
+ }
+
+ public Image getImage(IFile iconFile) {
+ String imageKey = computeImageKey(iconFile);
+ Image icon = register.get(imageKey);
+ if (icon == null) {
+ // load from project
+ registerImage(iconFile);
+ icon = register.get(imageKey);
+ }
+ return icon;
+ }
+
+ /**
+ * @param iconFile
+ * @param imageKey
+ */
+ private Image registerImage(IFile iconFile) {
+ Image icon = null;
+ if (iconFile.exists()) {
+ ImageDescriptor imageDescriptor = null;
+ try {
+ imageDescriptor = ImageDescriptor.createFromURL(iconFile
+ .getLocation().toFile().toURI().toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ if (imageDescriptor != null) {
+ icon = imageDescriptor.createImage(false);
+ if (icon != null) {
+ // register
+ register.put(computeImageKey(iconFile), icon);
+ notifyListeners();
+ registerResourceChangeListener(iconFile);
+ }
+ }
+ }
+ return icon;
+ }
+
+ /**
+ * @param iconFile
+ * @return
+ */
+ private String computeImageKey(IFile iconFile) {
+ return iconFile.getFullPath().toString();
+ }
+
+ private void registerResourceChangeListener(final IFile iconFile) {
+ final IWorkspace workspace = iconFile.getWorkspace();
+ IResourceChangeListener listener = new IResourceChangeListener() {
+ private IFile resource = iconFile;
+
+ public void resourceChanged(IResourceChangeEvent event) {
+
+ if (event.getDelta() != null) {// ignore open close project
+ // events
+ IResourceDelta findMember = event.getDelta().findMember(
+ resource.getFullPath());
+ if (findMember != null) {
+ String imageKey = computeImageKey(iconFile);
+ // resource changed
+ notifyListeners();
+ if ((findMember.getKind() & IResourceDelta.REMOVED) == IResourceDelta.REMOVED) {
+ // TODO couldn't dispose Image cause it used by a
+ // TreeViewer or DragDrop or else
+ // dispose later
+ deletedImages.add(register.remove(imageKey));
+ workspace.removeResourceChangeListener(this);
+ }
+ if ((findMember.getKind() & IResourceDelta.CHANGED) == IResourceDelta.CHANGED) {
+ deletedImages.add(register.remove(imageKey));
+ registerImage(iconFile);
+ }
+ }
+ }
+ }
+
+ };
+ workspace.addResourceChangeListener(listener);
+ }
+
+ public void dispose() {
+ try {
+ Set<String> keySet = register.keySet();
+ for (String key : keySet) {
+ Image im = register.get(key);
+ destroyImage(im);
+ }
+ register.clear();
+ for (Image delIm : deletedImages) {
+ destroyImage(delIm);
+ }
+ deletedImages.clear();
+ } catch (Exception e) {
+ EEPlugin.logError("ImageRegisty dispose failed!", e);
+ } finally {
+ register = new HashMap<String, Image>();
+ registryChangedListeners = new ArrayList<ChangeListener>();
+ }
+ }
+
+ /**
+ * @param im
+ */
+ private void destroyImage(final Image im) {
+ if (im != null && !im.isDisposed()) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ im.dispose();
+ }
+ });
+ }
+ }
+
+ public boolean addChangeListener(ChangeListener listener) {
+ return registryChangedListeners.add(listener);
+ }
+
+ public boolean removeChangeListener(ChangeListener listener) {
+ return registryChangedListeners.remove(listener);
+ }
+
+ private void notifyListeners() {
+ for (ChangeListener chl : registryChangedListeners) {
+ chl.stateChanged(new ChangeEvent(this));
+ }
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ProposalCreator.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ProposalCreator.java
new file mode 100644
index 0000000..65d0c5e
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/ProposalCreator.java
@@ -0,0 +1,95 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.impl.EEnumImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.editor.oaw.OawFacade;
+
+/**
+ * @author Dennis Hübner
+ *
+ */
+public class ProposalCreator {
+ private EditingDomain domain;
+ private final OawFacade facade;
+
+ public ProposalCreator(EditingDomain domain, OawFacade facade) {
+ super();
+ this.domain = domain;
+ this.facade = facade;
+ }
+
+ /**
+ *
+ * @param source
+ * @param feature
+ * @return possible values
+ */
+ public List<?> proposals(EObject source, EStructuralFeature feature) {
+
+ List<?> retVal = null;
+ // TODO Reference[] handle
+ if (feature instanceof EReference) {
+ retVal = findAllInstances(feature.getEType());
+ } else if (feature.getEType() instanceof EEnumImpl) {
+ EEnum eEnum = (EEnum) feature.getEType();
+ List<Enumerator> enumerators = new ArrayList<Enumerator>();
+ for (Iterator<?> iter = eEnum.getELiterals().iterator(); iter
+ .hasNext();) {
+ Enumerator instance = ((EEnumLiteral) iter.next())
+ .getInstance();
+ enumerators.add(instance);
+ }
+ retVal = enumerators;
+ }
+ return facade.proposals(feature, source, retVal);
+ }
+
+ private List<Object> findAllInstances(EClassifier type) {
+ List<Object> objects = new ArrayList<Object>();
+ TreeIterator<Object> allContents = EcoreUtil.getAllContents(domain
+ .getResourceSet().getResources(), true);
+ while (allContents.hasNext()) {
+ Object o = allContents.next();
+ if (type.isInstance(o))
+ objects.add(o);
+ }
+ for (TreeIterator<Object> iter = EcoreUtil.getAllContents(EcoreUtil
+ .getRootContainer(EcorePackage.eINSTANCE, true), false); iter
+ .hasNext();) {
+ Object next = iter.next();
+ if ((type.isInstance(next)) && !objects.contains(next)) {
+ objects.add(next);
+ }
+ }
+ return objects;
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/EmfSwtBindingFactory.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/EmfSwtBindingFactory.java
new file mode 100644
index 0000000..de02981
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/EmfSwtBindingFactory.java
@@ -0,0 +1,204 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui.binding;
+
+import java.util.List;
+
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.databinding.edit.EMFEditObservables;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.impl.EEnumImpl;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.emf.editor.oaw.OawFacade;
+import org.eclipse.emf.editor.ui.ProposalCreator;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.bindings.keys.ParseException;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.viewers.ViewersObservables;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class EmfSwtBindingFactory {
+ private Composite parent = null;
+ private FormToolkit toolkit = null;
+ private final EObject owner;
+ private final EditingDomain domain;
+ private final EMFDataBindingContext edbc;
+ private final AdapterFactory adapterFactory;
+ private final ProposalCreator proposalcreator;
+ public static final String EOBJECT_KEY = EcorePackage.Literals.EOBJECT
+ .getName();
+ public static final String ESTRUCTURALFEATURE_KEY = EcorePackage.Literals.ESTRUCTURAL_FEATURE
+ .getName();
+
+ public EmfSwtBindingFactory(AdapterFactory adapterFactory,
+ EditingDomain domain, EObject owner, Composite parent,
+ FormToolkit toolkit, OawFacade facade) {
+ this.adapterFactory = adapterFactory;
+ this.edbc = new EMFDataBindingContext();
+ this.domain = domain;
+ this.proposalcreator = new ProposalCreator(domain, facade);
+ this.owner = owner;
+ this.parent = parent;
+ this.toolkit = toolkit;
+ }
+
+ public Control create(EObject eObject) {
+ Control retVal = null;
+ if (eObject instanceof EStructuralFeature) {
+ retVal = createForEStructuralFeature((EStructuralFeature) eObject);
+ }
+ return retVal;
+ }
+
+ private Control createForEStructuralFeature(EStructuralFeature feature) {
+ Control retVal = null;
+ if (feature.isMany()) {
+ retVal = bindList(feature);
+ } else {
+ retVal = bindValue(feature);
+ }
+ setupControl(feature, retVal);
+ return retVal;
+ }
+
+ private Control bindList(EStructuralFeature feature) {
+ IObservableList source = EMFEditObservables.observeList(domain, owner,
+ feature);
+
+ List<?> choice = proposalcreator.proposals(owner, feature);
+ MultipleFeatureControl mfc = new MultipleFeatureControl(parent,
+ toolkit, new AdapterFactoryLabelProvider(adapterFactory),
+ owner, feature, choice);
+
+ IObservableList target = new SelectionProviderMultipleSelectionObservableList(
+ SWTObservables.getRealm(Display.getDefault()), mfc
+ .getInternalSelectionProvider(), Object.class);
+ Binding binding = edbc.bindList(target, source, null, null);
+ binding.updateModelToTarget();
+ return mfc;
+ }
+
+ private Control bindValue(EStructuralFeature feature) {
+ Control retVal = null;
+ IObservableValue source = EMFEditObservables.observeValue(domain,
+ owner, feature);
+ IObservableValue target = null;
+ if (feature.getEType().equals(EcorePackage.Literals.EBOOLEAN)
+ || feature.getEType().equals(
+ EcorePackage.Literals.EBOOLEAN_OBJECT)
+ || (feature.getEType() instanceof EDataType && (feature
+ .getEType().getInstanceClass() == Boolean.class || feature
+ .getEType().getInstanceClass() == Boolean.TYPE))) {
+ Button b = toolkit.createButton(parent, "", SWT.CHECK);
+ target = SWTObservables.observeSelection(b);
+ retVal = b;
+ } else if (feature instanceof EReference
+ || feature.getEType() instanceof EEnumImpl) {
+ ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY);
+ toolkit.adapt(combo.getCombo());
+ combo.setContentProvider(new ArrayContentProvider());
+ combo.setLabelProvider(new AdapterFactoryLabelProvider(
+ adapterFactory));
+ combo.setInput(proposalcreator.proposals(owner, feature));
+ target = ViewersObservables.observeSingleSelection(combo);
+ retVal = combo.getCombo();
+ } else {
+ Text t = toolkit.createText(parent, new String());
+ t.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
+ List<?> proposals = proposalcreator.proposals(owner, feature);
+ if (proposals != null && !proposals.isEmpty()) {
+ // TODO prevert adding null to a list, for example a Collection
+ // Type
+ while (proposals.remove(null)) {
+ // clear null entries
+ }
+ ControlDecoration field = new ControlDecoration(t, SWT.BORDER);
+ FieldDecoration requiredFieldIndicator = FieldDecorationRegistry
+ .getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ field.setImage(requiredFieldIndicator.getImage());
+ field.setDescriptionText(requiredFieldIndicator
+ .getDescription());
+ KeyStroke keyStroke = null;
+ String string = new String();
+ try {
+ string = "Ctrl+Space";
+ keyStroke = KeyStroke.getInstance(string);
+ } catch (ParseException e) {
+ EEPlugin.getDefault().getLog().log(
+ new Status(IStatus.ERROR, EEPlugin.PLUGIN_ID,
+ "Error while parse: " + string, e));
+ }
+ new ContentProposalAdapter(t, new TextContentAdapter(),
+ new SimpleContentProposalProvider(proposals
+ .toArray(new String[] {})), keyStroke, null);
+ }
+ target = SWTObservables.observeText(t, SWT.Modify);
+ retVal = t;
+
+ }
+ edbc.bindValue(target, source, null, null);
+ return retVal;
+ }
+
+ private void setupControl(EStructuralFeature f, Control c) {
+ // disable unchangeable and unserializable
+ c.setEnabled(f.isChangeable()
+ && (!(f.getEType() instanceof EDataType && !((EDataType) f
+ .getEType()).isSerializable())));
+ c.setData(EmfSwtBindingFactory.ESTRUCTURALFEATURE_KEY, f);
+ c.setData(EmfSwtBindingFactory.EOBJECT_KEY, owner);
+ c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ public void dispose() {
+ edbc.dispose();
+ parent.dispose();
+ // toolkit.dispose();
+ }
+
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/MultipleFeatureControl.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/MultipleFeatureControl.java
new file mode 100644
index 0000000..baf3603
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/MultipleFeatureControl.java
@@ -0,0 +1,229 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.emf.editor.ui.binding;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * @author Dennis Huebner
+ *
+ */
+public class MultipleFeatureControl extends Composite {
+
+ private FeatureEditorDialog dialog;
+ private Collection<?> currentValue;
+ private final ILabelProvider labelProvider;
+ private ISelectionProvider inernalProvider = new InternalSelectionProvider();
+
+ private Label label;
+
+ private Button button;
+
+ // private IPropertyChangeListener propertyChangeListener;
+ private boolean beQueit;
+
+ public MultipleFeatureControl(final Composite parent, FormToolkit toolkit,
+ final ILabelProvider labelProvider, final Object object,
+ final EStructuralFeature feature,
+ final List<? extends Object> choiceOfValues) {
+ super(parent, SWT.NONE);
+ this.labelProvider = labelProvider;
+ toolkit.adapt(this);
+ setLayout(new GridLayout(2, false));
+ label = toolkit.createLabel(this, "unreadable value");
+ label.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ MultipleFeatureControl.this.setFocus();
+ }
+ });
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ button = toolkit.createButton(this, "...", SWT.PUSH);
+ button.setLayoutData(new GridData());
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ List<?> oldValue = unwrapSelection();
+ dialog = new FeatureEditorDialog(parent.getShell(),
+ labelProvider, object, feature.getEType(), oldValue,
+ "Display Name", choiceOfValues, false, feature
+ .isOrdered());
+ dialog.setBlockOnOpen(true);
+ if (dialog.open() == Window.OK) {
+ setSelection(new StructuredSelection(dialog.getResult()
+ .toArray()));
+ // propertyChangeListener
+ // .propertyChange(new PropertyChangeEvent(this,
+ // feature.getName(), oldValue, currentValue));
+ }
+ }
+ });
+
+ }
+
+ protected void setSelection(ISelection structuredSelection) {
+ this.inernalProvider.setSelection(structuredSelection);
+ }
+
+ private List<?> unwrapSelection() {
+ List<Object> l = new ArrayList<Object>();
+ if (getSelection() != null && !getSelection().isEmpty()
+ && getSelection() instanceof IStructuredSelection) {
+ for (Iterator<?> iterator = ((IStructuredSelection) getSelection())
+ .iterator(); iterator.hasNext();) {
+ Object object = iterator.next();
+ l.add(object);
+
+ }
+
+ }
+ return l;
+
+ }
+
+ private ISelection getSelection() {
+ return this.inernalProvider.getSelection();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.widgets.Control#setMenu(org.eclipse.swt.widgets.Menu)
+ */
+ @Override
+ public void setMenu(Menu menu) {
+ if (label != null && !label.isDisposed())
+ label.setMenu(menu);
+ if (button != null && !button.isDisposed())
+ button.setMenu(menu);
+
+ }
+
+ @Override
+ public boolean setFocus() {
+ if (button != null)
+ return button.setFocus();
+ return super.setFocus();
+ }
+
+ @Override
+ public void addFocusListener(FocusListener listener) {
+ button.addFocusListener(listener);
+ }
+
+ @Override
+ public void removeFocusListener(FocusListener listener) {
+ button.removeFocusListener(listener);
+ }
+
+ /**
+ * @param selection
+ */
+ private void recalculateLabelText() {
+ StringBuffer buffy = new StringBuffer();
+ List<?> currSelection = unwrapSelection();
+ if (currSelection != null && !currSelection.isEmpty())
+ for (Iterator<?> iterator = currSelection.iterator(); iterator
+ .hasNext();) {
+ Object sel = iterator.next();
+ buffy.append(labelProvider.getText(sel));
+ if (iterator.hasNext())
+ buffy.append(", ");
+ }
+ label.setText(buffy.toString());
+ }
+
+ public Collection<?> getCurrentValue() {
+ return currentValue;
+ }
+
+ class InternalSelectionProvider implements ISelectionProvider {
+
+ public void setSelection(ISelection selection) {
+ this.selection = selection;
+ recalculateLabelText();
+ if (!beQueit) {
+ // notify
+ // SelectionProviderMultipleSelectionObservableList$SelectionListener
+ for (ISelectionChangedListener currListener : listeners) {
+ currListener.selectionChanged(new SelectionChangedEvent(
+ this, this.selection));
+ }
+ }
+ }
+
+ private java.util.List<ISelectionChangedListener> listeners = new ArrayList<ISelectionChangedListener>();
+
+ public void addSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ listeners.remove(listener);
+ }
+
+ public ISelection getSelection() {
+ return selection;
+ }
+
+ private ISelection selection;
+
+ }
+
+ public ISelectionProvider getInternalSelectionProvider() {
+ return inernalProvider;
+ }
+
+ public void quietClearSelection() {
+ beQueit = true;
+ try {
+ this.setSelection(new StructuredSelection());
+ } finally {
+ beQueit = false;
+ }
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/SelectionProviderMultipleSelectionObservableList.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/SelectionProviderMultipleSelectionObservableList.java
new file mode 100644
index 0000000..a80711e
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/binding/SelectionProviderMultipleSelectionObservableList.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Peter Centgraf 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:
+ * Peter Centgraf - initial API and implementation, bug 124683
+ * Boris Bokowski, IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.editor.ui.binding;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.ListDiff;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * Observes multiple-selection of an {@link ISelectionProvider}. Copied from
+ * jface!!!
+ *
+ * @since 1.2
+ */
+public class SelectionProviderMultipleSelectionObservableList extends
+ WritableList {
+
+ protected ISelectionProvider selectionProvider;
+ protected boolean handlingSelection;
+ protected boolean updating;
+ protected SelectionListener selectionListener = new SelectionListener();
+
+ class SelectionListener implements ISelectionChangedListener {
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (updating) {
+ return;
+ }
+ handlingSelection = true;
+ try {
+ updateWrappedList(new ArrayList<Object>(getSelectionList(event
+ .getSelection())));
+ } finally {
+ handlingSelection = false;
+ }
+ }
+ }
+
+ /**
+ * Create a new observable list based on the current selection of the given
+ * selection provider. Assumes that the selection provider provides
+ * structured selections.
+ *
+ * @param realm
+ * @param selectionProvider
+ * @param elementType
+ */
+ public SelectionProviderMultipleSelectionObservableList(Realm realm,
+ ISelectionProvider selectionProvider, Object elementType) {
+ super(realm,
+ new ArrayList<Object>(getSelectionList(selectionProvider)),
+ elementType);
+ this.selectionProvider = selectionProvider;
+ selectionProvider.addSelectionChangedListener(selectionListener);
+ }
+
+ @Override
+ protected void fireListChange(ListDiff diff) {
+ if (handlingSelection) {
+ super.fireListChange(diff);
+ } else {
+ // this is a bit of a hack - we are changing the diff to match the
+ // order
+ // of elements returned by the selection provider after we've set
+ // the
+ // selection.
+ updating = true;
+ try {
+ List<?> oldList = getSelectionList(selectionProvider);
+ selectionProvider.setSelection(new StructuredSelection(
+ wrappedList));
+ wrappedList = new ArrayList<Object>(
+ getSelectionList(selectionProvider));
+ super.fireListChange(Diffs
+ .computeListDiff(oldList, wrappedList));
+ } finally {
+ updating = false;
+ }
+ }
+ }
+
+ protected static List<?> getSelectionList(
+ ISelectionProvider selectionProvider) {
+ if (selectionProvider == null) {
+ throw new IllegalArgumentException();
+ }
+ return getSelectionList(selectionProvider.getSelection());
+ }
+
+ protected static List<?> getSelectionList(ISelection sel) {
+ if (sel instanceof IStructuredSelection) {
+ return ((IStructuredSelection) sel).toList();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public synchronized void dispose() {
+ selectionProvider.removeSelectionChangedListener(selectionListener);
+ selectionProvider = null;
+ super.dispose();
+ }
+}