use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class FindViewController method populateAllAttributes.
/**
* Returns a list of all available attributes on all open graphs. Used for
* the attributes in the advanced find tab.
*
* @param type
* @param attributeModificationCounter
* @return
*/
public List<Attribute> populateAllAttributes(final GraphElementType type, final long attributeModificationCounter) {
final List<Attribute> allAttributes = new ArrayList<>();
for (final Graph graph : GraphManager.getDefault().getAllGraphs().values()) {
// Call the plugin that retrieves all current attributes on the graph
final GraphAttributePlugin attrPlugin = new GraphAttributePlugin(type, allAttributes, attributeModificationCounter);
final Future<?> future = PluginExecution.withPlugin(attrPlugin).interactively(true).executeLater(graph);
// Wait for the search to find its results:
try {
future.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
// get all the current attributes based on the currently selcted type
allAttributes.addAll(attrPlugin.getAttributes());
}
final Set<Attribute> attributeSet = new LinkedHashSet<>();
attributeSet.addAll(allAttributes);
allAttributes.clear();
allAttributes.addAll(attributeSet);
allAttributes.sort(Comparator.comparing(Attribute::getName));
return allAttributes;
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class FindTopComponent method setDefaultFindCriteriaPanels.
/**
* add set of find criteria panel based on primary keys, otherwise just add
* one with the first column in it
*/
private void setDefaultFindCriteriaPanels() {
final Graph graph = graphNode.getGraph();
ReadableGraph rg = graph.getReadableGraph();
try {
int[] keys = rg.getPrimaryKey(type);
if (keys.length == 0) {
addFindCriteriaPanel();
} else {
for (int i = 0; i < keys.length; i++) {
Attribute attr = new GraphAttribute(rg, keys[i]);
FindRule rule = new FindRule();
rule.setAttribute(attr);
if ("boolean".equalsIgnoreCase(attr.getAttributeType())) {
rule.addBooleanBasedRule(true);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("color".equalsIgnoreCase(attr.getAttributeType())) {
rule.addColorBasedRule(Color.BLACK);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("date".equalsIgnoreCase(attr.getAttributeType())) {
rule.addDateBasedRule(new Date(), new Date());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if (attr.getAttributeType().equalsIgnoreCase(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
rule.addDateTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if ("time".equalsIgnoreCase(attr.getAttributeType())) {
rule.addTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if ("float".equalsIgnoreCase(attr.getAttributeType())) {
rule.addFloatBasedRule(0.0F, 0.0F);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("integer".equalsIgnoreCase(attr.getAttributeType())) {
rule.addIntegerBasedRule(0, 0);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("icon".equalsIgnoreCase(attr.getAttributeType())) {
rule.addIconBasedRule("");
rule.setOperator(FindTypeOperators.Operator.IS);
} else {
// string
rule.addStringBasedRule("", false, false);
rule.setOperator(FindTypeOperators.Operator.CONTAINS);
}
addFindCriteriaPanel(rule);
}
}
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class FindTopComponent method saveStateToGraph.
/**
* Causes the state to be gathered by collecting each 'rule' from all of the
* <code>FindCriteriaPanel</code>s hosted.
* <p>
* Upon all rules being wrapped in an overall <code>FindState</code>,
* invokes the write to graph plugin and passes it the state to write in the
* background.
*
* @return The state saved to the graph.
*
* @see FindCriteriaPanel
* @see FindState
*/
@SuppressWarnings("unchecked")
public FindState saveStateToGraph() {
final Graph graph = graphNode.getGraph();
// Collect the state of all of the FCPs (ie the current rules):
final FindState newState = new FindState();
for (Component c : panelFind.getComponents()) {
if (c instanceof FindCriteriaPanel && !attributes.isEmpty()) {
final FindCriteriaPanel fcp = (FindCriteriaPanel) c;
newState.addRule(fcp.getState());
}
}
// Save the GraphElementType:
if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_VERTEX())) {
newState.setGraphElementType(GraphElementType.VERTEX);
} else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_TRANSACTION())) {
newState.setGraphElementType(GraphElementType.TRANSACTION);
} else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_EDGE())) {
newState.setGraphElementType(GraphElementType.EDGE);
} else {
newState.setGraphElementType(GraphElementType.LINK);
}
// Save the AND/OR mode ('any'/'all'):
newState.setAny(this.cmbMatch.getSelectedItem().equals(Bundle.Find_ANY()));
// Save the hold selection mode:
newState.setHeld(chkAddToSelection.isSelected());
// Write what we have to the graph:
final FindStatePlugin findStatePlugin = new FindStatePlugin(newState);
PluginExecution.withPlugin(findStatePlugin).executeLater(graph);
return newState;
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class FindTopComponent method performSearch.
/**
* Gathers the state from the graph, and executes the
* <code>AdvancedQueryPlugin</code>, passing it the rules from the state.
* <p>
* (Where each <code>FindCriteriaPanel</code> represents an individual
* rule.)
*/
@SuppressWarnings("unchecked")
private void performSearch() {
final Graph graph = graphNode.getGraph();
final FindState state = saveStateToGraph();
final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(type, state.getRules(), !state.isAny());
final Future<?> future = PluginExecution.withPlugin(queryPlugin).interactively(true).executeLater(graph);
// Wait for the search to find its results:
try {
future.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Thread was interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
final List<FindResult> results = queryPlugin.getResults();
final SelectFindResultsPlugin selectPlugin = new SelectFindResultsPlugin(results, state.isHeld());
PluginExecution.withPlugin(selectPlugin).interactively(true).executeLater(graph);
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState.
@Test
public void loadDataAccessState() {
// Create current data access view state and set some parameters
// The code currenly only looks at the first tab so parameter2
// value will be ignored
final DataAccessState currentState = new DataAccessState();
currentState.newTab();
currentState.add("parameter1", "parameter1_new_value");
currentState.newTab();
currentState.add("parameter2", "parameter2_new_value");
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final TabPane tabPane = mock(TabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
verify(pluginParameter1).setStringValue("parameter1_new_value");
verify(pluginParameter2, never()).setStringValue(anyString());
verify(rGraph).release();
}
}
Aggregations