Skip to content
Snippets Groups Projects
Commit 5ef9da17 authored by Simon Barner's avatar Simon Barner
Browse files

- Move column label provider displaying the model element names in the first...

- Move column label provider displaying the model element names in the first column to a dedicated class ElementNameLabelProvider
- Introduce IAnnotationViewPart
parent eaf71397
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
/*--------------------------------------------------------------------------+
$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);
}
}
......@@ -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 */
......
/*--------------------------------------------------------------------------+
$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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment