Search in sources :

Example 6 with NodeProgressEvent

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

the class FileReaderNodeDialog method analyzeAction.

/**
 * triggers analysis.
 */
protected void analyzeAction() {
    synchronized (m_analysisRunning) {
        // wait until we have a chance to run the analysis
        while (m_analysisRunning.booleanValue()) {
            LOGGER.error("Internal error: Re-entering analysis thread - " + "canceling it - waiting for it to finish...");
            m_analysisExecMonitor.setExecuteInterrupted();
            // wait until it finishes
            try {
                m_analysisRunning.wait();
                LOGGER.error("Alright - continuing with new analysis...");
            } catch (InterruptedException ie) {
            // huh?!?
            }
        }
        // Create execution context for progress and cancellations
        // We use our own progress monitor, we need to distinguish
        // between user cancel and code interrupts.
        m_analysisExecMonitor = new FileReaderExecutionMonitor();
        m_analysisExecMonitor.getProgressMonitor().addProgressListener(new NodeProgressListener() {

            @Override
            public void progressChanged(final NodeProgressEvent pEvent) {
                if (pEvent.getNodeProgress().getMessage() != null) {
                    ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                        @Override
                        public void run() {
                            Double p = pEvent.getNodeProgress().getProgress();
                            if (p == null) {
                                p = new Double(0.0);
                            }
                            m_analyzeProgressMsg.setText(pEvent.getNodeProgress().getMessage());
                            m_analyzeProgressBar.setValue((int) Math.round(100 * p.doubleValue()));
                            getPanel().revalidate();
                            getPanel().repaint();
                        }
                    });
                }
            }
        });
        // the analysis thread, when finished, clears this flag.
        m_analysisRunning.setValue(true);
        // allow for quickies from now on
        m_analyzeCancel.setEnabled(true);
        m_scanLimitSpinner.setEnabled(true);
        setPreviewTable(null);
        setErrorLabelText("");
    }
    // clone current settings
    FileReaderNodeSettings newFRSettings = new FileReaderNodeSettings(m_frSettings);
    Vector<ColProperty> oldColProps = m_frSettings.getColumnProperties();
    // prepare the settings object for re-analysis
    newFRSettings.setNumberOfColumns(-1);
    Vector<ColProperty> newProps = new Vector<ColProperty>();
    if (oldColProps != null) {
        for (ColProperty cProp : oldColProps) {
            // take over only the ones modified by the user
            if ((cProp != null) && (cProp.getUserSettings())) {
                newProps.add(cProp);
            } else {
                newProps.add(null);
            }
        }
    }
    newFRSettings.setColumnProperties(newProps);
    analyzeInThread(newFRSettings);
}
Also used : NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) Vector(java.util.Vector)

Example 7 with NodeProgressEvent

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

the class TableSorterWorker method doInBackground.

/**
 * {@inheritDoc}
 */
@Override
protected DataTable doInBackground() throws Exception {
    // passed to table sorter for progress
    long rowCount;
    if (m_inputTable instanceof BufferedDataTable) {
        rowCount = ((BufferedDataTable) m_inputTable).size();
    } else if (m_inputTable instanceof ContainerTable) {
        rowCount = ((ContainerTable) m_inputTable).size();
    } else {
        // unknown, no progress
        rowCount = -1;
    }
    publish(new NodeProgress(0.0, "Starting table sort..."));
    Collection<String> sortColNames = new ArrayList<String>(2);
    DataTableSpec spec = m_inputTable.getDataTableSpec();
    for (int i : m_sortOrder.getSortColumnIndices()) {
        String name;
        if (i < 0) {
            // row id
            name = DataTableSorter.ROWKEY_SORT_SPEC.getName();
        } else {
            name = spec.getColumnSpec(i).getName();
        }
        sortColNames.add(name);
    }
    long start = System.currentTimeMillis();
    LOGGER.debug("Starting interactive table sorting on column(s) " + sortColNames);
    boolean[] sortOrders = m_sortOrder.getSortColumnOrder();
    // it DOES NOT respect blobs -- they will be copied (expensive)
    DataTableSorter sorter = new DataTableSorter(m_inputTable, rowCount, sortColNames, sortOrders, false);
    NodeProgressListener progLis = new NodeProgressListener() {

        @Override
        public void progressChanged(final NodeProgressEvent pe) {
            publish(pe.getNodeProgress());
        }
    };
    m_nodeProgressMonitor = new DefaultNodeProgressMonitor();
    ExecutionMonitor exec = new ExecutionMonitor(m_nodeProgressMonitor);
    m_nodeProgressMonitor.addProgressListener(progLis);
    try {
        DataTable result = sorter.sort(exec);
        long elapsedMS = System.currentTimeMillis() - start;
        String time = StringFormat.formatElapsedTime(elapsedMS);
        LOGGER.debug("Interactive table sorting finished (" + time + ")");
        return result;
    } finally {
        m_nodeProgressMonitor.removeProgressListener(progLis);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) ArrayList(java.util.ArrayList) ContainerTable(org.knime.core.data.container.ContainerTable) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) DataTableSorter(org.knime.core.data.sort.DataTableSorter) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 8 with NodeProgressEvent

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

the class DefaultNodeProgressMonitor method fireProgressChanged.

private void fireProgressChanged() {
    m_changed = false;
    NodeProgress pe = new NodeProgress(getProgress(), createMessage(m_messageSupplier, m_appendSupplier));
    for (NodeProgressListener l : m_listeners) {
        try {
            // we can't provide a useful node id here
            // TODO replace by null argument (0 is certainly misleading)
            l.progressChanged(new NodeProgressEvent(new NodeID(0), pe));
        } catch (Throwable t) {
            LOGGER.error("Exception while notifying listeners", t);
        }
    }
}
Also used : NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) NodeID(org.knime.core.node.workflow.NodeID)

Aggregations

NodeProgressEvent (org.knime.core.node.workflow.NodeProgressEvent)8 NodeProgressListener (org.knime.core.node.workflow.NodeProgressListener)7 NodeProgress (org.knime.core.node.workflow.NodeProgress)6 DataTableSpec (org.knime.core.data.DataTableSpec)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 DataTable (org.knime.core.data.DataTable)2 ContainerTable (org.knime.core.data.container.ContainerTable)2 DataTableSorter (org.knime.core.data.sort.DataTableSorter)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 DefaultNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor)2 NodeID (org.knime.core.node.workflow.NodeID)2 URL (java.net.URL)1 Test (org.junit.Test)1 FileReaderExecutionMonitor (org.knime.base.node.io.filereader.FileReaderExecutionMonitor)1 FileReaderNodeSettings (org.knime.base.node.io.filereader.FileReaderNodeSettings)1 FileTable (org.knime.base.node.io.filereader.FileTable)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionContext (org.knime.core.node.ExecutionContext)1