Search in sources :

Example 26 with HiLiteHandler

use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.

the class TableContentModelTest method testSetHiLiteHandler.

/**
 * Method being tested: setHiLiteHandler(HiLiteHandler) and
 *                      boolean hasHiLiteHandler().
 */
public final void testSetHiLiteHandler() {
    final TableContentModel m = new TableContentModel();
    assertFalse("Has Hilitehandler", m.hasHiLiteHandler());
    final HiLiteHandler hiliter = new HiLiteHandler();
    m.setHiLiteHandler(hiliter);
    assertTrue("Has HiLiteHandler", m.hasHiLiteHandler());
    // setting data on and off shouldn't change HiLite handler
    m.setDataTable(DATA);
    assertTrue("Has HiLiteHandler", m.hasHiLiteHandler());
    m.setDataTable(null);
    assertTrue("Has HiLiteHandler", m.hasHiLiteHandler());
    m.setHiLiteHandler(null);
    assertFalse("Has HiLiteHandler", m.hasHiLiteHandler());
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler)

Example 27 with HiLiteHandler

use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.

the class TableContentModelTest method testResetHilite.

// testUnHilite()
/**
 * Method being tested: resetHiLite().
 */
public final void testResetHilite() {
    final HiLiteHandler hiliter = new HiLiteHandler();
    final TableContentModel m = new TableContentModel(DATA, hiliter);
    final JTable table = new JTable(m);
    final ListSelectionModel listModel = table.getSelectionModel();
    // make sure, the content model knows about ALL ROWS
    m.getRow(OBJECT_DATA.length - 1);
    assertEquals(table.getRowCount(), OBJECT_DATA.length);
    // first: hilite all;
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertTrue(m.isHiLit(i));
    }
    // reset hilite
    m.requestResetHiLite();
    // hilite happens in EDT thread, this is executed in main - need to wait
    ViewUtils.invokeAndWaitInEDT(new Runnable() {

        @Override
        public void run() {
        // nothing, just run
        }
    });
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertFalse(m.isHiLit(i));
    }
    int lucky = (int) (Math.random() * OBJECT_DATA.length);
    listModel.setSelectionInterval(lucky, lucky);
    m.requestHiLite(listModel);
    flushEDTQueue();
    m.setTableContentFilter(TableContentFilter.HiliteOnly);
    // 0 should be ok, it returns the lucky row
    m.getRow(0);
    m.unHiLiteAll(new KeyEvent(this));
    assertEquals(m.getRowCount(), 0);
}
Also used : KeyEvent(org.knime.core.node.property.hilite.KeyEvent) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel)

Example 28 with HiLiteHandler

use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.

the class ExtendedStatisticsNodeModel method execute.

