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 @ 44129
History | View | Annotate | Download (6.18 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 | 44035 | jjdelcerro | import org.gvsig.app.project.documents.view.expressionevaluator.SavedPointsElementFactory; |
38 | 44006 | jjdelcerro | import org.gvsig.app.project.documents.view.expressionevaluator.ViewElementFactory; |
39 | 44129 | jjdelcerro | import org.gvsig.app.project.symboltables.ProjectSymbolTableFactory; |
40 | import org.gvsig.app.project.symboltables.functionPanels.area.AreaAditionalPanelFactory; |
||
41 | import org.gvsig.app.project.symboltables.functionPanels.firstlayerfeature.FirstLayerFeatureAditionalPanelFactory; |
||
42 | import org.gvsig.app.project.symboltables.functionPanels.perimeter.PerimeterAditionalPanelFactory; |
||
43 | 43987 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
44 | 41347 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextLibrary; |
45 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextLocator; |
46 | 41347 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContextManager; |
47 | import org.gvsig.fmap.mapcontrol.MapControlLibrary; |
||
48 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
49 | import org.gvsig.installer.lib.api.InstallerLibrary; |
||
50 | import org.gvsig.tools.library.AbstractLibrary; |
||
51 | import org.gvsig.tools.library.LibraryException; |
||
52 | import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
||
53 | 41347 | jjdelcerro | import org.slf4j.Logger; |
54 | import org.slf4j.LoggerFactory; |
||
55 | 40435 | jjdelcerro | |
56 | /**
|
||
57 | * @author 2008-2009 jmvivo
|
||
58 | * @author 2009- jjdelcerro
|
||
59 | *
|
||
60 | */
|
||
61 | public class ApplicationLibrary extends AbstractLibrary { |
||
62 | |||
63 | private static final Logger logger = |
||
64 | LoggerFactory.getLogger(ApplicationLibrary.class); |
||
65 | |||
66 | @Override
|
||
67 | public void doRegistration() { |
||
68 | registerAsAPI(ApplicationLibrary.class); |
||
69 | 41347 | jjdelcerro | require(MapContextLibrary.class); |
70 | require(MapControlLibrary.class); |
||
71 | 40435 | jjdelcerro | require(InstallerLibrary.class); |
72 | 43987 | jjdelcerro | require(ExpressionEvaluatorLibrary.class); |
73 | 40435 | jjdelcerro | } |
74 | |||
75 | @Override
|
||
76 | protected void doInitialize() throws LibraryException { |
||
77 | // Do nothing
|
||
78 | } |
||
79 | |||
80 | @Override
|
||
81 | protected void doPostInitialize() throws LibraryException { |
||
82 | ApplicationManager manager = ApplicationLocator.getManager(); |
||
83 | if (manager == null) { |
||
84 | throw new ReferenceNotRegisteredException( |
||
85 | ApplicationLocator.APPGVSIG_MANAGER_NAME, ApplicationLocator |
||
86 | .getInstance()); |
||
87 | } |
||
88 | DefaultProject.registerPersistent(); |
||
89 | 41347 | jjdelcerro | |
90 | MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
||
91 | |||
92 | PluginServices plugin = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
||
93 | mapContextManager.setColorTableLibraryFolder(new File(plugin.getPluginHomeFolder(),"colortable")); |
||
94 | |||
95 | MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
||
96 | 40435 | jjdelcerro | |
97 | 41347 | jjdelcerro | installBaseSymbols(); |
98 | 44129 | jjdelcerro | |
99 | ProjectSymbolTableFactory.selfRegister(); |
||
100 | AreaAditionalPanelFactory.selfRegister(); |
||
101 | PerimeterAditionalPanelFactory.selfRegister(); |
||
102 | FirstLayerFeatureAditionalPanelFactory.selfRegister(); |
||
103 | 44006 | jjdelcerro | ViewElementFactory.selfRegister(); |
104 | 44035 | jjdelcerro | SavedPointsElementFactory.selfRegister(); |
105 | 43987 | jjdelcerro | } |
106 | 41347 | jjdelcerro | |
107 | /**
|
||
108 | * Copy symbol folders from this plugin's 'Symbols' folder
|
||
109 | * to user's 'Symbols' folder unless a folder with same name
|
||
110 | * exists.
|
||
111 | */
|
||
112 | private void installBaseSymbols() { |
||
113 | PluginServices ps = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
||
114 | File from_folder = new File( ps.getPluginDirectory(), "Symbols"); |
||
115 | 40435 | jjdelcerro | String to_folder = MapContextLocator.getSymbolManager().
|
116 | 41347 | jjdelcerro | getSymbolPreferences().getSymbolLibraryPath(); |
117 | 40435 | jjdelcerro | try {
|
118 | 41347 | jjdelcerro | copyMissingFolders(from_folder, new File(to_folder)); |
119 | 40435 | jjdelcerro | } catch (IOException ioe) { |
120 | ApplicationLocator.getManager().message( |
||
121 | Messages.getText("_Unable_to_copy_symbols_from_main_plugin"),
|
||
122 | JOptionPane.ERROR_MESSAGE);
|
||
123 | } |
||
124 | 41347 | jjdelcerro | |
125 | 40435 | jjdelcerro | } |
126 | 41347 | jjdelcerro | |
127 | 40435 | jjdelcerro | private void copyMissingFolders(File fromf, File tof) |
128 | throws IOException { |
||
129 | |||
130 | if (fromf == null || tof == null) { |
||
131 | return;
|
||
132 | } |
||
133 | |||
134 | if (!fromf.exists() || !fromf.isDirectory() ||
|
||
135 | (tof.exists() && tof.isFile())) { |
||
136 | return;
|
||
137 | } |
||
138 | |||
139 | if (!tof.exists()) {
|
||
140 | tof.mkdirs(); |
||
141 | } |
||
142 | |||
143 | File[] from_subs = fromf.listFiles(); |
||
144 | for (int i=0; i<from_subs.length; i++) { |
||
145 | if (!folderIsOneIn(from_subs[i], tof)) {
|
||
146 | logger.info("Copying symbols subfolder: " + from_subs[i].getName());
|
||
147 | FileUtils.copyDirectoryToDirectory(from_subs[i], tof); |
||
148 | } else {
|
||
149 | logger.info("Symbols subfolder already exists: " + from_subs[i].getName());
|
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | |||
154 | |||
155 | /**
|
||
156 | * Tells whether <folder> is a folder and <tofolder>
|
||
157 | * has a file or subfolder with the same short name as
|
||
158 | * <folder>
|
||
159 | *
|
||
160 | */
|
||
161 | private boolean folderIsOneIn(File folder, File tofolder) { |
||
162 | |||
163 | if (!folder.isDirectory()) {
|
||
164 | return false; |
||
165 | } |
||
166 | |||
167 | String name = folder.getName();
|
||
168 | String tname = tofolder.getAbsolutePath() + File.separator + name; |
||
169 | File tfile = new File(tname); |
||
170 | return tfile.exists();
|
||
171 | } |
||
172 | |||
173 | |||
174 | } |