Revision 37477

View differences:

tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:49:47 CET 2011
3
buildNumber=2050
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.6-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<!-- Download the build jar file -->
29
		<get src="http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
30

  
31
		<mkdir dir="target" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
			<filterset>
41
				<filter token="GVSIG_HOME" value="/home/cordin/projects/gvsig/svn/gvSIG-2.0-build/build/product" />
42
			</filterset>
43
		</copy>
44

  
45
	</target>
46

  
47
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote">
48

  
49
		<mkdir dir="target" />
50

  
51
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
52

  
53
		<!-- Copy the maven launchers to the workspace metadata folder -->
54
		<copy todir="${workspace.basedir}/.metadata">
55
			<fileset dir="${build.basedir}/eclipse-launchers">
56
				<exclude name="**/org.eclipse.jdt.core.prefs" />
57
				<exclude name="**/org.eclipse.core.variables.prefs" />
58
			</fileset>
59
		</copy>
60

  
61
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
62
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
63
		</concat>
64
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
65
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
66
		</concat>
67

  
68
		<!-- Configure the eclipse workspace -->
69
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
70

  
71
		<!-- Configure the gvSIG profile -->
72
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" target="initialize" />
73

  
74
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
75

  
76
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
77
			<classpath>
78
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
79
			</classpath>
80
		</taskdef>
81

  
82
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
83
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
84
		</xmltask>
85

  
86
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
87
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
88

  
89
		<!-- Compile, install and generate eclipse projects -->
90
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
91

  
92
		<echo>INFORMATION!!!</echo>
93
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
94

  
95
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
96
	</target>
97

  
98
	<target name="clean">
99
		<delete dir="target" />
100
	</target>
101

  
102
</project>
0 103

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
7
	<packaging>pom</packaging>
8
	<version>1.0.0-SNAPSHOT</version>
9
	<name>org.gvsig.geometrymeasurement.app</name>
10
	<description>Extension of the GeometryMeasurement example project</description>
11
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${project.version}/basic/org.gvsig.geometrymeasurement.app</url>
12
    <parent>
13
        <groupId>org.gvsig</groupId>
14
        <artifactId>org.gvsig.maven.base.extension.pom</artifactId>
15
        <version>1.0.8-SNAPSHOT</version>
16
    </parent>
17
	<scm>
18
		<connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</connection>
19
		<developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/trunk</developerConnection>
20
		<url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.geometrymeasurement/extension/trunk/?root=gvsig-geometrymeasurement</url>
21
	</scm>
22

  
23
	<developers>
24
		<developer>
25
			<id>vcaballero</id>
26
			<name>Vicente Caballero Navarro</name>
27
			<email>vicente.caballero@iver.es</email>
28
			<roles>				
29
				<role>Developer</role>
30
			</roles>
31
		</developer>
32
		<developer>
33
			<id>jpiera</id>
34
			<name>Jorge Piera Llodr?</name>
35
			<email>jpiera@gvsig.org</email>
36
			<roles>
37
				<role>Developer</role>
38
			</roles>
39
		</developer>		
40
	</developers>
41

  
42
	<distributionManagement>
43
		<site>
44
			<id>gvsig-repository</id>
45
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.geometrymeasurement/${project.version}/basic/org.gvsig.geometrymeasurement.app</url>
46
		</site>
47
	</distributionManagement>
48
	<repositories>
49
		<repository>
50
			<id>gvsig-public-http-repository</id>
51
			<name>gvSIG maven public HTTP repository</name>
52
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
53
			<releases>
54
				<enabled>true</enabled>
55
				<updatePolicy>daily</updatePolicy>
56
				<checksumPolicy>warn</checksumPolicy>
57
			</releases>
58
			<snapshots>
59
				<enabled>true</enabled>
60
				<updatePolicy>daily</updatePolicy>
61
				<checksumPolicy>warn</checksumPolicy>
62
			</snapshots>
63
		</repository>
64
	</repositories>
65
	<build>
66
		<plugins>
