Commit fc95c825 authored by Simon Barner's avatar Simon Barner
Browse files

- Apply context menu action only to currently visible annotations (i.e., respect annotation filter)

- Add TODO to change interface of IAnnotationValueProvider::getContextMenuEntries(): The method should be based on another method in IAnnotationValueProvider that returns a <String, BiConsumer> whose BiConsumer defines the action to apply to a single annotation entry. This ensures uniform iteration over the affected annotation entries, while providing the flexibility to enable custom iteration schemes
- Minor cleanup
  - Perform all modifications of an action in a single command
  - Re-update of annotation view only it was enabled before issuing the command 
refs 2361
parent cdd597d6
......@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
import org.conqat.lib.commons.collections.Pair;
import org.eclipse.jface.viewers.ArrayContentProvider;
......@@ -92,7 +93,7 @@ import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilt
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 7A192862443127A75F619AC15433D8CD
* @ConQAT.Rating YELLOW Hash: E73C8AEA023803F8E01B7C576DDAC5A4
*/
public class GenericAnnotationView extends AnnotationViewPartBase {
/** Root composite of {@link GenericAnnotationView}. */
......@@ -445,9 +446,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
public void widgetSelected(SelectionEvent e) {
if(selectedTableItem.getFirstElement() instanceof AnnotationEntry) {
AnnotationEntry entry = (AnnotationEntry)selectedTableItem.getFirstElement();
boolean updateEnabled = isUpdateEnabled();
setUpdateEnabled(false);
action.accept(spec, entry);
setUpdateEnabled(true);
setUpdateEnabled(updateEnabled);
}
}
});
......@@ -460,8 +462,11 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
private void addContextMenuEntries(Menu contextMenu,
IAnnotationValueProvider<IAnnotatedSpecification> valueProvider,
AnnotationInstSpec<IAnnotatedSpecification> annotationClass) {
final Stream<AnnotationEntry> annotationEntriesMatchingFilter =
getLastAnnotationEntries().stream()
.filter(e -> annotationFilter.passesRowFilter(e));
for(Pair<String, BiConsumer<AnnotationInstSpec<IAnnotatedSpecification>, AnnotationEntry>> ctxMenuEntry : valueProvider
.getContextMenuEntries()) {
.getContextMenuEntries(annotationEntriesMatchingFilter)) {
MenuItem mItem = new MenuItem(contextMenu, SWT.None);
mItem.setText(ctxMenuEntry.getFirst());
addContextMenuEntryListener(mItem, ctxMenuEntry.getSecond(), annotationClass);
......
......@@ -17,12 +17,13 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.annotation.valueprovider;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.conqat.lib.commons.collections.Pair;
import org.fortiss.tooling.base.ToolingBaseActivator;
......@@ -30,7 +31,6 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
/**
* Interface defining default implementations for the context menu of
......@@ -47,7 +47,7 @@ public interface DefaultAnnotationContextActions<T extends IAnnotatedSpecificati
/** {@inheritDoc} */
@Override
public default List<Pair<String, BiConsumer<AnnotationInstSpec<T>, AnnotationEntry>>>
getContextMenuEntries() {
getContextMenuEntries(Stream<AnnotationEntry> annotationEntries) {
List<Pair<String, BiConsumer<AnnotationInstSpec<T>, AnnotationEntry>>> retList =
new ArrayList<>();
......@@ -63,26 +63,33 @@ public interface DefaultAnnotationContextActions<T extends IAnnotatedSpecificati
IPersistencyService.getInstance().getTopLevelElementFor(
entry.getModelElement());
Collection<T> sameAnnotations =
getChildrenWithType(topElement.getRootModelElement(), specType);
for(T sameAnn : sameAnnotations) {
// Apply the value for each annotation of the same type in the smae
// IToplevelElement.
Runnable run =
() -> {
// TODO: Move the creation of the runnable, the for-loop to iterate
// over the affected annotation entries as well as the selection of the affected
// entries (currently in GenericAnnotationView::addContextMenuEntries()) to
// IAnnotationValueProvider.getContextMenuEntries() (= DEFAULT ITERATION
// POLICY).
//
// The creation of the BiConsumer that the defines the actual action FOR A
// SINGLE ENTRY should be performed in another method of the
// IAnnotationValueProvider.
//
Runnable run =
() -> {
for(T annotation : annotationEntries.map(
e -> e.getSpecification(specType)).collect(
Collectors.toList())) {
try {
setAnnotationValue(value, sameAnn);
setAnnotationValue(value, annotation);
} catch(Exception ex) {
LoggingUtils
.error(ToolingBaseActivator.getDefault(),
"Could not set the value of the annotation " +
sameAnn.getName() +
" when trying to propagate the value form the selected annotation. Reason:\n" +
ex.getLocalizedMessage());
error(ToolingBaseActivator.getDefault(),
"Could not set the value of the annotation " +
annotation.getName() +
" when trying to propagate the value form the selected annotation.",
ex);
}
};
topElement.runAsCommand(run);
}
}
};
topElement.runAsCommand(run);
};
// Add the propagate action to the list of context menu entries.
retList.add(new Pair<String, BiConsumer<AnnotationInstSpec<T>, AnnotationEntry>>(
......
......@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
import org.conqat.lib.commons.collections.Pair;
import org.eclipse.emf.ecore.EObject;
......@@ -68,7 +69,7 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware;
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: F64D6AE408B10240BAF4A43B9D79827C
* @ConQAT.Rating YELLOW Hash: 35E646C624C6EEEF82A16AC2EC255A4D
*/
public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> extends
IEObjectAware<IModelElement> {
......@@ -203,10 +204,20 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
* <p>
* This list is used in the view part of the annotations to provide actions for concrete
* {@link AnnotationEntry}s that can be triggered via the context menu in the annotation view.
* The action is applied to the subset of {@link AnnotationEntry}s provided by the underlying
* annotation view (typically, the set of visible annotations that match the current filters).
* </p>
*
* @param annotationEntries
* {@link Stream} of {@link AnnotationEntry}s for which the actions should be
* offered.
*
* @return List of String <--> {@link BiConsumer} {@link Pair}s that define the context menu
* entries that are available for specific entries of an {@link IAnnotatedSpecification}
* .
*/
default List<Pair<String, BiConsumer<AnnotationInstSpec<T>, AnnotationEntry>>>
getContextMenuEntries() {
getContextMenuEntries(Stream<AnnotationEntry> annotationEntries) {
return Collections.emptyList();
}
}
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