svn-gvsig-desktop / tags / v2_0_0_Build_2038 / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerAddLayerWizardPanel.java @ 37007
History | View | Annotate | Download (6.26 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 |
this.loadParamsList(dynObject);
|
127 |
} catch (ServiceException ex) {
|
128 |
LOG.error( |
129 |
"Error creating a Swing component for the DynObject: "
|
130 |
+ dynObject, ex); |
131 |
} |
132 |
|
133 |
} else {
|
134 |
super.actionPerformed(e);
|
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* @return
|
140 |
*/
|
141 |
private IProjection getDefaultProjection() {
|
142 |
return getMapCtrl().getViewPort().getProjection();
|
143 |
} |
144 |
|
145 |
public static void main(String[] args) { |
146 |
try {
|
147 |
new DefaultLibrariesInitializer().fullInitialize();
|
148 |
|
149 |
JFrame frame = new JFrame(); |
150 |
|
151 |
AddLayerDialog addLayerDlg = new AddLayerDialog();
|
152 |
|
153 |
FilesystemExplorerAddLayerWizardPanel wizardPanel = |
154 |
new FilesystemExplorerAddLayerWizardPanel();
|
155 |
addLayerDlg.addWizardTab("File", wizardPanel);
|
156 |
wizardPanel.initWizard(); |
157 |
|
158 |
frame.setLayout(new BorderLayout()); |
159 |
frame.add(addLayerDlg); |
160 |
|
161 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
162 |
frame.setBounds(10, 10, 400, 400); |
163 |
frame.setVisible(true);
|
164 |
|
165 |
} catch (Exception e) { |
166 |
e.printStackTrace(); |
167 |
System.exit(-1); |
168 |
return;
|
169 |
} |
170 |
} |
171 |
|
172 |
@Override
|
173 |
protected PrepareContext getPrepareDataStoreContext() {
|
174 |
if (this.prepareContext == null) { |
175 |
this.prepareContext = new PrepareContextView() { |
176 |
|
177 |
public Window getOwnerWindow() { |
178 |
return null; |
179 |
} |
180 |
|
181 |
public MapControl getMapControl() {
|
182 |
return FilesystemExplorerAddLayerWizardPanel.this
|
183 |
.getMapCtrl(); |
184 |
} |
185 |
|
186 |
public IProjection getViewProjection() {
|
187 |
return getMapControl().getProjection();
|
188 |
} |
189 |
|
190 |
}; |
191 |
} |
192 |
return this.prepareContext; |
193 |
} |
194 |
|
195 |
} |