Revision 38690

View differences:

tags/v2_0_0_Build_2050/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.8-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
		<mkdir dir="target" />
29

  
30
		<!-- Download the build jar file -->
31
		<get src="http://devel.gvsig.org/m2repo/j2se/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
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
		</copy>
41

  
42
	</target>
43
	
44
	<target name="find.depends.natives.file">
45
	    <condition property="depends.natives.file.exists">
46
            <available file="${org.gvsig.initial.build.basedir}/DEPENDS_ON_NATIVE_LIBRARIES"/>
47
	    </condition>	
48
	</target>
49
	
50
	<target name="find.gvsig.platform.properties.file" 
51
			depends="find.depends.natives.file"
52
			if="depends.natives.file.exists">
53
	    <condition property="gvsig.platform.exists">
54
            <available file="${user.home}/.gvsig.platform.properties"/>
55
	    </condition>	
56
	</target>
57
	
58
	<target name="check.gvsig.platform.properties" 
59
			depends="find.gvsig.platform.properties.file">
60
		<fail if="depends.natives.file.exists" unless="gvsig.platform.exists">
61
ERROR!!
62
	
63
You have to define your gvSIG platform properties, 
64
by creating the file: ${user.home}/.gvsig.platform.properties
65
with the following content:
66

  
67
native_platform=linux
68
native_distribution=all
69
native_compiler=gcc4
70
native_arch=i386
71
native_libraryType=dynamic
72
export native_classifier=${native_platform}-${native_distribution}-${native_compiler}-${native_arch}-${native_libraryType}
73

  
74
Replace the fifth initial variables values with the ones appropiate 
75
to your platform.
76
	
77
If you use maven in the command line, you can use the previous file also
78
to define the MAVEN_OPTS environment variable, by adding to your 
79
.bash_rc file something like this:
80

  
81
if [ -f "${HOME}/.gvsig.platform.properties" ]
82
then
83
    . ${HOME}/.gvsig.platform.properties
84
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m -Dnative-classifier=${native_classifier}"
85
else
86
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m"
87
fi
88

  
89
It will work if you use the bash shell. In any other case or platform, you'll
90
have to define your MAVEN_OPTS environment variable and set the 
91
"native-classifier" parameter directly.
92
		</fail>			
93
	
94
	</target>
95

  
96
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote,check.gvsig.platform.properties">
97

  
98
		<mkdir dir="target" />
99

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

  
102
		<!-- Copy the maven launchers to the workspace metadata folder -->
103
		<copy todir="${workspace.basedir}/.metadata">
104
			<fileset dir="${build.basedir}/eclipse-launchers">
105
				<exclude name="**/org.eclipse.jdt.core.prefs" />
106
				<exclude name="**/org.eclipse.core.variables.prefs" />
107
			</fileset>
108
		</copy>
109

  
110
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
111
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
112
		</concat>
113
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
114
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
115
		</concat>
116

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

  
120
		<!-- Configure the gvSIG profile -->
121
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" />
122

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

  
125
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
126
			<classpath>
127
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
128
			</classpath>
129
		</taskdef>
130

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

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

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

  
141
		<echo>INFORMATION!!!</echo>
142
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
143

  
144
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
145
	</target>
146

  
147
	<target name="clean">
148
		<delete dir="target" />
149
	</target>
150
	
151
</project>
0 152

  
tags/v2_0_0_Build_2050/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
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.maven.base.extension.pom</artifactId>
14
        <version>1.0.8-SNAPSHOT</version>
15
    </parent>
16
    <scm>
17
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app</connection>
18
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app</developerConnection>
19
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/extensions/org.gvsig.geometrymeasurement.app</url>
20
    </scm>
21

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

  
41
	<repositories>
42
		<repository>
43
			<id>gvsig-public-http-repository</id>
44
			<name>gvSIG maven public HTTP repository</name>
45
            <url>http://devel.gvsig.org/m2repo/j2se</url>
