Search in sources :

Example 11 with IColumn

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

the class AbstractTable method execCopy.

/**
 * Called by a <code>CTRL-C</code> event on the table to copy the given rows into the clipboard.
 * <p>
 * Subclasses can override this method. The default creates a {@link TextTransferObject} of the table content (HTML
 * table).
 *
 * @param rows
 *          The selected table rows to copy.
 * @return A transferable object representing the given rows or null to not populate the clipboard.
 */
@ConfigOperation
@Order(30)
protected TransferObject execCopy(List<? extends ITableRow> rows) {
    if (!CollectionUtility.hasElements(rows)) {
        return null;
    }
    StringBuilder plainText = new StringBuilder();
    List<IColumn<?>> columns = getColumnSet().getVisibleColumns();
    boolean firstRow = true;
    for (ITableRow row : rows) {
        appendCopyTextForRow(plainText, row, firstRow, columns);
        firstRow = false;
    }
    TextTransferObject transferObject = new TextTransferObject(plainText.toString());
    return transferObject;
}
Also used : TextTransferObject(org.eclipse.scout.rt.client.ui.dnd.TextTransferObject) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 12 with IColumn

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

the class ColumnSet method setVisibleColumns.

/**
 * set visible columns and put them in specific order
 */
public void setVisibleColumns(Collection<? extends IColumn> columns) {
    try {
        m_table.setTableChanging(true);
        // 
        List<IColumn<?>> resolvedColumns = resolveColumns(columns);
        if (columns == null) {
            columns = CollectionUtility.hashSet();
        }
        if (resolvedColumns.size() > 0 || columns.size() == 0) {
            List<IColumn<?>> newColumns = new ArrayList<IColumn<?>>();
            for (IColumn col : columns) {
                if (col.isDisplayable()) {
                    // sanity check
                    if (col.getInitialWidth() == 0 && col.getWidth() == 0) {
                        col.setInitialWidth(60);
                        col.setWidth(60);
                    }
                    newColumns.add(col);
                }
            }
            int viewHint = 0;
            int nextNewIndex = 0;
            for (IColumn col : getAllColumnsInUserOrder()) {
                if (newColumns.contains(col)) {
                    // use next in list since the list is pre-ordered
                    IColumn nextSortedCol = newColumns.get(nextNewIndex);
                    nextNewIndex++;
                    nextSortedCol.setVisible(true);
                    nextSortedCol.setVisibleColumnIndexHint(viewHint);
                } else {
                    col.setVisible(false);
                    col.setVisibleColumnIndexHint(viewHint);
                }
                viewHint++;
            }
            reorganizeIndexes();
            List<IColumn<?>> displayableColumns = getDisplayableColumns();
            for (IColumn col : displayableColumns) {
                rebuildHeaderCell(col);
            }
            fireColumnHeadersUpdated(displayableColumns);
            fireColumnStructureChanged();
            checkMultiline();
        }
    } finally {
        m_table.setTableChanging(false);
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList)

Example 13 with IColumn

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

the class ColumnSet method setSortSpec.

public void setSortSpec(SortSpec spec) {
    if (spec != null) {
        for (IColumn col : m_userSortColumns) {
            HeaderCell cell = (HeaderCell) col.getHeaderCell();
            cell.setSortActive(false);
            cell.setSortAscending(false);
        }
        m_userSortColumns.clear();
        List<IColumn<?>> colList = new ArrayList<IColumn<?>>();
        for (int i = 0; i < spec.size(); i++) {
            IColumn col = getColumn(spec.getColumnIndex(i));
            if (col != null && (!isSortColumn(col))) {
                HeaderCell cell = (HeaderCell) col.getHeaderCell();
                cell.setSortActive(true);
                cell.setSortAscending(spec.isColumnAscending(i));
                colList.add(col);
            }
        }
        m_userSortColumns.addAll(colList);
        for (IColumn col : colList) {
            rebuildHeaderCell(col);
        }
        fireColumnHeadersUpdated(colList);
    } else {
        clearSortColumns();
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList)

Example 14 with IColumn

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

the class ColumnSet method initialize.

public void initialize() {
    ClientUIPreferences prefs = ClientUIPreferences.getInstance();
    // clean up visible column index hints, make as permutation of model indices
    int n = getColumnCount();
    TreeMap<CompositeObject, IColumn> sortMap = new TreeMap<CompositeObject, IColumn>();
    int viewIndex = 0;
    for (int modelIndex = 0; modelIndex < n; modelIndex++) {
        IColumn col = getColumn(modelIndex);
        double viewHint = col.getVisibleColumnIndexHint();
        if (viewHint < 0) {
            viewHint = col.getOrder();
        }
        if (viewHint < 0) {
            viewHint = viewIndex;
        }
        sortMap.put(new CompositeObject(viewHint, viewIndex), col);
        // next
        viewIndex++;
    }
    viewIndex = 0;
    for (Map.Entry<CompositeObject, IColumn> e : sortMap.entrySet()) {
        e.getValue().setVisibleColumnIndexHint(viewIndex);
        viewIndex++;
    }
    reorganizeIndexes();
    applySortingAndGrouping(null);
    /*
     * ticket 93309
     * sanity check: when there is no visible column at all, reset visibilities to model init defaults
     */
    if (getVisibleColumnCount() == 0) {
        viewIndex = 0;
        for (IColumn c : getColumns()) {
            if (c.isDisplayable() && c.isInitialVisible()) {
                c.setVisible(true);
            } else {
                c.setVisible(false);
            }
            c.setWidth(c.getInitialWidth());
            c.setVisibleColumnIndexHint(viewIndex);
            prefs.removeAllTableColumnPreferences(c, null, true);
            // next
            viewIndex++;
        }
        reorganizeIndexes();
    }
    checkMultiline();
}
Also used : CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ClientUIPreferences(org.eclipse.scout.rt.client.ui.ClientUIPreferences) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 15 with IColumn

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

the class ColumnSet method handleSortEvent.

/*
   * Sorting and Grouping
   */
/**
 * @param col
 * @param multiSort
 *          True: Multiple sort columns are supported, which means the given column is added to the list of sort
 *          columns, if not added yet.<br>
 *          False: The selected column is set as the (new) primary sort column.<br>
 * @param ascending
 *          Specifies the new sort direction
 */
public void handleSortEvent(IColumn col, boolean multiSort, boolean ascending) {
    col = resolveColumn(col);
    if (col == null) {
        return;
    }
    // 
    try {
        m_table.setTableChanging(true);
        // 
        if (multiSort) {
            if (isSortColumn(col)) {
                updateSortColumn(col, ascending);
            } else {
                addSortColumn(col, ascending);
            }
        } else {
            for (IColumn c : m_userSortColumns) {
                if (c != col) {
                    ((HeaderCell) c.getHeaderCell()).setGroupingActive(false);
                }
            }
            if (isSortColumn(col) && getSortColumnCount() == 1) {
                updateSortColumn(col, ascending);
            } else {
                setSortColumn(col, ascending);
                ((HeaderCell) col.getHeaderCell()).setGroupingActive(false);
            }
        }
    } finally {
        m_table.setTableChanging(false);
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)

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