Revision 1309

View differences:

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

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

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

  
39

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

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

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

  
78
	<dependencies>
79
	  <dependency>
80
	    <groupId>org.gvsig</groupId>
81
	    <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
82
	  </dependency>
83
	</dependencies>
84
</project>
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.mapcontrol/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.attributeeditor</artifactId>
6
        <version>1.0.252</version>
7
    </parent>
8
    <groupId>org.gvsig</groupId>
9
    <artifactId>org.gvsig.attributeeditor.mapcontrol</artifactId>
10
    <version>1.0.252</version>
11
    <name>org.gvsig.atributeeditor.mapcontrol</name>
12
    <dependencies>
13
        <dependency>
14
            <groupId>org.gvsig</groupId>
15
            <artifactId>org.gvsig.fmap.control</artifactId>
16
            <scope>compile</scope>
17
        </dependency>
18

  
19
        <dependency>
20
            <groupId>org.gvsig</groupId>
21
            <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
22
            <scope>compile</scope>
23
        </dependency>
24
        <dependency>
25
            <groupId>org.gvsig</groupId>
26
            <artifactId>org.gvsig.tools.lib</artifactId>
27
            <scope>compile</scope>
28
        </dependency>
29
    </dependencies>
30
</project>
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.mapcontrol/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/AttributeEditorBehavior.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontrol.tools.Listeners;
24

  
25
import java.awt.Image;
26

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

  
33

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

  
40
    AttributeEditorPointListener attributeEditorPointListener;
41

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

  
50
//        this.addMapBehavior(new PointBehavior(attributeEditorPointListener), true);
51
        this.addMapBehavior(new RectangleBehavior(attributeEditorPointListener), true);
52

  
53
    }
54

  
55
    @Override
56
    public Image getImageCursor() {
57
        return this.attributeEditorPointListener.getImageCursor();
58
    }
59

  
60
    @Override
61
    public AttributeEditorPointListener getListener(){
62
        return this.attributeEditorPointListener;
63
    }
64

  
65
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.mapcontrol/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/AttributeEditorPointListener.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright © 2007-2014 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

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

  
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ComponentAdapter;
28
import java.awt.event.ComponentEvent;
29
import java.awt.event.InputEvent;
30
import java.awt.event.MouseEvent;
31
import java.util.List;
32
import java.util.function.Predicate;
33
import javax.swing.Action;
34

  
35
import javax.swing.JOptionPane;
36
import javax.swing.SwingUtilities;
37
import org.apache.commons.lang3.StringUtils;
38

  
39
import org.cresques.cts.IProjection;
40
import org.gvsig.expressionevaluator.Expression;
41
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
42
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
import org.gvsig.featureform.swing.CreateJFeatureFormException;
47
import org.gvsig.featureform.swing.JFeaturesForm;
48
import org.gvsig.fmap.dal.DataStoreProviderFactory;
49
import org.gvsig.fmap.dal.exception.DataException;
50
import org.gvsig.fmap.dal.feature.FacadeOfAFeature;
51
import org.gvsig.fmap.dal.feature.Feature;
52
import org.gvsig.fmap.dal.feature.FeatureQuery;
53
import org.gvsig.fmap.dal.feature.FeatureSelection;
54
import org.gvsig.fmap.dal.feature.FeatureSet;
55
import org.gvsig.fmap.dal.feature.FeatureStore;
56
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
57
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
58
import org.gvsig.fmap.dal.feature.FeatureType;
59
import org.gvsig.fmap.dal.swing.DALSwingLocator;
60
import org.gvsig.fmap.dal.swing.DataSwingManager;
61
import org.gvsig.fmap.geom.Geometry;
62
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
63
import org.gvsig.fmap.geom.Geometry.TYPES;
64
import org.gvsig.fmap.geom.GeometryLocator;
65
import org.gvsig.fmap.geom.GeometryManager;
66
import org.gvsig.fmap.geom.exception.CreateGeometryException;
67
import org.gvsig.fmap.geom.primitive.Circle;
68
import org.gvsig.fmap.geom.primitive.Point;
69
import org.gvsig.fmap.mapcontext.ViewPort;
70
import org.gvsig.fmap.mapcontext.layers.FLayer;
71
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
72
import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory;
73
import org.gvsig.fmap.mapcontrol.MapControl;
74
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
75
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent;
76
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
77
import org.gvsig.tools.ToolsLocator;
78
import org.gvsig.tools.dispose.DisposeUtils;
79
import org.gvsig.tools.evaluator.Evaluator;
80
import org.gvsig.tools.i18n.I18nManager;
81
import org.gvsig.tools.identitymanagement.IdentityUtils;
82
import org.gvsig.tools.observer.Observable;
83
import org.gvsig.tools.observer.Observer;
84
import org.gvsig.tools.service.ServiceException;
85
import org.gvsig.tools.swing.api.ToolsSwingLocator;
86
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
87

  
88
/**
89
 * @author gvSIG Team
90
 *
91
 */
92
@SuppressWarnings("UseSpecificCatch")
93
public class AttributeEditorPointListener 
94
        extends AbstractToolListener  
95
        implements RectangleListener
96
    {
97

  
98
    private static Logger LOGGER = LoggerFactory.getLogger(AttributeEditorPointListener.class);
99

  
100
    public static final String ATTRIBUTE_EDITOR_TOOL_NAME = "attributeEditorTool";
101
    private static final String ATTRIBUTE_EDITOR_FORM_NAME = "attributeEditorForm";
102
    
103
    private final MapControl mapControl;
104
    private JFeaturesForm form;
105
    private Predicate<FeatureStore> refreshCallback;
106
    private Observer refreshFormObserver;
107

  
108
    public AttributeEditorPointListener(MapControl mapControl, JFeaturesForm form) {
109
        super();
110
        this.mapControl = mapControl;
111
        this.form = form;
112
        this.refreshFormObserver = (Observable o, Object o1) -> {
113
            doRefreshFormObserver(o, o1);
114
        };
115
    }
116

  
117
    public AttributeEditorPointListener(MapControl mapControl) {
118
        super();
119
        this.mapControl = mapControl;
120
        this.refreshFormObserver = (Observable o, Object o1) -> {
121
            doRefreshFormObserver(o, o1);
122
        };
123
        
124
    }
125

  
126
    private FLyrVect getLayer() {
127
        FLayer[] layers = mapControl.getMapContext().getLayers().getActives();
128
        if (layers == null || layers.length != 1) {
129
            return null;
130
        }
131
        return (FLyrVect) layers[0];
132

  
133
    }
134

  
135
//    @Override
136
//    public void point(PointEvent e) throws BehaviorException {
137
//        MouseEvent mouseEvent = e.getEvent();
138
//        if (((mouseEvent.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
139
//            | InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.META_DOWN_MASK)) != 0)
140
//            || !SwingUtilities.isLeftMouseButton(mouseEvent)) {
141
//            return;
142
//        }
143
//        String layerName = "";
144
//        I18nManager i18nManager = ToolsLocator.getI18nManager();
145
//        try {
146
//            FLyrVect layer = getLayer();
147
//            if (layer == null) {
148
//                String msg = i18nManager.getTranslation("There_is_no_one_and_only_one_active_layer");
149
//                ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
150
//                    i18nManager.getTranslation("attribute_editor"), JOptionPane.INFORMATION_MESSAGE);
151
//                return;
152
//            }
153
//            layerName = layer.getName();
154
//            ViewPort vp = this.mapControl.getViewPort();
155
//            Point point = vp.convertToMapPoint(e.getPoint());
156
//            double tolerance = vp.toMapDistance(layer.getDefaultTolerance());
157
//            FeatureQuery query = queryByPoint(point, tolerance);
158
//            showOrUpdateForm(layer, query);
159
//        } catch (Exception ex) {
160
//            LOGGER.warn("Can't show attribute information from point on the layer " + layerName, ex);
161
//            String msg =
162
//                i18nManager.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
163
//                    new String[] { layerName });
164
//            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
165
//                i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
166
//        }
167
//    }
168
    
169
    public void showOrUpdateForm() {
170
        String layerName = "";
171
        I18nManager i18nManager = ToolsLocator.getI18nManager();
172
        try {
173
            FLyrVect layer = getLayer();
174
            if (layer == null) {
175
                return;
176
            }
177
            layerName = layer.getName();
178
            FeatureQuery query;
179
            FeatureStore store = layer.getFeatureStore();
180
            if(store.isFeatureSelectionEmpty()){
181
                return;
182
            }
183
            FeatureSelection selection = store.getFeatureSelectionQuietly();
184
            Expression filter = selection.makeFilter(100);
185
            
186
            if(filter == null){
187
                String msg =
188
                    i18nManager.getTranslation("_Unable_to_get_filter_for_XlayernameX_layer_selection",
189
                        new String[] { layerName });
190
                ToolsSwingLocator.getThreadSafeDialogsManager().message(msg, JOptionPane.WARNING_MESSAGE);
191
                return;
192
            }
193
            if(selection.size()>100){
194
                String msg =
195
                    i18nManager.getTranslation("_Too_many_items_selected_Only_the_first_100_will_be_displayed",
196
                        new String[] { layerName });
197
                ToolsSwingLocator.getThreadSafeDialogsManager().message(msg, JOptionPane.WARNING_MESSAGE);
198

  
199
            }
200
            query = store.createFeatureQuery(filter);
201
            
202
            showOrUpdateForm(layer, query);
203
        } catch (Exception ex) {
204
            LOGGER.warn("Can't show attribute information from selection on the layer " + layerName, ex);
205
            String msg =
206
                i18nManager.getTranslation("_Cant_show_attribute_information_for_layer_XlayernameX_on_selection",
207
                    new String[] { layerName });
208
            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
209
                i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
210
        }
211
        
212
    }
213
    
214
    private void showOrUpdateForm(FLyrVect layer, FeatureQuery query) {
215
        if( layer == null || query==null ) {
216
            return;
217
        }
218
        String layerName = layer.getName();
219
        if( layerName == null ) {
220
            layerName = "";
221
        }
222
        showOrUpdateForm(layerName, layer.getFeatureStore(), query);
223
    }
224
    
225
    public void showOrUpdateForm(String storeName, FeatureStore featureStore, FeatureQuery query) {
226
        if( featureStore == null || query==null ) {
227
            return;
228
        }
229
        if( !IdentityUtils.isAuthorized(
230
                "attribute-editor", featureStore, featureStore.getFullName()) ) {
231
            return;
232
        }        
233
        I18nManager i18n = ToolsLocator.getI18nManager();
234
        try {
235
            synchronized (featureStore) {
236
            boolean needshow = true;
237
            if( StringUtils.isBlank(storeName) ) {
238
                storeName = featureStore.getLabel();
239
            }
240
            if (this.form == null) {
241
                this.form = getForm(featureStore, query);
242
                needshow = true;
243
//                this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
244
            } else if( this.form.getFeatureStore()!=featureStore ) {
245
//            } else if( !featureStore.getParameters().isTheSameStore(this.form.getFeatureStore().getParameters())) {
246
//                Dimension size = this.form.asJComponent().getPreferredSize();
247
                disposeForm();
248
                this.form = getForm(featureStore, query);
249
//                this.form.asJComponent().setPreferredSize(size);
250
//                this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
251
                needshow = true;
252
            } else {
253
                this.form.setQuery(query);
254
                needshow = false;
255
            }
256
            List<Feature> values = this.form.getFormset().getValues();
257
            FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
258
            selection.deselectAll();
259
            FeatureSelection selectionTmp = featureStore.createFeatureSelection();
260
            for (Feature fof : values) {
261
               selectionTmp.select(fof);
262
            }
263
            selection.select(selectionTmp);
264
//            try {
265
//                synchronized (featureStore) {
266
//                    FeatureSet featSet = featureStore.getFeatureSet(query);
267
//                    if( featSet.isEmpty() ) {
268
//                        return;
269
//                    }
270
//                    FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
271
//                    selection.deselectAll();
272
//                    selection.select(featSet);
273
//                }
274
//            } catch (DataException ex) {
275
//                LOGGER.warn("Can't query layer " + storeName+", query: "+query, ex);
276
//                return;
277
//            }
278
            if( needshow ) {
279
                this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
280
            }
281
            }
282
        } catch (Exception ex) {
283
            LOGGER.warn("Can't show attribute information from point on the layer " + storeName, ex);
284
            String msg =
285
                i18n.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
286
                    new String[] { storeName });
287
            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
288
                i18n.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
289
            disposeForm();
290
        }
291
    }
292
    
293
    private void disposeForm() {
294
        if( this.form != null ) {
295
            FeatureStore store = this.form.getFeatureStore();
296
            if( store!=null ) {
297
                store.deleteObserver(this.refreshFormObserver);
298
            }
299
        }
300
        DisposeUtils.disposeQuietly(this.form);
301
        this.form = null;
302
    }
303
    
304
    public void setRefreshCallback(Predicate<FeatureStore> refreshCallback) {
305
        this.refreshCallback = refreshCallback;
306
    }
307

  
308
    private JFeaturesForm getForm(FeatureStore store, FeatureQuery query) throws CreateJFeatureFormException, ServiceException, DataException {
309
        if (this.form == null) {
310
            DataSwingManager swingManager = DALSwingLocator.getSwingManager();
311
            JFeaturesForm theForm = swingManager.createJFeaturesForm(store, query);
312
            this.form = theForm;
313
            this.form.setTerminateEditingOnClose(false);
314
            this.form.asJComponent().setName(ATTRIBUTE_EDITOR_FORM_NAME);
315
            this.form.asJComponent().addComponentListener(new ComponentAdapter() {
316
                @Override
317
                public void componentHidden(ComponentEvent e) {
318
                    DisposeUtils.disposeQuietly(theForm);
319
                }
320
            });
321
            this.form.addActionListener((ActionEvent e) -> {
322
                switch (e.getActionCommand()) {
323
                    case "formAfterSave":
324
                    case "formAfterDelete":
325
                        if( this.refreshCallback!=null ) {
326
                            this.refreshCallback.test(store);
327
                        }
328
                        break;
329
                }
330
            });
331
            store.addObserver(this.refreshFormObserver);
332
        }
333
        return this.form;
334
    }
