use of org.eclipse.swt.dnd.DragSourceEvent 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.DragSourceEvent in project pentaho-kettle by pentaho.
the class UserDefinedJavaClassDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
setShellImage(shell, input);
lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
changed = input.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Shell.Title"));
middle = props.getMiddlePct();
margin = Const.MARGIN;
// Filename line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
wSash = new SashForm(shell, SWT.VERTICAL);
// Top sash form
//
Composite wTop = new Composite(wSash, SWT.NONE);
props.setLook(wTop);
FormLayout topLayout = new FormLayout();
topLayout.marginWidth = Const.FORM_MARGIN;
topLayout.marginHeight = Const.FORM_MARGIN;
wTop.setLayout(topLayout);
// Script line
Label wlScriptFunctions = new Label(wTop, SWT.NONE);
wlScriptFunctions.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.ClassesAndSnippits.Label"));
props.setLook(wlScriptFunctions);
FormData fdlScriptFunctions = new FormData();
fdlScriptFunctions.left = new FormAttachment(0, 0);
fdlScriptFunctions.top = new FormAttachment(0, 0);
wlScriptFunctions.setLayoutData(fdlScriptFunctions);
// Tree View Test
wTree = new Tree(wTop, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
props.setLook(wTree);
FormData fdlTree = new FormData();
fdlTree.left = new FormAttachment(0, 0);
fdlTree.top = new FormAttachment(wlScriptFunctions, margin);
fdlTree.right = new FormAttachment(20, 0);
fdlTree.bottom = new FormAttachment(100, -margin);
wTree.setLayoutData(fdlTree);
// Script line
Label wlScript = new Label(wTop, SWT.NONE);
wlScript.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Class.Label"));
props.setLook(wlScript);
FormData fdlScript = new FormData();
fdlScript.left = new FormAttachment(wTree, margin);
fdlScript.top = new FormAttachment(0, 0);
wlScript.setLayoutData(fdlScript);
folder = new CTabFolder(wTop, SWT.BORDER | SWT.RESIZE);
folder.setSimple(false);
folder.setUnselectedImageVisible(true);
folder.setUnselectedCloseVisible(true);
FormData fdScript = new FormData();
fdScript.left = new FormAttachment(wTree, margin);
fdScript.top = new FormAttachment(wlScript, margin);
fdScript.right = new FormAttachment(100, -5);
fdScript.bottom = new FormAttachment(100, -50);
folder.setLayoutData(fdScript);
wlPosition = new Label(wTop, SWT.NONE);
wlPosition.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Position.Label"));
props.setLook(wlPosition);
FormData fdlPosition = new FormData();
fdlPosition.left = new FormAttachment(wTree, margin);
fdlPosition.right = new FormAttachment(30, 0);
fdlPosition.top = new FormAttachment(folder, margin);
wlPosition.setLayoutData(fdlPosition);
wlHelpLabel = new Text(wTop, SWT.V_SCROLL | SWT.LEFT);
wlHelpLabel.setEditable(false);
wlHelpLabel.setText("Hallo");
props.setLook(wlHelpLabel);
FormData fdHelpLabel = new FormData();
fdHelpLabel.left = new FormAttachment(wlPosition, margin);
fdHelpLabel.top = new FormAttachment(folder, margin);
fdHelpLabel.right = new FormAttachment(100, -5);
fdHelpLabel.bottom = new FormAttachment(100, 0);
wlHelpLabel.setLayoutData(fdHelpLabel);
wlHelpLabel.setVisible(false);
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, 0);
wTop.setLayoutData(fdTop);
//
// Add a tab folder for the parameters and various input and output
// streams
//
wTabFolder = new CTabFolder(wSash, SWT.BORDER);
props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
wTabFolder.setSimple(false);
wTabFolder.setUnselectedCloseVisible(false);
FormData fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment(0, 0);
fdTabFolder.right = new FormAttachment(100, 0);
fdTabFolder.top = new FormAttachment(0, 0);
fdTabFolder.bottom = new FormAttachment(100, -75);
wTabFolder.setLayoutData(fdTabFolder);
// The Fields tab...
//
addFieldsTab();
// The parameters
//
addParametersTab();
prevStepNames = transMeta.getPrevStepNames(stepMeta);
nextStepNames = transMeta.getNextStepNames(stepMeta);
// OK, add another tab for the input settings...
//
addInfoTab();
addTargetTab();
// Select the fields tab...
//
wTabFolder.setSelection(fieldsTab);
FormData fdSash = new FormData();
fdSash.left = new FormAttachment(0, 0);
fdSash.top = new FormAttachment(wStepname, 0);
fdSash.right = new FormAttachment(100, 0);
fdSash.bottom = new FormAttachment(100, -50);
wSash.setLayoutData(fdSash);
wSash.setWeights(new int[] { 75, 25 });
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wTest = new Button(shell, SWT.PUSH);
wTest.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.TestClass.Button"));
// wCreatePlugin = new Button(shell, SWT.PUSH);
// wCreatePlugin.setText("Create Plug-in");
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel, wTest /* , wCreatePlugin */
}, margin, null);
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsTest = new Listener() {
public void handleEvent(Event e) {
test();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsTree = new Listener() {
public void handleEvent(Event e) {
treeDblClick(e);
}
};
/*
* lsCreatePlugin = new Listener() { public void handleEvent(Event e) { createPlugin(); } };
*/
wCancel.addListener(SWT.Selection, lsCancel);
wTest.addListener(SWT.Selection, lsTest);
wOK.addListener(SWT.Selection, lsOK);
// wCreatePlugin.addListener(SWT.Selection, lsCreatePlugin);
wTree.addListener(SWT.MouseDoubleClick, lsTree);
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
if (!cancel()) {
e.doit = false;
}
}
});
folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
CTabItem cItem = (CTabItem) event.item;
event.doit = false;
if (cItem != null && folder.getItemCount() > 1) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.NO | SWT.YES);
messageBox.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.DeleteItem.Label"));
messageBox.setMessage(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.ConfirmDeleteItem.Label", cItem.getText()));
switch(messageBox.open()) {
case SWT.YES:
modifyTabTree(cItem, TabActions.DELETE_ITEM);
event.doit = true;
break;
default:
break;
}
}
}
});
cMenu = new Menu(shell, SWT.POP_UP);
buildingFolderMenu();
tMenu = new Menu(shell, SWT.POP_UP);
buildingTreeMenu();
// Adding the Default Transform Class Item to the Tree
wTreeClassesItem = new TreeItem(wTree, SWT.NULL);
wTreeClassesItem.setImage(guiResource.getImageBol());
wTreeClassesItem.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Classes.Label"));
// Set the shell size, based upon previous time...
setSize();
getData();
// Adding the Rest (Functions, InputItems, etc.) to the Tree
buildSnippitsTree();
// Input Fields
itemInput = new TreeItem(wTree, SWT.NULL);
itemInput.setImage(imageInputFields);
itemInput.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.InputFields.Label"));
itemInput.setData("Field Helpers");
// Info Fields
itemInfo = new TreeItem(wTree, SWT.NULL);
itemInfo.setImage(imageInputFields);
itemInfo.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.InfoFields.Label"));
itemInfo.setData("Field Helpers");
// Output Fields
itemOutput = new TreeItem(wTree, SWT.NULL);
itemOutput.setImage(imageOutputFields);
itemOutput.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.OutputFields.Label"));
itemOutput.setData("Field Helpers");
// Display waiting message for input
itemWaitFieldsIn = new TreeItem(itemInput, SWT.NULL);
itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.GettingFields.Label"));
itemWaitFieldsIn.setForeground(guiResource.getColorDirectory());
itemInput.setExpanded(true);
// Display waiting message for info
itemWaitFieldsInfo = new TreeItem(itemInfo, SWT.NULL);
itemWaitFieldsInfo.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.GettingFields.Label"));
itemWaitFieldsInfo.setForeground(guiResource.getColorDirectory());
itemInfo.setExpanded(true);
// Display waiting message for output
itemWaitFieldsOut = new TreeItem(itemOutput, SWT.NULL);
itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.GettingFields.Label"));
itemWaitFieldsOut.setForeground(guiResource.getColorDirectory());
itemOutput.setExpanded(true);
//
// Search the fields in the background
//
final Runnable runnable = new Runnable() {
public void run() {
StepMeta stepMeta = transMeta.findStep(stepname);
if (stepMeta != null) {
try {
inputRowMeta = transMeta.getPrevStepFields(stepMeta);
infoRowMeta = transMeta.getPrevInfoFields(stepMeta);
outputRowMeta = transMeta.getThisStepFields(stepMeta, null, inputRowMeta.clone());
populateFieldsTree();
} catch (KettleException e) {
log.logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"), e);
}
}
}
};
new Thread(runnable).start();
addRenameToTreeScriptItems();
input.setChanged(changed);
// Create the drag source on the tree
DragSource ds = new DragSource(wTree, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
boolean doit = false;
TreeItem item = wTree.getSelection()[0];
// Allow dragging snippits and field helpers
if (item != null && item.getParentItem() != null) {
if ("Snippits Category".equals(item.getParentItem().getData()) && !"Snippits Category".equals(item.getData())) {
doit = true;
} else if ("Field Helpers".equals(item.getParentItem().getData())) {
doit = true;
} else if (item.getParentItem().getParentItem() != null && "Field Helpers".equals(item.getParentItem().getParentItem().getData())) {
doit = true;
}
}
event.doit = doit;
}
public void dragSetData(DragSourceEvent event) {
// Set the data to be the first selected item's data
event.data = wTree.getSelection()[0].getData();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.eclipse.swt.dnd.DragSourceEvent 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.DragSourceEvent 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.DragSourceEvent 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