[Schmitzm-commits] r2382 - in trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate: . gui
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sat Aug 3 14:17:25 CEST 2013
Author: mojays
Date: 2013-08-03 14:17:24 +0200 (Sat, 03 Aug 2013)
New Revision: 2382
Modified:
trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/DBUtil.java
trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java
trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java
Log:
DBUtil.determineAllRecords(.): extended to specify multiple ordering criteria
BasicTypeInputOption: array initialization by LangUtil.createGenericsArray(.)
BasicTypeComboBox: handle piped renderer for automatic ToolTipComboBoxRenderer
Modified: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/DBUtil.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/DBUtil.java 2013-08-03 12:13:20 UTC (rev 2381)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/DBUtil.java 2013-08-03 12:17:24 UTC (rev 2382)
@@ -229,7 +229,7 @@
* @param type type to determine the instances for
* @param filter filter to apply
*/
- public static <E extends Object> List<E> determineAllRecords(Session session, Class<E> type, Criterion filter, Order order) {
+ public static <E extends Object> List<E> determineAllRecords(Session session, Class<E> type, Criterion filter, Order... order) {
// if no session is specified, use the global session
if ( session == null )
session = getGlobalSession();
@@ -241,7 +241,8 @@
if (filter != null)
query.add(filter);
if (order != null)
- query.addOrder(order);
+ for (Order o : order)
+ query.addOrder(o);
return (List<E>) query.list();
}
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-08-03 12:13:20 UTC (rev 2381)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeComboBox.java 2013-08-03 12:17:24 UTC (rev 2382)
@@ -1,14 +1,19 @@
package de.schmitzm.db.hibernate.gui;
import java.awt.event.KeyEvent;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.swing.JComboBox;
import javax.swing.JTextField;
+import javax.swing.ListCellRenderer;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
import de.schmitzm.db.hibernate.DBUtil;
import de.schmitzm.db.hibernate.HibernateSessionFactory;
@@ -46,6 +51,7 @@
this.basicType = basicType;
this.nullable = nullable;
updateOptions();
+ setPrototypeDisplayValue("DUMMY");
setEditable(editable);
setSelectedItem(defValue);
addItemListener( ToolTipItemListener.INSTANCE ); // Tooltip depending on selected item
@@ -54,28 +60,6 @@
// textField.setDocument( new LimitedDocument(DBUtil.getBasicTypeDescrMaxSize(basicType)) );
}
- /**
- * Sets a restriction for the manual input of the combo box.
- * @param limit maximum number of allowed characters
- * @param style character restriction (see {@link LimitedDocument})
- * @see #getEditor()
- * @see JTextField#setDocument(javax.swing.text.Document)
- * @see LimitedDocument
- */
- public void limitInput(int limit, int style) {
- // Limit input
- JTextField textField = (JTextField)getEditor().getEditorComponent();
- textField.setDocument( new LimitedDocument(limit, style) );
- }
-
- /**
- * Sets the tooltip to the manually entered value.
- */
- @Override
- public void keyReleased(KeyEvent e) {
- super.keyReleased(e);
- setToolTipText(((JTextField)getEditor().getEditorComponent()).getText());
- }
/**
@@ -109,6 +93,29 @@
}
/**
+ * Sets a restriction for the manual input of the combo box.
+ * @param limit maximum number of allowed characters
+ * @param style character restriction (see {@link LimitedDocument})
+ * @see #getEditor()
+ * @see JTextField#setDocument(javax.swing.text.Document)
+ * @see LimitedDocument
+ */
+ public void limitInput(int limit, int style) {
+ // Limit input
+ JTextField textField = (JTextField)getEditor().getEditorComponent();
+ textField.setDocument( new LimitedDocument(limit, style) );
+ }
+
+ /**
+ * Sets the tooltip to the manually entered value.
+ */
+ @Override
+ public void keyReleased(KeyEvent e) {
+ super.keyReleased(e);
+ setToolTipText(((JTextField)getEditor().getEditorComponent()).getText());
+ }
+
+ /**
* Returns the {@link BasicType} of the combo box.
*/
public Class<F> getBasicType() {
@@ -151,6 +158,31 @@
}
/**
+ * Sets the renderer to render the list items.
+ */
+ @Override
+ public void setRenderer(ListCellRenderer renderer) {
+ ListCellRenderer oldRenderer = getRenderer();
+ // if possible keep the existing ToolTip renderer; just replace
+ // its piped renderer
+ if ( oldRenderer instanceof ToolTipComboBoxRenderer &&
+ !(renderer instanceof ToolTipComboBoxRenderer) )
+ ((ToolTipComboBoxRenderer)oldRenderer).setPipedRenderer(renderer);
+ else
+ super.setRenderer(renderer);
+ }
+
+ /**
+ * Determines all basic type instances from database. Used by {@link #updateOptions(Criterion)}.
+ * Sub classes can override this method, e.g. to implement a special order or a static filter
+ * criterion.
+ */
+ protected Collection<F> determineAllBasicTypes(Criterion filter) {
+ List<F> basicTypes = DBUtil.determineAllBasicTypes(null, getBasicType(),filter);
+ return basicTypes;
+ }
+
+ /**
* Updates the combo box selection options from database.
*/
public void updateOptions(Criterion filter) {
@@ -158,11 +190,16 @@
if ( isNullable() )
addItem(null);
Map<Object,String> tooltips = new HashMap<Object, String>();
- for ( F basicTypeInst : DBUtil.determineAllBasicTypes(null, getBasicType(),filter) ) {
+ for ( F basicTypeInst : determineAllBasicTypes(filter) ) {
tooltips.put(basicTypeInst,basicTypeInst.toString());
addItem(basicTypeInst);
}
- setRenderer(new ToolTipComboBoxRenderer(tooltips));
+ // if current renderer already is a ToolTipComboBoxRenderer, we have
+ // to create the new one (with the new tooltips) with the same piped
+ // renderer as used before!
+ ListCellRenderer oldRenderer = getRenderer();
+ ListCellRenderer pipedRenderer = ( oldRenderer instanceof ToolTipComboBoxRenderer ) ? ((ToolTipComboBoxRenderer)oldRenderer).getPipedRenderer() : null;
+ setRenderer(new ToolTipComboBoxRenderer(pipedRenderer,tooltips));
}
/**
Modified: 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 2013-08-03 12:13:20 UTC (rev 2381)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/BasicTypeInputOption.java 2013-08-03 12:17:24 UTC (rev 2382)
@@ -34,6 +34,7 @@
import javax.swing.JComboBox;
import de.schmitzm.db.hibernate.types.BasicTypeInterface;
+import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.input.SelectionInputOption;
/**
@@ -47,7 +48,7 @@
* new inner classes "List" and "MultiList"
* @author Martin O.J. Schmitz
*/
-public abstract class BasicTypeInputOption<E extends BasicTypeInterface> extends SelectionInputOption<E> {
+public abstract class BasicTypeInputOption<F extends BasicTypeInterface> extends SelectionInputOption<F> {
/**
* {@link SelectionInputOption} in form of {@link BasicTypeComboBox} which selection items
@@ -86,7 +87,7 @@
BasicTypeComboBox<E> basicTypeComboBox = (BasicTypeComboBox<E>)getInputComponent();
basicTypeComboBox.updateOptions();
// Update arrays used by super class
- selectionObject = new Object[basicTypeComboBox.getItemCount()];
+ selectionObject = LangUtil.createGenericsArray(basicTypeComboBox.getItemCount());
displayObject = new Object[basicTypeComboBox.getItemCount()];
for (int i=0; i<selectionObject.length; i++) {
E b = (E)basicTypeComboBox.getItemAt(i);
More information about the Schmitzm-commits
mailing list