46
			<releases>
47
				<enabled>true</enabled>
48
				<updatePolicy>daily</updatePolicy>
49
				<checksumPolicy>warn</checksumPolicy>
50
			</releases>
51
			<snapshots>
52
				<enabled>true</enabled>
53
				<updatePolicy>daily</updatePolicy>
54
				<checksumPolicy>warn</checksumPolicy>
55
			</snapshots>
56
		</repository>
57
	</repositories>
58
    <dependencyManagement>
59
        <dependencies>          
60
            <dependency>
61
                <groupId>org.gvsig</groupId>
62
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
63
                <version>2.0.1-SNAPSHOT</version>
64
                <type>pom</type>
65
                <scope>import</scope>
66
            </dependency>
67
        </dependencies>
68
    </dependencyManagement>
69
	<modules>
70
		<module>org.gvsig.geometrymeasurement.app.extension</module>
71
	</modules>
72
	<properties>
73
		<package.info.state>devel</package.info.state>
74
		<!-- alpha-devel -->
75
	</properties>
76
</project>
0 77

  
tags/v2_0_0_Build_2050/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_2050/extensions/org.gvsig.geometrymeasurement.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
tags/v2_0_0_Build_2050/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 09 12:38:20 CEST 2012
3
buildNumber=2057
tags/v2_0_0_Build_2050/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_2050/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_2050/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.andami.IconThemeHelper;
25
import org.gvsig.app.project.documents.table.TableDocument;
26
import org.gvsig.fmap.dal.feature.FeatureStore;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
29

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

  
39
    public void initialize() {
40
    super.initialize();
41
        IconThemeHelper.registerIcon("action", "table-add-area", this);
42
    }
43

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

  
51
    @Override
52
    protected boolean isVisibleForTable(TableDocument tableDocument) {
53
        return isStoreOfAnyType(tableDocument, new int[] { Geometry.TYPES.SURFACE,
54
            Geometry.TYPES.MULTISURFACE });
55
    }
56
}
0 57

  
tags/v2_0_0_Build_2050/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.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.app.project.documents.table.TableDocument;
27
import org.gvsig.fmap.dal.feature.FeatureStore;
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
30

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

  
40
    public void initialize() {
41
    	super.initialize();
42
        IconThemeHelper.registerIcon("action", "table-add-perimeter", this);
43
    }
44

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

  
52
    @Override
53
    protected boolean isVisibleForTable(TableDocument tableDocument) {
54
        return !isStoreOfAnyType(tableDocument, new int[] { Geometry.TYPES.POINT,
55
            Geometry.TYPES.MULTIPOINT});
56
    }
57

  
58
}
0 59

  
tags/v2_0_0_Build_2050/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_2050/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 java.awt.Component;
25
import java.util.Locale;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.app.ApplicationLocator;
37
import org.gvsig.app.project.documents.table.TableDocument;
38
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.dal.exception.ReadException;
41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.feature.FeatureType;
43
import org.gvsig.fmap.geom.type.GeometryType;
44
import org.gvsig.i18n.Messages;
45

  
46
/**
47
 * Abstract class for Geometry measurement operations extensions.
48
 * 
49
 * @author gvSIG Team
50
 * @version $Id$
51
 */
