コード例 #1
0
 private void handleRemove() {
   IStructuredSelection ssel = (IStructuredSelection) fImportListViewer.getSelection();
   if (ssel.size() > 0) {
     Table table = fImportListViewer.getTable();
     int index = table.getSelectionIndices()[0];
     doRemove(ssel.toList());
     table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
     pageChanged(false, true);
   }
 }
コード例 #2
0
 private void handleAdd() {
   IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
   if (ssel.size() > 0) {
     Table table = fAvailableListViewer.getTable();
     int index = table.getSelectionIndices()[0];
     doAdd(ssel.toList());
     table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
     pageChanged(true, false);
   }
 }
コード例 #3
0
  private void sort(int column) {
    if (table.getItemCount() <= 1) return;

    TableItem[] items = table.getItems();
    String[][] data = new String[items.length][table.getColumnCount()];
    for (int i = 0; i < items.length; i++) {
      for (int j = 0; j < table.getColumnCount(); j++) {
        data[i][j] = items[i].getText(j);
      }
    }

    Arrays.sort(data, new RowComparator(column));

    if (lastSortColumn != column) {
      table.setSortColumn(table.getColumn(column));
      table.setSortDirection(SWT.DOWN);
      for (int i = 0; i < data.length; i++) {
        items[i].setText(data[i]);
      }
      lastSortColumn = column;
    } else {
      // reverse order if the current column is selected again
      table.setSortDirection(SWT.UP);
      int j = data.length - 1;
      for (int i = 0; i < data.length; i++) {
        items[i].setText(data[j--]);
      }
      lastSortColumn = -1;
    }
  }
コード例 #4
0
  private boolean findEntry() {
    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    boolean matchCase = searchDialog.getMatchCase();
    boolean matchWord = searchDialog.getMatchWord();
    String searchString = searchDialog.getSearchString();
    int column = searchDialog.getSelectedSearchArea();

    searchString = matchCase ? searchString : searchString.toLowerCase();

    boolean found = false;
    if (searchDialog.getSearchDown()) {
      for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    } else {
      for (int i = table.getSelectionIndex() - 1; i > -1; i--) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    }

    shell.setCursor(null);

    return found;
  }
