Revision 42966 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/TableEditStopExtension.java

View differences:

TableEditStopExtension.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 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.
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 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.
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.app.extension;
25 24

  
......
66 65

  
67 66
public class TableEditStopExtension extends AbstractTableEditExtension {
68 67

  
69
    private static Logger logger =
70
        LoggerFactory.getLogger(TableEditStopExtension.class);
68
    private static Logger logger
69
            = LoggerFactory.getLogger(TableEditStopExtension.class);
71 70

  
72
	public void initialize() {
73
		super.initialize();
74
		IconThemeHelper.registerIcon("action", "table-stop-editing", this);
75
	}
71
    @Override
72
    public void initialize() {
73
        super.initialize();
74
        IconThemeHelper.registerIcon("action", "table-stop-editing", this);
75
    }
76 76

  
77 77
    public void execute(String actionCommand) {
78 78
        if ("table-stop-editing".equals(actionCommand)) {
......
83 83
                    EditingNotification.BEFORE_ENTER_EDITING_STORE,
84 84
                    doc,
85 85
                    doc.getStore());
86
            if( notification.isCanceled() ) {
86
            if (notification.isCanceled()) {
87 87
                return;
88 88
            }
89 89
            stopEditing(table);
......
101 101
        Object[] options = {
102 102
            PluginServices.getText(this, "_Guardar"),
103 103
            "       " + PluginServices.getText(this, "_Descartar") + "       ",
104
            PluginServices.getText(this, "_Continuar") };
104
            PluginServices.getText(this, "_Continuar")};
105 105

  
106 106
        JPanel explanation_panel = getExplanationPanel(table.getModel().getName());
107 107

  
108 108
        int resp = JOptionPane
109
            .showOptionDialog(
110
                    (Component) PluginServices.getMainFrame(),
111
                    explanation_panel,
112
                    PluginServices.getText(this, "stop_edition"),
113
                    JOptionPane.YES_NO_CANCEL_OPTION,
114
                    JOptionPane.QUESTION_MESSAGE, null, options,
115
                    options[2]);
109
                .showOptionDialog(
110
                        (Component) PluginServices.getMainFrame(),
111
                        explanation_panel,
112
                        PluginServices.getText(this, "stop_edition"),
113
                        JOptionPane.YES_NO_CANCEL_OPTION,
114
                        JOptionPane.QUESTION_MESSAGE, null, options,
115
                        options[2]);
116 116

  
117 117
        try {
118 118
            if (resp == JOptionPane.NO_OPTION) {
......
131 131
            }
132 132
        } catch (DataException e) {
133 133
            logger.error("While finishing or canceling table editing: "
134
                + e.getMessage(), e);
134
                    + e.getMessage(), e);
135 135
        }
136 136
    }
137 137

  
138
    /**
139
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
140
     */
141 138
    public boolean isEnabled() {
142 139
        return true;
143 140
    }
144 141

  
145
    /**
146
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
147
     */
142
    @Override
148 143
    public boolean isVisible() {
149 144
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
150 145

  
151 146
        if (v == null) {
152 147
            return false;
153
        } else
154
            if (v instanceof FeatureTableDocumentPanel
148
        } else if (v instanceof FeatureTableDocumentPanel
155 149
                && ((FeatureTableDocumentPanel) v).getModel().getStore()
156
                    .isEditing()) {
157
                table = (FeatureTableDocumentPanel) v;
158
                return true;
159
            } else {
160
                return false;
161
            }
150
                .isEditing()) {
151
            table = (FeatureTableDocumentPanel) v;
152
            return true;
153
        } else {
154
            return false;
155
        }
162 156
    }
163 157

  
164 158
    /**
......
167 161
     * unsaved editing table (and save them), and methods to check if the
168 162
     * extension has some associated background tasks.
169 163
     *
170
     * @author Vicente Caballero Navarro
171
     *
172 164
     */
