Skip to content
Snippets Groups Projects
Commit 0d7e511a authored by Xiuna Zhu's avatar Xiuna Zhu
Browse files

No commit message

No commit message
parent bf187ad2
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ package test.org.fortiss.tooling.graphicsGL.ui;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.IEditorPart;
import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
import org.fortiss.tooling.kernel.ui.extension.base.ModelEditorBindingBase;
/**
* Editor binding for {@link Test3DEditor}.
......@@ -29,7 +29,7 @@ import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 58E46F736C879DCAC0943A2B35ED764F
*/
public class Test3DEditorBinding implements IModelEditorBinding<EObject> {
public class Test3DEditorBinding extends ModelEditorBindingBase<EObject> {
/** {@inheritDoc} */
@Override
......
......@@ -29,7 +29,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
*
* <P>
* Each editor provided by some binding becomes part of an Eclipse multi-page editor. Its page
* carries the name delivered by {@link #getLabel()}. The {@link IModelEditorBindingService} sorts
* carries the name delivered by {@link #getLabel(T)}. The {@link IModelEditorBindingService} sorts
* the provided editors according to their priority returned by {@link #getPriority()} with higher
* values having lower priority.
*
......@@ -43,11 +43,12 @@ import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
public interface IModelEditorBinding<T extends EObject> extends IEObjectAware<EObject> {
/** Returns the class of the editor registered by this binding. */
Class<? extends IEditorPart> getEditorClass();
Class<? extends IEditorPart> getEditorClass(T object);
/** Returns the label of the editor. */
String getLabel();
String getLabel(T object);
/** Returns the priority of the editor. Higher values have lower priority. */
int getPriority();
}
/*--------------------------------------------------------------------------+
$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.ui.extension.base;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.service.base.IEObjectAware;
import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
/**
* Interface for editor bindings. An editor binding a defines a model element
* editor. Usually, an editor (in the Eclipse interpretation) is a view (in the
* model-based development interpretation) on the underlying model.
*
* <P>
* Each editor provided by some binding becomes part of an Eclipse multi-page editor. Its page
* carries the name delivered by {@link #getLabel()}. The {@link IModelEditorBindingService} sorts
* the provided editors according to their priority returned by {@link #getPriority()} with higher
* values having lower priority.
*
* @see IModelEditorBindingService
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: F5C4051E8E69E7E861B93FE470488974
*/
public abstract class ModelEditorBindingBase<T extends EObject> implements IEObjectAware<EObject>,
IModelEditorBinding<T> {
/** Returns the class of editor */
@Override
public java.lang.Class<? extends org.eclipse.ui.IEditorPart> getEditorClass(T object) {
return getEditorClass();
}
/** Returns the class of editor */
public java.lang.Class<? extends org.eclipse.ui.IEditorPart> getEditorClass() {
return getEditorClass(null);
}
/** Returns the label of editor */
@Override
public String getLabel(T object) {
return getLabel();
}
/** Returns the label of editor */
public String getLabel() {
return getLabel(null);
}
/** Returns the priority of the editor. Higher values have lower priority. */
@Override
public int getPriority() {
return 0;
}
}
......@@ -20,8 +20,6 @@ package org.fortiss.tooling.kernel.ui.internal;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.Collections;
import java.util.Comparator;
import java.util.EventObject;
import java.util.HashMap;
import java.util.List;
......@@ -87,11 +85,7 @@ public class ModelEditorBindingService extends
/** Constructor. */
public ModelEditorBindingService() {
super();
// sort editor bindings by priority.
EditorBindingComparator comparator = new EditorBindingComparator();
for(Class<?> clazz : handlerMap.keySet()) {
Collections.sort(handlerMap.get(clazz), comparator);
}
}
/** {@inheritDoc} */
......@@ -176,17 +170,6 @@ public class ModelEditorBindingService extends
return HANDLER_CLASS_ATTRIBUTE_NAME;
}
/** {@link Comparator} for {@link IModelEditorBinding}s. */
private static class EditorBindingComparator implements
Comparator<IModelEditorBinding<EObject>> {
/** {@inheritDoc} */
@Override
public int compare(IModelEditorBinding<EObject> eb0, IModelEditorBinding<EObject> eb1) {
return eb1.getPriority() - eb0.getPriority();
}
}
/** {@inheritDoc} */
@Override
public void closeEditors(EObject parentElement) {
......
......@@ -20,7 +20,10 @@ package org.fortiss.tooling.kernel.ui.internal.editor;
import static org.conqat.ide.commons.ui.logging.LoggingUtils.error;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EventObject;
import java.util.List;
import org.conqat.ide.commons.ui.logging.LoggingUtils;
import org.conqat.lib.commons.collections.IdentityHashSet;
......@@ -175,12 +178,23 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart implements
@Override
protected void createPages() {
int pageIndex = 0;
for(IModelEditorBinding<EObject> editorBinding : IModelEditorBindingService.INSTANCE
.getBindings(editedObject)) {
List<IModelEditorBinding<EObject>> bindings =
IModelEditorBindingService.INSTANCE.getBindings(editedObject);
Collections.sort(bindings, new Comparator<IModelEditorBinding<EObject>>() {
@Override
public int compare(IModelEditorBinding<EObject> o1, IModelEditorBinding<EObject> o2) {
return o2.getPriority() - o1.getPriority();
}
});
for(IModelEditorBinding<EObject> editorBinding : bindings) {
try {
IEditorPart editorPart = editorBinding.getEditorClass().newInstance();
addPage(editorPart, getEditorInput());
setPageText(pageIndex++, editorBinding.getLabel());
Class<? extends IEditorPart> editorClass =
editorBinding.getEditorClass(editedObject);
if(editorClass != null) {
IEditorPart editorPart = editorClass.newInstance();
addPage(editorPart, getEditorInput());
setPageText(pageIndex++, editorBinding.getLabel(editedObject));
}
} catch(Exception ex) {
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Editor instantiation failed.", ex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment