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 @ 47784
History | View | Annotate | Download (4.79 KB)
1 | 42448 | dmartinezizquierdo | /**
|
---|---|---|---|
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 | 42502 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
31 | 42448 | dmartinezizquierdo | import org.gvsig.app.project.documents.view.ViewDocument; |
32 | 42502 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewManager; |
33 | 44195 | omartinez | import org.gvsig.fmap.dal.exception.ReadException; |
34 | 42448 | dmartinezizquierdo | import org.gvsig.fmap.mapcontext.MapContext; |
35 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
36 | 42502 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
37 | import org.gvsig.tools.i18n.I18nManager; |
||
38 | 42448 | dmartinezizquierdo | 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 | 42502 | jjdelcerro | |
47 | 42448 | dmartinezizquierdo | private static final Logger logger = LoggerFactory.getLogger(AddToLocatorExtension.class); |
48 | |||
49 | 42502 | jjdelcerro | @Override
|
50 | 42448 | dmartinezizquierdo | public boolean isVisible() { |
51 | ApplicationManager application = ApplicationLocator.getManager(); |
||
52 | 42502 | jjdelcerro | 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 | 42448 | dmartinezizquierdo | } |
57 | return false; |
||
58 | } |
||
59 | |||
60 | 42502 | jjdelcerro | @Override
|
61 | 42448 | dmartinezizquierdo | public void postInitialize() { |
62 | super.postInitialize();
|
||
63 | 42502 | jjdelcerro | ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
64 | ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
||
65 | viewManager.addTOCContextAction("layer-addtolocator");
|
||
66 | 42448 | dmartinezizquierdo | } |
67 | |||
68 | 42502 | jjdelcerro | @Override
|
69 | 42448 | dmartinezizquierdo | public void execute(String actionCommand) { |
70 | this.execute(actionCommand, null); |
||
71 | } |
||
72 | |||
73 | 42502 | jjdelcerro | @Override
|
74 | 42448 | dmartinezizquierdo | public void execute(String command, Object[] args) { |
75 | ApplicationManager application = ApplicationLocator.getManager(); |
||
76 | 42502 | jjdelcerro | 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 | 44195 | omartinez | |
84 | 42502 | jjdelcerro | FLayer[] layers = view.getMapContext().getLayers().getActives();
|
85 | 44195 | omartinez | |
86 | for (FLayer layer : layers) {
|
||
87 | 42502 | jjdelcerro | try {
|
88 | mapOverViewContext.getLayers().addLayer(layer.cloneLayer()); |
||
89 | 44195 | omartinez | // 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 | 42502 | jjdelcerro | 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 | 42448 | dmartinezizquierdo | } |
110 | } |
||
111 | } |
||
112 | |||
113 | 42502 | jjdelcerro | @Override
|
114 | 42448 | dmartinezizquierdo | public boolean isEnabled() { |
115 | return true; |
||
116 | } |
||
117 | |||
118 | 42502 | jjdelcerro | @Override
|
119 | 42448 | dmartinezizquierdo | public void initialize() { |
120 | 42502 | jjdelcerro | IconThemeHelper.registerIcon("action", "layer-addtolocator", this); |
121 | 42448 | dmartinezizquierdo | } |
122 | } |