[Schmitzm-commits] r2379 - in trunk: schmitzm-core/src/main/java/de/schmitzm/swing/input schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Jul 29 17:39:38 CEST 2013


Author: mojays
Date: 2013-07-29 17:39:38 +0200 (Mon, 29 Jul 2013)
New Revision: 2379

Added:
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java
Log:
SelectionInputOption: new parameter-less constructors (protected for internal use)
new BasicTypeInputOption

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2013-07-29 14:52:04 UTC (rev 2378)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2013-07-29 15:39:38 UTC (rev 2379)
@@ -76,6 +76,14 @@
   protected Map<Object,String> displayToolTip  = new HashMap<Object, String>();
 
   /**
+   * Erzeugt eine neue Eingabe-Option. {@link #init(String, boolean, boolean)}
+   * muss nachtraeglich aufgerufen werden!
+   */
+  protected SelectionInputOption() {
+    super();
+  }
+
+  /**
    * Erzeugt eine neue Eingabe-Option.
    * @param label       Beschreibung
    * @param inputNeeded gibt an, ob eine Eingabe erforderlich ist
@@ -317,6 +325,14 @@
    */
   public static class Combo<E> extends SelectionInputOption {
     /**
+     * Erzeugt eine neue Eingabe-Option. {@link #init(String, boolean, boolean)}
+     * muss nachtraeglich aufgerufen werden!
+     */
+    protected Combo() {
+      super();
+    }
+
+    /**
      * Erzeugt eine neue Auswahl-Option.
      * @param label       Beschreibung
      * @param inputNeeded gibt an, ob eine Eingabe erforderlich ist
@@ -485,6 +501,14 @@
     private ActionListener actionListener;
     
     /**
+     * Erzeugt eine neue Eingabe-Option. {@link #init(String, boolean, boolean)}
+     * muss nachtraeglich aufgerufen werden!
+     */
+    protected Radio() {
+      super();
+    }
+
+    /**
      * Erzeugt eine neue Auswahl-Option.
      * @param label       Beschreibung
      * @param inputNeeded gibt an, ob eine Eingabe erforderlich ist
@@ -640,6 +664,13 @@
    * @version 1.0
    */
   public static class List<E> extends SelectionInputOption {
+    /**
+     * Erzeugt eine neue Eingabe-Option. {@link #init(String, boolean, boolean)}
+     * muss nachtraeglich aufgerufen werden!
+     */
+    protected List() {
+      super();
+    }
 
     /**
      * Erzeugt eine neue Auswahl-Option.
@@ -837,6 +868,13 @@
    * @version 1.0
    */
   public static class MultiList<E> extends List {
+    /**
+     * Erzeugt eine neue Eingabe-Option. {@link #init(String, boolean, boolean)}
+     * muss nachtraeglich aufgerufen werden!
+     */
+    protected MultiList() {
+      super();
+    }
 
     /**
      * Erzeugt eine neue Auswahl-Option.

Added: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java	                        (rev 0)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java	2013-07-29 15:39:38 UTC (rev 2379)
@@ -0,0 +1,123 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.db.hibernate.gui;
+
+import java.awt.event.ItemListener;
+
+import javax.swing.JComboBox;
+
+import de.schmitzm.db.hibernate.types.BasicTypeInterface;
+import de.schmitzm.swing.input.SelectionInputOption;
+
+/**
+ * This class represents a {@link SelectionInputOption} which selection items are defined
+ * by database {@link BasicTypeInterface BasicType}.
+ * The class itself does not implement any functionallty. To remain analogous with {@link SelectionInputOption}
+ * the inner classes have to be instantiated, e.g. {@link Combo}.<br>
+ * <br> 
+ * TODO: replace {@link GUIUtil#createBasicTypeListInputOption(Class, String, boolean, BasicTypeInterface, int, int)} and
+ *       {@link GUIUtil#createBasicTypeMultiListInputOption(Class, String, boolean, java.util.Collection, int, int)} by
+ *       new inner classes "List" and "MultiList"
+ * @author Martin O.J. Schmitz
+ */
+public abstract class BasicTypeInputOption<E extends BasicTypeInterface> extends SelectionInputOption<E> {
+  
+  /**
+   * {@link SelectionInputOption} in form of {@link BasicTypeComboBox} which selection items
+   * base on database {@link BasicTypeInterface BasicType}. 
+   * @author Martin O.J. Schmitz
+   */
+  public static class Combo<E extends BasicTypeInterface> extends SelectionInputOption.Combo<E> {
+    /** Hold the basic type represented by input option. */
+    protected Class<E> basicType;
+    /** Indicated whether the {@link JComboBox} is editable manually. */
+    protected boolean  editable;
+
+     /**
+      * Creates a new input option-
+      * @param type basic type which defines the selection values
+      * @param label label for the input option
+      * @param inputNeeded indicates whether the input is mandatory
+      * @param defaultValue default selection
+      * @param editable indicates whether the input can be specified by manual text input (a new item is
+      *                 NOT automatically added to database!)
+      */
+    public Combo(Class<E> type, String label, boolean inputNeeded, E defaultValue, boolean editable) {
+      super();
+      this.basicType = type;
+      this.editable  = editable;
+      init(label, inputNeeded, true);
+      performSelectionUpdate();
+      setValue(defaultValue);
+    }
+  
+    /**
+     * Updates the selection items from database.
+     */
+    @Override
+    protected void performSelectionUpdate() {
+      BasicTypeComboBox<E> basicTypeComboBox = (BasicTypeComboBox<E>)getInputComponent();
+      basicTypeComboBox.updateOptions();
+      // Update arrays used by super class
+      selectionObject = new Object[basicTypeComboBox.getItemCount()];
+      displayObject   = new Object[basicTypeComboBox.getItemCount()];
+      for (int i=0; i<selectionObject.length; i++) {
+        E b = (E)basicTypeComboBox.getItemAt(i);
+        selectionObject[i] = b;
+        displayObject[i]   = b;
+      }
+    }
+  
+    /**
+     * Creates the input component.
+     * @return instance of {@link BasicTypeComboBox}
+     */
+    @Override
+    protected BasicTypeComboBox<E> createInputComponent() {
+      BasicTypeComboBox<E> comboBox = new BasicTypeComboBox<E>(basicType,!inputNeeded(),null,editable);
+      for (ItemListener l : super.createInputComponent().getItemListeners())
+        comboBox.addItemListener(l);
+      return comboBox;
+    }
+    
+    /**
+     * Returns the current value. If input option is editable and a manual text input
+     * was made a new {@link BasicTypeInterface BasicType} instance is returned (which is
+     * NOT automatically added to database!)
+     */
+    @Override
+    protected E performGetValue() {
+      E value = (E)super.performGetValue();
+      if ( value == null && editable )
+        value = ((BasicTypeComboBox<E>)getInputComponent()).getSelectedItem();
+      return value;
+    }
+  }
+}

Modified: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java	2013-07-29 14:52:04 UTC (rev 2378)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java	2013-07-29 15:39:38 UTC (rev 2379)
@@ -165,23 +165,30 @@
    * a {@link BasicTypeInterface BasicType} as {@link JComboBox}.
    */
   public static <E extends BasicTypeInterface> SelectionInputOption<E> createBasicTypeInputOption(final Class<E> type, String label, final boolean inputNeeded, final E defaultValue, final boolean editable) {
-    List<E> valuesList = DBUtil.determineAllBasicTypes(type);
-    E[] values = (E[])valuesList.toArray(new BasicTypeInterface[0]);
-    SelectionInputOption<E> inputOption = new SelectionInputOption.Combo<E>(
-        label,
-        inputNeeded,
-        values,
-        null
-    ) {
-      @Override
-      protected BasicTypeComboBox<E> createInputComponent() {
-        BasicTypeComboBox<E> comboBox = new BasicTypeComboBox<E>(type,!inputNeeded,defaultValue,editable);
-        for (ItemListener l : super.createInputComponent().getItemListeners())
-          comboBox.addItemListener(l);
-        return comboBox;
-      }
-    };
-    
+//    List<E> valuesList = DBUtil.determineAllBasicTypes(type);
+//    E[] values = (E[])valuesList.toArray(new BasicTypeInterface[0]);
+//    SelectionInputOption<E> inputOption = new SelectionInputOption.Combo<E>(
+//        label,
+//        inputNeeded,
+//        values,
+//        null
+//    ) {
+//      @Override
+//      protected BasicTypeComboBox<E> createInputComponent() {
+//        BasicTypeComboBox<E> comboBox = new BasicTypeComboBox<E>(type,!inputNeeded,defaultValue,editable);
+//        for (ItemListener l : super.createInputComponent().getItemListeners())
+//          comboBox.addItemListener(l);
+//        return comboBox;
+//      }
+//      @Override
+//      protected E performGetValue() {
+//        E value = (E)super.performGetValue();
+//        if ( value == null && editable )
+//          value = ((BasicTypeComboBox<E>)getInputComponent()).getSelectedItem();
+//        return value;
+//      }
+//    };
+    BasicTypeInputOption.Combo<E> inputOption = new BasicTypeInputOption.Combo<E>(type, label, inputNeeded, defaultValue, editable);
     return inputOption;
   }
 



More information about the Schmitzm-commits mailing list