Search in sources :

Example 6 with HiLiteHandler

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

the class TreeEnsembleLearnerNodeView method modelChangedInUI.

private void modelChangedInUI() {
    assert SwingUtilities.isEventDispatchThread();
    final MODEL nodeModel = getNodeModel();
    TreeEnsembleModel ensembleModel = nodeModel.getEnsembleModel();
    int nrModels = ensembleModel == null ? 0 : ensembleModel.getNrModels();
    m_nrModelLabel.setText(nrModels + " model(s) in total");
    int min = nrModels == 0 ? 0 : 1;
    m_modelSpinner.setModel(new SpinnerNumberModel(min, min, nrModels, 1));
    HiLiteHandler hdl = nodeModel.getInHiLiteHandler(0);
    String warnMessage = nodeModel.getViewMessage();
    if (warnMessage == null) {
        m_warningLabel.setText(" ");
        m_warningLabel.setVisible(false);
    } else {
        m_warningLabel.setText(warnMessage);
        m_warningLabel.setVisible(true);
    }
    newHiliteHandler(hdl);
    newModel(min - 1);
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) TreeEnsembleModel(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler)

Example 7 with HiLiteHandler

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

the class TableContentModelTest method testHilite.

/**
 * Method being tested: hiLite(ListSelectionModel) and
 *         (implicitly) hiLite(KeyEvent).
 */
public final void testHilite() {
    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);
    // the hilite handler
    for (int i = 0; i < OBJECT_DATA.length; i += 2) {
        listModel.addSelectionInterval(i, i);
    }
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeHiLit = (i % 2 == 0);
        boolean isHiLit = m.isHiLit(i);
        assertEquals(shouldBeHiLit, isHiLit);
    }
    // add every third row to the selection.
    for (int i = 0; i < OBJECT_DATA.length; i += 3) {
        listModel.addSelectionInterval(i, i);
    }
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeHiLit = (i % 2 == 0) || (i % 3 == 0);
        boolean isHiLit = m.isHiLit(i);
        assertEquals(shouldBeHiLit, isHiLit);
    }
    // clearing the selection shouldn't have any effect
    listModel.clearSelection();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeHiLit = (i % 2 == 0) || (i % 3 == 0);
        boolean isHiLit = m.isHiLit(i);
        assertEquals(shouldBeHiLit, isHiLit);
    }
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertTrue(m.isHiLit(i));
    }
    try {
        m.requestHiLite((ListSelectionModel) null);
        fail("Expected " + NullPointerException.class + " not thrown");
    } catch (NullPointerException e) {
        NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass().getName(), e);
    }
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel)

Example 8 with HiLiteHandler

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

the class TableContentModelTest method testTableContentModelDataTableHiLiteHandler.

// testTableContentModelDataTable()
/**
 * Class under test for void TableContentModel(DataTable, HiLiteHandler).
 */
public final void testTableContentModelDataTableHiLiteHandler() {
    HiLiteHandler handler = new HiLiteHandler();
    final TableContentModel m2 = new TableContentModel(DATA, handler);
    assertEquals("Col Count", m2.getColumnCount(), OBJECT_DATA[0].length);
    assertTrue("Has Data", m2.hasData());
    assertTrue("Has HiLiteHandler", m2.hasHiLiteHandler());
    final TableContentModel m3 = new TableContentModel(null, handler);
    assertFalse("Has Data", m3.hasData());
    assertTrue("Has HiLiteHandler", m3.hasHiLiteHandler());
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler)

Example 9 with HiLiteHandler

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

the class TableContentModelTest method testIsHiLit.

/**
 * Method being tested: boolean isHiLit(int).
 */
public final void testIsHiLit() {
    final HiLiteHandler hiliteHdl = new HiLiteHandler();
    final TableContentModel m = new TableContentModel(DATA, hiliteHdl);
    // hilite every other in DATA and check if it is correctly reflected
    // in m
    final HashSet<RowKey> set = new HashSet<RowKey>();
    boolean isEvenNumber = true;
    for (RowIterator it = DATA.iterator(); it.hasNext(); ) {
        RowKey cell = it.next().getKey();
        if (isEvenNumber) {
            hiliteHdl.fireHiLiteEvent(cell);
            set.add(cell);
        }
        isEvenNumber = !isEvenNumber;
    }
    flushEDTQueue();
    for (int i = 0; i < m.getRowCount(); i++) {
        RowKey key = m.getRow(i).getKey();
        boolean isHiLit = m.isHiLit(i);
        assertEquals(set.contains(key), isHiLit);
    }
    try {
        m.isHiLit(-1);
        fail("Expected " + IndexOutOfBoundsException.class + " not thrown");
    } catch (IndexOutOfBoundsException e) {
        NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass().getName(), e);
    }
    try {
        m.isHiLit(OBJECT_DATA.length);
        fail("Expected " + IndexOutOfBoundsException.class + " not thrown");
    } catch (IndexOutOfBoundsException e) {
        NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass().getName(), e);
    }
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey) RowIterator(org.knime.core.data.RowIterator) DefaultRowIterator(org.knime.core.data.def.DefaultRowIterator) HashSet(java.util.HashSet)

Example 10 with HiLiteHandler

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

the class TableContentModelTest method testUnHilite.

// testHilite()
/**
 * Method being tested: unHiLite(ListSelectionModel)
 *         (implicitly) unHiLite(KeyEvent).
 */
public final void testUnHilite() {
    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; unhilite subsequently
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertTrue(m.isHiLit(i));
    }
    listModel.clearSelection();
    // the hilite handler
    for (int i = 0; i < OBJECT_DATA.length; i += 2) {
        listModel.addSelectionInterval(i, i);
    }
    m.requestUnHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeUnHiLit = (i % 2 == 0);
        boolean isUnHiLit = !m.isHiLit(i);
        assertEquals(shouldBeUnHiLit, isUnHiLit);
    }
    // remove every third row from the selection.
    for (int i = 0; i < OBJECT_DATA.length; i += 3) {
        listModel.addSelectionInterval(i, i);
    }
    m.requestUnHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeUnHiLit = (i % 2 == 0) || (i % 3 == 0);
        boolean isUnHiLit = !m.isHiLit(i);
        assertEquals(shouldBeUnHiLit, isUnHiLit);
    }
    // clearing the selection shouldn't have any effect
    listModel.clearSelection();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        boolean shouldBeUnHiLit = (i % 2 == 0) || (i % 3 == 0);
        boolean isUnHiLit = !m.isHiLit(i);
        assertEquals(shouldBeUnHiLit, isUnHiLit);
    }
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestUnHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertFalse(m.isHiLit(i));
    }
    try {
        m.requestUnHiLite((ListSelectionModel) null);
        fail("Expected " + NullPointerException.class + " not thrown");
    } catch (NullPointerException e) {
        NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass().getName(), e);
    }
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel)

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