svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / ApplicationLibrary.java @ 44006
History | View | Annotate | Download (5.53 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 40558 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app; |
||
25 | |||
26 | import java.io.File; |
||
27 | import java.io.IOException; |
||
28 | |||
29 | import javax.swing.JOptionPane; |
||
30 | |||
31 | import org.apache.commons.io.FileUtils; |
||
32 | import org.gvsig.andami.PluginServices; |
||
33 | import org.gvsig.andami.PluginsLocator; |
||
34 | import org.gvsig.app.extension.InitializeApplicationExtension; |
||
35 | 41347 | jjdelcerro | import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
36 | 40435 | jjdelcerro | import org.gvsig.app.project.DefaultProject; |
37 | 43987 | jjdelcerro | import org.gvsig.app.project.ProjectSymbolTable; |
38 | 44006 | jjdelcerro | import org.gvsig.app.project.documents.view.expressionevaluator.ViewElementFactory; |
39 | 43987 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
40 | 41347 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextLibrary; |
41 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextLocator; |
42 | 41347 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextManager; |
43 | import org.gvsig.fmap.mapcontrol.MapControlLibrary; |
||
44 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
45 | import org.gvsig.installer.lib.api.InstallerLibrary; |
||
46 | import org.gvsig.tools.library.AbstractLibrary; |
||
47 | import org.gvsig.tools.library.LibraryException; |
||
48 | import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
||
49 | 41347 | jjdelcerro | import org.slf4j.Logger; |
50 | import org.slf4j.LoggerFactory; |
||
51 | 40435 | jjdelcerro | |
52 | /**
|
||
53 | * @author 2008-2009 jmvivo
|
||
54 | * @author 2009- jjdelcerro
|
||
55 | *
|
||
56 | */
|
||
57 | public class ApplicationLibrary extends AbstractLibrary { |
||
58 | |||
59 | private static final Logger logger = |
||
60 | LoggerFactory.getLogger(ApplicationLibrary.class); |
||
61 | |||
62 | @Override
|
||
63 | public void doRegistration() { |
||
64 | registerAsAPI(ApplicationLibrary.class); |
||
65 | 41347 | jjdelcerro | require(MapContextLibrary.class); |
66 | require(MapControlLibrary.class); |
||
67 | 40435 | jjdelcerro | require(InstallerLibrary.class); |
68 | 43987 | jjdelcerro | require(ExpressionEvaluatorLibrary.class); |
69 | 40435 | jjdelcerro | } |
70 | |||
71 | @Override
|
||
72 | protected void doInitialize() throws LibraryException { |
||
73 | // Do nothing
|
||
74 | } |
||
75 | |||
76 | @Override
|
||
77 | protected void doPostInitialize() throws LibraryException { |
||
78 | ApplicationManager manager = ApplicationLocator.getManager(); |
||
79 | if (manager == null) { |
||
80 | throw new ReferenceNotRegisteredException( |
||
81 | ApplicationLocator.APPGVSIG_MANAGER_NAME, ApplicationLocator |
||
82 | .getInstance()); |
||
83 | } |
||
84 | DefaultProject.registerPersistent(); |
||
85 | 41347 | jjdelcerro | |
86 | MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
||
87 | |||
88 | PluginServices plugin = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
||
89 | mapContextManager.setColorTableLibraryFolder(new File(plugin.getPluginHomeFolder(),"colortable")); |
||
90 | |||
91 | MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
||
92 | 40435 | jjdelcerro | |
93 | 41347 | jjdelcerro | installBaseSymbols(); |
94 | 43987 | jjdelcerro | ProjectSymbolTable.selfRegister(); |
95 | 44006 | jjdelcerro | ViewElementFactory.selfRegister(); |
96 | 43987 | jjdelcerro | } |
97 | 41347 | jjdelcerro | |
98 | /**
|
||
99 | * Copy symbol folders from this plugin's 'Symbols' folder
|
||
100 | * to user's 'Symbols' folder unless a folder with same name
|
||
101 | * exists.
|
||
102 | */
|
||
103 | private void installBaseSymbols() { |
||
104 | PluginServices ps = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
||
105 | File from_folder = new File( ps.getPluginDirectory(), "Symbols"); |
||
106 | 40435 | jjdelcerro | String to_folder = MapContextLocator.getSymbolManager().
|
107 | 41347 | jjdelcerro | getSymbolPreferences().getSymbolLibraryPath(); |
108 | 40435 | jjdelcerro | try {
|
109 | 41347 | jjdelcerro | copyMissingFolders(from_folder, new File(to_folder)); |
110 | 40435 | jjdelcerro | } catch (IOException ioe) { |
111 | ApplicationLocator.getManager().message( |
||
112 | Messages.getText("_Unable_to_copy_symbols_from_main_plugin"),
|
||
113 | JOptionPane.ERROR_MESSAGE);
|
||
114 | } |
||
115 | 41347 | jjdelcerro | |
116 | 40435 | jjdelcerro | } |
117 | 41347 | jjdelcerro | |
118 | 40435 | jjdelcerro | private void copyMissingFolders(File fromf, File tof) |
119 | throws IOException { |
||
120 | |||
121 | if (fromf == null || tof == null) { |
||
122 | return;
|
||
123 | } |
||
124 | |||
125 | if (!fromf.exists() || !fromf.isDirectory() ||
|
||
126 | (tof.exists() && tof.isFile())) { |
||
127 | return;
|
||
128 | } |
||
129 | |||
130 | if (!tof.exists()) {
|
||
131 | tof.mkdirs(); |
||
132 | } |
||
133 | |||
134 | File[] from_subs = fromf.listFiles(); |
||
135 | for (int i=0; i<from_subs.length; i++) { |
||
136 | if (!folderIsOneIn(from_subs[i], tof)) {
|
||
137 | logger.info("Copying symbols subfolder: " + from_subs[i].getName());
|
||
138 | FileUtils.copyDirectoryToDirectory(from_subs[i], tof); |
||
139 | } else {
|
||
140 | logger.info("Symbols subfolder already exists: " + from_subs[i].getName());
|
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | |||
146 | /**
|
||
147 | * Tells whether <folder> is a folder and <tofolder>
|
||
148 | * has a file or subfolder with the same short name as
|
||
149 | * <folder>
|
||
150 | *
|
||
151 | */
|
||
152 | private boolean folderIsOneIn(File folder, File tofolder) { |
||
153 | |||
154 | if (!folder.isDirectory()) {
|
||
155 | return false; |
||
156 | } |
||
157 | |||
158 | String name = folder.getName();
|
||
159 | String tname = tofolder.getAbsolutePath() + File.separator + name; |
||
160 | File tfile = new File(tname); |
||
161 | return tfile.exists();
|
||
162 | } |
||
163 | |||
164 | |||
165 | } |