5bcf6fc0f1dc7e66246bb6dfb36301feb2cf5223
[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.IPartListener;
9 import org.eclipse.ui.IPartListener2;
10 import org.eclipse.ui.IWorkbenchPartReference;
11 import org.eclipse.ui.application.ActionBarAdvisor;
12 import org.eclipse.ui.application.IActionBarConfigurer;
13 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
14 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
15
16 import eu.etaxonomy.taxeditor.editor.EditorUtil;
17 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
18 import eu.etaxonomy.taxeditor.store.preference.InitNomenclaturalCodePrefDialog;
19 import eu.etaxonomy.taxeditor.store.preference.PreferencesUtil;
20
21 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
22 private static final Logger logger = Logger.getLogger(ApplicationWorkbenchWindowAdvisor.class);
23
24 private IPartListener2 propertySheetListener;
25
26 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
27 super(configurer);
28 }
29
30 public ActionBarAdvisor createActionBarAdvisor(
31 IActionBarConfigurer configurer) {
32 return new ApplicationActionBarAdvisor(configurer);
33 }
34
35 public void preWindowOpen() {
36 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
37 configurer.setInitialSize(new Point(963, 637));
38 configurer.setShowCoolBar(true);
39 configurer.setShowStatusLine(true);
40 configurer.setShowPerspectiveBar(true);
41 configurer.setTitle("EDIT Taxonomic Editor");
42 }
43
44 public void postWindowOpen() {
45 checkNomenclaturalCode();
46
47 // setPropertySheetListener();
48 }
49
50 // /**
51 // *
52 // */
53 // private void setPropertySheetListener() {
54 // propertySheetListener = new IPartListener2() {
55 //
56 // public void partActivated(IWorkbenchPartReference partRef) {
57 // if (partRef.getId().equals(MultiPageTaxonEditor.ID)) {
58 // EditorUtil.showPropertySheet();
59 // }
60 // }
61 //
62 // public void partOpened(IWorkbenchPartReference partRef) {
63 //// if (partRef.getId().equals(MultiPageTaxonEditor.ID)) {
64 //// EditorUtil.showPropertySheet();
65 //// }
66 // }
67 //
68 // public void partClosed(IWorkbenchPartReference partRef) {
69 //// if (partRef.getId().equals(MultiPageTaxonEditor.ID)) {
70 //// EditorUtil.checkHidePropertySheet();
71 //// }
72 // }
73 //
74 // public void partBroughtToTop(IWorkbenchPartReference partRef) {}
75 //
76 // public void partDeactivated(IWorkbenchPartReference partRef) {
77 // EditorUtil.checkHidePropertySheet();
78 // }
79 //
80 // public void partHidden(IWorkbenchPartReference partRef) {}
81 //
82 // public void partInputChanged(IWorkbenchPartReference partRef) {}
83 //
84 // public void partVisible(IWorkbenchPartReference partRef) {}
85 //
86 // };
87 //// getWindowConfigurer().getWindow().getActivePage().addPartListener(propertySheetListener);
88 // }
89
90 private void checkNomenclaturalCode() {
91
92 // First time Editor is opened, no nomenclatural code has been set
93 if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
94
95 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
96 .getActiveWorkbenchWindow().getShell();
97
98 // Query user re: preferred nom. code
99 Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
100 int returnCode = dialog.open();
101
102 // Short message confirming user's choice
103 String code = PreferencesUtil.getPreferredNomenclaturalCodeAsString();
104 MessageDialog.openInformation(shell, "Nomenclatural code set",
105 "The following has been set as your preferred nomenclatural code:\n\n\t" +
106 code + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
107 }
108 }
109 }
110