Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / IntializeApplicationExtension.java @ 24759

History | View | Annotate | Download (6.51 KB)

1
package com.iver.cit.gvsig;
2

    
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.InputStreamReader;
8
import java.io.StringWriter;
9
import java.security.KeyException;
10
import java.util.Properties;
11

    
12
import org.apache.log4j.Logger;
13
import org.gvsig.fmap.dal.DALLocator;
14
import org.gvsig.fmap.dal.resource.ResourceManager;
15
import org.gvsig.fmap.mapcontext.layers.vectorial.FLayerFileVectorial;
16
import org.gvsig.tools.observer.Observer;
17

    
18
import com.iver.andami.Launcher;
19
import com.iver.andami.PluginServices;
20
import com.iver.andami.plugins.Extension;
21
import com.iver.cit.gvsig.vectorialdb.DBResourceManager;
22
import com.iver.utiles.extensionPoints.ExtensionPoint;
23
import com.iver.utiles.extensionPoints.ExtensionPoints;
24
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
25

    
26
public class IntializeApplicationExtension extends Extension {
27
        private ExtensionPoints extensionPoints =
28
                ExtensionPointsSingleton.getInstance();
29
        private static Logger logger = Logger.getLogger("gvSIG");
30
        private Observer dbPasswordResorceObserver;
31
        public void initialize() {
32

    
33
                addToLogInfo();
34
                //this.extensionPoints.add("Layers","FileVectorial", FLayerFileVectorial.class);
35
                this.extensionPoints.add("Layers",FLayerFileVectorial.class.getName(), FLayerFileVectorial.class);
36

    
37
                //this.extensionPoints.add("Layers","GenericVectorial", FLayerGenericVectorial.class);
38
//                this.extensionPoints.add("Layers",FLayerGenericVectorial.class.getName(), FLayerGenericVectorial.class);
39
                try {
40
                        ((ExtensionPoint)this.extensionPoints.get("Layers")).addAlias(FLayerFileVectorial.class.getName(), "FileVectorial");
41
//                        ((ExtensionPoint)this.extensionPoints.get("Layers")).addAlias(FLayerGenericVectorial.class.getName(), "GenericVectorial");
42
                } catch (KeyException e) {
43
                        // TODO Auto-generated catch block
44
                        e.printStackTrace();
45
                }
46
                registerIcons();
47

    
48
        }
49
        public void postInitialize(){
50
                registerObservers();
51
        }
52
        private void registerObservers() {
53
                ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
54
                dbPasswordResorceObserver = new DBResourceManager();
55
                resMan.addObserver(dbPasswordResorceObserver);
56
        }
57

    
58
        //Registro en esta extension los iconos que no se donde registrarlos.
59
        private void registerIcons(){
60

    
61
                PluginServices.getIconTheme().registerDefault(
62
                                "view-add-event-layer",
63
                                this.getClass().getClassLoader().getResource("images/addeventtheme.png")
64
                        );
65
                PluginServices.getIconTheme().registerDefault(
66
                                "gvsig-logo-icon",
67
                                this.getClass().getClassLoader().getResource("images/icon_gvsig.png")
68
                        );
69

    
70

    
71

    
72
                PluginServices.getIconTheme().registerDefault(
73
                                "mapa-icono",
74
                                this.getClass().getClassLoader().getResource("images/mapas.png")
75
                        );
76

    
77
                PluginServices.getIconTheme().registerDefault(
78
                                "layout-insert-view",
79
                                this.getClass().getClassLoader().getResource("images/MapaVista.png")
80
                        );
81

    
82
                PluginServices.getIconTheme().registerDefault(
83
                                "vista-icono",
84
                                this.getClass().getClassLoader().getResource("images/Vista.png")
85
                        );
86

    
87
                PluginServices.getIconTheme().registerDefault(
88
                                "hand-icono",
89
                                this.getClass().getClassLoader().getResource("images/Hand.png")
90
                        );
91

    
92
                PluginServices.getIconTheme().registerDefault(
93
                                "add-layer-icono",
94
                                this.getClass().getClassLoader().getResource("images/add-layer.png")
95
                        );
96

    
97
                PluginServices.getIconTheme().registerDefault(
98
                                "delete-icono",
99
                                this.getClass().getClassLoader().getResource("images/delete.png")
100
                        );
101

    
102
                PluginServices.getIconTheme().registerDefault(
103
                                "arrow-up-icono",
104
                                this.getClass().getClassLoader().getResource("images/up-arrow.png")
105
                        );
106

    
107
                PluginServices.getIconTheme().registerDefault(
108
                                "arrow-down-icono",
109
                                this.getClass().getClassLoader().getResource("images/down-arrow.png")
110
                        );
111
//                PluginServices.getIconTheme().register(
112
//                                "arrow-down-icono",
113
//                                PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
114
//                        );
115
        }
116

    
117
        public void execute(String actionCommand) {
118

    
119
        }
120

    
121
        public boolean isEnabled() {
122
                return false;
123
        }
124

    
125
        public boolean isVisible() {
126
                return false;
127
        }
128

    
129
        private void addToLogInfo() {
130
                String info[] = this.getStringInfo().split("\n");
131
                for (int i=0;i< info.length;i++) {
132
                        logger.info(info[i]);
133
                }
134
        }
135

    
136
        public String getStringInfo() {
137
                StringWriter writer = new StringWriter();
138
                String andamiPath;
139
                String extensionsPath;
140
                String jaiVersion;
141

    
142
                Properties props = System.getProperties();
143

    
144
                try {
145
                        try {
146
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath();
147
                        } catch (IOException e) {
148
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath();
149
                        }
150
                } catch (Exception e1) {
151
                        andamiPath = (String)props.get("user.dir");
152
                }
153
                try {
154
                        try {
155
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath();
156
                        } catch (IOException e) {
157
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath();
158
                        }
159
                } catch (Exception e1) {
160
                        extensionsPath = "???";
161
                }
162

    
163

    
164

    
165
                writer.write("gvSIG version: " + Version.longFormat() + "\n");
166
                writer.write("    gvSIG app exec path: " + andamiPath + "\n");
167
                writer.write("    gvSIG user app home: " + Launcher.getAppHomeDir() + "\n");
168
                writer.write("    gvSIG extension path: " + extensionsPath + "\n");
169
                writer.write("    gvSIG locale language: " + Launcher.getAndamiConfig().getLocaleLanguage() + "\n");
170
                String osName = props.getProperty("os.name");
171
                writer.write("OS name: " + osName + "\n");
172
                writer.write("    arch:" + props.get("os.arch") + "\n");
173
                writer.write("    version:"+ props.get("os.version") + "\n");
174
                if (osName.startsWith("Linux")) {
175
                        try {
176
                                String[] command = {"lsb_release", "-a"};
177
                                Process p = Runtime.getRuntime().exec(command);
178
                                InputStream is = p.getInputStream();
179
                                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
180
                                String line;
181
                                while ( (line = reader.readLine()) != null) {
182
                                        writer.write("    "+line+"\n");
183
                                }
184
                        }
185
                        catch (Exception ex) {
186

    
187
                        }
188
                }
189

    
190
                writer.write("JAVA vendor: " + props.get("java.vendor") + "\n");
191
                writer.write("    version:" +props.get("java.version")+ "\n");
192
                writer.write("    home: " + props.get("java.home") + "\n");
193
                return writer.toString();
194
        }
195

    
196
        public void terminate() {
197

    
198
                super.terminate();
199
//                try {
200
//                        LayerFactory.getDataSourceFactory().finalizeThis();
201
//                } catch (Exception e) {
202
//                        //e.printStackTrace();
203
//                }
204

    
205
        }
206
}