root / trunk / extensions / extTableSummarize / src / org / gvsig / app / documents / table / summarize / TableSummarizeExtension.java @ 27644
History | View | Annotate | Download (4.09 KB)
1 |
/* gvSIG. Sistema de Informacion Geografica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2009 IVER T.I.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* IVER T.I.
|
22 |
* C/ Lerida, 20
|
23 |
* 46009 Valencia
|
24 |
* SPAIN
|
25 |
* http://www.iver.es
|
26 |
* dac@iver.es
|
27 |
* +34 963163400
|
28 |
*
|
29 |
* or
|
30 |
*
|
31 |
* Generalitat Valenciana
|
32 |
* Conselleria d'Infraestructures i Transport
|
33 |
* Av. Blasco Iba?ez, 50
|
34 |
* 46010 VALENCIA
|
35 |
* SPAIN
|
36 |
*/
|
37 |
package org.gvsig.app.documents.table.summarize; |
38 |
|
39 |
import java.util.BitSet; |
40 |
|
41 |
import org.gvsig.app.documents.table.summarize.gui.SummarizeForm; |
42 |
|
43 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
44 |
import com.hardcode.gdbms.engine.data.DataSource; |
45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.andami.messages.NotificationManager; |
47 |
import com.iver.andami.plugins.Extension; |
48 |
import com.iver.andami.plugins.PluginClassLoader; |
49 |
import com.iver.andami.ui.mdiManager.IWindow; |
50 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
51 |
|
52 |
/**
|
53 |
* Adds a Summarize tool for Tables.
|
54 |
*
|
55 |
* @author IVER T.I. <http://www.iver.es> 01/02/2009
|
56 |
*/
|
57 |
public class TableSummarizeExtension extends Extension { |
58 |
|
59 |
public void execute(String actionCommand) { |
60 |
try{
|
61 |
|
62 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
63 |
if (v instanceof Table){ |
64 |
|
65 |
Table table = (Table) PluginServices.getMDIManager().getActiveWindow(); |
66 |
try {
|
67 |
DataSource sds = table.getModel().getModelo().getRecordset();
|
68 |
BitSet indices = table.getSelectedFieldIndices();
|
69 |
SummarizeForm st = new SummarizeForm();
|
70 |
if (indices.cardinality()>0) { |
71 |
st.show(table, sds.getFieldName(indices.nextSetBit(0)));
|
72 |
} |
73 |
else {
|
74 |
st.show(table); |
75 |
} |
76 |
} catch (ReadDriverException e) {
|
77 |
NotificationManager.showMessageError(PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e); |
78 |
} |
79 |
} |
80 |
} |
81 |
catch (Exception e){ |
82 |
NotificationManager.showMessageError(PluginServices.getText(this, "Unknown_summarize_error"), e); |
83 |
} |
84 |
} |
85 |
|
86 |
public void initialize() { |
87 |
initilializeIcons(); |
88 |
} |
89 |
|
90 |
private void initilializeIcons(){ |
91 |
PluginClassLoader loader = PluginServices.getPluginServices(this).getClassLoader();
|
92 |
PluginServices.getIconTheme().registerDefault( |
93 |
"tableSummarize-statistics",
|
94 |
loader.getResource("images/tableSummarize16.png")
|
95 |
); |
96 |
PluginServices.getIconTheme().registerDefault( |
97 |
"tableSummarize-statistics-22x22",
|
98 |
loader.getResource("images/tableSummarize22.png")
|
99 |
); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
104 |
*/
|
105 |
public boolean isEnabled() { |
106 |
return true; |
107 |
// IWindow v = PluginServices.getMDIManager().getActiveWindow();
|
108 |
//
|
109 |
// if (v == null) {
|
110 |
// return false;
|
111 |
// }
|
112 |
//
|
113 |
// if (v instanceof Table) {
|
114 |
// Table table = (Table) v;
|
115 |
// return doIsEnabled(table);
|
116 |
// }
|
117 |
} |
118 |
|
119 |
// protected boolean doIsEnabled(Table table){
|
120 |
// BitSet indices = table.getSelectedFieldIndices();
|
121 |
// //one column must be selected to activate the extension button
|
122 |
// if (indices.cardinality() == 1) return true;
|
123 |
// else return false;
|
124 |
// }
|
125 |
|
126 |
|
127 |
|
128 |
/**
|
129 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
130 |
*/
|
131 |
public boolean isVisible() { |
132 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
133 |
|
134 |
if (v == null) { |
135 |
return false; |
136 |
} |
137 |
|
138 |
if (v instanceof Table) { |
139 |
return true; |
140 |
} |
141 |
return false; |
142 |
} |
143 |
|
144 |
} |