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;
}
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));
}
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();
}
}
});
}
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();
}
}
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);
}
}
Aggregations