gvsig-derived-geometries / org.gvsig.derivedgeometries / trunk / org.gvsig.derivedgeometries / org.gvsig.derivedgeometries.swing / org.gvsig.derivedgeometries.swing.impl / src / main / java / org / gvsig / derivedgeometries / swing / impl / panels / DefaultDerivedGeometriesPanel.java @ 68
History | View | Annotate | Download (7.01 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2014 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.derivedgeometries.swing.impl.panels; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
|
28 |
import javax.swing.JComponent; |
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
35 |
import org.gvsig.derivedgeometries.swing.api.exceptions.DerivedGeometriesException; |
36 |
import org.gvsig.derivedgeometries.swing.api.exceptions.ValidateSourceLayerException; |
37 |
import org.gvsig.derivedgeometries.swing.api.panels.DerivedGeometriesPanel; |
38 |
import org.gvsig.derivedgeometries.swing.impl.views.DerivedGeometriesPanelView; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.i18n.I18nManager; |
43 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
44 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
45 |
|
46 |
public class DefaultDerivedGeometriesPanel extends DerivedGeometriesPanelView |
47 |
implements DerivedGeometriesPanel {
|
48 |
|
49 |
private static final long serialVersionUID = -2874430817496441084L; |
50 |
|
51 |
private static final Logger LOG = LoggerFactory |
52 |
.getLogger(DefaultDerivedGeometriesPanel.class); |
53 |
|
54 |
public DefaultDerivedGeometriesPanel(MapControl theMapControl) {
|
55 |
super(theMapControl);
|
56 |
|
57 |
initNextButton(); |
58 |
initCancelButton(); |
59 |
} |
60 |
|
61 |
public JComponent asJComponent() { |
62 |
return this; |
63 |
} |
64 |
|
65 |
private void closeWindow() { |
66 |
setVisible(false);
|
67 |
} |
68 |
|
69 |
private void initCancelButton() { |
70 |
getCancelButton().addActionListener(new ActionListener() { |
71 |
|
72 |
public void actionPerformed(ActionEvent e) { |
73 |
|
74 |
DerivedGeometriesParameters parameters = null;
|
75 |
|
76 |
if (getLayerAndProcessSelectionPanel().asJComponent()
|
77 |
.isVisible()) { |
78 |
|
79 |
parameters = |
80 |
getLayerAndProcessSelectionPanel().getParameters(); |
81 |
|
82 |
} else if (getFeaturesControlPanel().asJComponent().isVisible()) { |
83 |
|
84 |
parameters = getFeaturesControlPanel().getParameters(); |
85 |
} |
86 |
|
87 |
if(parameters != null){ |
88 |
FeatureStore featureStore = parameters.getFeatureStore(); |
89 |
if (featureStore != null) { |
90 |
featureStore.dispose(); |
91 |
} |
92 |
} |
93 |
|
94 |
closeWindow(); |
95 |
} |
96 |
}); |
97 |
} |
98 |
|
99 |
private void initNextButton() { |
100 |
getNextButton().addActionListener(new ActionListener() { |
101 |
|
102 |
public void actionPerformed(ActionEvent e) { |
103 |
|
104 |
ThreadSafeDialogsManager dlgManager = |
105 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
106 |
|
107 |
if (getLayerAndProcessSelectionPanel().asJComponent()
|
108 |
.isVisible()) { |
109 |
|
110 |
// If selected source layer is not valid shows a dialog and
|
111 |
// finish method
|
112 |
try {
|
113 |
if (!validateSelectedSourceLayer()) {
|
114 |
|
115 |
String title = "_no_valid_source_layer"; |
116 |
String message = "_cant_process_this_type_of_layer"; |
117 |
dlgManager.messageDialog(message, title, |
118 |
JOptionPane.ERROR_MESSAGE);
|
119 |
return;
|
120 |
|
121 |
} |
122 |
} catch (DerivedGeometriesException ex) {
|
123 |
LOG.warn("Error validating source layer", ex);
|
124 |
return;
|
125 |
} |
126 |
|
127 |
if (validateLayerAndOutputLayerFields()) {
|
128 |
|
129 |
getLayerAndProcessSelectionPanel().doAccept(); |
130 |
|
131 |
DerivedGeometriesParameters parameters = |
132 |
getLayerAndProcessSelectionPanel().getParameters(); |
133 |
|
134 |
getLayerAndProcessSelectionPanel().asJComponent() |
135 |
.setVisible(false);
|
136 |
|
137 |
getFeaturesControlPanel().setParameters(parameters); |
138 |
getFeaturesControlPanel().asJComponent().setVisible( |
139 |
true);
|
140 |
|
141 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
142 |
getCancelButton().setText( |
143 |
i18nManager.getTranslation("finish"));
|
144 |
getNextButton().setText( |
145 |
i18nManager.getTranslation("generate"));
|
146 |
|
147 |
} else {
|
148 |
|
149 |
// If data fields is no valid shows a dialog and finish
|
150 |
// method
|
151 |
String title = "_no_valid_data"; |
152 |
String message =
|
153 |
"_no_valid_data_make_sure_data_are_valid";
|
154 |
dlgManager.messageDialog(message, title, |
155 |
JOptionPane.ERROR_MESSAGE);
|
156 |
return;
|
157 |
|
158 |
} |
159 |
} else if (getFeaturesControlPanel().asJComponent().isVisible()) { |
160 |
|
161 |
if (validateFeaturesControlPanelFields()) {
|
162 |
|
163 |
getFeaturesControlPanel().doAction(); |
164 |
|
165 |
} else {
|
166 |
|
167 |
// If data fields is no valid shows a dialog and finish
|
168 |
// method
|
169 |
String title = "_no_valid_data"; |
170 |
String message =
|
171 |
"_no_valid_data_make_sure_data_are_valid";
|
172 |
dlgManager.messageDialog(message, title, |
173 |
JOptionPane.ERROR_MESSAGE);
|
174 |
return;
|
175 |
|
176 |
} |
177 |
} |
178 |
} |
179 |
}); |
180 |
} |
181 |
|
182 |
private boolean validateLayerAndOutputLayerFields() { |
183 |
return getLayerAndProcessSelectionPanel().validateFields();
|
184 |
} |
185 |
|
186 |
private boolean validateFeaturesControlPanelFields() { |
187 |
return getFeaturesControlPanel().validateFields();
|
188 |
} |
189 |
|
190 |
private boolean validateSelectedSourceLayer() |
191 |
throws ValidateSourceLayerException {
|
192 |
return getLayerAndProcessSelectionPanel().validateSourceLayer();
|
193 |
} |
194 |
} |