Search in sources :

Example 31 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class AbstractTable method handleKeyStroke.

protected boolean handleKeyStroke(String keyName, char keyChar) {
    if (keyName == null) {
        return false;
    }
    keyName = keyName.toLowerCase();
    // check if there is no menu keystroke with that name
    for (IMenu m : getMenus()) {
        if (m.getKeyStroke() != null && m.getKeyStroke().equalsIgnoreCase(keyName)) {
            return false;
        }
    }
    // check if there is no keystroke with that name (ticket 78234)
    for (IKeyStroke k : getKeyStrokes()) {
        if (k.getKeyStroke() != null && k.getKeyStroke().equalsIgnoreCase(keyName)) {
            return false;
        }
    }
    if (keyChar > ' ' && (!keyName.contains("control")) && (!keyName.contains("ctrl")) && (!keyName.contains("alt"))) {
        // select first/next line with corresponding character
        String newText = "" + Character.toLowerCase(keyChar);
        m_keyStrokeBuffer.append(newText);
        String prefix = m_keyStrokeBuffer.getText();
        IColumn<?> col = getContextColumn();
        if (col == null) {
            List<IColumn<?>> sortCols = getColumnSet().getSortColumns();
            if (sortCols.size() > 0) {
                col = CollectionUtility.lastElement(sortCols);
            } else {
                TreeMap<CompositeObject, IColumn<?>> sortMap = new TreeMap<CompositeObject, IColumn<?>>();
                int index = 0;
                for (IColumn<?> c : getColumnSet().getVisibleColumns()) {
                    if (c.getDataType() == String.class) {
                        sortMap.put(new CompositeObject(1, index), c);
                    } else if (c.getDataType() == Boolean.class) {
                        sortMap.put(new CompositeObject(3, index), c);
                    } else {
                        sortMap.put(new CompositeObject(2, index), c);
                    }
                    index++;
                }
                if (sortMap.size() > 0) {
                    col = sortMap.get(sortMap.firstKey());
                }
            }
        }
        if (col != null) {
            int colIndex = col.getColumnIndex();
            String pattern = StringUtility.toRegExPattern(prefix.toLowerCase());
            pattern = pattern + ".*";
            if (LOG.isInfoEnabled()) {
                LOG.info("finding regex: '{}' in column '{}'", pattern, getColumnSet().getColumn(colIndex).getHeaderCell().getText());
            }
            // loop over values and find matching one
            int rowCount = getRowCount();
            ITableRow selRow = getSelectedRow();
            int startIndex = 0;
            if (selRow != null) {
                if (prefix.length() <= 1) {
                    startIndex = selRow.getRowIndex() + 1;
                } else {
                    startIndex = selRow.getRowIndex();
                }
            }
            for (int i = 0; i < rowCount; i++) {
                ITableRow row = m_rows.get((startIndex + i) % rowCount);
                String text = row.getCell(colIndex).getText();
                if (text != null && text.toLowerCase().matches(pattern)) {
                    // handled
                    selectRow(row, false);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) TreeMap(java.util.TreeMap) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)

Example 32 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class ColumnSet method resetColumnsViewOrder.

private void resetColumnsViewOrder() {
    for (IColumn c : getColumns()) {
        c.setVisibleColumnIndexHint(-1);
    }
    reorganizeIndexes();
    fireColumnOrderChanged();
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)

Example 33 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class ColumnSet method getSortSpec.

public SortSpec getSortSpec() {
    ArrayList<IColumn<?>> sortColumns = new ArrayList<IColumn<?>>();
    for (IColumn c : getSortColumns()) {
        sortColumns.add(c);
    }
    if (sortColumns.size() > 0) {
        int[] indexes = new int[sortColumns.size()];
        boolean[] asc = new boolean[sortColumns.size()];
        for (int i = 0; i < sortColumns.size(); i++) {
            indexes[i] = sortColumns.get(i).getColumnIndex();
            asc[i] = sortColumns.get(i).isSortAscending();
        }
        return new SortSpec(indexes, asc);
    } else {
        return null;
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList) SortSpec(org.eclipse.scout.rt.shared.data.basic.table.SortSpec)

Example 34 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class ColumnSet method moveVisibleColumnToVisibleIndex.

public void moveVisibleColumnToVisibleIndex(int fromVisibleIndex, int toVisibleIndex) {
    if (fromVisibleIndex != toVisibleIndex) {
        IColumn fromCol = getVisibleColumn(fromVisibleIndex);
        IColumn toCol = getVisibleColumn(toVisibleIndex);
        if (fromCol != null && toCol != null) {
            boolean traversedFrom = false;
            ArrayList<IColumn<?>> list = new ArrayList<IColumn<?>>();
            for (IColumn c : getAllColumnsInUserOrder()) {
                if (c == fromCol) {
                    traversedFrom = true;
                // nop
                } else if (c == toCol) {
                    if (traversedFrom) {
                        list.add(c);
                        list.add(fromCol);
                    } else {
                        list.add(fromCol);
                        list.add(c);
                    }
                } else {
                    list.add(c);
                }
            }
            int viewHint = 0;
            for (IColumn c : list) {
                c.setVisibleColumnIndexHint(viewHint);
                viewHint++;
            }
            reorganizeIndexes();
            fireColumnOrderChanged();
        }
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList)

Example 35 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class ColumnSet method clearPermanentTailSortColumns.

public void clearPermanentTailSortColumns() {
    if (m_permanentTailSortColumns.size() == 0) {
        return;
    }
    List<IColumn<?>> currentColumnList = new ArrayList<IColumn<?>>(m_permanentTailSortColumns);
    m_permanentTailSortColumns.clear();
    for (IColumn col : currentColumnList) {
        HeaderCell cell = (HeaderCell) col.getHeaderCell();
        cell.setSortActive(false);
        cell.setSortPermanent(false);
        cell.setGroupingActive(false);
    }
    for (IColumn col : currentColumnList) {
        rebuildHeaderCell(col);
    }
    fireColumnHeadersUpdated(currentColumnList);
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList)

Aggregations

IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)49 ArrayList (java.util.ArrayList)10 TreeMap (java.util.TreeMap)8 CompositeObject (org.eclipse.scout.rt.platform.util.CompositeObject)7 Test (org.junit.Test)6 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)5 JSONObject (org.json.JSONObject)5 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)4 INumberColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn)3 HashMap (java.util.HashMap)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 ClientUIPreferences (org.eclipse.scout.rt.client.ui.ClientUIPreferences)1 IKeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)1