Search in sources :

Example 1 with BufferedDataTableView

use of org.knime.core.node.workflow.BufferedDataTableView in project knime-core by knime.

the class DatabasePortObject method loadTablePreview.

private void loadTablePreview(final JComponent[] panels, final JPanel p, final JTextField cacheRows) {
    final AtomicInteger value = new AtomicInteger(100);
    try {
        int v = Integer.parseInt(cacheRows.getText().trim());
        value.set(v);
    } catch (NumberFormatException nfe) {
        cacheRows.setText(Integer.toString(value.get()));
    }
    panels[0].removeAll();
    panels[0].add(new JLabel("Fetching " + value.get() + " rows from database..."), BorderLayout.NORTH);
    panels[0].repaint();
    panels[0].revalidate();
    new SwingWorkerWithContext<DataTable, Void>() {

        /**
         * {@inheritDoc}
         */
        @Override
        protected DataTable doInBackgroundWithContext() throws Exception {
            return getDataTable(value.get());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected void doneWithContext() {
            DataTable dt = null;
            try {
                dt = super.get();
            } catch (ExecutionException ee) {
                LOGGER.warn("Error during fetching data from " + "database, reason: " + ee.getMessage(), ee);
            } catch (InterruptedException ie) {
                LOGGER.warn("Error during fetching data from " + "database, reason: " + ie.getMessage(), ie);
            }
            @SuppressWarnings("serial") final BufferedDataTableView dataView2 = new BufferedDataTableView(dt) {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public String getName() {
                    return "Table Preview";
                }
            };
            dataView2.setName("Table Preview");
            panels[0].removeAll();
            panels[0].add(p, BorderLayout.NORTH);
            panels[0].add(dataView2, BorderLayout.CENTER);
            panels[0].setName(dataView2.getName());
            panels[0].repaint();
            panels[0].revalidate();
        }
    }.execute();
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) JLabel(javax.swing.JLabel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BufferedDataTableView(org.knime.core.node.workflow.BufferedDataTableView)

Example 2 with BufferedDataTableView

use of org.knime.core.node.workflow.BufferedDataTableView in project knime-core by knime.

the class DatabasePortObject method getViews.

/**
 * {@inheritDoc}
 */
@Override
public JComponent[] getViews() {
    JComponent[] superViews = super.getViews();
    final JComponent[] panels = new JComponent[superViews.length + 1];
    @SuppressWarnings("serial") final BufferedDataTableView dataView = new BufferedDataTableView(null) {

        @Override
        public String getName() {
            return "Table Preview";
        }
    };
    final JButton b = new JButton("Cache no. of rows: ");
    final JPanel p = new JPanel(new FlowLayout());
    final JTextField cacheRows = new JTextField("100");
    cacheRows.setMinimumSize(new Dimension(50, 20));
    cacheRows.setPreferredSize(new Dimension(50, 20));
    p.add(b);
    p.add(cacheRows);
    panels[0] = new DatabaseOutPortPanel(new BorderLayout());
    panels[0].setName(dataView.getName());
    panels[0].add(p, BorderLayout.NORTH);
    panels[0].add(dataView, BorderLayout.CENTER);
    // store the NodeContext to explicitly set the NodeContext when the fetch rows button is pressed
    final NodeContext nodeContext = NodeContext.getContext();
    b.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent e) {
            // explicitly set the NodeContext to get the current workflow user that is used in Kerberos secured
            // db connection
            NodeContext.pushContext(nodeContext);
            try {
                loadTablePreview(panels, p, cacheRows);
            } finally {
                // remove the previously set NodeContext
                NodeContext.removeLastContext();
            }
        }
    });
    for (int i = 1; i < panels.length; i++) {
        panels[i] = superViews[i - 1];
    }
    return panels;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) NodeContext(org.knime.core.node.workflow.NodeContext) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) BufferedDataTableView(org.knime.core.node.workflow.BufferedDataTableView)

Aggregations

BufferedDataTableView (org.knime.core.node.workflow.BufferedDataTableView)2 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JTextField (javax.swing.JTextField)1 DataTable (org.knime.core.data.DataTable)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeContext (org.knime.core.node.workflow.NodeContext)1