Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Tabla.java @ 1052

History | View | Annotate | Download (3.27 KB)

1
/*
2
 * Created on 02-mar-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig;
8

    
9
import com.hardcode.driverManager.DriverLoadException;
10
import com.iver.andami.PluginServices;
11
import com.iver.andami.messages.NotificationManager;
12
import com.iver.andami.plugins.Extension;
13
import com.iver.cit.gvsig.fmap.DriverException;
14
import com.iver.cit.gvsig.fmap.layers.FLayer;
15
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
16
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
17
import com.iver.cit.gvsig.gui.Table;
18
import com.iver.cit.gvsig.gui.View;
19
import com.iver.cit.gvsig.project.ProjectFactory;
20
import com.iver.cit.gvsig.project.castor.ProjectTable;
21

    
22

    
23
/**
24
 * DOCUMENT ME!
25
 *
26
 * @author vcn To change the template for this generated type comment go to
27
 *                    Window>Preferences>Java>Code Generation>Code and
28
 *                    Comments
29
 */
30
public class Tabla implements Extension {
31
        /**
32
         * DOCUMENT ME!
33
         *
34
         * @return DOCUMENT ME!
35
         */
36
        public boolean isEnabled() {
37
                View f = (View) PluginServices.getMDIManager().getActiveView();
38

    
39
                if (f == null) {
40
                        return false;
41
                }
42

    
43
                FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
44
        
45
        boolean algunaTabla = false;
46
        for (int i = 0; i < selected.length; i++) {
47
                        if (selected[i] instanceof AlphanumericData){
48
                                AlphanumericData co = (AlphanumericData) selected[i];
49
                                try {
50
                                        if (co.getRecordset() != null) {
51
                                                algunaTabla = true;
52
                                        }
53
                                } catch (DriverException e) {
54
                                }
55
                        }
56
                }
57

    
58
                return algunaTabla;
59
        }
60

    
61
        /**
62
         * DOCUMENT ME!
63
         *
64
         * @return DOCUMENT ME!
65
         */
66
        public boolean isVisible() {
67
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
68
                                                                                                                   .getActiveView();
69

    
70
                if (f == null) {
71
                        return false;
72
                }
73

    
74
                return (f.getClass() == View.class);
75
        }
76

    
77
        /**
78
         * DOCUMENT ME!
79
         *
80
         * @param status DOCUMENT ME!
81
         * @param s DOCUMENT ME!
82
         */
83
        public void execute(String s) {
84
                View vista = (View) PluginServices.getMDIManager().getActiveView();
85
                FLayer[] actives = ((View) vista).getModel().getMapContext().getLayers()
86
                                                        .getActives();
87

    
88
                 for (int i = 0; i < actives.length; i++) {
89
                if (actives[i] instanceof AlphanumericData){
90
                        AlphanumericData co = (AlphanumericData)actives[i];
91
                        
92
                                try {
93
                                        SelectableDataSource dataSource = co.getRecordset();
94
                                        ProjectExtension ext = (ProjectExtension) PluginServices
95
                                                                                                                                                  .getExtension(ProjectExtension.class);
96

    
97
                                        ProjectTable projectTable = ext.getProject().getTable(co);
98

    
99
                                        if (projectTable == null) {
100
                                                String strAux = PluginServices.getText(this, "Tabla de atributos de ");
101
                                                projectTable = ProjectFactory.createTable(strAux + actives[i].getName(), dataSource);
102
                                                projectTable.setAssociatedTable(co);
103
                                                ext.getProject().addTable(projectTable);
104
                                        }//else{
105
                                        //        projectTable.setAssociatedTable(co);
106
                                        //}
107
                                        
108
                                        Table t = new Table();
109
                                        t.setModel(projectTable);
110
                                        PluginServices.getMDIManager().addView(t);
111
                                } catch (DriverException e) {
112
                                        NotificationManager.addError("Error al cargar los drivers",
113
                                                e);
114
                                }
115
                        }
116
                        
117
                }
118
        }
119

    
120
        /**
121
         * @see com.iver.andami.plugins.Extension#inicializar()
122
         */
123
        public void inicializar() {
124
        }
125
}