30 |
30 |
*/
|
31 |
31 |
package org.gvsig.app;
|
32 |
32 |
|
|
33 |
import java.io.File;
|
|
34 |
import java.io.IOException;
|
|
35 |
|
|
36 |
import javax.swing.JOptionPane;
|
|
37 |
|
|
38 |
import org.apache.commons.io.FileUtils;
|
|
39 |
|
|
40 |
import org.gvsig.andami.PluginServices;
|
|
41 |
import org.gvsig.andami.PluginsLocator;
|
|
42 |
import org.gvsig.app.extension.InitializeApplicationExtension;
|
33 |
43 |
import org.gvsig.app.project.DefaultProject;
|
|
44 |
import org.gvsig.fmap.mapcontext.MapContextLocator;
|
34 |
45 |
import org.gvsig.fmap.mapcontrol.MapControl;
|
|
46 |
import org.gvsig.i18n.Messages;
|
35 |
47 |
import org.gvsig.installer.lib.api.InstallerLibrary;
|
|
48 |
import org.gvsig.symbology.SymbologyLocator;
|
|
49 |
import org.gvsig.tools.ToolsLocator;
|
36 |
50 |
import org.gvsig.tools.library.AbstractLibrary;
|
37 |
51 |
import org.gvsig.tools.library.LibraryException;
|
38 |
52 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
|
... | ... | |
66 |
80 |
}
|
67 |
81 |
DefaultProject.registerPersistent();
|
68 |
82 |
|
|
83 |
/*
|
|
84 |
* Copy symbol folders from this plugin's 'Symbols' folder
|
|
85 |
* to user's 'Symbols' folder unless a folder with same name
|
|
86 |
* exists.
|
|
87 |
*/
|
|
88 |
PluginServices ps = PluginsLocator.getManager().getPlugin(
|
|
89 |
InitializeApplicationExtension.class);
|
|
90 |
File folder = ps.getPluginDirectory();
|
|
91 |
String from_folder = folder.getAbsolutePath() + File.separator
|
|
92 |
+ "Symbols";
|
|
93 |
String to_folder = MapContextLocator.getSymbolManager().
|
|
94 |
getSymbolPreferences().getSymbolLibraryPath();
|
|
95 |
|
|
96 |
try {
|
|
97 |
copyMissingFolders(new File(from_folder), new File(to_folder));
|
|
98 |
} catch (IOException ioe) {
|
|
99 |
ApplicationLocator.getManager().message(
|
|
100 |
Messages.getText("_Unable_to_copy_symbols_from_main_plugin"),
|
|
101 |
JOptionPane.ERROR_MESSAGE);
|
|
102 |
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
|
69 |
107 |
}
|
|
108 |
|
|
109 |
private void copyMissingFolders(File fromf, File tof)
|
|
110 |
throws IOException {
|
|
111 |
|
|
112 |
if (fromf == null || tof == null) {
|
|
113 |
return;
|
|
114 |
}
|
|
115 |
|
|
116 |
if (!fromf.exists() || !fromf.isDirectory() ||
|
|
117 |
(tof.exists() && tof.isFile())) {
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
if (!tof.exists()) {
|
|
122 |
tof.mkdirs();
|
|
123 |
}
|
|
124 |
|
|
125 |
File[] from_subs = fromf.listFiles();
|
|
126 |
for (int i=0; i<from_subs.length; i++) {
|
|
127 |
if (!folderIsOneIn(from_subs[i], tof)) {
|
|
128 |
FileUtils.copyDirectoryToDirectory(from_subs[i], tof);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
/**
|
|
135 |
* Tells whether <folder> is a folder and <tofolder>
|
|
136 |
* has a file or subfolder with the same short name as
|
|
137 |
* <folder>
|
|
138 |
*
|
|
139 |
*/
|
|
140 |
private boolean folderIsOneIn(File folder, File tofolder) {
|
|
141 |
|
|
142 |
if (!folder.isDirectory()) {
|
|
143 |
return false;
|
|
144 |
}
|
|
145 |
|
|
146 |
String name = folder.getName();
|
|
147 |
String tname = tofolder.getAbsolutePath() + File.separator + name;
|
|
148 |
File tfile = new File(tname);
|
|
149 |
return tfile.exists();
|
|
150 |
}
|
|
151 |
|
|
152 |
|
70 |
153 |
}
|