Statistics
| Revision:

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

History | View | Annotate | Download (3.36 KB)

1
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.driver.exceptions.ReadDriverException;
8
import com.hardcode.gdbms.engine.data.DataSource;
9
import com.hardcode.gdbms.engine.data.DataSourceFactory;
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.IWindow;
17
import com.iver.cit.gvsig.project.documents.table.gui.Table;
18

    
19
/**
20
 * @author Fernando Gonz?lez Cort?s
21
 */
22
public class TableFieldOperations extends Extension{
23

    
24
    /**
25
     * @see com.iver.andami.plugins.IExtension#initialize()
26
     */
27
    public void initialize() {
28
    }
29

    
30
    /**
31
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
32
     */
33
    public void execute(String actionCommand) {
34
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
35

    
36
                if (v != null) {
37
                        if (v instanceof Table) {
38

    
39
                            Table table = (Table) v;
40

    
41
                            doExecute(actionCommand,table);
42
                            table.getModel().setModified(true);
43
                        }
44
                }
45
    }
46

    
47
    /**
48
     * "execute" method acction
49
     * @param actionCommand
50
     * The acction command that executes this method
51
     * @param table
52
     * Table to operate
53
     */
54
        protected void doExecute(String actionCommand,Table table){
55
                int fieldIndex = table.getSelectedFieldIndices().nextSetBit(0);
56

    
57
        DataSource sds=null;
58
                try {
59
                        sds = table.getModel().getModelo().getRecordset();
60
                        String dsName = sds.getName();
61

    
62
                    String fieldName=sds.getFieldName(fieldIndex);
63
            String sql = "select * from '" + dsName + "' order by " + fieldName;
64
            if ("ORDERASC".equals(actionCommand)){
65
                sql += " asc;";
66
                    }else{
67
                sql += " desc;";
68
                    }
69
                    DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.MANUAL_OPENING);
70
                    table.setOrder(ds.getWhereFilter());
71
                } catch (ReadDriverException e) {
72
            NotificationManager.addError("No se pudo ordenar", e);
73
        } catch (ParseException e) {
74
            throw new RuntimeException(e);
75
        } catch (DriverLoadException e) {
76
            NotificationManager.addError("Error con la carga de drivers", e);
77
        } catch (SemanticException e) {
78
            throw new RuntimeException(e);
79
        } catch (IOException e) {
80
            throw new RuntimeException(e);
81
        } catch (EvaluationException e) {
82
            throw new RuntimeException(e);
83
        }
84
        }
85

    
86
    /**
87
     * @see com.iver.andami.plugins.IExtension#isEnabled()
88
     */
89
    public boolean isEnabled() {
90
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
91

    
92
                if (v == null) {
93
                        return false;
94
                }
95

    
96
                if (v instanceof Table) {
97
                    Table t = (Table) v;
98
                    BitSet indices = t.getSelectedFieldIndices();
99
                    if (indices.cardinality() == 1){
100
                        return true;
101
                    }
102
                }
103
                return false;
104
    }
105

    
106
    /**
107
     * @see com.iver.andami.plugins.IExtension#isVisible()
108
     */
109
    public boolean isVisible() {
110
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
111

    
112
                if (v == null) {
113
                        return false;
114
                }
115

    
116
                if (v instanceof Table) {
117
                    return true;
118
                }
119
                return false;
120
    }
121

    
122
}