Search in sources :

Example 1 with TableCellButtonRenderer

use of de.alpharogroup.swing.renderer.TableCellButtonRenderer in project bundle-app-ui by astrapi69.

the class OverviewOfAllBundleApplicationsPanel method onInitializeComponents.

@Override
protected void onInitializeComponents() {
    super.onInitializeComponents();
    lblHeaderOverview = new javax.swing.JLabel();
    lblBundleApp = new javax.swing.JLabel();
    srcBundleApps = new javax.swing.JScrollPane();
    tableModel = new StringBundleApplicationsBundleApplicationsTableModel();
    tableModel.addList(getTableModelList());
    tblBundleApps = new GenericJXTable<>(tableModel);
    final TableColumn chooseColumn = tblBundleApps.getColumn("Choose");
    chooseColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @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 String text = "Choose";
            setText(text);
            return this;
        }
    });
    chooseColumn.setCellEditor(new TableCellButtonEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getCellEditorValue() {
            final BundleApplications selectedBundleApplication = (BundleApplications) this.getValue();
            MainFrame.getInstance().setSelectedBundleApplication(selectedBundleApplication);
            final Model<ApplicationDashboardBean> baModel = MainFrame.getInstance().getSelectedBundleApplicationPropertyModel();
            final ApplicationDashboardContentPanel component = new ApplicationDashboardContentPanel(baModel);
            MainFrame.getInstance().replaceInternalFrame("Dashboard of " + selectedBundleApplication.getName() + " bundle app", component);
            final String text = "Select";
            return text;
        }

        @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 String text = "Choose";
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
    final TableColumn deleteColumn = tblBundleApps.getColumn("Delete");
    deleteColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @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 String text = "Delete";
            setText(text);
            return this;
        }
    });
    deleteColumn.setCellEditor(new TableCellButtonEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onClick() {
            try {
                super.onClick();
            } catch (IndexOutOfBoundsException e) {
                e.printStackTrace();
            }
        }

        @Override
        public Object getCellEditorValue() {
            final BundleApplications selectedBundleApplication = (BundleApplications) this.getValue();
            onDelete(selectedBundleApplication);
            final String text = "Delete";
            return text;
        }

        @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 String text = "Delete";
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
    btnCreateBundleApp = new javax.swing.JButton();
    lblHeaderOverview.setText("Overview of all bundle applications");
    lblBundleApp.setText("Bundle application count");
    srcBundleApps.setViewportView(tblBundleApps);
    btnCreateBundleApp.setText("Create new bundle application");
    btnCreateBundleApp.addActionListener(e -> onCreateBundleApp(e));
}
Also used : BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) ApplicationDashboardContentPanel(de.alpharogroup.bundle.app.panels.dashboard.ApplicationDashboardContentPanel) TableColumn(javax.swing.table.TableColumn) JCheckBox(javax.swing.JCheckBox) TableCellButtonEditor(de.alpharogroup.swing.table.editor.TableCellButtonEditor) TableCellButtonRenderer(de.alpharogroup.swing.renderer.TableCellButtonRenderer) JTable(javax.swing.JTable) BaseModel(de.alpharogroup.model.BaseModel) StringBundleApplicationsBundleApplicationsTableModel(de.alpharogroup.bundle.app.table.model.StringBundleApplicationsBundleApplicationsTableModel) PropertyModel(de.alpharogroup.model.PropertyModel) Model(de.alpharogroup.model.api.Model) StringBundleApplicationsBundleApplicationsTableModel(de.alpharogroup.bundle.app.table.model.StringBundleApplicationsBundleApplicationsTableModel) Component(java.awt.Component)

Example 2 with TableCellButtonRenderer

use of de.alpharogroup.swing.renderer.TableCellButtonRenderer in project bundle-app-ui by astrapi69.

the class OverviewResourceBundleAddEntryPanel method onInitializeComponents.

