Ejemplo n.º 1
0
 public static int getColumnAtPos(TableItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
Ejemplo n.º 2
0
  public static void sortTable(Table table, Comparator<TableItem> comparator) {
    int columnCount = table.getColumnCount();
    String[] values = new String[columnCount];
    TableItem[] items = table.getItems();
    for (int i = 1; i < items.length; i++) {
      for (int j = 0; j < i; j++) {
        TableItem item = items[i];
        if (comparator.compare(item, items[j]) < 0) {
          for (int k = 0; k < columnCount; k++) {
            values[k] = item.getText(k);
          }
          Object data = item.getData();
          boolean checked = item.getChecked();
          item.dispose();

          item = new TableItem(table, SWT.NONE, j);
          item.setText(values);
          item.setData(data);
          item.setChecked(checked);
          items = table.getItems();
          break;
        }
      }
    }
  }
  protected TableItem newOrderedTableItem(Mapping mapping, boolean selected) {
    TableItem[] items = fOrderedTable.getItems();
    int i = 0;
    while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0)
      i++;

    TableItem item = new TableItem(fOrderedTable, SWT.NULL, i);

    String[] values = new String[] {mapping.getElement(), mapping.getSignature()};
    item.setText(values);
    item.setData(mapping);
    if (selected) fOrderedTable.setSelection(i);

    return item;
  }
  protected TableItem newMappingsTableItem(Mapping mapping, boolean selected) {
    TableItem[] items = fMappingsTable.getItems();
    int i = 0;
    while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0)
      i++;
    TableItem item = new TableItem(fMappingsTable, SWT.NULL, i);
    String idtext = mapping.getIdAttribute();
    String idtype;
    if (idtext.charAt(0) == XMLStructureCreator.ID_TYPE_BODY) {
      idtext = idtext.substring(1, idtext.length());
      idtype = IDTYPE_CHILDBODY;
    } else idtype = IDTYPE_ATTRIBUTE;

    String[] values = new String[] {mapping.getElement(), mapping.getSignature(), idtext, idtype};
    item.setText(values);
    item.setData(mapping);
    if (selected) fMappingsTable.setSelection(i);

    return item;
  }
 protected TableItem newIdMapsTableItem(IdMap idmap, boolean selected) {
   // find index where to insert table entry
   TableItem[] items = fIdMapsTable.getItems();
   int i = 0;
   while (i < items.length && idmap.getName().compareToIgnoreCase(items[i].getText(0)) > 0) i++;
   TableItem item = new TableItem(fIdMapsTable, SWT.NULL, i);
   String[] values =
       new String[] {
         idmap.getName(),
         (idmap.isInternal())
             ? XMLCompareMessages.XMLComparePreference_topTableColumn2internal
             : XMLCompareMessages.XMLComparePreference_topTableColumn2user,
         idmap.getExtension()
       };
   item.setText(values);
   item.setData(idmap);
   if (selected) {
     fIdMapsTable.setSelection(i);
     fIdMapsTable.setFocus();
     selectionChanged();
   }
   return item;
 }