81b5e8cae90e70824881655f3083d9df014c67a3
[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
14 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
15 import eu.etaxonomy.taxeditor.dialogs.LoginDialog;
16 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
17 import eu.etaxonomy.taxeditor.preference.InitNomenclaturalCodePrefDialog;
18 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
19
20 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
21 private static final Logger logger = Logger.getLogger(ApplicationWorkbenchWindowAdvisor.class);
22
23 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
24 super(configurer);
25 }
26
27 public ActionBarAdvisor createActionBarAdvisor(
28 IActionBarConfigurer configurer) {
29 return new ApplicationActionBarAdvisor(configurer);
30 }
31
32 public void preWindowOpen() {
33 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
34 configurer.setInitialSize(new Point(963, 637));
35 configurer.setShowCoolBar(true);
36 configurer.setShowStatusLine(true);
37 configurer.setShowPerspectiveBar(true);
38 configurer.setTitle("EDIT Taxonomic Editor");
39 configurer.setShowProgressIndicator(true);
40 }
41
42 public void postWindowOpen() {
43 try{
44 authenticate();
45 }catch(BadCredentialsException e){
46 logger.error("Bad credentials", e);
47 }
48
49 checkNomenclaturalCode();
50 }
51
52 private void checkNomenclaturalCode() {
53
54 // First time Editor is opened, no nomenclatural code has been set
55 if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
56
57 logger.info("No nomencatural code set.");
58
59 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
60 .getActiveWorkbenchWindow().getShell();
61
62 // Query user re: preferred nom. code
63 Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
64 dialog.open();
65
66 // Short message confirming user's choice
67 NomenclaturalCode code = PreferencesUtil.getPreferredNomenclaturalCode();
68 MessageDialog.openInformation(shell, "Nomenclatural code set",
69 "The following has been set as your preferred nomenclatural code:\n\n\t" +
70 NomenclaturalCodeHelper.getDescription(code) + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
71 }
72 }
73
74 private int authenticate(){
75 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
76 .getActiveWorkbenchWindow().getShell();
77
78 LoginDialog loginDialog = new LoginDialog(shell);
79 return loginDialog.open();
80 }
81 }
82