コード例 #5
0
 /**
  * Positions the TableCursor over the cell at the given row and column in the parent table.
  *
  * @param row the index of the row for the cell to select
  * @param column the index of column for the cell 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 setSelection(int row, int column) {
   checkWidget();
   int columnCount = table.getColumnCount();
   int maxColumnIndex = columnCount == 0 ? 0 : columnCount - 1;
   if (row < 0 || row >= table.getItemCount() || column < 0 || column > maxColumnIndex)
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   setRowColumn(row, column, false);
 }
コード例 #6
0
  @Override
  public void modelChanged(IModelChangedEvent event) {
    if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      fHeader = null;
      markStale();
      return;
    }

    if (getExportedPackageHeader().equals(event.getChangedProperty())) {
      refresh();
      // Bug 171896
      // Since the model sends a CHANGE event instead of
      // an INSERT event on the very first addition to the empty table
      // Selection should fire here to take this first insertion into account
      Object lastElement =
          fPackageViewer.getElementAt(fPackageViewer.getTable().getItemCount() - 1);
      if (lastElement != null) {
        fPackageViewer.setSelection(new StructuredSelection(lastElement));
      }

      return;
    }

    Object[] objects = event.getChangedObjects();
    for (Object changedObject : objects) {
      if (changedObject instanceof ExportPackageObject) {
        ExportPackageObject object = (ExportPackageObject) changedObject;
        switch (event.getChangeType()) {
          case IModelChangedEvent.INSERT:
            fPackageViewer.add(object);
            fPackageViewer.setSelection(new StructuredSelection(object), false);
            fPackageViewer.getTable().setFocus();
            break;
          case IModelChangedEvent.REMOVE:
            Table table = fPackageViewer.getTable();
            int index = table.getSelectionIndex();
            fPackageViewer.remove(object);
            table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
            break;
          default:
            fPackageViewer.refresh(object);
        }
      }
    }
  }
コード例 #7
0
 void tableMouseDown(Event event) {
   if (isDisposed() || !isVisible()) return;
   Point pt = new Point(event.x, event.y);
   int lineWidth = table.getLinesVisible() ? table.getGridLineWidth() : 0;
   TableItem item = table.getItem(pt);
   if ((table.getStyle() & SWT.FULL_SELECTION) != 0) {
     if (item == null) return;
   } else {
     int start = item != null ? table.indexOf(item) : table.getTopIndex();
     int end = table.getItemCount();
     Rectangle clientRect = table.getClientArea();
     for (int i = start; i < end; i++) {
       TableItem nextItem = table.getItem(i);
       Rectangle rect = nextItem.getBounds(0);
       if (pt.y >= rect.y && pt.y < rect.y + rect.height + lineWidth) {
         item = nextItem;
         break;
       }
       if (rect.y > clientRect.y + clientRect.height) return;
     }
     if (item == null) return;
   }
   TableColumn newColumn = null;
   int columnCount = table.getColumnCount();
   if (columnCount == 0) {
     if ((table.getStyle() & SWT.FULL_SELECTION) == 0) {
       Rectangle rect = item.getBounds(0);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (!rect.contains(pt)) return;
     }
   } else {
     for (int i = 0; i < columnCount; i++) {
       Rectangle rect = item.getBounds(i);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (rect.contains(pt)) {
         newColumn = table.getColumn(i);
         break;
       }
     }
     if (newColumn == null) {
       if ((table.getStyle() & SWT.FULL_SELECTION) == 0) return;
       newColumn = table.getColumn(0);
     }
   }
   setRowColumn(item, newColumn, true);
   setFocus();
   return;
 }
コード例 #8
0
 @Override
 public boolean performOk() {
   try {
     updateNature();
     for (int i = 0; i < profilesTable.getItemCount(); ++i) {
       TableItem item = profilesTable.getItem(i);
       storeItem(item);
     }
     settings.save();
   } catch (CoreException e) {
     reportStatus(e.getStatus());
   }
   return super.performOk();
 }
コード例 #9
0
  @Override
  protected void performDefaults() {
    typeTable.removeAll();
    colorPicker.removeAll();
    for (DBPConnectionType source : DataSourceProviderRegistry.getInstance().getConnectionTypes()) {
      addTypeToTable(source, new DBPConnectionType(source));
    }
    typeTable.select(0);
    if (selectedType != null) {
      for (int i = 0; i < typeTable.getItemCount(); i++) {
        if (typeTable.getItem(i).getData().equals(selectedType)) {
          typeTable.select(i);
          break;
        }
      }
    }
    // Ad predefined colors
    int[] colorList = {
      SWT.COLOR_WHITE,
      SWT.COLOR_BLACK,
      SWT.COLOR_RED,
      SWT.COLOR_DARK_RED,
      SWT.COLOR_GREEN,
      SWT.COLOR_DARK_GREEN,
      SWT.COLOR_YELLOW,
      SWT.COLOR_DARK_YELLOW,
      SWT.COLOR_BLUE,
      SWT.COLOR_DARK_BLUE,
      SWT.COLOR_MAGENTA,
      SWT.COLOR_DARK_MAGENTA,
      SWT.COLOR_CYAN,
      SWT.COLOR_DARK_CYAN,
      SWT.COLOR_GRAY,
      SWT.COLOR_DARK_GRAY
    };
    for (int colorCode : colorList) {
      Color color = colorPicker.getShell().getDisplay().getSystemColor(colorCode);
      colorPicker.add(null, COLOR_TEXT, color, color);
    }
    showSelectedType(getSelectedType());

    typeTable.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent e) {
            UIUtils.packColumns(typeTable, true);
          }
        });
    super.performDefaults();
  }
コード例 #10
0
  private void sort(int column) {
    if (table.getItemCount() <= 1) return;

    TableItem[] items = table.getItems();
    String[][] data = new String[items.length][table.getColumnCount()];
    for (int i = 0; i < items.length; i++) {
      for (int j = 0; j < table.getColumnCount(); j++) {
        data[i][j] = items[i].getText(j);
      }
    }

    Arrays.sort(data, new RowComparator(column));

    for (int i = 0; i < data.length; i++) {
      items[i].setText(data[i]);
    }
  }
コード例 #11
0
  /* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
   */
  public void modelChanged(IModelChangedEvent e) {
    // No need to call super, handling world changed event here
    if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      handleModelEventWorldChanged(e);
      return;
    }
    Object[] objects = e.getChangedObjects();
    if (e.getChangeType() == IModelChangedEvent.INSERT) {
      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.add(objects[i]);
      }
    } else if (e.getChangeType() == IModelChangedEvent.REMOVE) {

      Table table = fPluginTable.getTable();
      int index = table.getSelectionIndex();

      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.remove(objects[i]);
      }

      // Update Selection

      int count = table.getItemCount();

      if (count == 0) {
        // Nothing to select
      } else if (index < count) {
        table.setSelection(index);
      } else {
        table.setSelection(count - 1);
      }

    } else if (e.getChangeType() == IModelChangedEvent.CHANGE) {
      fPluginTable.refresh();
    }
    updateRemoveButtons(false, true);
  }
