Search in sources :

Example 1 with WizardNodeLayoutInfo

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);
}
Also used : WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 2 with WizardNodeLayoutInfo

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);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) WorkflowPortTemplate(org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate) WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 3 with WizardNodeLayoutInfo

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);
}
Also used : WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 4 with WizardNodeLayoutInfo

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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) InputStream(java.io.InputStream) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 5 with WizardNodeLayoutInfo

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);
}
Also used : WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Aggregations

WizardNodeLayoutInfo (org.knime.core.node.wizard.WizardNodeLayoutInfo)6 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 Image (org.eclipse.swt.graphics.Image)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1 NodeID (org.knime.core.node.workflow.NodeID)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1