use of org.eclipse.swt.custom.CTabFolderEvent 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.custom.CTabFolderEvent 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;
}
Aggregations