Search in sources :

Example 16 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class ConfigureMetaNodePortsPage method updateButtonState.

private void updateButtonState() {
    int inSel = m_inPorts.getSelectionIndex();
    if (inSel >= 0) {
        MetaPortInfo info = m_inPortList.get(inSel + m_offset);
        m_addInPort.setEnabled(true);
        m_remInPort.setEnabled(!info.isConnected());
        m_upInPort.setEnabled(inSel > 0);
        m_downInPort.setEnabled(inSel < m_inPorts.getItemCount() - 1);
    } else {
        m_addInPort.setEnabled(true);
        m_remInPort.setEnabled(false);
        m_upInPort.setEnabled(false);
        m_downInPort.setEnabled(false);
    }
    int outSel = m_outPorts.getSelectionIndex();
    if (outSel >= 0) {
        MetaPortInfo info = m_outPortList.get(outSel + m_offset);
        m_addOutPort.setEnabled(true);
        m_remOutPort.setEnabled(!info.isConnected());
        m_upOutPort.setEnabled(outSel > 0);
        m_downOutPort.setEnabled(outSel < m_outPorts.getItemCount() - 1);
    } else {
        m_addOutPort.setEnabled(true);
        m_remOutPort.setEnabled(false);
        m_upOutPort.setEnabled(false);
        m_downOutPort.setEnabled(false);
    }
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Example 17 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class ConfigureMetaNodePortsPage method addPort.

private void addPort(final boolean inPort) {
    java.util.List<MetaPortInfo> infoList = inPort ? m_inPortList : m_outPortList;
    List portList = inPort ? m_inPorts : m_outPorts;
    MetaPortDialog dialog = new MetaPortDialog(Display.getDefault().getActiveShell());
    PortType port = dialog.open();
    if (port != null) {
        MetaPortInfo info = MetaPortInfo.builder().setPortType(port).setNewIndex(infoList.size()).build();
        infoList.add(info);
        populateSelectionlistFromInfolist(portList, infoList, inPort ? "in_" : "out_");
        portList.select(portList.getItemCount() - 1);
    }
    m_previewPanel.redraw();
    updateStatus();
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) ArrayList(java.util.ArrayList) List(org.eclipse.swt.widgets.List) PortType(org.knime.core.node.port.PortType)

Example 18 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class ConfigureMetaNodePortsPage method updateStatus.

private void updateStatus() {
    updateButtonState();
    m_portMsg.setText("");
    boolean inPort = true;
    int idx = m_inPorts.getSelectionIndex();
    if (idx < 0) {
        inPort = false;
        idx = m_outPorts.getSelectionIndex();
    }
    if (idx >= 0) {
        MetaPortInfo info = inPort ? m_inPortList.get(idx + m_offset) : m_outPortList.get(idx + m_offset);
        StringBuilder str = new StringBuilder();
        str.append(inPort ? "Input " : "Output ");
        str.append("port ");
        str.append(idx);
        str.append(": ");
        // Old ports show connectivity info
        if (info.getOldIndex() >= 0) {
            if (info.isConnected()) {
                if (info.getMessage() != null && !info.getMessage().isEmpty()) {
                    // info contains connectivity info
                    str.append(info.getMessage());
                    str.append(". ");
                } else {
                    str.append("Connected. ");
                }
            } else {
                str.append("Not connected. ");
            }
            if (info.getOldIndex() != idx + m_offset) {
                str.append("Moved from old index ");
                str.append(info.getOldIndex());
                str.append(". ");
            }
        } else {
            str.append("New port. ");
        }
        if (m_metaNode != null || m_subNode != null) {
            // only when we change things we show the infos
            m_portMsg.setText(str.toString());
        }
    }
    m_portMsg.setToolTipText(m_portMsg.getText());
    m_previewPanel.redraw();
    setPageComplete(isPageComplete());
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Example 19 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class ConfigureMetaNodePortsPage method populateInfoListsFromTemplate.

private void populateInfoListsFromTemplate() {
    LOGGER.debug("Populating fields from template " + m_template);
    // clear all fields
    m_inPortList.clear();
    m_outPortList.clear();
    if (m_template == null) {
        return;
    }
    int nrInPorts = 0;
    int nrOutPorts = 0;
    if (m_template.equals(SelectMetaNodePage.ZERO_ONE)) {
        nrInPorts = 0;
        nrOutPorts = 1;
    } else if (m_template.equals(SelectMetaNodePage.ONE_ONE)) {
        nrInPorts = 1;
        nrOutPorts = 1;
    } else if (m_template.equals(SelectMetaNodePage.ONE_TWO)) {
        nrInPorts = 1;
        nrOutPorts = 2;
    } else if (m_template.equals(SelectMetaNodePage.TWO_ONE)) {
        nrInPorts = 2;
        nrOutPorts = 1;
    } else if (m_template.equals(SelectMetaNodePage.TWO_TWO)) {
        nrInPorts = 2;
        nrOutPorts = 2;
    }
    // add the ports to the lists
    for (int i = 0; i < nrInPorts; i++) {
        // the "new index" is not maintained in this wizard page
        MetaPortInfo info = MetaPortInfo.builder().setPortType(BufferedDataTable.TYPE).setNewIndex(-1).build();
        m_inPortList.add(info);
    }
    for (int i = 0; i < nrOutPorts; i++) {
        // the "new index" is not maintained in this wizard page
        MetaPortInfo info = MetaPortInfo.builder().setPortType(BufferedDataTable.TYPE).setNewIndex(-1).build();
        m_outPortList.add(info);
    }
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Example 20 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class ConfigureMetaNodePortsPage method createPreviewPanel.

private void createPreviewPanel(final Composite parent) {
    m_previewPanel = new Composite(parent, SWT.FILL | SWT.BORDER);
    m_previewPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER));
    m_previewPanel.setLayout(new FillLayout());
    m_previewPanel.addPaintListener(new PaintListener() {

        private static final int IMAGE_HEIGHT = 30;

        private static final int IMAGE_WIDTH = 30;

        private static final int PORT_BAR_HEIGHT = 40;

        private final int PORT_SIZE = AbstractPortFigure.getPortSizeNode();

        private int m_top;

        @Override
        public void paintControl(final PaintEvent e) {
            GC gc = e.gc;
            Rectangle bounds = m_previewPanel.getBounds();
            m_top = (bounds.height / 2) - (IMAGE_HEIGHT / 2) - (PORT_SIZE / 2);
            drawInPorts(gc);
            drawOutPorts(gc);
            gc.drawImage(ImageRepository.getImage(KNIMEEditorPlugin.PLUGIN_ID, "/icons/meta/meta_custom_preview.png"), (bounds.width / 2) - (IMAGE_WIDTH / 2), (bounds.height / 2) - (IMAGE_HEIGHT / 2));
        }

        private void drawInPorts(final GC gc) {
            Rectangle b = m_previewPanel.getBounds();
            int offset = (PORT_BAR_HEIGHT + PORT_SIZE) / (m_inPortList.size() + 1);
            int left = (b.width / 2) - (IMAGE_WIDTH / 2);
            int i = 0;
            for (MetaPortInfo inPort : m_inPortList) {
                int y = m_top + (((i + 1) * offset) - (PORT_SIZE));
                if (inPort.getType().equals(BufferedDataTable.TYPE)) {
                    gc.drawPolygon(new int[] { left - PORT_SIZE, y, left, y + (PORT_SIZE / 2), left - PORT_SIZE, y + PORT_SIZE });
                } else if (PMMLPortObject.TYPE.isSuperTypeOf(inPort.getType())) {
                    gc.setBackground(ColorConstants.blue);
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(DatabasePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(FlowVariablePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
                    gc.fillOval(left - PORT_SIZE - 1, y - 1, PORT_SIZE + 1, PORT_SIZE + 1);
                } else {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                }
                i++;
            }
        }

        private void drawOutPorts(final GC gc) {
            Rectangle b = m_previewPanel.getBounds();
            int right = (b.width / 2) + (IMAGE_WIDTH / 2) + 2;
            int offset = (PORT_BAR_HEIGHT + PORT_SIZE) / (m_outPortList.size() + 1);
            int i = 0;
            for (MetaPortInfo inPort : m_outPortList) {
                int y = m_top + (((i + 1) * offset) - (PORT_SIZE));
                if (inPort.getType().equals(BufferedDataTable.TYPE)) {
                    gc.drawPolygon(new int[] { right, y, right + PORT_SIZE, y + (PORT_SIZE / 2), right, y + PORT_SIZE });
                } else if (PMMLPortObject.TYPE.isSuperTypeOf(inPort.getType())) {
                    gc.setBackground(ColorConstants.blue);
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(DatabasePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(FlowVariablePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                }
                i++;
            }
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) FillLayout(org.eclipse.swt.layout.FillLayout) GC(org.eclipse.swt.graphics.GC)

Aggregations

MetaPortInfo (org.knime.core.node.port.MetaPortInfo)22 PortType (org.knime.core.node.port.PortType)9 ArrayList (java.util.ArrayList)8 List (org.eclipse.swt.widgets.List)3 Test (org.junit.Test)3 NodeContainer (org.knime.core.node.workflow.NodeContainer)2 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)2 Pair (org.knime.core.util.Pair)2 ReconfigureMetaNodeCommand (org.knime.workbench.editor2.commands.ReconfigureMetaNodeCommand)2 Point (org.eclipse.draw2d.geometry.Point)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1