Revision 98

View differences:

org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
	<modelVersion>4.0.0</modelVersion>
3
	<parent>
4
		<groupId>org.gvsig</groupId>
5
		<artifactId>org.gvsig.desktop</artifactId>
6
		<version>2.0.111</version>
7
	</parent>
8
	<groupId>org.gvsig</groupId>
9
	<artifactId>org.gvsig.attributeeditor</artifactId>
10
	<version>1.0.14</version>
11
	<packaging>pom</packaging>
12
	<name>org.gvsig.attributeeditor</name>
13
	<description>This plugins allows to edit the alphanumeric attributes of a layer.</description>
14

  
15
	<repositories>
16
		<repository>
17
			<id>gvsig-public-http-repository</id>
18
			<name>gvSIG maven public HTTP repository</name>
19
			<url>http://devel.gvsig.org/m2repo/j2se</url>
20
			<releases>
21
				<enabled>true</enabled>
22
				<updatePolicy>daily</updatePolicy>
23
				<checksumPolicy>warn</checksumPolicy>
24
			</releases>
25
			<snapshots>
26
				<enabled>true</enabled>
27
				<updatePolicy>daily</updatePolicy>
28
				<checksumPolicy>warn</checksumPolicy>
29
			</snapshots>
30
		</repository>
31
	</repositories>
32

  
33
	<scm>
34
		<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-attributeeditor/org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14</connection>
35
		<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-attributeeditor/org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14</developerConnection>
36
		<url>https://devel.gvsig.org/redmine/projects/gvsig-attributeeditor/repository/show/org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14</url>
37
	</scm>
38

  
39

  
40
	<dependencyManagement>
41
		<dependencies>
42
			<dependency>
43
				<groupId>org.gvsig</groupId>
44
				<artifactId>
45
    				org.gvsig.attributeeditor.app.mainplugin
46
    			</artifactId>
47
				<version>1.0.14</version>
48
			</dependency>
49
			<dependency>
50
				<groupId>org.gvsig</groupId>
51
				<artifactId>
52
    				org.gvsig.attributeeditor.mapcontrol
53
    			</artifactId>
54
				<version>1.0.14</version>
55
			</dependency>
56
		</dependencies>
57
	</dependencyManagement>
58

  
59
	<build>
60
		<plugins>
61
			<plugin>
62
				<groupId>org.apache.maven.plugins</groupId>
63
				<artifactId>maven-release-plugin</artifactId>
64
				<configuration>
65
					<tagBase>https://devel.gvsig.org/svn/gvsig-attributeeditor/${project.artifactId}/tags</tagBase>
66
					<goal>deploy</goal>
67
				</configuration>
68
			</plugin>
69
		</plugins>
70
	</build>
71

  
72
	<modules>
73
<!-- 		<module>org.gvsig.featureform.swing</module> -->
74
		<module>org.gvsig.attributeeditor.mapcontrol</module>
75
		<module>org.gvsig.attributeeditor.app</module>
76
	</modules>
77

  
78
	<dependencies>
79
	  <dependency>
80
	    <groupId>org.gvsig</groupId>
81
	    <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
82
	  </dependency>
83
	</dependencies>
84
</project>
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.mapcontrol/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/AttributeEditorBehavior.java
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.fmap.mapcontrol.tools.Listeners;
24

  
25
import java.awt.Image;
26

  
27
import org.gvsig.fmap.mapcontrol.MapControl;
28
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
29
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
30
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
31

  
32

  
33
/**
34
 * @author fdiaz
35
 *
36
 */
