root / tags / v1_0_2_Build_903+3D / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 10722
History | View | Annotate | Download (3.46 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 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
18 | 2241 | fernando | |
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 | 9887 | fjp | table.getModel().setModified(true);
|
43 | } |
||
44 | 2241 | fernando | } |
45 | } |
||
46 | 6010 | caballero | |
47 | 4682 | jorpiell | /**
|
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 | 2241 | fernando | |
57 | 4682 | jorpiell | DataSource sds=null; |
58 | try {
|
||
59 | sds = table.getModel().getModelo().getRecordset(); |
||
60 | } catch (DriverLoadException e1) {
|
||
61 | // TODO Auto-generated catch block
|
||
62 | e1.printStackTrace(); |
||
63 | } |
||
64 | String dsName = sds.getName();
|
||
65 | try {
|
||
66 | 6010 | caballero | String fieldName=sds.getFieldName(fieldIndex);
|
67 | String sql = "select * from '" + dsName + "' order by " + fieldName; |
||
68 | 4682 | jorpiell | if ("ORDERASC".equals(actionCommand)){ |
69 | sql += " asc;";
|
||
70 | }else{
|
||
71 | sql += " desc;";
|
||
72 | } |
||
73 | 9887 | fjp | DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.MANUAL_OPENING);
|
74 | 4682 | jorpiell | table.setOrder(ds.getWhereFilter()); |
75 | } catch (DriverException e) {
|
||
76 | NotificationManager.addError("No se pudo ordenar", e);
|
||
77 | } catch (ParseException e) { |
||
78 | throw new RuntimeException(e); |
||
79 | } catch (DriverLoadException e) {
|
||
80 | NotificationManager.addError("Error con la carga de drivers", e);
|
||
81 | } catch (SemanticException e) {
|
||
82 | throw new RuntimeException(e); |
||
83 | } catch (IOException e) { |
||
84 | throw new RuntimeException(e); |
||
85 | } catch (EvaluationException e) {
|
||
86 | throw new RuntimeException(e); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | 2241 | fernando | /**
|
91 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
92 | 2241 | fernando | */
|
93 | public boolean isEnabled() { |
||
94 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
95 | 2241 | fernando | |
96 | if (v == null) { |
||
97 | return false; |
||
98 | } |
||
99 | |||
100 | 6127 | fjp | if (v instanceof Table) { |
101 | 2241 | fernando | Table t = (Table) v; |
102 | BitSet indices = t.getSelectedFieldIndices();
|
||
103 | if (indices.cardinality() == 1){ |
||
104 | return true; |
||
105 | } |
||
106 | } |
||
107 | return false; |
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
112 | 2241 | fernando | */
|
113 | public boolean isVisible() { |
||
114 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
115 | 2241 | fernando | |
116 | if (v == null) { |
||
117 | return false; |
||
118 | } |
||
119 | |||
120 | 5900 | jorpiell | if (v instanceof Table) { |
121 | 2241 | fernando | return true; |
122 | } |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | } |