From 002780daed4f36eb8f2ad70c3a983d9beed52cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20D=C3=B6bber?= <doebber@in.tum.de> Date: Tue, 29 Nov 2011 12:39:50 +0000 Subject: [PATCH] adapting eclipse API to AF3 mechanisms refs 86 --- .../trunk/META-INF/MANIFEST.MF | 3 +- .../base/ui/editor/TextEditorBase.java | 120 ++++++++++++++++++ .../trunk/META-INF/MANIFEST.MF | 1 + .../kernel/ui/extension/base/EditorBase.java | 2 +- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/TextEditorBase.java diff --git a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF index 3ffc996e7..eb58feac2 100644 --- a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-SymbolicName: org.fortiss.tooling.base.ui;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: org.fortiss.tooling.base.ui.ToolingBaseUIActivator Require-Bundle: org.fortiss.tooling.base;bundle-version="1.0.0";visibility:=reexport, - org.fortiss.tooling.kernel.ui;bundle-version="1.0.0";visibility:=reexport + org.fortiss.tooling.kernel.ui;bundle-version="1.0.0";visibility:=reexport, + org.eclipse.jface.text;bundle-version="3.7.1" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: fortiss diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/TextEditorBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/TextEditorBase.java new file mode 100644 index 000000000..a769b82d9 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/TextEditorBase.java @@ -0,0 +1,120 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| 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.base.ui.editor; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.databinding.EMFDataBindingContext; +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.editors.text.TextEditor; +import org.fortiss.tooling.kernel.service.ICommandStackService; +import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; +import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput; + +/** + * + * @author doebber + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public class TextEditorBase<T extends EObject> extends TextEditor { + + /** + * 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 IModelElementHandler<T> handler; + + /** Databinding context used for model changes. */ + protected final EMFDataBindingContext dbc = new EMFDataBindingContext(); + + /** Returns the edited object. */ + public T getEditedObject() { + return editedObject; + } + + // /** {@inheritDoc} */ + // @Override + // protected void doSetInput(IEditorInput input) throws CoreException { + // super.doSetInput(new ModelElementEditorInput(getEditedObject())); + // } + + /** {@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.getModelElement(); + if (editedObject == null) { + throw new PartInitException("Missing model element!"); + } + + handler = (IModelElementHandler<T>) meInput.getModelElementHandler(); + if (handler == null) { + throw new PartInitException("Missing model element handler!"); + } + + setSite(site); + setInput(input); + + setPartName(handler.getName(editedObject)); + setContentDescription(handler.getDescription(editedObject)); + } + + /** {@inheritDoc} */ + @Override + public final boolean isDirty() { + return ICommandStackService.INSTANCE.isDirty(editedObject); + } + + /** {@inheritDoc} */ + @Override + public final void doSave(IProgressMonitor monitor) { + ICommandStackService.INSTANCE.doSave(editedObject, monitor); + } + + /** {@inheritDoc} */ + @Override + public final boolean isSaveAsAllowed() { + return false; + } + + /** {@inheritDoc} */ + @Override + public final void doSaveAs() { + // Saving is handled automatically by persistency service + } + + /** {@inheritDoc} */ + @Override + public void setFocus() { + // nothing to do + } +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF index a047282c9..173442615 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Export-Package: org.fortiss.tooling.kernel.ui, org.fortiss.tooling.kernel.ui.extension.base, org.fortiss.tooling.kernel.ui.extension.data, org.fortiss.tooling.kernel.ui.extension.editingsupport, + org.fortiss.tooling.kernel.ui.internal.editor, org.fortiss.tooling.kernel.ui.listener, org.fortiss.tooling.kernel.ui.service, org.fortiss.tooling.kernel.ui.util diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java index 61f7bed0a..855e0ad98 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java @@ -94,8 +94,8 @@ public abstract class EditorBase<T extends EObject> extends EditorPart throw new PartInitException("Missing model element handler!"); } - setInput(input); setSite(site); + setInput(input); setPartName(handler.getName(editedObject)); setContentDescription(handler.getDescription(editedObject)); -- GitLab