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

YELLOW

parent bbbde489
No related branches found
No related tags found
1 merge request!1254014
This commit is part of merge request !125. Comments created here will be created in the context of that merge request.
AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 YELLOW AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 YELLOW
AnnotationViewFXController.java 3618e62b47054754708a5e6e6df6895757816d84 YELLOW AnnotationTreeTableUIProvider.java 4d9ea9f5267e1a04985c5f67e748f34474c97e0f YELLOW
AnnotationsFXUtils.java f34cfa95b26282d86c7425b7ab05f3c5d91feb80 RED AnnotationViewFXController.java 87d70534cde579cbd5f6470e729783306a139324 YELLOW
AnnotationsFXUtils.java 754152735e037da59a4c40fa045602c3ed85a40f YELLOW
ColumnHandle.java 761c2517b3f3e4725feb7ce7e8d5927ba191a4bb YELLOW ColumnHandle.java 761c2517b3f3e4725feb7ce7e8d5927ba191a4bb YELLOW
FXAnnotationFilterContentProvider.java 90620e61e5c91669da26c0564527e0b4a31e4b9d YELLOW FXAnnotationFilterContentProvider.java 90620e61e5c91669da26c0564527e0b4a31e4b9d YELLOW
/*-------------------------------------------------------------------------+
| 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;
}
}
...@@ -18,8 +18,6 @@ package org.fortiss.tooling.base.ui.annotation.view.fx; ...@@ -18,8 +18,6 @@ package org.fortiss.tooling.base.ui.annotation.view.fx;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Collections.sort; import static java.util.Collections.sort;
import static java.util.stream.Collectors.toList; 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_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_CURRENT;
import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_SELECTED_SUBMODEL; import static org.fortiss.tooling.base.ui.annotation.view.fx.FXAnnotationFilterContentProvider.HIERARCHY_LEVELS_SELECTED_SUBMODEL;
...@@ -72,7 +70,6 @@ import javafx.scene.control.SplitPane; ...@@ -72,7 +70,6 @@ import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView; import javafx.scene.control.TreeTableView;
import javafx.scene.paint.Color;
/** /**
* Controller for the Annotations view. * Controller for the Annotations view.
...@@ -86,12 +83,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -86,12 +83,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
/** Option text for the annotation type filter combo box. */ /** Option text for the annotation type filter combo box. */
private static final String SHOW_ALL_ANNOTATION_TYPES = "Show all annotation types"; 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. */ /** {@link TextField} for entering the filter pattern. */
@FXML @FXML
private TextField txtFilterText; private TextField txtFilterText;
...@@ -133,9 +124,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -133,9 +124,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
/** The {@link IProjectRootElement} in which the selected element is contained in. */ /** The {@link IProjectRootElement} in which the selected element is contained in. */
private IProjectRootElement curentRootElement; 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). */ /** {@link Set} of {@link ColumnHandle}s (i.e. management objects for columns). */
private Set<ColumnHandle<IAnnotatedSpecification>> columnHandles = new TreeSet<>(); private Set<ColumnHandle<IAnnotatedSpecification>> columnHandles = new TreeSet<>();
...@@ -158,9 +146,18 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -158,9 +146,18 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
* Associates the handles of the annotations with their ordered column indexes. * Associates the handles of the annotations with their ordered column indexes.
* Used for the UI providers of cell items. * Used for the UI providers of cell items.
*/ */
private Map<Integer, ColumnHandle<IAnnotatedSpecification>> colIdxAnnotationMap = /* package */ Map<Integer, ColumnHandle<IAnnotatedSpecification>> colIdxAnnotationMap =
new HashMap<>(); 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} */ /** {@inheritDoc} */
@Override @Override
public String getFXMLLocation() { public String getFXMLLocation() {
...@@ -263,7 +260,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -263,7 +260,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
boolean showRoot = false; boolean showRoot = false;
int revealLevel = 1; int revealLevel = 1;
DynamicTreeTableUIProviderBase<AnnotationEntry> uiProvider = DynamicTreeTableUIProviderBase<AnnotationEntry> uiProvider =
new AnnotationTreeTableUIProvider(); new AnnotationTreeTableUIProvider(this);
annotationViewer = new DynamicTreeTableViewer<AnnotationEntry>(annotationTreeTableView, annotationViewer = new DynamicTreeTableViewer<AnnotationEntry>(annotationTreeTableView,
root, showRoot, revealLevel, filterContentProvider, uiProvider); root, showRoot, revealLevel, filterContentProvider, uiProvider);
...@@ -454,7 +451,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -454,7 +451,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
* Local helper to set the given newValue for the given annotationEntry and * Local helper to set the given newValue for the given annotationEntry and
* specification. * specification.
*/ */
private void setAnnotationEntryValue(IAnnotatedSpecification specification, void setAnnotationEntryValue(IAnnotatedSpecification specification,
AnnotationEntry annotationEntry, String newValue) { AnnotationEntry annotationEntry, String newValue) {
ITopLevelElement tle = ITopLevelElement tle =
IPersistencyService.getInstance().getTopLevelElementFor(curentRootElement); IPersistencyService.getInstance().getTopLevelElementFor(curentRootElement);
...@@ -469,7 +466,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -469,7 +466,7 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
} }
/** Retrieves the model element name to be displayed for the given {@link AnnotationEntry}. */ /** 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(); IModelElement modelElement = entry.getModelElement();
if(modelElement instanceof INamedCommentedElement) { if(modelElement instanceof INamedCommentedElement) {
return ((INamedCommentedElement)modelElement).getName(); return ((INamedCommentedElement)modelElement).getName();
...@@ -477,98 +474,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP ...@@ -477,98 +474,6 @@ public class AnnotationViewFXController extends CompositeFXControllerBase<SplitP
return ""; 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. * Local class to represent the invisible root for the tree table.
* *
......
...@@ -38,7 +38,11 @@ public class AnnotationsFXUtils { ...@@ -38,7 +38,11 @@ public class AnnotationsFXUtils {
/** Background color for table cells, which are not editable and empty. */ /** Background color for table cells, which are not editable and empty. */
public static final Color READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR = LIGHTGREY; 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 @Deprecated
public static final org.eclipse.swt.graphics.Color READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR_SWT = public static final org.eclipse.swt.graphics.Color READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR_SWT =
convertFXColortoSWT(READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR); convertFXColortoSWT(READ_ONLY_EMPTY_ANNOTATION_BACKGROUND_COLOR);
...@@ -50,9 +54,15 @@ public class AnnotationsFXUtils { ...@@ -50,9 +54,15 @@ public class AnnotationsFXUtils {
protected static final Color SELECTED_ANNOTATION_BACKGROUND_COLOR = LIGHTSEAGREEN; protected static final Color SELECTED_ANNOTATION_BACKGROUND_COLOR = LIGHTSEAGREEN;
/** /**
* Retrieves the background {@link Color} to be used for the given
* {@link AnnotationEntry}.
*
* @param annotationEntry * @param annotationEntry
* The {@link AnnotationEntry} to get a background color for.
* @param annotationType * @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, public static Color getBackgroundColorForEntry(AnnotationEntry annotationEntry,
Class<? extends IAnnotatedSpecification> annotationType) { Class<? extends IAnnotatedSpecification> annotationType) {
...@@ -73,10 +83,22 @@ public class AnnotationsFXUtils { ...@@ -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 * @param annotationEntry
* The {@link AnnotationEntry} to get a background color for.
* @param annotationType * @param annotationType
* The {@link Class} of the {@link IAnnotatedSpecification}.
* @param defaultColor * @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 @Deprecated
public static org.eclipse.swt.graphics.Color getSWTBackgroundColorForEntry( public static org.eclipse.swt.graphics.Color getSWTBackgroundColorForEntry(
...@@ -93,14 +115,21 @@ public class AnnotationsFXUtils { ...@@ -93,14 +115,21 @@ public class AnnotationsFXUtils {
} }
/** /**
* @param bgCol * Helper to convert JavaFx Color objects to SWT.
* @return *
* 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(); Device device = getCurrent();
int red = (int)bgCol.getRed(); int red = (int)color.getRed();
int green = (int)bgCol.getGreen(); int green = (int)color.getGreen();
int blue = (int)bgCol.getBlue(); int blue = (int)color.getBlue();
return new org.eclipse.swt.graphics.Color(device, red, green, blue); return new org.eclipse.swt.graphics.Color(device, red, green, blue);
} }
} }
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