173 165
    private class StopEditingStatus implements IExtensionStatus {
174 166

  
......
177 169
         * editing tables.
178 170
         *
179 171
         * @return true if the extension has some unsaved editing tables, false
180
         *         otherwise.
172
         * otherwise.
181 173
         */
182 174
        public boolean hasUnsavedData() {
183 175
            Project project = ProjectManager.getInstance().getCurrentProject();
......
199 191
         * background process which is currently running.
200 192
         *
201 193
         * @return true if the extension has some associated background process,
202
         *         false otherwise.
194
         * false otherwise.
203 195
         */
204 196
        public boolean hasRunningProcesses() {
205 197
            return false;
......
212 204
         * </p>
213 205
         *
214 206
         * @return An array of the associated background tasks, or null in case
215
         *         there is
216
         *         no associated background tasks.
207
         * there is no associated background tasks.
217 208
         */
218 209
        public IMonitorableTask[] getRunningProcesses() {
219 210
            return null;
......
226 217
         * </p>
227 218
         *
228 219
         * @return An array of the associated unsaved editing layers, or null in
229
         *         case the extension
230
         *         has not unsaved editing tables.
220
         * case the extension has not unsaved editing tables.
231 221
         */
232 222
        public IUnsavedData[] getUnsavedData() {
233 223
            Project project = ProjectManager.getInstance().getCurrentProject();
......
240 230
                    continue;
241 231
                }
242 232
                if (store.isEditing()) {
243
                    UnsavedTable ul =
244
                        new UnsavedTable(TableEditStopExtension.this);
233
                    UnsavedTable ul
234
                            = new UnsavedTable(TableEditStopExtension.this);
245 235
                    ul.setTable(table);
246 236
                    unsavedTables.add(ul);
247 237
                }
248 238
            }
249 239
            return unsavedTables
250
                .toArray(new IUnsavedData[unsavedTables.size()]);
240
                    .toArray(new IUnsavedData[unsavedTables.size()]);
251 241
        }
252 242
    }
253 243

  
......
275 265
            this.table = table;
276 266
        }
277 267

  
268
        @Override
278 269
        public String getIcon() {
279 270
            return "document-table-icon-small";
280 271
        }
281 272
    }
282 273

  
283
    // TODO Este c?digo est? duplicado, tambi?n est? en la clase Table en el
284
    // m?todo "public void stopEditing()"
274
    // TODO Este codigo esta duplicado, tambien esta en la clase Table en el
275
    // metodo "public void stopEditing()"
285 276
    private boolean executeSaveTable(TableDocument table2) {
286 277
        FeatureStore fs = table2.getStore();
287 278
        if (fs.isEditing()) {
......
298 289
                return false;
299 290
            }
300 291
        }
301
        // if (ies instanceof IWriteable) {
302
        // IWriteable w = (IWriteable) ies;
303
        // IWriter writer = w.getWriter();
304
        // if (writer == null) {
305
        // return false;
306
        // }
307
        // try {
308
        // ITableDefinition tableDef = ies.getTableDefinition();
309
        // writer.initialize(tableDef);
310
        // ies.stopEdition(writer, EditionEvent.ALPHANUMERIC);
311
        // ies.getSelection().clear();
312
        // } catch (InitializeWriterException e) {
313
        // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
314
        // return false;
315
        // } catch (StopWriterVisitorException e) {
316
        // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
317
        // return false;
318
        // } catch (ReadDriverException e) {
319
        // NotificationManager.addError(PluginServices.getText(this,"error_saving_table"),e);
320
        // return false;
321
        // }
322
        // }
323 292
        return true;
324 293
    }
325 294

  
295
    @Override
326 296
    public IExtensionStatus getStatus() {
327 297
        return new StopEditingStatus();
328 298
    }
329 299

  
330

  
331 300
    private JPanel getExplanationPanel(String name) {
332 301

  
333 302
        BorderLayout bl = new BorderLayout(10, 10);

Also available in: Unified diff