use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class TalendEditPartTipHelper method hookShellListeners.
@Override
protected void hookShellListeners() {
/*
* If the cursor leaves the tip window, hide the tooltip and dispose of its shell
*/
getShell().addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent e) {
getShell().setCapture(false);
dispose();
}
});
/*
* If the mouseExit listener does not get called, dispose of the shell if the cursor is no longer in the
* tooltip. This occurs in the rare case that a mouseEnter is not received on the tooltip when it appears.
*/
getShell().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
}
}
});
// window.
if (shellListener == null) {
shellListener = new ShellAdapter() {
@Override
public void shellDeactivated(ShellEvent event) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.getShell() == active || getShell().isDisposed()) {
return;
}
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
}
});
}
};
control.getShell().addShellListener(shellListener);
getShell().addShellListener(shellListener);
}
/*
* Workaround for GTK Bug - Control.setCapture(boolean) not implemented: If the cursor is not over the shell
* when it is first painted, hide the tooltip and dispose of the shell.
*/
if (SWT.getPlatform().equals("gtk")) {
//$NON-NLS-1$
getShell().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
}
});
}
}
});
}
}
use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class SQLPatternComposite method createCodeControl.
/**
* DOC bqian Comment method "createCodeControl".
*
* @param panel
* @param
*/
private void createCodeControl(Composite panel, Control reference) {
codeText = new Text(panel, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
codeText.setEditable(false);
FormData fd = new FormData();
fd.left = new FormAttachment(10, 0);
fd.right = new FormAttachment(90, 0);
fd.top = new FormAttachment(reference, 2);
fd.bottom = new FormAttachment(95, 0);
codeText.setLayoutData(fd);
codeText.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
if (tableViewer.getTable().getSelection().length == 0) {
return;
}
TableItem item = tableViewer.getTable().getSelection()[0];
if (item == null || item.getText() == null) {
return;
}
String sqlpatternName = item.getText();
SQLPatternItem patternItem = SQLPatternUtils.getSQLPatternItem(SQLPatternComposite.this.element, sqlpatternName);
if (patternItem.isSystem()) {
boolean answer = //$NON-NLS-1$
MessageDialog.openQuestion(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
Messages.getString("SQLPatternComposite.forbidModification"));
if (!answer) {
return;
}
IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IElementParameter parameter = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
String dbName = (String) parameter.getValue();
//$NON-NLS-1$
String path = dbName + "/" + RepositoryConstants.USER_DEFINED;
repositoryService.createSqlpattern(path, true);
} else if (sqlPatternAndProject.get(patternItem) != null) {
MessageDialog.openInformation(getShell(), "Information", "Forbid modification on sql template from reference project");
} else {
boolean answer = //$NON-NLS-1$
MessageDialog.openQuestion(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
Messages.getString("SQLPatternComposite.modifySQLPattern"));
if (!answer) {
return;
}
IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
repositoryService.openSQLPatternEditor(patternItem, false);
}
}
@Override
public void mouseDown(MouseEvent e) {
// do nothing
}
@Override
public void mouseDoubleClick(MouseEvent e) {
mouseUp(e);
}
});
}
use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class WidgetFactory method adapt.
@Override
public void adapt(Composite composite) {
composite.setBackground(getColors().getBackground());
MouseAdapter listener = new MouseAdapter() {
public void mouseDown(MouseEvent e) {
Control control = (Control) e.widget;
if (control instanceof Composite) {
Composite parent = (Composite) control;
setChildFocus(parent);
} else {
control.setFocus();
}
}
};
composite.addMouseListener(listener);
composite.getParent().addMouseListener(listener);
composite.setMenu(composite.getParent().getMenu());
}
use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class ExpressionBuilderDialog method createButtonsForButtonBar.
/**
* Create contents of the button bar
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).numColumns++;
Composite buttons = new Composite(parent, SWT.NONE);
buttons.setLayout(new GridLayout(2, false));
final Button importButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
final Button exportButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
//$NON-NLS-1$
createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
//$NON-NLS-1$
createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
exportButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
String expresionContent = expressionComposite.getExpression();
List<Variable> variables = new ArrayList<Variable>();
variables = testComposite.getVariableList();
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
if (file != null) {
file.createNewFile();
}
operation.saveExpressionToFile(file, variables, expresionContent);
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
importButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
List list = operation.importExpressionFromFile(file, getShell());
if (list != null && list.size() != 0) {
expressionComposite.setExpression((String) list.get(0), false);
list.remove(0);
if (list.size() > 0) {
testComposite.addVariables(list);
}
}
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
} catch (SAXException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
}
use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class ExpressionCellEditor method createText.
public Text createText(Composite parent) {
text = new Text(parent, SWT.NONE);
text.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
handleDefaultSelection(e);
}
});
text.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
e.doit = false;
}
}
});
// We really want a selection listener but it is not supported so we
// use a key listener and a mouse listener to know when selection
// changes
// may have occured
text.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
highlightLineAndSetSelectionOfStyledTextFromTextControl(text);
}
@Override
public void mouseUp(MouseEvent e) {
checkSelection();
checkDeleteable();
checkSelectable();
}
});
text.setFont(parent.getFont());
text.setBackground(parent.getBackground());
//$NON-NLS-1$
text.setText("");
text.addModifyListener(getModifyListener());
return text;
}
Aggregations