Skip to content

Commit

Permalink
Merge pull request #186 from virtualsatellite/integrationOverwriteFlag
Browse files Browse the repository at this point in the history
Add simple UI to show Overwrite-Falg in SEI-Editor
  • Loading branch information
dellerDLR authored Aug 29, 2023
2 parents dedfa36 + cb36e50 commit a98f49c
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
*******************************************************************************/
package de.dlr.sc.virsat.model.extension.cefx.util;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

Expand All @@ -23,8 +24,12 @@
import org.junit.Test;

import de.dlr.sc.virsat.concept.unittest.util.test.AConceptTestCase;
import de.dlr.sc.virsat.model.concept.types.property.BeanPropertyComposed;
import de.dlr.sc.virsat.model.dvlm.categories.CategoryAssignment;
import de.dlr.sc.virsat.model.dvlm.concepts.Concept;
import de.dlr.sc.virsat.model.dvlm.concepts.util.ActiveConceptHelper;
import de.dlr.sc.virsat.model.extension.cefx.model.EquipmentMassParameters;
import de.dlr.sc.virsat.model.extension.cefx.model.EquipmentParameters;
import de.dlr.sc.virsat.model.extension.cefx.model.Parameter;
import de.dlr.sc.virsat.model.extension.cefx.model.SystemMode;
import de.dlr.sc.virsat.model.extension.cefx.model.Value;
Expand Down Expand Up @@ -209,5 +214,33 @@ public void testGetModeValueOrDefault() {
assertEquals("Found the correct mode value", value1.getValue(), modeValue1, EPS);
assertEquals("Found the correct mode value", value2.getValue(), modeValue2, EPS);
}

