root / tags / v2_0_0_Build_2047 / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerAddLayerWizardPanel.java @ 38262
History | View | Annotate | Download (6.21 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 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
28 |
|
29 |
import java.awt.BorderLayout; |
30 |
import java.awt.Window; |
31 |
import java.awt.event.ActionEvent; |
32 |
|
33 |
import javax.swing.JFrame; |
34 |
|
35 |
import org.cresques.cts.IProjection; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.app.addlayer.AddLayerDialog; |
40 |
import org.gvsig.app.prepareAction.PrepareContext; |
41 |
import org.gvsig.app.prepareAction.PrepareContextView; |
42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
43 |
import org.gvsig.fmap.dal.DataTypes; |
44 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
45 |
import org.gvsig.fmap.mapcontrol.MapControl; |
46 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
47 |
import org.gvsig.tools.dynobject.DynField; |
48 |
import org.gvsig.tools.dynobject.DynObject; |
49 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
50 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
51 |
import org.gvsig.tools.service.ServiceException; |
52 |
|
53 |
/**
|
54 |
* @author jmvivo
|
55 |
*
|
56 |
*/
|
57 |
public class FilesystemExplorerAddLayerWizardPanel extends |
58 |
FilesystemExplorerWizardPanel { |
59 |
|
60 |
private static final long serialVersionUID = -5054057255129168139L; |
61 |
|
62 |
private static final Logger LOG = LoggerFactory |
63 |
.getLogger(FilesystemExplorerAddLayerWizardPanel.class); |
64 |
|
65 |
private PrepareContext prepareContext;
|
66 |
|
67 |
@Override
|
68 |
public void execute() { |
69 |
if (this.getMapCtrl() == null) { |
70 |
throw new IllegalArgumentException("MapControl need"); |
71 |
} |
72 |
String layerName;
|
73 |
|
74 |
for (DataStoreParameters params : this.getParameters()) { |
75 |
IProjection proj = null;
|
76 |
|
77 |
proj = this.getMapCtrl().getProjection();
|
78 |
|
79 |
// Buscamos por el parametro de la proyeccion
|
80 |
// que sean obligatorios y est?n a null
|
81 |
// y le ponemos la proyeccion de la vista
|
82 |
DynField[] fields = params.getDynClass().getDynFields();
|
83 |
for (DynField field : fields) {
|
84 |
if (field.getType() == DataTypes.CRS && field.isMandatory()) {
|
85 |
if (params.getDynValue(field.getName()) == null) { |
86 |
params.setDynValue(field.getName(), proj); |
87 |
} |
88 |
} |
89 |
} |
90 |
|
91 |
layerName = |
92 |
((FilesystemStoreParameters) params).getFile().getName(); |
93 |
|
94 |
this.doAddLayer(this.getMapCtrl(), layerName, params); |
95 |
} |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void actionPerformed(ActionEvent e) { |
100 |
|
101 |
String command = e.getActionCommand();
|
102 |
FilesystemStoreListModel model = |
103 |
(FilesystemStoreListModel) getFileList().getModel(); |
104 |
|
105 |
if (command == EDIT_COMMAND) {
|
106 |
DynObject dynObject = |
107 |
model.getDynObjectAt(getFileList().getSelectedIndex()); |
108 |
|
109 |
// For store parameters with a CRS field, add the current view
|
110 |
// CRS as default value when null.
|
111 |
try {
|
112 |
IProjection projection = |
113 |
(IProjection) dynObject.getDynValue("CRS");
|
114 |
if (projection == null) { |
115 |
projection = getDefaultProjection(); |
116 |
dynObject.setDynValue("CRS", projection);
|
117 |
} |
118 |
} catch (DynFieldNotFoundException e1) {
|
119 |
LOG.debug("Loading a store whose parameters "
|
120 |
+ "don't have a CRS field");
|
121 |
} |
122 |
|
123 |
try {
|
124 |
DynObjectEditor editor = new DynObjectEditor(dynObject);
|
125 |
editor.editObject(true);
|
126 |
} catch (ServiceException ex) {
|
127 |
LOG.error( |
128 |
"Error creating a Swing component for the DynObject: "
|
129 |
+ dynObject, ex); |
130 |
} |
131 |
|
132 |
} else {
|
133 |
super.actionPerformed(e);
|
134 |
} |
135 |
} |
136 |
|
137 |
/**
|
138 |
* @return
|
139 |
*/
|
140 |
private IProjection getDefaultProjection() {
|
141 |
return getMapCtrl().getViewPort().getProjection();
|
142 |
} |
143 |
|
144 |
public static void main(String[] args) { |
145 |
try {
|
146 |
new DefaultLibrariesInitializer().fullInitialize();
|
147 |
|
148 |
JFrame frame = new JFrame(); |
149 |
|
150 |
AddLayerDialog addLayerDlg = new AddLayerDialog();
|
151 |
|
152 |
FilesystemExplorerAddLayerWizardPanel wizardPanel = |
153 |
new FilesystemExplorerAddLayerWizardPanel();
|
154 |
addLayerDlg.addWizardTab("File", wizardPanel);
|
155 |
wizardPanel.initWizard(); |
156 |
|
157 |
frame.setLayout(new BorderLayout()); |
158 |
frame.add(addLayerDlg); |
159 |
|
160 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
161 |
frame.setBounds(10, 10, 400, 400); |
162 |
frame.setVisible(true);
|
163 |
|
164 |
} catch (Exception e) { |
165 |
e.printStackTrace(); |
166 |
System.exit(-1); |
167 |
return;
|
168 |
} |
169 |
} |
170 |
|
171 |
@Override
|
172 |
protected PrepareContext getPrepareDataStoreContext() {
|
173 |
if (this.prepareContext == null) { |
174 |
this.prepareContext = new PrepareContextView() { |
175 |
|
176 |
public Window getOwnerWindow() { |
177 |
return null; |
178 |
} |
179 |
|
180 |
public MapControl getMapControl() {
|
181 |
return FilesystemExplorerAddLayerWizardPanel.this
|
182 |
.getMapCtrl(); |
183 |
} |
184 |
|
185 |
public IProjection getViewProjection() {
|
186 |
return getMapControl().getProjection();
|
187 |
} |
188 |
|
189 |
}; |
190 |
} |
191 |
return this.prepareContext; |
192 |
} |
193 |
|
194 |
} |