/* Label Provider */
fViewer.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
ShareProvider provider = (ShareProvider) cell.getElement();
cell.setText(provider.getName());
if (StringUtils.isSet(provider.getIconPath()))
cell.setImage(fResources.createImage(OwlUI.getImageDescriptor(provider.getPluginId(), provider.getIconPath())));
}
});
/* Selection */
fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateMoveEnablement();
}
});
/* Drag Support */
fViewer.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) fViewer.getSelection();
event.doit = (selection.size() < fViewer.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(fViewer) {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
return true;
}
@Override
public boolean performDrop(Object data) {
ShareProvider target = (ShareProvider) getCurrentTarget();
if (target != null) {
onMove((StructuredSelection) data, target, getCurrentLocation());
return true;
}
return false;
}
};
dropSupport.setFeedbackEnabled(true);
dropSupport.setScrollEnabled(true);
dropSupport.setSelectionFeedbackEnabled(true);
fViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, dropSupport);
/* Set input (ignored by ContentProvider anyways) */
fViewer.setInput(this);
updateCheckedState();
/* Ensure that the first checked element is visible */
TableItem[] items = fViewer.getTable().getItems();
for (TableItem item : items) {
if (item.getChecked()) {
fViewer.getTable().showItem(item);
break;
}
}
/* Listen on Check State Changes */
fViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
ShareProvider provider = (ShareProvider) event.getElement();
provider.setEnabled(event.getChecked());
save();
fViewer.update(provider, null);
}
});