37
public class AttributeEditorBehavior extends CompoundBehavior {
38

  
39
    AttributeEditorPointListener attributeEditorPointListener;
40

  
41
    /**
42
     * @param behaviors
43
     */
44
    public AttributeEditorBehavior(MapControl mapControl) {
45
        super(new Behavior[0]);
46
        this.attributeEditorPointListener =
47
            new AttributeEditorPointListener(mapControl);
48

  
49
        this.addMapBehavior(new PointBehavior(attributeEditorPointListener), true);
50

  
51
    }
52

  
53
    public Image getImageCursor() {
54
        return this.attributeEditorPointListener.getImageCursor();
55
    }
56

  
57
    public ToolListener getListener(){
58
        return this.attributeEditorPointListener;
59
    }
60

  
61
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.mapcontrol/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/AttributeEditorPointListener.java
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

  
24
package org.gvsig.fmap.mapcontrol.tools.Listeners;
25

  
26
import java.awt.Dimension;
27
import java.awt.event.ComponentEvent;
28
import java.awt.event.ComponentListener;
29
import java.awt.event.InputEvent;
30
import java.awt.event.MouseEvent;
31

  
32
import javax.swing.JOptionPane;
33
import javax.swing.SwingUtilities;
34

  
35
import org.cresques.cts.IProjection;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
import org.gvsig.featureform.swing.CreateJFeatureFormException;
40
import org.gvsig.featureform.swing.JFeatureForm;
41
import org.gvsig.fmap.dal.exception.DataException;
42
import org.gvsig.fmap.dal.feature.FeatureQuery;
43
import org.gvsig.fmap.dal.feature.FeatureSelection;
44
import org.gvsig.fmap.dal.feature.FeatureSet;
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.dal.feature.FeatureType;
47
import org.gvsig.fmap.dal.swing.DALSwingLocator;
48
import org.gvsig.fmap.dal.swing.DataSwingManager;
49
import org.gvsig.fmap.geom.Geometry;
50
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
51
import org.gvsig.fmap.geom.Geometry.TYPES;
52
import org.gvsig.fmap.geom.GeometryLocator;
53
import org.gvsig.fmap.geom.GeometryManager;
54
import org.gvsig.fmap.geom.exception.CreateGeometryException;
55
import org.gvsig.fmap.geom.primitive.Circle;
56
import org.gvsig.fmap.geom.primitive.Point;
57
import org.gvsig.fmap.mapcontext.ViewPort;
58
import org.gvsig.fmap.mapcontext.layers.FLayer;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsGeometryEvaluator;
61
import org.gvsig.fmap.mapcontrol.MapControl;
62
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
63
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
64
import org.gvsig.tools.ToolsLocator;
65
import org.gvsig.tools.i18n.I18nManager;
66
import org.gvsig.tools.service.ServiceException;
67
import org.gvsig.tools.swing.api.ToolsSwingLocator;
68
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
69

  
70
/**
71
 * @author fdiaz
72
 *
73
 */
74
public class AttributeEditorPointListener extends AbstractPointListener implements ComponentListener {
75

  
76
    private static Logger logger = LoggerFactory.getLogger(AttributeEditorPointListener.class);
77

  
78
    public static final String ATTRIBUTE_EDITOR_TOOL_NAME = "attributeEditorTool";
79
    private static final String ATTRIBUTE_EDITOR_FORM_NAME = "attributeEditorForm";
80
    private MapControl mapControl;
81
    private JFeatureForm form;
82
    private FLyrVect currentLayer = null;
83
    /**
84
     * Radius as tolerance around the selected point, the area will be used to
85
     * look for information.
86
     */
87
    private static int TOL = 7;
88

  
89
    public AttributeEditorPointListener(MapControl mapControl, JFeatureForm form) {
90
        super();
91
        this.mapControl = mapControl;
92
        this.form = form;
93
    }
94

  
95
    public AttributeEditorPointListener(MapControl mapControl) {
96
        super();
97
        this.mapControl = mapControl;
98
    }
99

  
100
    private FLyrVect getLayer() {
101
        FLayer[] layers = mapControl.getMapContext().getLayers().getActives();
102
        if (layers == null || layers.length != 1) {
103
            return null;
104
        }
105
        return (FLyrVect) layers[0];
106

  
107
    }
108

  
109
    public void point(PointEvent e) throws BehaviorException {
110
        MouseEvent mouseEvent = e.getEvent();
111
        if (((mouseEvent.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
112
            | InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.META_DOWN_MASK)) != 0)
113
            || !SwingUtilities.isLeftMouseButton(mouseEvent)) {
114
            return;
115
        }
116

  
117
        I18nManager i18nManager = ToolsLocator.getI18nManager();
118
        String layerName = "";
119
        try {
120
            FLyrVect layer = getLayer();
121
            if (layer == null) {
122
                String msg = i18nManager.getTranslation("There_is_no_one_and_only_one_active_layer");
123
                ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
124
                    i18nManager.getTranslation("attribute_editor"), JOptionPane.INFORMATION_MESSAGE);
125
                return;
126
            }
127
            FeatureStore featureStore;
128
            featureStore = layer.getFeatureStore();
129
            if (layer != this.currentLayer) {
130
                if (this.currentLayer != null) {
131
                    if (this.form != null) {
132
                        this.form.saveChanges();
133
                    }
134
                }
135
                this.currentLayer = layer;
136
                if (this.form != null) {
137
                    this.form.bind(featureStore);
138
                }
139
            }
140
            layerName = layer.getName();
141
            ViewPort vp = this.mapControl.getViewPort();
142
            Point point = vp.convertToMapPoint(e.getPoint());
143
            double tolerance = vp.toMapDistance(TOL);
144
            FeatureQuery query = null;
145
            query = queryByPoint(point, tolerance);
146
            if (query != null) {
147
                if (this.form == null) {
148
                    this.form = getForm();
149
                    this.form.showForm(MODE.TOOL);
150
                }
151

  
152
                if (query != null) {
153
                    try {
154
                        synchronized (featureStore) {
155
                            FeatureSet featSet = featureStore.getFeatureSet(query);
156
                            FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
157
                            selection.deselectAll();
158
                            selection.select(featSet);
159
                        }
160
                    } catch (DataException ex) {
161
                        throw new RuntimeException("Error getting a feature set with the query " + query);
162
                    }
163
                }
164
                this.form.setQuery(query);
165
            }
166
        } catch (Exception ex) {
167
            logger.warn("Can't show attribute information from point on the layer " + layerName, ex);
168
            String msg =
169
                i18nManager.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
170
                    new String[] { layerName });
171
            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
172
                i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
173
        }
