use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithNoResults.
@Test
public void testEditWithNoResults() throws Exception {
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
final int vertexLabelAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
final int vertexSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
final int vertexTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int transactionTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
final int vx0 = graph.addVertex();
graph.setStringValue(vertexLabelAttr, vx0, "foo");
graph.setBooleanValue(vertexSelectedAttr, vx0, true);
final PluginInteraction interaction = new TextPluginInteraction();
final SelectTopNPlugin instance = new SelectTopNPlugin();
final PluginParameters parameters = instance.createParameters();
parameters.getParameters().get(SelectTopNPlugin.MODE_PARAMETER_ID).setStringValue(SelectTopNPlugin.NODE);
parameters.getParameters().get(SelectTopNPlugin.TYPE_CATEGORY_PARAMETER_ID).setStringValue(AnalyticConcept.VertexType.LOCATION.getName());
// TYPE_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> subTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(SelectTopNPlugin.TYPE_PARAMETER_ID);
final List<String> arrayList = new ArrayList<>();
arrayList.add(AnalyticConcept.VertexType.COUNTRY.getName());
MultiChoiceParameterType.setChoices(subTypeParameter, arrayList);
parameters.getParameters().get(SelectTopNPlugin.LIMIT_PARAMETER_ID).setIntegerValue(2);
instance.edit(graph, interaction, parameters);
assertEquals(1, graph.getVertexCount());
assertTrue(graph.getBooleanValue(vertexSelectedAttr, vx0));
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions.
@Test
public void testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions() throws Exception {
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
final int vertexLabelAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
final int vertexSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
final int vertexTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int transactionTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
final int sourceVxId = graph.addVertex();
graph.setStringValue(vertexLabelAttr, sourceVxId, "source");
graph.setBooleanValue(vertexSelectedAttr, sourceVxId, true);
// buildId the graph
for (int i = 0; i < 10; i++) {
final int desintationVxId = graph.addVertex();
graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
for (int j = i; j < 10; j++) {
int txId = graph.addTransaction(sourceVxId, desintationVxId, true);
graph.setObjectValue(transactionTypeAttr, txId, AnalyticConcept.TransactionType.COMMUNICATION.getName());
}
}
final PluginInteraction interaction = new TextPluginInteraction();
final SelectTopNPlugin instance = new SelectTopNPlugin();
final PluginParameters parameters = instance.createParameters();
parameters.getParameters().get(SelectTopNPlugin.MODE_PARAMETER_ID).setStringValue(SelectTopNPlugin.TRANSACTION);
parameters.getParameters().get(SelectTopNPlugin.TYPE_CATEGORY_PARAMETER_ID).setStringValue(AnalyticConcept.TransactionType.COMMUNICATION.getName());
// TYPE_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> subTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(SelectTopNPlugin.TYPE_PARAMETER_ID);
final List<String> arrayList = new ArrayList<>();
arrayList.add(AnalyticConcept.TransactionType.COMMUNICATION.getName());
MultiChoiceParameterType.setChoices(subTypeParameter, arrayList);
parameters.getParameters().get(SelectTopNPlugin.LIMIT_PARAMETER_ID).setIntegerValue(2);
instance.edit(graph, interaction, parameters);
assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId));
assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 1));
assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 2));
for (int i = 3; i < 10; i++) {
assertFalse(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + i));
}
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class RecordStoreQueryPluginNGTest method testGetResult.
/**
* Test of getResult method, of class RecordStoreQueryPlugin.
*/
@Test
public void testGetResult() throws InterruptedException, PluginException {
System.out.println("getResult");
final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
final GraphReadMethods graph = new StoreGraph();
final PluginInteraction interaction = null;
final PluginParameters parameters = null;
instance.read(graph, interaction, parameters);
instance.query(interaction, parameters);
final RecordStore result = instance.getResult();
assertEquals(result.size(), 2);
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class RecordStoreQueryPluginNGTest method testEdit.
/**
* Test of edit method, of class RecordStoreQueryPlugin.
*/
@Test
public void testEdit() throws InterruptedException, PluginException {
System.out.println("edit");
final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
// only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
final Graph graph = new DualGraph(schema);
final PluginInteraction interaction = null;
final PluginParameters parameters = null;
ReadableGraph rg = graph.getReadableGraph();
try {
instance.read(rg, interaction, parameters);
instance.query(interaction, parameters);
} finally {
rg.release();
}
GraphRecordStore query;
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getAll(rg, false, false);
} finally {
rg.release();
}
final WritableGraph wg = graph.getWritableGraph("", true);
try {
VisualConcept.VertexAttribute.X.ensure(wg);
VisualConcept.VertexAttribute.Y.ensure(wg);
VisualConcept.VertexAttribute.Z.ensure(wg);
VisualConcept.GraphAttribute.CAMERA.ensure(wg);
instance.edit(wg, interaction, parameters);
} finally {
wg.commit();
}
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
} finally {
rg.release();
}
// verify nothing has moved
query.reset();
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class SaveTemplateAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.SAVE_TEMPLATE);
final PluginParameters params = plugin.createParameters();
while (true) {
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_SaveTemplateAction(), params);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
if (NewSchemaGraphAction.getTemplateNames().containsKey(params.getStringValue(SaveTemplatePlugin.TEMPLATE_NAME_PARAMETER_ID))) {
final PluginParameters warningParams = new PluginParameters();
final PluginParameter<StringParameterValue> warningMessageParam = StringParameterType.build("");
warningMessageParam.setName("");
warningMessageParam.setStringValue("Warning template with that name already exists - really overwrite?");
StringParameterType.setIsLabel(warningMessageParam, true);
warningParams.addParameter(warningMessageParam);
final PluginParametersSwingDialog overwrite = new PluginParametersSwingDialog("Overwrite?", warningParams);
overwrite.showAndWait();
if (!PluginParametersDialog.OK.equals(overwrite.getResult())) {
continue;
}
}
Future<?> f = PluginExecution.withPlugin(plugin).withParameters(params).executeLater(context.getGraph());
PluginExecution.withPlugin(new SimplePlugin() {
@Override
public String getName() {
return "Update Template Menu";
}
@Override
protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
NewSchemaGraphAction.recreateTemplateMenuItems();
}
}).waitingFor(f).executeLater(null);
}
break;
}
}
Aggregations