Search in sources :

Example 1 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.

the class DirectedShortestPathsPlugin method getSelectedNodes.

private Map<String, Integer> getSelectedNodes(final Graph graph) {
    if (selectedNodes == null) {
        final Map<String, Integer> label2VxId = new HashMap<>();
        if (graph != null) {
            final ReadableGraph rg = graph.getReadableGraph();
            try {
                final int vxLabelAttr = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.LABEL.getName());
                final int vxSelectedAttr = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
                if (vxSelectedAttr != Graph.NOT_FOUND && vxLabelAttr != Graph.NOT_FOUND) {
                    final int vxCount = rg.getVertexCount();
                    for (int position = 0; position < vxCount; position++) {
                        final int vxId = rg.getVertex(position);
                        if (rg.getBooleanValue(vxSelectedAttr, vxId)) {
                            final String label = rg.getStringValue(vxLabelAttr, vxId);
                            label2VxId.put(label, vxId);
                        }
                    }
                }
            } finally {
                rg.release();
            }
        }
        selectedNodes = label2VxId;
    }
    return selectedNodes;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HashMap(java.util.HashMap)

Example 2 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.

the class FactAnalyticPlugin method onPrerequisiteAttributeChange.

@Override
public void onPrerequisiteAttributeChange(final Graph graph, final PluginParameters parameters) {
    final Set<TransactionTypeParameterValue> transactionTypes = new HashSet<>();
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int typeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(readableGraph);
            final int transactionCount = readableGraph.getTransactionCount();
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = readableGraph.getTransaction(transactionPosition);
                final SchemaTransactionType type = readableGraph.getObjectValue(typeAttributeId, transactionId);
                transactionTypes.add(new TransactionTypeParameterValue(type));
            }
        } finally {
            readableGraph.release();
        }
    }
    // TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParam = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    MultiChoiceParameterType.setOptionsData(transactionTypesParam, new ArrayList<>(transactionTypes));
    MultiChoiceParameterType.setChoicesData(transactionTypesParam, new ArrayList<>(transactionTypes));
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet)

Example 3 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.

the class LayerByTimePlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final ReadableGraph rg = graph.getReadableGraph();
    final List<String> dateTimeAttributes = new ArrayList<>();
    try {
        final int attributeCount = rg.getAttributeCount(GraphElementType.TRANSACTION);
        for (int i = 0; i < attributeCount; i++) {
            final int attrId = rg.getAttribute(GraphElementType.TRANSACTION, i);
            final Attribute attr = new GraphAttribute(rg, attrId);
            if (attr.getAttributeType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                dateTimeAttributes.add(attr.getName());
            }
        }
    } finally {
        rg.release();
    }
    SingleChoiceParameterType.setOptions(dtAttrParam, dateTimeAttributes);
    parameters.addController(DATETIME_ATTRIBUTE_PARAMETER_ID, (masterId, paramMap, change) -> {
        if (change == ParameterChange.VALUE) {
            final String attrName = paramMap.get(DATETIME_ATTRIBUTE_PARAMETER_ID).getStringValue();
            final ReadableGraph rg2 = graph.getReadableGraph();
            try {
                final int attrId = rg2.getAttribute(GraphElementType.TRANSACTION, attrName);
                if (attrId == Graph.NOT_FOUND) {
                    return;
                }
                ZonedDateTime min = ZonedDateTime.ofInstant(Instant.now(), TimeZoneUtilities.UTC);
                ZonedDateTime max = ZonedDateTime.ofInstant(Instant.EPOCH, TimeZoneUtilities.UTC);
                final int txCount = rg.getTransactionCount();
                boolean nonNullDateTimeFound = false;
                for (int position = 0; position < txCount; position++) {
                    final int txId = rg.getTransaction(position);
                    // Ignore zero and "null" dates.
                    final ZonedDateTime dt = rg.getObjectValue(attrId, txId);
                    if (dt != null) {
                        nonNullDateTimeFound = true;
                        if (dt.toInstant().isBefore(min.toInstant())) {
                            min = dt;
                        }
                        if (dt.toInstant().isAfter(max.toInstant())) {
                            max = dt;
                        }
                    }
                }
                if (!nonNullDateTimeFound) {
                    final ZonedDateTime swap = min;
                    min = max;
                    max = swap;
                }
                dateRangeParam.setDateTimeRangeValue(new DateTimeRange(min, max));
            } finally {
                rg2.release();
            }
        }
    });
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ZonedDateTime(java.time.ZonedDateTime) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) DateTimeRange(au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange)

Example 4 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph 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 5 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.

the class ArrangeInScatter3dGeneralPlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    // Get the list of non-default attributes
    final ReadableGraph rg = graph.getReadableGraph();
    Map<String, Integer> vertexAttributes = null;
    try {
        vertexAttributes = AttributeUtilities.getVertexAttributes(rg, 0);
    } finally {
        rg.release();
    }
    if (vertexAttributes != null) {
        final List<String> keys = new ArrayList<>(vertexAttributes.keySet());
        final PluginParameter<SingleChoiceParameterValue> xAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(SCATTER_3D_X_ATTRIBUTE);
        SingleChoiceParameterType.setOptions(xAttribute, keys);
        final PluginParameter<SingleChoiceParameterValue> yAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(SCATTER_3D_Y_ATTRIBUTE);
        SingleChoiceParameterType.setOptions(yAttribute, keys);
        final PluginParameter<SingleChoiceParameterValue> zAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(SCATTER_3D_Z_ATTRIBUTE);
        SingleChoiceParameterType.setOptions(zAttribute, keys);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Aggregations

ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)167 Test (org.testng.annotations.Test)62 Graph (au.gov.asd.tac.constellation.graph.Graph)57 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)43 ArrayList (java.util.ArrayList)40 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)26 HashMap (java.util.HashMap)16 Attribute (au.gov.asd.tac.constellation.graph.Attribute)14 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)12 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)12 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)12 HashSet (java.util.HashSet)12 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)11 List (java.util.List)10 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)9 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)9 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 File (java.io.File)9