Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Tabla.java @ 596

History | View | Annotate | Download (3.2 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.layers.FLayer;
14
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
15
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
16
import com.iver.cit.gvsig.gui.Table;
17
import com.iver.cit.gvsig.gui.View;
18
import com.iver.cit.gvsig.project.ProjectFactory;
19
import com.iver.cit.gvsig.project.castor.ProjectTable;
20

    
21

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

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

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

    
57
                return algunaTabla;
58
        }
59

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

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

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

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

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

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

    
98
                                        if (projectTable == null) {
99
                                                projectTable = ProjectFactory.createTable(((FLayer) co).getName(),
100
                                                                dataSource);
101
                                                projectTable.setAssociatedTable(co);
102
                                                ext.getProject().addTable(projectTable);
103
                                        }//else{
104
                                        //        projectTable.setAssociatedTable(co);
105
                                        //}
106
                                        
107
                                        Table t = new Table();
108
                                        t.setModel(projectTable,
109
                                                ((View) vista).getModel().getMapContext());
110
                                        PluginServices.getMDIManager().addView(t);
111
                                } catch (DriverLoadException 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
}