use of de.alpharogroup.db.resource.bundles.entities.LanguageLocales in project bundle-app-ui by astrapi69.
the class NewBundleApplicationPanel method onSave.
protected void onSave(final ActionEvent e) {
final BundleApplicationsService bundleApplicationsService = (BundleApplicationsService) SpringApplicationContext.getInstance().getApplicationContext().getBean("bundleApplicationsService");
final String name = getTxtBundleName().getText();
BundleApplications currentBundleApplication;
if (getModelObject().getBundleApplication() != null) {
currentBundleApplication = getModelObject().getBundleApplication();
currentBundleApplication.setName(name);
Locale dl = getModelObject().getDefaultLocale();
LanguageLocales defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().getOrCreateNewLanguageLocales(dl);
if (currentBundleApplication.getDefaultLocale() != null) {
if (!currentBundleApplication.getDefaultLocale().equals(defaultLocale)) {
currentBundleApplication.setDefaultLocale(defaultLocale);
}
} else {
currentBundleApplication.setDefaultLocale(defaultLocale);
}
currentBundleApplication = bundleApplicationsService.merge(currentBundleApplication);
getModelObject().setBundleApplication(currentBundleApplication);
} else {
BundleApplications newBundleApplication = bundleApplicationsService.find(name);
if (newBundleApplication == null) {
Locale dl = getModelObject().getDefaultLocale();
LanguageLocales defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().find(dl);
newBundleApplication = BundleApplications.builder().name(name).defaultLocale(defaultLocale).build();
newBundleApplication = bundleApplicationsService.merge(newBundleApplication);
}
if (!MainFrame.getInstance().getModelObject().getBundleApplications().contains(newBundleApplication)) {
MainFrame.getInstance().getModelObject().getBundleApplications().add(newBundleApplication);
}
getModelObject().setBundleApplication(newBundleApplication);
}
}
use of de.alpharogroup.db.resource.bundles.entities.LanguageLocales in project bundle-app-ui by astrapi69.
the class SpringApplicationContext method initDb.
protected void initDb(final ApplicationContext ac) {
final LanguagesService languagesService = (LanguagesService) ac.getBean("languagesService");
final LanguageLocalesService languageLocalesService = (LanguageLocalesService) ac.getBean("languageLocalesService");
final BundleApplicationsService bundleApplicationsService = getBundleApplicationsService();
final List<Languages> languages = DataObjectFactory.newLanguages();
for (final Languages language : languages) {
final Languages found = languagesService.find(language.getName(), language.getIso639Dash1());
if (found == null) {
languagesService.merge(language);
}
}
final List<LanguageLocales> languageLocales = DataObjectFactory.newLanguageLocales();
for (final LanguageLocales languageLocale : languageLocales) {
final LanguageLocales found = languageLocalesService.find(languageLocale.getLocale());
if (found == null) {
languageLocalesService.merge(languageLocale);
}
}
BundleApplications baseBundleApplication = bundleApplicationsService.find(BundleApplications.BASE_BUNDLE_APPLICATION);
if (baseBundleApplication == null) {
baseBundleApplication = BundleApplications.builder().name(BundleApplications.BASE_BUNDLE_APPLICATION).build();
baseBundleApplication = bundleApplicationsService.merge(baseBundleApplication);
}
}
use of de.alpharogroup.db.resource.bundles.entities.LanguageLocales in project bundle-app-ui by astrapi69.
the class NewBundleApplicationPanel method newCmbDefaultLocale.
protected javax.swing.JComboBox<Locale> newCmbDefaultLocale(final Model<ApplicationDashboardBean> model) {
ApplicationDashboardBean bean = model.getObject();
BundleApplications bundleApplication = bean.getBundleApplication();
LocalesComboBoxModel cmbModel = LocalesComboBoxModel.get();
Locale dl = Locale.getDefault();
if (bundleApplication != null) {
LanguageLocales defaultLocale = bundleApplication.getDefaultLocale();
if (defaultLocale != null) {
dl = SpringApplicationContext.getInstance().getLanguageLocalesService().resolveLocale(defaultLocale);
}
}
cmbModel.setSelectedItem(dl);
final javax.swing.JComboBox<Locale> cmbDefaultLocale = new javax.swing.JComboBox<>(cmbModel);
cmbDefaultLocale.addItemListener(e -> onChangeDefaultLocale(e));
final Model<Locale> defaultLocaleModel = model(from(getModel()).getDefaultLocale());
cmbDefaultLocale.setRenderer(new LocalesComboBoxRenderer(defaultLocaleModel));
return cmbDefaultLocale;
}
use of de.alpharogroup.db.resource.bundles.entities.LanguageLocales in project bundle-app-ui by astrapi69.
the class NewCustomLocalePanel method onSave.
private void onSave(final ActionEvent e) {
System.out.println("de.alpharogroup.bundle.app.panels.creation.NewCustomLocalePanel.onSave()");
Languages selectedLanguage = (Languages) cmbLanguage.getSelectedItem();
Countries selectedCountry = (Countries) cmbCountry.getSelectedItem();
String variant = txtVariant.getText();
String localeCode = selectedLanguage.getIso639Dash1() + "_" + selectedCountry.getIso3166A2name() + "_" + variant;
LanguageLocales languageLocales = SpringApplicationContext.getInstance().getLanguageLocalesService().find(localeCode);
if (languageLocales == null) {
SpringApplicationContext.getInstance().getLanguageLocalesService().merge(LanguageLocales.builder().locale(localeCode).build());
cmbCountry.setModel(new CountriesComboBoxModel());
cmbLanguage.setModel(new LanguagesComboBoxModel());
txtVariant.setText("");
this.revalidate();
this.repaint();
} else {
// no owner frame
JOptionPane.showMessageDialog(// no owner frame
null, // text to display
"Locale already exists", // title
"Invalid Value", JOptionPane.WARNING_MESSAGE);
}
}
use of de.alpharogroup.db.resource.bundles.entities.LanguageLocales in project bundle-app-ui by astrapi69.
the class NewBundleNamePanel method onSave.
protected void onSave(final ActionEvent e) {
BundleApplications bundleApplication = getModelObject().getBundleApplication();
final BundleNamesService bundleNamesService = SpringApplicationContext.getInstance().getBundleNamesService();
final String baseName = txtBasename.getText();
final LanguageLocales selectedItem = (LanguageLocales) cmbLocale.getSelectedItem();
if (selectedItem != null) {
final Locale locale = LocaleResolver.resolveLocale(selectedItem.getLocale());
bundleNamesService.getOrCreateNewBundleNames(bundleApplication, baseName, locale);
} else {
final LanguageLocales languageLocales = getModelObject().getBundleApplication().getDefaultLocale();
final Locale locale = SpringApplicationContext.getInstance().getLanguageLocalesService().resolveLocale(languageLocales);
bundleNamesService.getOrCreateNewBundleNames(bundleApplication, baseName, locale);
}
}
Aggregations