r3607 - in branches/4.1/src/main: java/fr/ifremer/isisfish/datastore/migration java/fr/ifremer/isisfish/ui/input/variable xmi
Author: echatellier Date: 2012-02-15 11:24:56 +0100 (Wed, 15 Feb 2012) New Revision: 3607 Url: http://forge.codelutin.com/repositories/revision/isis-fish/3607 Log: Udpate variable UI Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV40V41.java branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableUI.jaxx branches/4.1/src/main/xmi/isis-fish.properties Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV40V41.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV40V41.java 2012-02-15 09:22:14 UTC (rev 3606) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV40V41.java 2012-02-15 10:24:56 UTC (rev 3607) @@ -66,7 +66,7 @@ "TOPIAID VARCHAR(255) NOT NULL, " + "TOPIAVERSION BIGINT NOT NULL, " + "TOPIACREATEDATE DATE, " + - "ENTITYID VARCHAR(255), " + + "ENTITYID VARCHAR(255) NOT NULL, " + "NAME LONGVARCHAR, " + "TYPE LONGVARCHAR, " + "DOUBLEVALUE DOUBLE, " + Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java 2012-02-15 09:22:14 UTC (rev 3606) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java 2012-02-15 10:24:56 UTC (rev 3607) @@ -32,6 +32,8 @@ import javax.swing.JList; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; @@ -55,6 +57,9 @@ */ public class EntityVariableHandler { + /** Class logger. */ + private static Log log = LogFactory.getLog(EntityVariableHandler.class); + /** * Init view with currently entity variables. * @@ -62,6 +67,10 @@ */ public void initView(EntityVariableUI view) { + // clear previous + view.getVariablesList().clearSelection(); + + // fill current list List<Variable> variables = null; TopiaEntityListModel model = (TopiaEntityListModel)view.getVariablesList().getModel(); TopiaEntity bean = view.getBean(); @@ -88,19 +97,51 @@ TopiaContext context = view.getTopiaContext(); VariableDAO dao = IsisFishDAOHelper.getVariableDAO(context); - Variable variable = dao.create("name", _("isisfish.variables.defaultname"), - "type", "double"); + Variable variable = dao.create( + Variable.PROPERTY_ENTITY_ID, view.getBean().getTopiaId(), + Variable.PROPERTY_NAME, _("isisfish.variables.defaultname"), + Variable.PROPERTY_TYPE, "double"); TopiaEntityListModel model = (TopiaEntityListModel)view.getVariablesList().getModel(); List<Variable> variables = (List<Variable>)model.getElements(); variables.add(variable); model.setEntities(variables); + + // auto select + view.getVariablesList().setSelectedValue(variable, true); } catch (TopiaException ex) { throw new IsisFishRuntimeException("Can't add variable", ex); } } /** + * Delete selected variable. + * + * @param view view + */ + public void deleteVariable(EntityVariableUI view) { + JList variableList = view.getVariablesList(); + Variable variable = (Variable)variableList.getSelectedValue(); + + try { + // delete in db + TopiaContext context = view.getTopiaContext(); + VariableDAO dao = IsisFishDAOHelper.getVariableDAO(context); + dao.delete(variable); + context.commitTransaction(); + + // refresh ui + view.getVariablesList().clearSelection(); // fix event bug + TopiaEntityListModel model = (TopiaEntityListModel)view.getVariablesList().getModel(); + List<Variable> variables = (List<Variable>)model.getElements(); + variables.remove(variable); + model.setEntities(variables); + } catch (TopiaException ex) { + throw new IsisFishRuntimeException("Can't delete variable", ex); + } + } + + /** * Display selected variable for edition. * * @param view view @@ -109,11 +150,21 @@ JList variableList = view.getVariablesList(); Variable variable = (Variable)variableList.getSelectedValue(); + view.setVariable(variable); if (variable != null) { view.getVariableNameField().setText(variable.getName()); - view.getVariableTypeCombo().setSelectedItem(variable.getType()); + + String type = variable.getType(); + view.getVariableTypeCombo().setSelectedItem(type); // fire showSelectedType + + if ("double".equals(type)) { + view.getVariableDoubleValue().setText(String.valueOf(variable.getDoubleValue())); + } else if ("matrix".equals(type)) { + //cardLayout.show(view.getVariableTypePanel(), "matrixtype"); + } else if ("equation".equals(type)) { + //cardLayout.show(view.getVariableTypePanel(), "equationtype"); + } } - } /** @@ -142,12 +193,19 @@ JList variableList = view.getVariablesList(); Variable variable = (Variable)variableList.getSelectedValue(); variable.setName(view.getVariableNameField().getText().trim()); - + String type = (String)view.getVariableTypeCombo().getSelectedItem(); variable.setType((String)view.getVariableTypeCombo().getSelectedItem()); - + if ("double".equals(type)) { - variable.setDoubleValue(0); + try { + double v = Double.parseDouble(view.getVariableDoubleValue().getText().trim()); + variable.setDoubleValue(v); + } catch (NumberFormatException ex) { + if (log.isWarnEnabled()) { + log.warn("Can't parse double value as double", ex); + } + } } else if ("matrix".equals(type)) { variable.setMatrixValue(view.getMatrixPanel().getMatrix()); } else if ("equation".equals(type)) { @@ -158,5 +216,20 @@ eq.setContent(view.getVariableDoubleValue().getText()); variable.setEquationValue(eq); } + + try { + // save in db + TopiaContext context = view.getTopiaContext(); + VariableDAO dao = IsisFishDAOHelper.getVariableDAO(context); + dao.update(variable); + context.commitTransaction(); + + // refresh ui (name change) + TopiaEntityListModel model = (TopiaEntityListModel)view.getVariablesList().getModel(); + List<Variable> variables = (List<Variable>)model.getElements(); + model.setEntities(variables); + } catch (TopiaException ex) { + throw new IsisFishRuntimeException("Can't save variable", ex); + } } } Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableUI.jaxx =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableUI.jaxx 2012-02-15 09:22:14 UTC (rev 3606) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableUI.jaxx 2012-02-15 10:24:56 UTC (rev 3607) @@ -29,6 +29,8 @@ <!-- bean property --> <org.nuiton.topia.persistence.TopiaEntityContextable id='bean' javaBean='null'/> + <fr.ifremer.isisfish.entities.Variable id="variable" javaBean='null' /> + <script><![CDATA[ protected void $afterCompleteSetup() { addPropertyChangeListener(PROPERTY_BEAN, new java.beans.PropertyChangeListener() { @@ -48,13 +50,15 @@ <JScrollPane> <JList id="variablesList" cellRenderer="{new VariableListRenderer()}" model="{new fr.ifremer.isisfish.ui.input.model.TopiaEntityListModel()}" - onValueChanged="getVarHandler().showSelectedVariable(this)"/> + onValueChanged="getVarHandler().showSelectedVariable(this)" + enabled='{isActive()}'/> </JScrollPane> </cell> </row> <row> <cell fill="horizontal"> - <JButton text="isisfish.variables.addvariable" onActionPerformed="getVarHandler().addNewVariable(this)" /> + <JButton text="isisfish.variables.addvariable" onActionPerformed="getVarHandler().addNewVariable(this)" + enabled='{isActive()}'/> </cell> </row> </Table> @@ -63,19 +67,23 @@ <Table border='{BorderFactory.createTitledBorder(_("isisfish.variables.variabledetail"))}'> <row> <cell fill="horizontal"> - <JLabel text="isisfish.variables.variablename" /> + <JLabel text="isisfish.variables.variablename" + enabled='{isActive() && getVariable() != null}'/> </cell> <cell fill="horizontal" weightx='1.0'> - <JTextField id="variableNameField" /> + <JTextField id="variableNameField" + enabled='{isActive() && getVariable() != null}'/> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="isisfish.variables.variabletype" /> + <JLabel text="isisfish.variables.variabletype" + enabled='{isActive() && getVariable() != null}'/> </cell> <cell fill="horizontal" weightx='1.0'> <JComboBox id="variableTypeCombo" model="{new VariableTypeComboModel()}" - onActionPerformed="getVarHandler().showSelectedType(this)"/> + onActionPerformed="getVarHandler().showSelectedType(this)" + enabled='{isActive() && getVariable() != null}'/> </cell> </row> <row> @@ -87,10 +95,10 @@ <Table constraints='"doubletype"'> <row> <cell fill="horizontal" anchor="northeast" weighty='1.0'> - <JLabel text="isisfish.variables.double.value" /> + <JLabel text="isisfish.variables.double.value" enabled='{isActive() && getVariable() != null}' /> </cell> <cell fill="horizontal" weightx='1.0' anchor="northeast" weighty='1.0'> - <JTextField id="variableDoubleValue" /> + <JTextField id="variableDoubleValue" enabled='{isActive() && getVariable() != null}' /> </cell> </row> </Table> @@ -99,12 +107,14 @@ <Table constraints='"matrixtype"'> <row> <cell fill="horizontal"> - <JLabel text="isisfish.variables.matrix.value" /> + <JLabel text="isisfish.variables.matrix.value" + enabled='{isActive() && getVariable() != null}'/> </cell> </row> <row> <cell fill="both" weightx='1.0' weighty='1.0'> - <org.nuiton.math.matrix.gui.MatrixPanelEditor id="matrixPanel" /> + <org.nuiton.math.matrix.gui.MatrixPanelEditor id="matrixPanel" + enabled='{isActive() && getVariable() != null}'/> </cell> </row> </Table> @@ -113,7 +123,8 @@ <Table constraints='"equationtype"'> <row> <cell fill="both" weightx='1.0' weighty='1.0'> - <fr.ifremer.isisfish.ui.input.InputOneEquationUI id="variableEquationValue" /> + <fr.ifremer.isisfish.ui.input.InputOneEquationUI id="variableEquationValue" + active='{isActive() && getVariable() != null}'/> </cell> </row> </Table> @@ -122,10 +133,14 @@ </row> <row> <cell anchor="west"> - <JButton text="isisfish.variables.deletevariable" /> + <JButton text="isisfish.variables.deletevariable" + onActionPerformed="getVarHandler().deleteVariable(this)" + enabled='{isActive() && getVariable() != null}'/> </cell> <cell anchor="east" weightx='1.0'> - <JButton text="isisfish.variables.savevariable" /> + <JButton text="isisfish.variables.savevariable" + onActionPerformed="getVarHandler().saveVariable(this)" + enabled='{isActive() && getVariable() != null}'/> </cell> </row> </Table> Modified: branches/4.1/src/main/xmi/isis-fish.properties =================================================================== --- branches/4.1/src/main/xmi/isis-fish.properties 2012-02-15 09:22:14 UTC (rev 3606) +++ branches/4.1/src/main/xmi/isis-fish.properties 2012-02-15 10:24:56 UTC (rev 3607) @@ -53,5 +53,6 @@ fr.ifremer.isisfish.entities.TargetSpecies.class.tagvalue.contextable=true fr.ifremer.isisfish.entities.TripType.class.tagvalue.contextable=true fr.ifremer.isisfish.entities.Variable.class.tagvalue.contextable=true +fr.ifremer.isisfish.entities.Variable.attribute.entityId.tagvalue.notNull=true fr.ifremer.isisfish.entities.VesselType.class.tagvalue.contextable=true fr.ifremer.isisfish.entities.Zone.class.tagvalue.contextable=true
participants (1)
-
echatellier@users.forge.codelutin.com