Revision 4181

View differences:

org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/test/resources/README.txt
1
====
2
    gvSIG. Desktop Geographic Information System.
3

  
4
    Copyright (C) 2007-2012 gvSIG Association.
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
    For any additional information, do not hesitate to contact us
22
    at info AT gvsig.com, or visit our website www.gvsig.com.
23
====
24

  
25
Put into this folder the resources needed by your test classes.
26

  
27
This folder is added to the Tests classpath, so you can load any resources 
28
through the ClassLoader.
29

  
30
By default, in this folder you can find an example of log4j configuration,
31
prepared to log messages through the console, so logging works when you
32
run your tests classes.
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2012 gvSIG Association.
7

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

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

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

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

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<!-- 
30
Log4J configuration file for unit tests execution.
31
 -->
32
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
33

  
34
	<!-- Appender configuration to show logging messages through the console -->
35
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
36
		<layout class="org.apache.log4j.PatternLayout">
37
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
38
		</layout>
39
	</appender>
40

  
41
	<!-- 
42
	Activate logging messages of DEBUG level of higher only for the
43
	org.gvsig.tools packages.
44
	You can put full classes names or packages instead, to configure
45
	logging for all the classes and subpackages of the package.
46
	-->
47
	<category name="org.gvsig.tools">
48
		<priority value="DEBUG" />
49
	</category>
50
	<category name="org.gvsig.vectorediting">
51
		<priority value="DEBUG" />
52
	</category>
53

  
54
	<!-- 
55
	By default, show only logging messages of INFO level or higher, 
56
	through the previously configured CONSOLE appender. 
57
	-->
58
	<root>
59
		<priority value="INFO" />
60
		<appender-ref ref="CONSOLE" />
61
	</root>
62
</log4j:configuration>
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.vectorediting.lib.impl;
26

  
27
import org.gvsig.fmap.dal.DALLibrary;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30
import org.gvsig.vectorediting.lib.spi.EditingProviderLibrary;
31
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
32

  
33
public class DefaultEditingProviderLibrary extends AbstractLibrary {
34

  
35
    @Override
36
    public void doRegistration() {
37
        registerAsImplementationOf(EditingProviderLibrary.class);
38
        require(DALLibrary.class);
39
    }
40

  
41
    @Override
42
    protected void doInitialize() throws LibraryException {
43
        EditingProviderLocator
44
        .registerEditingProviderManager(DefaultEditingProviderManager.class);
45
    }
46

  
47
    @Override
48
    protected void doPostInitialize() throws LibraryException {
49

  
50
    }
51

  
52
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingService.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.vectorediting.lib.impl;
26

  
27
import java.util.List;
28
import org.gvsig.fmap.dal.feature.EditableFeature;
29
import org.gvsig.fmap.dal.feature.FeatureStore;
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.primitive.Point;
32
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
33
import org.gvsig.tools.dynobject.DynClass;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.observer.BaseNotification;
36
import org.gvsig.tools.observer.Notification;
37
import org.gvsig.tools.observer.ObservableHelper;
38
import org.gvsig.tools.observer.Observer;
39
import org.gvsig.tools.service.AbstractService;
40
import org.gvsig.tools.service.Manager;
41
import org.gvsig.tools.service.ServiceException;
42
import org.gvsig.tools.service.spi.AbstractProviderServices;
43
import org.gvsig.vectorediting.lib.api.DrawingStatus;
44
import org.gvsig.vectorediting.lib.api.EditingLocator;
45
import org.gvsig.vectorediting.lib.api.EditingService;
46
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
47
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException;
48
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
49
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
50
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException;
51
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException;
52
import org.gvsig.vectorediting.lib.spi.EditingProvider;
53
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
54
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
55
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
56
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
57

  
58
public class DefaultEditingService extends AbstractService implements EditingService {
59

  
60
    private final ObservableHelper observableHelper;
61
//    private final DynObject parameters;
62

  
63
//    public DefaultEditingService(EditingProvider provider, DynObject parameters) {
64
//        this.parameters = parameters;
65
//        this.provider = provider;
66
//        this.observableHelper = new ObservableHelper();
67
//    }
68

  
69
    DefaultEditingService(DynObject arg0, EditingProviderServices editingProviderServices) throws ServiceException {
70
        this.init(arg0, editingProviderServices);
71
        ((AbstractProviderServices)editingProviderServices).setService(this);
72
        this.observableHelper = new ObservableHelper();
73
    }
74

  
75
    @Override
76
    protected EditingProvider getProvider() {
77
        return (EditingProvider) super.getProvider();
78
    }
79

  
80
    @Override
81
    public Manager getManager() {
82
        return null;
83
    }
84

  
85
    @Override
86
    public DrawingStatus getDrawingStatus(Point mousePosition)
87
        throws DrawServiceException {
88
        return getProvider().getDrawingStatus(mousePosition);
89
    }
90

  
91
    @Override
92
    public List<EditingServiceParameter> getParameters() {
93
        return getProvider().getParameters();
94
    }
95

  
96
    @Override
97
    public EditingServiceParameter next() {
98
        EditingServiceParameter x = getProvider().next();
99
        this.updateObservers(NEXT_NOTIFICATION, x, null);
100
        return x;
101
    }
102

  
103
    @Override
104
    public void setValue(Object value) throws InvalidEntryException {
105
        getProvider().setValue(value);
106
        this.updateObservers(PARAMETER_CHANGED1_NOTIFICATION, value, null);
107
    }
108

  
109
    @Override
110
    public void stop() throws StopServiceException {
111
        getProvider().stop();
112
        this.updateObservers(STOP_NOTIFICATION, null, null);
113
    }
114

  
115
    @Override
116
    public void finishAndStore() throws FinishServiceException {
117
        getProvider().finishAndStore();
118
        this.updateObservers(FINISH_AND_STORE_NOTIFICATION, null, null);
119
    }
120

  
121
    @Override
122
    public Geometry finish() throws FinishServiceException {
123
        Geometry x = getProvider().finish();
124
        this.updateObservers(FINISH_NOTIFICATION, x, null);
125
        return x;
126
    }
127

  
128
    @Override
129
    public void start() throws StartServiceException, InvalidEntryException {
130
        this.getProvider().start();
131
        this.getProvider().initDefaultValues();
132
        this.updateObservers(START_NOTIFICATION, null, null);
133
    }
134

  
135
    @Override
136
    public String getName() {
137
        return getProvider().getName();
138
    }
139
    
140
    @Override
141
    public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException {
142
        getProvider().setValue(parameter, value);
143
        this.updateObservers(PARAMETER_CHANGED2_NOTIFICATION, parameter, value);
144
    }
145

  
146
    @Override
147
    public boolean isEnabled(EditingServiceParameter parameter) {
148
        return getProvider().isEnabled(parameter);
149
    }
150

  
151
    @Override
152
    public void activate() {
153
        getProvider().activate();
154
        this.updateObservers(ACTIVATE_NOTIFICATION, null, null);
155
    }
156

  
157
    @Override
158
    public Object getValue(EditingServiceParameter parameter) {
159
        return getProvider().getValue(parameter);
160
    }
161

  
162
    @Override
163
    public Object getValue(EditingServiceParameter parameter, EditingServiceParameter.TYPE type) {
164
        return getProvider().getValue(parameter, type);
165
    }
166

  
167
    @Override
168
    public void addObserver(Observer o) {
169
        this.observableHelper.addObserver(o);
170
    }
171
    @Override
172
    public void deleteObserver(Observer o) {
173
        this.observableHelper.deleteObserver(o);
174
    }
175

  
176
    @Override
177
    public void deleteObservers() {
178
        this.observableHelper.deleteObservers();
179
    }
180
    
181
    private void updateObservers(String type, Object v1, Object v2) {
182
        Notification notification =
183
            new BaseNotification(type,new Object[] {v1,v2});
184
        this.observableHelper.notifyObservers(this, notification);
185
    }
186

  
187
    @Override
188
    public void setDefaultFeatureValues(EditableFeature feature) {
189
        this.getProvider().setDefaultFeatureValues(feature);
190
    }
191

  
192
    @Override
193
    public EditableFeature getDefaultFeatureValues() {
194
        return this.getProvider().getDefaultFeatureValues();
195
    }
196
    
197
    @Override
198
    public FeatureStore getStore() {
199
        return (FeatureStore) this.getServiceParameters().getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD);
200
    }
201
    
202
    @Override
203
    public IVectorLegend getLegend() {
204
        return (IVectorLegend) this.getServiceParameters().getDynValue(EditingProviderFactory.LEGEND_FIELD);
205
    }
206
    
207
    @Override
208
    public String getDescription() {
209
        String name = this.getProvider().getName();
210
        try {
211
            DynObject params = EditingLocator.getManager().createServiceParameters(name);
212
            DynClass dynclass = params.getDynClass();
213
            return dynclass.getDescription();
214
        } catch (ServiceException ex) {
215
            return name;
216
        }
217
    }
218

  
219
    @Override
220
    protected EditingProviderManager getProviderManager() {
221
        return EditingProviderLocator.getProviderManager();
222
    }
223

  
224
    @Override
225
    public void setShowPreviewSymbol(boolean showPreviewSymbol) {
226
        getProvider().setShowPreviewSymbol(showPreviewSymbol);
227
    }
228
    
229
    @Override
230
    public void restart() throws StartServiceException, InvalidEntryException ,StopServiceException {
231
        this.getProvider().restart();
232
        this.updateObservers(RESTART_NOTIFICATION, null, null);
233
    }
234

  
235
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.vectorediting.lib.impl;
25

  
26
import org.gvsig.fmap.dal.DALLibrary;
27
import org.gvsig.fmap.geom.GeometryLibrary;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30
import org.gvsig.vectorediting.lib.api.EditingLibrary;
31
import org.gvsig.vectorediting.lib.api.EditingLocator;
32

  
33
/**
34
 * Library for default implementation initialization and configuration.
35
 *
36
 * @author gvSIG team
37
 * @version $Id$
38
 */
39
public class DefaultEditingLibrary extends AbstractLibrary {
40

  
41
    @Override
42
    public void doRegistration() {
43
        registerAsImplementationOf(EditingLibrary.class);
44
        require(DALLibrary.class);
45
        require(GeometryLibrary.class);
46
    }
47

  
48
    @Override
49
    protected void doInitialize() throws LibraryException {
50
        EditingLocator.registerManager(DefaultEditingManager.class);
51
    }
52

  
53
    @Override
54
    protected void doPostInitialize() throws LibraryException {
55
        // Do nothing
56
    }
57

  
58
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.vectorediting.lib.impl;
26

  
27
import java.net.URL;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.Iterator;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.Properties;
34
import java.util.function.Predicate;
35
import javax.json.JsonArray;
36
import javax.json.JsonObject;
37
import javax.json.JsonValue;
38
import org.apache.commons.lang3.StringUtils;
39
import org.gvsig.fmap.dal.feature.EditableFeature;
40
import org.gvsig.fmap.dal.feature.Feature;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureStore;
43
import org.gvsig.fmap.geom.DataTypes;
44
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.GeometryCoercionContext;
46
import org.gvsig.fmap.geom.GeometryLocator;
47
import org.gvsig.fmap.geom.GeometryUtils;
48
import org.gvsig.fmap.geom.type.GeometryType;
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50
import org.gvsig.json.Json;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.dataTypes.Coercion;
53
import org.gvsig.tools.dataTypes.DataTypeUtils;
54
import org.gvsig.tools.dynobject.DynObject;
55
import org.gvsig.tools.service.Service;
56
import org.gvsig.tools.service.ServiceException;
57
import org.gvsig.tools.service.spi.AbstractProviderManager;
58
import org.gvsig.tools.service.spi.Provider;
59
import org.gvsig.tools.service.spi.ProviderFactory;
60
import org.gvsig.tools.service.spi.ProviderServices;
61
import org.gvsig.tools.swing.api.ToolsSwingLocator;
62
import org.gvsig.tools.swing.api.ToolsSwingManager;
63
import org.gvsig.tools.swing.icontheme.IconTheme;
64
import org.gvsig.vectorediting.lib.api.EditingServiceInfo;
65
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException;
66
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
67
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
68
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
69
import org.slf4j.Logger;
70
import org.slf4j.LoggerFactory;
71

  
72
public class DefaultEditingProviderManager extends AbstractProviderManager
73
implements EditingProviderManager {
74

  
75
    private static final Logger logger = LoggerFactory
76
        .getLogger(DefaultEditingProviderManager.class);
77

  
78
    Map<String, ISymbol> symbols = new HashMap<>();
79

  
80
    Map<String, Map<String, String>> defaultValues = new HashMap<>();
81
    
82
    private String clipboardValue;
83
    private List<Geometry> geometriesFromClipboard;
84
    private List<EditableFeature> featuresFromClipboard;
85

  
86

  
87
    public ProviderServices createProviderServices(Service service) {
88
        // TODO Auto-generated method stub
89
        return null;
90
    }
91

  
92
    @Override
93
    protected String getRegistryKey() {
94
        // TODO Auto-generated method stub
95
        return null;
96
    }
97

  
98
    @Override
99
    protected String getRegistryDescription() {
100
        // TODO Auto-generated method stub
101
        return null;
102
    }
103

  
104
    @Override
105
    public Provider createProvider(DynObject serviceParameters,
106
        ProviderServices providerServices) throws ServiceException {
107
        String providerName =
108
            (String) serviceParameters
109
            .getDynValue(EditingProviderFactory.PROVIDER_NAME_FIELD);
110
        ProviderFactory factory = getProviderFactory(providerName);
111
        return factory == null ? null : factory.create(serviceParameters,
112
            providerServices);
113
    }
114

  
115
    public EditingServiceInfo getServiceInfo(String name)
116
        throws ServiceInformationException {
117
        EditingProviderFactory factory;
118
        try {
119
            factory = (EditingProviderFactory) getProviderFactory(name);
120
            return (factory == null ? null : factory.getServiceInfo());
121
        } catch (Exception e) {
122
            throw new ServiceInformationException("Can't get service info of "
123
                + name, e);
124
        }
125
    }
126

  
127
    public void registerIcon(String group, String name, ClassLoader loader,
128
        String provider) {
129
        String resourceName;
130
        IconTheme iconTheme =
131
            ToolsSwingLocator.getIconThemeManager().getCurrent();
132
        if ((group == null) || (group.trim().length() == 0)) {
133
            resourceName = "images/" + name + ".png";
134
        } else {
135
            resourceName = "images/" + group + "/" + name + ".png";
136
        }
137

  
138
        URL resource = null;
139
        try {
140
            resource = loader.getResource(resourceName);
141
            iconTheme.registerDefault(provider, group, name, null, resource);
142
        } catch (Throwable e) {
143
            logger.info("Can't register icon '" + name + "'.", e);
144
        }
145

  
146
    }
147

  
148

  
149
    public void registerSymbol(String name, ISymbol symbol) {
150
        symbols.put(name, symbol);
151
    }
152

  
153
    public ISymbol getSymbol(String name) {
154
        return symbols.get(name);
155
    }
156

  
157
    public void registerDefaultValues(String provider, Map values) {
158
        if (!this.defaultValues.containsKey(provider)) {
159
            this.defaultValues.put(provider, values);
160
        }
161
    }
162

  
163
    public void registerDefaultValues(String provider, ClassLoader loader) {
164
        if (!this.defaultValues.containsKey(provider)) {
165
            String resourceName =
166
                "defaultvalues/" + provider + "/defaultvalues.properties";
167
            HashMap<String, String> providerDefaultValues =
168
                new HashMap<String, String>();
169

  
170
            URL resource = null;
171
            try {
172
                resource = loader.getResource(resourceName);
173

  
174
                Properties properties = new Properties();
175
                properties.load(resource.openStream());
176

  
177
                for (Iterator it = properties.keySet().iterator(); it.hasNext();) {
178
                    String key = (String) it.next();
179
                    providerDefaultValues.put(key, (String) properties.get(key));
180
                }
181
                this.defaultValues.put(provider, providerDefaultValues);
182
            } catch (Throwable e) {
183
                logger.info("Can't register default values from '" + provider
184
                    + "'.", e);
185
            }
186
        }
187
    }
188

  
189
    @Override
190
    public Map<String, String> getDefaultValues(String name) {
191
        return this.defaultValues.get(name);
192
    }
193
    
194
    @Override
195
    public List<Geometry> getGeometriesFromClipboard(){
196
        ToolsSwingManager manager = ToolsSwingLocator.getToolsSwingManager();
197
        String clipboardValue = manager.getFromClipboard();
198
        
199
        if(StringUtils.isNotBlank(clipboardValue) 
200
                && StringUtils.isNotBlank(this.clipboardValue)
201
                && StringUtils.equals(clipboardValue, this.clipboardValue)){
202
            return this.geometriesFromClipboard;
203
        }
204
        
205
        this.geometriesFromClipboard = new ArrayList<>();
206
        
207
        String geometryName = null;
208
        try {
209
            JsonArray jsonArray = Json.createArray(clipboardValue);
210

  
211
            Coercion toGeometry = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.GEOMETRY);
212

  
213
            for (JsonValue item : jsonArray) {
214
                JsonObject jsonItem = (JsonObject) item;
215
                if (StringUtils.isBlank(geometryName)) {
216
                    for (Map.Entry<String, JsonValue> field : jsonItem.entrySet()) {
217
                        Geometry geometry;
218
                        try {
219
                            geometry = (Geometry) toGeometry.coerce(field.getValue().toString().replace("\"", ""));
220
                            if (geometry != null) {
221
                                geometryName = field.getKey();
222
                                this.geometriesFromClipboard.add(geometry);
223
                                break;
224
                            }
225
                        } catch (Exception e) {
226
                            //DO NOTHING
227
                        }
228
                    }
229
                } else {
230
                    Geometry geometry;
231
                    try {
232
                        String strGeom = jsonItem.getString(geometryName);
233
                        geometry = (Geometry) toGeometry.coerce(strGeom);
234
                        if (geometry != null) {
235
                            this.geometriesFromClipboard.add(geometry);
236
                        }
237
                    } catch (Exception e) {
238
                        //DO NOTHING
239
    //                        logger.warn("Can't coerce geometry", e);
240
                    }
241
                }
242
            }
243
        } catch (Exception ex) {
244
            //DO NOTHING
245
        }
246
        return this.geometriesFromClipboard;
247
    }
248

  
249

  
250
    @Override
251
    public List<EditableFeature> getFeaturesFromClipboard(EditingProviderServices providerServices, FeatureStore store) {
252
        ToolsSwingManager manager = ToolsSwingLocator.getToolsSwingManager();
253
        String clipboardValue = manager.getFromClipboard();
254
        
255
        if(StringUtils.isNotBlank(clipboardValue) 
256
                && StringUtils.isNotBlank(this.clipboardValue)
257
                && StringUtils.equals(clipboardValue, this.clipboardValue)){
258
            return this.featuresFromClipboard;
259
        }
260
        
261
        this.featuresFromClipboard = new ArrayList<>();
262

  
263
        GeometryType storeGeomType = store.getDefaultFeatureTypeQuietly().getDefaultGeometryAttribute().getGeomType();
264
        GeometryCoercionContext context = GeometryLocator.getGeometryManager().createGeometryCoercionContext();
265
        context.setGeometryType(storeGeomType);
266
        context.setMode(GeometryCoercionContext.MODE_ONERROR_NULL);
267
        Coercion toGeometry = DataTypeUtils.getCoercion(DataTypes.GEOMETRY);
268

  
269
        
270
        String geometryName = null;
271
        try {
272
            JsonArray jsonArray = Json.createArray(clipboardValue);
273

  
274
            for (JsonValue item : jsonArray) {
275
                JsonObject jsonItem = (JsonObject) item;
276
                EditableFeature feat = providerServices.createNewFeature(store);
277
                feat.setDefaultGeometry(null);
278
                feat.copyFrom(jsonItem, (FeatureAttributeDescriptor t) -> !(t.isPrimaryKey() || (t.isIndexed() && !t.allowIndexDuplicateds())));
279
                Geometry geometry = feat.getDefaultGeometry();
280
                if(geometry == null){
281
                    if (StringUtils.isBlank(geometryName)) {
282
                        for (Map.Entry<String, JsonValue> field : jsonItem.entrySet()) {
283
                            try {
284
                                geometry = (Geometry) toGeometry.coerce(field.getValue().toString().replace("\"", ""), context);
285
                                if (geometry != null) {
286
                                    geometryName = field.getKey();
287
                                    break;
288
                                }
289
                            } catch (Exception e) {
290
                                //DO NOTHING
291
                            }
292
                        }
293
                    } else {
294
                        try {
295
                            String strGeom = jsonItem.getString(geometryName);
296
                            geometry = (Geometry) toGeometry.coerce(strGeom, context);
297
                        } catch (Exception e) {
298
                            //DO NOTHING
299
                        }
300
                    }
301
                    
302
                } else {
303
                    geometry = (Geometry) toGeometry.coerce(geometry,context);
304
                }
305
                
306
                if (geometry != null) {
307
                    feat.setDefaultGeometry(geometry);
308
                    this.featuresFromClipboard.add(feat);
309
                }
310
            }
311
        } catch (Exception ex) {
312
            //DO NOTHING
313
        }
314
        return this.featuresFromClipboard;
315
    }
316
    
317
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ๏ฟฝ 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.vectorediting.lib.impl;
26

  
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.FeatureStore;
29
import org.gvsig.fmap.mapcontext.MapContext;
30
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
31
import org.gvsig.tools.dynobject.DynObject;
32
import org.gvsig.tools.service.AbstractManager;
33
import org.gvsig.tools.service.Service;
34
import org.gvsig.tools.service.ServiceException;
35
import org.gvsig.vectorediting.lib.api.EditingManager;
36
import org.gvsig.vectorediting.lib.api.EditingService;
37
import org.gvsig.vectorediting.lib.api.EditingServiceInfo;
38
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException;
39
import org.gvsig.vectorediting.lib.spi.EditingProvider;
40
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
41
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
42
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
public class DefaultEditingManager extends AbstractManager implements
47
EditingManager {
48

  
49
    private static final Logger logger = LoggerFactory
50
        .getLogger(DefaultEditingManager.class);
51
    
52
    public DefaultEditingManager() {
53
        super(new DefaultEditingProviderManager());
54
    }
55

  
56
    public Service getService(DynObject arg0) throws ServiceException {
57
        EditingProviderServices editingProviderServices = new DefaultEditingProviderServices();
58
        DefaultEditingService service = new DefaultEditingService(arg0, editingProviderServices);
59
        
60
//        DefaultEditingProviderServices editingProviderServices = new DefaultEditingProviderServices();
61
//        EditingProvider provider = (EditingProvider) EditingProviderLocator.getProviderManager()
62
//            .createProvider(arg0, editingProviderServices);
63
//        FeatureStore store = (FeatureStore) arg0.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD);
64
//        try {
65
//            editingProviderServices.setDefaultFeatureValues(store.createNewFeature());
66
//        } catch (DataException ex) {
67
//        }
68
//        DefaultEditingService service = new DefaultEditingService(provider, arg0);
69
//        editingProviderServices.setService(service);
70
        return service;
71
    }
72

  
73
    public EditingServiceInfo getServiceInfo(String serviceName)
74
        throws ServiceInformationException {
75
        return EditingProviderLocator.getProviderManager().getServiceInfo(
76
            serviceName);
77
    }
78

  
79
    @Override
80
    public EditingService getEditingService(String name,
81
        FeatureStore featureStore, MapContext mapContext, IVectorLegend legend) {
82
        try {
83
            DynObject params = this.createServiceParameters(name);
84
            params.setDynValue(EditingProviderFactory.FEATURE_STORE_FIELD,
85
                featureStore);
86
            params.setDynValue(EditingProviderFactory.MAPCONTEXT_FIELD, mapContext);
87
            if(legend != null && params.getDynClass().getDynField(EditingProviderFactory.LEGEND_FIELD)!=null){
88
                params.setDynValue(EditingProviderFactory.LEGEND_FIELD, legend);
89
            }
90
            return (EditingService) this.getService(params);
91
        } catch (ServiceException e) {
92
            String msg =
93
                String
94
                .format(
95
                    "Some problem getting %1$s editing service. Seems to name is not correct or there is not factory registered with that name. ",
96
                    name);
97
            logger.info(msg, e);
98
        }
99

  
100
        return null;
101
    }
102

  
103
    @Override
104
    public EditingService getEditingService(String name, FeatureStore featureStore, MapContext mapContext) {
105
        return getEditingService(name, featureStore, mapContext, null);
106
    }
107
    
108
    
109
    
110
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.252/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderServices.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ๏ฟฝ 2007-2014 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.vectorediting.lib.impl;
25

  
26
import java.util.Iterator;
27
import java.util.List;
28
import java.util.Map;
29
import java.util.Objects;
30
import org.gvsig.euclidean.EuclideanLine2D;
31
import org.gvsig.expressionevaluator.Expression;
32
import org.gvsig.expressionevaluator.ExpressionUtils;
33
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.EditingNotification;
37
import org.gvsig.fmap.dal.EditingNotificationManager;
38
import org.gvsig.fmap.dal.exception.DataException;
39
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
40
import org.gvsig.fmap.dal.feature.EditableFeature;
41
import org.gvsig.fmap.dal.feature.Feature;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
43
import org.gvsig.fmap.dal.feature.FeatureSet;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureType;
46
import org.gvsig.fmap.dal.swing.DALSwingLocator;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
49
import org.gvsig.fmap.geom.GeometryLocator;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.GeometryUtils;
52
import org.gvsig.fmap.geom.exception.CreateGeometryException;
53
import org.gvsig.fmap.geom.operation.GeometryOperationException;
54
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
55
import org.gvsig.fmap.geom.primitive.Arc;
56
import org.gvsig.fmap.geom.primitive.Circle;
57
import org.gvsig.fmap.geom.primitive.Ellipse;
58
import org.gvsig.fmap.geom.primitive.Line;
59
import org.gvsig.fmap.geom.primitive.Point;
60
import org.gvsig.fmap.geom.primitive.Spline;
61
import org.gvsig.fmap.geom.type.GeometryType;
62
import org.gvsig.fmap.mapcontext.MapContext;
63
import org.gvsig.fmap.mapcontext.layers.CancelationException;
64
import org.gvsig.fmap.mapcontext.layers.FLayer;
65
import org.gvsig.fmap.mapcontext.layers.SpatialCache;
66
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
67
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
68
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
69
import org.gvsig.tools.ToolsLocator;
70
import org.gvsig.tools.exception.BaseException;
71
import org.gvsig.tools.i18n.I18nManager;
72
import org.gvsig.tools.lang.CloneableUtils;
73
import org.gvsig.tools.service.spi.AbstractProviderServices;
74
import org.gvsig.tools.swing.api.TransparencySupport;
75
import org.gvsig.vectorediting.lib.api.EditingService;
76
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions;
77
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions.ParameterOption;
78
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus;
79
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
80
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
81
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
82
import org.slf4j.Logger;
83
import org.slf4j.LoggerFactory;
84

  
85
public class DefaultEditingProviderServices extends AbstractProviderServices
86
        implements EditingProviderServices {
87

  
88
    private static final Logger LOGGER = LoggerFactory
89
            .getLogger(DefaultEditingProviderServices.class);
90

  
91
    public DefaultEditingProviderServices() {
92
        super();
93
    }
94

  
95
    @Override
96
    public void insertFeatureIntoFeatureStore(Feature feature,
97
            FeatureStore featureStore) {
98
        EditableFeature eFeature = null;
99
        try {
100

  
101
            if (feature instanceof EditableFeature) {
102
                eFeature = (EditableFeature) feature;
103
            } else {
104
                eFeature = feature.getEditable();
105
            }
106

  
107
            EditingNotificationManager editingNotificationManager
108
                    = DALSwingLocator.getEditingNotificationManager();
109

  
110
            EditingNotification notification
111
                    = editingNotificationManager.notifyObservers(this, // source
112
                            EditingNotification.BEFORE_INSERT_FEATURE, // type
113
                            null,// document
114
                            null,// layer
115
                            featureStore,// store
116
                            eFeature// feature
117
                    );
118

  
119
            if (notification.isCanceled()) {
120
                String msg
121
                        = String
122
                                .format(
123
                                        "Can't insert feature into %1$s, canceled by some observer.",
124
                                        featureStore.getName());
125
                throw new CancelationException(msg, null);
126
            }
127

  
128
            if (notification.shouldValidateTheFeature()) {
129
                if (!editingNotificationManager.validateFeature(eFeature)) {
130
                    String msg
131
                            = String.format("%1$s is not valid", eFeature.toString());
132
                    throw new Exception(msg);
133
                }
134
            }
135

  
136
            featureStore.insert(eFeature);
137

  
138
            editingNotificationManager.notifyObservers(this,
139
                    EditingNotification.AFTER_INSERT_FEATURE, null, null,
140
                    featureStore, eFeature);
141

  
142
        } catch (Exception e) {
143
            String msg
144
                    = String.format("Can't insert %1$s into %2$s",
145
                            eFeature.toString(), featureStore.getName());
146
            LOGGER.info(msg, e);
147
        }
148
    }
149

  
150
    @Override
151
    public EditableFeature createNewFeature(FeatureStore store){
152
        try {
153
            EditableFeature f = store.createNewFeature();
154
            //FIXME: ?Deber?amos saltarnos la geometr?a?
155
            f.copyFrom(this.getDefaultFeatureValues(),(FeatureAttributeDescriptor t) -> !(t.isPrimaryKey() || (t.isIndexed() && !t.allowIndexDuplicateds())));
156
            return f;
157
        } catch (DataException ex) {
158
            throw new RuntimeException("Can't create feature", ex);
159
        }
160
    }
161

  
162
    @Override
163
    public void insertGeometryIntoFeatureStore(Geometry geometry,
164
            FeatureStore featureStore) {
165
        EditableFeature eFeature = null;
166

  
167
        try {
168
            eFeature = this.createNewFeature(featureStore);
169

  
170
            eFeature.setGeometry(featureStore.getDefaultFeatureType()
171
                    .getDefaultGeometryAttributeName(), geometry);
172

  
173
            EditingNotificationManager editingNotificationManager
174
                    = DALSwingLocator.getEditingNotificationManager();
175

  
176
            EditingNotification notification
177
                    = editingNotificationManager.notifyObservers(this, // source
178
                            EditingNotification.BEFORE_INSERT_FEATURE, // type
179
                            null,// document
180
                            null,// layer
181
                            featureStore,// store
182
                            eFeature// feature
183
                    );
184

  
185
            if (notification.isCanceled()) {
186
                String msg
187
                        = String
188
                                .format(
189
                                        "Can't insert geometry into %1$s, canceled by some observer.",
190
                                        featureStore.getName());
191
                throw new CancelationException(msg, null);
192
            }
193

  
194
            if (notification.shouldValidateTheFeature()) {
195
                if (!editingNotificationManager.validateFeature(eFeature)) {
196
                    String msg
197
                            = String.format("%1$s is not valid", eFeature.toString());
198
                    throw new Exception(msg);
199
                }
200
            }
201

  
202
            featureStore.insert(eFeature);
203

  
204
            editingNotificationManager.notifyObservers(this,
205
                    EditingNotification.AFTER_INSERT_FEATURE, null, null,
206
                    featureStore, eFeature);
207

  
208
        } catch (Exception e) {
209
            String msg
210
                    = String.format("Can't insert %1$s into %2$s",
211
                            Objects.toString(eFeature), featureStore.getName());
212
            LOGGER.info(msg, e);
213
        }
214
    }
215

  
216
    @Override
217
    public void deleteFeatureFromFeatureSet(Feature feature,
218
            FeatureStore featureStore, FeatureSet set) {
219

  
220
        try {
221
            EditingNotificationManager editingNotificationManager
222
                    = DALSwingLocator.getEditingNotificationManager();
223

  
224
            EditingNotification notification
225
                    = editingNotificationManager.notifyObservers(this, // source
226
                            EditingNotification.BEFORE_REMOVE_FEATURE, // type
227
                            null,// document
228
                            null,// layer
229
                            featureStore,// store
230
                            feature// feature
231
                    );
232

  
233
            if (notification.isCanceled()) {
234
                String msg
235
                        = String
236
                                .format(
237
                                        "Can't delete feature from %1$s, canceled by some observer.",
238
                                        featureStore.getName());
239
                throw new CancelationException(msg, null);
240
            }
241

  
242
            set.delete(feature);
243

  
244
            editingNotificationManager.notifyObservers(this,
245
                    EditingNotification.AFTER_REMOVE_FEATURE, null, null,
246
                    featureStore, feature);
247

  
248
        } catch (Exception e) {
249
            LOGGER.warn(e.getMessage(), e);
250
        }
251
    }
252

  
253
    @Override
254
    public void deleteFeatureFromFeatureStore(Feature feature,
255
            FeatureStore featureStore) {
256

  
257
        try {
258
            EditingNotificationManager editingNotificationManager
259
                    = DALSwingLocator.getEditingNotificationManager();
260

  
261
            EditingNotification notification
262
                    = editingNotificationManager.notifyObservers(this, // source
263
                            EditingNotification.BEFORE_REMOVE_FEATURE, // type
264
                            null,// document
265
                            null,// layer
266
                            featureStore,// store
267
                            feature// feature
268
                    );
269

  
270
            if (notification.isCanceled()) {
271
                String msg
272
                        = String
273
                                .format(
274
                                        "Can't delete feature from %1$s, canceled by some observer.",
275
                                        featureStore.getName());
276
                throw new CancelationException(msg, null);
277
            }
278

  
279
            featureStore.delete(feature);
280

  
281
            editingNotificationManager.notifyObservers(this,
282
                    EditingNotification.AFTER_REMOVE_FEATURE, null, null,
283
                    featureStore, feature);
284

  
285
        } catch (Exception e) {
286
            LOGGER.warn(e.getMessage(), e);
287
        }
288
    }
289

  
290
    @Override
291
    public void updateFeatureInFeatureStore(Feature feature,
292
            FeatureStore featureStore) {
293
        EditableFeature eFeature = null;
294

  
295
        try {
296

  
297
            if (feature instanceof EditableFeature) {
298
                eFeature = (EditableFeature) feature;
299
            } else {
300
                eFeature = feature.getEditable();
301
            }
302

  
303
            EditingNotificationManager editingNotificationManager
304
                    = DALSwingLocator.getEditingNotificationManager();
305

  
306
            EditingNotification notification
307
                    = editingNotificationManager.notifyObservers(this, // source
308
                            EditingNotification.BEFORE_UPDATE_FEATURE, // type
309
                            null,// document
310
                            null,// layer
311
                            featureStore,// store
312
                            eFeature// feature
313
                    );
314

  
315
            if (notification.isCanceled()) {
316
                String msg
317
                        = String
318
                                .format(
319
                                        "Can't update feature in %1$s, canceled by some observer.",
320
                                        featureStore.getName());
321
                throw new CancelationException(msg, null);
322
            }
323

  
324
            if (notification.shouldValidateTheFeature()) {
325
                if (!editingNotificationManager.validateFeature(eFeature)) {
326
                    String msg
327
                            = String.format("%1$s is not valid", eFeature.toString());
328
                    throw new Exception(msg);
329
                }
330
            }
331

  
332
            featureStore.update(eFeature);
333
            editingNotificationManager.notifyObservers(this,
334
                    EditingNotification.AFTER_UPDATE_FEATURE, null, null,
335
                    featureStore, eFeature);
336

  
337
        } catch (Exception e) {
338
            String msg
339
                    = String.format("Can't update %1$s in %2$s", eFeature.toString(),
340
                            featureStore.getName());
341
            LOGGER.info(msg, e);
342
        }
343
    }
344

  
345
    @Override
346
    public Circle createCircle(Point center, double radius, int subtype)
347
            throws CreateGeometryException {
348
        return GeometryUtils.createCircle(center, radius, subtype);
349
    }
350

  
351
    @Override
352
    public Circle createCircle(Point firstPoint, Point secondPoint,
353
            Point thridPoint, int subtype) throws CreateGeometryException {
354
        return GeometryUtils.createCircle(firstPoint, secondPoint, thridPoint, subtype);
355
    }
356

  
357
    @Override
358
    public Arc createArc(Point center, double radius, double startAngle,
359
            double angleExt, int subtype) throws CreateGeometryException {
360
        return GeometryUtils.createArc(center, radius, startAngle, angleExt, subtype);
361
    }
362

  
363
    @Override
364
    public Ellipse createFilledEllipse(Point firstPointAxisA,
365
            Point secondPointAxisA, double halfLengthAxisB, int subtype)
366
            throws CreateGeometryException {
367
        return GeometryUtils.createFilledEllipse(firstPointAxisA, secondPointAxisA, halfLengthAxisB, subtype);
368
    }
369

  
370
    @Override
371
    public Arc createArc(Point start, Point middle, Point end, int subtype)
372
            throws BaseException {
373
        return GeometryUtils.createArc(start, middle, end, subtype);
374
    }
375

  
376
    @Override
377
    public Point createPoint(double x, double y, int subtype)
378
            throws CreateGeometryException {
379
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
380
        return geomManager.createPoint(x, y, subtype);
381
    }
382

  
383
    @Override
384
    public Line createLine(double x1, double y1, double x2, double y2,
385
            int subtype) throws CreateGeometryException {
386
        return GeometryUtils.createLine(x1, y1, x2, y2, subtype);
387
    }
388

  
389
    @Override
390
    public int getSubType(FeatureStore featureStore) throws DataException {
391

  
392
        GeometryType geomType = getGeomType(featureStore);
393
        if (geomType != null) {
394
            return geomType.getSubType();
395
        }
396
        return SUBTYPES.UNKNOWN;
397
    }
398

  
399
    @Override
400
    public GeometryType getGeomType(FeatureStore featureStore)
401
            throws DataException {
402
        return featureStore.getDefaultFeatureType()
403
                .getDefaultGeometryAttribute().getGeomType();
404
    }
405

  
406
    @Override
407
    public EditableFeature getFeatureCopyWithoutUniqueIndex(FeatureStore featureStore,
408
            Feature feature) throws DataException {
409
        EditableFeature editableFeature
410
                = featureStore.createNewFeature(feature.getType(), true);
411
        editableFeature.copyFrom(this.getDefaultFeatureValues(), (FeatureAttributeDescriptor t) -> !(t.isPrimaryKey() || (t.isIndexed() && !t.allowIndexDuplicateds())));
412
        
413
        editableFeature.copyFrom(feature, (FeatureAttributeDescriptor t) -> !(t.isPrimaryKey() || (t.isIndexed() && !t.allowIndexDuplicateds())));
414
        return editableFeature;
415
    }
416

  
417
    @Override
418
    public Point getCenter(Point a, Point b, Point c, int subtype)
419
            throws CreateGeometryException {
420
        return GeometryUtils.getCenter(a, b, c, subtype);
421
    }
422

  
423
    @Override
424
    public Point getMidPoint(Point a, Point b, int subtype)
425
            throws CreateGeometryException {
426
        return GeometryUtils.getMidPoint(a, b, subtype);
427
    }
428

  
429
    @Override
430
    public Double[] getLineParams(Point point, Point nextPoint) {
431
        Double[] lineParams = new Double[2];
432
        double denom = nextPoint.getX() - point.getX();
433
        if (denom != 0) {
434
            lineParams[0] = (nextPoint.getY() - point.getY()) / denom;
435
            lineParams[1] = point.getY() - (lineParams[0] * point.getX());
436
        } else {
437
            if (nextPoint.getY() >= point.getY()) {
438
                lineParams[0] = Double.POSITIVE_INFINITY;
439
                lineParams[1] = Double.NEGATIVE_INFINITY;
440
                if (point.getX() == 0) {
441
                    lineParams[1] = 0.0;
442
                }
443
            } else {
444
                lineParams[0] = Double.NEGATIVE_INFINITY;
445
                lineParams[1] = Double.POSITIVE_INFINITY;
446
                if (point.getX() == 0) {
447
                    lineParams[1] = 0.0;
448
                }
449
            }
450
        }
451
        return lineParams;
452
    }
453

  
454
    @Override
455
    public Point[] getPerpendicular(Double m, Double b, Point point, int subtype)
456
            throws CreateGeometryException {
457
        // Pendiente de la recta perpendicular
458
        Double m1 = -1 / m;
459

  
460
        // b de la funcion de la recta perpendicular
461
        Double b1 = point.getY() - (m1 * point.getX());
462

  
463
        // Obtenemos un par de puntos
464
        Point[] res = new Point[2];
465

  
466
        if (Double.isInfinite(m1)) {
467
            if (m1 > 0) {
468
                //return the director vector of the line
469
                res[0] = createPoint(point.getX(), 0.0, subtype);
470
                res[1] = createPoint(point.getX(), 1.0, subtype);
471
            } else {
472
                res[0] = createPoint(point.getX(), 0.0, subtype);
473
                res[1] = createPoint(point.getX(), -1.0, subtype);
474
            }
475
        } else {
476
            //return the director vector of the line
477
            res[0] = createPoint(0.0, b1, subtype);
478
            Double mod = Math.sqrt(1 + Math.pow(m1, 2));
479
            Double x = 1 / mod;
480
            Double y = m1 * x + b1;
481
            res[1] = createPoint(x, y, subtype);
482
        }
483

  
484
        return res;
485
    }
486

  
487
    @Override
488
    public Point getIntersection(Point[] lineA, Point[] lineB, int subtype)
489
            throws CreateGeometryException {
490
        Point p1 = lineA[0];
491
        Point p2 = lineA[1];
492
        Point p3 = lineB[0];
493
        Point p4 = lineB[1];
494

  
495
        double m1 = Double.POSITIVE_INFINITY;
496

  
497
        if ((p2.getX() - p1.getX()) != 0) {
498
            m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX());
499
        }
500

  
501
        double m2 = Double.POSITIVE_INFINITY;
502

  
503
        if ((p4.getX() - p3.getX()) != 0) {
504
            m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX());
505
        }
506

  
507
        if ((m1 == Double.POSITIVE_INFINITY)
508
                && (m2 == Double.POSITIVE_INFINITY)) {
509
            return null;
510
        }
511

  
512
        double b1 = p2.getY() - (m1 * p2.getX());
513

  
514
        double b2 = p4.getY() - (m2 * p4.getX());
515

  
516
        if ((m1 != Double.POSITIVE_INFINITY)
517
                && (m2 != Double.POSITIVE_INFINITY)) {
518
            if (m1 == m2) {
519
                return null;
520
            }
521

  
522
            double x = (b2 - b1) / (m1 - m2);
523

  
524
            return createPoint(x, (m1 * x) + b1, subtype);
525
        } else if (m1 == Double.POSITIVE_INFINITY) {
526
            double x = p1.getX();
527

  
528
            return createPoint(x, (m2 * x) + b2, subtype);
529
        } else if (m2 == Double.POSITIVE_INFINITY) {
530
            double x = p3.getX();
531

  
532
            return createPoint(x, (m1 * x) + b1, subtype);
533
        }
534

  
535
        return null;
536
    }
537

  
538
    @Override
539
    public double getAngle(Point start, Point end)
540
            throws GeometryOperationNotSupportedException,
541
            GeometryOperationException {
542
        double angle
543
                = Math.acos((end.getX() - start.getX()) / start.distance(end));
544

  
545
        if (start.getY() > end.getY()) {
546
            angle = -angle;
547
        }
548

  
549
        if (angle < 0) {
550
            angle += (2 * Math.PI);
551
        }
552

  
553
        return angle;
554
    }
555

  
556
    @Override
557
    public double angleDistance(double angle1, double angle2) {
558
        double result = angle2 - angle1;
559
        if (result < 0) {
560
            result = (Math.PI * 2) + result;
561
        }
562
        return result;
563
    }
564

  
565
    @Override
566
    public Line createLine(Point p1, Point p2, int subtype)
567
            throws CreateGeometryException {
568
        return GeometryUtils.createLine(p1, p2, subtype);
569
    }
570

  
571
    @Override
572
    public Spline createSpline(List<Point> points, int subtype)
573
            throws CreateGeometryException {
574
        return GeometryUtils.createSpline(points, subtype);
575
    }
576

  
577
    @Override
578
    public String makeConsoleMessage(String preText, Map<String, String> options) {
579

  
580
        I18nManager i18nManager = ToolsLocator.getI18nManager();
581

  
582
        StringBuilder stb = new StringBuilder();
583

  
584
        if (preText != null) {
585
            stb.append(i18nManager.getTranslation(preText));
586
            stb.append(" ");
587
        }
588

  
589
        for (String option : options.keySet()) {
590
            stb.append("[");
591
            stb.append(option);
592
            stb.append("]");
593
            stb.append(i18nManager.getTranslation(options.get(option)));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff