svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeToAnnotationExtension.java @ 5258
History | View | Annotate | Download (3.88 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig; |
42 |
|
43 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
44 |
import com.iver.andami.PluginServices; |
45 |
import com.iver.andami.plugins.Extension; |
46 |
import com.iver.andami.ui.mdiManager.View; |
47 |
import com.iver.cit.gvsig.fmap.FMap; |
48 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
49 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
50 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
51 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
52 |
import com.iver.cit.gvsig.gui.Panels.MappingFieldsToAnotation; |
53 |
import com.iver.cit.gvsig.project.ProjectView; |
54 |
|
55 |
|
56 |
/**
|
57 |
* DOCUMENT ME!
|
58 |
*
|
59 |
* @author Vicente Caballero Navarro
|
60 |
*/
|
61 |
public class ThemeToAnnotationExtension extends Extension { |
62 |
private FMap map=null; |
63 |
/**
|
64 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
65 |
*/
|
66 |
public void initialize() { |
67 |
} |
68 |
|
69 |
/**
|
70 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
71 |
*/
|
72 |
public void execute(String actionCommand) { |
73 |
if ("LAYERTOANNOTATION".equals(actionCommand)) { |
74 |
FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
|
75 |
FLyrAnnotation la=new FLyrAnnotation();
|
76 |
la.setSource(lv.getSource()); |
77 |
|
78 |
MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
|
79 |
PluginServices.getMDIManager().addView(mfta); |
80 |
|
81 |
if (mfta.isOk()){
|
82 |
map.getLayers().addLayer(la); |
83 |
map.getLayers().removeLayer(lv); |
84 |
} |
85 |
} |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
90 |
*/
|
91 |
public boolean isEnabled() { |
92 |
View v = PluginServices.getMDIManager().getActiveView();
|
93 |
|
94 |
if (v == null) { |
95 |
return false; |
96 |
} else if (v.getClass() == com.iver.cit.gvsig.gui.View.class) { |
97 |
com.iver.cit.gvsig.gui.View vista=(com.iver.cit.gvsig.gui.View)v; |
98 |
ProjectView model = vista.getModel(); |
99 |
map = model.getMapContext(); |
100 |
FLayer[] layers=map.getLayers().getActives();
|
101 |
if (layers.length==1){ |
102 |
if (layers[0] instanceof FLyrVect){ |
103 |
FLyrVect lv=(FLyrVect)layers[0];
|
104 |
SelectableDataSource sds=lv.getSource().getRecordset(); |
105 |
try {
|
106 |
if (sds.getFieldCount()>0) |
107 |
return true; |
108 |
} catch (DriverException e) {
|
109 |
return false; |
110 |
} |
111 |
} |
112 |
} |
113 |
return false; |
114 |
} else {
|
115 |
return false; |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
121 |
*/
|
122 |
public boolean isVisible() { |
123 |
View v = PluginServices.getMDIManager().getActiveView();
|
124 |
|
125 |
if (v == null) { |
126 |
return false; |
127 |
} else if (v.getClass() == com.iver.cit.gvsig.gui.View.class) { |
128 |
return true; |
129 |
} else {
|
130 |
return false; |
131 |
} |
132 |
} |
133 |
} |