Example usage for javax.swing.table TableColumn getIdentifier

List of usage examples for javax.swing.table TableColumn getIdentifier

Introduction

In this page you can find the example usage for javax.swing.table TableColumn getIdentifier.

Prototype

public Object getIdentifier() 

Source Link

Document

Returns the identifier object for this column.

Usage

From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java

@Override
public void apply(Element element, boolean sortable) {
    String horizontalScroll = element.attributeValue("horizontalScroll");
    if (!StringUtils.isBlank(horizontalScroll)) {
        table.setHorizontalScrollEnabled(Boolean.valueOf(horizontalScroll));
    }// w  ww  .  ja  va2s . co m

    loadFontPreferences(element);

    final Element columnsElem = element.element("columns");
    if (columnsElem == null) {
        return;
    }

    Collection<String> modelIds = new LinkedList<>();
    for (TableColumn modelColumn : table.getColumns(true)) {
        modelIds.add(String.valueOf(modelColumn.getIdentifier()));
    }

    Collection<String> loadedIds = new LinkedList<>();
    for (Element colElem : Dom4j.elements(columnsElem, "column")) {
        String id = colElem.attributeValue("id");
        loadedIds.add(id);
    }

    Configuration configuration = AppBeans.get(Configuration.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);

    if (clientConfig.getLoadObsoleteSettingsForTable()
            || CollectionUtils.isEqualCollection(modelIds, loadedIds)) {
        applyColumnSettings(element, sortable);
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java

@Override
public boolean saveSettings(Element element) {
    element.addAttribute("horizontalScroll", String.valueOf(table.isHorizontalScrollEnabled()));

    saveFontPreferences(element);/*from   w  ww . j  a va  2s  .  co  m*/

    Element columnsElem = element.element("columns");
    if (columnsElem != null) {
        element.remove(columnsElem);
    }
    columnsElem = element.addElement("columns");

    final List<TableColumn> visibleTableColumns = table.getColumns();
    final List<Table.Column> visibleColumns = new ArrayList<>();
    for (TableColumn tableColumn : visibleTableColumns) {
        visibleColumns.add((Table.Column) tableColumn.getIdentifier());
    }

    List<TableColumn> columns = table.getColumns(true);
    Collections.sort(columns, new Comparator<TableColumn>() {
        @SuppressWarnings("SuspiciousMethodCalls")
        @Override
        public int compare(TableColumn col1, TableColumn col2) {
            if (col1 instanceof TableColumnExt && !((TableColumnExt) col1).isVisible()) {
                return 1;
            }
            if (col2 instanceof TableColumnExt && !((TableColumnExt) col2).isVisible()) {
                return -1;
            }
            int i1 = visibleColumns.indexOf(col1.getIdentifier());
            int i2 = visibleColumns.indexOf(col2.getIdentifier());
            return Integer.compare(i1, i2);
        }
    });

    for (TableColumn column : columns) {
        Element colElem = columnsElem.addElement("column");
        colElem.addAttribute("id", column.getIdentifier().toString());

        int width = column.getWidth();
        colElem.addAttribute("width", String.valueOf(width));

        if (column instanceof TableColumnExt) {
            Boolean visible = ((TableColumnExt) column).isVisible();
            colElem.addAttribute("visible", visible.toString());
        }
    }

    if (table.getRowSorter() != null) {
        TableColumn sortedColumn = table.getSortedColumn();
        List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
        if (sortedColumn != null && !sortKeys.isEmpty()) {
            columnsElem.addAttribute("sortColumn", String.valueOf(sortedColumn.getIdentifier()));
            columnsElem.addAttribute("sortOrder", sortKeys.get(0).getSortOrder().toString());
        }
    }

    return true;
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

public void restoreColumnPreferences() {
    try {/*from  w  w w  . j  a  v  a 2s.  c o  m*/
        if (StringUtils.isNotEmpty(prefix)) {
            TableColumnModelExt columnModel = (TableColumnModelExt) getColumnModel();
            TreeMap<Integer, Integer> columnOrder = new TreeMap<Integer, Integer>();

            int columnIndex = 0;
            for (TableColumn column : columnModel.getColumns(true)) {
                String columnName = (String) column.getIdentifier();
                Integer viewIndex = columnOrderMap.get(columnName);
                TableColumnExt columnExt = getColumnExt(columnName);

                boolean visible = false;
                if (viewIndex == null) {
                    visible = defaultVisibleColumns == null || defaultVisibleColumns.contains(columnName);
                } else {
                    visible = viewIndex > -1;
                }

                columnExt.setVisible(visible);
                if (viewIndex != null && viewIndex > -1) {
                    columnOrder.put(viewIndex, columnIndex);
                }

                columnIndex++;
            }

            int viewIndex = 0;
            for (int index : columnOrder.values()) {
                columnModel.moveColumn(convertColumnIndexToView(index), viewIndex++);
            }

            if (sortKeys != null && !sortKeys.isEmpty()) {
                getRowSorter().setSortKeys(sortKeys);
            }
        }
    } catch (Exception e) {
        restoreDefaultColumnPreferences();
    }
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public int getColumnViewIndex(String columnName) {
    int viewIndex = -1;

    for (TableColumn column : getColumns()) {
        if (columnName.equals(column.getIdentifier())) {
            viewIndex = this.getColumnModel().getColumnIndex(columnName);
        }//from w w w . ja  va  2s  . c o  m
    }

    return viewIndex;
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public void restoreColumnPreferences() {
    if (StringUtils.isNotEmpty(prefix)) {
        try {//from  www  .  ja v  a2s .  c  om
            TableColumnModelExt columnModel = (TableColumnModelExt) getTableHeader().getColumnModel();
            TreeMap<Integer, Integer> columnOrder = new TreeMap<Integer, Integer>();

            int columnIndex = 0;
            for (TableColumn column : columnModel.getColumns(true)) {
                String columnName = (String) column.getIdentifier();
                Integer viewIndex = columnOrderMap.get(columnName);
                TableColumnExt columnExt = getColumnExt(columnName);

                boolean visible = false;
                if (viewIndex == null) {
                    visible = defaultVisibleColumns == null || defaultVisibleColumns.contains(columnName);
                } else {
                    visible = viewIndex > -1;
                }

                columnExt.setVisible(visible);
                if (viewIndex != null && viewIndex > -1) {
                    columnOrder.put(viewIndex, columnIndex);
                }

                columnIndex++;
            }

            int viewIndex = 0;
            for (int index : columnOrder.values()) {
                columnModel.moveColumn(convertColumnIndexToView(index), viewIndex++);
            }

            // MetaDataColumns are restored here by comparing them against the customHiddenColumnMap which contains a list of all columns that should be hidden
            if (CollectionUtils.isNotEmpty(metaDataColumns)) {
                Set<String> cachedColumns = customHiddenColumnMap.get(channelId);

                if (cachedColumns != null) {
                    for (String column : metaDataColumns) {
                        getColumnExt(column).setVisible(!cachedColumns.contains(column));
                    }
                }
            }

            // After restoring column order, restore sort order
            SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel();
            if (sortOrderColumn > -1 && sortOrderColumn < model.getColumnCount()) {
                model.setColumnAndToggleSortOrder(sortOrderColumn);
                model.setSortOrder(sortOrder);

                // Update sorting Icons
                ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()).setSortingIcon(sortOrder);
                ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer())
                        .setColumnIndex(sortOrderColumn);
            }
        } catch (Exception e) {
            restoreDefaultColumnPreferences();
        }
    }
}

From source file:edu.ku.brc.ui.tmanfe.SearchReplacePanel.java

/**
 * @return true if replace operation can proceed.
 * // w ww .  j  av  a2  s  . c  om
 */
protected boolean canReplace() {
    TableColumn sortedColumn = table.getSortedColumn();
    if (sortedColumn != null) {
        if (isSearchSelection()) {
            int[] selCols = table.getSelectedColumns();
            int sortCol = table.getColumnModel().getColumnIndex(sortedColumn.getIdentifier());
            for (int c = 0; c < selCols.length; c++) {
                if (selCols[c] == sortCol) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
    return true;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected TableColumn getColumn(Column column) {
    List<TableColumn> tableColumns = getAllColumns();

    for (TableColumn tableColumn : tableColumns) {
        if (column.equals(tableColumn.getIdentifier())) {
            return tableColumn;
        }//w w  w . j  av a2  s  . c  o m
    }

    return null;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected boolean isCustomCellEditable(int row, int column) {
    TableColumn tableColumn = impl.getColumnModel().getColumn(column);
    if (tableColumn.getIdentifier() instanceof Table.Column) {
        Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
        if (columnConf.getId() instanceof MetaPropertyPath && !getTableModel().isGeneratedColumn(columnConf)) {
            return isCustomCellEditable(tableModel.getItem(row), (MetaPropertyPath) columnConf.getId());
        }//from   www . j  a  va 2s. c  o m
    }
    return false;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected TableCellEditor getCellEditor(int row, int column) {

    TableColumn tableColumn = impl.getColumnModel().getColumn(column);
    if (tableColumn.getIdentifier() instanceof Column) {
        Column columnConf = (Column) tableColumn.getIdentifier();

        if (editableColumns != null && columnConf.getId() instanceof MetaPropertyPath
                && editableColumns.contains(columnConf.getId())) {

            return tableFieldFactory.createEditComponent(row, columnConf);
        }//  ww  w.  jav a 2s  .com
    }

    return null;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected TableCellEditor getColumnEditor(int column) {
    TableColumn tableColumn = impl.getColumnModel().getColumn(column);
    if (tableColumn.getIdentifier() instanceof Table.Column) {
        Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();

        if (columnConf.getId() instanceof MetaPropertyPath && !(isEditable() && columnConf.isEditable())
                && !getTableModel().isGeneratedColumn(columnConf)) {
            MetaPropertyPath propertyPath = (MetaPropertyPath) columnConf.getId();

            final CellProvider cellProvider = getCustomCellEditor(propertyPath);
            if (cellProvider != null) {
                return new CellProviderEditor(cellProvider);
            }/*from   w w w.j a v  a 2s .c o m*/
        }
    }
    return null;
}