From bee9f3a8c1e2af9f190d2cdc2b00f96f3616cfe7 Mon Sep 17 00:00:00 2001
From: Andreas Bayha <bayha@fortiss.org>
Date: Fri, 16 Oct 2020 13:15:28 +0200
Subject: [PATCH] YELLOW

Issue-Ref: 4014
Issue-Url: https://af3-developer.fortiss.org/issues/4014
Signed-off-by: Andreas Bayha <bayha@fortiss.org>
---
 .../base/ui/annotation/view/fx/.ratings       |   5 +-
 .../fx/AnnotationTreeTableUIProvider.java     | 130 ++++++++++++++++++
 .../view/fx/AnnotationViewFXController.java   | 121 ++--------------
 .../view/fx/AnnotationsFXUtils.java           |  47 +++++--
 4 files changed, 184 insertions(+), 119 deletions(-)
 create mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationTreeTableUIProvider.java

diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings
index 08c70fbac..aa1377353 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings
@@ -1,5 +1,6 @@
 AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 YELLOW
-AnnotationViewFXController.java 3618e62b47054754708a5e6e6df6895757816d84 YELLOW
-AnnotationsFXUtils.java f34cfa95b26282d86c7425b7ab05f3c5d91feb80 RED
+AnnotationTreeTableUIProvider.java 4d9ea9f5267e1a04985c5f67e748f34474c97e0f YELLOW
+AnnotationViewFXController.java 87d70534cde579cbd5f6470e729783306a139324 YELLOW
+AnnotationsFXUtils.java 754152735e037da59a4c40fa045602c3ed85a40f YELLOW
 ColumnHandle.java 761c2517b3f3e4725feb7ce7e8d5927ba191a4bb YELLOW
 FXAnnotationFilterContentProvider.java 90620e61e5c91669da26c0564527e0b4a31e4b9d YELLOW
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationTreeTableUIProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationTreeTableUIProvider.java
new file mode 100644
index 000000000..4d9ea9f52
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationTreeTableUIProvider.java
@@ -0,0 +1,130 @@
+/*-------------------------------------------------------------------------+
+| 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 org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.SELECTED_ANNOTATION_BACKGROUND_COLOR;
+import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.getBackgroundColorForEntry;
+
+import org.fortiss.tooling.base.annotation.AnnotationEntry;
+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.common.ui.javafx.control.treetableview.DynamicTreeTableUIProviderBase;
+import org.fortiss.tooling.kernel.model.INamedCommentedElement;
+
+import javafx.scene.paint.Color;
+
+/**
+ * UIProvider for the Annotation TreeTable.
+ */
+/* package */ final class AnnotationTreeTableUIProvider
+		extends DynamicTreeTableUIProviderBase<AnnotationEntry> {
+
+	/** The {@link AnnotationViewFXController} this UI provider was created for. */
+	private final AnnotationViewFXController viewController;
+
+	/**
+	 * Constructor.
+	 */
+	AnnotationTreeTableUIProvider(AnnotationViewFXController annotationViewFXController) {
+		this.viewController = annotationViewFXController;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public String getLabel(AnnotationEntry entry, int column) {
+		IModelElement element = entry.getModelElement();
+
+		switch(column) {
+			case 0:
+				return this.viewController.getNameForAnnotationEntry(entry);
+			case 1:
+				if(element instanceof INamedCommentedElement) {
+					return ((INamedCommentedElement)element).getComment();
+				}
+				return "";
+			default:
+				IAnnotatedSpecification columnSpec = this.viewController.colIdxAnnotationMap
+						.get(column).getAnnotatedSpecification();
+
+				Object specificationValue = entry.getSpecificationValue(columnSpec.getClass());
+				if(specificationValue != null) {
+					return specificationValue.toString();
+				}
+
+				return "";
+		}
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public Color getBackgroundColor(int column, AnnotationEntry element) {
+		if(element.getModelElement().equals(this.viewController.selected)) {
+			return SELECTED_ANNOTATION_BACKGROUND_COLOR;
+		}
+
+		if(column > 1 && this.viewController.colIdxAnnotationMap.containsKey(column)) {
+			Class<IAnnotatedSpecification> specType = this.viewController.colIdxAnnotationMap
+					.get(column).getAnnotatedSpecificationType();
+			return getBackgroundColorForEntry(element, specType);
+		}
+
+		return super.getBackgroundColor(column, element);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public void updateValue(AnnotationEntry element, int column, Object value) {
+		IAnnotatedSpecification specification =
+				this.viewController.colIdxAnnotationMap.get(column).getAnnotatedSpecification();
+		this.viewController.setAnnotationEntryValue(specification, element, (String)value);
+
+		super.updateValue(element, column, value);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean isEditable(int column, AnnotationEntry element) {
+		if(column > 1 && this.viewController.colIdxAnnotationMap.containsKey(column)) {
+			IAnnotatedSpecification spec =
+					this.viewController.colIdxAnnotationMap.get(column).getAnnotatedSpecification();
+			IAnnotationValueProvider<IAnnotatedSpecification> valueProvider =
+					element.getAnnotationValueProvider(spec.getClass());
+			return valueProvider != null && valueProvider.canEdit(spec);
+		}
+
+		return false;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean isEditable(int column) {
+
+		// The first two columns are not supposed to be editable.
+		if(column <= 1) {
+			return false;
+		}
+
+		for(AnnotationEntry ae : this.viewController.root.elements) {
+			// If any cell is editable in this column, the column is editable.
+			if(isEditable(column, ae)) {
+				return true;
+			}
+		}
+
+		return false;
+	}
+}
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java
index b1b158dfa..87d70534c 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java
@@ -18,8 +18,6 @@ package org.fortiss.tooling.base.ui.annotation.view.fx;
 import static java.util.Collections.emptyList;
 import static java.util.Collections.sort;
 import static java.util.stream.Collectors.toList;
-import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.SELECTED_ANNOTATION_BACKGROUND_COLOR;
-import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.getBackgroundColorForEntry;
 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;
@@ -72,7 +70,6 @@ import javafx.scene.control.SplitPane;
 import javafx.scene.control.TextField;
 import javafx.scene.control.TreeTableColumn;
 import javafx.scene.control.TreeTableView;
-import javafx.scene.paint.Color;
 
 /**
  * Controller for the Annotations view.
@@ -86,12 +83,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 	/** Option text for the annotation type filter combo box. */
 	private static final String SHOW_ALL_ANNOTATION_TYPES = "Show all annotation types";
 
-	/**
-	 * Root element to be added to the tree viewer (but not displayed). Container for all
-	 * {@link AnnotationEntry}s.
-	 */
-	ArtificialRoot root = new ArtificialRoot();
-
 	/** {@link TextField} for entering the filter pattern. */
 	@FXML
 	private TextField txtFilterText;
@@ -133,9 +124,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 	/** The {@link IProjectRootElement} in which the selected element is contained in. */
 	private IProjectRootElement curentRootElement;
 
-	/** The {@link IModelElement} that is currently selected by the user. */
-	private IModelElement selected;
-
 	/** {@link Set} of {@link ColumnHandle}s (i.e. management objects for columns). */
 	private Set<ColumnHandle<IAnnotatedSpecification>> columnHandles = new TreeSet<>();
 
@@ -158,9 +146,18 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 	 * Associates the handles of the annotations with their ordered column indexes.
 	 * Used for the UI providers of cell items.
 	 */
-	private Map<Integer, ColumnHandle<IAnnotatedSpecification>> colIdxAnnotationMap =
+	/* package */ Map<Integer, ColumnHandle<IAnnotatedSpecification>> colIdxAnnotationMap =
 			new HashMap<>();
 
+	/**
+	 * Root element to be added to the tree viewer (but not displayed). Container for all
+	 * {@link AnnotationEntry}s.
+	 */
+	/* package */ ArtificialRoot root = new ArtificialRoot();
+
+	/** The {@link IModelElement} that is currently selected by the user. */
+	/* package */ IModelElement selected;
+
 	/** {@inheritDoc} */
 	@Override
 	public String getFXMLLocation() {
@@ -263,7 +260,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 		boolean showRoot = false;
 		int revealLevel = 1;
 		DynamicTreeTableUIProviderBase<AnnotationEntry> uiProvider =
-				new AnnotationTreeTableUIProvider();
+				new AnnotationTreeTableUIProvider(this);
 
 		annotationViewer = new DynamicTreeTableViewer<AnnotationEntry>(annotationTreeTableView,
 				root, showRoot, revealLevel, filterContentProvider, uiProvider);
@@ -454,7 +451,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 	 * Local helper to set the given newValue for the given annotationEntry and
 	 * specification.
 	 */
-	private void setAnnotationEntryValue(IAnnotatedSpecification specification,
+	void setAnnotationEntryValue(IAnnotatedSpecification specification,
 			AnnotationEntry annotationEntry, String newValue) {
 		ITopLevelElement tle =
 				IPersistencyService.getInstance().getTopLevelElementFor(curentRootElement);
@@ -469,7 +466,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 	}
 
 	/** Retrieves the model element name to be displayed for the given {@link AnnotationEntry}. */
-	private String getNameForAnnotationEntry(AnnotationEntry entry) {
+	String getNameForAnnotationEntry(AnnotationEntry entry) {
 		IModelElement modelElement = entry.getModelElement();
 		if(modelElement instanceof INamedCommentedElement) {
 			return ((INamedCommentedElement)modelElement).getName();
@@ -477,98 +474,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
 		return "";
 	}
 
-	/**
-	 * UIProvider for the Annotation TreeTable.
-	 */
-	private class AnnotationTreeTableUIProvider
-			extends DynamicTreeTableUIProviderBase<AnnotationEntry> {
-
-		/** {@inheritDoc} */
-		@Override
-		public String getLabel(AnnotationEntry entry, int column) {
-			IModelElement element = entry.getModelElement();
-
-			switch(column) {
-				case 0:
-					return getNameForAnnotationEntry(entry);
-				case 1:
-					if(element instanceof INamedCommentedElement) {
-						return ((INamedCommentedElement)element).getComment();
-					}
-					return "";
-				default:
-					IAnnotatedSpecification columnSpec =
-							colIdxAnnotationMap.get(column).getAnnotatedSpecification();
-
-					Object specificationValue = entry.getSpecificationValue(columnSpec.getClass());
-					if(specificationValue != null) {
-						return specificationValue.toString();
-					}
-
-					return "";
-			}
-		}
-
-		/** {@inheritDoc} */
-		@Override
-		public Color getBackgroundColor(int column, AnnotationEntry element) {
-			if(element.getModelElement().equals(selected)) {
-				return SELECTED_ANNOTATION_BACKGROUND_COLOR;
-			}
-
-			if(column > 1 && colIdxAnnotationMap.containsKey(column)) {
-				Class<IAnnotatedSpecification> specType =
-						colIdxAnnotationMap.get(column).getAnnotatedSpecificationType();
-				return getBackgroundColorForEntry(element, specType);
-			}
-
-			return super.getBackgroundColor(column, element);
-		}
-
-		/** {@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 isEditable(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;
-		}
-
-		/** {@inheritDoc} */
-		@Override
-		public boolean isEditable(int column) {
-
-			// The first two columns are not supposed to be editable.
-			if(column <= 1) {
-				return false;
-			}
-
-			for(AnnotationEntry ae : root.elements) {
-				// If any cell is editable in this column, the column is editable.
-				if(isEditable(column, ae)) {
-					return true;
-				}
-			}
-
-			return false;
-		}
-	}
-
 	/**
 	 * Local class to represent the invisible root for the tree table.
 	 * 
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationsFXUtils.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationsFXUtils.java
index 81b8886fb..754152735 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationsFXUtils.java
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationsFXUtils.java
@@ -38,7 +38,11 @@ public class AnnotationsFXUtils {
 	/** Background color for table cells, which are not editable and empty. */
 	public static final Color READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR = LIGHTGREY;
 
-	/** SWT background color for table cells, which are not editable and empty. */
+	/**
+	 * SWT background color for table cells, which are not editable and empty.
+	 * 
+	 * Deprecated - should be removed, when SWT is completely replaced.
+	 */
 	@Deprecated
 	public static final org.eclipse.swt.graphics.Color READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR_SWT =
 			convertFXColortoSWT(READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR);
@@ -50,9 +54,15 @@ public class AnnotationsFXUtils {
 	protected static final Color SELECTED_ANNOTATION_BACKGROUND_COLOR = LIGHTSEAGREEN;
 
 	/**
+	 * Retrieves the background {@link Color} to be used for the given
+	 * {@link AnnotationEntry}.
+	 * 
 	 * @param annotationEntry
+	 *            The {@link AnnotationEntry} to get a background color for.
 	 * @param annotationType
-	 * @return
+	 *            The {@link Class} of the {@link IAnnotatedSpecification}.
+	 * 
+	 * @return The {@link Color} to be used in the background.
 	 */
 	public static Color getBackgroundColorForEntry(AnnotationEntry annotationEntry,
 			Class<? extends IAnnotatedSpecification> annotationType) {
@@ -73,10 +83,22 @@ public class AnnotationsFXUtils {
 	}
 
 	/**
+	 * Retrieves the background {@link org.eclipse.swt.graphics.Color} for the given
+	 * {@link AnnotationEntry}.
+	 * A default {@link org.eclipse.swt.graphics.Color} if there is nothing other than white
+	 * specified, yet.
+	 * 
+	 * Deprecated - should be removed, when SWT is completely replaced.
+	 * 
 	 * @param annotationEntry
+	 *            The {@link AnnotationEntry} to get a background color for.
 	 * @param annotationType
+	 *            The {@link Class} of the {@link IAnnotatedSpecification}.
 	 * @param defaultColor
-	 * @return
+	 *            The default {@link org.eclipse.swt.graphics.Color} to be used, if it would be
+	 *            white otherwise. Might be null if WHITE shall be used.
+	 * 
+	 * @return The background {@link org.eclipse.swt.graphics.Color} to be used for the given input.
 	 */
 	@Deprecated
 	public static org.eclipse.swt.graphics.Color getSWTBackgroundColorForEntry(
@@ -93,14 +115,21 @@ public class AnnotationsFXUtils {
 	}
 
 	/**
-	 * @param bgCol
-	 * @return
+	 * Helper to convert JavaFx Color objects to SWT.
+	 * 
+	 * Deprecated - should be removed, when SWT is completely replaced.
+	 * 
+	 * @param color
+	 *            The FX {@link Color} to be converted.
+	 * 
+	 * @return The input, converted to a SWT {@link org.eclipse.swt.graphics.Color}.
 	 */
-	private static org.eclipse.swt.graphics.Color convertFXColortoSWT(Color bgCol) {
+	@Deprecated
+	private static org.eclipse.swt.graphics.Color convertFXColortoSWT(Color color) {
 		Device device = getCurrent();
-		int red = (int)bgCol.getRed();
-		int green = (int)bgCol.getGreen();
-		int blue = (int)bgCol.getBlue();
+		int red = (int)color.getRed();
+		int green = (int)color.getGreen();
+		int blue = (int)color.getBlue();
 		return new org.eclipse.swt.graphics.Color(device, red, green, blue);
 	}
 }
-- 
GitLab