root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 23303
History | View | Annotate | Download (3.5 KB)
1 | 2241 | fernando | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | import java.io.IOException; |
||
4 | import java.util.BitSet; |
||
5 | |||
6 | 22360 | jmvivo | import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
7 | import org.gvsig.fmap.data.feature.FeatureStore; |
||
8 | 22334 | vcaballero | |
9 | 2241 | fernando | import com.iver.andami.PluginServices; |
10 | import com.iver.andami.messages.NotificationManager; |
||
11 | import com.iver.andami.plugins.Extension; |
||
12 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
13 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
14 | 2241 | fernando | |
15 | /**
|
||
16 | 6010 | caballero | * @author Fernando Gonz?lez Cort?s
|
17 | 2241 | fernando | */
|
18 | 5005 | jorpiell | public class TableFieldOperations extends Extension{ |
19 | 2241 | fernando | |
20 | /**
|
||
21 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
22 | 2241 | fernando | */
|
23 | 5005 | jorpiell | public void initialize() { |
24 | 14821 | jmvivo | registerIcons(); |
25 | 2241 | fernando | } |
26 | |||
27 | 14821 | jmvivo | private void registerIcons(){ |
28 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
29 | 14821 | jmvivo | "table-order-asc",
|
30 | this.getClass().getClassLoader().getResource("images/orderasc.png") |
||
31 | ); |
||
32 | |||
33 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
34 | 14821 | jmvivo | "table-order-desc",
|
35 | this.getClass().getClassLoader().getResource("images/orderdesc.png") |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | 2241 | fernando | /**
|
40 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
41 | 2241 | fernando | */
|
42 | public void execute(String actionCommand) { |
||
43 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
44 | 2241 | fernando | |
45 | if (v != null) { |
||
46 | 6259 | fjp | if (v instanceof Table) { |
47 | 3940 | caballero | |
48 | 4682 | jorpiell | Table table = (Table) v; |
49 | 6010 | caballero | |
50 | 4682 | jorpiell | doExecute(actionCommand,table); |
51 | 9532 | caballero | table.getModel().setModified(true);
|
52 | } |
||
53 | 2241 | fernando | } |
54 | } |
||
55 | 6010 | caballero | |
56 | 4682 | jorpiell | /**
|
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 | 22932 | jmvivo | FeatureStore fs=table.getModel().getModel(); |
66 | 22335 | vcaballero | // DataSource sds=null;
|
67 | // try {
|
||
68 | // sds = table.getModel().getModelo().getRecordset();
|
||
69 | // String dsName = sds.getName();
|
||
70 | 10626 | caballero | |
71 | 22335 | vcaballero | String fieldName=((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldIndex)).getName();
|
72 | String sql = fieldName;
|
||
73 | 4682 | jorpiell | if ("ORDERASC".equals(actionCommand)){ |
74 | 22335 | vcaballero | sql += " ASC";
|
75 | 4682 | jorpiell | }else{
|
76 | 22335 | vcaballero | sql += " DESC";
|
77 | 4682 | jorpiell | } |
78 | 22335 | vcaballero | // 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 | 4682 | jorpiell | } |
94 | |||
95 | 2241 | fernando | /**
|
96 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
97 | 2241 | fernando | */
|
98 | public boolean isEnabled() { |
||
99 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
100 | 2241 | fernando | |
101 | if (v == null) { |
||
102 | return false; |
||
103 | } |
||
104 | |||
105 | 6127 | fjp | if (v instanceof Table) { |
106 | 2241 | fernando | 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 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
117 | 2241 | fernando | */
|
118 | public boolean isVisible() { |
||
119 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
120 | 2241 | fernando | |
121 | if (v == null) { |
||
122 | return false; |
||
123 | } |
||
124 | |||
125 | 5900 | jorpiell | if (v instanceof Table) { |
126 | 2241 | fernando | return true; |
127 | } |
||
128 | return false; |
||
129 | } |
||
130 | |||
131 | } |