Esempio n. 1
0
 @Override
 protected void setSelectionToWidget(List in, boolean reveal) {
   if (reveal) {
     super.setSelectionToWidget(in, reveal);
   } else {
     if (in == null || in.size() == 0) { // clear selection
       list.deselectAll();
     } else {
       int n = in.size();
       int[] ixs = new int[n];
       int count = 0;
       for (int i = 0; i < n; ++i) {
         Object el = in.get(i);
         int ix = getElementIndex(el);
         if (ix >= 0) {
           ixs[count++] = ix;
         }
       }
       if (count < n) {
         System.arraycopy(ixs, 0, ixs = new int[count], 0, count);
       }
       list.deselectAll();
       list.select(ixs);
     }
   }
 }
Esempio n. 2
0
 /**
  * Deselects the items at the given zero-relative indices in the receiver. If the item at the
  * given zero-relative index in the receiver is selected, it is deselected. If the item at the
  * index was not selected, it remains deselected. The range of the indices is inclusive. Indices
  * that are out of range are ignored.
  *
  * @param start the start index of the items to deselect
  * @param end the end index of the items to deselect
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 1.3
  */
 public void deselect(int start, int end) {
   checkWidget();
   if (start == 0 && end == model.getItemCount() - 1) {
     deselectAll();
   } else {
     int actualStart = Math.max(0, start);
     for (int i = actualStart; i <= end; i++) {
       removeFromSelection(i);
     }
   }
 }
Esempio n. 3
0
 /**
  * Sets the contents of the receiver's text field to the given string.
  *
  * <p>Note: The text field in a <code>Combo</code> is typically only capable of displaying a
  * single line of text. Thus, setting the text to a string containing line breaks or other special
  * characters will probably cause it to display incorrectly.
  *
  * @param string the new text
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the string is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setText(String string) {
   checkWidget();
   if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   int index = list.indexOf(string);
   if (index == -1) {
     list.deselectAll();
     text.setText(string);
     return;
   }
   text.setText(string);
   text.selectAll();
   list.setSelection(index);
   list.showSelection();
 }
 private void browsePressed() {
   nameList.deselectAll();
   FileDialog subDlg = new FileDialog(getShell(), SWT.OPEN);
   selectedPath = subDlg.open();
   if (selectedPath != null) {
     try {
       selectedText = getFileContents(this.selectedPath);
       testTextField.setText(this.selectedText.getText());
       testTextField.redraw();
     } catch (Exception e) {
       messageLabel.setText(e.getMessage());
       messageLabel.redraw();
     }
   }
 }
Esempio n. 5
0
 /**
  * Selects the item at the given zero-relative index in the receiver's list. If the item at the
  * index was already selected, it remains selected. Indices that are out of range are ignored.
  *
  * @param index the index of the item to select
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void select(int index) {
   checkWidget();
   if (index == -1) {
     list.deselectAll();
     text.setText(""); // $NON-NLS-1$
     return;
   }
   if (0 <= index && index < list.getItemCount()) {
     if (index != getSelectionIndex()) {
       text.setText(list.getItem(index));
       text.selectAll();
       list.select(index);
       list.showSelection();
     }
   }
 }
Esempio n. 6
0
 public void deselectAll() {
   checkWidget();
   list.deselectAll();
 }
Esempio n. 7
0
 /**
  * Sets the selection in the receiver's text field to an empty selection starting just before the
  * first character. If the text field is editable, this has the effect of placing the i-beam at
  * the start of the text.
  *
  * <p>Note: To clear the selected items in the receiver's list, use <code>deselectAll()</code>.
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @see #deselectAll
  */
 public void clearSelection() {
   checkWidget();
   text.clearSelection();
   list.deselectAll();
 }
Esempio n. 8
0
  void textEvent(Event event) {
    switch (event.type) {
      case SWT.FocusIn:
        {
          handleFocus(SWT.FocusIn);
          break;
        }
      case SWT.KeyDown:
        {
          if (event.character == SWT.CR) {
            dropDown(false);
            Event e = new Event();
            e.time = event.time;
            e.stateMask = event.stateMask;
            notifyListeners(SWT.DefaultSelection, e);
          }
          // At this point the widget may have been disposed.
          // If so, do not continue.
          if (isDisposed()) break;

          if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) {
            event.doit = false;
            if ((event.stateMask & SWT.ALT) != 0) {
              boolean dropped = isDropped();
              text.selectAll();
              if (!dropped) setFocus();
              dropDown(!dropped);
              break;
            }

            int oldIndex = getSelectionIndex();
            if (event.keyCode == SWT.ARROW_UP && popup.isVisible()) {
              select(Math.max(oldIndex - 1, 0));
            } else if (popup.isVisible()) {
              select(Math.min(oldIndex + 1, getItemCount() - 1));
            }
            if (oldIndex != getSelectionIndex()) {
              Event e = new Event();
              e.time = event.time;
              e.stateMask = event.stateMask;
              notifyListeners(SWT.Selection, e);
            }
            // At this point the widget may have been disposed.
            // If so, do not continue.
            if (isDisposed()) break;
          }

          // Further work : Need to add support for incremental search in
          // pop up list as characters typed in text widget

          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyDown, e);
          break;
        }
      case SWT.KeyUp:
        {
          Event e = new Event();
          e.time = event.time;
          e.character = event.character;
          e.keyCode = event.keyCode;
          e.stateMask = event.stateMask;
          notifyListeners(SWT.KeyUp, e);
          break;
        }
      case SWT.Modify:
        {
          list.deselectAll();
          Event e = new Event();
          e.time = event.time;
          notifyListeners(SWT.Modify, e);
          break;
        }

      case SWT.MouseDown:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          boolean dropped = isDropped();
          text.selectAll();
          if (!dropped) setFocus();
          dropDown(!dropped);
          break;
        }

      case SWT.MouseUp:
        {
          if (event.button != 1) return;
          if (text.getEditable()) return;
          text.selectAll();
          break;
        }

      case SWT.Traverse:
        {
          switch (event.detail) {
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_ARROW_PREVIOUS:
            case SWT.TRAVERSE_ARROW_NEXT:
              // The enter causes default selection and
              // the arrow keys are used to manipulate the list contents so
              // do not use them for traversal.
              event.doit = false;
              break;
          }

          Event e = new Event();
          e.time = event.time;
          e.detail = event.detail;
          e.doit = event.doit;
          e.character = event.character;
          e.keyCode = event.keyCode;
          notifyListeners(SWT.Traverse, e);
          event.doit = e.doit;
          event.detail = e.detail;
          break;
        }
    }
  }
Esempio n. 9
0
 @Override
 protected void listDeselectAll() {
   list.deselectAll();
 }