335
    
336
    private void doRefreshFormObserver(Observable o, Object o1) {
337
        if( this.form == null || 
338
                !(o instanceof FeatureStore && o1 instanceof FeatureStoreNotification ) ) {
339
            return;
340
        }
341
        try {
342
            FeatureStoreNotification n = (FeatureStoreNotification) o1;
343
            if( n.getType().equalsIgnoreCase(FeatureStoreNotification.AFTER_REFRESH) ) {
344
                Action refreshAction = this.form.getFormset().getAction(JFeaturesForm.REFRESHFORM_ACTION);
345
                if( refreshAction!=null ) {
346
                    refreshAction.actionPerformed(null);
347
                }
348
            }
349
        } catch(Exception ex) {
350
            LOGGER.warn("Can't refresh attribute editor",ex);
351
        }
352
    }
353

  
354
    private FeatureQuery queryByPoint(Point point, double tol) throws CreateGeometryException, DataException {
355
        GeometryManager manager = GeometryLocator.getGeometryManager();
356
        Circle circle = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
357
        circle.setPoints(point, tol);
358
        
359
        FLyrVect currentLayer = this.getLayer();
360
        if( currentLayer==null ) {
361
            return null;
362
        }
363
        FeatureStore featureStore = currentLayer.getFeatureStore();
364
        FeatureQuery featureQuery = featureStore.createFeatureQuery();
365
        FeatureType featureType = featureStore.getDefaultFeatureType();
366
        featureQuery.setFeatureType(featureType);
367

  
368
        Geometry query_geo = currentLayer.transformToSourceCRS(circle, true);
369

  
370
        IProjection query_proj = currentLayer.getMapContext().getProjection();
371
        if (currentLayer.getCoordTrans() != null) {
372
            query_proj = currentLayer.getCoordTrans().getPOrig();
373
        }
374

  
375
        Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects(
376
                query_geo, 
377
                query_proj, 
378
                featureStore
379
        );
380
        featureQuery.setFilter(iee);
381
        featureQuery.retrievesAllAttributes();
382
        return featureQuery;
383
    }
384

  
385
    @Override
386
    public void rectangle(EnvelopeEvent e) throws BehaviorException {
387
        MouseEvent mouseEvent = e.getEvent();
388
        if (((mouseEvent.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
389
            | InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.META_DOWN_MASK)) != 0)
390
            || !SwingUtilities.isLeftMouseButton(mouseEvent)) {
391
            return;
392
        }
393
        String layerName = "";
394
        I18nManager i18nManager = ToolsLocator.getI18nManager();
395
        try {
396
            FLyrVect layer = getLayer();
397
            if (layer == null) {
398
                String msg = i18nManager.getTranslation("There_is_no_one_and_only_one_active_layer");
399
                ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
400
                    i18nManager.getTranslation("attribute_editor"), JOptionPane.INFORMATION_MESSAGE);
401
                return;
402
            }
403
            layerName = layer.getName();
404
            FeatureQuery query;
405
            Geometry geom = e.getWorldCoordRect().getGeometry();            
406
            if( geom instanceof Point ) {
407
                ViewPort vp = this.mapControl.getViewPort();
408
                double tolerance = vp.toMapDistance(layer.getDefaultTolerance());
409
                query = queryByPoint((Point) geom, tolerance);
410
            } else {
411
                FeatureStore store = layer.getFeatureStore();
412
                FeatureType featureType = store.getDefaultFeatureTypeQuietly();
413
                GeometryExpressionBuilder builder = GeometryExpressionUtils.createExpressionBuilder();
414
                String filter = builder.ST_Intersects(
415
                        builder.column(featureType.getDefaultGeometryAttributeName()), 
416
                        builder.geometry(e.getWorldCoordRect().getGeometry())
417
                ).toString();
418
                query = store.createFeatureQuery(filter);
419
            }
420
            showOrUpdateForm(layer, query);
421
        } catch (Exception ex) {
422
            LOGGER.warn("Can't show attribute information from point on the layer " + layerName, ex);
423
            String msg =
424
                i18nManager.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
425
                    new String[] { layerName });
426
            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
427
                i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
428
        }
429
    }
430

  
431
    public String makeTitle(String base, String docname, String docname2) {
432
        I18nManager i18n = ToolsLocator.getI18nManager();
433
//        if( StringUtils.startsWith(base, "_") ) {
434
            base = i18n.getTranslation(base);
435
//        }
436
        String title = base + ": " + docname;
437
        if( StringUtils.isNotBlank(docname2) && !StringUtils.equals(docname, docname2)) {
438
            title = title + " ("+docname2+")";
439
        }
440
        return title;
441
    }
442
}
0 443

  
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/buildNumber.properties
1
#Sun Jun 09 23:09:54 CEST 2024
2
buildNumber=254
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

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

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

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

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

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

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

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

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

  
61
</assembly>
62

  
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/java/org/gvsig/app/mainplugin/extension/AttributeEditorExtension.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.app.mainplugin.extension;
24

  
25

  
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.documents.view.ViewDocument;
31
import org.gvsig.app.project.documents.view.ViewManager;
32
import org.gvsig.app.project.documents.view.gui.IView;
33
import org.gvsig.expressionevaluator.Expression;
34
import org.gvsig.fmap.dal.EditingNotification;
35
import org.gvsig.fmap.dal.EditingNotificationManager;
36
import org.gvsig.fmap.dal.feature.Feature;
37
import org.gvsig.fmap.dal.feature.FeatureQuery;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.dal.feature.FeatureType;
40
import org.gvsig.fmap.dal.swing.DALSwingLocator;
41
import org.gvsig.fmap.mapcontext.layers.FLayer;
42
import org.gvsig.fmap.mapcontrol.MapControl;
43
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
44
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorBehavior;
45
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorPointListener;
46
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynobject.DynObjectManager;
49
import org.gvsig.tools.dynobject.Tags;
50
import org.gvsig.tools.observer.Observable;
51
import org.gvsig.tools.observer.Observer;
52

  
53
/**
54
 * @author fdiaz
55
 *
56
 */
57
public class AttributeEditorExtension extends Extension {
58

  
59
    private static final String TAG_ATTRIBUTEEDITOR_LOADONINSERT = "attributeeditor.loadoninsert";
60
    
61
    private Observer editingObserver;
62
       
63

  
64
    @Override
65
    public void execute(String actionCommand) {
66
        if (!actionCommand.equalsIgnoreCase("attribute-editor") ) {
67
            return;
68
        }
69
        ApplicationManager application = ApplicationLocator.getManager();
70
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
71
        if (view != null) {
72
            MapControl mapControl = view.getMapControl();
73
            if( mapControl.getMapContext().hasActiveVectorLayers() ) {
74
                if (!mapControl.hasTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME)) {
75
                    createMapTool(mapControl);
76
                }
77
                mapControl.setTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);                
78
                Behavior behavior = mapControl.getTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);                
79
                ((AttributeEditorPointListener)behavior.getListener()).showOrUpdateForm();
80
            }
81
        }
82

  
83
    }
84

  
85
    @Override
86
    public void initialize() {
87
        IconThemeHelper.registerIcon("action", "attribute-editor", this);
88
    }
89

  
90
    @Override
91
    @SuppressWarnings("Convert2Lambda")
92
    public void postInitialize() {
93
        this.editingObserver = new Observer() {
94
            @Override
95
            public void update(Observable o, Object notification) {
96
                if( !isEnabled() ) {
97
                    return;
98
                }
99
                EditingNotification n = (EditingNotification) notification;
100
                if( n.getType().equalsIgnoreCase(EditingNotification.AFTER_INSERT_FEATURE) ) {
101
                    if( n.getFeature()!=null && n.getFeatureStore()!=null ) {
102
                        FeatureType featureType = n.getFeatureStore().getDefaultFeatureTypeQuietly();
103
                        if( featureType != null ) {
104
                            Tags tags = featureType.getTags();
105
                            if( tags.getBoolean(TAG_ATTRIBUTEEDITOR_LOADONINSERT, false) ) {
106
                                doShowFeature(n.getFeatureStore(),n.getFeature());
107
                            }
108
                        }
109
                    }
110
                }
111
            }
112
        };
113
        EditingNotificationManager editingNotificationManager = DALSwingLocator.getEditingNotificationManager();
114
        editingNotificationManager.addObserver(this.editingObserver);       
115
        
116
        DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
117
        dynObjectManager.registerTag(
118
                TAG_ATTRIBUTEEDITOR_LOADONINSERT, 
119
                "Indicates if the attribute editor should be opened when creating a feature of this type. By default false.",
120
                new String[] { "true", "false" }
121
        );
122
        
123
    }
124
    
125
    @Override
126
    public boolean isEnabled() {
127
        ViewDocument viewDoc = getActiveViewDocument();
128
        if (viewDoc == null) {
129
            return false;
130
        }
131
        FLayer[] layers = viewDoc.getMapContext().getLayers().getActives();
132
        if (layers == null || layers.length != 1) {
133
            return false;
134
        }
135
        return true;
136
    }
137

  
138
    @Override
139
    public boolean isVisible() {
140
        return getActiveViewDocument() != null;
141
    }
142

  
143
    /**
144
     * Gets active window
145
     *
146
     * @return
147
     */
148
    private ViewDocument getActiveViewDocument() {
149
        return (ViewDocument) ApplicationLocator.getManager().getActiveDocument(ViewManager.TYPENAME);
150
    }
151

  
152
    private void createMapTool(MapControl mapControl) {
153
        ApplicationManager application = ApplicationLocator.getManager();
154
        
155
        AttributeEditorBehavior attributeEditorBehavior = new AttributeEditorBehavior(mapControl);
156
        attributeEditorBehavior.getListener().setRefreshCallback((FeatureStore store) -> {
157
            application.refreshDocument(store);
158
            return true;
159
        });
160
        mapControl.addBehavior(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME, attributeEditorBehavior);
161
    }
162
    
163
    private void doShowFeature(FeatureStore store, Feature feature) {
164
        Expression filter = feature.createFilter();
165
        if( filter == null ) {
166
            return;
167
        }
168
        ApplicationManager application = ApplicationLocator.getManager();
169
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
170
        if (view != null) {
171
            MapControl mapControl = view.getMapControl();
172
            Behavior tool = mapControl.getTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);
173
            if (tool == null ) {
174
                createMapTool(mapControl);
175
                tool = mapControl.getTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);
176
            }            
177
            AttributeEditorPointListener listener = (AttributeEditorPointListener) tool.getListener();
178
            listener.showOrUpdateForm(store.getLabel(), store, store.createFeatureQuery(filter));
179
        }
180
        
181
    }
182
}
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
# Resource bundle texts for the Spanish language locale (es)
2
attribute_editor=Editor de atributos
3
error_saving_data_will_not_save=Se ha producido un error intentando guardar los datos. Los datos no se guardar\u00e1n.
4
cant_edit_the store_XstorenameX=No se ha podido poner en edici\u00f3n el store '%(storename)'
5
cant_get_the_associated_feature_to_index_XindexX=No se ha podido obtener la feature asociada al index '%(index)'
6
cant_update_the_feature_XindexX_in_the_store_XstorenameX=No se ha podido actualizar la feature '%(index)' en el store '%(storename)'
7
cant_finish_the_edition_of_the_store_XstorenameX=No se ha podido finalizar la edici\u00f3n del store '%(storename)'
8
There_is_no_one_and_only_one_active_layer=No hay una y solo una capa activa.
9
Cant_show_attribute_information_for_layer_%1_on_point=No se ha podido mostrar la informaci\u00f3n de los atributos de la capa {0} sobre este punto.
10
create_default_definition=Crear definici\u00f3n por defecto
11
_Cant_show_attribute_information_for_layer_XlayernameX_on_selection=No se ha podido mostrar la informaci\u00f3n de los atributos de la capa {0} sobre la selecci\u00f3n.
12
_Unable_to_get_filter_for_XlayernameX_layer_selection=No se ha podido obtener el filtro para la selecci\u00f3n de la capa {0}
13
_Too_many_items_selected_Only_the_first_100_will_be_displayed=Demasiados elementos seleccionados. Solo se mostrar\u00e1n los 100 primeros.
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
attribute_editor=Attribute editor
3
error_saving_data_will_not_save=There was an error trying to save the data. The data will not be saved.
4
cant_edit_the store_XstorenameX=Can't edit the store '%(storename)'
5
cant_get_the_associated_feature_to_index_XindexX=Can't get the associated feature to index '%(index)'
6
cant_update_the_feature_XindexX_in_the_store_XstorenameX=Can't update the feature '%(index)' in the store '%(storename)'
7
cant_finish_the_edition_of_the_store_XstorenameX=Can't finish the edition of the store '%(storename)'
8
There_is_no_one_and_only_one_active_layer=There is no one and only one active layer
9
Cant_show_attribute_information_for_layer_%1_on_point=Can't show the attribute information for layer {0} on this point.
10
create_default_definition=Create default definition
11
_Cant_show_attribute_information_for_layer_XlayernameX_on_selection=Can't show the attribute information for layer {0} on selection.
12
_Unable_to_get_filter_for_XlayernameX_layer_selection=Unable to get filter for {0} layer selection
13
_Too_many_items_selected_Only_the_first_100_will_be_displayed=Too many items selected. Only the first 100 will be displayed.
org.gvsig.attributeeditor/tags/org.gvsig.attributeeditor-1.0.252/org.gvsig.attributeeditor.app/org.gvsig.attributeeditor.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2014 gvSIG
3
  Association. This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by the Free Software
5
  Foundation; either version 3 of the License, or (at your option) any later version.
6
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
  PURPOSE. See the GNU General Public License for more details. You should have received
9
  a copy of the GNU General Public License along with this program; if not, write to
10
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
11
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
12
  or visit our website www.gvsig.com. -->
13
<plugin-config>
14
  <depends plugin-name="org.gvsig.app.mainplugin" />
15
  <resourceBundle name="text" />
16
  <libraries library-dir="lib" />
17
  <extensions>
18
    <extension class-name="org.gvsig.app.mainplugin.extension.AttributeEditorExtension"
19
      description="" active="true" priority="1">
20

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

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

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

  
32
    </extension>
33

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

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

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

  
17
</project>
0 18

  

Also available in: Unified diff