svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / TableEditAttributes.java @ 47433
History | View | Annotate | Download (25.6 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 |
package org.gvsig.app.extension; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.nio.charset.StandardCharsets; |
33 |
import java.util.Collections; |
34 |
import java.util.Iterator; |
35 |
import java.util.Objects; |
36 |
import javax.swing.AbstractAction; |
37 |
import javax.swing.Action; |
38 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
39 |
import static javax.swing.Action.NAME; |
40 |
import javax.swing.JOptionPane; |
41 |
import javax.swing.event.ChangeEvent; |
42 |
import org.apache.commons.codec.binary.Hex; |
43 |
import org.apache.commons.io.FileUtils; |
44 |
import org.apache.commons.lang3.StringUtils; |
45 |
import org.apache.commons.lang3.math.NumberUtils; |
46 |
import org.gvsig.andami.IconThemeHelper; |
47 |
import org.gvsig.andami.plugins.Extension; |
48 |
import org.gvsig.app.ApplicationLocator; |
49 |
import org.gvsig.app.ApplicationManager; |
50 |
import org.gvsig.app.project.Project; |
51 |
import org.gvsig.app.project.ProjectManager; |
52 |
import org.gvsig.app.project.documents.Document; |
53 |
import org.gvsig.app.project.documents.table.TableDocument; |
54 |
import org.gvsig.app.project.documents.table.TableManager; |
55 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
56 |
import org.gvsig.app.project.documents.view.ViewDocument; |
57 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
58 |
import org.gvsig.fmap.dal.DALLocator; |
59 |
import org.gvsig.fmap.dal.DataManager; |
60 |
import org.gvsig.fmap.dal.DataStoreParameters; |
61 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
62 |
import org.gvsig.fmap.dal.DataTypes; |
63 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
64 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
65 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
66 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
68 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
69 |
import org.gvsig.fmap.dal.feature.FeatureType; |
70 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
71 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
72 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
73 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
74 |
import org.gvsig.tools.ToolsLocator; |
75 |
import org.gvsig.tools.folders.FoldersManager; |
76 |
import org.gvsig.tools.i18n.I18nManager; |
77 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
78 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
79 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
80 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
81 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
82 |
import org.gvsig.tools.util.ToolsUtilLocator; |
83 |
|
84 |
/**
|
85 |
* Extensi?n que abre la ventana para cambiar la configuraci?n de la estructura
|
86 |
* de la tabla.
|
87 |
*
|
88 |
*/
|
89 |
@SuppressWarnings("UseSpecificCatch") |
90 |
public class TableEditAttributes extends Extension { |
91 |
|
92 |
@Override
|
93 |
public void initialize() { |
94 |
IconThemeHelper.registerIcon("action", "table-column-manager", this); |
95 |
IconThemeHelper.registerIcon("action", "table-add-column", this); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void postInitialize() { |
100 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
101 |
cfgActionsManager.addConfigurableAction(FeatureTypePanel.CONFIGURABLE_PANEL_ID, new ShowAsTableAction());
|
102 |
cfgActionsManager.addConfigurableAction(FeatureTypePanel.CONFIGURABLE_PANEL_ID, new WriteToDALFileAction());
|
103 |
cfgActionsManager.addConfigurableAction(FeatureTypePanel.CONFIGURABLE_PANEL_ID, new WriteToDALFileHexAction());
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public boolean canQueryByAction() { |
108 |
return true; |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void execute(String s) { |
113 |
final I18nManager i18n = ToolsLocator.getI18nManager();
|
114 |
final WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
|
115 |
final DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
|
116 |
final DataManager dataMamager = DALLocator.getDataManager();
|
117 |
final ApplicationManager application = ApplicationLocator.getManager();
|
118 |
|
119 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
120 |
if (tabledoc == null) { |
121 |
return;
|
122 |
} |
123 |
// final FeatureStore featureStore = tabledoc.getStore();
|
124 |
final FeatureTableDocumentPanel tablePanel = (FeatureTableDocumentPanel) tabledoc.getMainComponent();
|
125 |
final FeatureStore featureStore = tablePanel.getFeatureStore();
|
126 |
|
127 |
if ("table-column-manager".equalsIgnoreCase(s)) { |
128 |
try {
|
129 |
ApplicationManager aplication = ApplicationLocator.getManager(); |
130 |
final FeatureType featureType = featureStore.getDefaultFeatureType();
|
131 |
final EditableFeatureType editableFeatureType = featureType.getEditable();
|
132 |
final FeatureTypePanel panel = dataSwingManager.createFeatureTypePanel();
|
133 |
ViewDocument viewdoc = (ViewDocument) application.getCurrentProject().getFirstDocument(ViewDocument.class); |
134 |
if( viewdoc != null ) { |
135 |
panel.setDefaultProjection(viewdoc.getProjection()); |
136 |
} |
137 |
final ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager();
|
138 |
|
139 |
ConfigurableActionsMamager.ActionsController actionController = |
140 |
cfgActionsManager.getConfigurableActionsController( |
141 |
FeatureTypePanel.CONFIGURABLE_PANEL_ID |
142 |
); |
143 |
actionController.addAction(new WriteOpenDataStoreParametersToFileHex(featureStore.getParameters()));
|
144 |
|
145 |
panel.put(editableFeatureType); |
146 |
|
147 |
int mode = featureStore.isEditing()
|
148 |
? FeatureTypePanel.MODE_EDIT_ALL |
149 |
: FeatureTypePanel.MODE_EDIT_ONLY_METADATA; |
150 |
DataStoreProviderFactory factory = featureStore.getProviderFactory(); |
151 |
if (factory instanceof FeatureStoreProviderFactory) { |
152 |
FeatureStoreProviderFactory ffactory = (FeatureStoreProviderFactory) factory; |
153 |
if (ffactory.allowEditableFeatureType() == FeatureStoreProviderFactory.NO) {
|
154 |
mode = FeatureTypePanel.MODE_SHOW_ONLY; |
155 |
} |
156 |
} |
157 |
String extraMsg = Objects.toString(featureStore.getProperty(DataManager.DAL_FEATURETYPE_MODE_EDIT_MSG),null); |
158 |
if( StringUtils.isNotBlank(extraMsg) ) {
|
159 |
extraMsg = "\n"+i18n.getTranslation(extraMsg);
|
160 |
} else {
|
161 |
extraMsg = "";
|
162 |
} |
163 |
switch(mode) {
|
164 |
case FeatureTypePanel.MODE_SHOW_ONLY:
|
165 |
break;
|
166 |
case FeatureTypePanel.MODE_EDIT_ONLY_METADATA:
|
167 |
int newmode = NumberUtils.toInt(Objects.toString(
|
168 |
featureStore.getProperty(DataManager.DAL_FEATURETYPE_MODE_EDIT) |
169 |
), |
170 |
mode |
171 |
); |
172 |
switch(newmode) {
|
173 |
case FeatureTypePanel.MODE_SHOW_ONLY:
|
174 |
mode = newmode; |
175 |
break;
|
176 |
case FeatureTypePanel.MODE_EDIT_ONLY_METADATA:
|
177 |
break;
|
178 |
case FeatureTypePanel.MODE_EDIT_ALL:
|
179 |
mode = FeatureTypePanel.MODE_EDIT_ONLY_METADATA; |
180 |
break;
|
181 |
} |
182 |
break;
|
183 |
case FeatureTypePanel.MODE_EDIT_ALL:
|
184 |
mode = NumberUtils.toInt(Objects.toString( |
185 |
featureStore.getProperty(DataManager.DAL_FEATURETYPE_MODE_EDIT) |
186 |
), |
187 |
mode |
188 |
); |
189 |
break;
|
190 |
} |
191 |
|
192 |
|
193 |
switch(mode) {
|
194 |
case FeatureTypePanel.MODE_SHOW_ONLY:
|
195 |
aplication.messageDialog( |
196 |
i18n.getTranslation("_The_table_dont_allow_edit_columns")+extraMsg,
|
197 |
i18n.getTranslation("_Warning"),
|
198 |
JOptionPane.INFORMATION_MESSAGE);
|
199 |
|
200 |
break;
|
201 |
case FeatureTypePanel.MODE_EDIT_ONLY_METADATA:
|
202 |
if( featureStore.isEditing() ) {
|
203 |
aplication.messageDialog( |
204 |
i18n.getTranslation("_The_table_is_not_in_edit_mode")+
|
205 |
"\n" +
|
206 |
i18n.getTranslation("_You_can_only_add_virtual_fields_and_modify_some_table_data_metadata") +
|
207 |
extraMsg, |
208 |
i18n.getTranslation("_Warning"),
|
209 |
JOptionPane.INFORMATION_MESSAGE);
|
210 |
} else {
|
211 |
aplication.messageDialog( |
212 |
i18n.getTranslation("_The_table_only_allow_edit_metadata_of_columns")+
|
213 |
"\n" +
|
214 |
i18n.getTranslation("_You_can_only_add_virtual_fields_and_modify_some_table_data_metadata") +
|
215 |
extraMsg, |
216 |
i18n.getTranslation("_Warning"),
|
217 |
JOptionPane.INFORMATION_MESSAGE);
|
218 |
} |
219 |
break;
|
220 |
case FeatureTypePanel.MODE_EDIT_ALL:
|
221 |
if( StringUtils.isNotBlank(extraMsg) ) {
|
222 |
aplication.messageDialog( |
223 |
extraMsg, |
224 |
i18n.getTranslation("_Warning"),
|
225 |
JOptionPane.INFORMATION_MESSAGE);
|
226 |
} |
227 |
break;
|
228 |
} |
229 |
panel.setMode(mode); |
230 |
String title = application.makeTitle("_Column_manager", tabledoc.getName(), featureStore.getName()); |
231 |
final Dialog dialog = winManager.createDialog( |
232 |
panel.asJComponent(), |
233 |
title, |
234 |
null,
|
235 |
WindowManager_v2.BUTTONS_OK_CANCEL |
236 |
); |
237 |
if( mode == FeatureTypePanel.MODE_SHOW_ONLY) {
|
238 |
dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, false);
|
239 |
} |
240 |
panel.addChangeListener((ChangeEvent e) -> {
|
241 |
if (panel.isEditing()) {
|
242 |
dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, false);
|
243 |
} else {
|
244 |
dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, true);
|
245 |
} |
246 |
}); |
247 |
dialog.addActionListener((ActionEvent e) -> {
|
248 |
if (dialog.getAction() != WindowManager_v2.BUTTON_OK) {
|
249 |
return;
|
250 |
} |
251 |
try {
|
252 |
panel.fetch(editableFeatureType); |
253 |
|
254 |
FeatureQuery query = tablePanel.getTablePanel().getFeatureQuery(); |
255 |
if (query != null) { |
256 |
FeatureQueryOrder order = query.getOrder(); |
257 |
if (order != null) { |
258 |
Iterator<FeatureQueryOrder.FeatureQueryOrderMember> it = order.iterator();
|
259 |
while (it.hasNext()) {
|
260 |
FeatureQueryOrder.FeatureQueryOrderMember orderMember = it.next(); |
261 |
String attrName = orderMember.getAttributeName();
|
262 |
if(editableFeatureType.getAttributeDescriptor(attrName)==null && !orderMember.hasEvaluator()){ |
263 |
// int n = ToolsSwingLocator.getThreadSafeDialogsManager().confirmDialog(
|
264 |
// i18n.getTranslation(
|
265 |
// "_You_are_trying_to_remove_the_column_XcolumnNameX_that_is_being_sorted_by_Do_you_wish_to_continue",
|
266 |
// new String[]{attrName}
|
267 |
// ),
|
268 |
// i18n.getTranslation("_Rename_column"),
|
269 |
// JOptionPane.OK_CANCEL_OPTION,
|
270 |
// JOptionPane.QUESTION_MESSAGE,
|
271 |
// "_You_are_trying_to_remove_the_column_XcolumnNameX_that_is_being_sorted_by_Do_you_wish_to_continue"
|
272 |
// );
|
273 |
// if (n != JOptionPane.OK_OPTION) {
|
274 |
// return;
|
275 |
// }
|
276 |
it.remove(); |
277 |
} |
278 |
} |
279 |
} |
280 |
} |
281 |
|
282 |
featureStore.update(editableFeatureType); |
283 |
dataMamager.clearAvailableValuesCache(); |
284 |
} catch (Exception ex) { |
285 |
logger.warn("Problems updating featuretype.", ex);
|
286 |
aplication.messageDialog( |
287 |
i18n.getTranslation("_Problems_updating_columns_information") +
|
288 |
"\n" +
|
289 |
i18n.getTranslation("_see_error_log_for_more_information"),
|
290 |
i18n.getTranslation("_Warning"),
|
291 |
JOptionPane.WARNING_MESSAGE);
|
292 |
} |
293 |
}); |
294 |
|
295 |
Dimension screensize = ApplicationLocator.getApplicationManager().getUIManager().getInternalSize();
|
296 |
Dimension panelsize = panel.asJComponent().getPreferredSize();
|
297 |
ToolsSwingUtils.ensureHeightWitdh( |
298 |
panel.asJComponent(), |
299 |
Math.max(3*(screensize.height/4), panelsize.height), |
300 |
Math.max(2*(screensize.width/4), panelsize.width), |
301 |
7*(screensize.height/8), |
302 |
3*(screensize.width/4) |
303 |
); |
304 |
dialog.show(WindowManager.MODE.WINDOW, |
305 |
Collections.singletonMap("align", GridBagConstraints.CENTER) |
306 |
); |
307 |
} catch (Exception ex) { |
308 |
logger.warn("Problems show FeatureTypePanel.", ex);
|
309 |
} |
310 |
|
311 |
} else if ("table-add-column".equals(s)) { |
312 |
try {
|
313 |
final FeatureType featureType = featureStore.getDefaultFeatureType();
|
314 |
final FeatureTypeAttributePanel panel = dataSwingManager.createFeatureTypeAttributePanel();
|
315 |
panel.clean(); |
316 |
panel.setNameAsNew(featureType); |
317 |
panel.setMode(FeatureTypePanel.MODE_EDIT_ALL); |
318 |
final Dialog dialog = winManager.createDialog( |
319 |
panel.asJComponent(), |
320 |
i18n.getTranslation("_New_field") + " - " + tabledoc.getName(), |
321 |
null,
|
322 |
WindowManager_v2.BUTTONS_OK_CANCEL |
323 |
); |
324 |
dialog.setAutoclose(false);
|
325 |
dialog.addActionListener(new ActionListener() { |
326 |
@Override
|
327 |
public void actionPerformed(ActionEvent e) { |
328 |
if (dialog.getAction() != WindowManager_v2.BUTTONS_OK) {
|
329 |
panel.asJComponent().setVisible(false);
|
330 |
return;
|
331 |
} |
332 |
if (!featureStore.isEditing()) {
|
333 |
panel.asJComponent().setVisible(false);
|
334 |
return;
|
335 |
} |
336 |
try {
|
337 |
EditableFeatureType editableFeatureType = featureType.getEditable(); |
338 |
EditableFeatureAttributeDescriptor descriptor = editableFeatureType.add( |
339 |
panel.getName(), |
340 |
DataTypes.STRING |
341 |
); |
342 |
if(panel.fetch(descriptor)!=null) { |
343 |
featureStore.update(editableFeatureType); |
344 |
panel.asJComponent().setVisible(false);
|
345 |
}; |
346 |
} catch (Exception ex) { |
347 |
logger.warn("Problems updating featuretype.", ex);
|
348 |
} |
349 |
} |
350 |
}); |
351 |
dialog.show(WindowManager.MODE.WINDOW, |
352 |
Collections.singletonMap("align", GridBagConstraints.CENTER) |
353 |
); |
354 |
} catch (Exception ex) { |
355 |
logger.warn("Problems show FeatureTypeAttributePanel.", ex);
|
356 |
} |
357 |
|
358 |
} |
359 |
} |
360 |
public static class WriteToDALFileAction extends AbstractAction { |
361 |
|
362 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
363 |
public WriteToDALFileAction() {
|
364 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
365 |
|
366 |
this.putValue(NAME, i18n.getTranslation("_Save_as_DAL_file")); |
367 |
this.putValue(ACTION_COMMAND_KEY, "WriteToDALFile"); |
368 |
} |
369 |
|
370 |
@Override
|
371 |
public void actionPerformed(ActionEvent ae) { |
372 |
FeatureTypePanel panel = (FeatureTypePanel) ae.getSource(); |
373 |
EditableFeatureType featureType = panel.fetch(null);
|
374 |
|
375 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
376 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
377 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
378 |
File[] f = application.showSaveFileDialog( |
379 |
i18n.getTranslation("_Save_as_DAL_file"),
|
380 |
foldersManager.getLastPath("SaveAsDALFile", null) |
381 |
); |
382 |
if( f==null || f.length==0 ) { |
383 |
return;
|
384 |
} |
385 |
foldersManager.setLastPath("SaveAsDALFile", f[0].getParentFile()); |
386 |
featureType.writeAsDALFile(f[0]);
|
387 |
} |
388 |
} |
389 |
|
390 |
public static class WriteToDALFileHexAction extends AbstractAction { |
391 |
|
392 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
393 |
public WriteToDALFileHexAction() {
|
394 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
395 |
|
396 |
this.putValue(NAME, i18n.getTranslation("_Save_as_DAL_file_hex")); |
397 |
this.putValue(ACTION_COMMAND_KEY, "WriteToDALFileHex"); |
398 |
} |
399 |
|
400 |
@Override
|
401 |
public void actionPerformed(ActionEvent ae) { |
402 |
FeatureTypePanel panel = (FeatureTypePanel) ae.getSource(); |
403 |
EditableFeatureType featureType = panel.fetch(null);
|
404 |
|
405 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
406 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
407 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
408 |
File[] f = application.showSaveFileDialog( |
409 |
i18n.getTranslation("_Save_as_DAL_file_hex"),
|
410 |
foldersManager.getLastPath("SaveAsDALFileHex", null) |
411 |
); |
412 |
if (f == null || f.length == 0) { |
413 |
return;
|
414 |
} |
415 |
foldersManager.setLastPath("SaveAsDALFileHex", f[0].getParentFile()); |
416 |
featureType.writeAsDALFile(f[0], "hex"); |
417 |
} |
418 |
} |
419 |
|
420 |
public static class WriteOpenDataStoreParametersToFileHex extends AbstractAction { |
421 |
|
422 |
private DataStoreParameters params;
|
423 |
|
424 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
425 |
public WriteOpenDataStoreParametersToFileHex(DataStoreParameters params) {
|
426 |
this.params = params;
|
427 |
|
428 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
429 |
|
430 |
this.putValue(NAME, i18n.getTranslation("_Save_OpenDataStoreParameters_hex")); |
431 |
this.putValue(ACTION_COMMAND_KEY, "WriteOpenDataStoreParametersToFileHex"); |
432 |
} |
433 |
|
434 |
@Override
|
435 |
public void actionPerformed(ActionEvent ae) { |
436 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
437 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
438 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
439 |
File[] f = application.showSaveFileDialog( |
440 |
i18n.getTranslation("_Save_OpenDataStoreParameters_hex"),
|
441 |
foldersManager.getLastPath("WriteOpenDataStoreParametersToFileHex", null) |
442 |
); |
443 |
if (f == null || f.length == 0) { |
444 |
return;
|
445 |
} |
446 |
foldersManager.setLastPath("WriteOpenDataStoreParametersToFileHex", f[0].getParentFile()); |
447 |
try {
|
448 |
FileUtils.write( |
449 |
f[0],
|
450 |
Hex.encodeHexString(this.params.toByteArray()),
|
451 |
StandardCharsets.UTF_8 |
452 |
); |
453 |
} catch (IOException ex) { |
454 |
logger.warn("Can't save parameters to file '"+Objects.toString(f[0]), ex); |
455 |
application.messageDialog( |
456 |
i18n.getTranslation("_Cant_save_parameters_to_file")+
|
457 |
"\n"+
|
458 |
i18n.getTranslation("_See_log_for_details"),
|
459 |
i18n.getTranslation("_Save_parameters_as_hex"),
|
460 |
JOptionPane.WARNING_MESSAGE
|
461 |
); |
462 |
} |
463 |
} |
464 |
} |
465 |
|
466 |
public static class ShowAsTableAction extends AbstractAction { |
467 |
|
468 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
469 |
public ShowAsTableAction() {
|
470 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
471 |
|
472 |
this.putValue(NAME, i18n.getTranslation("_Show_as_table")); |
473 |
this.putValue(ACTION_COMMAND_KEY, "ShowAsTable"); |
474 |
this.putValue(
|
475 |
Action.SMALL_ICON,
|
476 |
ToolsSwingLocator.getIconThemeManager().getCurrent().get("layer-show-attributes-table")
|
477 |
); |
478 |
} |
479 |
|
480 |
@Override
|
481 |
public void actionPerformed(ActionEvent ae) { |
482 |
FeatureTypePanel panel = (FeatureTypePanel) ae.getSource(); |
483 |
EditableFeatureType featureType = panel.fetch(null);
|
484 |
FeatureStore store = featureType.getAsFeatureStore(); |
485 |
|
486 |
ProjectManager projectManager = ApplicationLocator.getManager().getProjectManager(); |
487 |
Project project = projectManager.getCurrentProject(); |
488 |
TableDocument tableDoc = (TableDocument) project.getDocument(store.getName(), TableManager.TYPENAME); |
489 |
if (tableDoc == null) { |
490 |
tableDoc = (TableDocument) projectManager.createDocument(TableManager.TYPENAME); |
491 |
tableDoc.setStore(store); |
492 |
tableDoc.setName(store.getName()); |
493 |
project.addDocument(tableDoc); |
494 |
} |
495 |
ApplicationLocator.getManager().getUIManager().addWindow(tableDoc.getMainWindow()); |
496 |
} |
497 |
} |
498 |
|
499 |
@Override
|
500 |
public boolean isEnabled() { |
501 |
ApplicationManager application = ApplicationLocator.getManager(); |
502 |
|
503 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
504 |
if (tabledoc == null) { |
505 |
return false; |
506 |
} |
507 |
return tabledoc.getStore().isEditing();
|
508 |
} |
509 |
|
510 |
@Override
|
511 |
public boolean isVisible() { |
512 |
ApplicationManager application = ApplicationLocator.getManager(); |
513 |
|
514 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
515 |
return tabledoc != null; |
516 |
} |
517 |
|
518 |
@Override
|
519 |
public boolean isVisible(String action) { |
520 |
return this.isVisible(); |
521 |
} |
522 |
|
523 |
@Override
|
524 |
public boolean isEnabled(String action) { |
525 |
ApplicationManager application = ApplicationLocator.getManager(); |
526 |
|
527 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
528 |
if (tabledoc == null) { |
529 |
return false; |
530 |
} |
531 |
if ("table-column-manager".equalsIgnoreCase(action)) { |
532 |
return true; |
533 |
|
534 |
} else if ("table-add-column".equals(action)) { |
535 |
FeatureStore store = tabledoc.getStore(); |
536 |
|
537 |
DataStoreProviderFactory factory = store.getProviderFactory(); |
538 |
if (factory instanceof FeatureStoreProviderFactory) { |
539 |
FeatureStoreProviderFactory ffactory = (FeatureStoreProviderFactory) factory; |
540 |
if (ffactory.allowEditableFeatureType() == FeatureStoreProviderFactory.NO) {
|
541 |
return false; |
542 |
} else {
|
543 |
return tabledoc.getStore().isEditing();
|
544 |
} |
545 |
} else {
|
546 |
return tabledoc.getStore().isEditing();
|
547 |
} |
548 |
|
549 |
} |
550 |
return false; |
551 |
} |
552 |
|
553 |
} |