root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 7304
History | View | Annotate | Download (3.43 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.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.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 |
} |
43 |
} |
44 |
} |
45 |
|
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 |
|
56 |
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 fieldName=sds.getFieldName(fieldIndex);
|
66 |
String sql = "select * from '" + dsName + "' order by " + fieldName; |
67 |
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 |
/**
|
90 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
91 |
*/
|
92 |
public boolean isEnabled() { |
93 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
94 |
|
95 |
if (v == null) { |
96 |
return false; |
97 |
} |
98 |
|
99 |
if (v instanceof Table) { |
100 |
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 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
111 |
*/
|
112 |
public boolean isVisible() { |
113 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
114 |
|
115 |
if (v == null) { |
116 |
return false; |
117 |
} |
118 |
|
119 |
if (v instanceof Table) { |
120 |
return true; |
121 |
} |
122 |
return false; |
123 |
} |
124 |
|
125 |
} |