use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.
the class ConfigureMetaNodePortsPage method moveSelPort.
private void moveSelPort(final boolean inPort, final boolean moveUp) {
java.util.List<MetaPortInfo> infoList = inPort ? m_inPortList : m_outPortList;
List portList = inPort ? m_inPorts : m_outPorts;
int idx = portList.getSelectionIndex();
int minIdx = moveUp ? 1 : 0;
if (idx < minIdx) {
return;
}
int maxIdx = moveUp ? portList.getItemCount() - 1 : portList.getItemCount() - 2;
if (idx > maxIdx) {
LOGGER.coding("Selected port index is too big for internal port info list to move " + (moveUp ? "up" : "down"));
return;
}
MetaPortInfo info = infoList.get(idx + m_offset);
infoList.remove(idx + m_offset);
idx = moveUp ? (idx - 1) : (idx + 1);
infoList.add(idx + m_offset, info);
populateSelectionlistFromInfolist(portList, infoList, inPort ? "in_" : "out_");
portList.select(idx);
updateStatus();
}
use of org.knime.core.node.port.MetaPortInfo 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.core.node.port.MetaPortInfo in project knime-core by knime.
the class AddMetaNodeWizard method performCustomizedFinish.
private void performCustomizedFinish() {
// create subworkflow with the number and types
// of the entered in- and out ports
PortType[] inPorts = new PortType[m_addPage.getInPorts().size()];
PortType[] outPorts = new PortType[m_addPage.getOutPorts().size()];
int i = 0;
for (MetaPortInfo p : m_addPage.getInPorts()) {
inPorts[i++] = p.getType();
}
i = 0;
for (MetaPortInfo p : m_addPage.getOutPorts()) {
outPorts[i++] = p.getType();
}
String name = "";
if (m_addPage.getMetaNodeName() != null && m_addPage.getMetaNodeName().length() > 0) {
name = m_addPage.getMetaNodeName();
}
createMetaNodeFromPorts(inPorts, outPorts, name);
}
use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.
the class ReconfigureMetaNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
if (nc instanceof WorkflowManager) {
if (m_name != null) {
WorkflowManager metaNode = (WorkflowManager) nc;
m_oldName = metaNode.getName();
metaNode.setName(m_name);
}
if (m_inPorts != null) {
m_reverseInports = createReverseOperationList(getHostWFM().getMetanodeInputPortInfo(m_metanodeID), m_inPorts);
getHostWFM().changeMetaNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
}
if (m_outPorts != null) {
m_reverseOutports = createReverseOperationList(getHostWFM().getMetanodeOutputPortInfo(m_metanodeID), m_outPorts);
getHostWFM().changeMetaNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
}
} else if (nc instanceof SubNodeContainer) {
SubNodeContainer snc = (SubNodeContainer) nc;
if (m_name != null) {
m_oldName = snc.getName();
snc.setName(m_name);
}
if (m_inPorts != null) {
m_reverseInports = createReverseOperationList(getHostWFM().getSubnodeInputPortInfo(m_metanodeID), m_inPorts);
getHostWFM().changeSubNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
}
if (m_outPorts != null) {
m_reverseOutports = createReverseOperationList(getHostWFM().getSubnodeOutputPortInfo(m_metanodeID), m_outPorts);
getHostWFM().changeSubNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
}
}
}
use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.
the class ReconfigureMetaNodeCommand method createReverseOperationList.
/**
* Creates a port list that can be applied - after the newPortList was applied to a metanode with the
* currentPortList - to get the metanode back to a port list like the curentPortList.
*
* @param currentPortList
* @param newPortList
* @return
*/
private List<MetaPortInfo> createReverseOperationList(final MetaPortInfo[] currentPortList, final List<MetaPortInfo> newPortList) {
MetaPortInfo[] reverse = new MetaPortInfo[currentPortList.length];
for (MetaPortInfo newInfo : newPortList) {
if (newInfo.getOldIndex() >= 0) {
int revOldIdx = newInfo.getNewIndex();
int revNewIdx = newInfo.getOldIndex();
PortType revType = currentPortList[newInfo.getOldIndex()].getType();
boolean revConn = currentPortList[newInfo.getOldIndex()].isConnected();
MetaPortInfo revInfo = MetaPortInfo.builder().setPortType(revType).setIsConnected(revConn).setOldIndex(revOldIdx).setNewIndex(revNewIdx).build();
reverse[revNewIdx] = revInfo;
}
}
// all array positions still null got deleted and must be filled from the current list
for (int i = 0; i < reverse.length; i++) {
if (reverse[i] != null) {
// that is a port that got moved back above
continue;
}
MetaPortInfo currentInfo = currentPortList[i];
MetaPortInfo revInfo = MetaPortInfo.builder(currentInfo).setIsConnected(false).setMessage(null).setOldIndex(-1).setNewIndex(i).build();
reverse[i] = revInfo;
}
return new ArrayList<MetaPortInfo>(Arrays.asList(reverse));
}
Aggregations