root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerAddLayerWizardPanel.java @ 32880
History | View | Annotate | Download (5.52 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I. S.A. {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
32 |
|
33 |
import java.awt.BorderLayout; |
34 |
import java.awt.Window; |
35 |
import java.awt.event.ActionEvent; |
36 |
|
37 |
import javax.swing.JFrame; |
38 |
|
39 |
import org.cresques.cts.IProjection; |
40 |
import org.gvsig.andami.messages.NotificationManager; |
41 |
import org.gvsig.app.ApplicationLocator; |
42 |
import org.gvsig.app.ApplicationManager; |
43 |
import org.gvsig.app.addlayer.AddLayerDialog; |
44 |
import org.gvsig.app.prepareAction.PrepareContext; |
45 |
import org.gvsig.app.prepareAction.PrepareContextView; |
46 |
import org.gvsig.fmap.dal.DataStoreParameters; |
47 |
import org.gvsig.fmap.dal.DataTypes; |
48 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
52 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
53 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
54 |
import org.gvsig.fmap.mapcontrol.MapControl; |
55 |
import org.gvsig.tools.dynobject.DynField; |
56 |
import org.gvsig.tools.dynobject.DynObject; |
57 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
58 |
|
59 |
|
60 |
/**
|
61 |
* @author jmvivo
|
62 |
*
|
63 |
*/
|
64 |
public class FilesystemExplorerAddLayerWizardPanel extends |
65 |
FilesystemExplorerWizardPanel { |
66 |
|
67 |
/**
|
68 |
*
|
69 |
*/
|
70 |
private static final long serialVersionUID = -5054057255129168139L; |
71 |
private PrepareContext prepareContext;
|
72 |
|
73 |
/*
|
74 |
* (non-Javadoc)
|
75 |
*
|
76 |
* @see com.iver.cit.gvsig.gui.WizardPanel#execute()
|
77 |
*/
|
78 |
@Override
|
79 |
public void execute() { |
80 |
if (this.getMapCtrl() == null){ |
81 |
throw new IllegalArgumentException("MapControl need"); |
82 |
} |
83 |
MapContext mapContext = this.getMapCtrl().getMapContext();
|
84 |
FLayer layer; |
85 |
String layerName;
|
86 |
LayerFactory layerFactor = LayerFactory.getInstance(); |
87 |
|
88 |
ApplicationManager appGvSigMan = ApplicationLocator.getManager(); |
89 |
|
90 |
for (DataStoreParameters params : this.getParameters()) { |
91 |
IProjection proj = null;
|
92 |
|
93 |
proj = this.getMapCtrl().getProjection();
|
94 |
|
95 |
// Buscamos por el parametro de la proyeccion
|
96 |
// que sean obligatorios y est?n a null
|
97 |
// y le ponemos la proyeccion de la vista
|
98 |
DynField[] fields = params.getDynClass().getDynFields();
|
99 |
for (DynField field : fields) {
|
100 |
if (field.getType() == DataTypes.CRS && field.isMandatory()) {
|
101 |
if (params.getDynValue(field.getName()) == null) { |
102 |
params.setDynValue(field.getName(), proj); |
103 |
} |
104 |
} |
105 |
} |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
//FIXME: el nombre deberia sugerirlo los parametros?
|
111 |
layerName = ((FilesystemStoreParameters) params).getFile().getName(); |
112 |
|
113 |
try {
|
114 |
|
115 |
layer = layerFactor.createLayer(layerName, |
116 |
params); |
117 |
} catch (LoadLayerException e) {
|
118 |
NotificationManager.addError(e); |
119 |
return;
|
120 |
} |
121 |
try {
|
122 |
layer = appGvSigMan.prepareOpenLayer(layer, |
123 |
(PrepareContextView) this.getPrepareDataStoreContext());
|
124 |
} catch (Exception e) { |
125 |
NotificationManager.addError(e); |
126 |
if (layer instanceof SingleLayer) { |
127 |
((SingleLayer) layer).getDataStore().dispose(); |
128 |
} |
129 |
return;
|
130 |
} |
131 |
if (layer == null) { |
132 |
continue;
|
133 |
} |
134 |
|
135 |
mapContext.getLayers().addLayer(layer); |
136 |
} |
137 |
|
138 |
|
139 |
} |
140 |
|
141 |
@Override
|
142 |
public void actionPerformed(ActionEvent e) { |
143 |
|
144 |
String command = e.getActionCommand();
|
145 |
FilesystemStoreListModel model = (FilesystemStoreListModel) getFileList() |
146 |
.getModel(); |
147 |
|
148 |
if (command == EDIT_COMMAND) {
|
149 |
DynObject dynObject = model.getDynObjectAt(getFileList() |
150 |
.getSelectedIndex()); |
151 |
|
152 |
|
153 |
DynObjectEditor editor = new DynObjectEditor(dynObject,
|
154 |
DynObjectEditor.SHOW_ALL, null, true, true); |
155 |
editor.editObject(true);
|
156 |
this.loadParamsList(dynObject);
|
157 |
|
158 |
} else {
|
159 |
super.actionPerformed(e);
|
160 |
} |
161 |
} |
162 |
|
163 |
public static void main(String[] args) { |
164 |
try {
|
165 |
new DefaultLibrariesInitializer().fullInitialize();
|
166 |
|
167 |
JFrame frame = new JFrame(); |
168 |
|
169 |
AddLayerDialog addLayerDlg = new AddLayerDialog();
|
170 |
|
171 |
FilesystemExplorerAddLayerWizardPanel wizardPanel = new FilesystemExplorerAddLayerWizardPanel();
|
172 |
addLayerDlg.addWizardTab("File", wizardPanel);
|
173 |
wizardPanel.initWizard(); |
174 |
|
175 |
frame.setLayout(new BorderLayout()); |
176 |
frame.add(addLayerDlg); |
177 |
|
178 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
179 |
frame.setBounds(10, 10, 400, 400); |
180 |
frame.setVisible(true);
|
181 |
|
182 |
} catch (Exception e) { |
183 |
e.printStackTrace(); |
184 |
System.exit(-1); |
185 |
return;
|
186 |
} |
187 |
} |
188 |
|
189 |
@Override
|
190 |
protected PrepareContext getPrepareDataStoreContext() {
|
191 |
if (this.prepareContext == null) { |
192 |
this.prepareContext = new PrepareContextView() { |
193 |
public Window getOwnerWindow() { |
194 |
return null; |
195 |
} |
196 |
|
197 |
public MapControl getMapControl() {
|
198 |
return FilesystemExplorerAddLayerWizardPanel.this
|
199 |
.getMapCtrl(); |
200 |
} |
201 |
|
202 |
}; |
203 |
} |
204 |
return this.prepareContext; |
205 |
} |
206 |
|
207 |
|
208 |
} |