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