Search in sources :

Example 1 with JSONLayoutViewContent

use of org.knime.js.core.layout.bs.JSONLayoutViewContent in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method fillBasicComposite.

private void fillBasicComposite() {
    if (!m_basicPanelAvailable) {
        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalAlignment = SWT.CENTER;
        Label infoLabel = new Label(m_basicComposite, SWT.CENTER);
        infoLabel.setText("A basic configuration of the layout is not possible. \nPlease use the \"Advanced\" tab.");
        infoLabel.setLayoutData(gridData);
        return;
    }
    m_basicComposite.setLayout(new GridLayout(7, false));
    m_basicComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    Label titleLabel = new Label(m_basicComposite, 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);
    new Composite(m_basicComposite, SWT.NONE);
    /* Warning placeholder */
    Label rowLabel = new Label(m_basicComposite, SWT.CENTER);
    rowLabel.setText("Row");
    rowLabel.setFont(boldFont);
    Label colLabel = new Label(m_basicComposite, SWT.CENTER);
    colLabel.setText("Column");
    colLabel.setFont(boldFont);
    Label widthLabel = new Label(m_basicComposite, SWT.CENTER);
    widthLabel.setText("Width");
    widthLabel.setFont(boldFont);
    new Composite(m_basicComposite, SWT.NONE);
    /* More placeholder */
    new Composite(m_basicComposite, SWT.NONE);
    for (final Entry<NodeIDSuffix, BasicLayoutInfo> entry : m_basicMap.entrySet()) {
        NodeIDSuffix suffix = entry.getKey();
        BasicLayoutInfo layoutInfo = entry.getValue();
        NodeID nodeID = suffix.prependParent(m_subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = m_viewNodes.containsKey(suffix) ? m_wfManager.getNodeContainer(nodeID) : null;
        createNodeLabelComposite(m_basicComposite, nodeID, nodeContainer);
        final Label warningLabel = new Label(m_basicComposite, SWT.CENTER);
        if (nodeContainer != null && m_viewNodes.get(suffix).isHideInWizard()) {
            warningLabel.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/warning.png"));
            warningLabel.setToolTipText("Node is set to 'Hide in Wizard'. It might not be displayed in the layout.");
        }
        GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        gridData.widthHint = 50;
        final Spinner rowSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getRow(), 1, 999);
        rowSpinner.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                layoutInfo.setRow(rowSpinner.getSelection());
                tryUpdateJsonFromBasic();
            }
        });
        final Spinner colSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getCol(), 1, 99);
        colSpinner.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                layoutInfo.setCol(colSpinner.getSelection());
                tryUpdateJsonFromBasic();
            }
        });
        final Spinner widthSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getColWidth(), 1, 12);
        widthSpinner.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                layoutInfo.setColWidth(widthSpinner.getSelection());
                tryUpdateJsonFromBasic();
            }
        });
        final Button advancedButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
        advancedButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/settings.png"));
        advancedButton.setToolTipText("Additional layout settings");
        if (nodeContainer == null) {
            advancedButton.setEnabled(false);
        } else {
            advancedButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    JSONLayoutViewContent defaultViewContent = m_layoutCreator.getDefaultViewContentForNode(suffix, m_viewNodes.get(suffix));
                    ViewContentSettingsDialog settingsDialog = new ViewContentSettingsDialog(m_basicComposite.getShell(), layoutInfo.getView(), defaultViewContent);
                    if (settingsDialog.open() == Window.OK) {
                        layoutInfo.setView(settingsDialog.getViewSettings());
                        tryUpdateJsonFromBasic();
                    }
                }
            });
        }
        final Button removeButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
        removeButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/remove.png"));
        removeButton.setToolTipText("Remove node from layout");
        removeButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                if (nodeContainer != null) {
                    if (!MessageDialog.openConfirm(m_basicComposite.getShell(), "Confirm deletion", "Are you sure you want to delete node " + suffix + " from the layout?")) {
                        return;
                    }
                }
                m_basicMap.remove(suffix);
                tryUpdateJsonFromBasic();
            }
        });
    }
    for (@SuppressWarnings("rawtypes") final Entry<NodeIDSuffix, WizardNode> entry : m_viewNodes.entrySet()) {
        if (m_basicMap.containsKey(entry.getKey())) {
            continue;
        }
        // Node not in layout
        NodeID nodeID = entry.getKey().prependParent(m_subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
        createNodeLabelComposite(m_basicComposite, nodeID, nodeContainer);
        final Label warningLabel = new Label(m_basicComposite, SWT.CENTER);
        if (nodeContainer != null && m_viewNodes.get(entry.getKey()).isHideInWizard()) {
            warningLabel.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/warning.png"));
            warningLabel.setToolTipText("Node is set to 'Hide in Wizard'. It might not be displayed in the layout.");
        }
        final Button addButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
        addButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/add.png"));
        addButton.setToolTipText("Add node to layout");
        addButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                int lastRow = 0;
                for (BasicLayoutInfo basicLayoutInfo : m_basicMap.values()) {
                    lastRow = Math.max(lastRow, basicLayoutInfo.getRow());
                }
                BasicLayoutInfo newInfo = new BasicLayoutInfo();
                newInfo.setRow(lastRow + 1);
                newInfo.setCol(1);
                newInfo.setColWidth(12);
                newInfo.setView(m_layoutCreator.getDefaultViewContentForNode(entry.getKey(), entry.getValue()));
                m_basicMap.put(entry.getKey(), newInfo);
                tryUpdateJsonFromBasic();
            }
        });
        GridData gridData = new GridData();
        gridData.horizontalSpan = 4;
        Label space = new Label(m_basicComposite, SWT.NONE);
        space.setLayoutData(gridData);
    }
    GridData fillRow = new GridData();
    fillRow.grabExcessHorizontalSpace = true;
    fillRow.horizontalAlignment = SWT.CENTER;
    fillRow.horizontalSpan = 7;
    Button resetButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
    resetButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/reset.png"));
    resetButton.setText("Reset");
    resetButton.setToolTipText("Reset layout to default according to currently available nodes.");
    resetButton.setLayoutData(fillRow);
    resetButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (!MessageDialog.openConfirm(m_basicComposite.getShell(), "Confirm reset", "Are you sure you want to reset the layout according to the currently available nodes?")) {
                return;
            }
            resetLayout();
            if (isWindows()) {
                m_textArea.setText(m_jsonDocument);
            } else {
                m_text.setText(m_jsonDocument);
            }
            updateModelFromJson();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Spinner(org.eclipse.swt.widgets.Spinner) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WizardNode(org.knime.core.node.wizard.WizardNode) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) SelectionEvent(org.eclipse.swt.events.SelectionEvent) JSONLayoutViewContent(org.knime.js.core.layout.bs.JSONLayoutViewContent)

