Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableEditStartExtension.java @ 24759

History | View | Annotate | Download (4.67 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.HeadlessException;
44

    
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.plugins.Extension;
49
import com.iver.andami.ui.mdiManager.IWindow;
50
import com.iver.cit.gvsig.project.documents.table.exceptions.StartEditingTableException;
51
import com.iver.cit.gvsig.project.documents.table.gui.Table;
52

    
53

    
54
/**
55
 * DOCUMENT ME!
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class TableEditStartExtension extends Extension {
60
         /**
61
     * @see com.iver.andami.plugins.IExtension#initialize()
62
     */
63
    public void initialize() {
64
    }
65

    
66
    /**
67
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
68
     */
69
    public void execute(String actionCommand) {
70
            if ("STARTEDIT".equals(actionCommand)) {
71
                    IWindow v = PluginServices.getMDIManager().getActiveWindow();
72

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

    
99
                            table.startEditing();
100
                            /* IEditableSource edTable = (IEditableSource) table.getModel().getAssociatedTable();
101
                             edTable.getCommandRecord().addCommandListener(table); */
102

    
103
                    } catch (StartEditingTableException e) {
104
                            e.printStackTrace();
105
                    } catch (HeadlessException e) {
106
                            e.printStackTrace();
107
                    }
108
            }
109
    }
110

    
111
    /**
112
     * @see com.iver.andami.plugins.IExtension#isEnabled()
113
     */
114
    public boolean isEnabled() {
115
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
116

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

    
144
    /**
145
     * @see com.iver.andami.plugins.IExtension#isVisible()
146
     */
147
    public boolean isVisible() {
148
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
149

    
150
        if (v == null) {
151
            return false;
152
        }
153

    
154
        if (v instanceof Table && !((Table) v).isEditing() && ((Table)v).getModel().getAssociatedTable()==null) {
155
                       return true;
156
        }
157

    
158
        return false;
159
    }
160
}