Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 22932

History | View | Annotate | Download (3.5 KB)

1
package com.iver.cit.gvsig;
2

    
3
import java.io.IOException;
4
import java.util.BitSet;
5

    
6
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
7
import org.gvsig.fmap.data.feature.FeatureStore;
8

    
9
import com.iver.andami.PluginServices;
10
import com.iver.andami.messages.NotificationManager;
11
import com.iver.andami.plugins.Extension;
12
import com.iver.andami.ui.mdiManager.IWindow;
13
import com.iver.cit.gvsig.project.documents.table.gui.Table;
14

    
15
/**
16
 * @author Fernando Gonz?lez Cort?s
17
 */
18
public class TableFieldOperations extends Extension{
19

    
20
    /**
21
     * @see com.iver.andami.plugins.IExtension#initialize()
22
     */
23
    public void initialize() {
24
            registerIcons();
25
    }
26

    
27
    private void registerIcons(){
28
            PluginServices.getIconTheme().registerDefault(
29
                                "table-order-asc",
30
                                this.getClass().getClassLoader().getResource("images/orderasc.png")
31
                        );
32

    
33
            PluginServices.getIconTheme().registerDefault(
34
                                "table-order-desc",
35
                                this.getClass().getClassLoader().getResource("images/orderdesc.png")
36
                        );
37
    }
38

    
39
    /**
40
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
41
     */
42
    public void execute(String actionCommand) {
43
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
44

    
45
                if (v != null) {
46
                        if (v instanceof Table) {
47

    
48
                            Table table = (Table) v;
49

    
50
                            doExecute(actionCommand,table);
51
                            table.getModel().setModified(true);
52
                        }
53
                }
54
    }
55

    
56
    /**
57
     * "execute" method acction
58
     * @param actionCommand
59
     * The acction command that executes this method
60
     * @param table
61
     * Table to operate
62
     */
63
        protected void doExecute(String actionCommand,Table table){
64
                int fieldIndex = table.getSelectedFieldIndices().nextSetBit(0);
65
                FeatureStore fs=table.getModel().getModel();
66
//        DataSource sds=null;
67
//                try {
68
//                        sds = table.getModel().getModelo().getRecordset();
69
//                        String dsName = sds.getName();
70

    
71
                    String fieldName=((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldIndex)).getName();
72
            String sql = fieldName;
73
            if ("ORDERASC".equals(actionCommand)){
74
                sql += " ASC";
75
                    }else{
76
                sql += " DESC";
77
                    }
78
//                    DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.MANUAL_OPENING);
79
                    table.setOrder(sql);
80
//                } catch (ReadDriverException e) {
81
//            NotificationManager.addError("No se pudo ordenar", e);
82
//        } catch (ParseException e) {
83
//            throw new RuntimeException(e);
84
//        } catch (DriverLoadException e) {
85
//            NotificationManager.addError("Error con la carga de drivers", e);
86
//        } catch (SemanticException e) {
87
//            throw new RuntimeException(e);
88
//        } catch (IOException e) {
89
//            throw new RuntimeException(e);
90
//        } catch (EvaluationException e) {
91
//            throw new RuntimeException(e);
92
//        }
93
        }
94

    
95
    /**
96
     * @see com.iver.andami.plugins.IExtension#isEnabled()
97
     */
98
    public boolean isEnabled() {
99
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
100

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

    
105
                if (v instanceof Table) {
106
                    Table t = (Table) v;
107
                    BitSet indices = t.getSelectedFieldIndices();
108
                    if (indices.cardinality() == 1){
109
                        return true;
110
                    }
111
                }
112
                return false;
113
    }
114

    
115
    /**
116
     * @see com.iver.andami.plugins.IExtension#isVisible()
117
     */
118
    public boolean isVisible() {
119
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
120

    
121
                if (v == null) {
122
                        return false;
123
                }
124

    
125
                if (v instanceof Table) {
126
                    return true;
127
                }
128
                return false;
129
    }
130

    
131
}