174
    }
175

  
176
    private JFeatureForm getForm() throws CreateJFeatureFormException, ServiceException, DataException {
177
        if (this.form == null) {
178
            DataSwingManager swingManager = DALSwingLocator.getSwingManager();
179
            FeatureStore store = this.currentLayer.getFeatureStore();
180
            this.form = swingManager.createJFeatureForm(store);
181
            this.form.setPreferredSize(new Dimension(300, 200));
182
            this.form.asJComponent().setName(ATTRIBUTE_EDITOR_FORM_NAME);
183
            this.form.asJComponent().addComponentListener(this);
184
        }
185
        return this.form;
186
    }
187

  
188
    private FeatureQuery queryByPoint(Point point, double tol) throws CreateGeometryException, DataException {
189
        GeometryManager manager = GeometryLocator.getGeometryManager();
190
        Circle circle = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
191
        circle.setPoints(point, tol);
192

  
193
        FeatureStore featureStore = this.currentLayer.getFeatureStore();
194
        FeatureQuery featureQuery = featureStore.createFeatureQuery();
195
        FeatureType featureType = featureStore.getDefaultFeatureType();
196
        String geomName = featureType.getDefaultGeometryAttributeName();
197
        featureQuery.setFeatureType(featureType);
198

  
199
        Geometry query_geo = this.currentLayer.transformToSourceCRS(circle, true);
200

  
201
        IProjection query_proj = this.currentLayer.getMapContext().getProjection();
202
        if (this.currentLayer.getCoordTrans() != null) {
203
            query_proj = this.currentLayer.getCoordTrans().getPOrig();
204
        }
205

  
206
        IntersectsGeometryEvaluator iee =
207
            new IntersectsGeometryEvaluator(query_geo, query_proj, featureStore.getDefaultFeatureType(), geomName);
208
        featureQuery.setFilter(iee);
209
        featureQuery.setAttributeNames(null);
210
        return featureQuery;
211
    }
212

  
213
    public void componentResized(ComponentEvent e) {
214
        // TODO Auto-generated method stub
215

  
216
    }
217

  
218
    public void componentMoved(ComponentEvent e) {
219
        // TODO Auto-generated method stub
220

  
221
    }
222

  
223
    public void componentShown(ComponentEvent e) {
224
        // TODO Auto-generated method stub
225

  
226
    }