@Test
public void testIsValueCalculated() {
CefModeHelper helper = new CefModeHelper();

ElementConfiguration subSystem = new ElementConfiguration(conceptPS);
EquipmentMassParameters paramsMass = new EquipmentMassParameters(conceptCEFX);
EquipmentParameters params = new EquipmentParameters(conceptCEFX);
subSystem.add(params);
subSystem.add(paramsMass);
BeanPropertyComposed<Parameter> beanNotComputed = paramsMass.getMassBean();
BeanPropertyComposed<Parameter> beanComputed = paramsMass.getMassTotalBean();

Value valueNotComputed = new Value(conceptCEFX);
Value valueComputed = new Value(conceptCEFX);

SystemMode systemMode1 = new SystemMode(conceptCEFX);
SystemMode systemMode2 = new SystemMode(conceptCEFX);

valueNotComputed.setMode(systemMode1);
valueComputed.setMode(systemMode2);

beanNotComputed.getValue().getModeValues().add(valueNotComputed);
beanComputed.getValue().getModeValues().add(valueComputed);

assertTrue(helper.isValueCalculated((CategoryAssignment) valueComputed.getTypeInstance()));
assertFalse(helper.isValueCalculated((CategoryAssignment) valueNotComputed.getTypeInstance()));
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package de.dlr.sc.virsat.model.extension.cefx.ui;

import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

Expand Down Expand Up @@ -45,4 +46,14 @@ public void start(BundleContext context) throws Exception {
public static Plugin getDefault() {
return plugin;
}

/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
package de.dlr.sc.virsat.model.extension.cefx.ui.itemprovider;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.TreeColumn;

Expand All @@ -32,6 +34,10 @@
import de.dlr.sc.virsat.model.extension.cefx.model.SystemMode;
import de.dlr.sc.virsat.model.extension.cefx.model.SystemParameters;
import de.dlr.sc.virsat.model.extension.cefx.model.Value;
import de.dlr.sc.virsat.model.extension.cefx.ui.Activator;
import de.dlr.sc.virsat.model.extension.cefx.ui.snippet.tableimpl.OverrideFlagCellEditingSupport;
import de.dlr.sc.virsat.model.extension.cefx.ui.snippet.tableimpl.UiSnippetCefTreeTableImpl;
import de.dlr.sc.virsat.model.extension.cefx.util.CefModeHelper;
import de.dlr.sc.virsat.project.markers.VirSatProblemMarkerHelper;
import de.dlr.sc.virsat.project.ui.labelProvider.VirSatTransactionalAdapterFactoryLabelProvider;
import de.dlr.sc.virsat.uieingine.ui.DVLMEditorPlugin;
Expand All @@ -49,12 +55,22 @@ public class VirSatCefTreeLabelProvider extends VirSatTransactionalAdapterFactor
private MarkerImageProvider mip = new MarkerImageProvider(new VirSatProblemMarkerHelper());
private EsfMarkerImageProvider emip;
private static final String NO_MODE_SELECTED = "[No Mode Selected]";
private static final String CALCULATED_STRING = "<<calculated>>";
private static final String OVERRIDE_IMAGE_PATH = "resources/icons/Override.gif";
private static final String INHERIT_IMAGE_PATH = "resources/icons/Inherit.gif";
private static final String FLOAT_PROP_IMAGE_PATH = "resources/icons/FloatProperty.gif";
private static final Color COLOR_READ_ONLY = new Color(96, 96, 96);
private static final int OVERRIDE_COLUMN = 3;
private ColumnViewer columnViewer;
private Image imageCalculated;
private Image imageOverride;
private Image imageInherited;
private Image imageFloat;

TreeViewerColumn colOne;
TreeViewerColumn colTwo;
TreeViewerColumn colThree;
TreeViewerColumn colOverrie;


/**
Expand All @@ -66,24 +82,32 @@ public class VirSatCefTreeLabelProvider extends VirSatTransactionalAdapterFactor
* @param colThree
* @param emip
*/
public VirSatCefTreeLabelProvider(AdapterFactory adapterFactory, ColumnViewer columnViewer, TreeViewerColumn colOne, TreeViewerColumn colTwo, TreeViewerColumn colThree, EsfMarkerImageProvider emip) {
public VirSatCefTreeLabelProvider(AdapterFactory adapterFactory, ColumnViewer columnViewer, TreeViewerColumn colOne, TreeViewerColumn colOverride, TreeViewerColumn colTwo, TreeViewerColumn colThree, EsfMarkerImageProvider emip) {
super(adapterFactory);
this.columnViewer = columnViewer;
this.colOne = colOne;
this.colOverrie = colOverride;
this.colTwo = colTwo;
this.colThree = colThree;
this.emip = emip;

imageOverride = ExtendedImageRegistry.INSTANCE.getImage(Activator.getImageDescriptor(OVERRIDE_IMAGE_PATH));
imageInherited = ExtendedImageRegistry.INSTANCE.getImage(Activator.getImageDescriptor(INHERIT_IMAGE_PATH));
imageCalculated = DVLMEditorPlugin.getPlugin().getImageRegistry().get(DVLMEditorPlugin.IMAGE_CALCULATED);
imageFloat = ExtendedImageRegistry.INSTANCE.getImage(Activator.getImageDescriptor(FLOAT_PROP_IMAGE_PATH));
}

@Override
public String getColumnText(Object object, int columnIndex) {

TreeColumn column = ((TreeViewer) columnViewer).getTree().getColumn(columnIndex);
CategoryAssignment ca = getCategoryAssignment(object);
CefModeHelper modeHelper = new CefModeHelper();
redirectNotification(ca, object);

if (ca == null || ca.getType() == null) {
return null;
}

if (ca.getType().getFullQualifiedName().equals(Parameter.FULL_QUALIFIED_CATEGORY_NAME)) {
Parameter parameterBean = new Parameter(ca);
redirectNotification(parameterBean.getDefaultValueBean().getTypeInstance(), ca);
Expand All @@ -94,7 +118,22 @@ public String getColumnText(Object object, int columnIndex) {
} else if (column == colThree.getColumn()) {
AUnit unit = parameterBean.getDefaultValueBean().getTypeInstance().getUnit();
return super.getText(unit);
}
} else if (column == colOverrie.getColumn()) {
if (ca.getSuperTis().isEmpty()) {
column.setWidth(0);
} else {
column.setWidth(UiSnippetCefTreeTableImpl.OVERRIDE_COLUMN_SIZE);
}
Boolean overwrite = parameterBean.getDefaultValueBean().getTypeInstance().isOverride();
if (parameterBean.getDefaultValueBean().getIsCalculated()) {
return CALCULATED_STRING;
}
if (overwrite) {
return OverrideFlagCellEditingSupport.OVERRIDE_LITERALS[1];
} else {
return OverrideFlagCellEditingSupport.OVERRIDE_LITERALS[0];
}
}
} else if (ca.getType().getFullQualifiedName().equals(Value.FULL_QUALIFIED_CATEGORY_NAME)) {
Value valueBean = new Value(ca);
redirectNotification(valueBean, ca, true);
Expand All @@ -110,6 +149,22 @@ public String getColumnText(Object object, int columnIndex) {
} else if (column == colThree.getColumn()) {
AUnit unit = valuePropertyBean.getTypeInstance().getUnit();
return super.getText(unit);
} else if (column == colOverrie.getColumn()) {
if (ca.getSuperTis().isEmpty()) {
column.setWidth(0);
} else {
column.setWidth(UiSnippetCefTreeTableImpl.OVERRIDE_COLUMN_SIZE);
}
Boolean overwrite = valueBean.getValueBean().getTypeInstance().isOverride()
|| valueBean.getModeBean().getTypeInstance().isOverride();
if (modeHelper.isValueCalculated(ca)) {
return CALCULATED_STRING;
}
if (overwrite) {
return OverrideFlagCellEditingSupport.OVERRIDE_LITERALS[1];
} else {
return OverrideFlagCellEditingSupport.OVERRIDE_LITERALS[0];
}
}
} else if (ca.getType().getFullQualifiedName().equals(SystemParameters.FULL_QUALIFIED_CATEGORY_NAME)) {
UnitValuePropertyInstance uvi = (UnitValuePropertyInstance) object;
Expand Down Expand Up @@ -181,18 +236,33 @@ private CategoryAssignment getCategoryAssignment(Object object) {
* @return image problem image or null image
*/
private Image getColumnImageForParameter(CategoryAssignment ca, int columnIndex) {
PropertyInstanceHelper piHelper = new PropertyInstanceHelper();
if (columnIndex == 0) {
Image problemImage = emip.getProblemImageForStructuralFeatureInEobject(ca, GeneralPackage.Literals.INAME__NAME);
if (problemImage != null) {
return problemImage;
} else {
PropertyInstanceHelper piHelper = new PropertyInstanceHelper();
return piHelper.isCalculated(ca) ? imageCalculated : super.getColumnImage(ca, columnIndex);
return super.getColumnImage(ca, columnIndex);
}
} else if (columnIndex == 1) {
APropertyInstance propertyInstance = ca.getPropertyInstances().get(0);

Image problemImage = mip.getProblemImageForEObject(propertyInstance);
return (problemImage != null) ? problemImage : null;
if (problemImage != null) {
return problemImage;
} else if (piHelper.isCalculated(ca)) {
return imageCalculated;
} else {
return imageFloat;
}
} else if (columnIndex == OVERRIDE_COLUMN) {
if (ca.getType().getFullQualifiedName().equals(Parameter.FULL_QUALIFIED_CATEGORY_NAME)) {
Parameter parameterBean = new Parameter(ca);
Boolean override = parameterBean.getDefaultValueBean().getTypeInstance().isOverride();
if (!piHelper.isCalculated(ca)) {
return (override) ? imageOverride : imageInherited;
}
}
}
return null;
}
Expand Down Expand Up @@ -222,15 +292,29 @@ private Image getColumnImageForSystemParameter(CategoryAssignment ca, int column
* @return image problem image or null image
*/
private Image getColumnImageForModeValue(CategoryAssignment ca, int columnIndex) {
CefModeHelper modeHelper = new CefModeHelper();
if (columnIndex == 0) {
APropertyInstance propertyInstance = ca.getPropertyInstances().get(1);
Image problemImage = mip.getProblemImageForEObject(propertyInstance);
return (problemImage != null) ? problemImage : super.getColumnImage(ca, columnIndex);
} else if (columnIndex == 1) {
APropertyInstance propertyInstance = ca.getPropertyInstances().get(0);
Image problemImage = mip.getProblemImageForEObject(propertyInstance);
return (problemImage != null) ? problemImage : null;
}
if (problemImage != null) {
return problemImage;
} else if (modeHelper.isValueCalculated(ca)) {
return imageCalculated;
} else {
return imageFloat;
}
} else if (columnIndex == OVERRIDE_COLUMN) {
Value valueBean = new Value(ca);
Boolean override = valueBean.getValueBean().getTypeInstance().isOverride()
|| valueBean.getModeBean().getTypeInstance().isOverride();
if (!modeHelper.isValueCalculated(ca)) {
return (override) ? imageOverride : imageInherited;
}
}
return null;
}

Expand All @@ -251,5 +335,25 @@ private Image getColumnImageForEquipmentParameter(CategoryAssignment ca, int col
}
return null;
}

@Override
public Color getForeground(Object object) {
boolean isCalculated = false;
CategoryAssignment ca = getCategoryAssignment(object);
PropertyInstanceHelper piHelper = new PropertyInstanceHelper();
CefModeHelper modeHelper = new CefModeHelper();
redirectNotification(ca, object);
if (ca.getType().getFullQualifiedName().equals(Value.FULL_QUALIFIED_CATEGORY_NAME)) {
isCalculated = modeHelper.isValueCalculated(ca);
} else {
isCalculated = piHelper.isCalculated(ca);
}

if (isCalculated) {
return COLOR_READ_ONLY;
}

return super.getForeground(object);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2008-2019 German Aerospace Center (DLR), Simulation and Software Technology, Germany.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package de.dlr.sc.virsat.model.extension.cefx.ui.snippet.tableimpl;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.swt.widgets.Composite;

import de.dlr.sc.virsat.model.dvlm.categories.CategoryAssignment;
import de.dlr.sc.virsat.model.dvlm.categories.propertyinstances.ComposedPropertyInstance;
import de.dlr.sc.virsat.model.extension.cefx.model.Parameter;
import de.dlr.sc.virsat.model.extension.cefx.model.Value;
import de.dlr.sc.virsat.model.extension.cefx.util.CefModeHelper;
import de.dlr.sc.virsat.uiengine.ui.cellEditor.emfattributes.EBooleanCellEditingSupport;

public class OverrideFlagCellEditingSupport extends EBooleanCellEditingSupport {

private CellEditor editor;
public static final String[] OVERRIDE_LITERALS = { "Inherited", "Override" };

public OverrideFlagCellEditingSupport(EditingDomain editingDomain, ColumnViewer viewer, EAttribute emfAttribute) {
super(editingDomain, viewer, emfAttribute);
this.editor = new ComboBoxCellEditor((Composite) viewer.getControl(), OVERRIDE_LITERALS);
}

@Override
protected Object getValue(Object element) {
if (element instanceof ComposedPropertyInstance) {
Parameter param = new Parameter(((ComposedPropertyInstance) element).getTypeInstance());
return super.getValue(param.getDefaultValueBean().getTypeInstance());
} else if (element instanceof CategoryAssignment) {
Value value = new Value((CategoryAssignment) element);
return super.getValue(value.getValueBean().getTypeInstance());
}
return super.getValue(element);
}

@Override
protected void setValue(Object element, Object userInputValue) {
if (element instanceof ComposedPropertyInstance) {
Parameter param = new Parameter(((ComposedPropertyInstance) element).getTypeInstance());
super.setValue(param.getDefaultValueBean().getTypeInstance(), userInputValue);
} else if (element instanceof CategoryAssignment) {
Value value = new Value((CategoryAssignment) element);
super.setValue(value.getValueBean().getTypeInstance(), userInputValue);
} else {
super.setValue(element, userInputValue);
}
}
@Override
protected boolean canEdit(Object element) {
if (element instanceof ComposedPropertyInstance) {
Parameter param = new Parameter(((ComposedPropertyInstance) element).getTypeInstance());
if (param.getDefaultValueBean().getIsCalculated()) {
return false;
}
return super.canEdit(param.getDefaultValueBean().getTypeInstance());
} else if (element instanceof CategoryAssignment
&& ((CategoryAssignment) element).getType().getFullQualifiedName().equals(Value.FULL_QUALIFIED_CATEGORY_NAME)) {
if (!(new CefModeHelper().isValueCalculated((CategoryAssignment) element))) {
return true;
}

}
return false;
}

@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}

}
Loading

0 comments on commit a98f49c

Please sign in to comment.