use of de.alpharogroup.db.resource.bundles.entities.BundleNames 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);
}
}
}
use of de.alpharogroup.db.resource.bundles.entities.BundleNames in project bundle-app-ui by astrapi69.
the class OverviewOfAllResourceBundlesPanel method getTableModelList.
private List<Triple<String, String, BundleNames>> getTableModelList() {
if (tableModelList == null) {
tableModelList = new ArrayList<>();
BundleApplications bundleApplication = getModelObject().getBundleApplication();
getModelObject().setBundleNames(SpringApplicationContext.getInstance().getBundleApplicationsService().find(bundleApplication));
final Set<BundleNames> set = getModelObject().getBundleNames();
if (CollectionExtensions.isNotEmpty(set)) {
for (final BundleNames bundleNames : set) {
tableModelList.add(Triple.<String, String, BundleNames>builder().left(bundleNames.getBaseName().getName()).middle(bundleNames.getLocale().getLocale()).right(bundleNames).build());
}
}
Collections.sort(tableModelList, NullCheckComparator.<Triple<String, String, BundleNames>>of((o1, o2) -> o1.getLeft().compareTo(o2.getLeft())));
}
return tableModelList;
}
use of de.alpharogroup.db.resource.bundles.entities.BundleNames 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");
}
Aggregations