227

  
228
    public void componentHidden(ComponentEvent e) {
229
        this.form = null;
230
    }
231

  
232
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.mapcontrol/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.attributeeditor</artifactId>
6
    <version>1.0.14</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.attributeeditor.mapcontrol</artifactId>
10
  <version>1.0.14</version>
11
  <name>org.gvsig.atributeeditor.mapcontrol</name>
12
  <dependencies>
13
  	<dependency>
14
  		<groupId>org.gvsig</groupId>
15
  		<artifactId>org.gvsig.fmap.control</artifactId>
16

  
17
  	</dependency>
18

  
19
    <dependency>
20
      <groupId>org.gvsig</groupId>
21
      <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
22
    </dependency>
23
  </dependencies>
24
</project>
0 25

  
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
	<modelVersion>4.0.0</modelVersion>
3
	<parent>
4
		<groupId>org.gvsig</groupId>
5
		<artifactId>org.gvsig.attributeeditor</artifactId>
6
		<version>1.0.14</version>
7
	</parent>
8
	<groupId>org.gvsig</groupId>
9
	<artifactId>org.gvsig.attributeeditor.app</artifactId>
10
	<version>1.0.14</version>
11
	<packaging>pom</packaging>
12
	<name>org.gvsig.attributeeditor.app</name>
13
	<modules>
14
		<module>org.gvsig.attributeeditor.app.mainplugin</module>
15
	</modules>
16

  
17
</project>
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/buildNumber.properties
1
#Thu Nov 12 16:28:11 CET 2015
2
buildNumber=15
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2014 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
  <dependencySets>
51
    <dependencySet>
52
      <useProjectArtifact>false</useProjectArtifact>
53
      <useTransitiveDependencies>false</useTransitiveDependencies>
54
      <outputDirectory>lib</outputDirectory>
55
      <includes>
56
        <include>org.gvsig:org.gvsig.attributeeditor.mapcontrol</include>
57
      </includes>
58
    </dependencySet>
59
  </dependencySets>
60

  
61
</assembly>
62

  
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/java/org/gvsig/app/mainplugin/extension/AttributeEditorExtension.java
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.fmap.dal.swing.DALSwingLocator;
35
import org.gvsig.fmap.dal.swing.DataSwingManager;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.fmap.mapcontrol.MapControl;
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

  
48
    private static Logger logger = LoggerFactory.getLogger(
49
            AttributeEditorExtension.class);
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
                    AttributeEditorBehavior attributeEditorBehavior = new AttributeEditorBehavior(mapControl);
72
                    mapControl.addBehavior(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME, attributeEditorBehavior);
73
                }
74

  
75
                mapControl.setTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);
76

  
77
            }
78
        }
79

  
80
    }
81

  
82
    public void initialize() {
83

  
84
        IconThemeHelper.registerIcon("action", "attribute-editor", this);
85

  
86
        DataSwingManager featureFormManager = DALSwingLocator.getSwingManager();
87
        featureFormManager.registerFeatureFormDefinitionsProvider(new DefaultFeatureFormDefinitionsProvider());
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
        ViewDocument vw = actWin();
97

  
98
        if (vw != null) {
99

  
100
            FLayer[] act_lyr = vw.getMapContext().getLayers().getActives();
101
            if (act_lyr == null || act_lyr.length != 1
102
                    || !(act_lyr[0] instanceof FLyrVect)) {
103
                return false;
104

  
105
            } else {
106
                FLyrVect vect = (FLyrVect) act_lyr[0];
107
                if (!vect.isAvailable()) {
108
                    /*
109
                     * This can happen when opening a persisted project
110
                     * and there is a "slow" layer (GeoDB)
111
                     */
112
                    return false;
113
                }
114
                return true;
115
            }
116

  
117
        } else {
118
            return false;
119
        }
120
    }
121

  
122
    public boolean isVisible() {
123

  
124
        return actWin() != null;
125
    }
126

  
127
    /**
128
     * Gets active window
129
     *
130
     * @return
131
     */
132
    private ViewDocument actWin() {
133
        return (ViewDocument) ApplicationLocator.getManager().getActiveDocument(ViewManager.TYPENAME);
134
    }