Example 2 with JSONLayoutViewContent

use of org.knime.js.core.layout.bs.JSONLayoutViewContent in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method processBasicLayoutRow.

/**
 * Processes one layout row, creates {@link BasicLayoutInfo} for each contained node and determines if basic layout
 * is available. Some advanced configurations (additional styles or classes, HTML content or nested layouts) can not
 * be represented in a basic layout.
 *
 * @param row the row to process
 * @param rowIndex the index of the row as it appears in the layout
 */
private void processBasicLayoutRow(final JSONLayoutRow row, final int rowIndex) {
    if (listNotNullOrEmpty(row.getAdditionalStyles()) || listNotNullOrEmpty(row.getAdditionalClasses())) {
        // basic layout not possible, show only advanced tab
        m_basicPanelAvailable = false;
        return;
    }
    List<JSONLayoutColumn> columns = row.getColumns();
    for (int colIndex = 0; colIndex < columns.size(); colIndex++) {
        JSONLayoutColumn column = columns.get(colIndex);
        if (listNotNullOrEmpty(column.getAdditionalStyles()) || listNotNullOrEmpty(column.getAdditionalClasses())) {
            // basic layout not possible, show only advanced tab
            m_basicPanelAvailable = false;
            return;
        }
        List<JSONLayoutContent> content = column.getContent();
        if (content != null) {
            for (JSONLayoutContent jsonLayoutContent : content) {
                if (jsonLayoutContent != null) {
                    if (jsonLayoutContent instanceof JSONLayoutViewContent) {
                        JSONLayoutViewContent viewContent = (JSONLayoutViewContent) jsonLayoutContent;
                        if (listNotNullOrEmpty(viewContent.getAdditionalStyles()) || listNotNullOrEmpty(viewContent.getAdditionalClasses())) {
                            // basic layout not possible, show only advanced tab
                            m_basicPanelAvailable = false;
                            return;
                        }
                        BasicLayoutInfo basicInfo = new BasicLayoutInfo();
                        basicInfo.setRow(rowIndex + 1);
                        basicInfo.setCol(colIndex + 1);
                        basicInfo.setColWidth(column.getWidthMD());
                        basicInfo.setView(viewContent);
                        NodeIDSuffix id = NodeIDSuffix.fromString(viewContent.getNodeID());
                        m_basicMap.put(id, basicInfo);
                    } else {
                        // basic layout not possible, show only advanced tab
                        m_basicPanelAvailable = false;
                        return;
                    }
                }
            }
        }
    }
}
Also used : JSONLayoutContent(org.knime.js.core.layout.bs.JSONLayoutContent) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) JSONLayoutColumn(org.knime.js.core.layout.bs.JSONLayoutColumn) JSONLayoutViewContent(org.knime.js.core.layout.bs.JSONLayoutViewContent) Point(org.eclipse.swt.graphics.Point)

Aggregations

NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)2 JSONLayoutViewContent (org.knime.js.core.layout.bs.JSONLayoutViewContent)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Spinner (org.eclipse.swt.widgets.Spinner)1 WizardNode (org.knime.core.node.wizard.WizardNode)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 JSONLayoutColumn (org.knime.js.core.layout.bs.JSONLayoutColumn)1 JSONLayoutContent (org.knime.js.core.layout.bs.JSONLayoutContent)1