use of au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog in project constellation by constellation-app.
the class LayerByTimeAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent ev) {
final Plugin plugin = PluginRegistry.get(ArrangementPluginRegistry.TIME);
final PluginParameters params = plugin.createParameters();
final Graph graph = context.getGraph();
plugin.updateParameters(graph, params);
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_LayerByTimeAction(), params);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
PluginExecution.withPlugin(plugin).withParameters(params).executeLater(graph);
}
}
use of au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog in project constellation by constellation-app.
the class NewNebulaAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final PluginParameters params = new PluginParameters();
final PluginParameter<FileParameterValue> fileParam = FileParameterType.build(NEBULA_FILE_PARAMETER_ID);
fileParam.setName("Nebula file");
FileParameterType.setFileFilters(fileParam, new ExtensionFilter("Nebula file", "*.nebula"));
fileParam.getParameterValue().setKind(FileParameterKind.SAVE);
fileParam.setHelpID("au.gov.asd.tac.constellation.file.nebula");
params.addParameter(fileParam);
final PluginParameter<ColorParameterValue> colorParam = ColorParameterType.build(COLOR_PARAMETER_ID);
colorParam.setName("Nebula colour");
params.addParameter(colorParam);
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_NewNebulaAction(), params);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
final FileParameterValue fpv = fileParam.getParameterValue();
if (!fpv.get().isEmpty()) {
final Properties props = new Properties();
final ConstellationColor c = colorParam.getColorValue();
props.setProperty("colour", String.format("%f,%f,%f", c.getRed(), c.getGreen(), c.getBlue()));
File f = fpv.get().get(0);
if (!StringUtils.endsWithIgnoreCase(f.getName(), FileExtensionConstants.NEBULA)) {
f = new File(f.getAbsoluteFile() + FileExtensionConstants.NEBULA);
}
try {
try (final FileOutputStream fos = new FileOutputStream(f)) {
props.store(fos, null);
NebulaDataObject.addRecent(f);
}
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
}
}
use of au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog in project constellation by constellation-app.
the class HistogramControls method binFormatterComboActionPerformed.
// GEN-LAST:event_attributeChoiceActionPerformed
private void binFormatterComboActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_binFormatterComboActionPerformed
if (!isAdjusting) {
final BinFormatter binFormatter = (BinFormatter) binFormatterCombo.getSelectedItem();
final PluginParameters parameters;
if (currentHistogramState != null && binFormatter.getClass() == currentHistogramState.getBinFormatter().getClass()) {
PluginParameters p = currentHistogramState.getBinFormatterParameters();
parameters = p == null ? null : p.copy();
binFormatter.updateParameters(parameters);
} else if (CURRENT_PARAMETER_IDS.containsKey(binFormatter)) {
parameters = CURRENT_PARAMETER_IDS.get(binFormatter).copy();
binFormatter.updateParameters(parameters);
} else {
parameters = binFormatter.createParameters();
binFormatter.updateParameters(parameters);
}
if (parameters != null) {
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(binFormatter.getLabel(), parameters);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
CURRENT_PARAMETER_IDS.put(binFormatter, parameters.copy());
topComponent.setBinFormatter((BinFormatter) binFormatterCombo.getSelectedItem(), parameters);
} else if (currentHistogramState != null) {
binFormatterCombo.setSelectedItem(currentHistogramState.getBinFormatter());
} else {
// Do nothing
}
} else {
topComponent.setBinFormatter((BinFormatter) binFormatterCombo.getSelectedItem(), null);
}
}
}
use of au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog in project constellation by constellation-app.
the class VisualGraphTopComponent method getActions.
@Override
public Action[] getActions() {
// Add new actions above the default actions.
final ArrayList<Action> actionList = new ArrayList<>();
// An action that closes the topcomponent without saving the (possibly modified) graph.
final Action discard = new AbstractAction(DISCARD) {
@Override
public void actionPerformed(final ActionEvent e) {
savable.setModified(false);
close();
}
};
actionList.add(discard);
// If this graph is in a nebula, add some nebula-related actions.
final NebulaDataObject nebula = getGraphNode().getDataObject().getNebulaDataObject();
if (nebula != null) {
// Discard the nebula without saving.
final Action discardNebula = new AbstractAction("Discard nebula") {
@Override
public void actionPerformed(final ActionEvent e) {
TopComponent.getRegistry().getOpened().stream().filter(tc -> (tc instanceof VisualGraphTopComponent)).map(tc -> (VisualGraphTopComponent) tc).forEach(vtc -> {
final NebulaDataObject ndo = vtc.getGraphNode().getDataObject().getNebulaDataObject();
if (nebula.equalsPath(ndo)) {
vtc.savable.setModified(false);
vtc.close();
}
});
}
};
actionList.add(discardNebula);
// Are there any graphs in this nebula (if it exists) that need saving?
final List<Savable> savables = getNebulaSavables(nebula);
if (!savables.isEmpty()) {
// There's at least one graph in this nebula that needs saving...
final Action saveNebula = new AbstractAction("Save nebula") {
@Override
public void actionPerformed(final ActionEvent e) {
try {
for (final Savable s : savables) {
s.save();
}
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
};
actionList.add(saveNebula);
} else {
// No graphs in this nebula need saving, so offer to close the nebula.
final Action closeNebula = new AbstractAction("Close nebula") {
@Override
public void actionPerformed(final ActionEvent e) {
TopComponent.getRegistry().getOpened().stream().filter(tc -> (tc instanceof VisualGraphTopComponent)).map(tc -> (VisualGraphTopComponent) tc).forEach(vtc -> {
final NebulaDataObject ndo = vtc.getGraphNode().getDataObject().getNebulaDataObject();
if (nebula.equalsPath(ndo)) {
vtc.close();
}
});
}
};
actionList.add(closeNebula);
}
}
// An action that renames the topcomponent without saving the (possibly modified) graph.
final Action rename = new AbstractAction("Rename") {
@Override
public void actionPerformed(final ActionEvent e) {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<StringParameterValue> newGraphNameParameter = StringParameterType.build(NEW_GRAPH_NAME_PARAMETER_ID);
newGraphNameParameter.setName("New Graph Name");
newGraphNameParameter.setStringValue(graphNode.getDisplayName());
newGraphNameParameter.storeRecentValue();
parameters.addParameter(newGraphNameParameter);
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog("Rename Graph", parameters);
dialog.showAndWait();
if (PluginParametersSwingDialog.OK.equals(dialog.getResult())) {
final String newGraphName = parameters.getStringValue(NEW_GRAPH_NAME_PARAMETER_ID);
if (!newGraphName.isEmpty()) {
try {
// set the graph object name so the name is retained when you Save As
graphNode.getDataObject().rename(newGraphName);
// set the other graph name properties
graphNode.setName(newGraphName);
graphNode.setDisplayName(newGraphName);
// set the top component
setName(newGraphName);
setDisplayName(newGraphName);
// this changes the text on the tab
setHtmlDisplayName(newGraphName);
} catch (final IOException ex) {
throw new RuntimeException(String.format("The name %s already exists.", newGraphName), ex);
}
savable.setModified(true);
}
}
}
};
actionList.add(rename);
// Add the default actions.
for (final Action action : super.getActions()) {
actionList.add(action);
}
return actionList.toArray(new Action[actionList.size()]);
}
use of au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog in project constellation by constellation-app.
the class DefaultPluginInteraction method prompt.
@Override
public boolean prompt(final String promptName, final PluginParameters parameters) {
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Plugins should not be run on the EDT!");
}
boolean result = false;
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(promptName, parameters);
if (!parameters.hasMultiLineStringParameter()) {
dialog.showAndWait();
} else {
dialog.showAndWaitNoFocus();
}
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
result = true;
}
return result;
}
Aggregations