67
			<plugin>
68
				<groupId>org.apache.maven.plugins</groupId>
69
				<artifactId>maven-release-plugin</artifactId>
70
				<configuration>
71
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-geometrymeasurement/org.gvsig.geometrymeasurement/extension/tags</tagBase>
72
				</configuration>
73
			</plugin>
74
		</plugins>
75
	</build>
76
    <dependencyManagement>
77
        <dependencies>          
78
            <dependency>
79
                <groupId>org.gvsig</groupId>
80
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
81
                <version>2.0.1-SNAPSHOT</version>
82
                <type>pom</type>
83
                <scope>import</scope>
84
            </dependency>
85
        </dependencies>
86
    </dependencyManagement>
87
	<modules>
88
		<module>org.gvsig.geometrymeasurement.app.extension</module>
89
	</modules>
90
	<properties>
91
		<package.info.state>alpha2</package.info.state>
92
	</properties>
93
</project>
0 94

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/README.txt
1
The first time you checkout the current project to a new workspace, 
2
you have to prepare it to be able to work easily with maven from
3
eclipse itself.
4

  
5
Perform the following steps:
6

  
7
1.- Launch the *prepare-workspace.xml* ant build file. 
8
    You can do it by loading the file into the ant view, 
9
    and running the default task, or right-clicking the 
10
    file from the package explorer or the navigator and
11
    select the option: *Run as > Ant build*. 
12
    
13
2.- Restart eclipse.
14

  
15
3.- Import the subprojects of the project you have just checked out.
16

  
17
Those steps are only needed once per workspace.     
18

  
0 19

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:49:47 CET 2011
3
buildNumber=2042
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.geometrymeasurement">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AreaMeasurementExtension.java
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
package org.gvsig.geometrymeasurement.app.extension;
23

  
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
27
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
28

  
29
/**
30
 * Andami extension to show AreaMeasurementExtension in the application.
31
 * 
32
 * @author gvSIG Team
33
 * @version $Id$
34
 */
35
public class AreaMeasurementExtension extends
36
    AbstractGeometryMeasurementExtension {
37

  
38
    public void initialize() {
39
        // Do nothing
40
    }
41

  
42
    @Override
43
    protected void execute(String actionCommand, FeatureStore featureStore)
44
        throws Exception {
45
        new Operations().addDoubleFieldFromOperation(featureStore, "AREA",
46
            "area");
47
    }
48

  
49
    @Override
50
    protected boolean isVisibleForLayer(FLyrVect layer) {
51
        return isLayerOfAnyType(layer, new int[] { Geometry.TYPES.CIRCLE,
52
            Geometry.TYPES.ELLIPSE, Geometry.TYPES.SURFACE,
53
            Geometry.TYPES.MULTISURFACE });
54
    }
55
}
0 56

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/PerimeterMeasurementExtension.java
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
package org.gvsig.geometrymeasurement.app.extension;
23

  
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
27
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
28

  
29
/**
30
 * Andami extension to show PerimeterMeasurementExtension in the application.
31
 * 
32
 * @author gvSIG Team
33
 * @version $Id$
34
 */
35
public class PerimeterMeasurementExtension extends
36
    AbstractGeometryMeasurementExtension {
37

  
38
    public void initialize() {
39
        // Do nothing
40
    }
41

  
42
    @Override
43
    protected void execute(String actionCommand, FeatureStore featureStore)
44
        throws Exception {
45
        new Operations().addDoubleFieldFromOperation(featureStore, "PERIMETER",
46
            "perimeter");
47
    }
48

  
49
    @Override
50
    protected boolean isVisibleForLayer(FLyrVect layer) {
51
        return !isLayerOfAnyType(layer, new int[] { Geometry.TYPES.POINT });
52
    }
53

  
54
}
0 55

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/utils/Operations.java
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
package org.gvsig.geometrymeasurement.app.extension.utils;
23

  
24
import java.util.Iterator;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.app.project.documents.table.TableOperations;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.EditableFeature;
32
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
33
import org.gvsig.fmap.dal.feature.EditableFeatureType;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
36
import org.gvsig.fmap.dal.feature.FeatureSet;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.dal.feature.FeatureType;
39
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
42
import org.gvsig.fmap.geom.primitive.Point;
43
import org.gvsig.tools.dataTypes.DataTypes;
44
import org.gvsig.tools.dispose.DisposableIterator;
45

  
46
/**
47
 * Andami extension to show PerimeterMeasurementExtension in the application.
48
 * 
49
 * @author gvSIG Team
50
 * @version $Id$
51
 */
