Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableEditStartExtension.java @ 10626

History | View | Annotate | Download (5.14 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig;
42

    
43
import java.awt.Component;
44
import java.awt.HeadlessException;
45

    
46
import javax.swing.JOptionPane;
47

    
48
import com.hardcode.driverManager.Driver;
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51
import com.iver.andami.ui.mdiManager.IWindow;
52
import com.iver.cit.gvsig.exceptions.table.StartEditingTableException;
53
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
54
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
55
import com.iver.cit.gvsig.fmap.edition.IWriteable;
56
import com.iver.cit.gvsig.fmap.edition.IWriter;
57
import com.iver.cit.gvsig.project.documents.table.gui.Table;
58

    
59

    
60
/**
61
 * DOCUMENT ME!
62
 *
63
 * @author Vicente Caballero Navarro
64
 */
65
public class TableEditStartExtension extends Extension {
66
         /**
67
     * @see com.iver.andami.plugins.IExtension#initialize()
68
     */
69
    public void initialize() {
70
    }
71

    
72
    /**
73
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
74
     */
75
    public void execute(String actionCommand) {
76
        if ("STARTEDIT".equals(actionCommand)) {
77
            IWindow v = PluginServices.getMDIManager().getActiveWindow();
78

    
79
                try {
80
                        Table table = (Table) v;
81
                            Driver drv = table.getModel().getModelo().getOriginalDriver();
82
                            if (drv instanceof IWriteable)
83
                            {
84
                                    IWriter writer = ((IWriteable) drv).getWriter();
85
                                    if (!writer.canSaveEdits())
86
                                    {
87
                                            JOptionPane.showMessageDialog(
88
                                                            (Component) PluginServices.getMDIManager().getActiveWindow(),
89
                                                            PluginServices.getText(this, "this_table_is_not_self_editable"),
90
                                                            PluginServices.getText(this, "warning"),
91
                                                            JOptionPane.WARNING_MESSAGE);
92
                                            return;
93
                                    }
94
                            }
95
                            else
96
                            {
97
                                        JOptionPane.showMessageDialog(
98
                                                        (Component) PluginServices.getMDIManager().getActiveWindow(),
99
                                                        PluginServices.getText(this, "this_table_is_not_self_editable"),
100
                                                        PluginServices.getText(this, "warning"),
101
                                                        JOptionPane.WARNING_MESSAGE);
102
                                        return;
103
                            }
104

    
105
                                        table.startEditing();
106
                                        /* IEditableSource edTable = (IEditableSource) table.getModel().getAssociatedTable();
107
                                        edTable.getCommandRecord().addCommandListener(table); */
108

    
109
                                } catch (StartEditingTableException e) {
110
                                        e.printStackTrace();
111
                                } catch (HeadlessException e) {
112
                                        e.printStackTrace();
113
                                } catch (VisitorException e) {
114
                                        e.printStackTrace();
115
                                }
116

    
117
        }
118
    }
119

    
120
    /**
121
     * @see com.iver.andami.plugins.IExtension#isEnabled()
122
     */
123
    public boolean isEnabled() {
124
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
125

    
126
        if (v == null) {
127
            return false;
128
        }
129
        if (v instanceof Table)
130
        {
131
                    Table t = (Table) v;
132
                    IEditableSource ies = t.getModel().getModelo();
133
                    // FJP:
134
                    // Si est? linkada, por ahora no dejamos editar
135
                    // TODO: Esto evita la edici?n en un sentido, pero no en el otro
136
                    // Hay que permitir la edici?n, pero evitar que toquen el/los
137
                    // campos de uni?n. Para eso tendremos que a?adir alguna funci?n
138
                    // que indique si un campo est? involucrado en alguna uni?n, o
139
                    // quiz?s algo m?s gen?rico, algo que permita bloquear campos
140
                    // para que no se puedan editar.
141
                    if (t.getModel().getLinkTable() != null)
142
                            return false;
143
                    if (ies.getOriginalDriver() instanceof IWriteable)
144
                    {
145
                            return true;
146
                    }
147
        }
148
            return false;
149
    }
150

    
151
    /**
152
     * @see com.iver.andami.plugins.IExtension#isVisible()
153
     */
154
    public boolean isVisible() {
155
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
156

    
157
        if (v == null) {
158
            return false;
159
        }
160

    
161
        if (v instanceof Table && !((Table) v).isEditing() && ((Table)v).getModel().getAssociatedTable()==null) {
162
                       return true;
163
        }
164

    
165
        return false;
166
    }
167
}