svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.exportto.app / org.gvsig.exportto.app.mainplugin / src / main / java / org / gvsig / export / app / extension / ExportHistoryBookmarksExtension.java @ 44801
History | View | Annotate | Download (4.2 KB)
1 |
package org.gvsig.export.app.extension; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.HashMap; |
5 |
import java.util.List; |
6 |
import java.util.Map; |
7 |
import org.gvsig.andami.PluginServices; |
8 |
import org.gvsig.andami.PluginsLocator; |
9 |
import org.gvsig.andami.PluginsManager; |
10 |
import org.gvsig.andami.plugins.Extension; |
11 |
import org.gvsig.export.ExportLocator; |
12 |
import org.gvsig.export.ExportManager; |
13 |
import org.gvsig.export.ExportParameters; |
14 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
15 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
16 |
import org.gvsig.tools.bookmarksandhistory.History; |
17 |
import org.gvsig.tools.dynobject.DynObject; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author osc
|
22 |
*/
|
23 |
public class ExportHistoryBookmarksExtension extends Extension { |
24 |
|
25 |
@Override
|
26 |
public void initialize() { |
27 |
loadExportHistoryParameters(); |
28 |
loadExportBookmarksParameters(); |
29 |
} |
30 |
|
31 |
@Override
|
32 |
public void execute(String actionCommand) { |
33 |
|
34 |
} |
35 |
|
36 |
@Override
|
37 |
public boolean isEnabled() { |
38 |
return true; |
39 |
} |
40 |
|
41 |
@Override
|
42 |
public boolean isVisible() { |
43 |
return true; |
44 |
} |
45 |
|
46 |
private void loadExportHistoryParameters() { |
47 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
48 |
final PluginServices plugin = pluginManager.getPlugin(this); |
49 |
final ExportManager exportManager = ExportLocator.getManager();
|
50 |
History<ExportParameters> history = exportManager.getHistory(); |
51 |
pluginManager.addShutdownTask("saveExportHistory", new Runnable() { |
52 |
@Override
|
53 |
public void run() { |
54 |
DynObject properties = plugin.getPluginProperties(); |
55 |
ArrayList<ExportParameters> var = new ArrayList<>(); |
56 |
if (history == null) { |
57 |
return;
|
58 |
} |
59 |
for (ExportParameters historyBookmark : history) {
|
60 |
if (historyBookmark != null) { |
61 |
var.add(historyBookmark); |
62 |
} else {
|
63 |
logger.warn("Trying to save history but value is null");
|
64 |
} |
65 |
} |
66 |
properties.setDynValue("exportHistory", var);
|
67 |
} |
68 |
}, false, 100); |
69 |
DynObject pluginProperties = plugin.getPluginProperties(); |
70 |
List<ExportParameters> dynBookmarks = (List<ExportParameters>) pluginProperties.getDynValue("exportHistory"); |
71 |
if (dynBookmarks == null) { |
72 |
return;
|
73 |
} |
74 |
for (ExportParameters exportParameters : dynBookmarks) {
|
75 |
history.add(exportParameters); |
76 |
} |
77 |
|
78 |
} |
79 |
|
80 |
private void loadExportBookmarksParameters() { |
81 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
82 |
final PluginServices plugin = pluginManager.getPlugin(this); |
83 |
DynObject pluginProperties = plugin.getPluginProperties(); |
84 |
final ExportManager exportManager = ExportLocator.getManager();
|
85 |
Bookmarks<ExportParameters> bookmarks = exportManager.getBookmarks(); |
86 |
pluginManager.addShutdownTask("saveExportBookmarks", new Runnable() { |
87 |
@Override
|
88 |
public void run() { |
89 |
DynObject properties = plugin.getPluginProperties(); |
90 |
Map<String, ExportParameters> var = new HashMap<>(); |
91 |
for (Bookmark<ExportParameters> exportBookmark : bookmarks) {
|
92 |
ExportParameters value = exportBookmark.getValue(); |
93 |
if (value != null) { |
94 |
var.put(exportBookmark.getName(), value); |
95 |
} else {
|
96 |
logger.warn("Trying to save bookmark but value is null");
|
97 |
} |
98 |
} |
99 |
properties.setDynValue("exportBookmarks", var);
|
100 |
} |
101 |
}, false, 100); |
102 |
Map<String, ExportParameters> dynBookmarks = (Map<String, ExportParameters>) pluginProperties.getDynValue("exportBookmarks"); |
103 |
if (dynBookmarks == null) { |
104 |
return;
|
105 |
} |
106 |
for (String key : dynBookmarks.keySet()) { |
107 |
ExportParameters bookmarkParameters = dynBookmarks.get(key); |
108 |
if (bookmarkParameters != null) { |
109 |
bookmarks.add(key, bookmarkParameters); |
110 |
} else {
|
111 |
logger.warn("Trying to add bookmark but value is null");
|
112 |
} |
113 |
; |
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
} |