@Override
protected void onInitializeComponents() {
    super.onInitializeComponents();
    lblKey = new javax.swing.JLabel();
    lblHeaderOverview = new javax.swing.JLabel();
    lblValue = new javax.swing.JLabel();
    srcBundles = new javax.swing.JScrollPane();
    tableModel = new StringResourcebundlesTableModel();
    tableModel.addList(getTableModelList());
    tblBundles = new GenericJXTable<>(tableModel);
    btnToDashboard = new javax.swing.JButton();
    btnExport = new javax.swing.JButton();
    btnDelete = new javax.swing.JButton();
    final TableColumn editValueColumn = tblBundles.getColumn("Edit");
    editValueColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @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 String text = "Edit";
            setText(text);
            return this;
        }
    });
    editValueColumn.setCellEditor(new TableCellButtonEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getCellEditorValue() {
            final Resourcebundles selected = (Resourcebundles) this.getValue();
            MainFrame.getInstance().getModelObject().getSelectedBundleApplication().setSelectedResourcebundle(selected);
            txtKey.setText(selected.getKey().getName());
            txtValue.setText(selected.getValue());
            final String text = "Edit";
            return text;
        }

        @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 String text = "Edit";
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
    // ============================================================================================
    final TableColumn deleteValueColumn = tblBundles.getColumn("Delete");
    deleteValueColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @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 String text = "Delete";
            setText(text);
            return this;
        }
    });
    deleteValueColumn.setCellEditor(new TableCellButtonEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getCellEditorValue() {
            final Resourcebundles selected = (Resourcebundles) this.getValue();
            final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
            resourcebundlesService.delete(selected);
            if (selected.equals(MainFrame.getInstance().getModelObject().getSelectedBundleApplication().getSelectedResourcebundle())) {
                txtKey.setText("");
                txtValue.setText("");
                MainFrame.getInstance().getModelObject().getSelectedBundleApplication().setSelectedResourcebundle(null);
            }
            reloadTableModel();
            revalidate();
            final String text = "Delete";
            return text;
        }

        @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 String text = "Delete";
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
    // ============================================================================================
    btnAddEntry = new javax.swing.JButton();
    txtKey = new javax.swing.JTextField();
    txtValue = new javax.swing.JTextField();
    lblKey.setText("Key");
    lblHeaderOverview.setText("Overview of resource bundle " + getModelObject().getSelectedBundleName().getBaseName().getName());
    lblValue.setText("Value");
    srcBundles.setViewportView(tblBundles);
    btnAddEntry.setText("Add new entry");
    btnAddEntry.addActionListener(e -> onAddEntry(e));
    btnToDashboard.setText("Return to Dashboard");
    btnToDashboard.addActionListener(ReturnToDashboardAction.of());
    btnExport.setText("Export");
    btnExport.addActionListener(e -> onExport(e));
    btnDelete.setText("Delete");
    btnDelete.addActionListener(e -> onDelete(e));
}
Also used : StringResourcebundlesTableModel(de.alpharogroup.bundle.app.table.model.StringResourcebundlesTableModel) TableColumn(javax.swing.table.TableColumn) JCheckBox(javax.swing.JCheckBox) TableCellButtonEditor(de.alpharogroup.swing.table.editor.TableCellButtonEditor) TableCellButtonRenderer(de.alpharogroup.swing.renderer.TableCellButtonRenderer) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) JTable(javax.swing.JTable) Resourcebundles(de.alpharogroup.db.resource.bundles.entities.Resourcebundles) Component(java.awt.Component)

Example 3 with TableCellButtonRenderer

use of de.alpharogroup.swing.renderer.TableCellButtonRenderer 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)

Example 4 with TableCellButtonRenderer

use of de.alpharogroup.swing.renderer.TableCellButtonRenderer in project bundle-app-ui by astrapi69.

the class OverviewOfAllResourceBundlesPanel method onInitializeComponents.

@Override
protected void onInitializeComponents() {
    super.onInitializeComponents();
    lblHeaderOverview = new javax.swing.JLabel();
    lblBundleName = new javax.swing.JLabel();
    srcBundles = new javax.swing.JScrollPane();
    btnCreateBundle = new javax.swing.JButton();
    btnCreateBundle.addActionListener(e -> onCreateBundle(e));
    btnToDashboard = new javax.swing.JButton();
    btnToDashboard.setText("Return to Dashboard");
    btnToDashboard.addActionListener(ReturnToDashboardAction.of());
    tableModel = new StringBundleNamesTableModel();
    tableModel.addList(getTableModelList());
    tblBundles = new GenericJXTable<>(tableModel);
    final TableColumn valueColumn = tblBundles.getColumn("Action");
    valueColumn.setCellRenderer(new TableCellButtonRenderer(null, null) {

        private static final long serialVersionUID = 1L;

        @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 String text = "Choose";
            setText(text);
            return this;
        }
    });
    valueColumn.setCellEditor(new TableCellButtonEditor(new JCheckBox()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getCellEditorValue() {
            final BundleNames selectedBundleName = (BundleNames) this.getValue();
            final Model<ApplicationDashboardBean> baModel = MainFrame.getInstance().getSelectedBundleApplicationPropertyModel();
            MainFrame.getInstance().getModelObject().getSelectedBundleApplication().setSelectedBundleName(selectedBundleName);
            final OverviewResourceBundleAddEntryPanel component = new OverviewResourceBundleAddEntryPanel(baModel);
            MainFrame.getInstance().replaceInternalFrame("Values of resource bundle " + selectedBundleName.getBaseName().getName() + " with locale " + selectedBundleName.getLocale().getLocale() + "", component);
            final String text = "Choose";
            return text;
        }

        @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 String text = "Choose";
            getButton().setText(text);
            setClicked(true);
            return getButton();
        }
    });
    lblHeaderOverview.setText("Overview of all resource bundles");
    lblBundleName.setText("Bundle count");
    srcBundles.setViewportView(tblBundles);
    btnCreateBundle.setText("Create new resource bundle");
}
Also used : StringBundleNamesTableModel(de.alpharogroup.bundle.app.table.model.StringBundleNamesTableModel) TableColumn(javax.swing.table.TableColumn) JCheckBox(javax.swing.JCheckBox) TableCellButtonEditor(de.alpharogroup.swing.table.editor.TableCellButtonEditor) BundleNames(de.alpharogroup.db.resource.bundles.entities.BundleNames) TableCellButtonRenderer(de.alpharogroup.swing.renderer.TableCellButtonRenderer) JTable(javax.swing.JTable) BaseModel(de.alpharogroup.model.BaseModel) Model(de.alpharogroup.model.api.Model) StringBundleNamesTableModel(de.alpharogroup.bundle.app.table.model.StringBundleNamesTableModel) Component(java.awt.Component)

Aggregations

TableCellButtonRenderer (de.alpharogroup.swing.renderer.TableCellButtonRenderer)4 Component (java.awt.Component)4 JCheckBox (javax.swing.JCheckBox)4 JTable (javax.swing.JTable)4 TableColumn (javax.swing.table.TableColumn)4 TableCellButtonEditor (de.alpharogroup.swing.table.editor.TableCellButtonEditor)3 BaseModel (de.alpharogroup.model.BaseModel)2 Model (de.alpharogroup.model.api.Model)2 ApplicationDashboardContentPanel (de.alpharogroup.bundle.app.panels.dashboard.ApplicationDashboardContentPanel)1 TableCellCheckboxEditor (de.alpharogroup.bundle.app.radio.TableCellCheckboxEditor)1 FileLocaleBooleanTableModel (de.alpharogroup.bundle.app.table.model.FileLocaleBooleanTableModel)1 StringBundleApplicationsBundleApplicationsTableModel (de.alpharogroup.bundle.app.table.model.StringBundleApplicationsBundleApplicationsTableModel)1 StringBundleNamesTableModel (de.alpharogroup.bundle.app.table.model.StringBundleNamesTableModel)1 StringResourcebundlesTableModel (de.alpharogroup.bundle.app.table.model.StringResourcebundlesTableModel)1 KeyValuePair (de.alpharogroup.collections.pairs.KeyValuePair)1 BundleApplications (de.alpharogroup.db.resource.bundles.entities.BundleApplications)1 BundleNames (de.alpharogroup.db.resource.bundles.entities.BundleNames)1 Resourcebundles (de.alpharogroup.db.resource.bundles.entities.Resourcebundles)1 ResourcebundlesService (de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService)1 EventObject (de.alpharogroup.design.pattern.observer.event.EventObject)1