52
public class Operations {
53

  
54
    private static final Logger LOG = LoggerFactory.getLogger(Operations.class);
55

  
56
    private static final int NUM_DECIMALS = 5;
57

  
58
    public void addDoubleFieldFromOperation(FeatureStore featureStore,
59
        String fieldName, String operationName) throws DataException,
60
        GeometryOperationNotSupportedException, GeometryOperationException {
61
        boolean isEditing = false;
62
        if (featureStore.isEditing()) {
63
            isEditing = true;
64
        } else {
65
            featureStore.edit();
66
        }
67

  
68
        featureStore.beginEditingGroup(operationName);
69

  
70
        // Adding the new attribute type
71
        FeatureType featureType = featureStore.getDefaultFeatureType();
72
        EditableFeatureType editableFeatureType = featureType.getEditable();
73

  
74
        String realFieldName = getFieldName(featureStore, fieldName, 0);
75
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor =
76
            editableFeatureType.add(realFieldName, DataTypes.DOUBLE);
77
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
78
        editableFeatureAttributeDescriptor
79
            .setSize(TableOperations.MAX_FIELD_LENGTH);
80

  
81
        featureStore.update(editableFeatureType);
82

  
83
        DisposableIterator disposableIterator = null;
84
        FeatureSet featureSet = null;
85
        try {
86
            // Adding the attribute value
87
            featureSet = featureStore.getFeatureSet();
88
            disposableIterator = featureSet.fastIterator();
89
            while (disposableIterator.hasNext()) {
90
                Feature feature = (Feature) disposableIterator.next();
91
                EditableFeature editableFeature = feature.getEditable();
92
                editableFeature.setDouble(realFieldName, (Double) feature
93
                    .getDefaultGeometry().invokeOperation(operationName, null));
94
                featureSet.update(editableFeature);
95
            }
96
        } finally {
97
            if (disposableIterator != null) {
98
                disposableIterator.dispose();
99
            }
100
            if (featureSet != null) {
101
                featureSet.dispose();
102
            }
103
            try {
104
                featureStore.endEditingGroup();
105
            } catch (NeedEditingModeException e) {
106
                LOG.error("Exception endEditingGroup", e);
107
            }
108
        }
109

  
110
        if (!isEditing) {
111
            featureStore.finishEditing();
112
        }
113
    }
114

  
115
    public String getFieldName(FeatureStore featureStore, String fieldName,
116
        int index) throws DataException {
117
        String fullName = fieldName;
118
        if (index != 0) {
119
            fullName = fullName + index;
120
        }
121
        @SuppressWarnings("unchecked")
122
        Iterator<FeatureAttributeDescriptor> it =
123
            featureStore.getDefaultFeatureType().iterator();
124
        while (it.hasNext()) {
125
            FeatureAttributeDescriptor featureAttributeDescriptor = it.next();
126
            if (featureAttributeDescriptor.getName().equals(fullName)) {
127
                return getFieldName(featureStore, fieldName, index + 1);
128
            }
129
        }
130
        return fullName;
131
    }
132

  
133
    /**
134
     * @param featureStore
135
     * @param string
136
     * @param string2
137
     * @throws DataException
138
     */
139
    public void addXYPoints(FeatureStore featureStore, String xFieldName,
140
        String yFieldName) throws DataException {
141
        boolean isEditing = false;
142
        if (featureStore.isEditing()) {
143
            isEditing = true;
144
        } else {
145
            featureStore.edit();
146
        }
147

  
148
        // Adding the new attribute type
149
        FeatureType featureType = featureStore.getDefaultFeatureType();
150
        EditableFeatureType editableFeatureType = featureType.getEditable();
151

  
152
        String realXFieldName = getFieldName(featureStore, xFieldName, 0);
153
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor =
154
            editableFeatureType.add(realXFieldName, DataTypes.DOUBLE);
155
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
156
        editableFeatureAttributeDescriptor
157
            .setSize(TableOperations.MAX_FIELD_LENGTH);
158

  
159
        String realYFieldName = getFieldName(featureStore, yFieldName, 0);
160
        editableFeatureAttributeDescriptor =
161
            editableFeatureType.add(realYFieldName, DataTypes.DOUBLE);
162
        editableFeatureAttributeDescriptor.setPrecision(NUM_DECIMALS);
163
        editableFeatureAttributeDescriptor
164
            .setSize(TableOperations.MAX_FIELD_LENGTH);
165

  
166
        featureStore.update(editableFeatureType);
167

  
168
        // Adding the attribute value
169
        FeatureSet featureSet = featureStore.getFeatureSet();
170
        DisposableIterator disposableIterator = featureSet.fastIterator();
171
        while (disposableIterator.hasNext()) {
172
            Feature feature = (Feature) disposableIterator.next();
173
            EditableFeature editableFeature = feature.getEditable();
174
            editableFeature.setDouble(realXFieldName,
175
                ((Point) feature.getDefaultGeometry()).getX());
176
            editableFeature.setDouble(realYFieldName,
177
                ((Point) feature.getDefaultGeometry()).getY());
178
            featureSet.update(editableFeature);
179
        }
180

  
181
        featureSet.dispose();
182

  
183
        if (!isEditing) {
184
            featureStore.finishEditing();
185
        }
186

  
187
    }
188

  
189
}
0 190

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AbstractGeometryMeasurementExtension.java
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
package org.gvsig.geometrymeasurement.app.extension;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.ReadException;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.mapcontext.layers.FLayer;
35
import org.gvsig.fmap.mapcontext.layers.FLayers;
36
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
37

  
38
/**
39
 * Abstract class for Geometry measurement operations extensions.
40
 * 
41
 * @author gvSIG Team
42
 * @version $Id$
43
 */
