Revision 44130 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
TableEditAttributes.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.extension; |
25 | 25 |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
26 | 28 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.PluginServices; |
|
28 |
import org.gvsig.andami.messages.NotificationManager; |
|
29 | 29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
30 |
import org.gvsig.app.ApplicationLocator; |
|
31 |
import org.gvsig.app.ApplicationManager; |
|
31 | 32 |
import org.gvsig.app.project.documents.table.TableDocument; |
32 |
import org.gvsig.app.project.documents.table.TableOperations;
|
|
33 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
|
|
34 |
import org.gvsig.app.project.documents.table.gui.FeatureTypeEditingPanel;
|
|
35 |
import org.gvsig.fmap.dal.exception.DataException;
|
|
33 |
import org.gvsig.app.project.documents.table.TableManager;
|
|
34 |
import org.gvsig.fmap.dal.DataTypes;
|
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
|
|
36 |
import org.gvsig.fmap.dal.feature.EditableFeatureType;
|
|
36 | 37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.i18n.Messages; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
39 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
40 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
|
41 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
|
42 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
|
43 |
import org.gvsig.tools.ToolsLocator; |
|
44 |
import org.gvsig.tools.i18n.I18nManager; |
|
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
46 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
47 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
38 | 49 |
|
39 | 50 |
/** |
40 | 51 |
* Extensi?n que abre la ventana para cambiar la configuraci?n de la estructura |
41 | 52 |
* de la tabla. |
42 | 53 |
* |
43 |
* @author Vicente Caballero Navarro |
|
44 | 54 |
*/ |
55 |
@SuppressWarnings("UseSpecificCatch") |
|
45 | 56 |
public class TableEditAttributes extends Extension { |
46 | 57 |
|
47 |
private FeatureTableDocumentPanel table = null; |
|
48 |
private TableOperations featureTableOperations = null; |
|
58 |
public void initialize() { |
|
59 |
IconThemeHelper.registerIcon("action", "table-column-manager", this); |
|
60 |
IconThemeHelper.registerIcon("action", "table-add-column", this); |
|
61 |
} |
|
49 | 62 |
|
50 |
/** |
|
51 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String) |
|
52 |
*/ |
|
63 |
@Override |
|
64 |
public boolean canQueryByAction() { |
|
65 |
return true; |
|
66 |
} |
|
67 |
|
|
53 | 68 |
public void execute(String s) { |
69 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
70 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
71 |
DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
|
72 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
73 |
|
|
74 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
|
75 |
if( tabledoc == null ) { |
|
76 |
return; |
|
77 |
} |
|
78 |
final FeatureStore featureStore = tabledoc.getStore(); |
|
79 |
|
|
54 | 80 |
if( "table-column-manager".equalsIgnoreCase(s)) { |
55 |
TableDocument pt = table.getModel(); |
|
56 |
FeatureStore fs = pt.getStore(); |
|
57 |
try { |
|
58 |
PluginServices.getMDIManager().addWindow( |
|
59 |
new FeatureTypeEditingPanel(fs)); |
|
60 |
} catch (DataException e) { |
|
61 |
NotificationManager.addError( |
|
62 |
PluginServices.getText(this, "create_editabletype"), e); |
|
63 |
} |
|
64 |
} else { |
|
81 |
try { |
|
82 |
final FeatureType featureType = featureStore.getDefaultFeatureType(); |
|
83 |
final EditableFeatureType editableFeatureType = featureType.getEditable(); |
|
84 |
final FeatureTypePanel panel = dataSwingManager.createFeatureTypePanel(); |
|
85 |
panel.put(editableFeatureType); |
|
86 |
panel.setEditable(featureStore.isEditing()); |
|
87 |
final Dialog dialog = winManager.createDialog( |
|
88 |
panel.asJComponent(), |
|
89 |
i18n.getTranslation("field_manager") + " - " + tabledoc.getName(), |
|
90 |
null, |
|
91 |
featureStore.isEditing()? WindowManager_v2.BUTTONS_OK_CANCEL:WindowManager_v2.BUTTONS_OK |
|
92 |
); |
|
93 |
dialog.addActionListener(new ActionListener() { |
|
94 |
@Override |
|
95 |
public void actionPerformed(ActionEvent e) { |
|
96 |
if( dialog.getAction()!=WindowManager_v2.BUTTONS_OK ) { |
|
97 |
return; |
|
98 |
} |
|
99 |
if( !featureStore.isEditing() ) { |
|
100 |
return; |
|
101 |
} |
|
102 |
try { |
|
103 |
panel.fetch(editableFeatureType); |
|
104 |
featureStore.update(editableFeatureType); |
|
105 |
} catch (Exception ex) { |
|
106 |
logger.warn("Problems updating featuretype.", ex); |
|
107 |
} |
|
108 |
} |
|
109 |
}); |
|
110 |
dialog.show(WindowManager.MODE.WINDOW); |
|
111 |
} catch (Exception ex) { |
|
112 |
logger.warn("Problems show FeatureTypePanel.", ex); |
|
113 |
} |
|
65 | 114 |
|
66 |
try { |
|
67 |
if ("table-add-column".equals(s)) { |
|
68 |
featureTableOperations.setTablePanel(table); |
|
69 |
featureTableOperations.insertAttributes(table |
|
70 |
.getTablePanel().getTable()); |
|
71 |
} |
|
72 |
} catch (DataException de) { |
|
73 |
NotificationManager.showMessageError( |
|
74 |
Messages.getText("update_featuretype_error"), null); |
|
75 |
} |
|
115 |
} else if ("table-add-column".equals(s)) { |
|
116 |
try { |
|
117 |
final FeatureType featureType = featureStore.getDefaultFeatureType(); |
|
118 |
final FeatureTypeAttributePanel panel = dataSwingManager.createFeatureTypeAttributePanel(); |
|
119 |
panel.clean(); |
|
120 |
panel.setNameAsNew(featureType); |
|
121 |
final Dialog dialog = winManager.createDialog( |
|
122 |
panel.asJComponent(), |
|
123 |
i18n.getTranslation("_New_field") + " - " + tabledoc.getName(), |
|
124 |
null, |
|
125 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
126 |
); |
|
127 |
dialog.addActionListener(new ActionListener() { |
|
128 |
@Override |
|
129 |
public void actionPerformed(ActionEvent e) { |
|
130 |
if( dialog.getAction()!=WindowManager_v2.BUTTONS_OK ) { |
|
131 |
return; |
|
132 |
} |
|
133 |
if( !featureStore.isEditing() ) { |
|
134 |
return; |
|
135 |
} |
|
136 |
try { |
|
137 |
EditableFeatureType editableFeatureType = featureType.getEditable(); |
|
138 |
EditableFeatureAttributeDescriptor descriptor = editableFeatureType.add( |
|
139 |
panel.getName(), |
|
140 |
DataTypes.STRING |
|
141 |
); |
|
142 |
panel.fetch(descriptor); |
|
143 |
featureStore.update(editableFeatureType); |
|
144 |
} catch (Exception ex) { |
|
145 |
logger.warn("Problems updating featuretype.", ex); |
|
146 |
} |
|
147 |
} |
|
148 |
}); |
|
149 |
dialog.show(WindowManager.MODE.WINDOW); |
|
150 |
} catch (Exception ex) { |
|
151 |
logger.warn("Problems show FeatureTypeAttributePanel.", ex); |
|
152 |
} |
|
76 | 153 |
|
77 | 154 |
} |
78 | 155 |
} |
79 | 156 |
|
80 |
/** |
|
81 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
82 |
*/ |
|
83 |
public void initialize() { |
|
84 |
IconThemeHelper.registerIcon("action", "table-column-manager", this); |
|
85 |
IconThemeHelper.registerIcon("action", "table-add-column", this); |
|
86 |
featureTableOperations = TableOperations.getInstance(); |
|
157 |
public boolean isEnabled() { |
|
158 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
159 |
|
|
160 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
|
161 |
if( tabledoc == null ) { |
|
162 |
return false; |
|
163 |
} |
|
164 |
return tabledoc.getStore().isEditing(); |
|
87 | 165 |
} |
88 | 166 |
|
89 |
public boolean isEnabled() { |
|
90 |
FeatureStore fs = table.getModel().getStore(); |
|
91 |
return fs.isEditing(); |
|
167 |
public boolean isVisible() { |
|
168 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
169 |
|
|
170 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
|
171 |
return tabledoc!=null; |
|
92 | 172 |
} |
93 | 173 |
|
94 |
/** |
|
95 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
96 |
*/ |
|
97 |
public boolean isVisible() { |
|
98 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
99 |
if (v != null && v instanceof FeatureTableDocumentPanel) { |
|
100 |
table = (FeatureTableDocumentPanel) v; |
|
174 |
@Override |
|
175 |
public boolean isVisible(String action) { |
|
176 |
return this.isVisible(); |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public boolean isEnabled(String action) { |
|
181 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
182 |
|
|
183 |
TableDocument tabledoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME); |
|
184 |
if( tabledoc == null ) { |
|
185 |
return false; |
|
186 |
} |
|
187 |
if( "table-column-manager".equalsIgnoreCase(action)) { |
|
101 | 188 |
return true; |
189 |
|
|
190 |
} else if ("table-add-column".equals(action)) { |
|
191 |
return tabledoc.getStore().isEditing(); |
|
192 |
|
|
102 | 193 |
} |
103 | 194 |
return false; |
104 | 195 |
} |
105 |
|
|
196 |
|
|
106 | 197 |
} |
Also available in: Unified diff