root / org.gvsig.educa.thematicmap.app / trunk / org.gvsig.educa.thematicmap.app / org.gvsig.educa.thematicmap.app.editor / src / main / java / org / gvsig / educa / thematicmap / app / editor / RegenerateThematicMapExtension.java @ 177
History | View | Annotate | Download (3.86 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.educa.thematicmap.app.editor; |
23 |
|
24 |
import javax.swing.SwingUtilities; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.messages.NotificationManager; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
30 |
import org.gvsig.app.project.documents.view.gui.IView; |
31 |
import org.gvsig.educa.thematicmap.app.viewer.ThematicMapDocument; |
32 |
import org.gvsig.educa.thematicmap.app.viewer.ui.ThematicMapDocumentViewer; |
33 |
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator; |
34 |
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingManager; |
35 |
|
36 |
/**
|
37 |
* Andami extension to update a Thematic Map from its source View.
|
38 |
*
|
39 |
* @author gvSIG Team
|
40 |
* @version $Id$
|
41 |
*/
|
42 |
public class RegenerateThematicMapExtension extends Extension { |
43 |
|
44 |
private ThematicMapEditorManager editorManager;
|
45 |
private ThematicMapSwingManager swingManager;
|
46 |
|
47 |
public void initialize() { |
48 |
// Do nothing
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public void postInitialize() { |
53 |
editorManager = ThematicMapEditorLocator.getManager(); |
54 |
swingManager = ThematicMapSwingLocator.getSwingManager(); |
55 |
} |
56 |
|
57 |
public void execute(String actionCommand) { |
58 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
59 |
final ThematicMapDocument tmDocument = getRelatedThematicMap(window);
|
60 |
|
61 |
SwingUtilities.invokeLater(new Runnable() { |
62 |
|
63 |
public void run() { |
64 |
try {
|
65 |
editorManager.regenerateThematicMap(tmDocument, null, true); |
66 |
} catch (Exception ex) { |
67 |
NotificationManager.addError(swingManager |
68 |
.getTranslation("problems_regeneration_thematic_map"),
|
69 |
ex); |
70 |
} |
71 |
|
72 |
} |
73 |
}); |
74 |
} |
75 |
|
76 |
/** {@inheridDoc} */
|
77 |
public boolean isEnabled() { |
78 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
79 |
ThematicMapDocument thMap = getRelatedThematicMap(window); |
80 |
return thMap != null && thMap.getSourceView() != null; |
81 |
} |
82 |
|
83 |
/** {@inheridDoc} */
|
84 |
public boolean isVisible() { |
85 |
// it's a Thematic Map view
|
86 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
87 |
return window instanceof ThematicMapDocumentViewer |
88 |
|| window instanceof IView;
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* <p>
|
93 |
* Returns related thematic map of a window
|
94 |
* </p>
|
95 |
*
|
96 |
* @param window
|
97 |
* @return
|
98 |
*/
|
99 |
private ThematicMapDocument getRelatedThematicMap(IWindow window) {
|
100 |
if (editorManager == null) { |
101 |
// initialization process not finished yet
|
102 |
return null; |
103 |
} |
104 |
if (window instanceof IView) { |
105 |
return editorManager.getThematicMapDocumentByView(((IView) window)
|
106 |
.getViewDocument()); |
107 |
} else
|
108 |
if (window instanceof ThematicMapDocumentViewer) { |
109 |
return ((ThematicMapDocumentViewer) window)
|
110 |
.getThematicMapDocument(); |
111 |
|
112 |
} |
113 |
return null; |
114 |
|
115 |
} |
116 |
} |