use of org.eclipse.swt.dnd.DragSourceEvent in project netxms by netxms.
the class EventObjectList method enableDragSupport.
/**
* Enable drag support in object tree
*/
public void enableDragSupport() {
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(viewer.getSelection());
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
});
}
use of org.eclipse.swt.dnd.DragSourceEvent in project core by jcryptool.
the class FileExplorerView method setupDragNDrop.
private void setupDragNDrop() {
viewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {
TreeItem[] selection = viewer.getTree().getSelection();
event.data = new String[] { ((IFileStore) selection[0].getData()).toString() };
}
public void dragStart(DragSourceEvent event) {
TreeItem[] selection = viewer.getTree().getSelection();
if (selection.length > 0 && selection[0].getItemCount() == 0) {
event.doit = true;
event.data = ((IFileStore) selection[0].getData()).toString();
} else {
event.doit = false;
}
}
});
viewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { TextTransfer.getInstance() }, new DropTargetAdapter() {
public void dragOver(DropTargetEvent event) {
if (event.item != null && event.item.getData() instanceof IFileStore) {
String url = ((IFileStore) event.item.getData()).toString();
File file = new File(url);
if (file.isDirectory()) {
event.feedback = DND.DROP_NONE;
return;
}
}
}
public void drop(DropTargetEvent event) {
String url = ((IFileStore) event.item.getData()).toString();
String algorithm = (String) event.data;
File file = new File(url);
if (file.isDirectory()) {
event.feedback = DND.DROP_NONE;
return;
}
if (openFile(url))
AlgorithmView.doAction(algorithm);
}
});
}
use of org.eclipse.swt.dnd.DragSourceEvent in project tdq-studio-se by Talend.
the class ExpressionEditDialog method createTemplatesTablePart.
/**
* create templates Table Part(only TAB0 use old paramaters, and others use new paramaters)
*
* @param sform
*/
public void createTemplatesTablePart(SashForm sform) {
GridData data;
final Table templatesTable = new Table(sform, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
templatesTable.setLinesVisible(false);
templatesTable.setHeaderVisible(true);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200;
templatesTable.setLayoutData(data);
DragSource ds = new DragSource(templatesTable, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
event.data = templatesTable.getSelection()[0].getText();
}
});
TableColumn column = new TableColumn(templatesTable, SWT.NONE);
column.setText(TEMPLATES_TITLE);
for (String template : templates) {
TableItem item = new TableItem(templatesTable, SWT.NONE);
item.setText(0, template);
}
templatesTable.getColumn(0).pack();
}
use of org.eclipse.swt.dnd.DragSourceEvent in project tdq-studio-se by Talend.
the class ComparisonTableViewerDNDDecorate method installDragListener.
private void installDragListener(final TableViewer targetViewer, int operations) {
final Table table = targetViewer.getTable();
final DragSource source = new DragSource(table, operations);
source.setTransfer(transferTypes);
final TableItem[] dragSourceItem = new TableItem[1];
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TableItem[] selection = table.getSelection();
if (selection.length > 0) {
event.doit = true;
dragSourceItem[0] = selection[0];
dragSelectedElement = ((IStructuredSelection) targetViewer.getSelection()).getFirstElement();
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
dragSelectedElement = ((IStructuredSelection) targetViewer.getSelection()).getFirstElement();
event.data = dragSourceItem[0].getText();
}
public void dragFinished(DragSourceEvent event) {
}
});
}
use of org.eclipse.swt.dnd.DragSourceEvent in project tdq-studio-se by Talend.
the class DatabaseStructureView method addSession.
/**
* Add a new session to the database structure view. This will create a new tab for the session.
*
* @param session
*/
private void addSession(final MetaDataSession session) throws SQLCannotConnectException {
if (_allSessions.contains(session)) {
return;
}
try {
session.getMetaData();
session.setAutoCommit(true);
} catch (SQLCannotConnectException e) {
SQLExplorerPlugin.error(e);
throw e;
} catch (SQLException e) {
SQLExplorerPlugin.error(e);
MessageDialog.openError(getSite().getShell(), "Cannot connect", e.getMessage());
}
DatabaseNode rootNode = session.getRoot();
if (rootNode == null) {
return;
}
_allSessions.add(session);
if (_filterAction != null) {
_filterAction.setEnabled(true);
}
if (_tabFolder == null || _tabFolder.isDisposed()) {
clearParent();
// create tab folder for different sessions
_tabFolder = new CTabFolder(_parent, SWT.TOP | SWT.CLOSE);
// add listener to keep both views on the same active tab
_tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// Set up a gradient background for the selected tab
Display display = getSite().getShell().getDisplay();
_tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WHITE), new Color(null, 211, 225, 250), new Color(null, 175, 201, 246), IConstants.TAB_BORDER_COLOR }, new int[] { 25, 50, 75 }, true);
// Add a listener to handle the close button on each tab
_tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
@Override
public void close(CTabFolderEvent event) {
CTabItem tabItem = (CTabItem) event.item;
TabData tabData = (TabData) tabItem.getData();
_allSessions.remove(tabData.session);
event.doit = true;
}
});
_parent.layout();
_parent.redraw();
}
// create tab
final CTabItem tabItem = new CTabItem(_tabFolder, SWT.NULL);
TabData tabData = new TabData();
tabItem.setData(tabData);
tabData.session = session;
// set tab text
String labelText = session.getUser().getDescription();
tabItem.setText(labelText);
// create composite for our outline
Composite composite = new Composite(_tabFolder, SWT.NULL);
composite.setLayout(new FillLayout());
tabItem.setControl(composite);
// create outline
final TreeViewer treeViewer = new TreeViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
tabData.treeViewer = treeViewer;
// add drag support
// TODO improve drag support options
Transfer[] transfers = new Transfer[] { TableNodeTransfer.getInstance() };
treeViewer.addDragSupport(DND.DROP_COPY, transfers, new DragSourceListener() {
public void dragFinished(DragSourceEvent event) {
System.out.println("$drag finished");
TableNodeTransfer.getInstance().setSelection(null);
}
public void dragSetData(DragSourceEvent event) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
event.data = sel;
}
public void dragStart(DragSourceEvent event) {
event.doit = !treeViewer.getSelection().isEmpty();
if (event.doit) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
if (!(sel instanceof TableNode)) {
event.doit = false;
} else {
TableNode tn = (TableNode) sel;
TableNodeTransfer.getInstance().setSelection(tn);
if (!tn.isTable()) {
event.doit = false;
}
}
}
}
});
// use hash lookup to improve performance
treeViewer.setUseHashlookup(true);
// add content and label provider
treeViewer.setContentProvider(new DBTreeContentProvider());
treeViewer.setLabelProvider(new DBTreeLabelProvider());
// set input session
treeViewer.setInput(rootNode);
// add selection change listener, so we can update detail view as
// required.
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent ev) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// bring detail to front on doubleclick of node
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
try {
// find view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView == null) {
getSite().getPage().showView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
}
getSite().getPage().bringToTop(detailView);
synchronizeDetailView(detailView);
} catch (Exception e) {
// fail silent
}
}
});
// add expand/collapse listener
treeViewer.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(false);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
public void treeExpanded(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(true);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
});
// set new tab as the active one
_tabFolder.setSelection(_tabFolder.getItemCount() - 1);
// update detail view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView != null) {
// synchronze detail view with new session
synchronizeDetailView(detailView);
// bring detail to top of the view stack
getSite().getPage().bringToTop(detailView);
}
// refresh view
composite.layout();
_tabFolder.layout();
_tabFolder.redraw();
// bring this view to top of the view stack, above detail if needed..
getSite().getPage().bringToTop(this);
// add context menu
final DBTreeActionGroup actionGroup = new DBTreeActionGroup(treeViewer);
MenuManager menuManager = new MenuManager("DBTreeContextMenu");
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(contextMenu);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
actionGroup.fillContextMenu(manager);
}
});
// if (sessionSelectionMap.containsKey(tabData.session)) {
// tabData.treeViewer.setSelection(sessionSelectionMap.get(tabData.session));
// sessionSelectionMap.remove(tabData.session);
// _allSessions.remove(tabData.session);
// }
}
Aggregations