From 46ff15327e901b4140bcf5fabc56ef2940e436c8 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Thu, 24 Feb 2011 15:30:42 +0000
Subject: [PATCH] added simple project configuration editor added type system
 configuration selection

---
 org.fortiss.tooling.kernel/trunk/plugin.xml   |   9 ++
 .../tooling/kernel/base/EditorBase.java       | 107 ++++++++++++++++++
 .../internal/navigator/NavigatorViewPart.java |  39 ++++++-
 .../kernel/internal/navigator/NewMenu.java    |   2 +-
 .../util/EObjectSelectionUtils.java           |   2 +-
 5 files changed, 153 insertions(+), 6 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java
 rename org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/{internal => }/util/EObjectSelectionUtils.java (97%)

diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml
index e3605d576..c87f11ba8 100644
--- a/org.fortiss.tooling.kernel/trunk/plugin.xml
+++ b/org.fortiss.tooling.kernel/trunk/plugin.xml
@@ -13,6 +13,15 @@
             uri="http://www.fortiss.org/tooling/kernel">
       </package>
    </extension>
+   <extension
+         point="org.eclipse.ui.editors">
+      <editor
+            class="org.fortiss.tooling.kernel.internal.editor.BindingEditor"
+            default="false"
+            id="org.fortiss.tooling.kernel.internal.editor.BindingEditor"
+            name="Binding Editor">
+      </editor>
+   </extension>
    <extension
          point="org.eclipse.ui.views">
       <view
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java
new file mode 100644
index 000000000..d24a91887
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java
@@ -0,0 +1,107 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2011 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.base;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+import org.fortiss.tooling.kernel.interfaces.IEditorBinding;
+import org.fortiss.tooling.kernel.interfaces.IHandler;
+import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput;
+import org.fortiss.tooling.kernel.services.ICommandStackService;
+
+/**
+ * Base implementation of model element editors returned by
+ * {@link IEditorBinding}s.
+ * 
+ * @author hoelzlf
+ * @author $Author$
+ * @version $Rev$
+ * @levd.rating RED Rev:
+ */
+public abstract class EditorBase<T extends EObject> extends EditorPart {
+
+	/**
+	 * The object shown in this editor. This is valid as soon as
+	 * {@link #init(IEditorSite, IEditorInput)} has been called.
+	 */
+	protected T editedObject;
+
+	/** The model element handler to be used with the {@link #editedObject}. */
+	protected IHandler<T> handler;
+
+	/** {@inheritDoc} */
+	@SuppressWarnings("unchecked")
+	@Override
+	public void init(IEditorSite site, IEditorInput input)
+			throws PartInitException {
+		if (!(input instanceof ModelElementEditorInput)) {
+			throw new PartInitException("Expected input of type "
+					+ ModelElementEditorInput.class);
+		}
+		ModelElementEditorInput meInput = (ModelElementEditorInput) input;
+
+		editedObject = (T) meInput.getEditorInput();
+		if (editedObject == null) {
+			throw new PartInitException("Missing model element!");
+		}
+
+		handler = (IHandler<T>) meInput.getModelElementHandler();
+		if (handler == null) {
+			throw new PartInitException("Missing model element handler!");
+		}
+
+		setInput(input);
+		setSite(site);
+
+		setPartName(handler.getName(editedObject));
+		setContentDescription(handler.getDescription(editedObject));
+	}
+
+	/** Runs the given {@link Runnable} in the emfStore editing domain. */
+	protected final void executeCommand(Runnable runner) {
+		ICommandStackService.INSTANCE.runAsCommand(editedObject, runner);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final boolean isDirty() {
+		return false;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final boolean isSaveAsAllowed() {
+		return false;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final void doSave(IProgressMonitor monitor) {
+		// Saving is handled automatically by emfStore
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final void doSaveAs() {
+		// Saving is handled automatically by emfStore
+	}
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java
index 9a8e7f352..6339b8d4c 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java
@@ -27,6 +27,8 @@ import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -40,10 +42,14 @@ import org.eclipse.ui.IDecoratorManager;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.progress.UIJob;
 import org.fortiss.tooling.kernel.ToolingKernelActivator;
+import org.fortiss.tooling.kernel.internal.editor.BindingEditor;
+import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput;
+import org.fortiss.tooling.kernel.util.EObjectSelectionUtils;
 import org.unicase.ecp.model.ECPWorkspaceManager;
 import org.unicase.ecp.model.NoWorkspaceException;
 import org.unicase.ecp.model.workSpaceModel.ECPProject;
@@ -60,7 +66,7 @@ import org.unicase.ecp.model.workSpaceModel.WorkSpaceModelPackage;
  * @levd.rating RED Rev:
  */
 public final class NavigatorViewPart extends ViewPart implements
-		ISelectionListener, ISelectionChangedListener {
+		ISelectionListener, ISelectionChangedListener, IDoubleClickListener {
 
 	/** Stores the TreeViewer. */
 	private TreeViewer viewer;
@@ -77,9 +83,6 @@ public final class NavigatorViewPart extends ViewPart implements
 	/** Stores the menu manager. */
 	private MenuManager menuManager;
 
-	/** Stores the new model element menu. */
-	private NewMenu newMenu;
-
 	/** Constructor. */
 	public NavigatorViewPart() {
 		try {
@@ -172,6 +175,7 @@ public final class NavigatorViewPart extends ViewPart implements
 							.getLabelDecorator()));
 			viewer.setContentProvider(new NavigatorTreeContentProvider());
 			viewer.setInput(workspace);
+			viewer.addDoubleClickListener(this);
 		}
 
 		createContextMenu();
@@ -261,4 +265,31 @@ public final class NavigatorViewPart extends ViewPart implements
 
 		super.dispose();
 	}
+
+	/** {@inheritDoc} */
+	@Override
+	public void doubleClick(DoubleClickEvent event) {
+		if (event.getSelection() instanceof IStructuredSelection) {
+			EObject element = EObjectSelectionUtils.getFirstElement(event
+					.getSelection());
+			if (element != null) {
+				openInEditor(element);
+			}
+		}
+	}
+
+	/** Opens an editor for the given element. */
+	private void openInEditor(EObject element) {
+		try {
+			PlatformUI
+					.getWorkbench()
+					.getActiveWorkbenchWindow()
+					.getActivePage()
+					.openEditor(new ModelElementEditorInput(element),
+							BindingEditor.ID);
+		} catch (final PartInitException e) {
+			LoggingUtils.error(ToolingKernelActivator.getDefault(),
+					"Could not open editor with ID " + BindingEditor.ID, e);
+		}
+	}
 }
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java
index d1cd7b88b..1ffc233f8 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java
@@ -25,12 +25,12 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.CompoundContributionItem;
 import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider;
-import org.fortiss.tooling.kernel.internal.util.EObjectSelectionUtils;
 import org.fortiss.tooling.kernel.services.ICommandStackService;
 import org.fortiss.tooling.kernel.services.ICompositorService;
 import org.fortiss.tooling.kernel.services.IModelElementService;
 import org.fortiss.tooling.kernel.services.IPrototypeService;
 import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype;
+import org.fortiss.tooling.kernel.util.EObjectSelectionUtils;
 
 /**
  * The contributor for the dynamic new menu based on composition.
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java
similarity index 97%
rename from org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java
rename to org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java
index f740a87b1..04cd15ce4 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java
@@ -15,7 +15,7 @@ $Id$
 | See the License for the specific language governing permissions and      |
 | limitations under the License.                                           |
 +--------------------------------------------------------------------------*/
-package org.fortiss.tooling.kernel.internal.util;
+package org.fortiss.tooling.kernel.util;
 
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.viewers.ISelection;
-- 
GitLab