Commit 1dce78f9 authored by Simon Barner's avatar Simon Barner
Browse files

Correctly update tree viewer in case model entities become available due...

Correctly update tree viewer in case model entities become available due selecting a different source/target model.
refs 2950
parent 2c392508
AllocationTableEditor.java 0c91284a3413f4a02589fd4183b8ff92ba00f09a YELLOW
AllocationTableEditor.java 39624fa994c504f0783507eb785bbc4967c20c82 YELLOW
AllocationTableEditorUtils.java 3f53fc3ce279be40ca18d6d63f3f7f830ec4eb86 RED
ModelListenerEditorBase.java 6145b0682ffc82fee4c09ab51530506e79f286ad YELLOW
......@@ -171,25 +171,41 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
/** {@inheritDoc} */
@Override
protected void addModel(IProjectRootElement model) {
if(sourceModelType.isAssignableFrom(model.getClass())) {
updateViewPointSelectionComboBox(gui.getComboViewerSource(),
getModels(sourceModelType), editedObject.getSourceView());
} else if(targetModelType.isAssignableFrom(model.getClass())) {
updateViewPointSelectionComboBox(gui.getComboViewerTarget(),
getModels(targetModelType), editedObject.getTargetView());
}
refresh(model);
}
/** {@inheritDoc} */
@Override
protected void removeModel(IProjectRootElement model) {
refresh(model);
}
/** Performs a refresh for the given root element. */
protected void refresh(IProjectRootElement model) {
if(sourceModelType.isAssignableFrom(model.getClass())) {
updateViewPointSelectionComboBox(gui.getComboViewerSource(),
getModels(sourceModelType), editedObject.getSourceView());
// Update available source entity types (that might have changed when selecting a
// different source model)
Collection<Class<? extends IModelElement>> sourceEntityTypes =
IAllocationService.getInstance().getSourceEntityTypes(allocationEntryType);
updateEntityTypeComboBox(gui.getComboViewerSourceEntityType(), sourceEntityTypes,
editedObject.getSourceView(), this::setSourceEntityType);
} else if(targetModelType.isAssignableFrom(model.getClass())) {
updateViewPointSelectionComboBox(gui.getComboViewerTarget(),
getModels(targetModelType), editedObject.getTargetView());
// Update available target entity types (that might have changed when selecting a
// different target model)
Collection<Class<? extends IModelElement>> targetEntityTypes =
IAllocationService.getInstance().getTargetEntityTypes(allocationEntryType);
updateEntityTypeComboBox(gui.getComboViewerTargetEntityType(), targetEntityTypes,
editedObject.getTargetView(), this::setTargetEntityType);
}
treeViewerManager.updateTreeViewer();
}
/** {@inheritDoc} */
......@@ -238,8 +254,8 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
protected void modelSelectionChanged(IProjectRootElement model,
Consumer<IHierarchicElement> modelSetter, Supplier<IHierarchicElement> modelGetter) {
super.modelSelectionChanged(model, modelSetter, modelGetter);
// For now update the entire table
treeViewerManager.updateTreeViewer();
refresh(model);
}
/** Performs an update because an entity has been added or removed. */
......@@ -454,18 +470,13 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
comboViewer.setInput(models);
if(selectedModel != null) {
comboViewer.setSelection(new StructuredSelection(selectedModel));
}
Combo combo = comboViewer.getCombo();
if(combo.getItemCount() == 0) {
combo.deselectAll();
} else if(combo.getSelectionIndex() == -1) {
// ComboViewer.getInput() does not contain the newly added element. Hence, iterate over
// the list of Items and determine the specific index and it to set the selection. This
// approach also circumvents the creation of possibly problematic {@link
// SelectionChangedEvent}s.
// In contrast to comboViewer.setSelection(), this approach to set the selection does
// not trigger {@link SelectionChangedEvent}s that would result into an infinite
// recursion modelSelectionChanged()->refresh()->updateViewPointSelectionComboBox().
for(int i = 0; i < combo.getItems().length; i++) {
if(comboViewer.getElementAt(i) == selectedModel) {
combo.select(i);
......@@ -473,9 +484,6 @@ public abstract class AllocationTableEditor<T extends AllocationTable> extends
}
}
}
// Ensure that model entity tree-viewer is in sync with model selection combo-box
treeViewerManager.updateTreeViewer();
}
/********************* Miscellaneous options *********************/
......
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