svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 8745
History | View | Annotate | Download (3.41 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 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
17 | 2241 | fernando | import com.iver.cit.gvsig.gui.Table; |
18 | |||
19 | /**
|
||
20 | 6010 | caballero | * @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 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
35 | 2241 | fernando | |
36 | if (v != null) { |
||
37 | 6259 | fjp | if (v instanceof Table) { |
38 | 3940 | caballero | |
39 | 4682 | jorpiell | Table table = (Table) v; |
40 | 6010 | caballero | |
41 | 4682 | jorpiell | doExecute(actionCommand,table); |
42 | 2241 | fernando | } |
43 | } |
||
44 | } |
||
45 | 6010 | caballero | |
46 | 4682 | jorpiell | /**
|
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 | 6010 | caballero | String fieldName=sds.getFieldName(fieldIndex);
|
66 | String sql = "select * from '" + dsName + "' order by " + fieldName; |
||
67 | 4682 | jorpiell | if ("ORDERASC".equals(actionCommand)){ |
68 | sql += " asc;";
|
||
69 | }else{
|
||
70 | sql += " desc;";
|
||
71 | } |
||
72 | DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
|
||
73 | table.setOrder(ds.getWhereFilter()); |
||
74 | } catch (DriverException e) {
|
||
75 | NotificationManager.addError("No se pudo ordenar", e);
|
||
76 | } catch (ParseException e) { |
||
77 | throw new RuntimeException(e); |
||
78 | } catch (DriverLoadException e) {
|
||
79 | NotificationManager.addError("Error con la carga de drivers", e);
|
||
80 | } catch (SemanticException e) {
|
||
81 | throw new RuntimeException(e); |
||
82 | } catch (IOException e) { |
||
83 | throw new RuntimeException(e); |
||
84 | } catch (EvaluationException e) {
|
||
85 | throw new RuntimeException(e); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | 2241 | fernando | /**
|
90 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
91 | 2241 | fernando | */
|
92 | public boolean isEnabled() { |
||
93 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
94 | 2241 | fernando | |
95 | if (v == null) { |
||
96 | return false; |
||
97 | } |
||
98 | |||
99 | 6127 | fjp | if (v instanceof Table) { |
100 | 2241 | fernando | Table t = (Table) v; |
101 | BitSet indices = t.getSelectedFieldIndices();
|
||
102 | if (indices.cardinality() == 1){ |
||
103 | return true; |
||
104 | } |
||
105 | } |
||
106 | return false; |
||
107 | } |
||
108 | |||
109 | /**
|
||
110 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
111 | 2241 | fernando | */
|
112 | public boolean isVisible() { |
||
113 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
114 | 2241 | fernando | |
115 | if (v == null) { |
||
116 | return false; |
||
117 | } |
||
118 | |||
119 | 5900 | jorpiell | if (v instanceof Table) { |
120 | 2241 | fernando | return true; |
121 | } |
||
122 | return false; |
||
123 | } |
||
124 | |||
125 | } |