Search in sources :

Example 1 with SelectNamedSelectionPanel

use of au.gov.asd.tac.constellation.views.namedselection.utilities.SelectNamedSelectionPanel in project constellation by constellation-app.

the class ArrangeInBubbleTreeAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Graph graph = context.getGraph();
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        NamedSelectionState nsState = null;
        final int namedSelectionId = rg.getAttribute(GraphElementType.VERTEX, "named_selection");
        if (namedSelectionId != Graph.NOT_FOUND) {
            final int namedSelectionStateId = rg.getAttribute(GraphElementType.META, NamedSelectionState.ATTRIBUTE_NAME);
            if (namedSelectionStateId != Graph.NOT_FOUND) {
                nsState = rg.getObjectValue(namedSelectionStateId, 0);
                final SelectNamedSelectionPanel ssp = new SelectNamedSelectionPanel(nsState.getNamedSelections(), "Select a named selection to represent the tree roots.");
                final DialogDescriptor dd = new DialogDescriptor(ssp, Bundle.CTL_ArrangeInBubbleTreeAction());
                dd.setHelpCtx(new HelpCtx(HELP_LOCATION));
                final Object result = DialogDisplayer.getDefault().notify(dd);
                if (result == DialogDescriptor.OK_OPTION) {
                    final long selectionId = ssp.getNamedSelectionId();
                    if (selectionId != -1) {
                        final long mask = 1L << selectionId;
                        final Set<Integer> rootVxIds = new HashSet<>();
                        for (int position = 0; position < rg.getVertexCount(); position++) {
                            final int vxId = rg.getVertex(position);
                            final long selections = rg.getLongValue(namedSelectionId, vxId);
                            if ((selections & mask) != 0) {
                                rootVxIds.add(vxId);
                            }
                        }
                        PluginExecutor.startWith(ArrangementPluginRegistry.BUBBLE_TREE).set(ArrangeInBubbleTreePlugin.ROOTS_PARAMETER_ID, rootVxIds).set(ArrangeInBubbleTreePlugin.IS_MINIMAL_PARAMETER_ID, true).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeWriteLater(context.getGraph(), Bundle.CTL_ArrangeInBubbleTreeAction());
                    }
                }
            }
        }
        if (nsState == null) {
            NotifyDisplayer.display("There must be a named selection to specify the tree roots", NotifyDescriptor.WARNING_MESSAGE);
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) SelectNamedSelectionPanel(au.gov.asd.tac.constellation.views.namedselection.utilities.SelectNamedSelectionPanel) DialogDescriptor(org.openide.DialogDescriptor) HelpCtx(org.openide.util.HelpCtx) NamedSelectionState(au.gov.asd.tac.constellation.views.namedselection.state.NamedSelectionState) HashSet(java.util.HashSet)

Example 2 with SelectNamedSelectionPanel

use of au.gov.asd.tac.constellation.views.namedselection.utilities.SelectNamedSelectionPanel in project constellation by constellation-app.

the class ArrangeInHierarchyAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Graph graph = context.getGraph();
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        NamedSelectionState nsState = null;
        final int namedSelectionId = rg.getAttribute(GraphElementType.VERTEX, "named_selection");
        if (namedSelectionId != Graph.NOT_FOUND) {
            final int namedSelectionStateId = rg.getAttribute(GraphElementType.META, NamedSelectionState.ATTRIBUTE_NAME);
            if (namedSelectionStateId != Graph.NOT_FOUND) {
                nsState = rg.getObjectValue(namedSelectionStateId, 0);
                final SelectNamedSelectionPanel ssp = new SelectNamedSelectionPanel(nsState.getNamedSelections(), "Select a named selection to represent the top of the hierarchy.");
                final DialogDescriptor dd = new DialogDescriptor(ssp, Bundle.CTL_ArrangeInHierarchyAction());
                dd.setHelpCtx(new HelpCtx(HELP_LOCATION));
                final Object result = DialogDisplayer.getDefault().notify(dd);
                if (result == DialogDescriptor.OK_OPTION) {
                    final long selectionId = ssp.getNamedSelectionId();
                    if (selectionId != -1) {
                        final long mask = 1L << selectionId;
                        final Set<Integer> rootVxIds = new HashSet<>();
                        for (int position = 0; position < rg.getVertexCount(); position++) {
                            final int vxId = rg.getVertex(position);
                            final long selections = rg.getLongValue(namedSelectionId, vxId);
                            if ((selections & mask) != 0) {
                                rootVxIds.add(vxId);
                            }
                        }
                        PluginExecutor.startWith(ArrangementPluginRegistry.HIERARCHICAL).set(ArrangeInHierarchyPlugin.ROOTS_PARAMETER_ID, rootVxIds).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeWriteLater(context.getGraph(), Bundle.CTL_ArrangeInHierarchyAction());
                    }
                }
            }
        }
        if (nsState == null) {
            NotifyDisplayer.display("There must be a named selection to specify the tree roots", NotifyDescriptor.WARNING_MESSAGE);
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) SelectNamedSelectionPanel(au.gov.asd.tac.constellation.views.namedselection.utilities.SelectNamedSelectionPanel) DialogDescriptor(org.openide.DialogDescriptor) HelpCtx(org.openide.util.HelpCtx) NamedSelectionState(au.gov.asd.tac.constellation.views.namedselection.state.NamedSelectionState) HashSet(java.util.HashSet)

Aggregations

Graph (au.gov.asd.tac.constellation.graph.Graph)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 NamedSelectionState (au.gov.asd.tac.constellation.views.namedselection.state.NamedSelectionState)2 SelectNamedSelectionPanel (au.gov.asd.tac.constellation.views.namedselection.utilities.SelectNamedSelectionPanel)2 HashSet (java.util.HashSet)2 DialogDescriptor (org.openide.DialogDescriptor)2 HelpCtx (org.openide.util.HelpCtx)2