gvsig-attributeeditor / org.gvsig.attributeeditor / trunk / org.gvsig.attributeeditor / org.gvsig.attributeeditor.app / org.gvsig.attributeeditor.app.mainplugin / src / main / java / org / gvsig / app / mainplugin / extension / AttributeEditorExtension.java @ 8
History | View | Annotate | Download (4.78 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2014 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.mainplugin.extension; |
24 |
|
25 |
import org.slf4j.Logger; |
26 |
import org.slf4j.LoggerFactory; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.app.ApplicationLocator; |
31 |
import org.gvsig.app.project.documents.view.ViewDocument; |
32 |
import org.gvsig.app.project.documents.view.ViewManager; |
33 |
import org.gvsig.app.project.documents.view.gui.IView; |
34 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
36 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
37 |
import org.gvsig.fmap.mapcontrol.MapControl; |
38 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
39 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorBehavior; |
40 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorPointListener; |
41 |
|
42 |
/**
|
43 |
* @author fdiaz
|
44 |
*
|
45 |
*/
|
46 |
public class AttributeEditorExtension extends Extension { |
47 |
private static Logger logger = LoggerFactory.getLogger( |
48 |
AttributeEditorExtension.class); |
49 |
|
50 |
|
51 |
public void execute(String actionCommand) { |
52 |
|
53 |
if (actionCommand.compareToIgnoreCase("attribute-editor") != 0) { |
54 |
return;
|
55 |
} |
56 |
|
57 |
IView vw = (IView) ApplicationLocator.getManager().getActiveComponent(ViewDocument.class); |
58 |
|
59 |
if (vw != null) { |
60 |
|
61 |
FLayer[] act_lyr = vw.getMapControl().getMapContext().getLayers().getActives();
|
62 |
if (act_lyr == null || act_lyr.length != 1 |
63 |
|| !(act_lyr[0] instanceof FLyrVect)) { |
64 |
//do nothing
|
65 |
|
66 |
} else {
|
67 |
|
68 |
FLyrVect lyr = (FLyrVect)act_lyr[0];
|
69 |
MapControl mapControl = vw.getMapControl(); |
70 |
if (!mapControl.hasTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME)){
|
71 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
72 |
|
73 |
AttributeEditorBehavior attributeEditorBehavior = new AttributeEditorBehavior(mapControl);
|
74 |
attributeEditorBehavior.addMapBehavior(new MouseMovementBehavior(sbl), false); |
75 |
mapControl.addBehavior(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME, attributeEditorBehavior); |
76 |
} |
77 |
|
78 |
mapControl.setTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME); |
79 |
|
80 |
} |
81 |
} |
82 |
|
83 |
} |
84 |
|
85 |
public void initialize() { |
86 |
|
87 |
IconThemeHelper.registerIcon("action", "attribute-editor", this); |
88 |
} |
89 |
|
90 |
public boolean isEnabled() { |
91 |
|
92 |
/*
|
93 |
* It's enabled if there is exactly one vector layer in the active view
|
94 |
* and it has a selection
|
95 |
*/
|
96 |
|
97 |
ViewDocument vw = actWin(); |
98 |
|
99 |
if (vw != null) { |
100 |
|
101 |
// IView vw = (IView) actw;
|
102 |
FLayer[] act_lyr = vw.getMapContext().getLayers().getActives();
|
103 |
if (act_lyr == null || act_lyr.length != 1 |
104 |
|| !(act_lyr[0] instanceof FLyrVect)) { |
105 |
return false; |
106 |
|
107 |
} else {
|
108 |
FLyrVect vect = (FLyrVect) act_lyr[0];
|
109 |
if (!vect.isAvailable()) {
|
110 |
/*
|
111 |
* This can happen when opening a persisted project
|
112 |
* and there is a "slow" layer (GeoDB)
|
113 |
*/
|
114 |
return false; |
115 |
} |
116 |
// MapControl mapControl = vw.getMapControl();
|
117 |
// if(mapControl.getCurrentTool().equalsIgnoreCase(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME)){
|
118 |
// return false;
|
119 |
// }
|
120 |
return true; |
121 |
} |
122 |
|
123 |
} else {
|
124 |
return false; |
125 |
} |
126 |
} |
127 |
|
128 |
public boolean isVisible() { |
129 |
|
130 |
return actWin() != null; |
131 |
} |
132 |
|
133 |
|
134 |
/**
|
135 |
* Gets active window
|
136 |
* @return
|
137 |
*/
|
138 |
private ViewDocument actWin() {
|
139 |
return (ViewDocument) ApplicationLocator.getManager().getActiveDocument(ViewManager.TYPENAME);
|
140 |
} |
141 |
} |