Skip to content
Snippets Groups Projects
Commit d913bdf8 authored by Johannes Eder's avatar Johannes Eder
Browse files

added combo box possibility for table cells

refs 1841
parent fc50dec8
No related branches found
No related tags found
No related merge requests found
org.fortiss.tooling.base.ui/trunk/icons/annotation.gif

329 B

......@@ -13,7 +13,7 @@
<extension
point="org.eclipse.ui.views">
<view
class="org.fortiss.tooling.base.ui.annotation.DummyAnnotationView"
class="org.fortiss.tooling.base.ui.annotation.GenericAnnotationView"
id="org.fortiss.tooling.base.ui.annotationBase"
name="Annotation"
restorable="true">
......
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation;
import java.util.List;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -52,6 +54,14 @@ public class AnnotationEntry<T extends IAnnotatedSpecification> {
return valueProvider.getValue((T)specification);
}
public List<String> getFixedSpecifiactionValues() {
return valueProvider.getFixedValues();
}
public void setSpecificationValue(String value) {
valueProvider.setValue(value, (T)specification);
}
/** Returns modelElement. */
public IModelElement getModelElement() {
return modelElement;
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 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;
import static org.eclipse.swt.SWT.COLOR_DARK_GRAY;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.editpart.ElementEditPartBase;
import org.fortiss.tooling.kernel.ui.util.SelectionUtils;
/**
* Base class for displaying {@link IAnnotatedSpecification}s
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class AnnotationViewPartBase<T extends EObject, V extends IAnnotatedSpecification>
extends ViewPart implements ISelectionListener {
/** Color of the selected component */
protected Color currentlySelectedColor = Display.getCurrent().getSystemColor(SWT.COLOR_CYAN);
/** Color of non editable components */
protected Color notEditibleColor = Display.getCurrent().getSystemColor(COLOR_DARK_GRAY);
/** The currently selected Object */
private T currentlySelectedObject;
/** The annotated specification of the {@link #currentlySelectedObject} */
private V annotatedSpecification;
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
currentlySelectedObject = null;
currentlySelectedObject = SelectionUtils.checkAndPickFirst(selection, getT());
if(currentlySelectedObject == null) {
ElementEditPartBase<?> editPart =
SelectionUtils.checkAndPickFirst(selection, ElementEditPartBase.class);
if(editPart != null)
currentlySelectedObject = (T)editPart.getModel();
}
if(isAcceptedSelection(currentlySelectedObject)) {
addAll();
annotatedSpecification = extractAnnotatedSpecification();
onUpdateView();
}
}
/** Extracts the {@link IAnnotatedSpecification} from {@link #currentlySelectedObject} */
protected abstract V extractAnnotatedSpecification();
/** Returns the annotated specification. Null if there is none. */
public V getAnnotatedSpecification() {
return annotatedSpecification;
}
/** Returns currentlySelectedObject. Null if there is none. */
public T getCurrentlySelectedObject() {
return currentlySelectedObject;
}
/** Returns the class of type T. Must not be null! */
protected abstract Class<T> getT();
/** {@inheritDoc} */
@Override
public void dispose() {
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
super.dispose();
}
/** Adds specifications to all {@link IModelElement} */
protected abstract void addAll();
/** Returns all annotated specs of Type V */
protected abstract List<V> getAllAnnotatedSpecs();
/** called every time the view is updated */
protected abstract void onUpdateView();
protected abstract boolean isAcceptedSelection(EObject object);
}
......@@ -18,20 +18,31 @@ $Id$
package org.fortiss.tooling.base.ui.annotation;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbenchPart;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
*
......@@ -40,7 +51,7 @@ import org.fortiss.tooling.kernel.model.INamedCommentedElement;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DummyAnnotationView extends AnnotationViewPartBase2 {
public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** mapping of {@link IAnnotatedSpecification} -> TableViewerColumn */
private HashMap<Class<? extends IAnnotatedSpecification>, TableViewerColumn> columns =
......@@ -98,7 +109,17 @@ public class DummyAnnotationView extends AnnotationViewPartBase2 {
column.getColumn().setText(entry.getAnnotationName());
column.getColumn().setWidth(100);
columns.put(entry.getSpecification().getClass(), column);
column.setLabelProvider(new ColumnLabelProvider2());
if(entry.getFixedSpecifiactionValues() == null) {
column.setLabelProvider(new AnnotationLabelProvider());
EditingSupport editingSupport = new StandardEditingSupport(column.getViewer());
column.setEditingSupport(editingSupport);
} else {
column.setLabelProvider(new AnnotationLabelProvider());
EditingSupport editingSupport =
new ComboEditingSupport(column.getViewer(),
entry.getFixedSpecifiactionValues());
column.setEditingSupport(editingSupport);
}
}
}
......@@ -115,92 +136,157 @@ public class DummyAnnotationView extends AnnotationViewPartBase2 {
return false;
}
private class ColumnLabelProvider2 extends ColumnLabelProvider {
private final class ComboEditingSupport extends EditingSupport {
private ComboBoxViewerCellEditor cellEditor = null;
/**
* @param viewer
* @param values
*/
private ComboEditingSupport(ColumnViewer viewer, List<String> values) {
super(viewer);
cellEditor =
new ComboBoxViewerCellEditor((Composite)getViewer().getControl(), SWT.READ_ONLY);
cellEditor.setLabelProvider(new LabelProvider());
cellEditor.setContentProvider(new ArrayContentProvider());
cellEditor.setInput(values);
}
/** {@inheritDoc} */
@Override
public String getText(Object element) {
AnnotationEntry<?> entry = (AnnotationEntry<?>)element;
return entry.getSpecificationValue();
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
return true;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
}
return null;
}
/** {@inheritDoc} */
@Override
protected void setValue(Object element, final Object value) {
boolean test = true;
if(element instanceof AnnotationEntry<?> && value instanceof String) {
final AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(!value.equals(data.getSpecificationValue())) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(data
.getModelElement());
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
try {
data.setSpecificationValue((String)value);
} catch(IllegalArgumentException e) {
// should not happen with combo boxes and given values
MessageDialog.openError(new Shell(), "ERROR",
"The value you entered does not have the desired type.");
}
}
});
this.getViewer().refresh(true);
}
}
}
}
private final class StandardEditingSupport extends EditingSupport {
private TextCellEditor cellEditor = null;
/**
* @param viewer
*/
public StandardEditingSupport(ColumnViewer viewer) {
super(viewer);
cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE);
}
/** {@inheritDoc} */
@Override
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
return true;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
}
return null;
}
/** {@inheritDoc} */
@Override
protected void setValue(Object element, final Object value) {
if(element instanceof AnnotationEntry<?> && value instanceof String) {
final AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(!value.equals(data.getSpecificationValue())) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(data
.getModelElement());
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
try {
data.setSpecificationValue((String)value);
} catch(IllegalArgumentException e) {
// e.printStackTrace();
MessageDialog.openError(new Shell(), "ERROR",
"The value you entered does not have the desired type.");
}
}
});
this.getViewer().refresh(true);
}
}
}
}
// FIXME
// public final class ExampleEditingSupport extends EditingSupport {
//
// private ComboBoxViewerCellEditor cellEditor = null;
//
// private ExampleEditingSupport(ColumnViewer viewer) {
// super(viewer);
// cellEditor =
// new ComboBoxViewerCellEditor((Composite)getViewer().getControl(), SWT.READ_ONLY);
// cellEditor.setLabelProvider(new LabelProvider());
// cellEditor.setContentProvider(new ArrayContentProvider());
// cellEditor.setInput(Value.values());
// }
//
// @Override
// protected CellEditor getCellEditor(Object element) {
// return cellEditor;
// }
//
// @Override
// protected boolean canEdit(Object element) {
// return true;
// }
//
// @Override
// protected Object getValue(Object element) {
// if(element instanceof ExampleData) {
// ExampleData data = (ExampleData)element;
// return data.getData();
// }
// return null;
// }
//
// @Override
// protected void setValue(Object element, Object value) {
// if(element instanceof ExampleData && value instanceof Value) {
// ExampleData data = (ExampleData)element;
// Value newValue = (Value)value;
// /* only set new value if it differs from old one */
// if(!data.getData().equals(newValue)) {
// data.setData(newValue);
// }
// }
// }
//
// }
//
// public static enum Value {
// value1, value2, value3;
// }
//
// public class ExampleData {
//
// private String label;
// private Value value;
//
// public ExampleData(String label, Value data) {
// this.label = label;
// this.value = data;
// }
//
// public String getLabel() {
// return label;
// }
//
// public void setLabel(String label) {
// this.label = label;
// }
//
// public Value getData() {
// return value;
// }
//
// public void setData(Value data) {
// this.value = data;
// }
//
// }
/** Label provider for {@link AnnotationEntry}s */
public final class AnnotationLabelProvider extends ColumnLabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
}
return "-";
}
}
}
......@@ -35,15 +35,15 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware;
public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> extends
IEObjectAware<IModelElement> {
// List<Annotation> annotations = new ArrayList<Annotation>();
/** Returns the specific value */
public String getValue(T specification);
public void setValue(String value, T specification);
/**
* if this method does not return null, a combo box is provided with the specific return values
*/
public List<String> getFixedValues();
/** Returns the specific type of T */
// public Class<? extends IAnnotatedSpecification> getAnnotatedSpecClazz();
public void setValue(String value, T specification) throws IllegalArgumentException;
public T addNewSpecToModelElement(IModelElement element);
......
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