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