/[schmitzm]/branches/2.1/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/2.1/src/skrueger/geotools/selection/TableSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 103 by mojays, Fri May 8 13:48:00 2009 UTC revision 127 by mojays, Sat May 30 14:29:58 2009 UTC
# Line 27  import org.geotools.feature.Feature; Line 27  import org.geotools.feature.Feature;
27    
28  import schmitzm.geotools.gui.FeatureCollectionTableModel;  import schmitzm.geotools.gui.FeatureCollectionTableModel;
29  import schmitzm.swing.table.PipedTableModel;  import schmitzm.swing.table.PipedTableModel;
 import schmitzm.swing.table.SelectionTableModel;  
 import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;  
 import skrueger.geotools.selection.StyledLayerSelectionEvent;  
 import skrueger.geotools.selection.StyledLayerSelectionModel;  
30    
31  /**  /**
32   * This class keeps the selection of a (feature) {@link JTable} synchronized   * This class keeps the selection of a (feature) {@link JTable} synchronized
# Line 50  import skrueger.geotools.selection.Style Line 46  import skrueger.geotools.selection.Style
46   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
47   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
48   */   */
49  public class TableSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> implements ListSelectionListener {  public class TableSelectionSynchronizer extends
50                    StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
51                    implements ListSelectionListener {
52          /**          /**
53           * Holds the table to keep synchronized with the layer selection model.           * Holds the table to keep synchronized with the layer selection model.
54           */           */
# Line 67  public class TableSelectionSynchronizer Line 65  public class TableSelectionSynchronizer
65           * @param table           * @param table
66           *            table to keep synchronized with the layer selection model           *            table to keep synchronized with the layer selection model
67           */           */
68          public TableSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, JTable table) {          public TableSelectionSynchronizer(
69                            StyledFeatureLayerSelectionModel layerSelModel, JTable table) {
70                  super(layerSelModel);                  super(layerSelModel);
71    
72                  TableModel model = table.getModel();                  TableModel model = table.getModel();
# Line 102  public class TableSelectionSynchronizer Line 101  public class TableSelectionSynchronizer
101                          return;                          return;
102                  // Apply new selection on table (except this event is one of                  // Apply new selection on table (except this event is one of
103                  // some more events)                  // some more events)
104                  Vector<Feature> newSelection = layerSelModel.getSelection();                  Vector<String> newSelection = layerSelModel.getSelection();
105                  if (newSelection == null)                  if (newSelection == null)
106                          return;                          return;
107    
108                    // LOGGER.debug("Table pop changed "+selEvt);
109                    // LOGGER.debug("Table pop changed to "+newSelection);
110    
111                  // Avoid event circles in valueChanged(..)                  // Avoid event circles in valueChanged(..)
112                  selectionChangeCausedByMe = true;                  selectionChangeCausedByMe = true;
113    
114                  ListSelectionModel tableSelModel = featureTable.getSelectionModel();                  ListSelectionModel tableSelModel = featureTable.getSelectionModel();
115                  tableSelModel.setValueIsAdjusting(true);                  tableSelModel.setValueIsAdjusting(true);
116                  tableSelModel.clearSelection();                  tableSelModel.clearSelection();
117                  for (Feature f : newSelection) {                  for (String fid : newSelection) {
118                          int modelIdx = featureTableModel.findFeature(f);                          int modelIdx = featureTableModel.findFeature(fid);
119                          if (modelIdx >= 0) {                          if (modelIdx >= 0) {
120                                  int tableIdx = featureTable.convertRowIndexToView(modelIdx);                                  int tableIdx = featureTable.convertRowIndexToView(modelIdx);
121                                  tableSelModel.addSelectionInterval(tableIdx, tableIdx);                                  tableSelModel.addSelectionInterval(tableIdx, tableIdx);
122                            } else {
123                                    LOGGER
124                                                    .warn("Something that is not visible in the Table should be selected");
125                          }                          }
126                  }                  }
127                  tableSelModel.setValueIsAdjusting(false); // event is fired                  tableSelModel.setValueIsAdjusting(false); // event is fired
# Line 147  public class TableSelectionSynchronizer Line 152  public class TableSelectionSynchronizer
152    
153                  // reset the selection of the DpLayerSelectionModel                  // reset the selection of the DpLayerSelectionModel
154                  layerSelModel.setValueIsAdjusting(true);                  layerSelModel.setValueIsAdjusting(true);
155                  for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {                  LOGGER.debug("valueCahnged in TableSyncronizer vom Index "
156                          Feature changedFeature = featureTableModel.getFeature(featureTable                                  + evt.getFirstIndex() + " to " + evt.getLastIndex());
157                                          .convertRowIndexToModel(i));  
158                          if (featureTable.isRowSelected(i))                  if (evt == null || (evt != null && evt.getFirstIndex() == -1)){
159                                  layerSelModel.addSelection(changedFeature);                          // If the value is changing because the filter has been changed (e.g.
160                          else                          // table structure change) the evt.getFirstIndex() is -1, but evt.getLastIndex is > -1
161                                  layerSelModel.removeSelection(changedFeature);                          layerSelModel.clearSelection();
162                    } else{
163                            
164                            for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {
165                                    int featureIndex = featureTable.convertRowIndexToModel(i);
166                                    Feature changedFeature = featureTableModel.getFeature(featureIndex);
167                                    if (featureTable.isRowSelected(i))
168                                            layerSelModel.addSelection(changedFeature.getID());
169                                    else
170                                            layerSelModel.removeSelection(changedFeature.getID());
171                            }
172                  }                  }
173                  layerSelModel.setValueIsAdjusting(false);                  layerSelModel.setValueIsAdjusting(false);
174    

Legend:
Removed from v.103  
changed lines
  Added in v.127

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26