135
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/java/org/gvsig/app/mainplugin/extension/DefaultFeatureFormDefinitionsProvider.java
1

  
2
package org.gvsig.app.mainplugin.extension;
3

  
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7
import java.io.IOException;
8
import java.util.Map;
9
import java.util.zip.CRC32;
10
import org.apache.commons.io.FileUtils;
11
import org.gvsig.andami.PluginServices;
12
import org.gvsig.andami.PluginsLocator;
13
import org.gvsig.andami.PluginsManager;
14
import org.gvsig.featureform.swing.FeatureFormDefinitionsProvider;
15
import org.gvsig.fmap.dal.exception.DataException;
16
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
17
import org.gvsig.fmap.dal.feature.FeatureStore;
18
import org.gvsig.fmap.dal.feature.FeatureType;
19
import org.gvsig.tools.ToolsLocator;
20
import org.gvsig.tools.dynobject.DynClass;
21
import org.gvsig.tools.dynobject.DynObjectManager;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24
import org.xmlpull.v1.XmlPullParserException;
25

  
26

  
27
public class DefaultFeatureFormDefinitionsProvider implements FeatureFormDefinitionsProvider {
28

  
29
    private static final Logger logger = LoggerFactory.getLogger(DefaultFeatureFormDefinitionsProvider.class);
30
            
31
    private File definitionsFolder = null;
32
            
33
    private File getDefinitionsFolder() throws IOException {
34
        if( this.definitionsFolder == null ) {
35
            PluginsManager pluginManager = PluginsLocator.getManager();
36
            PluginServices plugin = pluginManager.getPlugin(AttributeEditorExtension.class);
37
            File homeFolder = plugin.getPluginHomeFolder();
38
            File definitionsFolder = new File(homeFolder,"definitions");
39
            if( !definitionsFolder.exists() ) {
40
                FileUtils.forceMkdir(definitionsFolder);
41
            }            
42
            this.definitionsFolder = definitionsFolder;
43
        }
44
        return this.definitionsFolder;
45
    }
46
    
47
    private long getCRC(FeatureType type) {
48
        StringBuffer buffer = new StringBuffer();
49
        for( int i=0; i< type.size(); i++) {
50
            FeatureAttributeDescriptor x = type.getAttributeDescriptor(i);
51
            buffer.append(x.getName());
52
            buffer.append(x.getDataTypeName());
53
            buffer.append(x.getSize());
54
        }
55
        CRC32 crc = new CRC32();
56
        byte[] data = buffer.toString().getBytes();
57
        crc.update(data);
58
        return crc.getValue();
59
    }
60

  
61
    private String getFilename(FeatureStore store) throws DataException {
62
        FeatureType type = store.getDefaultFeatureType();
63
        
64
        return store.getName()+"-"+Long.toHexString(getCRC(type))+".xml";
65
    }
66
    
67
    public void put(FeatureStore store) throws DataException, IOException {
68
        DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
69
        FeatureType type = store.getDefaultFeatureType();
70
        if( !getDefinitionsFolder().exists() ) {
71
            FileUtils.forceMkdir(getDefinitionsFolder());
72
        }
73
        File f = new File(getDefinitionsFolder(), getFilename(store));
74
        dynObjectManager.exportSimpleDynClassDefinitions(f,type);
75
    }
76

  
77
    public DynClass get(FeatureStore store) throws DataException {
78
        DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
79
        FeatureType type = store.getDefaultFeatureType();
80
        
81
        File f;
82
        try {
83
            f = new File(getDefinitionsFolder(), getFilename(store));
84
        } catch (IOException ex) {
85
            return type;
86
        }
87
        if( !f.exists() ) {
88
            return type;
89
        }
90
        FileInputStream fis;
91
        try {
92
            fis = new FileInputStream(f);
93
        } catch (FileNotFoundException ex) {
94
            return type;
95
        }
96
        Map classes = null;
97
        try {
98
            classes = dynObjectManager.importDynClassDefinitions(fis, this.getClass().getClassLoader());
99
        } catch (XmlPullParserException ex) {
100
            logger.warn("Can't load xml definition.", ex);
101
            return type;
102
        } catch (IOException ex) {
103
            return type;
104
        }
105
        DynClass dynClass = (DynClass) classes.get(type.getName());
106
        if( dynClass == null ) {
107
            return type;
108
        }
109
        return dynClass;
110
    }
111
    
112
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/java/org/gvsig/app/mainplugin/extension/CreateDefaultDefinitionExtension.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.app.mainplugin.extension;
7

  
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10

  
11
import org.gvsig.andami.plugins.Extension;
12
import org.gvsig.app.ApplicationLocator;
13
import org.gvsig.app.ApplicationManager;
14
import org.gvsig.app.project.documents.view.ViewDocument;
15
import org.gvsig.app.project.documents.view.ViewManager;
16
import org.gvsig.fmap.dal.swing.DALSwingLocator;
17
import org.gvsig.fmap.dal.swing.DataSwingManager;
18
import org.gvsig.fmap.mapcontext.MapContext;
19
import org.gvsig.fmap.mapcontext.layers.FLayer;
20
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
21

  
22
/**
23
 *
24
 * @author jjdelcerro
25
 */
26
public class CreateDefaultDefinitionExtension extends Extension {
27

  
28
    private static final Logger logger = LoggerFactory.getLogger(CreateDefaultDefinitionExtension.class);
29

  
30
    public void initialize() {
31

  
32
    }
33

  
34
    public void execute(String actionCommand) {
35
        if( "tools-attributeditor-create-default-definition".equalsIgnoreCase(actionCommand) ) {
36
            ApplicationManager application = ApplicationLocator.getManager();
37
            ViewDocument viewDoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
38
            if( viewDoc == null ) {
39
                return;
40
            }
41
            MapContext mapContext = viewDoc.getMapContext();
42
            if( !mapContext.hasActiveVectorLayers() ) {
43
                return;
44
            }
45
            DataSwingManager featureFormManager = DALSwingLocator.getSwingManager();
46
            FLayer[] layers = mapContext.getLayers().getActives();
47
            for( int i=0; i<layers.length; i++ ) {
48
                if( layers[i] instanceof FLyrVect ) {
49
                    FLyrVect layer = (FLyrVect) layers[i];
50
                    try {
51
                        featureFormManager.getFeatureFormDefinitionsProvider().put(layer.getFeatureStore());
52
                    } catch (Exception ex) {
53
                        logger.warn("Can't save form definition for layer '"+layer.getName()+"'.",ex);
54
                    }
55

  
56
                }
57
            }
58
        }
59
    }
60

  
61
    public boolean isEnabled() {
62
        ApplicationManager application = ApplicationLocator.getManager();
63
        ViewDocument viewDoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
64
        if( viewDoc == null ) {
65
            return false;
66
        }
67
        MapContext mapContext = viewDoc.getMapContext();
68
        return mapContext.hasActiveVectorLayers();
69
    }
70

  
71
    public boolean isVisible() {
72
        return true;
73
    }
74

  
75
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
# Resource bundle texts for the Spanish language locale (es)
2
attribute_editor=Editor de atributos
3
error_saving_data_will_not_save=Se ha producido un error intentando guardar los datos. Los datos no se guardar\u00e1n.
4
cant_edit_the store_XstorenameX=No se ha podido poner en edici\u00f3n el store '%(storename)'
5
cant_get_the_associated_feature_to_index_XindexX=No se ha podido obtener la feature asociada al index '%(index)'
6
cant_update_the_feature_XindexX_in_the_store_XstorenameX=No se ha podido actualizar la feature '%(index)' en el store '%(storename)'
7
cant_finish_the_edition_of_the_store_XstorenameX=No se ha podido finalizar la edici\u00f3n del store '%(storename)'
8
There_is_no_one_and_only_one_active_layer=No hay una y solo una capa activa.
9
Cant_show_attribute_information_for_layer_%1_on_point=No se ha podido mostrar la informaci\u00f3n de los atributos de la capa %1 sobre este punto.
10
create_default_definition=Crear definici\u00f3n por defecto
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
attribute_editor=Attribute editor
3
error_saving_data_will_not_save=There was an error trying to save the data. The data will not be saved.
4
cant_edit_the store_XstorenameX=Can't edit the store '%(storename)'
5
cant_get_the_associated_feature_to_index_XindexX=Can't get the associated feature to index '%(index)'
6
cant_update_the_feature_XindexX_in_the_store_XstorenameX=Can't update the feature '%(index)' in the store '%(storename)'
7
cant_finish_the_edition_of_the_store_XstorenameX=Can't finish the edition of the store '%(storename)'
8
There_is_no_one_and_only_one_active_layer=There is no one and only one active layer
9
Cant_show_attribute_information_for_layer_%1_on_point=Can't show the attribute information for layer %1 on this point.
10
create_default_definition=Create default definition
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2014 gvSIG
3
  Association. This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by the Free Software
5
  Foundation; either version 3 of the License, or (at your option) any later version.
6
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
  PURPOSE. See the GNU General Public License for more details. You should have received
9
  a copy of the GNU General Public License along with this program; if not, write to
10
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
11
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
12
  or visit our website www.gvsig.com. -->
13
<plugin-config>
14
  <depends plugin-name="org.gvsig.app.mainplugin" />
15
  <resourceBundle name="text" />
16
  <libraries library-dir="lib" />
17
  <extensions>
18
    <extension class-name="org.gvsig.app.mainplugin.extension.AttributeEditorExtension"
19
      description="" active="true" priority="1">
20

  
21
      <action name="attribute-editor" label="attribute_editor" tooltip="attribute_editor"
22
        position="300300000" action-command="attribute-editor" icon="attribute-editor"
23
        accelerator="" />
24

  
25
      <menu name="attribute-editor" text="Layer/attribute_editor"
26
        action-command="attribute-editor" />
27

  
28
      <tool-bar name="attribute-editor">
29
        <selectable-tool name="attribute-editor" />
30
      </tool-bar>
31

  
32
    </extension>
33

  
34
    <extension
35
      class-name="org.gvsig.app.mainplugin.extension.CreateDefaultDefinitionExtension"
36
      description="" active="true" priority="1">
37

  
38
      <action name="tools-attributeditor-create-default-definition"
39
        label="Create default definition" tooltip="attribute_editor" position="908500000"
40
        action-command="tools-attributeditor-create-default-definition" icon="tools-attributeditor-create-default-definition"
41
        accelerator="" />
42

  
43
      <menu name="tools-attributeditor-create-default-definition" text="tools/attribute_editor/create_default_definition" />
44

  
45
    </extension>
46

  
47
  </extensions>
48
</plugin-config>
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.14/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.attributeeditor.app</artifactId>
6
    <version>1.0.14</version>
7
  </parent>
8
  <artifactId>org.gvsig.attributeeditor.app.mainplugin</artifactId>
9
  <name>org.gvsig.attributeeditor.app.mainplugin</name>
10

  
11
	<properties>
12
		<!-- Package info property values -->
13
		<!-- Default values in org.gvsig.desktop -->
14
		<gvsig.package.info.state>testing</gvsig.package.info.state>
15
		<gvsig.package.info.official>true</gvsig.package.info.official>
16
		<gvsig.package.info.name>Attribute editor</gvsig.package.info.name>
17
		<gvsig.package.info.categories>Vector</gvsig.package.info.categories>
18
		<gvsig.package.info.description>Attribute editor: provides a tool to edit the attributes of vector layers easily and quickly.</gvsig.package.info.description>
19
		<gvsig.package.info.dependencies>required: org.gvsig.app -ge 2.1.0</gvsig.package.info.dependencies>
20
		<gvsig.package.info.javaVM>j1_6</gvsig.package.info.javaVM>
21
		<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-attributeeditor/pool/</gvsig.package.info.poolURL>
22
	</properties>
23
  <dependencies>
24
    <dependency>
25
        <groupId>org.gvsig</groupId>
26
        <artifactId>org.gvsig.app.mainplugin</artifactId>
27
        <scope>compile</scope>
28
    </dependency>
29
    <dependency>
30
    	<groupId>org.gvsig</groupId>
31
    	<artifactId>org.gvsig.attributeeditor.mapcontrol</artifactId>
32
    </dependency>
33
  </dependencies>
34
</project>
0 35

  

Also available in: Unified diff