コード例 #12
0
 void keyDown(Event event) {
   if (row == null) return;
   switch (event.character) {
     case SWT.CR:
       notifyListeners(SWT.DefaultSelection, new Event());
       return;
   }
   int rowIndex = table.indexOf(row);
   int columnIndex = column == null ? 0 : table.indexOf(column);
   switch (event.keyCode) {
     case SWT.ARROW_UP:
       setRowColumn(Math.max(0, rowIndex - 1), columnIndex, true);
       break;
     case SWT.ARROW_DOWN:
       setRowColumn(Math.min(rowIndex + 1, table.getItemCount() - 1), columnIndex, true);
       break;
     case SWT.ARROW_LEFT:
     case SWT.ARROW_RIGHT:
       {
         int columnCount = table.getColumnCount();
         if (columnCount == 0) break;
         int[] order = table.getColumnOrder();
         int index = 0;
         while (index < order.length) {
           if (order[index] == columnIndex) break;
           index++;
         }
         if (index == order.length) index = 0;
         int leadKey = (getStyle() & SWT.RIGHT_TO_LEFT) != 0 ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT;
         if (event.keyCode == leadKey) {
           setRowColumn(rowIndex, order[Math.max(0, index - 1)], true);
         } else {
           setRowColumn(rowIndex, order[Math.min(columnCount - 1, index + 1)], true);
         }
         break;
       }
     case SWT.HOME:
       setRowColumn(0, columnIndex, true);
       break;
     case SWT.END:
       {
         int i = table.getItemCount() - 1;
         setRowColumn(i, columnIndex, true);
         break;
       }
     case SWT.PAGE_UP:
       {
         int index = table.getTopIndex();
         if (index == rowIndex) {
           Rectangle rect = table.getClientArea();
           TableItem item = table.getItem(index);
           Rectangle itemRect = item.getBounds(0);
           rect.height -= itemRect.y;
           int height = table.getItemHeight();
           int page = Math.max(1, rect.height / height);
           index = Math.max(0, index - page + 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
     case SWT.PAGE_DOWN:
       {
         int index = table.getTopIndex();
         Rectangle rect = table.getClientArea();
         TableItem item = table.getItem(index);
         Rectangle itemRect = item.getBounds(0);
         rect.height -= itemRect.y;
         int height = table.getItemHeight();
         int page = Math.max(1, rect.height / height);
         int end = table.getItemCount() - 1;
         index = Math.min(end, index + page - 1);
         if (index == rowIndex) {
           index = Math.min(end, index + page - 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
   }
 }