52
public abstract class AbstractGeometryMeasurementExtension extends Extension {
53

  
54
    private static final Logger LOG = LoggerFactory
55
        .getLogger(AbstractGeometryMeasurementExtension.class);
56
    
57
    //Just to know if the resources has been initialized
58
    private static boolean isInitialized = false;
59
       
60
    public void initialize() {
61
        if (!isInitialized){
62
            //Register the strings
63
            if (!Messages.hasLocales()) {
64
                Messages.addLocale(Locale.getDefault());
65
            }
66
            
67
            Messages.addResourceFamily(
68
                    "org.gvsig.geometrymeasurement.app.extension.i18n.text",
69
                    AbstractGeometryMeasurementExtension.class.getClassLoader(),
70
                    AbstractGeometryMeasurementExtension.class.getClass().getName());
71
            
72
            //Register the icons
73
            
74
            isInitialized = true;
75
        }        
76
    }
77

  
78
    public boolean isEnabled() {
79
        TableDocument tableDocument;
80
        String name = "unknow";
81
        try {
82
            tableDocument = getActiveTableDocument();
83
            if (tableDocument != null) {
84
                name = tableDocument.getName();
85
            	return (tableDocument != null && tableDocument.getStore().allowWrite());
86
            }
87
        } catch (Throwable e) {
88
            LOG.info("Error accesing to the table document ("+name+")", e);
89
        }
90
        return false;
91
    }
92

  
93
    public final boolean isVisible() {
94
        TableDocument tableDocument;
95
        String name = "unknow";
96
        try {
97
            tableDocument = getActiveTableDocument();
98
            if (tableDocument != null) {
99
                name = tableDocument.getName();
100
                return isVisibleForTable(tableDocument);
101
            }
102
        } catch (Throwable e) {
103
            LOG.info("Error accesing to the table document ("+name+")", e);
104
        }       
105
        return false;
106
    }
107

  
108
    /**
109
     * Returns if the current extension is visible for the provided 
110
     * table.
111
     * 
112
     * The provided table will be always non null.
113
     * 
114
     * @param layer
115
     *            the active table
116
     * @return if the extension is visible
117
     */
118
    protected abstract boolean isVisibleForTable(TableDocument tableDocument);
119

  
120
    /**
121
     * Returns the active table document. If the active document is not a table,
122
     * or if the table has not a geometry, return null.
123
     * 
124
     * @return the active table document
125
     * @throws DataException 
126
     */
127
    protected TableDocument getActiveTableDocument() throws DataException {
128
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
129

  
130
        if (window instanceof FeatureTableDocumentPanel) {
131
            FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) window;
132
            TableDocument tableDocument = (TableDocument)table.getDocument();
133
            if (tableDocument.getStore().getDefaultFeatureType().getDefaultGeometryAttribute() != null){
134
                return tableDocument;
135
            }
136
           
137
        }
138
        return null;
139
    }
140

  
141
    protected boolean isStoreOfAnyType(TableDocument tableDocument, int[] geomTypes) {
142
        try {
143
            FeatureType featureType = tableDocument.getStore().getDefaultFeatureType();
144
            GeometryType geometryType = featureType.getDefaultGeometryAttribute().getGeomType();
145
            for (int i = 0; i < geomTypes.length; i++) {
146
                if (geometryType.isTypeOf(geomTypes[i])) {
147
                    return true;
148
                }
149
            }
150
        } catch (ReadException e) {
151
            LOG.error("Error reading the geometry type", e);
152
        } catch (DataException e) {
153
            LOG.error("Error reading the geometry type", e);
154
        }
155
        return false;
156
    }
157

  
158
    public void execute(String actionCommand) {
159
        try {
160
            TableDocument tableDocument = getActiveTableDocument();
161
            if (tableDocument == null) {
162
                return;
163
            }
164
            Component parentWindow = 
165
                (Component)ApplicationLocator.getManager().getUIManager().getActiveWindow();
166
            int addField = JOptionPane.showConfirmDialog(parentWindow, Messages.getText("new_field_query"),
167
                Messages.getText("info"), JOptionPane.YES_NO_OPTION);
168
            
169
            if (addField == JOptionPane.YES_OPTION){
170
                FeatureStore featureStore = tableDocument.getStore();
171
                execute(actionCommand, featureStore);
172
            }
173
        } catch (Exception e) {
174
            LOG.error("Not possible to add the new field", e);
175
            NotificationManager.addError(e);
176
        }
177
    }
