Author: tchemit Date: 2012-12-30 20:39:00 +0100 (Sun, 30 Dec 2012) New Revision: 132 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/132 Log: - use jaxx last features - clean css - improve table api - improve edit protocol design (at last do not save not valid data :() - try and stop to improve design of pmfm in fishing stuff (need to improve this point!) - start of config - improve start and run of application (sammoa was not a good example to follow...) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java trunk/tutti-ui-swing/src/main/resources/icons/action-reload-application.png trunk/tutti-ui-swing/src/main/resources/icons/action-reload-shortcut.png Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/RunTutti.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryType.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/HydrologicCaracteristicUtil.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueRenderer.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -28,7 +28,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.IdAware; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.config.TuttiConfig; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; @@ -48,7 +47,6 @@ import javax.swing.JList; import javax.swing.ListCellRenderer; -import javax.swing.ListModel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.text.JTextComponent; @@ -58,8 +56,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; @@ -168,7 +164,7 @@ Preconditions.checkNotNull(comboBox, "No comboBox!"); - Class<E> beanType = (Class<E>) comboBox.getHandler().getTargetClass(); + Class<E> beanType = comboBox.getBeanType(); Preconditions.checkNotNull(beanType, "No beanType on the combobox!"); @@ -195,8 +191,8 @@ * pour un service de persistance donné. * * @param list le component graphique à initialiser - * @param data - * @param selectedData + * @param data la liste des données à mettre dans la liste de gauche + * @param selectedData la liste des données à mettre dans la liste de droite */ protected <E extends IdAware> void initBeanList( BeanDoubleList<E> list, @@ -260,36 +256,6 @@ picker.getEditor().setEditable(false); } - protected <B extends IdAware> void updateIndices(JList jlist, - List<B> list) { - - List<String> ids = TuttiEntities.toIds(list); - - List<Integer> indices = new ArrayList<Integer>(); - - if (list != null && !list.isEmpty()) { - - ListModel model = jlist.getModel(); - - for (int i = 0, max = model.getSize(); i < max; i++) { - B s = (B) model.getElementAt(i); - if (ids.contains(s.getId())) { - indices.add(i); - } - } - } - int[] result = new int[indices.size()]; - int i = 0; - for (Integer indice : indices) { - result[i++] = indice; - } - indices.clear(); - if (log.isDebugEnabled()) { - log.debug("Selected indices : " + Arrays.toString(result)); - } - jlist.setSelectedIndices(result); - } - protected <O> Decorator<O> getDecorator(Class<O> type, String name) { DecoratorService decoratorService = context.getService(DecoratorService.class); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -23,103 +23,103 @@ */ #mainFrame { - title: "tutti.application.name"; - defaultCloseOperation: {JFrame.DO_NOTHING_ON_CLOSE}; + title: "tutti.application.name"; + defaultCloseOperation: {JFrame.DO_NOTHING_ON_CLOSE}; } #menuFile { - text: "tutti.menu.file"; - toolTipText: "tutti.menu.file.tip"; - mnemonic: F; + text: "tutti.menu.file"; + toolTipText: "tutti.menu.file.tip"; + mnemonic: F; } #menuFileConfiguration { - text: "tutti.action.configuration"; - toolTipText: "tutti.action.configuration.tip"; - actionIcon: "config"; - mnemonic: C; + text: "tutti.action.configuration"; + toolTipText: "tutti.action.configuration.tip"; + actionIcon: config; + mnemonic: C; } #menuFileExit { - text: "tutti.action.exit"; - toolTipText: "tutti.action.exit.tip"; - actionIcon: "exit"; + text: "tutti.action.exit"; + toolTipText: "tutti.action.exit.tip"; + actionIcon: exit; } #menuActions { - text: "tutti.menu.actions"; - toolTipText: "tutti.menu.actions.tip"; - mnemonic: A; + text: "tutti.menu.actions"; + toolTipText: "tutti.menu.actions.tip"; + mnemonic: A; } #menuActionManageProtocol { - text: "tutti.action.manageProtocol"; - toolTipText: "tutti.action.manageProtocol.tip"; - mnemonic: P; - enabled: {model.getScreen() != TuttiScreen.EDIT_PROTOCOL && model.getProtocolId() != null}; - /*actionIcon: "protocol";*/ + text: "tutti.action.manageProtocol"; + toolTipText: "tutti.action.manageProtocol.tip"; + mnemonic: P; + enabled: {model.getScreen() != TuttiScreen.EDIT_PROTOCOL && model.getProtocolId() != null}; + /*actionIcon: "protocol";*/ } #menuActionSelectCampaign { - text: "tutti.action.selectCampaign"; - toolTipText: "tutti.action.selectCampaign.tip"; - mnemonic: S; - enabled: {model.getScreen() != TuttiScreen.SELECT_CRUISE}; - /*actionIcon: "cruise";*/ + text: "tutti.action.selectCampaign"; + toolTipText: "tutti.action.selectCampaign.tip"; + mnemonic: S; + enabled: {model.getScreen() != TuttiScreen.SELECT_CRUISE}; + /*actionIcon: "cruise";*/ } #menuActionFillCatches { - text: "tutti.action.fillCatches"; - toolTipText: "tutti.action.fillCatches.tip"; - mnemonic: C; - enabled: {model.getScreen() != TuttiScreen.EDIT_FISHING_OPERATION && model.isCruiseContextFilled()}; - /*actionIcon: "catches";*/ + text: "tutti.action.fillCatches"; + toolTipText: "tutti.action.fillCatches.tip"; + mnemonic: C; + enabled: {model.getScreen() != TuttiScreen.EDIT_FISHING_OPERATION && model.isCruiseContextFilled()}; + /*actionIcon: "catches";*/ } #menuSynchronisations { - text: "tutti.menu.synchronisations"; - toolTipText: "tutti.menu.synchronisations.tip"; - mnemonic: S; + text: "tutti.menu.synchronisations"; + toolTipText: "tutti.menu.synchronisations.tip"; + mnemonic: S; } #menuSynchronisationImport { - text: "tutti.menu.synchronisationImport"; - toolTipText: "tutti.menu.synchronisationImport.tip"; - mnemonic: I; - enabled: false; + text: "tutti.menu.synchronisationImport"; + toolTipText: "tutti.menu.synchronisationImport.tip"; + mnemonic: I; + enabled: false; } #menuSynchronisationExport { - text: "tutti.menu.synchronisationExport"; - toolTipText: "tutti.menu.synchronisationExport.tip"; - mnemonic: E; - enabled: false; + text: "tutti.menu.synchronisationExport"; + toolTipText: "tutti.menu.synchronisationExport.tip"; + mnemonic: E; + enabled: false; } #menuSynchronisationAllegro { - text: "tutti.menu.synchronisationAllegro"; - toolTipText: "tutti.menu.synchronisationAllegro.tip"; - mnemonic: A; - enabled: false; + text: "tutti.menu.synchronisationAllegro"; + toolTipText: "tutti.menu.synchronisationAllegro.tip"; + mnemonic: A; + enabled: false; } #menuHelp { - text: "tutti.menu.help"; - toolTipText: "tutti.menu.help.tip"; - mnemonic: E; + text: "tutti.menu.help"; + toolTipText: "tutti.menu.help.tip"; + mnemonic: E; } #menuHelpSite { - text: "tutti.action.site"; - toolTipText: "tutti.action.site.tip"; - actionIcon: "site"; - mnemonic: S; + text: "tutti.action.site"; + toolTipText: "tutti.action.site.tip"; + actionIcon: site; + mnemonic: S; } #menuHelpAbout { - text: "tutti.action.about"; - toolTipText: "tutti.action.about.tip"; - actionIcon: "about"; - mnemonic: A; + text: "tutti.action.about"; + toolTipText: "tutti.action.about.tip"; + actionIcon: about; + mnemonic: A; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -72,13 +72,13 @@ <JMenu id='menuSynchronisations'> - <JMenuItem id='menuSynchronisationImport' - onActionPerformed="getHandler().showImportScreen()"/> - <JMenuItem id='menuSynchronisationExport' - onActionPerformed="getHandler().showExportScreen()"/> - <JMenuItem id='menuSynchronisationAllegro' - onActionPerformed="getHandler().showAllegroScreen()"/> - </JMenu> + <JMenuItem id='menuSynchronisationImport' + onActionPerformed="getHandler().showImportScreen()"/> + <JMenuItem id='menuSynchronisationExport' + onActionPerformed="getHandler().showExportScreen()"/> + <JMenuItem id='menuSynchronisationAllegro' + onActionPerformed="getHandler().showAllegroScreen()"/> + </JMenu> <JMenu id='menuHelp'> <JMenuItem id='menuHelpSite' Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -28,19 +28,16 @@ import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.service.config.TuttiServiceConfigOption; import fr.ifremer.tutti.ui.swing.config.TuttiConfig; -import fr.ifremer.tutti.ui.swing.config.TuttiConfigOption; +import fr.ifremer.tutti.ui.swing.config.TuttiConfigUI; import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUI; import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUI; import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; import fr.ifremer.tutti.ui.swing.content.program.EditProgramUI; import fr.ifremer.tutti.ui.swing.content.protocol.EditProtocolUI; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.AboutPanel; import jaxx.runtime.swing.ErrorDialogUI; -import jaxx.runtime.swing.editor.config.ConfigUIHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; @@ -54,7 +51,6 @@ import java.util.Calendar; import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; /** * @author tchemit <chemit@codelutin.com> @@ -78,6 +74,10 @@ context.addMessageNotifier(this); } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override public void beforeInitUI() { context.addPropertyChangeListener(new PropertyChangeListener() { @@ -129,7 +129,7 @@ @Override public void onCloseUI() { - closeCurrentBody(); +// closeCurrentBody(); context.close(); } @@ -139,94 +139,43 @@ return ui.getModel(); } - public void showConfig() { - TuttiConfig config = context.getConfig(); + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// - ConfigUIHelper helper = new ConfigUIHelper(config.getApplicationConfig()); + public void closeTutti() { + RunTutti.closeTutti(ui, true); + } - helper.registerCallBack( - "ui", n_("tutti.action.reload.ui"), - SwingUtil.createActionIcon("reload-ui"), - new Runnable() { + public void reloadTutti() { - @Override - public void run() { - reloadTutti(); - } - } - ).registerCallBack( - "home", n_("tutti.action.reload.home"), - SwingUtil.createActionIcon("config"), - new Runnable() { + // Close the application + RunTutti.closeTutti(ui, false); - @Override - public void run() { - if (TuttiScreen.SELECT_CRUISE == context.getScreen()) { - // Reselect home cruise -// SelectCampaignUI homeUI = (SelectCampaignUI) currentBody; -// homeUI.getHandler().selectCampaign(); - } - } - } - ).registerCallBack( - "actions", n_("tutti.action.reload.actions"), - SwingUtil.createActionIcon("config"), - new Runnable() { + // Re-open the context +// try { +// context.open(); +// } catch (Exception ex) { +// ErrorDialogUI.showError(ex); +// } - @Override - public void run() { + RunTutti.startTutti(context); + } - //TODO Reload actions shortcuts - } - } - ); + public void reloadApplication() { + //TODO + } - // APPLICATION + public void reloadShortcuts() { + //TODO + } - helper.addCategory(n_("tutti.config.category.applications"), - n_("tutti.config.category.applications.description")) - .addOption(TuttiServiceConfigOption.DATA_DIRECTORY) - .setOptionCallBack("ui"); -// .addOption(TuttiConfigOption.AUTO_COMMIT_DELAY) // milliseconds -// .setOptionCallBack("ui"); + public void showConfig() { - // SHORTCUT - -// helper.addCategory(n_("tutti.config.category.shortcuts"), -// n_("tutti.config.category.shortcuts.description"), "actions") -// .addOption(TuttiConfigOption.KEY_START) -// .addOption(TuttiConfigOption.KEY_STOP) -// .addOption(TuttiConfigOption.KEY_BEGIN) -// .addOption(TuttiConfigOption.KEY_END) -// .addOption(TuttiConfigOption.KEY_NEXT) -// .addOption(TuttiConfigOption.KEY_ADD) -// .addOption(TuttiConfigOption.KEY_LEFT_OBSERVATION) -// .addOption(TuttiConfigOption.KEY_CENTER_OBSERVATION) -// .addOption(TuttiConfigOption.KEY_RIGHT_OBSERVATION) -// .addOption(TuttiConfigOption.KEY_CIRCLE_BACK) -// .addOption(TuttiConfigOption.KEY_VALID_FLIGHT) -// .addOption(TuttiConfigOption.KEY_VALID_TRANSECT) -// .addOption(TuttiConfigOption.KEY_VALID_OBSERVATION) -// .addOption(TuttiConfigOption.KEY_VALID_ROUTE); - - // OTHER - - helper.addCategory(n_("tutti.config.category.other"), - n_("tutti.config.category.other.description")) - .addOption(TuttiServiceConfigOption.SITE_URL) - .addOption(TuttiConfigOption.UI_CONFIG_FILE) - .setOptionCallBack("ui"); - - - helper.buildUI(ui, "tutti.config.category.applications"); - - helper.displayUI(ui, false); + TuttiConfigUI configUI = new TuttiConfigUI(ui); + configUI.createUI(); } - public void closeTutti() { - closeTutti(true); - } - public void showManageProtocol() { context.setScreen(TuttiScreen.EDIT_PROTOCOL); } @@ -314,6 +263,10 @@ ui.getStatus().setStatus(message); } + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + protected void setScreen(TuttiScreen screen) { try { @@ -321,70 +274,80 @@ // busy ui TuttiUIUtil.updateBusyState(ui, true); - // remove any screen -// ui.setScreen(null); + // close current body (if any) + if (currentBody != null) { + TuttiUI<?, ?> body = (TuttiUI<?, ?>) currentBody; + body.getHandler().onCloseUI(); - closeCurrentBody(); + context.getSwingSession().save(); - String programId = context.getProgramId(); - String cruiseId = context.getCruiseId(); - String protocolId = context.getProtocolId(); + ui.getBody().remove(currentBody); - JComponent screenUI; - String screenTitle; + currentBody = null; + } - switch (screen) { - default: - case SELECT_CRUISE: + if (screen != null) { - screenUI = new SelectCruiseUI(context); - screenTitle = _("tutti.title.home"); - break; + String programId = context.getProgramId(); + String cruiseId = context.getCruiseId(); + String protocolId = context.getProtocolId(); - case EDIT_PROGRAM: + JComponent screenUI; + String screenTitle; - if (programId == null) { - screenTitle = _("tutti.title.create.program"); - } else { - screenTitle = _("tutti.title.edit.program"); - } + switch (screen) { + default: + case SELECT_CRUISE: - screenUI = new EditProgramUI(context); - break; + screenUI = new SelectCruiseUI(context); + screenTitle = _("tutti.title.home"); + break; - case EDIT_CRUISE: + case EDIT_PROGRAM: - if (cruiseId == null) { - screenTitle = _("tutti.title.create.cruise"); - } else { - screenTitle = _("tutti.title.edit.cruise"); - } + if (programId == null) { + screenTitle = _("tutti.title.create.program"); + } else { + screenTitle = _("tutti.title.edit.program"); + } - screenUI = new EditCruiseUI(context); - break; + screenUI = new EditProgramUI(context); + break; - case EDIT_PROTOCOL: + case EDIT_CRUISE: - if (protocolId == null) { - screenTitle = _("tutti.title.create.protocol"); - } else { - screenTitle = _("tutti.title.edit.protocol"); - } + if (cruiseId == null) { + screenTitle = _("tutti.title.create.cruise"); + } else { + screenTitle = _("tutti.title.edit.cruise"); + } - screenUI = new EditProtocolUI(context); - break; + screenUI = new EditCruiseUI(context); + break; - case EDIT_FISHING_OPERATION: + case EDIT_PROTOCOL: - screenTitle = _("tutti.title.edit.operations", getSelectedCruiseTitle()); - screenUI = new FishingOperationsUI(context); - break; - } + if (protocolId == null) { + screenTitle = _("tutti.title.create.protocol"); + } else { + screenTitle = _("tutti.title.edit.protocol"); + } - changeScreen(screenUI, screenTitle); + screenUI = new EditProtocolUI(context); + break; - // set new screen only if everything is ok -// ui.setScreen(screen); + case EDIT_FISHING_OPERATION: + + screenTitle = _("tutti.title.edit.operations", getSelectedCruiseTitle()); + screenUI = new FishingOperationsUI(context); + break; + } + + this.currentBody = screenUI; + context.getSwingSession().add(currentBody); + ui.getBody().setTitle(screenTitle); + ui.getBody().add(currentBody); + } } catch (Exception e) { ErrorDialogUI.showError(e); @@ -398,56 +361,20 @@ } } - protected void reloadTutti() { +// protected void closeTutti(boolean exit) { +// +// context.getSwingSession().save(); +// +// ui.setVisible(false); +// ui.dispose(); +// +// onCloseUI(); +// +// if (exit) { +// System.exit(0); +// } +// } - // Close the application - closeTutti(false); - - // Re-open the context - try { - context.open(); - } catch (Exception ex) { - ErrorDialogUI.showError(ex); - } - - MainUI mainUI = new MainUI(context); - mainUI.setVisible(true); - } - - protected void closeCurrentBody() { - if (currentBody != null) { - TuttiUI<?, ?> body = (TuttiUI<?, ?>) currentBody; - body.getHandler().onCloseUI(); - - context.getSwingSession().save(); - - ui.getBody().remove(currentBody); - - currentBody = null; - } - } - - protected void changeScreen(JComponent newBody, String title) { - currentBody = newBody; - context.getSwingSession().add(currentBody); - ui.getBody().setTitle(title); - ui.getBody().add(currentBody); - } - - protected void closeTutti(boolean exit) { - - context.getSwingSession().save(); - - ui.setVisible(false); - ui.dispose(); - - onCloseUI(); - - if (exit) { - System.exit(0); - } - } - protected void changeTitle() { String title = getSelectedCruiseTitle(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/RunTutti.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/RunTutti.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/RunTutti.java 2012-12-30 19:39:00 UTC (rev 132) @@ -67,8 +67,6 @@ } })); - context.open(); - // Initialize i18n I18n.init(new DefaultI18nInitializer("tutti-ui-swing"), Locale.UK); @@ -86,9 +84,29 @@ new BorderUIResource.LineBorderUIResource(Color.BLACK)); UIManager.put("BlockingLayerUI.blockingColor", new Color(50, 50, 50)); + startTutti(context); + } + + public static void startTutti(TuttiUIContext context) { + + context.open(); + MainUI mainUI = new MainUI(context); mainUI.setVisible(true); + } + public static void closeTutti(MainUI ui, boolean exit) { + + ui.getHandler().getContext().getSwingSession().save(); + + ui.getHandler().onCloseUI(); + + ui.setVisible(false); + ui.dispose(); + + if (exit) { + System.exit(0); + } } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2012-12-30 19:39:00 UTC (rev 132) @@ -348,6 +348,8 @@ cruiseId = null; protocolId = null; + setScreen(null); + IOUtils.closeQuietly(serviceContext); // remove listeners Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java 2012-12-30 19:39:00 UTC (rev 132) @@ -35,6 +35,7 @@ import org.nuiton.util.Version; import javax.swing.KeyStroke; +import java.awt.Color; import java.io.File; import java.io.IOException; import java.net.URL; @@ -133,7 +134,18 @@ return applicationConfig.getOption(TuttiConfigOption.PROTOCOL_ID.getKey()); } + public Color getColorRowInvalid() { + return applicationConfig.getOptionAsColor(TuttiConfigOption.COLOR_ROW_INVALID.getKey()); + } + public Color getColorRowReadOnly() { + return applicationConfig.getOptionAsColor(TuttiConfigOption.COLOR_ROW_READ_ONLY.getKey()); + } + + public KeyStroke getShortcutClosePopup() { + return applicationConfig.getOptionAsKeyStroke(TuttiConfigOption.SHORTCUT_CLOSE_POPUP.getKey()); + } + public KeyStroke getShortCut(String actionName) { KeyStroke result = applicationConfig.getOptionAsKeyStroke( "tutti.ui." + actionName); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java 2012-12-30 19:39:00 UTC (rev 132) @@ -26,6 +26,8 @@ import org.nuiton.util.ApplicationConfig; +import javax.swing.KeyStroke; +import java.awt.Color; import java.io.File; import static org.nuiton.i18n.I18n.n_; @@ -38,40 +40,66 @@ */ public enum TuttiConfigOption implements ApplicationConfig.OptionDef { - UI_CONFIG_FILE("tutti.ui.config", - n_("tutti.config.ui.config"), - "${tutti.data.directory}/tuttiUI.xml", - File.class + UI_CONFIG_FILE( + "tutti.ui.config", + n_("tutti.config.ui.config"), + "${tutti.data.directory}/tuttiUI.xml", + File.class ), - PROGRAM_ID("tutti.programId", - n_("tutti.config.programId"), - null, - String.class + + PROGRAM_ID( + "tutti.programId", + n_("tutti.config.programId"), + null, + String.class ), - CRUISE_ID("tutti.cruiseId", - n_("tutti.config.cruiseId"), - null, - String.class + + CRUISE_ID( + "tutti.cruiseId", + n_("tutti.config.cruiseId"), + null, + String.class ), - PROTOCOL_ID("tutti.protocolId", - n_("tutti.config.protocolId"), - null, - String.class + + PROTOCOL_ID( + "tutti.protocolId", + n_("tutti.config.protocolId"), + null, + String.class ), - // UI CONFIG (should be moved to ui module) - AUTO_POPUP_NUMBER_EDITOR("tutti.ui.autoPopupNumberEditor", - n_("tutti.config.ui.autoPopupNumberEditor"), - String.valueOf(false), - Boolean.class + AUTO_POPUP_NUMBER_EDITOR( + "tutti.ui.autoPopupNumberEditor", + n_("tutti.config.ui.autoPopupNumberEditor"), + String.valueOf(false), + Boolean.class ), - SHOW_NUMBER_EDITOR_BUTTON("tutti.ui.showNumberEditorButton", - n_("tutti.config.ui.showNumberEditorButton"), - String.valueOf(true), - Boolean.class - ); + SHOW_NUMBER_EDITOR_BUTTON( + "tutti.ui.showNumberEditorButton", + n_("tutti.config.ui.showNumberEditorButton"), + String.valueOf(true), + Boolean.class + ), + COLOR_ROW_READ_ONLY( + "tutti.ui.color.rowReadOnly", + n_("tutti.config.ui.color.rowReadOnly"), + new Color(192, 192, 192).toString(), + Color.class + ), + COLOR_ROW_INVALID( + "tutti.ui.color.rowInvalid", + n_("tutti.config.ui.color.rowInvalid"), + new Color(255, 128, 128).toString(), + Color.class), + + SHORTCUT_CLOSE_POPUP( + "tutti.ui.shortcut.closePopup", + n_("tutti.config.ui.shortcut.closePopup"), + "alt pressed F", + KeyStroke.class); + /** Configuration key. */ private final String key; Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java 2012-12-30 19:39:00 UTC (rev 132) @@ -0,0 +1,135 @@ +package fr.ifremer.tutti.ui.swing.config; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.service.config.TuttiServiceConfigOption; +import fr.ifremer.tutti.ui.swing.MainUI; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.editor.config.ConfigUIHelper; +import jaxx.runtime.swing.editor.config.model.MainCallBackFinalizer; + +import static org.nuiton.i18n.I18n.n_; + +/** + * To launch the config UI. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class TuttiConfigUI { + + public static final String CALLBACK_APPLICATION = "application"; + + public static final String CALLBACK_UI = "ui"; + + public static final String CALLBACK_SHORTCUT = "shortcut"; + + protected final MainUI mainUI; + + public TuttiConfigUI(MainUI mainUI) { + this.mainUI = mainUI; + } + + public void createUI() { + + TuttiConfig config = mainUI.getHandler().getContext().getConfig(); + + ConfigUIHelper helper = new ConfigUIHelper(config.getApplicationConfig()); + + helper.registerCallBack( + CALLBACK_UI, n_("tutti.action.reload.ui"), + SwingUtil.createActionIcon("reload-ui"), + new Runnable() { + + @Override + public void run() { + reloadUI(); + } + } + ).registerCallBack( + CALLBACK_APPLICATION, n_("tutti.action.reload.application"), + SwingUtil.createActionIcon("reload-application"), + new Runnable() { + + @Override + public void run() { + reloadApplication(); + } + } + ).registerCallBack( + CALLBACK_SHORTCUT, n_("tutti.action.reload.actions"), + SwingUtil.createActionIcon("reload-shortcut"), + new Runnable() { + + @Override + public void run() { + + reloadShortcuts(); + } + } + ); + + // APPLICATION + + helper.addCategory(n_("tutti.config.category.applications"), + n_("tutti.config.category.applications.description"), + CALLBACK_APPLICATION) + .addOption(TuttiServiceConfigOption.DATA_DIRECTORY) + .addOption(TuttiServiceConfigOption.SITE_URL) + .addOption(TuttiConfigOption.UI_CONFIG_FILE); + + // COLOR + helper.addCategory(n_("tutti.config.category.colors"), + n_("tutti.config.category.colors.description"), + CALLBACK_UI) + .addOption(TuttiConfigOption.COLOR_ROW_INVALID) + .addOption(TuttiConfigOption.COLOR_ROW_READ_ONLY); + + // SHORTCUT + + helper.addCategory(n_("tutti.config.category.shortcuts"), + n_("tutti.config.category.shortcuts.description"), + CALLBACK_SHORTCUT) + .addOption(TuttiConfigOption.SHORTCUT_CLOSE_POPUP); + + helper.setFinalizer(new MainCallBackFinalizer(CALLBACK_APPLICATION)); + + helper.buildUI(mainUI, "tutti.config.category.applications"); + + helper.displayUI(mainUI, false); + } + + protected void reloadApplication() { + mainUI.getHandler().reloadApplication(); + } + + protected void reloadUI() { + mainUI.getHandler().reloadTutti(); + } + + protected void reloadShortcuts() { + mainUI.getHandler().reloadShortcuts(); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -65,7 +65,7 @@ } #yearField { - property: "year"; + property: year; model: {model.getYear()}; useFloat: false; numberPattern: {INT_4_DIGITS_PATTERN}; @@ -86,7 +86,7 @@ } #countryComboBox { - property: "country"; + property: country; selectedItem: {model.getCountry()}; } @@ -96,7 +96,7 @@ } #surveyComboBox { - property: "program"; + property: program; selectedItem: {model.getProgram()}; } @@ -126,33 +126,29 @@ } #pocheField { - property: "poche"; + property: poche; model: {model.getPoche()}; useFloat: false; numberPattern: {INT_1_DIGITS_PATTERN}; } #vesselList { - beanType: {Vessel.class}; - property: "vessel"; + property: vessel; border: {BorderFactory.createTitledBorder(_("tutti.label.list.vessel"))}; } #gearList { - beanType: {Gear.class}; - property: "gear"; + property: gear; border: {BorderFactory.createTitledBorder(_("tutti.label.list.gear"))}; } #headOfMissionList { - beanType: {Person.class}; property: "headOfMission"; border: {BorderFactory.createTitledBorder(_("tutti.label.list.headOfMission"))}; } #headOfSortRoomList { - beanType: {Person.class}; - property: "headOfSortRoom"; + property: headOfSortRoom; border: {BorderFactory.createTitledBorder(_("tutti.label.list.headOfSortRoom"))}; } @@ -166,18 +162,18 @@ } #saveButton { - actionIcon: "save"; + actionIcon: save; text: "tutti.action.save"; enabled: {model.isModify() && model.isValid()}; } #cancelButton { - actionIcon: "cancel"; + actionIcon: cancel; text: "tutti.action.cancel"; } #generateNameButton { - actionIcon: "generate"; + actionIcon: generate; text: "tutti.action.generateCampaignName"; enabled: {model.isCanGenerateName()}; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -65,10 +65,10 @@ ]]></script> <EditCruiseUIHandler id='handler' - initializer='getContextValue(EditCruiseUIHandler.class)'/> + initializer='getContextValue(EditCruiseUIHandler.class)'/> <EditCruiseUIModel id='model' - initializer='getContextValue(EditCruiseUIModel.class)'/> + initializer='getContextValue(EditCruiseUIModel.class)'/> <SwingValidatorMessageTableModel id='errorTableModel'/> @@ -189,7 +189,7 @@ onFocusGained='commentField.requestFocus()'> <JTextArea id='commentField' onKeyReleased='handler.setText(event, "comment")'/> - </JScrollPane> + </JScrollPane> </cell> </row> @@ -206,7 +206,7 @@ <JPanel id='messagePanel' layout='{new GridLayout()}'> <JScrollPane columnHeaderView='{errorTable.getTableHeader()}'> - <JTable id='errorTable' /> + <JTable id='errorTable'/> </JScrollPane> </JPanel> </JSplitPane> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -24,8 +24,8 @@ * #L% */ +import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.referential.Country; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -33,19 +33,20 @@ } #programCombobox { - property: "program"; + property: program; + beanType: {Program.class}; selectedItem: {model.getProgram()}; } #editProgramButton { enabled: {model.isProgramFound()}; text: "tutti.action.edit"; - actionIcon: "edit"; + actionIcon: edit; } #newProgramButton { text: "tutti.action.new"; - actionIcon: "add"; + actionIcon: add; } #cruiseLabel { @@ -54,7 +55,7 @@ } #cruiseCombobox { - property: "cruise"; + property: cruise; enabled: {model.isProgramFound()}; selectedItem: {model.getCruise()}; } @@ -62,11 +63,11 @@ #editCruiseButton { enabled: {model.isProgramFound() && model.isCruiseFound()}; text: "tutti.action.edit"; - actionIcon: "edit"; + actionIcon: edit; } #newCruiseButton { - actionIcon: "add"; + actionIcon: add; enabled: {model.isProgramFound()}; text: "tutti.action.new"; } @@ -77,18 +78,18 @@ } #protocolCombobox { - property: "protocol"; + property: protocol; selectedItem: {model.getProtocol()}; } #editProtocolButton { enabled: {model.isProtocolFound()}; text: "tutti.action.edit"; - actionIcon: "edit"; + actionIcon: edit; } #newProtocolButton { - actionIcon: "add"; + actionIcon: add; enabled: true; text: "tutti.action.new"; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -53,10 +53,10 @@ ]]></script> <SelectCruiseUIHandler id='handler' - initializer='getContextValue(SelectCruiseUIHandler.class)'/> + initializer='getContextValue(SelectCruiseUIHandler.class)'/> <SelectCruiseUIModel id='model' - initializer='getContextValue(SelectCruiseUIModel.class)'/> + initializer='getContextValue(SelectCruiseUIModel.class)'/> <Table fill='both' constraints='BorderLayout.CENTER'> <row> @@ -64,8 +64,8 @@ <JLabel id='programLabel'/> </cell> <cell weightx='1.0'> - <BeanComboBox id='programCombobox' constructorParams='this' - genericType='Program'/> + <BeanComboBox id='programCombobox' constructorParams='this' + genericType='Program'/> </cell> <cell> <JPanel layout='{new GridLayout(1,0)}'> @@ -81,8 +81,8 @@ <JLabel id='cruiseLabel'/> </cell> <cell> - <BeanComboBox id='cruiseCombobox' constructorParams='this' - genericType='Cruise'/> + <BeanComboBox id='cruiseCombobox' constructorParams='this' + genericType='Cruise'/> </cell> <cell> <JPanel layout='{new GridLayout(1,0)}'> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -142,6 +142,30 @@ model.getPrograms(), model.getProgram()); +// ui.getProgramCombobox().setAutoComplete(false); +// ui.getProgramCombobox().setEditable(true); +// +// JComboBox combobox = ui.getProgramCombobox().getCombobox(); +// ComboBoxSearchable comboBoxSearchable = new ComboBoxSearchable(combobox) { +// +// final Decorator<Program> decorator = getDecorator(Program.class, null); +// +// @Override +// protected String convertElementToString(Object object) { +// return decorator.toString(object); +// } +// }; +// +// comboBoxSearchable.setRefreshPopupDuringSearching(true); +// comboBoxSearchable.setShowPopupDuringSearching(true); +// comboBoxSearchable.setFromStart(false); +// comboBoxSearchable.setHideSearchPopupOnEvent(false); +// comboBoxSearchable.setHeavyweightComponentEnabled(true); +// comboBoxSearchable.setForeground(Color.GREEN); +// +// AutoCompletion i= new AutoCompletion(combobox, comboBoxSearchable); + + initBeanComboBox(ui.getCruiseCombobox(), model.getCruises(), model.getCruise()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -33,23 +33,16 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; -import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.ComponentAdapter; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.sort.TableSortController; -import javax.swing.event.ListSelectionListener; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; -import java.awt.Color; import java.awt.Component; import java.awt.event.FocusEvent; import java.util.Collection; @@ -66,25 +59,11 @@ private static final Log log = LogFactory.getLog(AbstractTuttiBatchTableUIHandler.class); - protected abstract void saveSelectedRowIfRequired(); - - protected abstract void saveRow(R row); - - protected abstract FishingOperation getFishingOperation(); - public abstract void selectFishingOperation(FishingOperation bean); - /** - * Persistence service. - * - * @since 0.2 - */ - protected final PersistenceService persistenceService; - protected AbstractTuttiBatchTableUIHandler(TuttiUI<?, ?> parentUi, String... properties) { super(parentUi.getHandler().getContext(), properties); - this.persistenceService = context.getService(PersistenceService.class); } public final void saveSelectedRowIfRequired(FocusEvent event) { @@ -103,8 +82,9 @@ if (parentContainer == null) { // out of the table can save - if (getFishingOperation() != null) { - saveSelectedRowIfRequired(); + if (getModel().getFishingOperation() != null) { + + saveSelectedRowIfNeeded(); } } } @@ -135,7 +115,6 @@ AbstractTuttiTableModel<R> tableModel) { installTableKeyListener(columnModel, table); - table.getTableHeader().setReorderingAllowed(false); JTableFilter tableFilter = new JTableFilter(table); TableRowFilterSupport.forFilter(tableFilter).searchable(true).useTableRenderers(true).actions(true).apply(); @@ -161,44 +140,8 @@ TableSortController<TableModel> sorter = new TableSortController<TableModel>(tableModel); sorter.setSortable(false); - table.setRowSorter(sorter); - Highlighter readOnlyHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( - HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY); - - table.addHighlighter(readOnlyHighlighter); - Highlighter validHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( - new HighlightPredicate.AndHighlightPredicate(HighlightPredicate.EDITABLE, new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - - boolean result = false; - if (adapter.isEditable()) { - int rowIndex = adapter.convertRowIndexToModel(adapter.row); - R row = getTableModel().getEntry(rowIndex); - result = !row.isValid(); - } - return result; - } - }), Color.RED); - table.addHighlighter(validHighlighter); - - // when model datas change let's propagate it table model - listenRowsFromModel(); - - // save when row chaged and was modified - ListSelectionListener listener = new TableRowModificationListener<R>( - tableModel, getRowMonitor()) { - @Override - protected void saveSelectedRow() { - saveSelectedRowIfRequired(); - } - }; - table.getSelectionModel().addListSelectionListener(listener); - - // always scroll to selected row - SwingUtil.scrollToTableSelection(table); + initTable(table); } - } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -67,7 +67,7 @@ } #fishingOperationNumberField { - property: "fishingOperationNumber"; + property: fishingOperationNumber; model: {model.getFishingOperationNumber()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -89,7 +89,7 @@ } #strataComboBox { - property: "strata"; + property: strata; selectedItem: {model.getStrata()}; } @@ -99,7 +99,7 @@ } #subStrataComboBox { - property: "subStrata"; + property: subStrata; selectedItem: {model.getSubStrata()}; } @@ -109,7 +109,7 @@ } #locationComboBox { - property: "location"; + property: location; selectedItem: {model.getLocation()}; } @@ -151,7 +151,7 @@ } #gearShootingStartTimeField { - property: "gearShootingStartDate"; + property: gearShootingStartDate; date: {model.getGearShootingStartDate()}; } @@ -169,7 +169,7 @@ } #gearShootingEndTimeField { - property: "gearShootingEndDate"; + property: gearShootingEndDate; date: {model.getGearShootingEndDate()}; } @@ -180,7 +180,7 @@ } #resetValidStateButton { - actionIcon: "reset"; + actionIcon: reset; text: "tutti.action.reset.fishingOperationValidState"; } @@ -211,7 +211,7 @@ } #distanceChaluteeField { - property: "distanceChalutee"; + property: distanceChalutee; model: {model.getDistanceChalutee()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -229,8 +229,7 @@ } #saisisseurList { - beanType: {Person.class}; - property: "saisisseur"; + property: saisisseur; border: {BorderFactory.createTitledBorder(_("tutti.label.list.saisisseur"))}; } @@ -253,19 +252,18 @@ } #saveButton { - actionIcon: "save"; + actionIcon: save; text: "tutti.action.save"; enabled: {model.isValid()}; } #cancelButton { - actionIcon: "cancel"; + actionIcon: cancel; text: "tutti.action.cancel"; - /*enabled: {model.isModify()};*/ } #importCasinoButton { - actionIcon: "casino-import"; + actionIcon: casino-import; text: "tutti.action.casino-import"; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -30,11 +30,11 @@ #newFishingOperationButton { text: "tutti.action.new"; - actionIcon: "add"; + actionIcon: add; } #fishingOperationComboBox { - property: "selectedFishingOperation"; + property: selectedFishingOperation; selectedItem: {model.getSelectedFishingOperation()}; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -70,7 +70,8 @@ <JTabbedPane id='tabPane' constraints='BorderLayout.CENTER'> <tab id='fishingOperationTab' title='tutti.label.tab.fishingOperation'> - <EditFishingOperationUI id='fishingOperationTabContent' constructorParams='this'/> + <EditFishingOperationUI id='fishingOperationTabContent' + constructorParams='this'/> </tab> <tab id='catchesTab' title='tutti.label.tab.catches'> <EditCatchesUI id='catchesTabContent' constructorParams='this'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -31,15 +31,17 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.decorator.Decorator; + import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Date; import java.util.List; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import static org.nuiton.i18n.I18n._; -import org.nuiton.util.decorator.Decorator; /** * Handler of UI {@link FishingOperationsUI}. @@ -198,7 +200,7 @@ } public void saveFishingOperation(FishingOperation toSave) { - + // persist the fishingOperation boolean create = toSave.getId() == null; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -26,11 +26,12 @@ import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractSerializableBean; +import java.util.List; + /** * Model fo UI {@link FishingOperationsUI}. * @@ -40,7 +41,7 @@ public class FishingOperationsUIModel extends AbstractSerializableBean { private static final Log log = LogFactory.getLog(FishingOperationsUIModel.class); - + private static final long serialVersionUID = 1L; public static final String PROPERTY_FISHING_OPERATION = "fishingOperation"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -39,7 +39,7 @@ } #catchTotalWeightField { - property: "catchTotalWeight"; + property: catchTotalWeight; model: {model.getCatchTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -51,7 +51,7 @@ } #catchTotalSortedTremisWeightField { - property: "catchTotalSortedTremisWeight"; + property: catchTotalSortedTremisWeight; model: {model.getCatchTotalSortedTremisWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -63,7 +63,7 @@ } #catchTotalSortedCarousselWeightField { - property: "catchTotalSortedCarousselWeight"; + property: catchTotalSortedCarousselWeight; model: {model.getCatchTotalSortedCarousselWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -75,7 +75,7 @@ } #catchTotalRejectedWeightField { - property: "catchTotalRejectedWeight"; + property: catchTotalRejectedWeight; model: {model.getCatchTotalRejectedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -101,7 +101,7 @@ } #speciesTotalWeightField { - property: "speciesTotalWeight"; + property: speciesTotalWeight; model: {model.getSpeciesTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -113,7 +113,7 @@ } #speciesTotalSortedWeightField { - property: "speciesTotalSortedWeight"; + property: speciesTotalSortedWeight; model: {model.getSpeciesTotalSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -125,7 +125,7 @@ } #speciesTotalSampleSortedWeightField { - property: "speciesTotalSampleSortedWeight"; + property: speciesTotalSampleSortedWeight; model: {model.getSpeciesTotalSampleSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -151,7 +151,7 @@ } #benthosTotalWeightField { - property: "benthosTotalWeight"; + property: benthosTotalWeight; model: {model.getBenthosTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -163,7 +163,7 @@ } #benthosTotalSortedWeightField { - property: "benthosTotalSortedWeight"; + property: benthosTotalSortedWeight; model: {model.getBenthosTotalSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -175,7 +175,7 @@ } #benthosTotalSampleSortedWeightField { - property: "benthosTotalSampleSortedWeight"; + property: benthosTotalSampleSortedWeight; model: {model.getBenthosTotalSampleSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -201,19 +201,17 @@ } #macroWasteTotalWeightField { - property: "macroWasteTotalWeight"; + property: macroWasteTotalWeight; model: {model.getMacroWasteTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; } #importPupitriButton { - actionIcon: "pupitri-import"; + actionIcon: pupitri-import; text: "tutti.action.pupitri-import"; } #observationIndividuelTab { enabled: {false}; } - -//#catchesCaracteristicsTabScrollPane { } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -79,6 +79,10 @@ EditCatchesUIModel.PROPERTY_MACRO_WASTE_TOTAL_WEIGHT); } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override public void beforeInitUI() { @@ -110,6 +114,10 @@ return ui.getModel(); } + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + public void selectFishingOperation(FishingOperation bean, String fishingOperationText) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -74,169 +74,92 @@ } //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// + //-- AbstractTuttiBatchTableUIHandler methods --// //------------------------------------------------------------------------// @Override - protected AccidentalBatchUIModel getModel() { - return ui.getModel(); - } + public void selectFishingOperation(FishingOperation bean) { - @Override - protected AccidentalBatchTableModel getTableModel() { - return (AccidentalBatchTableModel) getTable().getModel(); - } + boolean empty = bean == null; - @Override - protected JXTable getTable() { - return ui.getTable(); - } + AccidentalBatchUIModel model = getModel(); - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } + List<AccidentalBatchRowModel> rows; + if (empty) { + rows = null; + } else { - @Override - protected void onRowModified(AccidentalBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + if (log.isInfoEnabled()) { + log.info("Get accidental batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); - boolean wasValid = row.isValid(); - - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); + if (!TuttiEntities.isNew(bean)) { + List<AccidentalBatch> catches = + persistenceService.getAllAccidentalBatch(bean.getId()); + for (AccidentalBatch aBatch : catches) { + AccidentalBatchRowModel entry = + new AccidentalBatchRowModel(aBatch); + rows.add(entry); + } + } } - row.setValid(valid); + model.setRows(rows); } - @Override - protected void onRowValidStateChanged(AccidentalBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - @Override - protected void onRowModifyStateChanged(AccidentalBatchRowModel row, - Boolean oldValue, - Boolean newValue) { + protected AccidentalBatchTableModel getTableModel() { + return (AccidentalBatchTableModel) getTable().getModel(); } @Override - protected void onModelRowsChanged(List<AccidentalBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (AccidentalBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } + protected JXTable getTable() { + return ui.getTable(); } @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<AccidentalBatchRowModel> rowMonitor = getRowMonitor(); - - AccidentalBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - AccidentalBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteAccidentalBatch(catchBean.getId()); - } - } - } - } - - @Override protected boolean isRowValid(AccidentalBatchRowModel row) { boolean result = row.getSpecies() != null && row.getWeight() != null; return result; } @Override - protected void saveRow(AccidentalBatchRowModel row) { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<AccidentalBatchRowModel> rowMonitor, + AccidentalBatchRowModel row) { - AccidentalBatch catchBean = row.toBean(); + if (row.isValid()) { + // there is a valid bean attached to the monitor - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } + if (rowMonitor.wasModified()) { - if (TuttiEntities.isNew(catchBean)) { + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } - catchBean = persistenceService.createAccidentalBatch(catchBean); - row.setId(catchBean.getId()); + saveRow(row); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } } else { - persistenceService.saveAccidentalBatch(catchBean); - } - } - @Override - public void selectFishingOperation(FishingOperation bean) { + // row is not valid can not save it - boolean empty = bean == null; + AccidentalBatch catchBean = row.toBean(); - AccidentalBatchUIModel model = getModel(); + if (!TuttiEntities.isNew(catchBean)) { - List<AccidentalBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get accidental batch for fishingOperation: " + - bean.getId()); + // remove this + persistenceService.deleteAccidentalBatch(catchBean.getId()); } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<AccidentalBatch> catches = - persistenceService.getAllAccidentalBatch(bean.getId()); - for (AccidentalBatch aBatch : catches) { - AccidentalBatchRowModel entry = - new AccidentalBatchRowModel(aBatch); - rows.add(entry); - } - } - } - model.setRows(rows); } //------------------------------------------------------------------------// @@ -244,6 +167,11 @@ //------------------------------------------------------------------------// @Override + protected AccidentalBatchUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { if (log.isInfoEnabled()) { @@ -347,4 +275,22 @@ //-- Internal methods --// //------------------------------------------------------------------------// + protected void saveRow(AccidentalBatchRowModel row) { + + AccidentalBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createAccidentalBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveAccidentalBatch(catchBean); + } + } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -29,7 +29,6 @@ import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import javax.swing.table.TableColumnModel; -import java.util.Set; import static org.nuiton.i18n.I18n.n_; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -35,7 +35,7 @@ } #benthosTotalWeightField { - property: "benthosTotalWeight"; + property: benthosTotalWeight; model: {model.getBenthosTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -47,7 +47,7 @@ } #benthosTotalSortedWeightField { - property: "benthosTotalSortedWeight"; + property: benthosTotalSortedWeight; model: {model.getBenthosTotalSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -59,7 +59,7 @@ } #benthosTotalSampleSortedWeightField { - property: "benthosTotalSampleSortedWeight"; + property: benthosTotalSampleSortedWeight; model: {model.getBenthosTotalSampleSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -74,180 +74,107 @@ BenthosBatchRowModel.PROPERTY_SAMPLE_WEIGHT, BenthosBatchRowModel.PROPERTY_COMMENT); this.ui = ui; - } //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// + //-- AbstractTuttiBatchTableUIHandler methods --// //------------------------------------------------------------------------// @Override - protected BenthosBatchUIModel getModel() { - return ui.getModel(); - } + public void selectFishingOperation(FishingOperation bean) { - @Override - protected BenthosBatchTableModel getTableModel() { - return (BenthosBatchTableModel) getTable().getModel(); - } + boolean empty = bean == null; - @Override - protected JXTable getTable() { - return ui.getTable(); - } + BenthosBatchUIModel model = getModel(); - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } + List<BenthosBatchRowModel> rows; - @Override - protected void onRowModified(BenthosBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + if (empty) { + rows = null; + } else { - boolean wasValid = row.isValid(); + if (log.isInfoEnabled()) { + log.info("Get benthos batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); + if (!TuttiEntities.isNew(bean)) { + List<BenthosBatch> catches = + persistenceService.getAllBenthosBatch(bean.getId()); + for (BenthosBatch aBatch : catches) { + BenthosBatchRowModel entry = + new BenthosBatchRowModel(aBatch); + rows.add(entry); + } + } } - row.setValid(valid); + model.setRows(rows); } - @Override - protected void onRowValidStateChanged(BenthosBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - @Override - protected void onRowModifyStateChanged(BenthosBatchRowModel row, - Boolean oldValue, - Boolean newValue) { + protected BenthosBatchTableModel getTableModel() { + return (BenthosBatchTableModel) getTable().getModel(); } @Override - protected void onModelRowsChanged(List<BenthosBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (BenthosBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } + protected JXTable getTable() { + return ui.getTable(); } @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<BenthosBatchRowModel> rowMonitor = getRowMonitor(); - - BenthosBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - BenthosBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteBenthosBatch(catchBean.getId()); - } - } - } - } - - @Override protected boolean isRowValid(BenthosBatchRowModel row) { boolean result = row.getSpecies() != null && row.getWeight() != null; return result; } @Override - protected void saveRow(BenthosBatchRowModel row) { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<BenthosBatchRowModel> rowMonitor, + BenthosBatchRowModel row) { - BenthosBatch catchBean = row.toBean(); + if (row.isValid()) { + // there is a valid bean attached to the monitor - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } + if (rowMonitor.wasModified()) { - if (TuttiEntities.isNew(catchBean)) { + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } - catchBean = persistenceService.createBenthosBatch(catchBean); - row.setId(catchBean.getId()); + saveRow(row); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } } else { - persistenceService.saveBenthosBatch(catchBean); - } - } - @Override - public void selectFishingOperation(FishingOperation bean) { + // row is not valid can not save it - boolean empty = bean == null; + BenthosBatch catchBean = row.toBean(); - BenthosBatchUIModel model = getModel(); + if (!TuttiEntities.isNew(catchBean)) { - List<BenthosBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get benthos batch for fishingOperation: " + - bean.getId()); + // remove this + persistenceService.deleteBenthosBatch(catchBean.getId()); } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<BenthosBatch> catches = - persistenceService.getAllBenthosBatch(bean.getId()); - for (BenthosBatch aBatch : catches) { - BenthosBatchRowModel entry = - new BenthosBatchRowModel(aBatch); - rows.add(entry); - } - } } - - model.setRows(rows); } - //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override + protected BenthosBatchUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { if (log.isInfoEnabled()) { @@ -259,8 +186,6 @@ BenthosBatchUIModel model = new BenthosBatchUIModel(catchesUIModel); ui.setContextValue(model); - -// fishingOperationMonitor.setBean(model); } @Override @@ -375,4 +300,23 @@ //-- Internal methods --// //------------------------------------------------------------------------// + protected void saveRow(BenthosBatchRowModel row) { + + BenthosBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createBenthosBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveBenthosBatch(catchBean); + } + } + } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -49,7 +49,7 @@ public static final String PROPERTY_WEIGHT = "weight"; - public static final String PROPERTY_NUMBER= "number"; + public static final String PROPERTY_NUMBER = "number"; public static final String PROPERTY_COMMENT = "comment"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -35,7 +35,7 @@ } #macroWasteTotalWeightField { - property: "macroWasteTotalWeight"; + property: macroWasteTotalWeight; model: {model.getMacroWasteTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -74,92 +74,80 @@ } //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// + //-- AbstractTuttiBatchTableUIHandler methods --// //------------------------------------------------------------------------// @Override - protected MacroWasteBatchUIModel getModel() { - return ui.getModel(); - } + public void selectFishingOperation(FishingOperation bean) { - @Override - protected MacroWasteBatchTableModel getTableModel() { - return (MacroWasteBatchTableModel) getTable().getModel(); - } + boolean empty = bean == null; - @Override - protected JXTable getTable() { - return ui.getTable(); - } + MacroWasteBatchUIModel model = getModel(); - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } + List<MacroWasteBatchRowModel> rows; - @Override - protected void onRowModified(MacroWasteBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + if (empty) { + rows = null; + } else { - boolean wasValid = row.isValid(); + if (log.isInfoEnabled()) { + log.info("Get macroWaste batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); + if (!TuttiEntities.isNew(bean)) { + List<MacroWasteBatch> catches = + persistenceService.getAllMacroWasteBatch(bean.getId()); + for (MacroWasteBatch aBatch : catches) { + MacroWasteBatchRowModel entry = + new MacroWasteBatchRowModel(aBatch); + rows.add(entry); + } + } } - row.setValid(valid); + model.setRows(rows); } - @Override - protected void onRowValidStateChanged(MacroWasteBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } + @Override + protected MacroWasteBatchTableModel getTableModel() { + return (MacroWasteBatchTableModel) getTable().getModel(); } @Override - protected void onRowModifyStateChanged(MacroWasteBatchRowModel row, - Boolean oldValue, - Boolean newValue) { + protected JXTable getTable() { + return ui.getTable(); } @Override - protected void onModelRowsChanged(List<MacroWasteBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (MacroWasteBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } + protected boolean isRowValid(MacroWasteBatchRowModel row) { + boolean result = row.getMacroWasteCategory() != null && + row.getMacroWasteSizeCategory() != null && + row.getWeight() != null; + return result; } @Override - protected void saveSelectedRowIfRequired() { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<MacroWasteBatchRowModel> rowMonitor, + MacroWasteBatchRowModel row) { - TuttiBeanMonitor<MacroWasteBatchRowModel> rowMonitor = getRowMonitor(); + if (row != null) { - MacroWasteBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { + if (row.isValid()) { // there is a valid bean attached to the monitor if (rowMonitor.wasModified()) { // monitored bean was modified, save it if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); + log.info("Row " + row + " was modified, will save it"); } - saveRow(bean); + saveRow(row); // clear modified flag on the monitor rowMonitor.clearModified(); @@ -168,7 +156,7 @@ // row is not valid can not save it - MacroWasteBatch catchBean = bean.toBean(); + MacroWasteBatch catchBean = row.toBean(); if (!TuttiEntities.isNew(catchBean)) { @@ -179,72 +167,16 @@ } } - @Override - protected boolean isRowValid(MacroWasteBatchRowModel row) { - boolean result = row.getMacroWasteCategory() != null && - row.getMacroWasteSizeCategory() != null && - row.getWeight() != null; - return result; - } - - @Override - protected void saveRow(MacroWasteBatchRowModel row) { - - MacroWasteBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createMacroWasteBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveMacroWasteBatch(catchBean); - } - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - boolean empty = bean == null; - - MacroWasteBatchUIModel model = getModel(); - - List<MacroWasteBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get macroWaste batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<MacroWasteBatch> catches = - persistenceService.getAllMacroWasteBatch(bean.getId()); - for (MacroWasteBatch aBatch : catches) { - MacroWasteBatchRowModel entry = - new MacroWasteBatchRowModel(aBatch); - rows.add(entry); - } - } - } - - model.setRows(rows); - } - //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override + protected MacroWasteBatchUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { if (log.isInfoEnabled()) { @@ -352,4 +284,22 @@ //-- Internal methods --// //------------------------------------------------------------------------// + protected void saveRow(MacroWasteBatchRowModel row) { + + MacroWasteBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createMacroWasteBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveMacroWasteBatch(catchBean); + } + } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -35,7 +35,7 @@ } #planktonTotalWeightField { - property: "planktonTotalWeight"; + property: planktonTotalWeight; model: {model.getPlanktonTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -47,7 +47,7 @@ } #planktonTotalSampleWeightField { - property: "planktonTotalSampleWeight"; + property: planktonTotalSampleWeight; model: {model.getPlanktonTotalSampleWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -74,169 +74,93 @@ } //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// + //-- AbstractTuttiBatchTableUIHandler methods --// //------------------------------------------------------------------------// @Override - protected PlanktonBatchUIModel getModel() { - return ui.getModel(); - } + public void selectFishingOperation(FishingOperation bean) { - @Override - protected PlanktonBatchTableModel getTableModel() { - return (PlanktonBatchTableModel) getTable().getModel(); - } + boolean empty = bean == null; - @Override - protected JXTable getTable() { - return ui.getTable(); - } + PlanktonBatchUIModel model = getModel(); - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } + List<PlanktonBatchRowModel> rows; - @Override - protected void onRowModified(PlanktonBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + if (empty) { + rows = null; + } else { - boolean wasValid = row.isValid(); - boolean valid = isRowValid(row); + if (log.isInfoEnabled()) { + log.info("Get plankton batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); + if (!TuttiEntities.isNew(bean)) { + List<PlanktonBatch> catches = + persistenceService.getAllPlanktonBatch(bean.getId()); + for (PlanktonBatch aBatch : catches) { + PlanktonBatchRowModel entry = + new PlanktonBatchRowModel(aBatch); + rows.add(entry); + } + } } - row.setValid(valid); + model.setRows(rows); } - @Override - protected void onRowValidStateChanged(PlanktonBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - @Override - protected void onRowModifyStateChanged(PlanktonBatchRowModel row, - Boolean oldValue, - Boolean newValue) { + protected PlanktonBatchTableModel getTableModel() { + return (PlanktonBatchTableModel) getTable().getModel(); } @Override - protected void onModelRowsChanged(List<PlanktonBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (PlanktonBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } + protected JXTable getTable() { + return ui.getTable(); } @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<PlanktonBatchRowModel> rowMonitor = getRowMonitor(); - - PlanktonBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - PlanktonBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deletePlanktonBatch(catchBean.getId()); - } - } - } - } - - @Override protected boolean isRowValid(PlanktonBatchRowModel row) { boolean result = row.getSpecies() != null && row.getWeight() != null; return result; } @Override - protected void saveRow(PlanktonBatchRowModel row) { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<PlanktonBatchRowModel> rowMonitor, + PlanktonBatchRowModel row) { - PlanktonBatch catchBean = row.toBean(); + if (row.isValid()) { + // there is a valid bean attached to the monitor - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } + if (rowMonitor.wasModified()) { - if (TuttiEntities.isNew(catchBean)) { + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } - catchBean = persistenceService.createPlanktonBatch(catchBean); - row.setId(catchBean.getId()); + saveRow(row); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } } else { - persistenceService.savePlanktonBatch(catchBean); - } - } - @Override - public void selectFishingOperation(FishingOperation bean) { + // row is not valid can not save it - boolean empty = bean == null; + PlanktonBatch catchBean = row.toBean(); - PlanktonBatchUIModel model = getModel(); + if (!TuttiEntities.isNew(catchBean)) { - List<PlanktonBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - - if (log.isInfoEnabled()) { - log.info("Get plankton batch for fishingOperation: " + - bean.getId()); + // remove this + persistenceService.deletePlanktonBatch(catchBean.getId()); } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<PlanktonBatch> catches = - persistenceService.getAllPlanktonBatch(bean.getId()); - for (PlanktonBatch aBatch : catches) { - PlanktonBatchRowModel entry = - new PlanktonBatchRowModel(aBatch); - rows.add(entry); - } - } } - - model.setRows(rows); } //------------------------------------------------------------------------// @@ -244,6 +168,11 @@ //------------------------------------------------------------------------// @Override + protected PlanktonBatchUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { if (log.isInfoEnabled()) { @@ -358,4 +287,22 @@ //-- Internal methods --// //------------------------------------------------------------------------// + protected void saveRow(PlanktonBatchRowModel row) { + + PlanktonBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createPlanktonBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.savePlanktonBatch(catchBean); + } + } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryType.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryType.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryType.java 2012-12-30 19:39:00 UTC (rev 132) @@ -1,5 +1,29 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species; +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; import fr.ifremer.tutti.service.DecoratorService; Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryType.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -35,7 +35,7 @@ } #speciesTotalWeightField { - property: "speciesTotalWeight"; + property: speciesTotalWeight; model: {model.getSpeciesTotalWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -47,7 +47,7 @@ } #speciesTotalSortedWeightField { - property: "speciesTotalSortedWeight"; + property: speciesTotalSortedWeight; model: {model.getSpeciesTotalSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; @@ -59,7 +59,7 @@ } #speciesTotalSampleSortedWeightField { - property: "speciesTotalSampleSortedWeight"; + property: speciesTotalSampleSortedWeight; model: {model.getSpeciesTotalSampleSortedWeight()}; useFloat: false; numberPattern: {INT_6_DIGITS_PATTERN}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -113,14 +113,47 @@ } //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// + //-- AbstractTuttiBatchTableUIHandler methods --// //------------------------------------------------------------------------// @Override - protected SpeciesBatchUIModel getModel() { - return ui.getModel(); + public void selectFishingOperation(FishingOperation bean) { + + boolean empty = bean == null; + + SpeciesBatchUIModel model = getModel(); + + List<SpeciesBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + if (log.isInfoEnabled()) { + log.info("Get species batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<SpeciesBatch> catches = + persistenceService.getAllSpeciesBatch(bean.getId()); + for (SpeciesBatch aBatch : catches) { + List<SpeciesBatchFrequency> frequencies = + persistenceService.getAllSpeciesBatchFrequency(aBatch.getId()); + SpeciesBatchRowModel entry = + new SpeciesBatchRowModel(aBatch, frequencies); + rows.add(entry); + } + } + } + model.setRows(rows); } + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + @Override protected SpeciesBatchTableModel getTableModel() { return (SpeciesBatchTableModel) getTable().getModel(); @@ -132,32 +165,79 @@ } @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); + protected boolean isRowValid(SpeciesBatchRowModel row) { + boolean result = row.getSpecies() != null; + if (result) { + result = row.getWeight() != null; + + if (!result) { + + // No weight filled, so at least one sample category must be valid + result = row.getSortedUnsortedSampleCategory().isValid() || + row.getSizeSampleCategory().isValid() || + row.getSexSampleCategory().isValid() || + row.getMaturitySampleCategory().isValid() || + row.getAgeSampleCategory().isValid(); + } + } + return result; } @Override + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor, + SpeciesBatchRowModel row) { + + if (row.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } + + showInformationMessage( + "[ Captures - Espèces ] " + + "Sauvegarde des modifications de " + row + "."); + + saveRow(row); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + SpeciesBatch catchBean = row.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deleteSpeciesBatch(catchBean.getId()); + } + } + + } + + @Override protected void onModelRowsChanged(List<SpeciesBatchRowModel> rows) { super.onModelRowsChanged(rows); - // compute row valid - for (SpeciesBatchRowModel row : rows) { - boolean rowValid = isRowValid(row); - row.setValid(rowValid); - } // build the new sampling tree from the new rows to edit // getModel().getSamplingTreeModel().populate(rows); } @Override - protected void onRowModified(SpeciesBatchRowModel row, + protected void onRowModified(int rowIndex, + SpeciesBatchRowModel row, String propertyName, Object oldValue, Object newValue) { - if (log.isInfoEnabled()) { - log.info("Property " + propertyName + " has changed on row."); - } + super.onRowModified(rowIndex, row, propertyName, oldValue, newValue); + if (RECOMPUTE_TOTAL_WEIGHT.contains(propertyName)) { // Need to recompute totalHorsVracWeight @@ -254,163 +334,19 @@ // } } - @Override - protected void onRowValidStateChanged(SpeciesBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(SpeciesBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor = getRowMonitor(); - - SpeciesBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - showInformationMessage( - "[ Captures - Espèces ] " + - "Sauvegarde des modifications de " + bean + - "."); - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - SpeciesBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteSpeciesBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(SpeciesBatchRowModel row) { - boolean result = row.getSpecies() != null; - if (result) { - result = row.getWeight() != null; - - if (!result) { - - // No weight filled, so at least one sample category must be valid - result = row.getSortedUnsortedSampleCategory().isValid() || - row.getSizeSampleCategory().isValid() || - row.getSexSampleCategory().isValid() || - row.getMaturitySampleCategory().isValid() || - row.getAgeSampleCategory().isValid(); - } - } - return result; - } - - @Override - protected void saveRow(SpeciesBatchRowModel row) { - - SpeciesBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - Preconditions.checkNotNull(fishingOperation); - - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createSpeciesBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveSpeciesBatch(catchBean); - } - - List<SpeciesFrequencyRowModel> frequencyRows = row.getFrequency(); - - List<SpeciesBatchFrequency> frequency = - SpeciesFrequencyRowModel.toBeans(frequencyRows, catchBean); - - if (log.isInfoEnabled()) { - log.info("Will save " + frequency.size() + " frequencies."); - } - frequency = persistenceService.saveSpeciesBatchFrequency( - catchBean.getId(), frequency); - - // push it back to row model - frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequency); - row.setFrequency(frequencyRows); - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - boolean empty = bean == null; - - SpeciesBatchUIModel model = getModel(); - - List<SpeciesBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get species batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<SpeciesBatch> catches = - persistenceService.getAllSpeciesBatch(bean.getId()); - for (SpeciesBatch aBatch : catches) { - List<SpeciesBatchFrequency> frequencies = - persistenceService.getAllSpeciesBatchFrequency(aBatch.getId()); - SpeciesBatchRowModel entry = - new SpeciesBatchRowModel(aBatch, frequencies); - rows.add(entry); - } - } - } - model.setRows(rows); - } - //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// - public static final String SPECIES_FREQUENCY_LENGHTS = "SPECIES_FREQUENCY_LENGHTS"; + public static final String SPECIES_FREQUENCY_LENGHTS = + "SPECIES_FREQUENCY_LENGHTS"; @Override + protected SpeciesBatchUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { if (log.isInfoEnabled()) { @@ -597,6 +533,42 @@ //-- Internal methods --// //------------------------------------------------------------------------// + protected void saveRow(SpeciesBatchRowModel row) { + + SpeciesBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + Preconditions.checkNotNull(fishingOperation); + + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createSpeciesBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveSpeciesBatch(catchBean); + } + + List<SpeciesFrequencyRowModel> frequencyRows = row.getFrequency(); + + List<SpeciesBatchFrequency> frequency = + SpeciesFrequencyRowModel.toBeans(frequencyRows, catchBean); + + if (log.isInfoEnabled()) { + log.info("Will save " + frequency.size() + " frequencies."); + } + frequency = persistenceService.saveSpeciesBatchFrequency( + catchBean.getId(), frequency); + + // push it back to row model + frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequency); + row.setFrequency(frequencyRows); + } + // protected void recomputeSuperSamplingRatio(SpeciesBatchTreeModel samplingTreeModel, // SpeciesBatchTreeNode node) { // Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -39,7 +39,7 @@ } #stepField { - property: "step"; + property: step; model: {model.getStep()}; useFloat: true; numberPattern: {DECIMAL1_PATTERN}; @@ -52,7 +52,7 @@ } #lenghtStepCaracteristicComboBox { - property: "lengthStepCaracteristic"; + property: lengthStepCaracteristic; selectedItem: {model.getLengthStepCaracteristic()}; } @@ -62,7 +62,7 @@ } #minStepField { - property: "minStep"; + property: minStep; model: {model.getMinStep()}; useFloat: true; showReset: true; @@ -76,7 +76,7 @@ } #maxStepField { - property: "maxStep"; + property: maxStep; model: {model.getMaxStep()}; useFloat: true; showReset: true; @@ -97,7 +97,7 @@ } #generateButton { - actionIcon: "generate"; + actionIcon: generate; text: "tutti.action.generate"; enabled: {model.isCanGenerate()}; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -31,18 +31,16 @@ import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIHandler; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.SwingUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; import javax.swing.JDialog; -import java.awt.Color; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; @@ -78,11 +76,6 @@ //------------------------------------------------------------------------// @Override - protected SpeciesFrequencyUIModel getModel() { - return ui.getModel(); - } - - @Override protected SpeciesFrequencyTableModel getTableModel() { return (SpeciesFrequencyTableModel) getTable().getModel(); } @@ -93,10 +86,24 @@ } @Override - protected void onRowModified(SpeciesFrequencyRowModel row, + protected boolean isRowValid(SpeciesFrequencyRowModel row) { + //TODO + return row.getLengthStep() != null && row.getWeight() != null; + } + + @Override + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SpeciesFrequencyRowModel> rowMonitor, + SpeciesFrequencyRowModel row) { + } + + @Override + protected void onRowModified(int rowIndex, + SpeciesFrequencyRowModel row, String propertyName, Object oldValue, Object newValue) { + super.onRowModified(rowIndex, row, propertyName, oldValue, newValue); + if (SpeciesFrequencyRowModel.PROPERTY_NUMBER.equals(propertyName)) { // Need to recompute the computedWeight @@ -104,29 +111,16 @@ } } - @Override - protected void onRowValidStateChanged(SpeciesFrequencyRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onRowModifyStateChanged(SpeciesFrequencyRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected boolean isRowValid(SpeciesFrequencyRowModel row) { - //TODO - return true; - } - //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override + protected SpeciesFrequencyUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { SpeciesFrequencyUIModel model = new SpeciesFrequencyUIModel(); @@ -152,8 +146,40 @@ lengthStepCaracterics, model.getLengthStepCaracteristic()); - JXTable table = getTable(); + //TODO Should it come from PROTOCOL or config ? + model.setStep(.5f); + + model.setMinStep(10f); + model.setMaxStep(20f); + + //TODO Configure this ? + model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE); + + ui.getRafaleStepField().getTextField().addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + e.consume(); + Float step = (Float) ui.getRafaleStepField().getModel(); + + applyRafaleStep(step); + } + } + }); + + // when lengthStepCaracteristic changed, let's updates all row with the new value + model.addPropertyChangeListener(SpeciesFrequencyUIModel.PROPERTY_LENGHT_STEP_CARACTERISTIC, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Caracteristic newValue = (Caracteristic) evt.getNewValue(); + for (SpeciesFrequencyRowModel rowModel : getModel().getRows()) { + rowModel.setLengthStepCaracteristic(newValue); + } + } + }); + // create table column model DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); @@ -189,54 +215,14 @@ SpeciesFrequencyTableModel tableModel = new SpeciesFrequencyTableModel(columnModel, model); + JXTable table = getTable(); + table.setModel(tableModel); table.setColumnModel(columnModel); installTableKeyListener(columnModel, table); - table.getTableHeader().setReorderingAllowed(false); - - table.addHighlighter(TuttiUIUtil.newBackgroundColorHighlighter( - HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY)); - - // when model datas change let's propagate it table model - listenRowsFromModel(); - - //TODO Should it come from PROTOCOL or config ? - model.setStep(.5f); - - model.setMinStep(10f); - model.setMaxStep(20f); - - //TODO Configure this ? - model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE); - - // always scroll to selected row - SwingUtil.scrollToTableSelection(getTable()); - - ui.getRafaleStepField().getTextField().addKeyListener(new KeyAdapter() { - - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - e.consume(); - Float step = (Float) ui.getRafaleStepField().getModel(); - - applyRafaleStep(step); - } - } - }); - - // when lengthStepCaracteristic changed, let's updates all row with the new value - model.addPropertyChangeListener(SpeciesFrequencyUIModel.PROPERTY_LENGHT_STEP_CARACTERISTIC, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Caracteristic newValue = (Caracteristic) evt.getNewValue(); - for (SpeciesFrequencyRowModel rowModel : getModel().getRows()) { - rowModel.setLengthStepCaracteristic(newValue); - } - } - }); + initTable(table); } @Override @@ -326,7 +312,6 @@ frequency = row.getFrequency(); } - List<SpeciesFrequencyRowModel> editFrequency; if (CollectionUtils.isEmpty(frequency)) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -38,7 +38,7 @@ } #categoryComboBox { - property: "selectedCategory"; + property: selectedCategory; selectedItem: {model.getSelectedCategory()}; } @@ -48,7 +48,7 @@ } #closeButton { - actionIcon: "close"; + actionIcon: close; text: "tutti.action.close"; mnemonic: F; enabled: {model.isValid()}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -58,10 +58,10 @@ ]]></script> <SplitSampleCategoryUIHandler id='handler' - initializer='getContextValue(SplitSampleCategoryUIHandler.class)'/> + initializer='getContextValue(SplitSampleCategoryUIHandler.class)'/> <SplitSampleCategoryUIModel id='model' - initializer='getContextValue(SplitSampleCategoryUIModel.class)'/> + initializer='getContextValue(SplitSampleCategoryUIModel.class)'/> <SwingValidatorMessageTableModel id='errorTableModel'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -34,19 +34,16 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; import org.nuiton.util.decorator.Decorator; import javax.swing.JDialog; -import javax.swing.table.DefaultTableModel; -import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.List; @@ -99,11 +96,6 @@ //------------------------------------------------------------------------// @Override - protected SplitSampleCategoryUIModel getModel() { - return ui.getModel(); - } - - @Override protected SplitSampleCategoryTableModel getTableModel() { return (SplitSampleCategoryTableModel) getTable().getModel(); } @@ -114,10 +106,26 @@ } @Override - protected void onRowModified(SplitSampleCategoryRowModel row, + protected boolean isRowValid(SplitSampleCategoryRowModel row) { + //TODO + return row.getCategoryValue() != null && row.getWeight() != null; + } + + @Override + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SplitSampleCategoryRowModel> rowMonitor, + SplitSampleCategoryRowModel row) { + //TODO + } + + @Override + protected void onRowModified(int rowIndex, + SplitSampleCategoryRowModel row, String propertyName, Object oldValue, Object newValue) { + + super.onRowModified(rowIndex, row, propertyName, oldValue, newValue); + if (SplitSampleCategoryRowModel.PROPERTY_WEIGHT.equals(propertyName)) { // Need to recompute the total weight @@ -125,29 +133,16 @@ } } - @Override - protected void onRowValidStateChanged(SplitSampleCategoryRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onRowModifyStateChanged(SplitSampleCategoryRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected boolean isRowValid(SplitSampleCategoryRowModel row) { - //TODO - return true; - } - //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override + protected SplitSampleCategoryUIModel getModel() { + return ui.getModel(); + } + + @Override public void beforeInitUI() { SplitSampleCategoryUIModel model = new SplitSampleCategoryUIModel(); @@ -167,19 +162,6 @@ Lists.<SampleCategoryType>newArrayList(), model.getSelectedCategory()); - JXTable table = getTable(); - - table.getTableHeader().setReorderingAllowed(false); - - table.addHighlighter(TuttiUIUtil.newBackgroundColorHighlighter( - HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY)); - - // when model datas change let's propagate it table model - listenRowsFromModel(); - - // always scroll to selected row - SwingUtil.scrollToTableSelection(getTable()); - // when category changed, remove selected category model.addPropertyChangeListener(SplitSampleCategoryUIModel.PROPERTY_CATEGORY, new PropertyChangeListener() { @Override @@ -198,6 +180,10 @@ generateTableModel(newValue); } }); + + generateTableModel(null); + + initTable(getTable()); } @Override @@ -295,21 +281,18 @@ } } - protected void generateTableModel(SampleCategoryEnum category) { - if (category == null) { + Caracteristic data = null; - getTable().setModel(new DefaultTableModel()); - } else { + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + if (category != null) { + Decorator<CaracteristicQualitativeValue> caracteristicDecorator = getDecorator(CaracteristicQualitativeValue.class, null); - Caracteristic data = null; - - DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); - switch (category) { case sortedUnsorted: @@ -344,30 +327,29 @@ SplitSampleCategoryTableModel.WEIGHT, TuttiUI.DECIMAL3_PATTERN); } + } - // create table model - SplitSampleCategoryTableModel tableModel = - new SplitSampleCategoryTableModel(columnModel, getModel()); + // create table model + SplitSampleCategoryTableModel tableModel = + new SplitSampleCategoryTableModel(columnModel, getModel()); - JXTable table = getTable(); + JXTable table = getTable(); - table.setModel(tableModel); - table.setColumnModel(columnModel); + table.setModel(tableModel); + table.setColumnModel(columnModel); - //TODO Fix this! + //TODO Fix this! // installTableKeyListener(columnModel, table); - if (data != null) { + if (data != null) { - // add a row for each qualitive value - for (CaracteristicQualitativeValue qualitativeValue : data.getQualitativeValue()) { - SplitSampleCategoryRowModel newRow = tableModel.createNewRow(); - newRow.setCategoryValue(qualitativeValue); - tableModel.addNewRow(newRow); - } + // add a row for each qualitive value + for (CaracteristicQualitativeValue qualitativeValue : data.getQualitativeValue()) { + SplitSampleCategoryRowModel newRow = tableModel.createNewRow(); + newRow.setCategoryValue(qualitativeValue); + tableModel.addNewRow(newRow); } } - } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -24,7 +24,6 @@ BeanComboBox { i18nPrefix: "tutti.property."; - bean: {model}; } #newRowKey { @@ -34,8 +33,8 @@ } #addRow { - actionIcon: "add"; - enabled: {!newRowKey.isEmpty() && newRowKey.getSelectedItem() != null}; + actionIcon: add; + enabled: {newRowKey.getSelectedItem() != null}; } #environmentTable { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -33,14 +33,12 @@ import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueRenderer; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import fr.ifremer.tutti.ui.swing.util.table.CaracteristicRow; -import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import javax.swing.event.ListSelectionListener; import java.util.Collection; import java.util.List; @@ -50,8 +48,14 @@ */ public class EnvironmentTabUIHandler extends AbstractTuttiTableUIHandler<EnvironmentRowModel, EnvironmentTabUIModel> { - private final static Log log = LogFactory.getLog(EnvironmentTabUIHandler.class); + private final static Log log = + LogFactory.getLog(EnvironmentTabUIHandler.class); + /** + * UI. + * + * @since 0.3 + */ protected final EnvironmentTabUI ui; public EnvironmentTabUIHandler(EditFishingOperationUI parentUi, @@ -61,10 +65,9 @@ this.ui = ui; } - @Override - protected JXTable getTable() { - return ui.getEnvironmentTable(); - } + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// @Override protected EnvironmentTableModel getTableModel() { @@ -72,28 +75,29 @@ } @Override - protected void onRowModified(EnvironmentRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + protected JXTable getTable() { + return ui.getEnvironmentTable(); } @Override - protected void onRowValidStateChanged(EnvironmentRowModel row, - Boolean oldValue, - Boolean newValue) { + protected boolean isRowValid(EnvironmentRowModel row) { + //TODO + return row.getValue() != null; } @Override - protected void onRowModifyStateChanged(EnvironmentRowModel row, - Boolean oldValue, - Boolean newValue) { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<EnvironmentRowModel> rowMonitor, + EnvironmentRowModel row) { +// getModel().setCaracteristic(row.getKey(), row.getValue()); } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override - protected boolean isRowValid(EnvironmentRowModel row) { - //TODO - return true; + protected EnvironmentTabUIModel getModel() { + return ui.getModel(); } @Override @@ -106,6 +110,9 @@ public void afterInitUI() { initUI(ui); + initBeanComboBox(ui.getNewRowKey(), + Lists.<CaracteristicRow>newArrayList(), null); + JXTable table = getTable(); // create table column model @@ -133,35 +140,16 @@ table.setModel(tableModel); table.setColumnModel(columnModel); - - initBeanComboBox(ui.getNewRowKey(), - Lists.<CaracteristicRow>newArrayList(), null); - - // modify the model when the user enters a value - ListSelectionListener listener = new TableRowModificationListener<EnvironmentRowModel>( - tableModel, getRowMonitor()) { - - @Override - protected void saveSelectedRow() { - TuttiBeanMonitor<EnvironmentRowModel> monitor = getRowMonitor(); - EnvironmentRowModel row = monitor.getBean(); - if (row != null) { - getModel().setCaracteristic(row.getKey(), row.getValue()); - } - } - }; - table.getSelectionModel().addListSelectionListener(listener); - table.getTableHeader().setReorderingAllowed(false); + initTable(table); } @Override public void onCloseUI() { } - @Override - protected EnvironmentTabUIModel getModel() { - return ui.getModel(); - } + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// /** Adds a row with the parameter selected in the combo box */ public void addRow() { @@ -171,7 +159,7 @@ EnvironmentRowModel row = getTableModel().createNewRow(); row.setKey(caracteristic); getTableModel().addNewRow(row); - getModel().setCaracteristic(caracteristic, null); +// getModel().setCaracteristic(caracteristic, null); keyCombo.removeItem(selectedItem); selectFirstInCombo(keyCombo); @@ -197,7 +185,7 @@ rows.add(newRow); } - tableModel.setRows(rows, false); + model.setRows(rows); List<CaracteristicRow> caracteristicList = Lists.newArrayList(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/environment/EnvironmentTabUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -29,7 +29,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; -import fr.ifremer.tutti.ui.swing.util.table.CaracteristicRow; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; @@ -82,11 +81,4 @@ public void setAvailableCaracteristics(List<Caracteristic> caracteristics) { availableCaracteristics = caracteristics; } - - //>>>--- Warning Added only to be able to use a BeanComboBox editor! ---// - - public void setSelectedCaracteristic(CaracteristicRow selectedCaracteristic) { - } - //<<<--- Warning Added only to be able to use a BeanComboBox editor! ---// - } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -24,7 +24,6 @@ BeanComboBox { i18nPrefix: "tutti.property."; - bean: {model}; } #newRowKey { @@ -34,8 +33,8 @@ } #addRow { - actionIcon: "add"; - enabled: {!newRowKey.isEmpty() && newRowKey.getSelectedItem() != null}; + actionIcon: add; + enabled: {newRowKey.getSelectedItem() != null}; } #gearShootingTable { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -33,14 +33,12 @@ import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueRenderer; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import fr.ifremer.tutti.ui.swing.util.table.CaracteristicRow; -import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import javax.swing.event.ListSelectionListener; import java.util.Collection; import java.util.List; @@ -50,19 +48,26 @@ */ public class GearShootingTabUIHandler extends AbstractTuttiTableUIHandler<GearShootingRowModel, GearShootingTabUIModel> { - private final static Log log = LogFactory.getLog(GearShootingTabUIHandler.class); + private final static Log log = + LogFactory.getLog(GearShootingTabUIHandler.class); + /** + * UI. + * + * @since 0.3 + */ protected final GearShootingTabUI ui; - public GearShootingTabUIHandler(EditFishingOperationUI parentUi, GearShootingTabUI ui) { - super(parentUi.getHandler().getContext(), GearShootingRowModel.PROPERTY_VALUE); + public GearShootingTabUIHandler(EditFishingOperationUI parentUi, + GearShootingTabUI ui) { + super(parentUi.getHandler().getContext(), + GearShootingRowModel.PROPERTY_VALUE); this.ui = ui; } - @Override - protected JXTable getTable() { - return ui.getGearShootingTable(); - } + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// @Override protected GearShootingTableModel getTableModel() { @@ -70,28 +75,31 @@ } @Override - protected void onRowModified(GearShootingRowModel row, - String propertyName, - Object oldValue, - Object newValue) { + protected JXTable getTable() { + return ui.getGearShootingTable(); } @Override - protected void onRowValidStateChanged(GearShootingRowModel row, - Boolean oldValue, - Boolean newValue) { + protected boolean isRowValid(GearShootingRowModel row) { + //TODO + return row.getValue() != null; } @Override - protected void onRowModifyStateChanged(GearShootingRowModel row, - Boolean oldValue, - Boolean newValue) { + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<GearShootingRowModel> rowMonitor, + GearShootingRowModel row) { + + //TODO Check row was modified and is valid ? + getModel().setCaracteristic(row.getKey(), row.getValue()); } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override - protected boolean isRowValid(GearShootingRowModel row) { - //TODO - return true; + protected GearShootingTabUIModel getModel() { + return ui.getModel(); } @Override @@ -104,6 +112,9 @@ public void afterInitUI() { initUI(ui); + initBeanComboBox(ui.getNewRowKey(), + Lists.<CaracteristicRow>newArrayList(), null); + JXTable table = getTable(); // create table column model @@ -133,34 +144,16 @@ table.setModel(tableModel); table.setColumnModel(columnModel); - initBeanComboBox(ui.getNewRowKey(), - Lists.<CaracteristicRow>newArrayList(), null); - - // modify the model when the user enters a value - ListSelectionListener listener = new TableRowModificationListener<GearShootingRowModel>( - tableModel, getRowMonitor()) { - - @Override - protected void saveSelectedRow() { - TuttiBeanMonitor<GearShootingRowModel> monitor = getRowMonitor(); - GearShootingRowModel row = monitor.getBean(); - if (row != null) { - getModel().setCaracteristic(row.getKey(), row.getValue()); - } - } - }; - table.getSelectionModel().addListSelectionListener(listener); - table.getTableHeader().setReorderingAllowed(false); + initTable(table); } @Override public void onCloseUI() { } - @Override - protected GearShootingTabUIModel getModel() { - return ui.getModel(); - } + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// /** Adds a row with the parameter selected in the combo box */ public void addRow() { @@ -195,7 +188,7 @@ rows.add(newRow); } - tableModel.setRows(rows, false); + model.setRows(rows); List<CaracteristicRow> caracteristicList = Lists.newArrayList(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/gearshooting/GearShootingTabUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -30,7 +30,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; -import fr.ifremer.tutti.ui.swing.util.table.CaracteristicRow; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; @@ -84,10 +83,4 @@ public void setAvailableCaracteristics(List<Caracteristic> availableCaracteristics) { this.availableCaracteristics = availableCaracteristics; } - - //>>>--- Warning Added only to be able to use a BeanComboBox editor! ---// - - public void setSelectedCaracteristic(CaracteristicRow selectedCaracteristic) { - } - //<<<--- Warning Added only to be able to use a BeanComboBox editor! ---// } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -24,7 +24,6 @@ BeanComboBox { i18nPrefix: "tutti.property."; - bean: {model}; } #newRowKey { @@ -34,8 +33,8 @@ } #addRow { - actionIcon: "add"; - enabled: {!newRowKey.isEmpty() && newRowKey.getSelectedItem() != null}; + actionIcon: add; + enabled: {newRowKey.getSelectedItem() != null}; } #hydrologyTable { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -21,11 +21,12 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<Table implements='fr.ifremer.tutti.ui.swing.TuttiUI<HydrologyTabUIModel, HydrologyTabUIHandler>'> - +<Table + implements='fr.ifremer.tutti.ui.swing.TuttiUI<HydrologyTabUIModel, HydrologyTabUIHandler>'> + <import> fr.ifremer.tutti.persistence.entities.referential.Caracteristic - + fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUI jaxx.runtime.swing.editor.bean.BeanComboBox @@ -35,13 +36,13 @@ javax.swing.ListSelectionModel java.awt.Color </import> - + <HydrologyTabUIHandler id='handler' initializer='getContextValue(HydrologyTabUIHandler.class)'/> <HydrologyTabUIModel id='model' initializer='getContextValue(HydrologyTabUIModel.class)'/> - + <row fill='both'> <cell fill='both' weightx='1'> <BeanComboBox id='newRowKey' constructorParams='this' Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -35,15 +35,12 @@ import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueEditor; import fr.ifremer.tutti.ui.swing.util.editor.CaracteristicValueRenderer; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; -import fr.ifremer.tutti.ui.swing.util.table.CaracteristicRow; -import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import javax.swing.event.ListSelectionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; @@ -58,8 +55,14 @@ */ public class HydrologyTabUIHandler extends AbstractTuttiTableUIHandler<HydrologyRowModel, HydrologyTabUIModel> { - private final static Log log = LogFactory.getLog(HydrologyTabUIHandler.class); + private final static Log log = + LogFactory.getLog(HydrologyTabUIHandler.class); + /** + * UI. + * + * @since 0.3 + */ protected final HydrologyTabUI ui; protected Map<Caracteristic, Map<Type, Caracteristic>> availableCaracteristics; @@ -74,6 +77,10 @@ this.ui = ui; } + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + @Override protected JXTable getTable() { return ui.getHydrologyTable(); @@ -85,28 +92,44 @@ } @Override - protected void onRowModified(HydrologyRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - } + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<HydrologyRowModel> rowMonitor, + HydrologyRowModel row) { - @Override - protected void onRowValidStateChanged(HydrologyRowModel row, - Boolean oldValue, - Boolean newValue) { + Map<Type, Caracteristic> caracteristics = + availableCaracteristics.get(row.getKey()); + CaracteristicMap map = new CaracteristicMap(); + for (Type type : caracteristics.keySet()) { + Serializable value = null; + switch (type) { + case START: + value = row.getGearShootingStartValue(); + break; + case END: + value = row.getGearShootingEndValue(); + break; + case AVERAGE: + value = row.getAverageValue(); + } + map.put(caracteristics.get(type), value); + } + getModel().addCaracteristics(map); } @Override - protected void onRowModifyStateChanged(HydrologyRowModel row, - Boolean oldValue, - Boolean newValue) { + protected boolean isRowValid(HydrologyRowModel row) { + //TODO + return row.getGearShootingStartValue() != null || + row.getGearShootingEndValue() != null || + row.getAverageValue() != null; } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override - protected boolean isRowValid(HydrologyRowModel row) { - //TODO - return true; + protected HydrologyTabUIModel getModel() { + return ui.getModel(); } @Override @@ -140,6 +163,9 @@ public void afterInitUI() { initUI(ui); + initBeanComboBox(ui.getNewRowKey(), + Lists.<Caracteristic>newArrayList(), null); + JXTable table = getTable(); // create table column model @@ -184,52 +210,16 @@ table.setModel(tableModel); table.setColumnModel(columnModel); - - initBeanComboBox(ui.getNewRowKey(), - Lists.<Caracteristic>newArrayList(), null); - - // modify the model when the user enters a value - ListSelectionListener listener = new TableRowModificationListener<HydrologyRowModel>( - tableModel, getRowMonitor()) { - - @Override - protected void saveSelectedRow() { - TuttiBeanMonitor<HydrologyRowModel> monitor = getRowMonitor(); - HydrologyRowModel row = monitor.getBean(); - if (row != null) { - Map<Type, Caracteristic> caracteristics = availableCaracteristics.get(row.getKey()); - CaracteristicMap map = new CaracteristicMap(); - for (Type type : caracteristics.keySet()) { - Serializable value = null; - switch (type) { - case START: - value = row.getGearShootingStartValue(); - break; - case END: - value = row.getGearShootingEndValue(); - break; - case AVERAGE: - value = row.getAverageValue(); - } - map.put(caracteristics.get(type), value); - } - getModel().addCaracteristics(map); - } - } - }; - table.getSelectionModel().addListSelectionListener(listener); - table.getTableHeader().setReorderingAllowed(false); - + initTable(table); } @Override public void onCloseUI() { } - @Override - protected HydrologyTabUIModel getModel() { - return ui.getModel(); - } + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// /** Adds a row with the parameter selected in the combo box */ public void addRow() { @@ -285,7 +275,8 @@ } } - tableModel.setRows(rows, false); + getModel().setRows(rows); + ui.getNewRowKey().setData(caracteristicList); selectFirstInCombo(ui.getNewRowKey()); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/hydrology/HydrologyTabUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -86,10 +86,4 @@ this.availableCaracteristics = availableCaracteristics; firePropertyChange(PROPERTY_AVAILABLE_CARACTERISTICS, oldValue, availableCaracteristics); } - - //>>>--- Warning Added only to be able to use a BeanComboBox editor! ---// - - public void setSelectedCaracteristic(Caracteristic selectedCaracteristic) { - } - //<<<--- Warning Added only to be able to use a BeanComboBox editor! ---// } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -41,7 +41,7 @@ #nameLabel { text: "tutti.label.program.name"; - labelFor: {nameField}; + labelFor: {nameField}; } #nameField { @@ -49,8 +49,8 @@ } #commentPane { - columnHeaderView: {new JLabel(_("tutti.label.comment"))}; - minimumSize: {new Dimension(10,50)}; + columnHeaderView: {new JLabel(_("tutti.label.comment"))}; + minimumSize: {new Dimension(10,50)}; } #commentField { @@ -63,19 +63,19 @@ } #zoneComboBox { - property: "zone"; + property: zone; selectedItem: {model.getZone()}; } #saveButton { text: "tutti.action.save"; enabled: {model.isModify() && model.isValid()}; - actionIcon: "save"; + actionIcon: save; } #cancelButton { text: "tutti.action.cancel"; - actionIcon: "cancel"; + actionIcon: cancel; } #messagePanel { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -100,7 +100,7 @@ onFocusGained='commentField.requestFocus()'> <JTextArea id='commentField' onKeyReleased='handler.setText(event, "comment")'/> - </JScrollPane> + </JScrollPane> </cell> </row> @@ -118,7 +118,7 @@ <!-- validation messages --> <JPanel id='messagePanel' layout='{new GridLayout()}'> <JScrollPane columnHeaderView='{errorTable.getTableHeader()}'> - <JTable id='errorTable' /> + <JTable id='errorTable'/> </JScrollPane> </JPanel> </JSplitPane> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/program/EditProgramUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -24,8 +24,8 @@ * #L% */ +import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.TuttiScreen; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -24,7 +24,6 @@ BeanComboBox { i18nPrefix: "tutti.property."; - bean: {model}; } BeanDoubleList { @@ -44,7 +43,7 @@ #nameLabel { text: "tutti.label.program.name"; - labelFor: {nameField}; + labelFor: {nameField}; } #nameField { @@ -52,8 +51,8 @@ } #commentPane { - columnHeaderView: {new JLabel(_("tutti.label.comment"))}; - minimumSize: {new Dimension(10,50)}; + columnHeaderView: {new JLabel(_("tutti.label.comment"))}; + minimumSize: {new Dimension(10,50)}; } #commentField { @@ -63,12 +62,12 @@ #saveButton { text: "tutti.action.save"; enabled: {model.isModify() && model.isValid()}; - actionIcon: "save"; + actionIcon: save; } #cancelButton { text: "tutti.action.cancel"; - actionIcon: "cancel"; + actionIcon: cancel; } #messagePanel { @@ -88,13 +87,12 @@ #speciesComboBox { showReset: false; - property: selectedSpecies; enabled: {!speciesComboBox.isEmpty()}; } #addRow { - actionIcon: "add"; - enabled: {!speciesComboBox.isEmpty() && speciesComboBox.getSelectedItem() != null}; + actionIcon: add; + enabled: {speciesComboBox.getSelectedItem() != null}; } #speciesTable { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -36,11 +36,11 @@ java.awt.Dimension java.awt.Color - + javax.swing.ListSelectionModel - + org.jdesktop.swingx.JXTable - + static org.nuiton.i18n.I18n._ static jaxx.runtime.SwingUtil.getStringValue @@ -60,10 +60,10 @@ ]]></script> <EditProtocolUIHandler id='handler' - initializer='getContextValue(EditProtocolUIHandler.class)'/> + initializer='getContextValue(EditProtocolUIHandler.class)'/> <EditProtocolUIModel id='model' - initializer='getContextValue(EditProtocolUIModel.class)'/> + initializer='getContextValue(EditProtocolUIModel.class)'/> <SwingValidatorMessageTableModel id='errorTableModel'/> @@ -103,7 +103,7 @@ </row> </Table> </tab> - + <tab title='tutti.label.tab.protocol.species'> <Table fill='both'> <row fill='both'> @@ -124,7 +124,7 @@ </row> </Table> </tab> - + <tab title='tutti.label.tab.protocol.pmfm'> <Table fill='both' weightx='1'> <row fill='both' weighty='1'> @@ -134,7 +134,8 @@ </row> <row fill='both' weighty='1'> <cell fill='both'> - <BeanDoubleList id='environmentList' genericType='Caracteristic'/> + <BeanDoubleList id='environmentList' + genericType='Caracteristic'/> </cell> </row> <row fill='both' weighty='1'> @@ -150,11 +151,11 @@ <JButton id='cancelButton' onActionPerformed='handler.cancel()'/> <JButton id='saveButton' onActionPerformed='handler.save()'/> </JPanel> - + </JPanel> <JPanel id='messagePanel' layout='{new GridLayout()}'> <JScrollPane columnHeaderView='{errorTable.getTableHeader()}'> - <JTable id='errorTable' /> + <JTable id='errorTable'/> </JScrollPane> </JPanel> </JSplitPane> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -26,9 +26,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; @@ -36,18 +34,16 @@ import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.TuttiScreen; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.util.HydrologicCaracteristicUtil; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; -import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; import jaxx.runtime.swing.editor.bean.BeanDoubleList; import jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer; import jaxx.runtime.validator.swing.SwingValidatorUtil; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; @@ -55,7 +51,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.event.TableColumnModelEvent; import javax.swing.event.TableColumnModelListener; import javax.swing.table.TableColumn; @@ -84,13 +79,6 @@ */ private final EditProtocolUI ui; - /** - * Persistence service. - * - * @since 0.3 - */ - private final PersistenceService persistenceService; - protected Map<String, Species> allSpecies; protected Map<String, Caracteristic> allLengthStepPmfm; @@ -108,7 +96,6 @@ public EditProtocolUIHandler(TuttiUIContext context, EditProtocolUI ui) { super(context); this.ui = ui; - persistenceService = context.getService(PersistenceService.class); columToSampleCategory = HashBiMap.create(SampleCategoryEnum.values().length); columToSampleCategory.put(EditProtocolSpeciesTableModel.SORTED_UNSORTED_ENABLED, SampleCategoryEnum.sortedUnsorted); columToSampleCategory.put(EditProtocolSpeciesTableModel.SIZE_ENABLED, SampleCategoryEnum.size); @@ -117,9 +104,13 @@ columToSampleCategory.put(EditProtocolSpeciesTableModel.AGE_ENABLED, SampleCategoryEnum.age); } + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + @Override - protected EditProtocolUIModel getModel() { - return ui.getModel(); + protected EditProtocolSpeciesTableModel getTableModel() { + return (EditProtocolSpeciesTableModel) getTable().getModel(); } @Override @@ -128,46 +119,43 @@ } @Override - protected EditProtocolSpeciesTableModel getTableModel() { - return (EditProtocolSpeciesTableModel) getTable().getModel(); + protected boolean isRowValid(EditProtocolSpeciesRowModel row) { + boolean result = row.getLengthStepPmfm() != null; + return result; } @Override - protected void onRowModified(EditProtocolSpeciesRowModel row, + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<EditProtocolSpeciesRowModel> rowMonitor, + EditProtocolSpeciesRowModel row) { + + // nothing to save when row changes, model is marked to be save + // when a row has changed and is valid or other protocol properties are modified + } + + @Override + protected void onRowModified(int rowIndex, + EditProtocolSpeciesRowModel row, String propertyName, Object oldValue, Object newValue) { - if (log.isInfoEnabled()) { - log.info("onRowModified property: " + propertyName + - ", newvalue: " + newValue); - } - boolean rowIsValid = isRowValid(row); - row.setValid(rowIsValid); - getModel().setModify(true); - } + super.onRowModified(rowIndex, row, propertyName, oldValue, newValue); - @Override - protected void onRowValidStateChanged(EditProtocolSpeciesRowModel row, - Boolean oldValue, - Boolean newValue) { - if (log.isInfoEnabled()) { - log.info("onRowValidStateChanged, newValidstate: " + newValue); - } - } + if (row.isValid()) { - @Override - protected void onRowModifyStateChanged(EditProtocolSpeciesRowModel row, - Boolean oldValue, - Boolean newValue) { - if (log.isInfoEnabled()) { - log.info("onRowModifyStateChanged, newModifiedState: " + newValue); + // row was modified and is valid, we can save protocol + // even if after the row becomes again not valid, this is not a + // problem since we will only save valid data! + getModel().setModify(true); } } + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + @Override - protected boolean isRowValid(EditProtocolSpeciesRowModel row) { - boolean result = row.getLengthStepPmfm() != null; - return result; + protected EditProtocolUIModel getModel() { + return ui.getModel(); } @Override @@ -175,45 +163,22 @@ EditProtocolUIModel model = new EditProtocolUIModel(); - String protocolId = context.getProtocolId(); - if (protocolId == null) { + // can't load directly model fro database here, since we want to + // fill only the model with rows (transformed from speciesProtocol) + // As we still don't have the table model at this point, wait the + // afterUI method to fill model - // create new protocol - - if (log.isDebugEnabled()) { - log.debug("Will create a new protocol"); - } - } else { - - // load existing program - TuttiProtocol protocol = - persistenceService.getProtocol(protocolId); - - model.fromBean(protocol); - if (log.isDebugEnabled()) { - log.debug("Will edit protocol: " + protocolId); - } - } - listModelIsModify(model); ui.setContextValue(model); - List<Species> species = persistenceService.getAllSpecies(); - allSpecies = Maps.newHashMap(); - for (Species s : species) { - allSpecies.put(s.getId(), s); - } + allSpecies = TuttiEntities.splitById( + persistenceService.getAllSpecies()); - List<Caracteristic> lengthStepCaracteristics = - persistenceService.getAllSpeciesLengthStepCaracteristic(); - allLengthStepPmfm = Maps.newHashMap(); - for (Caracteristic c : lengthStepCaracteristics) { - allLengthStepPmfm.put(c.getId(), c); - } + allLengthStepPmfm = TuttiEntities.splitById( + persistenceService.getAllSpeciesLengthStepCaracteristic()); - List<Caracteristic> hydrologyPmfm = persistenceService.getAllFishingOperationHydrologicCaracteristic(); - hydroCaracteristics = HashMultimap.create(); - for (Caracteristic caracteristic : hydrologyPmfm) { + for (Caracteristic caracteristic : + persistenceService.getAllFishingOperationHydrologicCaracteristic()) { String name = HydrologicCaracteristicUtil.getGlobalName(caracteristic.getName()); hydroCaracteristics.put(name, caracteristic.getId()); } @@ -231,8 +196,6 @@ listenValidatorValid(ui.getValidator(), model); - List<Species> speciesList = Lists.newArrayList(allSpecies.values()); - // create table model JXTable table = getTable(); @@ -278,77 +241,74 @@ EditProtocolSpeciesTableModel tableModel = new EditProtocolSpeciesTableModel(columnModel); + table.setModel(tableModel); + table.setColumnModel(columnModel); - // fill table model + initTable(table); - List<SpeciesProtocol> speciesProtocol = model.getSpecies(); - if (speciesProtocol == null) { - speciesProtocol = Lists.newArrayList(); + // Authorize to change column orders + table.getTableHeader().setReorderingAllowed(true); + + List<Species> speciesList = Lists.newArrayList(allSpecies.values()); + + // load protocol if existing + + String protocolId = context.getProtocolId(); + if (protocolId == null) { + + // create new protocol + + if (log.isDebugEnabled()) { + log.debug("Will create a new protocol"); + } + } else { + + // load existing protocol + TuttiProtocol protocol = persistenceService.getProtocol(protocolId); + + model.fromBean(protocol); + + // build speciesProtocol rows + List<EditProtocolSpeciesRowModel> rows = Lists.newArrayList(); + + List<SpeciesProtocol> speciesProtocols = protocol.getSpecies(); + if (CollectionUtils.isNotEmpty(speciesProtocols)) { + for (SpeciesProtocol speciesProtocol : speciesProtocols) { + Species species = allSpecies.get(speciesProtocol.getSpeciesId()); + speciesList.remove(species); + EditProtocolSpeciesRowModel row = tableModel.createNewRow(); + row.setSpecies(species); + row.setLengthStepPmfm(allLengthStepPmfm.get(speciesProtocol.getLengthStepPmfmId())); + row.fromBean(speciesProtocol); + rows.add(row); + } + } + if (log.isDebugEnabled()) { + log.debug("Will edit protocol: " + protocolId + " with " + + rows.size() + " species declared."); + } + + // set to model ( will propagate to tableModel) + model.setRows(rows); } - List<EditProtocolSpeciesRowModel> rows = Lists.newArrayList(); - for (SpeciesProtocol protocol : speciesProtocol) { - Species species = allSpecies.get(protocol.getSpeciesId()); - speciesList.remove(species); - EditProtocolSpeciesRowModel row = tableModel.createNewRow(); - row.setSpecies(species); - row.setLengthStepPmfm(allLengthStepPmfm.get(protocol.getLengthStepPmfmId())); - row.fromBean(protocol); - rows.add(row); - } - tableModel.setRows(rows, false); - table.setModel(tableModel); - table.setColumnModel(columnModel); // init species combo box initBeanComboBox(ui.getSpeciesComboBox(), speciesList, null); selectFirstInCombo(ui.getSpeciesComboBox()); -// // Species -// final JComboBox speciesCombo = ui.getNewSpeciesRowCombo(); -// speciesCombo.setRenderer(newListCellRender(Species.class)); -// speciesCombo.setModel(new DefaultComboBoxModel()); -// for (Species species : allSpecies.values()) { -// speciesCombo.addItem(species); -// } -// speciesCombo.getModel().addListDataListener(new ListDataListener() { -// -// public void intervalAdded(ListDataEvent e) { -// speciesCombo.setEnabled(true); -// ui.getAddRow().setEnabled(true); -// } -// -// public void intervalRemoved(ListDataEvent e) { -// if (speciesCombo.getItemCount() == 0) { -// speciesCombo.setEnabled(false); -// ui.getAddRow().setEnabled(false); -// } -// } -// -// public void contentsChanged(ListDataEvent e) { -// speciesCombo.setEnabled(true); -// ui.getAddRow().setEnabled(true); -// } -// }); - ListSelectionListener listener = new TableRowModificationListener<EditProtocolSpeciesRowModel>( - tableModel, getRowMonitor()) { + // init gear pmfm double list + List<Caracteristic> gearPmfm = + persistenceService.getAllFishingOperationGearCaracteristic(); + initDoubleList(ui.getGearList(), gearPmfm, model.getGearPmfmId()); - @Override - protected void saveSelectedRow() { - TuttiBeanMonitor<EditProtocolSpeciesRowModel> monitor = getRowMonitor(); - EditProtocolSpeciesRowModel row = monitor.getBean(); - if (row != null && monitor.wasModified()) { - getModel().setModify(true); - } - } - }; - table.getSelectionModel().addListSelectionListener(listener); + // init environement pmfm double list + List<Caracteristic> environmentPmfm = + persistenceService.getAllFishingOperationEnvironmentCaracteristic(); + initDoubleList(ui.getEnvironmentList(), + environmentPmfm, + model.getEnvironmentPmfmId()); - // PMFM - List<Caracteristic> gearPmfm = persistenceService.getAllFishingOperationGearCaracteristic(); - initDoubleList(ui.getGearList(), gearPmfm, model.getGearPmfmId()); - List<Caracteristic> environmentPmfm = persistenceService.getAllFishingOperationEnvironmentCaracteristic(); - initDoubleList(ui.getEnvironmentList(), environmentPmfm, model.getEnvironmentPmfmId()); - //hydro + // init hydro pmfm double list List<Caracteristic> selection = Lists.newArrayList(); Collection<String> availableCaracteristicNames = hydroCaracteristics.keySet(); List<Caracteristic> availableCaracteristics = Lists.newArrayList(); @@ -369,31 +329,20 @@ } } } - initBeanList(ui.getHydrologyList(), availableCaracteristics, selection); // if new protocol can already cancel his creation model.setModify(model.isCreate()); } - protected void initDoubleList(BeanDoubleList<Caracteristic> widget, - List<Caracteristic> availableCaracteristics, - List<String> selectedCaracteristics) { - List<Caracteristic> selection = Lists.newArrayList(); - if (selectedCaracteristics != null) { - for (Caracteristic caracteristic : availableCaracteristics) { - if (selectedCaracteristics.contains(caracteristic.getId())) { - selection.add(caracteristic); - } - } - } - initBeanList(widget, availableCaracteristics, selection); - } - @Override public void onCloseUI() { } + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + public void cancel() { context.setScreen(TuttiScreen.SELECT_CRUISE); @@ -407,11 +356,12 @@ // get the species protocols from the table List<SpeciesProtocol> protocols = Lists.newArrayList(); - List<EditProtocolSpeciesRowModel> rows = - ((AbstractTuttiTableModel<EditProtocolSpeciesRowModel>) ui.getSpeciesTable().getModel()).getRows(); - for (EditProtocolSpeciesRowModel row : rows) { - SpeciesProtocol protocol = row.toBean(); - protocols.add(protocol); + + for (EditProtocolSpeciesRowModel row : getTableModel().getRows()) { + if (row.isValid()) { + SpeciesProtocol protocol = row.toBean(); + protocols.add(protocol); + } } bean.setSpecies(protocols); @@ -459,4 +409,22 @@ selectFirstInCombo(ui.getSpeciesComboBox()); // getModel().setModify(true); } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void initDoubleList(BeanDoubleList<Caracteristic> widget, + List<Caracteristic> availableCaracteristics, + List<String> selectedCaracteristics) { + List<Caracteristic> selection = Lists.newArrayList(); + if (selectedCaracteristics != null) { + for (Caracteristic caracteristic : availableCaracteristics) { + if (selectedCaracteristics.contains(caracteristic.getId())) { + selection.add(caracteristic); + } + } + } + initBeanList(widget, availableCaracteristics, selection); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java 2012-12-30 19:39:00 UTC (rev 132) @@ -29,7 +29,6 @@ import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -162,16 +161,16 @@ setHydrologyPmfmId(ids); } - public List<SpeciesProtocol> getSpecies() { - return species; - } +// public List<SpeciesProtocol> getSpecies() { +// return species; +// } +// +// public void setSpecies(List<SpeciesProtocol> species) { +// Object oldValue = getSpecies(); +// this.species = species; +// firePropertyChange(PROPERTY_SPECIES, oldValue, species); +// } - public void setSpecies(List<SpeciesProtocol> species) { - Object oldValue = getSpecies(); - this.species = species; - firePropertyChange(PROPERTY_SPECIES, oldValue, species); - } - public List<SampleCategoryEnum> getSampleCategoryOrder() { return sampleCategoryOrder; } @@ -181,11 +180,4 @@ this.sampleCategoryOrder = sampleCategoryOrder; firePropertyChange(PROPERTY_SAMPLE_CATEGORY_ORDER, oldValue, sampleCategoryOrder); } - - - //>>>--- Warning Added only to be able to use a BeanComboBox editor! ---// - - public void setSelectedSpecies(Species selectedSpecies) { - } - //<<<--- Warning Added only to be able to use a BeanComboBox editor! ---// } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/HydrologicCaracteristicUtil.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/HydrologicCaracteristicUtil.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/HydrologicCaracteristicUtil.java 2012-12-30 19:39:00 UTC (rev 132) @@ -28,8 +28,8 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; /** - * * @author kmorin <kmorin@codelutin.com> + * @since 0.3 */ public class HydrologicCaracteristicUtil { @@ -38,14 +38,14 @@ END, AVERAGE } - + public static String getGlobalName(String name) { if (name.charAt(name.length() - 2) == '_') { name = name.substring(0, name.length() - 2); } return name; } - + public static Caracteristic createGlobalCaracteristic(String name, Caracteristic toClone) { Caracteristic caracteristic = new Caracteristic(); caracteristic.setName(name); @@ -61,7 +61,7 @@ } return caracteristic; } - + public static Type getTypeOfCaracteristic(Caracteristic caracteristic) { String name = caracteristic.getName(); Type result = null; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -37,11 +37,11 @@ } #addButton { - actionIcon: "add"; + actionIcon: add; } #closeButton { - actionIcon: "close"; + actionIcon: close; text: "tutti.action.close"; mnemonic: F; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx 2012-12-30 19:39:00 UTC (rev 132) @@ -22,13 +22,13 @@ #L% --> <Table id='mainPanel'> - + <import> fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel fr.ifremer.tutti.persistence.entities.data.Attachment jaxx.runtime.swing.editor.FileEditor </import> - + <!-- bean property linked state --> <String id='property' javaBean='""'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -36,11 +36,9 @@ import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.SwingConstants; import java.awt.Cursor; -import java.awt.Font; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -186,7 +184,7 @@ } protected void resetFields() { - ui.getFile().setSelectedFile((File)null); + ui.getFile().setSelectedFile((File) null); ui.getFileName().setText(""); ui.getFileComment().setText(""); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueEditor.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueEditor.java 2012-12-30 19:39:00 UTC (rev 132) @@ -29,14 +29,6 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; -import java.awt.Color; -import java.awt.Component; -import java.util.List; -import javax.swing.AbstractCellEditor; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.TableCellEditor; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.swing.editor.bean.BeanUIUtil; @@ -46,32 +38,43 @@ import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; import org.nuiton.util.decorator.Decorator; +import javax.swing.AbstractCellEditor; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import java.awt.Color; +import java.awt.Component; +import java.util.List; + /** * Editor for the values of the caracteristics of the fishing operations. * The editor depends on the caracteristic value type. - * + * * @author kmorin <kmorin@codelutin.com> * @since 0.3 */ public class CaracteristicValueEditor extends AbstractCellEditor implements TableCellEditor { + private static final long serialVersionUID = 1L; + protected int caracteristicColumn; - + protected TableCellEditor editor; - + protected Decorator<CaracteristicQualitativeValue> decorator; - + public CaracteristicValueEditor(TuttiUIContext context) { this(0, context); } - + public CaracteristicValueEditor(int caracteristicColumn, TuttiUIContext context) { super(); this.caracteristicColumn = caracteristicColumn; DecoratorService decoratorService = context.getService(DecoratorService.class); decorator = decoratorService.getDecoratorByType(CaracteristicQualitativeValue.class); } - + @Override public Object getCellEditorValue() { return editor.getCellEditorValue(); @@ -80,37 +83,36 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { editor = table.getDefaultEditor(Object.class); - + Caracteristic caracteristic = (Caracteristic) table.getModel().getValueAt(row, caracteristicColumn); - if (caracteristic != null) { + if (caracteristic != null) { if (caracteristic.isBooleanType()) { editor = table.getDefaultEditor(Boolean.class); - + } else if (caracteristic.isNumberType()) { NumberCellEditor<Float> editor = - JAXXWidgetUtil.newNumberTableCellEditor(Float.class, false); + JAXXWidgetUtil.newNumberTableCellEditor(Float.class, false); editor.getNumberEditor().setSelectAllTextOnError(true); editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); this.editor = editor; - + } else if (caracteristic.isQualitativeType()) { JComboBox comboBox = new JComboBox(); comboBox.setRenderer(new DecoratorListCellRenderer(decorator)); - + List<CaracteristicQualitativeValue> data = caracteristic.getQualitativeValue(); // add a null value at first position if (!data.isEmpty() && data.get(0) != null) { data.add(0, null); } SwingUtil.fillComboBox(comboBox, data, null); - ObjectToStringConverter converter = BeanUIUtil.newDecoratedObjectToStringConverter(decorator); BeanUIUtil.decorate(comboBox, converter); editor = new ComboBoxCellEditor(comboBox); } } - + Component result = editor.getTableCellEditorComponent(table, value, isSelected, row, column); return result; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueRenderer.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueRenderer.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/CaracteristicValueRenderer.java 2012-12-30 19:39:00 UTC (rev 132) @@ -29,48 +29,44 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; -import java.awt.Component; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.editor.bean.BeanUIUtil; import jaxx.runtime.swing.renderer.DecoratorTableCellRenderer; -import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; -import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; import org.nuiton.util.decorator.Decorator; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; +import java.awt.Component; + /** * Renderer for the values of the caracteristics of the fishing operations. * The renderer depends on the caracteristic value type. - * + * * @author kmorin <kmorin@codelutin.com> * @since 0.3 */ public class CaracteristicValueRenderer implements TableCellRenderer { protected int caracteristicColumn; - + protected Decorator<CaracteristicQualitativeValue> decorator; - + public CaracteristicValueRenderer(TuttiUIContext context) { this(0, context); } - + public CaracteristicValueRenderer(int caracteristicColumn, TuttiUIContext context) { super(); this.caracteristicColumn = caracteristicColumn; DecoratorService decoratorService = context.getService(DecoratorService.class); decorator = decoratorService.getDecoratorByType(CaracteristicQualitativeValue.class); } - + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { TableCellRenderer renderer = table.getDefaultRenderer(Object.class); Caracteristic caracteristic = (Caracteristic) table.getModel().getValueAt(row, caracteristicColumn); - if (caracteristic != null) { + if (caracteristic != null) { if (caracteristic.isBooleanType()) { renderer = table.getDefaultRenderer(Boolean.class); - + } else if (caracteristic.isQualitativeType()) { renderer = new DecoratorTableCellRenderer(decorator); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-30 19:39:00 UTC (rev 132) @@ -32,7 +32,6 @@ import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; -import java.awt.event.FocusEvent; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.lang3.StringUtils; @@ -50,7 +49,6 @@ import java.awt.Color; import java.awt.Component; import java.awt.Frame; -import java.awt.event.FocusListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -158,7 +156,7 @@ ComponentMover cm = new ComponentMover(); cm.setDragInsets(cr.getDragInsets()); cm.registerComponent(editor); - + editor.addWindowListener(new WindowAdapter() { @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css 2012-12-30 19:39:00 UTC (rev 132) @@ -22,7 +22,7 @@ * #L% */ #closeButton { - actionIcon: "close"; + actionIcon: close; text: "tutti.action.close"; mnemonic: F; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css 2012-12-30 19:39:00 UTC (rev 132) @@ -23,23 +23,22 @@ */ #hour { - value:{model.getTimeModel() / 60}; - enabled:{isEnabled()}; - model:{new SpinnerNumberModel(0, 0, 23, 1)}; + value: {model.getTimeModel() / 60}; + enabled: {isEnabled()}; + model: {new SpinnerNumberModel(0, 0, 23, 1)}; } #labelH { - text:"tutti.timeeditor.H"; - horizontalAlignment:center; + text: "tutti.timeeditor.H"; + horizontalAlignment: center; } #minuteModel { - calendarField:{java.util.Calendar.MINUTE}; - value:{handler.setMinuteModel(model.getDate())}; + calendarField: {java.util.Calendar.MINUTE}; + value: {handler.setMinuteModel(model.getDate())}; } #minute { - enabled:{isEnabled()}; - model:{minuteModel}; + enabled: {isEnabled()}; + model: {minuteModel}; } - Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2012-12-30 19:39:00 UTC (rev 132) @@ -26,32 +26,40 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Sets; +import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.swing.editor.bean.BeanUIUtil; import jaxx.runtime.swing.editor.cell.NumberCellEditor; import jaxx.runtime.swing.renderer.DecoratorTableCellRenderer; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.table.TableColumnExt; import org.nuiton.util.decorator.Decorator; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.border.LineBorder; +import javax.swing.event.ListSelectionListener; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import java.awt.Color; +import java.awt.Component; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; @@ -76,39 +84,57 @@ LogFactory.getLog(AbstractTuttiTableUIHandler.class); /** - * Monitor the selected row (save it only if something has changed). - * + * @return the table model handled byt the main table. * @since 0.2 */ - private final TuttiBeanMonitor<R> rowMonitor; + protected abstract AbstractTuttiTableModel<R> getTableModel(); + /** + * @return the main table of the ui. + * @since 0.2 + */ protected abstract JXTable getTable(); - protected abstract AbstractTuttiTableModel<R> getTableModel(); + /** + * Validates the given row. + * + * @param row row to validate + * @return {@code true} if row is valid, {@code false} otherwise. + * @since 0.2 + */ + protected abstract boolean isRowValid(R row); - protected abstract void onRowModified(R row, - String propertyName, - Object oldValue, - Object newValue); + /** + * Given the row monitor and his monitored row, try to save it if required. + * <p/> + * Coming in this method, we are sure that row is not null. + * + * @param rowMonitor the row monitor (see {@link #rowMonitor}) + * @param row the row to save if necessary + * @since 0.3 + */ + protected abstract void saveSelectedRowIfRequired(TuttiBeanMonitor<R> rowMonitor, R row); - protected abstract void onRowValidStateChanged(R row, - Boolean oldValue, - Boolean newValue); + /** + * Monitor the selected row (save it only if something has changed). + * + * @since 0.2 + */ + private final TuttiBeanMonitor<R> rowMonitor; - protected abstract void onRowModifyStateChanged(R row, - Boolean oldValue, - Boolean newValue); + /** + * Persistence service. + * + * @since 0.2 + */ + protected final PersistenceService persistenceService; - protected abstract boolean isRowValid(R row); - - protected String[] getRowPropertiesToIgnore() { - return ArrayUtils.EMPTY_STRING_ARRAY; - } - protected AbstractTuttiTableUIHandler(TuttiUIContext context, String... properties) { super(context); + this.persistenceService = context.getService(PersistenceService.class); + rowMonitor = new TuttiBeanMonitor<R>(properties); // listen when bean is changed @@ -127,17 +153,19 @@ Object oldValue = evt.getOldValue(); Object newValue = evt.getNewValue(); + int rowIndex = getTableModel().getRowIndex(row); + if (AbstractTuttiBeanUIModel.PROPERTY_VALID.equals(propertyName)) { - onRowValidStateChanged(row, + onRowValidStateChanged(rowIndex, row, (Boolean) oldValue, (Boolean) newValue); } else if (AbstractTuttiBeanUIModel.PROPERTY_MODIFY.equals(propertyName)) { - onRowModifyStateChanged(row, + onRowModifyStateChanged(rowIndex, row, (Boolean) oldValue, (Boolean) newValue); } else if (!propertiesToSkip.contains(propertyName)) { - onRowModified(row, + onRowModified(rowIndex, row, propertyName, oldValue, newValue); @@ -163,6 +191,132 @@ }); } + //------------------------------------------------------------------------// + //-- Internal methods (row methods) --// + //------------------------------------------------------------------------// + + protected String[] getRowPropertiesToIgnore() { + return ArrayUtils.EMPTY_STRING_ARRAY; + } + + protected void onModelRowsChanged(List<R> rows) { + if (CollectionUtils.isNotEmpty(rows)) { + for (R row : rows) { + boolean rowIsValid = isRowValid(row); + row.setValid(rowIsValid); + } + } + getTableModel().setRows(rows); + } + + protected void onRowModified(int rowIndex, + R row, + String propertyName, + Object oldValue, + Object newValue) { + + if (log.isInfoEnabled()) { + log.info("row [" + rowIndex + "] property " + + propertyName + " changed from " + oldValue + + " to " + newValue); + } + + // recompute row valid state + boolean valid = isRowValid(row); + + // apply it to row + row.setValid(valid); + } + + protected void onRowModifyStateChanged(int rowIndex, + R row, + Boolean oldValue, + Boolean newValue) { + if (log.isInfoEnabled()) { + log.info("row [" + rowIndex + "] modify state changed from " + + oldValue + " to " + newValue); + } + } + + protected void onRowValidStateChanged(int rowIndex, + R row, + Boolean oldValue, + Boolean newValue) { + + if (log.isInfoEnabled()) { + log.info("row [" + rowIndex + "] valid state changed from " + + oldValue + " to " + newValue); + } + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + //------------------------------------------------------------------------// + //-- Internal methods (init methods) --// + //------------------------------------------------------------------------// + + protected void initTable(JXTable table) { + + // by default do not authorize to change column orders + table.getTableHeader().setReorderingAllowed(false); + + // paint in a special color read only cells + Highlighter readOnlyHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( + HighlightPredicate.READ_ONLY, getConfig().getColorRowReadOnly()); + table.addHighlighter(readOnlyHighlighter); + + // paint in a special color inValid rows + Highlighter validHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( + new HighlightPredicate.AndHighlightPredicate(HighlightPredicate.EDITABLE, new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + + boolean result = false; + if (adapter.isEditable()) { + int rowIndex = adapter.convertRowIndexToModel(adapter.row); + R row = getTableModel().getEntry(rowIndex); + result = !row.isValid(); + } + return result; + } + }), getConfig().getColorRowInvalid()); + table.addHighlighter(validHighlighter); + + // when model data change let's propagate it table model + getModel().addPropertyChangeListener(AbstractTuttiTableUIModel.PROPERTY_ROWS, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + onModelRowsChanged((List<R>) evt.getNewValue()); + } + }); + + // always scroll to selected row + SwingUtil.scrollToTableSelection(getTable()); + + // save when row chaged and was modified + ListSelectionListener listener = new TableRowModificationListener<R>( + getTableModel(), rowMonitor) { + @Override + protected void saveSelectedRow() { + + saveSelectedRowIfNeeded(); + } + }; + table.getSelectionModel().addListSelectionListener(listener); + } + + protected final void saveSelectedRowIfNeeded() { + + R row = rowMonitor.getBean(); + + if (row != null) { + + saveSelectedRowIfRequired(rowMonitor, row); + } + } + protected KeyListener installTableKeyListener(TableColumnModel columnModel, JTable table) { @@ -262,7 +416,6 @@ addColumnToModel(model, editor, null, identifier); } - protected void addBooleanColumnToModel(TableColumnModel model, ColumnIdentifier<R> identifier, JTable table) { @@ -296,19 +449,6 @@ identifier); } - protected void listenRowsFromModel() { - getModel().addPropertyChangeListener(AbstractTuttiTableUIModel.PROPERTY_ROWS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - onModelRowsChanged((List<R>) evt.getNewValue()); - } - }); - } - - protected void onModelRowsChanged(List<R> rows) { - getTableModel().setRows(rows); - } - protected <O> TableCellRenderer newTableCellRender(Class<O> type) { return newTableCellRender(type, null); @@ -330,8 +470,4 @@ return result; } - protected TuttiBeanMonitor<R> getRowMonitor() { - return rowMonitor; - } - } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java 2012-12-30 19:39:00 UTC (rev 132) @@ -51,8 +51,8 @@ } protected ColumnIdentifier(String propertyName, - String headerI18nKey, - String headerTipI18nKey) { + String headerI18nKey, + String headerTipI18nKey) { this.propertyName = propertyName; this.headerI18nKey = headerI18nKey; this.headerTipI18nKey = headerTipI18nKey; Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-30 19:35:31 UTC (rev 131) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-30 19:39:00 UTC (rev 132) @@ -20,6 +20,7 @@ tutti.action.new=Nouveau tutti.action.pupitri-import=Import PUPITRI tutti.action.reload.actions=Recharger les actions +tutti.action.reload.application=Recharger l'application tutti.action.reload.home=Reload home screen tutti.action.reload.ui=Recharger l'interface graphique tutti.action.reset.fishingOperationValidState=Réinitialiser @@ -32,6 +33,8 @@ tutti.application.name=Tutti tutti.config.category.applications=Application tutti.config.category.applications.description=Application +tutti.config.category.colors=Couleurs +tutti.config.category.colors.description=Couleurs utilisées dans les interfaces graphiques tutti.config.category.other=Autres tutti.config.category.other.description=Autres options tutti.config.category.shortcuts=Raccourcis @@ -40,7 +43,10 @@ tutti.config.programId=Identifiant de la dernière série de campagne utilisée tutti.config.protocolId=Identifiant du dernier protocole utilisé tutti.config.ui.autoPopupNumberEditor=Toujours afficher le pavé numérique lors de l'édition d'un nombre +tutti.config.ui.color.rowInvalid=Ligne invalide +tutti.config.ui.color.rowReadOnly=Cellule non éditable tutti.config.ui.config=Chemin du fichier de configuration des interfaces graphiques +tutti.config.ui.shortcut.closePopup=Fermer une popup tutti.config.ui.showNumberEditorButton=Afficher le pavé numérique de saisie tutti.label.attachmentEditor.file=Fichier tutti.label.attachmentEditor.fileComment=Commentaire Added: trunk/tutti-ui-swing/src/main/resources/icons/action-reload-application.png =================================================================== (Binary files differ) Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-reload-application.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/tutti-ui-swing/src/main/resources/icons/action-reload-shortcut.png =================================================================== (Binary files differ) Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-reload-shortcut.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: svn:keywords + Author Date Id Revision HeadURL