Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 3718

History | View | Annotate | Download (3.31 KB)

1
package com.iver.cit.gvsig;
2

    
3
import java.io.IOException;
4
import java.sql.Types;
5
import java.util.BitSet;
6

    
7
import com.hardcode.driverManager.DriverLoadException;
8
import com.hardcode.gdbms.engine.data.DataSource;
9
import com.hardcode.gdbms.engine.data.DataSourceFactory;
10
import com.hardcode.gdbms.engine.data.driver.DriverException;
11
import com.hardcode.gdbms.engine.instruction.EvaluationException;
12
import com.hardcode.gdbms.engine.instruction.SemanticException;
13
import com.hardcode.gdbms.engine.values.NumericValue;
14
import com.hardcode.gdbms.parser.ParseException;
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.messages.NotificationManager;
17
import com.iver.andami.plugins.Extension;
18
import com.iver.andami.ui.mdiManager.View;
19
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
20
import com.iver.cit.gvsig.gui.Table;
21
import com.iver.cit.gvsig.gui.tables.Statistics;
22

    
23
/**
24
 * @author Fernando Gonz?lez Cort?s
25
 */
26
public class TableFieldOperations implements Extension{
27

    
28
    /**
29
     * @see com.iver.andami.plugins.Extension#inicializar()
30
     */
31
    public void inicializar() {
32
    }
33

    
34
    /**
35
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
36
     */
37
    public void execute(String actionCommand) {
38
                View v = PluginServices.getMDIManager().getActiveView();
39

    
40
                if (v != null) {
41
                        if (v.getClass() == Table.class) {
42
                            
43
                            Table t = (Table) v;
44
                            
45
                            int fieldIndex = t.getSelectedFieldIndices().nextSetBit(0);
46
                            
47
                        DataSource sds = t.getModel().getModelo();
48
                            String dsName = sds.getName();
49
                            try {
50
                    String sql = "select * from '" + dsName + "' order by " + sds.getFieldName(fieldIndex);
51
                    if ("ORDERASC".equals(actionCommand)){
52
                        sql += " asc;";
53
                                    }else{
54
                            sql += " desc;";
55
                                    }
56
                                    DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
57
                                    t.setOrder(ds.getWhereFilter());
58
                                } catch (DriverException e) {
59
                    NotificationManager.addError("No se pudo ordenar", e);
60
                } catch (ParseException e) {
61
                    throw new RuntimeException(e);
62
                } catch (DriverLoadException e) {
63
                    NotificationManager.addError("Error con la carga de drivers", e);
64
                } catch (SemanticException e) {
65
                    throw new RuntimeException(e);
66
                } catch (IOException e) {
67
                    throw new RuntimeException(e);
68
                } catch (EvaluationException e) {
69
                    throw new RuntimeException(e);
70
                }
71
            }
72
                }
73
    }
74

    
75
    /**
76
     * @see com.iver.andami.plugins.Extension#isEnabled()
77
     */
78
    public boolean isEnabled() {
79
                View v = PluginServices.getMDIManager().getActiveView();
80

    
81
                if (v == null) {
82
                        return false;
83
                }
84

    
85
                if (v.getClass() == Table.class) {
86
                    Table t = (Table) v;
87
                    BitSet indices = t.getSelectedFieldIndices();
88
                    if (indices.cardinality() == 1){
89
                        return true;
90
                    }
91
                }
92
                return false;
93
    }
94

    
95
    /**
96
     * @see com.iver.andami.plugins.Extension#isVisible()
97
     */
98
    public boolean isVisible() {
99
                View v = PluginServices.getMDIManager().getActiveView();
100

    
101
                if (v == null) {
102
                        return false;
103
                }
104

    
105
                if (v.getClass() == Table.class) {
106
                    return true;
107
                }
108
                return false;
109
    }
110

    
111
}