Commit 64f89500 authored by Simon Barner's avatar Simon Barner
Browse files

Create column to enable editing annotations that are annotated source entities...

Create column to enable editing annotations that are annotated source entities directly in ParameterTableEditor.

Example: Edit target-independent WCET of Tasks, in addition to the per-target column provided by ParameterEntryTreeViewerLabelProvider and ParameterEntryTreeViewerEditingSupport.
refs 2950,2562
parent 3e151065
ParameterEntryTreeViewerEditingSupport.java 759d5a5462aef5ec2ccd5e0b61b5858d3196145a YELLOW
ParameterEntryTreeViewerLabelProvider.java c6cd26de2d483a43f013893d0feff158e7cdb1bf YELLOW
ParameterTableTreeViewerManager.java 23b4b5039041e219945f08b00976954b30603299 YELLOW
ParameterSourceElementTreeViewerEditingSupport.java 6981413de8dc26e39aa144066ac41fd0181c543f YELLOW
ParameterSourceElementTreeViewerLabelProvider.java e2dbecb997ee8e283cd6eb9f91a882a8ec7b75e9 YELLOW
ParameterTableTreeViewerManager.java 2794ccede2a6dd2ddd38b5a9db08eef596c510b3 YELLOW
TreeViewerCheckBoxEditingSupport.java ae801bf9e495b983774224444549cfc8c26fee58 YELLOW
TreeViewerCheckBoxLabelProvider.java 6cb338ada7c286ae7aaedc3a9f326136571daf81 YELLOW
TreeViewerContentProvider.java 6b97e361c3c8a633eb29963d44f7d4b3a9b9089a YELLOW
......
/*-------------------------------------------------------------------------+
| Copyright 2018 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.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationType;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
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.AF3AllocationActivator;
import org.fortiss.af3.allocation.ui.editor.ParameterTableEditor;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* {@link EditingSupport} to enable editing parameter annotations of source entity types
* directly in {@link ParameterTableEditor}.
*
* @author barner
*/
public class ParameterSourceElementTreeViewerEditingSupport extends EditingSupport {
/** Annotation type used to implement this parameter */
private Class<? extends IAnnotatedSpecification> annotationType;
/** Type of annotated source entities. */
private Class<? extends IModelElement> sourceEntityType;
/** The editor used to manipulate the value of the cell. */
private TextCellEditor textCellEditor = new TextCellEditor((Composite)getViewer().getControl(),
SWT.NONE);
/** Constructor. */
public ParameterSourceElementTreeViewerEditingSupport(
Class<? extends IAnnotatedSpecification> annotationType,
Class<? extends IModelElement> sourceEntityType, ColumnViewer viewer) {
super(viewer);
this.annotationType = annotationType;
this.sourceEntityType = sourceEntityType;
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object object) {
if(object != null && sourceEntityType.isAssignableFrom(object.getClass())) {
AnnotationEntry annotationEntry =
IAnnotationValueService.getInstance().getAnnotationEntry((IModelElement)object);
return annotationEntry.canEdit(getAnnotationType(annotationEntry, annotationType));
}
return false;
}
/** {@inheritDoc} */
@Override
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object object) {
if(object != null && sourceEntityType.isAssignableFrom(object.getClass())) {
AnnotationEntry annotationEntry =
IAnnotationValueService.getInstance().getAnnotationEntry((IModelElement)object);
Object value =
annotationEntry.getSpecificationValue(getAnnotationType(annotationEntry,
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 object, Object value) {
if(object != null && sourceEntityType.isAssignableFrom(object.getClass())) {
final IModelElement element = (IModelElement)object;
runAsCommand(
element,
() -> {
AnnotationEntry annotationEntry =
IAnnotationValueService.getInstance().getAnnotationEntry(element);
try {
annotationEntry.setSpecificationValue(value,
getAnnotationType(annotationEntry, annotationType));
} catch(Exception e) {
error(AF3AllocationActivator.getDefault(),
"Error setting source entity annotation of type " +
annotationType.getSimpleName() + " for " +
getName(element), e);
}
});
getViewer().refresh(true);
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationType;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT;
import org.fortiss.af3.allocation.ui.editor.ParameterTableEditor;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* {@link ColumnLabelProvider} to enable editing parameter annotations of source entity types
* directly in {@link ParameterTableEditor}.
*
* @author barner
*/
public class ParameterSourceElementTreeViewerLabelProvider extends ColumnLabelProvider {
/** Annotation type used to implement this parameter */
private Class<? extends IAnnotatedSpecification> annotationType;
/** Type of annotated source entities. */
private Class<? extends IModelElement> sourceEntityType;
/** Constructor. */
public ParameterSourceElementTreeViewerLabelProvider(
Class<? extends IAnnotatedSpecification> annotationType,
Class<? extends IModelElement> sourceEntityType) {
this.annotationType = annotationType;
this.sourceEntityType = sourceEntityType;
}
/** {@inheritDoc} */
@Override
public String getText(Object object) {
if(object != null && sourceEntityType.isAssignableFrom(object.getClass())) {
AnnotationEntry annotationEntry =
IAnnotationValueService.getInstance().getAnnotationEntry((IModelElement)object);
Object value =
annotationEntry.getSpecificationValue(getAnnotationType(annotationEntry,
annotationType));
return value != null ? value.toString() : null;
}
return null;
}
/** {@inheritDoc} */
@Override
public String getToolTipText(Object object) {
if(object instanceof IModelElement && sourceEntityType.isAssignableFrom(object.getClass())) {
IModelElement element = (IModelElement)object;
return getAnnotationName(element, annotationType) + " of " + getName(element);
}
return null;
}
/** {@inheritDoc} */
@Override
public int getToolTipStyle(Object object) {
return SWT.CENTER;
}
}
......@@ -25,6 +25,9 @@ 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.af3.allocation.ui.editor.ParameterTableEditor;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -86,4 +89,63 @@ public class ParameterTableTreeViewerManager<T extends ParameterTable> extends T
return parameterName + ": " + columnLabel;
}
/** {@inheritDoc} */
@Override
protected TreeViewerFirstColumnLabelProvider<T> createFirstColumns() {
TreeViewerFirstColumnLabelProvider<T> firstColumnLabelProvider = super.createFirstColumns();
createSourceEntityAnnotationColumn();
return firstColumnLabelProvider;
}
/**
* Creates a table column that enables editing parameter annotations of source entity types
* directly in the {@link ParameterTableEditor}.
*/
private void createSourceEntityAnnotationColumn() {
String columnLabel;
if(!allocationTableEditor.getSourceViewModelElements().isEmpty()) {
// List is non-empty: Label can be determined using first source element
columnLabel =
getAnnotationName(allocationTableEditor.getSourceViewModelElements().get(0),
annotationType);
} else {
// Fall-back name
columnLabel = annotationType.getSimpleName();
}
ColumnLabelProvider labelProvider =
new ParameterSourceElementTreeViewerLabelProvider(annotationType,
allocationTableEditor.getSourceEntityType());
EditingSupport editingSupport =
new ParameterSourceElementTreeViewerEditingSupport(annotationType,
allocationTableEditor.getSourceEntityType(), treeViewer);
createTreeViewerColumn(100, columnLabel, null, null, labelProvider, editingSupport);
}
/** Returns the annotation type of the given {@link AnnotationEntry}. */
public static Class<? extends IAnnotatedSpecification>
getAnnotationType(AnnotationEntry annotationEntry,
Class<? extends IAnnotatedSpecification> annotationType) {
// TODO: We cannot use directly "annotationType" here since the IAnnotationValueService
// uses the EMF generated "Impl" type as key. See AllocationService.EMFTypeMap for a
// possible proper solution.
return annotationEntry.getSpecification(annotationType).getClass();
}
/** Returns the name of the parameter annotation of the given {@link IModelElement}. */
public static String getAnnotationName(IModelElement element,
Class<? extends IAnnotatedSpecification> annotationType) {
AnnotationEntry annotationEntry =
IAnnotationValueService.getInstance().getAnnotationEntry(element);
String annotationName =
annotationEntry.getSpecificationAnnotationName(getAnnotationType(annotationEntry,
annotationType));
return annotationName;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment