use of org.eclipse.swt.dnd.DragSourceEvent in project pentaho-kettle by pentaho.
the class SpoonTreeDelegate method addDragSourceToTree.
public void addDragSourceToTree(final Tree tree, final Tree selectionTree, final Tree coreObjectsTree) {
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { XMLTransfer.getInstance() };
DragSource ddSource = new DragSource(tree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
spoon.hideToolTips();
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
TransMeta transMeta = spoon.getActiveTransformation();
if (object instanceof StepMeta || object instanceof PluginInterface || (object instanceof DatabaseMeta && transMeta != null) || object instanceof TransHopMeta || object instanceof JobEntryCopy) {
event.doit = true;
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
int type = 0;
String id = null;
String data = null;
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
if (object instanceof StepMeta) {
StepMeta stepMeta = (StepMeta) object;
type = DragAndDropContainer.TYPE_STEP;
// name of the step.
data = stepMeta.getName();
} else if (object instanceof PluginInterface) {
PluginInterface plugin = (PluginInterface) object;
Class<? extends PluginTypeInterface> pluginType = plugin.getPluginType();
if (Const.classIsOrExtends(pluginType, StepPluginType.class)) {
type = DragAndDropContainer.TYPE_BASE_STEP_TYPE;
id = plugin.getIds()[0];
// Step type name
data = plugin.getName();
} else {
type = DragAndDropContainer.TYPE_BASE_JOB_ENTRY;
// job entry type name
data = plugin.getName();
if (treeObject.getItemText().equals(JobMeta.createStartEntry().getName())) {
data = treeObject.getItemText();
} else if (treeObject.getItemText().equals(JobMeta.createDummyEntry().getName())) {
data = treeObject.getItemText();
}
}
} else if (object instanceof DatabaseMeta) {
DatabaseMeta databaseMeta = (DatabaseMeta) object;
type = DragAndDropContainer.TYPE_DATABASE_CONNECTION;
data = databaseMeta.getName();
} else if (object instanceof TransHopMeta) {
TransHopMeta hop = (TransHopMeta) object;
type = DragAndDropContainer.TYPE_TRANS_HOP;
// nothing for really ;-)
data = hop.toString();
} else if (object instanceof JobEntryCopy) {
JobEntryCopy jobEntryCopy = (JobEntryCopy) object;
type = DragAndDropContainer.TYPE_JOB_ENTRY;
// name of the job entry.
data = jobEntryCopy.getName();
} else {
event.doit = false;
// ignore anything else you drag.
return;
}
event.data = new DragAndDropContainer(type, data, id);
}
public void dragFinished(DragSourceEvent event) {
}
});
}
use of org.eclipse.swt.dnd.DragSourceEvent in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method open.
public RepositoryObjectReference open() {
debug = "opening repository explorer";
try {
debug = "open new independent shell";
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageFolderConnections());
shell.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Title") + rep.getName() + "]");
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// Add a small toolbar to expand/collapse all items
//
ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
props.setLook(treeTb);
fdTreeTb = new FormData();
fdTreeTb.left = new FormAttachment(0, 0);
fdTreeTb.top = new FormAttachment(0, 0);
treeTb.setLayoutData(fdTreeTb);
// Add the items...
//
exportToXML = new ToolItem(treeTb, SWT.PUSH);
exportToXML.setImage(GUIResource.getInstance().getImageExport());
exportToXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Label"));
exportToXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Tooltip"));
importFromXML = new ToolItem(treeTb, SWT.PUSH);
importFromXML.setImage(GUIResource.getInstance().getImageImport());
importFromXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Label"));
importFromXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Tooltip"));
new ToolItem(treeTb, SWT.SEPARATOR);
showHideDeleted = new ToolItem(treeTb, SWT.PUSH);
showHideDeleted.setImage(GUIResource.getInstance().getImageShowDeleted());
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
showHideDeleted.setEnabled(rep.getRepositoryMeta().getRepositoryCapabilities().supportsRevisions());
new ToolItem(treeTb, SWT.SEPARATOR);
expandAll = new ToolItem(treeTb, SWT.PUSH);
expandAll.setImage(GUIResource.getInstance().getImageExpandAll());
expandAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Label"));
expandAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Tooltip"));
collapseAll = new ToolItem(treeTb, SWT.PUSH);
collapseAll.setImage(GUIResource.getInstance().getImageCollapseAll());
collapseAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Label"));
collapseAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Tooltip"));
// Tree
wTree = new Tree(shell, SWT.MULTI | SWT.BORDER);
wTree.setHeaderVisible(true);
props.setLook(wTree);
// Add some columns to it as well...
nameColumn = new TreeColumn(wTree, SWT.LEFT);
nameColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Name"));
nameColumn.setWidth(350);
nameColumn.setAlignment(10);
nameColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(0);
}
});
// No sorting on the type column just yet.
typeColumn = new TreeColumn(wTree, SWT.LEFT);
typeColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Type"));
typeColumn.setWidth(100);
typeColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(1);
}
});
userColumn = new TreeColumn(wTree, SWT.LEFT);
userColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.User"));
userColumn.setWidth(100);
userColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(2);
}
});
changedColumn = new TreeColumn(wTree, SWT.LEFT);
changedColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Changed"));
changedColumn.setWidth(120);
changedColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(3);
}
});
descriptionColumn = new TreeColumn(wTree, SWT.LEFT);
descriptionColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Description"));
descriptionColumn.setWidth(120);
descriptionColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(4);
}
});
lockColumn = new TreeColumn(wTree, SWT.LEFT);
lockColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.LockMessage"));
lockColumn.setWidth(120);
lockColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(5);
}
});
// Add a memory to the tree.
TreeMemory.addTreeListener(wTree, STRING_REPOSITORY_EXPLORER_TREE_NAME);
// Buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
FormData fdTree = new FormData();
int margin = 10;
// To the right of the label
fdTree.left = new FormAttachment(0, 0);
fdTree.top = new FormAttachment(treeTb, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, -50);
wTree.setLayoutData(fdTree);
BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK }, margin, null);
// Add listeners
wOK.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
close();
}
});
wTree.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
setTreeMenu();
}
});
wTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (e.button == 1) {
// left double click!
doDoubleClick();
}
}
});
wTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// F2 --> rename...
if (e.keyCode == SWT.F2) {
if (!readonly) {
renameInTree();
}
}
// F5 --> refresh...
if (e.keyCode == SWT.F5) {
refreshTree();
}
}
});
expandAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), true);
}
});
collapseAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), false);
}
});
importFromXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
importAll();
}
});
exportToXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
exportAll(null);
}
});
showHideDeleted.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
includeDeleted = !includeDeleted;
if (includeDeleted) {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Tooltip"));
} else {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
}
refreshTree();
}
});
// Drag & Drop
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wTree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
debug = "drag start";
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
debug = "drag set data";
event.data = "";
event.doit = false;
TreeItem[] ti = wTree.getSelection();
if (ti.length >= 1) {
int cat = getItemCategory(ti[0]);
//
if (cat == ITEM_CATEGORY_TRANSFORMATION) {
debug = "drag set: drag around transformation";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("transformation", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else if (cat == ITEM_CATEGORY_JOB) {
debug = "drag set: drag around job";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("job", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else {
debug = "do nothing";
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
}
}
@Override
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wTree, DND.DROP_MOVE);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragLeave(DropTargetEvent event) {
debug = "drag leave";
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
debug = "drag over";
}
@Override
public void drop(DropTargetEvent event) {
try {
debug = "Drop item in tree";
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
// event.feedback = DND.FEEDBACK_NONE;
TreeItem ti = (TreeItem) event.item;
if (ti != null) {
debug = "Get category";
int category = getItemCategory(ti);
if (category == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY || category == ITEM_CATEGORY_TRANSFORMATION) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveTransformation((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Title"));
mb.open();
}
}
} else if (category == ITEM_CATEGORY_JOB_DIRECTORY || category == ITEM_CATEGORY_JOB) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveJob((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Title"));
mb.open();
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Title"));
mb.open();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message2"), e);
}
}
@Override
public void dropAccept(DropTargetEvent event) {
debug = "drop accept";
}
});
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
close();
}
});
debug = "set screen size and position";
BaseStepDialog.setSize(shell, 400, 480, true);
// refreshes too.
setSort(0);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message2") + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message3"), e);
}
return lastOpened;
}
use of org.eclipse.swt.dnd.DragSourceEvent in project pentaho-kettle by pentaho.
the class ScriptValuesModDialog 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, "ScriptValuesDialogMod.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Filename line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.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
//
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
wlScriptFunctions = new Label(wTop, SWT.NONE);
wlScriptFunctions.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.JavascriptFunctions.Label"));
props.setLook(wlScriptFunctions);
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);
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
wlScript = new Label(wTop, SWT.NONE);
wlScript.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Javascript.Label"));
props.setLook(wlScript);
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);
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, "ScriptValuesDialogMod.Position.Label"));
props.setLook(wlPosition);
fdlPosition = new FormData();
fdlPosition.left = new FormAttachment(wTree, margin);
fdlPosition.right = new FormAttachment(30, 0);
fdlPosition.top = new FormAttachment(folder, margin);
wlPosition.setLayoutData(fdlPosition);
Label wlCompatible = new Label(wTop, SWT.NONE);
wlCompatible.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Compatible.Label"));
props.setLook(wlCompatible);
FormData fdlCompatible = new FormData();
fdlCompatible.left = new FormAttachment(wTree, margin);
fdlCompatible.right = new FormAttachment(middle, 0);
fdlCompatible.top = new FormAttachment(wlPosition, margin);
wlCompatible.setLayoutData(fdlCompatible);
wCompatible = new Button(wTop, SWT.CHECK);
wCompatible.setToolTipText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Compatible.Tooltip"));
props.setLook(wCompatible);
FormData fdCompatible = new FormData();
fdCompatible.left = new FormAttachment(wlCompatible, margin);
fdCompatible.top = new FormAttachment(wlPosition, margin);
wCompatible.setLayoutData(fdCompatible);
wCompatible.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setInputOutputFields();
input.setChanged(true);
}
});
Label wlOptimizationLevel = new Label(wTop, SWT.NONE);
wlOptimizationLevel.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OptimizationLevel.Label"));
props.setLook(wlOptimizationLevel);
FormData fdlOptimizationLevel = new FormData();
fdlOptimizationLevel.left = new FormAttachment(wCompatible, margin * 2);
fdlOptimizationLevel.top = new FormAttachment(wlPosition, margin);
wlOptimizationLevel.setLayoutData(fdlOptimizationLevel);
wOptimizationLevel = new TextVar(transMeta, wTop, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wOptimizationLevel.setToolTipText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OptimizationLevel.Tooltip"));
props.setLook(wOptimizationLevel);
FormData fdOptimizationLevel = new FormData();
fdOptimizationLevel.left = new FormAttachment(wlOptimizationLevel, margin);
fdOptimizationLevel.top = new FormAttachment(wlPosition, margin);
fdOptimizationLevel.right = new FormAttachment(100, margin);
wOptimizationLevel.setLayoutData(fdOptimizationLevel);
wOptimizationLevel.addModifyListener(lsMod);
wlHelpLabel = new Text(wTop, SWT.V_SCROLL | SWT.LEFT);
wlHelpLabel.setEditable(false);
wlHelpLabel.setText("Hallo");
props.setLook(wlHelpLabel);
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);
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);
wBottom = new Composite(wSash, SWT.NONE);
props.setLook(wBottom);
FormLayout bottomLayout = new FormLayout();
bottomLayout.marginWidth = Const.FORM_MARGIN;
bottomLayout.marginHeight = Const.FORM_MARGIN;
wBottom.setLayout(bottomLayout);
wSeparator = new Label(wBottom, SWT.SEPARATOR | SWT.HORIZONTAL);
fdSeparator = new FormData();
fdSeparator.left = new FormAttachment(0, 0);
fdSeparator.right = new FormAttachment(100, 0);
fdSeparator.top = new FormAttachment(0, -margin + 2);
wSeparator.setLayoutData(fdSeparator);
wlFields = new Label(wBottom, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wSeparator, 0);
wlFields.setLayoutData(fdlFields);
final int FieldsRows = input.getFieldname().length;
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Filename"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.RenameTo"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Length"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Precision"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Replace"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO) };
wFields = new TableView(transMeta, wBottom, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, 0);
wFields.setLayoutData(fdFields);
fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(0, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
wBottom.setLayoutData(fdBottom);
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"));
wVars = new Button(shell, SWT.PUSH);
wVars.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.GetVariables.Button"));
wTest = new Button(shell, SWT.PUSH);
wTest.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestScript.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel, wVars, wTest }, margin, null);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
// lsGet = new Listener() { public void handleEvent(Event e) { get(); } };
lsTest = new Listener() {
public void handleEvent(Event e) {
newTest();
}
};
lsVars = new Listener() {
public void handleEvent(Event e) {
test(true, true);
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsTree = new Listener() {
public void handleEvent(Event e) {
treeDblClick(e);
}
};
// lsHelp = new Listener(){public void handleEvent(Event e){ wlHelpLabel.setVisible(true); }};
wCancel.addListener(SWT.Selection, lsCancel);
// wGet.addListener (SWT.Selection, lsGet );
wTest.addListener(SWT.Selection, lsTest);
wVars.addListener(SWT.Selection, lsVars);
wOK.addListener(SWT.Selection, lsOK);
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, "ScriptValuesDialogMod.DeleteItem.Label"));
messageBox.setMessage(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ConfirmDeleteItem.Label", cItem.getText()));
switch(messageBox.open()) {
case SWT.YES:
modifyScriptTree(cItem, 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 Scripts Item to the Tree
wTreeScriptsItem = new TreeItem(wTree, SWT.NULL);
wTreeScriptsItem.setImage(guiresource.getImageBol());
wTreeScriptsItem.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.TransformScript.Label"));
// Set the shell size, based upon previous time...
setSize();
getData();
// Adding the Rest (Functions, InputItems, etc.) to the Tree
buildSpecialFunctionsTree();
// Input Fields
iteminput = new TreeItem(wTree, SWT.NULL);
iteminput.setImage(imageInputFields);
iteminput.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.InputFields.Label"));
// Output Fields
itemoutput = new TreeItem(wTree, SWT.NULL);
itemoutput.setImage(imageOutputFields);
itemoutput.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OutputFields.Label"));
// Display waiting message for input
itemWaitFieldsIn = new TreeItem(iteminput, SWT.NULL);
itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.GettingFields.Label"));
itemWaitFieldsIn.setForeground(guiresource.getColorDirectory());
iteminput.setExpanded(true);
// Display waiting message for output
itemWaitFieldsOut = new TreeItem(itemoutput, SWT.NULL);
itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.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 {
rowPrevStepFields = transMeta.getPrevStepFields(stepMeta);
if (rowPrevStepFields != null) {
setInputOutputFields();
} else {
// Can not get fields...end of wait message
if (Const.isRunningOnWebspoonMode() && (iteminput.isDisposed() || itemoutput.isDisposed())) {
return;
}
iteminput.removeAll();
itemoutput.removeAll();
}
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
}
}
}
};
new Thread(runnable).start();
// rebuildInputFieldsTree();
// buildOutputFieldsTree();
buildAddClassesListTree();
addRenameTowTreeScriptItems();
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) {
TreeItem item = wTree.getSelection()[0];
// Qualifikation where the Drag Request Comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeScriptsItem)) {
event.doit = false;
} else if (!item.getData().equals("Function")) {
String strInsert = (String) item.getData();
if (strInsert.equals("jsFunction")) {
event.doit = true;
} else {
event.doit = false;
}
} else {
event.doit = false;
}
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Set the data to be the first selected item's text
event.data = wTree.getSelection()[0].getText();
}
});
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 ScriptDialog 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, "ScriptDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Filename line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "ScriptDialog.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
//
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
wlScriptFunctions = new Label(wTop, SWT.NONE);
wlScriptFunctions.setText(BaseMessages.getString(PKG, "ScriptDialog.JavascriptFunctions.Label"));
props.setLook(wlScriptFunctions);
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);
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
wlScript = new Label(wTop, SWT.NONE);
wlScript.setText(BaseMessages.getString(PKG, "ScriptDialog.Javascript.Label"));
props.setLook(wlScript);
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);
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, "ScriptDialog.Position.Label"));
props.setLook(wlPosition);
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);
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);
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);
wBottom = new Composite(wSash, SWT.NONE);
props.setLook(wBottom);
FormLayout bottomLayout = new FormLayout();
bottomLayout.marginWidth = Const.FORM_MARGIN;
bottomLayout.marginHeight = Const.FORM_MARGIN;
wBottom.setLayout(bottomLayout);
wSeparator = new Label(wBottom, SWT.SEPARATOR | SWT.HORIZONTAL);
fdSeparator = new FormData();
fdSeparator.left = new FormAttachment(0, 0);
fdSeparator.right = new FormAttachment(100, 0);
fdSeparator.top = new FormAttachment(0, -margin + 2);
wSeparator.setLayoutData(fdSeparator);
wlFields = new Label(wBottom, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "ScriptDialog.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wSeparator, 0);
wlFields.setLayoutData(fdlFields);
final int FieldsRows = input.getFieldname().length;
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Filename"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.RenameTo"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Length"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Precision"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Replace"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO) };
wFields = new TableView(transMeta, wBottom, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, 0);
wFields.setLayoutData(fdFields);
fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(0, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
wBottom.setLayoutData(fdBottom);
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"));
wVars = new Button(shell, SWT.PUSH);
wVars.setText(BaseMessages.getString(PKG, "ScriptDialog.GetVariables.Button"));
wTest = new Button(shell, SWT.PUSH);
wTest.setText(BaseMessages.getString(PKG, "ScriptDialog.TestScript.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel, wVars, wTest }, margin, null);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
// lsGet = new Listener() { public void handleEvent(Event e) { get(); } };
lsTest = new Listener() {
public void handleEvent(Event e) {
newTest();
}
};
lsVars = new Listener() {
public void handleEvent(Event e) {
test(true, true);
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsTree = new Listener() {
public void handleEvent(Event e) {
treeDblClick(e);
}
};
// lsHelp = new Listener(){public void handleEvent(Event e){ wlHelpLabel.setVisible(true); }};
wCancel.addListener(SWT.Selection, lsCancel);
// wGet.addListener (SWT.Selection, lsGet );
wTest.addListener(SWT.Selection, lsTest);
wVars.addListener(SWT.Selection, lsVars);
wOK.addListener(SWT.Selection, lsOK);
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, "ScriptDialog.DeleteItem.Label"));
messageBox.setMessage(BaseMessages.getString(PKG, "ScriptDialog.ConfirmDeleteItem.Label", cItem.getText()));
switch(messageBox.open()) {
case SWT.YES:
modifyScriptTree(cItem, 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 Scripts Item to the Tree
wTreeScriptsItem = new TreeItem(wTree, SWT.NULL);
wTreeScriptsItem.setImage(guiresource.getImageBol());
wTreeScriptsItem.setText(BaseMessages.getString(PKG, "ScriptDialog.TransformScript.Label"));
// Set the shell size, based upon previous time...
setSize();
getData();
// Adding the Rest (Functions, InputItems, etc.) to the Tree
buildSpecialFunctionsTree();
// Input Fields
iteminput = new TreeItem(wTree, SWT.NULL);
iteminput.setImage(imageInputFields);
iteminput.setText(BaseMessages.getString(PKG, "ScriptDialog.InputFields.Label"));
// Output Fields
itemoutput = new TreeItem(wTree, SWT.NULL);
itemoutput.setImage(imageOutputFields);
itemoutput.setText(BaseMessages.getString(PKG, "ScriptDialog.OutputFields.Label"));
// Display waiting message for input
itemWaitFieldsIn = new TreeItem(iteminput, SWT.NULL);
itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "ScriptDialog.GettingFields.Label"));
itemWaitFieldsIn.setForeground(guiresource.getColorDirectory());
iteminput.setExpanded(true);
// Display waiting message for output
itemWaitFieldsOut = new TreeItem(itemoutput, SWT.NULL);
itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "ScriptDialog.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 {
rowPrevStepFields = transMeta.getPrevStepFields(stepMeta);
if (rowPrevStepFields != null) {
setInputOutputFields();
} else {
// Can not get fields...end of wait message
iteminput.removeAll();
itemoutput.removeAll();
}
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
}
}
}
};
new Thread(runnable).start();
// rebuildInputFieldsTree();
// buildOutputFieldsTree();
buildAddClassesListTree();
addRenameTowTreeScriptItems();
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) {
TreeItem item = wTree.getSelection()[0];
// Qualifikation where the Drag Request Comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeScriptsItem)) {
event.doit = false;
} else if (!item.getData().equals("Function")) {
String strInsert = (String) item.getData();
if (strInsert.equals("jsFunction")) {
event.doit = true;
} else {
event.doit = false;
}
} else {
event.doit = false;
}
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Set the data to be the first selected item's text
event.data = wTree.getSelection()[0].getText();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.eclipse.swt.dnd.DragSourceEvent in project cogtool by cogtool.
the class ProjectUI method setUpDragAndDrop.
// See http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
// for more documentation of SWT drag-and-drop support.
protected void setUpDragAndDrop() {
DragSource treeAsSource = new DragSource(tree, DND.DROP_MOVE | DND.DROP_COPY);
TaskDnDTransfer taskTransfer = TaskDnDTransfer.getInstance();
TaskAppDnDTransfer taskAppTransfer = TaskAppDnDTransfer.getInstance();
Transfer[] types = new Transfer[] { taskTransfer, taskAppTransfer };
treeAsSource.setTransfer(types);
// DropSourceEvent fields:
// dataType:
// the Transfer type of the data the target prefers to receive;
// useful in dragSetData
// detail:
// the operation the target performed; one of:
// DROP_MOVE - move from source to target; remove from source
// DROP_COPY - copy the source to target; leave the source
// DROP_LINK - create a link of the source at the target
// useful in dragFinished in case the source needs to be removed
// doit:
// in dragStart, determines if the operation should proceed
// in dragFinished, may be set to indicate if the operation succeeded
// image:
// may be set to the Image displayed during drag
// x, y: position within the Tree
DragSourceListener srcListener = new TreeDragSourceEffect(tree) {
@Override
public void dragStart(DragSourceEvent evt) {
// If the Transfer type cannot be determined until the drag
// starts, the setTransfer() call can be invoked here.
// Set evt.doit to false here if action is inappropriate.
// Reset, just in case no drag-and-drop should happen
currentDnDSource = null;
// Must be in first column!
TreeColumn column = findColumn(evt.x);
TreeItem row = tree.getItem(new Point(evt.x, evt.y));
if ((column != null) && (column.getData() == null)) {
if ((row != null) && (row.getData() != null)) {
if (((AUndertaking) row.getData()).isSpawned()) {
evt.doit = false;
return;
}
}
if (selection.getSelectedTaskCount() == 0) {
if (row != null) {
selection.setSelectedItem(row);
currentDnDSource = tree;
currentDnDColumn = 0;
}
} else {
currentDnDSource = tree;
currentDnDColumn = 0;
}
} else {
// Must be in cell with a valid TaskApplication!
if ((column != null) && (column.getData() != null)) {
if ((row != null) && (row.getData() != null)) {
Design design = (Design) column.getData();
AUndertaking task = (AUndertaking) row.getData();
TaskApplication taskApp = project.getTaskApplication(task, design);
if (taskApp != null) {
if (!taskApp.getDemonstration().isEditable()) {
evt.doit = false;
return;
}
// set some highlighting of the source cell
selection.setSelectedCell(row, column);
contextSelection.setSelectedDesign(design);
contextSelection.addSelectedTask(task);
currentDnDRow = row;
currentDnDSource = tree;
currentDnDColumn = tree.indexOf(column);
// do not do superclass work!
return;
}
}
}
evt.doit = false;
}
super.dragStart(evt);
}
@Override
public void dragSetData(DragSourceEvent evt) {
// Based on the requested Transfer data type, set evt.data
// if (taskTransfer.isSupportedType(evt.dataType)) {
// evt.data = "This is the requested data";
// }
super.dragSetData(evt);
}
@Override
public void dragFinished(DragSourceEvent evt) {
// Operation was performed by the drop target; clean up
// If needed, evt.detail should be the operation performed.
super.dragFinished(evt);
currentDnDSource = null;
currentDnDColumn = -1;
currentDnDRow = null;
currentDndTaskAppDropRow = null;
}
};
treeAsSource.addDragListener(srcListener);
DropTarget treeAsTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY);
treeAsTarget.setTransfer(types);
// DropTargetEvent fields:
// currentDataType:
// the Transfer type of the data the target prefers to receive;
// can be set -- see the method comments below
// dataTypes:
// the array of Transfer types the source can "send"
// detail:
// the operation the user is trying to perform; one of:
// DROP_MOVE - move from source to target; remove from source
// DROP_COPY - copy the source to target; leave the source
// DROP_LINK - create a link of the source at the target
// DROP_DEFAULT - indicator that target must choose operation
// DROP_NONE - indicator that user is trying an unsupported op
// may be set to the operation the target feels is correct
// (thus, if initially DEFAULT, then the operation that would be
// performed; if initially DEFAULT and not changed, it will appear
// to the user as a MOVE -- also, set to NONE if target determines
// operation is not permitted)
// feedback:
// bitwise OR'ing of feedback effects displayed to the user;
// can be set using the following constants:
// FEEDBACK_SELECT - item under cursor is selected
// FEEDBACK_SCROLL - allows scrolling to make items visible
// FEEDBACK_EXPAND - allows tree items to be expanded
// FEEDBACK_INSERT_BEFORE - insertion mark before item under cursor
// FEEDBACK_INSERT_AFTER - insertion mark after item under cursor
// FEEDBACK_NONE - no feedback
// item:
// TreeItem or TableItem under the cursor, if applicable
// operations:
// bitwise OR'ing of the operations that the DragSource can support
treeAsTarget.addDropListener(new TreeDropTargetEffect(tree) {
protected static final int DRAG_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE | DND.FEEDBACK_SCROLL;
protected static final int DRAG_APP_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
protected int requestedOp = DND.DROP_MOVE;
@Override
public void dragEnter(DropTargetEvent evt) {
// Set evt.detail to DND.DROP_NONE when the operation is a no-op
// or if the presented type is unacceptable. Other choices
// that make sense: DND.DROP_MOVE, DND.DROP_COPY
// evt.currentDataType is the type preferred by the target.
// evt.dataTypes contains types provided by the source.
super.dragEnter(evt);
if (currentDnDSource != getControl()) {
evt.detail = DND.DROP_NONE;
} else {
requestedOp = evt.detail;
}
}
@Override
public void dragLeave(DropTargetEvent evt) {
if (currentDndTaskAppDropRow != null) {
currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
}
super.dragLeave(evt);
}
@Override
public void dragOperationChanged(DropTargetEvent evt) {
// change evt.currentDataType if desired here.
if ((evt.detail != DND.DROP_MOVE) && (evt.detail != DND.DROP_COPY)) {
evt.detail = DND.DROP_NONE;
}
requestedOp = evt.detail;
super.dragOperationChanged(evt);
}
@Override
public void dragOver(DropTargetEvent evt) {
if (currentDndTaskAppDropRow != null) {
currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
}
Point toTreeEvtLoc = tree.toControl(evt.x, evt.y);
//System.out.println("dragOver; set feedback here?");
if (currentDnDSource != getControl()) {
evt.detail = DND.DROP_NONE;
evt.feedback = DND.FEEDBACK_NONE;
} else if (currentDnDColumn == 0) {
// Moving tasks
evt.feedback = DRAG_FEEDBACK;
evt.detail = requestedOp;
TreeItem row = tree.getItem(toTreeEvtLoc);
if ((row != null) && (row.getData() != null)) {
if (((AUndertaking) row.getData()).isSpawned()) {
evt.detail = DND.DROP_NONE;
evt.feedback = DND.FEEDBACK_NONE;
}
}
} else {
// Moving task applications
evt.feedback = DRAG_APP_FEEDBACK;
TreeColumn column = findColumn(toTreeEvtLoc.x);
if (column == null) {
evt.detail = DND.DROP_NONE;
} else {
Design design = (Design) column.getData();
if (design != contextSelection.getSelectedDesign()) {
evt.detail = DND.DROP_NONE;
} else {
TreeItem row = tree.getItem(toTreeEvtLoc);
if ((row == null) || (row.getData() == null)) {
evt.detail = DND.DROP_NONE;
} else {
AUndertaking task = (AUndertaking) row.getData();
if (task.isTaskGroup() || task.isSpawned() || contextSelection.isTaskSelected(task)) {
evt.detail = DND.DROP_NONE;
} else {
evt.detail = requestedOp;
currentDndTaskAppDropRow = row;
currentDndTaskAppDropRow.setBackground(currentDnDColumn, CONTEXT_COLOR);
}
}
}
}
}
super.dragOver(evt);
}
@Override
public void dropAccept(DropTargetEvent evt) {
// Can change evt.detail if desired here.
// Provide one last chance to define the type of data that
// will be returned in the drop event; thus, change
// evt.currentDataType if desired here
super.dropAccept(evt);
}
@Override
public void drop(DropTargetEvent evt) {
// When the drop operation is completed, update the
// evt.detail field with the operation performed.
// Do the operation!
AUndertaking beforeTask = null;
if (evt.item != null) {
beforeTask = (AUndertaking) evt.item.getData();
}
if (requestedOp == DND.DROP_COPY) {
if (currentDnDColumn == 0) {
ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, true);
if (performAction(ProjectLID.DuplicateTaskFull, parms, true)) {
evt.detail = DND.DROP_COPY;
}
} else {
AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
TreeColumn column = tree.getColumn(currentDnDColumn);
Design design = (Design) column.getData();
ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
selection.setSelectedCell(currentDndTaskAppDropRow, column);
if (performAction(ProjectLID.DuplicateTaskApplication, parms, true)) {
uiModel.redisplayAllResults();
evt.detail = DND.DROP_COPY;
}
}
} else if (requestedOp == DND.DROP_MOVE) {
if (currentDnDColumn == 0) {
ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, false);
if (performAction(ProjectLID.ChangeTaskPosition, parms, true)) {
evt.detail = DND.DROP_MOVE;
}
} else {
AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
TreeColumn column = tree.getColumn(currentDnDColumn);
Design design = (Design) column.getData();
ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
selection.setSelectedCell(currentDndTaskAppDropRow, column);
if (performAction(ProjectLID.MoveTaskApplication, parms, true)) {
uiModel.redisplayAllResults();
evt.detail = DND.DROP_MOVE;
}
}
}
super.drop(evt);
}
});
}
Aggregations