From f888af199b8266e6680230b0b8151c1c859ba0c3 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Fri, 19 Jan 2018 09:09:21 +0000 Subject: [PATCH] Eliminate support for multi-instance annotations, which was mostly unused and only complicated the code. refs 2964 --- .../ui/annotation/editingsupport/.ratings | 12 +- .../AnnotationEditingSupportBase.java | 14 +- .../CheckBoxEditingSupport.java | 4 +- .../ComboBoxEditingSupport.java | 16 +- .../editingsupport/EditingSupportFactory.java | 115 +++------- .../ElementEditingSupportBase.java | 2 +- .../MultiSelectionEditingSupport.java | 10 +- .../editingsupport/TextEditingSupport.java | 4 +- .../base/ui/annotation/labelprovider/.ratings | 7 +- .../AnnotationLabelProvider.java | 22 +- .../labelprovider/CheckBoxLabelProvider.java | 6 +- .../labelprovider/LabelProviderFactory.java | 43 +--- .../base/ui/annotation/view/generic/.ratings | 5 +- .../annotation/view/generic/ColumnHandle.java | 39 +--- .../view/generic/GenericAnnotationView.java | 50 +---- .../fortiss/tooling/base/annotation/.ratings | 2 +- .../base/annotation/AnnotationEntry.java | 77 ------- .../base/annotation/valueprovider/.ratings | 8 +- .../valueprovider/AnnotationInstSpec.java | 30 +-- .../DerivedAnnotationValueProviderBase.java | 135 +++-------- .../EStructuralFeatureValueProviderBase.java | 204 ++++++----------- .../IAnnotationValueProvider.java | 80 +------ .../valueprovider/ValueProviderBase.java | 209 +++++------------- .../org/fortiss/tooling/base/utils/.ratings | 2 +- .../tooling/base/utils/AnnotationUtils.java | 112 +++------- 25 files changed, 303 insertions(+), 905 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings index b36f90079..8c2b2dc7b 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings @@ -1,11 +1,11 @@ -AnnotationEditingSupportBase.java 7a16abe842cb44918d75395947bb6561e468ca03 GREEN -CheckBoxEditingSupport.java c7bc95da565bad53a125ff08982ea73ba06da3e5 GREEN -ComboBoxEditingSupport.java 1c778b6017f791339483606a31b72d0f8a39098c GREEN -EditingSupportFactory.java c72b4847ba219755178b785ea80f91295f259760 YELLOW +AnnotationEditingSupportBase.java 7e542e9d1084e929b798cf19de5c6b0e995e5922 YELLOW +CheckBoxEditingSupport.java 5ef3594428071da0c8df68202a101fda0fbc516c YELLOW +ComboBoxEditingSupport.java 8f2dfe75250de3a764c62ab73e21e217ece44d53 YELLOW +EditingSupportFactory.java b174a19f502d46f7e2ebefdc50437c6bdc007a97 YELLOW ElementCommentEditingSupport.java b7cbec5084aab81efc1da6b48647b172206f6256 GREEN ElementEditingSupportBase.java e04393748a0a0223b838fc59ef3c0e4f0960951b GREEN ElementNameEditingSupport.java 6393bb52ad1f7ff4823a3f0dd30128124b0e3347 GREEN LabelValueMapping.java 4493051db8444e8e2651802fe65603adf7bbd906 GREEN MultiSelectionCellEditor.java 115039c4ed80dcb984d90d98496eb70f81a78686 GREEN -MultiSelectionEditingSupport.java 54d8de719d543408aa914450d23bbd9192cd8b1c GREEN -TextEditingSupport.java 55b5927f6db702b030b44ba6bb1202493edb4064 GREEN +MultiSelectionEditingSupport.java 0f650b71943755333dd3a72d630ec7972084856e YELLOW +TextEditingSupport.java f4d21fc3dc480e9f9ad5f9b960805c7488123f5a YELLOW diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java index c0ac293e5..ef0033f37 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java @@ -40,15 +40,11 @@ public abstract class AnnotationEditingSupportBase extends EditingSupport { /** Specification class of this column. */ protected Class<? extends IAnnotatedSpecification> specClass; - /** Instance key to identify the corresponding instance of the annotation. */ - protected String instanceKey; - /** Constructs a new {@link AnnotationEditingSupportBase}. */ public AnnotationEditingSupportBase(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass, String instanceKey) { + Class<? extends IAnnotatedSpecification> specClass) { super(viewer); this.specClass = specClass; - this.instanceKey = instanceKey; } /** {@inheritDoc} */ @@ -56,7 +52,7 @@ public abstract class AnnotationEditingSupportBase extends EditingSupport { protected boolean canEdit(Object element) { if(element instanceof AnnotationEntry) { AnnotationEntry annotationEntry = (AnnotationEntry)element; - return annotationEntry.canEdit(specClass, instanceKey); + return annotationEntry.canEdit(specClass); } return true; @@ -64,7 +60,7 @@ public abstract class AnnotationEditingSupportBase extends EditingSupport { /** Actually gets the value from the {@link IAnnotatedSpecification}. */ protected Object doGetValue(AnnotationEntry annotationEntry) { - return annotationEntry.getSpecificationValue(specClass, instanceKey); + return annotationEntry.getSpecificationValue(specClass); } /** {@inheritDoc} */ @@ -78,12 +74,12 @@ public abstract class AnnotationEditingSupportBase extends EditingSupport { /** Actually sets a {@link String} value into a {@link IAnnotatedSpecification}. */ protected void doSetValue(AnnotationEntry annotationEntry, String value) throws Exception { - annotationEntry.setSpecificationValue(value, specClass, instanceKey); + annotationEntry.setSpecificationValue(value, specClass); } /** Actually sets a value into a {@link IAnnotatedSpecification}. */ protected void doSetValue(AnnotationEntry annotationEntry, Object value) throws Exception { - annotationEntry.setSpecificationValue(value, specClass, instanceKey); + annotationEntry.setSpecificationValue(value, specClass); } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java index 6ee3d2880..1d8d9dd44 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java @@ -35,8 +35,8 @@ public class CheckBoxEditingSupport extends AnnotationEditingSupportBase { /** Constructs a new {@link CheckBoxEditingSupport}. */ public CheckBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass, String instanceKey) { - super(viewer, specClass, instanceKey); + Class<? extends IAnnotatedSpecification> specClass) { + super(viewer, specClass); checkBoxEditor = new CheckboxCellEditor(((TableViewer)viewer).getTable()); } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java index 39c9405ba..57f901813 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java @@ -65,8 +65,8 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { * available choices which is prepared on demand in {@link #getCellEditor(Object)}. */ private ComboBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, String instanceKey, boolean isEditable) { - super(viewer, clazz, instanceKey); + Class<? extends IAnnotatedSpecification> clazz, boolean isEditable) { + super(viewer, clazz); this.isEditable = isEditable; @@ -83,15 +83,15 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { */ public ComboBoxEditingSupport(ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - String instanceKey, EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { + EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { // EENumns and EReferences are only of a set of possible choices, hence they are not // 'editable' // @CodeFormatterOff (cannot use local variables before explicit call of constructor) - this(viewer, clazz, instanceKey, + this(viewer, clazz, !(eStructuralFeatureDescriptor.getEType(specification) instanceof EEnum || eStructuralFeatureDescriptor.getEType(specification) instanceof EClass)); - // @CodeFormatterOff + // @CodeFormatterOn this.eStructuralFeatureDescriptor = eStructuralFeatureDescriptor; } @@ -100,10 +100,10 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { * {@link EStructuralFeature}-based input-choice. */ public ComboBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, String instanceKey, - Collection<String> stringInputChoice, boolean isEditable) { + Class<? extends IAnnotatedSpecification> clazz, Collection<String> stringInputChoice, + boolean isEditable) { - this(viewer, clazz, instanceKey, isEditable); + this(viewer, clazz, isEditable); this.stringInputChoice = stringInputChoice; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java index 66d37d1d4..dd1ad7608 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java @@ -17,7 +17,6 @@ package org.fortiss.tooling.base.ui.annotation.editingsupport; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -57,15 +56,14 @@ public class EditingSupportFactory { <T extends IDerivedAnnotation<?>, V extends DerivedAnnotationValueProviderBase<T>> EditingSupport createEditingSupport4DerivedAnnotationValueProviderBase(V valueProvider, ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, - T specification, String instanceKey) throws Exception { + T specification) throws Exception { - if(valueProvider.isDerivedKey(instanceKey) && !valueProvider.isEditableByUser()) { + if(!valueProvider.isEditableByUser()) { return null; } return createEditingSupport4EStructuralFeatureValueProviderBase( - (EStructuralFeatureValueProviderBase<T>)valueProvider, viewer, clazz, - specification, instanceKey); + (EStructuralFeatureValueProviderBase<T>)valueProvider, viewer, clazz, specification); } /** @@ -80,9 +78,6 @@ public class EditingSupportFactory { * Annotation type * @param specification * Annotation instance - * @param instanceKey - * Key identifying annotation instance - * * @return {@link EditingSupport} that is directly based on * {@link EStructuralFeatureValueProviderBase}. */ @@ -90,26 +85,24 @@ public class EditingSupportFactory { <T extends IAnnotatedSpecification, V extends EStructuralFeatureValueProviderBase<T>> EditingSupport createEditingSupport4EStructuralFeatureValueProviderBase( V valueProvider, ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, T specification, - String instanceKey) throws Exception { + Class<? extends IAnnotatedSpecification> clazz, T specification) + throws Exception { EStructuralFeature structuralFeature = - valueProvider.getEStructuralFeature(specification, instanceKey); + valueProvider.getEStructuralFeatureDescriptor() + .getEStructuralFeature(specification); - EClassifier eType; - try { - eType = structuralFeature.getEType(); - } catch(Exception e) { - eType = null; + if(structuralFeature == null) { + throw new Exception("EStructuralValueProvider: feature has not been set."); } - if(structuralFeature.getUpperBound() == 0) { throw new Exception( "EStructuralValueProvider: feature multiplicity == 0 is not supported."); } + EClassifier eType = structuralFeature.getEType(); EStructuralFeatureDescriptor eStructuralFeatureDescriptor = - valueProvider.getEStructuralFeatureDescriptor(instanceKey); + valueProvider.getEStructuralFeatureDescriptor(); if(structuralFeature.getUpperBound() == 1) { EReferenceScope eReferenceScope = eStructuralFeatureDescriptor.getEReferenceScope(); @@ -117,14 +110,14 @@ public class EditingSupportFactory { if(isSimpleType || ((eType instanceof EClass) && (eReferenceScope == null))) { return createEditingSupport4ValueProviderBase((ValueProviderBase<T>)valueProvider, - viewer, clazz, specification, instanceKey); + viewer, clazz, specification); } - return new ComboBoxEditingSupport(viewer, clazz, specification, instanceKey, + return new ComboBoxEditingSupport(viewer, clazz, specification, eStructuralFeatureDescriptor); } if(eType instanceof EClass || eType instanceof EEnum) { - return new MultiSelectionEditingSupport(viewer, clazz, specification, instanceKey, + return new MultiSelectionEditingSupport(viewer, clazz, specification, eStructuralFeatureDescriptor); } @@ -134,7 +127,7 @@ public class EditingSupportFactory { /** * Helper method for - * {@link #createEditingSupport4ValueProviderBase(ValueProviderBase, ColumnViewer, Class, IAnnotatedSpecification, String)} + * {@link #createEditingSupport4ValueProviderBase(ValueProviderBase, ColumnViewer, Class, IAnnotatedSpecification)} * that initialized the current input map of the value provider. * * @param valueProvider @@ -143,26 +136,21 @@ public class EditingSupportFactory { * {@link ColumnViewer} used to display annotation * @param clazz * Annotation type - * @param instanceKey - * Key identifying annotation instance */ @SuppressWarnings("unchecked") private static <T extends IAnnotatedSpecification, V extends ValueProviderBase<T>> void initializeInputChoice(V valueProvider, ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, String instanceKey) - throws Exception { + Class<? extends IAnnotatedSpecification> clazz) throws Exception { // Input choice is not set, or it is restricted to concrete set of values // (use SingleEnumAttributeValueProviderBase for EEnum types!)s - List<String> fixedInputChoice = valueProvider.getFixedInputChoiceMap().get(instanceKey); - Map<String, Collection<String>> currentInputChoiceMap = - valueProvider.getCurrentInputChoiceMap(); + List<String> fixedInputChoice = valueProvider.getFixedInputChoice(); if(fixedInputChoice == null || !fixedInputChoice.isEmpty()) { - currentInputChoiceMap.put(instanceKey, fixedInputChoice); + valueProvider.setCurrentInputChoice(fixedInputChoice); } else { Object viewerInput = viewer.getInput(); if(!(viewerInput instanceof Set<?>) || ((Set<?>)viewerInput).isEmpty() || !(((Set<?>)viewerInput).iterator().next() instanceof AnnotationEntry)) { - currentInputChoiceMap.put(instanceKey, null); + valueProvider.setCurrentInputChoice(null); } else { AnnotationEntry annotationEntry = @@ -180,8 +168,7 @@ public class EditingSupportFactory { choices.add(annotationValue.toString()); } } - - currentInputChoiceMap.put(instanceKey, choices); + valueProvider.setCurrentInputChoice(choices); } } } @@ -198,43 +185,36 @@ public class EditingSupportFactory { * Annotation type * @param specification * Annotation instance - * @param instanceKey - * Key identifying annotation instance - * * @return {@link EditingSupport} for value providers that are directly based on * {@link ValueProviderBase}. */ private static <T extends IAnnotatedSpecification, V extends ValueProviderBase<T>> EditingSupport createEditingSupport4ValueProviderBase(V valueProvider, ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, - T specification, String instanceKey) throws Exception { + T specification) throws Exception { try { - initializeInputChoice(valueProvider, viewer, clazz, instanceKey); + initializeInputChoice(valueProvider, viewer, clazz); } catch(Exception e) { // Use standard text editor as fall-back - valueProvider.setCurrentInputChoiceMap(null); + valueProvider.setCurrentInputChoice(null); } // Input is not restricted -> free editing in text cell - Collection<String> currentInputChoice = - valueProvider.getCurrentInputChoiceMap().get(instanceKey); + Collection<String> currentInputChoice = valueProvider.getCurrentInputChoice(); if(currentInputChoice == null) { - if(valueProvider.getAnnotationValue(specification, instanceKey) instanceof Boolean) { - return new CheckBoxEditingSupport(viewer, clazz, instanceKey); + if(valueProvider.getAnnotationValue(specification) instanceof Boolean) { + return new CheckBoxEditingSupport(viewer, clazz); } - return new TextEditingSupport(viewer, clazz, instanceKey); + return new TextEditingSupport(viewer, clazz); } - // Multiple instances are not supported (yet) for input to be edited in ComboBoxes - assert (instanceKey == null); - // Input is restricted to concrete set of values // (use SingleEnumAttributeValueProviderBase for EEnum types!) - List<String> fixedInputChoice = valueProvider.getFixedInputChoiceMap().get(instanceKey); - return new ComboBoxEditingSupport(viewer, clazz, instanceKey, currentInputChoice, + List<String> fixedInputChoice = valueProvider.getFixedInputChoice(); + return new ComboBoxEditingSupport(viewer, clazz, currentInputChoice, fixedInputChoice.isEmpty()); } @@ -249,56 +229,27 @@ public class EditingSupportFactory { * Annotation type * @param specification * Annotation instance - * @param instanceKey - * Key identifying annotation instance - * * @return {@link EditingSupport} for the given {@link IAnnotatedSpecification}. */ @SuppressWarnings({"rawtypes", "unchecked"}) public static <T extends IAnnotatedSpecification> EditingSupport createEditingSupport( IAnnotationValueProvider<T> valueProvider, ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, T specification, String instanceKey) - throws Exception { + Class<? extends IAnnotatedSpecification> clazz, T specification) throws Exception { if(valueProvider instanceof DerivedAnnotationValueProviderBase<?>) { return createEditingSupport4DerivedAnnotationValueProviderBase( (DerivedAnnotationValueProviderBase)valueProvider, viewer, clazz, - (IDerivedAnnotation)specification, instanceKey); + (IDerivedAnnotation)specification); } else if(valueProvider instanceof EStructuralFeatureValueProviderBase<?>) { return createEditingSupport4EStructuralFeatureValueProviderBase( (EStructuralFeatureValueProviderBase<T>)valueProvider, viewer, clazz, - specification, instanceKey); + specification); } if(valueProvider instanceof ValueProviderBase<?>) { return createEditingSupport4ValueProviderBase((ValueProviderBase<T>)valueProvider, - viewer, clazz, specification, instanceKey); + viewer, clazz, specification); } return null; } - - /** - * Creates the editing support without referring to the optional {@code instanceKey} (see - * {@link #createEditingSupport(IAnnotationValueProvider, ColumnViewer, Class, IAnnotatedSpecification, String)} - * . - * - * - * @param valueProvider - * Annotation's {@link IAnnotationValueProvider} - * @param viewer - * {@link ColumnViewer} used to display annotation - * @param clazz - * Annotation type - * @param specification - * Annotation instance - * - * @return {@link EditingSupport} without referring to the optional {@code instanceKey}. - */ - public static <T extends IAnnotatedSpecification> EditingSupport createEditingSupport( - IAnnotationValueProvider<T> valueProvider, ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, T specification) throws Exception { - - return createEditingSupport(valueProvider, viewer, clazz, specification, - IAnnotationValueProvider.DEFAULT_KEY); - } } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java index c518b29ad..a6360f99e 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java @@ -32,7 +32,7 @@ public class ElementEditingSupportBase extends TextEditingSupport { public ElementEditingSupportBase(ColumnViewer viewer) { // Specification class is not needed, since the name is stored // directly in the model (hence pass {@code null}). - super(viewer, null, null); + super(viewer, null); } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiSelectionEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiSelectionEditingSupport.java index 6edc1f555..ca89f1c69 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiSelectionEditingSupport.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiSelectionEditingSupport.java @@ -50,8 +50,8 @@ public class MultiSelectionEditingSupport extends AnnotationEditingSupportBase { /** Constructs a new {@link MultiSelectionEditingSupport}. */ public MultiSelectionEditingSupport(ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - String instanceKey, EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { - super(viewer, clazz, instanceKey); + EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { + super(viewer, clazz); this.specification = specification; this.eStructuralFeatureDescriptor = eStructuralFeatureDescriptor; @@ -70,7 +70,7 @@ public class MultiSelectionEditingSupport extends AnnotationEditingSupportBase { // Only can return a cell editor if the value of the underlying IAnnotatedSpecification is a // collection - Object value = entry.getSpecificationValue(specClass, instanceKey); + Object value = entry.getSpecificationValue(specClass); if(!(value instanceof Collection<?>)) { return null; } @@ -114,7 +114,7 @@ public class MultiSelectionEditingSupport extends AnnotationEditingSupportBase { if(element instanceof AnnotationEntry) { AnnotationEntry entry = (AnnotationEntry)element; - Object value = entry.getSpecificationValue(specClass, instanceKey); + Object value = entry.getSpecificationValue(specClass); if(value instanceof Collection<?>) { StringBuffer valueCollectionString = new StringBuffer(); @@ -150,7 +150,7 @@ public class MultiSelectionEditingSupport extends AnnotationEditingSupportBase { @Override public void run() { try { - entry.setSpecificationValue(value, specClass, instanceKey); + entry.setSpecificationValue(value, specClass); } catch(Exception e) { return; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java index 96d567fcc..e761ea393 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java @@ -38,8 +38,8 @@ public class TextEditingSupport extends AnnotationEditingSupportBase { /** Constructs a new {@link TextEditingSupport}. */ public TextEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass, String instanceKey) { - super(viewer, specClass, instanceKey); + Class<? extends IAnnotatedSpecification> specClass) { + super(viewer, specClass); cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE); } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings index 7e03600a9..43b261e14 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings @@ -1,8 +1,7 @@ - -AnnotationLabelProvider.java 7204dd4a921edc2859b94a10ff5476a3d4dda130 GREEN -CheckBoxLabelProvider.java 60ab25427dbf219fe675f434c943eacb1f9f8e58 YELLOW +AnnotationLabelProvider.java a592cde4a9ae83a832969a0e3379223aaaa793d2 YELLOW +CheckBoxLabelProvider.java fc68dc493591ebd7427f029b715de61f7696a2cb YELLOW ElementCommentLabelProvider.java b1b2fb39a2ec33bf5e1763186cd44634654f9a3a GREEN ElementLabelProviderBase.java 83b5e374fdd3357dffd8bd357b8db432825963d4 GREEN ElementNameLabelProvider.java 6b12d3c6841c261a1cf6e8501a3edfd6f83bfe9e GREEN LabelProviderBase.java a5f27ad40b1ac427418bd8a57a14a0779281df87 GREEN -LabelProviderFactory.java 0d74201d868963feaf492b3b4cd6c88a3e270a4b GREEN +LabelProviderFactory.java fc14fb327dc642d5988f693844a632068cc9c7bb YELLOW diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java index b92531c64..ddebfc2bf 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java @@ -45,9 +45,6 @@ public class AnnotationLabelProvider extends LabelProviderBase { /** Type of annotation that is displayed by this {@link AnnotationLabelProvider}. */ protected Class<? extends IAnnotatedSpecification> clazz; - /** Key identifying the annotation instance to be displayed. */ - protected String instanceKey; - /** * {@link EditingSupport} of the column to for which this {@link AnnotationLabelProvider} * provides the label. @@ -61,17 +58,14 @@ public class AnnotationLabelProvider extends LabelProviderBase { * Type of annotation that is displayed by this {@link AnnotationLabelProvider}. * @param viewPart * view required to retrieve the selected elements - * @param instanceKey - * Key identifying the annotation instance to be displayed. * @param editingSupport * {@link EditingSupport} of column for which the new {@link AnnotationLabelProvider} * should provided the label. */ public AnnotationLabelProvider(Class<? extends IAnnotatedSpecification> clazz, - IAnnotationViewPart viewPart, String instanceKey, EditingSupport editingSupport) { + IAnnotationViewPart viewPart, EditingSupport editingSupport) { super(viewPart); this.clazz = clazz; - this.instanceKey = instanceKey; this.editingSupport = editingSupport; } @@ -83,7 +77,7 @@ public class AnnotationLabelProvider extends LabelProviderBase { Object value = null; try { - value = annotationEntry.getSpecificationValue(clazz, instanceKey); + value = annotationEntry.getSpecificationValue(clazz); } catch(Exception e) { return ""; } @@ -108,9 +102,9 @@ public class AnnotationLabelProvider extends LabelProviderBase { return super.getBackground(element); } - if(!annotationEntry.canEdit(clazz, instanceKey)) { + if(!annotationEntry.canEdit(clazz)) { if(IDerivedAnnotation.class.isAssignableFrom(clazz) && - annotationEntry.getSpecificationValue(clazz, instanceKey) != null) { + annotationEntry.getSpecificationValue(clazz) != null) { return DERIVED_ANNOTATION_BACKGROUND_COLOR; } return READ_ONLY_ANNOTATION_BACKGROUND_COLOR; @@ -126,12 +120,4 @@ public class AnnotationLabelProvider extends LabelProviderBase { public Class<? extends IAnnotatedSpecification> getAnnotationType() { return clazz; } - - /** - * Returns the instance key (if any exists) of the {@link IAnnotatedSpecification} that is - * handled by {@code this} {@link AnnotationLabelProvider}. - */ - public String getInstanceKey() { - return instanceKey; - } } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java index e763cbbde..44d1e8394 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java @@ -39,8 +39,8 @@ public class CheckBoxLabelProvider extends AnnotationLabelProvider { /** Constructor. */ public CheckBoxLabelProvider(Class<? extends IAnnotatedSpecification> clazz, - IAnnotationViewPart viewPart, String instanceKey, EditingSupport editingSupport) { - super(clazz, viewPart, instanceKey, editingSupport); + IAnnotationViewPart viewPart, EditingSupport editingSupport) { + super(clazz, viewPart, editingSupport); } /** {@inheritDoc} */ @@ -70,7 +70,7 @@ public class CheckBoxLabelProvider extends AnnotationLabelProvider { Object value = null; try { - value = annotationEntry.getSpecificationValue(clazz, instanceKey); + value = annotationEntry.getSpecificationValue(clazz); } catch(Exception e) { return false; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java index c638780bc..45e2d0ad0 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java @@ -46,43 +46,6 @@ public class LabelProviderFactory { * Annotation type * @param specification * Annotation instance - * @param instanceKey - * Key identifying annotation instance - * - * @return {@link ColumnLabelProvider} for the given {@link IAnnotatedSpecification}. - */ - public static <T extends IAnnotatedSpecification> ColumnLabelProvider createLabelProvider( - IAnnotationValueProvider<T> valueProvider, IAnnotationViewPart viewPart, - ColumnViewer columnViewer, EditingSupport editingSupport, - Class<? extends IAnnotatedSpecification> clazz, T specification, String instanceKey) - throws Exception { - - if(valueProvider.getAnnotationValue(specification, instanceKey) instanceof Boolean) { - return new CheckBoxLabelProvider(clazz, viewPart, instanceKey, - editingSupport); - } - return new AnnotationLabelProvider(clazz, viewPart, instanceKey, editingSupport); - } - - /** - * Creates the {@link ColumnLabelProvider} without referring to the optional {@code instanceKey} - * (see - * {@link #createLabelProvider(IAnnotationValueProvider, IAnnotationViewPart, ColumnViewer, EditingSupport, Class, IAnnotatedSpecification, String)} - * . - * - * @param valueProvider - * Annotation's {@link IAnnotationValueProvider} - * @param viewPart - * {@link IAnnotationViewPart} in which the annotation will be displayed. - * @param columnViewer - * {@link ColumnViewer} used to display annotation - * @param editingSupport - * {@link EditingSupport} that has been provided for the annotation. - * @param clazz - * Annotation type - * @param specification - * Annotation instance - * * @return {@link ColumnLabelProvider} for the given {@link IAnnotatedSpecification}. */ public static <T extends IAnnotatedSpecification> ColumnLabelProvider createLabelProvider( @@ -90,7 +53,9 @@ public class LabelProviderFactory { ColumnViewer columnViewer, EditingSupport editingSupport, Class<? extends IAnnotatedSpecification> clazz, T specification) throws Exception { - return createLabelProvider(valueProvider, viewPart, columnViewer, editingSupport, clazz, - specification, IAnnotationValueProvider.DEFAULT_KEY); + if(valueProvider.getAnnotationValue(specification) instanceof Boolean) { + return new CheckBoxLabelProvider(clazz, viewPart, editingSupport); + } + return new AnnotationLabelProvider(clazz, viewPart, editingSupport); } } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings index efb8d9074..58c359bc9 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings @@ -1,4 +1,3 @@ -ColumnHandle.java 7fac3dbdd7da328052cbee3fa180ac78f51987e8 YELLOW -CreateAnnotationInstanceColumn.java f0e630afc37340c71d1afdf037b2df3c0f397a58 GREEN -GenericAnnotationView.java 6b1bcf8e6a561aa586463cf6da9da8b2624a7c71 YELLOW +ColumnHandle.java 66d0399a03dec18a67df08f19746a6a7c08a5c98 YELLOW +GenericAnnotationView.java 68a0c93c3863c172da3dfbee32de53349c510f5f YELLOW HierarchicalNameViewerComparator.java edf1d012a3d18860d2ef7f9e07baf46cdfeec381 GREEN diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java index bfe2dd9b1..465ff82a8 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java @@ -28,17 +28,11 @@ import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; */ public class ColumnHandle<T extends IAnnotatedSpecification> extends AnnotationInstSpec<T> implements Comparable<ColumnHandle<T>> { - /** - * Character used to separate the annotation name from the instance name for multi-instance - * annotations. - */ - private final static String MULTIINSTANCE_NAME_SEPARATOR = ":"; /** Constructs a new {@link ColumnHandle}. */ @SuppressWarnings("unchecked") - public ColumnHandle(AnnotationEntry entry, T annotatedSpecification, String instanceKey) { - super(entry, (Class<T>)annotatedSpecification.getClass(), annotatedSpecification, - instanceKey); + public ColumnHandle(AnnotationEntry entry, T annotatedSpecification) { + super(entry, (Class<T>)annotatedSpecification.getClass(), annotatedSpecification); } /** @@ -50,12 +44,7 @@ public class ColumnHandle<T extends IAnnotatedSpecification> extends AnnotationI String specName = getEntry().getSpecificationAnnotationName(getAnnotatedSpecification().getClass()); - if(getInstanceKey() != null) { - if(!specName.isEmpty()) { - specName += MULTIINSTANCE_NAME_SEPARATOR + " "; - } - specName += getInstanceKey(); - } else if(specName == null || specName.isEmpty()) { + if(specName == null || specName.isEmpty()) { specName = "<Unnamed Annotation>"; } return specName; @@ -65,29 +54,7 @@ public class ColumnHandle<T extends IAnnotatedSpecification> extends AnnotationI @Override public int compareTo(ColumnHandle<T> other) { String columnName = getColumnName(); - String annotationName; - - int columnNameSeparatorIndex = columnName.indexOf(MULTIINSTANCE_NAME_SEPARATOR); - if(columnNameSeparatorIndex != -1) { - annotationName = columnName.substring(0, columnNameSeparatorIndex); - } else { - annotationName = columnName; - } - String otherColumnName = other.getColumnName(); - String otherAnnotationName; - int otherColumnNameSeparatorIndex = otherColumnName.indexOf(MULTIINSTANCE_NAME_SEPARATOR); - if(otherColumnNameSeparatorIndex != -1) { - otherAnnotationName = otherColumnName.substring(0, otherColumnNameSeparatorIndex); - } else { - otherAnnotationName = otherColumnName; - } - - // Place "create" columns (label: "<specification name>") after their instances - // (which are labeled "<specification name>: <instance name>"). - if(annotationName.equals(otherAnnotationName)) { - return 0; - } // Sort alphabetically by specification column label return columnName.compareTo(otherColumnName); diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java index 211824281..a601b634e 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java @@ -239,28 +239,11 @@ public class GenericAnnotationView extends AnnotationViewPartBase { // Aggregate required columns. Column order is defined by ColumnHandle.compareTo(). for(AnnotationEntry entry : annotationEntries) { for(IAnnotatedSpecification spec : entry.getSpecificationsList()) { - // Create new column for each instance of the current multi-instance annotation - Class<? extends IAnnotatedSpecification> specClass = spec.getClass(); - boolean isSingleInstanceAnnotation = entry.getInstanceKeys(specClass).isEmpty(); - if(!isSingleInstanceAnnotation) { - - for(String instanceKey : entry.getInstanceKeys(specClass)) { - ColumnHandle<IAnnotatedSpecification> columnHandle = - new ColumnHandle<IAnnotatedSpecification>(entry, spec, - instanceKey); - if(annotationFilter.passesColumnFilter(columnHandle)) { - sortedColumnHandles.add(columnHandle); - } - } - } else { - - // Create a new column for ordinary (single-instance) annotations - ColumnHandle<IAnnotatedSpecification> columnHandle = - new ColumnHandle<IAnnotatedSpecification>(entry, spec, null); + ColumnHandle<IAnnotatedSpecification> columnHandle = + new ColumnHandle<IAnnotatedSpecification>(entry, spec); - if(annotationFilter.passesColumnFilter(columnHandle)) { - sortedColumnHandles.add(columnHandle); - } + if(annotationFilter.passesColumnFilter(columnHandle)) { + sortedColumnHandles.add(columnHandle); } } } @@ -416,11 +399,9 @@ public class GenericAnnotationView extends AnnotationViewPartBase { @SuppressWarnings("unchecked") Class<T> annotationType = (Class<T>)((AnnotationLabelProvider)labelProv).getAnnotationType(); T spec = selEntry.getSpecification(annotationType); - String instanceKey = ((AnnotationLabelProvider)labelProv).getInstanceKey(); AnnotationInstSpec<T> instSpec = - new AnnotationInstSpec<T>(selEntry, annotationType, spec, - instanceKey); + new AnnotationInstSpec<T>(selEntry, annotationType, spec); // By Construction of the map, we can ensure that this cast will always be // valid. @SuppressWarnings("unchecked") IAnnotationValueProvider<T> valProvider = @@ -431,7 +412,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { // annotation. // - Editable annotations (non-derived and no partially non-derived // annotations). - if(spec != null && valProvider.canEdit(spec, instanceKey)) { + if(spec != null && valProvider.canEdit(spec)) { addContextMenuEntries(contextMenu, valProvider, instSpec); } } @@ -561,15 +542,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase { for(Pair<AnnotationActionEntry, BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>>> ctxMenuEntry : valueProvider .getContextMenuEntries(specification)) { - String instanceKey = ctxMenuEntry.getFirst().getInstanceKey(); - if(instanceKey == null || - ctxMenuEntry.getFirst().getInstanceKey() - .equals(annotationClass.getInstanceKey())) { - MenuItem mItem = new MenuItem(contextMenu, SWT.None); - mItem.setText(ctxMenuEntry.getFirst().getName()); - addContextMenuEntryListener(mItem, ctxMenuEntry.getFirst(), - ctxMenuEntry.getSecond(), annotationClass, annotationEntriesMatchingFilter); - } + MenuItem mItem = new MenuItem(contextMenu, SWT.None); + mItem.setText(ctxMenuEntry.getFirst().getName()); + addContextMenuEntryListener(mItem, ctxMenuEntry.getFirst(), ctxMenuEntry.getSecond(), + annotationClass, annotationEntriesMatchingFilter); } } @@ -744,15 +720,13 @@ public class GenericAnnotationView extends AnnotationViewPartBase { IAnnotationValueProvider<IAnnotatedSpecification> valueProvider = entry.getAnnotationValueProvider(annotationClass); T specification = entry.getSpecification(annotationClass); - String instanceKey = columnHandle.getInstanceKey(); EditingSupport editingSupport = - createEditingSupport(valueProvider, tableViewer, annotationClass, specification, - instanceKey); + createEditingSupport(valueProvider, tableViewer, annotationClass, specification); ColumnLabelProvider columnLabelProvider = createLabelProvider(valueProvider, this, tableViewer, editingSupport, - annotationClass, specification, instanceKey); + annotationClass, specification); column.setEditingSupport(editingSupport); column.setLabelProvider(columnLabelProvider); diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/.ratings b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/.ratings index 72b6497af..9d9077240 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/.ratings +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/.ratings @@ -1,3 +1,3 @@ -AnnotationEntry.java d3405f0bbc26452812b0bc65043291fdac805287 YELLOW +AnnotationEntry.java f0e6d6f906fb94eae8e7f41a70b2b3d683d72e79 YELLOW AnnotationValueService.java 8e999ff1c54a15018f19117900822d2a749360e1 GREEN IAnnotationValueService.java ab22e1bf3e021f5f897d4d5a20e5fc51e084c734 GREEN diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java index ef468a265..60569a97d 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java @@ -15,10 +15,7 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.annotation; -import static java.util.Collections.emptyList; - import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -150,36 +147,6 @@ public final class AnnotationEntry { return false; } - /** Predicate if the given annotation can be edited for the given {@code instanceKey}. */ - public boolean canEdit(Class<? extends IAnnotatedSpecification> clazz, String instanceKey) { - IAnnotatedSpecification specification = getSpecification(clazz); - - if(isOperationEnabled(specification)) { - return getAnnotationValueProvider(clazz).canEdit(specification, instanceKey); - } - - // Invalid specifications cannot be edited - return false; - } - - /** Returns the annotation value. */ - public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz, - String instanceKey) { - - IAnnotatedSpecification specification = getSpecification(clazz); - - if(isOperationEnabled(specification)) { - try { - return getAnnotationValueProvider(clazz).getAnnotationValue(specification, - instanceKey); - } catch(Exception e) { - // Ignore exception - } - } - - return null; - } - /** * Returns the annotation value for a specific instance for an annotation with multi-value * support. @@ -199,35 +166,6 @@ public final class AnnotationEntry { return null; } - /** Sets a new value for the given specification {@code clazz}. */ - public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz, - String instanceKey) throws Exception { - - IAnnotatedSpecification specification = getSpecification(clazz); - - if(isOperationEnabled(specification)) { - getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey); - } else { - raiseCouldNotFindAnnotationValueProviderException(clazz); - } - } - - /** - * Sets a new value for the given specification {@code clazz} from a {@link String} - * representation. - */ - public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz, - String instanceKey) throws Exception { - - IAnnotatedSpecification specification = getSpecification(clazz); - - if(isOperationEnabled(specification)) { - getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey); - } else { - raiseCouldNotFindAnnotationValueProviderException(clazz); - } - } - /** Sets a new value for the given specification {@code clazz}. */ public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz) throws Exception { @@ -256,21 +194,6 @@ public final class AnnotationEntry { } } - /** - * Returns the instance keys supported by the respective {@link IAnnotationValueProvider}. - * {@link IAnnotationValueProvider}s (defined a static {@link List}). - */ - public Collection<String> getInstanceKeys(Class<? extends IAnnotatedSpecification> clazz) { - - IAnnotatedSpecification specification = getSpecification(clazz); - - if(isOperationEnabled(specification)) { - return getAnnotationValueProvider(clazz).getInstanceKeys(specification); - } - - return emptyList(); - } - /** Returns {@link #modelElement}. */ public IModelElement getModelElement() { return modelElement; diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings index 1b476cd92..92ed26a1c 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings @@ -1,6 +1,6 @@ -AnnotationInstSpec.java 86eaeb6f2f5b8d4a8322de69ff5196101b811b0a GREEN -DerivedAnnotationValueProviderBase.java 79e0a62f9cafb2cf8eebb3af7b9597cab8b820bf GREEN +AnnotationInstSpec.java 3b4dc57e844b75a549ef68acd327613a259dad80 RED +DerivedAnnotationValueProviderBase.java ae12ab7e386cc53a6a66dfc331ba43549b864b93 YELLOW EStructuralFeatureDescriptor.java b4093c8997472d0ab63a69c1d025d9aeb9b4f294 GREEN -EStructuralFeatureValueProviderBase.java c09e93e99816d02176fe9ee6343269ac20883f30 GREEN -IAnnotationValueProvider.java 40effc71478aa1429dfce90ac8ed6e1e462d0044 YELLOW +EStructuralFeatureValueProviderBase.java 5634d4f0fea682bddb5a93234963278784a06691 YELLOW +IAnnotationValueProvider.java 2d7b8ceff3ed83e7b5d2973bfa0632b9ff501d92 YELLOW ValueProviderBase.java 3138017b6c19933551b5e46033107df5ad954352 YELLOW diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/AnnotationInstSpec.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/AnnotationInstSpec.java index 24670c5b1..80f042ce2 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/AnnotationInstSpec.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/AnnotationInstSpec.java @@ -19,8 +19,8 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; /** - * Container class to uniquely specify an {@link IAnnotatedSpecification} including its instanceKey - * of multi-valued {@link IAnnotatedSpecification}s. + * Container class to uniquely specify an {@link IAnnotatedSpecification}, linking it with its + * {@link AnnotationEntry}. * * @author diewald */ @@ -31,6 +31,7 @@ public class AnnotationInstSpec<T extends IAnnotatedSpecification> { */ private AnnotationEntry entry; + // TODO: Check if this can be removed in favor of annotatedSpecification.getClass() /** * {@link IAnnotatedSpecification} from {@code entry} to be displayed in the column * represented by this {@link AnnotationInstSpec}. @@ -43,19 +44,12 @@ public class AnnotationInstSpec<T extends IAnnotatedSpecification> { */ private IAnnotatedSpecification annotatedSpecification; - /** - * Instance key identifying the particular instance of an {@link IAnnotatedSpecification} from - * {@code entry} to be displayed in the column represented by this {@link AnnotationInstSpec}. - */ - private String instanceKey; - /** Constructor. */ public AnnotationInstSpec(AnnotationEntry entry, Class<T> annotatedSpecificationClass, - T annotatedSpecification, String instanceKey) { + T annotatedSpecification) { this.entry = entry; this.annotatedSpecificationClass = annotatedSpecificationClass; this.annotatedSpecification = annotatedSpecification; - this.instanceKey = instanceKey; } /** @@ -82,19 +76,10 @@ public class AnnotationInstSpec<T extends IAnnotatedSpecification> { return annotatedSpecification; } - /** - * Returns the instance key identifying the particular instance of an - * {@link IAnnotatedSpecification} from {@code entry} to be displayed in the column - * represented by this {@link AnnotationInstSpec}. - */ - public String getInstanceKey() { - return instanceKey; - } - /** * <p> - * The hashcode of the {@link AnnotationInstSpec} is ONLY based on the annotation type and the - * instance key to represent one particular annotation instance type. Nevertheless, the + * The hashcode of the {@link AnnotationInstSpec} is ONLY based on the annotation type to + * represent one particular annotation instance type. Nevertheless, the * {@link AnnotationInstSpec} also carries references to the {@link AnnotationEntry} and the * {@link IAnnotatedSpecification} instances to allow a backtracking to the originating * elements. @@ -103,8 +88,7 @@ public class AnnotationInstSpec<T extends IAnnotatedSpecification> { */ @Override public int hashCode() { - return annotatedSpecificationClass.hashCode() + - (instanceKey != null ? instanceKey.hashCode() : 0); + return annotatedSpecificationClass.hashCode(); } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java index dfb09a60d..7d7e00233 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java @@ -15,15 +15,10 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.annotation.valueprovider; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.EReference; +import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor.EReferenceScope; import org.fortiss.tooling.base.model.element.IDerivedAnnotation; /** @@ -35,91 +30,44 @@ import org.fortiss.tooling.base.model.element.IDerivedAnnotation; public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnotation<?>> extends EStructuralFeatureValueProviderBase<T> { - /** Key representing the derived / calculated value. */ - private String derivedKey; - /** Flag indicating whether the derived value shall be editable by the user. */ - private boolean isEditableByUser = false; + private boolean isEditableByUser; - /** List of all supported instance keys. */ - private Set<String> keys = new LinkedHashSet<>(); + /** Constructor. */ + public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass, + EAttribute eAttribute, boolean isEditableByUser) { - /** - * Constructs a {@link IAnnotationValueProvider} for a pure derived annotation (i.e., an - * {@link IDerivedAnnotation} that does not contain any additional {@link EStructuralFeature}s). - */ - public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass) { - super(annotatedSpecificationEClass); - handlesMultipleEstructuralFeatures = false; - derivedKey = DEFAULT_KEY; - keys.add(DEFAULT_KEY); + super(annotatedSpecificationEClass, new EStructuralFeatureDescriptor(eAttribute)); + this.isEditableByUser = isEditableByUser; } - /** - * Constructs a {@link IAnnotationValueProvider} for a pure derived annotations (i.e., an - * {@link IDerivedAnnotation} that does not contain any additional {@link EStructuralFeature}s). - */ + /** Constructor. */ public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass, - boolean isEditableByUser) { - this(annotatedSpecificationEClass); + EReference eReference, EReferenceScope eReferenceScope, boolean isEditableByUser) { + + super(annotatedSpecificationEClass, new EStructuralFeatureDescriptor(eReference, + eReferenceScope)); this.isEditableByUser = isEditableByUser; } - /** - * Constructs a {@link IAnnotationValueProvider} for a derived annotations (i.e., based on an - * {@link IDerivedAnnotation}) that contains additional {@link EStructuralFeature}s). - * - * @param annotatedSpecificationEClass - * {@link EClass} implementing the annotation - * @param structuralFeatureDescriptorMap - * map: instance key -> {@link EStructuralFeatureDescriptor}s - * @param derivedKey - * key representing the derived / calculated value (must not be contained in - * structuralFeatureMap). - */ + /** Constructor. */ public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass, - Map<String, EStructuralFeatureDescriptor> structuralFeatureDescriptorMap, - String derivedKey) { - super(annotatedSpecificationEClass, structuralFeatureDescriptorMap); + EAttribute eAttribute) { - this.derivedKey = derivedKey; - keys.addAll(structuralFeatureDescriptorMap.keySet()); - keys.add(derivedKey); + this(annotatedSpecificationEClass, eAttribute, false); } - /** - * Constructs a {@link IAnnotationValueProvider} for a derived annotations (i.e., based on an - * {@link IDerivedAnnotation}) that contains additional {@link EStructuralFeature}s. - * - * @param annotatedSpecificationEClass - * {@link EClass} implementing the annotation - * @param structuralFeatureDescriptorMap - * map: instance key -> {@link EStructuralFeatureDescriptor}s - * @param derivedKey - * Key representing the derived / calculated value (must be named after the - * {@link EAttribute} which shall hold the values entered by the user iff the derived - * value shall be editable). - * @param derivedValueIsEditable - * Flag, indicating whether the derived value shall be (in principal) editable by the - * user. - */ + /** Constructor. */ public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass, - Map<String, EStructuralFeatureDescriptor> structuralFeatureDescriptorMap, - String derivedKey, boolean derivedValueIsEditable) { - super(annotatedSpecificationEClass, structuralFeatureDescriptorMap); - - this.derivedKey = derivedKey; - this.isEditableByUser = derivedValueIsEditable; - keys.addAll(structuralFeatureDescriptorMap.keySet()); - keys.add(derivedKey); + EReference eReference, EReferenceScope eReferenceScope) { + + this(annotatedSpecificationEClass, eReference, eReferenceScope, false); } - /** - * Predicate if the given instanceKey is the key representing the derived / calculated value - * provided by this {@link IAnnotationValueProvider}. - */ - public boolean isDerivedKey(String instanceKey) { - return (instanceKey == DEFAULT_KEY) || (instanceKey.equals(derivedKey)); + /** Constructor. */ + public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass) { + super(annotatedSpecificationEClass, new EStructuralFeatureDescriptor(null)); + this.isEditableByUser = false; } /** Predicate whether the derived value shall be editable by the user. */ @@ -129,9 +77,9 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot /** {@inheritDoc} */ @Override - public boolean canEdit(T specification, String instanceKey) { + public boolean canEdit(T specification) { // Deactivate editing if... - if(isDerivedKey(instanceKey) && !isEditableByUser) { + if(!isEditableByUser) { // ...editing is principally disabled or... return false; } @@ -144,44 +92,33 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot // ...the derived value is available and it should override the user annotated one. return false; } - return super.canEdit(specification, instanceKey); + return super.canEdit(specification); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception { - U calculatedValue; - - if(isDerivedKey(instanceKey)) { - calculatedValue = (U)specification.getValue(); - if(calculatedValue != null) { - return calculatedValue; - } + public <U> U getAnnotationValue(T specification) throws Exception { + U calculatedValue = (U)specification.getValue(); + if(calculatedValue != null) { + return calculatedValue; } - return super.getAnnotationValue(specification, instanceKey); + return super.getAnnotationValue(specification); } /** {@inheritDoc} */ @Override - public <U> void setAnnotationValue(U value, T specification, String instanceKey) - throws Exception { - if(isDerivedKey(instanceKey) && specification.getDerivedFeature() != null) { + public <U> void setAnnotationValue(U value, T specification) throws Exception { + if(specification.getDerivedFeature() != null) { if(value instanceof String) { - setAnnotationValueFromString((String)value, specification, instanceKey); + setAnnotationValueFromString((String)value, specification); } else { specification.eSet(specification.getDerivedFeature(), value); } return; } - super.setAnnotationValue(value, specification, instanceKey); - } - - /** {@inheritDoc} */ - @Override - public List<String> getInstanceKeys(T specification) { - return new ArrayList<>(keys); + super.setAnnotationValue(value, specification); } } diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java index cc624a716..aedd683a9 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java @@ -15,10 +15,6 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.annotation.valueprovider; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; @@ -40,16 +36,10 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp extends ValueProviderBase<T> { /** - * Map: Instance key -> {@link EStructuralFeatureDescriptor}s of the - * {@link IAnnotatedSpecification} managed by this {@link IAnnotationValueProvider}. - */ - private final Map<String, EStructuralFeatureDescriptor> structuralFeatureDescriptorMap; - - /** - * Flag if multiple {@link EStructuralFeature}s are managed by this + * {@link EStructuralFeatureDescriptor} of the {@link IAnnotatedSpecification} managed by this * {@link IAnnotationValueProvider}. */ - protected boolean handlesMultipleEstructuralFeatures; + private final EStructuralFeatureDescriptor structuralFeatureDescriptor; /** * Constructs a {@link IAnnotationValueProvider} for a {@link IAnnotatedSpecification} whose @@ -60,56 +50,29 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp super(annotatedSpecificationEClass); - structuralFeatureDescriptorMap = new HashMap<String, EStructuralFeatureDescriptor>(); - structuralFeatureDescriptorMap.put(DEFAULT_KEY, - new EStructuralFeatureDescriptor(eAttribute)); + structuralFeatureDescriptor = new EStructuralFeatureDescriptor(eAttribute); - handlesMultipleEstructuralFeatures = false; } /** - * Constructs a {@link IAnnotationValueProvider} for a {@link IAnnotatedSpecification} whose - * storage is implemented by a single {@link EReference}. + * Constructs a {@link IAnnotationValueProvider} for an {@link IAnnotatedSpecification}. */ public EStructuralFeatureValueProviderBase(EClass annotatedSpecificationEClass, EReference eReference, EStructuralFeatureDescriptor.EReferenceScope eReferenceScope) { super(annotatedSpecificationEClass); - structuralFeatureDescriptorMap = new HashMap<String, EStructuralFeatureDescriptor>(); - structuralFeatureDescriptorMap.put(DEFAULT_KEY, new EStructuralFeatureDescriptor( - eReference, eReferenceScope)); - - handlesMultipleEstructuralFeatures = false; + structuralFeatureDescriptor = new EStructuralFeatureDescriptor(eReference, eReferenceScope); } /** * Constructs a {@link IAnnotationValueProvider} for a {@link IAnnotatedSpecification} whose - * storage is implemented by a number of {@link EStructuralFeature}s contained in a single - * {@link EClass}. The mapping of instance keys to the corresponding {@link EStructuralFeature}s - * is explicitly provided in a {@link Map}. - */ - public EStructuralFeatureValueProviderBase(EClass annotatedSpecificationEClass, - Map<String, EStructuralFeatureDescriptor> structuralFeatureDescriptorMap) { - - super(annotatedSpecificationEClass); - - this.structuralFeatureDescriptorMap = structuralFeatureDescriptorMap; - - handlesMultipleEstructuralFeatures = true; - } - - /** - * Constructs a {@link IAnnotationValueProvider} for a {@link IAnnotatedSpecification} whose - * storage is implemented by all {@link EStructuralFeature}s defined locally in a single - * {@link EClass} (i.e., not considering inherited attributes). The instance keys, and the - * mapping to the corresponding {@link EStructuralFeature}s are automatically derived from the - * underlying {@link EClass} (instance keys = field names of {@link EStructuralFeature}). + * storage is implemented by an {@link EClass} that contains only a single + * {@link EStructuralFeature}. */ public EStructuralFeatureValueProviderBase(EClass annotatedSpecificationEClass) { - this(annotatedSpecificationEClass, false, - EStructuralFeatureDescriptor.EReferenceScope.MODEL); + this(annotatedSpecificationEClass, EStructuralFeatureDescriptor.EReferenceScope.MODEL); } /** @@ -118,72 +81,57 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp * @param annotatedSpecificationEClass * {@link EClass} for which {@link EStructuralFeatureValueProviderBase} should be * constructed. - * @param inheritedFeatures - * Flag if {@link EStructuralFeature}s that are not defined locally in - * {@code annotatedSpecificationEClass}, but that are inherited, should be included. + * * @param eReferenceScope * {@link EReferenceScope} to be offered to the user to select values for * {@link EReference}s. * */ public EStructuralFeatureValueProviderBase(EClass annotatedSpecificationEClass, - boolean inheritedFeatures, EStructuralFeatureDescriptor.EReferenceScope eReferenceScope) { + EStructuralFeatureDescriptor.EReferenceScope eReferenceScope) { super(annotatedSpecificationEClass); - structuralFeatureDescriptorMap = new HashMap<String, EStructuralFeatureDescriptor>(); - - EList<EStructuralFeature> featureList; - if(inheritedFeatures) { - featureList = annotatedSpecificationEClass.getEAllStructuralFeatures(); - } else { - featureList = annotatedSpecificationEClass.getEStructuralFeatures(); + final EList<EStructuralFeature> featureList = + annotatedSpecificationEClass.getEStructuralFeatures(); + if(featureList.size() > 1) { + throw new RuntimeException("Annotation class " + annotatedSpecificationEClass + + " must not contain more than one structural feature."); } - for(EStructuralFeature structuralFeature : featureList) { - // - In case there is only one feature, it is managed by the DEFAULT_KEY (see - // documentation of DEFAULT_KEY). - // - Otherwise, use the feature's name as instance key. - String instanceKey = - featureList.size() == 1 ? DEFAULT_KEY : structuralFeature.getName(); + if(featureList.size() == 1) { + // There is exactly one structural feature + EStructuralFeature structuralFeature = featureList.get(0); if(structuralFeature instanceof EAttribute) { - structuralFeatureDescriptorMap.put(instanceKey, new EStructuralFeatureDescriptor( - (EAttribute)structuralFeature)); + structuralFeatureDescriptor = + new EStructuralFeatureDescriptor((EAttribute)structuralFeature); } else if(structuralFeature instanceof EReference) { - structuralFeatureDescriptorMap.put(instanceKey, new EStructuralFeatureDescriptor( - (EReference)structuralFeature, eReferenceScope)); + structuralFeatureDescriptor = + new EStructuralFeatureDescriptor((EReference)structuralFeature, + eReferenceScope); + } else { + throw new RuntimeException("Unsupported EStructuralFeature specialization: " + + structuralFeature); } + } else { + structuralFeatureDescriptor = null; } - - handlesMultipleEstructuralFeatures = true; } /** - * Returns the {@link EStructuralFeature} for a given {@code instanceKey}, or throws - * an exception, if the key is unknown. - * + * Constructs a {@link IAnnotationValueProvider} for a {@link IAnnotatedSpecification} based on + * a custom {@link EStructuralFeatureDescriptor}. */ - public EStructuralFeature getEStructuralFeature(T specification, String instanceKey) - throws Exception { - EStructuralFeatureDescriptor eStructuralFeatureDescriptor = - structuralFeatureDescriptorMap.get(instanceKey); - EStructuralFeature structuralFeature = null; - if(eStructuralFeatureDescriptor != null) { - structuralFeature = eStructuralFeatureDescriptor.getEStructuralFeature(specification); - } - if(structuralFeature == null) { - throw new Exception("Instance key " + instanceKey + - " is unknown for annotation provider " + - annotatedSpecificationEClass.getInstanceClassName() + "."); - } - - return structuralFeature; + public EStructuralFeatureValueProviderBase(EClass annotatedSpecificationEClass, + EStructuralFeatureDescriptor structuralFeatureDescriptor) { + super(annotatedSpecificationEClass); + this.structuralFeatureDescriptor = structuralFeatureDescriptor; } /** {@inheritDoc} */ @Override - public EStructuralFeatureDescriptor getEStructuralFeatureDescriptor(String instanceKey) { - return structuralFeatureDescriptorMap.get(instanceKey); + public EStructuralFeatureDescriptor getEStructuralFeatureDescriptor() { + return structuralFeatureDescriptor; } /** Returns the {@link EFactory} for the given {@link EStructuralFeature}. */ @@ -195,10 +143,10 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp * Sets a value for a {@link IAnnotatedSpecification} from a {@link String} representation of * the input. */ - protected <V> void setAnnotationValueFromString(String value, T specification, - String instanceKey) throws Exception { + protected <V> void setAnnotationValueFromString(String value, T specification) throws Exception { - EStructuralFeature structuralFeature = getEStructuralFeature(specification, instanceKey); + EStructuralFeature structuralFeature = + getEStructuralFeatureDescriptor().getEStructuralFeature(specification); if(structuralFeature instanceof EAttribute) { EFactory eFactory = getEFactory(structuralFeature); @@ -212,15 +160,14 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp /** {@inheritDoc} */ @Override - public boolean canEdit(T specification, String instanceKey) { + public boolean canEdit(T specification) { return true; } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> void setAnnotationValue(U value, T specification, String instanceKey) - throws Exception { + public <U> void setAnnotationValue(U value, T specification) throws Exception { if(value instanceof String) { // In case the input choice is presented in dynamically managed combo box (i.e., where // new value choices can be entered by the user), the empty String indicates that the @@ -230,49 +177,43 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp if(((String)value).isEmpty()) { String rval = determineCurrentAnnotationValueAndUpdateInputChoice((String)value, - specification, instanceKey); + specification); if(rval != null) { value = (U)rval; } } - setAnnotationValueFromString((String)value, specification, instanceKey); + setAnnotationValueFromString((String)value, specification); } else { + final EStructuralFeature eStructuralFeature = + getEStructuralFeatureDescriptor().getEStructuralFeature(specification); if(value != null) { - specification.eSet(getEStructuralFeature(specification, instanceKey), value); + specification.eSet(eStructuralFeature, value); } else { // Treat 'null' as special value used to unset EStructural features. This // implementation choice prevents to distinguish between 'null' and unset for // EReferences). - specification.eUnset(getEStructuralFeature(specification, instanceKey)); + specification.eUnset(eStructuralFeature); } } } /** {@inheritDoc} */ @Override - public <U> void setAnnotationValue(U value, T specification) throws Exception { - setAnnotationValue(value, specification, DEFAULT_KEY); - } - - /** {@inheritDoc} */ - @Override - public void setAnnotationValue(String value, T specification, String instanceKey) - throws Exception { + public void setAnnotationValue(String value, T specification) throws Exception { // See comment in setAnnotationValue(U value, T specification) if((value == null || value.isEmpty())) { - String rval = - determineCurrentAnnotationValueAndUpdateInputChoice(value, specification, - instanceKey); + String rval = determineCurrentAnnotationValueAndUpdateInputChoice(value, specification); if(rval != null) { value = rval; } } - EStructuralFeature structuralFeature = getEStructuralFeature(specification, instanceKey); + EStructuralFeature structuralFeature = + getEStructuralFeatureDescriptor().getEStructuralFeature(specification); if(structuralFeature instanceof EAttribute) { - setAnnotationValueFromString(value, specification, instanceKey); + setAnnotationValueFromString(value, specification); } else { throw new Exception( "setAnnotationValue(String, T) is not supported / has not been implemented for the annotation type " + @@ -282,23 +223,12 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp } } - /** {@inheritDoc} */ - @Override - public void setAnnotationValue(String value, T specification) throws Exception { - setAnnotationValue(value, specification, DEFAULT_KEY); - } - /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception { - return (U)specification.eGet(getEStructuralFeature(specification, instanceKey)); - } - - /** {@inheritDoc} */ - @Override public <U> U getAnnotationValue(T specification) throws Exception { - return getAnnotationValue(specification, DEFAULT_KEY); + return (U)specification.eGet(getEStructuralFeatureDescriptor().getEStructuralFeature( + specification)); } /** @@ -306,11 +236,15 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp * annotation instances created in * {@link #getAnnotatedSpecificationForModelElement(IModelElement)}). */ - protected Object createStructuralFeatureInstance(String instanceKey) throws Exception { - EStructuralFeature structuralFeature = getEStructuralFeature(null, instanceKey); + protected Object createStructuralFeatureInstance() throws Exception { + EStructuralFeature structuralFeature = + getEStructuralFeatureDescriptor().getEStructuralFeature(null); + if(structuralFeature == null) { + return null; + } - EFactory factory = getEFactory(structuralFeature); if(structuralFeature instanceof EAttribute) { + EFactory factory = getEFactory(structuralFeature); EDataType attributeEDataType = ((EAttribute)structuralFeature).getEAttributeType(); @@ -333,24 +267,14 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp /** {@inheritDoc} */ @Override - protected void decorateAnnotationSpecification(T specification, String instanceKey) - throws Exception { + protected void decorateAnnotationSpecification(T specification) throws Exception { // Create and set structural feature implementing the annotation - Object structuralFeatureVal = createStructuralFeatureInstance(instanceKey); + Object structuralFeatureVal = createStructuralFeatureInstance(); if(structuralFeatureVal != null) { EStructuralFeature eStructuralFeature = - getEStructuralFeature(specification, instanceKey); + getEStructuralFeatureDescriptor().getEStructuralFeature(specification); specification.eSet(eStructuralFeature, structuralFeatureVal); } } - - /** {@inheritDoc} */ - @Override - public Collection<String> getInstanceKeys(T specification) { - if(handlesMultipleEstructuralFeatures) { - return structuralFeatureDescriptorMap.keySet(); - } - return super.getInstanceKeys(specification); - } } diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java index 761f41ce4..06d0344bb 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java @@ -18,7 +18,6 @@ package org.fortiss.tooling.base.annotation.valueprovider; import static org.fortiss.tooling.base.utils.BaseMathUtils.isExpectedType; import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -27,7 +26,6 @@ import java.util.function.BiConsumer; import org.conqat.lib.commons.collections.Pair; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; import org.fortiss.tooling.base.annotation.AnnotationEntry; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IModelElement; @@ -40,17 +38,6 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware; * provide specific implementations of this interface to perform the data exchange and conversion, * and to provide the required factory methods. * </p> - * Instance keys: - * <ul> - * <li>Kys are used to differentiate the different annotations that can be hosted by a single - * {@link IAnnotatedSpecification}. A typical use case is a single - * {@link EStructuralFeatureValueProviderBase} that supports multiple (or all) - * {@link EStructuralFeature} provided by single annotation class.</li> - * <li>In case the annotation only provides a single value, the {@link #DEFAULT_KEY} is used. For - * convenience, the method interface provides wrapper methods that omits the {@code instanceKey} - * parameter and wrap the corresponding generic method using the {@link #DEFAULT_KEY}).</li> - * </ul> - * </p> * * <p> * The interface / some of its methods take two template parameters: @@ -89,9 +76,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext /** {@link AnnotationEntry} elements to apply the associated action to. */ private ActionScope scope; - /** {@code instanceKey} with which the action is associated (if any). */ - private String instanceKey; - /** List of required input parameters to the annotation specific action. */ private AnnotationActionInputParameters inputParameters; @@ -102,11 +86,9 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext private boolean isWrite; /** Constructor defining the name and the scope of the corresponding action. */ - public AnnotationActionEntry(String entryName, ActionScope scope, String instanceKey, - boolean isWrite) { + public AnnotationActionEntry(String entryName, ActionScope scope, boolean isWrite) { this.entryName = entryName; this.scope = scope; - this.instanceKey = instanceKey; this.isWrite = isWrite; } @@ -114,9 +96,9 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext * Constructor defining the name and the scope of the corresponding action. Additionally, a * list of required input parameters types and their display name must be given. */ - public AnnotationActionEntry(String entryName, ActionScope scope, String instanceKey, - boolean isWrite, AnnotationActionReqInputParameters inputReqParameters) { - this(entryName, scope, instanceKey, isWrite); + public AnnotationActionEntry(String entryName, ActionScope scope, boolean isWrite, + AnnotationActionReqInputParameters inputReqParameters) { + this(entryName, scope, isWrite); this.inputReqParameters = inputReqParameters; } @@ -130,14 +112,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext return scope; } - /** - * Returns the {@code instanceKey} of the corresponding action (multiple actions per - * {@link IAnnotatedSpecification} may exist). - */ - public String getInstanceKey() { - return instanceKey; - } - /** Returns a list of entered input parameters. */ public AnnotationActionInputParameters getInputParameters() { return inputParameters; @@ -230,7 +204,7 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext /** * Defines the required input parameters to execute an action for an - * {@link IAnnotatedSpecification} (and its {@code instanceKey}). + * {@link IAnnotatedSpecification}. */ public class AnnotationActionReqInputParameter extends Pair<String, EStructuralFeatureDescriptor> { @@ -303,12 +277,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext // Wrapper class. } - /** - * Default key used in case this {@link IAnnotationValueProvider} is used to manage a single - * instance key only. - */ - public static String DEFAULT_KEY = null; - /** Returns the name of the annotation (e.g., used as labels in annotation views). */ public String getAnnotationName(T specification); @@ -324,15 +292,9 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext /** Predicate if the given annotation can be edited. */ public boolean canEdit(T specification); - /** Predicate if the given annotation can be edited. */ - public boolean canEdit(T specification, String instanceKey); - /** Returns the value of the annotation. */ public <U> U getAnnotationValue(T specification) throws Exception; - /** Returns the value of a multi-instance annotation's instance denoted by {@code instanceKey}. */ - public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception; - /** * Sets a new value for the annotation. * @@ -353,29 +315,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext */ public void setAnnotationValue(String value, T specification) throws Exception; - /** - * Sets a new value for a multi-instance annotation's instance denoted by {@code instanceKey}. - * - * @throws Exception - * is thrown if the conversion from the UI internal value representation ({@code U}) - * to the respective specialization of {@link IAnnotatedSpecification} has failed, - * or if this operation is not available. - */ - public <U> void setAnnotationValue(U value, T specification, String instanceKey) - throws Exception; - - /** - * Sets a new value for a multi-instance annotation's instance denoted by {@code instanceKey} - * from a {@link String} initializer. - * - * @throws Exception - * is thrown if the conversion from {@link String} to the respective specialization - * of {@link IAnnotatedSpecification} has failed, or if this operation is not - * available. - */ - public void setAnnotationValue(String value, T specification, String instanceKey) - throws Exception; - /** * Factory method that creates a new {@link IAnnotatedSpecification} specialization of type T to * the given model {@code element} and returns a reference to it. @@ -404,13 +343,10 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext public List<Class<? extends EObject>> excludeModelElementTypeFromAnnotatedSpecification(); /** - * Returns the instance keys supported by this {@link IAnnotationValueProvider}. - * {@link IAnnotationValueProvider}s can either define a static {@link List}. + * Returns the {@link EStructuralFeatureDescriptor} related to this + * {@link IAnnotatedSpecification}. */ - public Collection<String> getInstanceKeys(T specification); - - /** Returns the {@link EStructuralFeatureDescriptor} for a given {@code instanceKey}. */ - public EStructuralFeatureDescriptor getEStructuralFeatureDescriptor(String instanceKey); + public EStructuralFeatureDescriptor getEStructuralFeatureDescriptor(); /** * <p> diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/ValueProviderBase.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/ValueProviderBase.java index 2bd6753cb..fbc884688 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/ValueProviderBase.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/valueprovider/ValueProviderBase.java @@ -15,15 +15,15 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.annotation.valueprovider; -import static java.util.Collections.emptyList; +import static org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionEntry.ActionScope.ALL_VISIBLE_ITEMS; +import static org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionEntry.ActionScope.SINGLE_ITEM; import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf; +import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; import org.eclipse.emf.common.util.BasicEList; @@ -39,7 +39,6 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry; import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionEntry.ActionScope; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.kernel.utils.LoggingUtils; /** * Base class for {@link IAnnotationValueProvider}s. @@ -56,37 +55,29 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple protected final EClass annotatedSpecificationEClass; /** - * Map: instanceKey -> Fixed input choice to be offered in a combo box. The semantics of the map - * value is as follows (see {@link IAnnotationValueProvider} for the definition of instance - * keys). + * Fixed input choice to be offered in a combo box. The semantics of the map value is as + * follows: * <ul> - * <li> {@code fixedInputChoice[key] == null} -> do not use fixed values, provide text input - * cell.</li> - * <li> {@code !fixedInputChoice[key].isEmpty()} -> provide a fixed set of choices in an input - * box. - * <li> {@code fixedInputChoice[key].isEmpty()} -> dynamically manage the set of provided values, + * <li> {@code fixedInputChoice == null} -> do not use fixed values, provide text input cell.</li> + * <li> {@code !fixedInputChoice.isEmpty()} -> provide a fixed set of choices in an input box. + * <li> {@code fixedInputChoice.isEmpty()} -> dynamically manage the set of provided values, * i.e., the combo box is editable and enables the user to add new values and remove existing * choices (by removing all instances of them).</li> * <li>For enum types, the set of inputs is automatically initialized from the underlying * {@link EEnum} type definition.</li> * </ul> */ - private Map<String, List<String>> fixedInputChoiceMap; + private List<String> fixedInputChoice; /** - * Map: instanceKey -> Current input choice, computed according to the initialization of - * {@link #fixedInputChoiceMap}. + * Current input choice, computed according to the initialization of {@link #fixedInputChoice}. */ - private Map<String, Collection<String>> currentInputChoiceMap; + private Collection<String> currentInputChoice; /** - * Map: - * instanceKey -> - * last copied "annotation instance" (annotation + instanceKey + modelElement; unique) - * - * For single-value {@link IAnnotatedSpecification}s the instanceKey is {@code null}. + * Last copied "annotation instance" (annotation + modelElement; unique) */ - private Map<String, AnnotationInstSpec<T>> copiedAnnotation; + private AnnotationInstSpec<T> copiedAnnotation; /** * Constructs a new {@link IAnnotationValueProvider} for an annotation specified in a given @@ -94,10 +85,6 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple */ public ValueProviderBase(EClass annotatedSpecificationEClass) { this.annotatedSpecificationEClass = annotatedSpecificationEClass; - - fixedInputChoiceMap = new HashMap<>(); - currentInputChoiceMap = new HashMap<>(); - copiedAnnotation = new HashMap<>(); } /** {@inheritDoc} */ @@ -113,34 +100,9 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple return false; } - /** {@inheritDoc} */ - @Override - public boolean canEdit(T specification) { - return canEdit(specification, DEFAULT_KEY); - } - - /** {@inheritDoc} */ - @Override - public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception { - return getAnnotationValue(specification); - } - /** {@inheritDoc} */ @Override public void setAnnotationValue(String value, T specification) throws Exception { - setAnnotationValue(value, specification, null); - } - - /** {@inheritDoc} */ - @Override - public <U> void setAnnotationValue(U value, T specification) throws Exception { - setAnnotationValue(value, specification, null); - } - - /** {@inheritDoc} */ - @Override - public void setAnnotationValue(String value, T specification, String instanceKey) - throws Exception { throw new Exception( "setAnnotationValue(String) is not supported / has not been implemented for annotations of type " + specification.getClass()); @@ -148,8 +110,7 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple /** {@inheritDoc} */ @Override - public <U> void setAnnotationValue(U value, T specification, String instanceKey) - throws Exception { + public <U> void setAnnotationValue(U value, T specification) throws Exception { throw new Exception( "setAnnotationValue(U) is not supported / has not been implemented for annotations of type " + specification.getClass()); @@ -169,20 +130,6 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple * annotation to be decorated */ protected void decorateAnnotationSpecification(T specification) throws Exception { - decorateAnnotationSpecification(specification, null); - } - - /** - * Add decorations to an annotation when its instance is newly created by - * {@link #getAnnotatedSpecificationForModelElement(IModelElement)}. - * - * @param specification - * annotation to be decorated - * @param instanceKey - * instanceKey of annotation to be decorated - */ - protected void decorateAnnotationSpecification(T specification, String instanceKey) - throws Exception { // No decoration } @@ -203,21 +150,7 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple EFactory eFactory = annotatedSpecificationEClass.getEPackage().getEFactoryInstance(); T specification = (T)eFactory.create(annotatedSpecificationEClass); - if(getInstanceKeys(specification).isEmpty()) { - decorateAnnotationSpecification(specification); - } else { - for(String key : getInstanceKeys(specification)) { - try { - decorateAnnotationSpecification(specification, key); - } catch(Exception e) { - // Some of the keys might not be backed by an implementation that needs to - // "decorate" the underlying specification object (e.g., a custom key that - // represents a calculated, volatile value. Hence, just ignore invalid keys - // during this setup phase. The other methods (get/set/...) will throw an - // Exception on invalid keys. - } - } - } + decorateAnnotationSpecification(specification); // Hook specification to model element element.addSpecification(specification); @@ -232,25 +165,24 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple return (Class<T>)annotatedSpecificationEClass.getInstanceClass(); } - /** {@inheritDoc} */ - @Override - public Collection<String> getInstanceKeys(T specification) { - return emptyList(); + /** Returns the {@link #fixedInputChoice}. */ + public List<String> getFixedInputChoice() { + return fixedInputChoice; } - /** Returns the {@link #fixedInputChoiceMap}. */ - public Map<String, List<String>> getFixedInputChoiceMap() { - return fixedInputChoiceMap; + /** Sets the {@link #fixedInputChoice}. */ + public void setFixedInputChoice(List<String> fixedInputChoice) { + this.fixedInputChoice = fixedInputChoice; } - /** Returns the {@link #currentInputChoiceMap}. */ - public Map<String, Collection<String>> getCurrentInputChoiceMap() { - return currentInputChoiceMap; + /** Returns the {@link #currentInputChoice}. */ + public Collection<String> getCurrentInputChoice() { + return currentInputChoice; } - /** Sets the {@link #currentInputChoiceMap}. */ - public void setCurrentInputChoiceMap(Map<String, Collection<String>> currentInputChoiceMap) { - this.currentInputChoiceMap = currentInputChoiceMap; + /** Sets the {@link #currentInputChoice}. */ + public void setCurrentInputChoice(Collection<String> currentInputChoice) { + this.currentInputChoice = currentInputChoice; } /** @@ -265,15 +197,12 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple * to update the input choice. * @param specification * {@link IAnnotatedSpecification} for which the input choice is to be updated - * @param instanceKey - * Key identifying annotation instance of {@code specification} to be used. * * @return Currently selected choice. */ protected String determineCurrentAnnotationValueAndUpdateInputChoice(String newValue, - T specification, String instanceKey) throws Exception { + T specification) throws Exception { - Collection<String> currentInputChoice = currentInputChoiceMap.get(instanceKey); boolean noValue = newValue == null || newValue.isEmpty(); if(noValue && currentInputChoice != null && !currentInputChoice.isEmpty()) { @@ -296,7 +225,7 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple // Otherwise, return the entry just before the entry to be removed. String rval = null; - for(String s : currentInputChoiceMap.get(instanceKey)) { + for(String s : currentInputChoice) { if(s != null && s.equals(currentValue)) { currentInputChoice.remove(currentValue); return rval; @@ -314,76 +243,60 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple public AnnotationActions<T> getContextMenuEntries(T specification) { AnnotationActions<T> retList = new AnnotationActions<>(); - for(String instanceKey : getInstanceKeys(specification)) { - EStructuralFeature eType = null; - if(getEStructuralFeatureDescriptor(instanceKey) != null) { - eType = - getEStructuralFeatureDescriptor(instanceKey).getEStructuralFeature( - specification); - } - boolean isManyRef = eType instanceof EReference && ((EReference)eType).isMany(); + EStructuralFeature eType = null; + if(getEStructuralFeatureDescriptor() != null) { + eType = getEStructuralFeatureDescriptor().getEStructuralFeature(specification); + } + boolean isManyRef = eType instanceof EReference && ((EReference)eType).isMany(); - retList.add(createCopyAction(instanceKey)); - retList.addAll(createPasteActions(instanceKey, isManyRef, false)); - if(isManyRef) { - retList.addAll(createPasteActions(instanceKey, isManyRef, true)); - } + retList.add(createCopyAction()); + retList.addAll(createPasteActions(isManyRef, false)); + if(isManyRef) { + retList.addAll(createPasteActions(isManyRef, true)); } return retList; } /** Copy a selected annotation from the table. */ - private AnnotationAction<T> createCopyAction(String instanceKey) { + private AnnotationAction<T> createCopyAction() { BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>> copyAction = (AnnotationInstSpec<T> spec, AnnotationActionParameters<T> parameters) -> { - copiedAnnotation.put(instanceKey, spec); + copiedAnnotation = spec; }; AnnotationActionEntry copyDescriptor = - new AnnotationActionEntry("Copy", ActionScope.SINGLE_ITEM, instanceKey, false); + new AnnotationActionEntry("Copy", ActionScope.SINGLE_ITEM, false); return new AnnotationAction<T>(copyDescriptor, copyAction); } /** Paste a selected annotation from the table. */ - private List<AnnotationAction<T>> createPasteActions(String instanceKey, boolean isManyRef, - boolean doReplace) { + private List<AnnotationAction<T>> createPasteActions(boolean isManyRef, boolean doReplace) { List<AnnotationAction<T>> pasteActions = new ArrayList<>(); BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>> pasteAction = (AnnotationInstSpec<T> spec, AnnotationActionParameters<T> parameters) -> { - AnnotationInstSpec<T> copiedAnnInst = copiedAnnotation.get(instanceKey); - if(copiedAnnInst == null) { + if(copiedAnnotation == null) { // Skip pasting if no annotation was copied. return; } - AnnotationEntry annEntry = copiedAnnInst.getEntry(); + AnnotationEntry annEntry = copiedAnnotation.getEntry(); Object copiedValue = - annEntry.getSpecificationValue( - copiedAnnInst.getAnnotatedSpecificationType(), - copiedAnnInst.getInstanceKey()); + annEntry.getSpecificationValue(copiedAnnotation + .getAnnotatedSpecificationType()); T pasteAnnotation = parameters.getAnnotation(); if(pasteAnnotation != null) { try { - if(spec.getInstanceKey() == null || spec.getInstanceKey().equals("")) { - pasteValue(instanceKey, isManyRef, doReplace, copiedValue, - pasteAnnotation); - } else { - pasteValue(instanceKey, isManyRef, doReplace, copiedValue, - pasteAnnotation); - } + pasteValue(isManyRef, doReplace, copiedValue, pasteAnnotation); } catch(Exception e) { - // @CodeFormatterOff - LoggingUtils - .error(ToolingBaseActivator.getDefault(), - "Could not set the value of the annotation " + - pasteAnnotation.getName() + + error(ToolingBaseActivator.getDefault(), + "Could not set the value of the annotation " + + pasteAnnotation.getName() + " when trying to propagate the value form the selected annotation.", - e); - // @CodeFormatterOn + e); } } }; @@ -391,13 +304,11 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple String pasteSuffix = !isManyRef ? "" : (doReplace ? " (replace)" : " (append)"); AnnotationActionEntry pasteDescriptor = - new AnnotationActionEntry("Paste" + pasteSuffix, ActionScope.SINGLE_ITEM, - instanceKey, true); + new AnnotationActionEntry("Paste" + pasteSuffix, SINGLE_ITEM, true); pasteActions.add(new AnnotationAction<T>(pasteDescriptor, pasteAction)); AnnotationActionEntry pasteAllDescriptor = - new AnnotationActionEntry("Paste to all" + pasteSuffix, - ActionScope.ALL_VISIBLE_ITEMS, instanceKey, true); + new AnnotationActionEntry("Paste to all" + pasteSuffix, ALL_VISIBLE_ITEMS, true); pasteActions.add(new AnnotationAction<T>(pasteAllDescriptor, pasteAction)); return pasteActions; @@ -409,15 +320,15 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple */ // NOTE: We can suppress these warnings @SuppressWarnings({"unchecked", "rawtypes"}) - private void pasteValue(String instanceKey, boolean isManyRef, boolean doReplace, - Object copiedValue, T pasteAnnotation) throws Exception { + private void pasteValue(boolean isManyRef, boolean doReplace, Object copiedValue, + T pasteAnnotation) throws Exception { if(isManyRef) { // Do not copy values that cannot be pasted the target EList<EObject> castedList = new BasicEList((EList<EObject>)copiedValue); - castedList.removeIf(r -> !canPaste(r, instanceKey, pasteAnnotation)); + castedList.removeIf(r -> !canPaste(r, pasteAnnotation)); copiedValue = castedList; } else if(copiedValue instanceof EReference) { - if(!canPaste((EReference)copiedValue, instanceKey, pasteAnnotation)) { + if(!canPaste((EReference)copiedValue, pasteAnnotation)) { return; } } @@ -426,7 +337,7 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple setAnnotationValue(copiedValue, pasteAnnotation); } else { List<?> appendList = new ArrayList<>(); - appendList.addAll(getAnnotationValue(pasteAnnotation, instanceKey)); + appendList.addAll(getAnnotationValue(pasteAnnotation)); appendList.addAll((List)copiedValue); setAnnotationValue(appendList, pasteAnnotation); } @@ -437,8 +348,8 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple * prevent pasting of copied References that may not be set due to restrictions in the target * annotation. */ - private boolean canPaste(EObject refObj, String instanceKey, T pasteAnnotation) { - EStructuralFeatureDescriptor featurDescr = getEStructuralFeatureDescriptor(instanceKey); + private boolean canPaste(EObject refObj, T pasteAnnotation) { + EStructuralFeatureDescriptor featurDescr = getEStructuralFeatureDescriptor(); if(featurDescr.isAvailableObject(refObj, pasteAnnotation, pasteAnnotation.getSpecificationOf())) { return true; diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/.ratings b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/.ratings index a120fef3c..d19228c2d 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/.ratings +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/.ratings @@ -1,5 +1,5 @@ AngleUtils.java 6aaf8e974481e9bd5c0d813302c1f08d10d1c00d GREEN -AnnotationUtils.java a70d12c6d96010cda007720bf34b12882940b314 GREEN +AnnotationUtils.java 941cfdbc8c871da64f8e873ce50ed19c8f9c4b7e YELLOW BaseMathUtils.java 7d0e7113af72677b0a7e44fcc40e874624d3bee6 GREEN BaseModelElementUtils.java fc0596156b9f5761759ab3a9974fe0302e9889e9 GREEN ConstraintsBaseUtils.java ae80d8f4ad3b821b5025ef24ce34a4e6185cc67e GREEN diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/AnnotationUtils.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/AnnotationUtils.java index 5e16ca72a..9d8aeb70d 100644 --- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/AnnotationUtils.java +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/AnnotationUtils.java @@ -20,13 +20,9 @@ import static org.fortiss.tooling.kernel.utils.EcoreUtils.getEClassForClass; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getParentsWithType; import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf; import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf; +import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import java.util.function.BiConsumer; import java.util.stream.DoubleStream; @@ -51,7 +47,6 @@ import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.service.IPersistencyService; -import org.fortiss.tooling.kernel.utils.LoggingUtils; /** * Utility methods for dealing with {@link IAnnotatedSpecification}s. @@ -173,68 +168,36 @@ public class AnnotationUtils { return parentAnnotationList; } - /** - * Creates an action that takes an average value and a bound to generate a random value for - * single valued {@link IAnnotatedSpecification}s. See { - * {@link #createRandValInputAction(IAnnotationValueProvider, Map)}. - * - * @param provider - * {@link IAnnotationValueProvider} offering the ability to create random values. - * @param valType - * {@link EStructuralFeatureDescriptor} describing the values' properties. - * @return {@link AnnotationAction} (random value generation) for the given - * {@link IAnnotatedSpecification} (by the provider). - */ - public static <T extends IAnnotatedSpecification> AnnotationAction<T> createRandValInputAction( - IAnnotationValueProvider<T> provider, EStructuralFeatureDescriptor valType) { - Map<String, EStructuralFeatureDescriptor> valTypeMap = new HashMap<>(1, (float)1.0); - valTypeMap.put(null, valType); - return createRandValInputAction(provider, valTypeMap).stream().findAny().orElse(null); - } - /** * Creates an action that takes an average value and a bound to generate a random value. The - * action will be registered for each {@code instanceKey} - {@link EStructuralFeatureDescriptor} - * pair from the given map. This method must be called from an {@link IAnnotationValueProvider} - * when the action list is built (typically - * {@link IAnnotationValueProvider#getContextMenuEntries(IAnnotatedSpecification)}). + * action will be registered for the given {@link EStructuralFeatureDescriptor}. This + * method must be called from an {@link IAnnotationValueProvider} when the action list is built + * (typically {@link IAnnotationValueProvider#getContextMenuEntries(IAnnotatedSpecification)}). * * Usually, this method is used to allow the creation of random values for displayed set of * {@link IAnnotatedSpecification}s in the corresponding table from the context menu. * * @param provider * {@link IAnnotationValueProvider} offering the ability to create random values. - * @param valTypeMap - * Map of {@code instanceKey}s and their corresponding - * {@link EStructuralFeatureDescriptor}s describing the values' properties. - * @return Collection of {@link AnnotationAction}s (random value generation) for the given set - * of {@code instanceKey}s. + * @param valType + * {@link EStructuralFeatureDescriptor} describing the values' properties. + * @return {@link AnnotationAction}s to trigger random value generation. */ - public static <T extends IAnnotatedSpecification> Collection<AnnotationAction<T>> - createRandValInputAction(IAnnotationValueProvider<T> provider, - Map<String, EStructuralFeatureDescriptor> valTypeMap) { - Collection<AnnotationAction<T>> retActions = new ArrayList<>(); - - // TODO: error if valtype is empty or null - if(valTypeMap == null || valTypeMap.isEmpty()) { - throw new IllegalArgumentException( - "Cannot create the random value input action without a" - + "specification of the expected types" - + "that is derived from the annotation."); - } + public static <T extends IAnnotatedSpecification> AnnotationAction<T> createRandValInputAction( + IAnnotationValueProvider<T> provider, EStructuralFeatureDescriptor valType) { // Generates random entries around the given value and the fixed bound for all visible // annotations of the passed type. BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>> randomValuePropagation = - (AnnotationInstSpec<T> spec, AnnotationActionParameters<T> parameters) -> { + (AnnotationInstSpec<T> spec, AnnotationActionParameters<T> parameters) -> { T annotation = parameters.getAnnotation(); - - EStructuralFeatureDescriptor featureDescriptor = provider. - getEStructuralFeatureDescriptor(spec.getInstanceKey()); + + EStructuralFeatureDescriptor featureDescriptor = + provider.getEStructuralFeatureDescriptor(); EClassifier featureType = featureDescriptor.getEType(annotation); AnnotationActionInputParameters params = parameters.getInputParameters(); - + Object value = params.get("Average Value:", featureType.getInstanceClass()); Object bound = params.get("Bound: ", featureType.getInstanceClass()); @@ -246,11 +209,9 @@ public class AnnotationUtils { } if(dValue == null || dBound == null) { // @CodeFormatterOff - LoggingUtils - .error(ToolingBaseActivator.getDefault(), - "Generation of random values for " + - annotation.getName() + ": " + - "The average value or bound type is not number."); + error(ToolingBaseActivator.getDefault(), + "Generation of random values for " + annotation.getName() + ": " + + "The average value or bound type is not number."); // @CodeFormatterOn return; } @@ -265,40 +226,25 @@ public class AnnotationUtils { randVal = convertNumber(randVal, targetNumberType); try { - if(spec.getInstanceKey() == null || spec.getInstanceKey().equals("")) { - provider.setAnnotationValue(randVal, annotation); - } else { - provider.setAnnotationValue(randVal, annotation, spec.getInstanceKey()); - } + provider.setAnnotationValue(randVal, annotation); } catch(Exception e) { // @CodeFormatterOff - LoggingUtils - .error(ToolingBaseActivator.getDefault(), - "Could not set the value of the annotation " + - annotation.getName() + - " when trying to propagate the value form the selected annotation.", - e); + error(ToolingBaseActivator.getDefault(), + "Could not set the value of the annotation " + annotation.getName() + + " when trying to propagate the value form the selected annotation.", e); // @CodeFormatterOn } }; - for(Entry<String, EStructuralFeatureDescriptor> entry : valTypeMap.entrySet()) { - AnnotationActionReqInputParameters randInputParameters = - new AnnotationActionReqInputParameters(); - randInputParameters.add(new AnnotationActionReqInputParameter("Average Value:", entry - .getValue())); - randInputParameters.add(new AnnotationActionReqInputParameter("Bound: ", entry - .getValue())); - AnnotationActionEntry randValuePropDescriptor = - new AnnotationActionEntry("Create random values", - ActionScope.ALL_VISIBLE_ITEMS, entry.getKey(), true, - randInputParameters); + AnnotationActionReqInputParameters randInputParameters = + new AnnotationActionReqInputParameters(); + randInputParameters.add(new AnnotationActionReqInputParameter("Average Value:", valType)); + randInputParameters.add(new AnnotationActionReqInputParameter("Bound: ", valType)); - retActions - .add(new AnnotationAction<T>(randValuePropDescriptor, randomValuePropagation)); - } + AnnotationActionEntry randValuePropDescriptor = + new AnnotationActionEntry("Create random values", ActionScope.ALL_VISIBLE_ITEMS, + true, randInputParameters); - // Add the propagate action to the list of context menu entries. - return retActions; + return new AnnotationAction<T>(randValuePropDescriptor, randomValuePropagation); } } -- GitLab