svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.daltransform.app / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / LoadLayerWizardPanel.java @ 40558
History | View | Annotate | Download (10.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2009 {Iver T.I.} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.daltransform.swing.impl; |
30 |
|
31 |
import java.awt.Font; |
32 |
import java.awt.event.ItemEvent; |
33 |
import java.awt.event.ItemListener; |
34 |
import java.util.List; |
35 |
|
36 |
import javax.swing.JCheckBox; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JScrollPane; |
41 |
import javax.swing.JTextArea; |
42 |
|
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
import org.gvsig.andami.PluginServices; |
47 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
48 |
import org.gvsig.app.project.ProjectManager; |
49 |
import org.gvsig.app.project.documents.Document; |
50 |
import org.gvsig.app.project.documents.view.BaseViewDocument; |
51 |
import org.gvsig.app.project.documents.view.ViewManager; |
52 |
import org.gvsig.app.project.documents.view.gui.IView; |
53 |
import org.gvsig.daltransform.swing.DataTransformGui; |
54 |
import org.gvsig.fmap.dal.DataTypes; |
55 |
import org.gvsig.fmap.dal.exception.DataException; |
56 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
59 |
import org.gvsig.fmap.dal.feature.FeatureType; |
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
61 |
|
62 |
|
63 |
/**
|
64 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
65 |
*/
|
66 |
public class LoadLayerWizardPanel extends AbstractDataTransformWizardPanel implements ItemListener{ |
67 |
/**
|
68 |
*
|
69 |
*/
|
70 |
private static final long serialVersionUID = -7893735055404404591L; |
71 |
|
72 |
private static final Logger logger = LoggerFactory.getLogger(LoadLayerWizardPanel.class); |
73 |
private JCheckBox loadLayerCb = null; |
74 |
private JScrollPane messageScroll = null; |
75 |
private JTextArea messageTextArea = null; |
76 |
private JPanel northPanel = null; |
77 |
private JLabel selectViewLabel; |
78 |
private JComboBox selectViewCombo; |
79 |
private JPanel centerPanel; |
80 |
private FeatureStoreTransform transform = null; |
81 |
|
82 |
/**
|
83 |
* @param wizardComponents
|
84 |
*/
|
85 |
public LoadLayerWizardPanel() {
|
86 |
super();
|
87 |
|
88 |
initComponents(); |
89 |
initLabels(); |
90 |
addViews(); |
91 |
loadLayerCb.addItemListener(this);
|
92 |
itemStateChanged(null);
|
93 |
} |
94 |
|
95 |
private void initLabels(){ |
96 |
loadLayerCb.setText(PluginServices.getText(this, "transform_load_layer_query")); |
97 |
selectViewLabel.setText(PluginServices.getText(this, "transform_view_to_load")); |
98 |
} |
99 |
|
100 |
private void initComponents() { |
101 |
java.awt.GridBagConstraints gridBagConstraints; |
102 |
|
103 |
northPanel = new javax.swing.JPanel();
|
104 |
messageScroll = new javax.swing.JScrollPane();
|
105 |
messageTextArea = new javax.swing.JTextArea();
|
106 |
loadLayerCb = new javax.swing.JCheckBox();
|
107 |
selectViewLabel = new javax.swing.JLabel();
|
108 |
centerPanel = new javax.swing.JPanel();
|
109 |
selectViewCombo = new JComboBox(); |
110 |
|
111 |
setLayout(new java.awt.BorderLayout());
|
112 |
|
113 |
northPanel.setLayout(new java.awt.GridBagLayout());
|
114 |
|
115 |
messageScroll.setBorder(null);
|
116 |
|
117 |
messageTextArea.setColumns(20);
|
118 |
messageTextArea.setEditable(false);
|
119 |
messageTextArea.setLineWrap(true);
|
120 |
|
121 |
messageTextArea.setWrapStyleWord(true);
|
122 |
messageTextArea.setBackground(northPanel.getBackground()); |
123 |
Font fnt = messageTextArea.getFont();
|
124 |
fnt = fnt.deriveFont(Font.PLAIN);
|
125 |
messageTextArea.setFont(fnt); |
126 |
|
127 |
|
128 |
messageTextArea.setRows(5);
|
129 |
messageTextArea.setBorder(null);
|
130 |
messageScroll.setViewportView(messageTextArea); |
131 |
|
132 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
133 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
134 |
gridBagConstraints.gridx = 0;
|
135 |
gridBagConstraints.gridy = 0;
|
136 |
gridBagConstraints.weightx = 1.0;
|
137 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2); |
138 |
northPanel.add(messageScroll, gridBagConstraints); |
139 |
|
140 |
loadLayerCb.setText("jCheckBox1");
|
141 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
142 |
gridBagConstraints.gridx = 0;
|
143 |
gridBagConstraints.gridy = 1;
|
144 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
145 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
146 |
gridBagConstraints.weightx = 1.0;
|
147 |
gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 2); |
148 |
northPanel.add(loadLayerCb, gridBagConstraints); |
149 |
|
150 |
add(northPanel, java.awt.BorderLayout.NORTH); |
151 |
|
152 |
centerPanel.setLayout(new java.awt.GridBagLayout());
|
153 |
|
154 |
selectViewLabel.setText("jLabel1");
|
155 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
156 |
gridBagConstraints.gridx = 0;
|
157 |
gridBagConstraints.gridy = 0;
|
158 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
159 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
160 |
gridBagConstraints.weightx = 1.0;
|
161 |
gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 2); |
162 |
centerPanel.add(selectViewLabel, gridBagConstraints); |
163 |
|
164 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
165 |
gridBagConstraints.gridx = 0;
|
166 |
gridBagConstraints.gridy = 1;
|
167 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
168 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
169 |
gridBagConstraints.weightx = 1.0;
|
170 |
gridBagConstraints.weighty = 1.0;
|
171 |
gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 2); |
172 |
centerPanel.add(selectViewCombo, gridBagConstraints); |
173 |
|
174 |
add(centerPanel, java.awt.BorderLayout.CENTER); |
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
* @see org.gvsig.app.daltransform.impl.AbstractDataTransformWizardPanel#updatePanel()
|
180 |
*/
|
181 |
public void updatePanel() { |
182 |
//Gets the selected transformation
|
183 |
DataTransformGui featureTransformGui = getDataTransformWizard().getDataTransformGui(); |
184 |
|
185 |
//Gets the selected FeatureStore
|
186 |
FeatureStore featureStore = getFeatureStore(); |
187 |
|
188 |
//Apply the transformation
|
189 |
try {
|
190 |
transform = featureTransformGui.createFeatureStoreTransform(featureStore); |
191 |
|
192 |
if (getDataTransformWizard().isFeatureStoreLayer()){
|
193 |
updateGuiForLayer(transform); |
194 |
}else{
|
195 |
updateGuiForTable(transform); |
196 |
} |
197 |
} catch (DataException e) {
|
198 |
logger.error("Error creating the transformation", e);
|
199 |
} |
200 |
} |
201 |
|
202 |
/**
|
203 |
* Update the form when the transform has been applied in
|
204 |
* to a table
|
205 |
* @param transform
|
206 |
* @throws DataException
|
207 |
*/
|
208 |
private void updateGuiForTable(FeatureStoreTransform transform) throws DataException{ |
209 |
FeatureType featureType = transform.getDefaultFeatureType(); |
210 |
FeatureAttributeDescriptor[] featureAttributeDescriptors = featureType.getAttributeDescriptors();
|
211 |
boolean hasGeometry = false; |
212 |
for (int i=0 ; i<featureAttributeDescriptors.length ; i++){ |
213 |
if (featureAttributeDescriptors[i].getType() == DataTypes.GEOMETRY){
|
214 |
hasGeometry = true;
|
215 |
} |
216 |
} |
217 |
if (hasGeometry){
|
218 |
if (selectViewCombo.getItemCount() == 0){ |
219 |
messageTextArea.setText(PluginServices.getText(this, "transform_layout_not_view_to_load")); |
220 |
setLoadLayerVisible(false);
|
221 |
}else{
|
222 |
messageTextArea.setText(PluginServices.getText(this, "transform_layout_geometry")); |
223 |
setLoadLayerVisible(true);
|
224 |
} |
225 |
}else{
|
226 |
messageTextArea.setText(PluginServices.getText(this, "transform_layout_no_geometry")); |
227 |
setLoadLayerVisible(false);
|
228 |
} |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Set if it is possible or not lo load a layer
|
233 |
* from the transformation
|
234 |
* @param isVisible
|
235 |
*/
|
236 |
private void setLoadLayerVisible(boolean isVisible){ |
237 |
loadLayerCb.setVisible(isVisible); |
238 |
selectViewLabel.setVisible(isVisible); |
239 |
selectViewCombo.setVisible(isVisible); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* Add the project views
|
244 |
*/
|
245 |
private void addViews(){ |
246 |
selectViewCombo.removeAllItems(); |
247 |
|
248 |
List<Document> views = ProjectManager.getInstance().getCurrentProject().getDocuments(ViewManager.TYPENAME); |
249 |
for (Document view : views) { |
250 |
selectViewCombo.addItem(view); |
251 |
} |
252 |
// ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
|
253 |
// ArrayList<ProjectDocument> projects = ext.getProject().getDocumentsByType(ProjectViewFactory.registerName);
|
254 |
// for (int i=0 ; i<projects.size() ; i++){
|
255 |
// ProjectViewBase view = (ProjectViewBase)projects.get(i);
|
256 |
// ((DefaultListModel)selectViewList.getModel()).addElement(view);
|
257 |
// }
|
258 |
// if (selectViewList.getModel().getSize() > 0){
|
259 |
// hasViews = true;
|
260 |
// }
|
261 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
262 |
if (window instanceof IView){ |
263 |
selectViewCombo.setSelectedItem(window); |
264 |
} |
265 |
} |
266 |
|
267 |
public boolean isNextButtonEnabled() { |
268 |
return true; |
269 |
} |
270 |
|
271 |
|
272 |
/**
|
273 |
* Update the form when the transform has been applied in
|
274 |
* to a layer
|
275 |
* @param transform
|
276 |
* @throws DataException
|
277 |
*/
|
278 |
private void updateGuiForLayer(FeatureStoreTransform transform){ |
279 |
messageTextArea.setText(PluginServices.getText(this, "transform_layer")); |
280 |
setLoadLayerVisible(false);
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* @return if the layer has to be loaded
|
285 |
*/
|
286 |
public boolean isLayerLoaded(){ |
287 |
if (!loadLayerCb.isVisible()){
|
288 |
return false; |
289 |
} |
290 |
return loadLayerCb.isSelected();
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* @return the transform
|
295 |
*/
|
296 |
public FeatureStoreTransform getTransform() {
|
297 |
return transform;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* @return The mapcontext
|
302 |
*/
|
303 |
public MapContext getMapContext(){
|
304 |
Object obj = selectViewCombo.getSelectedItem();
|
305 |
if (obj != null){ |
306 |
return ((BaseViewDocument)obj).getMapContext();
|
307 |
} |
308 |
return null; |
309 |
} |
310 |
|
311 |
/* (non-Javadoc)
|
312 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
313 |
*/
|
314 |
public void itemStateChanged(ItemEvent arg0) { |
315 |
boolean isSelected = loadLayerCb.isSelected();
|
316 |
selectViewLabel.setEnabled(isSelected); |
317 |
selectViewCombo.setEnabled(isSelected); |
318 |
} |
319 |
|
320 |
/* (non-Javadoc)
|
321 |
* @see org.gvsig.app.daltransform.gui.FeatureTransformWizard#getPanelTitle()
|
322 |
*/
|
323 |
public String getPanelTitle() { |
324 |
return PluginServices.getText(this, "transform_apply"); |
325 |
} |
326 |
|
327 |
} |
328 |
|