Skip to content
Snippets Groups Projects
Commit 4be09b14 authored by Sebastian Bergemann's avatar Sebastian Bergemann
Browse files

Add caching of current item expansion status to recover it next time

Issue-ref: 4352
Issue-URL: af3#4352



Signed-off-by: default avatarSebastian Bergemann <bergemann@fortiss.org>
parent 40e36a93
Branches
Tags
1 merge request!223Categories in the Model Elements Navigator shall be collapsed by default
Pipeline #39747 passed
Pipeline: maven-releng

#39748

    DoubleClick.java a94d27299814a93b0d8914050a5da7378a7eccd1 GREEN DoubleClick.java a94d27299814a93b0d8914050a5da7378a7eccd1 GREEN
    GenericNewMenu.java 7e0dd435cb5ca6d4b486235ec17eef3e5c7aa5f6 GREEN GenericNewMenu.java 7e0dd435cb5ca6d4b486235ec17eef3e5c7aa5f6 GREEN
    LinkWithEditorPartListener.java c5ab74424378e7b158a805c4dd14fc03c8abeded GREEN LinkWithEditorPartListener.java c5ab74424378e7b158a805c4dd14fc03c8abeded GREEN
    ModelElementsView.java ea9b92e2b538a71275a19561633ae53cc5b397a5 YELLOW ModelElementsView.java a271d0785ed0943f8d600ca8ffa50a21804c0739 YELLOW
    NavigatorNewMenu.java a35e391960d1dacbe7f77982e53e1891e9382d5a GREEN NavigatorNewMenu.java a35e391960d1dacbe7f77982e53e1891e9382d5a GREEN
    NavigatorTreeContentComparator.java d9f1354cfdff78b104b28887d2397e5ca0e9755b GREEN NavigatorTreeContentComparator.java d9f1354cfdff78b104b28887d2397e5ca0e9755b GREEN
    NavigatorTreeContentProvider.java 8162138aab09b2cf833cf5f90ff6ab1fc3edc4d8 GREEN NavigatorTreeContentProvider.java 8162138aab09b2cf833cf5f90ff6ab1fc3edc4d8 GREEN
    ......
    ...@@ -20,6 +20,8 @@ import static java.util.Collections.emptyList; ...@@ -20,6 +20,8 @@ import static java.util.Collections.emptyList;
    import static org.fortiss.tooling.kernel.service.IPrototypeService.PROTOTYPE_DATA_FORMAT; import static org.fortiss.tooling.kernel.service.IPrototypeService.PROTOTYPE_DATA_FORMAT;
    import java.util.Collection; import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set; import java.util.Set;
    import org.conqat.ide.commons.ui.ui.EmptyPartListener; import org.conqat.ide.commons.ui.ui.EmptyPartListener;
    ...@@ -55,20 +57,31 @@ import javafx.scene.layout.BorderPane; ...@@ -55,20 +57,31 @@ import javafx.scene.layout.BorderPane;
    * @author hoelzl * @author hoelzl
    */ */
    public final class ModelElementsView extends FXViewPart { public final class ModelElementsView extends FXViewPart {
    /** A dummy object serving as hidden root element of the tree view. */ /** A dummy object serving as hidden root element of the tree view. */
    private static final Object DUMMY_ROOT = new Object(); private static final Object DUMMY_ROOT = new Object();
    /** The tree-table viewer. */ /** The tree-table viewer. */
    private DynamicTreeViewer<Object> treeViewer; private DynamicTreeViewer<Object> treeViewer;
    /** The filter text field if filtering is enabled in content provider. */ /** The filter text field if filtering is enabled in content provider. */
    private TextField filterWidget; private TextField filterWidget;
    /** Current active {@link ExtendableMultiPageEditor}. */ /** Current active {@link ExtendableMultiPageEditor}. */
    private ExtendableMultiPageEditor activeBindingEditor = null; private ExtendableMultiPageEditor activeBindingEditor = null;
    /** Stores the editor activation listener. */ /** Stores the editor activation listener. */
    private EditorActivationListener editorActivationListener = new EditorActivationListener(); private EditorActivationListener editorActivationListener = new EditorActivationListener();
    /** The container object used. */ /** The container object used. */
    private EObject containerObject = null; private EObject containerObject = null;
    /** The prototypes supported by the current editor. */ /** The prototypes supported by the current editor. */
    private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>(); private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>();
    /** Cached expansion status of each contained prototype category. */
    private Map<PrototypeCategory, Boolean> prototypeCategoryExpansionCache = new HashMap<>();
    /** Listener for reacting to changes of the embedded editor. */ /** Listener for reacting to changes of the embedded editor. */
    private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener = private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener =
    new ExtendableMultiPageEditorPageChangeListener() { new ExtendableMultiPageEditorPageChangeListener() {
    ...@@ -126,10 +139,40 @@ public final class ModelElementsView extends FXViewPart { ...@@ -126,10 +139,40 @@ public final class ModelElementsView extends FXViewPart {
    containerObject = null; containerObject = null;
    } }
    cacheCurrentItemExpansionStatus();
    treeViewer.update(); treeViewer.update();
    expandCorrectItems(); expandCorrectItems();
    } }
    /**
    * Goes through the current active {@link TreeItem}s and stores/caches their current expansion
    * status, i.e., whether they are expanded as item or not.
    */
    private void cacheCurrentItemExpansionStatus() {
    TreeItem<Object> rootItem = treeViewer.getControl().getRoot();
    for(TreeItem<Object> topLevelItem : rootItem.getChildren()) {
    cacheItemExpansionStatusOfItemAndChildrenRecursively(topLevelItem);
    }
    }
    /**
    * Stores/caches the current expansion status of the given {@link TreeItem}, i.e., whether they
    * are expanded as item or not, and does the same recursively for all of its (possible)
    * children.
    */
    private void cacheItemExpansionStatusOfItemAndChildrenRecursively(TreeItem<Object> item) {
    Object itemObject = item.getValue();
    if(itemObject instanceof PrototypeCategory) {
    PrototypeCategory category = (PrototypeCategory)itemObject;
    prototypeCategoryExpansionCache.put(category, item.isExpanded());
    for(TreeItem<Object> childItem : item.getChildren()) {
    cacheItemExpansionStatusOfItemAndChildrenRecursively(childItem);
    }
    }
    }
    /** /**
    * Expands the {@link TreeItem}s that should be expanded due to their (prototype) attribute (if * Expands the {@link TreeItem}s that should be expanded due to their (prototype) attribute (if
    * they should be expanded by default) or because they were already manually expanded by the * they should be expanded by default) or because they were already manually expanded by the
    ...@@ -153,7 +196,12 @@ public final class ModelElementsView extends FXViewPart { ...@@ -153,7 +196,12 @@ public final class ModelElementsView extends FXViewPart {
    Object itemObject = item.getValue(); Object itemObject = item.getValue();
    if(itemObject instanceof PrototypeCategory) { if(itemObject instanceof PrototypeCategory) {
    PrototypeCategory category = (PrototypeCategory)itemObject; PrototypeCategory category = (PrototypeCategory)itemObject;
    if(category.getExpandedByDefaultStatus()) { // Try getting previous/cached status before checking default one.
    Boolean shouldBeExpanded = prototypeCategoryExpansionCache.get(category);
    if(shouldBeExpanded == null) {
    shouldBeExpanded = category.getExpandedByDefaultStatus();
    }
    if(shouldBeExpanded) {
    // Expand this category (must also be set for all its direct children, otherwise the // Expand this category (must also be set for all its direct children, otherwise the
    // children will not show up in the expansion). // children will not show up in the expansion).
    treeViewer.expandItem(item); treeViewer.expandItem(item);
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please to comment