use of org.eclipse.swt.dnd.Transfer in project tdq-studio-se by Talend.
the class ColumnViewerDND method installDND.
/**
* DOC qzhang Comment method "installDND".
*/
public static void installDND(final Tree targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragEnter(org.eclipse.swt .dnd.DropTargetEvent)
*/
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
// if (object instanceof IFile) {
if (object instanceof SysIndicatorDefinitionRepNode) {
receiver = new UDIReceiver();
} else if (object instanceof PatternRepNode) {
receiver = new PatternReceiver();
}
// MOD klliu 15750 2011-01-17 for Drag&Drop On columnset
if (object instanceof DBColumnRepNode || object instanceof DBTableRepNode || object instanceof DFColumnRepNode) {
receiver = new ColumnReceiver();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.TreeDropTargetEffect#dragOver(org.eclipse .swt.dnd.DropTargetEvent)
*/
@Override
public void dragOver(DropTargetEvent event) {
super.dragOver(event);
// MOD yyi 2009-09-18 bug: 9044
if (null != receiver) {
receiver.doDropValidation(event, commonViewer);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd .DropTargetEvent)
*/
@Override
public void drop(DropTargetEvent event) {
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
// TreeItem item = new TreeItem(targetControl, SWT.NONE);
// item.setText(texts);
// item.setText(text);
index = 0;
} else {
TreeItem item = (TreeItem) event.item;
TreeItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
receiver.drop(event, commonViewer, index);
}
};
dropTarget.addDropListener(dndListener);
}
use of org.eclipse.swt.dnd.Transfer in project tdq-studio-se by Talend.
the class DataFilterDND method installDND.
public static void installDND(final Text targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
Object obj = ((IStructuredSelection) commonViewer.getSelection()).getFirstElement();
if (!(obj instanceof DBColumnRepNode)) {
event.detail = DND.DROP_NONE;
} else {
event.detail = DND.DROP_MOVE;
event.feedback = DND.FEEDBACK_INSERT_AFTER;
}
}
@Override
public void dropAccept(DropTargetEvent event) {
// do nothing until now
}
@Override
public void drop(DropTargetEvent event) {
if (event.detail != DND.DROP_NONE) {
IStructuredSelection selection = (IStructuredSelection) commonViewer.getSelection();
if (!selection.isEmpty()) {
List list = selection.toList();
IEditorPart currentActiveEditor = CorePlugin.getDefault().getCurrentActiveEditor();
if (currentActiveEditor instanceof AnalysisEditor) {
AnalysisEditor editor = (AnalysisEditor) currentActiveEditor;
AnalysisItemEditorInput input = (AnalysisItemEditorInput) editor.getEditorInput();
for (Object object : list) {
DBColumnRepNode node = (DBColumnRepNode) object;
DbmsLanguage language = DbmsLanguageFactory.createDbmsLanguage((Analysis) input.getModel());
MetadataColumnRepositoryObject columnObject = (MetadataColumnRepositoryObject) node.getObject();
String name = columnObject.getTdColumn().getName();
targetControl.insert(language.quote(name));
// Focus text.
targetControl.forceFocus();
}
}
}
}
}
});
}
use of org.eclipse.swt.dnd.Transfer in project statecharts by Yakindu.
the class ExampleDropTargetInstaller method registerWithExistingTarget.
protected void registerWithExistingTarget(DropTarget target) {
Transfer[] transfers = target.getTransfer();
boolean exists = false;
if (transfers != null) {
for (Transfer transfer : transfers) {
if (transfer instanceof URLTransfer) {
exists = true;
break;
}
}
if (!exists) {
Transfer[] newTransfers = new Transfer[transfers.length + 1];
System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
newTransfers[transfers.length] = URLTransfer.getInstance();
target.setTransfer(newTransfers);
}
}
}
use of org.eclipse.swt.dnd.Transfer in project ecf by eclipse.
the class EndpointDiscoveryView method makeActions.
protected void makeActions() {
copyValueAction = new Action() {
public void run() {
Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
String data = ((EndpointPropertyNode) o).getPropertyValue().toString();
if (data != null && data.length() > 0) {
clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
}
}
};
copyValueAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
copyValueAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
copyValueAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
copyNameAction = new Action() {
public void run() {
Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
String data = ((EndpointPropertyNode) o).getPropertyName();
if (data != null && data.length() > 0) {
clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
}
}
};
copyNameAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
copyNameAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
copyNameAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
importAction = new Action() {
public void run() {
EndpointNode edNode = getEDNodeSelected();
if (edNode != null) {
RemoteServiceAdmin rsa = discovery.getRSA();
if (rsa == null)
showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IS_NULL);
else {
// Do import
EndpointDescription ed = edNode.getEndpointDescription();
ImportRegistration reg = (ImportRegistration) rsa.importService(ed);
if (reg == null) {
logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, // $NON-NLS-1$
new Exception("Import Registration Is Null"));
showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + // $NON-NLS-1$
"Import Registration Is Null" + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
return;
}
// Check if import exception in returned registration
Throwable exception = reg.getException();
if (exception != null) {
logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, exception);
showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + exception.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
} else {
// Success! Set registration
// and refresh
edNode.setImportReference((ImportReference) reg.getImportReference());
viewer.refresh();
}
}
}
}
};
importAction.setText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE);
importAction.setToolTipText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE_TT);
importAction.setImageDescriptor(RSAImageRegistry.DESC_RSPROXY_CO);
edefDiscoverAction = new Action() {
public void run() {
IEndpointDescriptionLocator locator = discovery.getEndpointDescriptionLocator();
if (locator != null) {
FileDialog dialog = new FileDialog(viewer.getControl().getShell(), SWT.OPEN);
// $NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
dialog.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE);
dialog.setFilterPath(null);
String result = dialog.open();
if (result != null)
try {
EndpointDescription[] eds = (EndpointDescription[]) new EndpointDescriptionReader().readEndpointDescriptions(new FileInputStream(result));
if (eds != null) {
for (int i = 0; i < eds.length; i++) locator.discoverEndpoint(eds[i]);
}
} catch (IOException e) {
logError(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED, e);
showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED_PREFIX + e.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
}
}
}
};
edefDiscoverAction.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG);
edefDiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG_TT);
edefDiscoverAction.setEnabled(discovery.getRSA() != null);
edefDiscoverAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
undiscoverAction = new Action() {
public void run() {
EndpointNode endpoint = getEDNodeSelected();
if (endpoint != null && endpoint.getImportReference() == null) {
IEndpointDescriptionLocator l = discovery.getEndpointDescriptionLocator();
if (l != null && MessageDialog.openQuestion(viewer.getControl().getShell(), Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION_TITLE, Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION))
l.undiscoverEndpoint(endpoint.getEndpointDescription());
}
}
};
undiscoverAction.setText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT);
undiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_TT);
}
use of org.eclipse.swt.dnd.Transfer in project portfolio by buchen.
the class DisplayTextDialog method createButtonsForButtonBar.
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
Button button = createButton(parent, 9999, Messages.LabelCopyToClipboard, false);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (entryText.isDisposed())
return;
Clipboard cb = new Clipboard(Display.getCurrent());
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { entryText.getText() }, new Transfer[] { textTransfer });
}
});
}
Aggregations