/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/1.0-gt2-2.6/src/skrueger/geotools/selection/TableSelectionSynchronizer.java

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

revision 106 by alfonx, Fri May 8 15:13:49 2009 UTC revision 111 by alfonx, Tue May 12 23:33:14 2009 UTC
# Line 50  import skrueger.geotools.selection.Style Line 50  import skrueger.geotools.selection.Style
50   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
51   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
52   */   */
53  public class TableSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> implements ListSelectionListener {  public class TableSelectionSynchronizer extends
54                    StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
55                    implements ListSelectionListener {
56          /**          /**
57           * Holds the table to keep synchronized with the layer selection model.           * Holds the table to keep synchronized with the layer selection model.
58           */           */
# Line 67  public class TableSelectionSynchronizer Line 69  public class TableSelectionSynchronizer
69           * @param table           * @param table
70           *            table to keep synchronized with the layer selection model           *            table to keep synchronized with the layer selection model
71           */           */
72          public TableSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, JTable table) {          public TableSelectionSynchronizer(
73                            StyledFeatureLayerSelectionModel layerSelModel, JTable table) {
74                  super(layerSelModel);                  super(layerSelModel);
75    
76                  TableModel model = table.getModel();                  TableModel model = table.getModel();
# Line 102  public class TableSelectionSynchronizer Line 105  public class TableSelectionSynchronizer
105                          return;                          return;
106                  // Apply new selection on table (except this event is one of                  // Apply new selection on table (except this event is one of
107                  // some more events)                  // some more events)
108                  Vector<Feature> newSelection = layerSelModel.getSelection();                  Vector<String> newSelection = layerSelModel.getSelection();
109                  if (newSelection == null)                  if (newSelection == null)
110                          return;                          return;
111                    
112  //              LOGGER.debug("Table pop changed "+selEvt);                  // LOGGER.debug("Table pop changed "+selEvt);
113  //              LOGGER.debug("Table pop changed to "+newSelection);                  // LOGGER.debug("Table pop changed to "+newSelection);
114    
115                  // Avoid event circles in valueChanged(..)                  // Avoid event circles in valueChanged(..)
116                  selectionChangeCausedByMe = true;                  selectionChangeCausedByMe = true;
# Line 115  public class TableSelectionSynchronizer Line 118  public class TableSelectionSynchronizer
118                  ListSelectionModel tableSelModel = featureTable.getSelectionModel();                  ListSelectionModel tableSelModel = featureTable.getSelectionModel();
119                  tableSelModel.setValueIsAdjusting(true);                  tableSelModel.setValueIsAdjusting(true);
120                  tableSelModel.clearSelection();                  tableSelModel.clearSelection();
121                  for (Feature f : newSelection) {                  for (String fid : newSelection) {
122                          int modelIdx = featureTableModel.findFeature(f);                          int modelIdx = featureTableModel.findFeature(fid);
123                          if (modelIdx >= 0) {                          if (modelIdx >= 0) {
124                                  int tableIdx = featureTable.convertRowIndexToView(modelIdx);                                  int tableIdx = featureTable.convertRowIndexToView(modelIdx);
125                                  tableSelModel.addSelectionInterval(tableIdx, tableIdx);                                  tableSelModel.addSelectionInterval(tableIdx, tableIdx);
126                            } else {
127                                    LOGGER
128                                                    .warn("Something that is not visible in the Table should be selected");
129                          }                          }
130                  }                  }
131                  tableSelModel.setValueIsAdjusting(false); // event is fired                  tableSelModel.setValueIsAdjusting(false); // event is fired
# Line 150  public class TableSelectionSynchronizer Line 156  public class TableSelectionSynchronizer
156    
157                  // reset the selection of the DpLayerSelectionModel                  // reset the selection of the DpLayerSelectionModel
158                  layerSelModel.setValueIsAdjusting(true);                  layerSelModel.setValueIsAdjusting(true);
159                  for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {                  LOGGER.debug("valueCahnged in TableSyncronizer vom Index "
160                          Feature changedFeature = featureTableModel.getFeature(featureTable                                  + evt.getFirstIndex() + " to " + evt.getLastIndex());
161                                          .convertRowIndexToModel(i));  
162                          if (featureTable.isRowSelected(i))                  if (evt == null || (evt != null && evt.getFirstIndex() == -1)){
163                                  layerSelModel.addSelection(changedFeature);                          // If the value is changing because the filter has been changed (e.g.
164                          else                          // table structure change) the evt.getFirstIndex() is -1, but evt.getLastIndex is > -1
165                                  layerSelModel.removeSelection(changedFeature);                          layerSelModel.clearSelection();
166                    } else{
167                            
168                            for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {
169                                    int featureIndex = featureTable.convertRowIndexToModel(i);
170                                    Feature changedFeature = featureTableModel.getFeature(featureIndex);
171                                    if (featureTable.isRowSelected(i))
172                                            layerSelModel.addSelection(changedFeature.getID());
173                                    else
174                                            layerSelModel.removeSelection(changedFeature.getID());
175                            }
176                  }                  }
177                  layerSelModel.setValueIsAdjusting(false);                  layerSelModel.setValueIsAdjusting(false);
178    

Legend:
Removed from v.106  
changed lines
  Added in v.111

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26