Search in sources :

Example 1 with FileLocaleBooleanTableModel

use of de.alpharogroup.bundle.app.table.model.FileLocaleBooleanTableModel in project bundle-app-ui by astrapi69.

the class ImportProgressPanel method onInitializeComponents.

@Override
protected void onInitializeComponents() {
    super.onInitializeComponents();
    lblWelcomeImportHeader = new javax.swing.JLabel();
    prbImport = new javax.swing.JProgressBar();
    scrFoundProperties = new javax.swing.JScrollPane();
    lblFoundProperties = new javax.swing.JLabel();
    lblWelcomeImportHeader.setText("Progress of Import ");
    tableModel = new FileLocaleBooleanTableModel();
    tableModel.addList(getTableModelList());
    tblFoundProperties = new GenericJXTable<>(tableModel);
    scrFoundProperties.setViewportView(tblFoundProperties);
    lblFoundProperties.setText("Found properties");
    final TableColumn valueColumn = tblFoundProperties.getColumn("Action");
    valueColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            if (isSelected) {
                setForeground(newSelectionForeground(table));
                setBackground(newSelectionBackround(table));
            } else {
                setForeground(newForeground(table));
                setBackground(newBackround(table));
            }
            final KeyValuePair<Boolean, File> selectedPropertiesFile = (KeyValuePair<Boolean, File>) value;
            final String text;
            if (selectedPropertiesFile.getKey()) {
                text = "Exclude";
            } else {
                text = "Include";
            }
            setText(text);
            return this;
        }
    });
    valueColumn.setCellEditor(new TableCellCheckboxEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public Object getCellEditorValue() {
            final KeyValuePair<Boolean, File> selectedPropertiesFile = (KeyValuePair<Boolean, File>) this.getValue();
            selectedPropertiesFile.setKey(!selectedPropertiesFile.getKey());
            ConvertExtensions.update(selectedPropertiesFile, tableModelList);
            final String text;
            if (selectedPropertiesFile.getKey()) {
                text = "Include";
            } else {
                text = "Exclude";
            }
            return text;
        }

        @SuppressWarnings("unchecked")
        @Override
        public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
            setRow(row);
            setColumn(column);
            setValue(value);
            if (isSelected) {
                getButton().setForeground(table.getSelectionForeground());
                getButton().setBackground(table.getSelectionBackground());
            } else {
                getButton().setForeground(table.getForeground());
                getButton().setBackground(table.getBackground());
            }
            final KeyValuePair<Boolean, File> selectedPropertiesFile = (KeyValuePair<Boolean, File>) this.getValue();
            final String text;
            if (selectedPropertiesFile.getKey()) {
                text = "Include";
            } else {
                text = "Exclude";
            }
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
}
Also used : KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) TableColumn(javax.swing.table.TableColumn) JCheckBox(javax.swing.JCheckBox) TableCellButtonRenderer(de.alpharogroup.swing.renderer.TableCellButtonRenderer) JTable(javax.swing.JTable) FileLocaleBooleanTableModel(de.alpharogroup.bundle.app.table.model.FileLocaleBooleanTableModel) EventObject(de.alpharogroup.design.pattern.observer.event.EventObject) Component(java.awt.Component) File(java.io.File) TableCellCheckboxEditor(de.alpharogroup.bundle.app.radio.TableCellCheckboxEditor)

Aggregations

TableCellCheckboxEditor (de.alpharogroup.bundle.app.radio.TableCellCheckboxEditor)1 FileLocaleBooleanTableModel (de.alpharogroup.bundle.app.table.model.FileLocaleBooleanTableModel)1 KeyValuePair (de.alpharogroup.collections.pairs.KeyValuePair)1 EventObject (de.alpharogroup.design.pattern.observer.event.EventObject)1 TableCellButtonRenderer (de.alpharogroup.swing.renderer.TableCellButtonRenderer)1 Component (java.awt.Component)1 File (java.io.File)1 JCheckBox (javax.swing.JCheckBox)1 JTable (javax.swing.JTable)1 TableColumn (javax.swing.table.TableColumn)1