Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TOCImplementationExtension.java @ 37338

History | View | Annotate | Download (2.95 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.apache.log4j.Logger;
4
import org.gvsig.fmap.swing.impl.toc.DefaultTOCFactory;
5
import org.gvsig.fmap.swing.impl.toc.TOCDefaultImplLibrary;
6
import org.gvsig.fmap.swing.toc.TOCFactory;
7
import org.gvsig.fmap.swing.toc.TOCLibrary;
8
import org.gvsig.fmap.swing.toc.TOCLocator;
9
import org.gvsig.fmap.swing.toc.TOCManager;
10
import org.gvsig.tools.ToolsLibrary;
11
import org.gvsig.tools.ToolsLocator;
12
import org.gvsig.tools.dynobject.DynObjectManager;
13
import org.gvsig.tools.dynobject.impl.DefaultDynObjectManager;
14
import org.gvsig.tools.library.Library;
15
import org.gvsig.tools.service.ServiceException;
16

    
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.messages.NotificationManager;
19
import com.iver.andami.plugins.Extension;
20
import com.iver.andami.preferences.IPreference;
21
import com.iver.andami.preferences.IPreferenceExtension;
22
import com.iver.cit.gvsig.gui.preferencespage.TOCImplementationPage;
23
import com.iver.cit.gvsig.project.documents.view.toc.impl.DefaultToc;
24
import com.iver.utiles.XMLEntity;
25

    
26
public class TOCImplementationExtension extends Extension 
27
implements IPreferenceExtension {
28
        
29
        private static Logger logger = Logger.getLogger(TOCImplementationExtension.class.getName());
30
        private TOCImplementationPage page = null;
31
        
32
        private static boolean initDone = false;
33

    
34
        public IPreference getPreferencesPage() {
35
                if (page==null) {
36
                        page = new TOCImplementationPage();
37
                }
38
                return page;
39
        }
40
        
41

    
42

    
43

    
44
        public void initialize() {
45
                init();
46
        }
47
        
48
        public void postInitialize() {
49
                tryToSetTOCFromPersistence();
50
        }
51

    
52
        private void tryToSetTOCFromPersistence() {
53

    
54
                PluginServices ps = PluginServices.getPluginServices(this);
55
                XMLEntity xml = ps.getPersistentXML();
56
                if (xml!=null && xml.contains(DefaultToc.TOC_CURRENT_TOC_KEY)) {
57
                        
58
                        String pref_toc = xml.getStringProperty(DefaultToc.TOC_CURRENT_TOC_KEY);
59
                        try {
60
                                TOCLocator.getInstance().getTOCManager().setDefaultTOCFactory(pref_toc);
61
                        } catch (Exception ex) {
62
                                NotificationManager.addError("While getting TOC from persistence. ", ex);
63
                        }
64
                }                
65
        }
66

    
67

    
68

    
69

    
70
        private void init() {
71
                
72
                if (initDone) {
73
                        return;
74
                }
75
                
76
                Library lib = new ToolsLibrary();
77
                lib.initialize();
78
                lib.postInitialize();
79
                
80
                lib = new TOCLibrary();
81
                lib.initialize();
82
                lib.postInitialize();
83
                
84
                // =========================
85
                
86
                lib = new TOCDefaultImplLibrary();
87
                lib.initialize();
88
                lib.postInitialize();
89
                
90
                
91
                initDone = true;
92
        }
93

    
94
        
95
        public void setPreferredTOCImplementation(TOCFactory tf) {
96
                if (tf==null) {
97
                        return;
98
                }
99

    
100
                PluginServices ps = PluginServices.getPluginServices(this);
101
                XMLEntity xml = ps.getPersistentXML();
102
                xml.putProperty(
103
                                DefaultToc.TOC_CURRENT_TOC_KEY,
104
                                tf.getName());
105
        }
106

    
107

    
108

    
109

    
110
        public boolean isEnabled() {
111
                return false;
112
        }
113

    
114
        public boolean isVisible() {
115
                return false;
116
        }
117
        
118

    
119
        public IPreference[] getPreferencesPages() {
120
                IPreference[] preferences=new IPreference[1];
121
                preferences[0]=getPreferencesPage();
122
                return preferences;
123
        }
124
        
125
        public void execute(String actionCommand) { }
126

    
127

    
128
}