use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.
the class TableContentModel method setHiLiteHandler.
/**
* Set a new <code>HiLiteHandler</code>. If the argument is
* <code>null</code> hiliting is disabled.
*
* @param hiliter the new handler to use.
*/
public synchronized void setHiLiteHandler(final HiLiteHandler hiliter) {
// nothing has changed, we come away easy
if (hiliter == m_hiLiteHdl) {
return;
}
HiLiteHandler oldHandler = m_hiLiteHdl;
if (m_hiLiteHdl != null) {
// unregister from old handler
m_hiLiteHdl.removeHiLiteListener(this);
}
m_hiLiteHdl = hiliter;
if (hiliter != null) {
// register at new one
hiliter.addHiLiteListener(this);
}
// check for rows whose hilite status has changed
if (hasData()) {
if (m_tableFilter.performsFiltering()) {
m_isRowCountOfInterestFinal = false;
m_rowCountOfInterest = 0;
clearCache();
cacheNextRow();
fireTableDataChanged();
} else {
final int cacheSize = getCacheSize();
// init with nonsense values - will change soon
final int firstRowCached = firstRowCached();
// remember first and last changed index
int firstRow = -1;
int lastRow = -1;
// traverse all rows in cache and check if some are hilighted
for (int i = 0; i < cacheSize; i++) {
final int indexInCache = (firstRowCached + i) % cacheSize;
final DataRow current = indexInCache >= 0 ? m_cachedRows[indexInCache] : null;
if (current == null) {
// everything after is also null
break;
}
final RowKey key = current.getKey();
// do the hilite sync
final boolean wasHiLit = m_hilitSet.get(indexInCache);
final boolean isHiLit = (hiliter != null ? hiliter.isHiLit(key) : false);
// either hilite or color changed
if (wasHiLit != isHiLit) {
if (firstRow == -1) {
firstRow = indexInCache;
}
lastRow = indexInCache;
m_hilitSet.set(indexInCache, isHiLit);
}
}
// will swallow the event when firstRow > lastRow
fireRowsInCacheUpdated(firstRow, lastRow);
}
}
m_propertySupport.firePropertyChange(PROPERTY_HILITE, oldHandler, m_hiLiteHdl);
}
use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.
the class InteractiveHiLiteCollectorNodeModel method getHiLiteAnnotationsTable.
/**
* @return table with hilit rows first and then all rows with annotations
*/
DataTable getHiLiteAnnotationsTable() {
// return null if not executed
if (m_data == null) {
return null;
}
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();
}
use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.
the class InteractiveHiLiteCollectorNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
protected void modelChanged() {
DataTable data = super.getNodeModel().getHiLiteAnnotationsTable();
m_table.setDataTable(data);
HiLiteHandler hdl = super.getNodeModel().getInHiLiteHandler(0);
m_table.setHiLiteHandler(hdl);
m_table.setColumnWidth(50);
}
use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.
the class TreeEnsembleLearnerNodeView method recreateHiLite.
private void recreateHiLite() {
HiLiteHandler handler = m_hiLiteHdl;
if (handler == null) {
return;
}
Set<RowKey> hilited = handler.getHiLitKeys();
Set<DecisionTreeNode> toHilite = new HashSet<DecisionTreeNode>();
DecisionTreeNode root = m_graph.getRootNode();
List<DecisionTreeNode> toProcess = new LinkedList<DecisionTreeNode>();
if (null != root) {
toProcess.add(0, root);
}
// Traverse the tree breadth first
while (!toProcess.isEmpty()) {
DecisionTreeNode curr = toProcess.remove(0);
// cover any pattern
if (curr.coveredPattern().isEmpty()) {
continue;
}
if (hilited.containsAll(curr.coveredPattern())) {
// hilite subtree starting from curr
toHilite.addAll(getSubtree(curr));
} else {
for (int i = 0; i < curr.getChildCount(); i++) {
toProcess.add(0, curr.getChildAt(i));
}
}
}
m_graph.hiLite(toHilite);
}
use of org.knime.core.node.property.hilite.HiLiteHandler in project knime-core by knime.
the class TableContentModelTest method testShowOnlyHiLited.
// testCachingStrategy()
/**
* Tests the correctness of the model when only hilited are shown.
*/
public final void testShowOnlyHiLited() {
final String[] colnames = new String[] { "C1" };
final DataType[] colclasses = new DataType[] { DoubleCell.TYPE };
final DataRow[] data = new DefaultRow[500];
for (int i = 0; i < data.length; i++) {
data[i] = new DefaultRow(new RowKey("Row_" + i), new double[] { i });
}
// override DataTable to set own iterator
final DataTable table = new DefaultTable(data, colnames, colclasses);
TableContentModel model = new TableContentModel(table);
// change default chunk and cache size
final int chunkSize = 25;
final int cacheSize = 2 * chunkSize;
model.setChunkSize(chunkSize);
assertEquals(model.getChunkSize(), chunkSize);
model.setCacheSize(cacheSize);
assertEquals(model.getCacheSize(), cacheSize);
model.setTableContentFilter(TableContentFilter.HiliteOnly);
assertEquals(model.getRowCount(), 0);
assertTrue(model.isRowCountFinal());
final HiLiteHandler hiliter = new HiLiteHandler();
model.setHiLiteHandler(hiliter);
final Random rand = new Random();
int nrHiLitKeys = 0;
// reflected in the model
for (int i = 0; i < 500; i++) {
if (i % 100 == 0) {
// clear all, also that should work
hiliter.fireClearHiLiteEvent();
flushEDTQueue();
nrHiLitKeys = 0;
} else {
// let at most 20% change
int count = rand.nextInt(data.length / 5);
// change randomly drawn keys
for (int c = 0; c < count; c++) {
int index = rand.nextInt(data.length);
RowKey keyForIndex = data[index].getKey();
boolean isHilit = hiliter.isHiLit(keyForIndex);
if (isHilit) {
hiliter.fireUnHiLiteEvent(keyForIndex);
flushEDTQueue();
nrHiLitKeys--;
} else {
hiliter.fireHiLiteEvent(keyForIndex);
flushEDTQueue();
nrHiLitKeys++;
}
}
}
flushEDTQueue();
// now the sanity checks
for (int row = 0; row < model.getRowCount(); row++) {
RowKey key = model.getRow(row).getKey();
assertTrue(hiliter.isHiLit(key));
assertTrue(model.isHiLit(row));
}
assertEquals(model.getRowCount(), nrHiLitKeys);
assertTrue(model.isRowCountFinal());
}
}
Aggregations