178

  
179
    /**
180
     * Executes a command for the given {@link FeatureStore}.
181
     * 
182
     * @param actionCommand
183
     *            to execute
184
     * @param featureStore
185
     *            to use
186
     * @throws Exception
187
     *             if there is an error while executing
188
     */
189
    protected abstract void execute(String actionCommand,
190
        FeatureStore featureStore) throws Exception;
191

  
192
}
tags/v2_0_0_Build_2050/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.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.app.project.documents.table.TableDocument;
27
import org.gvsig.fmap.dal.feature.FeatureStore;
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.geometrymeasurement.app.extension.utils.Operations;
30

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

  
40
    public void initialize() {
41
        super.initialize();
42
        IconThemeHelper.registerIcon("action", "table-add-xy", this);
43
    }
44

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

  
51
    @Override
52
    protected boolean isVisibleForTable(TableDocument tableDocument) {
53
        return isStoreOfAnyType(tableDocument, new int[] { Geometry.TYPES.POINT });
54
    }
55
}
0 56

  
tags/v2_0_0_Build_2050/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="Table/Add/area" tooltip="area"
12
                action-command="AREA"
13
                position="500800100"
14
                icon="add-area" />
15
            <tool-bar name="area">
16
                <action-tool icon="add-area"
17
                    action-command="AREA" tooltip="area" position="500800100"
18
                    enable-text="deber?a de estar activada" last="true"/>
19
            </tool-bar>
20
		</extension>	
21
		
22
		<extension class-name="org.gvsig.geometrymeasurement.app.extension.PerimeterMeasurementExtension"
23
           description="Extension that measures the perimeter of all the lines they selected."
24
            active="true">
25
            <menu text="Table/Add/perimeter" tooltip="perimeter"
26
                action-command="PERIMETER"
27
                position="500800200"
28
                icon="add-perimeter" />
29
            <tool-bar name="perimeter">
30
                <action-tool icon="add-perimeter"
31
                    action-command="PERIMETER" tooltip="perimeter" position="500800200"
32
                    enable-text="deber?a de estar activada" last="true"/>
33
            </tool-bar>
34
        </extension>
35
        
36
        <extension class-name="org.gvsig.geometrymeasurement.app.extension.AddXYPointThemeExtension"
37
            description="Extension that add the coordinates x and y."
38
            active="true">
39
            <menu text="Tabla/add_x_y" tooltip="add_x_y"
40
                action-command="ADDXYPOINT"
41
                icon="add-xy-point" />
42
            <tool-bar name="add_x_y">
43
                <action-tool icon="add-xy-point"
44
                    action-command="ADDXYPOINT" tooltip="add_x_y"
45
                    enable-text="deber?a de estar activada" last="true"/>
46
            </tool-bar>
47
        </extension>    	
48
	</extensions>
49
</plugin-config>
0 50

  
tags/v2_0_0_Build_2050/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_2050/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/org/gvsig/geometrymeasurement/app/extension/i18n/text.properties
1
new_field_query=Se van a a?adir nuevos campo en la tabla.\nDesea continuar?
2
perimeter=Per?metro
3
add_x_y=A?adir X e Y
0 4

  
tags/v2_0_0_Build_2050/extensions/org.gvsig.geometrymeasurement.app/org.gvsig.geometrymeasurement.app.extension/src/main/resources/org/gvsig/geometrymeasurement/app/extension/i18n/text_en.properties
1
new_field_query=New fields are going to be added to the table.\nDo you want to continue?
2
perimeter=Perimeter
3
add_x_y=Add X and Y
0 4

  
tags/v2_0_0_Build_2050/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
        <package.info.categories>View,Vector</package.info.categories>
96
    </properties>    
97
</project>
0 98

  
tags/v2_0_0_Build_2050/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

  
tags/v2_0_0_Build_2050/extensions/org.gvsig.geometrymeasurement.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Aug 09 12:38:19 CEST 2012
3
buildNumber=2065
0 4

  

Also available in: Unified diff