[Schmitzm-commits] r2377 - trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sat Jul 27 19:13:45 CEST 2013


Author: mojays
Date: 2013-07-27 19:13:45 +0200 (Sat, 27 Jul 2013)
New Revision: 2377

Modified:
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java
Log:
Methods moved from WimeSwingUtil to GUIUtil (in SCHMITZM-HIBERNATE)

Modified: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java	2013-07-27 15:14:55 UTC (rev 2376)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java	2013-07-27 17:13:45 UTC (rev 2377)
@@ -13,6 +13,7 @@
 import de.schmitzm.db.hibernate.DBUtil;
 import de.schmitzm.db.hibernate.HibernateSessionFactory;
 import de.schmitzm.db.hibernate.types.BasicType;
+import de.schmitzm.db.hibernate.types.BasicTypeInterface;
 import de.schmitzm.swing.Disposable;
 import de.schmitzm.swing.EditableComboBox;
 import de.schmitzm.swing.LimitedDocument;
@@ -24,7 +25,7 @@
  * of a {@link BasicType} in the database.
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
  */
-public class BasicTypeComboBox<F extends BasicType> extends EditableComboBox implements Disposable {
+public class BasicTypeComboBox<F extends BasicTypeInterface> extends EditableComboBox implements Disposable {
   
   /** Contains the {@link BasicType} (Enum) of the combo box. */
   protected Class<F> basicType;

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-27 15:14:55 UTC (rev 2376)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/GUIUtil.java	2013-07-27 17:13:45 UTC (rev 2377)
@@ -30,18 +30,29 @@
 package de.schmitzm.db.hibernate.gui;
 
 import java.awt.Component;
+import java.awt.event.ItemListener;
+import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 
 import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JList;
 import javax.swing.JOptionPane;
 
 import org.hibernate.Session;
 import org.hibernate.Transaction;
 
 import de.schmitzm.db.hibernate.DBUtil;
+import de.schmitzm.db.hibernate.types.BasicTypeInterface;
 import de.schmitzm.lang.LangUtil;
 import de.schmitzm.lang.ResourceProvider;
+import de.schmitzm.swing.EditableComboBox;
 import de.schmitzm.swing.SwingUtil;
+import de.schmitzm.swing.input.MultipleOptionPane;
+import de.schmitzm.swing.input.SelectionInputOption;
+import de.schmitzm.swing.tree.EditableNode;
 
 /**
  * Utility GUI method for working with Hibernate.
@@ -149,4 +160,90 @@
       return true;
   }
 
+  /**
+   * Creates a {@link SelectionInputOption} (for {@link MultipleOptionPane}) of
+   * 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;
+      }
+    };
+    
+    return inputOption;
+  }
+
+  /**
+   * Creates a {@link SelectionInputOption} (for {@link MultipleOptionPane}) of
+   * a {@link BasicTypeInterface BasicType} as {@link JList}.
+   */
+  public static <E extends BasicTypeInterface> SelectionInputOption<E> createBasicTypeListInputOption(Class<E> type, String label, boolean inputNeeded, E defaultValue) {
+    return createBasicTypeListInputOption(type, label, inputNeeded, defaultValue, 100, 80);
+  }
+
+  /**
+   * Creates a {@link SelectionInputOption} (for {@link MultipleOptionPane}) of
+   * a {@link BasicTypeInterface BasicType} as {@link JList}.
+   */
+  public static <E extends BasicTypeInterface> SelectionInputOption<E> createBasicTypeListInputOption(Class<E> type, String label, boolean inputNeeded, E defaultValue, int width, int height) {
+    List<E> valuesList = DBUtil.determineAllBasicTypes(type);
+    E[] values = (E[])valuesList.toArray(new BasicTypeInterface[0]);
+    LangUtil.sort(values);
+    SelectionInputOption<E> inputOption = new SelectionInputOption.List<E>(
+        label,
+        inputNeeded,
+        values,
+        null,
+        null,
+        height,
+        width
+    );
+    
+    return inputOption;
+  }
+
+  /**
+   * Creates a {@link SelectionInputOption} (for {@link MultipleOptionPane}) of
+   * a {@link BasicTypeInterface BasicType} as {@link JList} with the option to
+   * select multiple values.
+   */
+  public static <E extends BasicTypeInterface> SelectionInputOption<E> createBasicTypeMultiListInputOption(Class<E> type, String label, boolean inputNeeded, Collection<E> defaultValues, int width, int height) {
+    List<E> valuesList = DBUtil.determineAllBasicTypes(type);
+    E[] values = (E[])valuesList.toArray(new BasicTypeInterface[0]);
+    LangUtil.sort(values);
+    SelectionInputOption.MultiList<E> inputOption = new SelectionInputOption.MultiList<E>(
+        label,
+        inputNeeded,
+        values,
+        null,
+        null,
+        height,
+        width
+    );
+    inputOption.setSelectedItems(defaultValues);
+    return inputOption;
+  }
+
+  /**
+   * Creates a {@link SelectionInputOption} (for {@link MultipleOptionPane}) of
+   * a {@link BasicTypeInterface BasicType} as {@link JList} with the option to
+   * select multiple values.
+   */
+  public static <E extends BasicTypeInterface> SelectionInputOption<E> createBasicTypeMultiListInputOption(Class<E> type, String label, boolean inputNeeded, E defaultValue, int width, int height) {
+    SelectionInputOption<E> inputOption = createBasicTypeMultiListInputOption(type, label, inputNeeded, (Collection<E>)null, width, height);
+    inputOption.setSelectedItem(defaultValue);
+    return inputOption;
+  }
 }



More information about the Schmitzm-commits mailing list