Skip to content
Snippets Groups Projects
Commit 1af6131f authored by Christoph Döbber's avatar Christoph Döbber
Browse files

organized model elements in a tree

refs 143
parent dafef52d
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import java.util.List;
import java.util.Set;
import org.conqat.lib.commons.collections.IdentityHashSet;
......@@ -37,6 +38,7 @@ import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.ProtoypeCategory;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
......@@ -74,12 +76,13 @@ public class LibraryView extends ViewPart {
private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>();
/** Listener for reacting to changes of the embedded editor. */
private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener = new ExtendableMultiPageEditorPageChangeListener() {
@Override
public void pageChanged() {
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
}
};
private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener =
new ExtendableMultiPageEditorPageChangeListener() {
@Override
public void pageChanged() {
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
}
};
/** {@inheritDoc} */
@Override
......@@ -87,42 +90,37 @@ public class LibraryView extends ViewPart {
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL
| SWT.V_SCROLL, patternFilter, false);
filteredTree = new FilteredTree(parent, SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, false);
viewer = filteredTree.getViewer();
viewer.setContentProvider(new LibraryTreeContentProvider());
viewer.setLabelProvider(new LibraryLabelProvider());
LibraryViewDragSourceAdapter dndAdapter = new LibraryViewDragSourceAdapter(
viewer);
LibraryViewDragSourceAdapter dndAdapter = new LibraryViewDragSourceAdapter(viewer);
viewer.addDragSupport(dndAdapter.getSupportedDNDOperations(),
new Transfer[] { dndAdapter.getPreferredTransfer() },
dndAdapter);
new Transfer[] {dndAdapter.getPreferredTransfer()}, dndAdapter);
viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypes().toArray());
viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypesByCategory());
// viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypes().toArray());
viewer.addFilter(new LibraryViewerFilter());
getViewSite().setSelectionProvider(viewer);
getSite().getWorkbenchWindow().getPartService()
.addPartListener(editorActivationListener);
getSite().getWorkbenchWindow().getPartService().addPartListener(editorActivationListener);
}
/** Switches to the given workbench editor part. */
private void switchWorkbenchEditor(IEditorPart editor) {
if (activeBindingEditor != null) {
activeBindingEditor
.removeBindingEditorListener(bindingEditorPageChangeListener);
if(activeBindingEditor != null) {
activeBindingEditor.removeBindingEditorListener(bindingEditorPageChangeListener);
activeBindingEditor = null;
}
if (editor instanceof ExtendableMultiPageEditor) {
activeBindingEditor = (ExtendableMultiPageEditor) editor;
activeBindingEditor
.addBindingEditorListener(bindingEditorPageChangeListener);
if(editor instanceof ExtendableMultiPageEditor) {
activeBindingEditor = (ExtendableMultiPageEditor)editor;
activeBindingEditor.addBindingEditorListener(bindingEditorPageChangeListener);
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
} else if (editor != null) {
} else if(editor != null) {
updateEditorFilters(editor);
}
}
......@@ -131,12 +129,11 @@ public class LibraryView extends ViewPart {
@SuppressWarnings("unchecked")
private void updateEditorFilters(IEditorPart editor) {
supportedBaseClasses.clear();
if (editor instanceof EditorBase
&& ((EditorBase<? extends EObject>) editor).enableLibraryView()) {
EditorBase<? extends EObject> editorBase = (EditorBase<? extends EObject>) editor;
if(editor instanceof EditorBase &&
((EditorBase<? extends EObject>)editor).enableLibraryView()) {
EditorBase<? extends EObject> editorBase = (EditorBase<? extends EObject>)editor;
containerObject = editorBase.getEditedObject();
for (Class<? extends EObject> clazz : editorBase
.getVisibleEObjectTypes()) {
for(Class<? extends EObject> clazz : editorBase.getVisibleEObjectTypes()) {
supportedBaseClasses.addAll(IPrototypeService.INSTANCE
.getComposablePrototypes(clazz));
}
......@@ -144,8 +141,9 @@ public class LibraryView extends ViewPart {
containerObject = null;
}
if (!viewer.getControl().isDisposed()) {
if(!viewer.getControl().isDisposed()) {
viewer.refresh();
viewer.expandAll();
}
}
......@@ -161,10 +159,14 @@ public class LibraryView extends ViewPart {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
if(element instanceof Prototype) {
Prototype prototype = (Prototype)element;
return prototype.getName();
}
if(element instanceof ProtoypeCategory) {
return ((ProtoypeCategory)element).getName();
}
return super.getText(element);
}
......@@ -172,15 +174,21 @@ public class LibraryView extends ViewPart {
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
if(element instanceof Prototype) {
Prototype prototype = (Prototype)element;
// delegate to the model element handlers
IModelElementHandler<EObject> handler = IModelElementHandlerService.INSTANCE
.getModelElementHandler(prototype.getPrototype());
if (handler != null) {
IModelElementHandler<EObject> handler =
IModelElementHandlerService.INSTANCE.getModelElementHandler(prototype
.getPrototype());
if(handler != null) {
return handler.getIcon();
}
}
if(element instanceof ProtoypeCategory &&
((ProtoypeCategory)element).getChildren().length > 0) {
return getImage(((ProtoypeCategory)element).getChildren()[0]);
}
return super.getImage(element);
}
}
......@@ -189,10 +197,14 @@ public class LibraryView extends ViewPart {
private class LibraryTreeContentProvider implements ITreeContentProvider {
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
if(inputElement instanceof Object[]) {
return (Object[])inputElement;
}
if(inputElement instanceof List) {
return ((List)inputElement).toArray();
}
return new Object[0];
}
......@@ -212,7 +224,10 @@ public class LibraryView extends ViewPart {
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
return null;
if(parentElement instanceof ProtoypeCategory) {
return ((ProtoypeCategory)parentElement).getChildren();
}
return new Object[0];
}
/** {@inheritDoc} */
......@@ -224,7 +239,7 @@ public class LibraryView extends ViewPart {
/** {@inheritDoc} */
@Override
public boolean hasChildren(Object element) {
return false;
return element instanceof ProtoypeCategory;
}
}
......@@ -233,11 +248,20 @@ public class LibraryView extends ViewPart {
/** {@inheritDoc} */
@Override
public boolean select(Viewer viewer, Object parentElement,
Object element) {
if (containerObject == null || supportedBaseClasses.isEmpty()) {
public boolean select(Viewer viewer, Object parentElement, Object element) {
if(containerObject == null || supportedBaseClasses.isEmpty()) {
return false;
}
if(element instanceof ProtoypeCategory) {
ProtoypeCategory pc = (ProtoypeCategory)element;
for(Object child : pc.getChildren()) {
if(select(viewer, pc, child)) {
return true;
}
}
return false;
}
return supportedBaseClasses.contains(element);
}
}
......@@ -250,11 +274,11 @@ public class LibraryView extends ViewPart {
*/
@Override
public void partActivated(IWorkbenchPart workbenchPart) {
if (!(workbenchPart instanceof IEditorPart)) {
if(!(workbenchPart instanceof IEditorPart)) {
return;
}
IEditorPart part = (IEditorPart) workbenchPart;
IEditorPart part = (IEditorPart)workbenchPart;
switchWorkbenchEditor(part);
}
......
......@@ -20,7 +20,9 @@ package org.fortiss.tooling.kernel.ui.internal.views;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.ProtoypeCategory;
import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionDragSourceAdapter;
/**
......@@ -31,8 +33,7 @@ import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionDragSourceAdapter;
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: C27A60ED7A9CF15253ED52862AACC49F
*/
public class LibraryViewDragSourceAdapter extends
ElementCompositionDragSourceAdapter {
public class LibraryViewDragSourceAdapter extends ElementCompositionDragSourceAdapter {
/** Library tree viewer */
private final TreeViewer libraryViewer;
......@@ -45,8 +46,19 @@ public class LibraryViewDragSourceAdapter extends
/** {@inheritDoc} */
@Override
protected EObject getSourceElement() {
IStructuredSelection sel = (IStructuredSelection) libraryViewer
.getSelection();
return ((Prototype) sel.getFirstElement()).getPrototypeCopy();
IStructuredSelection sel = (IStructuredSelection)libraryViewer.getSelection();
return ((Prototype)sel.getFirstElement()).getPrototypeCopy();
}
/** {@inheritDoc} */
@Override
public void dragStart(DragSourceEvent event) {
IStructuredSelection sel = (IStructuredSelection)libraryViewer.getSelection();
if(sel.getFirstElement() instanceof ProtoypeCategory) {
event.doit = false;
event.data = null;
} else {
super.dragStart(event);
}
}
}
......@@ -18,19 +18,19 @@ $Id$
package org.fortiss.tooling.kernel.extension;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.service.IPrototypeService;
/**
* An {@link IPrototypeProvider} extension offers pre-configured {@link EObject}
* s.
* An {@link IPrototypeProvider} extension offers pre-configured {@link EObject} s.
* <P>
* Prototype provider extensions are handled by {@link IPrototypeService}.
*
* A typical exmaple of a prototype is a model element, which also carries some
* initial default layout information.
* A typical exmaple of a prototype is a model element, which also carries some initial default
* layout information.
*
* @author hoelzl
* @author $Author$
......@@ -41,4 +41,7 @@ public interface IPrototypeProvider {
/** Returns the prototypes provided by this provider. */
List<Prototype> getPrototypes();
/** Returns the optional category affiliation for the prototypes. */
Map<Class<? extends EObject>, String> getCategories();
}
......@@ -18,9 +18,11 @@ $Id$
package org.fortiss.tooling.kernel.extension.base;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.conqat.lib.commons.collections.CollectionUtils;
import org.conqat.lib.commons.collections.UnmodifiableMap;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.IPrototypeProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
......@@ -29,8 +31,8 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
* Base implementation for {@link IPrototypeProvider}s.
*
* <p>
* Sub-classes must implement {@link #registerPrototypes()} to register specific
* prototypes using {@link #registerPrototype(String, EObject)} and
* Sub-classes must implement {@link #registerPrototypes()} to register specific prototypes using
* {@link #registerPrototype(String, EObject)} and
* {@link #registerPrimaryPrototype(String, EObject)}.
*
* @author hoelzl
......@@ -43,6 +45,10 @@ public abstract class PrototypeProviderBase implements IPrototypeProvider {
/** Stores the registered prototypes. */
private final List<Prototype> prototypes = new ArrayList<Prototype>();
/** Stores the optional category affiliation for the prototype. */
private final HashMap<Class<? extends EObject>, String> map =
new HashMap<Class<? extends EObject>, String>();
/** Constructor. */
public PrototypeProviderBase() {
registerPrototypes();
......@@ -51,11 +57,26 @@ public abstract class PrototypeProviderBase implements IPrototypeProvider {
/** Registers all prototypes. Sub-classes must override. */
protected abstract void registerPrototypes();
/** Registers the given {@link EObject} with the given name and category. */
protected final void registerPrototype(String name, EObject prototype, String category) {
registerPrototype(name, prototype);
registerCategory(prototype, category);
}
/** Registers the given {@link EObject} with the given name. */
protected final void registerPrototype(String name, EObject prototype) {
prototypes.add(new Prototype(name, prototype, false));
}
/**
* Registers the given {@link EObject} with the given name as primary
* prototype with the given category.
*/
protected final void registerPrimaryPrototype(String name, EObject prototype, String category) {
registerPrimaryPrototype(name, prototype);
registerCategory(prototype, category);
}
/**
* Registers the given {@link EObject} with the given name as primary
* prototype.
......@@ -69,4 +90,15 @@ public abstract class PrototypeProviderBase implements IPrototypeProvider {
public final List<Prototype> getPrototypes() {
return CollectionUtils.asUnmodifiable(prototypes);
}
/** Registers the element with the given category. */
public void registerCategory(EObject element, String category) {
map.put(element.getClass(), category);
}
/** {@inheritDoc} */
@Override
public UnmodifiableMap<Class<? extends EObject>, String> getCategories() {
return CollectionUtils.asUnmodifiable(map);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 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.extension.data;
import java.util.ArrayList;
/**
* Container object for prototypes of a certain category.
*
* @author doebber
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ProtoypeCategory {
/** Constructor. */
public ProtoypeCategory(String category) {
categoryName = category;
}
/** Stores the name of the category. */
private final String categoryName;
/** Stores the prototypes affiliated with this category. */
private ArrayList<Prototype> children = new ArrayList<Prototype>();
/** Adds the prototype. */
public void add(Prototype prototype) {
children.add(prototype);
}
/** Returns the members of this category. */
public Object[] getChildren() {
return children.toArray();
}
/** Returns the name of the category. */
public String getName() {
return categoryName;
}
}
......@@ -23,8 +23,10 @@ import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.loadClass;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import org.conqat.lib.commons.collections.CollectionUtils;
import org.conqat.lib.commons.collections.UnmodifiableList;
......@@ -33,6 +35,7 @@ import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IPrototypeProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.ProtoypeCategory;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import org.osgi.framework.Bundle;
......@@ -48,13 +51,25 @@ import org.osgi.framework.Bundle;
public class PrototypeService implements IPrototypeService {
/** The prototype provider extension point ID. */
private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelPrototypeProvider";
private static final String EXTENSION_POINT_NAME =
"org.fortiss.tooling.kernel.modelPrototypeProvider";
/** The prototype provider configuration element name. */
private static final String CONFIGURATION_ELEMENT_NAME = "modelPrototypeProvider";
/** Stores the registered prototype providers. */
private final List<IPrototypeProvider> prototypeProviderList = new ArrayList<IPrototypeProvider>();
private final List<IPrototypeProvider> prototypeProviderList =
new ArrayList<IPrototypeProvider>();
/** Stores the optional category affiliation for the prototype. */
private final HashMap<Class<? extends EObject>, String> map =
new HashMap<Class<? extends EObject>, String>();
/** {@inheritDoc} */
@Override
public String getCategory(EObject element) {
return map.get(element.getClass());
}
/** Constructor. */
public PrototypeService() {
......@@ -63,16 +78,15 @@ public class PrototypeService implements IPrototypeService {
/** Initializes the prototype list from plugin extensions. */
private void setupPrototypes() {
for (IConfigurationElement ce : getConfigurationElements(
EXTENSION_POINT_NAME, CONFIGURATION_ELEMENT_NAME)) {
for(IConfigurationElement ce : getConfigurationElements(EXTENSION_POINT_NAME,
CONFIGURATION_ELEMENT_NAME)) {
Bundle bundle = getBundle(ce);
try {
Class<?> handlerClass = loadClass(ce.getAttribute("provider"),
bundle);
IPrototypeProvider provider = (IPrototypeProvider) handlerClass
.getConstructor().newInstance();
Class<?> handlerClass = loadClass(ce.getAttribute("provider"), bundle);
IPrototypeProvider provider =
(IPrototypeProvider)handlerClass.getConstructor().newInstance();
prototypeProviderList.add(provider);
} catch (Exception ex) {
} catch(Exception ex) {
error(ToolingKernelActivator.getDefault(), ex.getMessage(), ex);
}
}
......@@ -99,9 +113,9 @@ public class PrototypeService implements IPrototypeService {
/** Returns prototypes including or excluding non-primaries. */
private UnmodifiableList<Prototype> getPrototypes(boolean primaryOnly) {
List<Prototype> result = new ArrayList<Prototype>();
for (IPrototypeProvider provider : prototypeProviderList) {
for (Prototype p : provider.getPrototypes()) {
if (!primaryOnly || p.isPrimary()) {
for(IPrototypeProvider provider : prototypeProviderList) {
for(Prototype p : provider.getPrototypes()) {
if(!primaryOnly || p.isPrimary()) {
result.add(p);
}
}
......@@ -111,15 +125,52 @@ public class PrototypeService implements IPrototypeService {
/** {@inheritDoc} */
@Override
public List<Prototype> getComposablePrototypes(
Class<? extends EObject> modelElementType) {
public List<Prototype> getComposablePrototypes(Class<? extends EObject> modelElementType) {
List<Prototype> result = new LinkedList<Prototype>();
for (Prototype prototype : getAllPrototypes()) {
if (IElementCompositorService.INSTANCE.canComposePrototype(
modelElementType, prototype)) {
for(Prototype prototype : getAllPrototypes()) {
if(IElementCompositorService.INSTANCE.canComposePrototype(modelElementType, prototype)) {
result.add(prototype);
}
}
return result;
}
/** {@inheritDoc} */
@Override
public List<Object> getAllPrototypesByCategory() {
init();
ArrayList<Object> result = new ArrayList<Object>();
ArrayList<Object> uncategorized = new ArrayList<Object>();
HashMap<String, ProtoypeCategory> categories = new HashMap<String, ProtoypeCategory>();
for(Prototype p : getAllPrototypes()) {
String categoryName = map.get(p.getPrototype().getClass());
if(categoryName != null) {
if(!categories.containsKey(categoryName)) {
categories.put(categoryName, new ProtoypeCategory(categoryName));
}
categories.get(categoryName).add(p);
} else {
uncategorized.add(p);
}
}
for(ProtoypeCategory pc : categories.values()) {
result.add(pc);
}
result.addAll(uncategorized);
return result;
}
/** Initially fills the map with categorized elements. */
private void init() {
if(!map.isEmpty()) {
return;
}
for(IPrototypeProvider provider : prototypeProviderList) {
// map.entrySet().addAll(provider.getCategories().entrySet());
for(Entry<Class<? extends EObject>, String> entry : provider.getCategories().entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
}
}
}
......@@ -58,6 +58,11 @@ public interface IPrototypeService {
* Returns the list of all prototypes composable with the given model
* element class.
*/
List<Prototype> getComposablePrototypes(
Class<? extends EObject> modelElementType);
List<Prototype> getComposablePrototypes(Class<? extends EObject> modelElementType);
/** Returns the category of the given element. */
public String getCategory(EObject element);
/** Returns all prototypes in a tree sorted by category with uncategorized appended. */
List<Object> getAllPrototypesByCategory();
}
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