From 25a4d8271983c0b8d45f67b00e4105670c6b04c3 Mon Sep 17 00:00:00 2001 From: peterdell Date: Sat, 18 Sep 2021 01:07:23 +0200 Subject: [PATCH] Change localization to /OSGI-INF/l10n --- .../src/com/wudsn/ide/base/gui/EnumField.java | 308 +++++++++--------- .../l10n/bundle.properties} | 0 .../l10n/bundle_de_DE.properties} | 0 3 files changed, 154 insertions(+), 154 deletions(-) rename com.wudsn.ide.hex/{plugin.properties => OSGI-INF/l10n/bundle.properties} (100%) rename com.wudsn.ide.hex/{plugin_de_DE.properties => OSGI-INF/l10n/bundle_de_DE.properties} (100%) diff --git a/com.wudsn.ide.base/src/com/wudsn/ide/base/gui/EnumField.java b/com.wudsn.ide.base/src/com/wudsn/ide/base/gui/EnumField.java index d1e5a3de..8c4636a2 100644 --- a/com.wudsn.ide.base/src/com/wudsn/ide/base/gui/EnumField.java +++ b/com.wudsn.ide.base/src/com/wudsn/ide/base/gui/EnumField.java @@ -38,177 +38,177 @@ import com.wudsn.ide.base.BasePlugin; * * @author Peter Dell * - * @param - * The enum class. + * @param The enum class. */ public final class EnumField> extends Field { - private static final class Entry { - public T constant; - public String name; - public String text; + private static final class Entry { + public T constant; + public String name; + public String text; - public Entry() { - } - - } - - private Combo combo; - private List> entries; - - /** - * Creates a new enum field. - * - * @param parent - * The parent composite, not null. - * @param labelText - * The label text, not null. - * @param enumClass - * The enum class, not null. - * @param visibleValues - * The non-empty array containing the subset of enum values to be - * displayed or null to display all values. - */ - public EnumField(Composite parent, String labelText, Class enumClass, T visibleValues[]) { - if (parent == null) { - throw new IllegalArgumentException("Parameter 'parent' must not be null."); - } - if (labelText == null) { - throw new IllegalArgumentException("Parameter 'labelText' must not be null."); - } - if (enumClass == null) { - throw new IllegalArgumentException("Parameter 'enumClass' must not be null."); - } - if (visibleValues != null && visibleValues.length == 0) { - throw new IllegalArgumentException("Parameter 'visibleValues' must not be empty"); - } - label = new Label(parent, SWT.NONE); - label.setText(labelText); - combo = new Combo(parent, SWT.DROP_DOWN); - - ResourceBundle resourceBundle; - resourceBundle = ResourceBundle.getBundle("plugin", Locale.getDefault(), enumClass.getClassLoader()); - - T[] constants = enumClass.getEnumConstants(); - - if (constants.length == 0) { - throw new IllegalArgumentException("Enum class '" + enumClass + "' has no constants."); - } - - // Ensure all visible values are contained in the set of constants. - if (visibleValues != null) { - for (int i = 0; i < visibleValues.length; i++) { - T visibleValue = visibleValues[i]; - boolean found = false; - for (int j = 0; j < constants.length; j++) { - if (constants[j] == visibleValue) { - found = true; - continue; - } + public Entry() { } - if (!found) { - throw new IllegalArgumentException("Parameter 'visibleValues' contain the undefined value '" - + visibleValue + "'."); + + } + + private Combo combo; + private List> entries; + + /** + * Creates a new enum field. + * + * @param parent The parent composite, not null. + * @param labelText The label text, not null. + * @param enumClass The enum class, not null. + * @param visibleValues The non-empty array containing the subset of enum values + * to be displayed or null to display all + * values. + */ + public EnumField(Composite parent, String labelText, Class enumClass, T visibleValues[]) { + if (parent == null) { + throw new IllegalArgumentException("Parameter 'parent' must not be null."); } - } - constants = visibleValues; + if (labelText == null) { + throw new IllegalArgumentException("Parameter 'labelText' must not be null."); + } + if (enumClass == null) { + throw new IllegalArgumentException("Parameter 'enumClass' must not be null."); + } + if (visibleValues != null && visibleValues.length == 0) { + throw new IllegalArgumentException("Parameter 'visibleValues' must not be empty"); + } + label = new Label(parent, SWT.NONE); + label.setText(labelText); + combo = new Combo(parent, SWT.DROP_DOWN); + + ResourceBundle resourceBundle; + try { + // TODO Remove when all bundles have been changed to "OSGI-INF/l10n/bundle" + resourceBundle = ResourceBundle.getBundle("plugin", Locale.getDefault(), enumClass.getClassLoader()); + } catch (java.util.MissingResourceException mre) { + resourceBundle = ResourceBundle.getBundle("OSGI-INF/l10n/bundle", Locale.getDefault(), + enumClass.getClassLoader()); + } + + T[] constants = enumClass.getEnumConstants(); + + if (constants.length == 0) { + throw new IllegalArgumentException("Enum class '" + enumClass + "' has no constants."); + } + + // Ensure all visible values are contained in the set of constants. + if (visibleValues != null) { + for (int i = 0; i < visibleValues.length; i++) { + T visibleValue = visibleValues[i]; + boolean found = false; + for (int j = 0; j < constants.length; j++) { + if (constants[j] == visibleValue) { + found = true; + continue; + } + } + if (!found) { + throw new IllegalArgumentException( + "Parameter 'visibleValues' contain the undefined value '" + visibleValue + "'."); + } + } + constants = visibleValues; + } + + // Read the localized texts and create the entries. + entries = new ArrayList>(constants.length); + for (int i = 0; i < constants.length; i++) { + Entry entry = new Entry(); + entry.constant = constants[i]; + entry.name = constants[i].name(); + String key = enumClass.getName() + "." + entry.name; + try { + entry.text = resourceBundle.getString(key); + } catch (MissingResourceException ex) { + entry.text = entry.name + " - Text missing"; + BasePlugin.getInstance().logError("Resource for enum value {0} is missing.", new Object[] { key }, ex); + } + + entries.add(entry); + } + + for (Entry entry : entries) { + combo.add(entry.text); + } + combo.select(0); + } - // Read the localized texts and create the entries. - entries = new ArrayList>(constants.length); - for (int i = 0; i < constants.length; i++) { - Entry entry = new Entry(); - entry.constant = constants[i]; - entry.name = constants[i].name(); - String key = enumClass.getName() + "." + entry.name; - try { - entry.text = resourceBundle.getString(key); - } catch (MissingResourceException ex) { - entry.text = entry.name + " - Text missing"; - BasePlugin.getInstance().logError("Resource for enum value {0} is missing.", new Object[] { key }, ex); - } - - entries.add(entry); + /** + * {@inheritDoc} + */ + @Override + public Control getControl() { + return combo; } - for (Entry entry : entries) { - combo.add(entry.text); + /** + * {@inheritDoc} + */ + @Override + public void setEnabled(boolean enabled) { + label.setEnabled(enabled); + combo.setEnabled(enabled); + } - combo.select(0); - } - - /** - * {@inheritDoc} - */ - @Override - public Control getControl() { - return combo; - } - - /** - * {@inheritDoc} - */ - @Override - public void setEnabled(boolean enabled) { - label.setEnabled(enabled); - combo.setEnabled(enabled); - - } - - /** - * {@inheritDoc} - */ - @Override - public void setEditable(boolean editable) { - // There is only a style SWT#READ_ONLY, but no changeable property - } - - /** - * Sets the value. - * - * @param value - * The value, not null. - */ - public void setValue(T value) { - if (value == null) { - throw new IllegalArgumentException("Parameter 'value' must not be null."); + /** + * {@inheritDoc} + */ + @Override + public void setEditable(boolean editable) { + // There is only a style SWT#READ_ONLY, but no changeable property } - for (int i = 0; i < entries.size(); i++) { - if (value.name().equals(entries.get(i).name)) { - combo.select(i); - break; - } - } - } - /** - * Gets the value. - * - * @return The value, not null. - */ - public T getValue() { - int index; - index = combo.getSelectionIndex(); - if (index == -1) { - throw new IllegalStateException("No item selected"); + /** + * Sets the value. + * + * @param value The value, not null. + */ + public void setValue(T value) { + if (value == null) { + throw new IllegalArgumentException("Parameter 'value' must not be null."); + } + for (int i = 0; i < entries.size(); i++) { + if (value.name().equals(entries.get(i).name)) { + combo.select(i); + break; + } + } } - T result = entries.get(index).constant; - return result; - } - /** - * Adds a selection action. - * - * @param action - * The selection action, not null. - */ - public void addSelectionAction(Action action) { - if (action == null) { - throw new IllegalArgumentException("Parameter 'action' must not be null."); + /** + * Gets the value. + * + * @return The value, not null. + */ + public T getValue() { + int index; + index = combo.getSelectionIndex(); + if (index == -1) { + throw new IllegalStateException("No item selected"); + } + T result = entries.get(index).constant; + return result; } - combo.addSelectionListener(action); - } + /** + * Adds a selection action. + * + * @param action The selection action, not null. + */ + public void addSelectionAction(Action action) { + if (action == null) { + throw new IllegalArgumentException("Parameter 'action' must not be null."); + } + combo.addSelectionListener(action); + + } } diff --git a/com.wudsn.ide.hex/plugin.properties b/com.wudsn.ide.hex/OSGI-INF/l10n/bundle.properties similarity index 100% rename from com.wudsn.ide.hex/plugin.properties rename to com.wudsn.ide.hex/OSGI-INF/l10n/bundle.properties diff --git a/com.wudsn.ide.hex/plugin_de_DE.properties b/com.wudsn.ide.hex/OSGI-INF/l10n/bundle_de_DE.properties similarity index 100% rename from com.wudsn.ide.hex/plugin_de_DE.properties rename to com.wudsn.ide.hex/OSGI-INF/l10n/bundle_de_DE.properties