Revision 8474a42a

b/src/gr/grnet/pithos/web/client/PithosSelectionEventManager.java
43 43

  
44 44
import java.util.ArrayList;
45 45
import java.util.List;
46
import java.util.Set;
46 47

  
47 48
/**
48 49
 * An implementation of {@link com.google.gwt.view.client.CellPreviewEvent.Handler} that adds selection
......
103 104
      if ("click".equals(nativeEvent.getType())) {
104 105
        // Ignore if the event didn't occur in the correct column.
105 106
        if (column > -1 && column != event.getColumn()) {
107
            Pithos.LOG("PithosSelectionEventManager::translateSelectionEvent(), IGNORE because not same column: ", column, " != ", event.getColumn());
106 108
          return SelectAction.IGNORE;
107 109
        }
108 110

  
......
114 116
            // Synchronize the checkbox with the current selection state.
115 117
            input.setChecked(event.getDisplay().getSelectionModel().isSelected(
116 118
                event.getValue()));
119
              Pithos.LOG("PithosSelectionEventManager::translateSelectionEvent(), TOGGLE: synchronizing checkbox with current selection");
117 120
            return SelectAction.TOGGLE;
118 121
          }
119 122
        }
123
          Pithos.LOG("PithosSelectionEventManager::translateSelectionEvent(), IGNORE");
120 124
        return SelectAction.IGNORE;
121 125
      }
122 126

  
123 127
      // For keyboard events, do the default action.
128
        Pithos.LOG("PithosSelectionEventManager::translateSelectionEvent(), DEFAULT, since keyboard event");
124 129
      return SelectAction.DEFAULT;
125 130
    }
126 131
  }
......
261 266
  public void doMultiSelection(MultiSelectionModel<? super T> selectionModel,
262 267
      HasData<T> display, int row, T rowValue, SelectAction action,
263 268
      boolean selectRange, boolean clearOthers) {
269
      Pithos.LOG("PithosSelectionEventManager::doMultiSelection(row=", row, ", rowValue=", rowValue, ", action=", action, ", selectRange=", selectRange, ", clearOthers=", clearOthers, ")");
264 270
    // Determine if we will add or remove selection.
265 271
    boolean addToSelection = true;
266 272
    if (action != null) {
......
375 381
   */
376 382
  protected void handleMultiSelectionEvent(CellPreviewEvent<T> event,
377 383
      SelectAction action, MultiSelectionModel<? super T> selectionModel) {
378
    Pithos.LOG("handleMultiSelectionEvent(action=", action, ")");
384
    Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, ")");
379 385
    NativeEvent nativeEvent = event.getNativeEvent();
380 386
    String type = nativeEvent.getType();
381 387
    boolean rightclick = "mousedown".equals(type) && nativeEvent.getButton()==NativeEvent.BUTTON_RIGHT;
382 388
    SelectAction action1 = action;
383 389
    if(rightclick){
384
        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), rightclick");
390
        Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, "), rightclick");
385 391
    	boolean shift = nativeEvent.getShiftKey();
386 392
        boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey();
387 393
        boolean clearOthers = (translator == null) ? !ctrlOrMeta
......
391 397
        }
392 398
        //if the row is selected then do nothing
393 399
        if(selectionModel.isSelected(event.getValue())){
400
            Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, "), row is selected, event.getValue()=", event.getValue(), " RETURN");
394 401
        	return;
395 402
        }
396 403
        doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(),
......
409 416
      if (action == null || action == SelectAction.DEFAULT) {
410 417
        action1 = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT;
411 418
      }
412
        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), click, shift=", shift, ", ctrlOrMeta=", ctrlOrMeta, ", clearOthers=", clearOthers, ", action1=", action1);
419
        Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, "), click, shift=", shift, ", ctrlOrMeta=", ctrlOrMeta, ", clearOthers=", clearOthers, ", action1=", action1);
413 420
      doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(),
414 421
          event.getValue(), action1, shift, clearOthers);
415 422
      if(ctrlOrMeta){
416
          Pithos.LOG("handleMultiSelectionEvent(action=", action, "), click, ctrlOrMeta=true => cancelling event=", event);
423
          Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, "), click, ctrlOrMeta=true => cancelling event=", event);
417 424
    	  event.setCanceled(true);
418 425
      }
419 426
    } else if ("keyup".equals(type)) {
420 427
      int keyCode = nativeEvent.getKeyCode();
421
        Pithos.LOG("handleMultiSelectionEvent(action=", action, "), keyup, keyCode=", keyCode, ", isSpaceBar=", keyCode == 32);
428
        Pithos.LOG("PithosSelectionEventManager::handleMultiSelectionEvent(action=", action, "), keyup, keyCode=", keyCode, ", isSpaceBar=", keyCode == 32);
422 429
      if (keyCode == 32) {
423 430
        /*
424 431
         * Update selection when the space bar is pressed. The spacebar always
425 432
         * toggles selection, regardless of whether the control key is pressed.
426 433
         */
427 434
        boolean shift = nativeEvent.getShiftKey();
428
        boolean clearOthers = (translator == null) ? false
429
            : translator.clearCurrentSelection(event);
435
        boolean clearOthers = (translator != null) && translator.clearCurrentSelection(event);
430 436
        if (action == null || action == SelectAction.DEFAULT) {
431 437
          action1 = SelectAction.TOGGLE;
432 438
        }
......
495 501
   * @param selected true to select, false to deselect
496 502
   * @param clearOthers true to clear all other selected items
497 503
   */
498
  protected void selectOne(MultiSelectionModel<? super T> selectionModel,
499
      T target, boolean selected, boolean clearOthers) {
500
    if (clearOthers) {
501
      clearSelection(selectionModel);
502
    }
503
    selectionModel.setSelected(target, selected);
504
  protected void selectOne(
505
      MultiSelectionModel<? super T> selectionModel,
506
      T target,
507
      boolean selected,
508
      boolean clearOthers
509
  ) {
510
      Pithos.LOG("PithosSelectionEventManager::selectOne(target=", target, ", selected=", selected, ", clearOthers=", clearOthers, ")");
511
      if(clearOthers) {
512
          Pithos.LOG("PithosSelectionEventManager::selectOne(...), before clearSelection");
513
          Set<? super T> selectedSetBefore = selectionModel.getSelectedSet();
514
          for(Object selectedObj : selectedSetBefore) {
515
              Pithos.LOG("  ==> selected: ", selectedObj);
516
          }
517

  
518
          clearSelection(selectionModel);
519

  
520
          Pithos.LOG("PithosSelectionEventManager::selectOne(...), after clearSelection");
521
          Set<? super T> selectedSetAfter = selectionModel.getSelectedSet();
522
          for(Object selectedObj : selectedSetAfter) {
523
              Pithos.LOG("  ==> selected: ", selectedObj);
524
          }
525
      }
526

  
527
      selectionModel.setSelected(target, selected);
528
      Pithos.LOG("PithosSelectionEventManager::selectOne(...), after selectionModel.setSelected(target, selected)");
529
      Set<? super T> selectedSetAfter2 = selectionModel.getSelectedSet();
530
      for(Object selectedObj : selectedSetAfter2) {
531
          Pithos.LOG("  ==> selected: ", selectedObj);
532
      }
504 533
  }
505 534

  
506 535
  /**

Also available in: Unified diff