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

Annotations: Added background color for non-editable cells

Enhances DynamicTreeTableViewer such that cell background can easily be
set.

Refactored combo column code to be more generic and reusable.

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


Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent 97dd2d1d
No related branches found
No related tags found
1 merge request!1254014
AnnotationFxViewPart.java 6b65210913c150420f4fe67d055a0051d1d37a4e YELLOW
AnnotationViewFXController.java 55041ac106d68f27fcbcb26cf0a15cc3842f9bb1 YELLOW
AnnotationViewFXController.java c83d79c19d8be7de81c648a413e8527d48294005 YELLOW
FXAnnotationFilterContentProvider.java 80fa6e9cc2f5ba3a255cab7061edca5fa368451a YELLOW
......@@ -17,6 +17,9 @@ package org.fortiss.tooling.base.ui.annotation.view.fx;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static javafx.scene.paint.Color.ALICEBLUE;
import static javafx.scene.paint.Color.LIGHTGREY;
import static javafx.scene.paint.Color.WHITE;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_ALL;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_CURRENT;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_SELECTED_SUBMODEL;
......@@ -50,7 +53,6 @@ import org.fortiss.tooling.base.annotation.valueprovider.ValueProviderBase;
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.DynamicTextFieldTreeTableCell;
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;
......@@ -69,9 +71,9 @@ import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.paint.Color;
/**
* Controller for the Annotations view.
......@@ -276,7 +278,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
columnHandles.clear();
columnHandleToColumn.clear();
annotationTreeTableView.getColumns().clear();
annotationTreeTableView.setRoot(null);
// annotationTreeTableView.setRoot(null);
}
/** Configures the filter widgets for the annotation table. */
......@@ -402,7 +404,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
colIdxAnnotationMap.put(columnIdx, handle);
TreeTableColumn<AnnotationEntry, String> column = null;
TreeTableColumn<AnnotationEntry, ?> column = null;
// Case distinction for the cell factory depending on the type to be edited.
if(valueType == null) {
......@@ -410,7 +412,9 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
column.setEditable(false);
return column;
} else if(valueType instanceof EEnum) {
}
if(valueType instanceof EEnum) {
// Add a combo column for enumerations.
column = annotationViewer.addComboColumn(columnName, 150, rowEntry -> {
ValueProviderBase<IAnnotatedSpecification> annotationValueProvider =
......@@ -431,43 +435,14 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
});
} else if(valueType.getInstanceClass().equals(Boolean.class)) {
// Use a checkbox column for booleans
annotationViewer.addCheckboxColumn(columnName, 100);
column = annotationViewer.addCheckboxColumn(columnName, 100);
} else {
// For all other types, there is text editing.
column = annotationViewer.addColumn(columnName, 150);
column.setCellFactory(ttColumn -> new DynamicTextFieldTreeTableCell<AnnotationEntry>() {
/** {@inheritDoc} */
@Override
protected boolean canEdit(AnnotationEntry element) {
// We start editing only, if this cell is supposed to be editable.
IAnnotationValueProvider<IAnnotatedSpecification> annotationValueProvider =
element.getAnnotationValueProvider(annotationClass);
IAnnotatedSpecification currentSpecification =
element.getSpecification(annotationClass);
return annotationValueProvider != null &&
annotationValueProvider.canEdit(currentSpecification);
}
/** {@inheritDoc} */
@Override
protected void setValueOnLeavingCell(AnnotationEntry element, String currentValue) {
IAnnotatedSpecification specification =
element.getSpecification(annotationClass);
setAnnotationEntryValue(specification, element, currentValue);
}
});
column = annotationViewer.addTextColumn(columnName, 150);
}
if(column != null) {
column.setEditable(true);
column.setOnEditCommit(event -> {
TreeItem<AnnotationEntry> treeItem = event.getRowValue();
AnnotationEntry rowEntry = treeItem.getValue();
String newValue = event.getNewValue();
setAnnotationEntryValue(specification, rowEntry, newValue);
});
}
return column;
......@@ -531,6 +506,51 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
return "";
}
}
/** {@inheritDoc} */
@Override
public Color getBackgroundColor(AnnotationEntry element, int column) {
if(column > 1 && colIdxAnnotationMap.containsKey(column)) {
IAnnotatedSpecification spec =
colIdxAnnotationMap.get(column).getAnnotatedSpecification();
IAnnotationValueProvider<IAnnotatedSpecification> valueProvider =
element.getAnnotationValueProvider(spec.getClass());
if(valueProvider != null && valueProvider.getAnnotationValue(spec) != null &&
!isElementEditable(column, element)) {
return ALICEBLUE;
}
if(!isElementEditable(column, element)) {
return LIGHTGREY;
}
}
return WHITE;
}
/** {@inheritDoc} */
@Override
public void updateValue(AnnotationEntry element, int column, Object value) {
IAnnotatedSpecification specification =
colIdxAnnotationMap.get(column).getAnnotatedSpecification();
setAnnotationEntryValue(specification, element, (String)value);
super.updateValue(element, column, value);
}
/** {@inheritDoc} */
@Override
public boolean isElementEditable(int column, AnnotationEntry element) {
if(column > 1 && colIdxAnnotationMap.containsKey(column)) {
IAnnotatedSpecification spec =
colIdxAnnotationMap.get(column).getAnnotatedSpecification();
IAnnotationValueProvider<IAnnotatedSpecification> valueProvider =
element.getAnnotationValueProvider(spec.getClass());
return valueProvider != null && valueProvider.canEdit(spec);
}
return false;
}
}
/**
......
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