Revision 39081
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableOperations.java | ||
---|---|---|
28 | 28 |
import java.util.List; |
29 | 29 |
|
30 | 30 |
import javax.swing.JOptionPane; |
31 |
import javax.swing.event.TableModelListener; |
|
31 | 32 |
|
32 | 33 |
import org.slf4j.Logger; |
33 | 34 |
import org.slf4j.LoggerFactory; |
... | ... | |
36 | 37 |
import org.gvsig.andami.messages.NotificationManager; |
37 | 38 |
import org.gvsig.app.ApplicationLocator; |
38 | 39 |
import org.gvsig.app.project.documents.table.gui.CreateNewAttributePanel; |
40 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
39 | 41 |
import org.gvsig.fmap.dal.DataTypes; |
40 | 42 |
import org.gvsig.fmap.dal.exception.DataException; |
41 | 43 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
... | ... | |
48 | 50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 | 51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
50 | 52 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTable; |
53 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel; |
|
51 | 54 |
import org.gvsig.i18n.Messages; |
52 | 55 |
import org.gvsig.tools.dispose.DisposableIterator; |
53 | 56 |
|
... | ... | |
63 | 66 |
|
64 | 67 |
public static final int MAX_FIELD_LENGTH = 254; |
65 | 68 |
private static TableOperations fto = null; |
66 |
private FeatureStore featureStore; |
|
67 | 69 |
private ArrayList<Feature> selectedFeatures = new ArrayList<Feature>(); |
68 | 70 |
private boolean cutting = false; |
71 |
|
|
72 |
private FeatureTableDocumentPanel tablePanel = null; |
|
73 |
private FeatureStore featureStore; |
|
69 | 74 |
|
70 | 75 |
public static TableOperations getInstance() { |
71 | 76 |
if (fto == null) { |
... | ... | |
74 | 79 |
return fto; |
75 | 80 |
} |
76 | 81 |
|
77 |
public void setStore(FeatureStore store) { |
|
78 |
featureStore = store; |
|
82 |
public void setTablePanel(FeatureTableDocumentPanel tp) { |
|
83 |
tablePanel = tp; |
|
84 |
featureStore = tp.getModel().getStore(); |
|
79 | 85 |
} |
80 | 86 |
|
81 | 87 |
public void copyFeatures() throws DataException { |
... | ... | |
130 | 136 |
} |
131 | 137 |
|
132 | 138 |
public void deleteFeatures() throws DataException { |
139 |
|
|
140 |
FeatureTableModel _ftm = this.tablePanel.getTablePanel().getTableModel(); |
|
141 |
List<TableModelListener> tmll = removeTableModelListeners(_ftm); |
|
142 |
|
|
143 |
|
|
133 | 144 |
DisposableIterator features = null; |
134 | 145 |
try { |
146 |
/* |
|
135 | 147 |
features = |
136 | 148 |
((FeatureSelection) featureStore.getSelection()).fastIterator(); |
149 |
*/ |
|
137 | 150 |
|
138 |
// featureStore.beginEditingGroup("Deleting one or more selected rows in table."); |
|
151 |
FeatureSet all_fset = featureStore.getFeatureSet(); |
|
152 |
FeatureSelection sele = (FeatureSelection) featureStore.getSelection(); |
|
153 |
features = all_fset.fastIterator(); |
|
154 |
Feature item = null; |
|
139 | 155 |
|
140 |
List<Feature> sel = new ArrayList<Feature>(); |
|
141 | 156 |
while (features.hasNext()) { |
142 |
Feature feature = (Feature) features.next(); |
|
143 |
sel.add(feature); |
|
157 |
item = (Feature) features.next(); |
|
158 |
if (sele.isSelected(item)) { |
|
159 |
all_fset.delete(item); |
|
160 |
} |
|
144 | 161 |
} |
145 |
|
|
146 |
int n = sel.size();
|
|
147 |
for (int i=0; i<n; i++) {
|
|
148 |
featureStore.delete(sel.get(i));
|
|
162 |
|
|
163 |
/*
|
|
164 |
while (features.hasNext()) {
|
|
165 |
features.remove();
|
|
149 | 166 |
} |
150 |
sel.clear(); |
|
151 |
// featureStore.endEditingGroup(); |
|
167 |
*/ |
|
152 | 168 |
|
153 | 169 |
} finally { |
154 | 170 |
if (features != null) { |
155 | 171 |
features.dispose(); |
156 | 172 |
} |
173 |
|
|
174 |
addTableModelListeners(_ftm, tmll); |
|
157 | 175 |
} |
158 | 176 |
} |
159 | 177 |
|
178 |
/** |
|
179 |
* @param _ftm |
|
180 |
* @param tmll |
|
181 |
*/ |
|
182 |
private void addTableModelListeners( |
|
183 |
FeatureTableModel _model, |
|
184 |
List<TableModelListener> _list) { |
|
185 |
|
|
186 |
Iterator<TableModelListener> iter = _list.iterator(); |
|
187 |
while (iter.hasNext()) { |
|
188 |
_model.addTableModelListener(iter.next()); |
|
189 |
} |
|
190 |
_model.fireTableDataChanged(); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* @param ftm |
|
195 |
* @param class1 |
|
196 |
* @return |
|
197 |
*/ |
|
198 |
private List<TableModelListener> removeTableModelListeners(FeatureTableModel ftm) { |
|
199 |
|
|
200 |
TableModelListener[] ll = ftm.getListeners(TableModelListener.class); |
|
201 |
List<TableModelListener> resp = new ArrayList<TableModelListener>(); |
|
202 |
|
|
203 |
int n = ll.length; |
|
204 |
for (int i=0; i<n; i++) { |
|
205 |
resp.add(ll[i]); |
|
206 |
ftm.removeTableModelListener(ll[i]); |
|
207 |
} |
|
208 |
|
|
209 |
return resp; |
|
210 |
} |
|
211 |
|
|
160 | 212 |
public void insertNewFeature() throws DataException { |
161 | 213 |
// if (getModel().getAssociatedTable()!=null){ |
162 | 214 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"No se puede a?adir una fila a una tabla asociada a una capa."); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditRemoveRowExtension.java | ||
---|---|---|
41 | 41 |
public void execute(String actionCommand) { |
42 | 42 |
if ("table-remove-row".equals(actionCommand)) { |
43 | 43 |
try { |
44 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
44 |
featureTableOperations.setTablePanel(table);
|
|
45 | 45 |
featureTableOperations.deleteFeatures(); |
46 | 46 |
} catch (DataException e) { |
47 | 47 |
e.printStackTrace(); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditChangeColumnsExtension.java | ||
---|---|---|
44 | 44 |
*/ |
45 | 45 |
public void execute(String actionCommand) { |
46 | 46 |
try { |
47 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
47 |
featureTableOperations.setTablePanel(table);
|
|
48 | 48 |
if ("table-remove-column".equals(actionCommand)) { |
49 | 49 |
featureTableOperations.deleteAttributes(table.getTablePanel() |
50 | 50 |
.getTable()); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditCutExtension.java | ||
---|---|---|
43 | 43 |
public void execute(String actionCommand) { |
44 | 44 |
if ("edit-cut-table".equals(actionCommand)) { |
45 | 45 |
try { |
46 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
46 |
featureTableOperations.setTablePanel(table);
|
|
47 | 47 |
featureTableOperations.cutFeatures(); |
48 | 48 |
} catch (DataException e) { |
49 | 49 |
e.printStackTrace(); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditInsertExtension.java | ||
---|---|---|
41 | 41 |
public void execute(String actionCommand) { |
42 | 42 |
if ("table-add-row".equals(actionCommand)) { |
43 | 43 |
try { |
44 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
44 |
featureTableOperations.setTablePanel(table);
|
|
45 | 45 |
featureTableOperations.insertNewFeature(); |
46 | 46 |
} catch (DataException e) { |
47 | 47 |
e.printStackTrace(); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditCopyExtension.java | ||
---|---|---|
43 | 43 |
public void execute(String actionCommand) { |
44 | 44 |
if ("edit-copy-table".equals(actionCommand)) { |
45 | 45 |
try { |
46 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
46 |
featureTableOperations.setTablePanel(table);
|
|
47 | 47 |
featureTableOperations.copyFeatures(); |
48 | 48 |
} catch (DataException e) { |
49 | 49 |
e.printStackTrace(); |
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableEditPasteExtension.java | ||
---|---|---|
43 | 43 |
public void execute(String actionCommand) { |
44 | 44 |
if ("edit-paste-table".equals(actionCommand)) { |
45 | 45 |
try { |
46 |
featureTableOperations.setStore(table.getModel().getStore());
|
|
46 |
featureTableOperations.setTablePanel(table);
|
|
47 | 47 |
featureTableOperations.pasteFeatures(); |
48 | 48 |
} catch (DataException e) { |
49 | 49 |
e.printStackTrace(); |
Also available in: Unified diff