use of org.knime.workbench.editor2.commands.ReconfigureMetaNodeCommand in project knime-core by knime.
the class SetupSubnodeWizard method applyPortChanges.
private boolean applyPortChanges() {
List<MetaPortInfo> inPorts = m_portsPage.getInPorts();
List<MetaPortInfo> outPorts = m_portsPage.getOutPorts();
String name = m_portsPage.getMetaNodeName();
// fix the indicies
for (int i = 0; i < inPorts.size(); i++) {
m_portsPage.replaceInPortAtIndex(i, MetaPortInfo.builder(inPorts.get(i)).setNewIndex(i).build());
}
for (int i = 0; i < outPorts.size(); i++) {
m_portsPage.replaceOutPortAtIndex(i, MetaPortInfo.builder(outPorts.get(i)).setNewIndex(i).build());
}
inPorts = m_portsPage.getInPorts();
outPorts = m_portsPage.getOutPorts();
// determine what has changed
boolean inPortChanges = m_subNode.getNrInPorts() != inPorts.size();
for (MetaPortInfo inInfo : inPorts) {
// new port types would create a new info object - which would have an unspecified old index -> change
inPortChanges |= inInfo.getOldIndex() != inInfo.getNewIndex();
}
boolean outPortChanges = m_subNode.getNrOutPorts() != outPorts.size();
for (MetaPortInfo outInfo : outPorts) {
// new port types would create a new info object - which would have an unspecified old index -> change
outPortChanges |= outInfo.getOldIndex() != outInfo.getNewIndex();
}
boolean nameChange = !m_subNode.getName().equals(name);
StringBuilder infoStr = new StringBuilder();
if (inPortChanges) {
infoStr.append("the input ports - ");
}
if (outPortChanges) {
infoStr.append("the output ports - ");
}
if (nameChange) {
infoStr.append("the name - ");
}
if (infoStr.length() == 0) {
LOGGER.info("No changes made in the configuration wizard. Nothing to do.");
return true;
}
infoStr.insert(0, "Changing - ");
infoStr.append("of MetaNode " + m_subNode.getID());
LOGGER.info(infoStr);
ReconfigureMetaNodeCommand reconfCmd = new ReconfigureMetaNodeCommand(m_subNode.getParent(), m_subNode.getID());
if (nameChange) {
reconfCmd.setNewName(name);
}
if (inPortChanges) {
reconfCmd.setNewInPorts(inPorts);
}
if (outPortChanges) {
reconfCmd.setNewOutPorts(outPorts);
}
m_viewer.getEditDomain().getCommandStack().execute(reconfCmd);
return true;
}
use of org.knime.workbench.editor2.commands.ReconfigureMetaNodeCommand in project knime-core by knime.
the class ReconfigureMetaNodeWizard method performFinish.
/**
* {@inheritDoc}
*/
@Override
public boolean performFinish() {
NodeContainer node = m_metaNode != null ? m_metaNode : m_subNode;
List<MetaPortInfo> inPorts = m_addPage.getInPorts();
List<MetaPortInfo> outPorts = m_addPage.getOutPorts();
String name = m_addPage.getMetaNodeName();
// fix the indicies
for (int i = 0; i < inPorts.size(); i++) {
m_addPage.replaceInPortAtIndex(i, MetaPortInfo.builder(inPorts.get(i)).setNewIndex(i).build());
}
for (int i = 0; i < outPorts.size(); i++) {
m_addPage.replaceOutPortAtIndex(i, MetaPortInfo.builder(outPorts.get(i)).setNewIndex(i).build());
}
inPorts = m_addPage.getInPorts();
outPorts = m_addPage.getOutPorts();
// determine what has changed
boolean inPortChanges = node.getNrInPorts() != inPorts.size();
for (MetaPortInfo inInfo : inPorts) {
// new port types would create a new info object - which would have an unspecified old index -> change
inPortChanges |= inInfo.getOldIndex() != inInfo.getNewIndex();
}
boolean outPortChanges = node.getNrOutPorts() != outPorts.size();
for (MetaPortInfo outInfo : outPorts) {
// new port types would create a new info object - which would have an unspecified old index -> change
outPortChanges |= outInfo.getOldIndex() != outInfo.getNewIndex();
}
boolean nameChange = !node.getName().equals(name);
StringBuilder infoStr = new StringBuilder();
if (inPortChanges) {
infoStr.append("the input ports - ");
}
if (outPortChanges) {
infoStr.append("the output ports - ");
}
if (nameChange) {
infoStr.append("the name - ");
}
if (infoStr.length() == 0) {
LOGGER.info("No changes made in the configuration wizard. Nothing to do.");
return true;
}
infoStr.insert(0, "Changing - ");
infoStr.append("of MetaNode " + node.getID());
LOGGER.info(infoStr);
ReconfigureMetaNodeCommand reconfCmd = new ReconfigureMetaNodeCommand(node.getParent(), node.getID());
if (nameChange) {
reconfCmd.setNewName(name);
}
if (inPortChanges) {
reconfCmd.setNewInPorts(inPorts);
}
if (outPortChanges) {
reconfCmd.setNewOutPorts(outPorts);
}
m_viewer.getEditDomain().getCommandStack().execute(reconfCmd);
return true;
}
Aggregations