From 8163bfa03b0fb1dcbedf79ff945d3d44f0866c3a Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Thu, 28 Aug 2014 15:13:39 +0000 Subject: [PATCH] - Enable editing of component names from GenericAnnotationView refs 1841 --- .../ElementNameEditingSupport.java | 71 +++++++++++++++++++ .../view/GenericAnnotationView.java | 2 + 2 files changed, 73 insertions(+) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java new file mode 100644 index 000000000..aa45adf3c --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ElementNameEditingSupport.java @@ -0,0 +1,71 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| 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.model.element.IModelElement; +import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; +import org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView; +import org.fortiss.tooling.kernel.model.INamedElement; + +/** + * Base class for {@link EditingSupport}s used in the {@link GenericAnnotationView}. + * + * @author barner + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED + */ +public class ElementNameEditingSupport extends TextEditingSupport { + + /** Constructs a new {@link ElementNameEditingSupport}. */ + public ElementNameEditingSupport(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 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/trunk/src/org/fortiss/tooling/base/ui/annotation/view/GenericAnnotationView.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/GenericAnnotationView.java index 7ec1899ca..1eb0b7efe 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/GenericAnnotationView.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/GenericAnnotationView.java @@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; +import org.fortiss.tooling.base.ui.annotation.editingsupport.ElementNameEditingSupport; import org.fortiss.tooling.base.ui.annotation.valueprovider.IAnnotationValueProvider; /** @@ -192,6 +193,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { tableViewer.setContentProvider(new ArrayContentProvider()); firstColumn.setLabelProvider(new ElementNameLabelProvider(this, firstColumn)); + firstColumn.setEditingSupport(new ElementNameEditingSupport(tableViewer)); } /** Creates a column in tableViewer that displays the annotation given in spec */ -- GitLab