root / branches / v2_0_0_prep / extensions / org.gvsig.geometrymeasurement.app / org.gvsig.geometrymeasurement.app.extension / src / main / java / org / gvsig / geometrymeasurement / app / extension / AddXYPointThemeExtension.java @ 34143
History | View | Annotate | Download (3.58 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.geometrymeasurement.app.extension; |
23 |
|
24 |
import org.slf4j.Logger; |
25 |
import org.slf4j.LoggerFactory; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.messages.NotificationManager; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.geom.Geometry; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 |
import org.gvsig.geometrymeasurement.app.extension.utils.Operations; |
40 |
|
41 |
/**
|
42 |
* Andami extension to show PerimeterMeasurementExtension in the application.
|
43 |
*
|
44 |
* @author gvSIG Team
|
45 |
* @version $Id$
|
46 |
*/
|
47 |
public class AddXYPointThemeExtension extends Extension { |
48 |
private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class); |
49 |
private FLyrVect fLyrVect;
|
50 |
|
51 |
public void initialize() { |
52 |
// Do nothing
|
53 |
} |
54 |
|
55 |
@Override
|
56 |
public void postInitialize() { |
57 |
super.postInitialize();
|
58 |
} |
59 |
|
60 |
public void execute(String actionCommand) { |
61 |
Operations operations = new Operations();
|
62 |
FeatureStore featureStore = fLyrVect.getFeatureStore(); |
63 |
|
64 |
try {
|
65 |
operations.addXYPoints(featureStore, "X", "Y"); |
66 |
} catch (DataException e) {
|
67 |
LOG.error("Not possible to create the X and Y fields", e);
|
68 |
NotificationManager.addError(e); |
69 |
} |
70 |
} |
71 |
|
72 |
public boolean isEnabled() { |
73 |
return true; |
74 |
} |
75 |
|
76 |
public boolean isVisible() { |
77 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
78 |
|
79 |
if (window == null){ |
80 |
return false; |
81 |
} |
82 |
if (window instanceof IView){ |
83 |
IView view = (IView) window; |
84 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
85 |
FLayer[] activeLayers = layers.getActives();
|
86 |
|
87 |
if (activeLayers.length == 1){ |
88 |
if (activeLayers[0] instanceof FLyrVect){ |
89 |
fLyrVect = (FLyrVect) activeLayers[0];
|
90 |
try {
|
91 |
int type = fLyrVect.getShapeType();
|
92 |
if (Geometry.TYPES.POINT == type){
|
93 |
return true; |
94 |
} |
95 |
} catch (ReadException e) {
|
96 |
LOG.error("Error reading the geometry type", e);
|
97 |
return false; |
98 |
} |
99 |
} |
100 |
} |
101 |
} |
102 |
return false; |
103 |
} |
104 |
|
105 |
} |