All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.plugins.dndviewer.viewer.tree.TreeDisplayRules Maven / Gradle / Ivy

The newest version!
package org.nakedobjects.plugins.dndviewer.viewer.tree;

import org.nakedobjects.metamodel.adapter.NakedObject;
import org.nakedobjects.metamodel.consent.Allow;
import org.nakedobjects.metamodel.consent.Consent;
import org.nakedobjects.metamodel.spec.SpecificationFacets;
import org.nakedobjects.metamodel.spec.feature.NakedObjectActionType;
import org.nakedobjects.plugins.dndviewer.UserAction;
import org.nakedobjects.plugins.dndviewer.UserActionSet;
import org.nakedobjects.plugins.dndviewer.View;
import org.nakedobjects.plugins.dndviewer.Workspace;
import org.nakedobjects.plugins.dndviewer.viewer.drawing.Location;


public class TreeDisplayRules {
    private static boolean showCollectionsOnly = false;

    private TreeDisplayRules() {}

    public static void menuOptions(final UserActionSet options) {
        // TODO fix and remove following line
        if (true) {
            return;
        }

        final UserAction option = new UserAction() {
            public void execute(final Workspace workspace, final View view, final Location at) {
                showCollectionsOnly = !showCollectionsOnly;
            }

            public String getName(final View view) {
                return showCollectionsOnly ? "Show collections only" : "Show all references";
            }

            public Consent disabled(final View view) {
                return Allow.DEFAULT;
            }

            public String getDescription(final View view) {
                return "This option makes the system only show collections within the trees, and not single elements";
            }

            public NakedObjectActionType getType() {
                return USER;
            }

            public String getHelp(final View view) {
                return "";
            }
        };
        options.add(option);
    }

    public static boolean isCollectionsOnly() {
        return showCollectionsOnly;
    }

    public static boolean canDisplay(final NakedObject object) {
        boolean lookupView = object != null && SpecificationFacets.isBoundedSet(object.getSpecification());
        final boolean showNonCollections = !TreeDisplayRules.isCollectionsOnly();
        final boolean objectView = object instanceof NakedObject && showNonCollections;
        final boolean collectionView = object.getSpecification().isCollection();
        return (objectView || collectionView) && !lookupView;
    }
}
// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy