Search in sources :

Example 1 with KeyValuePair

use of de.alpharogroup.collections.pairs.KeyValuePair 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 KeyValuePair

use of de.alpharogroup.collections.pairs.KeyValuePair in project bundle-app-ui by astrapi69.

the class ImportWizardPanel method startResolving.

private void startResolving() throws IOException {
    final File rootDir = getModelObject().getRootDir();
    final Locale defaultLocale = getModelObject().getDefaultLocale();
    final PropertiesListResolver resolver1 = new PropertiesListResolver(rootDir, defaultLocale);
    resolver1.resolve();
    final List<KeyValuePair<File, Locale>> propertiesList = resolver1.getPropertiesList();
    getModelObject().setFoundProperties(ConvertExtensions.convertAndSort(propertiesList));
    getModelObject().setDbImport(true);
    final EventSource<EventObject<ImportWizardModel>> eventSource = MainApplication.getImportWizardModel();
    eventSource.fireEvent(new EventObject<>(getModelObject()));
    // set buttons state...
    getModelObject().setValidPrevious(true);
    getModelObject().setValidFinish(true);
    final EventSource<EventObject<NavigationEventState>> navigationEventState = MainApplication.getImportNavigationState();
    navigationEventState.fireEvent(new EventObject<>(NavigationEventState.UPDATE));
}
Also used : Locale(java.util.Locale) KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) PropertiesListResolver(de.alpharogroup.resourcebundle.inspector.search.PropertiesListResolver) File(java.io.File) EventObject(de.alpharogroup.design.pattern.observer.event.EventObject)

Example 3 with KeyValuePair

use of de.alpharogroup.collections.pairs.KeyValuePair 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 4 with KeyValuePair

use of de.alpharogroup.collections.pairs.KeyValuePair 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

KeyValuePair (de.alpharogroup.collections.pairs.KeyValuePair)4 File (java.io.File)4 Locale (java.util.Locale)3 Triple (de.alpharogroup.collections.pairs.Triple)2 BundleApplications (de.alpharogroup.db.resource.bundles.entities.BundleApplications)2 BundleApplicationsService (de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService)2 ResourcebundlesService (de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService)2 EventObject (de.alpharogroup.design.pattern.observer.event.EventObject)2 PropertiesListResolver (de.alpharogroup.resourcebundle.inspector.search.PropertiesListResolver)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 TableCellCheckboxEditor (de.alpharogroup.bundle.app.radio.TableCellCheckboxEditor)1 FileLocaleBooleanTableModel (de.alpharogroup.bundle.app.table.model.FileLocaleBooleanTableModel)1 KeyValuePairKeyComparator (de.alpharogroup.comparators.pairs.KeyValuePairKeyComparator)1 BundleNames (de.alpharogroup.db.resource.bundles.entities.BundleNames)1 TableCellButtonRenderer (de.alpharogroup.swing.renderer.TableCellButtonRenderer)1 Component (java.awt.Component)1 JCheckBox (javax.swing.JCheckBox)1 JTable (javax.swing.JTable)1 TableColumn (javax.swing.table.TableColumn)1