Commit 0b872df8 authored by Simon Barner's avatar Simon Barner
Browse files

- Add AllocationTable.clearAllocations()

- Clear allocations when switching the source/target view. Ask for confirmation if the current set of allocation entries is not empty
refs 2950
parent e0d2b93d
AllocationTableEditor.java 39624fa994c504f0783507eb785bbc4967c20c82 YELLOW
AllocationTableEditor.java 75629eea8a869b102cccafee73b0db1730df5651 YELLOW
AllocationTableEditorUtils.java 3f53fc3ce279be40ca18d6d63f3f7f830ec4eb86 RED
ModelListenerEditorBase.java 6145b0682ffc82fee4c09ab51530506e79f286ad YELLOW
......@@ -17,6 +17,7 @@ package org.fortiss.af3.allocation.ui.editor;
import static java.util.Collections.emptyList;
import static org.conqat.lib.commons.reflect.ReflectionUtils.isInstanceOfAny;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.eclipse.jface.viewers.AbstractTreeViewer.ALL_LEVELS;
import static org.fortiss.af3.allocation.utils.AllocationUtils.checkAllocationEntryType;
import static org.fortiss.tooling.common.util.LambdaUtils.asStream;
......@@ -46,6 +47,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.fortiss.af3.allocation.IAllocationService;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
......@@ -253,9 +255,22 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
@Override
protected void modelSelectionChanged(IProjectRootElement model,
Consumer<IHierarchicElement> modelSetter, Supplier<IHierarchicElement> modelGetter) {
super.modelSelectionChanged(model, modelSetter, modelGetter);
refresh(model);
boolean changeSelection = true;
if(!editedObject.getAllocationEntries().isEmpty()) {
changeSelection =
openConfirm(Display.getCurrent().getActiveShell(), "Reset Allocation",
"Selecting a different source or target view will reset the allocation. Are you sure?");
}
if(changeSelection) {
runAsCommand(editedObject, () -> {
editedObject.clearAllocationEntries();
});
super.modelSelectionChanged(model, modelSetter, modelGetter);
refresh(model);
}
}
/** Performs an update because an entity has been added or removed. */
......@@ -560,7 +575,7 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
@SuppressWarnings("unchecked")
private List<IProjectRootElement> getModels(Class<? extends IProjectRootElement> type) {
List<? extends IProjectRootElement> models =
KernelModelElementUtils.getRootElements(getEditedObject(), type);
KernelModelElementUtils.getRootElements(editedObject, type);
return (List<IProjectRootElement>)models;
}
......
......@@ -233,6 +233,12 @@
</eGenericType>
</eParameters>
</eOperations>
<eOperations name="clearAllocationEntries">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Clears all {@link AllocationEntry}s from this {@link AllocationTable}."/>
<details key="body" value="AllocationTableStaticImpl.clearAllocationEntries(this);"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="sourceView" eType="ecore:EClass platform:/resource/org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElement">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Source model for which to define {@link Allocation}."/>
......
......@@ -70,6 +70,7 @@
<genParameters ecoreParameter="allocation.ecore#//AllocationTable/getSourceElements.2/type"/>
<genTypeParameters ecoreTypeParameter="allocation.ecore#//AllocationTable/getSourceElements.2/T"/>
</genOperations>
<genOperations ecoreOperation="allocation.ecore#//AllocationTable/clearAllocationEntries"/>
</genClasses>
<genClasses image="false" ecoreClass="allocation.ecore#//AllocationEntry"/>
<genClasses ecoreClass="allocation.ecore#//OneToOneAllocationEntry">
......
AF3AllocationFactoryImplCustom.java 46630be40ab1aa52cd8312c2abac7572cef06f41 GREEN
AllocationTableCollectionStaticImpl.java 27131d10e64c7640339337e900257c11427ce9d2 GREEN
AllocationTableStaticImpl.java 668f0c388e7376e9c8812fbb1bfd41e5abc973f3 GREEN
AllocationTableStaticImpl.java f22462d5f66a4327834d29799ed1028ab2ce8da3 YELLOW
......@@ -460,4 +460,10 @@ public class AllocationTableStaticImpl {
// Eliminate duplicates that might arise from overlaps
return toEList(rval);
}
/** Clears all {@link AllocationEntry}s from the given {@link AllocationTable}. */
public static void clearAllocationEntries(AllocationTable allocationTable) {
// Compositors ensure that AllocationEntries are the only child elements of AllocationTables
allocationTable.getContainedElements().clear();
}
}
Markdown is supported
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