From 2e22102d30f0540eb1fafdf59a0c9fc84c834a60 Mon Sep 17 00:00:00 2001 From: Andreas Bayha <bayha@fortiss.org> Date: Fri, 9 Oct 2020 14:29:22 +0200 Subject: [PATCH] Annotations: Removed old annotations view Completely replaced the old annotation view with the fx based implementation. So far, both were available in parallel. Issue-Ref: 4014 Issue-Url: https://af3-developer.fortiss.org/issues/4014 Signed-off-by: Andreas Bayha <bayha@fortiss.org> --- .../META-INF/MANIFEST.MF | 5 +- org.fortiss.tooling.base.ui/plugin.xml | 9 +- .../ui/annotation/editingsupport/.ratings | 17 - .../AnnotationEditingSupportBase.java | 108 --- .../CheckBoxEditingSupport.java | 52 -- .../ComboBoxEditingSupport.java | 186 ----- .../editingsupport/EditingSupportFactory.java | 203 ----- .../ElementCommentEditingSupport.java | 57 -- .../ElementEditingSupportBase.java | 55 -- .../ElementNameEditingSupport.java | 57 -- .../IMultiValueAnnotationDialog.java | 35 - .../IMultiValueAnnotationEditingSupport.java | 41 - .../editingsupport/LabelValueMapping.java | 215 ------ .../MultiValueAnnotationDialogBase.java | 129 ---- ...ultiValueAnnotationEditingSupportBase.java | 163 ---- .../MultiValueAnnotationSelectionDialog.java | 143 ---- ...alueAnnotationSelectionEditingSupport.java | 57 -- ...MultiValueAnnotationTextEditingDialog.java | 244 ------ ...ultiValueAnnotationTextEditingSupport.java | 54 -- .../editingsupport/TextEditingSupport.java | 79 -- .../ui/annotation/editingsupport/package.html | 4 - .../base/ui/annotation/labelprovider/.ratings | 7 - .../AnnotationLabelProvider.java | 135 ---- .../labelprovider/CheckBoxLabelProvider.java | 93 --- .../ElementCommentLabelProvider.java | 43 -- .../ElementLabelProviderBase.java | 50 -- .../ElementNameLabelProvider.java | 42 -- .../labelprovider/LabelProviderBase.java | 106 --- .../labelprovider/LabelProviderFactory.java | 61 -- .../ui/annotation/labelprovider/package.html | 4 - .../tooling/base/ui/annotation/package.html | 11 - .../tooling/base/ui/annotation/view/.ratings | 2 +- .../view/AnnotationViewPartBase.java | 398 ---------- .../annotation/view/IAnnotationViewPart.java | 4 - .../base/ui/annotation/view/fx/.ratings | 7 +- .../view/fx/AnnotationFxViewPart.java | 3 +- .../view/fx/AnnotationViewFXController.java | 1 - .../view/{generic => fx}/ColumnHandle.java | 4 +- .../fx/FXAnnotationFilterContentProvider.java | 1 - .../base/ui/annotation/view/generic/.ratings | 2 - .../view/generic/GenericAnnotationView.java | 699 ------------------ .../annotation/view/generic/filter/.ratings | 3 - .../view/generic/filter/AnnotationFilter.java | 300 -------- .../filter/AnnotationFilterWidget.java | 366 --------- .../generic/filter/TextFocusListener.java | 95 --- .../view/generic/filter/package.html | 4 - .../ui/annotation/view/generic/package.html | 4 - .../tooling/base/ui/layout/auto/.ratings | 2 +- .../ui/layout/auto/KielerAutoLayouter.java | 6 - 49 files changed, 12 insertions(+), 4354 deletions(-) delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementCommentEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationDialog.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/LabelValueMapping.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationDialogBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationEditingSupportBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionDialog.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingDialog.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/package.html delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementCommentLabelProvider.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementLabelProviderBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementNameLabelProvider.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderBase.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/package.html delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/package.html delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java rename org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/{generic => fx}/ColumnHandle.java (94%) delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/.ratings delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilter.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilterWidget.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/TextFocusListener.java delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/package.html delete mode 100644 org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/package.html diff --git a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF index 5fe281bb2..1f31d0fee 100644 --- a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF @@ -13,11 +13,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-Vendor: fortiss GmbH Export-Package: org.fortiss.tooling.base.ui, org.fortiss.tooling.base.ui.annotation, - org.fortiss.tooling.base.ui.annotation.editingsupport, - org.fortiss.tooling.base.ui.annotation.labelprovider, org.fortiss.tooling.base.ui.annotation.view, - org.fortiss.tooling.base.ui.annotation.view.generic, - org.fortiss.tooling.base.ui.annotation.view.generic.filter, + org.fortiss.tooling.base.ui.annotation.view.fx, org.fortiss.tooling.base.ui.contentprovider, org.fortiss.tooling.base.ui.dialog, org.fortiss.tooling.base.ui.dnd.gef, diff --git a/org.fortiss.tooling.base.ui/plugin.xml b/org.fortiss.tooling.base.ui/plugin.xml index 231f48481..468962915 100644 --- a/org.fortiss.tooling.base.ui/plugin.xml +++ b/org.fortiss.tooling.base.ui/plugin.xml @@ -14,19 +14,12 @@ <!-- Keep ID constant in sync with org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart.ANNOTATION_VIEW_ID --> <extension point="org.eclipse.ui.views"> <view - class="org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView" + class="org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationFxViewPart" icon="icons/annotation.gif" id="org.fortiss.tooling.base.ui.annotationView" name="Annotations" restorable="true"> </view> - <view - class="org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationFxViewPart" - icon="icons/annotation.gif" - id="org.fortiss.tooling.base.ui.annotationFxView" - name="Annotations FX" - restorable="true"> - </view> </extension> <extension point="org.fortiss.tooling.kernel.uiMessageHandler"> <uiMessageHandler diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings deleted file mode 100644 index 77cba538c..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/.ratings +++ /dev/null @@ -1,17 +0,0 @@ -AnnotationEditingSupportBase.java a5ecf54616b50f947d251f45cbb5789df5234170 GREEN -CheckBoxEditingSupport.java 1d8d9dd444f0e52767c65fd2711321438d3a9b29 GREEN -ComboBoxEditingSupport.java 6b6a23be327ebdea9bdaf007304bd3d7c14b2cef GREEN -EditingSupportFactory.java e42347692ef23a8cb71532edadcf176ae49e992d GREEN -ElementCommentEditingSupport.java 4be366924a040caf3f80e35b383e796e84aedcac GREEN -ElementEditingSupportBase.java a6360f99ee149276f0fbd299820ebd1c9731ea97 GREEN -ElementNameEditingSupport.java 0dcaecf4ba5f8ddefa3ccb7d6f4e4506f7f09b26 GREEN -IMultiValueAnnotationDialog.java b0e0c72c25c5655f8c791bb99b2ed4fd3d0b0c3e GREEN -IMultiValueAnnotationEditingSupport.java 12e93b20e71e31d30c54e6b9ead8895aaa38454c GREEN -LabelValueMapping.java 3b7a9c6112cc56595ec99f3b3ea0d469a61ebf1d GREEN -MultiValueAnnotationDialogBase.java 9d9e6e10e11d1d03a3c5a8c86c3d887aa39e37a6 GREEN -MultiValueAnnotationEditingSupportBase.java ac228c1a4dec5d7035729585c2dcb9799da6aba9 GREEN -MultiValueAnnotationSelectionDialog.java eb493c084158bfaf4267d6a1f3dd41bcf0867eef GREEN -MultiValueAnnotationSelectionEditingSupport.java a4c3c3f9c3cc4f43f27c95f9ba676b4bef01e157 GREEN -MultiValueAnnotationTextEditingDialog.java 50cf3bb99fe93be4b8f6453f563860193f6fcea4 GREEN -MultiValueAnnotationTextEditingSupport.java 38c780819396fc75d10fbb660832652d89d59378 GREEN -TextEditingSupport.java e761ea393816f23ca41157f2a9a9a8d8ef30b858 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java deleted file mode 100644 index a5ecf5461..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/AnnotationEditingSupportBase.java +++ /dev/null @@ -1,108 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import static org.eclipse.jface.dialogs.MessageDialog.openError; - -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.widgets.Shell; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.service.IPersistencyService; - -/** - * Base class for {@link EditingSupport}s used to display an manipulate - * {@link IAnnotatedSpecification}s in {@link TableViewer}-based annotation views. - * - * @author barner - */ -public abstract class AnnotationEditingSupportBase extends EditingSupport { - - /** Value used to allow user to unset annotation value. */ - protected final static String UNSET_RESERVED_VALUE = ""; - - /** Specification class of this column. */ - protected Class<? extends IAnnotatedSpecification> specClass; - - /** Constructs a new {@link AnnotationEditingSupportBase}. */ - public AnnotationEditingSupportBase(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass) { - super(viewer); - this.specClass = specClass; - } - - /** {@inheritDoc} */ - @Override - protected boolean canEdit(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry annotationEntry = (AnnotationEntry)element; - return annotationEntry.canEdit(specClass); - } - - return true; - } - - /** Actually gets the value from the {@link IAnnotatedSpecification}. */ - protected Object doGetValue(AnnotationEntry annotationEntry) { - return annotationEntry.getSpecificationValue(specClass); - } - - /** {@inheritDoc} */ - @Override - protected Object getValue(Object element) { - if(element instanceof AnnotationEntry) { - return doGetValue((AnnotationEntry)element); - } - return null; - } - - /** Actually sets a {@link String} value into a {@link IAnnotatedSpecification}. */ - protected void doSetValue(AnnotationEntry annotationEntry, String value) throws Exception { - 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); - } - - /** {@inheritDoc} */ - @Override - protected void setValue(Object element, final Object value) { - if(element instanceof AnnotationEntry) { - final AnnotationEntry annotationEntry = (AnnotationEntry)element; - - ITopLevelElement modelContext = IPersistencyService.getInstance() - .getTopLevelElementFor(annotationEntry.getModelElement()); - modelContext.runAsCommand(() -> { - try { - doSetValue(annotationEntry, value); - } catch(IllegalArgumentException e) { - String msg = - "The value you entered does not have the desired type.\nDetailed message:\n" + - e.getMessage(); - openError(new Shell(), "ERROR", msg); - } catch(Exception e) { - openError(new Shell(), "ERROR", e.getMessage()); - } - }); - this.getViewer().refresh(true); - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java deleted file mode 100644 index 1d8d9dd44..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/CheckBoxEditingSupport.java +++ /dev/null @@ -1,52 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckboxCellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; - -/** - * {@link EditingSupport} providing a check box to display and manipulate boolean annotation values. - * - * @author diewald - */ -public class CheckBoxEditingSupport extends AnnotationEditingSupportBase { - - /** Placeholder for the boolean value editor (in fact, only an icon is toggled). */ - private CheckboxCellEditor checkBoxEditor; - - /** Constructs a new {@link CheckBoxEditingSupport}. */ - public CheckBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass) { - super(viewer, specClass); - checkBoxEditor = new CheckboxCellEditor(((TableViewer)viewer).getTable()); - } - - /** {@inheritDoc} */ - @Override - protected CellEditor getCellEditor(Object element) { - if(!(element instanceof AnnotationEntry)) { - return null; - } - - return checkBoxEditor; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java deleted file mode 100644 index 6b6a23be3..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java +++ /dev/null @@ -1,186 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.annotation.valueprovider.ValueProviderBase; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IDerivedAnnotation; - -/** - * {@link EditingSupport} providing a {@link ComboBoxViewerCellEditor} for suitable - * {@link IAnnotatedSpecification}s ({@link EEnum}s, fixed set of {@link String}s, - * {@link EReference}s). - * - * @author diewald - */ -public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { - - /** Combo box cell editor. */ - private ComboBoxViewerCellEditor cellEditor = null; - - /** Flag if this {@link ComboBoxEditingSupport} is editable. */ - boolean isEditable; - - /** - * Input-choice based on an {@link EStructuralFeature} (i.e., {@link EEnum} or - * {@link EReference}). - */ - EStructuralFeatureDescriptor eStructuralFeatureDescriptor; - - /** - * Base constructor that sets up the {@link ComboBoxEditingSupport} (apart from the set of - * available choices which is prepared on demand in {@link #getCellEditor(Object)}. - */ - public ComboBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, boolean isEditable) { - super(viewer, clazz); - - this.isEditable = isEditable; - - cellEditor = new ComboBoxViewerCellEditor((Composite)getViewer().getControl()); - cellEditor.setLabelProvider(new LabelProvider()); - cellEditor.setContentProvider(new ArrayContentProvider()); - - cellEditor.getViewer().getCCombo().setEditable(isEditable); - } - - /** - * Creates a {@link ComboBoxEditingSupport} for a {@link EStructuralFeature}-based input-choice - * (i.e., {@link EEnum} or {@link EReference}. - */ - public ComboBoxEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - 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, - !(eStructuralFeatureDescriptor.getEType(specification) instanceof EEnum || - eStructuralFeatureDescriptor.getEType(specification) instanceof EClass)); - // @CodeFormatterOn - this.eStructuralFeatureDescriptor = eStructuralFeatureDescriptor; - } - - /** - * <p> - * Creates a {@link LabelValueMapping} for the given {@link AnnotationEntry}. - * </p> - * <p> - * Note: Since {@link IDerivedAnnotation}s support that the {@link EStructuralFeature} of their - * return value is changed at runtime, the resulting {@link LabelValueMapping} should not be - * cached. - * </p> - */ - @SuppressWarnings("unchecked") - private <T extends IAnnotatedSpecification> LabelValueMapping - getLabelValueMapping(AnnotationEntry entry) { - ValueProviderBase<T> valueProvider = - (ValueProviderBase<T>)entry.getAnnotationValueProvider(specClass); - valueProvider.updateInputChoice(getViewer().getInput(), (Class<T>)specClass); - - return new LabelValueMapping(eStructuralFeatureDescriptor, - entry.getSpecification(specClass), entry.getModelElement(), - valueProvider.getCurrentInputChoice()); - } - - /** {@inheritDoc} */ - @Override - protected CellEditor getCellEditor(Object element) { - - if(!(element instanceof AnnotationEntry)) { - return null; - } - - AnnotationEntry entry = (AnnotationEntry)element; - - List<String> labels = new ArrayList<String>(getLabelValueMapping(entry).getLabels()); - - // Allow to unset EReferences. This does not make sense for EENums which have a default - // value. Resetting of String-based annotations is handled in TextEditingSupport. - if(eStructuralFeatureDescriptor != null && eStructuralFeatureDescriptor - .getEType(entry.getSpecification(specClass)) instanceof EClass) { - labels.add(UNSET_RESERVED_VALUE); - } - - cellEditor.setInput(labels); - - return cellEditor; - } - - /** {@inheritDoc} */ - @Override - protected void setValue(Object element, Object label) { - if(!(element instanceof AnnotationEntry)) { - return; - } - - if(isEditable && label == null) { - // New values, i.e values that have been entered into the text input field, and have not - // been selected from the combo box are indicated by a null value. Hence, fetch the text - // from the corresponding UI control. - label = ((CCombo)cellEditor.getControl()).getText(); - } - - if(label != null) { - super.setValue(element, - label.equals(UNSET_RESERVED_VALUE) ? null - : getLabelValueMapping((AnnotationEntry)element) - .getValueForLabel(label.toString())); - } - } - - /** {@inheritDoc} */ - @Override - protected Object getValue(Object element) { - return getLabel(element); - } - - /** - * Returns a {@link String} label for the given annotation (identified by its - * {@link AnnotationEntry}). - */ - public String getLabel(Object element) { - if(!(element instanceof AnnotationEntry)) { - return null; - } - - Object value = super.getValue(element); - - if(value != null) { - return getLabelValueMapping((AnnotationEntry)element).getLabelForValue(value); - } - - return null; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java deleted file mode 100644 index e42347692..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/EditingSupportFactory.java +++ /dev/null @@ -1,203 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2015 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EEnumLiteral; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.fortiss.tooling.base.annotation.valueprovider.DerivedAnnotationValueProviderBase; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor.EReferenceScope; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureValueProviderBase; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider; -import org.fortiss.tooling.base.annotation.valueprovider.ValueProviderBase; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IDerivedAnnotation; -import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView; - -/** - * Factory to build {@link AnnotationEditingSupportBase}-based {@link EditingSupport} for the - * {@link GenericAnnotationView}. - * - * @author barner - */ -public class EditingSupportFactory { - - /** - * Creates the {@link EditingSupport} that is directly based on - * {@link DerivedAnnotationValueProviderBase}. - */ - private static <T extends IDerivedAnnotation<?>, V extends DerivedAnnotationValueProviderBase<T>> - EditingSupport createEditingSupport4DerivedAnnotationValueProviderBase(V valueProvider, - ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, - T specification) throws Exception { - - if(!valueProvider.isEditableByUser()) { - return null; - } - - return createEditingSupport4EStructuralFeatureValueProviderBase( - (EStructuralFeatureValueProviderBase<T>)valueProvider, viewer, clazz, - specification); - } - - /** - * Creates the {@link EditingSupport} that is directly based on - * {@link EStructuralFeatureValueProviderBase}. - * - * @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} that is directly based on - * {@link EStructuralFeatureValueProviderBase}. - */ - private static <T extends IAnnotatedSpecification, V extends EStructuralFeatureValueProviderBase<T>> - EditingSupport createEditingSupport4EStructuralFeatureValueProviderBase(V valueProvider, - ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, - T specification) throws Exception { - - EStructuralFeature structuralFeature = valueProvider.getEStructuralFeatureDescriptor() - .getEStructuralFeature(specification); - - 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(); - if(structuralFeature.getUpperBound() == 1) { - - EReferenceScope eReferenceScope = eStructuralFeatureDescriptor.getEReferenceScope(); - boolean isSimpleType = (!(eType instanceof EEnum)) && (!(eType instanceof EClass)); - if(isSimpleType || ((eType instanceof EClass) && (eReferenceScope == null))) { - - return createEditingSupport4ValueProviderBase((ValueProviderBase<T>)valueProvider, - viewer, clazz, specification); - } - return new ComboBoxEditingSupport(viewer, clazz, specification, - eStructuralFeatureDescriptor); - } - - if(eType instanceof EClass) { - return new MultiValueAnnotationSelectionEditingSupport<EObject>(viewer, clazz, - specification, eStructuralFeatureDescriptor); - } else if(eType instanceof EEnum) { - return new MultiValueAnnotationSelectionEditingSupport<EEnumLiteral>(viewer, clazz, - specification, eStructuralFeatureDescriptor); - } - - return new MultiValueAnnotationTextEditingSupport<String>(viewer, clazz, specification, - eStructuralFeatureDescriptor); - } - - /** - * Creates the {@link EditingSupport} for value providers that are directly based on - * {@link ValueProviderBase}. - * - * @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} for value providers that are directly based on - * {@link ValueProviderBase}. - */ - @SuppressWarnings("unchecked") - private static <T extends IAnnotatedSpecification, V extends ValueProviderBase<T>> - EditingSupport createEditingSupport4ValueProviderBase(V valueProvider, - ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, - T specification) throws Exception { - - try { - valueProvider.updateInputChoice(viewer.getInput(), (Class<T>)clazz); - } catch(Exception e) { - // Use standard text editor as fall-back - valueProvider.setCurrentInputChoice(null); - } - - // Input is not restricted -> free editing in text cell - Collection<String> currentInputChoice = valueProvider.getCurrentInputChoice(); - if(currentInputChoice == null) { - - if(valueProvider.getAnnotationValue(specification) instanceof Boolean) { - return new CheckBoxEditingSupport(viewer, clazz); - } - - return new TextEditingSupport(viewer, clazz); - } - - // Input is restricted to concrete set of values - // (use SingleEnumAttributeValueProviderBase for EEnum types!) - List<String> fixedInputChoice = valueProvider.getFixedInputChoice(); - return new ComboBoxEditingSupport(viewer, clazz, fixedInputChoice.isEmpty()); - } - - /** - * Creates an {@link EditingSupport} for the given {@link IAnnotatedSpecification}. - * - * @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} 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) throws Exception { - - if(valueProvider instanceof DerivedAnnotationValueProviderBase<?>) { - return createEditingSupport4DerivedAnnotationValueProviderBase( - (DerivedAnnotationValueProviderBase)valueProvider, viewer, clazz, - (IDerivedAnnotation)specification); - } else if(valueProvider instanceof EStructuralFeatureValueProviderBase<?>) { - return createEditingSupport4EStructuralFeatureValueProviderBase( - (EStructuralFeatureValueProviderBase<T>)valueProvider, viewer, clazz, - specification); - } - if(valueProvider instanceof ValueProviderBase<?>) { - return createEditingSupport4ValueProviderBase((ValueProviderBase<T>)valueProvider, - viewer, clazz, specification); - } - - return null; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementCommentEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementCommentEditingSupport.java deleted file mode 100644 index 4be366924..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementCommentEditingSupport.java +++ /dev/null @@ -1,57 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.kernel.model.INamedCommentedElement; - -/** - * {@link EditingSupport} that allows to edit the comment of {@link INamedCommentedElement}s. - * - * @author barner - */ -public class ElementCommentEditingSupport extends ElementEditingSupportBase { - - /** Constructs a new {@link ElementCommentEditingSupport}. */ - public ElementCommentEditingSupport(ColumnViewer viewer) { - super(viewer); - } - - /** {@inheritDoc} */ - @Override - protected Object doGetValue(AnnotationEntry annotationEntry) { - IModelElement modelElement = annotationEntry.getModelElement(); - - if(modelElement instanceof INamedCommentedElement) { - return ((INamedCommentedElement)modelElement).getComment(); - } - - return null; - } - - /** {@inheritDoc} */ - @Override - protected void doSetValue(AnnotationEntry annotationEntry, String value) throws Exception { - IModelElement modelElement = annotationEntry.getModelElement(); - - if(modelElement instanceof INamedCommentedElement) { - ((INamedCommentedElement)modelElement).setComment(value); - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java deleted file mode 100644 index a6360f99e..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementEditingSupportBase.java +++ /dev/null @@ -1,55 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; - -/** - * Base class for {@link EditingSupport}s that directly access models element fields (and not the - * model elements {@link IAnnotatedSpecification}s). - * - * @author barner - */ -public class ElementEditingSupportBase extends TextEditingSupport { - - /** Constructs a new {@link ElementEditingSupportBase}. */ - 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); - } - - /** {@inheritDoc} */ - @Override - protected boolean canEdit(Object element) { - return true; - } - - /** {@inheritDoc} */ - @Override - protected void doSetValue(AnnotationEntry annotationEntry, Object value) throws Exception { - String strVal = value.toString(); - if(value.toString().equals(UNSET_RESERVED_VALUE)) { - strVal = null; - } - - // Forward to String-based variant of doSetValue() - doSetValue(annotationEntry, strVal); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java deleted file mode 100644 index 0dcaecf4b..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java +++ /dev/null @@ -1,57 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.kernel.model.INamedElement; - -/** - * {@link EditingSupport} that allows to edit the name of {@link INamedElement}s. - * - * @author barner - */ -public class ElementNameEditingSupport extends ElementEditingSupportBase { - - /** Constructs a new {@link ElementNameEditingSupport}. */ - public ElementNameEditingSupport(ColumnViewer viewer) { - super(viewer); - } - - /** {@inheritDoc} */ - @Override - protected Object doGetValue(AnnotationEntry annotationEntry) { - IModelElement modelElement = annotationEntry.getModelElement(); - - if(modelElement instanceof INamedElement) { - return ((INamedElement)modelElement).getName(); - } - - return null; - } - - /** {@inheritDoc} */ - @Override - protected void doSetValue(AnnotationEntry annotationEntry, String value) throws Exception { - IModelElement modelElement = annotationEntry.getModelElement(); - - if(modelElement instanceof INamedElement) { - ((INamedElement)modelElement).setName(value); - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationDialog.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationDialog.java deleted file mode 100644 index b0e0c72c2..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationDialog.java +++ /dev/null @@ -1,35 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; - -import org.eclipse.jface.window.Window; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; - -/** - * Interface for dialogs for editing {@link IAnnotatedSpecification}s that can hold multiple values. - * - * @author barner - */ -public interface IMultiValueAnnotationDialog<T> { - - /** Opens the dialog. See {@link Window#open()}. */ - public int open(); - - /** Returns the elements entered/selected in the dialog. */ - Collection<T> getElements(); -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationEditingSupport.java deleted file mode 100644 index 12e93b20e..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/IMultiValueAnnotationEditingSupport.java +++ /dev/null @@ -1,41 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; - -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IModelElement; - -/** - * Interface for {@link EditingSupport}s for annotations that can hold multiple values. - * - * @author barner - */ -public interface IMultiValueAnnotationEditingSupport<T> { - - /** - * Returns a {@link String} label for the given annotation (identified by its - * {@link AnnotationEntry}). - */ - String getLabel(Object element); - - /** Creates the {@link IMultiValueAnnotationDialog} to edit multiple values. */ - IMultiValueAnnotationDialog<T> createMultiEditingDialog(Composite parent, - IModelElement modelElement, Collection<T> values); -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/LabelValueMapping.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/LabelValueMapping.java deleted file mode 100644 index 3b7a9c611..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/LabelValueMapping.java +++ /dev/null @@ -1,215 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType; -import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeFullyQualifiedName; -import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeRelativeName; -import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement; - -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import org.eclipse.emf.common.util.BasicEList; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EEnumLiteral; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor.EReferenceScope; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.kernel.model.IIdLabeled; -import org.fortiss.tooling.kernel.model.INamedElement; -import org.fortiss.tooling.kernel.model.IProjectRootElement; -import org.fortiss.tooling.kernel.utils.HierarchicalNameComparator; - -/** - * Translates between the labels shown in a GUI and actual model elements (=values) (e.g., - * required to integrate {@link EReference}s into {@link ComboBoxEditingSupport} or - * {@link MultiValueAnnotationSelectionEditingSupport}. This class ensures that its label set is - * unique. - * - * @author barner - */ -public class LabelValueMapping { - - /** Map: label -> actual value */ - private Map<String, Object> labelToValueMap; - - /** {@link String}-based input choice */ - Collection<String> stringLabels; - - /** - * Constructs a {@link LabelValueMapping}. {@code eStructuralFeatureDescriptor} may be - * {@code null} in which case this translator acts as the identity-function. - */ - public LabelValueMapping(EStructuralFeatureDescriptor eStructuralFeatureDescriptor, - IAnnotatedSpecification specification, EObject modelElement, - Collection<String> stringLabels) { - - if(eStructuralFeatureDescriptor == null) { - this.stringLabels = stringLabels; - return; - } - - EClassifier eType = eStructuralFeatureDescriptor.getEType(specification); - if(eType instanceof EEnum) { - createEnumLabels((EEnum)eType, eStructuralFeatureDescriptor, modelElement); - } else if(eType instanceof EClass) { - - EObject root = null; - switch(eStructuralFeatureDescriptor.getEReferenceScope()) { - case PROJECT: - root = getParentElement(modelElement, IProjectRootElement.class, true); - if(root != null) { - // Get FileProject (type is not available in this plugin) - root = root.eContainer(); - } - break; - case MODEL: - root = getParentElement(modelElement, IProjectRootElement.class, true); - break; - case SUB_MODEL: - case STRICT_SUB_MODEL: - root = modelElement; - break; - } - - if(root == null) { - return; - } - - EList<EObject> values = new BasicEList<EObject>(); - if(eStructuralFeatureDescriptor.getEReferenceScope() == EReferenceScope.SUB_MODEL) { - values.add(root); - } - @SuppressWarnings("unchecked") Class<? extends EObject> instanceClass = - (Class<? extends EObject>)eType.getInstanceClass(); - for(EObject obj : getChildrenWithType(root, instanceClass)) { - if(eStructuralFeatureDescriptor.isAvailableObject(obj, specification, - modelElement)) { - values.add(obj); - } - } - - Collections.sort(values, new HierarchicalNameComparator()); - labelToValueMap = new LinkedHashMap<String, Object>(); - for(Object v : values) { - if(v instanceof INamedElement) { - if(root instanceof INamedElement) { - String label = computeRelativeName((INamedElement)root, (INamedElement)v); - if(eStructuralFeatureDescriptor.getEReferenceScope() - .equals(EStructuralFeatureDescriptor.EReferenceScope.PROJECT)) { - // Strip explicit qualification of project name - int i = label.indexOf("."); - if(i != -1) { - label = label.substring(i + 1); - } - } - addLabelValuePair(label, v); - } else { - addLabelValuePair(computeFullyQualifiedName((INamedElement)v), v); - } - } else { - addLabelValuePair(v.toString(), v); - } - } - } - } - - /** - * Creates the enum labels based on the literals that are given by the - * {@link EStructuralFeatureDescriptor}. - */ - private void createEnumLabels(EEnum eType, - EStructuralFeatureDescriptor eStructuralFeatureDescriptor, EObject modelElement) { - labelToValueMap = new LinkedHashMap<String, Object>(); - Set<String> enumValues = new TreeSet<String>(); - Collection<EEnumLiteral> literalsToShow = - eStructuralFeatureDescriptor.getEnumLiterals(eType, modelElement); - for(EEnumLiteral e : literalsToShow) { - enumValues.add(e.getName()); - addLabelValuePair(e.getName(), e.getInstance()); - } - } - - /** Returns the set of labels managed by this {@link LabelValueMapping}. */ - public Collection<String> getLabels() { - if(labelToValueMap == null) { - return stringLabels; - } - - return labelToValueMap.keySet(); - } - - /** - * Adds a label / value pair to this {@link LabelValueMapping}. This methods ensures that the - * label set managed by this {@link LabelValueMapping} unique. - */ - private void addLabelValuePair(String label, Object value) { - // Append IDs for IIdLabeled objects - if(value instanceof IIdLabeled) { - label += " [Id=" + ((IIdLabeled)value).getId() + "]"; - } - - // Be extra careful and add unique suffix if required. - String prefix = new String(label); - int i = 1; - while(labelToValueMap.keySet().contains(label)) { - label = prefix + " (" + i + ")"; - i++; - } - label = prefix; - - labelToValueMap.put(label, value); - } - - /** Translates a value into the corresponding label. */ - public String getLabelForValue(Object value) { - if(labelToValueMap == null) { - return value != null ? value.toString() : ""; - } - - for(String key : labelToValueMap.keySet()) { - Object currValue = labelToValueMap.get(key); - - if(value == currValue) { - return key; - } - } - - // In case the label could not be found, return a string representation of the value. This - // is useful to implement custom label providers for model elements are edited in combo - // boxes. - return value != null ? value.toString() : ""; - } - - /** Translates a label into the corresponding value. */ - public Object getValueForLabel(String label) { - if(labelToValueMap == null) { - return label; - } - - return labelToValueMap.get(label); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationDialogBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationDialogBase.java deleted file mode 100644 index 9d9e6e10e..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationDialogBase.java +++ /dev/null @@ -1,129 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import static org.eclipse.emf.ecore.ETypedElement.UNBOUNDED_MULTIPLICITY; -import static org.eclipse.emf.ecore.ETypedElement.UNSPECIFIED_MULTIPLICITY; - -import java.util.Collection; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; - -/** - * Base class for dialogs to select/edit values of multi-valued annotations. - * - * @author barner - */ -public abstract class MultiValueAnnotationDialogBase<T> extends Dialog - implements IMultiValueAnnotationDialog<T> { - - /** Lower multiplicity bound. */ - private int lowerMultiplicityBound; - - /** Upper multiplicity bound. */ - private int upperMultiplicityBound; - - /** Name of action performed in this dialog. */ - private String actionName; - - /** The collection of elements selected/edited using this dialog. */ - private Collection<T> elements; - - /** Constructs a new {@link MultiValueAnnotationDialogBase}. */ - public MultiValueAnnotationDialogBase(String actionName, int lowerMultiplicityBound, - int upperMultiplicityBound) { - super((Shell)null); - this.actionName = actionName; - this.lowerMultiplicityBound = lowerMultiplicityBound; - this.upperMultiplicityBound = upperMultiplicityBound; - } - - /** {@inheritDoc} */ - @Override - protected final Control createButtonBar(Composite parent) { - Control ctrl = super.createButtonBar(parent); - updateOkButton(); - - return ctrl; - } - - /** Helper to select the right number for "element". */ - private String titleElementStringHelper(int n) { - return n != 1 ? "elements" : "element"; - } - - /** {@inheritDoc} */ - @Override - protected final void configureShell(Shell newShell) { - super.configureShell(newShell); - String title; - if(lowerMultiplicityBound == UNSPECIFIED_MULTIPLICITY || lowerMultiplicityBound == 0) { - if(upperMultiplicityBound == UNSPECIFIED_MULTIPLICITY || - upperMultiplicityBound == UNBOUNDED_MULTIPLICITY) { - title = actionName + " multiple elements"; - } else { - title = actionName + " at most " + upperMultiplicityBound + " " + - titleElementStringHelper(upperMultiplicityBound); - } - } else { - if(upperMultiplicityBound == UNSPECIFIED_MULTIPLICITY || - upperMultiplicityBound == UNBOUNDED_MULTIPLICITY) { - title = actionName + " at least " + lowerMultiplicityBound + " " + - titleElementStringHelper(lowerMultiplicityBound); - } else { - title = actionName + " " + lowerMultiplicityBound + " to " + - upperMultiplicityBound + " " + - titleElementStringHelper(upperMultiplicityBound); - } - } - newShell.setText(title); - } - - /** Enables the Ok button iff the multiplicity constraints are met. */ - protected final void updateOkButton() { - Button okButton = getButton(IDialogConstants.OK_ID); - - int numElements = getElementsFromDialog().size(); - boolean lowerBoundOk = lowerMultiplicityBound == UNSPECIFIED_MULTIPLICITY || - numElements >= lowerMultiplicityBound; - boolean upperBoundOk = upperMultiplicityBound == UNSPECIFIED_MULTIPLICITY || - upperMultiplicityBound == UNBOUNDED_MULTIPLICITY || - numElements <= upperMultiplicityBound; - okButton.setEnabled(lowerBoundOk && upperBoundOk); - } - - /** {@inheritDoc} */ - @Override - protected final void okPressed() { - elements = getElementsFromDialog(); - - super.okPressed(); - } - - /** {@inheritDoc} */ - @Override - public final Collection<T> getElements() { - return elements; - } - - /** Returns the current {@link Collection} of elements from the corresponding widget of the editor. */ - protected abstract Collection<T> getElementsFromDialog(); -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationEditingSupportBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationEditingSupportBase.java deleted file mode 100644 index ac228c1a4..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationEditingSupportBase.java +++ /dev/null @@ -1,163 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.DialogCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.model.INamedElement; -import org.fortiss.tooling.kernel.service.IPersistencyService; - -/** - * Base class for {@link EditingSupport}s for annotations that can hold multiple values. - * - * @author barner - */ -public abstract class MultiValueAnnotationEditingSupportBase<T> extends AnnotationEditingSupportBase - implements IMultiValueAnnotationEditingSupport<T> { - - /** The underlying annotation */ - protected IAnnotatedSpecification specification; - - /** Annotation's {@link EStructuralFeatureDescriptor}. */ - protected EStructuralFeatureDescriptor eStructuralFeatureDescriptor; - - /** Constructs a new {@link MultiValueAnnotationEditingSupportBase}. */ - public MultiValueAnnotationEditingSupportBase(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { - super(viewer, clazz); - - this.specification = specification; - this.eStructuralFeatureDescriptor = eStructuralFeatureDescriptor; - } - - /** {@inheritDoc} */ - @Override - protected CellEditor getCellEditor(Object element) { - - if(!(element instanceof AnnotationEntry)) { - return null; - } - AnnotationEntry entry = (AnnotationEntry)element; - - Object value = entry.getSpecificationValue(specClass); - if(!(value instanceof Collection<?>)) { - return null; - } - - Composite parent = (Composite)getViewer().getControl(); - @SuppressWarnings("unchecked") IMultiValueAnnotationDialog<T> dialog = - createMultiEditingDialog(parent, entry.getModelElement(), (Collection<T>)value); - - return new MultiValueAnnotationCellEditor(parent, dialog); - } - - /** {@inheritDoc} */ - @Override - protected boolean canEdit(Object element) { - return true; - } - - /** {@inheritDoc} */ - @Override - protected Object getValue(Object element) { - return getLabel(element); - } - - /** {@inheritDoc} */ - @Override - public String getLabel(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry entry = (AnnotationEntry)element; - - Object value = entry.getSpecificationValue(specClass); - - if(value instanceof Collection<?>) { - StringBuffer valueCollectionString = new StringBuffer(); - for(Iterator<?> iter = ((Collection<?>)value).iterator(); iter.hasNext();) { - Object v = iter.next(); - if(v instanceof INamedElement) { - valueCollectionString.append(((INamedElement)v).getName()); - } else { - valueCollectionString.append(v != null ? v.toString() : "<null>"); - } - if(iter.hasNext()) { - valueCollectionString.append(", "); - } - } - return "[" + valueCollectionString + "]"; - } - } - return "[]"; - } - - /** {@inheritDoc} */ - @Override - protected void setValue(Object element, final Object value) { - // Writes back into the model the collection of selected elements - if(element instanceof AnnotationEntry && value instanceof Collection<?>) { - final AnnotationEntry entry = (AnnotationEntry)element; - - ITopLevelElement modelContext = IPersistencyService.getInstance() - .getTopLevelElementFor(entry.getModelElement()); - modelContext.runAsCommand(new Runnable() { - - @Override - public void run() { - try { - entry.setSpecificationValue(value, specClass); - } catch(Exception e) { - return; - } - } - }); - } - } - - /** {@link CellEditor} that opens a dialog to edit a multi-valued annotation. */ - private class MultiValueAnnotationCellEditor extends DialogCellEditor { - - /** The dialog opened by this cell editor. */ - private IMultiValueAnnotationDialog<T> dialog; - - /** Constructor. */ - public MultiValueAnnotationCellEditor(Composite parent, - IMultiValueAnnotationDialog<T> dialog) { - super(parent); - - this.dialog = dialog; - } - - /** {@inheritDoc} */ - @Override - protected Object openDialogBox(Control cellEditorWindow) { - - dialog.open(); - return dialog.getElements(); - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionDialog.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionDialog.java deleted file mode 100644 index eb493c084..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionDialog.java +++ /dev/null @@ -1,143 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.mihalis.opal.itemSelector.DLItem; -import org.mihalis.opal.itemSelector.DualList; -import org.mihalis.opal.itemSelector.SelectionChangeEvent; -import org.mihalis.opal.itemSelector.SelectionChangeListener; - -/** - * Dialog that allows to select multiple values - * - * @author barner - */ -public class MultiValueAnnotationSelectionDialog<T> extends MultiValueAnnotationDialogBase<T> { - - /** Element selection dialog */ - private DualList dl; - - /** Mapping: label shown in GUI -> actual value. */ - private LabelValueMapping labelValueMapping; - - /** The {@link Collection} of initially selected elements. */ - private Collection<T> initialElements; - - /** Constructs a new {@link MultiValueAnnotationSelectionDialog}. */ - public MultiValueAnnotationSelectionDialog(LabelValueMapping labelValueMapping, - EStructuralFeature eStructuralFeature, Collection<T> initialElements) { - super("Select", eStructuralFeature.getLowerBound(), eStructuralFeature.getUpperBound()); - this.labelValueMapping = labelValueMapping; - this.initialElements = initialElements; - - setShellStyle(getShellStyle() | SWT.RESIZE); - } - - /** {@inheritDoc} */ - @Override - protected Composite createDialogArea(Composite parent) { - /* Generate the dialog and its layout */ - Composite area = (Composite)super.createDialogArea(parent); - area.setLayout(new FillLayout()); - - dl = new LabelValueMappingDualList(area, initialElements, labelValueMapping); - dl.addSelectionChangeListener(new SelectionChangeListener() { - @Override - public void widgetSelected(SelectionChangeEvent e) { - updateOkButton(); - } - }); - - return area; - } - - /** {@inheritDoc} */ - @Override - protected Point getInitialSize() { - return new Point(800, 400); - } - - /** {@inheritDoc} */ - @Override - @SuppressWarnings("unchecked") - protected Collection<T> getElementsFromDialog() { - List<T> elements = new ArrayList<>(); - for(DLItem item : dl.getSelection()) { - if(item != null) { - elements.add((T)labelValueMapping.getValueForLabel(item.getText())); - } - } - return elements; - } - - /** Extension of {@link DualList} that is initialized from {@link LabelValueMapping}s. */ - private class LabelValueMappingDualList extends DualList { - - /** - * Constructs a new {@link LabelValueMappingDualList}. - * - * @param parent - * Parent {@link Composite} widget - * @param selectedElements - * Collection of elements that are selected initially - * @param labelValueMapping - * {@link LabelValueMapping} required to populate this - * {@link LabelValueMappingDualList}. - */ - public LabelValueMappingDualList(Composite parent, Collection<?> selectedElements, - LabelValueMapping labelValueMapping) { - - super(parent, SWT.NONE); - - List<String> labels = new ArrayList<String>(); - labels.addAll(labelValueMapping.getLabels()); - - for(Object selectedItem : selectedElements) { - String label = labelValueMapping.getLabelForValue(selectedItem); - DLItem item = new DLItem(label); - add(item); - selectDoNotFireEvent(0); - remove(item); - labels.remove(label); - } - - for(String label : labels) { - DLItem item = new DLItem(label); - add(item); - } - } - - /** {@inheritDoc} */ - @Override - public void deselectAll(final boolean shouldFireEvents) { - super.deselectAll(shouldFireEvents); - - // Required to issue a selection changed event after all elements have actually been - // deselected. This is required for the invocation of - // MultiSelectionDialog.updateOkButton() to work correctly. - super.deselectAll(false); - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionEditingSupport.java deleted file mode 100644 index a4c3c3f9c..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationSelectionEditingSupport.java +++ /dev/null @@ -1,57 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; - -/** - * {@link EditingSupport} that supports the selection of multiple values. - * - * @author barner - */ -public class MultiValueAnnotationSelectionEditingSupport<T> - extends MultiValueAnnotationEditingSupportBase<T> { - - /** Constructs a new {@link MultiValueAnnotationSelectionEditingSupport}. */ - public MultiValueAnnotationSelectionEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { - super(viewer, clazz, specification, eStructuralFeatureDescriptor); - } - - /** {@inheritDoc} */ - @Override - public IMultiValueAnnotationDialog<T> createMultiEditingDialog(Composite parent, - IModelElement modelElement, Collection<T> values) { - - LabelValueMapping labelValueMapping = new LabelValueMapping(eStructuralFeatureDescriptor, - specification, modelElement, null); - - EStructuralFeature eStructuralFeature = - eStructuralFeatureDescriptor.getEStructuralFeature(specification); - - return new MultiValueAnnotationSelectionDialog<T>(labelValueMapping, eStructuralFeature, - values); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingDialog.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingDialog.java deleted file mode 100644 index 50cf3bb99..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingDialog.java +++ /dev/null @@ -1,244 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import static java.lang.Integer.compare; -import static java.lang.Math.min; -import static java.util.Arrays.asList; -import static java.util.Arrays.stream; - -import java.util.Collection; -import java.util.OptionalInt; -import java.util.stream.IntStream; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SegmentEvent; -import org.eclipse.swt.events.SegmentListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Text; - -/** - * Dialog that allows to edit multiple values - * - * @author barner - */ -public class MultiValueAnnotationTextEditingDialog<T> extends MultiValueAnnotationDialogBase<T> { - - /** The {@link Text} into which input is entered. */ - private Text textInput; - - /** {@link List} containing the current input. */ - private List list; - - /** {@link Button} to add the current value of {@link #textInput} to {@link #list}. */ - private Button addButton; - - /** {@link Button} to remove the currently selected item from {@link #list}. */ - private Button removeButton; - - /** {@link Button} to move up the currently selected item of {@link #list}. */ - private Button upButton; - - /** {@link Button} to move down the currently selected item of {@link #list}. */ - private Button downButton; - - /** Flag if dialog is currently set up in {@link #createDialogArea(Composite)}. */ - private boolean isCreateDialogArea; - - /** Underlying {@link EAttribute}. */ - private EAttribute eAttribute; - - /** The {@link Collection} of initial values. */ - private Collection<T> initialValues; - - /** Constructs a new {@link MultiValueAnnotationTextEditingDialog}. */ - public MultiValueAnnotationTextEditingDialog(EAttribute eAttribute, - Collection<T> initialValues) { - super("Add", eAttribute.getLowerBound(), eAttribute.getUpperBound()); - this.eAttribute = eAttribute; - this.initialValues = initialValues; - } - - /** Returns the {@link EFactory} for the underlying {@link #eAttribute}. */ - protected EFactory getEFactory() { - return eAttribute.getEType().getEPackage().getEFactoryInstance(); - } - - /** Refreshes the status of the dialog's UI elements. */ - protected void refresh() { - if(isCreateDialogArea) { - return; - } - - boolean isValidText = true; - try { - EFactory eFactory = getEFactory(); - eFactory.createFromString(eAttribute.getEAttributeType(), textInput.getText()); - } catch(Exception e) { - isValidText = false; - } - - addButton.setEnabled(isValidText); - - OptionalInt min = stream(list.getSelectionIndices()).reduce(Integer::min); - OptionalInt max = stream(list.getSelectionIndices()).reduce(Integer::max); - removeButton.setEnabled(min.isPresent()); - - upButton.setEnabled(min.isPresent() && min.getAsInt() > 0); - downButton.setEnabled(max.isPresent() && max.getAsInt() < list.getItemCount() - 1); - } - - /** {@inheritDoc} */ - @Override - protected Composite createDialogArea(Composite parent) { - isCreateDialogArea = true; - Composite area = (Composite)super.createDialogArea(parent); - area.setLayout(new GridLayout(2, false)); - - textInput = new Text(area, SWT.BORDER | SWT.LEFT); - GridData gd_Text = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1); - gd_Text.widthHint = 300; - gd_Text.minimumWidth = 300; - textInput.setLayoutData(gd_Text); - textInput.addSegmentListener(new SegmentListener() { - /** {@inheritDoc} */ - @Override - public void getSegments(SegmentEvent event) { - refresh(); - } - }); - - addButton = new Button(area, SWT.PUSH); - GridData gd_Buttons = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); - gd_Buttons.widthHint = 100; - gd_Buttons.minimumWidth = 100; - addButton.setLayoutData(gd_Buttons); - addButton.setText("Add"); - - addButton.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - list.add(textInput.getText()); - textInput.setText(""); - refresh(); - } - }); - - list = new List(area, SWT.BORDER | SWT.LEFT | SWT.MULTI); - GridData gd_List = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 4); - gd_List.minimumWidth = 310; - gd_List.heightHint = 310; - list.setLayoutData(gd_List); - list.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - refresh(); - } - }); - for(Object value : initialValues) { - EFactory eFactory = getEFactory(); - String valueLabel = eFactory.convertToString(eAttribute.getEAttributeType(), value); - list.add(valueLabel); - } - - removeButton = new Button(area, SWT.PUSH); - removeButton.setLayoutData(gd_Buttons); - removeButton.setText("Remove"); - removeButton.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - int[] selectionIndices = list.getSelectionIndices(); - int index = -1; - if(selectionIndices.length == 1) { - index = selectionIndices[0]; - } - for(int i : selectionIndices) { - list.remove(i); - } - list.setSelection(min(index, list.getItemCount())); - refresh(); - } - }); - - upButton = new Button(area, SWT.PUSH); - upButton.setLayoutData(gd_Buttons); - upButton.setText("Up"); - upButton.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - stream(list.getSelectionIndices()).sorted().forEach(i -> { - String swap = list.getItem(i - 1); - list.setItem(i - 1, list.getItem(i)); - list.setItem(i, swap); - }); - IntStream oldIndices = stream(list.getSelectionIndices()); - list.deselectAll(); - list.select(oldIndices.map(i -> i - 1).toArray()); - refresh(); - } - }); - - downButton = new Button(area, SWT.PUSH); - downButton.setLayoutData(gd_Buttons); - downButton.setText("Down"); - downButton.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - stream(list.getSelectionIndices()).boxed().sorted((i1, i2) -> compare(i2, i1)) - .forEach(i -> { - String swap = list.getItem(i + 1); - list.setItem(i + 1, list.getItem(i)); - list.setItem(i, swap); - }); - IntStream oldIndices = stream(list.getSelectionIndices()); - list.deselectAll(); - list.select(oldIndices.map(i -> i + 1).toArray()); - refresh(); - } - }); - - isCreateDialogArea = false; - refresh(); - return area; - } - - /** {@inheritDoc} */ - @Override - public void create() { - super.create(); - getShell().setDefaultButton(addButton); - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Override - protected Collection<T> getElementsFromDialog() { - return (Collection<T>)asList(list.getItems()); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingSupport.java deleted file mode 100644 index 38c780819..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/MultiValueAnnotationTextEditingSupport.java +++ /dev/null @@ -1,54 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2018 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import java.util.Collection; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; - -/** - * {@link EditingSupport} for textual editing of multi-value annotations. - * - * @author barner - */ -public class MultiValueAnnotationTextEditingSupport<T> - extends MultiValueAnnotationEditingSupportBase<T> { - - /** Constructs a new {@link MultiValueAnnotationTextEditingSupport}. */ - public MultiValueAnnotationTextEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, IAnnotatedSpecification specification, - EStructuralFeatureDescriptor eStructuralFeatureDescriptor) { - super(viewer, clazz, specification, eStructuralFeatureDescriptor); - } - - /** {@inheritDoc} */ - @Override - public IMultiValueAnnotationDialog<T> createMultiEditingDialog(Composite parent, - IModelElement modelElement, Collection<T> values) { - - EStructuralFeature eStructuralFeature = - eStructuralFeatureDescriptor.getEStructuralFeature(specification); - - return new MultiValueAnnotationTextEditingDialog<T>((EAttribute)eStructuralFeature, values); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java deleted file mode 100644 index e761ea393..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/TextEditingSupport.java +++ /dev/null @@ -1,79 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.editingsupport; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; - -/** - * {@link EditingSupport} providing a simple text input field to display an manipulate - * {@link IAnnotatedSpecification}s. It is used in all cases where no more specialized - * {@link EditingSupport} is available. - * - * @author diewald - */ -public class TextEditingSupport extends AnnotationEditingSupportBase { - - /** Text cell editor. */ - protected TextCellEditor cellEditor = null; - - /** Constructs a new {@link TextEditingSupport}. */ - public TextEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> specClass) { - super(viewer, specClass); - - cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE); - } - - /** {@inheritDoc} */ - @Override - protected CellEditor getCellEditor(Object element) { - return cellEditor; - } - - /** {@inheritDoc} */ - @Override - protected Object getValue(Object element) { - // This method is triggered from several methods in EditingSupport, which - for this - // TextEditingSupport - passes its result to TextCellEditor.doSetValue() which expects a - // non-null String. - Object rval = super.getValue(element); - - return (rval != null) ? rval.toString() : ""; - } - - /** {@inheritDoc} */ - @Override - protected void doSetValue(AnnotationEntry annotationEntry, String value) throws Exception { - super.doSetValue(annotationEntry, value.equals(UNSET_RESERVED_VALUE) ? null : value); - } - - /** {@inheritDoc} */ - @Override - protected void doSetValue(AnnotationEntry annotationEntry, Object value) throws Exception { - if(value.toString().equals(UNSET_RESERVED_VALUE)) { - value = null; - } - - super.doSetValue(annotationEntry, value); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/package.html b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/package.html deleted file mode 100644 index 1d58e7add..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/editingsupport/package.html +++ /dev/null @@ -1,4 +0,0 @@ -<!-- (c) 2017 fortiss GmbH --> -<body> -Editing support to embed annotations into table-based annotation views. When a users edits the value of an annotation, the editing support replaces the label provider that has been showing the current value of the annotation and provides a widget to set a new value. -</body> diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings deleted file mode 100644 index 63461080b..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings +++ /dev/null @@ -1,7 +0,0 @@ -AnnotationLabelProvider.java 27d5bbb02d122e603abd158fa5a1fb39e79b0dc5 GREEN -CheckBoxLabelProvider.java 894ef9b2ae1a86d8916c8872da1d94b9e3eeb7bf GREEN -ElementCommentLabelProvider.java 76aa6e9b930ce5680607852fd776172942c89ce5 GREEN -ElementLabelProviderBase.java f33502f73033ebdf30316df627e8a9c87e7d1b28 GREEN -ElementNameLabelProvider.java 897296ac8318b6dfdea9c50fc73aaeea23c2fffa GREEN -LabelProviderBase.java d8c4dae010246c94bb8d1596bd60f7af8d1ad7c6 GREEN -LabelProviderFactory.java 45e2d0ad0449182b9f8196257b20f0dba3c27f35 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java deleted file mode 100644 index 27d5bbb02..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java +++ /dev/null @@ -1,135 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.graphics.Color; -import org.eclipse.wb.swt.SWTResourceManager; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IDerivedAnnotation; -import org.fortiss.tooling.base.ui.annotation.editingsupport.ComboBoxEditingSupport; -import org.fortiss.tooling.base.ui.annotation.editingsupport.IMultiValueAnnotationEditingSupport; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; - -/** - * This class provides the text labels shown in {@link TableViewer}-based annotation views when no - * item is selected for editing. - * - * @author diewald, barner - */ -public class AnnotationLabelProvider extends LabelProviderBase { - - /** Background color for annotations that cannot be edited (and that are not derived). */ - public static final Color READ_ONLY_ANNOTATION_BACKGROUND_COLOR = - SWTResourceManager.getColor(230, 230, 230); - - /** Background color for derived (computed) annotations. */ - private static final Color DERIVED_ANNOTATION_BACKGROUND_COLOR = - SWTResourceManager.getColor(200, 240, 250); - - /** Type of annotation that is displayed by this {@link AnnotationLabelProvider}. */ - protected Class<? extends IAnnotatedSpecification> clazz; - - /** - * {@link EditingSupport} of the column to for which this {@link AnnotationLabelProvider} - * provides the label. - */ - EditingSupport editingSupport; - - /** - * Creates an {@link AnnotationLabelProvider} for a given annotation class. - * - * @param clazz - * Type of annotation that is displayed by this {@link AnnotationLabelProvider}. - * @param viewPart - * view required to retrieve the selected elements - * @param editingSupport - * {@link EditingSupport} of column for which the new {@link AnnotationLabelProvider} - * should provided the label. - */ - public AnnotationLabelProvider(Class<? extends IAnnotatedSpecification> clazz, - IAnnotationViewPart viewPart, EditingSupport editingSupport) { - super(viewPart); - this.clazz = clazz; - this.editingSupport = editingSupport; - } - - /** {@inheritDoc} */ - @Override - public String getText(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry annotationEntry = (AnnotationEntry)element; - - Object value = null; - try { - value = annotationEntry.getSpecificationValue(clazz); - } catch(Exception e) { - return ""; - } - - if(editingSupport instanceof ComboBoxEditingSupport) { - return ((ComboBoxEditingSupport)editingSupport).getLabel(element); - } else if(editingSupport instanceof IMultiValueAnnotationEditingSupport) { - return ((IMultiValueAnnotationEditingSupport<?>)editingSupport).getLabel(element); - } - - return (value != null) ? value.toString() : ""; - } - return ""; - } - - /** {@inheritDoc} */ - @Override - public Color getBackground(Object element) { - Color color = super.getBackground(element); - if(element instanceof AnnotationEntry) { - AnnotationEntry annotationEntry = (AnnotationEntry)element; - if(annotationEntry.getModelElement().equals(viewPart.getCurrentlySelectedObject())) { - return color; - } - - return getAnnotatationBackgroundColor(annotationEntry, clazz, color); - } - return color; - } - - /** - * Returns the background {@link Color} for the {@link AnnotationEntry} of the given - * {@code type}. The method returns dedicated colors for special cases such as read-only or - * "derived" annotations. Otherwise, the provided {@code defaultColor} is returned. - */ - public static Color getAnnotatationBackgroundColor(AnnotationEntry annotationEntry, - Class<? extends IAnnotatedSpecification> type, Color defaultColor) { - if(annotationEntry.canEdit(type)) { - return defaultColor; - } - if(IDerivedAnnotation.class.isAssignableFrom(type) && - annotationEntry.getSpecificationValue(type) != null) { - return DERIVED_ANNOTATION_BACKGROUND_COLOR; - } - return READ_ONLY_ANNOTATION_BACKGROUND_COLOR; - } - - /** - * Returns the type (class) of the {@link IAnnotatedSpecification} that is handled by - * {@code this} {@link AnnotationLabelProvider}. - */ - public Class<? extends IAnnotatedSpecification> getAnnotationType() { - return clazz; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java deleted file mode 100644 index 894ef9b2a..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2014 Tom Schindl and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Florian Potschka <signalrauschen@gmail.com> - Bug 260061 - * Alexander Ljungberg <siker@norwinter.com> - Bug 260061 - * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565 - * Alexander Mark Diewald <diewald@fortiss.org> - *******************************************************************************/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.CHECKED_LABEL; -import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.UNCHECKED_LABEL; -import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.useTextIcon; - -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.graphics.Image; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; - -/** - * <p> - * A {@link ColumnLabelProvider} for annotations that displays checkboxes indicating the value of - * annotations that contain boolean values. - * </p> - * <p> - * This implementation uses 'screenshot' {@link Image}s of the checkboxes, since {@link TableViewer} - * is not able to display SWT widgets when a cell is not edited. Since the screenshots are made - * during runtime, the resulting images fit the underlying OS. - * </p> - * - * @author diewald - */ -public class CheckBoxLabelProvider extends AnnotationLabelProvider { - - /** Constructor. */ - public CheckBoxLabelProvider(Class<? extends IAnnotatedSpecification> clazz, - IAnnotationViewPart viewPart, EditingSupport editingSupport) { - super(clazz, viewPart, editingSupport); - } - - /** {@inheritDoc} */ - @Override - public String getText(Object element) { - if(useTextIcon() && element instanceof AnnotationEntry && - ((AnnotationEntry)element).canEdit(clazz)) { - return isChecked(element) ? CHECKED_LABEL : UNCHECKED_LABEL; - } - - return null; - } - - /** {@inheritDoc} */ - @Override - public Image getImage(Object element) { - if(element instanceof AnnotationEntry) { - boolean enabled = ((AnnotationEntry)element).canEdit(clazz); - return org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider - .getImage(isChecked(element), enabled); - } - return null; - } - - /** - * Determines whether the boolean value is 'true' or 'false'. Used to determine the 'checked' - * status of the checkbox. - */ - protected boolean isChecked(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry annotationEntry = (AnnotationEntry)element; - - Object value = null; - try { - value = annotationEntry.getSpecificationValue(clazz); - } catch(Exception e) { - return false; - } - if(value != null) { - // It is already known that the value is a boolean. - return (Boolean)value; - } - } - return false; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementCommentLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementCommentLabelProvider.java deleted file mode 100644 index 76aa6e9b9..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementCommentLabelProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; -import org.fortiss.tooling.kernel.model.INamedCommentedElement; -import org.fortiss.tooling.kernel.model.INamedElement; - -/** - * Label provider that uses the comments of {@link INamedElement}s as column labels. - * - * @author barner - */ -public class ElementCommentLabelProvider extends ElementLabelProviderBase { - /** Creates a new {@link ElementCommentLabelProvider}. */ - public ElementCommentLabelProvider(IAnnotationViewPart viewPart) { - super(viewPart); - } - - /** {@inheritDoc} */ - @Override - public String getText(IModelElement modelElement) { - if(modelElement instanceof INamedCommentedElement) { - return ((INamedCommentedElement)modelElement).getComment(); - } - - return null; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementLabelProviderBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementLabelProviderBase.java deleted file mode 100644 index f33502f73..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementLabelProviderBase.java +++ /dev/null @@ -1,50 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2015 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; - -/** - * Base class for label providers that access attributes of {@link IModelElement}s (instead of - * referring to {@link IAnnotatedSpecification}s). - * - * @author Simon - */ -public abstract class ElementLabelProviderBase extends LabelProviderBase { - - /** Creates a new {@link ElementLabelProviderBase}. */ - public ElementLabelProviderBase(IAnnotationViewPart viewPart) { - super(viewPart); - } - - /** {@inheritDoc} */ - @Override - public String getText(Object element) { - if(!(element instanceof AnnotationEntry)) { - return ""; - } - - String text = getText(((AnnotationEntry)element).getModelElement()); - - return (text != null) ? text : ""; - } - - /** Returns the text for the label for the given {@link IModelElement}. */ - protected abstract String getText(IModelElement modelElement); -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementNameLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementNameLabelProvider.java deleted file mode 100644 index 897296ac8..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/ElementNameLabelProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; -import org.fortiss.tooling.kernel.model.INamedElement; - -/** - * Label provider that uses the names of {@link INamedElement}s as column labels. - * - * @author barner - */ -public class ElementNameLabelProvider extends ElementLabelProviderBase { - /** Creates a new {@link ElementNameLabelProvider}. */ - public ElementNameLabelProvider(IAnnotationViewPart viewPart) { - super(viewPart); - } - - /** {@inheritDoc} */ - @Override - protected String getText(IModelElement modelElement) { - if(modelElement instanceof INamedElement) { - return ((INamedElement)modelElement).getName(); - } - - return null; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderBase.java deleted file mode 100644 index d8c4dae01..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderBase.java +++ /dev/null @@ -1,106 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import static org.eclipse.wb.swt.SWTResourceManager.getColor; - -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; -import org.fortiss.tooling.kernel.model.IIdLabeled; -import org.fortiss.tooling.kernel.model.INamedElement; - -/** - * Base class for {@link ColumnLabelProvider}s. The text labels are shown in {@link TableViewer} - * -based annotation views when no item is selected for editing. - * - * @author barner - */ -public class LabelProviderBase extends ColumnLabelProvider { - - /** Color used to highlight currently selected row. */ - private static final Color HIGHLIGHT_SELECTED_ROW_COLOR = getColor(0, 255, 0); - - /** The view part in which this {@link LabelProviderBase} is used. */ - protected final IAnnotationViewPart viewPart; - - /** Creates a new {@link LabelProviderBase} for a given parent {@code viewPart}. */ - public LabelProviderBase(IAnnotationViewPart viewPart) { - this.viewPart = viewPart; - } - - /** {@inheritDoc} */ - @Override - public Color getBackground(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry data = (AnnotationEntry)element; - if(data.getModelElement().equals(viewPart.getCurrentlySelectedObject())) { - return HIGHLIGHT_SELECTED_ROW_COLOR; - } - } - return super.getBackground(element); - } - - /** {@inheritDoc} */ - @Override - public String getToolTipText(Object element) { - if(!(element instanceof AnnotationEntry)) { - return null; - } - - IModelElement modelElement = ((AnnotationEntry)element).getModelElement(); - - String rval = null; - - if(modelElement instanceof INamedElement) { - rval = ((INamedElement)modelElement).getName(); - } - - if(modelElement instanceof IIdLabeled) { - String id = "[Id=" + ((IIdLabeled)modelElement).getId() + "]"; - - if(rval != null) { - rval += " " + id; - } else { - rval = id; - } - } - - return rval; - } - - /** {@inheritDoc} */ - @Override - public Point getToolTipShift(Object object) { - return new Point(15, 0); - } - - /** {@inheritDoc} */ - @Override - public int getToolTipDisplayDelayTime(Object object) { - return 50; // msec - } - - /** {@inheritDoc} */ - @Override - public int getToolTipTimeDisplayed(Object object) { - return 5000; // msec - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java deleted file mode 100644 index 45e2d0ad0..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/LabelProviderFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2015 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.labelprovider; - -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; -import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView; - -/** - * Factory to build {@link LabelProviderBase}-based {@link ColumnLabelProvider}s for the - * {@link GenericAnnotationView}. - * - * @author barner - */ -public class LabelProviderFactory { - - /** - * Creates an {@link ColumnLabelProvider} for the given {@link IAnnotatedSpecification}. - * - * @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( - IAnnotationValueProvider<T> valueProvider, IAnnotationViewPart viewPart, - ColumnViewer columnViewer, EditingSupport editingSupport, - Class<? extends IAnnotatedSpecification> clazz, T specification) throws Exception { - - 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/src/org/fortiss/tooling/base/ui/annotation/labelprovider/package.html b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/package.html deleted file mode 100644 index 09f8bd6c9..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/package.html +++ /dev/null @@ -1,4 +0,0 @@ -<!-- (c) 2017 fortiss GmbH --> -<body> -Text label providers to embed annotations table-based annotation views. Label providers are used to display the current values of annotations when they are not edited. -</body> diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/package.html b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/package.html deleted file mode 100644 index 972b690f7..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/package.html +++ /dev/null @@ -1,11 +0,0 @@ -<!-- (c) 2017 fortiss GmbH --> -<body> -GUI support of annotation framework. - -<ul> -<li><tt>editingsupport.*</tt>: contains editing support to edit annotations into the generic table-based annotation view.</li> -<li><tt>labelprovider.*</tt>: contains label providers support to display annotations in the generic table-based annotation view.</li> -<li><tt>view.*</tt>: provides abstract base classes and a generic table-based view part to display and edit annotations.</li> -</ul> - -</body> diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/.ratings index 235adc2a4..3d71afedf 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/.ratings @@ -1,2 +1,2 @@ AnnotationViewPartBase.java 7512f37b761b118c73a2555376f8e673ddaf1bd9 GREEN -IAnnotationViewPart.java a011f327370ded8738031059f9c3b94ce6ba63d1 GREEN +IAnnotationViewPart.java 5f267d95a19962637259c7478c48fe9c71c77864 YELLOW diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java deleted file mode 100644 index 7512f37b7..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java +++ /dev/null @@ -1,398 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.view; - -import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType; -import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement; - -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EContentAdapter; -import org.eclipse.gef.editparts.AbstractGraphicalEditPart; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IPartListener2; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.part.ViewPart; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.annotation.IAnnotationValueService; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage; -import org.fortiss.tooling.kernel.model.IProjectRootElement; -import org.fortiss.tooling.kernel.service.IPersistencyService; - -/** - * Base class for annotation views: - * <ul> - * <li>Maintain set of annotations displayed in annotation view.</li> - * <li>Selection management (mapping of selection in annotation view and related model - * elements).</li> - * <li>Watch model for changes and trigger view update.</li> - * </ul> - * - * @author eder - * @author barner - */ -public abstract class AnnotationViewPartBase extends ViewPart - implements ISelectionListener, IAnnotationViewPart { - - /** Currently selected object. */ - private IModelElement currentlySelectedObject; - - /** Last selected object. */ - private IModelElement lastSelectedObject; - - /** Last root element determined during the last successful {@link #update(IModelElement)}. */ - private IProjectRootElement lastRootElement; - - /** - * Root element for which the {@link #changeListener} has been installed to (recursively) - * watch for model changes (to trigger an update of this {@link AnnotationViewPartBase}). - */ - private EObject watchedElement; - - /** - * Cache: root element -> annotation entries. An entry is invalidated when an object is added to - * / removed from the model. - */ - private Map<EObject, Collection<AnnotationEntry>> lastAnnotationEntriesMap = - new HashMap<EObject, Collection<AnnotationEntry>>(); - - /** Flag to prevent nested calls of {@link #selectionChanged(IWorkbenchPart, ISelection)}. */ - private boolean processingSectionChanged = false; - - /** Flag if update of {@link AnnotationViewPartBase} views is enabled. */ - private static boolean isUpdateEnabled = true; - - /** Active instances of {@link AnnotationViewPartBase} views. */ - private static Set<AnnotationViewPartBase> activeInstances = - new HashSet<AnnotationViewPartBase>(); - - /** Constructs a new {@link AnnotationViewPartBase}. */ - public AnnotationViewPartBase() { - activeInstances.add(this); - } - - /** - * {@link Adapter} to watch for the addition, removal or value change of model elements - * to/from/in elements visible in this {@link AnnotationViewPartBase} (to trigger according - * updates). - */ - private final Adapter changeListener = new EContentAdapter() { - /** {@inheritDoc} */ - @Override - public void notifyChanged(Notification notification) { - if(!isUpdateEnabled) { - return; - } - - // Required to actually watch child elements (behavior of EContentAdapter) - super.notifyChanged(notification); - - // Optimization: Do not not react on the addition of annotations. The latter is actually - // a consequence of the addition of a new model element for which annotations have - // been registered. - // - // Otherwise, the addition of a new model elements results in a cascade of updates (one - // for the model element, and one for each of the annotations that have been registered - // for it) - int eventType = notification.getEventType(); - if(eventType == Notification.ADD && - notification.getNewValue() instanceof IAnnotatedSpecification) { - return; - } - - // Ignore update of IDs that may be triggered massively when saving a model that - // contains a lot of generated artifacts for which IDs are typically not assigned. - // - // Disabling the delivery of notifications during the assignment of IDs is not possible - // since the kernel needs to be notified about ID changes. - if(notification.getFeature() == FortissToolingKernelPackage.Literals.IID_LABELED__ID) { - return; - } - - boolean isAddOrRemoveEvent = eventType == Notification.ADD || - eventType == Notification.ADD_MANY || eventType == Notification.REMOVE || - eventType == Notification.REMOVE_MANY; - if(isAddOrRemoveEvent || eventType == Notification.SET) { - - Object notifier = notification.getNotifier(); - if((notifier instanceof EObject) && (IPersistencyService.getInstance() - .getTopLevelElementFor((EObject)notifier) != null)) { - // Ignore update requests for elements that are not hooked to a top-level - // element, e.g. SET events that are fired when a component is removed (before - // the actual REMOVE event). Otherwise, the AnnotationValueService would create - // a NPE during the preparation of the context via - // KernelModelElementUtils.runAsCommand(). - - IModelElement modelElement = null; - if(notifier instanceof IModelElement) { - modelElement = (IModelElement)notifier; - } else if(notifier instanceof IAnnotatedSpecification) { - modelElement = ((IAnnotatedSpecification)notifier).getSpecificationOf(); - } - - if(modelElement != null) { - if(isAddOrRemoveEvent) { - - // Invalidate cache if elements are added to / removed from the model - lastAnnotationEntriesMap.put( - getParentElement(modelElement, IProjectRootElement.class, true), - null); - } - - // Ensure that refresh is run in the UI thread - final IModelElement updatedModelElement = modelElement; - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - update(updatedModelElement); - } - }); - } - } - } - } - }; - - /** {@inheritDoc} */ - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(processingSectionChanged) { - return; - } - processingSectionChanged = true; - - currentlySelectedObject = checkAndPickFirst(selection, IModelElement.class); - - if(currentlySelectedObject == null) { - AbstractGraphicalEditPart editPart = - checkAndPickFirst(selection, AbstractGraphicalEditPart.class); - if(editPart != null && editPart.getModel() instanceof IModelElement) { - currentlySelectedObject = (IModelElement)editPart.getModel(); - } - } - - // Optimization: Do nothing if the same object as been selected again - if(currentlySelectedObject != lastSelectedObject && currentlySelectedObject != null) { - update(currentlySelectedObject); - lastSelectedObject = currentlySelectedObject; - } - - processingSectionChanged = false; - } - - /** - * Adds an AnnotationEntry for a given {@code modelElement} to a list of - * {@code annotationEntries} in case the acquired annotation is not empty, i.e. if it - * contributes at least one {@link IAnnotatedSpecification}. - */ - private void addAnnotationEntry(Collection<AnnotationEntry> annotationEntries, - IModelElement modelElement) { - AnnotationEntry entry = - IAnnotationValueService.getInstance().getAnnotationEntry(modelElement); - - if(!entry.isEmpty()) { - annotationEntries.add(entry); - } - } - - /** - * Update the {@link AnnotationViewPartBase}: delegate update of concrete view to - * {@link #update(Collection)}, and update model change listeners. - */ - protected void update(IModelElement modelElement) { - IProjectRootElement rootElement = - getParentElement(modelElement, IProjectRootElement.class, true); - if(rootElement == null) { - return; - } - - lastRootElement = rootElement; - - update(rootElement); - } - - /** Perform update for given {@link IProjectRootElement}. */ - private void update(IProjectRootElement rootElement) { - // Check cache if annotation entries for the given root element have already been determined - Collection<AnnotationEntry> annotationEntries = lastAnnotationEntriesMap.get(rootElement); - - if(annotationEntries == null) { - annotationEntries = new TreeSet<AnnotationEntry>(new Comparator<AnnotationEntry>() { - /** Compare AnnotationEntries by the model element they refer to. */ - @Override - public int compare(AnnotationEntry a1, AnnotationEntry a2) { - // Equality of model element implies equal hashCode(), order is arbitrary - // but not relevant for ensuring uniqueness of annotation entries. - - return Integer.compare(a1.getModelElement().hashCode(), - a2.getModelElement().hashCode()); - } - }); - - // Collect all AnnotationEntries for the current root element and its offspring - if(rootElement instanceof IModelElement) { - addAnnotationEntry(annotationEntries, (IModelElement)rootElement); - } - - for(IModelElement childModelElement : getChildrenWithType(rootElement, - IModelElement.class)) { - addAnnotationEntry(annotationEntries, childModelElement); - } - - // Cache annotation entries for the given root element - lastAnnotationEntriesMap.put(rootElement, annotationEntries); - } - - // If required, update change listener registration - EObject newWatchedElement = rootElement; - while(newWatchedElement.eContainer() != null) { - newWatchedElement = newWatchedElement.eContainer(); - } - - if(watchedElement != newWatchedElement) { - if(watchedElement != null) { - watchedElement.eAdapters().remove(changeListener); - } - watchedElement = newWatchedElement; - watchedElement.eAdapters().add(changeListener); - } - - // Update the view - update(annotationEntries); - } - - /** Update concrete view */ - protected abstract void update(Collection<AnnotationEntry> annotationEntries); - - /** Triggers an update of the view to refresh its last state. */ - public abstract void update(); - - /** {@inheritDoc} */ - @Override - public void createPartControl(Composite parent) { - final IWorkbenchPartSite site = getSite(); - site.getWorkbenchWindow().getSelectionService().addSelectionListener(this); - site.getPage().addPartListener(new IPartListener2() { - @Override - public void partActivated(IWorkbenchPartReference partRef) { - // Nothing to do - } - - @Override - public void partBroughtToTop(IWorkbenchPartReference partRef) { - // Nothing to do - } - - @Override - public void partClosed(IWorkbenchPartReference partRef) { - // Nothing to do - } - - @Override - public void partDeactivated(IWorkbenchPartReference partRef) { - // Nothing to do - } - - @Override - public void partOpened(IWorkbenchPartReference partRef) { - // Nothing to do - } - - @Override - public void partHidden(IWorkbenchPartReference partRef) { - if(partRef.getId().equals(IAnnotationViewPart.ANNOTATION_VIEW_ID)) { - setUpdateEnabled(false); - } - } - - @Override - public void partVisible(IWorkbenchPartReference partRef) { - if(partRef.getId().equals(IAnnotationViewPart.ANNOTATION_VIEW_ID)) { - setUpdateEnabled(true); - } - } - - @Override - public void partInputChanged(IWorkbenchPartReference partRef) { - // Nothing to do - } - }); - } - - /** {@inheritDoc} */ - @Override - public IModelElement getCurrentlySelectedObject() { - return currentlySelectedObject; - } - - /** {@inheritDoc} */ - @Override - public synchronized void dispose() { - // Unregister listeners - getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this); - if(watchedElement != null) { - watchedElement.eAdapters().remove(changeListener); - watchedElement = null; - } - - super.dispose(); - - activeInstances.remove(this); - } - - /** Enforces a full update of the view based on {@link #lastRootElement}. */ - private void forceFullUpdate() { - lastAnnotationEntriesMap.clear(); - if(lastRootElement != null) { - update(lastRootElement); - } - } - - /** Sets {@link #isUpdateEnabled}. If the update is re-enabled, the view is refreshed. */ - public static synchronized void setUpdateEnabled(boolean isUpdateEnabled) { - AnnotationViewPartBase.isUpdateEnabled = isUpdateEnabled; - if(isUpdateEnabled) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - activeInstances.stream().forEach(avp -> avp.forceFullUpdate()); - } - }); - } - } - - /** Returns {@link #isUpdateEnabled}. */ - public synchronized static boolean isUpdateEnabled() { - return isUpdateEnabled; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java index a011f3273..5f267d95a 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java @@ -16,7 +16,6 @@ package org.fortiss.tooling.base.ui.annotation.view; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; /** * Interface for views displaying {@link IAnnotatedSpecification}s. @@ -28,7 +27,4 @@ public interface IAnnotationViewPart { /** View ID for annotation views. */ // Keep in sync with plugin.xml public static String ANNOTATION_VIEW_ID = "org.fortiss.tooling.base.ui.annotationView"; - - /** Returns the currently selected object. */ - public IModelElement getCurrentlySelectedObject(); } diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings index 27e7ed082..565ccc5a9 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/.ratings @@ -1,3 +1,4 @@ -AnnotationFxViewPart.java 6b65210913c150420f4fe67d055a0051d1d37a4e YELLOW -AnnotationViewFXController.java d31a8251ed42a9b432f6f978768413f6a20315f1 YELLOW -FXAnnotationFilterContentProvider.java 80fa6e9cc2f5ba3a255cab7061edca5fa368451a YELLOW +AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 YELLOW +AnnotationViewFXController.java 3618e62b47054754708a5e6e6df6895757816d84 YELLOW +ColumnHandle.java 761c2517b3f3e4725feb7ce7e8d5927ba191a4bb YELLOW +FXAnnotationFilterContentProvider.java 90620e61e5c91669da26c0564527e0b4a31e4b9d YELLOW diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationFxViewPart.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationFxViewPart.java index 6b6521091..ca1548c49 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationFxViewPart.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationFxViewPart.java @@ -15,6 +15,7 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.annotation.view.fx; +import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; import org.fortiss.tooling.common.ui.javafx.AF3FXViewPart; import javafx.scene.Scene; @@ -24,7 +25,7 @@ import javafx.scene.Scene; * * @author bayha */ -public class AnnotationFxViewPart extends AF3FXViewPart { +public class AnnotationFxViewPart extends AF3FXViewPart implements IAnnotationViewPart { /** The FX Controller for this view. */ private static final AnnotationViewFXController VIEW_CONTROLLER = diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java index d31a8251e..3618e62b4 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/AnnotationViewFXController.java @@ -53,7 +53,6 @@ import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvide import org.fortiss.tooling.base.annotation.valueprovider.ValueProviderBase; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.generic.ColumnHandle; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeTableUIProviderBase; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeTableViewer; import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase; diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/ColumnHandle.java similarity index 94% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java rename to org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/ColumnHandle.java index 8fc5f04cb..761c2517b 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/ColumnHandle.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/ColumnHandle.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.view.generic; +package org.fortiss.tooling.base.ui.annotation.view.fx; import org.fortiss.tooling.base.annotation.AnnotationEntry; import org.fortiss.tooling.base.annotation.valueprovider.AnnotationInstSpec; @@ -21,7 +21,7 @@ import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; /** * Data required to identify a column displaying a particular {@link IAnnotatedSpecification} in - * a column of the {@link GenericAnnotationView}. Used to sort columns (see + * a column of the {@link AnnotationViewFXController}. Used to sort columns (see * {@link #compareTo(ColumnHandle)}). * * @author barner diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/FXAnnotationFilterContentProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/FXAnnotationFilterContentProvider.java index 80fa6e9cc..90620e61e 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/FXAnnotationFilterContentProvider.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/fx/FXAnnotationFilterContentProvider.java @@ -30,7 +30,6 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationViewFXController.ArtificialRoot; -import org.fortiss.tooling.base.ui.annotation.view.generic.ColumnHandle; import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeContentProviderBase; import org.fortiss.tooling.kernel.model.INamedElement; import org.fortiss.tooling.kernel.model.IProjectRootElement; diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings deleted file mode 100644 index b0d39817f..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings +++ /dev/null @@ -1,2 +0,0 @@ -ColumnHandle.java 8fc5f04cbb0127e5df8c7a9e3b2620502bf93716 GREEN -GenericAnnotationView.java 68a6eb91a4db97a58ebfacf400e73c297ab6b1a3 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java deleted file mode 100644 index 68a6eb91a..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java +++ /dev/null @@ -1,699 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.view.generic; - -import static org.apache.commons.lang3.reflect.MethodUtils.getMatchingMethod; -import static org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory.createEditingSupport; -import static org.fortiss.tooling.base.ui.annotation.labelprovider.LabelProviderFactory.createLabelProvider; -import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; -import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.conqat.lib.commons.collections.Pair; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.CellLabelProvider; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerCell; -import org.eclipse.jface.window.ToolTip; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.annotation.IAnnotationValueService; -import org.fortiss.tooling.base.annotation.valueprovider.AnnotationInstSpec; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionEntry; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionInputParameters; -import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider.AnnotationActionParameters; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.ToolingBaseUIActivator; -import org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory; -import org.fortiss.tooling.base.ui.annotation.editingsupport.ElementCommentEditingSupport; -import org.fortiss.tooling.base.ui.annotation.editingsupport.ElementNameEditingSupport; -import org.fortiss.tooling.base.ui.annotation.labelprovider.AnnotationLabelProvider; -import org.fortiss.tooling.base.ui.annotation.labelprovider.ElementCommentLabelProvider; -import org.fortiss.tooling.base.ui.annotation.labelprovider.ElementNameLabelProvider; -import org.fortiss.tooling.base.ui.annotation.view.AnnotationViewPartBase; -import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilter; -import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilterWidget; -import org.fortiss.tooling.base.ui.dialog.MultiFieldInputDialog; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.service.IPersistencyService; -import org.fortiss.tooling.kernel.ui.util.HierarchicalNameViewerComparator; - -/** - * <p> - * This class provides a generic table-based annotation view. - * </p> - * <p> - * In order to support displaying and editing specific annotation types, - * {@link EditingSupportFactory} must create an appropriate {@link EditingSupport} for the - * corresponding {@link IAnnotationValueProvider} base classes. - * </p> - * - * @author eder, diewald, barner - */ -public class GenericAnnotationView extends AnnotationViewPartBase { - /** Root composite of {@link GenericAnnotationView}. */ - private Composite rootComposite; - - /** The table viewer used to implement the view. */ - private TableViewer tableViewer; - - /** Caches the currently selected item in the table to make it available to listeners. */ - IStructuredSelection selectedTableItem; - - /** Associates the columns of the annotation view with the providers responsible for them. */ - Map<AnnotationInstSpec<? extends IAnnotatedSpecification>, IAnnotationValueProvider<IAnnotatedSpecification>> annotationCtxEntries = - new HashMap<>(); - - /** Row and column filter for annotations. */ - private AnnotationFilter annotationFilter; - - /** Widget for filter options. */ - private AnnotationFilterWidget annotationFilterWidget; - - /** - * Last set of {@link AnnotationEntry}s used to {@link #update(Collection)} the - * {@link GenericAnnotationView}, i.e., during the construction of the, or because of a model - * change. The reference is required to update view after a change of the column (annotation) - * filter. - */ - private Collection<AnnotationEntry> lastAnnotationEntries; - - /** Number of fixed columns shown for every model element (e.g., name, comment). */ - private int fixedColumnCount; - - /** - * Map used to preserve column width of annotation columns during update of the view (fixed - * columns are not deleted hence caching the width is not necessary). - */ - private Map<String, Integer> columnWidthCache; - - /** Default width of columns. */ - private static final int COLUMN_DEFAULT_WIDTH = 125; - - /** Default height of rows. */ - private int defaultRowHeight; - - /** - * Sets a fixed {@link AnnotationFilter}. - * <ul> - * <li>If the {@link AnnotationFilter} is non-{@code null}, it sets the filter and disables the - * {@link AnnotationFilterWidget}. For instance, this can be used to embed / extend the - * {@link GenericAnnotationView} into a specialized view dedicated to a particular model - * type.</li> - * <li>Otherwise, this method reinitializes the {@link AnnotationFilterWidget}.</li> - * </ul> - */ - public void setFixedAnnotationFilter(AnnotationFilter annotationFilter) { - - // Remove old table row filter - tableViewer.removeFilter(this.annotationFilter); - - if(annotationFilter != null) { - // Externally created filter -> remove filter option GUI - this.annotationFilter = annotationFilter; - if(annotationFilterWidget != null) { - annotationFilterWidget.dispose(); - annotationFilterWidget = null; - } - } else { - // No externally created filter -> setup filter option GUI - this.annotationFilter = new AnnotationFilter(); - setupAnnotationFilterWidget(); - } - - // Add new table row filter - tableViewer.addFilter(this.annotationFilter); - - // Update layout - rootComposite.layout(true, true); - } - - /** Returns the view's {@link AnnotationFilter}. */ - public AnnotationFilter getAnnotationFilter() { - return annotationFilter; - } - - /** {@inheritDoc} */ - @Override - public void update() { - // Full update, i.e. including reconstructions of columns is always required due to the - // following scenario: - // - Filter is set for annotation names. - // - Filter scope is changed to component names -> annotation filter needs to be undone - // - Filter is based on annotation entry type - // - Filter is set to current level / current sub model - // - Update of view as been disabled using setUpdateEnable(boolean) is re-enabled now - if(lastAnnotationEntries != null) { - update(lastAnnotationEntries); - } - } - - /** {@inheritDoc} */ - @Override - protected void update(Collection<AnnotationEntry> annotationEntries) { - if(!isUpdateEnabled()) { - return; - } - - // Update row filter with currently selected element - annotationFilter.setCurrentySelectedModelElement(getCurrentlySelectedObject()); - boolean contentRequiresUpdate = - lastAnnotationEntries == null || !annotationEntries.equals(lastAnnotationEntries); - - if(annotationFilter.annotationViewQueryUpdateRequired() || contentRequiresUpdate) { - // Update filter widget - if(annotationFilterWidget != null) { - annotationFilterWidget.updateAnnotationTypeFilterOptionsComboBox(annotationEntries, - this); - } - - // Remember last annotation entries (required to re-draw table after changing the - // column/annotation filter - lastAnnotationEntries = annotationEntries; - - // Minimize flickering while updating the table - tableViewer.getTable().setRedraw(false); - - // Sorted set of {@link ColumnHandle} used to instantiate this {@link - // GenericAnnotationView}'s columns in the right order. - Set<ColumnHandle<?>> sortedColumnHandles = new TreeSet<ColumnHandle<?>>(); - - // Dispose all columns of the table viewer, except the leading fixed columns, which e.g. - // hold the model elements' names and comments. - while(tableViewer.getTable().getColumnCount() > fixedColumnCount) { - TableColumn column = tableViewer.getTable().getColumn(fixedColumnCount); - column.dispose(); - } - - // Input must be set before the construction of the columns, since the editing support - // for a given cell might need to query the contents of other model elements (e.g., in - // order to aggregate a set of admissible choices for its value). - tableViewer.setInput(annotationEntries); - - // Aggregate required columns. Column order is defined by ColumnHandle.compareTo(). - for(AnnotationEntry entry : annotationEntries) { - for(IAnnotatedSpecification spec : entry.getSpecificationsList()) { - ColumnHandle<IAnnotatedSpecification> columnHandle = - new ColumnHandle<IAnnotatedSpecification>(entry, spec); - - if(annotationFilter.passesColumnFilter(columnHandle)) { - sortedColumnHandles.add(columnHandle); - } - } - } - - // Instantiate columns - for(ColumnHandle<?> columnHandle : sortedColumnHandles) { - createAnnotationColumn(columnHandle); - } - - tableViewer.getTable().setRedraw(true); - - // After contents change, restore row height. It will be adjusted to the new content - // using the TableViewer's SWT.{MeasureItem, PaintItem, EraseItem} listeners installed - // in addRowHeightListener(). This needs to be done here since in the above listeners, - // the table row height can only grow and may not be decreased. - // See <https://bugs.eclipse.org/bugs/show_bug.cgi?id=154341>. - setTableItemHeight(tableViewer.getTable(), defaultRowHeight); - } - - // Update the view - tableViewer.refresh(); - } - - /** {@inheritDoc} */ - @Override - protected void update(IModelElement modelElement) { - // Updates the contents of the table - super.update(modelElement); - - // ensure that selected model element is visible in annotation view - AnnotationEntry entry = - IAnnotationValueService.getInstance().getAnnotationEntry(modelElement); - assert (entry.getModelElement() == modelElement); - - tableViewer.reveal(entry); - } - - /** Initializes the {@link AnnotationFilterWidget}. */ - private void setupAnnotationFilterWidget() { - annotationFilterWidget = new AnnotationFilterWidget(rootComposite, SWT.NULL, this); - annotationFilterWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - } - - /** - * Sets the item height of the given {@link Table} to the specified value. - * - * <b>The underlying method {@code Table#setItemHeight} is not exposed. This wrapper method - * should only called during a full {@link #update(Collection)} of the table's contents.</b>> - */ - private void setTableItemHeight(Table table, int height) { - try { - Method method = getMatchingMethod(table.getClass(), "setItemHeight", int.class); - if(method != null) { - boolean accessible = method.canAccess(table); - if(method.trySetAccessible()) { - method.invoke(table, height); - method.setAccessible(accessible); - } else { - warning(ToolingBaseUIActivator.getDefault(), - "Could not set annotation table height."); - } - } - } catch(Exception e) { - error(ToolingBaseUIActivator.getDefault(), "Failed to set annotation table height.", e); - } - } - - /** - * Constructs a {@link Listener} such that a context menu is created upon a right-click on - * entries in the Annotation View. - */ - private <T extends IAnnotatedSpecification> void addContextMenuListener(Table table) { - table.addListener(SWT.MouseDown, new Listener() { - @Override - public void handleEvent(Event event) { - TableItem[] selection = table.getSelection(); - if(selection.length != 0 && (event.button == 3)) { - - Menu contextMenu = new Menu(table); - table.setMenu(contextMenu); - - ViewerCell cell = tableViewer.getCell(new Point(event.x, event.y)); - if(cell == null) { - return; - } - CellLabelProvider labelProv = - tableViewer.getLabelProvider(cell.getColumnIndex()); - - Object selectedElement = cell.getElement(); - - if(labelProv instanceof AnnotationLabelProvider && - selectedElement instanceof AnnotationEntry) { - AnnotationEntry selEntry = (AnnotationEntry)selectedElement; - @SuppressWarnings("unchecked") Class<T> annotationType = - (Class<T>)((AnnotationLabelProvider)labelProv).getAnnotationType(); - T spec = selEntry.getSpecification(annotationType); - - AnnotationInstSpec<T> instSpec = new AnnotationInstSpec<T>(selEntry, spec); - // By Construction of the map, we can ensure that this cast will always be - // valid. - @SuppressWarnings("unchecked") IAnnotationValueProvider<T> valProvider = - (IAnnotationValueProvider<T>)annotationCtxEntries.get(instSpec); - - // Only show the context menu for: - // - Model elements that are actually annotated with the particular - // annotation. - // - Editable annotations (non-derived and no partially non-derived - // annotations). - if(spec != null && valProvider.canEdit(spec)) { - addContextMenuEntries(contextMenu, valProvider, instSpec); - } - } - contextMenu.setVisible(true); - } - } - }); - } - - /** - * Adds a {@link Listener} to the given {@link Menu} entry such that the given - * {@link BiConsumer} is executed upon selection. - */ - private <T extends IAnnotatedSpecification, S extends IModelElement> void - addContextMenuEntryListener(MenuItem entry, AnnotationActionEntry actionEntry, - BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>> action, - AnnotationInstSpec<T> entrySpecification, - Stream<AnnotationEntry> annotationEntries) { - entry.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if(selectedTableItem.getFirstElement() instanceof AnnotationEntry) { - AnnotationEntry entry = (AnnotationEntry)selectedTableItem.getFirstElement(); - - AnnotationActionInputParameters parameterList = null; - if(actionEntry.getRequiredInputParameters() != null) { - MultiFieldInputDialog paramDialog = - new MultiFieldInputDialog(rootComposite.getShell()); - paramDialog.loadAllInputFields(actionEntry.getRequiredInputParameters(), - entrySpecification.getAnnotatedSpecification()); - paramDialog.setBlockOnOpen(true); - paramDialog.open(); - parameterList = paramDialog.getParameterValues(); - } - - Runnable r = createAnnoationActionRunnable(entry, action, actionEntry, - entrySpecification, parameterList, annotationEntries); - - ITopLevelElement modelContext = IPersistencyService.getInstance() - .getTopLevelElementFor(entry.getModelElement()); - - boolean updateEnabled = isUpdateEnabled(); - setUpdateEnabled(false); - if(actionEntry.isWrite()) { - modelContext.runAsCommand(r); - } else { - modelContext.runAsNonDirtyingCommand(r); - } - setUpdateEnabled(updateEnabled); - } - } - }); - } - - /** - * Creates a runnable for actions defined in {@link IAnnotationValueProvider} that are selected - * via the context menu of the AnnotationView. The Scope enum of an - * {@link AnnotationActionEntry} defines the elements on which the created {@link Runnable} - * executes the define {@link BiConsumer}. - * - * @param entry - * {@link AnnotationEntry} selected in the AnnotationView. - * @param action - * Action to be executed it selected. - * @param actionEntry - * {@link AnnotationActionEntry} describing the parameters of the action. - * @param specificationType - * Type of the Annotation. - * @param inputParameters - * List of input parameters for the executed BiConsumer. - * @param annotationEntries - * {@link AnnotationEntry}s that are currently visible in the AnnotationView. - * @return Runnable that is executed when the corresponding menu entry is selected. - */ - private <T extends IAnnotatedSpecification> Runnable createAnnoationActionRunnable( - AnnotationEntry entry, - BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>> action, - AnnotationActionEntry actionEntry, AnnotationInstSpec<T> specificationType, - AnnotationActionInputParameters inputParameters, - Stream<AnnotationEntry> annotationEntries) { - Runnable r; - if(actionEntry.getScope() == AnnotationActionEntry.ActionScope.ALL_VISIBLE_ITEMS) { - r = () -> { - for(T annotation : annotationEntries.map( - e -> e.getSpecification(specificationType.getAnnotatedSpecificationType())) - .filter(e -> e != null).collect(Collectors.toList())) { - // TODO (#2779): Use a (yet to come) LambdaUtil method for the lengthy - // expression above. - - action.accept(specificationType, - new AnnotationActionParameters<>(annotation, inputParameters)); - } - }; - } else if(actionEntry.getScope() == AnnotationActionEntry.ActionScope.SINGLE_ITEM) { - T annotation = - entry.getSpecification(specificationType.getAnnotatedSpecificationType()); - r = () -> { - action.accept(specificationType, - new AnnotationActionParameters<>(annotation, inputParameters)); - }; - } else { - r = () -> {/* NOP */ - }; - } - - return r; - } - - /** - * Adds context menu entries to the given {@link Menu} whose name and associated action is - * determined by the {@link IAnnotationValueProvider}. - */ - private <T extends IAnnotatedSpecification> void addContextMenuEntries(Menu contextMenu, - IAnnotationValueProvider<T> valueProvider, AnnotationInstSpec<T> annotationClass) { - final Stream<AnnotationEntry> annotationEntriesMatchingFilter = getLastAnnotationEntries() - .stream().filter(e -> annotationFilter.passesRowFilter(e)); - - // Known by construction. - @SuppressWarnings("unchecked") T specification = - (T)annotationClass.getAnnotatedSpecification(); - - for(Pair<AnnotationActionEntry, BiConsumer<AnnotationInstSpec<T>, AnnotationActionParameters<T>>> ctxMenuEntry : valueProvider - .getContextMenuEntries(specification)) { - MenuItem mItem = new MenuItem(contextMenu, SWT.None); - mItem.setText(ctxMenuEntry.getFirst().getName()); - addContextMenuEntryListener(mItem, ctxMenuEntry.getFirst(), ctxMenuEntry.getSecond(), - annotationClass, annotationEntriesMatchingFilter); - } - } - - /** {@inheritDoc} */ - @Override - public void createPartControl(Composite parent) { - super.createPartControl(parent); - rootComposite = new Composite(parent, SWT.NULL); - rootComposite.setLayout(new GridLayout(1, false)); - - tableViewer = new TableViewer(rootComposite, SWT.BORDER | SWT.FULL_SELECTION); - Table table = tableViewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); - - // Preserve default row-height (used to restore it during contents updates in - // update(Collection<AnnotationEntry>)). - defaultRowHeight = table.getItemHeight(); - - ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); - - // Install layout for Table in order to ensure that it claims all available vertical space - // in case the - // filter option GUI is removed (see setFixedAnnotationFilter()). - table.setLayout(new FillLayout(SWT.VERTICAL)); - - fixedColumnCount = createFixedModelElementColumns(); - columnWidthCache = new HashMap<String, Integer>(); - - tableViewer.setComparator(new HierarchicalNameViewerComparator() { - /** {@inheritDoc} */ - @Override - public int compare(Viewer viewer, Object o1, Object o2) { - if(o1 instanceof AnnotationEntry && o2 instanceof AnnotationEntry) { - return super.compare(viewer, ((AnnotationEntry)o1).getModelElement(), - ((AnnotationEntry)o2).getModelElement()); - } - - return super.compare(viewer, o1, o2); - } - }); - - tableViewer.setComparer(new IElementComparer() { - - @Override - public int hashCode(Object element) { - if(element instanceof AnnotationEntry) { - return ((AnnotationEntry)element).getModelElement().hashCode(); - } - return element.hashCode(); - } - - @Override - public boolean equals(Object a, Object b) { - if(a instanceof AnnotationEntry && b instanceof AnnotationEntry) { - return ((AnnotationEntry)a).getModelElement() == ((AnnotationEntry)b) - .getModelElement(); - } - return a.equals(b); - } - }); - - tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(final SelectionChangedEvent event) { - selectedTableItem = (IStructuredSelection)event.getSelection(); - } - }); - - addContextMenuListener(table); - - // Rows (= components) are filtered using a specialized ViewerFilter. - // Since the data model is an array of AnnotationEntries, columns (= annotations) - // cannot be filtered using such a filter, and require the reconstruction of the - // table, with an implementation of the filter in update(Set<AnnotationEntry>). - annotationFilter = new AnnotationFilter(); - tableViewer.addFilter(annotationFilter); - - // Add filter widget - setupAnnotationFilterWidget(); - } - - /** Creates a fixed (leading) column to be shown for every model element. */ - private void createFixedColumn(String label, ColumnLabelProvider labelProvider, - EditingSupport editingSupport) { - TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText(label); - column.getColumn().setWidth(COLUMN_DEFAULT_WIDTH); - - tableViewer.setContentProvider(new ArrayContentProvider()); - column.setLabelProvider(labelProvider); - column.setEditingSupport(editingSupport); - } - - /** - * Creates the (leading) columns which displays the model elements' names and comments. - * - * @returns Number of leading columns. - */ - protected int createFixedModelElementColumns() { - createFixedColumn("Model Element", new ElementNameLabelProvider(this), - new ElementNameEditingSupport(tableViewer)); - - createFixedColumn("Comment", new ElementCommentLabelProvider(this), - new ElementCommentEditingSupport(tableViewer)); - - return 2; - } - - /** - * Creates a column in the table viewer displaying the annotation identified by the given - * {@link ColumnHandle}. - */ - protected void - createAnnotationColumn(ColumnHandle<? extends IAnnotatedSpecification> columnHandle) { - - TableColumn tableColumn = null; - @SuppressWarnings("unchecked") Class<IAnnotatedSpecification> annotationClass = - (Class<IAnnotatedSpecification>)columnHandle.getAnnotatedSpecification().getClass(); - - // Add new column - try { - @SuppressWarnings("unchecked") TableViewerColumn column = - createAnnotationTableViewerColumn( - (ColumnHandle<IAnnotatedSpecification>)columnHandle, annotationClass); - - tableColumn = column.getColumn(); - String specName = columnHandle.getColumnName(); - tableColumn.setText(specName); - } catch(Exception e) { - System.out.println("Failed to create table viewer column for annotation class " + - annotationClass.getCanonicalName() + - ((e.getMessage() != null) ? ": " + e.getMessage() : ".")); - } - - if(tableColumn != null) { - tableColumn.addControlListener(new ControlListener() { - @Override - public void controlResized(ControlEvent e) { - TableColumn tc = (TableColumn)e.getSource(); - columnWidthCache.put(tc.getText(), tc.getWidth()); - } - - @Override - public void controlMoved(ControlEvent e) { - // Nothing to do - } - }); - Integer width = columnWidthCache.get(tableColumn.getText()); - if(width != null) { - // If possible, use cached with (possibly adjusted by the user) - tableColumn.setWidth(width); - } else { - // Otherwise, calculate width for new columns - tableColumn.pack(); - width = tableColumn.getWidth(); - if(width < COLUMN_DEFAULT_WIDTH) { - tableColumn.setWidth(COLUMN_DEFAULT_WIDTH); - } else if(width > 1.2f * COLUMN_DEFAULT_WIDTH) { - tableColumn.setWidth(Math.round(1.2f * COLUMN_DEFAULT_WIDTH)); - } - } - } - } - - /** - * Creates a {@link TableViewerColumn}, i.e., instantiate matching {@link EditingSupport} and - * {@link LabelProvider} for the given annotation. - */ - private <T extends IAnnotatedSpecification> TableViewerColumn createAnnotationTableViewerColumn( - ColumnHandle<T> columnHandle, Class<T> annotationClass) throws Exception { - TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); - - // Have the matching EditingSupport created for the current annotated specification. - AnnotationEntry entry = columnHandle.getEntry(); - IAnnotationValueProvider<IAnnotatedSpecification> valueProvider = - entry.getAnnotationValueProvider(annotationClass); - T specification = entry.getSpecification(annotationClass); - - EditingSupport editingSupport = - createEditingSupport(valueProvider, tableViewer, annotationClass, specification); - - ColumnLabelProvider columnLabelProvider = createLabelProvider(valueProvider, this, - tableViewer, editingSupport, annotationClass, specification); - - column.setEditingSupport(editingSupport); - column.setLabelProvider(columnLabelProvider); - - annotationCtxEntries.put(columnHandle, valueProvider); - // addContextMenuEntries(valueProvider, annotationClass); - - return column; - } - - /** {@inheritDoc} */ - @Override - public void setFocus() { - // nothing to do - } - - /** {@inheritDoc} */ - @Override - public synchronized void dispose() { - tableViewer.getTable().dispose(); - super.dispose(); - } - - /** Returns {@link #lastAnnotationEntries}. */ - public Collection<AnnotationEntry> getLastAnnotationEntries() { - return lastAnnotationEntries; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/.ratings deleted file mode 100644 index 2feaf383a..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/.ratings +++ /dev/null @@ -1,3 +0,0 @@ -AnnotationFilter.java 2bf8b803c93f49d106a3597815ef570a8ffcc996 GREEN -AnnotationFilterWidget.java 66ca89b5d823d33f20da3d94bc64bf08faebaade GREEN -TextFocusListener.java 53aac76e88517ecbb34be84e6d2476e6ba101a31 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilter.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilter.java deleted file mode 100644 index 2bf8b803c..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilter.java +++ /dev/null @@ -1,300 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.view.generic.filter; - -import static java.util.regex.Pattern.CASE_INSENSITIVE; -import static java.util.regex.Pattern.DOTALL; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementAncestor; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementLevel; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.model.element.IModelElement; -import org.fortiss.tooling.base.ui.annotation.view.generic.ColumnHandle; -import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView; -import org.fortiss.tooling.kernel.model.INamedElement; -import org.fortiss.tooling.kernel.model.IProjectRootElement; - -/** - * Row and column filter for the {@link GenericAnnotationView}. - * <ul> - * <li>Row filtering is realized by inheriting {@link ViewerFilter} and the default filtering - * mechanism provided by {@link TableViewer}.</li> - * <li>Column filtering is supported by {@link AnnotationFilter#passesColumnFilter(ColumnHandle)} - * that is evaluated during the update of the {@link GenericAnnotationView}.</li> - * </ul> - * - * @author barner - */ -public class AnnotationFilter extends ViewerFilter { - /** Filter hint text. */ - static final String FILTER_HINT_TEXT = "type filter text (regex)"; - - /** Hierarchy filter option: all model elements from any level. */ - static final String HIERARCHY_LEVELS_ALL = "Show all levels"; - - /** Hierarchy filter option: all model elements from current level. */ - static final String HIERARCHY_LEVELS_CURRENT = "Show current level"; - - /** Hierarchy filter option: currently selected model element and its offspring. */ - static final String HIERARCHY_LEVELS_SELECTED_SUBMODEL = "Show selected sub-model"; - - /** Current model element / annotation name filter pattern. */ - private Pattern filterPattern; - - /** Flag whether columns / annotation names should be filtered. */ - private boolean filterColumnName; - - /** Flag whether rows / model element names should be filtered. */ - private boolean filterRowName; - - /** Flag whether the row/column filter should be case sensitive. */ - private boolean filterNameMatchCase; - - /** Currently selected model element (may be {@code null}). */ - private IModelElement currentlySelectedModelElement; - - /** - * Flag whether the displayed rows should be restricted to the currently selected model - * element type. - */ - boolean restrictToSelectedModelElementType; - - /** Row filter option based on hierarchy level of model element. */ - private String hierarchyLevelFilter; - - /** Column filter option based on annotation type. */ - private Class<? extends IAnnotatedSpecification> annotationTypeFilter; - - /** Flag if a full update of the annotation view has been requested. */ - boolean annotationViewFullUpdateRequested; - - /** {@inheritDoc} */ - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - if(!(element instanceof AnnotationEntry)) { - return true; - } - - AnnotationEntry annotationEntry = ((AnnotationEntry)element); - if(!(annotationEntry.getModelElement() instanceof INamedElement)) { - return true; - } - - return passesRowFilter(annotationEntry); - } - - /** - * Returns {@code true} if a given {@code input} passes a case-insensitive filter specified - * by {@code filterString}. - */ - private boolean passesNameFilter(String input) { - // Null-filter accepts every input. This covers also the case when the pattern provided by - // the user is invalid. - if(filterPattern == null) { - return true; - } - - // Null-input cannot be accepted by a non-null filter - if(input == null) { - return false; - } - - return filterPattern.matcher(input).matches(); - } - - /** - * Returns {@code true} if given annotation entry matches the currently selected model - * element (or if this particular filter option is turned off). - */ - private boolean passesSelectedElementTypeFilter(AnnotationEntry annotationEntry) { - boolean selectedElementIsInvalid = currentlySelectedModelElement == null || - currentlySelectedModelElement instanceof IProjectRootElement; - - if(selectedElementIsInvalid || hierarchyLevelFilter == null) { - return true; - } - - IModelElement modelElement = annotationEntry.getModelElement(); - int modelElementLevel = getModelElementLevel(modelElement); - int currentlySelectedModelElementLevel = - getModelElementLevel(currentlySelectedModelElement); - - if(hierarchyLevelFilter.equals(HIERARCHY_LEVELS_CURRENT)) { - // Elements have different levels -> filter - if(modelElementLevel != currentlySelectedModelElementLevel) { - return false; - } - - if(currentlySelectedModelElement.eContainer() != modelElement.eContainer()) { - return false; - } - } - if(hierarchyLevelFilter.equals(HIERARCHY_LEVELS_SELECTED_SUBMODEL)) { - // Model element has lower level than currently selected element -> filter - if(modelElementLevel < currentlySelectedModelElementLevel) { - return false; - } - - // Otherwise, check that model element is actually in the subtree below the currently - // selected element, i.e. filter if the model element's anchestor is not identical - // to the currently selected model element. - int levelsUp = modelElementLevel - currentlySelectedModelElementLevel; - EObject modelElementAncestor = - getModelElementAncestor(annotationEntry.getModelElement(), levelsUp); - - if(currentlySelectedModelElement != modelElementAncestor) { - return false; - } - } - - Class<? extends IModelElement> modelElementClass = modelElement.getClass(); - Class<? extends IModelElement> currentlySelectedModelElementClass = - currentlySelectedModelElement.getClass(); - - // Pass test if either the model element type is not restricted, or the element has the same - // type as the selected one - return !restrictToSelectedModelElementType || - modelElementClass.equals(currentlySelectedModelElementClass); - } - - /** Returns true if the given specification passes the current annotation type filter. */ - private boolean passesAnnotationTypeFilter(IAnnotatedSpecification spec) { - return annotationTypeFilter == null || spec.getClass().equals(annotationTypeFilter); - } - - /** - * Returns {@code true} if the column represented by the given column is visible in the - * view. - */ - public boolean passesColumnFilter(ColumnHandle<?> columnHandle) { - // Whether the annotation is visible (i.e., not principally hidden from any view) - boolean passesHiddenFilter = !columnHandle.getEntry() - .isHidden(columnHandle.getAnnotatedSpecification().getClass()); - - // Pass name filter, if: name is not filtered, or the condition is met - boolean passesNameFilter = - !filterColumnName || passesNameFilter(columnHandle.getColumnName()); - - // Check if column passes all tests - // @CodeFormatterOff - return - passesHiddenFilter && - passesNameFilter && - passesSelectedElementTypeFilter(columnHandle.getEntry()) && - passesAnnotationTypeFilter(columnHandle.getAnnotatedSpecification()); - // @CodeFormatterOn - } - - /** - * Returns {@code true} if the rows represented by {@code annotationEntry} are visible - * in the view. - */ - public boolean passesRowFilter(AnnotationEntry annotationEntry) { - IModelElement modelElement = annotationEntry.getModelElement(); - - // Pass name filter, if: name is not filtered, element is not a INamedElement, or it - // actually passes the filter - boolean passesNameFilter = !filterRowName || !(modelElement instanceof INamedElement) || - passesNameFilter(((INamedElement)modelElement).getName()); - - return passesNameFilter && passesSelectedElementTypeFilter(annotationEntry); - } - - /** - * Query if a full update of the annotation view as been requested (and reset the request), or - * if the current filter settings require a full update in any case. - */ - public boolean annotationViewQueryUpdateRequired() { - // In case an update has been explicitly requested, reset the request here. - boolean annotationViewFullUpdateRequested = this.annotationViewFullUpdateRequested; - this.annotationViewFullUpdateRequested = false; - - // If the filter is based on the current selection (i.e., currently selected model element - // type, current level, or current sub-model, ), a full update is required on every - // selection change since the newly selected element might contribute a different set of - // annotations. - boolean filterSettingsRequireFullUpdate = restrictToSelectedModelElementType || - !hierarchyLevelFilter.equals(HIERARCHY_LEVELS_ALL); - return filterSettingsRequireFullUpdate || annotationViewFullUpdateRequested; - } - - /** Request a full update of the annotation view (due to changed filter settings). */ - public void annotationViewRequestFullUpdate() { - this.annotationViewFullUpdateRequested = true; - } - - /** Sets the model element / annotation name filter pattern. */ - public void setNameFilterPattern(String filterPatternString) { - if(filterPatternString.equals(FILTER_HINT_TEXT)) { - filterPattern = null; - } else { - try { - final int patternFlags = (filterNameMatchCase ? 0 : CASE_INSENSITIVE) | DOTALL; - filterPattern = Pattern.compile(".*" + filterPatternString + ".*", patternFlags); - } catch(PatternSyntaxException e) { - filterPattern = null; - } - } - } - - /** Sets the flag whether rows should be filtered by name. */ - public void setFilterRowName(boolean filterRowName) { - this.filterRowName = filterRowName; - } - - /** Sets the flag whether columns should be filtered by name. */ - public void setFilterColumnName(boolean filterColumnName) { - this.filterColumnName = filterColumnName; - } - - /** Sets the flag whether the row/column filter should be case sensitive. */ - public void setFilterNameMatchCase(boolean filterNameMatchCase) { - this.filterNameMatchCase = filterNameMatchCase; - // Recompile pattern - if(filterPattern != null) { - setNameFilterPattern(filterPattern.pattern()); - } - } - - /** Sets the flag whether the view should be filtered by the selected model element type. */ - public void setRestrictToSelectedModelElementType(boolean restrictToSelectedModelElementType) { - this.restrictToSelectedModelElementType = restrictToSelectedModelElementType; - } - - /** Sets the model element hierarchy level filter option. */ - public void setHierarchyLevelFilter(String hierarchyLevelFilter) { - this.hierarchyLevelFilter = hierarchyLevelFilter; - } - - /** Sets the annotation type filter option. */ - public void - setAnnotationTypeFilter(Class<? extends IAnnotatedSpecification> annotationTypeFilter) { - this.annotationTypeFilter = annotationTypeFilter; - } - - /** Sets the currently selected model element (may be {@code null}). */ - public void setCurrentySelectedModelElement(IModelElement currentySelectedModelElement) { - this.currentlySelectedModelElement = currentySelectedModelElement; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilterWidget.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilterWidget.java deleted file mode 100644 index 66ca89b5d..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/AnnotationFilterWidget.java +++ /dev/null @@ -1,366 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.annotation.view.generic.filter; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.fortiss.tooling.base.annotation.AnnotationEntry; -import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; -import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView; -import org.fortiss.tooling.base.ui.widget.ExtendedCCombo; - -/** - * Widget to set content filters for the {@link GenericAnnotationView}. - * - * @author barner - */ -public class AnnotationFilterWidget extends Composite { - - /** Annotation type filter: all annotations. */ - private static final String ANNOTATION_TYPE_ANY = "Show all annotations"; - - /** Combo box Column filter option based on annotation type. */ - private ExtendedCCombo<Class<? extends IAnnotatedSpecification>> filterAnnotationTypeCombo; - - /** Constructs a new {@link AnnotationFilterWidget}. */ - public AnnotationFilterWidget(Composite parent, int style, final GenericAnnotationView view) { - super(parent, style); - - GridLayout layout = new GridLayout(4, false); - layout.horizontalSpacing = 50; - setLayout(layout); - - // Row 1: name filter scope / labels - Composite nameFilterScopeComposite = createNameFilterScopeComposite(this, view); - nameFilterScopeComposite - .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1)); - - createFilterLabel(this, "Filter model element type:"); - createFilterLabel(this, "Filter model element hierarchy level:"); - createFilterLabel(this, "Filter annotation type:"); - - // Row 2: controls - Text nameFilterText = createNameFilterText(this, view); - nameFilterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1)); - - Button modelElementTypeFilterButton = - createModelElementTypeFilterOptionsCheckButton(this, view); - modelElementTypeFilterButton - .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); - - CCombo hierarchyLevelFilterCombo = createHierarchyLevelFilterOptionsComboBox(this, view); - hierarchyLevelFilterCombo - .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); - - ExtendedCCombo<Class<? extends IAnnotatedSpecification>> annotationTypeFilterCombo = - createAnnotationTypeFilterOptionsComboBox(this, view); - annotationTypeFilterCombo - .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); - } - - /** Creates a {@link Label} with a given {@code text}. */ - private Label createFilterLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.NULL); - label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); - label.setText(text); - return label; - } - - /** - * Creates the {@link Text} input box for setting the pattern to filter the - * {@link GenericAnnotationView} for model element or annotation names. - */ - private Text createNameFilterText(Composite parent, final GenericAnnotationView view) { - // Text input field for filter pattern - final Text nameFilterText = - new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); - view.getAnnotationFilter(); - nameFilterText.setText(AnnotationFilter.FILTER_HINT_TEXT); - nameFilterText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY)); - - // Observe changes of filter pattern - nameFilterText.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - String filterPattern = nameFilterText.getText(); - if(filterPattern.isEmpty()) { - nameFilterText.setText(AnnotationFilter.FILTER_HINT_TEXT); - nameFilterText.selectAll(); - filterPattern = AnnotationFilter.FILTER_HINT_TEXT; - } - Display display = Display.getCurrent(); - if(filterPattern.equals(AnnotationFilter.FILTER_HINT_TEXT)) { - nameFilterText.setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); - } else { - nameFilterText - .setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); - } - view.getAnnotationFilter().setNameFilterPattern(filterPattern); - updateView(view); - } - }); - - // Select the filter pattern if it is equal to the FILTER_HINT_TEXT - TextFocusListener textSelectionOnFocusListener = new TextFocusListener() { - - @Override - protected void focusOut(Text text, Event e) { - text.clearSelection(); - } - - @Override - protected void focusIn(Text text, Event e) { - boolean isFilterHintText = text.getText().equals(AnnotationFilter.FILTER_HINT_TEXT); - boolean isSelectionEmpty = text.getSelectionCount() == 0; - if(isFilterHintText && (e.type != SWT.MouseUp || isSelectionEmpty)) { - text.selectAll(); - } - } - }; - nameFilterText.addListener(SWT.FocusIn, textSelectionOnFocusListener); - nameFilterText.addListener(SWT.FocusOut, textSelectionOnFocusListener); - nameFilterText.addListener(SWT.MouseDown, textSelectionOnFocusListener); - nameFilterText.addListener(SWT.MouseUp, textSelectionOnFocusListener); - - return nameFilterText; - } - - /** - * Creates a {@link Composite} that contains radio buttons to set the scope of the name - * filter (model element names or annotation names). - */ - private Composite createNameFilterScopeComposite(Composite parent, - final GenericAnnotationView view) { - Composite nameFilterScopeComposite = new Composite(parent, SWT.NULL); - nameFilterScopeComposite.setLayout(new RowLayout()); - - // Radio buttons to select between row and column name filtering - final Label filterLabel = new Label(nameFilterScopeComposite, SWT.NULL); - filterLabel.setText("Filter "); - - final Button filterComponentNamesButton = new Button(nameFilterScopeComposite, SWT.RADIO); - filterComponentNamesButton.setText("model element"); - filterComponentNamesButton.setSelection(true); - view.getAnnotationFilter().setFilterRowName(true); - - filterComponentNamesButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // widgetSelected() is also fired when the selection is removed from the radio - // button, so check, if this is the button that just obtained the selection - if(!((Button)e.getSource()).getSelection()) { - return; - } - view.getAnnotationFilter().setFilterRowName(true); - view.getAnnotationFilter().setFilterColumnName(false); - updateView(view); - } - }); - - final Button filterAnnotationNamesButton = new Button(nameFilterScopeComposite, SWT.RADIO); - filterAnnotationNamesButton.setText("annotation names:"); - filterAnnotationNamesButton.setSelection(false); - - filterAnnotationNamesButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // widgetSelected() is also fired when the selection is removed from the radio - // button, so check, if this is the button that just obtained the selection - if(!((Button)e.getSource()).getSelection()) { - return; - } - view.getAnnotationFilter().setFilterRowName(false); - view.getAnnotationFilter().setFilterColumnName(true); - updateView(view); - } - }); - - final Button filterNamesMatchCaseButton = new Button(nameFilterScopeComposite, SWT.CHECK); - filterNamesMatchCaseButton.setText("match case:"); - filterNamesMatchCaseButton.setSelection(false); - - filterNamesMatchCaseButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - final boolean selection = ((Button)e.getSource()).getSelection(); - view.getAnnotationFilter().setFilterNameMatchCase(selection); - updateView(view); - } - }); - - return nameFilterScopeComposite; - } - - /** - * Returns a {@link Button} for setting the options for filtering the - * {@link GenericAnnotationView} for the currently selected model element type. - * - * @param parent - * {@link Composite} to which button should be added - * @param view - * {@link GenericAnnotationView} to be filtered. - * - * @return {@link Button} for setting the options for filtering the - * {@link GenericAnnotationView} for the currently selected model element type. - */ - private Button createModelElementTypeFilterOptionsCheckButton(Composite parent, - final GenericAnnotationView view) { - - // Check box to restrict view to currently selected model element type - final Button filterModelElementTypeButton = new Button(parent, SWT.CHECK); - - filterModelElementTypeButton.setText("Show only selected model element type."); - filterModelElementTypeButton.setSelection(false); - - filterModelElementTypeButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // widgetSelected() is also fired when the selection is removed from the radio - // button, so check, if this is the button that just obtained the selection - view.getAnnotationFilter().setRestrictToSelectedModelElementType( - ((Button)e.getSource()).getSelection()); - updateView(view); - } - }); - - return filterModelElementTypeButton; - } - - /** - * Returns a {@link CCombo} for setting the options for filtering the - * {@link GenericAnnotationView} for the model element hierarchy level. - */ - private CCombo createHierarchyLevelFilterOptionsComboBox(Composite parent, - final GenericAnnotationView view) { - - // Combo box to select component hierarchy level filter - final CCombo filterHierarchyLevelCombo = new CCombo(parent, SWT.READ_ONLY); - - filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_ALL); - filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_CURRENT); - filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_SELECTED_SUBMODEL); - filterHierarchyLevelCombo.select(0); - - view.getAnnotationFilter().setHierarchyLevelFilter(filterHierarchyLevelCombo.getText()); - - filterHierarchyLevelCombo.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - view.getAnnotationFilter() - .setHierarchyLevelFilter(filterHierarchyLevelCombo.getText()); - updateView(view); - } - }); - - return filterHierarchyLevelCombo; - } - - /** - * Returns an {@link ExtendedCCombo} for setting the options for filtering the - * {@link GenericAnnotationView} for the annotation type. - */ - private ExtendedCCombo<Class<? extends IAnnotatedSpecification>> - createAnnotationTypeFilterOptionsComboBox(Composite parent, - final GenericAnnotationView view) { - - // Combo box to select annotation type filter - filterAnnotationTypeCombo = - new ExtendedCCombo<Class<? extends IAnnotatedSpecification>>(parent, SWT.READ_ONLY); - updateAnnotationTypeFilterOptionsComboBox(view.getLastAnnotationEntries(), view); - - filterAnnotationTypeCombo.addSelectionListener(new SelectionAdapter() { - /** {@inheritDoc} */ - @Override - public void widgetSelected(SelectionEvent e) { - Class<? extends IAnnotatedSpecification> selectedAnnotationType = - filterAnnotationTypeCombo - .getObject(filterAnnotationTypeCombo.getSelectionIndex()); - view.getAnnotationFilter().setAnnotationTypeFilter(selectedAnnotationType); - updateView(view); - } - }); - - return filterAnnotationTypeCombo; - } - - /** - * Update the ComboBox that can be used to configure the annotation type filter based on the - * annotations contained in the current set of annotation entries / model elements (before - * filtering). - */ - public void updateAnnotationTypeFilterOptionsComboBox( - Collection<AnnotationEntry> annotationEntries, GenericAnnotationView view) { - String currentSelection = filterAnnotationTypeCombo.getText(); - filterAnnotationTypeCombo.removeAll(); - filterAnnotationTypeCombo.add(ANNOTATION_TYPE_ANY, null); - - if(annotationEntries != null) { - // Set needed to ensure that each IAnnotatedSpecification which may be contributed - // by more than one AnnotationEntry is added exactly once to the ComboBox. - Set<Class<? extends IAnnotatedSpecification>> annotatedSpecificationClasses = - new HashSet<Class<? extends IAnnotatedSpecification>>(); - - for(AnnotationEntry annotationEntry : annotationEntries) { - for(IAnnotatedSpecification spec : annotationEntry.getSpecificationsList()) { - Class<? extends IAnnotatedSpecification> specClass = spec.getClass(); - if(!annotatedSpecificationClasses.contains(specClass)) { - String annotationName = - annotationEntry.getSpecificationAnnotationName(specClass); - filterAnnotationTypeCombo.add("Show " + annotationName, specClass); - annotatedSpecificationClasses.add(specClass); - } - } - } - } - - // If possible, maintain selected element - int index = filterAnnotationTypeCombo.indexOf(currentSelection); - if(index == -1) { - filterAnnotationTypeCombo.select(0); - view.getAnnotationFilter() - .setAnnotationTypeFilter(filterAnnotationTypeCombo.getObject(0)); - } else { - filterAnnotationTypeCombo.select(index); - } - - // Adjust size to new content - filterAnnotationTypeCombo.pack(true); - } - - /** Updates the annotation view. */ - private void updateView(final GenericAnnotationView view) { - view.getAnnotationFilter().annotationViewRequestFullUpdate(); - view.update(); - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/TextFocusListener.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/TextFocusListener.java deleted file mode 100644 index 53aac76e8..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/TextFocusListener.java +++ /dev/null @@ -1,95 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ - -// Based on http://stackoverflow.com/a/10048884, provided by Stackoverflow user "seand". -// (follow link for license) -package org.fortiss.tooling.base.ui.annotation.view.generic.filter; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; - -/** - * Listener to react to focus in/out events of {@link Text} controls than can originate from both - * keyboard and mouse events. - * - * @author barner - */ -public abstract class TextFocusListener implements Listener { - - /** Flag if {@link Text} currently has the focus. */ - private boolean hasFocus = false; - - /** Flag required to obtain focus via mouse events. */ - private boolean hadFocusOnMousedown = false; - - /** Action to be performed on focus in events. */ - protected abstract void focusIn(Text text, Event e); - - /** Action to be performed on focus out events. */ - protected abstract void focusOut(Text text, Event e); - - /** {@inheritDoc} */ - @Override - public void handleEvent(Event e) { - if(!(e.widget instanceof Text)) { - return; - } - Text text = (Text)e.widget; - - switch(e.type) { - case SWT.FocusIn: { - // Covers the case where the user focuses by keyboard. - focusIn(text, e); - - // The case where the user focuses by mouse click is special because Eclipse, - // for some reason, fires SWT.FocusIn before SWT.MouseDown, and on mouse down - // it cancels the selection. So we set a variable to keep track of whether the - // control is focused (can't rely on isFocusControl() because sometimes it's - // wrong), and we make it asynchronous so it will get set AFTER SWT.MouseDown is - // fired. - text.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - hasFocus = true; - } - }); - - break; - } - case SWT.FocusOut: { - hasFocus = false; - focusOut(text, e); - - break; - } - case SWT.MouseDown: { - // Set the variable which is used in SWT.MouseUp. - hadFocusOnMousedown = hasFocus; - - break; - } - case SWT.MouseUp: { - if(!hadFocusOnMousedown) { - focusIn(text, e); - } - - break; - } - } - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/package.html b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/package.html deleted file mode 100644 index f527ba7a7..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/filter/package.html +++ /dev/null @@ -1,4 +0,0 @@ -<!-- (c) 2017 fortiss GmbH --> -<body> -Column and row filters and filter configuration widget for JFace TableViewer based generic annotation view. -</body> diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/package.html b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/package.html deleted file mode 100644 index 25460feef..000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/package.html +++ /dev/null @@ -1,4 +0,0 @@ -<!-- (c) 2017 fortiss GmbH --> -<body> -JFace TableViewer based generic annotation view. -</body> diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/.ratings index e5b3c778d..abc636f3c 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/.ratings @@ -2,4 +2,4 @@ AutoLayoutMenu.java 67dc2d04a6f39ec72ea640b745997baa8ff63a49 GREEN DiagramTapeMeasure.java 72454e6fe5225dab11d3d691baad93aab7a171c0 GREEN IAutoLayouter.java de1b11d9e202c7e23352ad85684dbf8a3fd17c7d GREEN IAutoLayouterTapeMeasure.java df186e0ba505e0ecda211b1df76cf12f3245b47e GREEN -KielerAutoLayouter.java a0f2d0cd94ffd043e6d4ddbe1589a1894412f81c GREEN +KielerAutoLayouter.java 8c01dc17ce6c9a1bbd3fc02f1d19eb86e0a79e86 YELLOW diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/KielerAutoLayouter.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/KielerAutoLayouter.java index a0f2d0cd9..8c01dc17c 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/KielerAutoLayouter.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/layout/auto/KielerAutoLayouter.java @@ -28,8 +28,6 @@ import static de.cau.cs.kieler.klay.layered.properties.Properties.FEEDBACK_EDGES import static de.cau.cs.kieler.klay.layered.properties.Properties.INTERACTIVE_REFERENCE_POINT; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE; -import static org.fortiss.tooling.base.ui.annotation.view.AnnotationViewPartBase.isUpdateEnabled; -import static org.fortiss.tooling.base.ui.annotation.view.AnnotationViewPartBase.setUpdateEnabled; import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addBendPointToConnection; import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodeLayoutData; import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodePosition; @@ -114,8 +112,6 @@ public class KielerAutoLayouter implements IAutoLayouter { /** {@inheritDoc} */ @Override public void performAutoLayout(IHierarchicElement element) { - boolean avUpdateEnabled = isUpdateEnabled(); - setUpdateEnabled(false); KNode rootNode = createKIELERGraph(element); KShapeLayout rootNodeLayout = rootNode.getData(KShapeLayout.class); @@ -129,8 +125,6 @@ public class KielerAutoLayouter implements IAutoLayouter { layoutProvider.doLayout(rootNode, progressMonitor); applyLayout(rootNode, element); - - setUpdateEnabled(avUpdateEnabled); } /** -- GitLab