cell.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
}
});
/* Selection */
fItemViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateButtonEnablement();
}
});
/* Support Keyboard Remove */
fItemViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL || (Application.IS_MAC && e.keyCode == SWT.BS))
onRemove();
}
});
/* Drag Support */
fItemViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceAdapter() {
@Override
public void dragStart(final DragSourceEvent event) {
SafeRunnable.run(new LoggingSafeRunnable() {
public void run() throws Exception {
IStructuredSelection selection = (IStructuredSelection) fItemViewer.getSelection();
event.doit = (selection.size() < fItemViewer.getTable().getItemCount());
if (event.doit) {
LocalSelectionTransfer.getTransfer().setSelection(selection);
LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
};
}
});
}
@Override
public void dragSetData(final DragSourceEvent event) {
SafeRunnable.run(new LoggingSafeRunnable() {
public void run() throws Exception {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType))
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
});
}
@Override
public void dragFinished(DragSourceEvent event) {
SafeRunnable.run(new LoggingSafeRunnable() {
public void run() throws Exception {
LocalSelectionTransfer.getTransfer().setSelection(null);
LocalSelectionTransfer.getTransfer().setSelectionSetTime(0);
}
});
}
});
/* Drop Support */
ViewerDropAdapter dropSupport = new ViewerDropAdapter(fItemViewer) {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
return true;
}
@Override
public boolean performDrop(Object data) {
ToolBarItem target = (ToolBarItem) getCurrentTarget();
if (target != null) {
onMove((StructuredSelection) data, target, getCurrentLocation());
return true;
}
return false;
}
};
dropSupport.setFeedbackEnabled(true);
dropSupport.setScrollEnabled(true);
dropSupport.setSelectionFeedbackEnabled(true);
fItemViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, dropSupport);
/* Set Dummy Input */
fItemViewer.setInput(this);
/* Container for the Buttons to Manage Providers */
Composite buttonContainer = new Composite(container, SWT.None);
buttonContainer.setLayout(LayoutUtils.createGridLayout(1, 0, 0));
buttonContainer.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false));
/* Add */
fAddMenu = new Menu(getShell(), SWT.POP_UP);
fAddMenu.addMenuListener(new MenuListener() {
public void menuShown(MenuEvent e) {
MenuItem[] items = fAddMenu.getItems();
for (MenuItem item : items) {
item.dispose();
}
/* Fill not yet visible Items */
int[] toolbarItemIds = fPreferences.getIntegers(DefaultPreferences.TOOLBAR_ITEMS);
List<CoolBarItem> visibleItems = new ArrayList<CoolBarItem>();
for (int toolbarItemId : toolbarItemIds) {
visibleItems.add(CoolBarItem.values()[toolbarItemId]);
}
CoolBarItem[] toolItems = getSortedItems();
int currentGroup = -1;
for (final CoolBarItem toolItem : toolItems) {
if (!visibleItems.contains(toolItem) || toolItem == CoolBarItem.SEPARATOR || toolItem == CoolBarItem.SPACER) {
/* Divide Groups by Separators */
if (currentGroup >= 0 && currentGroup != toolItem.getGroup())
new MenuItem(fAddMenu, SWT.SEPARATOR);
/* Create Menu Item */
MenuItem item = new MenuItem(fAddMenu, SWT.PUSH);
if (StringUtils.isSet(toolItem.getTooltip()))
item.setText(toolItem.getTooltip());
else
item.setText(toolItem.getName());
if (toolItem.getImg() != null)
item.setImage(fResources.createImage(toolItem.getImg()));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/* Add Item */
onAdd(toolItem);
/* Re-Open Menu for More */
JobRunner.runInUIThread(fAddMenu, new Runnable() {
public void run() {
fAddMenu.setVisible(true);
};
});
}
});
currentGroup = toolItem.getGroup();
}
}
}
public void menuHidden(MenuEvent e) {}
});
fAddButton = new Button(buttonContainer, SWT.DOWN);
fAddButton.setText(Messages.CustomizeToolbarDialog_ADD);
applyDialogFont(fAddButton);
setButtonLayoutData(fAddButton);
fAddButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Rectangle rect = fAddButton.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
pt = fAddButton.toDisplay(pt);
fAddMenu.setLocation(pt.x, pt.y);
fAddMenu.setVisible(true);
}
});
/* Remove */
fRemoveButton = new Button(buttonContainer, SWT.PUSH);
fRemoveButton.setText(Messages.CustomizeToolbarDialog_REMOVE);
fRemoveButton.setEnabled(false);
applyDialogFont(fRemoveButton);
setButtonLayoutData(fRemoveButton);
fRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onRemove();
}
});
/* Move Provider Up */
fMoveUpButton = new Button(buttonContainer, SWT.PUSH);
fMoveUpButton.setText(Messages.CustomizeToolbarDialog_MOVE_UP);
fMoveUpButton.setEnabled(false);
applyDialogFont(fMoveUpButton);
setButtonLayoutData(fMoveUpButton);
((GridData)fMoveUpButton.getLayoutData()).verticalIndent= 10;
fMoveUpButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onMove(true);
}
});
/* Move Provider Down */
fMoveDownButton = new Button(buttonContainer, SWT.PUSH);
fMoveDownButton.setText(Messages.CustomizeToolbarDialog_MOVE_DOWN);
fMoveDownButton.setEnabled(false);
applyDialogFont(fMoveDownButton);
setButtonLayoutData(fMoveDownButton);
fMoveDownButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onMove(false);
}
});
/* Restore Defaults */
fRestoreDefaults = new Button(buttonContainer, SWT.PUSH);
fRestoreDefaults.setText(Messages.CustomizeToolbarDialog_RESTORE_DEFAULTS);
applyDialogFont(fRestoreDefaults);
setButtonLayoutData(fRestoreDefaults);
((GridData) fRestoreDefaults.getLayoutData()).grabExcessVerticalSpace = true;
((GridData) fRestoreDefaults.getLayoutData()).verticalAlignment = SWT.END;
fRestoreDefaults.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onRestoreDefaults();
}
});
/* Toolbar Mode */
Composite modeContainer = new Composite(container, SWT.None);
modeContainer.setLayout(LayoutUtils.createGridLayout(2, 5, 0));
modeContainer.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false, 2, 1));
Label showLabel = new Label(modeContainer, SWT.NONE);
showLabel.setText(Messages.CustomizeToolbarDialog_SHOW);
fModeViewer = new ComboViewer(modeContainer, SWT.READ_ONLY | SWT.BORDER);
fModeViewer.setContentProvider(new ArrayContentProvider());
fModeViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof CoolBarMode) {
switch ((CoolBarMode) element) {
case IMAGE:
return Messages.CustomizeToolbarDialog_ICONS;
case TEXT:
return Messages.CustomizeToolbarDialog_TEXT;
case IMAGE_TEXT_VERTICAL:
return Messages.CustomizeToolbarDialog_ICONS_AND_TEXT;
case IMAGE_TEXT_HORIZONTAL:
return Messages.CustomizeToolbarDialog_ICONS_AND_TEXT_SMALL;
}
}
return super.getText(element);
}
});
fModeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
CoolBarMode mode = (CoolBarMode) selection;
fPreferences.putInteger(DefaultPreferences.TOOLBAR_MODE, mode.ordinal());
}