svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / AddToLocatorExtension.java @ 44259
History | View | Annotate | Download (4.79 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import javax.swing.JOptionPane; |
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.plugins.Extension; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.project.ProjectManager; |
31 |
import org.gvsig.app.project.documents.view.ViewDocument; |
32 |
import org.gvsig.app.project.documents.view.ViewManager; |
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.i18n.I18nManager; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
/**
|
42 |
* Extensi?n que a?ade una capa al locator
|
43 |
*
|
44 |
*/
|
45 |
public class AddToLocatorExtension extends Extension { |
46 |
|
47 |
private static final Logger logger = LoggerFactory.getLogger(AddToLocatorExtension.class); |
48 |
|
49 |
@Override
|
50 |
public boolean isVisible() { |
51 |
ApplicationManager application = ApplicationLocator.getManager(); |
52 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
53 |
if (view != null) { |
54 |
FLayer[] layers = view.getMapContext().getLayers().getActives();
|
55 |
return layers != null && layers.length > 0; |
56 |
} |
57 |
return false; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void postInitialize() { |
62 |
super.postInitialize();
|
63 |
ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
64 |
ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
65 |
viewManager.addTOCContextAction("layer-addtolocator");
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
public void execute(String actionCommand) { |
70 |
this.execute(actionCommand, null); |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void execute(String command, Object[] args) { |
75 |
ApplicationManager application = ApplicationLocator.getManager(); |
76 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
77 |
if ("layer-addtolocator".equalsIgnoreCase(command)) { |
78 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
79 |
if (view == null) { |
80 |
return;
|
81 |
} |
82 |
MapContext mapOverViewContext = view.getMapOverViewContext(); |
83 |
|
84 |
FLayer[] layers = view.getMapContext().getLayers().getActives();
|
85 |
|
86 |
for (FLayer layer : layers) {
|
87 |
try {
|
88 |
mapOverViewContext.getLayers().addLayer(layer.cloneLayer()); |
89 |
// initialize mapOverviewContext envelope
|
90 |
try {
|
91 |
if (mapOverViewContext.getViewPort().getEnvelope() == null && layer.getFullEnvelope() != null) { |
92 |
mapOverViewContext.getViewPort().setEnvelope(layer.getFullEnvelope()); |
93 |
} |
94 |
} catch (ReadException ex) {
|
95 |
logger.warn("Not able to set Envelope for the overview.", ex);
|
96 |
} |
97 |
mapOverViewContext.invalidate(); |
98 |
view.setModified(true);
|
99 |
} catch (Exception ex) { |
100 |
logger.warn("Can't add layer '" + layer.getName() + "' to the overview.", ex); |
101 |
application.messageDialog( |
102 |
i18nManager.getTranslation("_Add_to_locator"),
|
103 |
i18nManager.getTranslation("_Cant_add_layer_{0}_to_locator", new String[] {layer.getName()}) |
104 |
+ "\n\n"
|
105 |
+ i18nManager.getTranslation("_See_the_error_log_for_more_information"),
|
106 |
JOptionPane.WARNING_MESSAGE
|
107 |
); |
108 |
} |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public boolean isEnabled() { |
115 |
return true; |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void initialize() { |
120 |
IconThemeHelper.registerIcon("action", "layer-addtolocator", this); |
121 |
} |
122 |
} |