root / branches / v1_9_0 / extGPE-gvSIG / src / org / gvsig / gpe / GPEWriterExtension.java @ 64
History | View | Annotate | Download (5.01 KB)
1 |
package org.gvsig.gpe; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileNotFoundException; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import org.gvsig.gpe.gui.dialogs.SelectVersionListener; |
8 |
import org.gvsig.gpe.gui.dialogs.SelectVersionWindow; |
9 |
import org.gvsig.gpe.writer.GPEWriterHandler; |
10 |
|
11 |
import com.iver.andami.PluginServices; |
12 |
import com.iver.andami.messages.NotificationManager; |
13 |
import com.iver.andami.plugins.Extension; |
14 |
import com.iver.cit.gvsig.StopEditing; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
17 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
18 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
19 |
|
20 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
21 |
*
|
22 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* as published by the Free Software Foundation; either version 2
|
27 |
* of the License, or (at your option) any later version.
|
28 |
*
|
29 |
* This program is distributed in the hope that it will be useful,
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
* GNU General Public License for more details.
|
33 |
*
|
34 |
* You should have received a copy of the GNU General Public License
|
35 |
* along with this program; if not, write to the Free Software
|
36 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
37 |
*
|
38 |
* For more information, contact:
|
39 |
*
|
40 |
* Generalitat Valenciana
|
41 |
* Conselleria d'Infraestructures i Transport
|
42 |
* Av. Blasco Ib??ez, 50
|
43 |
* 46010 VALENCIA
|
44 |
* SPAIN
|
45 |
*
|
46 |
* +34 963862235
|
47 |
* gvsig@gva.es
|
48 |
* www.gvsig.gva.es
|
49 |
*
|
50 |
* or
|
51 |
*
|
52 |
* IVER T.I. S.A
|
53 |
* Salamanca 50
|
54 |
* 46005 Valencia
|
55 |
* Spain
|
56 |
*
|
57 |
* +34 963163400
|
58 |
* dac@iver.es
|
59 |
*/
|
60 |
/* CVS MESSAGES:
|
61 |
*
|
62 |
* $Id: GPEWriterExtension.java 64 2009-10-12 16:20:02Z groldan $
|
63 |
* $Log$
|
64 |
*
|
65 |
*/
|
66 |
/**
|
67 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
68 |
*/
|
69 |
public class GPEWriterExtension extends Extension{ |
70 |
private String writersFile = "gvSIG" + File.separatorChar + "extensiones" + File.separatorChar + |
71 |
"org.gvsig.gpe" + File.separatorChar + "writer.properties"; |
72 |
|
73 |
/*
|
74 |
* (non-Javadoc)
|
75 |
* @see com.iver.cit.gvsig.ExportTo#execute(java.lang.String)
|
76 |
*/
|
77 |
public void execute(String format) { |
78 |
ArrayList writers = null; |
79 |
if (format.equals("GML")){ |
80 |
writers =GPERegister.getWriterHandlerByFormat("text/xml; subtype=gml/3.1.2");
|
81 |
ArrayList auxWriters = GPERegister.getWriterHandlerByFormat("text/xml; subtype=gml/2.1.2"); |
82 |
for (int i=0 ; i<auxWriters.size() ; i++){ |
83 |
writers.add(auxWriters.get(i)); |
84 |
} |
85 |
auxWriters = GPERegister.getWriterHandlerByFormat("text/x-bxml; subtype=gml/3.1.2");
|
86 |
for (int i=0 ; i<auxWriters.size() ; i++){ |
87 |
writers.add(auxWriters.get(i)); |
88 |
} |
89 |
}else if(format.equals("KML")){ |
90 |
writers = GPERegister.getWriterHandlerByFormat("text/xml; subtype=kml/2.1");
|
91 |
} |
92 |
//Creates the window
|
93 |
SelectVersionWindow window = new SelectVersionWindow();
|
94 |
|
95 |
for (int i=0 ; i<writers.size() ; i++){ |
96 |
window.addWriter((GPEWriterHandler)writers.get(i)); |
97 |
} |
98 |
//Sets the listeners and shows the window
|
99 |
SelectVersionListener listener = new SelectVersionListener(window);
|
100 |
window.addListener(listener); |
101 |
window.setFile(window.getDefaultFileName()); |
102 |
PluginServices.getMDIManager().addCentredWindow(window); |
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
108 |
*/
|
109 |
public void initialize() { |
110 |
// ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
111 |
// extensionPoints.add("AplicationPreferences","GPEPreferencesPage", GPEPreferencesPage.class);
|
112 |
|
113 |
loadWriters(); |
114 |
StopEditing.addExportFormat("GML", this.getClass()); |
115 |
StopEditing.addExportFormat("KML", this.getClass()); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Load the GPE writers from a file
|
120 |
*/
|
121 |
private void loadWriters(){ |
122 |
File file = new File(writersFile); |
123 |
if (!file.exists()){
|
124 |
NotificationManager.addWarning("File not found",
|
125 |
new FileNotFoundException()); |
126 |
return;
|
127 |
} |
128 |
try {
|
129 |
GPERegister.addWritersFile(file); |
130 |
} catch (Exception e) { |
131 |
NotificationManager.addWarning("GPE writers file not found",
|
132 |
new FileNotFoundException()); |
133 |
} |
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
139 |
*/
|
140 |
public boolean isEnabled() { |
141 |
com.iver.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager() |
142 |
.getActiveWindow(); |
143 |
|
144 |
if (window == null) { |
145 |
return false; |
146 |
} |
147 |
|
148 |
if (!(window instanceof IView)){ |
149 |
return false; |
150 |
} |
151 |
|
152 |
IView view = (IView)window; |
153 |
LayersIterator it = new LayersIterator(
|
154 |
view.getMapControl().getMapContext().getLayers()); |
155 |
while(it.hasNext()){
|
156 |
FLayer layer = it.nextLayer(); |
157 |
if (layer instanceof FLyrVect){ |
158 |
return true; |
159 |
} |
160 |
} |
161 |
return false; |
162 |
} |
163 |
|
164 |
/*
|
165 |
* (non-Javadoc)
|
166 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
167 |
*/
|
168 |
public boolean isVisible() { |
169 |
com.iver.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager() |
170 |
.getActiveWindow(); |
171 |
|
172 |
if (window == null) { |
173 |
return false; |
174 |
} |
175 |
|
176 |
return (window instanceof IView); |
177 |
} |
178 |
} |