44
public abstract class AbstractGeometryMeasurementExtension extends Extension {
45

  
46
    private static final Logger LOG = LoggerFactory
47
        .getLogger(AbstractGeometryMeasurementExtension.class);
48

  
49
    public boolean isEnabled() {
50
        FLyrVect layer = getActiveFLyrVect();
51
        return (layer != null && layer.isWritable());
52
    }
53

  
54
    public final boolean isVisible() {
55
        FLyrVect layer = getActiveFLyrVect();
56
        if (layer != null) {
57
            return isVisibleForLayer(layer);
58
        }
59
        return false;
60
    }
61

  
62
    /**
63
     * Returns if the current extension is visible for the provided vectorial
64
     * layer.
65
     * 
66
     * The provided layer will be always non null.
67
     * 
68
     * @param layer
69
     *            the active vectorial layer
70
     * @return if the extension is visible
71
     */
72
    protected abstract boolean isVisibleForLayer(FLyrVect layer);
73

  
74
    /**
75
     * Returns the active vectorial layer. If there are more than
76
     * one active layers, it returns null;
77
     * 
78
     * @return the active vectorial layer
79
     */
80
    protected FLyrVect getActiveFLyrVect() {
81
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
82

  
83
        if (window instanceof IView) {
84
            IView view = (IView) window;
85
            FLayers layers = view.getMapControl().getMapContext().getLayers();
86
            FLayer[] activeLayers = layers.getActives();
87

  
88
            if (activeLayers.length == 1 && activeLayers[0] instanceof FLyrVect) {
89
                return (FLyrVect) activeLayers[0];
90
            }
91
        }
92
        return null;
93
    }
94

  
95
    protected boolean isLayerOfAnyType(FLyrVect layer, int[] geomTypes) {
96
        try {
97
            int type = layer.getShapeType();
98
            for (int i = 0; i < geomTypes.length; i++) {
99
                if (type == geomTypes[i]) {
100
                    return true;
101
                }
102
            }
103
        } catch (ReadException e) {
104
            LOG.error("Error reading the geometry type", e);
105
        }
106
        return false;
107
    }
108

  
109
    public void execute(String actionCommand) {
110
        FLyrVect layer = getActiveFLyrVect();
111
        if (layer == null) {
112
            return;
113
        }
114
        FeatureStore featureStore = layer.getFeatureStore();
115

  
116
        try {
117
            execute(actionCommand, featureStore);
118
        } catch (Exception e) {
119
            LOG.error("Not possible to create the area field", e);
120
            NotificationManager.addError(e);
121
        }
122
    }
123

  
124
    /**
125
     * Executes a command for the given {@link FeatureStore}.
126
     * 
127
     * @param actionCommand
128
     *            to execute
129
     * @param featureStore
130
     *            to use
131
     * @throws Exception
132
     *             if there is an error while executing
133
     */
134
    protected abstract void execute(String actionCommand,
135
        FeatureStore featureStore) throws Exception;
136

  
137
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/java/org/gvsig/geometrymeasurement/app/extension/AddXYPointThemeExtension.java
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
package org.gvsig.geometrymeasurement.app.extension;
23

  
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
27
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
28

  
29
/**
30
 * Andami extension to show PerimeterMeasurementExtension in the application.
31
 * 
32
 * @author gvSIG Team
33
 * @version $Id$
34
 */
35
public class AddXYPointThemeExtension extends
36
    AbstractGeometryMeasurementExtension {
37

  
38
    public void initialize() {
39
        // Do nothing
40
    }
41

  
42
    @Override
43
    protected void execute(String actionCommand, FeatureStore featureStore)
44
        throws Exception {
45
        new Operations().addXYPoints(featureStore, "X", "Y");
46
    }
47

  
48
    @Override
49
    protected boolean isVisibleForLayer(FLyrVect layer) {
50
        return isLayerOfAnyType(layer, new int[] { Geometry.TYPES.POINT });
51
    }
52
}
0 53

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/build.number
1
#Build Number for ANT. Do not edit!
2
#Tue Apr 28 16:00:47 CEST 2009
3
build.number=2005
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.app" />
4
    <depends plugin-name="org.gvsig.app.document.table.app.mainplugin" />
5
   	<resourceBundle name="text"/>
6
	<libraries library-dir="lib"/>
7
	<extensions>
8
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.AreaMeasurementExtension"
9
			description="Extension that measures the area of all the polygonos they selected."
10
            active="true">
11
            <menu text="Vista/area" tooltip="area"
12
                action-command="AREA"
13
                icon="images/area.png" />
14
            <tool-bar name="area">
15
                <action-tool icon="images/area.png"
16
                    action-command="AREA" tooltip="area"
17
                    enable-text="deber?a de estar activada" last="true"/>
18
            </tool-bar>
19
		</extension>	
20
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.PerimeterMeasurementExtension"
21
           description="Extension that measures the perimeter of all the lines they selected."
22
            active="true">
23
            <menu text="Vista/perimeter" tooltip="perimeter"
24
                action-command="PERIMETER"
25
                icon="images/perimeter.png" />
26
            <tool-bar name="perimeter">
27
                <action-tool icon="images/perimeter.png"
28
                    action-command="PERIMETER" tooltip="perimeter"
29
                    enable-text="deber?a de estar activada" last="true"/>
30
            </tool-bar>
31
        </extension>
32
        <extension class-name="org.gvsig.geometrymeasurement.app.extension.AddXYPointThemeExtension"
33
            description="Extension that add the coordinates x and y."
34
            active="true">
35
            <menu text="Vista/add_x_y" tooltip="add_x_y"
36
                action-command="ADDXYPOINT"
37
                icon="images/xypoint.png" />
38
            <tool-bar name="add_x_y">
39
                <action-tool icon="images/xypoint.png"
40
                    action-command="ADDXYPOINT" tooltip="add_x_y"
41
                    enable-text="deber?a de estar activada" last="true"/>
42
            </tool-bar>
43
        </extension>    	
44
	</extensions>
45
</plugin-config>
0 46

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.geometrymeasurement.app.extension</artifactId>
7
	<packaging>jar</packaging>
8
	<name>Tools: Geometry measurement</name>
9
    <description>Add 3 tools to gvSIG:
10
- Add a new attribute to the data source with the geometry area
11
- Add a new attribute to the data source with the geometry perimeter
12
- Add a new attribute to a Point type data source two new columns, one with the X Point value, and another with the Y Point value. 
13
    </description>
14
	<parent>
15
		<groupId>org.gvsig</groupId>
16
		<artifactId>org.gvsig.geometrymeasurement.app</artifactId>
17
		<version>1.0.0-SNAPSHOT</version>
18
	</parent>
19

  
20
	<dependencies>
21
		<dependency>
22
			<groupId>org.gvsig</groupId>
23
			<artifactId>org.gvsig.andami</artifactId>
24
            <scope>compile</scope>
25
		</dependency>
26
		<dependency>
27
           <groupId>org.gvsig</groupId>
28
            <artifactId>org.gvsig.app</artifactId>
29
            <version>2.0-SNAPSHOT</version>
30
            <scope>compile</scope>
31
        </dependency>
32
        <dependency>
33
            <groupId>org.gvsig</groupId>
34
            <artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId>
35
            <version>2.0.0-SNAPSHOT</version>
36
            <scope>compile</scope>
37
        </dependency>
38
		<dependency>
39
			<groupId>org.gvsig</groupId>
40
			<artifactId>org.gvsig.i18n</artifactId>
41
            <scope>compile</scope>
42
		</dependency>
43
		<dependency>
44
			<groupId>org.gvsig</groupId>
45
			<artifactId>org.gvsig.tools.lib</artifactId>
46
            <scope>compile</scope>
47
		</dependency>	
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
50
            <artifactId>org.gvsig.fmap.dal</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.gvsig</groupId>
55
            <artifactId>org.gvsig.fmap.mapcontext</artifactId>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.fmap.geometry</artifactId>
61
            <scope>compile</scope>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.gvsig</groupId>
65
            <artifactId>org.gvsig.fmap.control</artifactId>
66
            <scope>compile</scope>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
71
            <scope>compile</scope>
72
        </dependency>
73
        <dependency>
74
            <groupId>org.slf4j</groupId>
75
            <artifactId>slf4j-api</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
	</dependencies>
79
	<profiles>
80
		<profile>
81
			<id>gvsig-install</id>
82
			<activation>
83
				<activeByDefault>true</activeByDefault>
84
			</activation>
85
			<properties>
86
				<!--
87
					Default gvSIG installation folder relative to the current workspace
88
				-->
89
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
90
			</properties>
91
		</profile>
92
	</profiles>
93
    <properties>
94
        <package.info.dependencies>required: org.gvsig.app.document.table.app.mainplugin -ge 2</package.info.dependencies>
95
    </properties>    
96
</project>
0 97

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
    <files>
15
        <file>
16
            <source>package.info</source>
17
            <outputDirectory>${extension.install.dir.name}</outputDirectory>
18
        </file>
19
    </files>
20
	<dependencySets>
21
		<dependencySet>
22
			<outputDirectory>${extension.install.dir.name}/${library-dir}
23
			</outputDirectory>
24
			<includes>
25
				<include>org.gvsig:org.gvsig.geometrymeasurement.app.extension</include>
26
			</includes>
27
		</dependencySet>
28
	</dependencySets>
29
</assembly>
0 30

  

Also available in: Unified diff