root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableFieldOperations.java @ 24759
History | View | Annotate | Download (3.42 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.util.BitSet; |
4 |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
6 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
7 |
|
8 |
import com.iver.andami.PluginServices; |
9 |
import com.iver.andami.plugins.Extension; |
10 |
import com.iver.andami.ui.mdiManager.IWindow; |
11 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
12 |
|
13 |
/**
|
14 |
* @author Fernando Gonz?lez Cort?s
|
15 |
*/
|
16 |
public class TableFieldOperations extends Extension{ |
17 |
|
18 |
/**
|
19 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
20 |
*/
|
21 |
public void initialize() { |
22 |
registerIcons(); |
23 |
} |
24 |
|
25 |
private void registerIcons(){ |
26 |
PluginServices.getIconTheme().registerDefault( |
27 |
"table-order-asc",
|
28 |
this.getClass().getClassLoader().getResource("images/orderasc.png") |
29 |
); |
30 |
|
31 |
PluginServices.getIconTheme().registerDefault( |
32 |
"table-order-desc",
|
33 |
this.getClass().getClassLoader().getResource("images/orderdesc.png") |
34 |
); |
35 |
} |
36 |
|
37 |
/**
|
38 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
39 |
*/
|
40 |
public void execute(String actionCommand) { |
41 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
42 |
|
43 |
if (v != null) { |
44 |
if (v instanceof Table) { |
45 |
|
46 |
Table table = (Table) v; |
47 |
|
48 |
doExecute(actionCommand,table); |
49 |
table.getModel().setModified(true);
|
50 |
} |
51 |
} |
52 |
} |
53 |
|
54 |
/**
|
55 |
* "execute" method acction
|
56 |
* @param actionCommand
|
57 |
* The acction command that executes this method
|
58 |
* @param table
|
59 |
* Table to operate
|
60 |
*/
|
61 |
protected void doExecute(String actionCommand,Table table){ |
62 |
int fieldIndex = table.getSelectedFieldIndices().nextSetBit(0); |
63 |
FeatureStore fs=table.getModel().getModel(); |
64 |
// DataSource sds=null;
|
65 |
// try {
|
66 |
// sds = table.getModel().getModelo().getRecordset();
|
67 |
// String dsName = sds.getName();
|
68 |
|
69 |
String fieldName=((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldIndex)).getName();
|
70 |
String sql = fieldName;
|
71 |
if ("ORDERASC".equals(actionCommand)){ |
72 |
sql += " ASC";
|
73 |
}else{
|
74 |
sql += " DESC";
|
75 |
} |
76 |
// DataSource ds = sds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.MANUAL_OPENING);
|
77 |
table.setOrder(sql); |
78 |
// } catch (ReadDriverException e) {
|
79 |
// NotificationManager.addError("No se pudo ordenar", e);
|
80 |
// } catch (ParseException e) {
|
81 |
// throw new RuntimeException(e);
|
82 |
// } catch (DriverLoadException e) {
|
83 |
// NotificationManager.addError("Error con la carga de drivers", e);
|
84 |
// } catch (SemanticException e) {
|
85 |
// throw new RuntimeException(e);
|
86 |
// } catch (IOException e) {
|
87 |
// throw new RuntimeException(e);
|
88 |
// } catch (EvaluationException e) {
|
89 |
// throw new RuntimeException(e);
|
90 |
// }
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
95 |
*/
|
96 |
public boolean isEnabled() { |
97 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
98 |
|
99 |
if (v == null) { |
100 |
return false; |
101 |
} |
102 |
|
103 |
if (v instanceof Table) { |
104 |
Table t = (Table) v; |
105 |
BitSet indices = t.getSelectedFieldIndices();
|
106 |
if (indices.cardinality() == 1){ |
107 |
return true; |
108 |
} |
109 |
} |
110 |
return false; |
111 |
} |
112 |
|
113 |
/**
|
114 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
115 |
*/
|
116 |
public boolean isVisible() { |
117 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
118 |
|
119 |
if (v == null) { |
120 |
return false; |
121 |
} |
122 |
|
123 |
if (v instanceof Table) { |
124 |
return true; |
125 |
} |
126 |
return false; |
127 |
} |
128 |
|
129 |
} |