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 @ 43
History | View | Annotate | Download (4.66 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.featureform.swing.FeatureFormSwingLocator; |
36 |
import org.gvsig.featureform.swing.FeatureFormSwingManager; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
40 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
41 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorBehavior; |
42 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorPointListener; |
43 |
|
44 |
/**
|
45 |
* @author fdiaz
|
46 |
*
|
47 |
*/
|
48 |
public class AttributeEditorExtension extends Extension { |
49 |
|
50 |
private static Logger logger = LoggerFactory.getLogger( |
51 |
AttributeEditorExtension.class); |
52 |
|
53 |
public void execute(String actionCommand) { |
54 |
|
55 |
if (actionCommand.compareToIgnoreCase("attribute-editor") != 0) { |
56 |
return;
|
57 |
} |
58 |
|
59 |
IView vw = (IView) ApplicationLocator.getManager().getActiveComponent(ViewDocument.class); |
60 |
|
61 |
if (vw != null) { |
62 |
|
63 |
FLayer[] act_lyr = vw.getMapControl().getMapContext().getLayers().getActives();
|
64 |
if (act_lyr == null || act_lyr.length != 1 |
65 |
|| !(act_lyr[0] instanceof FLyrVect)) { |
66 |
//do nothing
|
67 |
|
68 |
} else {
|
69 |
|
70 |
FLyrVect lyr = (FLyrVect) act_lyr[0];
|
71 |
MapControl mapControl = vw.getMapControl(); |
72 |
if (!mapControl.hasTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME)) {
|
73 |
AttributeEditorBehavior attributeEditorBehavior = new AttributeEditorBehavior(mapControl);
|
74 |
mapControl.addBehavior(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME, attributeEditorBehavior); |
75 |
} |
76 |
|
77 |
mapControl.setTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME); |
78 |
|
79 |
} |
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
public void initialize() { |
85 |
|
86 |
IconThemeHelper.registerIcon("action", "attribute-editor", this); |
87 |
|
88 |
FeatureFormSwingManager featureFormManager = FeatureFormSwingLocator.getSwingManager(); |
89 |
featureFormManager.registerFeatureFormDefinitionsProvider(new DefaultFeatureFormDefinitionsProvider());
|
90 |
} |
91 |
|
92 |
public boolean isEnabled() { |
93 |
|
94 |
/*
|
95 |
* It's enabled if there is exactly one vector layer in the active view
|
96 |
* and it has a selection
|
97 |
*/
|
98 |
ViewDocument vw = actWin(); |
99 |
|
100 |
if (vw != null) { |
101 |
|
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 |
return true; |
117 |
} |
118 |
|
119 |
} else {
|
120 |
return false; |
121 |
} |
122 |
} |
123 |
|
124 |
public boolean isVisible() { |
125 |
|
126 |
return actWin() != null; |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Gets active window
|
131 |
*
|
132 |
* @return
|
133 |
*/
|
134 |
private ViewDocument actWin() {
|
135 |
return (ViewDocument) ApplicationLocator.getManager().getActiveDocument(ViewManager.TYPENAME);
|
136 |
} |
137 |
} |