root / org.gvsig.hyperlink.app / trunk / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / LinkConfigExtension.java @ 15
History | View | Annotate | Download (4.45 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 |
|
23 |
package org.gvsig.hyperlink.app.extension; |
24 |
|
25 |
import org.gvsig.andami.PluginServices; |
26 |
import org.gvsig.andami.plugins.Extension; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
28 |
import org.gvsig.app.project.documents.view.ViewDocument; |
29 |
import org.gvsig.app.project.documents.view.gui.IView; |
30 |
import org.gvsig.fmap.mapcontext.MapContext; |
31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
32 |
import org.gvsig.hyperlink.app.extension.config.gui.ConfigTab; |
33 |
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry; |
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
/**
|
38 |
* Extensi?n para gestionar los hiperlinks.
|
39 |
*
|
40 |
* @author Vicente Caballero Navarro
|
41 |
*/
|
42 |
public class LinkConfigExtension extends Extension { |
43 |
|
44 |
private static final Logger logger = |
45 |
LoggerFactory.getLogger(LinkConfigExtension.class); |
46 |
ManagerRegistry layerManager; |
47 |
|
48 |
/**
|
49 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
50 |
*/
|
51 |
public void execute(String s) { |
52 |
logger.debug("Command : " + s);
|
53 |
|
54 |
if (s.compareTo("LINK_SETTINGS") == 0) { |
55 |
IView view = |
56 |
(IView) PluginServices.getMDIManager().getActiveWindow(); |
57 |
HyperlinkExtension ext = |
58 |
(HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class); |
59 |
// init tool and load legacy config in case it has been not done
|
60 |
ext.initTool(view); |
61 |
FLayer[] activas =
|
62 |
view.getMapControl().getMapContext().getLayers().getActives(); |
63 |
for (int i = 0; i < activas.length; i++) { |
64 |
if (!activas[i].isAvailable()) {
|
65 |
return;
|
66 |
} |
67 |
|
68 |
if (layerManager.hasManager(activas[i])) {
|
69 |
ConfigTab configWindow = new ConfigTab();
|
70 |
configWindow.setModel(activas[i]); |
71 |
PluginServices.getMDIManager() |
72 |
.addCentredWindow(configWindow); |
73 |
} |
74 |
} |
75 |
|
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
81 |
*/
|
82 |
public boolean isVisible() { |
83 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
84 |
|
85 |
if (window == null) { |
86 |
return false; |
87 |
} |
88 |
|
89 |
if (window instanceof IView) { |
90 |
|
91 |
MapContext mapa = |
92 |
((IView) window).getViewDocument().getMapContext(); |
93 |
|
94 |
return mapa.getLayers().getLayersCount() > 0; |
95 |
} else {
|
96 |
return false; |
97 |
} |
98 |
} |
99 |
|
100 |
/**
|
101 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
102 |
*/
|
103 |
public boolean isEnabled() { |
104 |
// it will be enabled when there is only ONE active layer, and this
|
105 |
// layer
|
106 |
// is available and has a valid ILayerLinkManager
|
107 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
108 |
|
109 |
if (window == null) { |
110 |
return false; |
111 |
} |
112 |
|
113 |
if (window instanceof IView) { |
114 |
IView view = (IView) window; |
115 |
ViewDocument model = view.getViewDocument(); |
116 |
FLayer[] activas = model.getMapContext().getLayers().getActives();
|
117 |
if (activas.length == 1) { |
118 |
if (activas[0].isAvailable() |
119 |
&& layerManager.hasManager(activas[0])) {
|
120 |
return true; |
121 |
} |
122 |
} |
123 |
} |
124 |
return false; |
125 |
} |
126 |
|
127 |
public void postInitialize() { |
128 |
HyperlinkExtension ext = |
129 |
(HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class); |
130 |
layerManager = ext.getLayerManager(); |
131 |
} |
132 |
|
133 |
public void initialize() { |
134 |
//Do nothing
|
135 |
} |
136 |
|
137 |
} |