Ejemplo n.º 1
0
  private void onAdd(CoolBarItem newItem) {
    int[] toolbarItemIds = fPreferences.getIntegers(DefaultPreferences.TOOLBAR_ITEMS);
    List<CoolBarItem> newItems = new ArrayList<CoolBarItem>();
    for (int toolbarItemId : toolbarItemIds) {
      newItems.add(CoolBarItem.values()[toolbarItemId]);
    }

    int selectionIndex = fItemViewer.getTable().getSelectionIndex();
    if (selectionIndex >= 0) newItems.add(selectionIndex + 1, newItem);
    else newItems.add(newItem);

    /* Save & Refresh */
    int[] newItemsRaw = new int[newItems.size()];
    for (int i = 0; i < newItems.size(); i++) newItemsRaw[i] = newItems.get(i).ordinal();

    fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, newItemsRaw);
    fItemViewer.refresh();

    /* Update Selection */
    if (selectionIndex >= 0) fItemViewer.getTable().setSelection(selectionIndex + 1);
    else fItemViewer.getTable().setSelection(fItemViewer.getTable().getItemCount() - 1);

    /* Update Buttons */
    updateButtonEnablement();
  }
Ejemplo n.º 2
0
  private void onRemove() {
    int[] toolbarItemIds = fPreferences.getIntegers(DefaultPreferences.TOOLBAR_ITEMS);
    List<CoolBarItem> newItems = new ArrayList<CoolBarItem>();
    for (int toolbarItemId : toolbarItemIds) {
      newItems.add(CoolBarItem.values()[toolbarItemId]);
    }

    int[] selectionIndices = fItemViewer.getTable().getSelectionIndices();
    for (int i = 0; i < selectionIndices.length; i++) {
      int index = selectionIndices[i] - i;
      newItems.remove(index);
    }

    /* Save & Refresh */
    int[] newItemsRaw = new int[newItems.size()];
    for (int i = 0; i < newItems.size(); i++) newItemsRaw[i] = newItems.get(i).ordinal();

    fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, newItemsRaw);
    fItemViewer.refresh();

    /* Update Selection */
    int tableItemCount = fItemViewer.getTable().getItemCount();
    if (selectionIndices.length > 0 && selectionIndices[0] < tableItemCount)
      fItemViewer.getTable().setSelection(selectionIndices[0]);
    else if (tableItemCount > 0) fItemViewer.getTable().setSelection(tableItemCount - 1);

    /* Update Buttons */
    updateButtonEnablement();
  }
Ejemplo n.º 3
0
  private CoolBarItem[] getSortedItems() {
    CoolBarItem[] items = CoolBarItem.values();
    List<CoolBarItem> sortedItems = new ArrayList<CoolBarItem>(items.length);
    sortedItems.addAll(Arrays.asList(items));

    /* Move "Delete News" before "Print News" */
    sortedItems.remove(CoolBarItem.DELETE);
    sortedItems.add(sortedItems.indexOf(CoolBarItem.PRINT), CoolBarItem.DELETE);

    /* Move "Attachments" after "Print News" */
    sortedItems.remove(CoolBarItem.ATTACHMENTS);
    sortedItems.add(sortedItems.indexOf(CoolBarItem.PRINT) + 1, CoolBarItem.ATTACHMENTS);

    /* Move "Archive" after "Copy News" */
    sortedItems.remove(CoolBarItem.ARCHIVE);
    sortedItems.add(sortedItems.indexOf(CoolBarItem.COPY) + 1, CoolBarItem.ARCHIVE);

    return sortedItems.toArray(new CoolBarItem[sortedItems.size()]);
  }