root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 13967
History | View | Annotate | Download (3.36 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 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
8 | 2241 | fernando | 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 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
17 | 7304 | caballero | 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 | 9532 | caballero | 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 | 10626 | caballero | String dsName = sds.getName();
|
61 | |||
62 | 6010 | caballero | String fieldName=sds.getFieldName(fieldIndex);
|
63 | String sql = "select * from '" + dsName + "' order by " + fieldName; |
||
64 | 4682 | jorpiell | if ("ORDERASC".equals(actionCommand)){ |
65 | sql += " asc;";
|
||
66 | }else{
|
||
67 | sql += " desc;";
|
||
68 | } |
||
69 | 9833 | fjp | DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.MANUAL_OPENING);
|
70 | 4682 | jorpiell | table.setOrder(ds.getWhereFilter()); |
71 | 10626 | caballero | } catch (ReadDriverException e) {
|
72 | 4682 | jorpiell | 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 | 2241 | fernando | /**
|
87 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
88 | 2241 | fernando | */
|
89 | public boolean isEnabled() { |
||
90 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
91 | 2241 | fernando | |
92 | if (v == null) { |
||
93 | return false; |
||
94 | } |
||
95 | |||
96 | 6127 | fjp | if (v instanceof Table) { |
97 | 2241 | fernando | 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 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
108 | 2241 | fernando | */
|
109 | public boolean isVisible() { |
||
110 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
111 | 2241 | fernando | |
112 | if (v == null) { |
||
113 | return false; |
||
114 | } |
||
115 | |||
116 | 5900 | jorpiell | if (v instanceof Table) { |
117 | 2241 | fernando | return true; |
118 | } |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | } |