implemented user management, fixes #803. Minor refactorings.
[taxeditor.git] / taxeditor-application / src / main / java / eu / etaxonomy / taxeditor / ApplicationWorkbenchWindowAdvisor.java
1 package eu.etaxonomy.taxeditor;
2
3 import org.apache.log4j.Logger;
4 import org.eclipse.jface.dialogs.Dialog;
5 import org.eclipse.jface.dialogs.MessageDialog;
6 import org.eclipse.swt.graphics.Point;
7 import org.eclipse.swt.widgets.Shell;
8 import org.eclipse.ui.application.ActionBarAdvisor;
9 import org.eclipse.ui.application.IActionBarConfigurer;
10 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
11 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
12 import org.springframework.security.BadCredentialsException;
13 import org.springframework.security.userdetails.UsernameNotFoundException;
14
15 import eu.etaxonomy.taxeditor.dialogs.LoginDialog;
16 import eu.etaxonomy.taxeditor.preference.InitNomenclaturalCodePrefDialog;
17 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18
19 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
20 private static final Logger logger = Logger.getLogger(ApplicationWorkbenchWindowAdvisor.class);
21
22 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
23 super(configurer);
24 }
25
26 public ActionBarAdvisor createActionBarAdvisor(
27 IActionBarConfigurer configurer) {
28 return new ApplicationActionBarAdvisor(configurer);
29 }
30
31 public void preWindowOpen() {
32 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
33 configurer.setInitialSize(new Point(963, 637));
34 configurer.setShowCoolBar(true);
35 configurer.setShowStatusLine(true);
36 configurer.setShowPerspectiveBar(true);
37 configurer.setTitle("EDIT Taxonomic Editor");
38
39 }
40
41 public void postWindowOpen() {
42 try{
43 authenticate();
44 }catch(BadCredentialsException e){
45 logger.error("Bad credentials", e);
46 }
47
48 checkNomenclaturalCode();
49 }
50
51 private void checkNomenclaturalCode() {
52
53 // First time Editor is opened, no nomenclatural code has been set
54 if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
55
56 logger.debug("No nomencatural code set.");
57
58 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
59 .getActiveWorkbenchWindow().getShell();
60
61 // Query user re: preferred nom. code
62 Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
63 dialog.open();
64
65 // Short message confirming user's choice
66 String code = PreferencesUtil.getPreferredNomenclaturalCodeAsString();
67 MessageDialog.openInformation(shell, "Nomenclatural code set",
68 "The following has been set as your preferred nomenclatural code:\n\n\t" +
69 code + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
70 }
71 }
72
73 private int authenticate(){
74 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
75 .getActiveWorkbenchWindow().getShell();
76
77 LoginDialog loginDialog = new LoginDialog(shell);
78 return loginDialog.open();
79 }
80 }
81