/**
 * {@inheritDoc}
 *
 * @throws CanceledExecutionException
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws CanceledExecutionException {
    double initPercent = m_enableHiLite.getBooleanValue() ? .25 : .2;
    ExecutionContext init = exec.createSubExecutionContext(initPercent);
    DataTableSpec dataSpec = inData[0].getDataTableSpec();
    List<String> includes = nominalColumns(dataSpec);
    m_statTable = new Statistics3Table(inData[0], m_computeMedian.getBooleanValue(), numOfNominalValuesOutput(), includes, init);
    if (getStatTable().getWarning() != null) {
        setWarningMessage(getStatTable().getWarning());
    }
    BufferedDataTable outTableOccurrences = exec.createBufferedDataTable(getStatTable().createNominalValueTable(includes), exec.createSubProgress(0.5));
    BufferedDataTable[] ret = new BufferedDataTable[3];
    DataTableSpec newSpec = renamedOccurrencesSpec(outTableOccurrences.getSpec());
    ret[2] = exec.createSpecReplacerTable(outTableOccurrences, newSpec);
    ExecutionContext table = exec.createSubExecutionContext(initPercent);
    ret[0] = getStatTable().createStatisticsInColumnsTable(table);
    ExecutionContext histogram = exec.createSubExecutionContext(1.0 / 2);
    final HistogramColumn histogramColumn = createHistogramColumn();
    HiLiteHandler hlHandler = getEnableHiLite().getBooleanValue() ? getInHiLiteHandler(0) : new HiLiteHandler();
    double[] mins = getStatTable().getMin(), maxes = getStatTable().getMax(), means = getStatTable().getMean();
    for (int i = 0; i < maxes.length; i++) {
        DataCell min = getStatTable().getNonInfMin(i);
        if (min.isMissing()) {
            mins[i] = Double.NaN;
        } else {
            mins[i] = ((DoubleValue) min).getDoubleValue();
        }
        DataCell max = getStatTable().getNonInfMax(i);
        if (max.isMissing()) {
            maxes[i] = Double.NaN;
        } else {
            maxes[i] = ((DoubleValue) max).getDoubleValue();
        }
    }
    Pair<BufferedDataTable, Map<Integer, ? extends HistogramModel<?>>> pair = histogramColumn.process(histogram, inData[0], hlHandler, ret[0], mins, maxes, means, numOfNominalValues(), getColumnNames());
    // final BufferedDataTable outTable =
    // histogramColumn.appendNominal(pair.getFirst(), getStatTable(), hlHandler, exec, numOfNominalValues());
    ret[0] = pair.getFirst();
    ret[1] = histogramColumn.nominalTable(getStatTable(), hlHandler, exec, numOfNominalValues());
    if (m_enableHiLite.getBooleanValue()) {
        double rest = 1 - initPercent * 2 - 1.0 / 2;
        ExecutionContext projection = exec.createSubExecutionContext(rest / 2);
        ColumnRearranger rearranger = new ColumnRearranger(dataSpec);
        Set<String> colNames = new HashSet<String>(Arrays.asList(getColumnNames()));
        for (DataColumnSpec spec : rearranger.createSpec()) {
            if ((!spec.getType().isCompatible(DoubleValue.class) && !spec.getType().isCompatible(NominalValue.class)) || !colNames.contains(spec.getName())) {
                rearranger.remove(spec.getName());
            }
        }
        ExecutionContext save = exec.createSubExecutionContext(rest / 2);
        m_subTable = new DefaultDataArray(projection.createColumnRearrangeTable(inData[0], rearranger, projection), 1, inData[0].getRowCount(), save);
        m_histograms = histogramColumn.histograms(inData[0], getInHiLiteHandler(0), mins, maxes, means, getColumnNames());
        Set<String> nominalColumns = new LinkedHashSet<String>();
        for (int i = 0; i < inData[0].getSpec().getNumColumns(); ++i) {
            Map<DataCell, Integer> nominalValues = getStatTable().getNominalValues(i);
            if (nominalValues != null) {
                nominalColumns.add(inData[0].getSpec().getColumnSpec(i).getName());
            }
        }
        final Pair<Map<Integer, Map<Integer, Set<RowKey>>>, Map<Integer, Map<DataValue, Set<RowKey>>>> bucketsAndNominals = HistogramColumn.construct(m_histograms, m_subTable, nominalColumns);
        m_buckets = bucketsAndNominals.getFirst();
        m_nominalKeys = bucketsAndNominals.getSecond();
    } else {
        m_histograms = pair.getSecond();
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) DataValue(org.knime.core.data.DataValue) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) HistogramColumn(org.knime.base.data.statistics.HistogramColumn) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HistogramModel(org.knime.base.data.statistics.HistogramModel) SettingsModelInteger(org.knime.core.node.defaultnodesettings.SettingsModelInteger) ExecutionContext(org.knime.core.node.ExecutionContext) Statistics3Table(org.knime.base.data.statistics.Statistics3Table) DataCell(org.knime.core.data.DataCell) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with HiLiteHandler

use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.

the class HiLiteCollectorNodeModel method appendAnnotation.

/**
 * Appends new annotation.
 * @param anno the annotation to append to the current hilit keys
 * @param newColumn true, a new column is created at the end of the table
 *                  holding the current annotation
 */
final void appendAnnotation(final String anno, final boolean newColumn) {
    HiLiteHandler hdl = getInHiLiteHandler(0);
    if (hdl == null || hdl.getHiLitKeys().isEmpty()) {
        return;
    }
    if (m_lastIndex == null) {
        m_lastIndex = 0;
    } else if (newColumn) {
        m_lastIndex++;
    }
    for (RowKey key : hdl.getHiLitKeys()) {
        Map<Integer, String> list = m_annotationMap.get(key);
        if (list == null) {
            list = new LinkedHashMap<Integer, String>();
            list.put(m_lastIndex, anno);
        } else {
            String str = list.get(m_lastIndex);
            if (str == null) {
                list.put(m_lastIndex, anno);
            } else if (!str.contains(anno)) {
                list.put(m_lastIndex, str + "," + anno);
            }
        }
        m_annotationMap.put(key, list);
    }
    notifyViews(null);
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey)

Example 30 with HiLiteHandler

use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.

the class HiLiteCollectorNodeModel method getHiLiteAnnotationsTable.

/**
 * @return table with hilit rows first and then all rows with annotations
 */
DataTable getHiLiteAnnotationsTable() {
    DataContainer buf;
    if (m_annotationMap.isEmpty()) {
        buf = new DataContainer(new DataTableSpec());
    } else {
        buf = new DataContainer(new DataTableSpec(createSpecs(null)));
    }
    HiLiteHandler hdl = getInHiLiteHandler(0);
    if (hdl != null) {
        for (RowKey key : hdl.getHiLitKeys()) {
            DataCell[] cells = new DataCell[buf.getTableSpec().getNumColumns()];
            for (int i = 0; i < cells.length; i++) {
                Map<Integer, String> map = m_annotationMap.get(key);
                if (map == null) {
                    cells[i] = DataType.getMissingCell();
                } else {
                    String str = m_annotationMap.get(key).get(i);
                    if (str == null) {
                        cells[i] = DataType.getMissingCell();
                    } else {
                        cells[i] = new StringCell(str);
                    }
                }
            }
            buf.addRowToTable(new DefaultRow(key, cells));
        }
        for (RowKey key : m_annotationMap.keySet()) {
            if (!hdl.isHiLit(key)) {
                DataCell[] cells = new DataCell[buf.getTableSpec().getNumColumns()];
                for (int i = 0; i < cells.length; i++) {
                    String str = m_annotationMap.get(key).get(i);
                    if (str == null) {
                        cells[i] = DataType.getMissingCell();
                    } else {
                        cells[i] = new StringCell(str);
                    }
                }
                buf.addRowToTable(new DefaultRow(key, cells));
            }
        }
    }
    buf.close();
    return buf.getTable();
}
Also used : DataContainer(org.knime.core.data.container.DataContainer) DataTableSpec(org.knime.core.data.DataTableSpec) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)31 RowKey (org.knime.core.data.RowKey)11 HashSet (java.util.HashSet)7 DataTableSpec (org.knime.core.data.DataTableSpec)4 LinkedList (java.util.LinkedList)3 JTable (javax.swing.JTable)3 ListSelectionModel (javax.swing.ListSelectionModel)3 SpinnerNumberModel (javax.swing.SpinnerNumberModel)3 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)3 DataCell (org.knime.core.data.DataCell)3 DataRow (org.knime.core.data.DataRow)3 DataTable (org.knime.core.data.DataTable)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 NodeModel (org.knime.core.node.NodeModel)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 TreeEnsembleModel (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModel)2 AbstractPlotter (org.knime.base.node.viz.plotter.AbstractPlotter)2