From 56086f96dbfea3e68dd0914273c830f7f1abf137 Mon Sep 17 00:00:00 2001 From: Yuuki Aschwanden Date: Fri, 8 Sep 2023 12:45:52 +0200 Subject: [PATCH] 360873 SimRel Build: Contacts/Widgets --- .../scout/contacts/client/ClientSession.java | 6 ++- .../scout/contacts/client/OptionsForm.java | 30 ++++++++------- .../contacts/client/person/PersonForm.java | 37 ++----------------- 3 files changed, 24 insertions(+), 49 deletions(-) diff --git a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/ClientSession.java b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/ClientSession.java index 7d3794ded..3caa416e2 100644 --- a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/ClientSession.java +++ b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/ClientSession.java @@ -19,6 +19,7 @@ public class ClientSession extends AbstractClientSession { public static final String PREF_USER_LOCALE = "PREF_USER_LOCALE"; + public static final String PREF_USER_LAYOUT = "PREF_USER_LAYOUT"; public ClientSession() { super(true); @@ -35,12 +36,15 @@ public static ClientSession get() { protected void execLoadSession() { initializeSharedVariables(); - // The locale needs to be set before the Desktop is created. + String denseLayout = ClientUIPreferences.getClientPreferences(get()).get(PREF_USER_LAYOUT, null); String localeString = ClientUIPreferences.getClientPreferences(get()).get(PREF_USER_LOCALE, null); + + // The locale needs to be set before the Desktop is created. if (localeString != null) { setLocale(Locale.forLanguageTag(localeString)); } setDesktop(new Desktop()); + getDesktop().setDense(Boolean.parseBoolean(denseLayout)); } } diff --git a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/OptionsForm.java b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/OptionsForm.java index 374992dff..2ca524284 100644 --- a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/OptionsForm.java +++ b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/OptionsForm.java @@ -42,14 +42,9 @@ protected String getConfiguredTitle() { @Override protected void execInitForm() { - String theme = ObjectUtility.nvl(getDesktop().getTheme(), DefaultCode.ID); - getUiThemeField().setValue(theme); + getUiThemeField().setValue(ObjectUtility.nvl(getDesktop().getTheme(), DefaultCode.ID)); getDenseRadioButtonGroup().setValue(getDesktop().isDense()); - - String localeString = ClientUIPreferences.getClientPreferences(ClientSession.get()).get(ClientSession.PREF_USER_LOCALE, null); - if (localeString != null) { - getLocaleField().setValue(Locale.forLanguageTag(localeString)); - } + getLocaleField().setValue(ObjectUtility.nvl(ClientSession.get().getLocale(), Locale.getDefault())); } public MainBox getMainBox() { @@ -70,15 +65,22 @@ public LocaleField getLocaleField() { protected void storeOptions() { // Not inside form handler, because the form is used in a FormToolButton without a handler - getDesktop().setTheme(getUiThemeField().getValue()); - getDesktop().setDense(getDenseRadioButtonGroup().getValue()); + boolean denseLayout = ObjectUtility.nvl(getDenseRadioButtonGroup().getValue(), false); Locale locale = ObjectUtility.nvl(getLocaleField().getValue(), Locale.getDefault()); + + boolean layoutChanged = ClientUIPreferences.getClientPreferences(ClientSession.get()).put(ClientSession.PREF_USER_LAYOUT, String.valueOf(denseLayout)); boolean localeChanged = ClientUIPreferences.getClientPreferences(ClientSession.get()).put(ClientSession.PREF_USER_LOCALE, locale.toLanguageTag()); - if (localeChanged) { + + getDesktop().setTheme(getUiThemeField().getValue()); + getDesktop().setDense(denseLayout); + + if (layoutChanged || localeChanged) { ClientUIPreferences.getClientPreferences(ClientSession.get()).flush(); - MessageBoxes.createOk() - .withBody(TEXTS.get("ChangeOfLanguageAppliedOnNextLogin")) - .show(); + if(localeChanged) { + MessageBoxes.createOk() + .withBody(TEXTS.get("ChangeOfLanguageAppliedOnNextLogin")) + .show(); + } } } @@ -186,7 +188,7 @@ protected boolean getConfiguredStatusVisible() { @Override protected Class> getConfiguredLookupCall() { - return (Class>) AvailableLocaleLookupCall.class; + return AvailableLocaleLookupCall.class; } } } diff --git a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/person/PersonForm.java b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/person/PersonForm.java index 9593771d0..f5d6f19e7 100644 --- a/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/person/PersonForm.java +++ b/code/contacts/org.eclipse.scout.contacts.client/src/main/java/org/eclipse/scout/contacts/client/person/PersonForm.java @@ -10,10 +10,10 @@ package org.eclipse.scout.contacts.client.person; import java.util.Date; -import java.util.regex.Pattern; import org.eclipse.scout.contacts.client.Icons; import org.eclipse.scout.contacts.client.common.AbstractDirtyFormHandler; +import org.eclipse.scout.contacts.client.common.AbstractEmailField; import org.eclipse.scout.contacts.client.common.ContactsHelper; import org.eclipse.scout.contacts.client.common.CountryLookupCall; import org.eclipse.scout.contacts.client.common.MapHelper; @@ -637,33 +637,7 @@ protected String getConfiguredLabel() { // tag::email[] @Order(40) @ClassId("5f9d9363-8e57-4151-b281-7d401e64702c") - public class EmailField extends AbstractStringField { - - // end::email[] - // http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/ - // tag::email[] - private static final String EMAIL_PATTERN = // <1> - "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + - "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; - - @Override - protected String getConfiguredLabel() { - return TEXTS.get("Email"); - } - - @Override // <2> - protected int getConfiguredMaxLength() { - return 64; - } - - @Override // <3> - protected String execValidateValue(String rawValue) { - if (rawValue != null && !Pattern.matches(EMAIL_PATTERN, rawValue)) { - throw new VetoException(TEXTS.get("BadEmailAddress")); // <4> - } - - return rawValue; // <5> - } + public class EmailField extends AbstractEmailField { } // end::email[] // tag::layout[] @@ -720,12 +694,7 @@ protected String getConfiguredLabel() { @Order(40) @ClassId("7f693443-ec4e-47fb-874e-b31328cc22fb") - public class EmailWorkField extends AbstractStringField { - - @Override - protected String getConfiguredLabel() { - return TEXTS.get("Email"); - } + public class EmailWorkField extends AbstractEmailField { } // tag::layout[] // tag::organizationField[]