15/32: refs #8429 : réusinage des arbres
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit fe96e92e9d3e3c9f7d0f22376623df49fc212c07 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Nov 21 07:57:52 2016 +0100 refs #8429 : réusinage des arbres --- .../swing/decoration/DecoratorService.java | 8 +- .../ObserveSwingApplicationDataSourcesManager.java | 14 +- .../application/swing/ui/ObserveMainUI.jaxx | 31 +- .../application/swing/ui/ObserveMainUI.jcss | 5 - .../application/swing/ui/ObserveMainUIHandler.java | 168 +++-- .../swing/ui/actions/ReloadStorageAction.java | 7 +- .../ui/actions/content/CancelCreateUIAction.java | 9 +- .../ui/actions/content/CloseAndCreateUIAction.java | 41 +- .../ui/actions/content/CloseOpenUIAction.java | 15 +- .../content/MoveActivityLonglinesUIAction.java | 36 +- .../content/MoveActivitySeinesUIAction.java | 37 +- .../ui/actions/content/MoveRoutesUIAction.java | 37 +- .../ui/actions/content/MoveTripsUIAction.java | 35 +- .../swing/ui/actions/content/ReOpenUIAction.java | 13 +- .../ui/actions/content/ResetEditUIAction.java | 9 +- .../swing/ui/actions/shared/AbstractUIAction.java | 22 - .../swing/ui/actions/shared/GoDownUIAction.java | 34 +- .../swing/ui/actions/shared/GoUpUIAction.java | 19 +- .../ui/actions/shared/SelectNodeUIAction.java | 6 +- .../ui/actions/shared/SelectOpenNodeUIAction.java | 2 +- .../swing/ui/admin/AdminTabUIHandler.java | 74 +-- .../application/swing/ui/admin/AdminUIHandler.java | 31 + .../application/swing/ui/admin/AdminUIModel.java | 216 +++---- .../swing/ui/admin/config/ConfigUI.jaxx | 3 +- .../swing/ui/admin/config/ConfigUIHandler.java | 28 +- .../swing/ui/admin/config/SelectDataUI.jaxx | 40 +- .../swing/ui/admin/config/SelectDataUI.jcss | 19 +- .../ui/admin/consolidate/ConsolidateUIHandler.java | 44 +- .../swing/ui/admin/export/ExportModel.java | 65 +- .../swing/ui/admin/export/ExportUIHandler.java | 23 +- .../swing/ui/admin/report/ReportUIHandler.java | 26 +- .../admin/synchronize/data/DataSynchroModel.java | 40 +- .../data/DataSynchroSelectionTreeCellRenderer.java | 45 +- .../ui/admin/synchronize/data/DataSynchroUI.jaxx | 33 +- .../ui/admin/synchronize/data/DataSynchroUI.jcss | 22 - .../synchronize/data/DataSynchroUIHandler.java | 93 ++- .../referential/ng/ReferentialSynchroUI.jaxx | 4 - .../swing/ui/admin/validate/ValidateUI.jaxx | 4 +- .../swing/ui/admin/validate/ValidateUIHandler.java | 82 +-- .../application/swing/ui/content/ContentUI.jaxx | 3 - .../swing/ui/content/ContentUIHandler.java | 157 ++--- .../swing/ui/content/ContentUIManager.java | 224 +------ .../swing/ui/content/ObserveFocusManager.java | 2 + .../content/impl/longline/BranchlineUIHandler.java | 5 + .../LonglineGlobalCompositionUIHandler.java | 19 +- .../impl/longline/SetLonglineUIHandler.java | 10 +- .../impl/seine/FloatingObjectUIHandler.java | 10 +- .../ui/content/impl/seine/SetSeineUIHandler.java | 10 +- .../ui/content/list/ContentListUIHandler.java | 46 +- .../ui/content/open/ContentOpenableUIHandler.java | 28 +- .../impl/longline/ActivityLonglineUIHandler.java | 4 +- .../open/impl/seine/ActivitySeineUIHandler.java | 4 +- .../ui/content/open/impl/seine/RouteUIHandler.java | 17 +- .../ui/content/ref/ContentReferenceUIHandler.java | 8 +- .../ui/content/table/ContentTableUIHandler.java | 11 +- .../impl/longline/BaitsCompositionUIHandler.java | 5 + .../longline/BranchlinesCompositionUIHandler.java | 5 + .../impl/longline/CatchLonglineUIHandler.java | 19 +- .../longline/FloatlinesCompositionUIHandler.java | 5 + .../impl/longline/HooksCompositionUIHandler.java | 5 + .../swing/ui/storage/ObstunaAdminAction.java | 53 +- .../swing/ui/storage/StorageBackupUILauncher.java | 30 +- .../swing/ui/storage/StorageUIHandler.java | 207 +++--- .../swing/ui/storage/StorageUILauncher.java | 198 +++--- .../swing/ui/storage/StorageUIModel.java | 105 ++- .../swing/ui/storage/tabs/ChooseDbModeUI.jcss | 2 +- .../swing/ui/storage/tabs/DataSelectionModel.java | 619 ------------------ .../swing/ui/storage/tabs/SelectDataUI.jaxx | 24 +- .../swing/ui/storage/tabs/SelectDataUI.jcss | 6 - .../swing/ui/storage/tabs/StorageTabUIHandler.java | 99 +-- .../ui/tree/DataSelectionTreeSelectionModel.java | 709 --------------------- .../ui/tree/NavigationTreeSelectionModel.java | 117 ---- .../swing/ui/tree/ObserveDataProvider.java | 83 --- .../tree/ObserveNavigationTreeShowPopupAction.java | 52 +- .../swing/ui/tree/ObserveTreeBridge.java | 142 ----- .../swing/ui/tree/ObserveTreeHelper.java | 625 ------------------ .../swing/ui/tree/ObserveTreeNodeSupport.java | 39 ++ .../actions/ChangeActivityRouteActionListener.java | 25 +- .../actions/ChangeActivityTripActionListener.java | 25 +- .../actions/ChangeRouteTripActionListener.java | 25 +- .../actions/ChangeTripProgramActionListener.java | 23 +- .../ui/tree/actions/NodeChangeActionListener.java | 36 +- .../ui/tree/loadors/AbstractNodeChildLoador.java | 95 --- .../loadors/ActivityLonglineNodeChildLoador.java | 109 ---- .../loadors/ActivityLonglinesNodeChildLoador.java | 64 -- .../tree/loadors/ActivitySeineNodeChildLoador.java | 97 --- .../loadors/ActivitySeinesNodeChildLoador.java | 66 -- .../loadors/FloatingObjectNodeChildLoador.java | 60 -- .../loadors/ProgramLonglineNodeChildLoador.java | 126 ---- .../tree/loadors/ProgramSeineNodeChildLoador.java | 119 ---- .../ui/tree/loadors/ReferenceNodeChildLoador.java | 80 --- .../swing/ui/tree/loadors/RootNodeChildLoador.java | 148 ----- .../ui/tree/loadors/RoutesNodeChildLoador.java | 70 -- .../tree/loadors/SetLonglineNodeChildLoador.java | 67 -- .../ui/tree/loadors/SetSeineNodeChildLoador.java | 76 --- .../MoveActivityLonglineNodeMenuPopulator.java | 29 +- .../menu/MoveActivitySeineNodeMenuPopulator.java | 29 +- .../swing/ui/tree/menu/MoveNodeMenuPopulator.java | 18 +- .../ui/tree/menu/MoveRouteNodeMenuPopulator.java | 29 +- .../ui/tree/menu/MoveTripNodeMenuPopulator.java | 41 +- .../swing/ui/tree/navigation/NavigationTree.java | 563 ++++++++++++++++ .../navigation/NavigationTreeCellRenderer.java | 208 ++++++ .../ui/tree/navigation/NavigationTreeModel.java | 83 +++ .../navigation/nodes/ClassNavigationTreeNode.java | 57 ++ .../nodes/NavigationTreeNodeSupport.java | 132 ++++ .../nodes/ReferenceNavigationTreeNodeSupport.java | 45 ++ .../navigation/nodes/RootNavigationTreeNode.java | 71 +++ .../nodes/StringNavigationTreeNodeSupport.java | 52 ++ .../ActivitiesLonglineNavigationTreeNode.java | 44 ++ .../ActivityLonglineNavigationTreeNode.java | 64 ++ .../longline/CatchLonglineNavigationTreeNode.java | 23 + .../EncounterLonglineNavigationTreeNode.java | 23 + .../GearUseFeaturesLonglineNavigationTreeNode.java | 23 + .../ProgramLonglineNavigationTreeNode.java | 47 ++ .../SensorUsedLonglineNavigationTreeNode.java | 23 + ...etailCompositionLonglineNavigationTreeNode.java | 23 + ...lobalCompositionLonglineNavigationTreeNode.java | 23 + .../longline/SetLonglineNavigationTreeNode.java | 38 ++ .../longline/TdrLonglineNavigationTreeNode.java | 23 + .../longline/TripLonglineNavigationTreeNode.java | 39 ++ .../referential/ReferentialNavigationTreeNode.java | 47 ++ .../ReferentialsNavigationTreeNode.java | 51 ++ .../seine/ActivitiesSeineNavigationTreeNode.java | 50 ++ .../seine/ActivitySeineNavigationTreeNode.java | 50 ++ ...cardedTargetCatchesSeineNavigationTreeNode.java | 23 + ...cardedTargetSamplesSeineNavigationTreeNode.java | 23 + .../FloatingObjectSeineNavigationTreeNode.java | 35 + .../GearUseFeaturesSeineNavigationTreeNode.java | 23 + .../KeptTargetCatchesSeineNavigationTreeNode.java | 23 + .../KeptTargetSamplesSeineNavigationTreeNode.java | 26 + .../NonTargetCatchesSeineNavigationTreeNode.java | 23 + .../NoneTargetSamplesSeineNavigationTreeNode.java | 23 + .../seine/ProgramSeineNavigationTreeNode.java | 48 ++ .../nodes/seine/RouteSeineNavigationTreeNode.java | 36 ++ .../nodes/seine/RoutesSeineNavigationTreeNode.java | 50 ++ .../SchoolEstimatesSeineNavigationTreeNode.java | 23 + .../nodes/seine/SetSeineNavigationTreeNode.java | 41 ++ .../nodes/seine/TripSeineNavigationTreeNode.java | 40 ++ .../ui/tree/node/AbstrctReferenceNodeSupport.java | 103 --- .../swing/ui/tree/node/ActivityLonglineNode.java | 52 -- .../swing/ui/tree/node/ActivitySeineNode.java | 52 -- .../ui/tree/node/DataReferenceNodeSupport.java | 98 --- .../ui/tree/node/FloatingObjectSeineNode.java | 52 -- .../swing/ui/tree/node/ObserveNode.java | 119 ---- .../swing/ui/tree/node/ProgramLonglineNode.java | 71 --- .../swing/ui/tree/node/ProgramSeineNode.java | 69 -- .../tree/node/ReferentialReferenceNodeSupport.java | 85 --- .../swing/ui/tree/node/RouteSeineNode.java | 49 -- .../swing/ui/tree/node/SetLonglineNode.java | 52 -- .../swing/ui/tree/node/SetSeineNode.java | 52 -- .../swing/ui/tree/node/TripLonglineNode.java | 50 -- .../swing/ui/tree/node/TripSeineNode.java | 62 -- .../renderer/AbstractObserveTreeCellRenderer.java | 434 ------------- .../renderer/DataSelectionTreeCellRenderer.java | 140 ---- .../tree/renderer/NavigationTreeCellRenderer.java | 101 --- .../swing/ui/tree/selection/SelectionTree.java | 164 +++++ .../tree/selection/SelectionTreeCellRenderer.java | 39 ++ .../ui/tree/selection/SelectionTreeHeader.jaxx | 43 ++ .../SelectionTreeHeader.jcss} | 47 +- .../tree/selection/SelectionTreeHeaderHandler.java | 96 +++ .../ui/tree/selection/SelectionTreeModel.java | 339 ++++++++++ .../selection/nodes/ProgramSelectionTreeNode.java | 85 +++ .../nodes/ReferenceSelectionTreeNodeSupport.java | 52 ++ .../nodes/ReferentialSelectionTreeNode.java | 51 ++ .../nodes/ReferentialsSelectionTreeNode.java | 86 +++ .../selection/nodes/RootSelectionTreeNode.java | 115 ++++ .../selection/nodes/SelectionTreeNodeSupport.java | 68 ++ .../nodes/TripLonglineSelectionTreeNode.java | 44 ++ .../nodes/TripSeineSelectionTreeNode.java | 45 ++ .../nodes/TripSelectionTreeNodeSupport.java | 27 + .../swing/ui/util/DecoratedNodeEntity.java | 6 +- .../ftl/dataSourceConnectionReport_en.ftl | 10 +- .../ftl/dataSourceConnectionReport_es.ftl | 10 +- .../ftl/dataSourceConnectionReport_fr.ftl | 10 +- .../i18n/application-swing_en_GB.properties | 2 + .../i18n/application-swing_es_ES.properties | 2 + .../i18n/application-swing_fr_FR.properties | 2 + .../entities/longline/TripLonglineImpl.java | 11 + .../entities/longline/TripLonglineTopiaDao.java | 7 +- .../entities/referentiel/ProgramTopiaDao.java | 124 ---- entities/src/main/xmi/observe-longline.zargo | Bin 93824 -> 93999 bytes .../dto/reference/DataReferenceSetDefinitions.java | 1 + .../services/dto/longline/TripLonglineHelper.java | 10 + .../services/dto/referential/ProgramHelper.java | 6 +- .../seine/VesselActivitySeineHelper.java | 26 +- .../services/dto/seine/ActivitySeineDto.java | 25 +- .../services/dto/seine/TripSeineHelper.java | 9 + .../main/xmi/observe-services-dto-longline.zargo | Bin 67946 -> 68017 bytes 188 files changed, 4899 insertions(+), 7147 deletions(-) diff --git a/application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java b/application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java index 9190d0f..d8393a7 100644 --- a/application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java +++ b/application-swing-decoration/src/main/java/fr/ird/observe/application/swing/decoration/DecoratorService.java @@ -466,13 +466,13 @@ public class DecoratorService extends DecoratorProvider { return (DataReferenceDecorator<T>) (DataReferenceDecorator) getDecoratorByType(DataReference.class, referenceType.getSimpleName() + context); } - public Decorator getReferenceDecorator(Class referenceType) { - Decorator decorator; + public <D extends IdDto> Decorator<D> getReferenceDecorator(Class<D> referenceType) { + Decorator<D> decorator; if (DataDto.class.isAssignableFrom(referenceType)) { - decorator = this.getDataReferenceDecorator(referenceType); + decorator = getDataReferenceDecorator((Class)referenceType); } else { - decorator = this.getReferentialReferenceDecorator(referenceType); + decorator = getReferentialReferenceDecorator((Class)referenceType); } return decorator; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java index 9b12f1f..ff923d3 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java @@ -33,12 +33,11 @@ import fr.ird.observe.application.swing.db.event.ObserveSwingDataSourceListenerA import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.ObserveUIMode; import fr.ird.observe.application.swing.ui.actions.ChangeStorageAction; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; +import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; -import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.runner.ObserveDataSourceConfigurationMainFactory; import fr.ird.observe.services.service.BabModelVersionException; import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; @@ -374,7 +373,8 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { applicationContext.getConfig().saveTreeOpenNodeIds(dataContext.getOpenIds()); dataContext.populateOpens(); - mainUI.getTreeHelper().cleanNavigationUI(mainUI); + mainUI.getHandler().cleanNavigationUI(mainUI); +// mainUI.getTreeHelper().cleanNavigationUI(mainUI); // on met a jour l'état dans la config applicationContext.getConfig().setMainStorageOpened(false); @@ -435,9 +435,7 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { DataContext dataContext = mainUI.getDataContext(); dataContext.setEnabled(true); - ObserveTreeHelper treeHelper = mainUI.getTreeHelper(); - - treeHelper.cleanNavigationUI(mainUI); + mainUI.getHandler().cleanNavigationUI(mainUI); String[] openIds = config.getTreeOpenNodeIds(); @@ -446,7 +444,9 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { } dataContext.populateOpens(openIds); - treeHelper.loadNavigationUI(source); + mainUI.getHandler().loadNavigationUI(mainUI); + + mainUI.getNavigation().getNavigationTreeModel().openRoot(); mainUI.setMode(ObserveUIMode.DB); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx index 22ce441..72d31e4 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx @@ -44,8 +44,7 @@ fr.ird.observe.application.swing.ui.actions.SaveStorageToFileAction fr.ird.observe.application.swing.ui.actions.ShowStorageInfoAction fr.ird.observe.application.swing.ui.content.ContentUIManager - fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper - fr.ird.observe.application.swing.ui.tree.renderer.NavigationTreeCellRenderer + fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree fr.ird.observe.application.swing.ui.util.tree.BeanTreeHeader jaxx.runtime.swing.CardLayout2 @@ -63,10 +62,6 @@ javax.swing.UIManager javax.swing.Icon - <!-- FIXME --> - <!--fr.ird.observe.services.dto.TripDto--> - <!--fr.ird.observe.services.dto.ActivityDto--> - <!--fr.ird.observe.services.dto.SetDto--> </import> <ObserveUIMode id='mode' javaBean='ObserveUIMode.NO_DB'/> @@ -96,8 +91,6 @@ <ObserveMainUIHandler id='handler' initializer='getContextValue(ObserveMainUIHandler.class)'/> - <ObserveTreeHelper id='treeHelper' initializer='getContextValue(ObserveTreeHelper.class)'/> - <DataContext id='dataContext' initializer='ObserveSwingApplicationContext.get().getDataContext()'/> <Boolean id='mainFromSynchro' javaBean='false'/> @@ -113,15 +106,15 @@ <script><![CDATA[ protected Icon updateStorageSatutIcon(boolean isOpened) { - return getHandler().updateStorageSatutIcon(this, isOpened); + return getHandler().updateStorageSatutIcon(this); } protected String updateStorageSatutText(boolean isOpened) { - return getHandler().updateStorageSatutText(this, isOpened); + return getHandler().updateStorageSatutText(this); } protected String updateStorageStatutToolTipText(boolean isOpened) { - return getHandler().updateStorageStatutToolTipText(this, isOpened); + return getHandler().updateStorageStatutToolTipText(this); } @Override @@ -182,18 +175,18 @@ void $afterCompleteSetup() { <JMenu id='menuNavigation'> <JMenuItem id='menuNavigationProgram' - onActionPerformed="getTreeHelper().selectOpenNode(ProgramDto.class)"/> + onActionPerformed="navigation.selectOpenNode(ProgramDto.class)"/> <JMenuItem id='menuNavigationTrip' - onActionPerformed="getTreeHelper().selectOpenNode(TripSeineDto.class)"/> + onActionPerformed="navigation.selectOpenNode(TripSeineDto.class)"/> <JMenuItem id='menuNavigationRoute' - onActionPerformed="getTreeHelper().selectOpenNode(RouteDto.class)"/> + onActionPerformed="navigation.selectOpenNode(RouteDto.class)"/> <JMenuItem id='menuNavigationActivity' - onActionPerformed="getTreeHelper().selectOpenNode(ActivitySeineDto.class)"/> + onActionPerformed="navigation.selectOpenNode(ActivitySeineDto.class)"/> <JMenuItem id='menuNavigationSet' - onActionPerformed="getTreeHelper().selectOpenNode(SetSeineDto.class)"/> + onActionPerformed="navigation.selectOpenNode(SetSeineDto.class)"/> <JSeparator/> <JMenuItem id='menuNavigationReferentiel' - onActionPerformed='getTreeHelper().selectNode("observe.common.referentiel")'/> + onActionPerformed='navigation.selectNode("observe.common.referentiel")'/> </JMenu> <JMenu id='menuConfiguration'> <JMenu id='menuLanguage'> @@ -222,7 +215,7 @@ void $afterCompleteSetup() { <JToolBar id='toolbar'> <javax.swing.Box.Filler - constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> + constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> <!-- pour afficher le status du service de persistance et changer de service de persistance --> <JButton id='storageStatus' @@ -258,7 +251,7 @@ void $afterCompleteSetup() { <JXTitledPanel id='navigationView'> <JScrollPane id='navigationScrollPane' columnHeaderView='{navigationTreeHeader}'> - <JTree id="navigation"/> + <NavigationTree id="navigation"/> <BeanTreeHeader id='navigationTreeHeader' tree='{navigation}'/> </JScrollPane> </JXTitledPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss index 0172c0b..e13f2fa 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss @@ -380,13 +380,8 @@ JSplitPane { } #navigation { - rootVisible: false; - largeModel: true; minimumSize: {UIHelper.newMinDimension()}; font-size:11; - model: {getTreeHelper().getModel()}; - selectionModel: {getTreeHelper().newNavigationSelectionModel()}; - cellRenderer: {new NavigationTreeCellRenderer()}; } #navigationTreeHeader { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java index b6d7b65..5f8c6d6 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java @@ -32,8 +32,10 @@ import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.ContentUIManager; import fr.ird.observe.application.swing.ui.content.ContentUIModel; import fr.ird.observe.application.swing.ui.tree.ObserveNavigationTreeShowPopupAction; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.ObserveSwingValidatorMessageTableModel; import fr.ird.observe.application.swing.ui.util.ObserveValidatorMessageTableRenderer; import fr.ird.observe.services.dto.AbstractObserveDto; @@ -51,11 +53,8 @@ import org.nuiton.i18n.I18n; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.SwingUtilities; -import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; -import javax.swing.event.TreeWillExpandListener; -import javax.swing.tree.ExpandVetoException; import javax.swing.tree.TreePath; import java.awt.Cursor; import java.awt.event.MouseAdapter; @@ -81,7 +80,6 @@ public class ObserveMainUIHandler { public void changeNavigationNode(ObserveMainUI ui, TreeSelectionEvent event) { - ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); if (source == null || !source.isOpen()) { @@ -99,7 +97,7 @@ public class ObserveMainUIHandler { } TreePath path = event.getPath(); - ObserveNode node = (ObserveNode) path.getLastPathComponent(); + NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) path.getLastPathComponent(); ContentUIManager manager = ui.getContentUIManager(); // obtain the ui type to show @@ -125,10 +123,10 @@ public class ObserveMainUIHandler { } finally { ui.setBusy(false); String params; - if (node.isStringNode()) { - params = t(node.getId()); + if (node instanceof StringNavigationTreeNodeSupport) { + params = t(((StringNavigationTreeNodeSupport) node).getData()); } else { - params = t(ObserveI18nDecoratorHelper.getTypeI18nKey(node.getInternalClass())); + params = t(ObserveI18nDecoratorHelper.getTypeI18nKey(node.getDataType())); } ui.getStatus().setStatus(t("observe.action.open.screen", params)); } @@ -142,12 +140,11 @@ public class ObserveMainUIHandler { Object[] nodes = path.getPath(); List<String> ids = new ArrayList<>(); for (Object o : nodes) { - ObserveNode n = (ObserveNode) o; + NavigationTreeNodeSupport n = (NavigationTreeNodeSupport) o; - if (n.isStringNode() || n.isReferentielNode() || n.isRoot() || !n.isDataNode()) { - continue; + if (n instanceof ReferenceNavigationTreeNodeSupport) { + ids.add(n.getId()); } - ids.add(n.getId()); } if (log.isDebugEnabled()) { @@ -220,26 +217,24 @@ public class ObserveMainUIHandler { decoratorService.reload(); } - ObserveTreeHelper treeHelper = new ObserveTreeHelper(); - ObserveSwingDataSource source = context.getDataSourcesManager().getMainDataSource(); +// ObserveTreeHelper treeHelper = new ObserveTreeHelper(); +// ObserveSwingDataSource source = context.getDataSourcesManager().getMainDataSource(); - boolean open = context.getDataContext().getEnabled(); - if (open) { - treeHelper.createModel(source); - } else { - treeHelper.createEmptyModel(); - } +// boolean open = context.getDataContext().getEnabled(); +// if (open) { +// treeHelper.initModel(source); +// } else { +// treeHelper.createEmptyModel(); +// } JAXXInitialContext tx = new JAXXInitialContext(); - - tx.add(context).add(treeHelper).add(errorModel); + tx.add(context).add(errorModel); // show main ui ObserveMainUI ui = new ObserveMainUI(tx); ui.setUndecorated(config.isFullScreen()); - String title = t("observe.title.welcome.admin"); - title += " v " + config.getVersion(); + String title = t("observe.title.welcome.admin") + (" v " + config.getVersion()); ui.setTitle(title); context.setMainUI(ui); @@ -249,7 +244,7 @@ public class ObserveMainUIHandler { // set fullscreen propery on main ui ui.getGraphicsConfiguration().getDevice().setFullScreenWindow(config.isFullScreen() ? ui : null); - new ObserveNavigationTreeShowPopupAction(treeHelper, ui.getNavigationScrollPane(), ui.getNavigationPopup()); + new ObserveNavigationTreeShowPopupAction(ui.getNavigation(), ui.getNavigationScrollPane(), ui.getNavigationPopup()); return ui; } @@ -307,7 +302,7 @@ public class ObserveMainUIHandler { oldMode = ui.getMode(); - ids = ui.getTreeHelper().getSelectedIds(); + ids = ui.getNavigation().getSelectedIds(); ErrorDialogUI.init(null); @@ -341,14 +336,14 @@ public class ObserveMainUIHandler { // selection du noeud d'ouverture (le noeud precedemment selectionne, // ou le noeud le plus ouvert // ou le premier program si aucune donnée ouverte) - ui.getTreeHelper().selectInitialNode(); + ui.getNavigation().selectInitialNode(); } // show ui UIHelper.setMainUIVisible(ui); } - protected Icon updateStorageSatutIcon(ObserveMainUI ui, boolean isOpened) { + protected Icon updateStorageSatutIcon(ObserveMainUI ui) { Icon icon; if (ui.getConfig().isMainStorageOpened()) { @@ -368,7 +363,7 @@ public class ObserveMainUIHandler { return icon; } - protected String updateStorageSatutText(ObserveMainUI ui, boolean isOpened) { + protected String updateStorageSatutText(ObserveMainUI ui) { String text; if (ui.getConfig().isMainStorageOpened()) { ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); @@ -379,7 +374,7 @@ public class ObserveMainUIHandler { return text; } - protected String updateStorageStatutToolTipText(ObserveMainUI ui, boolean isOpened) { + protected String updateStorageStatutToolTipText(ObserveMainUI ui) { String text; if (ui.getConfig().isMainStorageOpened()) { ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); @@ -432,6 +427,8 @@ public class ObserveMainUIHandler { // bad binding, force value ui.getStopH2WebServer().setEnabled(false); +// ui.setContextValue(ui.getNavigation()); + ui.getStatus().init(); // ajout d'un ecouteur sur la navigation pour toujours mettre la scrollbar @@ -439,39 +436,40 @@ public class ObserveMainUIHandler { TreeSelectionListener listener; listener = e -> { changeNavigationNode(ui, e); - SwingUtilities.invokeLater(() -> { - ui.getNavigationScrollPane().getHorizontalScrollBar().setValue(0); - ui.getSplitpane2().resetToPreferredSizes(); - }); - }; - TreeWillExpandListener veteobableTreeWillExpand = new TreeWillExpandListener() { - @Override - public void treeWillExpand(TreeExpansionEvent event) { - } - - @Override - public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { - - // le seul posant problème est la fermeture d'un noeud parent - // du noeud courant : cela va changer la selection - ObserveNode selectedNode = ui.getTreeHelper().getSelectedNode(); - if (selectedNode == null) { - // pas de noeud selectionne - return; - } - - ObserveNode o = (ObserveNode) event.getPath().getLastPathComponent(); - if (selectedNode.equals(o) || !selectedNode.isNodeAncestor(o)) { - return; - } - boolean canChange = ObserveSwingApplicationContext.get().getContentUIManager().closeSelectedContentUI(); - if (!canChange) { - throw new ExpandVetoException(event, "Can not collapse node " + event.getPath()); - } - } +// SwingUtilities.invokeLater(() -> { +// ui.getNavigationScrollPane().getHorizontalScrollBar().setValue(0); +// ui.getSplitpane2().resetToPreferredSizes(); +// }); }; - - ui.getTreeHelper().setUI(ui.getNavigation(), true, true, listener, veteobableTreeWillExpand); + ui.getNavigation().addTreeSelectionListener(listener); +// TreeWillExpandListener veteobableTreeWillExpand = new TreeWillExpandListener() { +// @Override +// public void treeWillExpand(TreeExpansionEvent event) { +// } +// +// @Override +// public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { +// +// // le seul posant problème est la fermeture d'un noeud parent +// // du noeud courant : cela va changer la selection +// ObserveNode selectedNode = ui.getTreeHelper().getSelectedNode(); +// if (selectedNode == null) { +// // pas de noeud selectionne +// return; +// } +// +// ObserveNode o = (ObserveNode) event.getPath().getLastPathComponent(); +// if (selectedNode.equals(o) || !selectedNode.isNodeAncestor(o)) { +// return; +// } +// boolean canChange = ObserveSwingApplicationContext.get().getContentUIManager().closeSelectedContentUI(); +// if (!canChange) { +// throw new ExpandVetoException(event, "Can not collapse node " + event.getPath()); +// } +// } +// }; + +// ui.getTreeHelper().setUI(ui.getNavigation(), true, true, listener, veteobableTreeWillExpand); SwingValidatorUtil.installUI(ui.getErrorTable(), new ObserveValidatorMessageTableRenderer()); @@ -518,4 +516,46 @@ public class ObserveMainUIHandler { } } + /** + * Nettoye des ui tout ce qui concerne un modèle de navigation. + * + * <b>Note:</b> cette méthode doit être appelée avant tout rechargement de + * modèle de naivgation. + * + * @param mainUI l'ui principale + */ + public void cleanNavigationUI(ObserveMainUI mainUI) { + + // reset content uis + mainUI.getContentLayout().reset(mainUI.getContent()); + + // clean messages + mainUI.getContextValue(SwingValidatorMessageTableModel.class).clear(); + + // clean tree model + NavigationTree tree = mainUI.getNavigation(); + + tree.clearModel(); + + // no tree navigation view + tree.setVisible(false); + + } + + /** + * Charge dans l'ui un nouveau modèle de navigation. + * + * <b>Note:</b> cette méthode doit être appelée après tout rechargement de modèle de naivgation. + **/ + public void loadNavigationUI(ObserveMainUI mainUI) { + + NavigationTree tree = mainUI.getNavigation(); + + tree.createModel(); + + // select initial node + tree.selectInitialNode(); + + tree.setVisible(true); + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ReloadStorageAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ReloadStorageAction.java index 8884d04..5a88364 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ReloadStorageAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ReloadStorageAction.java @@ -25,10 +25,10 @@ package fr.ird.observe.application.swing.ui.actions; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2; -import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2; +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFactory; import java.awt.event.ActionEvent; import static org.nuiton.i18n.I18n.t; + /** * Created on 1/17/15. * @@ -79,7 +80,7 @@ public class ReloadStorageAction extends AbstractObserveAction { ui.setBusy(false); - String[] ids = ui.getTreeHelper().getSelectedIds(); + String[] ids = ui.getNavigation().getSelectedIds(); try { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CancelCreateUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CancelCreateUIAction.java index e415500..330b1e9 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CancelCreateUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CancelCreateUIAction.java @@ -22,9 +22,9 @@ package fr.ird.observe.application.swing.ui.actions.content; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import static org.nuiton.i18n.I18n.n; @@ -54,8 +54,9 @@ public class CancelCreateUIAction extends AbstractContentUIAction { @Override protected void actionPerformed(ContentUI<?, ?> ui) { ui.stopEdit(); - ObserveNode parentNode = ui.getTreeHelper().removeNode(ui.getTreeHelper().getSelectedNode()); - ui.getTreeHelper().selectNode(parentNode); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport parentNode = tree.removeNode(tree.getSelectedNode()); + tree.selectNode(parentNode); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java index c774930..8d544aa 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java @@ -22,19 +22,19 @@ package fr.ird.observe.application.swing.ui.actions.content; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.db.DataContext; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI; import fr.ird.observe.application.swing.ui.content.open.impl.longline.ActivityLonglineUI; import fr.ird.observe.application.swing.ui.content.open.impl.seine.ActivitySeineUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import javax.swing.JTree; import javax.swing.tree.TreePath; import static org.nuiton.i18n.I18n.n; @@ -73,13 +73,12 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { // cas particulier pour l'écran des activitys - JTree tree = getMainUI().getNavigation(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, treeHelper, getMainUI().getDataContext()); + boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, getMainUI().getDataContext()); // selection du noeud de l'activity ouverte - treeHelper.selectOpenNode(ActivitySeineDto.class); + tree.selectOpenNode(ActivitySeineDto.class); // on conserve le path de l'activity TreePath path = tree.getSelectionPath(); @@ -105,17 +104,12 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { // cas particulier pour l'écran des activitys - JTree tree = getMainUI().getNavigation(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - boolean wasCollapsed = isOpenActivityNodeCollapsed( - tree, - treeHelper, - getMainUI().getDataContext() - ); + boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, getMainUI().getDataContext()); // selection du noeud de l'activity ouverte - treeHelper.selectOpenNode(ActivityLonglineDto.class); + tree.selectOpenNode(ActivityLonglineDto.class); // on conserve le path de l'activity TreePath path = tree.getSelectionPath(); @@ -140,4 +134,21 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { throw new IllegalStateException("Can not come here!"); } + protected boolean isOpenActivityNodeCollapsed(NavigationTree tree, DataContext dataContext) { + + // on regarde si le noeud de l'activité ouverte est collapsé + + NavigationTreeNodeSupport node = tree.getSelectedNode(); + + TreePath path = tree.getSelectionPath(); + + String id = dataContext.getOpenActivityId(); + + NavigationTreeNodeSupport node1 = node.findNodeById(tree.getNavigationTreeModel(), id); + + TreePath activityPath = path.pathByAddingChild(node1); + + return tree.isCollapsed(activityPath); + } + } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseOpenUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseOpenUIAction.java index d2c6a43..c02b4b9 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseOpenUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseOpenUIAction.java @@ -23,7 +23,6 @@ package fr.ird.observe.application.swing.ui.actions.content; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUI; @@ -31,8 +30,8 @@ import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeine import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import javax.swing.SwingUtilities; @@ -102,12 +101,12 @@ public class CloseOpenUIAction extends AbstractContentUIAction { private void closeData(ObserveSwingApplicationContext applicationContext, ContentUI<?, ?> ui, String id) { - ObserveTreeHelper treeHelper = ui.getTreeHelper(); - ObserveNode selectedNode = treeHelper.getSelectedNode(); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport selectedNode = tree.getSelectedNode(); - ObserveNode node = treeHelper.findNode(selectedNode, id); + NavigationTreeNodeSupport node = tree.getChild(selectedNode, id); - treeHelper.selectNode(node); + tree.selectNode(node); ContentOpenableUI selectedUI = (ContentOpenableUI) applicationContext.getContentUIManager().getSelectedContentUI(); @@ -117,7 +116,7 @@ public class CloseOpenUIAction extends AbstractContentUIAction { SwingUtilities.invokeLater(() -> { // retour sur le noeud parent - treeHelper.selectNode(selectedNode); + tree.selectNode(selectedNode); }); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivityLonglinesUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivityLonglinesUIAction.java index 4fdeed0..e986b23 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivityLonglinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivityLonglinesUIAction.java @@ -28,9 +28,9 @@ import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecor import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.TripLonglineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; @@ -83,9 +83,9 @@ public class MoveActivityLonglinesUIAction extends AbstractContentUIAction { // get current triplongline id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldActivitiesNode = treeHelper.getSelectedNode(); - ObserveNode oldTripLonglineNode = oldActivitiesNode.getParent(); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport oldActivitiesNode = tree.getSelectedNode(); + NavigationTreeNodeSupport oldTripLonglineNode = oldActivitiesNode.getParent(); // choose the new tripLongline String tripLonglineId = chooseNewTripLongline(ui, oldTripLonglineNode); @@ -110,8 +110,8 @@ public class MoveActivityLonglinesUIAction extends AbstractContentUIAction { } - protected String chooseNewTripLongline(ContentUI<?, ?> ui, ObserveNode oldTripLonglineNode) { - ObserveNode programNode = oldTripLonglineNode.getParent(); + protected String chooseNewTripLongline(ContentUI<?, ?> ui, NavigationTreeNodeSupport oldTripLonglineNode) { + NavigationTreeNodeSupport programNode = oldTripLonglineNode.getParent(); String oldTripLonglineId = oldTripLonglineNode.getId(); int tripLonglineNb = programNode.getChildCount(); @@ -124,7 +124,7 @@ public class MoveActivityLonglinesUIAction extends AbstractContentUIAction { int j = 0; for (int i = 0; i < tripLonglineNb; i++) { - TripLonglineNode tripLonglineNode = (TripLonglineNode) programNode.getChildAt(i); + TripLonglineNavigationTreeNode tripLonglineNode = (TripLonglineNavigationTreeNode) programNode.getChildAt(i); String tripLonglineId = tripLonglineNode.getId(); @@ -143,19 +143,19 @@ public class MoveActivityLonglinesUIAction extends AbstractContentUIAction { return decoratedTripLongline != null ? ((DecoratedNodeEntity) decoratedTripLongline).getId() : null; } - protected void updateTree(ObserveNode oldActivitiesNode, + protected void updateTree(NavigationTreeNodeSupport oldActivitiesNode, String tripLonglineId, List<String> activityIds) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - ObserveNode oldTripLonglineNode = oldActivitiesNode.getParent(); - ObserveNode programNode = oldTripLonglineNode.getParent(); - ObserveNode newTripLonglineNode = treeHelper.getChild(programNode, tripLonglineId); + NavigationTreeNodeSupport oldTripLonglineNode = oldActivitiesNode.getParent(); + NavigationTreeNodeSupport programNode = oldTripLonglineNode.getParent(); + NavigationTreeNodeSupport newTripLonglineNode = tree.getChild(programNode, tripLonglineId); String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class); - ObserveNode newActivitiesNode = treeHelper.getChild(newTripLonglineNode, activitiesNodeId); + NavigationTreeNodeSupport newActivitiesNode = tree.getChild(newTripLonglineNode, activitiesNodeId); // Let's check if we're moving an open activity Optional<String> openActivity = activityIds @@ -170,11 +170,11 @@ public class MoveActivityLonglinesUIAction extends AbstractContentUIAction { // Let's reload the sub tree of each activities node. // As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees - treeHelper.reloadNodeSubTree(oldActivitiesNode, true); - treeHelper.reloadNodeSubTree(newActivitiesNode, true); + tree.reloadNodeSubTree(oldActivitiesNode, true); + tree.reloadNodeSubTree(newActivitiesNode, true); // Let's put the focus on the activities node which received the activities - treeHelper.selectNode(newActivitiesNode); + tree.selectNode(newActivitiesNode); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivitySeinesUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivitySeinesUIAction.java index 26a9630..a3adf22 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivitySeinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveActivitySeinesUIAction.java @@ -26,13 +26,12 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.RouteSeineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.seine.ActivitySeineDto; @@ -78,9 +77,9 @@ public class MoveActivitySeinesUIAction extends AbstractContentUIAction { } // get current route id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldActivitiesNode = treeHelper.getSelectedNode(); - ObserveNode oldRouteNode = oldActivitiesNode.getParent(); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport oldActivitiesNode = tree.getSelectedNode(); + NavigationTreeNodeSupport oldRouteNode = oldActivitiesNode.getParent(); // choose the new route String routeId = chooseNewRoute(ui, oldRouteNode); @@ -100,8 +99,8 @@ public class MoveActivitySeinesUIAction extends AbstractContentUIAction { } - protected String chooseNewRoute(ContentUI<?, ?> ui, ObserveNode oldRouteNode) { - ObserveNode routesNode = oldRouteNode.getParent(); + protected String chooseNewRoute(ContentUI<?, ?> ui, NavigationTreeNodeSupport oldRouteNode) { + NavigationTreeNodeSupport routesNode = oldRouteNode.getParent(); String oldRouteId = oldRouteNode.getId(); int routeNb = routesNode.getChildCount(); @@ -114,7 +113,7 @@ public class MoveActivitySeinesUIAction extends AbstractContentUIAction { int j = 0; for (int i = 0; i < routeNb; i++) { - RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i); + RouteSeineNavigationTreeNode routeNode = (RouteSeineNavigationTreeNode) routesNode.getChildAt(i); String routeId = routeNode.getId(); @@ -134,20 +133,20 @@ public class MoveActivitySeinesUIAction extends AbstractContentUIAction { return decoratedRoute != null ? ((DecoratedNodeEntity) decoratedRoute).getId() : null; } - protected void updateTree(ObserveNode oldActivitiesNode, + protected void updateTree(NavigationTreeNodeSupport oldActivitiesNode, String routeId, List<String> activityIds) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - ObserveNode oldRouteNode = oldActivitiesNode.getParent(); - ObserveNode routesNode = oldRouteNode.getParent(); + NavigationTreeNodeSupport oldRouteNode = oldActivitiesNode.getParent(); + NavigationTreeNodeSupport routesNode = oldRouteNode.getParent(); // ObserveNode tripNode = routesNode.getParent(); - ObserveNode newRouteNode = treeHelper.getChild(routesNode, routeId); + NavigationTreeNodeSupport newRouteNode = tree.getChild(routesNode, routeId); String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class); - ObserveNode newActivitiesNode = treeHelper.getChild(newRouteNode, activitiesNodeId); + NavigationTreeNodeSupport newActivitiesNode = tree.getChild(newRouteNode, activitiesNodeId); // Let's check if we're moving an open activity Optional<String> openActivity = activityIds @@ -162,11 +161,11 @@ public class MoveActivitySeinesUIAction extends AbstractContentUIAction { // Let's reload the sub tree of each activities node. // As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees - treeHelper.reloadNodeSubTree(oldActivitiesNode, true); - treeHelper.reloadNodeSubTree(newActivitiesNode, true); + tree.reloadNodeSubTree(oldActivitiesNode, true); + tree.reloadNodeSubTree(newActivitiesNode, true); // Let's put the focus on the activities node which received the activities - treeHelper.selectNode(newActivitiesNode); + tree.selectNode(newActivitiesNode); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveRoutesUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveRoutesUIAction.java index 7abe582..e510eb5 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveRoutesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveRoutesUIAction.java @@ -26,12 +26,11 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.TripSeineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.seine.RouteDto; @@ -78,9 +77,9 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { RoutesUI theUi = (RoutesUI) ui; // get current tripseine id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldRoutesNode = treeHelper.getSelectedNode(); - ObserveNode oldTripSeineNode = oldRoutesNode.getParent(); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport oldRoutesNode = tree.getSelectedNode(); + NavigationTreeNodeSupport oldTripSeineNode = oldRoutesNode.getParent(); // choose the new tripseine String tripSeineId = chooseNewTripSeine(theUi, oldTripSeineNode); @@ -98,8 +97,8 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { } - protected String chooseNewTripSeine(ContentUI<?, ?> ui, ObserveNode oldTripSeineNode) { - ObserveNode programNode = oldTripSeineNode.getParent(); + protected String chooseNewTripSeine(ContentUI<?, ?> ui, NavigationTreeNodeSupport oldTripSeineNode) { + NavigationTreeNodeSupport programNode = oldTripSeineNode.getParent(); String oldTripSeineId = oldTripSeineNode.getId(); int tripSeineNb = programNode.getChildCount(); @@ -112,7 +111,7 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { int j = 0; for (int i = 0; i < tripSeineNb; i++) { - TripSeineNode tripSeineNode = (TripSeineNode) programNode.getChildAt(i); + TripSeineNavigationTreeNode tripSeineNode = (TripSeineNavigationTreeNode) programNode.getChildAt(i); String tripSeineId = tripSeineNode.getId(); @@ -131,19 +130,19 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { return decoratedTripSeine != null ? ((DecoratedNodeEntity) decoratedTripSeine).getId() : null; } - protected void updateTree(ObserveNode oldRoutesNode, + protected void updateTree(NavigationTreeNodeSupport oldRoutesNode, String tripSeineId, List<String> routeIds) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - ObserveNode oldTripSeineNode = oldRoutesNode.getParent(); - ObserveNode programNode = oldTripSeineNode.getParent(); - ObserveNode newTripSeineNode = treeHelper.getChild(programNode, tripSeineId); + NavigationTreeNodeSupport oldTripSeineNode = oldRoutesNode.getParent(); + NavigationTreeNodeSupport programNode = oldTripSeineNode.getParent(); + NavigationTreeNodeSupport newTripSeineNode = tree.getChild(programNode, tripSeineId); String routesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class); - ObserveNode newRoutesNode = treeHelper.getChild(newTripSeineNode, routesNodeId); + NavigationTreeNodeSupport newRoutesNode = tree.getChild(newTripSeineNode, routesNodeId); // Let's check if we're moving an open route Optional<String> openRoute = routeIds @@ -158,8 +157,8 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { // Let's reload the sub tree of each routes node. // As the change have already be done in database, we just call the child loaders to regenerate the routes nodes sub trees - treeHelper.reloadNodeSubTree(oldRoutesNode, true); - treeHelper.reloadNodeSubTree(newRoutesNode, true); + tree.reloadNodeSubTree(oldRoutesNode, true); + tree.reloadNodeSubTree(newRoutesNode, true); // 1. Select the newRoutesNode : // only a selected node can be reloaded (@see fr.ird.observe.application.swing.ui.tree.ObserveTreeBridge.canLoadChild). @@ -171,7 +170,7 @@ public class MoveRoutesUIAction extends AbstractContentUIAction { // // That's why, if we do this before the trip is opened, // we will end up with an incoherent list view (some buttons will be deactivated while they should be activated for instance) - treeHelper.selectNode(newRoutesNode); + tree.selectNode(newRoutesNode); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveTripsUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveTripsUIAction.java index c4f73bc..2a3ee12 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveTripsUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/MoveTripsUIAction.java @@ -26,9 +26,10 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.ContentListUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.RootNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; import fr.ird.observe.services.dto.DataDto; import fr.ird.observe.services.dto.DataReference; @@ -77,8 +78,8 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractConte checkUIClass(ui); // get current program id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldProgramNode = treeHelper.getSelectedNode(); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport oldProgramNode = tree.getSelectedNode(); String oldProgramId = oldProgramNode.getId(); // choose the new program @@ -99,12 +100,12 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractConte protected String chooseNewProgram(ContentUI<?, ?> ui, String oldProgramId) { - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); GearType geartype = getGearType(ui); // racine - ObserveNode rootNode = treeHelper.getRootNode(); + RootNavigationTreeNode rootNode = tree.getNavigationTreeModel().getRoot(); //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel List<DecoratedNodeEntity> decoratedProgramList = new ArrayList<>(); @@ -126,7 +127,7 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractConte } protected void updateTree(ContentUI<?, ?> ui, - ObserveNode oldProgramNode, + NavigationTreeNodeSupport oldProgramNode, String oldProgramId, String programId, List<String> tripIds, @@ -134,24 +135,24 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractConte ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - ObserveNode rootNode = treeHelper.getRootNode(); - ObserveNode newProgramNode = treeHelper.getChild(rootNode, programId); + RootNavigationTreeNode rootNode = tree.getNavigationTreeModel().getRoot(); + NavigationTreeNodeSupport newProgramNode = tree.getChild(rootNode, programId); for (int i = 0, s = positions.size(); i < s; i++) { String tripId = tripIds.get(i); - ObserveNode tripNode = treeHelper.getChild(oldProgramNode, tripId); + NavigationTreeNodeSupport tripNode = tree.getChild(oldProgramNode, tripId); boolean wasOpen = tripNode.isOpen(); - treeHelper.removeNode(tripNode); + tree.removeNode(tripNode); if (wasOpen) { openDataManager.closeProgram(oldProgramId); openDataManager.openProgram(programId); } - ObserveNode newTripNode = treeHelper.getChild(newProgramNode, tripId); + NavigationTreeNodeSupport newTripNode = tree.getChild(newProgramNode, tripId); if (newTripNode == null) { @@ -159,15 +160,15 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractConte if (log.isInfoEnabled()) { log.info("Insert trip node: "); } - treeHelper.insertNode(newProgramNode, tripNode, positions.get(i)); + tree.insertNode(newProgramNode, tripNode, positions.get(i)); } } updateModelData(ui); - treeHelper.reloadNode(oldProgramNode, true); - treeHelper.reloadNode(newProgramNode, true); - treeHelper.selectNode(newProgramNode); + tree.reloadNode(oldProgramNode, true); + tree.reloadNode(newProgramNode, true); + tree.selectNode(newProgramNode); } protected abstract void checkUIClass(ContentUI<?, ?> ui) throws IllegalStateException; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ReOpenUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ReOpenUIAction.java index b96e700..e3908ba 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ReOpenUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ReOpenUIAction.java @@ -23,12 +23,11 @@ package fr.ird.observe.application.swing.ui.actions.content; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.ContentListUI; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.DataReference; import static org.nuiton.i18n.I18n.n; @@ -70,11 +69,11 @@ public class ReOpenUIAction extends AbstractContentUIAction { String id = selectedData.getId(); - ObserveTreeHelper treeHelper = ui.getTreeHelper(); - ObserveNode selectedNode = treeHelper.getSelectedNode(); - ObserveNode node = treeHelper.findNode(selectedNode, id); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport selectedNode = tree.getSelectedNode(); + NavigationTreeNodeSupport node = tree.getChild(selectedNode, id); - treeHelper.selectNode(node); + tree.selectNode(node); openUI = (ContentOpenableUI<?, ?>) ObserveSwingApplicationContext.get().getContentUIManager().getSelectedContentUI(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ResetEditUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ResetEditUIAction.java index b922346..4ba3b74 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ResetEditUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/ResetEditUIAction.java @@ -22,9 +22,9 @@ package fr.ird.observe.application.swing.ui.actions.content; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.actions.content.AbstractContentUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import static org.nuiton.i18n.I18n.n; @@ -56,8 +56,9 @@ public class ResetEditUIAction extends AbstractContentUIAction { if (ui.getModel().isCreatingMode()) { ui.stopEdit(); - ObserveNode parentNode = ui.getTreeHelper().removeNode(ui.getTreeHelper().getSelectedNode()); - ui.getTreeHelper().selectNode(parentNode); + NavigationTree tree = getMainUI().getNavigation(); + NavigationTreeNodeSupport parentNode = tree.removeNode(tree.getSelectedNode()); + tree.selectNode(parentNode); } else { ui.resetEdit(); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java index 251cac4..2f9be25 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java @@ -22,11 +22,8 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.DataContext; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,9 +33,7 @@ import javax.swing.AbstractButton; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPopupMenu; -import javax.swing.JTree; import javax.swing.KeyStroke; -import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.util.Objects; @@ -153,23 +148,6 @@ public abstract class AbstractUIAction extends AbstractAction { return (JComponent) getValue(EDITOR); } - public static boolean isOpenActivityNodeCollapsed(JTree tree, ObserveTreeHelper treeHelper, DataContext dataContext) { - - // on regarde si le noeud de l'activité ouverte est collapsé - - ObserveNode node = treeHelper.getSelectedNode(); - - TreePath path = tree.getSelectionPath(); - - String id = dataContext.getOpenActivityId(); - - ObserveNode node1 = treeHelper.findNode(node, id); - - TreePath activityPath = path.pathByAddingChild(node1); - - return tree.isCollapsed(activityPath); - } - protected ContentUI<?, ?> getContentUI(ActionEvent e) { JComponent c = (JComponent) e.getSource(); ContentUI<?, ?> ui; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoDownUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoDownUIAction.java index 4220ac5..b15959f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoDownUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoDownUIAction.java @@ -23,9 +23,9 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import javax.swing.AbstractButton; import javax.swing.Action; @@ -83,30 +83,29 @@ public class GoDownUIAction extends AbstractUIAction { public void updateAction(ContentUI<?, ?> ui, AbstractButton editor) { ObserveMainUI mainUI = getMainUI(); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree tree = getMainUI().getNavigation(); - AbstractObserveTreeCellRenderer render = treeHelper.getTreeCellRenderer(); + NavigationTreeCellRenderer render = tree.getNavigationCellRenderer(); - ObserveNode node; + NavigationTreeNodeSupport node; super.updateAction(ui, editor); JPopupMenu scopePopup = mainUI.getScopeDownPopup(); Action action = mainUI.getRootPane().getActionMap().get(SelectNodeUIAction.ACTION_NAME); - node = treeHelper.getSelectedNode(); - ObserveNode nodeOriginal = node; + node = tree.getSelectedNode(); + NavigationTreeNodeSupport nodeOriginal = node; scopePopup.removeAll(); Enumeration<?> e = node.children(); while (e.hasMoreElements()) { - node = (ObserveNode) e.nextElement(); - String text = render.getNodeText(node); + node = (NavigationTreeNodeSupport) e.nextElement(); + String text = node.getText(); if (text == null) { continue; } - Color color = - render.getNavigationTextColor(node); - Icon icon = render.getNavigationIcon(node, "-16"); + Color color = node.getColor(); + Icon icon = node.getIcon("-16"); JMenuItem mi = new JMenuItem(); mi.setAction(action); mi.setText(text.trim()); @@ -122,11 +121,10 @@ public class GoDownUIAction extends AbstractUIAction { !nodeOriginal.getChildAt(0).isLeaf()) { e = nodeOriginal.getChildAt(0).children(); while (e.hasMoreElements()) { - node = (ObserveNode) e.nextElement(); - Color color = render.getNavigationTextColor( - node); - Icon icon = render.getNavigationIcon(node, "-16"); - String text = render.getNodeText(node); + node = (NavigationTreeNodeSupport) e.nextElement(); + Color color = node.getColor(); + Icon icon = node.getIcon("-16"); + String text = node.getText(); JMenuItem mi = new JMenuItem(); mi.setAction(action); mi.setText(text.trim()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoUpUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoUpUIAction.java index db7b648..f23baed 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoUpUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/GoUpUIAction.java @@ -23,9 +23,9 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import javax.swing.AbstractButton; import javax.swing.Action; @@ -84,11 +84,11 @@ public class GoUpUIAction extends AbstractUIAction { public void updateAction(ContentUI<?, ?> ui, AbstractButton editor) { super.updateAction(ui, editor); - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + NavigationTree treeHelper = getMainUI().getNavigation(); - AbstractObserveTreeCellRenderer render = treeHelper.getTreeCellRenderer(); + NavigationTreeCellRenderer render = treeHelper.getNavigationCellRenderer(); - ObserveNode node; + NavigationTreeNodeSupport node; JPopupMenu scopePopup = getMainUI().getScopeUpPopup(); @@ -101,10 +101,9 @@ public class GoUpUIAction extends AbstractUIAction { scopePopup.setLayout(new GridLayout(0, 1)); while (!root.equals(node.getParent())) { node = node.getParent(); - Color color = - render.getNavigationTextColor(node); - Icon icon = render.getNavigationIcon(node, "-16"); - String text = render.getNodeText(node); + Color color = node.getColor(); + Icon icon = node.getIcon("-16"); + String text = node.getText(); JMenuItem mi = new JMenuItem(); mi.setAction(action); mi.setText(text.trim()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectNodeUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectNodeUIAction.java index 3fd936f..14a0b4a 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectNodeUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectNodeUIAction.java @@ -22,7 +22,7 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import javax.swing.JComponent; import java.awt.event.ActionEvent; @@ -57,7 +57,7 @@ public class SelectNodeUIAction extends AbstractUIAction { @Override public void actionPerformed(ActionEvent e) { JComponent source = (JComponent) e.getSource(); - ObserveNode node = (ObserveNode) source.getClientProperty(NODE); - getMainUI().getTreeHelper().selectNode(node); + NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) source.getClientProperty(NODE); + getMainUI().getNavigation().selectNode(node); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java index 616273c..b7c14f0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java @@ -57,6 +57,6 @@ public class SelectOpenNodeUIAction extends AbstractUIAction { JComponent c = (JComponent) e.getSource(); Class<?> type = (Class<?>) c.getClientProperty("type"); Objects.requireNonNull(type, "could not find client property type on component" + c); - getMainUI().getTreeHelper().selectOpenNode(type); + getMainUI().getNavigation().selectOpenNode(type); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java index c7497de..3e8f11f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java @@ -27,11 +27,7 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; -import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; import fr.ird.observe.application.swing.ui.admin.resume.ShowResumeUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.referential.ProgramDto; import fr.ird.observe.services.dto.referential.ReferentialReference; @@ -47,8 +43,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.StringUtil; -import javax.swing.JTree; -import javax.swing.tree.TreeModel; import java.io.PrintWriter; import java.io.StringWriter; import java.util.concurrent.Callable; @@ -96,23 +90,6 @@ public class AdminTabUIHandler { return decoratorService; } - public final WizardState onCancel(Exception e) { - if (log.isDebugEnabled()) { - log.debug(this, e); - } - sendMessage(t("observe.actions.operation.message.canceled")); - return WizardState.CANCELED; - } - - public final WizardState onError(Exception e) { - model.getStepModel(model.getOperation()).setError(e); - if (log.isErrorEnabled()) { - log.error(e.getMessage(), e); - } - sendMessage(t("observe.actions.operation.message.failed")); - return WizardState.FAILED; - } - public void initTabUI(AdminUI ui, AdminTabUI tabUI) { parentUI = ui; @@ -188,24 +165,6 @@ public class AdminTabUIHandler { return txt; } - public void updateSelectionModel(SelectDataUI tabUI) { - - JTree selectTree = tabUI.getSelectTree(); - DataSelectionModel selectDataModel = tabUI.getSelectDataModel(); - DataSelectionTreeSelectionModel selectionModel = tabUI.getSelectionModel(); - ObserveTreeHelper helper = tabUI.getTreeHelper(); - ObserveSwingDataSource source = tabUI.getModel().getSafeLocalSource(true); - - updateSelectionModel(tabUI, helper, selectTree, source, selectDataModel, selectionModel); - - } - - protected void checkStepIsOperation(AdminTabUI ui) { - if (!ui.getStep().isOperation()) { - throw new IllegalStateException("can not launch objectOperation on none operation step " + ui.getStep()); - } - } - protected ObserveSwingDataSource openSource(ObserveSwingDataSource service) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException, BabModelVersionException { if (!service.isOpen()) { service.open(); @@ -218,40 +177,11 @@ public class AdminTabUIHandler { ObserveRunner.getActionExecutor().addAction(worker); } - protected void updateSelectionModel(AdminTabUI tabUI, - ObserveTreeHelper helper, - JTree selectTree, - ObserveSwingDataSource source, - DataSelectionModel selectDataModel, - DataSelectionTreeSelectionModel selectionModel) { - - - if (log.isDebugEnabled()) { - log.debug("reload model " + selectDataModel); - } - - selectionModel.clearSelection(); - - if (log.isDebugEnabled()) { - log.debug("Will treeHelper : " + helper); - log.debug("selection model : " + selectDataModel); - log.debug("use referentiel : " + selectDataModel.isUseReferentiel()); - log.debug("use data : " + selectDataModel.isUseData()); - } - - helper.setUI(selectTree, false); - - TreeModel model = helper.createModel(tabUI, selectDataModel, source); - selectTree.setModel(model); - - selectionModel.initUI(selectTree); - } - public void addMessage(AdminStep step, String text) { ui.getProgression().append(text + "\n"); } - protected void logExportResult(String i18nKey, + protected void logExportResult(String i18nKey, ExportTripResult tripResult, ReferentialReferenceDecorator<ProgramDto> programDecorator, ReferentialReference<ProgramDto> program, @@ -272,7 +202,7 @@ public class AdminTabUIHandler { ReferentialReference<ProgramDto> program, DataReference trip) { - DecoratorService decoratorService = getDecoratorService(); +// DecoratorService decoratorService = getDecoratorService(); if (tripResult.isDeleted()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java index 19649a2..4648162 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java @@ -26,8 +26,10 @@ import fr.ird.observe.application.swing.ObserveActionExecutor; import fr.ird.observe.application.swing.ObserveRunner; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; +import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; import fr.ird.observe.application.swing.ui.admin.resume.ShowResumeUI; import fr.ird.observe.application.swing.ui.admin.save.SaveLocalUI; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; import jaxx.runtime.swing.wizard.WizardUILancher; import jaxx.runtime.swing.wizard.ext.WizardExtUtil; import jaxx.runtime.swing.wizard.ext.WizardState; @@ -37,6 +39,7 @@ import org.apache.commons.logging.LogFactory; import javax.swing.Icon; import javax.swing.JCheckBox; import javax.swing.JComponent; +import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import java.awt.Component; import java.util.Arrays; @@ -212,6 +215,34 @@ public class AdminUIHandler { if (index > -1 && ui.tabs.getSelectedIndex() != index) { ui.tabs.setSelectedIndex(index); } + + if (AdminStep.SELECT_DATA == newStep) { + + if (oldStep != null && oldStep.ordinal() < AdminStep.SELECT_DATA.ordinal()) { + + // préparation de l'arbre de sélection + onSelectDataOpen((SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA)); + } + + } + + } + + protected void onSelectDataOpen(SelectDataUI stepUI) { + + SelectionTree selectTree = stepUI.getSelectTree(); + selectTree.clearSelection(); + + SwingUtilities.invokeLater(selectTree::grabFocus); + + if (selectTree.getTreeModel().isNotEmpty()) { + + selectTree.getSelectionModel().setLeadSelectionIndex(0); + } + if (stepUI.getModel().getSafeLocalSource(true).isLocal()) { + SwingUtilities.invokeLater(selectTree::expandAll); + } + } /** diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java index 092714e..a4c383f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.application.swing.ui.admin; -import com.google.common.collect.Lists; import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; @@ -39,7 +38,7 @@ import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.Refe import fr.ird.observe.application.swing.ui.admin.validate.ValidateModel; import fr.ird.observe.application.swing.ui.storage.StorageUIHandler; import fr.ird.observe.application.swing.ui.storage.StorageUIModel; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.application.swing.validation.ValidationModelMode; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; @@ -89,18 +88,16 @@ import static org.nuiton.i18n.I18n.t; */ public class AdminUIModel extends WizardExtModel<AdminStep> { - public static final String SELECTION_MODEL_CHANGED_PROPERTY_NAME = "selectionModelChanged"; - + // public static final String SELECTION_MODEL_CHANGED_PROPERTY_NAME = "selectionModelChanged"; public static final String SELECTED_TRIP_PROPERTY_NAME = "selectedTrip"; + public static final String PROPERTY_LOCAL_SOURCE_LABEL = "localSourceLabel"; + public static final String PROPERTY_CENTRAL_SOURCE_LABEL = "centralSourceLabel"; /** Logger */ private static final Log log = LogFactory.getLog(AdminUIModel.class); public static final PropertyChangeListener LOG_PROPERTY_CHANGE_LISTENER = new LogPropertyChanged(); - public static final String PROPERTY_LOCAL_SOURCE_LABEL = "localSourceLabel"; - public static final String PROPERTY_CENTRAL_SOURCE_LABEL = "centralSourceLabel"; - /** la source de données en cours d'utilisation par l'application */ protected ObserveSwingDataSource previousSource; @@ -122,8 +119,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { /** le controleur pour configurer les sources */ protected StorageUIHandler storageHandler; - /** selection des donnees a valider */ - protected final DataSelectionModel selectionDataModel; + protected SelectionTreeModel selectionDataModel; /** la liste des modes disponibles en entrée */ protected final EnumSet<DbMode> availableIncomingModes; @@ -166,6 +162,10 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { firePropertyChange(PROPERTY_CENTRAL_SOURCE_LABEL, oldValue, centralSourceLabel); } + public void setSelectionDataModel(SelectionTreeModel selectionDataModel) { + this.selectionDataModel = selectionDataModel; + } + public AdminUIModel() { super(AdminStep.class); @@ -234,8 +234,6 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } }; - selectionDataModel = new DataSelectionModel(); - availableIncomingModes = EnumSet.noneOf(DbMode.class); if (log.isDebugEnabled()) { @@ -309,46 +307,22 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return; } - DataSelectionModel selectModel = getSelectionDataModel(); + if (newStep == AdminStep.SELECT_DATA) { - if (containsOperation(AdminStep.EXPORT_DATA)) { - - // on doit aussi calculer les ids des marées distantes - computeExistingTrips(getSafeCentralSource(true)); + initSelectionModel(); } - if (newStep == AdminStep.SELECT_DATA && containsOperation(AdminStep.REPORT)) { - - // on remplit le modèle de sélection uniquement avec le bon type de marées - ReportModel reportModel = getReportModel(); - ObserveModelType reportType = reportModel.getModelType(); - boolean loadSeineTrip = ObserveModelType.PS == reportType; - - ObserveSwingDataSource dataSource = getSafeLocalSource(true); - populateSelectionModel(dataSource, loadSeineTrip); - return; - - } - - // on remplit le modèle de sélection - if (log.isDebugEnabled()) { - log.debug("Will refill selectionModel [" + newStep + "] : " + selectModel); - } - ObserveSwingDataSource dataSource = getSafeLocalSource(true); - populateSelectionModel(dataSource); }; listenSelectModified = evt -> { - DataSelectionModel source = (DataSelectionModel) evt.getSource(); + SelectionTreeModel source = (SelectionTreeModel) evt.getSource(); if (log.isDebugEnabled()) { - log.debug("selection data model [" + source + "] changed on " + - evt.getPropertyName() + ", new value = " + - evt.getNewValue()); + log.debug(String.format("selection data model [%s] changed on %s, new value = %s", + source, evt.getPropertyName(), evt.getNewValue())); } validate(); if (log.isDebugEnabled()) { - log.debug("nb selected export datas = " + - source.getSelectedData().size()); + log.debug("nb selected export datas = " + source.getSelectedCount()); } // on declanche la revalidation du modèle @@ -424,7 +398,64 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; } - public DataSelectionModel getSelectionDataModel() { + private void initSelectionModel() { + + SelectionTreeModel selectionDataModel = getSelectionDataModel(); + + ObserveSwingDataSource dataSource = getSafeLocalSource(true); + + if (dataSource.isLocal()) { + selectionDataModel.setShowEmptyTrips(false); + } + + boolean selectAllTrips = true; + if (containsOperation(AdminStep.REPORT)) { + + // on remplit le modèle de sélection uniquement avec le bon type de marées + ReportModel reportModel = getReportModel(); + ObserveModelType reportType = reportModel.getModelType(); + boolean loadSeineTrip = ObserveModelType.PS == reportType; + + selectionDataModel.setLoadLongline(!loadSeineTrip); + selectionDataModel.setLoadSeine(loadSeineTrip); + + selectAllTrips = false; + + } + + // on remplit le modèle de sélection + + selectionDataModel.populate(dataSource); + + if (containsOperation(AdminStep.EXPORT_DATA)) { + + // on doit aussi calculer les ids des marées distantes + ObserveSwingDataSource safeCentralSource = getSafeCentralSource(true); + + List<DataReference<?>> existingTrip = new ArrayList<>(); + + TripSeineService tripSeineService = safeCentralSource.newTripSeineService(); + DataReferenceSet<TripSeineDto> tripSeineSet = tripSeineService.getAllTripSeine(); + existingTrip.addAll(tripSeineSet.getReferences()); + + TripLonglineService tripLonglineService = safeCentralSource.newTripLonglineService(); + DataReferenceSet<TripLonglineDto> tripLonglineSet = tripLonglineService.getAllTripLongline(); + existingTrip.addAll(tripLonglineSet.getReferences()); + + selectionDataModel.setExistingTrips(existingTrip); + + + } + + if (dataSource.isLocal() && selectAllTrips) { + + // on sélectionne toutes les marées + selectionDataModel.selectAllTrips(); + } + + } + + public SelectionTreeModel getSelectionDataModel() { return selectionDataModel; } @@ -442,7 +473,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } public DataReference getSelectedTrip() { - Set<DataReference> data = getSelectionDataModel().getSelectedData(); + Set<DataReference<?>> data = getSelectionDataModel().getSelectedData(); if (data.isEmpty()) { // pas de Trip selectionne @@ -604,21 +635,16 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (log.isWarnEnabled()) log.warn("Default report file " + reportFile + " does not exists."); } -// // on charge la liste des reports disponilbes -// List<Report> reports = getReportModel().getReports(); // on ecoute la modification du modèle getReportModel().removePropertyChangeListener(listenReportModified); getReportModel().addPropertyChangeListener(listenReportModified); // on ecoute la modification de la sélection - getSelectionDataModel().removePropertyChangeListener(DataSelectionModel.PROPERTY_SELECTED_DATA, listenerSelectedDataForReport); - getSelectionDataModel().addPropertyChangeListener(DataSelectionModel.PROPERTY_SELECTED_DATA, listenerSelectedDataForReport); + getSelectionDataModel().removePropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); + getSelectionDataModel().addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); getReportModel().updateReports(); -// if (log.isInfoEnabled()) { -// log.info("Detects " + reports.size() + " report(s)."); -// } } if (containsOperation(AdminStep.CONSOLIDATE)) { @@ -792,7 +818,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } else { // on intialize le modèle de la source locale à partir du service entrant (s'il existe) - localSourceModel.initFromPreviousConfig(ui, previousSourceConfig, previousSourceInfo); + localSourceModel.initFromPreviousConfig(previousSourceConfig, previousSourceInfo); } DbMode dbMode = localSourceModel.getDbMode(); @@ -812,42 +838,48 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return; } - DataSelectionModel selectionModel = getSelectionDataModel(); + SelectionTreeModel selectionModel = getSelectionDataModel(); if (containsOperation(AdminStep.EXPORT_DATA)) { - selectionModel.setUseData(true); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); selectionModel.setUseOpenData(false); - selectionModel.setUseReferentiel(false); } if (containsOperation(AdminStep.REPORT)) { - selectionModel.setUseData(true); selectionModel.setUseOpenData(true); - selectionModel.setUseReferentiel(false); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); } if (containsOperation(AdminStep.VALIDATE)) { selectionModel.setUseOpenData(true); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(true); } if (containsOperation(AdminStep.CONSOLIDATE)) { selectionModel.setUseOpenData(true); - selectionModel.setUseData(true); - selectionModel.setUseReferentiel(false); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); } - selectionModel.addPropertyChangeListener(listenSelectModified); + selectionModel.addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenSelectModified); } @Override public void destroy() { localSourceModel.destroy(); centralSourceModel.destroy(); - selectionDataModel.destroy(); +// selectionDataModel.destroy(); super.destroy(); } @@ -1013,7 +1045,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return false; } - DataSelectionModel selectionModel = getSelectionDataModel(); + SelectionTreeModel selectionModel = getSelectionDataModel(); switch (step) { case CONFIG: @@ -1104,7 +1136,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return false; } } - if (selectionModel.isUseReferentiel()) { + if (selectionModel.isLoadReferential()) { // il faut les droits en L sur le referentiel if (!(dataSourceInformation.canReadReferential())) { @@ -1246,7 +1278,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isEmpty(); + boolean empty = selectionModel.isSelectionEmpty(); validate = !empty; } } @@ -1257,7 +1289,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isDataEmpty(); + boolean empty = selectionModel.isSelectionEmpty(); validate = !empty; } } @@ -1268,7 +1300,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isDataEmpty(); + boolean empty = selectionModel.isSelectionEmpty(); validate = !empty; } } @@ -1279,9 +1311,8 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (validate) { // il faut exactement une Trip de selectionnee - boolean empty = selectionModel.isDataEmpty(); - validate = !empty && - selectionModel.getSelectedData().size() == 1; + int selectedCount = selectionModel.getSelectedCount(); + validate = selectedCount == 1; } } break; @@ -1409,55 +1440,6 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - public void populateSelectionModel(ObserveSwingDataSource source) { - try { - DataSelectionModel.populate(getSelectionDataModel(), source); - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("could not populate selected model", e); - } - } finally { - - // on notifie que le modèle de sélection a changé - // (il faut donc recalculé l'arbre de sélection) - firePropertyChange(SELECTION_MODEL_CHANGED_PROPERTY_NAME, getSelectionDataModel()); - } - } - - public void populateSelectionModel(ObserveSwingDataSource source, boolean tripSeine) { - try { - DataSelectionModel.populate(getSelectionDataModel(), source, tripSeine); - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("could not populate selected model", e); - } - } finally { - - // on notifie que le modèle de sélection a changé - // (il faut donc recalculé l'arbre de sélection) - firePropertyChange(SELECTION_MODEL_CHANGED_PROPERTY_NAME, getSelectionDataModel()); - } - } - - protected void computeExistingTrips(ObserveSwingDataSource source) { - - List<DataReference<?>> existingTrip = Lists.newArrayList(); - - TripSeineService tripSeineService = source.newTripSeineService(); - DataReferenceSet<TripSeineDto> tripSeineSet = tripSeineService.getAllTripSeine(); - existingTrip.addAll(tripSeineSet.getReferences()); - - TripLonglineService tripLonglineService = source.newTripLonglineService(); - DataReferenceSet<TripLonglineDto> tripLonglineSet = tripLonglineService.getAllTripLongline(); - existingTrip.addAll(tripLonglineSet.getReferences()); - - - getExportModel().setExistingTrips(existingTrip); - - } - protected void updateSaveLocalOperation() { boolean shouldAdd = false; for (AdminStep s : operations) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx index 6cd6cf9..8aad3ca 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx @@ -25,8 +25,7 @@ <!-- ************************************************************* --> <fr.ird.observe.application.swing.ui.admin.AdminTabUI _successIcon='SwingUtil.getUIManagerActionIcon("connect_ok")' - _failedIcon='SwingUtil.getUIManagerActionIcon("connect_no")' - > + _failedIcon='SwingUtil.getUIManagerActionIcon("connect_no")'> <import> fr.ird.observe.application.swing.ui.admin.AdminUI diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java index 16b1900..b8cee91 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java @@ -23,22 +23,21 @@ package fr.ird.observe.application.swing.ui.admin.config; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveTextGenerator; -import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.storage.StorageStep; -import fr.ird.observe.application.swing.ui.storage.StorageUIHandler; import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; +import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.swing.JCheckBox; import javax.swing.JLabel; -import javax.swing.JTree; import java.awt.Window; import java.util.Set; @@ -72,7 +71,6 @@ public class ConfigUIHandler extends AdminTabUIHandler { UIHelper.setLayerUI(tabUI.getContent(), null); } - public void initTabUI(AdminUI ui, SelectDataUI tabUI) { super.initTabUI(ui, tabUI); @@ -84,11 +82,12 @@ public class ConfigUIHandler extends AdminTabUIHandler { UIHelper.setLayerUI(tabUI.getContent(), null); UIHelper.setLayerUI(tabUI.getSelectTreePane(), ui.getConfigBlockLayerUI()); - JTree tree = tabUI.getSelectTree(); - tabUI.getTreeHelper().setUI(tree, false, null); + SelectionTree tree = tabUI.getSelectTree(); + ui.getModel().setSelectionDataModel(tree.getTreeModel()); - // customize tree selection colors - UIHelper.initUI(tabUI.getSelectTreePane(), tree); + tree.installUI(); + //FIXME Init tree ? +// UIHelper.initUI(tabUI.getSelectTreePane(), tree); } public void updateOperationState(JCheckBox checkBox) { @@ -105,9 +104,7 @@ public class ConfigUIHandler extends AdminTabUIHandler { } } - public String updateStorageLabel(StorageUIModel service, - boolean serviceValid, - JLabel label) { + public String updateStorageLabel(StorageUIModel service, boolean serviceValid, JLabel label) { String text; if (serviceValid) { @@ -131,10 +128,6 @@ public class ConfigUIHandler extends AdminTabUIHandler { return operations.contains(scope); } - public StorageUIHandler getStorageHandler() { - return ui.getContextValue(StorageUIHandler.class); - } - public void obtainIncomingConnexion() { StorageUIModel sourceModel = ui.getLocalSourceModel(); StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); @@ -178,9 +171,4 @@ public class ConfigUIHandler extends AdminTabUIHandler { return text; } - protected boolean canShowLocalStorage(Set<AdminStep> operations, - boolean needLocalStorage) { - return !operations.isEmpty() && needLocalStorage; - } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx index 7e9fc24..296703b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx @@ -28,34 +28,20 @@ <import> fr.ird.observe.application.swing.ui.UIHelper + fr.ird.observe.application.swing.ui.admin.AdminActionModel fr.ird.observe.application.swing.ui.admin.AdminUI fr.ird.observe.application.swing.ui.admin.AdminStep - fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper - fr.ird.observe.application.swing.ui.tree.renderer.DataSelectionTreeCellRenderer - fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel - fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel + fr.ird.observe.application.swing.ui.tree.selection.SelectionTree - fr.ird.observe.application.swing.ui.util.tree.BeanTreeHeader + fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeHeader jaxx.runtime.SwingUtil - javax.swing.tree.TreeSelectionModel - </import> - <ObserveTreeHelper id='treeHelper'/> - <ConfigUIHandler id='handler' constructorParams='this'/> - <fr.ird.observe.application.swing.ui.admin.AdminActionModel id='stepModel' initializer='null'/> - - <DataSelectionModel id='selectDataModel' - initializer='getModel().getSelectionDataModel()'/> - - <DataSelectionTreeSelectionModel id='selectionModel'/> - - <DataSelectionTreeCellRenderer id='selectionRenderer' - constraints='BorderLayout.EAST'/> + <AdminActionModel id='stepModel' initializer='null'/> <script><![CDATA[ public SelectDataUI(AdminUI parentContext) { @@ -66,25 +52,15 @@ public void initUI(AdminUI ui) { getHandler().initTabUI(ui, this); } -@Override -public void destroy() { - selectionModel.clearSelection(); - //selectDataModel = null; - super.destroy(); -} ]]> </script> <JPanel id='PENDING_content'> - <JScrollPane id='selectTreePane' constraints='BorderLayout.CENTER' - decorator='boxed' columnHeaderView='{selectTreeHeader}'> - - <!-- arbre de selection des exports --> - <JTree id='selectTree'/> - - <BeanTreeHeader id='selectTreeHeader' tree='{selectTree}'/> - + <JScrollPane id='selectTreePane' constraints='BorderLayout.CENTER' decorator='boxed' + columnHeaderView='{selectTreeHeader}'> + <SelectionTree id='selectTree'/> + <SelectionTreeHeader id='selectTreeHeader' treeTable='{selectTree}'/> </JScrollPane> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss index 9aef87d..4e863e0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss @@ -25,25 +25,14 @@ } #selectTree { - rootVisible:false; - largeModel:true; + /*rootVisible:false; + largeModel:true;*/ minimumSize:{UIHelper.newMinDimension()}; font-size:11; - showsRootHandles:false; - toggleClickCount:100; -} - -#selectionModel { - selectionMode: {TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION}; - dataModel:{selectDataModel}; + /*showsRootHandles:false; + toggleClickCount:100;*/ } #selectTreePane { verticalScrollBarPolicy:{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}; } - -#selectTree { - selectionModel:{selectionModel}; - cellRenderer:{selectionRenderer}; -} - diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java index d7f50c2..3661e00 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java @@ -23,15 +23,9 @@ package fr.ird.observe.application.swing.ui.admin.consolidate; import com.google.common.collect.ImmutableSet; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.AdminUI; -import fr.ird.observe.application.swing.ui.admin.AdminUIModel; -import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.service.actions.consolidate.ConsolidateActivitySeineDataResult; import fr.ird.observe.services.service.actions.consolidate.ConsolidateDataService; @@ -41,8 +35,6 @@ import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.JTree; -import java.beans.PropertyChangeListener; import java.util.Date; import java.util.Set; import java.util.stream.Collectors; @@ -73,44 +65,14 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { super.initTabUI(ui, tabUI); if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + - "] for main ui " + ui.getClass().getName() + "@" + - System.identityHashCode(ui)); + log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); } - tabUI.getStartButton().setText( - t("observe.actions.synchro.launch.operation", - t(tabUI.getStep().getOperationLabel()))); + tabUI.getStartButton().setText(t("observe.actions.synchro.launch.operation", t(tabUI.getStep().getOperationLabel()))); - SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); - - PropertyChangeListener listener = evt -> { - AdminUIModel model1 = (AdminUIModel) evt.getSource(); - if (!model1.containsStep(selectTabUI.getStep())) { - // avoid multi-cast - return; - } - DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("selection model changed to " + value); - } - updateSelectionModel(selectTabUI); - }; - tabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, listener); - } - - @Override - protected void updateSelectionModel(AdminTabUI tabUI, ObserveTreeHelper helper, JTree selectTree, ObserveSwingDataSource source, DataSelectionModel selectDataModel, DataSelectionTreeSelectionModel selectionModel) { - super.updateSelectionModel(tabUI, helper, selectTree, source, selectDataModel, selectionModel); - if (source.isLocal()) { - - // on sélectionne toutes les marées - selectDataModel.addAllSelectedData(); - } } public void startAction() { - addAdminWorker(((ConsolidateUI) ui).getStartButton().getToolTipText(), this::doAction); } @@ -121,7 +83,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { getStepModel().setSource(model.getSafeLocalSource(false)); - Set<DataReference> trips = model.getSelectionDataModel().getSelectedData(); + Set<DataReference<?>> trips = model.getSelectionDataModel().getSelectedData(); ImmutableSet<String> tripIds = ImmutableSet.copyOf(trips.stream() .filter(DataReference.newTripSeinePredicate()) .map(DataReference.ID_FUNCTION) diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java index 86064d3..bb72f62 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java @@ -22,23 +22,17 @@ package fr.ird.observe.application.swing.ui.admin.export; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.AbstractReference; -import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; +import fr.ird.observe.application.swing.ui.admin.AdminActionModel; +import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.services.dto.longline.TripLonglineDto; import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.application.swing.ui.admin.AdminActionModel; -import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; -import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * Le modèle d'une opération d'export de données observers. @@ -51,9 +45,6 @@ public class ExportModel extends AdminActionModel { /** les index des marées à exporter. */ protected int[] exportDataSelectedIndex; - /** les ids des marées déjà existante sur la base distante lors d'un export */ - protected List<DataReference<?>> existingTrips; - /** les données exportables */ protected List<TripEntry> data; @@ -77,21 +68,9 @@ public class ExportModel extends AdminActionModel { this.exportDataSelectedIndex = exportDataSelectedIndex; } - public List<DataReference<?>> getExistingTrips() { - return existingTrips; - } - - public void setExistingTrips(List<DataReference<?>> existingTrips) { - this.existingTrips = existingTrips; - } - @Override public void destroy() { super.destroy(); - if (existingTrips != null) { - existingTrips.clear(); - existingTrips = null; - } exportDataSelectedIndex = null; tripSeineDecorator = null; data = null; @@ -103,26 +82,8 @@ public class ExportModel extends AdminActionModel { return data; } - public void setData(DataSelectionModel selectionModel) { - - List<TripEntry> tripEntries = Lists.newArrayList(); - - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : selectionModel.getSelectedDataByProgram().entrySet()) { - - ReferentialReference<ProgramDto> program = entry.getKey(); - - for (DataReference trip : entry.getValue()) { - - boolean exists = existingTrips.contains(trip); - - TripEntry tripEntry = new TripEntry(program, trip, exists); - - tripEntries.add(tripEntry); - } - } - - this.data = ImmutableList.copyOf(tripEntries); - + public void setData(ImmutableList<TripEntry> data) { + this.data = data; } public ObserveSwingDataSource getSource() { @@ -153,20 +114,6 @@ public class ExportModel extends AdminActionModel { this.tripLonglineDecorator = tripLonglineDecorator; } - public String decorate(AbstractReference referenceDto) { - String decor = null; - - if (ProgramDto.class.isAssignableFrom(referenceDto.getType())) { - decor = programDecorator.toString(referenceDto); - } else if (TripSeineDto.class.isAssignableFrom(referenceDto.getType())) { - decor = tripSeineDecorator.toString(referenceDto); - } else if (TripLonglineDto.class.isAssignableFrom(referenceDto.getType())) { - decor = tripLonglineDecorator.toString(referenceDto); - } - - return decor; - } - public List<TripEntry> getSelectedTrips() { List<TripEntry> entries = new ArrayList<>(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java index 4f46a9d..2ac9563 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java @@ -33,10 +33,8 @@ import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.AdminUI; -import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; -import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.application.swing.ui.usage.UsagesUI; import fr.ird.observe.services.dto.AbstractReference; import fr.ird.observe.services.dto.DataReference; @@ -105,21 +103,6 @@ public class ExportUIHandler extends AdminTabUIHandler { configabUI.getCentralSourceInfoLabel().setText(t("observe.action.config.export.required.write.data")); configabUI.getCentralSourceLabel().setText(t("observe.action.config.export.required.write.data")); - SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); - - tabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, evt -> { - AdminUIModel model1 = (AdminUIModel) evt.getSource(); - - DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); - if (log.isInfoEnabled()) { - log.info("selection model changed to " + value); - } - - selectTabUI.getSelectionModel().clearSelection(); - selectTabUI.getSelectionRenderer().setExistingTrips(model1.getExportModel().getExistingTrips()); - updateSelectionModel(selectTabUI); - }); - // tableau de l'export de données final JTable table4 = tabUI.getTrips(); @@ -226,8 +209,8 @@ public class ExportUIHandler extends AdminTabUIHandler { sendMessage(t("observe.actions.exportData.message.prepare.data")); // récupération des couples (program, marees) sur la base temporaire - DataSelectionModel selectionModel = model.getSelectionDataModel(); - stepModel.setData(selectionModel); + SelectionTreeModel selectionModel = model.getSelectionDataModel(); + stepModel.setData(selectionModel.getSelectedTripEntries()); List<TripEntry> entries = stepModel.getData(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java index 71af856..abfe150 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java @@ -29,10 +29,7 @@ import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.AdminUI; -import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; -import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; import fr.ird.observe.services.dto.DataDto; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.ObserveModelType; @@ -197,23 +194,6 @@ public class ReportUIHandler extends AdminTabUIHandler { ReportConfigUI extraConfig = new ReportConfigUI(tx); configUI.getExtraConfig().add(extraConfig); - - final SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); - ui.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, evt -> { - AdminUIModel model1 = (AdminUIModel) evt.getSource(); - if (!model1.containsStep(selectTabUI.getStep())) { - - // avoid multi-cast - return; - } - - DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("selection model changed to " + value.getDatas()); - log.debug("IS USE DATA ? : " + value.isUseData()); - } - updateSelectionModel(selectTabUI); - }); } public void setModelTypeFromEvent(ItemEvent event) { @@ -228,7 +208,7 @@ public class ReportUIHandler extends AdminTabUIHandler { if (log.isInfoEnabled()) { log.info("Item selected!"); } - JComboBox<Report> source = (JComboBox<Report>) event.getSource(); + JComboBox source = (JComboBox) event.getSource(); updateSelectedReport((Report) source.getSelectedItem()); } } @@ -310,9 +290,7 @@ public class ReportUIHandler extends AdminTabUIHandler { } @SuppressWarnings({"unchecked"}) - protected void onSelectedReportChanged(ReportUI tabUI, - ReportModel model, - Report report) { + protected void onSelectedReportChanged(ReportUI tabUI, ReportModel model, Report report) { if (log.isInfoEnabled()) { log.info("New selected report [" + report + "]"); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java index d3a5251..19abcde 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java @@ -26,7 +26,7 @@ import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.DataSynchronizeTaskSupport; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,7 +45,7 @@ public class DataSynchroModel extends AdminActionModel { public static final String LEFT_SOURCE_PROPERTY_NAME = "leftSource"; public static final String RIGHT_SOURCE_PROPERTY_NAME = "rightSource"; - public static final String TASKS_PROPERTY_NAME = "tasks"; +// public static final String TASKS_PROPERTY_NAME = "tasks"; public static final String LEFT_SELECTION_MODEL_CHANGED_PROPERTY_NAME = "leftSelectionModelChanged"; public static final String RIGHT_SELECTION_MODEL_CHANGED_PROPERTY_NAME = "rightSelectionModelChanged"; @@ -57,25 +57,39 @@ public class DataSynchroModel extends AdminActionModel { protected ObserveSwingDataSource rightSource; /** les données sélectionnées sur le panneau de gauche. */ - protected final DataSelectionModel leftSelectionDataModel; + protected SelectionTreeModel leftSelectionDataModel; /** les données sélectionnées sur le panneau de droite. */ - protected final DataSelectionModel rightSelectionDataModel; + protected SelectionTreeModel rightSelectionDataModel; protected final DefaultListModel<DataSynchronizeTaskSupport> tasks; public DataSynchroModel() { super(AdminStep.DATA_SYNCHRONIZE); - leftSelectionDataModel = new DataSelectionModel(); - leftSelectionDataModel.setUseData(true); - - rightSelectionDataModel = new DataSelectionModel(); - rightSelectionDataModel.setUseData(true); +// leftSelectionDataModel = new SelectionTreeModel(); +// leftSelectionDataModel.setLoadLongline(true); +// leftSelectionDataModel.setLoadSeine(true); +// leftSelectionDataModel.setLoadReferential(false); +// leftSelectionDataModel.setShowEmptyTrips(false); +// +// rightSelectionDataModel = new SelectionTreeModel(); +// rightSelectionDataModel.setLoadLongline(true); +// rightSelectionDataModel.setLoadSeine(true); +// rightSelectionDataModel.setLoadReferential(false); +// rightSelectionDataModel.setShowEmptyTrips(false); tasks = new DefaultListModel<>(); } + public void setLeftSelectionDataModel(SelectionTreeModel leftSelectionDataModel) { + this.leftSelectionDataModel = leftSelectionDataModel; + } + + public void setRightSelectionDataModel(SelectionTreeModel rightSelectionDataModel) { + this.rightSelectionDataModel = rightSelectionDataModel; + } + public ObserveSwingDataSource getLeftSource() { return leftSource; } @@ -94,11 +108,11 @@ public class DataSynchroModel extends AdminActionModel { firePropertyChange(RIGHT_SOURCE_PROPERTY_NAME, rightSource); } - public DataSelectionModel getLeftSelectionDataModel() { + public SelectionTreeModel getLeftSelectionDataModel() { return leftSelectionDataModel; } - public DataSelectionModel getRightSelectionDataModel() { + public SelectionTreeModel getRightSelectionDataModel() { return rightSelectionDataModel; } @@ -118,11 +132,11 @@ public class DataSynchroModel extends AdminActionModel { tasks.addElement(task); } - private void populateSelectionModel(ObserveSwingDataSource dataSource, DataSelectionModel selectionDataModel, String propertyName) { + private void populateSelectionModel(ObserveSwingDataSource dataSource, SelectionTreeModel selectionDataModel, String propertyName) { try { - DataSelectionModel.populate(selectionDataModel, dataSource); + selectionDataModel.populate(dataSource); } catch (Exception e) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroSelectionTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroSelectionTreeCellRenderer.java index 1cf804c..53537e9 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroSelectionTreeCellRenderer.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroSelectionTreeCellRenderer.java @@ -24,57 +24,50 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.data; import com.google.common.collect.ImmutableSet; import fr.ird.observe.application.swing.ui.UIHelper; -import fr.ird.observe.application.swing.ui.tree.renderer.DataSelectionTreeCellRenderer; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.ReferentialReferenceNodeSupport; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.ProgramSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.ReferenceSelectionTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.RootSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.SelectionTreeNodeSupport; import javax.swing.Icon; -import javax.swing.JTree; -import javax.swing.tree.TreeModel; -import java.util.Enumeration; /** * Created by tchemit on 04/10/16. * * @author Tony Chemit - chemit@codelutin.com */ -public class DataSynchroSelectionTreeCellRenderer extends DataSelectionTreeCellRenderer { +public class DataSynchroSelectionTreeCellRenderer extends SelectionTreeCellRenderer { private final Icon newTripIcon = UIHelper.createActionIcon("synchroAdd"); private final Icon existingTripIcon = UIHelper.createActionIcon("synchroUpdate"); - private final JTree oppositeTree; + private final SelectionTree oppositeTree; private ImmutableSet<String> oppositeIds; - public DataSynchroSelectionTreeCellRenderer(JTree oppositeTree) { + public DataSynchroSelectionTreeCellRenderer(SelectionTree oppositeTree) { this.oppositeTree = oppositeTree; } @Override - public void setIcon(ObserveNode node) { - if (node instanceof ReferentialReferenceNodeSupport<?> || !(oppositeTree.getModel().getRoot() instanceof ObserveNode)) { - super.setIcon(node); + public Icon getIcon(SelectionTreeNodeSupport node) { + if (getOppositeIds().contains(node.getId())) { + return existingTripIcon; } else { - if (getOppositeIds().contains(node.getId())) { - setDefaultIcons(existingTripIcon); - } else { - setDefaultIcons(newTripIcon); - } + return newTripIcon; } } private ImmutableSet<String> getOppositeIds() { if (oppositeIds == null) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); - TreeModel model = oppositeTree.getModel(); - ObserveNode rootNode = (ObserveNode) model.getRoot(); - Enumeration<ObserveNode> programNodes = rootNode.children(); - while (programNodes.hasMoreElements()) { - ObserveNode programNode = programNodes.nextElement(); - Enumeration<ObserveNode> tripNodes = programNode.children(); - while (tripNodes.hasMoreElements()) { - ObserveNode tripNode = tripNodes.nextElement(); - builder.add(tripNode.getId()); + SelectionTreeModel model = oppositeTree.getTreeModel(); + RootSelectionTreeNode rootNode = model.getRoot(); + for (ProgramSelectionTreeNode programNode : rootNode) { + for (ReferenceSelectionTreeNodeSupport<?, ?> tripNode : programNode) { + builder.add(tripNode.getData().getId()); } } oppositeIds = builder.build(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx index 4a15765..203d32e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx @@ -28,33 +28,18 @@ fr.ird.observe.application.swing.ui.UIHelper fr.ird.observe.application.swing.ui.admin.AdminUI fr.ird.observe.application.swing.ui.admin.AdminStep - fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper - fr.ird.observe.application.swing.ui.tree.renderer.DataSelectionTreeCellRenderer - fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel - fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel - fr.ird.observe.application.swing.ui.util.tree.BeanTreeHeader + fr.ird.observe.application.swing.ui.tree.selection.SelectionTree + fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeHeader jaxx.runtime.SwingUtil javax.swing.ListSelectionModel - javax.swing.tree.TreeSelectionModel </import> - <ObserveTreeHelper id='leftTreeHelper'/> - <ObserveTreeHelper id='rightTreeHelper'/> - <DataSynchroUIHandler id='handler' constructorParams='this'/> <DataSynchroModel id='stepModel' initializer='getModel().getDataSynchroModel()'/> - <DataSelectionModel id='leftSelectDataModel' - initializer='getModel().getDataSynchroModel().getLeftSelectionDataModel()'/> - <DataSelectionTreeSelectionModel id='leftSelectionModel'/> - - <DataSelectionModel id='rightSelectDataModel' - initializer='getModel().getDataSynchroModel().getRightSelectionDataModel()'/> - <DataSelectionTreeSelectionModel id='rightSelectionModel'/> - <script><![CDATA[ public DataSynchroUI(AdminUI parentContext) { super(AdminStep.DATA_SYNCHRONIZE, parentContext); @@ -64,12 +49,6 @@ public void initUI(AdminUI ui) { getHandler().initTabUI(ui, this); } -@Override -public void destroy() { - leftSelectionModel.clearSelection(); - rightSelectionModel.clearSelection(); - super.destroy(); -} ]]> </script> @@ -89,8 +68,8 @@ public void destroy() { <row> <cell weightx="0.45"> <JScrollPane id='leftTreePane' decorator='boxed' columnHeaderView='{leftTreeHeader}'> - <JTree id='leftTree'/> - <BeanTreeHeader id='leftTreeHeader' tree='{leftTree}'/> + <SelectionTree id='leftTree'/> + <SelectionTreeHeader id='leftTreeHeader' treeTable='{leftTree}'/> </JScrollPane> </cell> <cell weightx="0.1"> @@ -105,8 +84,8 @@ public void destroy() { </cell> <cell weightx="0.45"> <JScrollPane id='rightTreePane' decorator='boxed' columnHeaderView='{rightTreeHeader}'> - <JTree id='rightTree'/> - <BeanTreeHeader id='rightTreeHeader' tree='{rightTree}'/> + <SelectionTree id='rightTree'/> + <SelectionTreeHeader id='rightTreeHeader' treeTable='{rightTree}'/> </JScrollPane> </cell> </row> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jcss index a6be801..91956b8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jcss @@ -44,19 +44,8 @@ } #leftTree { - rootVisible:false; - largeModel:true; minimumSize:{UIHelper.newMinDimension()}; font-size:11; - showsRootHandles:false; - toggleClickCount:100; - selectionModel:{leftSelectionModel}; - cellRenderer:{new DataSynchroSelectionTreeCellRenderer(rightTree)}; -} - -#leftSelectionModel { - selectionMode: {TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION}; - dataModel:{leftSelectDataModel}; } #leftTreePane { @@ -64,19 +53,8 @@ } #rightTree { - rootVisible:false; - largeModel:true; minimumSize:{UIHelper.newMinDimension()}; font-size:11; - showsRootHandles:false; - toggleClickCount:100; - selectionModel:{rightSelectionModel}; - cellRenderer:{new DataSynchroSelectionTreeCellRenderer(leftTree)}; -} - -#rightSelectionModel { - selectionMode: {TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION}; - dataModel:{rightSelectDataModel}; } #rightTreePane { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java index cc16fb5..5ac903a 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.data; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; -import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; @@ -36,8 +35,8 @@ import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.CopyToRig import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.DataSynchronizeTaskSupport; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.DeleteFromLeftDataSynchronizeTask; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.DeleteFromRightDataSynchronizeTask; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.referential.ProgramDto; @@ -98,28 +97,47 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); } - getStepModel().getLeftSelectionDataModel().addPropertyChangeListener(evt -> { + DataSynchroModel stepModel = getStepModel(); + + SelectionTree leftTree = tabUI.getLeftTree(); + SelectionTreeModel leftSelectionDataModel = leftTree.getTreeModel(); + stepModel.setLeftSelectionDataModel(leftSelectionDataModel); + leftSelectionDataModel.setLoadLongline(true); + leftSelectionDataModel.setLoadSeine(true); + leftSelectionDataModel.setLoadReferential(false); + leftSelectionDataModel.setShowEmptyTrips(false); + + + SelectionTree rightTree = tabUI.getRightTree(); + SelectionTreeModel rightSelectionDataModel = rightTree.getTreeModel(); + stepModel.setRightSelectionDataModel(rightSelectionDataModel); + rightSelectionDataModel.setLoadLongline(true); + rightSelectionDataModel.setLoadSeine(true); + rightSelectionDataModel.setLoadReferential(false); + rightSelectionDataModel.setShowEmptyTrips(false); + + // on n'installe qu'une seule fois l'ui + leftTree.installUI2(rightTree); - DataSelectionModel model = (DataSelectionModel) evt.getSource(); - boolean withDataSelected = !model.isDataEmpty(); + stepModel.getLeftSelectionDataModel().addPropertyChangeListener(evt -> { + + SelectionTreeModel model = (SelectionTreeModel) evt.getSource(); + boolean withDataSelected = !model.isSelectionEmpty(); tabUI.getCopyToRight().setEnabled(withDataSelected); tabUI.getDeleteFromLeft().setEnabled(withDataSelected); }); - getStepModel().getRightSelectionDataModel().addPropertyChangeListener(evt -> { + stepModel.getRightSelectionDataModel().addPropertyChangeListener(evt -> { - DataSelectionModel model = (DataSelectionModel) evt.getSource(); - boolean withDataSelected = !model.isDataEmpty(); + SelectionTreeModel model = (SelectionTreeModel) evt.getSource(); + boolean withDataSelected = !model.isSelectionEmpty(); tabUI.getCopyToLeft().setEnabled(withDataSelected); tabUI.getDeleteFromRight().setEnabled(withDataSelected); }); - UIHelper.initUI(tabUI.getLeftTreePane(), tabUI.getLeftTree()); - UIHelper.initUI(tabUI.getRightTreePane(), tabUI.getRightTree()); - } public void doStartAction() { @@ -130,49 +148,38 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { public void addCopyToLeftTasks() { - DataSelectionModel rightSelectionDataModel = getStepModel().getRightSelectionDataModel(); - DataSelectionModel leftSelectionDataModel = getStepModel().getLeftSelectionDataModel(); - ObserveTreeHelper rightTreeHelper = getUi().getRightTreeHelper(); - ObserveTreeHelper leftTreeHelper = getUi().getLeftTreeHelper(); - Map<ReferentialReference<ProgramDto>, List<DataReference>> selectedDataByProgram = rightSelectionDataModel.getSelectedDataByProgram(); + SelectionTreeModel rightSelectionDataModel = getStepModel().getRightSelectionDataModel(); + SelectionTreeModel leftSelectionDataModel = getStepModel().getLeftSelectionDataModel(); + Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> selectedDataByProgram = rightSelectionDataModel.getSelectedDataByProgram(); rightSelectionDataModel.removeAllSelectedData(); - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : selectedDataByProgram.entrySet()) { + for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference<?>>> entry : selectedDataByProgram.entrySet()) { ReferentialReference<ProgramDto> program = entry.getKey(); for (DataReference trip : entry.getValue()) { boolean tripExistOnLeft = leftSelectionDataModel.containsData(program, trip); getStepModel().addTask(new CopyToLeftDataSynchronizeTask(program, trip, tripExistOnLeft)); - rightTreeHelper.removeTrip(program, trip); - rightSelectionDataModel.removeTrip(program, trip); if (tripExistOnLeft) { - leftTreeHelper.removeTrip(program, trip); leftSelectionDataModel.removeTrip(program, trip); } } } - } public void addCopyToRightTasks() { - DataSelectionModel leftSelectionDataModel = getStepModel().getLeftSelectionDataModel(); - DataSelectionModel rightSelectionDataModel = getStepModel().getRightSelectionDataModel(); - ObserveTreeHelper leftTreeHelper = getUi().getLeftTreeHelper(); - ObserveTreeHelper rightTreeHelper = getUi().getRightTreeHelper(); - Map<ReferentialReference<ProgramDto>, List<DataReference>> selectedDataByProgram = leftSelectionDataModel.getSelectedDataByProgram(); + SelectionTreeModel leftSelectionDataModel = getStepModel().getLeftSelectionDataModel(); + SelectionTreeModel rightSelectionDataModel = getStepModel().getRightSelectionDataModel(); + Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> selectedDataByProgram = leftSelectionDataModel.getSelectedDataByProgram(); leftSelectionDataModel.removeAllSelectedData(); - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : selectedDataByProgram.entrySet()) { + for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference<?>>> entry : selectedDataByProgram.entrySet()) { ReferentialReference<ProgramDto> program = entry.getKey(); for (DataReference trip : entry.getValue()) { boolean tripExistOnRight = rightSelectionDataModel.containsData(program, trip); getStepModel().addTask(new CopyToRightDataSynchronizeTask(program, trip, tripExistOnRight)); - leftTreeHelper.removeTrip(program, trip); - leftSelectionDataModel.removeTrip(program, trip); if (tripExistOnRight) { - rightTreeHelper.removeTrip(program, trip); rightSelectionDataModel.removeTrip(program, trip); } } @@ -182,36 +189,28 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { public void addDeleteFromLeftTasks() { - DataSelectionModel selectionDataModel = getStepModel().getLeftSelectionDataModel(); - ObserveTreeHelper treeHelper = getUi().getLeftTreeHelper(); - Map<ReferentialReference<ProgramDto>, List<DataReference>> selectedDataByProgram = selectionDataModel.getSelectedDataByProgram(); + SelectionTreeModel selectionDataModel = getStepModel().getLeftSelectionDataModel(); + Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> selectedDataByProgram = selectionDataModel.getSelectedDataByProgram(); selectionDataModel.removeAllSelectedData(); - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : selectedDataByProgram.entrySet()) { + for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference<?>>> entry : selectedDataByProgram.entrySet()) { ReferentialReference<ProgramDto> program = entry.getKey(); for (DataReference trip : entry.getValue()) { getStepModel().addTask(new DeleteFromLeftDataSynchronizeTask(program, trip)); - treeHelper.removeTrip(program, trip); - selectionDataModel.removeTrip(program, trip); } } - } public void addDeleteFromRightTasks() { - DataSelectionModel selectionDataModel = getStepModel().getRightSelectionDataModel(); - ObserveTreeHelper treeHelper = getUi().getRightTreeHelper(); - Map<ReferentialReference<ProgramDto>, List<DataReference>> selectedDataByProgram = selectionDataModel.getSelectedDataByProgram(); + SelectionTreeModel selectionDataModel = getStepModel().getRightSelectionDataModel(); + Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> selectedDataByProgram = selectionDataModel.getSelectedDataByProgram(); selectionDataModel.removeAllSelectedData(); - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : selectedDataByProgram.entrySet()) { + for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference<?>>> entry : selectedDataByProgram.entrySet()) { ReferentialReference<ProgramDto> program = entry.getKey(); for (DataReference trip : entry.getValue()) { getStepModel().addTask(new DeleteFromRightDataSynchronizeTask(program, trip)); - treeHelper.removeTrip(program, trip); - selectionDataModel.removeTrip(program, trip); } } - } public void doExecuteAction() { @@ -234,14 +233,14 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { tabUI.getLeftTreePane().setBorder(new TitledBorder(getModel().getLocalSourceModel().getLabel())); stepModel.populateLeftSelectionModel(); - updateSelectionModel(tabUI, tabUI.getLeftTreeHelper(), tabUI.getLeftTree(), leftSource, stepModel.getLeftSelectionDataModel(), tabUI.getLeftSelectionModel()); +// updateSelectionModel(tabUI.getLeftTree(), leftSource); sendMessage(t("observe.actions.synchro.referential.message.data.leftData.loaded")); configUI.getLocalSourceConfig().setBorder(new TitledBorder(getModel().getLocalSourceLabel())); tabUI.getRightTreePane().setBorder(new TitledBorder(getModel().getCentralSourceModel().getLabel())); stepModel.populateRightSelectionModel(); - updateSelectionModel(tabUI, tabUI.getRightTreeHelper(), tabUI.getRightTree(), rightSource, stepModel.getRightSelectionDataModel(), tabUI.getRightSelectionModel()); +// updateSelectionModel(tabUI.getRightTree(), rightSource); sendMessage(t("observe.actions.synchro.referential.message.data.rightData.loaded")); configUI.getCentralSourceConfig().setBorder(new TitledBorder(getModel().getCentralSourceLabel())); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx index e637979..1ec9b95 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx @@ -36,7 +36,6 @@ fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.action.RegisterSkipTaskAction fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.tree.ReferentialSynchronizeTreeModel fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.tree.ReferentialSynchronizeTreeCellRenderer - fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper fr.ird.observe.application.swing.ui.util.tree.BeanTreeHeader javax.swing.ListSelectionModel @@ -44,9 +43,6 @@ </import> - <ObserveTreeHelper id='leftTreeHelper'/> - <ObserveTreeHelper id='rightTreeHelper'/> - <ReferentialSynchroUIHandler id='handler' constructorParams='this'/> <ReferentialSynchroModel id='stepModel' javaBean='getModel().getReferentialSynchroModel()'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx index 4e19959..c40b605 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx @@ -27,6 +27,8 @@ <fr.ird.observe.application.swing.ui.admin.AdminTabUI> <import> + fr.ird.observe.services.dto.AbstractReference + fr.ird.observe.application.swing.ui.UIHelper fr.ird.observe.application.swing.ui.admin.AdminStep fr.ird.observe.application.swing.ui.admin.AdminTabUI @@ -49,7 +51,7 @@ <DefaultListModel id='typeModel' genericType='Class<?>'/> - <DefaultListModel id='refModel'/> + <DefaultListModel id='refModel' genericType='AbstractReference<?>'/> <ValidationMessageTableModel id='messagesModel'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java index e75fc89..91857ce 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java @@ -34,10 +34,9 @@ import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.AdminUI; -import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.application.swing.ui.util.ObserveValidationMessageTableRenderer; import fr.ird.observe.application.swing.validation.ValidationModelMode; import fr.ird.observe.services.dto.AbstractReference; @@ -50,8 +49,8 @@ import fr.ird.observe.services.service.actions.validate.ValidateDataResult; import fr.ird.observe.services.service.actions.validate.ValidateReferentialsRequest; import fr.ird.observe.services.service.actions.validate.ValidateReferentialsResult; import fr.ird.observe.services.service.actions.validate.ValidateResultForDto; -import fr.ird.observe.services.service.actions.validate.ValidateResultForDtoType; import fr.ird.observe.services.service.actions.validate.ValidateResultForDtoHelper; +import fr.ird.observe.services.service.actions.validate.ValidateResultForDtoType; import fr.ird.observe.services.service.actions.validate.ValidateService; import fr.ird.observe.services.service.actions.validate.ValidationMessage; import fr.ird.observe.services.service.actions.validate.ValidatorDto; @@ -64,8 +63,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.validator.NuitonValidatorScope; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListModel; import javax.swing.JCheckBox; import javax.swing.JTable; @@ -94,7 +91,7 @@ import static org.nuiton.i18n.I18n.t; */ public class ValidateUIHandler extends AdminTabUIHandler { - public static final String[] EMPTY_STRING_ARRAY = new String[]{}; +// public static final String[] EMPTY_STRING_ARRAY = new String[]{}; public static final String LINE = "--------------------------------------------------------------------------------"; @@ -160,42 +157,31 @@ public class ValidateUIHandler extends AdminTabUIHandler { // rien a faire pour le moment... return; } - DataSelectionModel selectDataModel; - selectDataModel = selectTabUI.getSelectDataModel(); + SelectionTreeModel selectDataModel = selectTabUI.getSelectTree().getTreeModel(); + selectDataModel.setLoadLongline(false); + selectDataModel.setLoadSeine(false); + selectDataModel.setLoadReferential(false); if (log.isDebugEnabled()) { log.debug("validation model changed to " + value); } switch (value) { case REFERENTIEL: - selectDataModel.setUseData(false); - selectDataModel.setUseReferentiel(true); + selectDataModel.setLoadReferential(true); break; case DATA: - selectDataModel.setUseData(true); - selectDataModel.setUseReferentiel(false); + selectDataModel.setLoadLongline(true); + selectDataModel.setLoadSeine(true); break; case ALL: - selectDataModel.setUseData(true); - selectDataModel.setUseReferentiel(true); + selectDataModel.setLoadReferential(true); + selectDataModel.setLoadLongline(true); + selectDataModel.setLoadSeine(true); break; } //updateModel(); }); - selectTabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, evt -> { - AdminUIModel model1 = (AdminUIModel) evt.getSource(); - if (!model1.containsStep(selectTabUI.getStep())) { - // avoid multi-cast - return; - } - DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); - if (log.isInfoEnabled()) { - log.info("selection model changed to " + value); - } - updateSelectionModel(selectTabUI); - }); - ImmutableSet<ValidatorDto> validators = ObserveSwingApplicationContext.get().getValidators(); ValidateModel stepModel = model.getValidateModel(); @@ -237,11 +223,11 @@ public class ValidateUIHandler extends AdminTabUIHandler { tabUI.typeSelectionModel.clearSelection(); typeModel.clear(); - Set<Class> messageTypes = (Set) tabUI.getStepModel().getMessageTypes(); + Set<Class<? extends IdDto>> messageTypes = tabUI.getStepModel().getMessageTypes(); - List<Class> classes = ObserveI18nDecoratorHelper.sortTypes(messageTypes); + List<Class> classes = ObserveI18nDecoratorHelper.sortTypes((Set) messageTypes); - for (Class<?> e : classes) { + for (Class e : classes) { typeModel.addElement(e); @@ -272,7 +258,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { Class<?> type = (Class<?>) o; List<AbstractReference> refs = tabUI.getStepModel().getMessagesDto(type); - for (AbstractReference ref : Iterables.limit(refs, 100)) { + for (AbstractReference<?> ref : Iterables.limit(refs, 100)) { if (log.isDebugEnabled()) { log.debug("add ref = " + ref); } @@ -310,7 +296,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { log.debug(ref); } - ValidateResultForDto resultForDto = tabUI.getStepModel().getMessages(ref); + ValidateResultForDto<?> resultForDto = tabUI.getStepModel().getMessages(ref); ImmutableSet<ValidationMessage> messages = resultForDto.getMessages(); @@ -400,7 +386,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { ValidateModel stepModel = model.getValidateModel(); stepModel.setMessages(null); - DataSelectionModel dataModel = model.getSelectionDataModel(); + SelectionTreeModel dataModel = model.getSelectionDataModel(); ObserveSwingDataSource dataSourceToValidate = model.getLocalSource(); @@ -412,12 +398,12 @@ public class ValidateUIHandler extends AdminTabUIHandler { Map<Class<? extends IdDto>, ValidateResultForDtoType> messages = Maps.newHashMap(); - if (dataModel.isUseReferentiel()) { + if (dataModel.isLoadReferential()) { // validation des referentiels selectionnes ValidateReferentialsRequest request = new ValidateReferentialsRequest(); - request.setReferentialTypes(ImmutableSet.copyOf(dataModel.getSelectedReferentiel())); + request.setReferentialTypes(dataModel.getSelectedReferentiel()); request.setScopes(ImmutableSet.copyOf(stepModel.getScopes())); request.setValidationContext(stepModel.getContextName()); @@ -491,11 +477,11 @@ public class ValidateUIHandler extends AdminTabUIHandler { builder.append(t("observe.actions.validate.report.entities.with.messages", messages.size())).append('\n'); builder.append(LINE).append('\n').append('\n'); - for (ValidateResultForDtoType validateResultForDtoType : messages.values()) { + for (ValidateResultForDtoType<?> validateResultForDtoType : messages.values()) { - ImmutableSet<ValidateResultForDto> validateResultForHelper = validateResultForDtoType.getValidateResultForDto(); - for (ValidateResultForDto validateResultForDto : validateResultForHelper) { - AbstractReference referenceDto = validateResultForDto.getDto(); + ImmutableSet<? extends ValidateResultForDto<?>> validateResultForHelper = validateResultForDtoType.getValidateResultForDto(); + for (ValidateResultForDto<?> validateResultForDto : validateResultForHelper) { + AbstractReference<?> referenceDto = validateResultForDto.getDto(); String refStr = service.getReferenceDecorator(referenceDto.getType()).toString(referenceDto); @@ -510,7 +496,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { for (ValidationMessage message : messagesByScope) { - builder.append(message.getScope() + " - " + message.getMessage()).append('\n'); + builder.append(message.getScope()).append(" - ").append(message.getMessage()).append('\n'); } @@ -545,13 +531,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { } } - public ComboBoxModel updateComboModel(Object... datas) { - if (datas == null) { - return new DefaultComboBoxModel(); - } - return new DefaultComboBoxModel(datas); - } - public String updateValidatorResumeLabel(boolean valid) { ValidateModel validateModel = getModel().getValidateModel(); @@ -562,10 +541,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { return t("observe.actions.validate.selected.validators", validateModel.getValidators().size()); } - public AdminStep getObjectOperation(JCheckBox checkBox) { - return AdminStep.valueOf(checkBox.getName()); - } - public NuitonValidatorScope getValidatorScope(JCheckBox checkBox) { return (NuitonValidatorScope) checkBox.getClientProperty("value"); } @@ -575,11 +550,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { return scopes.contains(scope); } - public boolean isObjectOperationSelected(Set<AdminStep> objectOperations, JCheckBox checkBox) { -// AdminStep scope = getObjectOperation(checkBox); - return objectOperations.contains(getObjectOperation(checkBox)); - } - public void chooseValidationReportFile(ValidateConfigUI configUI) { File f = UIHelper.chooseDirectory( configUI, diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx index de045dc..e2b53e0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx @@ -40,7 +40,6 @@ fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig fr.ird.observe.application.swing.ui.actions.shared.GoUpUIAction fr.ird.observe.application.swing.ui.actions.shared.GoDownUIAction - fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper fr.ird.observe.services.dto.IdDto @@ -63,8 +62,6 @@ <DataContext id='dataContext' javaBean='ObserveSwingApplicationContext.get().getDataContext()'/> - <ObserveTreeHelper id='treeHelper' initializer='getContextValue(ObserveTreeHelper.class)'/> - <ContentUIModel id='model' genericType='E' initializer='ContentUIModel.newModel((U) this)'/> <ContentUIHandler id='handler' genericType='E, U' initializer='ContentUIHandler.newHandler((U) this)'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java index d5d0443..06eb161 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java @@ -37,9 +37,9 @@ import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferen import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.actions.shared.AbstractUIAction; import fr.ird.observe.application.swing.ui.content.ref.ContentReferenceUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.SpringUtilities; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.DataDto; @@ -85,6 +85,7 @@ import javax.swing.UIManager; import javax.swing.border.TitledBorder; import java.awt.Component; import java.awt.Dimension; +import java.awt.FocusTraversalPolicy; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.util.ArrayList; @@ -137,8 +138,8 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U } - public static ObserveTreeHelper getTreeHelper(JAXXContext context) { - return context.getContextValue(ObserveTreeHelper.class); + public static NavigationTree getTreeHelper(JAXXContext context) { + return ObserveSwingApplicationContext.get().getMainUI().getNavigation(); } /** @@ -303,60 +304,64 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM, evt -> updateUiWithReferenceSetsFromModel()); - ObserveSwingApplicationContext.get().getFocusManager().installFocusTraversalPolicy(ui); + installFocusTraversalPolicy(); // addFocusabelOnForm(); } - protected void addFocusabelOnForm() { - getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_MODE, evt -> updateFocusable((ContentMode) evt.getNewValue())); - updateFocusable(ContentMode.READ); + protected void installFocusTraversalPolicy() { + ObserveSwingApplicationContext.get().getFocusManager().installFocusTraversalPolicy(ui); } - public void updateFocusable(ContentMode newMode) { - if (newMode == null) { - return; - } - switch (newMode) { - case CREATE: - case UPDATE: - ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { - JComponent component = (JComponent) o; - if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { - return; - } - if (component instanceof BeanComboBox) { - BeanComboBox beanComboBox = (BeanComboBox) component; - component = beanComboBox.getCombobox(); - } - Boolean focusable = (Boolean) component.getClientProperty("_focusable"); - component.setFocusable(BooleanUtils.isTrue(focusable)); - - }); - break; - case READ: - - // remove all focusables - ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { - JComponent component = (JComponent) o; - if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { - return; - } - if (component instanceof BeanComboBox) { - BeanComboBox beanComboBox = (BeanComboBox) component; - component = beanComboBox.getCombobox(); - } - boolean focusable = component.isFocusable(); - if (focusable) { - component.putClientProperty("_focusable", true); - component.setFocusable(false); - } - - }); - break; - } - } +// protected void addFocusabelOnForm() { +// getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_MODE, evt -> updateFocusable((ContentMode) evt.getNewValue())); +// updateFocusable(ContentMode.READ); +// } + +// public void updateFocusable(ContentMode newMode) { +// if (newMode == null) { +// return; +// } +// switch (newMode) { +// case CREATE: +// case UPDATE: +// ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { +// JComponent component = (JComponent) o; +// if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { +// return; +// } +// if (component instanceof BeanComboBox) { +// BeanComboBox beanComboBox = (BeanComboBox) component; +// component = beanComboBox.getCombobox(); +// } +// Boolean focusable = (Boolean) component.getClientProperty("_focusable"); +// component.setFocusable(BooleanUtils.isTrue(focusable)); +// +// }); +// break; +// case READ: +// +// // remove all focusables +// ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { +// JComponent component = (JComponent) o; +// if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { +// return; +// } +// if (component instanceof BeanComboBox) { +// BeanComboBox beanComboBox = (BeanComboBox) component; +// component = beanComboBox.getCombobox(); +// } +// boolean focusable = component.isFocusable(); +// if (focusable) { +// component.putClientProperty("_focusable", true); +// component.setFocusable(false); +// } +// +// }); +// break; +// } +// } public void openUI() { @@ -375,21 +380,25 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U } // suppression des messages de validation removeAllMessages(ui); - ObserveTreeHelper treeHelper = getTreeHelper(ui); - AbstractObserveTreeCellRenderer render = treeHelper.getTreeCellRenderer(); - ObserveNode node = treeHelper.getSelectedNode(); + NavigationTree tree = getTreeHelper(ui); + NavigationTreeCellRenderer render = tree.getNavigationCellRenderer(); + + NavigationTreeNodeSupport node = tree.getSelectedNode(); if (ContentReferenceUIHandler.class.isAssignableFrom(getClass())) { node = node.getParent(); } - ui.setContentIcon(render.getNavigationIcon(node)); + ui.setContentIcon(node.getIcon("")); updateActions(); - JComponent firstComponent = (JComponent) ui.getFocusTraversalPolicy().getFirstComponent(ui); - if (log.isInfoEnabled()) { - log.info("Grab focus on first component: " + firstComponent); + FocusTraversalPolicy focusTraversalPolicy = ui.getFocusTraversalPolicy(); + if (focusTraversalPolicy != null) { + JComponent firstComponent = (JComponent) focusTraversalPolicy.getFirstComponent(ui); + if (log.isInfoEnabled()) { + log.info("Grab focus on first component: " + firstComponent); + } + firstComponent.grabFocus(); } - firstComponent.grabFocus(); } public Icon getErrorIconIfFalse(boolean valid) { @@ -477,13 +486,11 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U // on ne peut redemarrer une edition que si la donnee // est exactement une entites (pas possible sur une liste) - ObserveTreeHelper treeHelper = getTreeHelper(ui); -// ObserveNode node = treeHelper.getSelectedNode(); + NavigationTree tree = getTreeHelper(ui); removeAllMessages(ui); -// treeHelper.refreshNode(node, true); - treeHelper.reloadSelectedNode(false, true); + tree.reloadSelectedNode(false, true); model.setMode(ContentMode.UPDATE); @@ -541,10 +548,10 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U // rien a faire return; } - ObserveTreeHelper treeHelper = getTreeHelper(ui); - ObserveNode parentNode = treeHelper.getSelectedNode(); + NavigationTree treeHelper = getTreeHelper(ui); + NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode(); String id = entity.getId(); - ObserveNode node = treeHelper.findNode(parentNode, id); + NavigationTreeNodeSupport node = treeHelper.getChild(parentNode, id); if (log.isInfoEnabled()) { log.info("will go to node " + node + " for " + id); } @@ -552,8 +559,8 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U } public void addChild(Class<?> type) { - ObserveTreeHelper treeHelper = getTreeHelper(ui); - ObserveNode parentNode = treeHelper.getSelectedNode(); + NavigationTree treeHelper = getTreeHelper(ui); + NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode(); treeHelper.addUnsavedNode(parentNode, type); } @@ -709,10 +716,10 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U boolean create = model.isCreatingMode(); if (create && model.isEditable()) { // remove node - ObserveTreeHelper treehelper = getTreeHelper(ui); - ObserveNode node = treehelper.getSelectedNode(); + NavigationTree treehelper = getTreeHelper(ui); + NavigationTreeNodeSupport node = treehelper.getSelectedNode(); - ObserveNode parentNode = node.getParent(); + NavigationTreeNodeSupport parentNode = node.getParent(); if (parentNode != null) { // node still attached, so remove it treehelper.removeNode(node); @@ -738,9 +745,9 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U removeAllMessages(ui); if (!(getBean() instanceof ReferentialDto)) { - ObserveTreeHelper treeHelper = getTreeHelper(ui); - ObserveNode node = treeHelper.getSelectedNode(); - ObserveNode parentNode = treeHelper.removeNode(node); + NavigationTree treeHelper = getTreeHelper(ui); + NavigationTreeNodeSupport node = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport parentNode = treeHelper.removeNode(node); treeHelper.selectNode(parentNode); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java index 0182303..7e6ac25 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java @@ -21,79 +21,14 @@ */ package fr.ird.observe.application.swing.ui.content; -import com.google.common.collect.ImmutableSet; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveSwingSessionHelper; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.UIHelper; -import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineDetailCompositionUI; -import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineGlobalCompositionUI; -import fr.ird.observe.application.swing.ui.content.impl.longline.SetLonglineUI; -import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectTransmittingBuoyOperationUI; -import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectUI; -import fr.ird.observe.application.swing.ui.content.impl.seine.SetSeineUI; -import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI; -import fr.ird.observe.application.swing.ui.content.open.impl.longline.ActivityLonglineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.longline.TripLonglineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.ActivitySeineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.RouteUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.TripSeineUI; -import fr.ird.observe.application.swing.ui.content.ref.ContentReferenceUI; -import fr.ird.observe.application.swing.ui.content.ref.ReferenceHomeUI; -import fr.ird.observe.application.swing.ui.content.table.impl.longline.CatchLonglineUI; -import fr.ird.observe.application.swing.ui.content.table.impl.longline.EncounterUI; -import fr.ird.observe.application.swing.ui.content.table.impl.longline.GearUseFeaturesLonglineUI; -import fr.ird.observe.application.swing.ui.content.table.impl.longline.SensorUsedUI; -import fr.ird.observe.application.swing.ui.content.table.impl.longline.TdrUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.GearUseFeaturesSeineUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.NonTargetCatchUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.NonTargetSampleUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.ObjectObservedSpeciesUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.ObjectSchoolEstimateUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.SchoolEstimateUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetCatchUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetDiscardCatchUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetSampleCaptureUI; -import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetSampleRejeteUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.CatchLonglineDto; -import fr.ird.observe.services.dto.longline.EncounterDto; -import fr.ird.observe.services.dto.longline.GearUseFeaturesLonglineDto; -import fr.ird.observe.services.dto.longline.SensorUsedDto; -import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; -import fr.ird.observe.services.dto.longline.SetLonglineDto; -import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionDto; -import fr.ird.observe.services.dto.longline.TdrDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.dto.referential.ReferentialHelper; -import fr.ird.observe.services.dto.referential.seine.ObjectOperationDto; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.DiscardedTargetCatchDto; -import fr.ird.observe.services.dto.seine.DiscardedTargetSampleDto; -import fr.ird.observe.services.dto.seine.FloatingObjectDto; -import fr.ird.observe.services.dto.seine.GearUseFeaturesSeineDto; -import fr.ird.observe.services.dto.seine.KeptTargetCatchDto; -import fr.ird.observe.services.dto.seine.KeptTargetSampleDto; -import fr.ird.observe.services.dto.seine.NonTargetCatchDto; -import fr.ird.observe.services.dto.seine.NonTargetSampleDto; -import fr.ird.observe.services.dto.seine.ObjectObservedSpeciesDto; -import fr.ird.observe.services.dto.seine.ObjectSchoolEstimateDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.SchoolEstimateDto; -import fr.ird.observe.services.dto.seine.SetSeineDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.CardLayout2; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -105,10 +40,6 @@ import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.reflect.Constructor; -import java.util.Map; -import java.util.TreeMap; - -import static org.nuiton.i18n.I18n.n; /** * Manager des ecrans d'editions @@ -118,120 +49,11 @@ import static org.nuiton.i18n.I18n.n; */ public class ContentUIManager { - private static final String REFERENCE = "reference"; - - public static final String DATA = "data"; - /** Logger */ - static private final Log log = LogFactory.getLog(ContentUIManager.class); - - private final Map<String, Class<? extends ContentUI<?, ?>>> mapping; - - public ContentUIManager() { - - mapping = new TreeMap<>(); - - // --- Seine data --- // - addMapping(DATA, ProgramDto.class, GearType.seine.name(), TripSeinesUI.class); - - addMapping(DATA, TripSeineDto.class, null, TripSeineUI.class); - addMapping(DATA, TripSeineDto.class, n("observe.type.tripSeine.unsaved"), TripSeineUI.class); - addMapping(DATA, TripSeineDto.class, GearUseFeaturesSeineDto.class, GearUseFeaturesSeineUI.class); - addMapping(DATA, TripSeineDto.class, RouteDto.class, RoutesUI.class); - - addMapping(DATA, RouteDto.class, null, RouteUI.class); - addMapping(DATA, RouteDto.class, n("observe.type.route.unsaved"), RouteUI.class); - addMapping(DATA, RouteDto.class, ActivitySeineDto.class, ActivitySeinesUI.class); - - addMapping(DATA, ActivitySeineDto.class, null, ActivitySeineUI.class); - addMapping(DATA, ActivitySeineDto.class, n("observe.type.activitySeine.unsaved"), ActivitySeineUI.class); - - addMapping(DATA, SetSeineDto.class, null, SetSeineUI.class); - addMapping(DATA, SetSeineDto.class, n("observe.type.setSeine.unsaved"), SetSeineUI.class); - addMapping(DATA, SetSeineDto.class, SchoolEstimateDto.class, SchoolEstimateUI.class); - addMapping(DATA, SetSeineDto.class, KeptTargetCatchDto.class, TargetCatchUI.class); - addMapping(DATA, SetSeineDto.class, DiscardedTargetCatchDto.class, TargetDiscardCatchUI.class); - addMapping(DATA, SetSeineDto.class, NonTargetCatchDto.class, NonTargetCatchUI.class); - - addMapping(DATA, SetSeineDto.class, KeptTargetSampleDto.class, TargetSampleCaptureUI.class); - addMapping(DATA, SetSeineDto.class, DiscardedTargetSampleDto.class, TargetSampleRejeteUI.class); - addMapping(DATA, SetSeineDto.class, NonTargetSampleDto.class, NonTargetSampleUI.class); - - addMapping(DATA, FloatingObjectDto.class, null, FloatingObjectUI.class); - addMapping(DATA, FloatingObjectDto.class, n("observe.type.floatingObject.unsaved"), FloatingObjectUI.class); - addMapping(DATA, FloatingObjectDto.class, ObjectOperationDto.class, FloatingObjectTransmittingBuoyOperationUI.class); - addMapping(DATA, FloatingObjectDto.class, ObjectObservedSpeciesDto.class, ObjectObservedSpeciesUI.class); - addMapping(DATA, FloatingObjectDto.class, ObjectSchoolEstimateDto.class, ObjectSchoolEstimateUI.class); - - // --- Longline data --- // - - addMapping(DATA, ProgramDto.class, GearType.longline.name(), TripLonglinesUI.class); - - addMapping(DATA, TripLonglineDto.class, null, TripLonglineUI.class); - addMapping(DATA, TripLonglineDto.class, n("observe.type.tripLongline.unsaved"), TripLonglineUI.class); - addMapping(DATA, TripLonglineDto.class, GearUseFeaturesLonglineDto.class, GearUseFeaturesLonglineUI.class); - addMapping(DATA, TripLonglineDto.class, ActivityLonglineDto.class, ActivityLonglinesUI.class); - - addMapping(DATA, ActivityLonglineDto.class, null, ActivityLonglineUI.class); - addMapping(DATA, ActivityLonglineDto.class, n("observe.type.activityLongline.unsaved"), ActivityLonglineUI.class); - addMapping(DATA, ActivityLonglineDto.class, EncounterDto.class, EncounterUI.class); - addMapping(DATA, ActivityLonglineDto.class, SensorUsedDto.class, SensorUsedUI.class); - - addMapping(DATA, SetLonglineDto.class, null, SetLonglineUI.class); - addMapping(DATA, SetLonglineDto.class, n("observe.type.setLongline.unsaved"), SetLonglineUI.class); - addMapping(DATA, SetLonglineDto.class, SetLonglineGlobalCompositionDto.class, LonglineGlobalCompositionUI.class); - addMapping(DATA, SetLonglineDto.class, SetLonglineDetailCompositionDto.class, LonglineDetailCompositionUI.class); - - addMapping(DATA, SetLonglineDto.class, CatchLonglineDto.class, CatchLonglineUI.class); - addMapping(DATA, SetLonglineDto.class, TdrDto.class, TdrUI.class); - - // --- Referential --- // - - loadReferentialsMapping(ReferentialHelper.REFERENCE_COMMON_DTOS, "impl"); - loadReferentialsMapping(ReferentialHelper.REFERENCE_SEINE_DTOS, "impl.seine"); - loadReferentialsMapping(ReferentialHelper.REFERENCE_LONGLINE_DTOS, "impl.longline"); - - addMapping(REFERENCE, null, null, ReferenceHomeUI.class); - - } - - public Class<? extends ContentUI<?, ?>> convertNodeToContentUI(ObserveNode node) { - if (log.isDebugEnabled()) { - log.debug("Entrer for node = " + node); - } - if (node.isRoot()) { - return null; - } - - Class<?> editType = node.getInternalClass(); - String prefix = node.isReferentielNode() ? REFERENCE : DATA; - String context = node.getContext(); - - String mappingKey; - - if (node.isReferentielNode()) { - - if (String.class.equals(editType)) { - editType = null; - } - - } else { - - // noeud de donnee - if (String.class.equals(editType)) { - editType = node.getContainerNode().getInternalClass(); - } - } - - mappingKey = getMappingKey(prefix, editType, context); - if (mappingKey == null) { - throw new NullPointerException("Could not find mappingKey for node " + node); - } - if (log.isDebugEnabled()) { - log.debug("mappingKey = [" + mappingKey + "] for node " + node); - } + private static final Log log = LogFactory.getLog(ContentUIManager.class); - return mapping.get(mappingKey); + public Class<? extends ContentUI<?, ?>> convertNodeToContentUI(NavigationTreeNodeSupport<?> node) { + return node.getContentClass(); } public <U extends ContentUI<?, ?>> U getContent(Class<U> uiClass) { @@ -383,21 +205,6 @@ public class ContentUIManager { close(); } - private void loadReferentialsMapping(ImmutableSet<Class<? extends ReferentialDto>> types, String packagePrefix) { - for (Class<? extends ReferentialDto> editType : types) { - String simpleName = StringUtils.removeEnd(editType.getSimpleName(), "Dto"); - String fqn = ContentReferenceUI.class.getPackage().getName() + "." + packagePrefix + "." + simpleName + "UI"; - Class<?> result; - try { - result = Class.forName(fqn); - addMapping(REFERENCE, null, editType, result); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Could not find " + fqn); - } - } - - } - private JPanel getLayoutContent() { return getMainUI().getContent(); } @@ -428,27 +235,4 @@ public class ContentUIManager { return result; } - private void addMapping(String prefix, Class<?> klass, Object context, Class<?> contentClass) { - - String contextValue = context instanceof Class ? ((Class) context).getName() : (context == null ? null : context.toString()); - String key = getMappingKey(prefix, klass, contextValue); - if (log.isDebugEnabled()) { - log.debug("Add key: " + key + " → " + contentClass.getName()); - } - mapping.put(key, (Class) contentClass); - } - - private String getMappingKey(String prefix, Class<?> klass, String context) { - String key = prefix + "."; - if (klass != null) { - key += klass.getName(); - } - if (context != null) { - if (klass != null) { - key += "#"; - } - key += context; - } - return key; - } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java index c5c28fe..e138b52 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java @@ -1,7 +1,9 @@ package fr.ird.observe.application.swing.ui.content; import com.google.common.collect.ImmutableMap; +import fr.ird.observe.application.swing.ui.content.impl.longline.BranchlineUI; import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineDetailCompositionUI; +import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineGlobalCompositionUI; import fr.ird.observe.application.swing.ui.content.impl.longline.SetLonglineUI; import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectTransmittingBuoyOperationUI; import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectUI; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/BranchlineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/BranchlineUIHandler.java index 56cab3e..1f2f747 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/BranchlineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/BranchlineUIHandler.java @@ -74,6 +74,11 @@ public class BranchlineUIHandler extends ContentUIHandler<BranchlineDto, Branchl }; } + @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + public void edit(BranchlineDto branchline) { if (log.isInfoEnabled()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index a9d5ded..f2abcad 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -24,14 +24,8 @@ package fr.ird.observe.application.swing.ui.content.impl.longline; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.db.DataContext; -import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.Form; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionDto; -import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionHelper; -import fr.ird.observe.services.dto.result.SaveResultDto; -import fr.ird.observe.services.service.data.longline.SetLonglineGlobalCompositionService; +import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; import fr.ird.observe.application.swing.ui.content.table.impl.longline.BaitsCompositionUI; @@ -42,6 +36,12 @@ import fr.ird.observe.application.swing.ui.content.table.impl.longline.Floatline import fr.ird.observe.application.swing.ui.content.table.impl.longline.FloatlinesCompositionUIModel; import fr.ird.observe.application.swing.ui.content.table.impl.longline.HooksCompositionUI; import fr.ird.observe.application.swing.ui.content.table.impl.longline.HooksCompositionUIModel; +import fr.ird.observe.services.dto.Form; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionDto; +import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionHelper; +import fr.ird.observe.services.dto.result.SaveResultDto; +import fr.ird.observe.services.service.data.longline.SetLonglineGlobalCompositionService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; @@ -64,6 +64,11 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong } @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + + @Override protected boolean computeCanWrite(ObserveSwingDataSource source) { return source.canWriteData(); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/SetLonglineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/SetLonglineUIHandler.java index fab54cd..3ecf77c 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/SetLonglineUIHandler.java @@ -29,8 +29,8 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; import fr.ird.observe.application.swing.ui.content.ContentUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.Form; @@ -353,9 +353,9 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLonglineDto, SetLo SwingValidatorUtil.setValidatorChanged(getUi(), false); - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); - ObserveNode node = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport node = treeHelper.getSelectedNode(); boolean create = node.getId() == null; if (create) { @@ -363,7 +363,7 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLonglineDto, SetLo getModel().setMode(ContentMode.UPDATE); // remove old node and recreate new node - ObserveNode parentNode = treeHelper.removeNode(node); + NavigationTreeNodeSupport parentNode = treeHelper.removeNode(node); DataReference<SetLonglineDto> beanRef = ObserveSwingApplicationContext.get().getReferenceBinderEngine().transformDataDtoToReference(getDecoratorService().getReferentialLocale(), bean); node = treeHelper.addSetLongline(parentNode, beanRef); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/FloatingObjectUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/FloatingObjectUIHandler.java index e4335b9..5aea97e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -28,8 +28,8 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; import fr.ird.observe.application.swing.ui.content.ContentUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.result.SaveResultDto; @@ -172,9 +172,9 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, super.afterSave(refresh); FloatingObjectDto bean = getBean(); - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); - ObserveNode node = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport node = treeHelper.getSelectedNode(); boolean create = node.getId() == null; if (create) { @@ -182,7 +182,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, getModel().setMode(ContentMode.UPDATE); // remove old node and recreate new node - ObserveNode parentNode = treeHelper.removeNode(node); + NavigationTreeNodeSupport parentNode = treeHelper.removeNode(node); DataReference<FloatingObjectDto> beanRef = ObserveSwingApplicationContext.get().getReferenceBinderEngine().transformDataDtoToReference(getDecoratorService().getReferentialLocale(), bean); node = treeHelper.addFloatingObject(parentNode, beanRef); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/SetSeineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/SetSeineUIHandler.java index ec01a12..8f9de9b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/SetSeineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/seine/SetSeineUIHandler.java @@ -29,8 +29,8 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; import fr.ird.observe.application.swing.ui.content.ContentUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.constants.seine.SchoolType; @@ -253,16 +253,16 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeineDto, SetSeineUI> SwingValidatorUtil.setValidatorChanged(getUi(), false); - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); - ObserveNode node = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport node = treeHelper.getSelectedNode(); boolean create = node.getId() == null; if (create) { getModel().setMode(ContentMode.UPDATE); // remove old node and recreate new node - ObserveNode parentNode = treeHelper.removeNode(node); + NavigationTreeNodeSupport parentNode = treeHelper.removeNode(node); DataReference<SetSeineDto> beanRef = ObserveSwingApplicationContext.get().getReferenceBinderEngine().transformDataDtoToReference(getDecoratorService().getReferentialLocale(), bean); node = treeHelper.addSetSeine(parentNode, beanRef); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java index 915a071..31a28c8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java @@ -26,9 +26,9 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.actions.shared.SelectNodeUIAction; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeCellRenderer; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.AbstractReference; import fr.ird.observe.services.dto.DataDto; import fr.ird.observe.services.dto.DataReference; @@ -94,17 +94,17 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U // on installe un renderer sur la liste pour afficher les couleurs + // icones comme dans l'arbre ListCellRenderer renderer = getUi().getList().getCellRenderer(); - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); ListCellRenderer renderer2 = new EntityListCellRenderer(renderer, treeHelper); getUi().getList().setCellRenderer(renderer2); } - @Override - protected void addFocusabelOnForm() { - // pas besoin de gérer le focus, pas de formulaire - } +// @Override +// protected void addFocusabelOnForm() { +// // pas besoin de gérer le focus, pas de formulaire +// } @Override public final void openUI() { @@ -190,14 +190,14 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U gotoChild(selectedData); return; } - ObserveNode node = null; + NavigationTreeNodeSupport node = null; if (selectedData != null) { // obtain the node corresponding to the selected data String id = selectedData.getId(); - ObserveTreeHelper helper = getTreeHelper(getUi()); - ObserveNode selectedNode = helper.getSelectedNode(); - node = helper.findNode(selectedNode, id); + NavigationTree helper = getTreeHelper(getUi()); + NavigationTreeNodeSupport selectedNode = helper.getSelectedNode(); + node = helper.getChild(selectedNode, id); } // attach the node to action @@ -231,17 +231,16 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U private final transient ListCellRenderer delegate; - private final transient ObserveTreeHelper treeHelper; + private final transient NavigationTree treeHelper; - private final AbstractObserveTreeCellRenderer treeRenderer; + private final NavigationTreeCellRenderer treeRenderer; - private ThreadLocal<ObserveNode> containerNode = new ThreadLocal<>(); + private final ThreadLocal<NavigationTreeNodeSupport> containerNode = new ThreadLocal<>(); - EntityListCellRenderer(ListCellRenderer delegate, - ObserveTreeHelper treeHelper) { + EntityListCellRenderer(ListCellRenderer delegate, NavigationTree treeHelper) { this.delegate = delegate; this.treeHelper = treeHelper; - this.treeRenderer = treeHelper.getTreeCellRenderer(); + this.treeRenderer = treeHelper.getNavigationCellRenderer(); } public void init() { @@ -264,17 +263,14 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U cellHasFocus ); - if (value == null || - !(value instanceof AbstractReference) || - containerNode.get() == null) { + if (value == null || !(value instanceof AbstractReference) || containerNode.get() == null) { // rien de plus a faire return comp; } // recuperation du noeud correspondant dans l'arbre - ObserveNode node = - treeHelper.findNode(containerNode.get(), ((AbstractReference) value).getId()); + NavigationTreeNodeSupport node = treeHelper.getChild(containerNode.get(), ((AbstractReference) value).getId()); if (node == null) { @@ -282,9 +278,9 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U return comp; } - Icon icon = treeRenderer.getNavigationIcon(node); + Icon icon = node.getIcon(""); comp.setIcon(icon); - Color color = treeRenderer.getNavigationTextColor(node); + Color color = node.getColor(); comp.setForeground(color); comp.setBackground(null); return comp; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java index bb95dae..8b4081d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java @@ -27,10 +27,10 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ProgramLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.ProgramSeineNavigationTreeNode; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.longline.TripLonglineDto; @@ -98,7 +98,7 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten updateUiWithReferenceSetsFromModel(); // on repaint le parent (le program devient alors ouvert) - ObserveTreeHelper treeHelper = getTreeHelper(ui); + NavigationTree treeHelper = getTreeHelper(ui); treeHelper.reloadSelectedNode(true, true); // ObserveNode node = treeHelper.getSelectedNode(); // treeHelper.refreshNode(node.getParent(), true); @@ -142,7 +142,7 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten addMessage(ui, NuitonValidatorScope.INFO, getTypeI18nKey(bean.getClass()), t(closeMessage)); - ObserveTreeHelper treeHelper = getTreeHelper(ui); + NavigationTree treeHelper = getTreeHelper(ui); treeHelper.reloadSelectedNode(bean instanceof TripSeineDto || bean instanceof TripLonglineDto, true); updateActions(); } @@ -155,10 +155,10 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten U ui = getUi(); int position = ui.getContextValue(Integer.class, POSITION_OPENABLE); - ObserveTreeHelper treeHelper = getTreeHelper(ui); + NavigationTree treeHelper = getTreeHelper(ui); - ObserveNode node = treeHelper.getSelectedNode(); - ObserveNode parentNode = node.getParent(); + NavigationTreeNodeSupport node = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport parentNode = node.getParent(); boolean create = node.getId() == null; E bean = getBean(); @@ -233,11 +233,11 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten // création d'une nouvelle donnée - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); treeHelper.reloadSelectedNode(false, true); - ObserveNode parentNode = treeHelper.getSelectedNode().getParent(); + NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode().getParent(); if (log.isDebugEnabled()) { log.debug("PARENT NODE = " + parentNode); } @@ -308,9 +308,9 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten return; } - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); - ObserveNode tripNode = treeHelper.getSelectedNode(); - while (!(tripNode instanceof ProgramSeineNode || tripNode instanceof ProgramLonglineNode)) { + NavigationTree treeHelper = getTreeHelper(getUi()); + NavigationTreeNodeSupport tripNode = treeHelper.getSelectedNode(); + while (!(tripNode instanceof ProgramSeineNavigationTreeNode || tripNode instanceof ProgramLonglineNavigationTreeNode)) { tripNode = tripNode.getParent(); } if (log.isInfoEnabled()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index 23fb43f..597d966 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -28,7 +28,7 @@ import fr.ird.observe.application.swing.db.constants.DataContextType; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIModel; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUIHandler; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivityLonglineNodeChildLoador; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ActivityLonglineNavigationTreeNode; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; @@ -259,7 +259,7 @@ class ActivityLonglineUIHandler extends ContentOpenableUIHandler<ActivityLonglin // ouverture de l'activité après création getOpenDataManager().openActivityLongline(getSelectedParentId(), bean.getId()); - if (ActivityLonglineNodeChildLoador.FISHING_OPERATION_ID.equals(bean.getVesselActivityLongline().getId())) { + if (ActivityLonglineNavigationTreeNode.FISHING_OPERATION_ID.equals(bean.getVesselActivityLongline().getId())) { // création de l'opération de pêche SwingUtilities.invokeLater(() -> getUi().getAddSet().doClick()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 381b4aa..de962a5 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -31,6 +31,7 @@ import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.dto.referential.seine.VesselActivitySeineDto; +import fr.ird.observe.services.dto.referential.seine.VesselActivitySeineHelper; import fr.ird.observe.services.dto.result.SaveResultDto; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.dto.seine.ActivitySeineHelper; @@ -338,8 +339,7 @@ class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySeineDto, Set<ReferentialReference<VesselActivitySeineDto>> activities = getDataSource().getReferentialReferences(VesselActivitySeineDto.class); for (ReferentialReference<VesselActivitySeineDto> vesselActivity : activities) { - //FIXME Il serait mieux d'utiliser le topiaId - if (ActivitySeineDto.ACTIVITY_FIN_DE_PECHE.equals(vesselActivity.getPropertyValue(VesselActivitySeineDto.PROPERTY_CODE))) { + if (VesselActivitySeineHelper.isActivityPeche(vesselActivity)) { return getDecoratorService().getReferentialReferenceDecorator(VesselActivitySeineDto.class).toString(vesselActivity); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/RouteUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/RouteUIHandler.java index 6196f15..63b902b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/RouteUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/seine/RouteUIHandler.java @@ -28,11 +28,12 @@ import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.dto.referential.seine.VesselActivitySeineDto; +import fr.ird.observe.services.dto.referential.seine.VesselActivitySeineHelper; import fr.ird.observe.services.dto.result.TripChildSaveResultDto; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.dto.seine.RouteDto; @@ -281,8 +282,8 @@ class RouteUIHandler extends ContentOpenableUIHandler<RouteDto, RouteUI> { boolean closeActivityFinDeVeille = false; boolean gotoActivityFinDeVeille = false; - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); - ObserveNode routeNode = treeHelper.getSelectedNode(); + NavigationTree treeHelper = getTreeHelper(getUi()); + NavigationTreeNodeSupport routeNode = treeHelper.getSelectedNode(); if (mustAddFinVeille) { @@ -361,11 +362,11 @@ class RouteUIHandler extends ContentOpenableUIHandler<RouteDto, RouteUI> { private ActivitySeineUI addActivityFinDeVeille(boolean close) { - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); // on créee l'activity de fin de veille - ObserveNode parentNode = treeHelper.getSelectedNode(); - parentNode = treeHelper.findNode(parentNode, ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class)); + NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode(); + parentNode = treeHelper.getChild(parentNode, ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class)); if (log.isDebugEnabled()) { log.debug("PARENT NODE = " + parentNode); } @@ -379,7 +380,7 @@ class RouteUIHandler extends ContentOpenableUIHandler<RouteDto, RouteUI> { for (ReferentialReference<VesselActivitySeineDto> refVesselActivity : selectedUI.getVesselActivitySeine().getData()) { - if (ActivitySeineDto.ACTIVITY_FIN_DE_VEILLE.equals(refVesselActivity.getPropertyValue(VesselActivitySeineDto.PROPERTY_CODE))) { + if (VesselActivitySeineHelper.isActivityFinDeVeille(refVesselActivity)) { vesselActivitySeine = refVesselActivity; break; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java index c0b7fa5..1e713aa 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java @@ -30,7 +30,7 @@ import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferen import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; import fr.ird.observe.application.swing.ui.usage.UsagesUI; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.Form; @@ -637,7 +637,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte if (bean instanceof ProgramDto) { // add the program in tree - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); ReferentialReference<ProgramDto> reference = ObserveSwingApplicationContext.get().getReferenceBinderEngine().transformReferentialDtoToReference(getDecoratorService().getReferentialLocale(), (ProgramDto) bean); treeHelper.addProgram(reference); @@ -712,7 +712,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte if (bean instanceof ProgramDto) { // update the program in tree - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); treeHelper.updateProgram((ProgramDto) bean); } @@ -795,7 +795,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte if (bean instanceof ProgramDto) { // remove the program in tree - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + NavigationTree treeHelper = getTreeHelper(getUi()); treeHelper.removeProgram(bean.getId()); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/ContentTableUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/ContentTableUIHandler.java index 097684e..71d9bbb 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/ContentTableUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/ContentTableUIHandler.java @@ -30,7 +30,7 @@ import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; import fr.ird.observe.application.swing.ui.content.ContentUIModel; import fr.ird.observe.application.swing.ui.content.table.impl.longline.WeightMeasuresTableModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.table.EditableTableModelSupport; import fr.ird.observe.application.swing.ui.util.table.InlineTableAutotSelectRowAndShowPopupAction; import fr.ird.observe.services.dto.IdDto; @@ -219,10 +219,8 @@ public abstract class ContentTableUIHandler<E extends IdDto, D extends IdDto, U uiInitializer.initUI(); getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM, evt -> updateUiWithReferenceSetsFromModel()); - getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_MODE, evt -> updateFocusable((ContentMode) evt.getNewValue())); - updateFocusable(ContentMode.READ); - ObserveSwingApplicationContext.get().getFocusManager().installFocusTraversalPolicy(ui); + installFocusTraversalPolicy(); } @@ -284,9 +282,8 @@ public abstract class ContentTableUIHandler<E extends IdDto, D extends IdDto, U protected void addUpdateInfoMessage() { String message = n("observe.entity.message.updating"); - ObserveNode node = getTreeHelper(getUi()).getSelectedNode(); - String entityLabel = - getTypeI18nKey(node.getParent().getInternalClass()); + NavigationTreeNodeSupport node = getTreeHelper(getUi()).getSelectedNode(); + String entityLabel = getTypeI18nKey(node.getParent().getDataType()); message = t(message, t(entityLabel)); addMessage(getUi(), NuitonValidatorScope.INFO, entityLabel, message); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index 644a4d1..3f152b8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -53,6 +53,11 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + + @Override protected void onSelectedRowChanged(int editingRow, BaitsCompositionDto bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index 852d0a1..2dec127 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -53,6 +53,11 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + + @Override protected void onSelectedRowChanged(int editingRow, BranchlinesCompositionDto bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 3146d7a..58ddda8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -33,9 +33,9 @@ import fr.ird.observe.application.swing.ui.content.ContentUIInitializer; import fr.ird.observe.application.swing.ui.content.ContentUIModel; import fr.ird.observe.application.swing.ui.content.table.ContentTableModel; import fr.ird.observe.application.swing.ui.content.table.ContentTableUIHandler; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.TripLonglineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.table.AutotSelectRowAndShowPopupActionSupport; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.Form; @@ -146,6 +146,8 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat CatchLonglineContentTableUIInitializer uiInitializer = new CatchLonglineContentTableUIInitializer(getUi()); uiInitializer.initUI(); + installFocusTraversalPolicy(); + getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, evt -> { Boolean newValue = (Boolean) evt.getNewValue(); showIndividualTabs(newValue); @@ -417,15 +419,12 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat // go back to first pane ui.getFishingOperationTabPane().setSelectedIndex(0); - // select by default individual acquisition mode -// String openTripLonglineId = getDataContext().getOpenTripLonglineId(); - - ObserveTreeHelper treeHelper = ObserveSwingApplicationContext.get().getMainUI().getTreeHelper(); - ObserveNode selectedNode = treeHelper.getSelectedNode(); - while (!(selectedNode instanceof TripLonglineNode)) { + NavigationTree treeHelper = getTreeHelper(ui); + NavigationTreeNodeSupport selectedNode = treeHelper.getSelectedNode(); + while (!(selectedNode instanceof TripLonglineNavigationTreeNode)) { selectedNode = selectedNode.getParent(); } - DataReference<TripLonglineDto> tripReference = ((TripLonglineNode) selectedNode).getEntity(); + DataReference<TripLonglineDto> tripReference = ((TripLonglineNavigationTreeNode) selectedNode).getData(); String tripTypeId = (String) tripReference.getPropertyValue(TripLonglineDto.PROPERTY_TRIP_TYPE + "Id"); if (log.isInfoEnabled()) { log.info("Use tripId: " + tripTypeId); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index 56b3624..beed1eb 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -52,6 +52,11 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + + @Override protected void onSelectedRowChanged(int editingRow, FloatlinesCompositionDto bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 266d1e8..4c942b7 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -55,6 +55,11 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void installFocusTraversalPolicy() { + // rien a installer + } + + @Override protected void onSelectedRowChanged(int editingRow, HooksCompositionDto bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/ObstunaAdminAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/ObstunaAdminAction.java index 78262ba..801e903 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/ObstunaAdminAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/ObstunaAdminAction.java @@ -27,11 +27,11 @@ import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.configuration.constants.DbMode; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; +import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; -import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.ObserveDbUserDto; @@ -103,18 +103,7 @@ public enum ObstunaAdminAction { protected void initTask(StorageUIModel model) throws Exception { - if (DbMode.USE_REMOTE.equals(model.getDbMode())) { - ObserveDataSourceConfigurationTopiaPG pgConfig = model.getPgConfig(); - - // pas autorise a migrer automatiquement - pgConfig.setCanMigrate(false); - - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(pgConfig); - } else { - ObserveDataSourceConfigurationRest restConfig = model.getRestConfig(); - - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(restConfig); - } + dataSource = ObstunaAdminAction.getDataSource(model); createConfigurationDto = model.toImportReferentielSourceConfig(); @@ -143,7 +132,7 @@ public enum ObstunaAdminAction { checkImportDbVersion(model, importDataConfig.getConfiguration()); - DataSelectionModel dataModel = model.getSelectDataModel(); + SelectionTreeModel dataModel = model.getSelectDataModel(); ImmutableSet<String> importDataIds = ImmutableSet.copyOf( dataModel.getSelectedData() @@ -268,22 +257,8 @@ public enum ObstunaAdminAction { @Override protected void initTask(StorageUIModel model) throws Exception { - - if (DbMode.USE_REMOTE.equals(model.getDbMode())) { - ObserveDataSourceConfigurationTopiaPG pgConfig = model.getPgConfig(); - - // pas autorise a migrer automatiquement - pgConfig.setCanMigrate(false); - - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(pgConfig); - } else { - ObserveDataSourceConfigurationRest restConfig = model.getRestConfig(); - - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(restConfig); - } - + dataSource = ObstunaAdminAction.getDataSource(model); users = model.getSecurityModel().getUsers(); - } @Override @@ -320,4 +295,22 @@ public enum ObstunaAdminAction { public String toString() { return I18nEnumHelper.getLabel(this); } + + private static ObserveSwingDataSource getDataSource(StorageUIModel model) { + ObserveSwingDataSource dataSource; + + if (DbMode.USE_REMOTE.equals(model.getDbMode())) { + ObserveDataSourceConfigurationTopiaPG pgConfig = model.getPgConfig(); + + // pas autorise a migrer automatiquement + pgConfig.setCanMigrate(false); + + dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(pgConfig); + } else { + ObserveDataSourceConfigurationRest restConfig = model.getRestConfig(); + + dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(restConfig); + } + return dataSource; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageBackupUILauncher.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageBackupUILauncher.java index 099a2d8..865f650 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageBackupUILauncher.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageBackupUILauncher.java @@ -25,7 +25,7 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveSwingTechnicalException; import fr.ird.observe.application.swing.configuration.constants.DbMode; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.DataSourceCreateWithNoReferentialImportException; @@ -57,15 +57,10 @@ import java.util.Objects; */ public class StorageBackupUILauncher extends StorageUILauncher { - - /** - * Logger - */ + /** Logger */ private static final Log log = LogFactory.getLog(StorageBackupUILauncher.class); - public StorageBackupUILauncher(JAXXContext context, - Window frame, - String title) { + public StorageBackupUILauncher(JAXXContext context, Window frame, String title) { super(context, frame, title); } @@ -98,7 +93,7 @@ public class StorageBackupUILauncher extends StorageUILauncher { // Selection des données uniquement pour une base locale // Voir https://forge.codelutin.com/issues/7207 boolean selectAllData = model.isLocal(); - getStorageUIHandler().initSelectData(ui, source, selectAllData); + model.setSelectAll(selectAllData); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -120,13 +115,14 @@ public class StorageBackupUILauncher extends StorageUILauncher { ObserveSwingDataSource sourceToBackup = localSource; try { - DataSelectionModel dataModel = storageModel.getSelectDataModel(); - Map<ReferentialReference<ProgramDto>, List<DataReference>> tripsByProgram; - if (dataModel != null && !dataModel.isDataFull()) { -// // on renseigne les marees a exporter uniquement si -// // on en a selectionner, de plus si on a selectionne -// // toutes les marees, on le les passe pas : car c un dump -// // complet de la base. + SelectionTreeModel dataModel = storageModel.getSelectDataModel(); + Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> tripsByProgram; + if (!dataModel.isDataFull()) { + + // on renseigne les marees a exporter uniquement si + // on en a selectionner, de plus si on a selectionne + // toutes les marees, on le les passe pas : car c un dump + // complet de la base. tripsByProgram = dataModel.getSelectedDataByProgram(); @@ -144,7 +140,7 @@ public class StorageBackupUILauncher extends StorageUILauncher { TripManagementService tmpManagementService = sourceToBackup.newTripManagementService(); - for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference>> entry : tripsByProgram.entrySet()) { + for (Map.Entry<ReferentialReference<ProgramDto>, List<DataReference<?>>> entry : tripsByProgram.entrySet()) { for (DataReference trip : entry.getValue()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java index ec9eaeb..c88124d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.application.swing.ui.storage; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveActionExecutor; import fr.ird.observe.application.swing.ObserveRunner; @@ -39,16 +38,16 @@ import fr.ird.observe.application.swing.db.event.ObserveSwingDataSourceListenerA import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.UIHelper; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; import fr.ird.observe.application.swing.ui.storage.tabs.RolesTableModel; import fr.ird.observe.application.swing.ui.storage.tabs.SecurityModel; +import fr.ird.observe.application.swing.ui.storage.tabs.SelectDataUI; import fr.ird.observe.application.swing.ui.storage.tabs.StorageTabUI; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; -import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.ObserveDbUserDto; import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest; @@ -56,18 +55,18 @@ import fr.ird.observe.services.service.sql.SqlScriptProducerService; import jaxx.runtime.context.DefaultApplicationContext.AutoLoad; import jaxx.runtime.swing.wizard.WizardUILancher; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.swing.JTabbedPane; +import javax.swing.SwingUtilities; import java.awt.Component; import java.awt.Window; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -206,6 +205,8 @@ public class StorageUIHandler { // on demarre le modele pour le type de base connu ui.getModel().start(ui.getModel().getDbMode()); + ui.setSize(800, 600); + // centrage sur la frame parent UIHelper.center(ui.getContextValue(Window.class, "parent"), ui); @@ -252,13 +253,8 @@ public class StorageUIHandler { if (StorageStep.SELECT_DATA == newStep && mustRecompute) { - if (ObstunaAdminAction.CREATE == ui.getModel().getAdminAction() - && (model.getSelectDataModel() == null || model.getSelectDataModel().isEmpty())) { - - // récupération des données possibles à importer - initSelectData(ui); - - } + // récupération des données possibles à importer + initSelectData(ui); } @@ -370,6 +366,8 @@ public class StorageUIHandler { localDataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(localConfiguration); } + Objects.requireNonNull(localDataSource); + // Let's check if the datasource is opened or not : // we could have close the datasource through the ui // If the datasource is closed, we try to open it @@ -403,6 +401,9 @@ public class StorageUIHandler { UIHelper.handlingError(e); return; } + + Objects.requireNonNull(localDataSource); + // effectue la backup de la base locale existante File f = model.getBackupFile(); if (log.isDebugEnabled()) { @@ -465,7 +466,7 @@ public class StorageUIHandler { localDataSource.close(); } - localDataSource = null; +// localDataSource = null; if (log.isDebugEnabled()) { log.debug("Will create new storage..."); @@ -535,7 +536,7 @@ public class StorageUIHandler { } } if (log.isInfoEnabled()) { - log.info(">>> create initial dump with " + localDataSource + " in " + f); + log.info(">>> create initial dump with " + currentDataSource + " in " + f); } try { SqlScriptProducerService dumpProducerService = observeContext.getMainDataSourceServicesProvider().newSqlScriptProducerService(); @@ -638,60 +639,60 @@ public class StorageUIHandler { } } - /** - * Effectue une sauvegarde d'un service de persitances vers le fichier - * choisi. - * - * On peut spécifier les donnéees à exporter via le paramètre {@code - * marees}. - * - * <b>Note:</b> Si ce paramètre vaut {@code null}, on export tout. - * - * @param dataSource la source de donnée qui encapsule la base locale - * @param dst le fichier de sauvegarde - * @param trips les marees a exporter (si {@code null} on exporte tout) - */ - public void backupLocalDatabase(ObserveSwingDataSource dataSource, - File dst, - Set<DataReference> trips) { - - SqlScriptProducerService dumpService = dataSource.newSqlScriptProducerService(); - - - if (trips == null) { - if (log.isInfoEnabled()) { - log.info("will export all datas."); - } - backupLocalDatabase(dumpService, dst); - return; - } - if (dst == null) { - throw new IllegalArgumentException( - "file where to backup can not be null"); - } - if (log.isInfoEnabled()) { - log.info("will export " + trips.size() + " marees to " + dst); - } - if (log.isDebugEnabled()) { - log.debug(trips); - } - - // on doit dumper la base distante dans une base h2 et en faire - // la sauvegarde - - ImmutableSet<String> tripIds = ImmutableSet.copyOf(trips.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toSet())); - - AddSqlScriptProducerRequest request = AddSqlScriptProducerRequest.forH2().addSchema().addReferential().dataIdsToAdd(tripIds); - byte[] dump = dumpService.produceAddSqlScript(request).getSqlCode(); - - try (FileOutputStream fileOutputStream = new FileOutputStream(dst)) { - - IOUtils.write(dump, fileOutputStream); - - } catch (IOException e) { - UIHelper.handlingError(e); - } - } +// /** +// * Effectue une sauvegarde d'un service de persitances vers le fichier +// * choisi. +// * +// * On peut spécifier les donnéees à exporter via le paramètre {@code +// * marees}. +// * +// * <b>Note:</b> Si ce paramètre vaut {@code null}, on export tout. +// * +// * @param dataSource la source de donnée qui encapsule la base locale +// * @param dst le fichier de sauvegarde +// * @param trips les marees a exporter (si {@code null} on exporte tout) +// */ +// public void backupLocalDatabase(ObserveSwingDataSource dataSource, +// File dst, +// Set<DataReference> trips) { +// +// SqlScriptProducerService dumpService = dataSource.newSqlScriptProducerService(); +// +// +// if (trips == null) { +// if (log.isInfoEnabled()) { +// log.info("will export all datas."); +// } +// backupLocalDatabase(dumpService, dst); +// return; +// } +// if (dst == null) { +// throw new IllegalArgumentException( +// "file where to backup can not be null"); +// } +// if (log.isInfoEnabled()) { +// log.info("will export " + trips.size() + " marees to " + dst); +// } +// if (log.isDebugEnabled()) { +// log.debug(trips); +// } +// +// // on doit dumper la base distante dans une base h2 et en faire +// // la sauvegarde +// +// ImmutableSet<String> tripIds = ImmutableSet.copyOf(trips.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toSet())); +// +// AddSqlScriptProducerRequest request = AddSqlScriptProducerRequest.forH2().addSchema().addReferential().dataIdsToAdd(tripIds); +// byte[] dump = dumpService.produceAddSqlScript(request).getSqlCode(); +// +// try (FileOutputStream fileOutputStream = new FileOutputStream(dst)) { +// +// IOUtils.write(dump, fileOutputStream); +// +// } catch (IOException e) { +// UIHelper.handlingError(e); +// } +// } public String computeReport(StorageUI ui, StorageStep step) { if (log.isDebugEnabled()) { @@ -725,61 +726,67 @@ public class StorageUIHandler { return ObserveSwingApplicationContext.get().getDecoratorService(); } - public void initSelectData(StorageUI ui, ObserveSwingDataSource source, boolean selectAll) { + protected void initSelectData(StorageUI ui) { StorageUIModel model = ui.getModel(); - try { - - Preconditions.checkState(source != null, "Can't select data on a null dataSource"); - - DataSelectionModel dataModel = new DataSelectionModel(); - dataModel.setUseData(true); - dataModel.setUseOpenData(true); - dataModel.setUseReferentiel(false); - DataSelectionModel.populate(dataModel, source); + boolean closeSource = true; + try { - if (selectAll) { + // Creation de la data source de lecture des données à sélectionner + ObserveSwingDataSource importDataSource; - dataModel.addAllSelectedData(); + if (ObstunaAdminAction.CREATE == model.getAdminAction()) { + importDataSource = model.toImportDataSourceConfig(); + } else { + importDataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); + closeSource = false; } - // positionnement du model de selection de données - // dans le model du wizard - model.setSelectDataModel(dataModel); + Preconditions.checkState(importDataSource != null, "Can't select data on a null dataSource"); - // initialisation de l'ui dedié - ui.getSELECT_DATA().initTree(source); + try { - } catch (Exception e) { - throw new RuntimeException("Could not grab data to select", e); - } + if (closeSource) { - } + importDataSource.open(); + model.checkImportDbVersion(importDataSource); - protected void initSelectData(StorageUI ui) { + } - StorageUIModel model = ui.getModel(); + SelectDataUI selectDataUI = (SelectDataUI) ui.getStepUI(StorageStep.SELECT_DATA); + SelectionTreeModel treeModel = selectDataUI.getSelectTree().getTreeModel(); - try { + treeModel.setLoadLongline(true); + treeModel.setLoadSeine(true); + treeModel.setUseOpenData(true); + treeModel.setLoadReferential(false); + treeModel.setShowEmptyTrips(false); - // Creation de la data source de lecture des données à sélectionner - ObserveSwingDataSource importDataSource = model.toImportDataSourceConfig(); + treeModel.populate(importDataSource); - Preconditions.checkState(importDataSource != null, "Can't select data on a null dataSource"); + boolean selectAll = model.isSelectAll(); - try { + if (selectAll) { + treeModel.selectAllTrips(); + SwingUtilities.invokeLater(() -> selectDataUI.getSelectTree().expandAll()); + } - importDataSource.open(); + // positionnement du model de selection de données dans le model du wizard + model.setSelectDataModel(treeModel); - model.checkImportDbVersion(importDataSource); + if (selectAll) { + treeModel.selectAllTrips(); + SwingUtilities.invokeLater(() -> selectDataUI.getSelectTree().expandAll()); + } - initSelectData(ui, importDataSource, false); } finally { - importDataSource.close(); + if (closeSource) { + importDataSource.close(); + } } } catch (Exception e) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java index 68f1269..6bf33c8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java @@ -242,7 +242,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod * @param mainUI la fenetre principale parent (peut etre null) * @param model le modèle de source de données à utiliser * @param title le titre de la fenêtre - * @param model le type deconnexion (base distante ou serveur distant) + * @param dbMode le type deconnexion (base distante ou serveur distant) * @see StorageUI */ public static void obtainConnexion(final JAXXContext context, @@ -317,102 +317,102 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod launcher.start(); } - /** - * Méthode pour lancer l'action de connexion à une base locale. - * - * @param context le context applicatif - * @param mainUI la fenetre principale parent (peut etre null) - * @param model le modèle de source de données à utiliser - * @see StorageUI - */ - public static void obtainLocalConnexion(final JAXXContext context, - Window mainUI, - final StorageUIModel model) { - - if (mainUI == null) { - mainUI = ObserveSwingApplicationContext.get().getMainUI(); - } - - addStorageUIHandler(context); - - StorageUILauncher launcher = new StorageUILauncher( - context, - mainUI, - model, - t("observe.title.connect.localDB")) { - - @Override - protected StorageUI createUI(JAXXContext context, - Window mainUI, - Class<StorageUI> storageUIClass, - Class<StorageUIModel> modelClass, - StorageUIModel model) throws Exception { - if (!(mainUI instanceof JAXXObject)) { - // sinon on a pas de context propagé... - mainUI = null; - } - return super.createUI(context, mainUI, storageUIClass, modelClass, model); - } - - @Override - protected void init(StorageUI ui) { - StorageUIModel model = ui.getModel(); - - int nbModes = 0; - - DbMode mode = null; - if (model.isCanCreateLocalService()) { - nbModes++; - mode = DbMode.CREATE_LOCAL; - } - if (model.isCanUseLocalService()) { - nbModes++; - mode = DbMode.USE_LOCAL; - } - if (model.isCanUseRemoteService()) { - nbModes++; - mode = DbMode.USE_REMOTE; - } - if (model.isCanUseServerService()) { - nbModes++; - mode = DbMode.USE_SERVER; - } - - if (nbModes == 1) { - - if (log.isDebugEnabled()) { - log.debug("Only one mode available [" + mode + - "], set it in model"); - } - - // un seul mode possible, on le sélectionne - model.setDbMode(mode); - } - - // on supprime des étapes - model.setExcludeSteps(Arrays.asList( - StorageStep.BACKUP, - StorageStep.CONFIG_REFERENTIEL, - StorageStep.CONFIG_DATA, - StorageStep.SELECT_DATA, - StorageStep.CONFIRM)); - - model.updateUniverse(); - } - - @Override - protected void doAction(StorageUI ui) { - super.doAction(ui); - if (log.isDebugEnabled()) { - log.debug("Apply new local connexion to " + model); - } - ui.getModel().copyTo(model); - model.validate(); - } - }; - - launcher.start(); - } +// /** +// * Méthode pour lancer l'action de connexion à une base locale. +// * +// * @param context le context applicatif +// * @param mainUI la fenetre principale parent (peut etre null) +// * @param model le modèle de source de données à utiliser +// * @see StorageUI +// */ +// public static void obtainLocalConnexion(final JAXXContext context, +// Window mainUI, +// final StorageUIModel model) { +// +// if (mainUI == null) { +// mainUI = ObserveSwingApplicationContext.get().getMainUI(); +// } +// +// addStorageUIHandler(context); +// +// StorageUILauncher launcher = new StorageUILauncher( +// context, +// mainUI, +// model, +// t("observe.title.connect.localDB")) { +// +// @Override +// protected StorageUI createUI(JAXXContext context, +// Window mainUI, +// Class<StorageUI> storageUIClass, +// Class<StorageUIModel> modelClass, +// StorageUIModel model) throws Exception { +// if (!(mainUI instanceof JAXXObject)) { +// // sinon on a pas de context propagé... +// mainUI = null; +// } +// return super.createUI(context, mainUI, storageUIClass, modelClass, model); +// } +// +// @Override +// protected void init(StorageUI ui) { +// StorageUIModel model = ui.getModel(); +// +// int nbModes = 0; +// +// DbMode mode = null; +// if (model.isCanCreateLocalService()) { +// nbModes++; +// mode = DbMode.CREATE_LOCAL; +// } +// if (model.isCanUseLocalService()) { +// nbModes++; +// mode = DbMode.USE_LOCAL; +// } +// if (model.isCanUseRemoteService()) { +// nbModes++; +// mode = DbMode.USE_REMOTE; +// } +// if (model.isCanUseServerService()) { +// nbModes++; +// mode = DbMode.USE_SERVER; +// } +// +// if (nbModes == 1) { +// +// if (log.isDebugEnabled()) { +// log.debug("Only one mode available [" + mode + +// "], set it in model"); +// } +// +// // un seul mode possible, on le sélectionne +// model.setDbMode(mode); +// } +// +// // on supprime des étapes +// model.setExcludeSteps(Arrays.asList( +// StorageStep.BACKUP, +// StorageStep.CONFIG_REFERENTIEL, +// StorageStep.CONFIG_DATA, +// StorageStep.SELECT_DATA, +// StorageStep.CONFIRM)); +// +// model.updateUniverse(); +// } +// +// @Override +// protected void doAction(StorageUI ui) { +// super.doAction(ui); +// if (log.isDebugEnabled()) { +// log.debug("Apply new local connexion to " + model); +// } +// ui.getModel().copyTo(model); +// model.validate(); +// } +// }; +// +// launcher.start(); +// } /** * Méthode pour lancer l'action de connexion à une base locale ou distante. @@ -422,9 +422,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod * @param model le modèle de source de données à utiliser * @see StorageUI */ - public static void obtainConnexion(final JAXXContext context, - Window mainUI, - final StorageUIModel model) { + public static void obtainConnexion(JAXXContext context, Window mainUI, StorageUIModel model) { if (mainUI == null) { mainUI = ObserveSwingApplicationContext.get().getMainUI(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIModel.java index 108d5dd..ade4992 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIModel.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.application.swing.ui.storage; -import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveSwingApplicationDataSourcesManager; import fr.ird.observe.application.swing.ObserveSwingTechnicalException; @@ -30,13 +29,13 @@ import fr.ird.observe.application.swing.configuration.constants.CreationMode; import fr.ird.observe.application.swing.configuration.constants.DbMode; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.db.constants.ConnexionStatus; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; import fr.ird.observe.application.swing.ui.storage.tabs.SecurityModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; +import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2; import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG; -import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.DataSourceCreateWithNoReferentialImportException; import fr.ird.observe.services.dto.IncompatibleDataSourceCreateConfigurationException; @@ -48,17 +47,18 @@ import fr.ird.observe.services.security.UnknownObserveWebUserException; import fr.ird.observe.services.security.UnknownObserveWebUserForDatabaseException; import fr.ird.observe.services.security.UserLoginNotFoundException; import fr.ird.observe.services.security.UserPasswordNotFoundException; -import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest; import fr.ird.observe.services.service.BabModelVersionException; import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; import fr.ird.observe.services.service.DatabaseNotFoundException; import fr.ird.observe.services.service.PingService; +import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest; import fr.ird.observe.services.service.sql.SqlScriptProducerService; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.wizard.WizardModel; import jaxx.runtime.swing.wizard.WizardUILancher; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.version.Version; @@ -201,7 +201,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { protected boolean canUseServerService = true; /** le modèle de sélection de données (utilisé pour les exports) */ - protected DataSelectionModel selectDataModel; + protected SelectionTreeModel selectDataModel; /** le modèle de sécurité (utilisé pour la mise à jour sécurité sur base distante) */ protected SecurityModel securityModel; @@ -254,6 +254,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { * @since 3.6 */ protected CreationMode dataImportMode; + private boolean selectAll; public StorageUIModel() { super(StorageStep.class, @@ -261,7 +262,6 @@ public class StorageUIModel extends WizardModel<StorageStep> { StorageStep.BACKUP, StorageStep.CONFIRM ); - selectDataModel = new DataSelectionModel(); securityModel = new SecurityModel(); connexionStatus = ConnexionStatus.UNTESTED; @@ -345,7 +345,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { return; } - StorageUIHandler storageUIHandler = context.getContextValue(StorageUIHandler.class); +// StorageUIHandler storageUIHandler = context.getContextValue(StorageUIHandler.class); // ajout paramétrage depuis la configuration @@ -426,22 +426,10 @@ public class StorageUIModel extends WizardModel<StorageStep> { log.debug("no service found, using default configuration"); } - DbMode newDbMode = config.getDefaultDbMode(); - if (getAdminAction() != null) { + Pair<CreationMode, DbMode> modes = computeModes(config); + mode = modes.getLeft(); + DbMode newDbMode = modes.getRight(); - // une action d'admin obstuna toujours sur base distante - newDbMode = DbMode.USE_REMOTE; - } else { - if (isCanUseLocalService()) { - mode = null; - } else if (isCanCreateLocalService()) { - mode = CreationMode.IMPORT_EXTERNAL_DUMP; - } else if (isCanUseRemoteService()) { - mode = CreationMode.IMPORT_REMOTE_STORAGE; - } else if (isCanUseServerService()) { - mode = CreationMode.IMPORT_SERVER_STORAGE; - } - } if (log.isDebugEnabled()) { log.debug("Will use creationMode : " + mode); } @@ -453,34 +441,21 @@ public class StorageUIModel extends WizardModel<StorageStep> { * La méthode pour initialiser le modèle à partir du context applicatif et * d'une configuration de source de donnée existante. * - * @param context le context applicatif * @param previousConfig la configuration de service existant * @since 2.0 */ - public void initFromPreviousConfig(JAXXContext context, - ObserveDataSourceConfiguration previousConfig, + public void initFromPreviousConfig(ObserveDataSourceConfiguration previousConfig, ObserveDataSourceInformation previousInfo) { Objects.requireNonNull(previousConfig, "previousConfig parameter can not be null in method initFromPreviousConfig"); ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); - StorageUIHandler storageUIHandler = context.getContextValue(StorageUIHandler.class); - // ajout paramétrage depuis la configuration boolean isLocalStorageExist = config.isLocalStorageExist(); setLocalStorageExist(isLocalStorageExist); - if (log.isDebugEnabled()) { - log.debug("Local storage exists ? " + isLocalStorageExist()); - log.debug("can use local storage ? " + isCanUseLocalService()); - log.debug("can create local storage ? " + isCanCreateLocalService()); - log.debug("can use remote storage ? " + isCanUseRemoteService()); - log.debug("can use server storage ? " + isCanUseServerService()); - log.debug("previous service ? " + previousConfig); - } - setStoreRemoteConfig(config.isStoreRemoteStorage()); setBackupFile(config.newBackupDataFile()); setDumpFile(config.getBackupDirectory()); @@ -560,8 +535,6 @@ public class StorageUIModel extends WizardModel<StorageStep> { log.debug("canMigrate ? " + isCanMigrate()); } - CreationMode mode = config.getDefaultCreationMode(); - if (log.isDebugEnabled()) { log.debug("no service found, using default configuration"); } @@ -577,12 +550,27 @@ public class StorageUIModel extends WizardModel<StorageStep> { pgConfig = dataSourcesManager.newPGDataSourceConfiguration(config, t("observe.storage.label.remote")); restConfig = dataSourcesManager.newRestDataSourceConfiguration(config, t("observe.storage.label.server")); - DbMode newDbMode = config.getDefaultDbMode(); + Pair<CreationMode, DbMode> modes = computeModes(config); + CreationMode mode = modes.getLeft(); + DbMode newDbMode = modes.getRight(); + + if (log.isDebugEnabled()) { + log.debug("Will use creationMode : " + mode); + } + setDbMode(newDbMode); + setCreationMode(mode); + } + + protected Pair<CreationMode, DbMode> computeModes(ObserveSwingApplicationConfig config) { + DbMode newDbMode; + + CreationMode mode = config.getDefaultCreationMode(); if (getAdminAction() != null) { // une action d'admin obstuna toujours sur base distante newDbMode = DbMode.USE_REMOTE; } else { + newDbMode = config.getDefaultDbMode(); if (isCanUseLocalService()) { mode = null; } else if (isCanCreateLocalService()) { @@ -593,11 +581,8 @@ public class StorageUIModel extends WizardModel<StorageStep> { mode = CreationMode.IMPORT_SERVER_STORAGE; } } - if (log.isDebugEnabled()) { - log.debug("Will use creationMode : " + mode); - } - setDbMode(newDbMode); - setCreationMode(mode); + + return Pair.of(mode, newDbMode); } protected void startCentralSourceModel() { @@ -726,15 +711,15 @@ public class StorageUIModel extends WizardModel<StorageStep> { return adminAction; } - public String getAdminActionLabel() { - return I18nEnumHelper.getLabel(getAdminAction()); - } +// public String getAdminActionLabel() { +// return I18nEnumHelper.getLabel(getAdminAction()); +// } - public DataSelectionModel getSelectDataModel() { + public SelectionTreeModel getSelectDataModel() { return selectDataModel; } - public void setSelectDataModel(DataSelectionModel selectDataModel) { + public void setSelectDataModel(SelectionTreeModel selectDataModel) { this.selectDataModel = selectDataModel; } @@ -1086,10 +1071,10 @@ public class StorageUIModel extends WizardModel<StorageStep> { } public boolean isUseSelectData() { - return getSteps() != null && - getSteps().contains(StorageStep.SELECT_DATA); + return getSteps() != null && getSteps().contains(StorageStep.SELECT_DATA); } + // Ne pas supprimer, utilise dans des templates public boolean isBackupAction() { return getSteps() != null && getStepIndex(StorageStep.BACKUP) == 0; } @@ -1160,6 +1145,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { return ObserveSwingApplicationContext.get().getConfig().getModelVersion(); } + // ne pas supprimer utiliser dans les templates public File getInitialDbDump() { return ObserveSwingApplicationContext.get().getConfig().getInitialDbDump(); } @@ -1402,9 +1388,9 @@ public class StorageUIModel extends WizardModel<StorageStep> { return serverUrl; } - protected void setServerUrl(String serverUrl) { - this.serverUrl = serverUrl; - } +// protected void setServerUrl(String serverUrl) { +// this.serverUrl = serverUrl; +// } public boolean isUseSsl() { return pgConfig.isUseSsl(); @@ -1797,6 +1783,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { log.error("Error in test remote", e); } + setConnexionStatus(null); setConnexionStatus(ConnexionStatus.FAILED); } finally { @@ -1813,7 +1800,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { return result; } - + // ne pas supprimer, utilisé dans les templates public String getConnexionStatusError() { return connexionStatusError; } @@ -2066,4 +2053,12 @@ public class StorageUIModel extends WizardModel<StorageStep> { dumpFile.exists() && dumpFile.getName().endsWith(".sql.gz"); } + + public boolean isSelectAll() { + return selectAll; + } + + public void setSelectAll(boolean selectAll) { + this.selectAll = selectAll; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss index 2920282..6909e3c 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss @@ -84,7 +84,7 @@ #importInternalDumpMode { value:{CreationMode.IMPORT_INTERNAL_DUMP}; - text:{getHandler().updateInternalDumpModeLabel(ChooseDbModeUI.this, config.isInitialDumpExist())}; + text:{getHandler().updateInternalDumpModeLabel(config.isInitialDumpExist())}; visible:{getHandler().updateCreationModeLayout(ChooseDbModeUI.this, config.isInitialDumpExist(), importInternalDumpMode)}; selected:{model.getCreationMode() == CreationMode.IMPORT_INTERNAL_DUMP}; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/DataSelectionModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/DataSelectionModel.java deleted file mode 100644 index c1c5841..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/DataSelectionModel.java +++ /dev/null @@ -1,619 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.storage.tabs; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.AbstractReference; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ProgramHelper; -import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.dto.referential.ReferentialHelper; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.data.longline.TripLonglineService; -import fr.ird.observe.services.service.data.seine.TripSeineService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import static com.google.common.collect.Lists.newArrayList; - -/** - * Un modèle pour représenter la sélection de données. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class DataSelectionModel implements Serializable { - - public static void populate(DataSelectionModel model, ObserveSwingDataSource source) { - - Preconditions.checkState(source.isOpen()); - - Map<ReferentialReference<ProgramDto>, List<DataReference>> datas = Maps.newHashMap(); - - TripSeineService tripSeineService = source.newTripSeineService(); - TripLonglineService tripLonglineService = source.newTripLonglineService(); - - Set<ReferentialReference<ProgramDto>> programSet = source.getReferentialReferences(ProgramDto.class); - - for (ReferentialReference<ProgramDto> program : programSet) { - - List<DataReference> referenceHelper = newArrayList(); - - if (ProgramHelper.isProgramSeine(program)) { - - DataReferenceSet<TripSeineDto> tripSeineRef = tripSeineService.getTripSeineByProgram(program.getId()); - referenceHelper.addAll(tripSeineRef.getReferences()); - - } else if (ProgramHelper.isProgramLongline(program)) { - - DataReferenceSet<TripLonglineDto> tripLonglineRef = tripLonglineService.getTripLonglineByProgram(program.getId()); - referenceHelper.addAll(tripLonglineRef.getReferences()); - - } - - populate(program, referenceHelper, datas); - - } - model.setDatas(datas); - - } - - public static void populate(DataSelectionModel model, ObserveSwingDataSource source, boolean tripSeine) { - - Preconditions.checkState(source.isOpen()); - - Map<ReferentialReference<ProgramDto>, List<DataReference>> datas = Maps.newHashMap(); - - Set<ReferentialReference<ProgramDto>> programSet = source.getReferentialReferences(ProgramDto.class); - - ImmutableSet<DataReference> allTrips; - if (tripSeine) { - TripSeineService tripSeineService = source.newTripSeineService(); - allTrips = (ImmutableSet) tripSeineService.getAllTripSeine().getReferences(); - - } else { - TripLonglineService tripLonglineService = source.newTripLonglineService(); - allTrips = (ImmutableSet) tripLonglineService.getAllTripLongline().getReferences(); - } - - for (ReferentialReference<ProgramDto> program : programSet) { - - List<DataReference> referenceHelper = new ArrayList<>(); - - boolean add = false; - if (tripSeine && ProgramHelper.isProgramSeine(program)) { - - for (DataReference trip : allTrips) { - String programId = (String) trip.getPropertyValue(TripSeineDto.PROPERTY_PROGRAM + "Id"); - if (program.getId().equals(programId)) { - referenceHelper.add(trip); - } - } - add = true; - - } else if (!tripSeine && ProgramHelper.isProgramLongline(program)) { - - for (DataReference trip : allTrips) { - String programId = (String) trip.getPropertyValue(TripSeineDto.PROPERTY_PROGRAM + "Id"); - if (program.getId().equals(programId)) { - referenceHelper.add(trip); - } - } - add = true; - } - - if (add) { - populate(program, referenceHelper, datas); - } - - } - model.setDatas(datas); - - } - - protected static void populate(ReferentialReference<ProgramDto> program, - List<DataReference> trips, - Map<ReferentialReference<ProgramDto>, List<DataReference>> datas) { - - if (!trips.isEmpty()) { - - datas.put(program, trips); - if (log.isDebugEnabled()) { - log.debug("Add program " + program.getPropertyValue(ProgramDto.PROPERTY_LABEL1) + " with " + trips.size() + " trip(s)."); - } - - - } - - } - - public static final String PROPERTY_USE_REFERENTIEL = "useReferentiel"; - - public static final String PROPERTY_USE_DATA = "useData"; - - public static final String PROPERTY_USE_OPEN_DATA = "useOpenData"; - - public static final String PROPERTY_SELECTED_DATA = "selectedData"; - - public static final String PROPERTY_SELECTED_REFERENTIEL = "selectedReferentiel"; - - public static final String PROPERTY_DATAS = "datas"; - - /** Logger */ - private static final Log log = LogFactory.getLog(DataSelectionModel.class); - - private static final long serialVersionUID = 2L; - - /** un drapeau pour selectionner ou non les donnees observers */ - protected boolean useData; - - /** un drapeau pour selectionner ou non des donnees observers ouvertes */ - protected boolean useOpenData; - - /** un drapeau pour selectionner ou non des donnees observer */ - protected boolean useReferentiel; - - /** la liste des programs utilisables (qui ont des marees) */ - protected transient Map<ReferentialReference<ProgramDto>, List<DataReference>> datas; - - /** la liste des marees selectionnee */ - protected transient Set<DataReference> selectedData; - - /** la liste des referentiels possibles */ - protected final Set<Class<? extends ReferentialDto>> referentiel; - - /** la liste des referentiels selectionnes */ - protected final Set<Class<? extends ReferentialDto>> selectedReferentiel; - - /** nb marees */ - protected int nbTrips; - - /** nb referentiels */ - protected final int nbReferentiels; - - protected final PropertyChangeSupport pcs; - - public void populate() { - throw new UnsupportedOperationException(); - } - - public DataSelectionModel() { - pcs = new PropertyChangeSupport(this); - referentiel = Sets.newHashSet(ReferentialHelper.REFERENCE_DTOS); - selectedReferentiel = Sets.newHashSet(); - nbReferentiels = referentiel.size(); - } - - public boolean isUseReferentiel() { - return useReferentiel; - } - - public boolean isUseData() { - return useData; - } - - public boolean isUseOpenData() { - return useOpenData; - } - - public boolean isEmpty() { - if (isUseReferentiel()) { - if (!isReferentielEmpty()) { - return false; - } - } - if (isUseData()) { - if (!isDataEmpty()) { - return false; - } - } - return true; - } - - - public boolean isReferentielEmpty() { - return selectedReferentiel.isEmpty(); - } - - public boolean isReferentielFull() { - return selectedReferentiel.size() == nbReferentiels; - } - - public boolean isDataEmpty() { - return selectedData == null || selectedData.isEmpty(); - } - - public boolean isDataFull() { - return selectedData != null && selectedData.size() == nbTrips; - } - - public int selectDataSize() { - return selectedData == null ? 0 : selectedData.size(); - } - - public Set<Class<? extends ReferentialDto>> getSelectedReferentiel() { - return selectedReferentiel; - } - - public Map<ReferentialReference<ProgramDto>, List<DataReference>> getDatas() { - if (datas == null) { - datas = Maps.newHashMap(); - } - return datas; - } - - public boolean containsData(ReferentialReference<ProgramDto> program, DataReference trip) { - List<DataReference> datas = getDatas(program.getId()); - return datas != null && datas.contains(trip); - } - - public Set<DataReference> getSelectedData() { - if (selectedData == null) { - selectedData = Sets.newHashSet(); - } - return selectedData; - } - - public Map<ReferentialReference<ProgramDto>, List<DataReference>> getSelectedDataByProgram() { - if (datas == null || selectedData == null || selectedData.isEmpty()) { - return Collections.emptyMap(); - } - Map<ReferentialReference<ProgramDto>, List<DataReference>> result = Maps.newHashMap(); - - for (DataReference referenceDto : selectedData) { - - // on recherche son program - for (ReferentialReference<ProgramDto> p : datas.keySet()) { - if (datas.get(p).contains(referenceDto)) { - List<DataReference> referenceHelper = result.get(p); - if (referenceHelper == null) { - referenceHelper = newArrayList(); - result.put(p, referenceHelper); - } - referenceHelper.add(referenceDto); - break; - } - } - } - return result; - } - - public List<ReferentialReference<ProgramDto>> getSelectedProgram() { - if (datas == null || selectedData == null || selectedData.isEmpty()) { - return Collections.emptyList(); - } - - Set<ReferentialReference<ProgramDto>> result = Sets.newHashSet(); - - for (DataReference referenceDto : selectedData) { - - // on recherche son program - for (ReferentialReference<ProgramDto> p : datas.keySet()) { - if (datas.get(p).contains(referenceDto)) { - result.add(p); - break; - } - } - } - - return result.stream().collect(Collectors.toList()); - } - - public List<DataReference> getSelectedTripsByProgram(ReferentialReference<ProgramDto> program) { - if (datas == null || selectedData == null || selectedData.isEmpty()) { - return Collections.emptyList(); - } - - return datas.get(program).stream() - .filter(trip -> selectedData.contains(trip)) - .collect(Collectors.toList()); - } - - - public boolean isSelectedData(AbstractReference<?> referenceDto) { - - boolean result; - - if (ProgramDto.class.isAssignableFrom(referenceDto.getType())) { - - List<DataReference> trips = datas.get(referenceDto); - result = CollectionUtils.isNotEmpty(trips); - - if (result) { - for (DataReference trip : trips) { - if (!getSelectedData().contains(trip)) { - - // au moins une marée non sélectionnée - - result = false; - } - } - } - } else { - - // recherche directe sur les ids de marees - result = getSelectedData().contains(referenceDto); - - } - - // ne devrait pas arrivée - return result; - - } - - public boolean isSelectedReferentiel(Class<?> type) { - checkReferentielType(type); - return getSelectedReferentiel().contains(type); - } - - public void setUseReferentiel(boolean useReferentiel) { - this.useReferentiel = useReferentiel; - firePropertyChange(PROPERTY_USE_REFERENTIEL, useReferentiel); - } - - public void setUseData(boolean useData) { - this.useData = useData; - firePropertyChange(PROPERTY_USE_DATA, useData); - } - - public void setUseOpenData(boolean useOpenData) { - this.useOpenData = useOpenData; - firePropertyChange(PROPERTY_USE_OPEN_DATA, useOpenData); - } - - public void addSelectedReferentiel(Class<? extends ReferentialDto> type) { - checkReferentielType(type); - if (log.isDebugEnabled()) { - log.debug("Add referentiel type " + type); - } - getSelectedReferentiel().add(type); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public void addAllSelectedReferentiel() { - getSelectedReferentiel().addAll(referentiel); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public void removeSelectedReferentiel(Class<?> type) { - checkReferentielType(type); - if (log.isDebugEnabled()) { - log.debug("remove referentiel type " + type); - } - getSelectedReferentiel().remove(type); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public void removeAll() { - getSelectedReferentiel().clear(); - getSelectedData().clear(); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - firePropertyChange(PROPERTY_SELECTED_DATA, selectedData); - } - - public void removeAllSelectedReferentiel() { - getSelectedReferentiel().clear(); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public boolean isReferentielSelectAll(Collection<Class<? extends ReferentialDto>> classes) { - return selectedReferentiel.containsAll(classes); - } - - public void removeAllReferentiel(Collection<Class<? extends ReferentialDto>> classes) { - selectedReferentiel.removeAll(classes); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public void addAllReferentiel(Collection<Class<? extends ReferentialDto>> classes) { - selectedReferentiel.addAll(classes); - firePropertyChange(PROPERTY_SELECTED_REFERENTIEL, selectedReferentiel); - } - - public void setDatas(Map<ReferentialReference<ProgramDto>, List<DataReference>> datas) { - this.datas = datas; - - // on compte le count de marées totale - int nbTrips = 0; - if (datas != null) { - for (List<DataReference> marees : datas.values()) { - nbTrips += marees.size(); - } - } - this.nbTrips = nbTrips; - - if (log.isDebugEnabled()) { - log.debug("Nb program registred : " + (datas == null ? 0 : datas.size())); - log.debug("Nb trip registred : " + this.nbTrips); - } - firePropertyChange(PROPERTY_DATAS, datas); - } - - public void addSelectedData(AbstractReference referenceDto) { - - if (ProgramDto.class.isAssignableFrom(referenceDto.getType())) { - - // ajout de toutes les marées du program - - if (log.isDebugEnabled()) { - log.debug("Add all trips of program " + referenceDto.getId()); - } - getSelectedData().addAll(datas.get(referenceDto)); - - } else { - // ajout d'une marée - if (log.isDebugEnabled()) { - log.debug("Add Trip " + referenceDto.getId()); - } - getSelectedData().add((DataReference) referenceDto); - } - firePropertyChange(PROPERTY_SELECTED_DATA, selectedData); - } - - public void addAllSelectedData() { - if (log.isDebugEnabled()) { - log.debug("All all data."); - } - for (List<DataReference> p : datas.values()) { - getSelectedData().addAll(p); - } - firePropertyChange(PROPERTY_SELECTED_DATA, selectedData); - } - - public void removeSelectedData(AbstractReference referenceDto) { - - if (ProgramDto.class.isAssignableFrom(referenceDto.getType())) { - - // ajout de toutes les marées du program - - if (log.isDebugEnabled()) { - log.debug("Remove all marees of program " + referenceDto); - } - getSelectedData().removeAll(datas.get(referenceDto)); - } else { - - // ajout d'une marée - if (log.isDebugEnabled()) { - log.debug("Remove maree " + referenceDto); - } - getSelectedData().remove(referenceDto); - } - firePropertyChange(PROPERTY_SELECTED_DATA, selectedData); - } - - public void removeAllSelectedData() { - if (selectedData != null) { - selectedData.clear(); - } - firePropertyChange(PROPERTY_SELECTED_DATA, selectedData); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object newValue) { - pcs.firePropertyChange(propertyName, null, newValue); - } - - protected void firePropertyChange(String propertyName, - Object oldValue, - Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - - protected void checkReferentielType(Class<?> type) { - if (!referentiel.contains(type)) { - throw new IllegalArgumentException( - "given <" + type + "> is not in referentiel universe : " + - referentiel); - } - } - - public void destroy() { - removeAll(); - // suppression de tous les listeners - PropertyChangeListener[] listeners = pcs.getPropertyChangeListeners(); - for (PropertyChangeListener l : listeners) { - removePropertyChangeListener(l); - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - destroy(); - } - - public List<DataReference> getDatas(String programId) { - Optional<ReferentialReference<ProgramDto>> programRefOptional = getDatas().keySet().stream().filter(ReferentialReference.newIdPredicate(programId)).findFirst(); - - List<DataReference> result; - - if (programRefOptional.isPresent()) { - - result = getDatas().get(programRefOptional.get()); - - } else { - - result = Collections.emptyList(); - - } - - return result; - } - - public void addData(ReferentialReference<ProgramDto> program, DataReference trip) { - if (!getDatas().containsKey(program)) { - getDatas().put(program, new ArrayList<>()); - } - getDatas(program.getId()).add(trip); - firePropertyChange(PROPERTY_DATAS, getDatas()); - } - - public Set<ReferentialReference<ProgramDto>> getPrograms() { - return getDatas().keySet(); - } - - public void removeTrip(ReferentialReference<ProgramDto> program, DataReference trip) { - List<DataReference> trips = getDatas(program.getId()); - trips.remove(trip); - if (trips.isEmpty()) { - getDatas().remove(program); - } - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx index 90d5b82..d1b9882 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx @@ -27,40 +27,28 @@ <StorageTabUI> <import> - fr.ird.observe.application.swing.db.ObserveSwingDataSource + fr.ird.observe.application.swing.ui.storage.StorageUIModel fr.ird.observe.application.swing.ui.storage.StorageStep - fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel - fr.ird.observe.application.swing.ui.tree.renderer.DataSelectionTreeCellRenderer - fr.ird.observe.application.swing.ui.util.tree.BeanTreeHeader + fr.ird.observe.application.swing.ui.tree.selection.SelectionTree + fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeHeader </import> <StorageStep id='step' initializer='StorageStep.SELECT_DATA'/> - <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='model'/> - - <DataSelectionTreeSelectionModel id='selectionModel'/> + <StorageUIModel id='model'/> <script><![CDATA[ @Override public void init() { getHandler().initUI(this); } - -public void initTree(ObserveSwingDataSource dataSource) { - getHandler().initTree(this, dataSource); -} ]]> </script> <JPanel id='content'> - <JScrollPane id='selectedTreePane' constraints='BorderLayout.CENTER' columnHeaderView='{selectTreeHeader}'> - - <!-- arbre de selection des exports --> - <JTree id='selectTree'/> - - <BeanTreeHeader id='selectTreeHeader' tree='{selectTree}'/> - + <SelectionTree id='selectTree'/> + <SelectionTreeHeader id='selectTreeHeader' treeTable='{selectTree}'/> </JScrollPane> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jcss index a8c2fcd..2eda397 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jcss @@ -34,11 +34,5 @@ font-size:11; showsRootHandles:false; toggleClickCount:100; - selectionModel:{selectionModel}; - cellRenderer:{new DataSelectionTreeCellRenderer()}; -} - -#selectionModel { - selectionMode: {DataSelectionTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION}; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java index f07a45e..69ba3e8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java @@ -26,14 +26,11 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveTextGenerator; import fr.ird.observe.application.swing.configuration.constants.CreationMode; import fr.ird.observe.application.swing.configuration.constants.DbMode; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.db.constants.ConnexionStatus; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.storage.StorageStep; import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; import fr.ird.observe.application.swing.ui.storage.StorageUIModel; -import fr.ird.observe.application.swing.ui.tree.DataSelectionTreeSelectionModel; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import jaxx.runtime.swing.editor.MyDefaultCellEditor; import org.apache.commons.logging.Log; @@ -46,7 +43,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTable; -import javax.swing.JTree; import javax.swing.KeyStroke; import javax.swing.table.DefaultTableCellRenderer; import java.awt.BorderLayout; @@ -73,9 +69,7 @@ public class StorageTabUIHandler { private static final Log log = LogFactory.getLog(StorageTabUIHandler.class); - public boolean updateCreationModeLayout(ChooseDbModeUI ui, - boolean visible, - JRadioButton button) { + public boolean updateCreationModeLayout(ChooseDbModeUI ui, boolean visible, JRadioButton button) { JPanel panel = ui.getUseCreateMode(); if (visible) { for (Component c : panel.getComponents()) { @@ -171,7 +165,7 @@ public class StorageTabUIHandler { } - public void initUI(final ConfigReferentielUI ui) { + public void initUI(ConfigReferentielUI ui) { if (ui.getStep() != null) { ui.setDescriptionText(t(ui.getStep().getDescription())); @@ -206,7 +200,7 @@ public class StorageTabUIHandler { } } - public void initUI(final ConfigDataUI ui) { + public void initUI(ConfigDataUI ui) { if (ui.getStep() != null) { ui.setDescriptionText(t(ui.getStep().getDescription())); @@ -280,9 +274,7 @@ public class StorageTabUIHandler { if (ui.getStep() != null) { ui.setDescriptionText(t(ui.getStep().getDescription())); } - - // customize tree selection colors - UIHelper.initUI(ui.getSelectedTreePane(), ui.getSelectTree()); + ui.getSelectTree().installUI(); } public void initUI(BackupUI ui) { @@ -317,12 +309,10 @@ public class StorageTabUIHandler { } public void chooseBackupFile(BackupUI ui) { - File f = UIHelper.chooseDirectory( - ui, - t("observe.title.choose.db.dump.directory"), - t("observe.action.choose.db.dump.directory"), - new File(ui.getDirectoryText().getText()) - ); + File f = UIHelper.chooseDirectory(ui, + t("observe.title.choose.db.dump.directory"), + t("observe.action.choose.db.dump.directory"), + new File(ui.getDirectoryText().getText())); if (f != null) { changeDirectory(ui, f); } @@ -392,59 +382,38 @@ public class StorageTabUIHandler { } public void chooseDumpFile(ConfigUI ui) { - File f = UIHelper.chooseFile( - ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); ui.getModel().setDumpFile(f); } public void chooseDumpFile(ConfigReferentielUI ui) { - File f = UIHelper.chooseFile( - ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); ui.getCentralSourceModel().setDumpFile(f); ui.getModel().validate(); } public void chooseDumpFile(ConfigDataUI ui) { - File f = UIHelper.chooseFile( - ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); ui.getCentralSourceModel().setDumpFile(f); ui.getModel().validate(); } - public void initTree(SelectDataUI ui, ObserveSwingDataSource source) { - StorageUIModel model = ui.getModel(); - if (model.isUseSelectData()) { - - DataSelectionModel dataModel = model.getSelectDataModel(); - ObserveTreeHelper helper = new ObserveTreeHelper(); - JTree tree = ui.selectTree; - helper.setUI(tree, false, null); - - tree.setModel(helper.createModel(ui, dataModel, source)); - DataSelectionTreeSelectionModel selectionModel = - ui.getSelectionModel(); - selectionModel.initUI(tree); - selectionModel.setDataModel(dataModel); - } - } - - protected String updateInternalDumpModeLabel(ChooseDbModeUI ui, - boolean dumpExist) { + protected String updateInternalDumpModeLabel(boolean dumpExist) { File f = ObserveSwingApplicationContext.get().getConfig().getInitialDbDump(); String text; if (f.exists()) { @@ -455,11 +424,6 @@ public class StorageTabUIHandler { return I18nEnumHelper.getLabel(CreationMode.IMPORT_INTERNAL_DUMP) + text; } - protected String updateCanMigrateLabel(ChooseDbModeUI ui, - boolean canMigrate) { - return t("observe.storage.action.canMigrate", ui.getModel().getModelVersion()); - } - public void obtainRemoteConnexion(ConfigReferentielUI ui) { StorageUIModel sourceModel = ui.getCentralSourceModel(); StorageUILauncher.obtainRemoteConnexion( @@ -513,10 +477,7 @@ public class StorageTabUIHandler { ui.getModel().validate(); } - public String updateStorageLabel(StorageUIModel service, - boolean serviceValid, - JLabel label, - boolean remote) { + public String updateStorageLabel(StorageUIModel service, boolean serviceValid, JLabel label, boolean remote) { String text; if (serviceValid && remote == service.isRemote()) { @@ -530,9 +491,7 @@ public class StorageTabUIHandler { return text; } - protected String updateDataSourcePolicy(StorageUIModel sourceModel, - boolean valid, - boolean remote) { + protected String updateDataSourcePolicy(StorageUIModel sourceModel, boolean valid, boolean remote) { String text = null; if (valid && remote == sourceModel.isRemote()) { ObserveDataSourceInformation dataSourceInformation = sourceModel.getDataSourceInformation(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/DataSelectionTreeSelectionModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/DataSelectionTreeSelectionModel.java deleted file mode 100644 index 4bb8039..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/DataSelectionTreeSelectionModel.java +++ /dev/null @@ -1,709 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree; - -import com.google.common.collect.Sets; -import fr.ird.observe.application.swing.ui.tree.node.AbstrctReferenceNodeSupport; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; -import fr.ird.observe.services.dto.AbstractReference; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTree; -import javax.swing.event.EventListenerList; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.RowMapper; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Modèle de sélection dans un arbre de navigation prévu pour sélectionner des - * données. - * - * La sélection se fait en cliquant (reclic pour supprimer). - * - * Si on sélectionne un program, alors ses marée sont aussi sélectionnées. - * - * Un program est sélectionné uniquement si toutes ses marées le sont. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public class DataSelectionTreeSelectionModel implements TreeSelectionModel, PropertyChangeListener, Serializable { - - /** Logger */ - private static final Log log = - LogFactory.getLog(DataSelectionTreeSelectionModel.class); - - private static final long serialVersionUID = -1L; - - protected DataSelectionModel dataModel; - - /** - * Paths that are currently selected. Will be null if nothing is currently - * selected. - */ - protected TreePath[] selection; - - /** Event listener list. */ - protected final EventListenerList listenerList = new EventListenerList(); - - /** Last path that was added. */ - protected TreePath leadPath; - - /** Index of the lead path in selection. */ - protected int leadIndex; - - /** Lead row. */ - protected int leadRow; - - protected int minSelectionRow; - - protected int maxSelectionRow; - - protected int[] selectionRows; - - /** Provides a row for a given path. */ - transient protected RowMapper rowMapper; - - protected Set<TreePath> universe; - - private PropertyChangeSupport changeSupport; - - private static final PropertyChangeListener[] - EMPTY_PROPERTY_CHANGE_LISTENERS = new PropertyChangeListener[]{}; - - public void initUI(JTree tree) { - clearSelection(); - if (universe != null) { - universe.clear(); - } - // expand tree - int i = 0; - while (i < tree.getRowCount()) { - tree.expandRow(i++); - } - // build universe of path : position of path in universe is - // exactly the row of the path - int count = tree.getRowCount(); - universe = new HashSet<>(count); - for (i = 0; i < count; i++) { - TreePath path = tree.getPathForRow(i); - universe.add(path); - if (log.isDebugEnabled()) { - log.debug("init path : " + path.getLastPathComponent()); - } - } - } - - public void setDataModel(DataSelectionModel dataModel) { - DataSelectionModel oldModel = this.dataModel; - if (oldModel != null) { - oldModel.removePropertyChangeListener(this); - oldModel.destroy(); - //TODO Should destroy all other listeners ? - //TODO this means model is dead... - } - this.dataModel = dataModel; - if (dataModel != null) { - this.dataModel.addPropertyChangeListener(this); - } - updateModel(); - } - - @Override - public void setSelectionMode(int mode) { - // pas utilise - } - - @Override - public int getSelectionMode() { - return DISCONTIGUOUS_TREE_SELECTION; - } - - @Override - public void setSelectionPath(TreePath path) { - if (dataModel == null) { - return; - } - Object o = path.getLastPathComponent(); - ObserveNode node = AbstractObserveTreeCellRenderer.getNode(o); - if (node == null) { - return; - } - Class<?> internalClass = node.getInternalClass(); - - boolean referentiel = node.isReferentielNode(); - - if (!universe.contains(path)) { - // new path - universe.add(path); - if (log.isDebugEnabled()) { - log.debug("add new path to universe " + - path.getLastPathComponent()); - } - if (!referentiel && ProgramDto.class.equals(internalClass)) { - if (log.isDebugEnabled()) { - log.debug("Adding program childs path (" + - node.getChildCount() + ")"); - } - // on ajoute toutes les marees du program - Enumeration<?> childs = node.children(); - while (childs.hasMoreElements()) { - Object o1 = childs.nextElement(); - TreePath path1 = path.pathByAddingChild(o1); - if (!universe.contains(path1)) { - if (log.isDebugEnabled()) { - log.debug("adding path for node " + o1); - } - universe.add(path1); - } - } - } - if (TripSeineDto.class.equals(internalClass)) { - TreePath parentPath = path.getParentPath(); - - if (!universe.contains(parentPath)) { - // on ajoute son parent (et tous ses freres) - universe.add(parentPath); - ObserveNode parentNode = node.getParent(); - if (log.isDebugEnabled()) { - log.debug("Adding program with his childs (" + - parentNode.getChildCount() + ")"); - } - Enumeration<?> childs = parentNode.children(); - while (childs.hasMoreElements()) { - Object o1 = childs.nextElement(); - TreePath path1 = parentPath.pathByAddingChild(o1); - if (!universe.contains(path1)) { - if (log.isDebugEnabled()) { - log.debug("adding path for node " + o1); - } - universe.add(path1); - } - } - } - } - } - - boolean pathSelected = isPathSelected(path); - - if (log.isDebugEnabled()) { - log.debug("node " + node + ", path selected ? " + pathSelected); - } - - if (referentiel && node.isStringNode()) { - - Set<Class<? extends ReferentialDto>> subClasses = Sets.newHashSet(); - - for (Enumeration<ObserveNode> children = node.children(); children.hasMoreElements(); ) { - subClasses.add((Class<? extends ReferentialDto>) children.nextElement().getInternalClass()); - } - - if (pathSelected) { - if (log.isDebugEnabled()) { - log.debug("Will remove all referentiels on " + node); - } - dataModel.removeAllReferentiel(subClasses); - } else { - if (log.isDebugEnabled()) { - log.debug("Will add all referentiels on " + node); - } - dataModel.addAllReferentiel(subClasses); - } - return; - } - - if (referentiel) { - - if (pathSelected) { - if (log.isDebugEnabled()) { - log.debug("Will remove referentiel " + internalClass + " to model"); - } - dataModel.removeSelectedReferentiel(internalClass); - } else { - if (log.isDebugEnabled()) { - log.debug("Will add referentiel " + internalClass + " to model"); - } - dataModel.addSelectedReferentiel((Class<? extends ReferentialDto>) internalClass); - } - return; - } - - if (node instanceof AbstrctReferenceNodeSupport) { - AbstractReference dto = ((AbstrctReferenceNodeSupport) node).getEntity(); - if (log.isDebugEnabled()) { - log.debug("bean " + dto.getId()); - } - if (pathSelected) { - if (log.isDebugEnabled()) { - log.debug("Already add ? remove it."); - } - removeFromDataModel(dto); - } else { - if (log.isDebugEnabled()) { - log.debug("Will add selection to model"); - } - addToDataModel(dto); - } - } - } - - @Override - public void setSelectionPaths(TreePath[] paths) { - // do nothing - } - - @Override - public void addSelectionPath(TreePath path) { - // do nothing - } - - @Override - public void addSelectionPaths(TreePath[] paths) { - // do nothing - } - - @Override - public void removeSelectionPath(TreePath path) { - // do nothing - } - - @Override - public void removeSelectionPaths(TreePath[] paths) { - // do nothing - } - - @Override - public TreePath getSelectionPath() { - return selection == null ? null : selection[0]; - } - - @Override - public TreePath[] getSelectionPaths() { - return selection; - } - - @Override - public int getSelectionCount() { - return selection == null ? 0 : selection.length; - } - - @Override - public boolean isPathSelected(TreePath path) { - if (dataModel == null) { - return false; - } - Object o = path.getLastPathComponent(); - ObserveNode node = AbstractObserveTreeCellRenderer.getNode(o); - if (node != null) { - - Class<?> internalClass = node.getInternalClass(); - if (node.isReferentielNode() && node.isStringNode()) { - Set<Class<? extends ReferentialDto>> subClasses = Sets.newHashSet(); - - for (Enumeration<ObserveNode> children = node.children(); children.hasMoreElements(); ) { - subClasses.add((Class<? extends ReferentialDto>) children.nextElement().getInternalClass()); - } - - boolean result = dataModel.isReferentielSelectAll(subClasses); - if (log.isTraceEnabled()) { - log.trace("selectModel use full referentiel " + - internalClass + " ? " + result); - } - return result; - } - if (node.isReferentielNode()) { - boolean result = dataModel.isSelectedReferentiel(internalClass); - if (log.isTraceEnabled()) { - log.trace("selectModel use referentiel " + - internalClass + " ? " + result); - } - return result; - } - - if (log.isTraceEnabled()) { - log.trace("begin data node " + node); - } - - if (node instanceof AbstrctReferenceNodeSupport) { - boolean result = dataModel.isSelectedData(((AbstrctReferenceNodeSupport) node).getEntity()); - if (log.isTraceEnabled()) { - log.trace("selectModel contains the program ? " + result); - } - return result; - } - - - } - return false; - } - - @Override - public boolean isSelectionEmpty() { - return selection == null || selection.length == 0; - } - - @Override - public void clearSelection() { - if (dataModel == null) { - return; - } - selection = null; - dataModel.removeAll(); - } - - @Override - public RowMapper getRowMapper() { - return rowMapper; - } - - @Override - public void setRowMapper(RowMapper newMapper) { - rowMapper = newMapper; - } - - @Override - public int[] getSelectionRows() { - // on doit recalcule cette valeur a chaque fois - //This is currently rather expensive.Needs - // to be better support from ListSelectionModel to speed this up. - return selectionRows; - } - - @Override - public int getMinSelectionRow() { - return minSelectionRow; - } - - @Override - public int getMaxSelectionRow() { - return maxSelectionRow; - } - - @Override - public int getLeadSelectionRow() { - return leadRow; - } - - @Override - public TreePath getLeadSelectionPath() { - return leadPath; - } - - @Override - public boolean isRowSelected(int row) { - if (!isSelectionEmpty()) { - for (int i : selectionRows) { - if (row == i) { - return true; - } - } - } - return false; - } - - @Override - public void resetRowSelection() { - if (log.isDebugEnabled()) { - log.debug("start rebuild row values..."); - } - leadRow = minSelectionRow = maxSelectionRow = -1; - selectionRows = null; - if (rowMapper == null || selection == null || selection.length == 0) { - return; - } - - int[] rows = rowMapper.getRowsForPaths(selection); - - if (rows != null) { - int invisCount = 0; - - for (int counter = rows.length - 1; counter >= 0; counter--) { - if (rows[counter] == -1) { - invisCount++; - } - } - if (invisCount > 0) { - if (invisCount == rows.length) { - rows = null; - } else { - int[] tempRows = new int[rows.length - invisCount]; - - for (int counter = rows.length - 1, visCounter = 0; - counter >= 0; counter--) { - if (rows[counter] != -1) { - tempRows[visCounter++] = rows[counter]; - } - } - rows = tempRows; - } - } - } - - selectionRows = rows; - - if (isSelectionEmpty()) { - leadPath = null; - leadIndex = -1; - leadRow = -1; - } else { - leadPath = selection[0]; - leadIndex = 0; - leadRow = selectionRows[0]; - } - - int selectionLength = selectionRows.length; - - minSelectionRow = -1; - maxSelectionRow = 0; - for (int i = 0; i < selectionLength; i++) { - int row = selectionRows[i]; - if (row > maxSelectionRow) { - maxSelectionRow = row; - } - if (row < minSelectionRow) { - minSelectionRow = row; - } - } - } - - /** - * Adds x to the list of listeners that are notified each time the set of - * selected TreePaths changes. - * - * @param x the new listener to be added - */ - @Override - public void addTreeSelectionListener(TreeSelectionListener x) { - listenerList.add(TreeSelectionListener.class, x); - } - - /** - * Removes x from the list of listeners that are notified each time the set - * of selected TreePaths changes. - * - * @param x the listener to remove - */ - @Override - public void removeTreeSelectionListener(TreeSelectionListener x) { - listenerList.remove(TreeSelectionListener.class, x); - } - - /** - * Returns an array of all the tree selection listeners registered on this - * model. - * - * @return all of this model's {@code TreeSelectionListener}s or an - * empty array if no tree selection listeners are currently - * registered - * @see #addTreeSelectionListener - * @see #removeTreeSelectionListener - * @since 1.4 - */ - public TreeSelectionListener[] getTreeSelectionListeners() { - return listenerList.getListeners(TreeSelectionListener.class); - } - - /** - * Adds a PropertyChangeListener to the listener list. The listener is - * registered for all properties. - * - * A PropertyChangeEvent will get fired when the selection mode changes. - * - * @param listener the PropertyChangeListener to be added - */ - @Override - public void addPropertyChangeListener(PropertyChangeListener listener) { - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(listener); - } - - /** - * Removes a PropertyChangeListener from the listener list. This removes a - * PropertyChangeListener that was registered for all properties. - * - * @param listener the PropertyChangeListener to be removed - */ - - @Override - public void removePropertyChangeListener(PropertyChangeListener listener) { - if (changeSupport == null) { - return; - } - changeSupport.removePropertyChangeListener(listener); - } - - /** - * Returns an array of all the property change listeners registered on this - * {@code DefaultTreeSelectionModel}. - * - * @return all of this model's {@code PropertyChangeListener}s or an - * empty array if no property change listeners are currently - * registered - * @see #addPropertyChangeListener - * @see #removePropertyChangeListener - * @since 1.4 - */ - public PropertyChangeListener[] getPropertyChangeListeners() { - if (changeSupport == null) { - return EMPTY_PROPERTY_CHANGE_LISTENERS; - } - return changeSupport.getPropertyChangeListeners(); - } - - protected void fireValueChanged(TreeSelectionEvent e) { - // Guaranteed to return a non-null array - Object[] listeners = listenerList.getListenerList(); - // TreeSelectionEvent e = null; - // Process the listeners last to first, notifying - // those that are interested in this event - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (TreeSelectionListener.class.equals(listeners[i])) { - // Lazily create the event: - // if (e == null) - // e = new ListSelectionEvent(this, firstIndex, lastIndex); - ((TreeSelectionListener) listeners[i + 1]).valueChanged(e); - } - } - } - - protected void addToDataModel(AbstractReference dto) { - - if (log.isTraceEnabled()) { - log.trace("selectModel add " + dto.getId()); - } - dataModel.addSelectedData(dto); - - } - - protected void removeFromDataModel(AbstractReference dto) { - if (log.isTraceEnabled()) { - log.trace("selectModel remove " + dto.getId()); - } - dataModel.removeSelectedData(dto); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String propertyName = evt.getPropertyName(); - if (DataSelectionModel.PROPERTY_SELECTED_DATA.equals(propertyName) || - DataSelectionModel.PROPERTY_SELECTED_REFERENTIEL.equals(propertyName)) { - // la selection a changee - Object value = evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("selection data changed " + value); - } - } - updateModel(); - } - - protected void updateModel() { - if (rowMapper == null || universe == null) { - return; - } - - // recalcule de la selection - - List<TreePath> oldSelection = isSelectionEmpty() ? - Collections.emptyList() : - Arrays.asList(selection); - - List<TreePath> newSelection = new ArrayList<>(); - - for (TreePath p : universe) { - if (isPathSelected(p)) { - newSelection.add(p); - } - } - - int selectionLength = newSelection.size(); - - selection = newSelection.toArray(new TreePath[selectionLength]); - - // calcul du leadPath - - TreePath oldLeadPath = leadPath; - - if (isSelectionEmpty()) { - leadPath = null; - leadIndex = -1; - } else { - leadPath = selectionLength > 0 ? selection[0] : null; - leadIndex = 0; - } - - if (log.isDebugEnabled()) { - log.debug("new selection length = " + selectionLength); - } - - // recalcule des donnees de rows - resetRowSelection(); - - if (log.isDebugEnabled()) { - log.debug("new selection length = " + - (selectionRows == null ? 0 : selectionRows.length)); - if (log.isDebugEnabled()) { - log.debug("selected rows = " + Arrays.toString(selectionRows)); - } - } - - // calcule des paths qui ont changés - List<TreePath> obsoleteSelection = new ArrayList<>(oldSelection); - obsoleteSelection.removeAll(newSelection); - - List<TreePath> changedPaths = new ArrayList<>(oldSelection); - changedPaths.addAll(newSelection); - - TreePath[] treePaths = changedPaths.toArray(new TreePath[changedPaths.size()]); - - // notification des modifications sur la selection - TreeSelectionEvent event = new TreeSelectionEvent( - this, - treePaths, - new boolean[treePaths.length], - oldLeadPath, - leadPath - ); - fireValueChanged(event); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/NavigationTreeSelectionModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/NavigationTreeSelectionModel.java deleted file mode 100644 index 92cca8e..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/NavigationTreeSelectionModel.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.UIHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.DefaultTreeSelectionModel; -import javax.swing.tree.TreePath; - -/** - * Le modèle de sélection de l'abre de navigation. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class NavigationTreeSelectionModel extends DefaultTreeSelectionModel { - - /** Logger */ - static private final Log log = LogFactory.getLog(NavigationTreeSelectionModel.class); - - private static final long serialVersionUID = 1L; - - @Override - public void addSelectionPath(TreePath newPath) { - TreePath oldPath = getSelectionPath(); - if (log.isDebugEnabled()) { - log.debug(">------------------------------------------------------------------------------"); - log.debug("Try to change selection"); - log.debug("old path " + oldPath); - log.debug("new path " + newPath); - } - boolean canChange = beforeSelectionPath(oldPath, newPath); - if (log.isDebugEnabled()) { - log.debug("Can change path ? " + canChange); - log.debug("<------------------------------------------------------------------------------"); - } - if (!canChange) { - return; - } - - // ok can safely select the new path - if (log.isTraceEnabled()) { - log.trace("will select path " + newPath); - } - super.addSelectionPath(newPath); - } - - @Override - public void setSelectionPath(TreePath newPath) { - TreePath oldPath = getSelectionPath(); - if (log.isDebugEnabled()) { - log.debug(">------------------------------------------------------------------------------"); - log.debug("Try to change selection"); - log.debug("old path " + oldPath); - log.debug("new path " + newPath); - } - boolean canChange = beforeSelectionPath(oldPath, newPath); - if (log.isDebugEnabled()) { - log.debug("Can change path ? " + canChange); - log.debug("<------------------------------------------------------------------------------"); - } - if (!canChange) { - return; - } - - // ok can safely select the new path - if (log.isTraceEnabled()) { - log.trace("will select path " + newPath); - } - try { - super.setSelectionPath(newPath); - } catch (Exception e) { - UIHelper.handlingError(e); - } - } - - protected boolean beforeSelectionPath(TreePath oldPath, TreePath newPath) { - - boolean canChange = true; - - if (newPath.equals(oldPath)) { - // stay on same node, can skip - if (log.isDebugEnabled()) { - log.debug("skip stay on path " + newPath); - } - canChange = false; - } - - if (canChange && !isSelectionEmpty()) { - canChange = ObserveSwingApplicationContext.get().getContentUIManager().closeSelectedContentUI(); - } - - return canChange; - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveDataProvider.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveDataProvider.java deleted file mode 100644 index ff61d4a..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveDataProvider.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree; - -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import jaxx.runtime.swing.nav.NavDataProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Provider de données pour les noeuds des arbres. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ObserveDataProvider implements NavDataProvider { - - /** Logger */ - static private final Log log = LogFactory.getLog(ObserveDataProvider.class); - - protected ObserveSwingDataSource dataSource; - - protected DataSelectionModel selectionModel; - - private boolean creating; - - public ObserveDataProvider(ObserveSwingDataSource dataSource) { - this.dataSource = dataSource; - } - - public void setSource(ObserveSwingDataSource dataSource) { - this.dataSource = dataSource; - } - - public void setSelectionModel(DataSelectionModel selectionModel) { - if (log.isDebugEnabled()) { - log.debug("Set selection model : " + selectionModel); - } - this.selectionModel = selectionModel; - } - - @Override - public boolean isEnabled() { - return dataSource != null && dataSource.isOpen() || selectionModel != null; - } - - public ObserveSwingDataSource getDataSource() { - return dataSource; - } - - public DataSelectionModel getSelectionModel() { - return selectionModel; - } - - public boolean isCreating() { - return creating; - } - - public void setCreating(boolean creating) { - this.creating = creating; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java index 3c4b1a5..9010e0e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java @@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableMap; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.db.DataContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI; import fr.ird.observe.application.swing.ui.tree.menu.MoveActivityLonglineNodeMenuPopulator; @@ -35,8 +34,15 @@ import fr.ird.observe.application.swing.ui.tree.menu.MoveActivitySeineNodeMenuPo import fr.ird.observe.application.swing.ui.tree.menu.MoveNodeMenuPopulator; import fr.ird.observe.application.swing.ui.tree.menu.MoveRouteNodeMenuPopulator; import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.seine.ActivitySeineDto; +import fr.ird.observe.services.dto.seine.RouteDto; +import fr.ird.observe.services.dto.seine.TripSeineDto; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,7 +51,6 @@ import javax.swing.JButton; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; -import javax.swing.JTree; import javax.swing.MenuElement; import javax.swing.SwingUtilities; import javax.swing.tree.TreePath; @@ -83,11 +88,9 @@ public class ObserveNavigationTreeShowPopupAction { n("observe.navigationMenu.move.activityLongline"); } - private final ObserveTreeHelper treeHelper; - private final JPopupMenu popup; - private final JTree tree; + private final NavigationTree tree; private final JMenuItem noAction; private final JMenuItem openAction; @@ -97,11 +100,10 @@ public class ObserveNavigationTreeShowPopupAction { private final ImmutableMap<String, MoveNodeMenuPopulator> moveNodeDataByNodeType; - public ObserveNavigationTreeShowPopupAction(ObserveTreeHelper treeHelper, JScrollPane pane, JPopupMenu popup) { + public ObserveNavigationTreeShowPopupAction(NavigationTree tree, JScrollPane pane, JPopupMenu popup) { - this.treeHelper = treeHelper; this.popup = popup; - this.tree = treeHelper.getUI(); + this.tree = tree; JMenuItem noActionComponent = null; // trip menus @@ -232,7 +234,7 @@ public class ObserveNavigationTreeShowPopupAction { log.info("Will show popup from row: " + row); } - ObserveNode selectedNode = (ObserveNode) tree.getPathForRow(row).getLastPathComponent(); + NavigationTreeNodeSupport selectedNode = (NavigationTreeNodeSupport) tree.getPathForRow(row).getLastPathComponent(); if (log.isInfoEnabled()) { log.info("Found selected node: " + selectedNode); @@ -244,7 +246,7 @@ public class ObserveNavigationTreeShowPopupAction { } - protected void beforeOpenPopup(ObserveNode selectedNode) { + protected void beforeOpenPopup(NavigationTreeNodeSupport selectedNode) { // clean popup popup.removeAll(); @@ -261,30 +263,31 @@ public class ObserveNavigationTreeShowPopupAction { closeActionEnabled = closeButton.isEnabled(); } - if (selectedNode.isTripNode()) { + Class dataType = selectedNode.getDataType(); + if (TripSeineDto.class.equals(dataType) || TripLonglineDto.class.equals(dataType)) { - beforeOpenMenu(selectedNode, TRIP_MENU_ITEMS); + beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, TRIP_MENU_ITEMS); openAction.setEnabled(!dataContext.isOpenTrip()); closeAction.setEnabled(closeActionEnabled); - } else if (selectedNode.isRouteNode()) { + } else if (RouteDto.class.equals(dataType)) { - beforeOpenMenu(selectedNode, ROUTE_MENU_ITEMS); + beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ROUTE_MENU_ITEMS); openAction.setEnabled(openDataManager.canOpenRoute(dataContext.getSelectedTripSeineId())); closeAction.setEnabled(closeActionEnabled); - } else if (selectedNode.isActivitySeineNode()) { + } else if (ActivitySeineDto.class.equals(dataType)) { - beforeOpenMenu(selectedNode, ACTIVITY_SEINE_MENU_ITEMS); + beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ACTIVITY_SEINE_MENU_ITEMS); openAction.setEnabled(openDataManager.canOpenActivitySeine(dataContext.getSelectedRouteId())); closeAction.setEnabled(closeActionEnabled); - } else if (selectedNode.isActivityLonglineNode()) { + } else if (ActivityLonglineDto.class.equals(dataType)) { - beforeOpenMenu(selectedNode, ACTIVITY_LONGLINE_MENU_ITEMS); + beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ACTIVITY_LONGLINE_MENU_ITEMS); openAction.setEnabled(openDataManager.canOpenActivityLongline(dataContext.getSelectedTripLonglineId())); closeAction.setEnabled(closeActionEnabled); @@ -295,7 +298,7 @@ public class ObserveNavigationTreeShowPopupAction { } } - protected void beforeOpenMenu(ObserveNode selectedNode, String nodeType) { + protected void beforeOpenMenu(ReferenceNavigationTreeNodeSupport selectedNode, String nodeType) { if (log.isInfoEnabled()) { log.info("Will load popup for " + nodeType + " node."); } @@ -328,9 +331,7 @@ public class ObserveNavigationTreeShowPopupAction { String id = selectedNode.getId(); - ObserveSwingDataSource dataSource = treeHelper.getDataProvider().getDataSource(); - - List<DecoratedNodeEntity> possibleParentNodes = moveNodeData.getPossibleParentNodes(selectedNode, treeHelper); + List<DecoratedNodeEntity> possibleParentNodes = moveNodeData.getPossibleParentNodes(selectedNode); for (DecoratedNodeEntity possibleParent : possibleParentNodes) { @@ -339,10 +340,7 @@ public class ObserveNavigationTreeShowPopupAction { item.setName(possibleParentId); - item.addActionListener(moveNodeData.createChangeActionListener(treeHelper, - dataSource, - id, - possibleParentId)); + item.addActionListener(moveNodeData.createChangeActionListener(tree, id, possibleParentId)); moveAction.add(item); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeBridge.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeBridge.java deleted file mode 100644 index 6f406ec..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeBridge.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree; - -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import jaxx.runtime.swing.nav.tree.NavTreeBridge; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTree; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Bridge specialise pour reduire le count de chargements de noeuds non visibles. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.0 - */ -public class ObserveTreeBridge extends NavTreeBridge<ObserveNode> { - - /** Logger. */ - static private final Log log = LogFactory.getLog(ObserveTreeBridge.class); - - protected JTree ui; - - protected final List<String> pathToSelect; - - public ObserveTreeBridge() { - pathToSelect = new ArrayList<>(); - } - - public void setUi(JTree ui) { - this.ui = ui; - } - - @Override - public boolean canLoadChild(ObserveNode node) { - - ObserveNode root = getRoot(); - if (node.equals(root)) { - - // always allow to load childs from level 0 - return true; - } - ObserveNode parent = node.getParent(); - if (parent.equals(root)) { - - // always allow to load childs from level 0 - return true; - } - - TreeNode[] pathToRoot = getPathToRoot(node); - TreePath path = new TreePath(pathToRoot); - if (CollectionUtils.isNotEmpty(pathToSelect)) { - - // select mode is on - if (log.isDebugEnabled()) { - log.debug("There is a selected path, try to use it for " + node); - } - String nodeId = node.getId(); - - ObserveNode containerNode; - if (nodeId.startsWith("observe.type.")) { - containerNode = node.getParent(); - } else { - containerNode = node; - } - - String containerNodeId = containerNode.getId(); - if (log.isDebugEnabled()) { - log.debug("Test if data node is in path ? " + - containerNodeId + " : " + - pathToSelect.contains(containerNodeId)); - } - - if (pathToSelect.contains(containerNodeId)) { - - // ok on the good way... - return true; - } - - // not on a good way, skip loading of childs... - return false; - } - - if (ui == null) { - if (log.isDebugEnabled()) { - log.debug("No ui in bridge!!!"); - } - - // no ui, and no path to select : so no need to restrict - return true; - } - - boolean visible = ui.isVisible(path); - - if (!visible) { - - // only visible node can be loaded - return false; - } - - TreePath selected = ui.getSelectionPath(); - if (!path.equals(selected)) { - - // only selected node can be loaded - return false; - } - - // ok childs can be loaded - return true; - } - - public void setPathToSelect(String... pathToSelect) { - this.pathToSelect.clear(); - this.pathToSelect.addAll(Arrays.asList(pathToSelect)); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeHelper.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeHelper.java deleted file mode 100644 index 711f93a..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeHelper.java +++ /dev/null @@ -1,625 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimaps; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.DataContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivityLonglineNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivityLonglinesNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivitySeineNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivitySeinesNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.ProgramLonglineNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.ProgramSeineNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.RootNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.loadors.RoutesNodeChildLoador; -import fr.ird.observe.application.swing.ui.tree.node.AbstrctReferenceNodeSupport; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.application.swing.ui.tree.renderer.AbstractObserveTreeCellRenderer; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.IdDto; -import fr.ird.observe.services.dto.constants.ReferentialLocale; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.SetLonglineDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.reference.ReferenceBinderEngine; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.FloatingObjectDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.SetSeineDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import jaxx.runtime.JAXXContext; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeHelper; -import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTree; -import javax.swing.SwingUtilities; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeCellRenderer; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import static org.nuiton.i18n.I18n.n; - -/** - * Class utilitaire pour la bestion de l'arbre de navigation. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { - - /** Logger. */ - static private final Log log = LogFactory.getLog(ObserveTreeHelper.class); - - public static void sortPrograms(List<ReferentialReference<ProgramDto>> data) { - - ObserveSwingApplicationContext.get().getDecoratorService().sort(ProgramDto.class, data); - - } - - public ObserveTreeHelper() { - super(new ObserveTreeBridge()); - } - - public NavigationTreeSelectionModel newNavigationSelectionModel() { - NavigationTreeSelectionModel model = new NavigationTreeSelectionModel(); - model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - return model; - } - - public AbstractObserveTreeCellRenderer getTreeCellRenderer() { - JTree t = getUI(); - if (t == null) { - return null; - } - TreeCellRenderer r = t.getCellRenderer(); - return (AbstractObserveTreeCellRenderer) (r instanceof AbstractObserveTreeCellRenderer ? r : null); - } - - public TreeModel createEmptyModel() { - - setDataSource(null); - - ObserveNode node = new ObserveNode(n("observe.message.db.none.loaded"), false); - - return createModel(node); - } - - public TreeModel createModel(ObserveSwingDataSource source) { - - setDataSource(source); - - ObserveDataProvider provider = getDataProvider(); - provider.setCreating(true); - - try { - - RootNodeChildLoador loador = new RootNodeChildLoador(source.canReadData(), true); - ObserveNode node = new ObserveNode(String.class, "Root node", null, loador, false); - - DefaultTreeModel model = createModel(node); - node.populateChilds(getBridge(), provider); - - if (source.canReadData()) { - // on va charger en une seule fois tous les nœuds des marées - ImmutableSet<DataReference<TripSeineDto>> tripsSeine = source.newTripSeineService().getAllTripSeine().getReferences(); - if (log.isInfoEnabled()) { - log.info("[PS] Loaded " + tripsSeine.size() + " trip(s)."); - } - ImmutableSet<DataReference<TripLonglineDto>> tripsLongline = source.newTripLonglineService().getAllTripLongline().getReferences(); - if (log.isInfoEnabled()) { - log.info("[LL] Loaded " + tripsLongline.size() + " trip(s)."); - } - ImmutableListMultimap<String, DataReference<TripSeineDto>> tripsSeineByProgramId = Multimaps.index(tripsSeine, r -> (String) r.getPropertyValue(TripSeineDto.PROPERTY_PROGRAM + "Id")); - ImmutableListMultimap<String, DataReference<TripLonglineDto>> tripsLonglineByProgramId = Multimaps.index(tripsLongline, r -> (String) r.getPropertyValue(TripSeineDto.PROPERTY_PROGRAM + "Id")); - - Enumeration<ObserveNode> children = node.children(); - while (children.hasMoreElements()) { - ObserveNode observeNode = children.nextElement(); - if (observeNode instanceof ProgramSeineNode) { - ProgramSeineNode programNode = (ProgramSeineNode) observeNode; - String programId = programNode.getEntity().getId(); - ImmutableList<DataReference<TripSeineDto>> trips = tripsSeineByProgramId.get(programId); - ImmutableMap<String, DataReference<TripSeineDto>> tripsById = Maps.uniqueIndex(trips, DataReference::getId); - if (CollectionUtils.isNotEmpty(trips)) { - if (log.isInfoEnabled()) { - log.info("[PS] Add " + trips.size() + " trips to " + programNode); - } - programNode.populateChilds(trips, getBridge(), provider); - Enumeration<ObserveNode> tripNodes = programNode.children(); - while (tripNodes.hasMoreElements()) { - TripSeineNode tripNode = (TripSeineNode) tripNodes.nextElement(); - String tripId = tripNode.getEntity().getId(); - DataReference<TripSeineDto> tripDto = tripsById.get(tripId); - int routeCount = (int) tripDto.getPropertyValue(TripSeineDto.PROPERTY_ROUTE_COUNT); - tripNode.setInitialRouteCount(routeCount); - } - } - } - if (observeNode instanceof ProgramLonglineNode) { - ProgramLonglineNode programNode = (ProgramLonglineNode) observeNode; - String programId = programNode.getEntity().getId(); - ImmutableList<DataReference<TripLonglineDto>> trips = tripsLonglineByProgramId.get(programId); - if (CollectionUtils.isNotEmpty(trips)) { - if (log.isInfoEnabled()) { - log.info("[LL] Add " + trips.size() + " trips to " + programNode); - } - programNode.populateChilds(trips, getBridge(), provider); - } - } - } - } - return model; - - } finally { - - provider.setCreating(false); - - } - } - - public DefaultTreeModel createModel(JAXXContext context, - DataSelectionModel dataModel, - ObserveSwingDataSource source) { - - setDataSource(source); - context.setContextValue(dataModel); - - if (log.isDebugEnabled()) { - log.debug("create tree model " + this); - } - - ObserveDataProvider provider = getDataProvider(); - provider.setSelectionModel(dataModel); - provider.setCreating(true); - - try { - - RootNodeChildLoador loador = getChildLoador(RootNodeChildLoador.class); - loador.setAddData(dataModel.isUseData()); - loador.setAddReferentiel(dataModel.isUseReferentiel()); - ObserveNode node = new ObserveNode(String.class, "Root node", loador, false); - - DefaultTreeModel model = createModel(node); - loadAllNodes(node, provider); - return model; - - } finally { - - provider.setCreating(false); - - } - - } - - /** - * Charge dans l'ui un nouveau modèle de navigation. - * - * <b>Note:</b> cette méthode doit être appelée après tout rechargement de - * modèle de naivgation. - * - * @param source la source de données - */ - public void loadNavigationUI(ObserveSwingDataSource source) { - - ObserveNode.count = 0; - - // propagate ui in observe bridge to control which nodes can be loads - // from ui state - getBridge().setUi(getUI()); - - // build navigation model - createModel(source); - - // select initial node - selectInitialNode(); - - getUI().setVisible(true); - } - - /** - * Nettoye des ui tout ce qui concerne un modèle de navigation. - * - * <b>Note:</b> cette méthode doit être appelée avant tout rechargement de - * modèle de naivgation. - * - * @param mainUI l'ui principale - */ - public void cleanNavigationUI(ObserveMainUI mainUI) { - - // invalidate provider - setDataSource(null); - - // reset content uis - mainUI.getContentLayout().reset(mainUI.getContent()); - - // clean messages - mainUI.getContextValue(SwingValidatorMessageTableModel.class).clear(); - - // clean tree model - - JTree tree = getUI(); - - // remove tree from bridge to disable propagation of any node - getBridge().setUi(null); - - ObserveNode root = getBridge().getRoot(); - root.removeAllChildren(); - createEmptyModel(); - - // no tree navigation view - tree.setVisible(false); - } - - public void selectOpenNode(Class<?> type) { - - DataContext context = ObserveSwingApplicationContext.get().getDataContext(); - - String[] ids = context.getOpenIds(type); - - if (log.isDebugEnabled()) { - log.debug("using open ids = " + Arrays.toString(ids)); - } - if (ids == null) { - - // rien n'est ouvert, rien à selectionner - return; - } - - selectNode(ids); - } - - /** - * Sélectionne le noeud dans l'arbre de navigation. - * - * <b>Note:</b> cette méthode doit être appelée après un rechargement du - * modèle de navigation. - */ - public void selectInitialNode() { - - if (log.isDebugEnabled()) { - log.debug("Will select initial node..."); - } - DataContext context = ObserveSwingApplicationContext.get().getDataContext(); - - String[] path; - - JTree tree = getUI(); - - List<String> selectedIds = ObserveSwingApplicationContext.get().getNodesToReselect(); - if (CollectionUtils.isNotEmpty(selectedIds)) { - if (log.isDebugEnabled()) { - log.debug("will select previous ids " + selectedIds); - } - path = selectedIds.toArray(new String[selectedIds.size()]); - } else { - - // on trouve le meilleur noeud a selectionner. - - String id = context.getHigherOpenId(); - - if (id != null) { - - // on se positionne sur la donnée la plus haute ouverte - path = context.getOpenIds(); - if (log.isDebugEnabled()) { - log.debug("will select open ids " + Arrays.toString(path)); - } - } else { - - // on selectionne le premier noeud de $root - - ObserveNode node = (ObserveNode) tree.getModel().getRoot(); - if (!node.isLeaf()) { - node = node.getFirstChild(); - } - path = new String[]{node.getId()}; - if (log.isDebugEnabled()) { - log.debug("will select first program " + Arrays.toString(path)); - } - } - } - - if (log.isDebugEnabled()) { - log.debug("Selected path : " + Arrays.toString(path)); - } - - try { - - selectNode(path); - } finally { - - // nettoyage du context - ObserveSwingApplicationContext.get().setNodesToReselect(null); - } - - // navigation tree should acquire focus - SwingUtilities.invokeLater(tree::grabFocus); - } - - @Override - public void selectNode(String... path) { - long count = ObserveNode.count; - if (log.isDebugEnabled()) { - log.debug("Will select path : " + Arrays.toString(path)); - } - getBridge().setPathToSelect(path); - try { - super.selectNode(path); - } finally { - getBridge().setPathToSelect(); - if (log.isInfoEnabled()) { - log.info("Creates " + (ObserveNode.count - count) + " nodes to select path " + Arrays.toString(path)); - } - } - } - - public ObserveNode addUnsavedNode(ObserveNode parentNode, Class<?> type) { - - // noeud en mode creation - String label = ObserveI18nDecoratorHelper.getTypeI18nKey(type) + ".unsaved"; - ObserveNode result = new ObserveNode(type, null, label, null, false); - insertNode(parentNode, result); - - // refresh parent node (render of parent can have changed) - refreshNode(parentNode, true); - - // Fix bug (if no child in parent node, it will not expand...) - getUI().fireTreeExpanded(new TreePath(result.getPath())); - - // Select new node - selectNode(result); - - return result; - } - - public <E extends IdDto> ObserveNode addOpenable(ObserveNode parentNode, E bean) { - - ReferenceBinderEngine referenceBinderEngine = ObserveSwingApplicationContext.get().getReferenceBinderEngine(); - ReferentialLocale referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); - if (bean instanceof TripSeineDto) { - - DataReference<TripSeineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (TripSeineDto) bean); - return addTripSeine(parentNode, ref); - - } else if (bean instanceof TripLonglineDto) { - - DataReference<TripLonglineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (TripLonglineDto) bean); - return addTripLongline(parentNode, ref); - - } else if (bean instanceof RouteDto) { - - DataReference<RouteDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (RouteDto) bean); - return addRoute(parentNode, ref); - - } else if (bean instanceof ActivitySeineDto) { - - DataReference<ActivitySeineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (ActivitySeineDto) bean); - return addActivitySeine(parentNode, ref); - - } else if (bean instanceof ActivityLonglineDto) { - - DataReference<ActivityLonglineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (ActivityLonglineDto) bean); - return addActivityLongline(parentNode, ref); - - } - throw new IllegalStateException("Can not come here!"); - } - - private ObserveNode addTripSeine(ObserveNode parentNode, DataReference<TripSeineDto> bean) { - ProgramSeineNodeChildLoador loador = - getChildLoador(ProgramSeineNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - private ObserveNode addTripLongline(ObserveNode parentNode, DataReference<TripLonglineDto> bean) { - ProgramLonglineNodeChildLoador loador = - getChildLoador(ProgramLonglineNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - private ObserveNode addRoute(ObserveNode parentNode, DataReference<RouteDto> bean) { - RoutesNodeChildLoador loador = - getChildLoador(RoutesNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - private ObserveNode addActivitySeine(ObserveNode parentNode, DataReference<ActivitySeineDto> bean) { - ActivitySeinesNodeChildLoador loador = - getChildLoador(ActivitySeinesNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - private ObserveNode addActivityLongline(ObserveNode parentNode, DataReference<ActivityLonglineDto> bean) { - ActivityLonglinesNodeChildLoador loador = - getChildLoador(ActivityLonglinesNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - public ObserveNode addFloatingObject(ObserveNode parentNode, DataReference<FloatingObjectDto> bean) { - ActivitySeineNodeChildLoador loador = - getChildLoador(ActivitySeineNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(parentNode, result); - return result; - } - - public ObserveNode addSetSeine(ObserveNode parentNode, DataReference<SetSeineDto> bean) { - ActivitySeineNodeChildLoador loador = - getChildLoador(ActivitySeineNodeChildLoador.class); - ObserveNode result = loador.createSetNode(bean); - insertNode(parentNode, result); - return result; - } - - public ObserveNode addSetLongline(ObserveNode parentNode, DataReference<SetLonglineDto> bean) { - ActivityLonglineNodeChildLoador loador = - getChildLoador(ActivityLonglineNodeChildLoador.class); - ObserveNode result = loador.createSetNode(bean); - insertNode(parentNode, result); - return result; - } - - public ObserveNode addProgram(ReferentialReference<ProgramDto> bean) { - - Set<ReferentialReference<ProgramDto>> programs = getDataProvider().getDataSource().getReferentialReferences(ProgramDto.class); - List<ReferentialReference<ProgramDto>> data = Lists.newArrayList(programs); - int newIndex = 0; - if (CollectionUtils.isNotEmpty(data)) { - sortPrograms(data); - newIndex = data.indexOf(bean); - } - RootNodeChildLoador loador = getChildLoador(RootNodeChildLoador.class); - ObserveNode result = loador.createNode(bean, dataProvider); - insertNode(getRootNode(), result, newIndex); - return result; - } - - public void removeProgram(String programId) { - ObserveNode rootNode = getRootNode(); - ObserveNode result = rootNode.getChild(programId, getBridge(), dataProvider); - Objects.requireNonNull(result, "Could not find program node with id: " + programId); - removeNode(result); - } - - public void updateProgram(ProgramDto bean) { - ObserveNode rootNode = getRootNode(); - ObserveNode result = rootNode.getChild(bean.getId(), getBridge(), dataProvider); - Objects.requireNonNull(result, "Could not find program node with id: " + bean.getId()); - reloadNode(result, false); - refreshNode(result, false); - } - - public void removeTrip(ReferentialReference<ProgramDto> program, DataReference trip) { - - ObserveNode rootNode = getRootNode(); - ObserveNode programNode = rootNode.getChild(program.getId(), getBridge(), dataProvider); - Objects.requireNonNull(programNode, "Could not find program node with id: " + program); - ObserveNode tripNode = programNode.getChild(trip.getId(), getBridge(), dataProvider); - Objects.requireNonNull(tripNode, "Could not find program node with id: " + trip); - removeNode(tripNode); - - if (programNode.isLeaf()) { - removeProgram(program.getId()); - } - } - - public void reloadSelectedNode(boolean refreshFromParent, boolean refreshChilds) { - ObserveNode node = getSelectedNode(); - ((AbstrctReferenceNodeSupport) node).setReloadEntity(true); - - if (refreshFromParent) { - node = node.getParent(); - } - refreshNode(node, refreshChilds); - } - - public void reloadNode(ObserveNode node, boolean refreshChilds) { - ((AbstrctReferenceNodeSupport) node).setReloadEntity(true); - refreshNode(node, refreshChilds); - } - - @Override - protected ObserveDataProvider getDataProvider() { - return (ObserveDataProvider) super.getDataProvider(); - } - - @Override - protected ObserveTreeBridge getBridge() { - return (ObserveTreeBridge) super.getBridge(); - } - - void setDataSource(ObserveSwingDataSource source) { - NavDataProvider provider = null; - if (source != null) { - provider = new ObserveDataProvider(source); - } - setDataProvider(provider); - } - - public void reloadNodeSubTree(ObserveNode node, boolean expandNode) { - Objects.requireNonNull(node, "node is null, we can not reload its structure"); - ObserveTreeBridge bridge = getBridge(); - - // 1. Let's clear node structure - while (node.getChildCount() > 0) { - removeNode(node.getFirstChild()); - } - - // 2. We add the node and its parent to the select path in order to force the call to the child loadors when populating the node. - // see fr.ird.observe.application.swing.ui.tree.ObserveTreeBridge.canLoadChild - bridge.setPathToSelect(node.getId(), node.getParent().getId()); - - try { - - // 3. Let's re-generate node's children by populating the node : this will call the child loaders. - node.populateNode(bridge, getDataProvider(), true); - - } finally { - // Clean the path to select - bridge.setPathToSelect(); - } - - if (expandNode) { - - // Fix bug (if no child in parent node, it will not expand...) - getUI().fireTreeExpanded(new TreePath(node.getPath())); - - } - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeNodeSupport.java new file mode 100644 index 0000000..f9fb375 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveTreeNodeSupport.java @@ -0,0 +1,39 @@ +package fr.ird.observe.application.swing.ui.tree; + +import javax.swing.Icon; +import javax.swing.UIManager; +import javax.swing.tree.DefaultMutableTreeNode; +import java.awt.Color; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class ObserveTreeNodeSupport<O> extends DefaultMutableTreeNode { + + public abstract boolean isOpen(); + + public abstract String getId(); + + public abstract String getText(); + + public abstract String getIconPath(); + + public abstract Color getColor(); + + public O getData() { + return (O) getUserObject(); + } + + public ObserveTreeNodeSupport(O userObject, boolean allowsChildren) { + super(userObject, allowsChildren); + } + + public Icon getIcon(String suffix) { + String iconPath = getIconPath(); + return iconPath == null ? null : UIManager.getIcon(iconPath + suffix); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java index 737c048..098c78e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java @@ -25,14 +25,11 @@ package fr.ird.observe.application.swing.ui.tree.actions; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.service.data.seine.ActivitySeineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Created on 1/9/15. @@ -42,14 +39,8 @@ import org.apache.commons.logging.LogFactory; */ public class ChangeActivityRouteActionListener extends NodeChangeActionListener { - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeActivityRouteActionListener.class); - - public ChangeActivityRouteActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String activityId, - String routeId) { - super(treeHelper, activityId, routeId); + public ChangeActivityRouteActionListener(NavigationTree tree, String activityId, String routeId) { + super(tree, activityId, routeId); } @Override @@ -63,15 +54,15 @@ public class ChangeActivityRouteActionListener extends NodeChangeActionListener } @Override - protected ObserveNode getParentNode(ObserveNode node) { + protected NavigationTreeNodeSupport getParentNode(NavigationTreeNodeSupport node) { return node.getParent().getParent(); } @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - ObserveNode routeNode = getTreeHelper().getChild(grandParentNode, parentNodeId); + protected NavigationTreeNodeSupport getNewParentNode(NavigationTreeNodeSupport grandParentNode, String parentNodeId) { + NavigationTreeNodeSupport routeNode = getTree().getChild(grandParentNode, parentNodeId); String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class); - return getTreeHelper().getChild(routeNode, activitiesNodeId); + return getTree().getChild(routeNode, activitiesNodeId); } @Override diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java index 488b3f4..06176d2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java @@ -25,14 +25,11 @@ package fr.ird.observe.application.swing.ui.tree.actions; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; import fr.ird.observe.services.service.data.longline.ActivityLonglineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Created on 1/9/15. @@ -42,14 +39,8 @@ import org.apache.commons.logging.LogFactory; */ public class ChangeActivityTripActionListener extends NodeChangeActionListener { - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeActivityTripActionListener.class); - - public ChangeActivityTripActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String activityId, - String tripLonglineId) { - super(treeHelper, activityId, tripLonglineId); + public ChangeActivityTripActionListener(NavigationTree tree, String activityId, String tripLonglineId) { + super(tree, activityId, tripLonglineId); } @Override @@ -63,15 +54,15 @@ public class ChangeActivityTripActionListener extends NodeChangeActionListener { } @Override - protected ObserveNode getParentNode(ObserveNode node) { + protected NavigationTreeNodeSupport getParentNode(NavigationTreeNodeSupport node) { return node.getParent().getParent(); } @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - ObserveNode tripLonglineNode = getTreeHelper().getChild(grandParentNode, parentNodeId); + protected NavigationTreeNodeSupport getNewParentNode(NavigationTreeNodeSupport grandParentNode, String parentNodeId) { + NavigationTreeNodeSupport tripLonglineNode = getTree().getChild(grandParentNode, parentNodeId); String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class); - return getTreeHelper().getChild(tripLonglineNode, activitiesNodeId); + return getTree().getChild(tripLonglineNode, activitiesNodeId); } @Override diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java index f0c0cad..ef8a539 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java @@ -25,14 +25,11 @@ package fr.ird.observe.application.swing.ui.tree.actions; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.dto.seine.RouteDto; import fr.ird.observe.services.service.data.seine.RouteService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Created on 1/9/15. @@ -42,14 +39,8 @@ import org.apache.commons.logging.LogFactory; */ public class ChangeRouteTripActionListener extends NodeChangeActionListener { - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeRouteTripActionListener.class); - - public ChangeRouteTripActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String routeId, - String tripId) { - super(treeHelper, routeId, tripId); + public ChangeRouteTripActionListener(NavigationTree tree, String routeId, String tripId) { + super(tree, routeId, tripId); } @Override @@ -63,15 +54,15 @@ public class ChangeRouteTripActionListener extends NodeChangeActionListener { } @Override - protected ObserveNode getParentNode(ObserveNode node) { + protected NavigationTreeNodeSupport getParentNode(NavigationTreeNodeSupport node) { return node.getParent().getParent(); } @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - ObserveNode tripNode = getTreeHelper().getChild(grandParentNode, parentNodeId); + protected NavigationTreeNodeSupport getNewParentNode(NavigationTreeNodeSupport grandParentNode, String parentNodeId) { + NavigationTreeNodeSupport tripNode = getTree().getChild(grandParentNode, parentNodeId); String routesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class); - return getTreeHelper().getChild(tripNode, routesNodeId); + return getTree().getChild(tripNode, routesNodeId); } @Override diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java index 79ac357..8a270f8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java @@ -25,15 +25,12 @@ package fr.ird.observe.application.swing.ui.tree.actions; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.services.ObserveServicesProvider; import fr.ird.observe.services.dto.IdHelper; import fr.ird.observe.services.service.data.longline.TripLonglineService; import fr.ird.observe.services.service.data.seine.TripSeineService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Created on 1/9/15. @@ -43,14 +40,8 @@ import org.apache.commons.logging.LogFactory; */ public class ChangeTripProgramActionListener extends NodeChangeActionListener { - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeTripProgramActionListener.class); - - public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String tripId, - String programId) { - super(treeHelper, tripId, programId); + public ChangeTripProgramActionListener(NavigationTree tree, String tripId, String programId) { + super(tree, tripId, programId); } @Override @@ -59,13 +50,13 @@ public class ChangeTripProgramActionListener extends NodeChangeActionListener { } @Override - protected ObserveNode getParentNode(ObserveNode node) { + protected NavigationTreeNodeSupport getParentNode(NavigationTreeNodeSupport node) { return node.getParent(); } @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - return getTreeHelper().getChild(grandParentNode, parentNodeId); + protected NavigationTreeNodeSupport getNewParentNode(NavigationTreeNodeSupport grandParentNode, String parentNodeId) { + return getTree().getChild(grandParentNode, parentNodeId); } @Override diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java index 63d72c6..da0ce94 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java @@ -23,8 +23,8 @@ package fr.ird.observe.application.swing.ui.tree.actions; */ -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,33 +46,33 @@ public abstract class NodeChangeActionListener implements ActionListener { private final String parentNodeId; - private final ObserveTreeHelper treeHelper; + private final NavigationTree tree; - public NodeChangeActionListener(ObserveTreeHelper treeHelper, + public NodeChangeActionListener(NavigationTree tree, String nodeId, String parentNodeId) { this.nodeId = nodeId; this.parentNodeId = parentNodeId; - this.treeHelper = treeHelper; + this.tree = tree; } @Override public void actionPerformed(ActionEvent event) { - ObserveNode node = treeHelper.getSelectedNode(); - ObserveNode oldParentNode = getParentNode(node); - ObserveNode grandParentNode = oldParentNode.getParent(); - ObserveNode newParentNode = getNewParentNode(grandParentNode, parentNodeId); + NavigationTreeNodeSupport node = tree.getSelectedNode(); + NavigationTreeNodeSupport oldParentNode = getParentNode(node); + NavigationTreeNodeSupport grandParentNode = oldParentNode.getParent(); + NavigationTreeNodeSupport newParentNode = getNewParentNode(grandParentNode, parentNodeId); closeNode(node.getId()); int position = moveNodeToParent(nodeId, parentNodeId, oldParentNode.getId()); - treeHelper.selectNode(newParentNode); + tree.selectNode(newParentNode); - treeHelper.removeNode(node); + tree.removeNode(node); - ObserveNode newNode = treeHelper.getChild(newParentNode, nodeId); + NavigationTreeNodeSupport newNode = tree.getChild(newParentNode, nodeId); if (newNode == null) { @@ -80,23 +80,23 @@ public abstract class NodeChangeActionListener implements ActionListener { if (log.isInfoEnabled()) { log.info("Insert node: "); } - treeHelper.insertNode(newParentNode, node, position); + tree.insertNode(newParentNode, node, position); newNode = node; } - treeHelper.selectNode(newNode); + tree.selectNode(newNode); } - protected ObserveTreeHelper getTreeHelper() { - return treeHelper; + public NavigationTree getTree() { + return tree; } protected abstract void closeNode(String nodeId); - protected abstract ObserveNode getParentNode(ObserveNode node); + protected abstract NavigationTreeNodeSupport getParentNode(NavigationTreeNodeSupport node); - protected abstract ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId); + protected abstract NavigationTreeNodeSupport getNewParentNode(NavigationTreeNodeSupport grandParentNode, String parentNodeId); protected abstract int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractNodeChildLoador.java deleted file mode 100644 index b29f1a2..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractNodeChildLoador.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeNodeChildLoador; - -import java.util.Objects; -import java.util.Set; - -/** - * Un object pour charger les fils d'un noeud. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public abstract class AbstractNodeChildLoador<T, O> extends NavTreeNodeChildLoador<T, O, ObserveNode> { - - private static final long serialVersionUID = 1L; - - protected AbstractNodeChildLoador(Class<O> beanType) { - super(beanType); - } - - protected ObserveSwingDataSource getDataSource(NavDataProvider dataProvider) { - ObserveDataProvider provider = (ObserveDataProvider) dataProvider; - return provider.getDataSource(); - } - - protected DataSelectionModel getSelectionModel(NavDataProvider dataProvider) { - ObserveDataProvider provider = (ObserveDataProvider) dataProvider; - return provider.getSelectionModel(); - } - - ObserveNode createNode0(Set<Class> pluralizeProperties, Class data) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - if (pluralizeProperties.contains(data)) { - return createPluralizeStringNode(data, null); - } else { - return createStringNode(data, null); - } - } - - <L extends AbstractNodeChildLoador<?, ?>> ObserveNode createStringNode(Class<?> context, Class<L> loadorType) { - Objects.requireNonNull(context, "Ne peut pas ajouter un context null"); - L childLoador = loadorType == null ? null : ObserveTreeHelper.getChildLoador(loadorType); - - String propertyLabel = ObserveI18nDecoratorHelper.getTypeI18nKey(context); - return new ObserveNode(String.class, - propertyLabel, - context.getName(), - childLoador, - false); - - } - - <L extends AbstractNodeChildLoador<?, ?>> ObserveNode createPluralizeStringNode(Class<?> context, Class<L> loadorType) { - Objects.requireNonNull(context, "Ne peut pas ajouter un context null"); - L childLoador = loadorType == null ? null : ObserveTreeHelper.getChildLoador(loadorType); - - String propertyLabel = ObserveI18nDecoratorHelper.getTypePluralI18nKey(context); - return new ObserveNode(String.class, - propertyLabel, - context.getName(), - childLoador, - false); - } - - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglineNodeChildLoador.java deleted file mode 100644 index 7ec820a..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglineNodeChildLoador.java +++ /dev/null @@ -1,109 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.loadors; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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 com.google.common.collect.ImmutableSet; -import fr.ird.observe.application.swing.ui.tree.node.ActivityLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.SetLonglineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.EncounterDto; -import fr.ird.observe.services.dto.longline.SensorUsedDto; -import fr.ird.observe.services.dto.longline.SetLonglineDto; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeBridge; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * Created on 8/28/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class ActivityLonglineNodeChildLoador extends AbstractNodeChildLoador<Class, String> { - - private static final long serialVersionUID = 1L; - - public final static String FISHING_OPERATION_ID = - "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.1"; // operation de peche - - private final static ImmutableSet<String> ENCOUNTERS_ID = ImmutableSet.of( - FISHING_OPERATION_ID, // operation de peche - "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.4" // rencontre interaction - ); - private final static ImmutableSet<String> SENSOR_USED_ID = ImmutableSet.of( - FISHING_OPERATION_ID, // operation de peche - "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.3" // station oceanographique - ); - - public ActivityLonglineNodeChildLoador() { - super(String.class); - } - - @Override - public void loadChilds(NavTreeBridge<ObserveNode> model, - ObserveNode parentNode, - NavDataProvider dataProvider) throws Exception { - - ObserveNode containerNode = parentNode.getContainerNode(); - - if (containerNode == null) { - throw new IllegalStateException("Could not find containerNode of " + parentNode); - } - - DataReference<ActivityLonglineDto> activityLonglineRef = ((ActivityLonglineNode) parentNode).getEntity(); - - DataReference<SetLonglineDto> setLonglineRef = (DataReference) activityLonglineRef.getPropertyValue(ActivityLonglineDto.PROPERTY_SET_LONGLINE); - if (setLonglineRef != null) { - parentNode.add(createSetNode(setLonglineRef)); - } - - String vesselActivityId = (String) activityLonglineRef.getPropertyValue(ActivityLonglineDto.PROPERTY_VESSEL_ACTIVITY_LONGLINE + "Id"); - - if (ENCOUNTERS_ID.contains(vesselActivityId)) { - parentNode.add(createNode(EncounterDto.class, dataProvider)); - } - if (SENSOR_USED_ID.contains(vesselActivityId)) { - parentNode.add(createNode(SensorUsedDto.class, dataProvider)); - } - } - - @Override - public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataService) { - return Collections.emptyList(); - } - - @Override - public ObserveNode createNode(Class data, NavDataProvider dataProvider) { - return createPluralizeStringNode(data, null); - } - - public ObserveNode createSetNode(DataReference<SetLonglineDto> data) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new SetLonglineNode(data); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java deleted file mode 100644 index 09dd4e2..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java +++ /dev/null @@ -1,64 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.loadors; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.node.ActivityLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.service.data.longline.ActivityLonglineService; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Created on 8/28/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class ActivityLonglinesNodeChildLoador extends AbstractDataReferenceChildLoador<ActivityLonglineDto> { - - private static final long serialVersionUID = 1L; - - public ActivityLonglinesNodeChildLoador() { - super(ActivityLonglineDto.class); - } - - @Override - public List<DataReference<ActivityLonglineDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) throws Exception { - ActivityLonglineService activityLonglineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivityLonglineService(); - DataReferenceSet<ActivityLonglineDto> activityLonglineByTripLongline = activityLonglineService.getActivityLonglineByTripLongline(parentId); - return new ArrayList<>(activityLonglineByTripLongline.getReferences()); - } - - @Override - public ObserveNode createNode(DataReference<ActivityLonglineDto> data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new ActivityLonglineNode(data); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeineNodeChildLoador.java deleted file mode 100644 index fd2013d..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeineNodeChildLoador.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.node.ActivitySeineNode; -import fr.ird.observe.application.swing.ui.tree.node.FloatingObjectSeineNode; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.SetSeineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.FloatingObjectDto; -import fr.ird.observe.services.dto.seine.SetSeineDto; -import fr.ird.observe.services.service.data.seine.FloatingObjectService; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeBridge; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Le chargeur des noeuds de marees. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ActivitySeineNodeChildLoador extends AbstractDataReferenceChildLoador<FloatingObjectDto> { - - private static final long serialVersionUID = 1L; - - public ActivitySeineNodeChildLoador() { - super(FloatingObjectDto.class); - } - - @Override - public void loadChilds(NavTreeBridge<ObserveNode> model, ObserveNode parentNode, NavDataProvider dataProvider) throws Exception { - - ObserveNode containerNode = parentNode.getContainerNode(); - - if (containerNode == null) { - throw new IllegalStateException( - "Could not find containerNode of " + parentNode); - } - - DataReference<ActivitySeineDto> activitySeineRef = ((ActivitySeineNode) parentNode).getEntity(); - DataReference<SetSeineDto> setSeineRef = (DataReference) activitySeineRef.getPropertyValue(ActivitySeineDto.PROPERTY_SET_SEINE); - if (setSeineRef != null) { - parentNode.add(createSetNode(setSeineRef)); - } - - // ajout des objets flottants - super.loadChilds(model, parentNode, dataProvider); - } - - public ObserveNode createSetNode(DataReference<SetSeineDto> data) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new SetSeineNode(data); - } - - @Override - public ObserveNode createNode(DataReference<FloatingObjectDto> data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new FloatingObjectSeineNode(data); - } - - @Override - public List<DataReference<FloatingObjectDto>> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { - - FloatingObjectService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newFloatingObjectService(); - DataReferenceSet<FloatingObjectDto> floatingObjectByActivitySeine = service.getFloatingObjectByActivitySeine(parentId); - return new ArrayList<>(floatingObjectByActivitySeine.getReferences()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeinesNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeinesNodeChildLoador.java deleted file mode 100644 index 4a4c104..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ActivitySeinesNodeChildLoador.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.node.ActivitySeineNode; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.service.data.seine.ActivitySeineService; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Le chargeur des noeuds des activités d'une route. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ActivitySeinesNodeChildLoador extends AbstractDataReferenceChildLoador<ActivitySeineDto> { - - private static final long serialVersionUID = 1L; - - public ActivitySeinesNodeChildLoador() { - super(ActivitySeineDto.class); - } - - @Override - public List<DataReference<ActivitySeineDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) throws Exception { - - ActivitySeineService activitySeineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService(); - DataReferenceSet<ActivitySeineDto> activitySeineStubByRoute = activitySeineService.getActivitySeineByRoute(parentId); - return new ArrayList<>(activitySeineStubByRoute.getReferences()); - - } - - @Override - public ObserveNode createNode(DataReference<ActivitySeineDto> data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new ActivitySeineNode(data); - - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/FloatingObjectNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/FloatingObjectNodeChildLoador.java deleted file mode 100644 index 6d4e3b0..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/FloatingObjectNodeChildLoador.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - - -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.referential.seine.ObjectOperationDto; -import fr.ird.observe.services.dto.seine.ObjectObservedSpeciesDto; -import fr.ird.observe.services.dto.seine.ObjectSchoolEstimateDto; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Le chargeur des noeuds de marees. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class FloatingObjectNodeChildLoador extends AbstractNodeChildLoador<Class, String> { - - private static final long serialVersionUID = 1L; - - public FloatingObjectNodeChildLoador() { - super(String.class); - } - - @Override - public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataService) { - return Arrays.asList(ObjectOperationDto.class, ObjectSchoolEstimateDto.class, ObjectObservedSpeciesDto.class); - } - - @Override - public ObserveNode createNode(Class data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return createStringNode(data, null); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramLonglineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramLonglineNodeChildLoador.java deleted file mode 100644 index 92d9715..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramLonglineNodeChildLoador.java +++ /dev/null @@ -1,126 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.loadors; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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 com.google.common.collect.ImmutableList; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.GearUseFeaturesLonglineDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.service.data.longline.TripLonglineService; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeBridge; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; - -/** - * Created on 8/28/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class ProgramLonglineNodeChildLoador extends AbstractNodeChildLoador<DataReference<TripLonglineDto>, TripLonglineDto> { - - private static final long serialVersionUID = 1L; - - private boolean addChilds; - private ImmutableList<DataReference<TripLonglineDto>> trips; - - public ProgramLonglineNodeChildLoador() { - super(TripLonglineDto.class); - } - - @Override - public void loadChilds(NavTreeBridge<ObserveNode> model, - ObserveNode parentNode, - NavDataProvider dataProvider) throws Exception { - - DataSelectionModel selectionModel = getSelectionModel(dataProvider); - addChilds = selectionModel == null; - - try { - super.loadChilds(model, parentNode, dataProvider); - } finally { - addChilds = true; - } - - } - - @Override - public List<DataReference<TripLonglineDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) throws Exception { - - DataSelectionModel selectionModel = getSelectionModel(dataProvider); - - List<DataReference<TripLonglineDto>> result; - - if (selectionModel != null) { - - result = new ArrayList<>((Collection) selectionModel.getDatas(parentId)); - - } else if (trips != null) { - - result = new ArrayList<>(trips); - - } else { - - TripLonglineService tripLonglineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripLonglineService(); - DataReferenceSet<TripLonglineDto> tripLonglineByProgram = tripLonglineService.getTripLonglineByProgram(parentId); - - result = new ArrayList<>(tripLonglineByProgram.getReferences()); - - } - - - return result; - } - - @Override - public ObserveNode createNode(DataReference<TripLonglineDto> data, NavDataProvider dataProvider) { - - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - - ObserveNode result = new TripLonglineNode(data); - - if (addChilds) { - result.add(createPluralizeStringNode(GearUseFeaturesLonglineDto.class, null)); - result.add(createPluralizeStringNode(ActivityLonglineDto.class, ActivityLonglinesNodeChildLoador.class)); - } - - return result; - - } - - public void setTrips(ImmutableList<DataReference<TripLonglineDto>> trips) { - this.trips = trips; - } - -} - diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramSeineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramSeineNodeChildLoador.java deleted file mode 100644 index 92e14d7..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ProgramSeineNodeChildLoador.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import com.google.common.collect.ImmutableList; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.seine.GearUseFeaturesSeineDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.data.seine.TripSeineService; -import jaxx.runtime.swing.nav.NavDataProvider; -import jaxx.runtime.swing.nav.tree.NavTreeBridge; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; - -/** - * Le chargeur des noeuds fils d'un program (les marees du programme). - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ProgramSeineNodeChildLoador extends AbstractNodeChildLoador<DataReference<TripSeineDto>, TripSeineDto> { - - private static final long serialVersionUID = 1L; - - private boolean addChilds; - private ImmutableList<DataReference<TripSeineDto>> trips; - - public ProgramSeineNodeChildLoador() { - super(TripSeineDto.class); - } - - @Override - public void loadChilds(NavTreeBridge<ObserveNode> model, ObserveNode parentNode, NavDataProvider dataProvider) throws Exception { - DataSelectionModel selectionModel = getSelectionModel(dataProvider); - addChilds = selectionModel == null; - - try { - super.loadChilds(model, parentNode, dataProvider); - } finally { - addChilds = true; - } - } - - @Override - public List<DataReference<TripSeineDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) throws Exception { - - DataSelectionModel selectionModel = getSelectionModel(dataProvider); - - List<DataReference<TripSeineDto>> result; - - if (selectionModel != null) { - - result = new ArrayList<>((Collection) selectionModel.getDatas(parentId)); - - } else if (trips != null) { - - result = new ArrayList<>(trips); - - } else { - - TripSeineService tripSeineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripSeineService(); - DataReferenceSet<TripSeineDto> tripSeineByProgram = tripSeineService.getTripSeineByProgram(parentId); - - result = new ArrayList<>(tripSeineByProgram.getReferences()); - - } - return result; - - } - - @Override - public ObserveNode createNode(DataReference<TripSeineDto> data, NavDataProvider dataProvider) { - - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - - ObserveNode result = new TripSeineNode(data); - - if (addChilds) { - result.add(createPluralizeStringNode(GearUseFeaturesSeineDto.class, null)); - result.add(createPluralizeStringNode(RouteDto.class, RoutesNodeChildLoador.class)); - } - - return result; - - } - - public void setTrips(ImmutableList<DataReference<TripSeineDto>> trips) { - this.trips = trips; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ReferenceNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ReferenceNodeChildLoador.java deleted file mode 100644 index 2400af8..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/ReferenceNodeChildLoador.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - - -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.referential.ReferentialHelper; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** - * Le chargeur des noeuds du referentiel. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -class ReferenceNodeChildLoador extends AbstractNodeChildLoador<Class, Class> { - - public static class CommonReferenceNodeChildLoador extends ReferenceNodeChildLoador { - public CommonReferenceNodeChildLoador() { - super(ReferentialHelper.REFERENCE_COMMON_DTOS); - } - } - - public static class SeineReferenceNodeChildLoador extends ReferenceNodeChildLoador { - public SeineReferenceNodeChildLoador() { - super(ReferentialHelper.REFERENCE_SEINE_DTOS); - } - } - - public static class LonglineReferenceNodeChildLoador extends ReferenceNodeChildLoador { - public LonglineReferenceNodeChildLoador() { - super(ReferentialHelper.REFERENCE_LONGLINE_DTOS); - } - } - - - private static final long serialVersionUID = 1L; - - private final Set<Class> classes; - - private ReferenceNodeChildLoador(Set classes) { - super(Class.class); - this.classes = classes; - } - - @Override - public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - return ObserveI18nDecoratorHelper.sortTypes(classes); - } - - @Override - public ObserveNode createNode(Class data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - return new ObserveNode(data, data.getSimpleName(), null, true); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RootNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RootNodeChildLoador.java deleted file mode 100644 index 6f01055..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RootNodeChildLoador.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import fr.ird.observe.application.swing.ui.storage.tabs.DataSelectionModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import static org.nuiton.i18n.I18n.n; - -/** - * Le chargeur des noeuds fils d'un program (les marees du programme). - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class RootNodeChildLoador extends AbstractNodeChildLoador<ReferentialReference<ProgramDto>, ProgramDto> { - - private static final long serialVersionUID = 1L; - - private boolean addData; - - private boolean addReferentiel; - - public RootNodeChildLoador() { - this(false, false); - } - - public RootNodeChildLoador(boolean addData, boolean addReferentiel) { - super(ProgramDto.class); - this.addData = addData; - this.addReferentiel = addReferentiel; - } - - public void setAddData(boolean addData) { - this.addData = addData; - } - - public void setAddReferentiel(boolean addReferentiel) { - this.addReferentiel = addReferentiel; - } - - @Override - public List<ReferentialReference<ProgramDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - - DataSelectionModel selectionModel = getSelectionModel(dataProvider); - - List<ReferentialReference<ProgramDto>> data = Collections.emptyList(); - - if (addData) { - - if (selectionModel != null) { - data = new ArrayList<>(selectionModel.getDatas().keySet()); - } else { - Set<ReferentialReference<ProgramDto>> referentialReferenceSet = getDataSource(dataProvider).getReferentialReferences(ProgramDto.class); - data = new ArrayList<>(referentialReferenceSet); - } - - ObserveTreeHelper.sortPrograms(data); - } - - return data; - - } - - @Override - public void addChildNodes(ObserveNode parentNode, List<ReferentialReference<ProgramDto>> datas, NavDataProvider dataProvider) { - super.addChildNodes(parentNode, datas, dataProvider); - if (addReferentiel) { - parentNode.add(new ObserveNode( - String.class, - n("observe.type.reference.common"), - ObserveTreeHelper.getChildLoador(ReferenceNodeChildLoador.CommonReferenceNodeChildLoador.class), - true)); - parentNode.add(new ObserveNode( - String.class, - n("observe.type.reference.seine"), - ObserveTreeHelper.getChildLoador(ReferenceNodeChildLoador.SeineReferenceNodeChildLoador.class), - true)); - parentNode.add(new ObserveNode( - String.class, - n("observe.type.reference.longline"), - ObserveTreeHelper.getChildLoador(ReferenceNodeChildLoador.LonglineReferenceNodeChildLoador.class), - true)); - } - } - - @Override - public ObserveNode createNode(ReferentialReference<ProgramDto> data, NavDataProvider dataProvider) { - - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - - GearType gearType = (GearType) data.getPropertyValue(ProgramDto.PROPERTY_GEAR_TYPE); - - ObserveNode result; - - switch (gearType) { - - case seine: - - result = new ProgramSeineNode(data); - break; - - case longline: - - result = new ProgramLonglineNode(data); - break; - - default: - throw new IllegalStateException("The program has a gearType " + gearType + " we can't deal with"); - - } - - return result; - - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RoutesNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RoutesNodeChildLoador.java deleted file mode 100644 index a8264de..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/RoutesNodeChildLoador.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.service.data.seine.RouteService; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Le chargeur des noeuds de routes d'une marée. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class RoutesNodeChildLoador extends AbstractDataReferenceChildLoador<RouteDto> { - - private static final long serialVersionUID = 1L; - - public RoutesNodeChildLoador() { - super(RouteDto.class); - } - - @Override - public List<DataReference<RouteDto>> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) throws Exception { - RouteService routeService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService(); - DataReferenceSet<RouteDto> routeByTripSeine = routeService.getRouteByTripSeine(parentId); - return new ArrayList<>(routeByTripSeine.getReferences()); - } - - - @Override - public ObserveNode createNode(DataReference<RouteDto> data, NavDataProvider dataProvider) { - Objects.requireNonNull(data, "Ne peut pas ajouter un objet null"); - ObserveNode result = new RouteSeineNode(data); - ObserveNode child = createPluralizeStringNode(ActivitySeineDto.class, ActivitySeinesNodeChildLoador.class); - result.add(child); - return result; - } - - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetLonglineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetLonglineNodeChildLoador.java deleted file mode 100644 index ba9faf8..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetLonglineNodeChildLoador.java +++ /dev/null @@ -1,67 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.loadors; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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 com.google.common.collect.Sets; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.longline.CatchLonglineDto; -import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; -import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionDto; -import fr.ird.observe.services.dto.longline.TdrDto; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -/** - * Created on 8/30/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class SetLonglineNodeChildLoador extends AbstractNodeChildLoador<Class, String> { - - private static final long serialVersionUID = 1L; - - private static final Set<Class> PLURALIZE_PROPERTIES = Sets.newHashSet(CatchLonglineDto.class, TdrDto.class); - - public SetLonglineNodeChildLoador() { - super(String.class); - } - - @Override - public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - return Arrays.asList(SetLonglineGlobalCompositionDto.class, - SetLonglineDetailCompositionDto.class, - CatchLonglineDto.class, - TdrDto.class); - } - - @Override - public ObserveNode createNode(Class data, NavDataProvider dataProvider) { - return createNode0(PLURALIZE_PROPERTIES, data); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetSeineNodeChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetSeineNodeChildLoador.java deleted file mode 100644 index 0bc122d..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/SetSeineNodeChildLoador.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.loadors; - - -import com.google.common.collect.Sets; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.services.dto.seine.DiscardedTargetCatchDto; -import fr.ird.observe.services.dto.seine.DiscardedTargetSampleDto; -import fr.ird.observe.services.dto.seine.KeptTargetCatchDto; -import fr.ird.observe.services.dto.seine.KeptTargetSampleDto; -import fr.ird.observe.services.dto.seine.NonTargetCatchDto; -import fr.ird.observe.services.dto.seine.NonTargetSampleDto; -import fr.ird.observe.services.dto.seine.SchoolEstimateDto; -import fr.ird.observe.services.dto.seine.TargetCatchDto; -import fr.ird.observe.services.dto.seine.TargetSampleDto; -import jaxx.runtime.swing.nav.NavDataProvider; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -/** - * Le chargeur des noeuds de marees. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class SetSeineNodeChildLoador extends AbstractNodeChildLoador<Class, String> { - - private static final long serialVersionUID = 1L; - - private static final Set<Class> PLURALIZE_PROPERTIES = Sets.newHashSet(TargetCatchDto.class, - TargetSampleDto.class, - NonTargetSampleDto.class, - NonTargetCatchDto.class); - - public SetSeineNodeChildLoador() { - super(String.class); - } - - @Override - public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - return Arrays.asList(SchoolEstimateDto.class, - KeptTargetCatchDto.class, - DiscardedTargetCatchDto.class, - DiscardedTargetSampleDto.class, - KeptTargetSampleDto.class, - NonTargetCatchDto.class, - NonTargetSampleDto.class); - } - - @Override - public ObserveNode createNode(Class data, NavDataProvider dataProvider) { - return createNode0(PLURALIZE_PROPERTIES, data); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java index 32ebcb2..e56c148 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java @@ -22,17 +22,17 @@ package fr.ird.observe.application.swing.ui.tree.menu; * #L% */ -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityTripActionListener; import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.TripLonglineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.longline.TripLonglineDto; import java.util.ArrayList; import java.util.List; @@ -44,31 +44,30 @@ import java.util.List; public class MoveActivityLonglineNodeMenuPopulator extends MoveNodeMenuPopulator { @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, + public NodeChangeActionListener createChangeActionListener(NavigationTree tree, String id, String parentId) { - return new ChangeActivityTripActionListener(treeHelper, dataSource, id, parentId); + return new ChangeActivityTripActionListener(tree, id, parentId); } @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activityLonglineNode, ObserveTreeHelper treeHelper) { + public List<DecoratedNodeEntity> getPossibleParentNodes(NavigationTreeNodeSupport activityLonglineNode) { // noeud de marée parent - ObserveNode parentNode = activityLonglineNode.getParent().getParent(); + NavigationTreeNodeSupport parentNode = activityLonglineNode.getParent().getParent(); // noeud de route de la marée sans le parent actuel List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); // noeud du programme - ObserveNode programNode = parentNode.getParent(); + NavigationTreeNodeSupport programNode = parentNode.getParent(); - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); + DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); DataReferenceDecorator<TripLonglineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripLonglineDto.class); for (int i = 0, n = programNode.getChildCount(); i < n; i++) { - TripLonglineNode tripNode = (TripLonglineNode) programNode.getChildAt(i); + TripLonglineNavigationTreeNode tripNode = (TripLonglineNavigationTreeNode) programNode.getChildAt(i); String tripId = tripNode.getId(); // si le noeud de marée n'est pas le même que le parent actuel diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java index 8c78ec9..a262fcf 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java @@ -22,17 +22,17 @@ package fr.ird.observe.application.swing.ui.tree.menu; * #L% */ -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.seine.RouteDto; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityRouteActionListener; import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.RouteSeineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.seine.RouteDto; import java.util.ArrayList; import java.util.List; @@ -44,31 +44,30 @@ import java.util.List; public class MoveActivitySeineNodeMenuPopulator extends MoveNodeMenuPopulator { @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, + public NodeChangeActionListener createChangeActionListener(NavigationTree tree, String id, String parentId) { - return new ChangeActivityRouteActionListener(treeHelper, dataSource, id, parentId); + return new ChangeActivityRouteActionListener(tree, id, parentId); } @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activitySeineNode, ObserveTreeHelper treeHelper) { + public List<DecoratedNodeEntity> getPossibleParentNodes(NavigationTreeNodeSupport activitySeineNode) { // noeud de route parent - ObserveNode parentNode = activitySeineNode.getParent().getParent(); + NavigationTreeNodeSupport parentNode = activitySeineNode.getParent().getParent(); // noeud de route de la marée sans le parent actuel List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); // noeud des routes de la marée - ObserveNode routesNode = parentNode.getParent(); + NavigationTreeNodeSupport routesNode = parentNode.getParent(); - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); + DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); DataReferenceDecorator<RouteDto> routeDecorator = decoratorService.getDataReferenceDecorator(RouteDto.class); for (int i = 0, n = routesNode.getChildCount(); i < n; i++) { - RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i); + RouteSeineNavigationTreeNode routeNode = (RouteSeineNavigationTreeNode) routesNode.getChildAt(i); String routeId = routeNode.getId(); // si le noeud de marée n'est pas le même que le parent actuel diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java index e96903a..0c40b51 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java @@ -22,10 +22,9 @@ package fr.ird.observe.application.swing.ui.tree.menu; * #L% */ -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; import java.util.List; @@ -40,23 +39,20 @@ public abstract class MoveNodeMenuPopulator { /** * Crée une action pour déplacer le noeud quand on sélectionne le menu du nouveau parent - * @param treeHelper - * @param dataSource + * + * @param tree * @param id * @param parentId * @return */ - public abstract NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId); + public abstract NodeChangeActionListener createChangeActionListener(NavigationTree tree, String id, String parentId); /** * Récupère les parents dans lesquels on peut déplacer le noeud sélectionné + * * @param node le noeud sélectionné - * @param treeHelper le treehelper * @return une liste contenant les ids et les libellés des noeuds */ - public abstract List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode node, ObserveTreeHelper treeHelper); + public abstract List<DecoratedNodeEntity> getPossibleParentNodes(NavigationTreeNodeSupport node); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java index b503be6..41c3375 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java @@ -22,17 +22,17 @@ package fr.ird.observe.application.swing.ui.tree.menu; * #L% */ -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.tree.actions.ChangeRouteTripActionListener; import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.TripSeineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.seine.TripSeineDto; import java.util.ArrayList; import java.util.List; @@ -44,31 +44,30 @@ import java.util.List; public class MoveRouteNodeMenuPopulator extends MoveNodeMenuPopulator { @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, + public NodeChangeActionListener createChangeActionListener(NavigationTree tree, String id, String parentId) { - return new ChangeRouteTripActionListener(treeHelper, dataSource, id, parentId); + return new ChangeRouteTripActionListener(tree, id, parentId); } @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode routeNode, ObserveTreeHelper treeHelper) { + public List<DecoratedNodeEntity> getPossibleParentNodes(NavigationTreeNodeSupport routeNode) { // noeud de marée parent - ObserveNode parentNode = routeNode.getParent().getParent(); + NavigationTreeNodeSupport parentNode = routeNode.getParent().getParent(); // noeud de marée du programme sans le parent actuel List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); // noeud du programme - ObserveNode programNode = parentNode.getParent(); + NavigationTreeNodeSupport programNode = parentNode.getParent(); - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); + DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); DataReferenceDecorator<TripSeineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripSeineDto.class); for (int i = 0, n = programNode.getChildCount(); i < n; i++) { - TripSeineNode tripNode = (TripSeineNode) programNode.getChildAt(i); + TripSeineNavigationTreeNode tripNode = (TripSeineNavigationTreeNode) programNode.getChildAt(i); String tripId = tripNode.getId(); // si le noeud de marée n'est pas le même que le parent actuel diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java index bab4625..4c42e43 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java @@ -23,18 +23,18 @@ package fr.ird.observe.application.swing.ui.tree.menu; */ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; +import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; import fr.ird.observe.application.swing.ui.tree.actions.ChangeTripProgramActionListener; import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.RootNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ProgramLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.ProgramSeineNavigationTreeNode; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.constants.GearType; +import fr.ird.observe.services.dto.referential.ProgramDto; import java.util.ArrayList; import java.util.List; @@ -46,18 +46,17 @@ import java.util.List; public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator { @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, + public NodeChangeActionListener createChangeActionListener(NavigationTree tree, String id, String parentId) { - return new ChangeTripProgramActionListener(treeHelper, dataSource, id, parentId); + return new ChangeTripProgramActionListener(tree, id, parentId); } @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode tripNode, ObserveTreeHelper treeHelper) { + public List<DecoratedNodeEntity> getPossibleParentNodes(NavigationTreeNodeSupport tripNode) { // noeud du programme parent - ObserveNode parentNode = tripNode.getParent(); + NavigationTreeNodeSupport parentNode = tripNode.getParent(); // programmes du même type que le noeud de marée, sans le parent actuel List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); @@ -66,34 +65,34 @@ public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator { GearType gearType = IdHelper.isLonglineId(tripNode.getId()) ? GearType.longline : GearType.seine; // racine - ObserveNode rootNode = treeHelper.getRootNode(); + RootNavigationTreeNode rootNode = tripNode.getRoot(); createPossibleParents(parentNode.getId(), possibleParents, gearType, rootNode); return possibleParents; } - public static void createPossibleParents(String oldProgramId, List<DecoratedNodeEntity> possibleParents, GearType gearType, ObserveNode rootNode) { + public static void createPossibleParents(String oldProgramId, List<DecoratedNodeEntity> possibleParents, GearType gearType, NavigationTreeNodeSupport rootNode) { ReferentialReferenceDecorator<ProgramDto> programDecorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialReferenceDecorator(ProgramDto.class); for (int i = 0, n = rootNode.getChildCount(); i < n; i++) { - ObserveNode programNode = rootNode.getChildAt(i); + NavigationTreeNodeSupport programNode = (NavigationTreeNodeSupport) rootNode.getChildAt(i); String programId = programNode.getId(); // si le noeud programme n'est pas le même que le parent actuel // si le noeud est bien un noeud de programme if (IdHelper.isProgramId(programId) && !oldProgramId.equals(programId)) { - if (programNode instanceof ProgramSeineNode && GearType.seine == gearType) { + if (programNode instanceof ProgramSeineNavigationTreeNode && GearType.seine == gearType) { - ProgramSeineNode node = (ProgramSeineNode) programNode; + ProgramSeineNavigationTreeNode node = (ProgramSeineNavigationTreeNode) programNode; possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); - } else if (programNode instanceof ProgramLonglineNode && GearType.longline == gearType) { + } else if (programNode instanceof ProgramLonglineNavigationTreeNode && GearType.longline == gearType) { - ProgramLonglineNode node = (ProgramLonglineNode) programNode; + ProgramLonglineNavigationTreeNode node = (ProgramLonglineNavigationTreeNode) programNode; possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTree.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTree.java new file mode 100644 index 0000000..aacee98 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTree.java @@ -0,0 +1,563 @@ +package fr.ird.observe.application.swing.ui.tree.navigation; + +import com.google.common.collect.Lists; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.db.DataContext; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.RootNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ActivityLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ProgramLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.SetLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.TripLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.ActivitySeineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.FloatingObjectSeineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.ProgramSeineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.RouteSeineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.SetSeineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.TripSeineNavigationTreeNode; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.services.dto.constants.ReferentialLocale; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.dto.longline.SetLonglineDto; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.reference.ReferenceBinderEngine; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ProgramHelper; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import fr.ird.observe.services.dto.seine.ActivitySeineDto; +import fr.ird.observe.services.dto.seine.FloatingObjectDto; +import fr.ird.observe.services.dto.seine.RouteDto; +import fr.ird.observe.services.dto.seine.SetSeineDto; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTree; + +import javax.swing.SwingUtilities; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeWillExpandListener; +import javax.swing.tree.ExpandVetoException; +import javax.swing.tree.TreeCellRenderer; +import javax.swing.tree.TreePath; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class NavigationTree extends JXTree { + + /** Logger */ + private static final Log log = LogFactory.getLog(NavigationTree.class); + + + public static void sortPrograms(List<ReferentialReference<ProgramDto>> data) { + ObserveSwingApplicationContext.get().getDecoratorService().sort(ProgramDto.class, data); + } + + public NavigationTree() { + super(new NavigationTreeModel()); + setLargeModel(true); + setRootVisible(false); + addTreeWillExpandListener(new TreeWillExpandListener() { + + @Override + public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { + if (!(getModel() instanceof NavigationTreeModel)) { + return; + } + NavigationTreeModel model = getNavigationTreeModel(); + NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) event.getPath().getLastPathComponent(); + model.open(node); + + } + + @Override + public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { + if (!(getModel() instanceof NavigationTreeModel)) { + return; + } + NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) event.getPath().getLastPathComponent(); + + // le seul posant problème est la fermeture d'un noeud parent + // du noeud courant : cela va changer la selection + NavigationTreeNodeSupport selectedNode = getSelectedNode(); + if (selectedNode == null) { + // pas de noeud selectionne + return; + } + + if (selectedNode.equals(node) || !selectedNode.isNodeAncestor(node)) { + return; + } + boolean canChange = ObserveSwingApplicationContext.get().getContentUIManager().closeSelectedContentUI(); + if (!canChange) { + throw new ExpandVetoException(event, "Can not collapse node " + event.getPath()); + } + + } + }); + addTreeSelectionListener(e -> { + if (!e.isAddedPath()) { + return; + } + TreePath path = e.getPath(); + getNavigationTreeModel().open((NavigationTreeNodeSupport) path.getLastPathComponent()); + }); + + NavigationTreeCellRenderer renderer = new NavigationTreeCellRenderer(); + setCellRenderer(renderer); + + } + + public NavigationTreeModel getNavigationTreeModel() { + return (NavigationTreeModel) getModel(); + } + + public NavigationTreeNodeSupport getSelectedNode() { + return isSelectionEmpty() ? null : (NavigationTreeNodeSupport) getSelectionPath().getLastPathComponent(); + } + + public void selectOpenNode(Class<?> type) { + + DataContext context = ObserveSwingApplicationContext.get().getDataContext(); + + String[] ids = context.getOpenIds(type); + + if (log.isDebugEnabled()) { + log.debug("using open ids = " + Arrays.toString(ids)); + } + if (ids == null) { + + // rien n'est ouvert, rien à selectionner + return; + } + + selectNode(ids); + } + + /** + * Selects the node described by his given {@code path} of ids. + * + * @param path the absolute path of ids from root node to node to select. + */ + public void selectNode(String... path) { + + if (log.isDebugEnabled()) { + log.debug("try to select node from ids " + Arrays.toString(path)); + } + RootNavigationTreeNode root = this.getNavigationTreeModel().getRoot(); + NavigationTreeNodeSupport node = NavigationTreeNodeSupport.findNode(getNavigationTreeModel(), root, path); + if (log.isDebugEnabled()) { + log.debug("selected node [" + node + "]"); + } + if (node != null) { + selectNode(node); + } + } + + + /** + * Selects the given {@code node} in the registred tree. + * + * @param node the node to select + */ + public void selectNode(NavigationTreeNodeSupport node) { + if (log.isDebugEnabled()) { + log.debug("try to select node [" + node + "]"); + } + TreePath path = new TreePath(getNavigationTreeModel().getPathToRoot(node)); + + addSelectionPath(path); + scrollPathToVisible(path); + } + + public NavigationTreeNodeSupport getChild(NavigationTreeNodeSupport node, String id) { + return node.findNodeById(getNavigationTreeModel(), id); + } + + public NavigationTreeNodeSupport removeNode(NavigationTreeNodeSupport node) { + getNavigationTreeModel().removeNodeFromParent(node); + return null; + } + + public void insertNode(NavigationTreeNodeSupport parentNode, NavigationTreeNodeSupport node, int position) { + getNavigationTreeModel().insertNodeInto(node, parentNode, position); + } + + public void clearModel() { + + NavigationTreeModel treeModel = new NavigationTreeModel(); + treeModel.setLoadLongline(false); + treeModel.setLoadReferential(false); + treeModel.setLoadSeine(false); + treeModel.setRoot(new RootNavigationTreeNode()); + setModel(treeModel); + } + + public void createModel() { + NavigationTreeModel treeModel = new NavigationTreeModel(); + treeModel.setLoadLongline(true); + treeModel.setLoadReferential(true); + treeModel.setLoadSeine(true); + treeModel.setRoot(new RootNavigationTreeNode()); + setModel(treeModel); + } + + /** + * Sélectionne le noeud dans l'arbre de navigation. + * + * <b>Note:</b> cette méthode doit être appelée après un rechargement du + * modèle de navigation. + */ + public void selectInitialNode() { + + if (log.isDebugEnabled()) { + log.debug("Will select initial node..."); + } + DataContext context = ObserveSwingApplicationContext.get().getDataContext(); + + String[] path; + + List<String> selectedIds = ObserveSwingApplicationContext.get().getNodesToReselect(); + if (CollectionUtils.isNotEmpty(selectedIds)) { + if (log.isDebugEnabled()) { + log.debug("will select previous ids " + selectedIds); + } + path = selectedIds.toArray(new String[selectedIds.size()]); + } else { + + // on trouve le meilleur noeud a selectionner. + + String id = context.getHigherOpenId(); + + if (id != null) { + + // on se positionne sur la donnée la plus haute ouverte + path = context.getOpenIds(); + if (log.isDebugEnabled()) { + log.debug("will select open ids " + Arrays.toString(path)); + } + } else { + + // on selectionne le premier noeud de $root + + NavigationTreeNodeSupport node = getNavigationTreeModel().getRoot(); + if (!node.isLeaf()) { + node = (NavigationTreeNodeSupport) node.getFirstChild(); + } + path = new String[]{node.getId()}; + if (log.isDebugEnabled()) { + log.debug("will select first program " + Arrays.toString(path)); + } + } + } + + if (log.isDebugEnabled()) { + log.debug("Selected path : " + Arrays.toString(path)); + } + + try { + + selectNode(path); + } finally { + + // nettoyage du context + ObserveSwingApplicationContext.get().setNodesToReselect(null); + } + + // navigation tree should acquire focus + SwingUtilities.invokeLater(this::grabFocus); + } + + public void reloadNodeSubTree(NavigationTreeNodeSupport node, boolean expandNode) { + Objects.requireNonNull(node, "node is null, we can not reload its structure"); + + // 1. Let's clear node structure + while (node.getChildCount() > 0) { + removeNode((NavigationTreeNodeSupport) node.getFirstChild()); + } + + // 3. Let's re-generate node's children by populating the node : this will call the child loaders. + node.reload(); + node.populateChilds(getNavigationTreeModel()); + + + if (expandNode) { + + // Fix bug (if no child in parent node, it will not expand...) + fireTreeExpanded(new TreePath(node.getPath())); + + } + } + + public void reloadNode(NavigationTreeNodeSupport node, boolean deep) { + + if (log.isDebugEnabled()) { + log.debug("Will refresh (deep ? " + deep + ") node " + node); + } + getNavigationTreeModel().nodeChanged(node); + if (deep) { + // repaint childs nodes + Enumeration<NavigationTreeNodeSupport> e = node.children(); + while (e.hasMoreElements()) { + NavigationTreeNodeSupport child = e.nextElement(); + reloadNode(child, true); + } + } + + } + + /** + * Obtains the path of ids fro the root node to the selected node on the + * registred tree. + * + * @return the array of ids from root node to selected node. + */ + public String[] getSelectedIds() { + List<String> result = new ArrayList<>(); + NavigationTreeNodeSupport selectedNode = getSelectedNode(); + while (selectedNode != null && !selectedNode.isRoot()) { + + result.add(selectedNode.getId()); + selectedNode = selectedNode.getParent(); + } + Collections.reverse(result); + return result.toArray(new String[result.size()]); + } + + + public void reloadSelectedNode(boolean refreshFromParent, boolean refreshChilds) { + NavigationTreeNodeSupport node = getSelectedNode(); + node.setLoaded(false); + + if (refreshFromParent) { + node = node.getParent(); + } + reloadNode(node, refreshChilds); + } + + public NavigationTreeNodeSupport addUnsavedNode(NavigationTreeNodeSupport parentNode, Class<?> type) { + + // noeud en mode creation + NavigationTreeNodeSupport result; + + if (TripSeineDto.class.equals(type)) { + DataReference<TripSeineDto> data = new DataReference<>(); + data.init(TripSeineDto.class, new String[0]); + result = new TripSeineNavigationTreeNode(data); + } else if (RouteDto.class.equals(type)) { + DataReference<RouteDto> data = new DataReference<>(); + data.init(RouteDto.class, new String[0]); + result = new RouteSeineNavigationTreeNode(data); + } else if (ActivitySeineDto.class.equals(type)) { + DataReference<ActivitySeineDto> data = new DataReference<>(); + data.init(ActivitySeineDto.class, new String[0]); + result = new ActivitySeineNavigationTreeNode(data); + } else if (SetSeineDto.class.equals(type)) { + DataReference<SetSeineDto> data = new DataReference<>(); + data.init(SetSeineDto.class, new String[0]); + result = new SetSeineNavigationTreeNode(data); + } else if (FloatingObjectDto.class.equals(type)) { + DataReference<FloatingObjectDto> data = new DataReference<>(); + data.init(FloatingObjectDto.class, new String[0]); + result = new FloatingObjectSeineNavigationTreeNode(data); + } else if (TripLonglineDto.class.equals(type)) { + DataReference<TripLonglineDto> data = new DataReference<>(); + data.init(TripLonglineDto.class, new String[0]); + result = new TripLonglineNavigationTreeNode(data); + } else if (ActivityLonglineDto.class.equals(type)) { + DataReference<ActivityLonglineDto> data = new DataReference<>(); + data.init(ActivityLonglineDto.class, new String[0]); + result = new ActivityLonglineNavigationTreeNode(data); + } else { + throw new IllegalStateException("Can't use type to create unsaved node: " + type.getName()); + } + insertNode(parentNode, result, parentNode.getChildCount()); + + // refresh parent node (render of parent can have changed) + reloadNode(parentNode, true); + + // Fix bug (if no child in parent node, it will not expand...) + fireTreeExpanded(new TreePath(result.getPath())); + + // Select new node + selectNode(result); + + return result; + } + + public <E extends IdDto> NavigationTreeNodeSupport addOpenable(NavigationTreeNodeSupport parentNode, E bean) { + + ReferenceBinderEngine referenceBinderEngine = ObserveSwingApplicationContext.get().getReferenceBinderEngine(); + ReferentialLocale referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); + if (bean instanceof TripSeineDto) { + + DataReference<TripSeineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (TripSeineDto) bean); + return addTripSeine(parentNode, ref); + + } else if (bean instanceof TripLonglineDto) { + + DataReference<TripLonglineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (TripLonglineDto) bean); + return addTripLongline(parentNode, ref); + + } else if (bean instanceof RouteDto) { + + DataReference<RouteDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (RouteDto) bean); + return addRoute(parentNode, ref); + + } else if (bean instanceof ActivitySeineDto) { + + DataReference<ActivitySeineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (ActivitySeineDto) bean); + return addActivitySeine(parentNode, ref); + + } else if (bean instanceof ActivityLonglineDto) { + + DataReference<ActivityLonglineDto> ref = referenceBinderEngine.transformDataDtoToReference(referentialLocale, (ActivityLonglineDto) bean); + return addActivityLongline(parentNode, ref); + + } + throw new IllegalStateException("Can not come here!"); + } + + private TripSeineNavigationTreeNode addTripSeine(NavigationTreeNodeSupport parentNode, DataReference<TripSeineDto> bean) { + TripSeineNavigationTreeNode result = new TripSeineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + private NavigationTreeNodeSupport addTripLongline(NavigationTreeNodeSupport parentNode, DataReference<TripLonglineDto> bean) { + NavigationTreeNodeSupport result = new TripLonglineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + private NavigationTreeNodeSupport addRoute(NavigationTreeNodeSupport parentNode, DataReference<RouteDto> bean) { + NavigationTreeNodeSupport result = new RouteSeineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + private NavigationTreeNodeSupport addActivitySeine(NavigationTreeNodeSupport parentNode, DataReference<ActivitySeineDto> bean) { + NavigationTreeNodeSupport result = new ActivitySeineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + private NavigationTreeNodeSupport addActivityLongline(NavigationTreeNodeSupport parentNode, DataReference<ActivityLonglineDto> bean) { + NavigationTreeNodeSupport result = new ActivityLonglineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + public NavigationTreeNodeSupport addFloatingObject(NavigationTreeNodeSupport parentNode, DataReference<FloatingObjectDto> bean) { + NavigationTreeNodeSupport result = new FloatingObjectSeineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + public NavigationTreeNodeSupport addSetSeine(NavigationTreeNodeSupport parentNode, DataReference<SetSeineDto> bean) { + NavigationTreeNodeSupport result = new SetSeineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + public NavigationTreeNodeSupport addSetLongline(NavigationTreeNodeSupport parentNode, DataReference<SetLonglineDto> bean) { + NavigationTreeNodeSupport result = new SetLonglineNavigationTreeNode(bean); + insertNode(parentNode, result); + return result; + } + + public void insertNode(NavigationTreeNodeSupport parentNode, NavigationTreeNodeSupport childNode) { + insertNode(parentNode, childNode, parentNode.getChildCount()); + } + + public NavigationTreeNodeSupport addProgram(ReferentialReference<ProgramDto> bean) { + + ObserveSwingDataSource mainDataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); + Set<ReferentialReference<ProgramDto>> programs = mainDataSource.getReferentialReferences(ProgramDto.class); + List<ReferentialReference<ProgramDto>> data = Lists.newArrayList(programs); + int newIndex = 0; + if (CollectionUtils.isNotEmpty(data)) { + sortPrograms(data); + newIndex = data.indexOf(bean); + } + + NavigationTreeNodeSupport result; + if (ProgramHelper.isProgramLongline(bean)) { + result = new ProgramLonglineNavigationTreeNode(bean); + } else { + result = new ProgramSeineNavigationTreeNode(bean); + } + insertNode(getRootNode(), result, newIndex); + return result; + } + + public void removeProgram(String programId) { + RootNavigationTreeNode rootNode = getRootNode(); + NavigationTreeNodeSupport result = getChild(rootNode, programId); + Objects.requireNonNull(result, "Could not find program node with id: " + programId); + removeNode(result); + } + + public void updateProgram(ProgramDto bean) { + RootNavigationTreeNode rootNode = getRootNode(); + NavigationTreeNodeSupport result = getChild(rootNode, bean.getId()); + Objects.requireNonNull(result, "Could not find program node with id: " + bean.getId()); + reloadNode(result, false); + //FIXME voir a quoi ça servait +// refreshNode(result, false); + } + + public void removeTrip(ReferentialReference<ProgramDto> program, DataReference trip) { + + RootNavigationTreeNode rootNode = getRootNode(); + NavigationTreeNodeSupport programNode = getChild(rootNode, program.getId()); + Objects.requireNonNull(programNode, "Could not find program node with id: " + program); + NavigationTreeNodeSupport tripNode = getChild(programNode, trip.getId()); + Objects.requireNonNull(tripNode, "Could not find program node with id: " + trip); + removeNode(tripNode); + + if (programNode.isLeaf()) { + removeProgram(program.getId()); + } + } + + public RootNavigationTreeNode getRootNode() { + return getNavigationTreeModel().getRoot(); + } + + /** + * Moves the given {@code node} to the new {@code position}. + * + * @param parentNode the parent node + * @param node the node to move + * @param position the new position of the node + */ + public void moveNode(NavigationTreeNodeSupport parentNode, NavigationTreeNodeSupport node, int position) { + parentNode.remove(node); + parentNode.insert(node, position); + getNavigationTreeModel().nodeStructureChanged(parentNode); + } + + public NavigationTreeCellRenderer getNavigationCellRenderer() { + TreeCellRenderer render0 = getCellRenderer(); + if (render0 instanceof JXTree.DelegatingRenderer) { + JXTree.DelegatingRenderer render01 = (JXTree.DelegatingRenderer) render0; + return (NavigationTreeCellRenderer) render01.getDelegateRenderer(); + } else { + return (NavigationTreeCellRenderer) render0; + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeCellRenderer.java new file mode 100644 index 0000000..ff4e2a5 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeCellRenderer.java @@ -0,0 +1,208 @@ +package fr.ird.observe.application.swing.ui.tree.navigation; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.DecoratorService; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; +import java.awt.Color; +import java.awt.Component; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class NavigationTreeCellRenderer extends DefaultTreeCellRenderer { + + /** Logger */ + private static final Log log = LogFactory.getLog(NavigationTreeCellRenderer.class); + + /** service de décoration */ + private transient DecoratorService decoratorService; + + public DecoratorService getDecoratorService() { + if (decoratorService == null) { + + // on récupère le service commun + decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); + } + return decoratorService; + } + + @Override + public Color getBackgroundSelectionColor() { + return null; + } + + @Override + public Color getBackgroundNonSelectionColor() { + // Fixes http://forge.codelutin.com/issues/830 for jdk 7 + return Color.WHITE; + } + + // protected void setDefaultIcons(Icon icon) { +// if (icon == null) { +// // the icon is not customized for this node +// setOpenIcon(getDefaultOpenIcon()); +// setClosedIcon(getDefaultClosedIcon()); +// setLeafIcon(getDefaultLeafIcon()); +// } else { +// // replace all possible icons for this node +// setOpenIcon(icon); +// setClosedIcon(icon); +// setLeafIcon(icon); +// } +// } + +// protected String computeNodeText(NavigationTreeNodeSupport node) { +// +// if (node instanceof StringNavigationTreeNodeSupport) { +// return t(((StringNavigationTreeNodeSupport) node).getData()); +// } +// +// Class dataType = node.getDataType(); +// +// if (node instanceof ReferenceNavigationTreeNodeSupport && node.getId() == null) { +// // nœud en création +// return t(ObserveI18nDecoratorHelper.getTypeI18nKey(dataType) + ".unsaved"); +// } +// +// if (node instanceof ClassNavigationTreeNode) { +// return t(ObserveI18nDecoratorHelper.getTypePluralI18nKey(dataType)); +// } +// +// if (node.isReferentielNode()) { +// return t(ObserveI18nDecoratorHelper.getTypeI18nKey(dataType)); +// } +// +// // noeud de donnée +// +// String id = node.getId(); +// +// if (id == null) { +// +// // noeud d'un objet en cours de création +// +// //FIXME +// return t(""); +// } +// +// +// if (node instanceof SetLonglineNavigationTreeNode) { +// return t(ObserveI18nDecoratorHelper.getTypeI18nKey(dataType)); +// } +// +// if (node instanceof SetSeineNavigationTreeNode) { +// return t(ObserveI18nDecoratorHelper.getTypeI18nKey(dataType)); +// } +// +// if (node instanceof ReferenceNavigationTreeNodeSupport && DataDto.class.isAssignableFrom(dataType)) { +// ReferenceNavigationTreeNodeSupport<?, ?> entityNodeSupport = (ReferenceNavigationTreeNodeSupport) node; +// +// AbstractReference<?> data = entityNodeSupport.getData(); +// Objects.requireNonNull(data, "L'entité doit être chargée dans le noeud: " + node); +// +// Decorator<?> decorator = getDecoratorService().getDataReferenceDecorator(dataType); +// +// String result = decorator.toString(data); +// if (node instanceof TripSeineNavigationTreeNode) { +// result += " (" + TripSeineHelper.getRouteCount(((TripSeineNavigationTreeNode) node).getData()) + ")"; +// } +// return result; +// } +// +// if (node instanceof ReferenceNavigationTreeNodeSupport) { +// ReferenceNavigationTreeNodeSupport<?, ?> entityNodeSupport = (ReferenceNavigationTreeNodeSupport) node; +// +// AbstractReference<?> data = entityNodeSupport.getData(); +// Objects.requireNonNull(data, "L'entité doit être chargée dans le noeud: " + node); +// +// Decorator<?> decorator = getDecoratorService().getReferentialReferenceDecorator(dataType); +// +// String result = decorator.toString(data); +// if (node instanceof ProgramSeineNavigationTreeNode || node instanceof ProgramLonglineNavigationTreeNode) { +// ReferentialReference<ProgramDto> nodeData = (ReferentialReference<ProgramDto>) node.getData(); +// result += " (" + ProgramHelper.getTripCount(nodeData) + ")"; +// } +// return result; +// } +// +// throw new IllegalStateException("Don't know how to render node: " + node); +// +// } + + /** + * @param value the value which should be a node + * @return the cast {@link NavigationTreeNodeSupport}, or {@code null} if + * value is null. + */ + public static NavigationTreeNodeSupport getNode(Object value) { + NavigationTreeNodeSupport node = null; + if (value instanceof NavigationTreeNodeSupport) { + node = (NavigationTreeNodeSupport) value; + } + return node; + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + + if (!(tree.getModel() instanceof NavigationTreeModel)) { + Component rendererComponent; + rendererComponent = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + return rendererComponent; + } + + // get the icon to set for the node + NavigationTreeNodeSupport node = getNode(value); + + Icon icon = node.getIcon(""); + setDefaultIcons(icon); + + if (!sel) { + + Color color = node.getColor(); + if (log.isTraceEnabled()) { + log.trace("===" + color + " for node " + node.getDataType() + " - " + node.getId()); + } + setTextNonSelectionColor(color); + } + + String text = node.getText(); + + if (log.isTraceEnabled()) { + log.trace("===" + text + " for node " + node.getDataType() + " - " + node.getId()); + } + Component comp = super.getTreeCellRendererComponent(tree, text, sel, expanded, leaf, row, hasFocus); + ((JComponent) comp).setToolTipText(text); + return comp; + } + + protected void setDefaultIcons(Icon icon) { + if (icon == null) { + // the icon is not customized for this node + setOpenIcon(getDefaultOpenIcon()); + setClosedIcon(getDefaultClosedIcon()); + setLeafIcon(getDefaultLeafIcon()); + } else { + // replace all possible icons for this node + setOpenIcon(icon); + setClosedIcon(icon); + setLeafIcon(icon); + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeModel.java new file mode 100644 index 0000000..fc81607 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/NavigationTreeModel.java @@ -0,0 +1,83 @@ +package fr.ird.observe.application.swing.ui.tree.navigation; + +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.RootNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; + +import javax.swing.tree.DefaultTreeModel; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class NavigationTreeModel extends DefaultTreeModel { + + private boolean loadSeine = true; + private boolean loadLongline = true; + private boolean loadReferential = true; + private boolean useSelectionModel; + + public NavigationTreeModel() { + super(new RootNavigationTreeNode()); + } + + @Override + public RootNavigationTreeNode getRoot() { + return (RootNavigationTreeNode) super.getRoot(); + } + + public void setLoadSeine(boolean loadSeine) { + this.loadSeine = loadSeine; + getRoot().populateChilds(this); + nodeStructureChanged(getRoot()); + } + + public void setLoadLongline(boolean loadLongline) { + this.loadLongline = loadLongline; + getRoot().populateChilds(this); + nodeStructureChanged(getRoot()); + } + + public void setLoadReferential(boolean loadReferential) { + this.loadReferential = loadReferential; + getRoot().populateChilds(this); + nodeStructureChanged(getRoot()); + } + + public void setUseSelectionModel(boolean useSelectionModel) { + this.useSelectionModel = useSelectionModel; + } + + public boolean isLoadSeine() { + return loadSeine; + } + + public boolean isLoadLongline() { + return loadLongline; + } + + public boolean isLoadReferential() { + return loadReferential; + } + + public boolean isUseSelectionModel() { + return useSelectionModel; + } + + public <N extends NavigationTreeNodeSupport> void reload(N node) { + node.reload(); + super.reload(node); + } + + public <N extends NavigationTreeNodeSupport> void open(N node) { + boolean updated = node.populateChilds(this); + if (updated) { + reload(node); + } + } + + public void openRoot() { + open(getRoot()); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ClassNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ClassNavigationTreeNode.java new file mode 100644 index 0000000..c6fd6a0 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ClassNavigationTreeNode.java @@ -0,0 +1,57 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes; + +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.services.dto.IdDto; + +import javax.swing.Icon; +import javax.swing.UIManager; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class ClassNavigationTreeNode<D extends IdDto> extends NavigationTreeNodeSupport<Class<D>> { + + protected ClassNavigationTreeNode(Class<D> data) { + this(data, false); + } + + protected ClassNavigationTreeNode(Class<D> data, boolean allowChildren) { + super(data, allowChildren); + } + + @Override + public Class<D> getDataType() { + return getData(); + } + + @Override + public void reload() { + } + + @Override + public String getId() { + return getParent().getId(); + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + } + + @Override + public String getText() { + return t(ObserveI18nDecoratorHelper.getTypeI18nKey(getDataType())); + } + + @Override + public String getIconPath() { + return "navigation." + getParent().getDataType().getName() + ".sub"; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/NavigationTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/NavigationTreeNodeSupport.java new file mode 100644 index 0000000..7cd4797 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/NavigationTreeNodeSupport.java @@ -0,0 +1,132 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.content.ContentUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.services.ObserveServicesProvider; + +import java.awt.Color; +import java.util.Enumeration; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSupport<O> { + + public abstract Class<?> getDataType(); + + public abstract void reload(); + + public abstract Class<? extends ContentUI<?, ?>> getContentClass(); + + protected abstract void populateChilds0(NavigationTreeModel treeModel); + + private boolean loaded; + + @Override + public RootNavigationTreeNode getRoot() { + return (RootNavigationTreeNode) super.getRoot(); + } + + @Override + public NavigationTreeNodeSupport<?> getParent() { + return (NavigationTreeNodeSupport<?>) super.getParent(); + } + + protected NavigationTreeNodeSupport(O data, boolean allowChildren) { + super(data, allowChildren); + } + + //FIXME Should reload then node ? + public void setData(O data) { + setUserObject(data); + } + + public final boolean populateChilds(NavigationTreeModel treeModel) { + if (getAllowsChildren() && !isLoaded()) { + populateChilds0(treeModel); + loaded = true; + return true; + } + return false; + } + + public boolean isLoaded() { + return loaded; + } + + public void setLoaded(boolean loaded) { + this.loaded = loaded; + } + + protected ObserveServicesProvider getMainDataSourceServicesProvider() { + return ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider(); + } + + public static NavigationTreeNodeSupport findNode(NavigationTreeModel treeModel, NavigationTreeNodeSupport node, String... ids) { + NavigationTreeNodeSupport result = null; + for (String id : ids) { + + result = node.findNodeById(treeModel, id); + + if (result == null) { + + // un des noeud n'a pas ete trouve, on sort + break; + } + node = result; + } + return result; + } + + public NavigationTreeNodeSupport findNodeById(NavigationTreeModel treeModel, String id) { + if (id == null) { + + // id null ? donc rien a faire + return null; + } + if (id.equals(getId())) { + + // on a trouve le bon noeud + return this; + } + + if (!isLoaded()) { + + // il faut charger les fils du noeud pour effectuer la recherche + populateChilds(treeModel); + } + + if (isLeaf()) { + + // au final le noeud est une feuille, donc ne convient pas + return null; + } + + // on recherche dans les fils + Enumeration<NavigationTreeNodeSupport> enumeration = children(); + while (enumeration.hasMoreElements()) { + NavigationTreeNodeSupport node = enumeration.nextElement(); + NavigationTreeNodeSupport nodeById = node.findNodeById(treeModel, id); + if (nodeById != null) { + return nodeById; + } + } + + // aucun des noeud fils ne convient + return null; + } + + public boolean isOpen() { + return false; + } + + @Override + public Color getColor() { + return isOpen() ? Color.BLACK : Color.GRAY; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ReferenceNavigationTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ReferenceNavigationTreeNodeSupport.java new file mode 100644 index 0000000..3bb37c4 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/ReferenceNavigationTreeNodeSupport.java @@ -0,0 +1,45 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.AbstractReference; +import fr.ird.observe.services.dto.IdDto; +import org.nuiton.decorator.Decorator; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class ReferenceNavigationTreeNodeSupport<D extends IdDto, O extends AbstractReference<D>> extends NavigationTreeNodeSupport<O> { + + @Override + public String getId() { + return getData().getId(); + } + + protected ReferenceNavigationTreeNodeSupport(O data, boolean allowChildren) { + super(data, allowChildren && data.getId() != null); + } + + @Override + public Class<D> getDataType() { + return getData().getType(); + } + + public boolean isOpen() { + return ObserveSwingApplicationContext.get().getOpenDataManager().isOpen(getId()); + } + + @Override + public String getText() { + Decorator<D> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferenceDecorator(getData().getType()); + return decorator.toString(getData()); + } + + @Override + public String getIconPath() { + return "navigation." + getData().getType().getName(); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/RootNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/RootNavigationTreeNode.java new file mode 100644 index 0000000..09e76b6 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/RootNavigationTreeNode.java @@ -0,0 +1,71 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.content.ContentUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline.ProgramLonglineNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.referential.ReferentialsNavigationTreeNode; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine.ProgramSeineNavigationTreeNode; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ProgramHelper; +import fr.ird.observe.services.dto.referential.ReferentialHelper; +import fr.ird.observe.services.dto.referential.ReferentialReference; + +import java.util.ArrayList; +import java.util.List; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class RootNavigationTreeNode extends StringNavigationTreeNodeSupport { + + public RootNavigationTreeNode() { + super("<ROOT>", true); + } + + @Override + public String getId() { + return null; + } + + @Override + public Class<? extends ContentUI<?, ?>> getContentClass() { + return null; + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + + removeAllChildren(); + + ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); + List<ReferentialReference<ProgramDto>> data = new ArrayList<>(source.getReferentialReferences(ProgramDto.class)); + NavigationTree.sortPrograms(data); + + if (treeModel.isLoadLongline()) { + data.stream().filter(ProgramHelper::isProgramLongline).forEach(reference -> { + add(new ProgramLonglineNavigationTreeNode(reference)); + }); + } + if (treeModel.isLoadSeine()) { + data.stream().filter(ProgramHelper::isProgramSeine).forEach(reference -> { + add(new ProgramSeineNavigationTreeNode(reference)); + }); + } + + if (treeModel.isLoadReferential()) { + add(ReferentialsNavigationTreeNode.of(n("observe.type.reference.common"), ReferentialHelper.REFERENCE_COMMON_DTOS)); + add(ReferentialsNavigationTreeNode.of(n("observe.type.reference.longline"), ReferentialHelper.REFERENCE_LONGLINE_DTOS)); + add(ReferentialsNavigationTreeNode.of(n("observe.type.reference.seine"), ReferentialHelper.REFERENCE_SEINE_DTOS)); + } + + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/StringNavigationTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/StringNavigationTreeNodeSupport.java new file mode 100644 index 0000000..f5bdaba --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/StringNavigationTreeNodeSupport.java @@ -0,0 +1,52 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes; + +import fr.ird.observe.application.swing.ui.content.ContentUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class StringNavigationTreeNodeSupport extends NavigationTreeNodeSupport<String> { + + public StringNavigationTreeNodeSupport(String data, boolean allowChildren) { + super(data, allowChildren); + } + + @Override + public Class<String> getDataType() { + return String.class; + } + + @Override + public String getId() { + return getParent().getId(); + } + + @Override + public Class<? extends ContentUI<?, ?>> getContentClass() { + return null; + } + + @Override + public void reload() { + // par défaut, rien à recharger sur un tel type de nœud + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + // par défaut, pas de fils à charger + } + + @Override + public String getText() { + return getData(); + } + + @Override + public String getIconPath() { + return null; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivitiesLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivitiesLonglineNavigationTreeNode.java new file mode 100644 index 0000000..57f9d6b --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivitiesLonglineNavigationTreeNode.java @@ -0,0 +1,44 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.service.data.longline.ActivityLonglineService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ActivitiesLonglineNavigationTreeNode extends ClassNavigationTreeNode<ActivityLonglineDto> { + + public ActivitiesLonglineNavigationTreeNode() { + super(ActivityLonglineDto.class, true); + } + + @Override + public String getId() { + return getParent().getId(); + } + + @Override + public Class<ActivityLonglinesUI> getContentClass() { + return ActivityLonglinesUI.class; + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + String id = getId(); + ActivityLonglineService service = getMainDataSourceServicesProvider().newActivityLonglineService(); + DataReferenceSet<ActivityLonglineDto> referenceSet = service.getActivityLonglineByTripLongline(id); + for (DataReference<ActivityLonglineDto> reference : referenceSet.getReferences()) { + add(new ActivityLonglineNavigationTreeNode(reference)); + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivityLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivityLonglineNavigationTreeNode.java new file mode 100644 index 0000000..41e0f61 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ActivityLonglineNavigationTreeNode.java @@ -0,0 +1,64 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.application.swing.ui.content.open.impl.longline.ActivityLonglineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.dto.longline.SetLonglineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ActivityLonglineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<ActivityLonglineDto, DataReference<ActivityLonglineDto>> { + + + public final static String FISHING_OPERATION_ID = + "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.1"; // operation de peche + + private final static ImmutableSet<String> ENCOUNTERS_ID = ImmutableSet.of( + FISHING_OPERATION_ID, // operation de peche + "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.4" // rencontre interaction + ); + private final static ImmutableSet<String> SENSOR_USED_ID = ImmutableSet.of( + FISHING_OPERATION_ID, // operation de peche + "fr.ird.observe.entities.referentiel.longline.VesselActivityLongline#1239832686138#0.3" // station oceanographique + ); + + public ActivityLonglineNavigationTreeNode(DataReference<ActivityLonglineDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<ActivityLonglineUI> getContentClass() { + return ActivityLonglineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + DataReference<ActivityLonglineDto> data = getData(); + DataReference<SetLonglineDto> setLonglineRef = (DataReference) data.getPropertyValue(ActivityLonglineDto.PROPERTY_SET_LONGLINE); + if (setLonglineRef != null) { + add(new SetLonglineNavigationTreeNode(setLonglineRef)); + } + + String vesselActivityId = (String) data.getPropertyValue(ActivityLonglineDto.PROPERTY_VESSEL_ACTIVITY_LONGLINE + "Id"); + + if (ENCOUNTERS_ID.contains(vesselActivityId)) { + add(new EncounterLonglineNavigationTreeNode()); + } + if (SENSOR_USED_ID.contains(vesselActivityId)) { + add(new SensorUsedLonglineNavigationTreeNode()); + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/CatchLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/CatchLonglineNavigationTreeNode.java new file mode 100644 index 0000000..a49ba42 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/CatchLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.table.impl.longline.CatchLonglineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.CatchLonglineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class CatchLonglineNavigationTreeNode extends ClassNavigationTreeNode<CatchLonglineDto> { + + public CatchLonglineNavigationTreeNode() { + super(CatchLonglineDto.class); + } + + @Override + public Class<CatchLonglineUI> getContentClass() { + return CatchLonglineUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/EncounterLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/EncounterLonglineNavigationTreeNode.java new file mode 100644 index 0000000..ce66bf0 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/EncounterLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.table.impl.longline.EncounterUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.EncounterDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class EncounterLonglineNavigationTreeNode extends ClassNavigationTreeNode<EncounterDto> { + + public EncounterLonglineNavigationTreeNode() { + super(EncounterDto.class); + } + + @Override + public Class<EncounterUI> getContentClass() { + return EncounterUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/GearUseFeaturesLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/GearUseFeaturesLonglineNavigationTreeNode.java new file mode 100644 index 0000000..34fb1a6 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/GearUseFeaturesLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.table.impl.longline.GearUseFeaturesLonglineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.GearUseFeaturesLonglineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class GearUseFeaturesLonglineNavigationTreeNode extends ClassNavigationTreeNode<GearUseFeaturesLonglineDto> { + + public GearUseFeaturesLonglineNavigationTreeNode() { + super(GearUseFeaturesLonglineDto.class); + } + + @Override + public Class<GearUseFeaturesLonglineUI> getContentClass() { + return GearUseFeaturesLonglineUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ProgramLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ProgramLonglineNavigationTreeNode.java new file mode 100644 index 0000000..1aba427 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/ProgramLonglineNavigationTreeNode.java @@ -0,0 +1,47 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import fr.ird.observe.services.service.data.longline.TripLonglineService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ProgramLonglineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<ProgramDto, ReferentialReference<ProgramDto>> { + + public ProgramLonglineNavigationTreeNode(ReferentialReference<ProgramDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<TripLonglinesUI> getContentClass() { + return TripLonglinesUI.class; + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + TripLonglineService tripLonglineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripLonglineService(); + DataReferenceSet<TripLonglineDto> referenceSet = tripLonglineService.getTripLonglineByProgram(getData().getId()); + for (DataReference<TripLonglineDto> reference : referenceSet.getReferences()) { + TripLonglineNavigationTreeNode childNode = new TripLonglineNavigationTreeNode(reference); + add(childNode); + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SensorUsedLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SensorUsedLonglineNavigationTreeNode.java new file mode 100644 index 0000000..fcc02a8 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SensorUsedLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.table.impl.longline.SensorUsedUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.SensorUsedDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SensorUsedLonglineNavigationTreeNode extends ClassNavigationTreeNode<SensorUsedDto> { + + public SensorUsedLonglineNavigationTreeNode() { + super(SensorUsedDto.class); + } + + @Override + public Class<SensorUsedUI> getContentClass() { + return SensorUsedUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetDetailCompositionLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetDetailCompositionLonglineNavigationTreeNode.java new file mode 100644 index 0000000..99d9378 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetDetailCompositionLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineDetailCompositionUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SetDetailCompositionLonglineNavigationTreeNode extends ClassNavigationTreeNode<SetLonglineDetailCompositionDto> { + + public SetDetailCompositionLonglineNavigationTreeNode() { + super(SetLonglineDetailCompositionDto.class); + } + + @Override + public Class<LonglineDetailCompositionUI> getContentClass() { + return LonglineDetailCompositionUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetGlobalCompositionLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetGlobalCompositionLonglineNavigationTreeNode.java new file mode 100644 index 0000000..4aacff3 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetGlobalCompositionLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.impl.longline.LonglineGlobalCompositionUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.SetLonglineGlobalCompositionDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SetGlobalCompositionLonglineNavigationTreeNode extends ClassNavigationTreeNode<SetLonglineGlobalCompositionDto> { + + public SetGlobalCompositionLonglineNavigationTreeNode() { + super(SetLonglineGlobalCompositionDto.class); + } + + @Override + public Class<LonglineGlobalCompositionUI> getContentClass() { + return LonglineGlobalCompositionUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetLonglineNavigationTreeNode.java new file mode 100644 index 0000000..44aff9c --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/SetLonglineNavigationTreeNode.java @@ -0,0 +1,38 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.impl.longline.SetLonglineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.longline.SetLonglineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SetLonglineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<SetLonglineDto, DataReference<SetLonglineDto>> { + + public SetLonglineNavigationTreeNode(DataReference<SetLonglineDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<SetLonglineUI> getContentClass() { + return SetLonglineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + add(new SetGlobalCompositionLonglineNavigationTreeNode()); + add(new SetDetailCompositionLonglineNavigationTreeNode()); + add(new CatchLonglineNavigationTreeNode()); + add(new TdrLonglineNavigationTreeNode()); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TdrLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TdrLonglineNavigationTreeNode.java new file mode 100644 index 0000000..c07f64f --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TdrLonglineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.table.impl.longline.TdrUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.longline.TdrDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class TdrLonglineNavigationTreeNode extends ClassNavigationTreeNode<TdrDto> { + + public TdrLonglineNavigationTreeNode() { + super(TdrDto.class); + } + + @Override + public Class<TdrUI> getContentClass() { + return TdrUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TripLonglineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TripLonglineNavigationTreeNode.java new file mode 100644 index 0000000..1b8e837 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/longline/TripLonglineNavigationTreeNode.java @@ -0,0 +1,39 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.longline; + +import fr.ird.observe.application.swing.ui.content.open.impl.longline.TripLonglineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.longline.TripLonglineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class TripLonglineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<TripLonglineDto, DataReference<TripLonglineDto>> { + + public TripLonglineNavigationTreeNode(DataReference<TripLonglineDto> data) { + super(data, data.getId() != null); + } + + @Override + public void reload() { + + } + + @Override + public Class<TripLonglineUI> getContentClass() { + return TripLonglineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + if (!treeModel.isUseSelectionModel()) { + add(new GearUseFeaturesLonglineNavigationTreeNode()); + add(new ActivitiesLonglineNavigationTreeNode()); + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialNavigationTreeNode.java new file mode 100644 index 0000000..0af5ad2 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialNavigationTreeNode.java @@ -0,0 +1,47 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.referential; + +import fr.ird.observe.application.swing.ObserveSwingTechnicalException; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.ui.content.ContentUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.referential.ReferentialDto; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.Icon; +import javax.swing.UIManager; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 16/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ReferentialNavigationTreeNode<D extends ReferentialDto> extends ClassNavigationTreeNode<D> { + + public ReferentialNavigationTreeNode(Class<D> data) { + super(data, true); + } + + @Override + public Class<? extends ContentUI<?, ?>> getContentClass() { + String className = String.format("fr.ird.observe.application.swing.ui.content.ref.impl.%sUI", StringUtils.removeEnd(getData().getSimpleName(), "Dto")); + try { + return (Class) Class.forName(className); + } catch (ClassNotFoundException e) { + throw new ObserveSwingTechnicalException("Can't get ui class for: " + className, e); + } + } + + @Override + public String getText() { + return t(ObserveI18nDecoratorHelper.getTypePluralI18nKey(getDataType())); + } + + @Override + public String getIconPath() { + return "navigation.sub.referentiel"; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialsNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialsNavigationTreeNode.java new file mode 100644 index 0000000..7c2cbd4 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/referential/ReferentialsNavigationTreeNode.java @@ -0,0 +1,51 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.referential; + +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.application.swing.ui.content.ref.ReferenceHomeUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.referential.ReferentialDto; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ReferentialsNavigationTreeNode extends StringNavigationTreeNodeSupport { + + public static ReferentialsNavigationTreeNode of(String name, ImmutableSet<Class<? extends ReferentialDto>> types) { + ReferentialsNavigationTreeNode result = new ReferentialsNavigationTreeNode(t(name)); + for (Class<? extends ReferentialDto> aClass : types) { + ReferentialNavigationTreeNode child = new ReferentialNavigationTreeNode<>(aClass); + result.add(child); + } + return result; + } + + public ReferentialsNavigationTreeNode(String name) { + super(name, true); + } + + @Override + public String getId() { + return null; + } + + @Override + public Class<ReferenceHomeUI> getContentClass() { + return ReferenceHomeUI.class; + } + + @Override + public String getText() { + return getData(); + } + + @Override + public String getIconPath() { + return "navigation.referentiel"; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitiesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitiesSeineNavigationTreeNode.java new file mode 100644 index 0000000..1f111bb --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitiesSeineNavigationTreeNode.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.seine.ActivitySeineDto; +import fr.ird.observe.services.service.data.seine.ActivitySeineService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ActivitiesSeineNavigationTreeNode extends StringNavigationTreeNodeSupport { + + public ActivitiesSeineNavigationTreeNode() { + super(ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class), true); + } + + @Override + public String getId() { + return getParent().getId(); + } + + @Override + public Class<ActivitySeinesUI> getContentClass() { + return ActivitySeinesUI.class; + } + + @Override + public void reload() { + + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + String id = getId(); + ActivitySeineService service = getMainDataSourceServicesProvider().newActivitySeineService(); + DataReferenceSet<ActivitySeineDto> referenceSet = service.getActivitySeineByRoute(id); + for (DataReference<ActivitySeineDto> reference : referenceSet.getReferences()) { + add(new ActivitySeineNavigationTreeNode(reference)); + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitySeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitySeineNavigationTreeNode.java new file mode 100644 index 0000000..7a64926 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ActivitySeineNavigationTreeNode.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.open.impl.seine.ActivitySeineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.seine.ActivitySeineDto; +import fr.ird.observe.services.dto.seine.FloatingObjectDto; +import fr.ird.observe.services.dto.seine.SetSeineDto; +import fr.ird.observe.services.service.data.seine.FloatingObjectService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ActivitySeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<ActivitySeineDto, DataReference<ActivitySeineDto>> { + + public ActivitySeineNavigationTreeNode(DataReference<ActivitySeineDto> data) { + super(data, true); + } + + @Override + public void reload() { + } + + @Override + public Class<ActivitySeineUI> getContentClass() { + return ActivitySeineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + + DataReference<SetSeineDto> set = (DataReference<SetSeineDto>) getData().getPropertyValue(ActivitySeineDto.PROPERTY_SET_SEINE); + if (set != null) { + add(new SetSeineNavigationTreeNode(set)); + } + + FloatingObjectService service = getMainDataSourceServicesProvider().newFloatingObjectService(); + DataReferenceSet<FloatingObjectDto> referenceSet = service.getFloatingObjectByActivitySeine(getId()); + for (DataReference<FloatingObjectDto> reference : referenceSet.getReferences()) { + add(new FloatingObjectSeineNavigationTreeNode(reference)); + } + + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetCatchesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetCatchesSeineNavigationTreeNode.java new file mode 100644 index 0000000..19e7e1a --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetCatchesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetDiscardCatchUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.DiscardedTargetCatchDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class DiscardedTargetCatchesSeineNavigationTreeNode extends ClassNavigationTreeNode<DiscardedTargetCatchDto> { + + public DiscardedTargetCatchesSeineNavigationTreeNode() { + super(DiscardedTargetCatchDto.class); + } + + @Override + public Class<TargetDiscardCatchUI> getContentClass() { + return TargetDiscardCatchUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetSamplesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetSamplesSeineNavigationTreeNode.java new file mode 100644 index 0000000..4df8e90 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/DiscardedTargetSamplesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetSampleRejeteUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.DiscardedTargetSampleDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class DiscardedTargetSamplesSeineNavigationTreeNode extends ClassNavigationTreeNode<DiscardedTargetSampleDto> { + + public DiscardedTargetSamplesSeineNavigationTreeNode() { + super(DiscardedTargetSampleDto.class); + } + + @Override + public Class<TargetSampleRejeteUI> getContentClass() { + return TargetSampleRejeteUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/FloatingObjectSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/FloatingObjectSeineNavigationTreeNode.java new file mode 100644 index 0000000..9870d9e --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/FloatingObjectSeineNavigationTreeNode.java @@ -0,0 +1,35 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.seine.FloatingObjectDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class FloatingObjectSeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<FloatingObjectDto, DataReference<FloatingObjectDto>> { + + public FloatingObjectSeineNavigationTreeNode(DataReference<FloatingObjectDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<FloatingObjectUI> getContentClass() { + return FloatingObjectUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/GearUseFeaturesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/GearUseFeaturesSeineNavigationTreeNode.java new file mode 100644 index 0000000..55561f6 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/GearUseFeaturesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.GearUseFeaturesSeineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.GearUseFeaturesSeineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class GearUseFeaturesSeineNavigationTreeNode extends ClassNavigationTreeNode<GearUseFeaturesSeineDto> { + + public GearUseFeaturesSeineNavigationTreeNode() { + super(GearUseFeaturesSeineDto.class); + } + + @Override + public Class<GearUseFeaturesSeineUI> getContentClass() { + return GearUseFeaturesSeineUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetCatchesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetCatchesSeineNavigationTreeNode.java new file mode 100644 index 0000000..c160a42 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetCatchesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetCatchUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.KeptTargetCatchDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class KeptTargetCatchesSeineNavigationTreeNode extends ClassNavigationTreeNode<KeptTargetCatchDto> { + + public KeptTargetCatchesSeineNavigationTreeNode() { + super(KeptTargetCatchDto.class); + } + + @Override + public Class<TargetCatchUI> getContentClass() { + return TargetCatchUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetSamplesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetSamplesSeineNavigationTreeNode.java new file mode 100644 index 0000000..362af7c --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/KeptTargetSamplesSeineNavigationTreeNode.java @@ -0,0 +1,26 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.TargetSampleCaptureUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.KeptTargetSampleDto; + +import javax.swing.Icon; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class KeptTargetSamplesSeineNavigationTreeNode extends ClassNavigationTreeNode<KeptTargetSampleDto> { + + public KeptTargetSamplesSeineNavigationTreeNode() { + super(KeptTargetSampleDto.class); + } + + @Override + public Class<TargetSampleCaptureUI> getContentClass() { + return TargetSampleCaptureUI.class; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NonTargetCatchesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NonTargetCatchesSeineNavigationTreeNode.java new file mode 100644 index 0000000..a379d43 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NonTargetCatchesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.NonTargetCatchUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.NonTargetCatchDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class NonTargetCatchesSeineNavigationTreeNode extends ClassNavigationTreeNode<NonTargetCatchDto> { + + public NonTargetCatchesSeineNavigationTreeNode() { + super(NonTargetCatchDto.class); + } + + @Override + public Class<NonTargetCatchUI> getContentClass() { + return NonTargetCatchUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NoneTargetSamplesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NoneTargetSamplesSeineNavigationTreeNode.java new file mode 100644 index 0000000..a410f49 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/NoneTargetSamplesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.NonTargetSampleUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.NonTargetSampleDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class NoneTargetSamplesSeineNavigationTreeNode extends ClassNavigationTreeNode<NonTargetSampleDto> { + + public NoneTargetSamplesSeineNavigationTreeNode() { + super(NonTargetSampleDto.class); + } + + @Override + public Class<NonTargetSampleUI> getContentClass() { + return NonTargetSampleUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ProgramSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ProgramSeineNavigationTreeNode.java new file mode 100644 index 0000000..04a90d5 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/ProgramSeineNavigationTreeNode.java @@ -0,0 +1,48 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.data.seine.TripSeineService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ProgramSeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<ProgramDto, ReferentialReference<ProgramDto>> { + + public ProgramSeineNavigationTreeNode(ReferentialReference<ProgramDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<TripSeinesUI> getContentClass() { + return TripSeinesUI.class; + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + TripSeineService tripSeineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripSeineService(); + DataReferenceSet<TripSeineDto> referenceSet = tripSeineService.getTripSeineByProgram(getData().getId()); + for (DataReference<TripSeineDto> reference : referenceSet.getReferences()) { + TripSeineNavigationTreeNode childNode = new TripSeineNavigationTreeNode(reference); + add(childNode); + } + + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RouteSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RouteSeineNavigationTreeNode.java new file mode 100644 index 0000000..5345d1d --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RouteSeineNavigationTreeNode.java @@ -0,0 +1,36 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.open.impl.seine.RouteUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.seine.RouteDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class RouteSeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<RouteDto, DataReference<RouteDto>> { + + public RouteSeineNavigationTreeNode(DataReference<RouteDto> data) { + super(data, true); + } + + @Override + public void reload() { + + } + + @Override + public Class<RouteUI> getContentClass() { + return RouteUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + add(new ActivitiesSeineNavigationTreeNode()); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RoutesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RoutesSeineNavigationTreeNode.java new file mode 100644 index 0000000..8588633 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/RoutesSeineNavigationTreeNode.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.seine.RouteDto; +import fr.ird.observe.services.service.data.seine.RouteService; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class RoutesSeineNavigationTreeNode extends StringNavigationTreeNodeSupport { + + @Override + public String getId() { + return getParent().getId(); + } + + @Override + public Class<RoutesUI> getContentClass() { + return RoutesUI.class; + } + + public RoutesSeineNavigationTreeNode() { + super(ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class), true); + } + + @Override + public void reload() { + + } + + @Override + protected void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + String id = getId(); + RouteService routeService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService(); + DataReferenceSet<RouteDto> referenceSet = routeService.getRouteByTripSeine(id); + for (DataReference<RouteDto> reference : referenceSet.getReferences()) { + add(new RouteSeineNavigationTreeNode(reference)); + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SchoolEstimatesSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SchoolEstimatesSeineNavigationTreeNode.java new file mode 100644 index 0000000..becd51d --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SchoolEstimatesSeineNavigationTreeNode.java @@ -0,0 +1,23 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.table.impl.seine.SchoolEstimateUI; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ClassNavigationTreeNode; +import fr.ird.observe.services.dto.seine.SchoolEstimateDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SchoolEstimatesSeineNavigationTreeNode extends ClassNavigationTreeNode<SchoolEstimateDto> { + + public SchoolEstimatesSeineNavigationTreeNode() { + super(SchoolEstimateDto.class); + } + + @Override + public Class<SchoolEstimateUI> getContentClass() { + return SchoolEstimateUI.class; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SetSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SetSeineNavigationTreeNode.java new file mode 100644 index 0000000..726f2ff --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/SetSeineNavigationTreeNode.java @@ -0,0 +1,41 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.impl.seine.SetSeineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.seine.SetSeineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SetSeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<SetSeineDto, DataReference<SetSeineDto>> { + + public SetSeineNavigationTreeNode(DataReference<SetSeineDto> data) { + super(data, true); + } + + @Override + public void reload() { + } + + @Override + public Class<SetSeineUI> getContentClass() { + return SetSeineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + add(new SchoolEstimatesSeineNavigationTreeNode()); + add(new KeptTargetCatchesSeineNavigationTreeNode()); + add(new DiscardedTargetCatchesSeineNavigationTreeNode()); + add(new KeptTargetSamplesSeineNavigationTreeNode()); + add(new DiscardedTargetSamplesSeineNavigationTreeNode()); + add(new NonTargetCatchesSeineNavigationTreeNode()); + add(new NoneTargetSamplesSeineNavigationTreeNode()); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/TripSeineNavigationTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/TripSeineNavigationTreeNode.java new file mode 100644 index 0000000..5433643 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/navigation/nodes/seine/TripSeineNavigationTreeNode.java @@ -0,0 +1,40 @@ +package fr.ird.observe.application.swing.ui.tree.navigation.nodes.seine; + +import fr.ird.observe.application.swing.ui.content.open.impl.seine.TripSeineUI; +import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.seine.TripSeineDto; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class TripSeineNavigationTreeNode extends ReferenceNavigationTreeNodeSupport<TripSeineDto, DataReference<TripSeineDto>> { + + public TripSeineNavigationTreeNode(DataReference<TripSeineDto> data) { + super(data, true); + } + + @Override + public void reload() { + DataReference<TripSeineDto> data = getMainDataSourceServicesProvider().newTripSeineService().loadReferenceToRead(getId()); + setData(data); + } + + @Override + public Class<TripSeineUI> getContentClass() { + return TripSeineUI.class; + } + + @Override + public void populateChilds0(NavigationTreeModel treeModel) { + removeAllChildren(); + if (!treeModel.isUseSelectionModel()) { + add(new GearUseFeaturesSeineNavigationTreeNode()); + add(new RoutesSeineNavigationTreeNode()); + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/AbstrctReferenceNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/AbstrctReferenceNodeSupport.java deleted file mode 100644 index d818379..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/AbstrctReferenceNodeSupport.java +++ /dev/null @@ -1,103 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.services.dto.AbstractReference; -import fr.ird.observe.services.dto.IdDto; -import fr.ird.observe.application.swing.ui.tree.loadors.AbstractNodeChildLoador; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public abstract class AbstrctReferenceNodeSupport<E extends IdDto, R extends AbstractReference<E>> extends ObserveNode { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstrctReferenceNodeSupport.class); - - private static final long serialVersionUID = 1L; - - /** - * Pour cacher l'entité attachée au noeud. - * Elle pourra être directement injectée pour éviter de la recharger (lors de la création d'un modèle initiale). - * - * @since 4.0 - */ - protected transient R entity; - - protected boolean reloadEntity; - - protected abstract R fetchEntity(); - - protected AbstrctReferenceNodeSupport(Class<E> type, R entity, AbstractNodeChildLoador<?, ?> childLoador) { - this(type, entity, null, childLoador); - } - - protected AbstrctReferenceNodeSupport(Class<E> type, R entity, String context, AbstractNodeChildLoador<?, ?> childLoador) { - super(type, entity.getId(), context, childLoador, false); - setEntity(entity); - } - - @Override - public void setDirty(boolean dirty) { - super.setDirty(dirty); - - if (dirty && reloadEntity) { - entity = null; - } - - } - - public R getEntity() { - return entity; - } - - public void setEntity(R entity) { - this.entity = entity; - } - - - protected void loadEntity(ObserveDataProvider oProvider) { - - if (entity == null) { - - if (log.isInfoEnabled()) { - log.info("will load entity " + internalClass.getSimpleName() + " : " + id); - } - - entity = fetchEntity(); - - } - - } - - public void setReloadEntity(boolean reloadEntity) { - this.reloadEntity = reloadEntity; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivityLonglineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivityLonglineNode.java deleted file mode 100644 index 6b53ef2..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivityLonglineNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.service.data.longline.ActivityLonglineService; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivityLonglineNodeChildLoador; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ActivityLonglineNode extends DataReferenceNodeSupport<ActivityLonglineDto> { - - private static final long serialVersionUID = 1L; - - public ActivityLonglineNode(DataReference<ActivityLonglineDto> entity) { - super(ActivityLonglineDto.class, entity, ObserveTreeHelper.getChildLoador(ActivityLonglineNodeChildLoador.class)); - } - - @Override - protected DataReference<ActivityLonglineDto> fetchEntity() { - ActivityLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivityLonglineService(); - return service.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivitySeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivitySeineNode.java deleted file mode 100644 index 69690d5..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ActivitySeineNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.service.data.seine.ActivitySeineService; -import fr.ird.observe.application.swing.ui.tree.loadors.ActivitySeineNodeChildLoador; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ActivitySeineNode extends DataReferenceNodeSupport<ActivitySeineDto> { - - private static final long serialVersionUID = 1L; - - public ActivitySeineNode(DataReference<ActivitySeineDto> entity) { - super(ActivitySeineDto.class, entity, ObserveTreeHelper.getChildLoador(ActivitySeineNodeChildLoador.class)); - } - - @Override - protected DataReference<ActivitySeineDto> fetchEntity() { - ActivitySeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService(); - return service.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/DataReferenceNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/DataReferenceNodeSupport.java deleted file mode 100644 index 4b92678..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/DataReferenceNodeSupport.java +++ /dev/null @@ -1,98 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveOpenDataManager; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.services.dto.DataDto; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.OpenableDto; -import fr.ird.observe.application.swing.ui.tree.loadors.AbstractNodeChildLoador; -import jaxx.runtime.swing.nav.NavBridge; -import jaxx.runtime.swing.nav.NavDataProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.DefaultTreeModel; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public abstract class DataReferenceNodeSupport<E extends DataDto> extends AbstrctReferenceNodeSupport<E, DataReference<E>> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(DataReferenceNodeSupport.class); - - private static final long serialVersionUID = 1L; - - protected DataReferenceNodeSupport(Class<E> internalClass, DataReference<E> entity) { - super(internalClass, entity, null); - } - - protected DataReferenceNodeSupport(Class<E> type, DataReference<E> entity, AbstractNodeChildLoador<?, ?> childLoador) { - super(type, entity, null, childLoador); - } - - protected DataReferenceNodeSupport(Class<E> type, DataReference<E> entity, String context, AbstractNodeChildLoador<?, ?> childLoador) { - super(type, entity, context, childLoador); - } - - @Override - public void populateNode(NavBridge<DefaultTreeModel, ObserveNode> bridge, - NavDataProvider provider, - boolean populateChilds) { - - - try { - super.populateNode(bridge, provider, populateChilds); - } finally { - reloadEntity = false; - } - - if (provider != null && id != null) { - - if (entity == null) { - - loadEntity((ObserveDataProvider) provider); - - } - - if (OpenableDto.class.isAssignableFrom(entity.getType())) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - open = openDataManager.isOpen(entity.getId()); - if (log.isDebugEnabled()) { - log.debug("Set open: " + open + " for entity: " + id); - } - - } - - } - - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/FloatingObjectSeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/FloatingObjectSeineNode.java deleted file mode 100644 index 8531d6b..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/FloatingObjectSeineNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.FloatingObjectDto; -import fr.ird.observe.services.service.data.seine.FloatingObjectService; -import fr.ird.observe.application.swing.ui.tree.loadors.FloatingObjectNodeChildLoador; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class FloatingObjectSeineNode extends DataReferenceNodeSupport<FloatingObjectDto> { - - private static final long serialVersionUID = 1L; - - public FloatingObjectSeineNode(DataReference<FloatingObjectDto> entity) { - super(FloatingObjectDto.class, entity, ObserveTreeHelper.getChildLoador(FloatingObjectNodeChildLoador.class)); - } - - @Override - protected DataReference<FloatingObjectDto> fetchEntity() { - FloatingObjectService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newFloatingObjectService(); - return service.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java deleted file mode 100644 index 3046094..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.node; - -import fr.ird.observe.services.dto.OpenableDto; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import jaxx.runtime.swing.nav.tree.NavTreeNode; -import jaxx.runtime.swing.nav.tree.NavTreeNodeChildLoador; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Le modèle d'une noeud. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class ObserveNode extends NavTreeNode<ObserveNode> { - - /** Logger */ - static private final Log log = LogFactory.getLog(ObserveNode.class); - - public static long count; - - private static final long serialVersionUID = 1L; - - /** un drapeau pour savoir si le noeud fait parti du referentiel */ - protected final boolean referentiel; - - /** - * Un etat pour savoir si l'objet (de donnee) encapsule est ouvert. - * - * <b>Note:</b> Il faut que l'objet soit de type {@link OpenableDto}. - */ - protected Boolean open; - - public ObserveNode(String id, boolean referentiel) { - this(String.class, id, null, null, referentiel); - } - - public ObserveNode(Class<?> internalClass, - String id, - boolean referentiel) { - this(internalClass, id, null, null, referentiel); - } - - public ObserveNode(Class<?> internalClass, - String id, - NavTreeNodeChildLoador<?, ?, ObserveNode> childLoador, - boolean referentiel) { - this(internalClass, id, null, childLoador, referentiel); - } - - public ObserveNode(Class<?> internalClass, - String id, - String context, - NavTreeNodeChildLoador<?, ?, ObserveNode> childLoador, - boolean referentiel) { - super(internalClass, id, context, childLoador); - this.referentiel = referentiel; - count++; - if (log.isDebugEnabled()) { - log.debug("Creates a new node [" + count + "] " + this); - } - } - - public boolean isDataNode() { - return !referentiel; - } - - public boolean isReferentielNode() { - return referentiel; - } - - public Boolean isOpen() { - return open; - } - - public boolean isTripNode() { - return isDataNode() && - (TripSeineDto.class.isAssignableFrom(internalClass) - || TripLonglineDto.class.isAssignableFrom(internalClass)); - } - - public boolean isRouteNode() { - return isDataNode() && RouteDto.class.isAssignableFrom(internalClass); - } - - public boolean isActivitySeineNode() { - return isDataNode() && ActivitySeineDto.class.isAssignableFrom(internalClass); - } - - public boolean isActivityLonglineNode() { - return isDataNode() && ActivityLonglineDto.class.isAssignableFrom(internalClass); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramLonglineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramLonglineNode.java deleted file mode 100644 index 16066b4..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramLonglineNode.java +++ /dev/null @@ -1,71 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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 com.google.common.collect.ImmutableList; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeBridge; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.loadors.ProgramLonglineNodeChildLoador; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.services.service.referential.ReferentialService; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ProgramLonglineNode extends ReferentialReferenceNodeSupport<ProgramDto> { - - private static final long serialVersionUID = 1L; - - public ProgramLonglineNode(ReferentialReference<ProgramDto> entity) { - super(ProgramDto.class, - entity, - ((GearType) entity.getPropertyValue(ProgramDto.PROPERTY_GEAR_TYPE)).name(), - ObserveTreeHelper.getChildLoador(ProgramLonglineNodeChildLoador.class)); - // FIXME kmorin 20151012 pkoi refaire un setEntity alors qu'il est fait dans le super ? - setEntity(entity); - } - - @Override - protected ReferentialReference<ProgramDto> fetchEntity() { - ReferentialService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newReferentialService(); - return service.loadReference(ProgramDto.class, getId()); - } - - public void populateChilds(ImmutableList<DataReference<TripLonglineDto>> trips, ObserveTreeBridge bridge, ObserveDataProvider provider) { - ((ProgramLonglineNodeChildLoador) childLoador).setTrips(trips); - try { - populateChilds(bridge, provider); - } finally { - ((ProgramLonglineNodeChildLoador) childLoador).setTrips(null); - } - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramSeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramSeineNode.java deleted file mode 100644 index 44187fc..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ProgramSeineNode.java +++ /dev/null @@ -1,69 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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 com.google.common.collect.ImmutableList; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeBridge; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.loadors.ProgramSeineNodeChildLoador; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.referential.ReferentialService; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ProgramSeineNode extends ReferentialReferenceNodeSupport<ProgramDto> { - - private static final long serialVersionUID = 1L; - - public ProgramSeineNode(ReferentialReference<ProgramDto> entity) { - super(ProgramDto.class, - entity, - ((GearType) entity.getPropertyValue(ProgramDto.PROPERTY_GEAR_TYPE)).name(), - ObserveTreeHelper.getChildLoador(ProgramSeineNodeChildLoador.class)); - } - - @Override - protected ReferentialReference<ProgramDto> fetchEntity() { - ReferentialService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newReferentialService(); - return service.loadReference(ProgramDto.class, getId()); - } - - public void populateChilds(ImmutableList<DataReference<TripSeineDto>> trips, ObserveTreeBridge bridge, ObserveDataProvider provider) { - ((ProgramSeineNodeChildLoador) childLoador).setTrips(trips); - try { - populateChilds(bridge, provider); - } finally { - ((ProgramSeineNodeChildLoador) childLoador).setTrips(null); - } - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ReferentialReferenceNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ReferentialReferenceNodeSupport.java deleted file mode 100644 index cf4e33a..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ReferentialReferenceNodeSupport.java +++ /dev/null @@ -1,85 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.application.swing.ui.tree.loadors.AbstractNodeChildLoador; -import jaxx.runtime.swing.nav.NavBridge; -import jaxx.runtime.swing.nav.NavDataProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.DefaultTreeModel; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public abstract class ReferentialReferenceNodeSupport<E extends ReferentialDto> extends AbstrctReferenceNodeSupport<E, ReferentialReference<E>> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ReferentialReferenceNodeSupport.class); - - private static final long serialVersionUID = 1L; - - protected ReferentialReferenceNodeSupport(Class<E> internalClass, ReferentialReference<E> entity) { - super(internalClass, entity, null); - } - - protected ReferentialReferenceNodeSupport(Class<E> type, ReferentialReference<E> entity, AbstractNodeChildLoador<?, ?> childLoador) { - super(type, entity, null, childLoador); - } - - protected ReferentialReferenceNodeSupport(Class<E> type, ReferentialReference<E> entity, String context, AbstractNodeChildLoador<?, ?> childLoador) { - super(type, entity, context, childLoador); - } - - @Override - public void populateNode(NavBridge<DefaultTreeModel, ObserveNode> bridge, - NavDataProvider provider, - boolean populateChilds) { - - - try { - super.populateNode(bridge, provider, populateChilds); - } finally { - reloadEntity = false; - } - - if (provider != null && id != null) { - - if (entity == null) { - - loadEntity((ObserveDataProvider) provider); - - } - - } - - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/RouteSeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/RouteSeineNode.java deleted file mode 100644 index e061765..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/RouteSeineNode.java +++ /dev/null @@ -1,49 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.service.data.seine.RouteService; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class RouteSeineNode extends DataReferenceNodeSupport<RouteDto> { - - private static final long serialVersionUID = 1L; - - public RouteSeineNode(DataReference<RouteDto> entity) { - super(RouteDto.class, entity); - } - - @Override - protected DataReference<RouteDto> fetchEntity() { - RouteService routeService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService(); - return routeService.loadReferenceToRead(getId()); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetLonglineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetLonglineNode.java deleted file mode 100644 index 50ea200..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetLonglineNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.longline.SetLonglineDto; -import fr.ird.observe.services.service.data.longline.SetLonglineService; -import fr.ird.observe.application.swing.ui.tree.loadors.SetLonglineNodeChildLoador; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SetLonglineNode extends DataReferenceNodeSupport<SetLonglineDto> { - - private static final long serialVersionUID = 1L; - - public SetLonglineNode(DataReference<SetLonglineDto> entity) { - super(SetLonglineDto.class, entity, ObserveTreeHelper.getChildLoador(SetLonglineNodeChildLoador.class)); - } - - @Override - protected DataReference<SetLonglineDto> fetchEntity() { - SetLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newSetLonglineService(); - return service.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetSeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetSeineNode.java deleted file mode 100644 index 7ebf830..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/SetSeineNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.SetSeineDto; -import fr.ird.observe.services.service.data.seine.SetSeineService; -import fr.ird.observe.application.swing.ui.tree.loadors.SetSeineNodeChildLoador; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SetSeineNode extends DataReferenceNodeSupport<SetSeineDto> { - - private static final long serialVersionUID = 1L; - - public SetSeineNode(DataReference<SetSeineDto> entity) { - super(SetSeineDto.class, entity, ObserveTreeHelper.getChildLoador(SetSeineNodeChildLoador.class)); - } - - @Override - protected DataReference<SetSeineDto> fetchEntity() { - SetSeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newSetSeineService(); - return service.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripLonglineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripLonglineNode.java deleted file mode 100644 index 5046386..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripLonglineNode.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.service.data.longline.TripLonglineService; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TripLonglineNode extends DataReferenceNodeSupport<TripLonglineDto> { - - private static final long serialVersionUID = 1L; - - public TripLonglineNode(DataReference<TripLonglineDto> entity) { - super(TripLonglineDto.class, entity); - } - - @Override - protected DataReference<TripLonglineDto> fetchEntity() { - TripLonglineService tripLonglineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripLonglineService(); - return tripLonglineService.loadReferenceToRead(getId()); - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripSeineNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripSeineNode.java deleted file mode 100644 index 9b99304..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/TripSeineNode.java +++ /dev/null @@ -1,62 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.node; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.data.seine.TripSeineService; - -/** - * Created on 4/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TripSeineNode extends DataReferenceNodeSupport<TripSeineDto> { - - private static final long serialVersionUID = 1L; - - public TripSeineNode(DataReference<TripSeineDto> entity) { - super(TripSeineDto.class, entity); - } - - private int initialRouteCount; - - @Override - protected DataReference<TripSeineDto> fetchEntity() { - TripSeineService tripSeineService = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripSeineService(); - return tripSeineService.loadReferenceToRead(getId()); - } - - public void setInitialRouteCount(int initialRouteCount) { - this.initialRouteCount = initialRouteCount; - } - - public int getRouteCount() { - if (entity == null) { - return initialRouteCount; - } - return (int) entity.getPropertyValue(TripSeineDto.PROPERTY_ROUTE_COUNT); - } -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/AbstractObserveTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/AbstractObserveTreeCellRenderer.java deleted file mode 100644 index 8970097..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/AbstractObserveTreeCellRenderer.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.renderer; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.DataContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.content.impl.seine.FloatingObjectUI; -import fr.ird.observe.application.swing.ui.content.impl.seine.SetSeineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.longline.ActivityLonglineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.longline.TripLonglineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.ActivitySeineUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.RouteUI; -import fr.ird.observe.application.swing.ui.content.open.impl.seine.TripSeineUI; -import fr.ird.observe.application.swing.ui.tree.ObserveDataProvider; -import fr.ird.observe.application.swing.ui.tree.node.DataReferenceNodeSupport; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; -import fr.ird.observe.application.swing.ui.tree.node.ReferentialReferenceNodeSupport; -import fr.ird.observe.application.swing.ui.tree.node.SetLonglineNode; -import fr.ird.observe.application.swing.ui.tree.node.SetSeineNode; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.OpenableDto; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import jaxx.runtime.swing.nav.tree.AbstractNavTreeCellRenderer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; - -import javax.swing.Icon; -import javax.swing.UIManager; -import javax.swing.tree.DefaultTreeModel; -import java.awt.Color; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import static org.nuiton.i18n.I18n.t; - -/** - * Le renderer abstrait (qui a toutes les methodes qui aident) pour implanter de - * vrai renderer pour les différents cas d'utilisation de l'abre de navigation. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public abstract class AbstractObserveTreeCellRenderer extends AbstractNavTreeCellRenderer<DefaultTreeModel, ObserveNode> { - - /** Logger */ - protected static final Log log = - LogFactory.getLog(AbstractObserveTreeCellRenderer.class); - - /** la liste des ui qui peuvent être en mode création */ - private static final List<Class<?>> CREATION_UI = - Collections.unmodifiableList( - Arrays.<Class<?>>asList( - TripSeineUI.class, - RouteUI.class, - ActivitySeineUI.class, - FloatingObjectUI.class, - SetSeineUI.class, - TripLonglineUI.class, - ActivityLonglineUI.class) - ); - - private static final long serialVersionUID = 1L; - - /** la couleur des noeuds fermés */ - private Color closeColor; - - /** la couleur des noeuds de données ouverts */ - private Color openColor; - - /** la couleur pour indiquer que la données est non valide ou non sauvée */ - private Color redColor; - - /** service de décoration */ - private transient DecoratorService decoratorService; - - public DecoratorService getDecoratorService() { - if (decoratorService == null) { - - // on récupère le service commun - decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); - } - return decoratorService; - } - - @Override - public ObserveDataProvider getDataProvider() { - ObserveDataProvider provider = (ObserveDataProvider) super.getDataProvider(); - if (provider == null) { - ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - if (source != null) { - provider = new ObserveDataProvider(source); - setDataProvider(provider); - } - } - return provider; - } - - AbstractObserveTreeCellRenderer() { - init(); - } - - protected void init() { - closeColor = Color.LIGHT_GRAY; - openColor = getForeground(); - redColor = Color.RED; - } - - /** - * Positionne dans le renderer delege l'icone a utiliser. - * - * @param node le noeud passé au renderer - */ - public void setIcon(ObserveNode node) { - Icon icon = getNavigationIcon(node); - setDefaultIcons(icon); - } - - /** - * Récupère l'icon adequate pour le noeud donnes. - * - * @param node le noeud passé au renderer - * @return l'icone du noeud (ou null si non trouve) - */ - public Icon getNavigationIcon(ObserveNode node) { - return getNavigationIcon(node, null); - - } - - @Override - public Color getBackgroundSelectionColor() { - return null; - } - - @Override - public Color getBackgroundNonSelectionColor() { - // Fixes http://forge.codelutin.com/issues/830 for jdk 7 - return Color.WHITE; - } - - /** - * Récupère l'icon adequate pour le noeud donnes. - * - * @param node le noeud passé au renderer - * @param suffix un suffix a ajouter a la clef qui identifie l'icone - * @return l'icone du noeud (ou null si non trouve) - */ - public Icon getNavigationIcon(ObserveNode node, String suffix) { - if (node == null || node.isRoot()) { - return null; - } - if (suffix == null) { - suffix = ""; - } - - Icon icon; - - if (node.isReferentielNode()) { - - // referentiel root node - - if (node.isStringNode()) { - icon = UIManager.getIcon("navigation.referentiel" + suffix); - } else { - icon = UIManager.getIcon("navigation.sub.referentiel" + suffix); - } - return icon; - } - - if (!node.isStringNode()) { - - // on est sur un noeud de donnees, rien a calculer - String path = "navigation." + node.getInternalClass().getName() + suffix; - icon = UIManager.getIcon(path); - return icon; - } - - // dernier cas, on est sur un noeud intermediaire sans donnee - // on doit se baser sur le container node - - ObserveNode containerNode = node.getContainerNode(); - - Class<?> containerClass = containerNode.getInternalClass(); - String path; - if (TripSeineDto.class.equals(containerClass)) { - // remonte sur une maree : donc routes - path = RouteDto.class.getName(); - } else if (TripLonglineDto.class.equals(containerClass)) { - // remonte sur une maree : donc activités - path = ActivityLonglineDto.class.getName(); - } else if (RouteDto.class.equals(containerClass)) { - // remonte sur une route : donc activitys - path = ActivitySeineDto.class.getName(); - } else { - // dans le cas d'un sub, il n'y a pas de suffixe possible - suffix = ""; - path = containerClass.getName() + ".sub"; - } - icon = UIManager.getIcon("navigation." + path + suffix); - return icon; - } - - protected void setDefaultIcons(Icon icon) { - if (icon == null) { - // the icon is not customized for this node - setOpenIcon(getDefaultOpenIcon()); - setClosedIcon(getDefaultClosedIcon()); - setLeafIcon(getDefaultLeafIcon()); - } else { - // replace all possible icons for this node - setOpenIcon(icon); - setClosedIcon(icon); - setLeafIcon(icon); - } - } - - @Override - protected String computeNodeText(ObserveNode node) { - - if (node.isStringNode()) { - return t(node.getId()); - } - - Class<?> beanType = node.getInternalClass(); - - if (node.isReferentielNode()) { - - return t(ObserveI18nDecoratorHelper.getTypeI18nKey(beanType)); - } - - // noeud de donnée - - String id = node.getId(); - - if (id == null) { - - // noeud d'un objet en cours de création - - return t(node.getContext()); - } - - // noeud de donnée connue en base - - if (getDataProvider() == null) { - // data provider non utilisable - return "No data provider opened to render " + id; - } - - if (node instanceof SetLonglineNode) { - return t(ObserveI18nDecoratorHelper.getTypeI18nKey(((SetLonglineNode) node).getEntity().getType())); - } - - if (node instanceof SetSeineNode) { - return t(ObserveI18nDecoratorHelper.getTypeI18nKey(((SetSeineNode) node).getEntity().getType())); - } - - if (node instanceof DataReferenceNodeSupport) { - DataReferenceNodeSupport<?> entityNodeSupport = (DataReferenceNodeSupport) node; - - DataReference entity = entityNodeSupport.getEntity(); - - Objects.requireNonNull(entity, "L'entité doit être chargée dans le noeud: " + node); - - Decorator<?> decorator = getDecoratorService().getDataReferenceDecorator((Class) beanType); - - String result = decorator.toString(entity); - if (node instanceof TripSeineNode) { - result += " (" + ((TripSeineNode) node).getRouteCount() + ")"; - } - return result; - } - - if (node instanceof ReferentialReferenceNodeSupport) { - ReferentialReferenceNodeSupport<?> entityNodeSupport = (ReferentialReferenceNodeSupport) node; - - ReferentialReference entity = entityNodeSupport.getEntity(); - - Objects.requireNonNull(entity, "L'entité doit être chargée dans le noeud: " + node); - - Decorator<?> decorator = getDecoratorService().getReferentialReferenceDecorator((Class) beanType); - - String result = decorator.toString(entity); - if (node instanceof ProgramSeineNode || node instanceof ProgramLonglineNode) { - result += " (" + node.getChildCount() + ")"; - } - return result; - } - - throw new IllegalStateException("Don't know how to render node: " + node); - - } - - public Color getNavigationTextColor(ObserveNode node) { - - if (node == null) { - return openColor; - } - - if (node.isRoot() || node.isReferentielNode()) { - return openColor; - } - - // le noeud pointe sur un objet ouvert - - Class<?> contentClass = node.getInternalClass(); - ObserveNode parentNode = node.getParent(); - Class<?> parentContentClass = parentNode == null ? null : parentNode.getInternalClass(); - - if (log.isTraceEnabled()) { - log.trace("[" + node + "] Content class to use : " + contentClass); - log.trace("[" + node + "] Parent Content class to use : " + parentContentClass); - } - DataContext dataContext = ObserveSwingApplicationContext.get().getDataContext(); - String nodeId = node.getId(); - - if (ProgramDto.class.equals(contentClass)) { - - // on grise le program si aucune marée ouverte sur ce programme - String p = dataContext.getOpenProgramId(); - if (p != null && p.equals(nodeId)) { - return openColor; - } - return closeColor; - } - - boolean nodeIsOpen = isOpenNode(node); - - if (!nodeIsOpen) { - if (log.isDebugEnabled()) { - log.debug("[" + node + "] is not open, use closeColor"); - } - // l'objet pointé n'est pas ouvert - return closeColor; - } - - if (CREATION_UI.contains(contentClass)) { - - // un noeud de creation - if (nodeId == null) { - // mode creation - return redColor; - } - return openColor; - } - - return openColor; - } - - private boolean isOpenNode(ObserveNode node) { - - if (node.isRoot() || node.isReferentielNode()) { - return false; - } - - boolean nodeIsOpen = false; - - ObserveNode openableNode; - openableNode = getFirstOpenableNode(node); - if (log.isDebugEnabled()) { - log.debug("openable node " + openableNode + " for " + Arrays.toString(node.getPath())); - } - if (openableNode != null) { - Boolean open = openableNode.isOpen(); - nodeIsOpen = open != null && open; - } - - return nodeIsOpen; - } - - /** - * @param value the value which should be a node - * @return the cast {@link ObserveNode}, or {@code null} if - * value is null. - */ - public static ObserveNode getNode(Object value) { - ObserveNode node = null; - if (value instanceof ObserveNode) { - node = (ObserveNode) value; - } - return node; - } - - private ObserveNode getFirstOpenableNode(ObserveNode node) { - - if (OpenableDto.class.isAssignableFrom(node.getInternalClass())) { - return node; - } - - if (ProgramDto.class.isAssignableFrom(node.getInternalClass())) { - return node; - } - - // this is not a openable node, go to parent node - ObserveNode parentNode = node.getParent(); - if (parentNode != null) { - return getFirstOpenableNode(parentNode); - } - return null; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/DataSelectionTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/DataSelectionTreeCellRenderer.java deleted file mode 100644 index d99608c..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/DataSelectionTreeCellRenderer.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.renderer; - -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JComponent; -import javax.swing.JTree; -import java.awt.Color; -import java.awt.Component; -import java.util.List; - -import static org.nuiton.i18n.I18n.t; - -/** - * Le renderer pour décorer l'arbre de sélection des données. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public class DataSelectionTreeCellRenderer extends AbstractObserveTreeCellRenderer { - - /** Logger */ - private static final Log log = LogFactory.getLog(DataSelectionTreeCellRenderer.class); - - private static final long serialVersionUID = 1L; - - protected List<DataReference<?>> existingTrips; - - public List<DataReference<?>> getExistingTrips() { - return existingTrips; - } - - public void setExistingTrips(List<DataReference<?>> existingTrips) { - this.existingTrips = existingTrips; - } - - public DataSelectionTreeCellRenderer() { - } - - @Override - protected void init() { - super.init(); - setBackgroundNonSelectionColor(null); - setBackgroundSelectionColor(null); - setBackground(null); - - setTextNonSelectionColor(Color.BLACK); - setTextSelectionColor(Color.BLUE); - } - - @Override - public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - - // get the icon to set for the node - ObserveNode node = getNode(value); - - if (node == null) { - return super.getTreeCellRendererComponent( - tree, - value, - sel, - expanded, - leaf, - row, - hasFocus - ); - } - setIcon(node); - - String text = getNodeText(node); - if (log.isDebugEnabled()) { - text += " (" + row + ')'; - log.debug("repaint node " + text + " (selected:" + sel + - ") for node " + node.getId()); - } - - boolean exist = false; - - if (TripSeineDto.class.equals(node.getInternalClass())) { - - if (existingTrips != null) { - - if (existingTrips.contains(((TripSeineNode) node).getEntity())) { - text = t("observe.common.exist.on.remote", text); - exist = true; - } - } - } - Component comp = super.getTreeCellRendererComponent( - tree, - text, - sel, - expanded, - leaf, - row, - hasFocus - ); - - //FIXME-TC20100316 can not display tooltiptext... -// delegate.setToolTipText(text); - if (exist) { - text = t("observe.message.warning.will.be.delete", text); - } - ((JComponent) comp).setToolTipText(text); - return comp; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/NavigationTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/NavigationTreeCellRenderer.java deleted file mode 100644 index 6208203..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/renderer/NavigationTreeCellRenderer.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.application.swing.ui.tree.renderer; - -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; - -import javax.swing.JComponent; -import javax.swing.JTree; -import javax.swing.tree.DefaultTreeModel; -import java.awt.Color; -import java.awt.Component; - -/** - * Un renderer pour modifier l'apparence des noeuds de l'arbre de navigation. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class NavigationTreeCellRenderer extends AbstractObserveTreeCellRenderer { - - private static final long serialVersionUID = 1L; - - public NavigationTreeCellRenderer() { - } - - @Override - public Component getTreeCellRendererComponent(JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - - if (!(tree.getModel() instanceof DefaultTreeModel)) { - Component rendererComponent; - rendererComponent = super.getTreeCellRendererComponent( - tree, - value, - sel, - expanded, - leaf, - row, - hasFocus - ); - return rendererComponent; - } - - // get the icon to set for the node - ObserveNode node = getNode(value); - - setIcon(node); - - if (!sel) { - - Color color = getNavigationTextColor(node); - if (log.isTraceEnabled()) { - log.trace("===" + color + " for node " + - node.getInternalClass() + " - " + node.getId()); - } - setTextNonSelectionColor(color); - } - - String text = getNodeText(node); - if (log.isTraceEnabled()) { - log.trace("===" + text + " for node " + - node.getInternalClass() + " - " + node.getId()); - } - Component comp = super.getTreeCellRendererComponent( - tree, - text, - sel, - expanded, - leaf, - row, - hasFocus - ); - ((JComponent) comp).setToolTipText(text); - return comp; - } - -} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTree.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTree.java new file mode 100644 index 0000000..bb39933 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTree.java @@ -0,0 +1,164 @@ +package fr.ird.observe.application.swing.ui.tree.selection; + +import fr.ird.observe.application.swing.ui.tree.selection.nodes.SelectionTreeNodeSupport; +import org.jdesktop.swingx.JXTreeTable; +import org.jdesktop.swingx.renderer.CellContext; +import org.jdesktop.swingx.renderer.CheckBoxProvider; +import org.jdesktop.swingx.renderer.DefaultTableRenderer; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SelectionTree extends JXTreeTable { + + public SelectionTree() { + super(new SelectionTreeModel()); + setLargeModel(true); + setTreeCellRenderer(new SelectionTreeCellRenderer()); + setRootVisible(false); + setDefaultRenderer(boolean.class, new DefaultTableRenderer(new CheckBoxProvider() { + @Override + protected void configureVisuals(CellContext context) { + super.configureVisuals(context); + if (context != null) { + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) getValueAt(context.getRow(), 0); + boolean editable = getTreeModel().isCellEditable(node, 1); + rendererComponent.setEnabled(editable); + } + } + })); + setShowGrid(false); + setRowHeight(30); + getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + } + + public void installUI() { + + InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW); + ActionMap actionMap = getActionMap(); + inputMap.put(KeyStroke.getKeyStroke("pressed F3"), "fold/unfold"); + actionMap.put("fold/unfold", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + int selectedRow = getSelectedRow(); + if (selectedRow == -1) { + return; + } + + if (!isFocusOwner()) { + return; + } + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) getPathForRow(selectedRow).getLastPathComponent(); + if (node.isLeaf()) { + return; + } + if (isExpanded(selectedRow)) { + + collapseRow(selectedRow); + } else { + expandRow(selectedRow); + } + } + }); + + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "select/unselect"); + actionMap.put("select/unselect", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + int selectedRow = getSelectedRow(); + if (selectedRow == -1) { + return; + } + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) getPathForRow(selectedRow).getLastPathComponent(); + getTreeModel().setValueAt(!node.isSelected(), node, 1); + } + }); + } + + public void installUI2(SelectionTree oppositeTree) { + + InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW); + ActionMap actionMap = getActionMap(); + inputMap.put(KeyStroke.getKeyStroke("pressed F3"), "fold/unfold"); + actionMap.put("fold/unfold", new AbstractAction() { + + protected void forTree(SelectionTree tree) { + int selectedRow = tree.getSelectedRow(); + if (selectedRow == -1) { + return; + } + + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) tree.getPathForRow(selectedRow).getLastPathComponent(); + if (node.isLeaf()) { + return; + } + if (tree.isExpanded(selectedRow)) { + + tree.collapseRow(selectedRow); + } else { + tree.expandRow(selectedRow); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + if (isFocusOwner()) { + forTree(SelectionTree.this); + return; + } else { + forTree(oppositeTree); + } + } + }); + + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "select/unselect"); + actionMap.put("select/unselect", new AbstractAction() { + + protected void forTree(SelectionTree tree) { + int selectedRow = tree.getSelectedRow(); + if (selectedRow == -1) { + return; + } + + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) tree.getPathForRow(selectedRow).getLastPathComponent(); + tree.getTreeModel().setValueAt(!node.isSelected(), node, 1); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (isFocusOwner()) { + forTree(SelectionTree.this); + return; + } else { + forTree(oppositeTree); + } + } + }); + } + + public SelectionTreeModel getTreeModel() { + return (SelectionTreeModel) getTreeTableModel(); + } + + @Override + protected void configureEnclosingScrollPane() { + // ne rien faire, on utilise un autre composant + } + + @Override + protected void unconfigureEnclosingScrollPane() { + // ne rien faire, on utilise un autre composant + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeCellRenderer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeCellRenderer.java new file mode 100644 index 0000000..5fcdd04 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeCellRenderer.java @@ -0,0 +1,39 @@ +package fr.ird.observe.application.swing.ui.tree.selection; + +import fr.ird.observe.application.swing.ui.tree.selection.nodes.SelectionTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.TripLonglineSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.TripSeineSelectionTreeNode; +import org.jdesktop.swingx.tree.DefaultXTreeCellRenderer; + +import javax.swing.Icon; +import javax.swing.JLabel; +import javax.swing.JTree; +import java.awt.Component; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SelectionTreeCellRenderer extends DefaultXTreeCellRenderer { + + public Icon getIcon(SelectionTreeNodeSupport node) { + return node.getIcon(""); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { + SelectionTreeNodeSupport node = (SelectionTreeNodeSupport) value; + Icon icon = getIcon(node); + JLabel treeCellRendererComponent = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + treeCellRendererComponent.setIcon(icon); + if (node instanceof TripSeineSelectionTreeNode) { + treeCellRendererComponent.setToolTipText(((TripSeineSelectionTreeNode) node).getToolTipText()); + } else if (node instanceof TripLonglineSelectionTreeNode) { + treeCellRendererComponent.setToolTipText(((TripLonglineSelectionTreeNode) node).getToolTipText()); + } + return treeCellRendererComponent; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jaxx new file mode 100644 index 0000000..66e9f14 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jaxx @@ -0,0 +1,43 @@ +<!-- + #%L + ObServe :: Application Swing + %% + Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit + %% + 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% + --> +<JPanel layout='{new BorderLayout()}'> + + <!-- label --> + <String id='labelText' javaBean='null'/> + + <!-- tree --> + <SelectionTree id='treeTable' javaBean='new SelectionTree()'/> + + + <JLabel id="label" constraints='BorderLayout.CENTER'/> + + <JToolBar id='toolbar' constraints='BorderLayout.EAST'> + + <!-- les boutons pour grouper/déplier tout l'arbre --> + <JButton id='colapseAll' onActionPerformed='handler.collapseAll()'/> + <JButton id='expandAll' onActionPerformed='handler.expandAll()'/> + + <!-- les boutons pour sélectionner/déselectionner tout l'arbre --> + <JButton id='selectAll' onActionPerformed='handler.selectAll()'/> + <JButton id='unselectAll' onActionPerformed='handler.unselectAll()'/> + + </JToolBar> + +</JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractDataReferenceChildLoador.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jcss similarity index 54% rename from application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractDataReferenceChildLoador.java rename to application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jcss index 828496a..1bdf131 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/loadors/AbstractDataReferenceChildLoador.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeader.jcss @@ -1,39 +1,50 @@ -package fr.ird.observe.application.swing.ui.tree.loadors; - -/*- +/* * #%L - * ObServe :: Application Swing + * ObServe :: Swing * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit + * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit * %% * 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.ird.observe.services.dto.DataDto; -import fr.ird.observe.services.dto.DataReference; +#label { + text:{getLabelText()}; +} -/** - * @author Kevin Morin (Code Lutin) - * @since x.x - */ -abstract class AbstractDataReferenceChildLoador<O extends DataDto> extends AbstractNodeChildLoador<DataReference<O>, O> { +JButton { + focusable:false; + focusPainted:false; +} - private static final long serialVersionUID = 1L; +#colapseAll { + actionIcon:collapse; + toolTipText:"observe.tree.action.collapseAll.tip"; +} + +#expandAll { + actionIcon:expand; + toolTipText:"observe.tree.action.expandAll.tip"; +} + +#selectAll { + actionIcon:select; + toolTipText:"observe.tree.action.selectAll.tip"; +} - AbstractDataReferenceChildLoador(Class<O> beanType) { - super(beanType); - } +#unselectAll { + actionIcon:unselect; + toolTipText:"observe.tree.action.unselectAll.tip"; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeaderHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeaderHandler.java new file mode 100644 index 0000000..6d79d0a --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeHeaderHandler.java @@ -0,0 +1,96 @@ +package fr.ird.observe.application.swing.ui.tree.selection; + +/* + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit + * %% + * 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 jaxx.runtime.spi.UIHandler; + +import javax.swing.SwingUtilities; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SelectionTreeHeaderHandler implements UIHandler<SelectionTreeHeader> { + + private SelectionTreeHeader ui; + + public SelectionTreeHeader getUi() { + return ui; + } + + private SelectionTree getTree() { + return getUi().getTreeTable(); + } + + @Override + public void beforeInit(SelectionTreeHeader selectionTreeHeader) { + this.ui = selectionTreeHeader; + } + + @Override + public void afterInit(SelectionTreeHeader selectionTreeHeader) { + + PropertyChangeListener propertyChangeListener = e -> onTripCountChanged((int) e.getNewValue()); + selectionTreeHeader.addPropertyChangeListener(SelectionTreeHeader.PROPERTY_TREE_TABLE, e -> { + SelectionTreeModel newValue = ((SelectionTree) e.getNewValue()).getTreeModel(); + newValue.removePropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, propertyChangeListener); + newValue.addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, propertyChangeListener); + }); + } + + private void onTripCountChanged(int newValue) { + + String text; + if (newValue == 0) { + text = t("observe.selection.no.trips.selected"); + } else { + text = t("observe.selection.selected.trips", newValue); + } + getUi().setLabelText(text); + } + + public void collapseAll() { + SelectionTree tree = getTree(); + tree.collapseAll(); + } + + public void expandAll() { + SelectionTree tree = getTree(); + tree.expandAll(); + } + + public void selectAll() { + SelectionTree selectionTree = getTree(); + selectionTree.getTreeModel().selectAllTrips(); + SwingUtilities.invokeLater(selectionTree::repaint); + } + + public void unselectAll() { + SelectionTree selectionTree = getTree(); + selectionTree.getTreeModel().unselectAllTrips(); + SwingUtilities.invokeLater(selectionTree::repaint); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeModel.java new file mode 100644 index 0000000..19eea6a --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/SelectionTreeModel.java @@ -0,0 +1,339 @@ +package fr.ird.observe.application.swing.ui.tree.selection; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.admin.export.TripEntry; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.ProgramSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.ReferenceSelectionTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.ReferentialsSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.RootSelectionTreeNode; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.SelectionTreeNodeSupport; +import fr.ird.observe.application.swing.ui.tree.selection.nodes.TripSelectionTreeNodeSupport; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ReferentialDto; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableNode; + +import javax.swing.tree.TreePath; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +/** + * Created on 14/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class SelectionTreeModel extends DefaultTreeTableModel { + + public static final String SELECTED_COUNT = "selectedCount"; + public static final String SELECTION_EMPTY = "selectionEmpty"; + private boolean loadSeine = true; + private boolean loadLongline = true; + private boolean loadReferential = true; + private boolean showEmptyTrips = true; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + private int selectedCount; + private boolean useOpenData; + + @Override + public int getColumnCount() { + return 2; + } + + @Override + public Class<?> getColumnClass(int column) { + if (column == 0) { + return Object.class; + } + return boolean.class; + } + + @Override + public Object getValueAt(Object node, int column) { + switch (column) { + case 0: + return node; + default: + return ((SelectionTreeNodeSupport) node).isSelected(); + } + } + + @Override + public void setValueAt(Object value, Object node, int column) { + SelectionTreeNodeSupport node1 = (SelectionTreeNodeSupport) node; + node1.setSelected((Boolean) value); + if (node1.isLeaf()) { + modelSupport.firePathChanged(new TreePath(getPathToRoot(node1.getParent()))); + } else { + Enumeration<? extends TreeTableNode> children = node1.getParent().children(); + while (children.hasMoreElements()) { + TreeTableNode treeTableNode = children.nextElement(); + modelSupport.firePathChanged(new TreePath(treeTableNode)); + } + } + recomputeSelectedCount(); + } + + private void recomputeSelectedCount() { + int result = getSelectedData().size(); + setSelectedCount(result); + } + + public int getSelectedCount() { + return selectedCount; + } + + public void setSelectedCount(int selectedCount) { + int oldValue = getSelectedCount(); + boolean oldSelectionempty = isSelectionEmpty(); + this.selectedCount = selectedCount; + pcs.firePropertyChange(SELECTED_COUNT, oldValue, selectedCount); + pcs.firePropertyChange(SELECTION_EMPTY, oldSelectionempty, isSelectionEmpty()); + } + + public boolean isSelectionEmpty() { + return selectedCount == 0; + } + + @Override + public boolean isCellEditable(Object node, int column) { + SelectionTreeNodeSupport node1 = (SelectionTreeNodeSupport) node; + return column == 1 && !(node1 instanceof ProgramSelectionTreeNode && node1.isLeaf()); + } + + @Override + public RootSelectionTreeNode getRoot() { + return (RootSelectionTreeNode) super.getRoot(); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String name, PropertyChangeListener listener) { + pcs.addPropertyChangeListener(name, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String name, PropertyChangeListener listener) { + pcs.removePropertyChangeListener(name, listener); + } + + public SelectionTreeModel() { + super(new RootSelectionTreeNode()); + } + + public void setLoadSeine(boolean loadSeine) { + this.loadSeine = loadSeine; + } + + public void setLoadLongline(boolean loadLongline) { + this.loadLongline = loadLongline; + } + + public void setLoadReferential(boolean loadReferential) { + this.loadReferential = loadReferential; + } + + public void setShowEmptyTrips(boolean showEmptyTrips) { + this.showEmptyTrips = showEmptyTrips; + } + + public boolean isLoadSeine() { + return loadSeine; + } + + public boolean isLoadLongline() { + return loadLongline; + } + + public boolean isLoadReferential() { + return loadReferential; + } + + public boolean isShowEmptyTrips() { + return showEmptyTrips; + } + + @Override + public int getHierarchicalColumn() { + return 0; + } + + public Set<DataReference<?>> getSelectedData() { + ImmutableSet.Builder<DataReference<?>> builder = ImmutableSet.builder(); + for (ProgramSelectionTreeNode programNode : getRoot()) { + builder.addAll(programNode.getSelected()); + } + return builder.build(); + } + + public boolean isUseData() { + return isLoadLongline() || isLoadSeine(); + } + + public void populate(ObserveSwingDataSource dataSource) { + RootSelectionTreeNode rootTreeNode = RootSelectionTreeNode.of(this, dataSource); + setRoot(rootTreeNode); + } + + public ImmutableSet<Class<? extends ReferentialDto>> getSelectedReferentiel() { + ImmutableSet.Builder<Class<? extends ReferentialDto>> builder = ImmutableSet.builder(); + for (ReferentialsSelectionTreeNode programNode : getRoot().getReferentialsNodes()) { + if (!programNode.isLeaf()) { + ImmutableList<Class<? extends ReferentialDto>> selected = programNode.getSelected(); + builder.addAll(selected); + } + } + return builder.build(); + } + + public Map<ReferentialReference<ProgramDto>, List<DataReference<?>>> getSelectedDataByProgram() { + ImmutableMap.Builder<ReferentialReference<ProgramDto>, List<DataReference<?>>> result = ImmutableMap.builder(); + for (ProgramSelectionTreeNode programNode : getRoot()) { + if (!programNode.isLeaf()) { + ImmutableList<DataReference<?>> trips = programNode.getSelected(); + result.put(programNode.getData(), trips); + } + } + return result.build(); + } + + public void removeProgram(String programId) { + RootSelectionTreeNode rootNode = getRoot(); + SelectionTreeNodeSupport result = rootNode.findById(programId); + Objects.requireNonNull(result, "Could not find program node with id: " + programId); + removeNodeFromParent(result); + } + + public void removeTrip(ReferentialReference<ProgramDto> program, DataReference trip) { + + RootSelectionTreeNode rootNode = getRoot(); + SelectionTreeNodeSupport programNode = rootNode.findById(program.getId()); + Objects.requireNonNull(programNode, "Could not find program node with id: " + program); + SelectionTreeNodeSupport tripNode = programNode.findById(trip.getId()); + Objects.requireNonNull(tripNode, "Could not find program node with id: " + trip); + removeNodeFromParent(tripNode); + + if (programNode.isLeaf()) { + removeProgram(program.getId()); + } + } + + public boolean containsData(ReferentialReference<ProgramDto> program, DataReference trip) { + ReferenceSelectionTreeNodeSupport programNode = getRoot().findById(program.getId()); + return programNode != null && programNode.findById(trip.getId()) != null; + } + + public void removeAllSelectedData() { + for (ProgramSelectionTreeNode programNode : getRoot()) { + + if (programNode.isSelected()) { + removeProgram(programNode.getId()); + } else { + for (TripSelectionTreeNodeSupport<?> tripNode : programNode) { + if (tripNode.isSelected()) { + removeTrip(programNode.getData(), (DataReference) tripNode.getData()); + } + } + } + + } + recomputeSelectedCount(); + } + + public void selectAllTrips() { + for (ProgramSelectionTreeNode programNode : getRoot()) { + programNode.setSelected(true); + } + recomputeSelectedCount(); + } + + public void unselectAllTrips() { + for (ProgramSelectionTreeNode programNode : getRoot()) { + programNode.setSelected(false); + } + recomputeSelectedCount(); + } + + public void setExistingTrips(List<DataReference<?>> existingTrips) { + for (ProgramSelectionTreeNode programNode : getRoot()) { + for (TripSelectionTreeNodeSupport<?> tripNode : programNode) { + DataReference<?> data = tripNode.getData(); + tripNode.setExist(existingTrips.contains(data)); + } + } + } + + public void setUseOpenData(boolean useOpenData) { + this.useOpenData = useOpenData; + } + + public boolean isUseOpenData() { + return useOpenData; + } + + public boolean isNotEmpty() { + return !isEmpty(); + } + + public ImmutableList<TripEntry> getSelectedTripEntries() { + + ImmutableList.Builder<TripEntry> tripEntries = ImmutableList.builder(); + for (ProgramSelectionTreeNode programNode : getRoot()) { + + ReferentialReference<ProgramDto> program = programNode.getData(); + + for (TripSelectionTreeNodeSupport<?> tripNode : programNode) { + if (tripNode.isSelected()) { + DataReference<?> trip = tripNode.getData(); + boolean exists = tripNode.isExist(); + TripEntry tripEntry = new TripEntry(program, trip, exists); + tripEntries.add(tripEntry); + } + } + + } + return tripEntries.build(); + } + + public boolean isEmpty() { + return getRoot().isLeaf(); + } + + public boolean isDataFull() { + for (ProgramSelectionTreeNode programNode : getRoot()) { + if (!programNode.isSelected()) { + return false; + } + } + return !getRoot().isLeaf(); + } + + // Ne pas supprimer utiliser dans les templates + public ImmutableList<ReferentialReference<ProgramDto>> getSelectedProgram() { + return ImmutableList.copyOf(getSelectedDataByProgram().keySet()); + } + + // Ne pas supprimer utiliser dans les templates + public ImmutableList<DataReference<?>> getSelectedTripsByProgram(ReferentialReference<ProgramDto> program) { + ProgramSelectionTreeNode programNode = (ProgramSelectionTreeNode) getRoot().findById(program.getId()); + return programNode.getSelected(); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ProgramSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ProgramSelectionTreeNode.java new file mode 100644 index 0000000..b469017 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ProgramSelectionTreeNode.java @@ -0,0 +1,85 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import org.apache.commons.collections4.EnumerationUtils; + +import java.util.Iterator; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ProgramSelectionTreeNode extends ReferenceSelectionTreeNodeSupport<ProgramDto, ReferentialReference<ProgramDto>> implements Iterable<TripSelectionTreeNodeSupport<?>> { + + public static ProgramSelectionTreeNode ofSeine(ReferentialReference<ProgramDto> data, ImmutableSet<DataReference<TripSeineDto>> tripSeines) { + ProgramSelectionTreeNode result = new ProgramSelectionTreeNode(data); + for (DataReference<TripSeineDto> tripSeine : tripSeines) { + result.add(new TripSeineSelectionTreeNode(tripSeine)); + } + return result; + } + + public static ProgramSelectionTreeNode ofLongline(ReferentialReference<ProgramDto> data, ImmutableSet<DataReference<TripLonglineDto>> tripLonglines) { + ProgramSelectionTreeNode result = new ProgramSelectionTreeNode(data); + for (DataReference<TripLonglineDto> tripLongline : tripLonglines) { + result.add(new TripLonglineSelectionTreeNode(tripLongline)); + } + return result; + } + + public ProgramSelectionTreeNode(ReferentialReference<ProgramDto> data) { + super(data, true); + } + + @Override + public boolean isOpen() { + return ObserveSwingApplicationContext.get().getOpenDataManager().isOpenProgram(toString()); + } + + @Override + public Iterator<TripSelectionTreeNodeSupport<?>> iterator() { + return (Iterator) EnumerationUtils.toList(super.children()).iterator(); + } + + @Override + public String getText() { + return super.getText() + " (" + getChildCount() + ")"; + } + + @Override + public boolean isSelected() { + for (ReferenceSelectionTreeNodeSupport<?, ?> nodeSupport : this) { + if (!nodeSupport.isSelected()) { + return false; + } + } + return !isLeaf(); + } + + @Override + public void setSelected(boolean selected) { + for (ReferenceSelectionTreeNodeSupport<?, ?> node : this) { + node.setSelected(selected); + } + } + + public ImmutableList<DataReference<?>> getSelected() { + ImmutableList.Builder<DataReference<?>> builder = ImmutableList.builder(); + for (TripSelectionTreeNodeSupport<?> nodeSupport : this) { + if (nodeSupport.isSelected()) { + builder.add(nodeSupport.getData()); + } + } + return builder.build(); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferenceSelectionTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferenceSelectionTreeNodeSupport.java new file mode 100644 index 0000000..40485a6 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferenceSelectionTreeNodeSupport.java @@ -0,0 +1,52 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.AbstractReference; +import fr.ird.observe.services.dto.IdDto; +import org.nuiton.decorator.Decorator; + +import javax.swing.Icon; +import javax.swing.UIManager; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class ReferenceSelectionTreeNodeSupport<D extends IdDto, O extends AbstractReference<D>> extends SelectionTreeNodeSupport<O> { + + private boolean selected; + + public abstract boolean isOpen(); + + public ReferenceSelectionTreeNodeSupport(O data, boolean allowChildren) { + super(data, allowChildren); + } + + @Override + public String getId() { + return getData() == null ? null : getData().getId(); + } + + @Override + public String getText() { + Decorator<D> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferenceDecorator(getData().getType()); + return decorator.toString(getData()); + } + + @Override + public String getIconPath() { + return "navigation." + getData().getType().getName(); + } + + @Override + public boolean isSelected() { + return selected; + } + + @Override + public void setSelected(boolean selected) { + this.selected = selected; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialSelectionTreeNode.java new file mode 100644 index 0000000..fb1e077 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialSelectionTreeNode.java @@ -0,0 +1,51 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.services.dto.referential.ReferentialDto; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ReferentialSelectionTreeNode<D extends ReferentialDto> extends SelectionTreeNodeSupport<Class<D>> { + + private boolean selected; + + public ReferentialSelectionTreeNode(Class<D> data) { + super(data, false); + } + + @Override + public boolean isOpen() { + return true; + } + + @Override + public String getId() { + return null; + } + + @Override + public String getIconPath() { + return "navigation.sub.referentiel"; + } + + @Override + public String getText() { + return t(ObserveI18nDecoratorHelper.getTypeI18nKey(getData())); + } + + @Override + public boolean isSelected() { + return selected; + } + + @Override + public void setSelected(boolean selected) { + this.selected = selected; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialsSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialsSelectionTreeNode.java new file mode 100644 index 0000000..ba35166 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/ReferentialsSelectionTreeNode.java @@ -0,0 +1,86 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.services.dto.referential.ReferentialDto; +import org.apache.commons.collections4.EnumerationUtils; + +import java.util.Iterator; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ReferentialsSelectionTreeNode extends SelectionTreeNodeSupport<String> implements Iterable<ReferentialSelectionTreeNode<?>> { + + public static ReferentialsSelectionTreeNode of(String name, ImmutableSet<Class<? extends ReferentialDto>> types) { + ReferentialsSelectionTreeNode result = new ReferentialsSelectionTreeNode(t(name)); + for (Class<? extends ReferentialDto> aClass : types) { + ReferentialSelectionTreeNode child = new ReferentialSelectionTreeNode<>(aClass); + result.add(child); + } + + return result; + } + + @Override + public void setSelected(boolean selected) { + for (ReferentialSelectionTreeNode<?> node : this) { + node.setSelected(selected); + } + } + + public ReferentialsSelectionTreeNode(String name) { + super(name, true); + } + + @Override + public String getText() { + return t(getData()); + } + + @Override + public String getIconPath() { + return "navigation.referentiel"; + } + + @Override + public boolean isOpen() { + return true; + } + + @Override + public String getId() { + return null; + } + + @Override + public Iterator<ReferentialSelectionTreeNode<?>> iterator() { + return (Iterator) EnumerationUtils.toList(children()).iterator(); + } + + @Override + public boolean isSelected() { + for (ReferentialSelectionTreeNode<?> nodeSupport : this) { + if (!nodeSupport.isSelected()) { + return false; + } + } + return true; + } + + public ImmutableList<Class<? extends ReferentialDto>> getSelected() { + ImmutableList.Builder<Class<? extends ReferentialDto>> builder = ImmutableList.builder(); + for (ReferentialSelectionTreeNode<?> nodeSupport : this) { + if (nodeSupport.isSelected()) { + builder.add(nodeSupport.getData()); + } + } + return builder.build(); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/RootSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/RootSelectionTreeNode.java new file mode 100644 index 0000000..7d5d879 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/RootSelectionTreeNode.java @@ -0,0 +1,115 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ProgramHelper; +import fr.ird.observe.services.dto.referential.ReferentialHelper; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.data.longline.TripLonglineService; +import fr.ird.observe.services.service.data.seine.TripSeineService; +import org.apache.commons.collections4.EnumerationUtils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class RootSelectionTreeNode extends SelectionTreeNodeSupport<Void> implements Iterable<ProgramSelectionTreeNode> { + + public static RootSelectionTreeNode of(SelectionTreeModel treeModel, ObserveSwingDataSource dataSource) { + + RootSelectionTreeNode result = new RootSelectionTreeNode(); + + List<ReferentialReference<ProgramDto>> programs = new ArrayList<>(dataSource.getReferentialReferences(ProgramDto.class)); + ObserveSwingApplicationContext.get().getDecoratorService().sort(ProgramDto.class, programs); + + if (treeModel.isLoadLongline()) { + TripLonglineService tripLonglineService = dataSource.newTripLonglineService(); + programs.stream().filter(ProgramHelper::isProgramLongline).forEach(program -> { + DataReferenceSet<TripLonglineDto> trips = tripLonglineService.getTripLonglineByProgram(program.getId()); + if (treeModel.isShowEmptyTrips() || trips.sizeReference() > 0) { + ProgramSelectionTreeNode programNode = ProgramSelectionTreeNode.ofLongline(program, trips.getReferences()); + result.add(programNode); + } + }); + } + + if (treeModel.isLoadSeine()) { + TripSeineService tripSeineService = dataSource.newTripSeineService(); + programs.stream().filter(ProgramHelper::isProgramSeine).forEach(program -> { + DataReferenceSet<TripSeineDto> trips = tripSeineService.getTripSeineByProgram(program.getId()); + if (treeModel.isShowEmptyTrips() || trips.sizeReference() > 0) { + ProgramSelectionTreeNode programNode = ProgramSelectionTreeNode.ofSeine(program, trips.getReferences()); + result.add(programNode); + } + }); + } + + if (treeModel.isLoadReferential()) { + result.add(ReferentialsSelectionTreeNode.of(n("observe.type.reference.common"), ReferentialHelper.REFERENCE_COMMON_DTOS)); + result.add(ReferentialsSelectionTreeNode.of(n("observe.type.reference.longline"), ReferentialHelper.REFERENCE_LONGLINE_DTOS)); + result.add(ReferentialsSelectionTreeNode.of(n("observe.type.reference.seine"), ReferentialHelper.REFERENCE_SEINE_DTOS)); + } + + return result; + } + + public RootSelectionTreeNode() { + super(null, true); + } + + @Override + public boolean isOpen() { + return false; + } + + @Override + public String getId() { + return null; + } + + @Override + public String getText() { + return null; + } + + @Override + public String getIconPath() { + return null; + } + + @Override + public Iterator<ProgramSelectionTreeNode> iterator() { + return (Iterator) EnumerationUtils.toList(children()).stream().filter(c -> c instanceof ProgramSelectionTreeNode).iterator(); + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public void setSelected(boolean selected) { + // rien a faire + } + + public ReferentialsSelectionTreeNode[] getReferentialsNodes() { + ReferentialsSelectionTreeNode[] result = new ReferentialsSelectionTreeNode[3]; + result[0] = (ReferentialsSelectionTreeNode) getChildAt(getChildCount() - 3); + result[1] = (ReferentialsSelectionTreeNode) getChildAt(getChildCount() - 2); + result[2] = (ReferentialsSelectionTreeNode) getChildAt(getChildCount() - 1); + return result; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/SelectionTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/SelectionTreeNodeSupport.java new file mode 100644 index 0000000..b12b0f4 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/SelectionTreeNodeSupport.java @@ -0,0 +1,68 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import javax.swing.Icon; +import javax.swing.UIManager; +import java.awt.Color; +import java.util.Enumeration; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class SelectionTreeNodeSupport<O> extends DefaultMutableTreeTableNode { + + public abstract boolean isOpen(); + + public abstract String getId(); + + public abstract String getText(); + + public abstract String getIconPath(); + + public SelectionTreeNodeSupport(O data, boolean allowChildren) { + super(data, allowChildren); + } + + @Override + public String toString() { + return getText(); + } + + public O getData() { + return (O) getUserObject(); + } + + public Icon getIcon(String suffix) { + String iconPath = getIconPath(); + return iconPath == null ? null : UIManager.getIcon(iconPath + suffix); + } + + public abstract boolean isSelected(); + + public abstract void setSelected(boolean selected); + + @Override + public Enumeration<SelectionTreeNodeSupport> children() { + return (Enumeration) super.children(); + } + + public ReferenceSelectionTreeNodeSupport findById(String id) { + Enumeration<SelectionTreeNodeSupport> children = children(); + while (children.hasMoreElements()) { + ReferenceSelectionTreeNodeSupport<?, ?> child = (ReferenceSelectionTreeNodeSupport) children.nextElement(); + if (id.equals(child.getData().getId())) { + return child; + } + } + return null; + } + + public Color getColor() { + return isOpen() ? Color.BLACK : Color.GRAY; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripLonglineSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripLonglineSelectionTreeNode.java new file mode 100644 index 0000000..648709d --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripLonglineSelectionTreeNode.java @@ -0,0 +1,44 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.longline.TripLonglineHelper; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class TripLonglineSelectionTreeNode extends TripSelectionTreeNodeSupport<TripLonglineDto> { + + public TripLonglineSelectionTreeNode(DataReference<TripLonglineDto> data) { + super(data, false); + } + + @Override + public boolean isOpen() { + return ObserveSwingApplicationContext.get().getOpenDataManager().isOpenTripLongline(getData().getId()); + } + + @Override + public String getText() { + String s = super.getText() + " (" + TripLonglineHelper.getActivityCount(getData()) + ")"; + if (isExist()) { + return t("observe.common.exist.on.remote", s); + } + return s; + } + + public String getToolTipText() { + if (isExist()) { + return t("observe.message.warning.will.be.delete", getText()); + } else { + return getText(); + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSeineSelectionTreeNode.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSeineSelectionTreeNode.java new file mode 100644 index 0000000..c723050 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSeineSelectionTreeNode.java @@ -0,0 +1,45 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.dto.seine.TripSeineHelper; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 18/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class TripSeineSelectionTreeNode extends TripSelectionTreeNodeSupport<TripSeineDto> { + + public TripSeineSelectionTreeNode(DataReference<TripSeineDto> data) { + super(data, false); + } + + @Override + public boolean isOpen() { + return ObserveSwingApplicationContext.get().getOpenDataManager().isOpenTripSeine(getData().getId()); + } + + @Override + public String getText() { + String s = super.getText() + " (" + TripSeineHelper.getRouteCount(getData()) + ")"; + if (isExist()) { + return t("observe.common.exist.on.remote", s); + } + return s; + } + + public String getToolTipText() { + if (isExist()) { + return t("observe.message.warning.will.be.delete", getText()); + } else { + return getText(); + } + } + +} + diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSelectionTreeNodeSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSelectionTreeNodeSupport.java new file mode 100644 index 0000000..ffc8278 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/selection/nodes/TripSelectionTreeNodeSupport.java @@ -0,0 +1,27 @@ +package fr.ird.observe.application.swing.ui.tree.selection.nodes; + +import fr.ird.observe.services.dto.DataDto; +import fr.ird.observe.services.dto.DataReference; + +/** + * Created on 20/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public abstract class TripSelectionTreeNodeSupport<D extends DataDto> extends ReferenceSelectionTreeNodeSupport<D, DataReference<D>> { + + private boolean exist; + + public TripSelectionTreeNodeSupport(DataReference<D> data, boolean allowChildren) { + super(data, allowChildren); + } + + public boolean isExist() { + return exist; + } + + public void setExist(boolean exist) { + this.exist = exist; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/util/DecoratedNodeEntity.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/util/DecoratedNodeEntity.java index 7375552..daa20f7 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/util/DecoratedNodeEntity.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/util/DecoratedNodeEntity.java @@ -22,7 +22,7 @@ package fr.ird.observe.application.swing.ui.util; * #L% */ -import fr.ird.observe.application.swing.ui.tree.node.AbstrctReferenceNodeSupport; +import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; import fr.ird.observe.services.dto.IdDto; import org.nuiton.decorator.Decorator; @@ -38,10 +38,10 @@ public class DecoratedNodeEntity { private final String label; - public static <E extends IdDto> DecoratedNodeEntity newDecoratedNodeEntity(AbstrctReferenceNodeSupport<E, ?> node, Decorator<?> decorator) { + public static <E extends IdDto> DecoratedNodeEntity newDecoratedNodeEntity(ReferenceNavigationTreeNodeSupport<E, ?> node, Decorator<?> decorator) { Objects.requireNonNull(node); Objects.requireNonNull(decorator); - return new DecoratedNodeEntity(node.getId(), decorator.toString(node.getEntity())); + return new DecoratedNodeEntity(node.getId(), decorator.toString(node.getData())); } public String getId() { diff --git a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_en.ftl b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_en.ftl index 75b4fff..59a40a3 100644 --- a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_en.ftl +++ b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_en.ftl @@ -49,25 +49,25 @@ <ul> <li> - <#if selectDataModel.isDataEmpty()> + <#if selectDataModel.isEmpty()> No data to export <#elseif selectDataModel.isDataFull()> All observed data have to be exported - (<#if selectDataModel.selectDataSize() == 1> + (<#if selectDataModel.getSelectedCount() == 1> 1 trip <#else> - ${selectDataModel.selectDataSize()} trips + ${selectDataModel.getSelectedCount()} trips </#if>). <#else> - <#if selectDataModel.selectDataSize() == 1> + <#if selectDataModel.getSelectedCount() == 1> 1 trip <#else> - ${selectDataModel.selectDataSize()} trips + ${selectDataModel.getSelectedCount()} trips </#if> à exporter diff --git a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_es.ftl b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_es.ftl index 61b01e4..04863d4 100644 --- a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_es.ftl +++ b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_es.ftl @@ -49,25 +49,25 @@ <ul> <li> - <#if selectDataModel.isDataEmpty()> + <#if selectDataModel.isEmpty()> No hay datos de observaciones a exporter <#elseif selectDataModel.isDataFull()> Todos los datos de observador deben ser exportados - (<#if selectDataModel.selectDataSize() == 1> + (<#if selectDataModel.getSelectCedount() == 1> 1 marea <#else> - ${selectDataModel.selectDataSize()} mareas + ${selectDataModel.getSelectedCount()} mareas </#if>). <#else> - <#if selectDataModel.selectDataSize() == 1> + <#if selectDataModel.getSelectedCount() == 1> 1 marea <#else> - ${selectDataModel.selectDataSize()} mareas + ${selectDataModel.getSelectedCount()} mareas </#if> a exportar diff --git a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl index 65720af..d3c16cb 100644 --- a/application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl +++ b/application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl @@ -49,25 +49,25 @@ <ul> <li> - <#if selectDataModel.isDataEmpty()> + <#if selectDataModel.isEmpty()> Pas de données observateur à exporter <#elseif selectDataModel.isDataFull()> Toutes les données observateur sont à exporter - (<#if selectDataModel.selectDataSize() == 1> + (<#if selectDataModel.getSelectedCount() == 1> 1 marée <#else> - ${selectDataModel.selectDataSize()} marées + ${selectDataModel.getSelectedCount()} marées </#if>). <#else> - <#if selectDataModel.selectDataSize() == 1> + <#if selectDataModel.getSelectedCount() == 1> 1 marée <#else> - ${selectDataModel.selectDataSize()} marées + ${selectDataModel.getSelectedCount()} marées </#if> à exporter diff --git a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties index 9514fdc..60f9b8c 100644 --- a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties +++ b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties @@ -1556,6 +1556,8 @@ observe.security.unused=Unused observe.security.unused.tip=Unused observe.security.utilisateur=User observe.security.utilisateur.tip=Read on data and referential +observe.selection.no.trips.selected=No trip selected. +observe.selection.selected.trips=%s selected trip(s). observe.storage.action.apply=Apply observe.storage.action.apply.tip=Apply configured storage observe.storage.action.canMigrate=Update database (current version %1$s) diff --git a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties index 35ebcc4..4f0439b 100644 --- a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties +++ b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties @@ -1556,6 +1556,8 @@ observe.security.unused=No utilizado observe.security.unused.tip=No usar este rol observe.security.utilisateur=Usuario observe.security.utilisateur.tip=El rol tiene permisos de lectura sobre el referencial y los datos +observe.selection.no.trips.selected=Aucune marée sélectionnée. \#TODO +observe.selection.selected.trips=%s marée(s) sélectionnée(s). \#TODO observe.storage.action.apply=Utilizar observe.storage.action.apply.tip=Utilizar la fuente de datos configuarada observe.storage.action.canMigrate=Actualización de la base (versión actual %1$s) diff --git a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties index af21d96..83536fa 100644 --- a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties +++ b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties @@ -1556,6 +1556,8 @@ observe.security.unused=Non utilisé observe.security.unused.tip=Ne pas utiliser ce rôle observe.security.utilisateur=Utilisateur observe.security.utilisateur.tip=Rôle ayant les droits de lecture sur le référentiel et les données +observe.selection.no.trips.selected=Aucune marée sélectionnée. +observe.selection.selected.trips=%s marée(s) sélectionnée(s). observe.storage.action.apply=Utiliser observe.storage.action.apply.tip=Utiliser la source de données configurée observe.storage.action.canMigrate=Mettre à jour la base (version courante %1$s) diff --git a/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineImpl.java b/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineImpl.java index 23699b0..b19940d 100644 --- a/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineImpl.java +++ b/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineImpl.java @@ -32,6 +32,8 @@ public class TripLonglineImpl extends TripLonglineAbstract { private static final long serialVersionUID = 1L; + private int activityCount; + @Override public String getObserverLabel() { return observer == null ? "" : observer.getLastName() + " " + observer.getFirstName(); @@ -47,4 +49,13 @@ public class TripLonglineImpl extends TripLonglineAbstract { return false; } + @Override + public int getActivityCount() { + return activityCount; + } + + @Override + public void setActivityCount(int activityCount) { + this.activityCount = activityCount; + } } diff --git a/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineTopiaDao.java b/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineTopiaDao.java index 57a62b5..51f0511 100644 --- a/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineTopiaDao.java +++ b/entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineTopiaDao.java @@ -257,7 +257,8 @@ public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongl " p.lastName," + " p.firstName," + " v.topiaId," + - " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + + " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + "," + + " (select count(*) from observe_longline.activity a where a.trip = t.topiaId) as activityCount" + " FROM observe_longline.trip t, observe_common.person p, observe_common.vessel v, observe_common.program pr, observe_longline.triptype tt" + " WHERE " + " t.program = ?" + @@ -283,7 +284,8 @@ public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongl " p.lastName," + " p.firstName," + " v.topiaId," + - " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + + " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + "," + + " (select count(*) from observe_longline.activity a where a.trip = t.topiaId) as activityCount" + " FROM observe_longline.trip t, observe_common.person p, observe_common.vessel v, observe_common.program pr, observe_longline.triptype tt" + " WHERE " + " t.topiaId = ?" + @@ -333,6 +335,7 @@ public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongl vessel.setTopiaId(vesselId); String label = set.getString(9); I18nReferenceEntities.setLabel(referenceLocale, vessel, label); + trip.setActivityCount(set.getInt(10)); trip.setVessel(vessel); return trip; diff --git a/entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramTopiaDao.java b/entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramTopiaDao.java deleted file mode 100644 index 3e7775a..0000000 --- a/entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramTopiaDao.java +++ /dev/null @@ -1,124 +0,0 @@ -package fr.ird.observe.entities.referentiel; - -/* - * #%L - * ObServe :: Entities - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit - * %% - * 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.ird.observe.entities.constants.GearTypePersist; -import org.nuiton.topia.persistence.support.TopiaSqlQuery; -import org.nuiton.topia.persistence.support.TopiaSqlSupport; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - - -public class ProgramTopiaDao extends AbstractProgramTopiaDao<Program> { - - public List<Program> findAllStub(int referenceLocale) { - return StubSqlQuery.findAll(topiaSqlSupport, referenceLocale); - - } - - public Program findStubByTopiaId(String programId, int referentielLocale) { - return StubSqlQuery.find(topiaSqlSupport, programId, referentielLocale); - } - - - private static class StubSqlQuery extends TopiaSqlQuery<Program> { - - private final String sql; - - private final String id; - - private final int referenceLocale; - - static List<Program> findAll(TopiaSqlSupport topiaSqlSupport, int referenceLocale) { - - String sql = "SELECT" + - " p.topiaId," + - " p.gearType," + - " p." + I18nReferenceEntities.getPropertyName(referenceLocale) + - " FROM observe_common.program p" + - " ORDER BY p." + I18nReferenceEntities.getPropertyName(referenceLocale); - - StubSqlQuery request = new StubSqlQuery(sql, null, referenceLocale); - return topiaSqlSupport.findMultipleResult(request); - - } - - static Program find(TopiaSqlSupport topiaSqlSupport, String tripId, int referenceLocale) { - - String sql = "SELECT" + - " p.topiaId," + - " p.gearType," + - " p." + I18nReferenceEntities.getPropertyName(referenceLocale) + - "(select count(*) from observe_seine.trip t where t.program = p.id) + (select count(*) from observe_longline.trip t where t.program = p.id) "+ - " FROM observe_common.program p" + - " WHERE " + - " p.topiaId = ?" + - " ORDER BY p." + I18nReferenceEntities.getPropertyName(referenceLocale); - - StubSqlQuery request = new StubSqlQuery(sql, tripId, referenceLocale); - return topiaSqlSupport.findSingleResult(request); - - } - - StubSqlQuery(String sql, String id, int referenceLocale) { - this.sql = sql; - this.id = id; - this.referenceLocale = referenceLocale; - } - - @Override - public PreparedStatement prepareQuery(Connection connection) throws SQLException { - PreparedStatement preparedStatement = connection.prepareStatement(sql); - if (id != null) { - preparedStatement.setString(1, id); - } - return preparedStatement; - } - - @Override - public Program prepareResult(ResultSet set) throws SQLException { - - Program program = new ProgramImpl(); - program.setTopiaId(set.getString(1)); - - int gearTypeOrdinal = set.getInt(2); - GearTypePersist gearType = GearTypePersist.fromOrdinal(gearTypeOrdinal); - program.setGearType(gearType); - - String label = set.getString(3); - I18nReferenceEntities.setLabel(referenceLocale, program, label); - - int tripCount = set.getInt(4); - program.setTripCount(tripCount); - return program; - - } - - } - - -} diff --git a/entities/src/main/xmi/observe-longline.zargo b/entities/src/main/xmi/observe-longline.zargo index f96b968..57dd558 100644 Binary files a/entities/src/main/xmi/observe-longline.zargo and b/entities/src/main/xmi/observe-longline.zargo differ diff --git a/services-dto-reference/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java b/services-dto-reference/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java index 30012e0..153dafb 100644 --- a/services-dto-reference/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java +++ b/services-dto-reference/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java @@ -135,6 +135,7 @@ public enum DataReferenceSetDefinitions { .addProperty(Date.class, TripLonglineDto.PROPERTY_END_DATE) .addProperty(String.class, TripLonglineDto.PROPERTY_PROGRAM + "Id") .addProperty(String.class, TripLonglineDto.PROPERTY_TRIP_TYPE + "Id") + .addProperty(int.class, TripLonglineDto.PROPERTY_ACTIVITY_COUNT) .addProperty(String.class, TripLonglineDto.PROPERTY_VESSEL) .addProperty(String.class, TripLonglineDto.PROPERTY_OBSERVER)), diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/longline/TripLonglineHelper.java b/services-dto/src/main/java/fr/ird/observe/services/dto/longline/TripLonglineHelper.java new file mode 100644 index 0000000..6359eca --- /dev/null +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/longline/TripLonglineHelper.java @@ -0,0 +1,10 @@ +package fr.ird.observe.services.dto.longline; + +import fr.ird.observe.services.dto.DataReference; + +public class TripLonglineHelper extends GeneratedTripLonglineHelper { + + public static int getActivityCount(DataReference<TripLonglineDto> data) { + return (int) data.getPropertyValue(TripLonglineDto.PROPERTY_ACTIVITY_COUNT); + } +} diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/referential/ProgramHelper.java b/services-dto/src/main/java/fr/ird/observe/services/dto/referential/ProgramHelper.java index 80cf1a4..dfae73d 100644 --- a/services-dto/src/main/java/fr/ird/observe/services/dto/referential/ProgramHelper.java +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/referential/ProgramHelper.java @@ -54,8 +54,8 @@ public class ProgramHelper extends GeneratedProgramHelper { return result; } -// public static Iterable<ReferenceDto<ProgramDto>> filterReferencesByGearType(Iterable<ReferenceDto<ProgramDto>> programs, GearType gearType) { -// return Iterables.filter(programs, ReferenceDtos.newLabelValuePredicate(ProgramDto.PROPERTY_GEAR_TYPE, gearType)); -// } + public static int getTripCount(ReferentialReference<ProgramDto> reference) { + return (int) reference.getPropertyValue(ProgramDto.PROPERTY_TRIP_COUNT); + } } diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/referential/seine/VesselActivitySeineHelper.java b/services-dto/src/main/java/fr/ird/observe/services/dto/referential/seine/VesselActivitySeineHelper.java index 4b8395d..e908653 100644 --- a/services-dto/src/main/java/fr/ird/observe/services/dto/referential/seine/VesselActivitySeineHelper.java +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/referential/seine/VesselActivitySeineHelper.java @@ -22,7 +22,6 @@ package fr.ird.observe.services.dto.referential.seine; * #L% */ -import com.google.common.collect.ImmutableSet; import fr.ird.observe.services.dto.referential.ReferentialReference; public class VesselActivitySeineHelper extends GeneratedVesselActivitySeineHelper { @@ -31,22 +30,37 @@ public class VesselActivitySeineHelper extends GeneratedVesselActivitySeineHelpe public static final String VESSEL_ACTIVITY_ID_CHANGED_ZONE = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1379684416896#0.38648073770690594"; + public static final String ACTIVITY_FIN_DE_VEILLE = "16"; + + public static final String ACTIVITY_DEBUT_DE_PECHE = "6"; + public static boolean isSetOpreration(String id) { return VESSEL_ACTIVITY_ID_FOR_SET.equals(id); } - public static boolean isSetOperation(ReferentialReference<VesselActivitySeineDto> vesselActivitySeineRef) { - return vesselActivitySeineRef != null && isSetOpreration(vesselActivitySeineRef.getId()); + public static boolean isSetOperation(ReferentialReference<VesselActivitySeineDto> reference) { + return reference != null && isSetOpreration(reference.getId()); } - public static boolean isDcpOperation(ReferentialReference<VesselActivitySeineDto> vesselActivitySeineRef) { - boolean result = vesselActivitySeineRef != null; + public static boolean isDcpOperation(ReferentialReference<VesselActivitySeineDto> reference) { + boolean result = reference != null; if (result) { - result = (boolean) vesselActivitySeineRef.getPropertyValue(VesselActivitySeineDto.PROPERTY_ALLOW_FAD); + result = (boolean) reference.getPropertyValue(VesselActivitySeineDto.PROPERTY_ALLOW_FAD); } return result; } + public static boolean isActivityFinDeVeille(ReferentialReference<VesselActivitySeineDto> reference) { + return reference != null + && ACTIVITY_FIN_DE_VEILLE.equals(reference.getPropertyValue(VesselActivitySeineDto.PROPERTY_CODE)); + } + + public static boolean isActivityPeche(ReferentialReference<VesselActivitySeineDto> reference) { + return reference != null + && ACTIVITY_DEBUT_DE_PECHE.equals(reference.getPropertyValue(VesselActivitySeineDto.PROPERTY_CODE)); + } + + public static boolean isChangedZoneOperation(String id) { return VESSEL_ACTIVITY_ID_CHANGED_ZONE.equals(id); } diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/seine/ActivitySeineDto.java b/services-dto/src/main/java/fr/ird/observe/services/dto/seine/ActivitySeineDto.java index 6e6bd06..6225a49 100644 --- a/services-dto/src/main/java/fr/ird/observe/services/dto/seine/ActivitySeineDto.java +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/seine/ActivitySeineDto.java @@ -31,39 +31,24 @@ import java.util.Date; public class ActivitySeineDto extends GeneratedActivitySeineDto { - public static final String ACTIVITY_FIN_DE_VEILLE = "16"; - - public static final String ACTIVITY_DEBUT_DE_PECHE = "7"; - - public static final String ACTIVITY_FIN_DE_PECHE = "6"; - public static final String PROPERTY_SET_SEINE = "setSeine"; public static final String PROPERTY_SET_OPERATION = "setOperation"; public static final String PROPERTY_DCP_OPERATION = "dcpOperation"; - private static final long serialVersionUID = 3846974823980413495L; + private static final long serialVersionUID = 1L; public boolean isActivityFinDeVeille() { - return vesselActivitySeine != null - && ACTIVITY_FIN_DE_VEILLE.equals( - vesselActivitySeine.getPropertyValue(VesselActivitySeineDto.PROPERTY_CODE)); + return VesselActivitySeineHelper.isActivityFinDeVeille(vesselActivitySeine); } public boolean isDcpOperation() { - boolean result = vesselActivitySeine != null; - if (result) { - result = (boolean) vesselActivitySeine .getPropertyValue(VesselActivitySeineDto.PROPERTY_ALLOW_FAD); - } - return result; + return VesselActivitySeineHelper.isDcpOperation(vesselActivitySeine); } + public boolean isSetOperation() { - boolean result = vesselActivitySeine != null; - if (result) { - result = VesselActivitySeineHelper.isSetOperation(vesselActivitySeine); - } - return result; + return VesselActivitySeineHelper.isSetOperation(vesselActivitySeine); } @Override diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/seine/TripSeineHelper.java b/services-dto/src/main/java/fr/ird/observe/services/dto/seine/TripSeineHelper.java new file mode 100644 index 0000000..6e18cd9 --- /dev/null +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/seine/TripSeineHelper.java @@ -0,0 +1,9 @@ +package fr.ird.observe.services.dto.seine; + +import fr.ird.observe.services.dto.DataReference; + +public class TripSeineHelper extends GeneratedTripSeineHelper { + public static int getRouteCount(DataReference<TripSeineDto> data) { + return (int) data.getPropertyValue(TripSeineDto.PROPERTY_ROUTE_COUNT); + } +} diff --git a/services-dto/src/main/xmi/observe-services-dto-longline.zargo b/services-dto/src/main/xmi/observe-services-dto-longline.zargo index c95582f..c887dd5 100644 Binary files a/services-dto/src/main/xmi/observe-services-dto-longline.zargo and b/services-dto/src/main/xmi/observe-services-dto-longline.zargo differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm