Skip to content
Snippets Groups Projects
Commit f6398930 authored by Simon Barner's avatar Simon Barner
Browse files

Merge branch 'master' of https://git.fortiss.org/af3/kernel.git into 3708

parents 2d0b2246 b466d9ca
No related branches found
No related tags found
1 merge request!50Add a isAssignableFromAny test for class objects
ModelElementTreeViewer.java 8a555fc12eb6c0531f6334fdc61e9abf52ff784d YELLOW ModelElementTreeViewer.java 9c7637313b0ce4d70566ebb4f90dfca0d9931d09 GREEN
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.fortiss.tooling.base.ui.javafx.control.treetableview; package org.fortiss.tooling.base.ui.javafx.control.treetableview;
import static javafx.embed.swt.SWTFXUtils.toFXImage; import static javafx.embed.swt.SWTFXUtils.toFXImage;
import static org.fortiss.tooling.kernel.ui.util.KernelUIUtils.getName;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -24,9 +25,10 @@ import org.fortiss.tooling.base.model.element.IHierarchicElement; ...@@ -24,9 +25,10 @@ import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.common.ui.javafx.AF3FXViewPart; import org.fortiss.tooling.common.ui.javafx.AF3FXViewPart;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeContentProviderBase; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeContentProviderBase;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeItem;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeUIProviderBase; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeUIProviderBase;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeViewer; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeViewer;
import org.fortiss.tooling.kernel.model.INamedCommentedElement; import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
import javafx.scene.Node; import javafx.scene.Node;
...@@ -39,18 +41,48 @@ import javafx.scene.image.ImageView; ...@@ -39,18 +41,48 @@ import javafx.scene.image.ImageView;
/** /**
* This class is a support fragment for creating tree views in JavaFX Controls. It provides the view * This class is a support fragment for creating tree views in JavaFX Controls. It provides the view
* counter part of a {@link DynamicTreeContentProviderBase}. The content provider is responsible * counter part of a {@link DynamicTreeContentProviderBase}. The content provider is responsible
* for selecting elements from a base model and ordering them acc. to a custom defined structure. * for selecting elements from a base model and ordering them according to a custom defined
* structure.
* These two fragments have to be combined in a JavaFX controller inheriting from the base class * These two fragments have to be combined in a JavaFX controller inheriting from the base class
* {@link AF3FXViewPart}. * {@link AF3FXViewPart}.
* <p> * <p>
* TreeViewer that constructs a DynamicTreeViewer whose UI provider uses the methods and kernel * TreeViewer that constructs a DynamicTreeViewer whose UI provider uses the methods and kernel
* services for {@link IHierarchicElement}s and {@link INamedCommentedElement}s. * services for {@link INamedElement}s.
* The Viewer uses a composition principle where a client must provide a {@link TreeView} (JavaFX), * The Viewer uses a composition principle where a client must provide a {@link TreeView} (JavaFX),
* a root element (AF3), and a content provider that selects the elements to be displayed. * a root element (AF3), and a content provider that selects the elements to be displayed.
* *
* @author diewald * @author diewald
*/ */
public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedElement> { public class ModelElementTreeViewer<T extends INamedElement> {
/** {@link DynamicTreeUIProviderBase} for named (and commented) {@link IModelElement}s . */
protected class ModelElementUIProvider extends DynamicTreeUIProviderBase<T> {
/** {@inheritDoc} */
@Override
public String getLabel(T element) {
return getName(element);
}
/** {@inheritDoc} */
@Override
public Node getIconNode(T element) {
org.eclipse.swt.graphics.Image icon =
IModelElementHandlerService.getInstance().getIcon(element);
if(icon != null) {
Image fxImage = toFXImage(icon.getImageData(), null);
return new ImageView(fxImage);
}
return null;
}
/** {@inheritDoc} */
@Override
public ContextMenu createContextMenu(T element) {
ContextMenu menu = new ContextMenu();
contextMenuEntries.forEach(entry -> menu.getItems().add(entry));
return menu;
}
}
/** References the constructed {@link DynamicTreeViewer} "controller". */ /** References the constructed {@link DynamicTreeViewer} "controller". */
protected DynamicTreeViewer<T> dynTreeViewer; protected DynamicTreeViewer<T> dynTreeViewer;
...@@ -64,7 +96,7 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle ...@@ -64,7 +96,7 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle
/** Constructor. */ /** Constructor. */
public ModelElementTreeViewer(TreeView<T> treeView, T modelRoot, public ModelElementTreeViewer(TreeView<T> treeView, T modelRoot,
DynamicTreeContentProviderBase<T> contentProvider) { DynamicTreeContentProviderBase<T> contentProvider) {
DynamicTreeUIProviderBase<T> uiProvider = createContentUIProvider(); DynamicTreeUIProviderBase<T> uiProvider = createUIProvider();
dynTreeViewer = dynTreeViewer =
new DynamicTreeViewer<T>(treeView, modelRoot, true, 0, contentProvider, uiProvider); new DynamicTreeViewer<T>(treeView, modelRoot, true, 0, contentProvider, uiProvider);
} }
...@@ -76,35 +108,8 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle ...@@ -76,35 +108,8 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle
* *
* @return The constructed UI Provider. * @return The constructed UI Provider.
*/ */
protected DynamicTreeUIProviderBase<T> createContentUIProvider() { protected DynamicTreeUIProviderBase<T> createUIProvider() {
return new DynamicTreeUIProviderBase<T>() { return new ModelElementUIProvider();
/** {@inheritDoc} */
@Override
public String getLabel(T element) {
return element.getName();
}
/** {@inheritDoc} */
@Override
public Node getIconNode(T element) {
org.eclipse.swt.graphics.Image icon =
IModelElementHandlerService.getInstance().getIcon(element);
if(icon != null) {
Image fxImage = toFXImage(icon.getImageData(), null);
return new ImageView(fxImage);
}
return null;
}
/** {@inheritDoc} */
@Override
public ContextMenu createContextMenu(T element) {
ContextMenu menu = new ContextMenu();
contextMenuEntries.forEach(entry -> menu.getItems().add(entry));
return menu;
}
};
} }
/** /**
...@@ -123,4 +128,10 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle ...@@ -123,4 +128,10 @@ public class ModelElementTreeViewer<T extends IModelElement & INamedCommentedEle
public void update() { public void update() {
dynTreeViewer.update(); dynTreeViewer.update();
} }
/** Expands the tree down to the given value. */
public void expandItem(T value) {
DynamicTreeItem<T> item = dynTreeViewer.findItem(value);
dynTreeViewer.expandItem(item);
}
} }
...@@ -3,6 +3,6 @@ DynamicTreeItem.java afc105cf5acf3d2506d89e0892555100c234ce5b GREEN ...@@ -3,6 +3,6 @@ DynamicTreeItem.java afc105cf5acf3d2506d89e0892555100c234ce5b GREEN
DynamicTreeTableUIProviderBase.java fd9fce19a65eb1006ceacb0d869bbe90a8c578b3 GREEN DynamicTreeTableUIProviderBase.java fd9fce19a65eb1006ceacb0d869bbe90a8c578b3 GREEN
DynamicTreeTableViewer.java e474f3a890fd6525db7de8e299d7fbe67f932a15 GREEN DynamicTreeTableViewer.java e474f3a890fd6525db7de8e299d7fbe67f932a15 GREEN
DynamicTreeUIProviderBase.java 56fe4df4577b35f1e5e6e4c4be189b706c852d52 GREEN DynamicTreeUIProviderBase.java 56fe4df4577b35f1e5e6e4c4be189b706c852d52 GREEN
DynamicTreeViewer.java ffead9e76286fb7a17723cd201fdc187187a737f GREEN DynamicTreeViewer.java da5e24ae57777a482d8e12c8262513d8143bfa93 GREEN
DynamicTreeViewerBase.java 47124c847de322a0ae26eb7a114f85ce4bd02d7e GREEN DynamicTreeViewerBase.java 47124c847de322a0ae26eb7a114f85ce4bd02d7e GREEN
IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN
...@@ -97,7 +97,7 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> { ...@@ -97,7 +97,7 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
/** Searches the {@link DynamicTreeItem} for the given value. */ /** Searches the {@link DynamicTreeItem} for the given value. */
public DynamicTreeItem<T> findItem(DynamicTreeItem<T> item, Object value) { public DynamicTreeItem<T> findItem(DynamicTreeItem<T> item, Object value) {
if(item == null || value == null) { if(item == null || value == null || item.getValue() == null) {
return null; return null;
} }
if(item.getValue().equals(value)) { if(item.getValue().equals(value)) {
......
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