Commit 6d75a3b0 authored by Simon Barner's avatar Simon Barner
Browse files

Enable to edit ParameterEntries directly within allocation editor:

- Add ParameterTableEditor, ParameterTableTreeViewerManager, ParameterEntryTreeViewerLabelProvider, ParameterEntryTreeViewerEditingSupport
- Add Annotations.{getParameterEntryValue(), setParameterEntryValue(), getParameterEntryName()}

Use this new feature in TaskWcetTableEditor
refs 2950,2562
parent b747f701
AllocationTableEditor.java 3f180b48f7012d56fa887b46ac3e98ec37a1bb8d YELLOW
AllocationTableEditor.java 49a3ff93d5907b5c97fb81a3f138e2467efd2fc3 YELLOW
AllocationTableEditorUtils.java 3f53fc3ce279be40ca18d6d63f3f7f830ec4eb86 RED
ModelListenerEditorBase.java ad5ecd0c353234b76bb81dad72fb259ff961607f YELLOW
ModelListenerEditorBase.java 049722f3cc28e7533e6baf74dfaf399cbd7bcb79 YELLOW
ParameterTableEditor.java 8e2dd6f79bf9b907db6606febb6b89292470acf9 YELLOW
......@@ -36,6 +36,7 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
......@@ -98,14 +99,23 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
private TreeViewerManager<T> treeViewerManager;
/** Constructor. */
protected AllocationTableEditor(Class<? extends AllocationEntry> allocationEntryType,
ViewElementFilter sourceViewElementFilter, ViewElementFilter targetViewElementFilter) {
/* package */AllocationTableEditor(Class<? extends AllocationEntry> allocationEntryType,
ViewElementFilter sourceViewElementFilter, ViewElementFilter targetViewElementFilter,
List<EStructuralFeature> observedFeatures) {
super(observedFeatures);
this.allocationEntryType = allocationEntryType;
this.sourceViewElementFilter = sourceViewElementFilter;
this.targetViewElementFilter = targetViewElementFilter;
}
/** Constructor. */
protected AllocationTableEditor(Class<? extends AllocationEntry> allocationEntryType,
ViewElementFilter sourceViewElementFilter, ViewElementFilter targetViewElementFilter) {
this(allocationEntryType, sourceViewElementFilter, targetViewElementFilter, emptyList());
}
/** Constructor. */
protected AllocationTableEditor(Class<? extends AllocationEntry> allocationEntryType) {
this(allocationEntryType, null, null);
......@@ -353,13 +363,21 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
/********************* Implementation of IWorkbenchPart *********************/
/**
* Creates the {@link TreeViewerManager} used to provide the tree representation of the edited
* {@link AllocationTable}.
*/
protected TreeViewerManager<T> createTreeViewerManager(TreeViewer treeViewer) {
return new TreeViewerManager<T>(this, treeViewer);
}
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
checkConfiguration();
gui = new AllocationTableEditorGUI(parent, SWT.NONE);
treeViewerManager = new TreeViewerManager<>(this, gui.getTreeViewer());
treeViewerManager = createTreeViewerManager(gui.getTreeViewer());
final IAllocationService as = IAllocationService.getInstance();
IProjectRootElement sourceView = null;
......
......@@ -15,7 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.allocation.ui.editor;
import static java.util.Collections.emptyList;
import static org.eclipse.emf.common.notify.Notification.ADD;
import static org.eclipse.emf.common.notify.Notification.REMOVE;
import static org.eclipse.emf.common.notify.Notification.REMOVING_ADAPTER;
......@@ -63,7 +62,7 @@ public abstract class ModelListenerEditorBase<T extends EObject> extends GEFEdit
private FileProject fileProject;
/** Features in models and model entities to be observed. */
private List<EStructuralFeature> observedFeatures = emptyList();
private List<EStructuralFeature> observedFeatures;
/**
* Adapter to watch a {@link FileProject} for added / removed / renamed
......@@ -121,10 +120,6 @@ public abstract class ModelListenerEditorBase<T extends EObject> extends GEFEdit
}
};
/** Constructor. */
public ModelListenerEditorBase() {
}
/** Constructor. */
public ModelListenerEditorBase(List<EStructuralFeature> observedFeatures) {
this.observedFeatures = observedFeatures;
......
/*-------------------------------------------------------------------------+
| Copyright 2017 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.af3.allocation.ui.editor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getEClassForClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.TreeViewer;
import org.fortiss.af3.allocation.model.ParameterEntry;
import org.fortiss.af3.allocation.model.ParameterTable;
import org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager;
import org.fortiss.af3.allocation.ui.editor.treeviewer.TreeViewerManager;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
/**
* Editor for {@link ParameterTable}s.
*
* @author barner
*/
public class ParameterTableEditor<T extends ParameterTable> extends AllocationTableEditor<T> {
/** Type of annotation used to implement parameter. */
private Class<? extends IAnnotatedSpecification> annotationType;
/** Constructor. */
public ParameterTableEditor(Class<? extends ParameterEntry> allocationEntryType,
Class<? extends IAnnotatedSpecification> annotationType,
ViewElementFilter sourceViewElementFilter, ViewElementFilter targetViewElementFilter) {
super(allocationEntryType, sourceViewElementFilter, targetViewElementFilter,
getEClassForClass(annotationType).getEAllStructuralFeatures());
this.annotationType = annotationType;
}
/** Constructor. */
public ParameterTableEditor(Class<? extends ParameterEntry> allocationEntryType,
Class<? extends IAnnotatedSpecification> annotationType) {
super(allocationEntryType, null, null, getEClassForClass(annotationType)
.getEAllStructuralFeatures());
this.annotationType = annotationType;
}
/** {@inheritDoc} */
@Override
protected TreeViewerManager<T> createTreeViewerManager(TreeViewer treeViewer) {
return new ParameterTableTreeViewerManager<T>(this, treeViewer, annotationType);
}
/** {@inheritDoc} */
@Override
protected void valueSet(EObject eObject) {
// Refresh TreeViewer in case an EStructuralFeature of the underlying annotationType has
// been set.
getGUI().getTreeViewer().refresh();
}
}
ParameterEntryTreeViewerEditingSupport.java 759d5a5462aef5ec2ccd5e0b61b5858d3196145a YELLOW
ParameterEntryTreeViewerLabelProvider.java c6cd26de2d483a43f013893d0feff158e7cdb1bf YELLOW
ParameterTableTreeViewerManager.java 39e302f938586545f8fb0d2f61ffbed4ff31faef YELLOW
TreeViewerCheckBoxEditingSupport.java ae801bf9e495b983774224444549cfc8c26fee58 YELLOW
TreeViewerCheckBoxLabelProvider.java 6cb338ada7c286ae7aaedc3a9f326136571daf81 YELLOW
TreeViewerContentProvider.java 6b97e361c3c8a633eb29963d44f7d4b3a9b9089a YELLOW
TreeViewerFirstColumnLabelProvider.java 974b095a190e6f57d437bc3b85753ac5b4ecabf6 YELLOW
TreeViewerManager.java 581304be0e99fb714c1cf3f4e67ba15f2536b68f YELLOW
TreeViewerManager.java 9cd53feeb73f5e7a1a042d88f9cbc025955ce880 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2017 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.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.utils.AllocationUtils.deleteAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryValue;
import static org.fortiss.af3.allocation.utils.AllocationUtils.isModifiableAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.setParameterEntryValue;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
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.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.ParameterEntry;
import org.fortiss.af3.allocation.model.ParameterTable;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* Editing support to edit {@link AllocationTable}'s entries.
*
* @author barner
*/
public class ParameterEntryTreeViewerEditingSupport<T extends ParameterTable> extends
EditingSupport {
/** The underlying {@link ParameterTable}. */
private T parameterTable;
/**
* {@link AllocationEntry} type to be edited in this
* {@link ParameterEntryTreeViewerEditingSupport}.
*/
private Class<? extends ParameterEntry> parameterEntryType;
/** Target element of {@link AllocationTable} entry. */
private IModelElement targetElement;
/** Annotation type used to implement this {@link ParameterEntry}. */
private Class<? extends IAnnotatedSpecification> annotationType;
/** The editor used to manipulate the value of the cell. */
private TextCellEditor textCellEditor = new TextCellEditor((Composite)getViewer().getControl(),
SWT.NONE);
/** Constructor. */
public ParameterEntryTreeViewerEditingSupport(T parameterTable,
Class<? extends ParameterEntry> parameterEntryType, IModelElement targetElement,
Class<? extends IAnnotatedSpecification> annotationType, ColumnViewer viewer) {
super(viewer);
this.parameterTable = parameterTable;
this.parameterEntryType = parameterEntryType;
this.targetElement = targetElement;
this.annotationType = annotationType;
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
if(element instanceof IModelElement) {
IModelElement sourceElement = (IModelElement)element;
return isModifiableAllocationEntry(parameterTable, parameterEntryType, sourceElement,
targetElement);
}
return false;
}
/** {@inheritDoc} */
@Override
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object element) {
if(element instanceof IModelElement) {
final String value =
getParameterEntryValue(parameterTable, (IModelElement)element, targetElement,
parameterEntryType, annotationType);
// Return empty String instead of null since otherwise the CellEditor cannot be
// initialized correctly when editing an empty cell.
return value != null ? value : "";
}
return null;
}
/** {@inheritDoc} */
@Override
protected void setValue(Object element, Object value) {
if(element instanceof IModelElement) {
runAsCommand(
parameterTable,
() -> {
final IModelElement sourceElement = (IModelElement)element;
if(value != null && !value.equals("")) {
setParameterEntryValue(parameterTable, sourceElement, targetElement,
value, parameterEntryType, annotationType);
} else {
deleteAllocationEntry(parameterTable, parameterEntryType,
sourceElement, targetElement);
}
});
getViewer().refresh(true);
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2017 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.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.ui.DefaultStyle.RIGHT_ARROW;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryName;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryValue;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.ParameterEntry;
import org.fortiss.af3.allocation.model.ParameterTable;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* Label provider to display {@link ParameterEntry}s.
*
* @author barner
*/
public class ParameterEntryTreeViewerLabelProvider<T extends ParameterTable> extends
ColumnLabelProvider {
/** The underlying {@link ParameterTable}. */
private T parameterTable;
/**
* {@link ParameterEntry} type to be edited in this
* {@link ParameterEntryTreeViewerLabelProvider}.
*/
private Class<? extends ParameterEntry> parameterEntryType;
/**
* Type of source model entities used to create {@link AllocationEntry}s for the given
* {@link AllocationTable}.
*/
private Class<? extends IModelElement> sourceEntityType;
/** Target element of {@link AllocationTable} entry. */
private IModelElement targetElement;
/** Annotation type used to implement this {@link ParameterEntry}. */
private Class<? extends IAnnotatedSpecification> annotationType;
/** Constructor. */
public ParameterEntryTreeViewerLabelProvider(T parameterTable,
Class<? extends ParameterEntry> parameterEntryType,
Class<? extends IModelElement> sourceEntityType, IModelElement targetElement,
Class<? extends IAnnotatedSpecification> annotationType) {
this.parameterTable = parameterTable;
this.parameterEntryType = parameterEntryType;
this.sourceEntityType = sourceEntityType;
this.targetElement = targetElement;
this.annotationType = annotationType;
}
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if(element != null && sourceEntityType.isAssignableFrom(element.getClass())) {
return getParameterEntryValue(parameterTable, (IModelElement)element, targetElement,
parameterEntryType, annotationType);
}
return null;
}
/**
* Returns the tooltip label prefix for the given {@code sourceElement} that provides the name
* of the underlying {@link IAnnotatedSpecification}.
*/
private String getParameterToolTipLabelPrefix(IModelElement sourceElement) {
String parameterToolTipLabel =
getParameterEntryName(parameterTable, sourceElement, targetElement,
parameterEntryType, annotationType);
return parameterToolTipLabel + " of\n";
}
/** {@inheritDoc} */
@Override
public String getToolTipText(Object object) {
if(object instanceof IModelElement) {
IModelElement sourceElement = (IModelElement)object;
return getParameterToolTipLabelPrefix(sourceElement) + getName(sourceElement) + " " +
"\n" + RIGHT_ARROW + "\n" + getName(targetElement);
}
return null;
}
/** {@inheritDoc} */
@Override
public int getToolTipStyle(Object object) {
return SWT.CENTER;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2017 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.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryName;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.ParameterEntry;
import org.fortiss.af3.allocation.model.ParameterTable;
import org.fortiss.af3.allocation.ui.editor.AllocationTableEditor;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* Manages a {@link TreeViewer} to show and edit entries of {@link ParameterTable}s.
*
* @author barner
*/
public class ParameterTableTreeViewerManager<T extends ParameterTable> extends TreeViewerManager<T> {
/** Annotation type used to implement this {@link ParameterEntry}. */
private Class<? extends IAnnotatedSpecification> annotationType;
/** Constructor. */
public ParameterTableTreeViewerManager(AllocationTableEditor<T> allocationTableEditor,
TreeViewer treeViewer, Class<? extends IAnnotatedSpecification> annotationType) {
super(allocationTableEditor, treeViewer);
this.annotationType = annotationType;
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
protected ColumnLabelProvider createColumnLabelProvider(AllocationTable allocationTable,
Class<? extends AllocationEntry> allocationEntryType,
Class<? extends IModelElement> sourceEntityType, IModelElement targetElement) {
return new ParameterEntryTreeViewerLabelProvider<T>((T)allocationTable,
(Class<? extends ParameterEntry>)allocationEntryType, sourceEntityType,
targetElement, annotationType);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected EditingSupport createEditingSupport(AllocationTable allocationTable,
Class<? extends AllocationEntry> allocationEntryType, IModelElement targetElement) {
return new ParameterEntryTreeViewerEditingSupport<T>((T)allocationTable,
(Class<? extends ParameterEntry>)allocationEntryType, targetElement,
annotationType, treeViewer);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected String getColumnLabel(TreeViewerColumn treeViewerColumn, IModelElement targetElement,
boolean showContainerName,
TreeViewerFirstColumnLabelProvider<T> firstColumnLabelProvider) {
String columnLabel =
super.getColumnLabel(treeViewerColumn, targetElement, showContainerName,
firstColumnLabelProvider);
String parameterName =
getParameterEntryName((ParameterTable)allocationTableEditor.getEditedObject(),
null, targetElement,
(Class<? extends ParameterEntry>)allocationTableEditor
.getAllocationEntryType(), annotationType);
return parameterName + ": " + columnLabel;
}
}
......@@ -22,6 +22,8 @@ import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.ge
import java.util.List;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.SWT;
......@@ -36,8 +38,7 @@ import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* {@link org.eclipse.jface.viewers.TreeViewer} specialization to show and edit entries of
* {@link AllocationTable}s.
* Manages a {@link TreeViewer} to show and edit entries of {@link AllocationTable}s.
*
* @author barner
*/
......@@ -53,10 +54,10 @@ public class TreeViewerManager<T extends AllocationTable> {
public static final int ROW_LABEL_INDENT = 25;
/** {@link AllocationTableEditor} for which this {@link TreeViewerManager} is used. */
private final AllocationTableEditor<T> allocationTableEditor;
protected final AllocationTableEditor<T> allocationTableEditor;
/** The {@link TreeViewer} that is managed by this {@link TreeViewerManager}. */
private TreeViewer treeViewer;
protected TreeViewer treeViewer;
/** Constructor. */
public TreeViewerManager(AllocationTableEditor<T> allocationTableEditor, TreeViewer treeViewer) {
......@@ -110,29 +111,25 @@ public class TreeViewerManager<T extends AllocationTable> {
treeColumn.setWidth(100);
boolean showContainerName = targetElement instanceof IConnector;
treeColumn.setText(firstColumnLabelProvider.getTrimmedColumnLabel(targetElement,
treeViewerColumn, showContainerName, COLUMN_HEADER_OFFSET));
treeColumn.setText(getColumnLabel(treeViewerColumn, targetElement, showContainerName,
firstColumnLabelProvider));
treeColumn.setToolTipText(firstColumnLabelProvider.getToolTipText(targetElement));
treeColumn.setImage(getImage(targetElement));
Class<? extends AllocationEntry> allocationEntryType =
allocationTableEditor.getAllocationEntryType();
Class<? extends IModelElement> sourceEntityType =