Commit 84deaf36 authored by Simon Barner's avatar Simon Barner
Browse files

Enable to show model hierarchy.

refs 2950
parent 953263fe
......@@ -19,13 +19,18 @@ package org.fortiss.af3.allocation.ui.editor;
import static java.util.Collections.emptyList;
import static org.conqat.lib.commons.reflect.ReflectionUtils.isInstanceOfAny;
import static org.eclipse.jface.viewers.AbstractTreeViewer.ALL_LEVELS;
import static org.fortiss.af3.allocation.utils.AllocationUtils.addAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.checkAllocationEntryType;
import static org.fortiss.af3.allocation.utils.AllocationUtils.deleteAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.isAllocated;
import static org.fortiss.af3.allocation.utils.AllocationUtils.isModifiableAllocationEntry;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeFullyQualifiedName;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
......@@ -35,6 +40,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
......@@ -46,13 +52,16 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
......@@ -72,7 +81,7 @@ import org.fortiss.tooling.kernel.utils.KernelModelElementUtils;
* @author zverlov
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating RED Hash: E24FB2CEED8BF45E16C5F91AD3BD3595
*/
public abstract class AllocationTableEditor<T extends AllocationTable> extends
ModelListenerEditorBase<T> {
......@@ -176,7 +185,7 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
} else if(targetModelType.isAssignableFrom(model.getClass())) {
gui.getComboViewerTarget().refresh();
}
gui.getTableViewer().refresh();
gui.getTreeViewer().refresh();
}
/** {@inheritDoc} */
......@@ -223,6 +232,32 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
setupViewPointSelectionComboBox(gui.getComboViewerTarget(), getModels(targetModelType),
editedObject.getTargetView(), editedObject::setTargetView,
editedObject::getTargetView);
gui.getCheckboxShowSourceModelHierarchy().addSelectionListener(new SelectionListener() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
updateTreeViewerShowSourceModelHierarchy();
}
/** {@inheritDoc} */
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// Nothing to do
}
});
updateTreeViewerShowSourceModelHierarchy();
}
/** Updates the {@link TreeViewer}'s model hierarchy. */
private void updateTreeViewerShowSourceModelHierarchy() {
// Update the TreeViewer's contents accordingly
updateTableViewer();
if(gui.getCheckboxShowSourceModelHierarchy().getSelection()) {
gui.getTreeViewer().expandToLevel(ALL_LEVELS);
}
}
/********************* Model selection ComboBoxes *********************/
......@@ -368,20 +403,64 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
* the first (source) column to it.
*/
protected void updateTableViewer() {
// Dispose old table. NOOP if it does not exist.
TableViewer tableViewer = gui.getTableViewer();
Table table = tableViewer.getTable();
table.setRedraw(false);
// Dispose old tree. NOOP if it does not exist.
TreeViewer treeViewer = gui.getTreeViewer();
Tree tree = treeViewer.getTree();
tree.setRedraw(false);
for(TableColumn column : table.getColumns()) {
for(TreeColumn column : tree.getColumns()) {
column.dispose();
}
List<? extends IModelElement> sourceModelElements = getSourceViewModelElements();
tableViewer.setContentProvider(new ArrayContentProvider());
treeViewer.setContentProvider(new TreeContentProviderBase() {
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
if(gui.getCheckboxShowSourceModelHierarchy().getSelection()) {
if(parentElement instanceof EObject) {
EObject node = (EObject)parentElement;
IModelElementHandler<EObject> nodeHandler =
IModelElementHandlerService.getInstance().getModelElementHandler(
node);
List<EObject> rval = new ArrayList<EObject>();
// Add relevant structural elements: atomic sub-nodes that are of
// source-entity type, and nodes that can contain source-entity type
// elements in their offspring
for(EObject subNode : nodeHandler.getSubnodes(node)) {
IModelElementHandler<EObject> subNodeHandler =
IModelElementHandlerService.getInstance()
.getModelElementHandler(subNode);
boolean isAtomicSourceEntity =
sourceEntityType.isAssignableFrom(subNode.getClass()) &&
subNodeHandler.getSubnodes(subNode).isEmpty();
boolean containsSourceEntity =
getFirstChildWithType(subNode, sourceEntityType) != null;
if(isAtomicSourceEntity || containsSourceEntity) {
rval.add(subNode);
}
}
// Add source-entity type connectors
rval.addAll(pickInstanceOf(sourceEntityType,
nodeHandler.getConnectors(node)));
TableViewerColumn firstColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnSrc = firstColumn.getColumn();
if(!rval.isEmpty()) {
return rval.toArray();
}
}
} else {
if(parentElement == editedObject.getSourceView()) {
return getSourceViewModelElements().toArray();
}
}
return new Object[0];
}
});
TreeViewerColumn firstColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn tblclmnSrc = firstColumn.getColumn();
tblclmnSrc.setWidth(100);
tblclmnSrc.setText("\u2193 Src. | Tgt. \u2192"); // Down and right unicode arrow
......@@ -397,18 +476,26 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
public String getText(Object element) {
return getName(element);
}
/** {@inheritDoc} */
@Override
public String getToolTipText(Object object) {
return AllocationTableEditor.getToolTipText(object);
}
});
tableViewer.setInput(sourceModelElements);
treeViewer.setInput(editedObject.getSourceView());
List<? extends IModelElement> targetModelElements = getTargetViewModelElements();
for(IModelElement targetElement : targetModelElements) {
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tableColumn = tableViewerColumn.getColumn();
tableColumn.setWidth(100);
tableColumn.setText(getName(targetElement));
tableColumn.setImage(getImage(targetElement));
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn treeColumn = treeViewerColumn.getColumn();
treeColumn.setWidth(100);
treeColumn.setText(getName(targetElement));
treeColumn.setToolTipText(getToolTipText(targetElement));
treeColumn.setImage(getImage(targetElement));
CheckBoxLabelProvider checkBoxlabelProvider = new CheckBoxLabelProvider() {
/** {@inheritDoc} */
@Override
protected boolean isChecked(Object element) {
if(element instanceof IModelElement) {
......@@ -419,6 +506,7 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
return false;
}
/** {@inheritDoc} */
@Override
protected boolean isEnabled(Object element) {
if(element instanceof IModelElement) {
......@@ -428,9 +516,18 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
}
return false;
}
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if(element != null && sourceEntityType.isAssignableFrom(element.getClass())) {
return super.getImage(element);
}
return null;
}
};
tableViewerColumn.setLabelProvider(checkBoxlabelProvider);
tableViewerColumn.setEditingSupport(new CheckBoxEditingSupport(tableViewer) {
treeViewerColumn.setLabelProvider(checkBoxlabelProvider);
treeViewerColumn.setEditingSupport(new CheckBoxEditingSupport(treeViewer) {
/** {@inheritDoc} */
@Override
......@@ -481,8 +578,8 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
}
});
}
tableViewer.refresh();
table.setRedraw(true);
treeViewer.refresh();
tree.setRedraw(true);
}
/********************* Binding to underlying model *********************/
......@@ -549,6 +646,14 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
return null;
}
/** Returns the text to be displayed as tool-tip for a given element. */
private static String getToolTipText(Object object) {
if(object instanceof INamedElement) {
return computeFullyQualifiedName((INamedElement)object, false);
}
return null;
}
// TODO Move to a utility class after the release
/**
* Returns an {@link Image} for the given {@code element}, or {@code null} in case it cannot be
......
......@@ -17,35 +17,42 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.allocation.ui.editor;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Tree;
import org.fortiss.af3.allocation.model.AllocationTable;
/**
* GENERATED CODE: GUI elements for {@link AllocationTableEditor}.
*
* @author zverlov
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class AllocationTableEditorGUI extends Composite {
/** {@link TableViewer} used to edit {@link AllocationTable}. */
private TableViewer tableViewer;
/** {@link ComboViewer} used to select source viewpoint. */
private ComboViewer comboViewerSource;
/** {@link ComboViewer} used to select target viewpoint. */
private ComboViewer comboViewerTarget;
/** Checkbox used to select whether to show the source model elements' hierarchy. */
private Button checkboxShowSourceModelHierarchy;
/** {@link TableViewer} used to edit {@link AllocationTable}. */
private TreeViewer treeViewer;
/** Constructor. */
public AllocationTableEditorGUI(Composite parent, int style) {
super(parent, style);
......@@ -53,31 +60,51 @@ public class AllocationTableEditorGUI extends Composite {
setLayout(new GridLayout(2, false));
Label labelSource = new Label(this, SWT.NONE);
labelSource.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
GridData gd_labelSource = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
gd_labelSource.verticalIndent = 2;
labelSource.setLayoutData(gd_labelSource);
labelSource.setText("Source");
comboViewerSource = new ComboViewer(this, SWT.NONE);
Composite composite = new Composite(this, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2));
GridLayout compositeLayout = new GridLayout(2, false);
compositeLayout.marginWidth = 0;
compositeLayout.marginHeight = 0;
compositeLayout.horizontalSpacing = 20;
composite.setLayout(compositeLayout);
comboViewerSource = new ComboViewer(composite, SWT.NONE);
Combo comboSource = getComboViewerSource().getCombo();
GridData gd_comboSource = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
gd_comboSource.widthHint = 265;
GridData gd_comboSource = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_comboSource.widthHint = 270;
comboSource.setLayoutData(gd_comboSource);
Label labelTarget = new Label(this, SWT.NONE);
labelTarget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
labelTarget.setText("Target");
checkboxShowSourceModelHierarchy = new Button(composite, SWT.CHECK);
checkboxShowSourceModelHierarchy.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
false, 1, 1));
checkboxShowSourceModelHierarchy.setSelection(true);
checkboxShowSourceModelHierarchy.setText("Show Hierarchy");
comboViewerTarget = new ComboViewer(this, SWT.NONE);
comboViewerTarget = new ComboViewer(composite, SWT.NONE);
Combo comboTarget = getComboViewerTarget().getCombo();
GridData gd_comboTarget = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
GridData gd_comboTarget = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_comboTarget.widthHint = 270;
comboTarget.setLayoutData(gd_comboTarget);
new Label(composite, SWT.NONE);
Label labelTarget = new Label(this, SWT.NONE);
GridData gd_labelTarget = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_labelTarget.verticalIndent = 2;
labelTarget.setLayoutData(gd_labelTarget);
labelTarget.setText("Target");
new Label(this, SWT.NONE);
tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
Table table = getTableViewer().getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setLinesVisible(true);
table.setHeaderVisible(true);
treeViewer = new TreeViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
Tree tree = getTreeViewer().getTree();
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(treeViewer, ToolTip.NO_RECREATE);
}
/** Returns {@link #comboViewerSource}. */
......@@ -90,15 +117,13 @@ public class AllocationTableEditorGUI extends Composite {
return comboViewerTarget;
}
/** Returns {@link #tableViewer}. */
public TableViewer getTableViewer() {
return tableViewer;
/** Returns {@link #checkboxShowSourceModelHierarchy}. */
public Button getCheckboxShowSourceModelHierarchy() {
return checkboxShowSourceModelHierarchy;
}
// /** {@inheritDoc} */
// @Override
// public boolean setFocus() {
// tableViewer.refresh();
// return super.setFocus();
// }
/** Returns {@link #treeViewer}. */
public TreeViewer getTreeViewer() {
return treeViewer;
}
}
......@@ -48,7 +48,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating RED Hash: 4473E3431AB768E401B90A545600B16C
*/
public abstract class ModelListenerEditorBase<T extends EObject> extends GEFEditorBase<T> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment