use of org.knime.core.node.wizard.WizardNodeLayoutInfo in project knime-core by knime.
the class SubnodeLayoutPage method editY.
private void editY(final NodeID nodeId, final Text yText) {
WizardNodeLayoutInfo layoutInfo = getOrCreateLayoutInfo(nodeId);
layoutInfo.setY(yText.getText());
updateLayoutInfo(nodeId, layoutInfo);
}
use of org.knime.core.node.wizard.WizardNodeLayoutInfo in project knime-core by knime.
the class FileSubNodeContainerPersistor method preLoadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
super.preLoadNodeContainer(parentPersistor, parentSettings, result);
// assigned by super
NodeSettingsRO nodeSettings = getNodeSettings();
try {
int i = nodeSettings.getInt("virtual-in-ID");
CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
m_virtualInNodeIDSuffix = i;
} catch (InvalidSettingsException e) {
String error = "Can't load virtual input node ID: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
}
try {
int i = nodeSettings.getInt("virtual-in-ID");
CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
m_virtualInNodeIDSuffix = i;
} catch (InvalidSettingsException e) {
String error = "Can't load virtual input node ID: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
}
Set<String> inportSetKeys = Collections.emptySet();
NodeSettingsRO inportsSettings = null;
try {
inportsSettings = nodeSettings.getNodeSettings("inports");
// input of subnode is represented by output of virtual in node.
inportSetKeys = inportsSettings.keySet();
// an extra for hidden flow var port
m_inPortTemplates = new WorkflowPortTemplate[inportSetKeys.size() + 1];
m_inPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
for (int i = 1; i < m_inPortTemplates.length; i++) {
// fallback values, correctly set below
m_inPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
}
} catch (InvalidSettingsException e) {
String error = "Can't load virtual input port information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
m_inPortTemplates = new WorkflowPortTemplate[0];
}
for (String key : inportSetKeys) {
try {
@SuppressWarnings("null") NodeSettingsRO inportSetting = inportsSettings.getNodeSettings(key);
WorkflowPortTemplate portTemplate = loadPort(inportSetting, inportSetKeys.size());
m_inPortTemplates[portTemplate.getPortIndex()] = portTemplate;
} catch (InvalidSettingsException e) {
String error = "Could not load input port information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
continue;
}
}
try {
if (m_templateInformation != null) {
// template information was set after construction (this node is a link created from a template)
assert m_templateInformation.getRole() == Role.Link;
} else {
m_templateInformation = MetaNodeTemplateInformation.load(nodeSettings, getLoadVersion());
CheckUtils.checkSettingNotNull(m_templateInformation, "No template information");
}
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow template information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
result.addError(error);
m_templateInformation = MetaNodeTemplateInformation.NONE;
}
try {
int i = nodeSettings.getInt("virtual-out-ID");
CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
m_virtualOutNodeIDSuffix = i;
} catch (InvalidSettingsException e) {
String error = "Can't load virtual output node ID: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
}
Set<String> outportSetKeys = Collections.emptySet();
NodeSettingsRO outportsSettings = null;
try {
outportsSettings = nodeSettings.getNodeSettings("outports");
// output of subnode is represented by input of virtual out node.
outportSetKeys = outportsSettings.keySet();
m_outPortTemplates = new WorkflowPortTemplate[outportSetKeys.size() + 1];
m_outPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
for (int i = 1; i < m_outPortTemplates.length; i++) {
// fallback values, correctly set below
m_outPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
}
} catch (InvalidSettingsException e) {
String error = "Can't load virtual output port information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
m_outPortTemplates = new WorkflowPortTemplate[0];
}
for (String key : outportSetKeys) {
try {
@SuppressWarnings("null") NodeSettingsRO outportSetting = outportsSettings.getNodeSettings(key);
WorkflowPortTemplate portTemplate = loadPort(outportSetting, outportSetKeys.size());
m_outPortTemplates[portTemplate.getPortIndex()] = portTemplate;
} catch (InvalidSettingsException e) {
String error = "Could not load output port information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
continue;
}
}
Set<String> layoutSetKeys = Collections.emptySet();
m_layoutInfo = new HashMap<Integer, WizardNodeLayoutInfo>();
NodeSettingsRO layoutSettings = null;
try {
layoutSettings = nodeSettings.getNodeSettings("layoutInfos");
layoutSetKeys = layoutSettings.keySet();
for (String key : layoutSetKeys) {
NodeSettingsRO singleLayoutSetting = layoutSettings.getNodeSettings(key);
int nodeID = singleLayoutSetting.getInt("nodeID");
WizardNodeLayoutInfo layoutInfo = WizardNodeLayoutInfo.loadFromNodeSettings(singleLayoutSetting);
m_layoutInfo.put(nodeID, layoutInfo);
}
} catch (InvalidSettingsException e) {
String error = "Could not load Wrapped Metanode layout information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
}
// added in 3.1, load with default value
m_layoutJSONString = nodeSettings.getString("layoutJSON", "");
m_workflowPersistor.preLoadNodeContainer(parentPersistor, parentSettings, result);
}
use of org.knime.core.node.wizard.WizardNodeLayoutInfo in project knime-core by knime.
the class SubnodeLayoutPage method editPadding.
private void editPadding(final NodeID nodeId, final Text paddingText) {
WizardNodeLayoutInfo layoutInfo = getOrCreateLayoutInfo(nodeId);
layoutInfo.setPadding(paddingText.getText());
updateLayoutInfo(nodeId, layoutInfo);
}
use of org.knime.core.node.wizard.WizardNodeLayoutInfo in project knime-core by knime.
the class SubnodeLayoutPage method createControl.
/**
* {@inheritDoc}
*/
@Override
public void createControl(final Composite parent) {
ScrolledComposite scrollPane = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
scrollPane.setExpandHorizontal(true);
scrollPane.setExpandVertical(true);
Composite composite = new Composite(scrollPane, SWT.NONE);
scrollPane.setContent(composite);
scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
composite.setLayout(new GridLayout(4, false));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
Label titleLabel = new Label(composite, SWT.LEFT);
FontData fontData = titleLabel.getFont().getFontData()[0];
Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
titleLabel.setText("Node");
titleLabel.setFont(boldFont);
Label xLabel = new Label(composite, SWT.LEFT);
xLabel.setText("X");
xLabel.setFont(boldFont);
Label yLabel = new Label(composite, SWT.LEFT);
yLabel.setText("Y");
yLabel.setFont(boldFont);
Label paddingLabel = new Label(composite, SWT.LEFT);
paddingLabel.setText("Padding");
paddingLabel.setFont(boldFont);
for (final NodeID nodeID : m_viewNodes) {
NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
WizardNodeLayoutInfo layoutInfo = null;
if (m_subNodeContainer != null && m_subNodeContainer.getLayoutInfo() != null) {
layoutInfo = m_subNodeContainer.getLayoutInfo().get(nodeID.getIndex());
if (layoutInfo != null) {
m_layoutMap.put(nodeID.getIndex(), layoutInfo);
}
}
Composite labelComposite = new Composite(composite, SWT.NONE);
labelComposite.setLayout(new GridLayout(2, false));
labelComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Label iconLabel = new Label(labelComposite, SWT.CENTER);
iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
try (InputStream iconURLStream = FileLocator.resolve(nodeContainer.getIcon()).openStream()) {
iconLabel.setImage(new Image(Display.getCurrent(), iconURLStream));
} catch (IOException e) {
/* do nothing */
}
Label nodeLabel = new Label(labelComposite, SWT.LEFT);
nodeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
String nodeName = nodeContainer.getName();
String annotation = nodeContainer.getNodeAnnotation().getText();
nodeLabel.setText(nodeName + "\nID: " + nodeID.getIndex() + "\n" + annotation);
GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gridData.widthHint = 80;
final Text xText = new Text(composite, SWT.SINGLE | SWT.BORDER);
xText.setLayoutData(gridData);
xText.setText(layoutInfo == null ? "" : layoutInfo.getX());
xText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editX(nodeID, xText);
}
});
final Text yText = new Text(composite, SWT.SINGLE | SWT.BORDER);
yText.setLayoutData(gridData);
yText.setText(layoutInfo == null ? "" : layoutInfo.getY());
yText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editY(nodeID, yText);
}
});
final Text paddingText = new Text(composite, SWT.SINGLE | SWT.BORDER);
paddingText.setLayoutData(gridData);
paddingText.setText(layoutInfo == null || layoutInfo.getPadding() == null ? "" : layoutInfo.getPadding());
paddingText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editPadding(nodeID, paddingText);
}
});
}
scrollPane.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
setControl(scrollPane);
}
use of org.knime.core.node.wizard.WizardNodeLayoutInfo in project knime-core by knime.
the class SubnodeLayoutPage method editX.
private void editX(final NodeID nodeId, final Text xText) {
WizardNodeLayoutInfo layoutInfo = getOrCreateLayoutInfo(nodeId);
layoutInfo.setX(xText.getText());
updateLayoutInfo(nodeId, layoutInfo);
}
Aggregations