/** Method for creating a list */
 protected void createList(
     int horizontalSpan, int verticalSpan, int widthHint, int numberOfItems) {
   entityList = new List(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.HORIZONTAL);
   GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
   gridData.verticalSpan = verticalSpan;
   gridData.horizontalSpan = horizontalSpan;
   gridData.heightHint = entityList.getItemHeight() * numberOfItems;
   gridData.widthHint = widthHint;
   entityList.setLayoutData(gridData);
 }
Exemple #2
0
  private void computeShowArea() {
    //    Point size = getSize ();
    int itemCount = list.getItemCount();
    itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
    int itemHeight = list.getItemHeight() * itemCount;
    Point listSize = list.computeSize(SWT.DEFAULT, itemHeight, false);
    //  list.setBounds(1, 1, Math.min (size.x - 2, listSize.x), listSize.y);

    int index = list.getSelectionIndex();
    if (index != -1) list.setTopIndex(index);

    Display display = getDisplay();
    Rectangle listRect = list.getBounds();
    Rectangle parentRect = display.map(getParent(), null, getBounds());
    Point comboSize = getSize();
    Rectangle displayRect = getMonitor().getClientArea();
    int width = Math.max(comboSize.x, listRect.width + 2);
    int height = listRect.height + 2;
    int x = parentRect.x;
    int y = parentRect.y + comboSize.y;
    if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height;
    popup.setBounds(x, y, width - 15, listSize.y + 15);
  }
 @Override
 public void reveal(Object element) {
   Assert.isNotNull(element);
   int index = getElementIndex(element);
   if (index == -1) {
     return;
   }
   // algorithm patterned after List.showSelection()
   int count = list.getItemCount();
   if (count == 0) {
     return;
   }
   int height = list.getItemHeight();
   Rectangle rect = list.getClientArea();
   int topIndex = list.getTopIndex();
   int visibleCount = Math.max(rect.height / height, 1);
   int bottomIndex = Math.min(topIndex + visibleCount, count) - 1;
   if ((topIndex <= index) && (index <= bottomIndex)) {
     return;
   }
   int newTop = Math.min(Math.max(index - (visibleCount / 2), 0), count - 1);
   list.setTopIndex(newTop);
 }
Exemple #4
0
 public int getItemHeight() {
   checkWidget();
   return list.getItemHeight();
 }
  /**
   * Creates the filtering list widgets
   *
   * @param ancestor the ancestor
   */
  private void createFilterLists(Composite ancestor) {
    // Do not show the filter lists if not filter criteria
    // is defined.
    if (filterStrings.length == 0) return;
    // setup layout
    Composite parent = new Composite(ancestor, SWT.NULL);
    Composite dummy = new Composite(ancestor, SWT.NULL);
    GridData dgd = new GridData();
    dgd.widthHint = 0;
    dummy.setLayoutData(dgd);

    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 3;
    parent.setLayout(layout);

    // Create the possible filter items list
    Label filterItemsLabel = new Label(parent, SWT.LEFT);
    filterItemsLabel.setText(FILTER_ITEMS_CONTAINING);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    filterItemsLabel.setLayoutData(gd);

    // Create the possible filter items list
    // Label emptyLabel =
    new Label(parent, SWT.LEFT);

    // Create the possible filter items list
    Label filterItemLabel = new Label(parent, SWT.LEFT);
    filterItemLabel.setText(FILTER_ITEMS_LIST);
    GridData gd2 = new GridData();
    gd2.horizontalAlignment = GridData.BEGINNING;
    filterItemLabel.setLayoutData(gd2);

    // Create the possible filter items list
    filters = new org.eclipse.swt.widgets.List(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL);
    gridData.verticalSpan = 1;
    gridData.widthHint = 80;
    int listHeight = filters.getItemHeight() * LIST_HEIGHT;
    Rectangle trim = filters.computeTrim(0, 0, 0, listHeight);
    gridData.heightHint = trim.height;
    filters.setLayoutData(gridData);

    // Create a new composite for the buttons and add
    // stack them vertically
    Composite buttonComposite = new Composite(parent, SWT.NULL);
    GridLayout buttonLayout = new GridLayout();
    buttonLayout.marginHeight = 0;
    buttonLayout.marginWidth = 0;
    buttonLayout.numColumns = 1;
    buttonComposite.setLayout(buttonLayout);

    GridData buttGD = new GridData(GridData.FILL_VERTICAL | GridData.CENTER);
    buttGD.horizontalSpan = 1;
    buttGD.widthHint = 30;
    buttonComposite.setLayoutData(buttGD);

    removeFrom = new Button(buttonComposite, SWT.PUSH);
    removeFrom.setText(REMOVE_FROM_LABEL);
    removeFrom.setToolTipText(REMOVE_FROM);
    removeFrom.setLayoutData(makeArrowButtonGridData(removeFrom));
    removeFrom.setData(new Integer(REMOVE_FROM_ID));
    removeFrom.addSelectionListener(buttonSelectionAdapter);
    removeFrom.setEnabled(false);

    addTo = new Button(buttonComposite, SWT.PUSH);
    addTo.setText(ADD_TO_LABEL);
    addTo.setToolTipText(ADD_TO);
    addTo.setLayoutData(makeArrowButtonGridData(addTo));
    addTo.setData(new Integer(ADD_TO_ID));
    addTo.addSelectionListener(buttonSelectionAdapter);
    addTo.setEnabled(false);

    removeAllFrom = new Button(buttonComposite, SWT.PUSH);
    removeAllFrom.setText(REMOVE_ALL_LABEL);
    removeAllFrom.setToolTipText(REMOVE_ALL);
    removeAllFrom.setLayoutData(makeArrowButtonGridData(removeAllFrom));
    removeAllFrom.setData(new Integer(REMOVE_ALL_FROM_ID));
    removeAllFrom.addSelectionListener(buttonSelectionAdapter);
    addAllTo = new Button(buttonComposite, SWT.PUSH);

    addAllTo.setText(ADD_ALL_LABEL);
    addAllTo.setToolTipText(ADD_ALL);
    addAllTo.setLayoutData(makeArrowButtonGridData(addAllTo));
    addAllTo.setData(Integer.valueOf(ADD_ALL_TO_ID));
    addAllTo.addSelectionListener(buttonSelectionAdapter);

    // Add the possible list of filter items
    this.filterList =
        new org.eclipse.swt.widgets.List(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    GridData gridData2 = new GridData(GridData.VERTICAL_ALIGN_FILL);
    gridData2.verticalSpan = 1;
    gridData2.widthHint = 80;
    int listHeight2 = filterList.getItemHeight() * LIST_HEIGHT;
    Rectangle trim2 = filterList.computeTrim(0, 0, 0, listHeight2);
    gridData.heightHint = trim2.height;
    filterList.setLayoutData(gridData2);

    filters.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            removeFrom.setEnabled(filters.getSelectionCount() > 0);
          }
        });

    filterList.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            addTo.setEnabled(filterList.getSelectionCount() > 0);
          }
        });

    populateFilterLists();
  }