Search in sources :

Example 1 with ResourcebundlesService

use of de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService in project bundle-app-ui by astrapi69.

the class ApplicationDashboardContentPanel method onChooseImportResourceBundle.

/**
 * Callback method which import resourcebundles from a folder of file.
 *
 * @param dir the dir
 */
protected void onChooseImportResourceBundle(final boolean dir) {
    final int returnVal = fileChooser.showOpenDialog(ApplicationDashboardContentPanel.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File resourceBundleToImport = fileChooser.getSelectedFile();
        getModelObject().setResourceBundleToImport(resourceBundleToImport);
        try {
            if (dir) {
                ApplicationDashboardBean mo = getModelObject();
                BundleApplications bundleApplications = SpringApplicationContext.getInstance().getBundleApplicationsService().get(mo.getBundleApplication().getId());
                final Locale defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().resolveLocale(bundleApplications.getDefaultLocale());
                final PropertiesListResolver resolver1 = new PropertiesListResolver(resourceBundleToImport, defaultLocale);
                resolver1.resolve();
                final List<KeyValuePair<File, Locale>> propertiesList = resolver1.getPropertiesList();
                getModelObject().setFoundProperties(ConvertExtensions.convertAndSort(propertiesList));
                // 1. create bundleapp
                final BundleApplicationsService bundleApplicationsService = SpringApplicationContext.getInstance().getBundleApplicationsService();
                final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
                BundleApplications bundleApplication = getModelObject().getBundleApplication();
                // 2. get properties files
                final List<Triple<File, Locale, KeyValuePair<Boolean, File>>> foundProperties = getModelObject().getFoundProperties();
                // 3. save properties files the to the bundleapp
                final Set<BundleNames> set = SetExtensions.newHashSet();
                for (final Triple<File, Locale, KeyValuePair<Boolean, File>> entry : foundProperties) {
                    if (BooleanUtils.toBoolean(entry.getRight().getKey())) {
                        final File propertiesFile = entry.getLeft();
                        final Locale locale = entry.getMiddle();
                        final String bundlename = LocaleResolver.resolveBundlename(propertiesFile);
                        Properties properties = null;
                        try {
                            properties = PropertiesExtensions.loadProperties(propertiesFile);
                        } catch (final IOException e) {
                            log.error(e.getLocalizedMessage(), e);
                        }
                        final BundleNames bundleNames = resourcebundlesService.updateProperties(bundleApplication, properties, bundlename, locale);
                        set.add(bundleNames);
                    }
                }
                bundleApplication = bundleApplicationsService.merge(bundleApplication);
            } else {
                final Properties importedProperties = PropertiesExtensions.loadProperties(resourceBundleToImport);
                getModelObject().setImportedProperties(importedProperties);
                final List<KeyValuePair<String, String>> keyValuePairs = PropertiesExtensions.toKeyValuePairs(importedProperties);
                Collections.sort(keyValuePairs, NullCheckComparator.<KeyValuePair<String, String>>of(new KeyValuePairKeyComparator<>()));
                getModelObject().setImportedKeyValuePairs(keyValuePairs);
                MainApplication.get().getApplicationEventBus().post(ApplicationDashboardContentPanel.this.getModelObject());
                getCardLayout().show(this, ApplicationDashboardView.IMPORT_RB.name());
            }
        } catch (final IOException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : Locale(java.util.Locale) KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) PropertiesListResolver(de.alpharogroup.resourcebundle.inspector.search.PropertiesListResolver) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) IOException(java.io.IOException) Properties(java.util.Properties) Triple(de.alpharogroup.collections.pairs.Triple) BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) BundleNames(de.alpharogroup.db.resource.bundles.entities.BundleNames) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) KeyValuePairKeyComparator(de.alpharogroup.comparators.pairs.KeyValuePairKeyComparator) File(java.io.File)

Example 2 with ResourcebundlesService

use of de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService in project bundle-app-ui by astrapi69.

the class ImportWizardPanel method startDbImport.

private void startDbImport() {
    // 1. create bundleapp
    final BundleApplicationsService bundleApplicationsService = SpringApplicationContext.getInstance().getBundleApplicationsService();
    final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
    BundleApplications bundleApplication = bundleApplicationsService.find(getModelObject().getBundleAppName());
    // 2. get properties files
    final List<Triple<File, Locale, KeyValuePair<Boolean, File>>> foundProperties = getModelObject().getFoundProperties();
    // 3. save properties files the to the bundleapp
    for (final Triple<File, Locale, KeyValuePair<Boolean, File>> entry : foundProperties) {
        if (BooleanUtils.toBoolean(entry.getRight().getKey())) {
            final File propertiesFile = entry.getLeft();
            final Locale locale = entry.getMiddle();
            final String bundlename = LocaleResolver.resolveBundlename(propertiesFile);
            Properties properties = null;
            try {
                properties = PropertiesExtensions.loadProperties(propertiesFile);
            } catch (final IOException e) {
                log.error("Loading Properties file " + propertiesFile.getAbsolutePath() + " failed.", e);
            }
            resourcebundlesService.updateProperties(bundleApplication, properties, bundlename, locale);
        }
    }
}
Also used : Locale(java.util.Locale) KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) IOException(java.io.IOException) Properties(java.util.Properties) Triple(de.alpharogroup.collections.pairs.Triple) BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) File(java.io.File)

Example 3 with ResourcebundlesService

use of de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService in project bundle-app-ui by astrapi69.

the class OverviewResourceBundleAddEntryPanel method onAddEntry.

protected void onAddEntry(final ActionEvent e) {
    final String key = txtKey.getText();
    final String value = txtValue.getText();
    BundleApplications bundleApplication = getModelObject().getBundleApplication();
    final String baseName = getModelObject().getSelectedBundleName().getBaseName().getName();
    final Locale locale = LocaleResolver.resolveLocale(getModelObject().getSelectedBundleName().getLocale().getLocale());
    final PropertiesKeysService propertiesKeysService = SpringApplicationContext.getInstance().getPropertiesKeysService();
    final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
    final boolean update = true;
    Resourcebundles resourcebundle = resourcebundlesService.getResourcebundle(bundleApplication, baseName, locale, key);
    if (resourcebundle != null) {
        if (update) {
            resourcebundle.setValue(value);
        }
    } else {
        final PropertiesKeys pkey = propertiesKeysService.getOrCreateNewPropertiesKeys(key);
        resourcebundle = Resourcebundles.builder().bundleName(getModelObject().getSelectedBundleName()).key(pkey).value(value).build();
        ResourceBundlesDomainObjectFactory.getInstance().newResourcebundles(getModelObject().getSelectedBundleName(), pkey, value);
    }
    resourcebundle = resourcebundlesService.merge(resourcebundle);
    reloadTableModel();
    MainFrame.getInstance().getModelObject().getSelectedBundleApplication().setSelectedResourcebundle(null);
    txtKey.setText("");
    txtValue.setText("");
    revalidate();
}
Also used : Locale(java.util.Locale) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) Resourcebundles(de.alpharogroup.db.resource.bundles.entities.Resourcebundles) PropertiesKeysService(de.alpharogroup.db.resource.bundles.service.api.PropertiesKeysService) PropertiesKeys(de.alpharogroup.db.resource.bundles.entities.PropertiesKeys)

Example 4 with ResourcebundlesService

use of de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService 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 5 with ResourcebundlesService

use of de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService in project bundle-app-ui by astrapi69.

the class OverviewResourceBundleAddEntryPanel method reloadTableModelList.

private void reloadTableModelList() {
    tableModelList = new ArrayList<>();
    final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
    BundleApplications bundleApplication = getModelObject().getBundleApplication();
    final String baseName = getModelObject().getSelectedBundleName().getBaseName().getName();
    final Locale locale = LocaleResolver.resolveLocale(getModelObject().getSelectedBundleName().getLocale().getLocale());
    final List<Resourcebundles> list = resourcebundlesService.findResourceBundles(bundleApplication, baseName, locale);
    for (final Resourcebundles resourcebundle : list) {
        tableModelList.add(Quattro.<String, String, Resourcebundles, Resourcebundles>builder().topLeft(resourcebundle.getKey().getName()).topRight(resourcebundle.getValue()).bottomLeft(resourcebundle).bottomRight(resourcebundle).build());
    }
    Collections.sort(tableModelList, NullCheckComparator.<Quattro<String, String, Resourcebundles, Resourcebundles>>of((o1, o2) -> o1.getTopLeft().compareTo(o2.getTopLeft())));
}
Also used : Locale(java.util.Locale) PropertiesKeysService(de.alpharogroup.db.resource.bundles.service.api.PropertiesKeysService) TableCellButtonEditor(de.alpharogroup.swing.table.editor.TableCellButtonEditor) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) BaseModel(de.alpharogroup.model.BaseModel) MainFrame(de.alpharogroup.bundle.app.MainFrame) ArrayList(java.util.ArrayList) PropertiesExtensions(de.alpharogroup.collections.properties.PropertiesExtensions) LocaleResolver(de.alpharogroup.resourcebundle.locale.LocaleResolver) Locale(java.util.Locale) StringResourcebundlesTableModel(de.alpharogroup.bundle.app.table.model.StringResourcebundlesTableModel) BasePanel(de.alpharogroup.swing.base.BasePanel) JFileChooser(javax.swing.JFileChooser) SpringApplicationContext(de.alpharogroup.bundle.app.spring.SpringApplicationContext) Properties(java.util.Properties) Resourcebundles(de.alpharogroup.db.resource.bundles.entities.Resourcebundles) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) TableColumn(javax.swing.table.TableColumn) Model(de.alpharogroup.model.api.Model) FileOutputStream(java.io.FileOutputStream) ApplicationDashboardContentPanel(de.alpharogroup.bundle.app.panels.dashboard.ApplicationDashboardContentPanel) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) NullCheckComparator(de.alpharogroup.comparators.NullCheckComparator) ResourceBundlesDomainObjectFactory(de.alpharogroup.db.resource.bundles.factories.ResourceBundlesDomainObjectFactory) GenericJXTable(de.alpharogroup.swing.x.GenericJXTable) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ReturnToDashboardAction(de.alpharogroup.bundle.app.actions.ReturnToDashboardAction) JCheckBox(javax.swing.JCheckBox) ApplicationDashboardBean(de.alpharogroup.bundle.app.panels.dashboard.ApplicationDashboardBean) JTable(javax.swing.JTable) PropertiesKeys(de.alpharogroup.db.resource.bundles.entities.PropertiesKeys) TableCellButtonRenderer(de.alpharogroup.swing.renderer.TableCellButtonRenderer) Collections(java.util.Collections) Quattro(de.alpharogroup.collections.pairs.Quattro) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) Resourcebundles(de.alpharogroup.db.resource.bundles.entities.Resourcebundles)

Aggregations

ResourcebundlesService (de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService)5 BundleApplications (de.alpharogroup.db.resource.bundles.entities.BundleApplications)4 Locale (java.util.Locale)4 Resourcebundles (de.alpharogroup.db.resource.bundles.entities.Resourcebundles)3 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3 StringResourcebundlesTableModel (de.alpharogroup.bundle.app.table.model.StringResourcebundlesTableModel)2 KeyValuePair (de.alpharogroup.collections.pairs.KeyValuePair)2 Triple (de.alpharogroup.collections.pairs.Triple)2 PropertiesKeys (de.alpharogroup.db.resource.bundles.entities.PropertiesKeys)2 BundleApplicationsService (de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService)2 PropertiesKeysService (de.alpharogroup.db.resource.bundles.service.api.PropertiesKeysService)2 TableCellButtonRenderer (de.alpharogroup.swing.renderer.TableCellButtonRenderer)2 TableCellButtonEditor (de.alpharogroup.swing.table.editor.TableCellButtonEditor)2 Component (java.awt.Component)2 JCheckBox (javax.swing.JCheckBox)2 JTable (javax.swing.JTable)2 TableColumn (javax.swing.table.TableColumn)2 MainFrame (de.alpharogroup.bundle.app.MainFrame)1