Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 5086

History | View | Annotate | Download (3.4 KB)

1 2241 fernando
package com.iver.cit.gvsig;
2
3
import java.io.IOException;
4
import java.util.BitSet;
5
6
import com.hardcode.driverManager.DriverLoadException;
7
import com.hardcode.gdbms.engine.data.DataSource;
8
import com.hardcode.gdbms.engine.data.DataSourceFactory;
9
import com.hardcode.gdbms.engine.data.driver.DriverException;
10
import com.hardcode.gdbms.engine.instruction.EvaluationException;
11
import com.hardcode.gdbms.engine.instruction.SemanticException;
12
import com.hardcode.gdbms.parser.ParseException;
13
import com.iver.andami.PluginServices;
14
import com.iver.andami.messages.NotificationManager;
15
import com.iver.andami.plugins.Extension;
16
import com.iver.andami.ui.mdiManager.View;
17
import com.iver.cit.gvsig.gui.Table;
18
19
/**
20 4682 jorpiell
 * @author Fernando Gonz?lez Cort?s
21 2241 fernando
 */
22 5005 jorpiell
public class TableFieldOperations extends Extension{
23 2241 fernando
24
    /**
25 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#initialize()
26 2241 fernando
     */
27 5005 jorpiell
    public void initialize() {
28 2241 fernando
    }
29
30
    /**
31 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
32 2241 fernando
     */
33
    public void execute(String actionCommand) {
34
                View v = PluginServices.getMDIManager().getActiveView();
35
36
                if (v != null) {
37
                        if (v.getClass() == Table.class) {
38 3940 caballero
39 4682 jorpiell
                            Table table = (Table) v;
40
41
                            doExecute(actionCommand,table);
42 2241 fernando
            }
43
                }
44
    }
45 4682 jorpiell
46
    /**
47
     * "execute" method acction
48
     * @param actionCommand
49
     * The acction command that executes this method
50
     * @param table
51
     * Table to operate
52
     */
53
        protected void doExecute(String actionCommand,Table table){
54
                int fieldIndex = table.getSelectedFieldIndices().nextSetBit(0);
55 2241 fernando
56 4682 jorpiell
        DataSource sds=null;
57
                try {
58
                        sds = table.getModel().getModelo().getRecordset();
59
                } catch (DriverLoadException e1) {
60
                        // TODO Auto-generated catch block
61
                        e1.printStackTrace();
62
                }
63
            String dsName = sds.getName();
64
            try {
65
            String sql = "select * from '" + dsName + "' order by " + sds.getFieldName(fieldIndex);
66
            if ("ORDERASC".equals(actionCommand)){
67
                sql += " asc;";
68
                    }else{
69
                sql += " desc;";
70
                    }
71
                    DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
72
                    table.setOrder(ds.getWhereFilter());
73
                } catch (DriverException e) {
74
            NotificationManager.addError("No se pudo ordenar", e);
75
        } catch (ParseException e) {
76
            throw new RuntimeException(e);
77
        } catch (DriverLoadException e) {
78
            NotificationManager.addError("Error con la carga de drivers", e);
79
        } catch (SemanticException e) {
80
            throw new RuntimeException(e);
81
        } catch (IOException e) {
82
            throw new RuntimeException(e);
83
        } catch (EvaluationException e) {
84
            throw new RuntimeException(e);
85
        }
86
        }
87
88 2241 fernando
    /**
89 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#isEnabled()
90 2241 fernando
     */
91
    public boolean isEnabled() {
92
                View v = PluginServices.getMDIManager().getActiveView();
93
94
                if (v == null) {
95
                        return false;
96
                }
97
98
                if (v.getClass() == Table.class) {
99
                    Table t = (Table) v;
100
                    BitSet indices = t.getSelectedFieldIndices();
101
                    if (indices.cardinality() == 1){
102
                        return true;
103
                    }
104
                }
105
                return false;
106
    }
107
108
    /**
109 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#isVisible()
110 2241 fernando
     */
111
    public boolean isVisible() {
112
                View v = PluginServices.getMDIManager().getActiveView();
113
114
                if (v == null) {
115
                        return false;
116
                }
117
118
                if (v.getClass() == Table.class) {
119
                    return true;
120
                }
121
                return false;
122
    }
123
124
}