diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationLabelProvider.java index 264049cde059f91b2a82f443056c4dba17d7789a..54278df1456d492bf6f6df8dcbad90c84ca346d8 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationLabelProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationLabelProvider.java @@ -37,7 +37,7 @@ public class AnnotationLabelProvider extends ColumnLabelProvider { protected Class<? extends IAnnotatedSpecification> specClass; /** Contains the basic annotation view class */ - protected AnnotationViewPartBase parentView; + protected IAnnotationViewPart parentView; /** String holding the key of which identifies the value to be displayed */ protected String instanceKey; @@ -51,7 +51,7 @@ public class AnnotationLabelProvider extends ColumnLabelProvider { * @param instanceKey */ public AnnotationLabelProvider(Class<? extends IAnnotatedSpecification> class1, - AnnotationViewPartBase parent, String instanceKey) { + IAnnotationViewPart parent, String instanceKey) { specClass = class1; parentView = parent; this.instanceKey = instanceKey; diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java index 8a531d85050da4d82b359e1f1865ad04841d0988..1f13380637dc17b60b8b810826e64844f1b13781 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java @@ -51,7 +51,7 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils; * @version $Rev$ * @ConQAT.Rating YELLOW Hash: 40FF672DC52B17062D1716341177D76A */ -public abstract class AnnotationViewPartBase extends ViewPart implements ISelectionListener { +public abstract class AnnotationViewPartBase extends ViewPart implements ISelectionListener, IAnnotationViewPart { /** the currently selected object */ private IModelElement currentlySelectedObject; @@ -188,7 +188,8 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this); } - /** Returns currentlySelectedObject. */ + /** {@inheritDoc} */ + @Override public IModelElement getCurrentlySelectedObject() { return currentlySelectedObject; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/ElementNameLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/ElementNameLabelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..28ac41ced3134cebbf5102ff07951296c79d838e --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/ElementNameLabelProvider.java @@ -0,0 +1,76 @@ +/*--------------------------------------------------------------------------+ +$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.view; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.graphics.Color; +import org.eclipse.wb.swt.SWTResourceManager; +import org.fortiss.tooling.base.model.element.IModelElement; +import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; +import org.fortiss.tooling.kernel.model.INamedElement; + +/** + * Provider that uses the names of {@link INamedElement}s as column labels. + * + * @author barner + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public class ElementNameLabelProvider extends ColumnLabelProvider { + /** The view part in which this {@link ElementNameLabelProvider} is used. */ + private final IAnnotationViewPart viewPart; + + /** Column the which a label is provided by this {@link ElementNameLabelProvider}. */ + private final TableViewerColumn column; + + /** Creates a new {@link ElementNameLabelProvider} for a given {@code column}. */ + public ElementNameLabelProvider(IAnnotationViewPart viewPart, TableViewerColumn column) { + this.viewPart = viewPart; + this.column = column; + } + + /** {@inheritDoc} */ + @Override + public String getText(Object element) { + AnnotationEntry annotationEntry = (AnnotationEntry)element; + IModelElement modelElement = annotationEntry.getModelElement(); + + String modelElementName = modelElement.getClass().getSimpleName(); + modelElementName = modelElementName.replace("Impl", ""); + column.getColumn().setText(modelElementName); + + if(modelElement instanceof INamedElement) { + return ((INamedElement)modelElement).getName(); + } + return "-"; + } + + /** {@inheritDoc} */ + @Override + public Color getBackground(Object element) { + if(element instanceof AnnotationEntry) { + AnnotationEntry data = (AnnotationEntry)element; + if(data.getModelElement().equals(viewPart.getCurrentlySelectedObject())) { + return SWTResourceManager.getColor(0, 255, 0); + } + } + return super.getBackground(element); + } +} 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 849e066b8c5b95a4ee0d867d441bb0bd242f46a3..7ec1899cab3e93abd09473669c64d5840a375267 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 @@ -25,26 +25,28 @@ import java.util.Map; import org.eclipse.emf.common.util.EMap; import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; -import org.eclipse.wb.swt.SWTResourceManager; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; -import org.fortiss.tooling.kernel.model.INamedCommentedElement; +import org.fortiss.tooling.base.ui.annotation.valueprovider.IAnnotationValueProvider; /** + * <p> * This class provides a generic annotation view whose methods are intended to be reused by child * classes. Inherited classes can avoid code duplication, e.g. the creation of the table and its * first row, using this class. - * Per default, this class only supports displaying simple annotation types. You are required to - * override the {@code selectionChanged} method to support displaying these annotations. + * </p> + * <p> + * In order to support displaying and editing specific annotation types, the corresponding + * {@link IAnnotationValueProvider#createEditingSupport(org.eclipse.jface.viewers.ColumnViewer, Class, String)} + * factory method must return an appropriate {@link EditingSupport}. + * </p> * * @author eder, diewald, barner * @author $Author$ @@ -189,29 +191,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { firstColumn.getColumn().setWidth(100); tableViewer.setContentProvider(new ArrayContentProvider()); - firstColumn.setLabelProvider(new ColumnLabelProvider() { - /** {@inheritDoc} */ - @Override - public String getText(Object element) { - AnnotationEntry entry = (AnnotationEntry)element; - String modelElementName = entry.getModelElement().getClass().getSimpleName(); - modelElementName = modelElementName.replace("Impl", ""); - firstColumn.getColumn().setText(modelElementName); - return ((INamedCommentedElement)entry.getModelElement()).getName(); - } - - /** {@inheritDoc} */ - @Override - public Color getBackground(Object element) { - if(element instanceof AnnotationEntry) { - AnnotationEntry data = (AnnotationEntry)element; - if(data.getModelElement().equals(getCurrentlySelectedObject())) { - return SWTResourceManager.getColor(0, 255, 0); - } - } - return super.getBackground(element); - } - }); + firstColumn.setLabelProvider(new ElementNameLabelProvider(this, firstColumn)); } /** Creates a column in tableViewer that displays the annotation given in spec */ diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java new file mode 100644 index 0000000000000000000000000000000000000000..f2c2c890c99a147d55dda83bec5c421ece4344e6 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/IAnnotationViewPart.java @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------+ +$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.view; + +import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; +import org.fortiss.tooling.base.model.element.IModelElement; + +/** + * Interface for views displaying {@link IAnnotatedSpecification}s. + * + * @author barner + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public interface IAnnotationViewPart { + + /** Returns the currently selected object. */ + public IModelElement getCurrentlySelectedObject(); + +}