performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / NavigatorStateManager.java
1
2 package eu.etaxonomy.taxeditor.navigation;
3
4 import org.eclipse.core.runtime.IProgressMonitor;
5 import org.eclipse.ui.IMemento;
6
7 import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
8 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
9
10 /**
11 * <p>NavigatorStateManager class.</p>
12 *
13 * @author n.hoffmann
14 * @created Apr 1, 2010
15 * @version 1.0
16 */
17 public class NavigatorStateManager extends ContextListenerAdapter {
18
19 /**
20 * {@inheritDoc}
21 *
22 * Tries to restore the state of the taxon editor and the navigator when a context starts.
23 */
24 @Override
25 public void contextStart(IMemento memento, IProgressMonitor monitor) {
26 TaxonNavigator navigator = NavigationUtil.getNavigator(true);
27 if(navigator != null){
28 navigator.init();
29 navigator.restore(memento, monitor);
30 }
31 }
32
33 /**
34 * {@inheritDoc}
35 *
36 * If the context
37 */
38 @Override
39 public void contextStop(IMemento memento, IProgressMonitor monitor) {
40 saveNavigatorState(memento, monitor);
41 clearNavigator();
42 }
43
44 /* (non-Javadoc)
45 * @see eu.etaxonomy.taxeditor.model.ContextListenerAdapter#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
46 */
47 /** {@inheritDoc} */
48 @Override
49 public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
50 saveNavigatorState(memento, monitor);
51 }
52
53 /**
54 * @param memento
55 */
56 private void saveNavigatorState(IMemento memento, IProgressMonitor monitor) {
57 TaxonNavigator navigator = NavigationUtil.getNavigator(false);
58 if(navigator != null){
59 navigator.save(memento, monitor);
60 }
61 }
62
63 /**
64 * Removes all content form the TaxonNavigator
65 */
66 private void clearNavigator() {
67 TaxonNavigator navigator = NavigationUtil.getNavigator(false);
68 if(navigator != null){
69 navigator.clear();
70 }
71 }
72
73 }