Skip to content
Snippets Groups Projects
Commit 8ca82855 authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Annotations: AnnotationFxView table

First Durchstich to display annotations according to the current
selection.

Issue-Ref: 4014
Issue-Url: https://af3-developer.fortiss.org/issues/4014


Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent 035376eb
No related branches found
No related tags found
1 merge request!1254014
......@@ -7,7 +7,7 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="build"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="lib" path="lib/opal-1.0.4.jar" sourcepath="lib/opal-1.0.4-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/com.google.guava-15.0.0.v201403281430.jar" sourcepath="lib/klay-layouters-2016-02-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/de.cau.cs.kieler.core-0.15.0.201602160301.jar" sourcepath="lib/klay-layouters-2016-02-src.zip"/>
......@@ -16,4 +16,5 @@
<classpathentry exported="true" kind="lib" path="lib/de.cau.cs.kieler.klay.force-0.4.0.201602160301.jar" sourcepath="lib/klay-layouters-2016-02-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/de.cau.cs.kieler.klay.layered-0.13.0.201602160301.jar" sourcepath="lib/klay-layouters-2016-02-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/de.cau.cs.kieler.klay.tree-0.4.0.201602160301.jar" sourcepath="lib/klay-layouters-2016-02-src.zip"/>
<classpathentry kind="output" path="build"/>
</classpath>
......@@ -6,7 +6,8 @@ Bundle-Version: 2.17.0.qualifier
Bundle-Activator: org.fortiss.tooling.base.ui.ToolingBaseUIActivator
Require-Bundle: org.fortiss.tooling.base;bundle-version="2.17.0";visibility:=reexport,
org.fortiss.tooling.kernel.ui;bundle-version="2.17.0";visibility:=reexport,
org.eclipse.swt
org.eclipse.swt,
org.fortiss.tooling.common.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-Vendor: fortiss GmbH
......
......@@ -20,6 +20,13 @@
name="Annotations"
restorable="true">
</view>
<view
class="org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationFxViewPart"
icon="icons/annotation.gif"
id="org.fortiss.tooling.base.ui.annotationFxView"
name="Annotations FX"
restorable="true">
</view>
</extension>
<extension point="org.fortiss.tooling.kernel.uiMessageHandler">
<uiMessageHandler
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.layout.AnchorPane?>
<SplitPane fx:id="annotationSplitPane" dividerPositions="0.6105527638190955" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<items>
<AnchorPane fx:id="annotationTablePane" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TreeTableView fx:id="annotationTreeTableView" layoutX="328.0" layoutY="20.0" prefHeight="239.0" prefWidth="598.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children></AnchorPane>
<AnchorPane fx:id="filterPane" minHeight="0.0" minWidth="0.0" prefHeight="219.0" prefWidth="598.0" />
</items>
</SplitPane>
/*-------------------------------------------------------------------------+
| Copyright 2020 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.annotation.view.fx;
import org.fortiss.tooling.common.ui.javafx.AF3FXViewPart;
import javafx.scene.Scene;
/**
*
* @author bayha
*/
public class AnnotationFxViewPart extends AF3FXViewPart {
private static final AnnotationViewFXController VIEW_CONTROLLER =
new AnnotationViewFXController();
/**
* @param controller
* @param cssLocation
* @throws Exception
*/
public AnnotationFxViewPart() throws Exception {
super(VIEW_CONTROLLER, null);
}
/** {@inheritDoc} */
@Override
protected Scene createFxScene() {
Scene scene = super.createFxScene();
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(VIEW_CONTROLLER);
return scene;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2020 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.annotation.view.fx;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotationValueProvider;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.AnnotationValueService;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.view.generic.ColumnHandle;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeContentProviderBase;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeTableUIProviderBase;
import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeTableViewer;
import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TreeTableView;
/**
*
* @author bayha
*/
@SuppressWarnings("unchecked")
public class AnnotationViewFXController extends CompositeFXControllerBase<SplitPane, Node>
implements ISelectionListener {
/** */
@FXML
private SplitPane annotationSplitPane;
/** */
@FXML
private TreeTableView<AnnotationEntry> annotationTreeTableView;
/** */
private DynamicTreeTableViewer<AnnotationEntry> annotationTreeViewer;
/** */
private IModelElement selectedElement;
/** */
private DynamicTreeContentProviderBase<AnnotationEntry> contentProvider =
new AnnotationTableContentProvider();
/** */
private DynamicTreeTableUIProviderBase<AnnotationEntry> uiProvider =
new AnnotationTreeTableUIProvider();
/**
* Associates the handles of the annotations with their ordered column indexes. Used for the UI
* providers of cell items.
*/
Map<Integer, ColumnHandle<IAnnotatedSpecification>> colIdxAnnotationMap = new HashMap<>();
/** {@inheritDoc} */
@Override
public String getFXMLLocation() {
return "AnnotationViewFx.fxml";
}
/** {@inheritDoc} */
@Override
public void initialize() {
// EMPTY
}
/** {@inheritDoc} */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
selectedElement = checkAndPickFirst(selection, IModelElement.class);
updateAnnotationTree();
}
/**
*
*/
private void updateAnnotationTree() {
if(selectedElement == null) {
return;
}
EList<IModelElement> childElements =
getChildrenWithType(selectedElement, IModelElement.class);
ArtificialRoot root = new ArtificialRoot(selectedElement);
for(IModelElement elem : childElements) {
AnnotationEntry entry = IAnnotationValueService.getInstance().getAnnotationEntry(elem);
if(entry != null) {
root.elements.add(entry);
}
}
// Sorted set of {@link ColumnHandle} used to instantiate this {@link
// GenericAnnotationView}'s columns in the right order.
Set<ColumnHandle<IAnnotatedSpecification>> sortedColumnHandles = new TreeSet<>();
Set<AnnotationEntry> annotationEntries = new HashSet<>();
childElements.forEach(e -> annotationEntries
.add(AnnotationValueService.getInstance().getAnnotationEntry(e)));
// Aggregate required columns. Column order is defined by ColumnHandle.compareTo().
for(AnnotationEntry entry : annotationEntries) {
for(IAnnotatedSpecification spec : entry.getSpecificationsList()) {
ColumnHandle<IAnnotatedSpecification> columnHandle =
new ColumnHandle<IAnnotatedSpecification>(entry, spec);
sortedColumnHandles.add(columnHandle);
}
}
annotationTreeTableView.getColumns().clear();
boolean showRoot = false;
int revealLevel = 1;
annotationTreeViewer = new DynamicTreeTableViewer<AnnotationEntry>(annotationTreeTableView,
root, showRoot, revealLevel, contentProvider, uiProvider);
annotationTreeViewer.addColumn("Model Element", 200);
annotationTreeViewer.addColumn("Comment", 250);
int columnIdx = 2;
for(ColumnHandle<IAnnotatedSpecification> handle : sortedColumnHandles) {
annotationTreeViewer.addColumn(handle.getColumnName(), 150);
colIdxAnnotationMap.put(columnIdx++, handle);
}
}
/**
*
* @author bayha
*/
protected class AnnotationTreeTableUIProvider
extends DynamicTreeTableUIProviderBase<AnnotationEntry> {
/** {@inheritDoc} */
@Override
public String getLabel(AnnotationEntry entry, int column) {
IModelElement element = entry.getModelElement();
switch(column) {
case 0:
if(element instanceof INamedCommentedElement) {
return ((INamedCommentedElement)element).getName();
}
return "";
case 1:
if(element instanceof INamedCommentedElement) {
return ((INamedCommentedElement)element).getComment();
}
return "";
default:
ColumnHandle<IAnnotatedSpecification> colHandle =
colIdxAnnotationMap.get(column);
IAnnotationValueProvider<IAnnotatedSpecification> valProvider =
getAnnotationValueProvider(element,
colHandle.getAnnotatedSpecificationType());
try {
return valProvider.getAnnotationValue(colHandle.getAnnotatedSpecification())
.toString();
} catch(Exception e) {
// For this demo class, it is expected that direct conversions to
// strings will fail for some annotations. Simple don't show anything in
// this case.
return "";
}
}
}
}
/**
*
* @author bayha
*/
protected class AnnotationTableContentProvider
extends DynamicTreeContentProviderBase<AnnotationEntry> {
/** {@inheritDoc} */
@Override
protected Collection<? extends AnnotationEntry> getChildren(AnnotationEntry parent) {
if(parent instanceof ArtificialRoot) {
return ((ArtificialRoot)parent).elements;
}
return emptyList();
}
}
/**
*
* @author bayha
*/
protected class ArtificialRoot extends AnnotationEntry {
/**
* @param modelElement
*/
public ArtificialRoot(IModelElement modelElement) {
super(modelElement);
}
/** */
List<AnnotationEntry> elements = new ArrayList<AnnotationEntry>();
}
}
......@@ -43,7 +43,7 @@ import org.fortiss.tooling.kernel.service.types.EMFTypeMap;
*
* @author eder, barner
*/
public final class AnnotationEntry {
public class AnnotationEntry {
/**
* Model element for which the set of relevant {@link IAnnotatedSpecification}s is managed by
......
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