1 package fr.ifremer.dali.ui.swing;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.google.common.collect.Lists;
27 import com.google.common.collect.Maps;
28 import com.google.common.collect.Sets;
29 import fr.ifremer.dali.config.DaliConfiguration;
30 import fr.ifremer.dali.config.DaliConfigurationOption;
31 import fr.ifremer.dali.decorator.DecoratorService;
32 import fr.ifremer.dali.dto.configuration.context.ContextDTO;
33 import fr.ifremer.dali.dto.data.survey.SurveyFilterDTO;
34 import fr.ifremer.dali.dto.system.extraction.ExtractionDTO;
35 import fr.ifremer.dali.service.DaliDataContext;
36 import fr.ifremer.dali.service.DaliServiceLocator;
37 import fr.ifremer.dali.service.administration.campaign.CampaignService;
38 import fr.ifremer.dali.service.administration.context.ContextService;
39 import fr.ifremer.dali.service.administration.program.ProgramStrategyService;
40 import fr.ifremer.dali.service.administration.user.UserService;
41 import fr.ifremer.dali.service.control.ControlRuleService;
42 import fr.ifremer.dali.service.control.RuleListService;
43 import fr.ifremer.dali.service.extraction.ExtractionPerformService;
44 import fr.ifremer.dali.service.extraction.ExtractionService;
45 import fr.ifremer.dali.service.observation.ObservationService;
46 import fr.ifremer.dali.service.persistence.PersistenceService;
47 import fr.ifremer.dali.service.referential.ReferentialService;
48 import fr.ifremer.dali.service.system.SystemService;
49 import fr.ifremer.dali.ui.swing.action.ImportReferentialSynchroAction;
50 import fr.ifremer.dali.ui.swing.content.DaliMainUI;
51 import fr.ifremer.dali.ui.swing.content.config.DaliConfigUI;
52 import fr.ifremer.dali.ui.swing.content.extraction.ExtractionUI;
53 import fr.ifremer.dali.ui.swing.content.home.HomeUI;
54 import fr.ifremer.dali.ui.swing.content.manage.campaign.CampaignsUI;
55 import fr.ifremer.dali.ui.swing.content.manage.context.ManageContextsUI;
56 import fr.ifremer.dali.ui.swing.content.manage.filter.campaign.FilterCampaignUI;
57 import fr.ifremer.dali.ui.swing.content.manage.filter.department.FilterDepartmentUI;
58 import fr.ifremer.dali.ui.swing.content.manage.filter.equipment.FilterEquipmentUI;
59 import fr.ifremer.dali.ui.swing.content.manage.filter.instrument.FilterInstrumentUI;
60 import fr.ifremer.dali.ui.swing.content.manage.filter.location.FilterLocationUI;
61 import fr.ifremer.dali.ui.swing.content.manage.filter.pmfm.FilterPmfmUI;
62 import fr.ifremer.dali.ui.swing.content.manage.filter.program.FilterProgramUI;
63 import fr.ifremer.dali.ui.swing.content.manage.filter.taxon.FilterTaxonUI;
64 import fr.ifremer.dali.ui.swing.content.manage.filter.taxongroup.FilterTaxonGroupUI;
65 import fr.ifremer.dali.ui.swing.content.manage.filter.user.FilterUserUI;
66 import fr.ifremer.dali.ui.swing.content.manage.program.ProgramsUI;
67 import fr.ifremer.dali.ui.swing.content.manage.program.strategiesByLocation.StrategiesLieuxUI;
68 import fr.ifremer.dali.ui.swing.content.manage.referential.analysisinstruments.ReferentialAnalysisInstrumentsUI;
69 import fr.ifremer.dali.ui.swing.content.manage.referential.department.ManageDepartmentsUI;
70 import fr.ifremer.dali.ui.swing.content.manage.referential.location.ManageLocationUI;
71 import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.ManagePmfmsUI;
72 import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.fraction.ManageFractionsUI;
73 import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.ManageMatricesUI;
74 import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.method.ManageMethodsUI;
75 import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.parameter.ManageParametersUI;
76 import fr.ifremer.dali.ui.swing.content.manage.referential.samplingequipment.ManageSamplingEquipmentsUI;
77 import fr.ifremer.dali.ui.swing.content.manage.referential.taxon.ManageTaxonsUI;
78 import fr.ifremer.dali.ui.swing.content.manage.referential.taxongroup.ManageTaxonGroupUI;
79 import fr.ifremer.dali.ui.swing.content.manage.referential.unit.ReferentialUnitsUI;
80 import fr.ifremer.dali.ui.swing.content.manage.referential.user.ManageUsersUI;
81 import fr.ifremer.dali.ui.swing.content.manage.rule.RulesUI;
82 import fr.ifremer.dali.ui.swing.content.observation.ObservationUI;
83 import fr.ifremer.dali.ui.swing.content.welcome.WelcomeUI;
84 import fr.ifremer.dali.ui.swing.util.tab.DaliTabIndexes;
85 import fr.ifremer.dali.ui.swing.util.table.state.DaliTableSessionState;
86 import fr.ifremer.quadrige3.core.dao.technical.Assert;
87 import fr.ifremer.quadrige3.core.security.QuadrigeUserDetails;
88 import fr.ifremer.quadrige3.core.security.SecurityContextHelper;
89 import fr.ifremer.quadrige3.synchro.service.client.SynchroHistoryService;
90 import fr.ifremer.quadrige3.ui.swing.*;
91 import fr.ifremer.quadrige3.ui.swing.component.OverlayIcon;
92 import fr.ifremer.quadrige3.ui.swing.content.db.DbManagerUI;
93 import fr.ifremer.quadrige3.ui.swing.model.BeanPropertyChangeListener;
94 import fr.ifremer.quadrige3.ui.swing.model.ProgressionUIModel;
95 import fr.ifremer.quadrige3.ui.swing.synchro.log.SynchroLogUI;
96 import fr.ifremer.quadrige3.ui.swing.table.FixedSwingTable;
97 import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
98 import fr.ifremer.quadrige3.ui.swing.table.state.FixedSwingTableSessionState;
99 import jaxx.runtime.JAXXContext;
100 import jaxx.runtime.SwingUtil;
101 import jaxx.runtime.swing.editor.bean.BeanDoubleList;
102 import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
103 import jaxx.runtime.swing.help.JAXXHelpBroker;
104 import jaxx.runtime.swing.help.JAXXHelpUIHandler;
105 import jaxx.runtime.swing.session.BeanDoubleListState;
106 import jaxx.runtime.swing.session.BeanFilterableComboBoxState;
107 import jaxx.runtime.swing.session.State;
108 import org.apache.commons.collections4.CollectionUtils;
109 import org.apache.commons.io.FileUtils;
110 import org.apache.commons.io.IOUtils;
111 import org.apache.commons.lang3.StringUtils;
112 import org.apache.commons.logging.Log;
113 import org.apache.commons.logging.LogFactory;
114 import org.nuiton.jaxx.application.ApplicationBusinessException;
115 import org.nuiton.jaxx.application.ApplicationIOUtil;
116 import org.nuiton.jaxx.application.listener.PropagatePropertyChangeListener;
117 import org.nuiton.jaxx.application.swing.action.ApplicationActionUI;
118 import org.nuiton.jaxx.application.swing.action.ApplicationUIAction;
119 import org.springframework.security.core.GrantedAuthority;
120
121 import javax.swing.Icon;
122 import javax.swing.ImageIcon;
123 import java.awt.Color;
124 import java.awt.Component;
125 import java.io.File;
126 import java.io.InputStream;
127 import java.net.URI;
128 import java.util.List;
129 import java.util.Map;
130 import java.util.Properties;
131 import java.util.Set;
132
133 import static org.nuiton.i18n.I18n.t;
134
135
136
137
138
139
140 public class DaliUIContext extends ApplicationUIContext implements JAXXHelpUIHandler, BeanPropertyChangeListener {
141
142
143
144
145 public static final String PROPERTY_VALIDATION_CONTEXT = "validationContext";
146
147
148
149 public static final String PROPERTY_LAST_OBSERVATION_ID = "lastObservationId";
150
151
152
153 public static final String PROPERTY_SELECTED_CONTEXT_ID = "selectedContextId";
154
155
156
157 public static final String PROPERTY_AUTHENTICATION_LABEL = "authenticationLabel";
158
159
160
161 public static final String PROPERTY_AUTHENTICATION_TOOLTIPTEXT = "authenticationToolTipText";
162
163
164
165 public static final String PROPERTY_SELECTED_SURVEY_ID = "selectedSurveyId";
166
167
168
169 private static final Log LOG = LogFactory.getLog(DaliUIContext.class);
170
171
172
173
174
175
176 protected final Set<UIMessageNotifier> messageNotifiers;
177
178
179
180 protected final DaliDataContext dataContext;
181
182
183
184 private final Map<String, Icon> objectStatusIconMap = Maps.newHashMap();
185
186
187
188
189
190 protected DaliHelpBroker helpBroker;
191 private Properties helpMapping;
192
193
194
195
196
197 private String validationContext;
198
199
200
201 private SurveyFilterDTO surveyFilter;
202
203
204
205
206 private String authenticationLabel;
207 private String authenticationToolTipText;
208
209
210
211
212 private Integer selectedSurveyId;
213
214
215
216 private Integer selectedSamplingOperationId;
217
218
219
220 private String selectProgramCode;
221
222
223
224 private Integer selectedLocationId;
225
226
227
228 private Integer selectedContextId;
229
230 private boolean preventNextImportSynchroCheckAction;
231
232
233
234
235
236
237 protected DaliUIContext(DaliConfiguration config) {
238 super(config);
239
240 Map<Class, State> additionalStates = Maps.newHashMap();
241 additionalStates.put(BeanFilterableComboBox.class, new BeanFilterableComboBoxState());
242 additionalStates.put(BeanDoubleList.class, new BeanDoubleListState());
243 additionalStates.put(SwingTable.class, new DaliTableSessionState());
244
245 additionalStates.put(FixedSwingTable.class, new FixedSwingTableSessionState());
246 setSwingSession(SwingSession.newSwingSession(config.getUIConfigFile(), false, additionalStates));
247 this.dataContext = DaliServiceLocator.instance().getDataContext();
248 PropagatePropertyChangeListener.listenAndPropagateAll(dataContext, this);
249 UIMessageNotifier logMessageNotifier = message -> {
250 if (StringUtils.isNotBlank(message) && LOG.isDebugEnabled()) {
251 LOG.debug(ApplicationUIUtil.removeHtmlTags(message));
252 }
253 };
254 this.messageNotifiers = Sets.newHashSet();
255 addMessageNotifier(logMessageNotifier);
256
257 PROPERTIES_TO_SAVE.add(PROPERTY_SELECTED_CONTEXT_ID);
258 PROPERTIES_TO_SAVE.add(PROPERTY_LAST_OBSERVATION_ID);
259
260 }
261
262
263
264
265
266
267
268 public static DaliUIContext newContext(DaliConfiguration config) {
269 Assert.notNull(config);
270 Assert.state(getInstance() == null, "Application context was already opened!");
271 ApplicationUIContext.setInstance(new DaliUIContext(config));
272 return (DaliUIContext) ApplicationUIContext.getInstance();
273 }
274
275
276
277
278
279
280 public String getValidationContext() {
281 return validationContext;
282 }
283
284
285
286
287
288
289 public void setValidationContext(String validationContext) {
290 Object oldValue = getValidationContext();
291 this.validationContext = validationContext;
292 firePropertyChange(PROPERTY_VALIDATION_CONTEXT, oldValue, validationContext);
293 }
294
295
296
297
298
299
300
301
302
303
304 @Override
305 public void init(String i18nBundleName) {
306
307 super.init(i18nBundleName);
308
309
310
311
312 File helpDirectory = getConfiguration().getHelpDirectory();
313
314 if (!getConfiguration().isFullLaunchMode() && (helpDirectory == null || !helpDirectory.exists())) {
315 helpDirectory = new File(getConfiguration().getDataDirectory(), "help");
316 }
317
318 if (LOG.isDebugEnabled()) {
319 LOG.debug("Help directory: " + helpDirectory);
320 }
321 ApplicationIOUtil.forceMkdir(helpDirectory, t("dali.help.mkDir.error", helpDirectory));
322
323
324 String mappingProperties = "/dali-help-" + getLocale().getLanguage() + ".properties";
325 try {
326
327 InputStream resourceAsStream = getClass().getResourceAsStream(mappingProperties);
328 helpMapping = new Properties();
329 helpMapping.load(resourceAsStream);
330
331 } catch (Exception eee) {
332 LOG.error("Failed to load help mapping file at '" + mappingProperties + "'", eee);
333 }
334 if (LOG.isInfoEnabled()) {
335 LOG.info(String.format("Starts help with locale [%s] at [%s]", getLocale(), helpDirectory));
336 }
337
338 initAuthentication();
339
340
341 checkDbExists();
342
343 }
344
345 private void initAuthentication() {
346
347
348 setAuthenticated(false);
349
350 }
351
352
353
354
355 @Override
356 public void close() {
357
358
359 if (isClosed()) {
360 return;
361 }
362
363
364
365 if (isPersistenceLoaded() && isAuthenticated()) {
366
367 if (LOG.isInfoEnabled()) {
368 LOG.info("Saving Contexts and Filters ...");
369 }
370
371 {
372
373 List<ContextDTO> contexts = getContextService().getAllContexts();
374
375 File exportFile = new File(getConfiguration().getContextDirectory(), String.format(ContextService.EXPORT_FILE_FORMAT, "autosave"));
376
377 getContextService().exportContexts(contexts, exportFile);
378 if (LOG.isInfoEnabled()) {
379 LOG.info(String.format("Auto-save all contexts in %s", exportFile.getAbsolutePath()));
380 }
381 }
382
383 {
384
385 List<ExtractionDTO> extractions = getExtractionService().getExtractions(null, null);
386 File extractionDirectory = getConfiguration().getExtractionDirectory();
387 extractions.forEach(extraction -> {
388 File exportFile = new File(
389 extractionDirectory,
390 String.format("%s-%s-autosave.%s", t("dali.service.extraction.file.prefix"), extraction.getName(), getConfiguration().getExtractionFileExtension())
391 );
392 getExtractionService().exportExtraction(extraction, exportFile);
393 if (LOG.isInfoEnabled()) {
394 LOG.info(String.format("Auto-save extraction in %s", exportFile.getAbsolutePath()));
395 }
396 });
397 }
398 }
399
400 super.close();
401 }
402
403
404
405
406
407
408
409
410
411
412 public DecoratorService getDecoratorService() {
413 return dataContext.getDecoratorService();
414 }
415
416
417
418
419
420
421 public SystemService getSystemService() {
422 return dataContext.getSystemService();
423 }
424
425
426
427
428
429
430 public ReferentialService getReferentialService() {
431 return dataContext.getReferentialService();
432 }
433
434
435
436
437
438
439 public ObservationService getObservationService() {
440 return dataContext.getObservationService();
441 }
442
443
444
445
446
447
448 public ExtractionService getExtractionService() {
449 return dataContext.getExtractionService();
450 }
451
452
453
454
455
456
457 public ExtractionPerformService getExtractionPerformService() {
458 return dataContext.getExtractionPerformService();
459 }
460
461
462
463
464
465
466 public PersistenceService getPersistenceService() {
467 return dataContext.getPersistenceService();
468 }
469
470
471
472
473
474
475 public UserService getUserService() {
476 return dataContext.getUserService();
477 }
478
479
480
481
482
483
484 public SynchroHistoryService getSynchroHistoryService() {
485 return dataContext.getSynchroHistoryService();
486 }
487
488
489
490
491
492
493 public ProgramStrategyService getProgramStrategyService() {
494 return dataContext.getProgramStrategyService();
495 }
496
497
498
499
500
501
502 public ContextService getContextService() {
503 return dataContext.getContextService();
504 }
505
506
507
508
509
510
511 public ControlRuleService getRulesControlService() {
512 return dataContext.getRulesControlService();
513 }
514
515 public RuleListService getRuleListService() {
516 return dataContext.getRuleListService();
517 }
518
519 public CampaignService getCampaignService() {
520 return dataContext.getCampaignService();
521 }
522
523 @Override
524 protected boolean doUpdates() {
525 boolean needRestart = super.doUpdates();
526
527
528 if (StringUtils.isBlank(getConfiguration().getApplicationConfig().getOption(DaliConfigurationOption.DB_TIMEZONE.getKey()))) {
529 getDialogHelper().showWarningDialog(t("dali.config.option.dbTimezone.missing"), t("quadrige3.error.business.warning"));
530 }
531
532 return needRestart;
533 }
534
535
536
537
538 private void checkDbExists() {
539
540
541 String enablePersistenceProperty = System.getProperty("dali.persistence.enable");
542 boolean enablePersistence = !"false".equals(enablePersistenceProperty);
543 if (enablePersistence) {
544 setDbExist(getConfiguration().isDbExists());
545
546 if (!isDbExist()) {
547 setPersistenceLoaded(false);
548 }
549 } else {
550
551
552 setDbExist(true);
553 setPersistenceLoaded(true);
554 }
555 }
556
557
558
559
560 public void closePersistenceService() {
561 closePersistenceService(false, false);
562 }
563
564
565
566
567
568
569
570 public void closePersistenceService(boolean compact, boolean keepAuthenticationProperties) {
571
572 if (isPersistenceLoaded() && compact) {
573 getPersistenceService().compactDb();
574 }
575
576
577 if (LOG.isDebugEnabled()) {
578 LOG.debug("closing Spring context");
579 }
580 IOUtils.closeQuietly(DaliServiceLocator.instance());
581 if (LOG.isDebugEnabled()) {
582 LOG.debug("Spring context closed");
583 }
584
585
586 setPersistenceLoaded(false);
587
588
589 if (keepAuthenticationProperties) {
590 clearDbContext(true);
591 } else {
592 clearDbContext(false);
593 }
594
595 }
596
597
598
599
600
601
602 public void openPersistenceService(boolean clearCache) {
603
604
605 getPersistenceService();
606
607
608 setPersistenceLoaded(true);
609
610
611 if (clearCache || isDbJustInstalled() || isDbJustImportedFromFile()) {
612 clearAllCaches();
613 }
614
615
616 tryReAuthenticate();
617 }
618
619
620
621
622
623
624 public void checkDbContext(ProgressionUIModel progressionModel) {
625
626
627 {
628
629 if (isDbJustImportedFromFile()) {
630
631
632 setDbJustImportedFromFile(false);
633
634
635
636 }
637
638
639 if (isDbJustInstalled()) {
640
641 setDbJustInstalled(false);
642
643
644 clearAllCaches();
645 }
646
647 }
648
649
650 try {
651 getPersistenceService().loadDefaultCaches(progressionModel);
652 } catch (Exception e) {
653
654 LOG.error("Something goes wrong with cache loading", e);
655 }
656
657
658 save();
659
660
661
662
663 if (isSynchroEnabled()) {
664 ImportReferentialSynchroAction importSynchroAction = getActionFactory().createLogicAction(getMainUI().getHandler(), ImportReferentialSynchroAction.class);
665 importSynchroAction.setSilentIfNoUpdate(true);
666 getActionEngine().runFullInternalAction(importSynchroAction);
667 }
668 }
669
670
671
672
673 public void clearAllCaches() {
674
675 if (isPersistenceLoaded()) {
676
677
678 getPersistenceService().clearAllCaches();
679
680
681 dataContext.resetLocalCache();
682 }
683 }
684
685
686
687
688
689
690 protected void clearAuthenticationCache() {
691 }
692
693
694
695
696 @Override
697 public void clearDbContext() {
698
699 if (isPersistenceLoaded()) {
700 tryReAuthenticate();
701 clearDbContext(isAuthenticated());
702 } else {
703 clearDbContext(false);
704 }
705 }
706
707
708
709
710
711
712 protected void clearDbContext(boolean keepAuthentication) {
713 if (LOG.isDebugEnabled()) {
714 LOG.debug(String.format("Clear DB context (keep authentication=%1$s)", keepAuthentication));
715 }
716 if (!keepAuthentication || !isAuthenticated()) {
717 dataContext.clearContext();
718
719 setAuthenticated(false);
720 } else {
721 dataContext.clearContextKeepRecorderPerson();
722
723 setAuthenticated(true);
724 }
725 setDbJustInstalled(false);
726 setDbJustImportedFromFile(false);
727 }
728
729
730
731
732
733
734 public Integer getLastObservationId() {
735 return getConfiguration().getLastSurveyId();
736 }
737
738
739
740
741
742
743 public void setLastObservationId(Integer lastObservationId) {
744 Integer oldValue = getLastObservationId();
745 getConfiguration().setLastSurveyId(lastObservationId);
746 firePropertyChange(PROPERTY_LAST_OBSERVATION_ID, oldValue, lastObservationId);
747 }
748
749
750
751
752
753
754
755
756 public Icon getObjectStatusIcon(String objectType, String statusCode) {
757 if (StringUtils.isBlank(objectType)) {
758 return null;
759 }
760
761 Icon icon = objectStatusIconMap.get(statusCode);
762
763 if (icon == null) {
764
765 OverlayIcon newIcon = new OverlayIcon(SwingUtil.createActionIcon(objectType));
766 newIcon.setOverlay((ImageIcon) getStatusOverlayIcon(statusCode));
767
768 objectStatusIconMap.put(objectType + StringUtils.defaultString(statusCode), newIcon);
769 return newIcon;
770 }
771
772 return icon;
773 }
774
775 private Icon getStatusOverlayIcon(String code) {
776 String overlayName = null;
777 if (getConfiguration().getEnableStatusCode().equals(code)) {
778 overlayName = "overlay-enable";
779 } else if (getConfiguration().getTemporaryStatusCode().equals(code)) {
780 overlayName = "overlay-temporary";
781 } else if (getConfiguration().getDisableStatusCode().equals(code)) {
782 overlayName = "overlay-disable";
783 } else if (getConfiguration().getDeletedStatusCode().equals(code)) {
784 overlayName = "overlay-deleted";
785 }
786 if (overlayName != null) {
787 return SwingUtil.createActionIcon(overlayName);
788 }
789 return null;
790 }
791
792 private Icon getSynchronizationStatusOverlayIcon(String code) {
793 String overlayName = null;
794 if (getConfiguration().getDirtySynchronizationStatusCode().equals(code)) {
795 overlayName = "overlay-dirty";
796 } else if (getConfiguration().getReadySynchronizationStatusCode().equals(code)) {
797 overlayName = "overlay-waiting";
798 } else if (getConfiguration().getSynchronizedSynchronizationStatusCode().equals(code)) {
799 overlayName = "overlay-enable";
800 }
801 if (overlayName != null) {
802 return SwingUtil.createActionIcon(overlayName);
803 }
804 return null;
805 }
806
807
808
809
810
811
812
813
814
815
816 public DaliDataContext getDataContext() {
817 return dataContext;
818 }
819
820
821
822
823
824
825
826
827 @Override
828 public void showHelp(final JAXXContext context, final JAXXHelpBroker broker, final String helpId) {
829
830 String helpIdTemp = helpId;
831 if (helpIdTemp == null) {
832 helpIdTemp = broker.getDefaultID();
833 }
834
835 if (LOG.isInfoEnabled()) {
836 LOG.info("show help " + helpIdTemp);
837 }
838
839 String value = (String) helpMapping.get(helpIdTemp);
840
841 if (value == null) {
842 throw new ApplicationBusinessException(t("dali.context.helpPage.notFound", helpIdTemp));
843 }
844
845 String helpDirectory = getConfiguration().getHelpResourceWithLocale(value);
846 boolean withFragment = helpDirectory.contains("#");
847
848 String fragment = null;
849 if (withFragment) {
850 helpDirectory = StringUtils.substringBefore(helpDirectory, "#");
851 fragment = StringUtils.substringAfter(helpDirectory, "#");
852 }
853
854 URI resolvedUri = new File(helpDirectory).toURI();
855 try {
856
857 if (withFragment) {
858 resolvedUri = new URI(resolvedUri.toString() + "#" + fragment);
859 }
860 if (LOG.isInfoEnabled()) {
861 LOG.info("help uri = " + resolvedUri);
862 }
863 ApplicationUIUtil.openLink(resolvedUri);
864 } catch (Exception e) {
865 LOG.error(e.getMessage());
866 throw new ApplicationBusinessException(t("dali.context.helpPage.notFound", resolvedUri));
867 }
868 }
869
870
871
872
873 @Override
874 public void firePropertyChanged(String propertyName, Object oldValue, Object newValue) {
875 firePropertyChange(propertyName, oldValue, newValue);
876 }
877
878 @Override
879 public void fireIndexedPropertyChanged(String propertyName, int index, Object oldValue, Object newValue) {
880 fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
881 }
882
883
884
885
886 @Override
887 public String getI18nPrefix() {
888 return "dali.property.";
889 }
890
891
892
893
894 @Override
895 public String getDateFormat() {
896 return getConfiguration().getDateFormat();
897 }
898
899
900
901
902 @Override
903 public boolean isActionInProgress(ApplicationUIAction applicationUIAction) {
904
905
906 return false;
907 }
908
909
910
911
912 @Override
913 public void setActionInProgress(ApplicationUIAction applicationUIAction, boolean b) {
914
915
916 }
917
918
919
920
921
922
923
924
925
926
927 @Override
928 public final String getAuthenticationLabel() {
929 return authenticationLabel;
930 }
931
932
933
934
935
936
937 public final void setAuthenticationLabel(String authenticationLabel) {
938 this.authenticationLabel = authenticationLabel;
939 firePropertyChange(PROPERTY_AUTHENTICATION_LABEL, null, authenticationLabel);
940 }
941
942
943
944
945
946
947 public final String getAuthenticationToolTipText() {
948 return authenticationToolTipText;
949 }
950
951
952
953
954
955
956 public final void setAuthenticationToolTipText(String authenticationTooTipText) {
957 this.authenticationToolTipText = authenticationTooTipText;
958 firePropertyChange(PROPERTY_AUTHENTICATION_TOOLTIPTEXT, null, authenticationTooTipText);
959 }
960
961
962
963
964
965
966 @Override
967 public final void setAuthenticated(boolean authenticated) {
968 super.setAuthenticated(authenticated);
969 if (authenticated) {
970 QuadrigeUserDetails user = SecurityContextHelper.getQuadrigeUser();
971 if (LOG.isInfoEnabled()) {
972 LOG.info("the authenticated user is " + user);
973 }
974 dataContext.setRecorderPersonId(user.getUserId());
975 setAuthenticationLabel(t("dali.status.authentication.label.user", user.getUsername()));
976
977
978 String userToolTip = null;
979 if (CollectionUtils.isNotEmpty(user.getAuthorities())) {
980 List<String> authorities = Lists.newArrayList();
981 for (GrantedAuthority authority : user.getAuthorities()) {
982 authorities.add(String.valueOf(authority));
983 }
984 userToolTip = ApplicationUIUtil.getHtmlString(t("dali.status.authentication.label.authorities"), authorities);
985 }
986 setAuthenticationToolTipText(userToolTip);
987
988
989 clearAuthenticationCache();
990
991 } else {
992 SecurityContextHelper.clear();
993 dataContext.setRecorderPersonId(null);
994 setAuthenticationLabel(t("dali.status.authentication.label.none"));
995 setAuthenticationToolTipText(null);
996 }
997 }
998
999
1000
1001
1002
1003
1004 public boolean isAuthenticatedAsLocalUser() {
1005 return isAuthenticated() && SecurityContextHelper.getQuadrigeUser().isLocal();
1006 }
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018 @Override
1019 public ApplicationUI<?, ?> getApplicationUI(Screen screen) {
1020
1021 if (DaliScreen.HOME.equals(screen)) {
1022 return new WelcomeUI(getMainUI());
1023
1024 } else if (DaliScreen.OBSERVATION.equals(screen)) {
1025 return new HomeUI(getMainUI());
1026
1027 } else if (DaliScreen.MANAGE_DB.equals(screen)) {
1028 DbManagerUI dbManagerUI = new DbManagerUI(getMainUI());
1029
1030 dbManagerUI.getExportAllReferentialToFileButton().setVisible(false);
1031 return dbManagerUI;
1032
1033 } else if (DaliScreen.OBSERVATION_GENERAL.equals(screen)) {
1034 return new ObservationUI(getMainUI(), DaliTabIndexes.OBSERVATION_GENERAL);
1035
1036 } else if (DaliScreen.OPERATION_MEASUREMENTS.equals(screen)) {
1037 return new ObservationUI(getMainUI(), DaliTabIndexes.OPERATION_MEASUREMENTS);
1038
1039 } else if (DaliScreen.PHOTOS.equals(screen)) {
1040 return new ObservationUI(getMainUI(), DaliTabIndexes.PHOTOS);
1041
1042 } else if (DaliScreen.CONFIGURATION.equals(screen)) {
1043 return new DaliConfigUI(getMainUI());
1044
1045 } else if (DaliScreen.CONTEXT.equals(screen)) {
1046 return new ManageContextsUI(getMainUI());
1047
1048 } else if (DaliScreen.FILTER_LOCATION.equals(screen)) {
1049 return new FilterLocationUI(getMainUI());
1050
1051 } else if (DaliScreen.FILTER_PROGRAM.equals(screen)) {
1052 return new FilterProgramUI(getMainUI());
1053
1054 } else if (DaliScreen.FILTER_CAMPAIGN.equals(screen)) {
1055 return new FilterCampaignUI(getMainUI());
1056
1057 } else if (DaliScreen.FILTER_DEPARTMENT.equals(screen)) {
1058 return new FilterDepartmentUI(getMainUI());
1059
1060 } else if (DaliScreen.FILTER_ANALYSIS_INSTRUMENT.equals(screen)) {
1061 return new FilterInstrumentUI(getMainUI());
1062
1063 } else if (DaliScreen.FILTER_SAMPLING_EQUIPMENT.equals(screen)) {
1064 return new FilterEquipmentUI(getMainUI());
1065
1066 } else if (DaliScreen.FILTER_PMFM.equals(screen)) {
1067 return new FilterPmfmUI(getMainUI());
1068
1069 } else if (DaliScreen.FILTER_TAXON.equals(screen)) {
1070 return new FilterTaxonUI(getMainUI());
1071
1072 } else if (DaliScreen.FILTER_TAXON_GROUP.equals(screen)) {
1073 return new FilterTaxonGroupUI(getMainUI());
1074
1075 } else if (DaliScreen.FILTER_USER.equals(screen)) {
1076 return new FilterUserUI(getMainUI());
1077
1078 } else if (DaliScreen.LOCATION.equals(screen)) {
1079 return new ManageLocationUI(getMainUI());
1080
1081 } else if (DaliScreen.STRATEGY_LOCATION.equals(screen)) {
1082 return new StrategiesLieuxUI(getMainUI());
1083
1084 } else if (DaliScreen.PROGRAM.equals(screen)) {
1085 return new ProgramsUI(getMainUI());
1086
1087 } else if (DaliScreen.CAMPAIGNS.equals(screen)) {
1088 return new CampaignsUI(getMainUI());
1089
1090 } else if (DaliScreen.RULE_LIST.equals(screen)) {
1091 return new RulesUI(getMainUI());
1092
1093 } else if (DaliScreen.TAXON_GROUP.equals(screen)) {
1094 return new ManageTaxonGroupUI(getMainUI());
1095
1096 } else if (DaliScreen.TAXON.equals(screen)) {
1097 return new ManageTaxonsUI(getMainUI());
1098
1099 } else if (DaliScreen.USER.equals(screen)) {
1100 return new ManageUsersUI(getMainUI());
1101
1102 } else if (DaliScreen.DEPARTMENT.equals(screen)) {
1103 return new ManageDepartmentsUI(getMainUI());
1104
1105 } else if (DaliScreen.PARAMETER.equals(screen)) {
1106 return new ManageParametersUI(getMainUI());
1107
1108 } else if (DaliScreen.METHOD.equals(screen)) {
1109 return new ManageMethodsUI(getMainUI());
1110
1111 } else if (DaliScreen.FRACTION.equals(screen)) {
1112 return new ManageFractionsUI(getMainUI());
1113
1114 } else if (DaliScreen.MATRIX.equals(screen)) {
1115 return new ManageMatricesUI(getMainUI());
1116
1117 } else if (DaliScreen.PMFM.equals(screen)) {
1118 return new ManagePmfmsUI(getMainUI());
1119
1120 } else if (DaliScreen.UNIT.equals(screen)) {
1121 return new ReferentialUnitsUI(getMainUI());
1122
1123 } else if (DaliScreen.SAMPLING_EQUIPMENT.equals(screen)) {
1124 return new ManageSamplingEquipmentsUI(getMainUI());
1125
1126 } else if (DaliScreen.ANALYSIS_INSTRUMENT.equals(screen)) {
1127 return new ReferentialAnalysisInstrumentsUI(getMainUI());
1128
1129 } else if (DaliScreen.SYNCHRO_LOG.equals(screen)) {
1130 return new SynchroLogUI(getMainUI());
1131
1132 } else if (DaliScreen.EXTRACTION.equals(screen)) {
1133 return new ExtractionUI(getMainUI());
1134
1135 }
1136
1137 return null;
1138 }
1139
1140 @Override
1141 public String getSelectedScreenTitle() {
1142 String title;
1143
1144 if (isPersistenceLoaded()) {
1145 if (getSelectedContext() == null) {
1146 title = t("dali.main.title.noContext");
1147 } else {
1148 title = getSelectedContext().getName();
1149 }
1150 } else {
1151
1152
1153 title = t("dali.main.title.noDb");
1154 }
1155 return title;
1156
1157 }
1158
1159
1160
1161
1162 @Override
1163 public DaliMainUI getMainUI() {
1164 return (DaliMainUI) super.getMainUI();
1165 }
1166
1167
1168
1169
1170 @Override
1171 public ApplicationActionUI getExistingActionUI() {
1172 while (getActionUI() == null) {
1173
1174 try {
1175 Thread.sleep(50);
1176 } catch (InterruptedException e) {
1177
1178 }
1179 }
1180 return getActionUI();
1181 }
1182
1183
1184
1185
1186 @Override
1187 public Component getBodyUI() {
1188 return getMainUI() == null ? null : getMainUI().getBody();
1189 }
1190
1191
1192
1193
1194 @Override
1195 public Component getStatusUI() {
1196 return getMainUI() == null ? null : getMainUI().getStatus();
1197 }
1198
1199
1200
1201
1202 @Override
1203 public Color getColorBlockingLayer() {
1204 return getConfiguration().getColorBlockingLayer();
1205 }
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216 public final void addMessageNotifier(UIMessageNotifier messageNotifier) {
1217 this.messageNotifiers.add(messageNotifier);
1218 }
1219
1220
1221
1222
1223
1224
1225 public final void removeMessageNotifier(UIMessageNotifier messageNotifier) {
1226 this.messageNotifiers.remove(messageNotifier);
1227 }
1228
1229
1230
1231
1232 @Override
1233 public void showInformationMessage(String message) {
1234 for (UIMessageNotifier messageNotifier : messageNotifiers) {
1235 messageNotifier.showInformationMessage(message);
1236 }
1237 }
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248 @Override
1249 public DaliConfiguration getConfiguration() {
1250 return (DaliConfiguration) super.getConfiguration();
1251 }
1252
1253
1254
1255
1256
1257
1258 public Integer getSelectedSurveyId() {
1259 return selectedSurveyId;
1260 }
1261
1262
1263
1264
1265
1266
1267 public void setSelectedSurveyId(Integer selectedSurveyId) {
1268 this.selectedSurveyId = selectedSurveyId;
1269 firePropertyChange(PROPERTY_SELECTED_SURVEY_ID, null, selectedSurveyId);
1270 }
1271
1272
1273
1274
1275
1276
1277 public Integer getSelectedSamplingOperationId() {
1278 return selectedSamplingOperationId;
1279 }
1280
1281
1282
1283
1284
1285
1286 public void setSelectedSamplingOperationId(Integer selectedSamplingOperationId) {
1287 this.selectedSamplingOperationId = selectedSamplingOperationId;
1288 }
1289
1290
1291
1292
1293
1294
1295 public SurveyFilterDTO getSurveyFilter() {
1296 return surveyFilter;
1297 }
1298
1299
1300
1301
1302
1303
1304 public void setSurveyFilter(SurveyFilterDTO surveyFilter) {
1305 this.surveyFilter = surveyFilter;
1306 }
1307
1308
1309
1310
1311
1312
1313 public void clearObservationIds() {
1314 setSelectedSurveyId(null);
1315 setSelectedSamplingOperationId(null);
1316 setSurveyFilter(null);
1317 }
1318
1319
1320
1321
1322
1323
1324 public String getSelectProgramCode() {
1325 return selectProgramCode;
1326 }
1327
1328
1329
1330
1331
1332
1333 public void setSelectedProgramCode(String code) {
1334 this.selectProgramCode = code;
1335 }
1336
1337
1338
1339
1340
1341
1342 public Integer getSelectedLocationId() {
1343 return selectedLocationId;
1344 }
1345
1346
1347
1348
1349
1350
1351 public void setSelectedLocationId(Integer id) {
1352 this.selectedLocationId = id;
1353 }
1354
1355
1356
1357
1358 public void clearProgrammeStrategieIds() {
1359 setSelectedProgramCode(null);
1360 setSelectedLocationId(null);
1361 }
1362
1363
1364
1365
1366
1367
1368 public Integer getSelectedContextId() {
1369 return selectedContextId;
1370 }
1371
1372
1373
1374
1375
1376
1377 public ContextDTO getSelectedContext() {
1378 if (selectedContextId == null) {
1379
1380
1381 if (getConfiguration().getLastContextId() != null) {
1382 setSelectedContext(getContextService().getContext(getConfiguration().getLastContextId()));
1383 }
1384 }
1385 return dataContext.getContext();
1386 }
1387
1388
1389
1390
1391
1392
1393 public void setSelectedContext(ContextDTO selectedContext) {
1394 Integer contextId = selectedContext == null ? null : selectedContext.getId();
1395 this.selectedContextId = contextId;
1396
1397
1398 getConfiguration().setLastContextId(contextId);
1399
1400
1401 dataContext.setContext(selectedContext);
1402 firePropertyChange(PROPERTY_SELECTED_CONTEXT_ID, null, contextId);
1403
1404
1405 getMainUI().getHandler().changeTitle();
1406 }
1407
1408
1409
1410
1411 public void deleteAllSynchroContext() {
1412
1413 File synchroDir = getConfiguration().getSynchronizationDirectory();
1414 if (synchroDir != null && synchroDir.exists()) {
1415 FileUtils.deleteQuietly(synchroDir);
1416 }
1417 }
1418
1419 public void preventNextImportSynchroCheckAction() {
1420 this.preventNextImportSynchroCheckAction = true;
1421 }
1422
1423 public boolean isNextImportSynchroCheckActionPrevented() {
1424 try {
1425 return preventNextImportSynchroCheckAction;
1426 } finally {
1427 preventNextImportSynchroCheckAction = false;
1428 }
1429 }
1430
1431 }