use of org.eclipse.swt.dnd.DragSourceListener 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);
// }
}
use of org.eclipse.swt.dnd.DragSourceListener in project pentaho-kettle by pentaho.
the class EnterListDialog method open.
public String[] open() {
Shell parent = getParent();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageTransGraph());
shell.setText(BaseMessages.getString(PKG, "EnterListDialog.Title"));
shell.setLayout(new FormLayout());
int margin = Const.MARGIN;
// //////////////////////////////////////////////////
// Top & Bottom regions.
// //////////////////////////////////////////////////
Composite top = new Composite(shell, SWT.NONE);
FormLayout topLayout = new FormLayout();
topLayout.marginHeight = margin;
topLayout.marginWidth = margin;
top.setLayout(topLayout);
FormData fdTop = new FormData();
fdTop.left = new FormAttachment(0, 0);
fdTop.top = new FormAttachment(0, 0);
fdTop.right = new FormAttachment(100, 0);
fdTop.bottom = new FormAttachment(100, -50);
top.setLayoutData(fdTop);
props.setLook(top);
Composite bottom = new Composite(shell, SWT.NONE);
bottom.setLayout(new FormLayout());
FormData fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(top, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
bottom.setLayoutData(fdBottom);
props.setLook(bottom);
// //////////////////////////////////////////////////
// Sashform
// //////////////////////////////////////////////////
SashForm sashform = new SashForm(top, SWT.HORIZONTAL);
sashform.setLayout(new FormLayout());
FormData fdSashform = new FormData();
fdSashform.left = new FormAttachment(0, 0);
fdSashform.top = new FormAttachment(0, 0);
fdSashform.right = new FormAttachment(100, 0);
fdSashform.bottom = new FormAttachment(100, 0);
sashform.setLayoutData(fdSashform);
// ////////////////////////
// / LEFT
// ////////////////////////
Composite leftsplit = new Composite(sashform, SWT.NONE);
leftsplit.setLayout(new FormLayout());
FormData fdLeftsplit = new FormData();
fdLeftsplit.left = new FormAttachment(0, 0);
fdLeftsplit.top = new FormAttachment(0, 0);
fdLeftsplit.right = new FormAttachment(100, 0);
fdLeftsplit.bottom = new FormAttachment(100, 0);
leftsplit.setLayoutData(fdLeftsplit);
props.setLook(leftsplit);
// Source list to the left...
wlListSource = new Label(leftsplit, SWT.NONE);
wlListSource.setText(BaseMessages.getString(PKG, "EnterListDialog.AvailableItems.Label"));
props.setLook(wlListSource);
FormData fdlListSource = new FormData();
fdlListSource.left = new FormAttachment(0, 0);
fdlListSource.top = new FormAttachment(0, 0);
wlListSource.setLayoutData(fdlListSource);
wListSource = new List(leftsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListSource);
FormData fdListSource = new FormData();
fdListSource.left = new FormAttachment(0, 0);
fdListSource.top = new FormAttachment(wlListSource, 0);
fdListSource.right = new FormAttachment(100, 0);
fdListSource.bottom = new FormAttachment(100, 0);
wListSource.setLayoutData(fdListSource);
// /////////////////////////
// MIDDLE
// /////////////////////////
Composite compmiddle = new Composite(sashform, SWT.NONE);
compmiddle.setLayout(new FormLayout());
FormData fdCompMiddle = new FormData();
fdCompMiddle.left = new FormAttachment(0, 0);
fdCompMiddle.top = new FormAttachment(0, 0);
fdCompMiddle.right = new FormAttachment(100, 0);
fdCompMiddle.bottom = new FormAttachment(100, 0);
compmiddle.setLayoutData(fdCompMiddle);
props.setLook(compmiddle);
Composite gButtonGroup = new Composite(compmiddle, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, false);
gButtonGroup.setLayout(gridLayout);
wAddOne = new Button(gButtonGroup, SWT.PUSH);
wAddOne.setText(" > ");
wAddOne.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.AddOne.Tooltip"));
wAddAll = new Button(gButtonGroup, SWT.PUSH);
wAddAll.setText(" >> ");
wAddAll.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.AddAll.Tooltip"));
wRemoveOne = new Button(gButtonGroup, SWT.PUSH);
wRemoveOne.setText(" < ");
wRemoveOne.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.RemoveOne.Tooltip"));
wRemoveAll = new Button(gButtonGroup, SWT.PUSH);
wRemoveAll.setText(" << ");
wRemoveAll.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.RemoveAll.Tooltip"));
GridData gdAddOne = new GridData(GridData.FILL_BOTH);
wAddOne.setLayoutData(gdAddOne);
GridData gdAddAll = new GridData(GridData.FILL_BOTH);
wAddAll.setLayoutData(gdAddAll);
GridData gdRemoveAll = new GridData(GridData.FILL_BOTH);
wRemoveAll.setLayoutData(gdRemoveAll);
GridData gdRemoveOne = new GridData(GridData.FILL_BOTH);
wRemoveOne.setLayoutData(gdRemoveOne);
FormData fdButtonGroup = new FormData();
// get a size
wAddAll.pack();
fdButtonGroup.left = new FormAttachment(50, -(wAddAll.getSize().x / 2) - 5);
fdButtonGroup.top = new FormAttachment(30, 0);
// the default looks ugly
gButtonGroup.setBackground(shell.getBackground());
gButtonGroup.setLayoutData(fdButtonGroup);
// ///////////////////////////////
// RIGHT
// ///////////////////////////////
Composite rightsplit = new Composite(sashform, SWT.NONE);
rightsplit.setLayout(new FormLayout());
FormData fdRightsplit = new FormData();
fdRightsplit.left = new FormAttachment(0, 0);
fdRightsplit.top = new FormAttachment(0, 0);
fdRightsplit.right = new FormAttachment(100, 0);
fdRightsplit.bottom = new FormAttachment(100, 0);
rightsplit.setLayoutData(fdRightsplit);
props.setLook(rightsplit);
wlListDest = new Label(rightsplit, SWT.NONE);
wlListDest.setText(BaseMessages.getString(PKG, "EnterListDialog.Selection.Label"));
props.setLook(wlListDest);
FormData fdlListDest = new FormData();
fdlListDest.left = new FormAttachment(0, 0);
fdlListDest.top = new FormAttachment(0, 0);
wlListDest.setLayoutData(fdlListDest);
wListDest = new List(rightsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListDest);
FormData fdListDest = new FormData();
fdListDest.left = new FormAttachment(0, 0);
fdListDest.top = new FormAttachment(wlListDest, 0);
fdListDest.right = new FormAttachment(100, 0);
fdListDest.bottom = new FormAttachment(100, 0);
wListDest.setLayoutData(fdListDest);
sashform.setWeights(new int[] { 40, 16, 40 });
// //////////////////////////////////////////////////////////////
// THE BOTTOM BUTTONS...
// //////////////////////////////////////////////////////////////
wOK = new Button(bottom, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wCancel = new Button(bottom, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
FormData fdOK = new FormData();
FormData fdCancel = new FormData();
fdOK.left = new FormAttachment(35, 0);
fdOK.bottom = new FormAttachment(100, 0);
wOK.setLayoutData(fdOK);
fdCancel.left = new FormAttachment(wOK, 10);
fdCancel.bottom = new FormAttachment(100, 0);
wCancel.setLayoutData(fdCancel);
// Add listeners
wCancel.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
dispose();
}
});
// Add listeners
wOK.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
handleOK();
}
});
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wListSource, DND.DROP_MOVE | DND.DROP_COPY);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
}
public void dragSetData(DragSourceEvent event) {
String[] ti = wListSource.getSelection();
String data = new String();
for (int i = 0; i < ti.length; i++) {
data += ti[i] + Const.CR;
}
event.data = data;
}
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wListDest, DND.DROP_MOVE | DND.DROP_COPY);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
StringTokenizer strtok = new StringTokenizer((String) event.data, Const.CR);
while (strtok.hasMoreTokens()) {
String source = strtok.nextToken();
addToDestination(source);
}
}
public void dropAccept(DropTargetEvent event) {
}
});
wListSource.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
addToSelection(wListSource.getSelection());
}
}
});
wListDest.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
delFromSelection(wListDest.getSelection());
}
}
});
// Double click adds to destination.
wListSource.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
// Double click adds to source
wListDest.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
delFromSelection(wListDest.getSelection());
}
});
wAddOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
wRemoveOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
delFromSelection(wListDest.getSelection());
}
});
wAddAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addToSelection(wListSource.getItems());
}
});
wRemoveAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
delFromSelection(wListDest.getItems());
}
});
opened = true;
getData();
BaseStepDialog.setSize(shell);
shell.open();
Display display = parent.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return retval;
}
use of org.eclipse.swt.dnd.DragSourceListener in project pentaho-kettle by pentaho.
the class RipDatabaseWizardPage2 method createControl.
public void createControl(Composite parent) {
shell = parent.getShell();
int margin = Const.MARGIN;
// create the composite to hold the widgets
Composite composite = new Composite(parent, SWT.NONE);
props.setLook(composite);
FormLayout compLayout = new FormLayout();
compLayout.marginHeight = Const.FORM_MARGIN;
compLayout.marginWidth = Const.FORM_MARGIN;
composite.setLayout(compLayout);
// Put it all on the composite!
// //////////////////////////////////////////////////
// Top & Bottom regions.
// //////////////////////////////////////////////////
Composite top = new Composite(composite, SWT.NONE);
FormLayout topLayout = new FormLayout();
topLayout.marginHeight = margin;
topLayout.marginWidth = margin;
top.setLayout(topLayout);
FormData fdTop = new FormData();
fdTop.left = new FormAttachment(0, 0);
fdTop.top = new FormAttachment(0, 0);
fdTop.right = new FormAttachment(100, 0);
fdTop.bottom = new FormAttachment(100, -50);
top.setLayoutData(fdTop);
props.setLook(top);
Composite bottom = new Composite(composite, SWT.NONE);
bottom.setLayout(new FormLayout());
FormData fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(top, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
bottom.setLayoutData(fdBottom);
props.setLook(bottom);
// //////////////////////////////////////////////////
// Sashform
// //////////////////////////////////////////////////
SashForm sashform = new SashForm(top, SWT.HORIZONTAL);
sashform.setLayout(new FormLayout());
FormData fdSashform = new FormData();
fdSashform.left = new FormAttachment(0, 0);
fdSashform.top = new FormAttachment(0, 0);
fdSashform.right = new FormAttachment(100, 0);
fdSashform.bottom = new FormAttachment(100, 0);
sashform.setLayoutData(fdSashform);
// ////////////////////////
// / LEFT
// ////////////////////////
Composite leftsplit = new Composite(sashform, SWT.NONE);
leftsplit.setLayout(new FormLayout());
FormData fdLeftsplit = new FormData();
fdLeftsplit.left = new FormAttachment(0, 0);
fdLeftsplit.top = new FormAttachment(0, 0);
fdLeftsplit.right = new FormAttachment(100, 0);
fdLeftsplit.bottom = new FormAttachment(100, 0);
leftsplit.setLayoutData(fdLeftsplit);
props.setLook(leftsplit);
// Source list to the left...
wlListSource = new Label(leftsplit, SWT.NONE);
wlListSource.setText("Available items:");
props.setLook(wlListSource);
FormData fdlListSource = new FormData();
fdlListSource.left = new FormAttachment(0, 0);
fdlListSource.top = new FormAttachment(0, 0);
wlListSource.setLayoutData(fdlListSource);
wListSource = new List(leftsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListSource);
FormData fdListSource = new FormData();
fdListSource.left = new FormAttachment(0, 0);
fdListSource.top = new FormAttachment(wlListSource, 0);
fdListSource.right = new FormAttachment(100, 0);
fdListSource.bottom = new FormAttachment(100, 0);
wListSource.setLayoutData(fdListSource);
// /////////////////////////
// MIDDLE
// /////////////////////////
Composite compmiddle = new Composite(sashform, SWT.NONE);
compmiddle.setLayout(new FormLayout());
FormData fdCompMiddle = new FormData();
fdCompMiddle.left = new FormAttachment(0, 0);
fdCompMiddle.top = new FormAttachment(0, 0);
fdCompMiddle.right = new FormAttachment(100, 0);
fdCompMiddle.bottom = new FormAttachment(100, 0);
compmiddle.setLayoutData(fdCompMiddle);
props.setLook(compmiddle);
wAddOne = new Button(compmiddle, SWT.PUSH);
wAddOne.setText(" > ");
wAddOne.setToolTipText("Add the selected items on the left.");
wAddAll = new Button(compmiddle, SWT.PUSH);
wAddAll.setText(" >> ");
wAddAll.setToolTipText("Add all items on the left.");
wRemoveOne = new Button(compmiddle, SWT.PUSH);
wRemoveOne.setText(" < ");
wRemoveOne.setToolTipText("Remove the selected items on the right.");
wRemoveAll = new Button(compmiddle, SWT.PUSH);
wRemoveAll.setText(" << ");
wRemoveAll.setToolTipText("Add all items on the right.");
FormData fdAddOne = new FormData();
fdAddOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdAddOne.top = new FormAttachment(30, 0);
wAddOne.setLayoutData(fdAddOne);
FormData fdAddAll = new FormData();
fdAddAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdAddAll.top = new FormAttachment(wAddOne, margin);
wAddAll.setLayoutData(fdAddAll);
FormData fdRemoveAll = new FormData();
fdRemoveAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdRemoveAll.top = new FormAttachment(wAddAll, margin);
wRemoveAll.setLayoutData(fdRemoveAll);
FormData fdRemoveOne = new FormData();
fdRemoveOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdRemoveOne.top = new FormAttachment(wRemoveAll, margin);
wRemoveOne.setLayoutData(fdRemoveOne);
// ///////////////////////////////
// RIGHT
// ///////////////////////////////
Composite rightsplit = new Composite(sashform, SWT.NONE);
rightsplit.setLayout(new FormLayout());
FormData fdRightsplit = new FormData();
fdRightsplit.left = new FormAttachment(0, 0);
fdRightsplit.top = new FormAttachment(0, 0);
fdRightsplit.right = new FormAttachment(100, 0);
fdRightsplit.bottom = new FormAttachment(100, 0);
rightsplit.setLayoutData(fdRightsplit);
props.setLook(rightsplit);
wlListDest = new Label(rightsplit, SWT.NONE);
wlListDest.setText("Your selection:");
props.setLook(wlListDest);
FormData fdlListDest = new FormData();
fdlListDest.left = new FormAttachment(0, 0);
fdlListDest.top = new FormAttachment(0, 0);
wlListDest.setLayoutData(fdlListDest);
wListDest = new List(rightsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListDest);
FormData fdListDest = new FormData();
fdListDest.left = new FormAttachment(0, 0);
fdListDest.top = new FormAttachment(wlListDest, 0);
fdListDest.right = new FormAttachment(100, 0);
fdListDest.bottom = new FormAttachment(100, 0);
wListDest.setLayoutData(fdListDest);
sashform.setWeights(new int[] { 45, 10, 45 });
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wListSource, DND.DROP_MOVE | DND.DROP_COPY);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
}
public void dragSetData(DragSourceEvent event) {
String[] ti = wListSource.getSelection();
String data = new String();
for (int i = 0; i < ti.length; i++) {
data += ti[i] + Const.CR;
}
event.data = data;
}
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wListDest, DND.DROP_MOVE | DND.DROP_COPY);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
StringTokenizer strtok = new StringTokenizer((String) event.data, Const.CR);
while (strtok.hasMoreTokens()) {
String source = strtok.nextToken();
addToDestination(source);
}
}
public void dropAccept(DropTargetEvent event) {
}
});
wListSource.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
addToSelection(wListSource.getSelection());
}
}
});
wListDest.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
delFromSelection(wListDest.getSelection());
}
}
});
// Double click adds to destination.
wListSource.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
// Double click adds to source
wListDest.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
String[] sel = wListDest.getSelection();
delFromSelection(sel);
}
});
wAddOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
wRemoveOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
delFromSelection(wListDest.getSelection());
}
});
wAddAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addAllToSelection();
}
});
wRemoveAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
removeAllFromSelection();
}
});
// set the composite as the control for this page
setControl(composite);
}
use of org.eclipse.swt.dnd.DragSourceListener in project archi by archimatetool.
the class UsedInRelationshipsSection method createTableControl.
private void createTableControl(Composite parent) {
createLabel(parent, Messages.UsedInRelationshipsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
// Table
Composite tableComp = createTableComposite(parent, SWT.NONE);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.ANALYSIS_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Column
TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
// On Mac shows alternate table row colours
fTableViewer.getTable().setLinesVisible(true);
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return ArchimateModelUtils.getAllRelationshipsForConcept((IArchimateConcept) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new UsedInRelationshipsTableLabelProvider());
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (isAlive(fArchimateConcept)) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof IArchimateRelationship) {
IArchimateRelationship relation = (IArchimateRelationship) o;
ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
if (view != null) {
view.getViewer().setSelection(new StructuredSelection(relation), true);
}
}
}
}
});
fTableViewer.setComparator(new ViewerComparator());
// DND
fTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
// Drag started from the Table
LocalSelectionTransfer.getTransfer().setSelection(fTableViewer.getSelection());
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
// For consistency set the data to the selection even though
// the selection is provided by the LocalSelectionTransfer
// to the drop target adapter.
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
@Override
public void dragFinished(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(null);
}
});
}
use of org.eclipse.swt.dnd.DragSourceListener in project archi by archimatetool.
the class UserPropertiesSection method addDragSupport.
/*
* Drag Source support
*/
private void addDragSupport() {
int operations = DND.DROP_MOVE;
Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
fTableViewer.addDragSupport(operations, transferTypes, new DragSourceListener() {
@Override
public void dragFinished(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(null);
fDragSourceValid = false;
}
@Override
public void dragSetData(DragSourceEvent event) {
// For consistency set the data to the selection even though
// the selection is provided by the LocalSelectionTransfer
// to the drop target adapter.
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
@Override
public void dragStart(DragSourceEvent event) {
if (isAlive(fPropertiesElement)) {
IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
LocalSelectionTransfer.getTransfer().setSelection(selection);
event.doit = true;
fDragSourceValid = true;
}
}
});
}
Aggregations