use of au.gov.asd.tac.constellation.graph.file.nebula.NebulaDataObject 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.graph.file.nebula.NebulaDataObject in project constellation by constellation-app.
the class VisualGraphTopComponent method getNebulaSavables.
/**
* A List of Savable instances in this nebula.
*
* @param nebula The nebula that this graph is in.
*
* @return A List of Savable instances in this nebula.
*/
private static List<Savable> getNebulaSavables(final NebulaDataObject nebula) {
final List<Savable> savableList = new ArrayList<>();
final Collection<? extends Savable> savables = Savable.REGISTRY.lookupAll(Savable.class);
savables.stream().filter(s -> (s instanceof MySavable)).forEach(s -> {
final NebulaDataObject otherNDO = ((MySavable) s).tc().getGraphNode().getDataObject().getNebulaDataObject();
if (nebula.equalsPath(otherNDO)) {
savableList.add(s);
}
});
return savableList;
}
Aggregations