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 ReviewComponentDialog method createRatingComp.
private void createRatingComp(Composite parent) {
initImages();
final Composite rateBtnComp = new Composite(parent, SWT.NONE);
final GridLayout rateLayout = new GridLayout();
rateLayout.numColumns = 5;
rateBtnComp.setLayout(rateLayout);
rateBtnComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
for (int i = 0; i < 5; i++) {
final Button rateButton = new Button(rateBtnComp, SWT.NONE);
rateButton.setLayoutData(new GridData(30, SWT.DEFAULT));
rateButton.setImage(imageMap.get(1));
rateButton.setData(0);
rateBtnMap.put(i, rateButton);
rateButton.addMouseTrackListener(new MouseTrackListener() {
public void mouseHover(MouseEvent e) {
handleMouseHover(rateButton);
}
public void mouseExit(MouseEvent e) {
handleMouseExit(rateButton);
}
public void mouseEnter(MouseEvent e) {
}
});
rateButton.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
handleMouseDown(rateButton);
checkInput();
}
public void mouseDoubleClick(MouseEvent e) {
}
});
}
rateLabel = new Label(parent, SWT.NONE);
rateLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
rateLabel.setText("Please select your rating*");
}
use of org.eclipse.swt.events.MouseEvent in project yyl_example by Relucent.
the class HelloCanvasArrow method open.
public void open() {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setLayout(new FillLayout());
final Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_ARROW));
canvas.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent arg0) {
}
public void mouseDown(MouseEvent e) {
p[0] = e.x;
p[1] = e.y;
b = true;
}
public void mouseUp(MouseEvent arg0) {
if (b) {
int[] tp = new int[4];
tp[0] = p[0];
tp[1] = p[0];
tp[2] = p[0];
tp[3] = p[3];
}
b = false;
}
});
canvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
p[2] = e.x;
p[3] = e.y;
canvas.redraw();
}
});
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent paintevent) {
if (b) {
paintArrow(paintevent.gc, new Point(p[0], p[1]), new Point(p[2], p[3]));
}
}
});
shell.setText("test");
shell.setSize(300, 300);
shell.layout();
shell.open();
while (!shell.isDisposed()) if (!display.readAndDispatch())
display.sleep();
}
use of org.eclipse.swt.events.MouseEvent in project tdi-studio-se by Talend.
the class ImportComponentDialog method createDialogArea.
/*
* (non-Javadoc) Method declared on Dialog.
*/
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gl = new GridLayout(5, true);
composite.setLayout(gl);
if (message != null) {
Label label = new Label(composite, SWT.WRAP);
label.setText(message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 5;
label.setLayoutData(data);
label.setFont(parent.getFont());
}
Label label1 = new Label(composite, SWT.NONE);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.horizontalSpan = 2;
label1.setLayoutData(gd);
//$NON-NLS-1$
label1.setText(Messages.getString("ImportComponentDialog.SelectDirectoryLabel"));
text = new Text(composite, SWT.BORDER);
text.setEditable(false);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
text.setLayoutData(gd);
if (paletteComponentsPath == null) {
//$NON-NLS-1$
paletteComponentsPath = "";
}
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validateInput(true);
}
});
Button button = new Button(composite, SWT.NONE);
//$NON-NLS-1$
button.setText(Messages.getString("ImportComponentDialog.Browser"));
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalSpan = 1;
button.setLayoutData(gd);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dd = new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
String path = dd.open();
if (path != null) {
text.setText(path);
}
}
});
Button showPaletteComponents = new Button(composite, SWT.NONE);
gd = new GridData();
gd.horizontalSpan = 2;
showPaletteComponents.setLayoutData(gd);
//$NON-NLS-1$
showPaletteComponents.setText(Messages.getString("ImportComponentDialog.ShowPaletteComponents"));
showPaletteComponents.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
text.setText(paletteComponentsPath);
}
});
label1 = new Label(composite, SWT.LEFT);
gd = new GridData();
gd.horizontalSpan = 1;
label1.setLayoutData(gd);
//$NON-NLS-1$
label1.setText(Messages.getString("ImportComponentDialog.Filter"));
filterText = new Text(composite, SWT.BORDER);
filterText.setEditable(true);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
filterText.setLayoutData(gd);
filterText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validateInput(false);
}
});
label1 = new Label(composite, SWT.LEFT);
gd = new GridData();
gd.horizontalSpan = 5;
label1.setLayoutData(gd);
//$NON-NLS-1$
label1.setText(Messages.getString("ImportComponentDialog.ChooseComponentsLabel"));
componentList = new List(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 5;
componentList.setLayoutData(gd);
componentList.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
validateSelected();
}
public void mouseUp(MouseEvent e) {
validateSelected();
}
});
errorMessageText = new Text(composite, SWT.READ_ONLY | SWT.CENTER);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 5;
label1.setLayoutData(gd);
errorMessageText.setLayoutData(gd);
errorMessageText.setBackground(errorMessageText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
applyDialogFont(composite);
//$NON-NLS-1$
text.setText("");
return composite;
}
use of org.eclipse.swt.events.MouseEvent in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method createEmptyTable.
/**
* Create the empty parameter table
*
* @param parent Composite
* @param isMulti boolean
*/
protected void createEmptyTable(Composite parent) {
Group typeGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
GridData groupGd = new GridData(GridData.FILL_HORIZONTAL);
groupGd.heightHint = 70;
typeGroup.setLayoutData(groupGd);
typeGroup.setLayout(new GridLayout());
typeGroup.setText(Messages.colParaType);
parameterTypeTable = new Table(typeGroup, SWT.BORDER | SWT.H_SCROLL);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 45;
parameterTypeTable.setLayoutData(gd);
parameterTypeTable.setHeaderVisible(true);
parameterTypeTable.setLinesVisible(false);
parameterTypeTable.setDragDetect(false);
TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.CENTER);
columnNO.setWidth(40);
columnNO.setText("");
tableEditor = new TableEditor(parameterTypeTable);
tableEditor.horizontalAlignment = SWT.LEFT;
tableEditor.grabHorizontal = true;
parameterTypeTable.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
if (event.button != 1) {
return;
}
if (isChanging) {
return;
}
Point pt = new Point(event.x, event.y);
final TableItem item = parameterTypeTable.getItem(0);
for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
handleType(item, i);
}
}
}
});
Group parameterGroup = new Group(parent, SWT.SHADOW_IN);
parameterGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
parameterGroup.setLayout(new GridLayout(2, false));
parameterGroup.setText(Messages.colParaValue);
ToolBar toolBar = new ToolBar(parameterGroup, SWT.FLAT);
ToolItem addRecordItem = new ToolItem(toolBar, SWT.PUSH);
addRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_insert.png"));
addRecordItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addData();
}
});
ToolItem delRecordItem = new ToolItem(toolBar, SWT.PUSH);
delRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
delRecordItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (parameterTable.getTable().getSelectionIndices().length == 0) {
setErrorMessage(Messages.errDeleteMsg);
return;
}
List<Integer> deleteIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
deleteIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
int lastSelectedIndex = 0;
for (int i = 0; i < deleteIndex.size(); i++) {
int seletectIndex = deleteIndex.get(i);
int newIndex = seletectIndex - i;
valueList.remove(newIndex);
lastSelectedIndex = newIndex;
}
//reset the index in data
for (int i = 0; i < valueList.size(); i++) {
ParamValueObject paramValueObject = valueList.get(i);
paramValueObject.getValue().set(0, String.valueOf(i + 1));
}
parameterTable.setInput(valueList);
parameterTable.refresh();
if (parameterTable.getTable().getItemCount() > 0) {
parameterTable.getTable().setSelection(lastSelectedIndex < 1 ? 0 : lastSelectedIndex - 1);
parameterTable.getTable().setFocus();
}
validate();
}
});
parameterTable = new TableViewer(parameterGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
// press the tab key, it is moved next input area
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(parameterTable, new FocusCellOwnerDrawHighlighter(parameterTable));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(parameterTable) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && ((MouseEvent) event.sourceEvent).button == 1) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
// || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
TableViewerEditor.create(parameterTable, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
// new Table(parameterGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
parameterTable.getTable().setLayoutData(gridData);
parameterTable.getTable().setHeaderVisible(true);
parameterTable.getTable().setLinesVisible(true);
parameterTable.setUseHashlookup(true);
final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
columnNO2.getColumn().setWidth(40);
columnNO2.getColumn().setText("");
parameterTable.setContentProvider(new ParamValueContentProvider());
parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
parameterTable.getTable().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
StringBuffer clipboardDataString = new StringBuffer();
List<Integer> replaceIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
for (int i = 0; i < replaceIndex.size(); i++) {
if (i != 0) {
clipboardDataString.append(EXCELDATASEPRATOR);
}
ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
for (int j = 1; j < parameterTypeTable.getColumnCount(); j++) {
if (j != 1) {
clipboardDataString.append(EXCELCOLUMNSEPRATOR);
}
String value = paramValueObject.getValue().get(j);
clipboardDataString.append(value);
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { clipboardDataString.toString() };
cb.setContents(data, transfers);
cb.dispose();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'v') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
// boolean supportFlag = false;
// TransferData[] transferDatas = cb.getAvailableTypes();
// for(int i=0; i<transferDatas.length; i++) {
// // Checks whether RTF format is available.
// if(RTFTransfer.getInstance().isSupportedType(transferDatas[i])) {
// supportFlag = true;
// break;
// }
// }
// if (!supportFlag) {
// setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
// return;
// }
String plainText = (String) cb.getContents(TextTransfer.getInstance());
List<ParamValueObject> list = generateParamValueObjectListFromClipboardString(plainText);
if (list.size() == 0 || list.get(0).getValue().size() != parameterTypeTable.getColumnCount()) {
setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
return;
}
// String rtfText = (String)cb.getContents(RTFTransfer.getInstance());
int startIndex = parameterTable.getTable().getSelectionIndex();
//if the copy line bigger than the value list, add new ParamValueObject to the end
if (parameterTable.getTable().getSelectionCount() <= 1) {
if (startIndex < 0 || startIndex > valueList.size()) {
for (ParamValueObject copyParamValueObject : list) {
valueList.add(copyParamValueObject);
}
} else {
for (ParamValueObject copyParamValueObject : list) {
if (startIndex > valueList.size() - 1) {
valueList.add(copyParamValueObject);
} else {
ParamValueObject paramValueObject = valueList.get(startIndex);
List<String> oldValue = paramValueObject.getValue();
for (int i = 1; i < oldValue.size(); i++) {
List<String> newValue = copyParamValueObject.getValue();
if (i > newValue.size() - 1) {
break;
}
oldValue.set(i, newValue.get(i));
}
}
startIndex++;
}
}
} else {
// replay the select line
List<Integer> replaceIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
for (int i = 0; i < replaceIndex.size(); i++) {
ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
List<String> oldValue = paramValueObject.getValue();
if (i > list.size()) {
break;
}
List<String> newValue = list.get(i).getValue();
for (int j = 1; j < oldValue.size(); j++) {
if (j > newValue.size()) {
break;
}
oldValue.set(j, newValue.get(j));
}
}
}
cb.dispose();
refreshValueListIndex();
parameterTable.refresh();
validate();
}
}
});
// use to mark click point, the right click menu use this point
parameterTable.getTable().addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
clickPoint = new Point(event.x, event.y);
}
});
registerContextMenu();
parameterTable.setInput(valueList);
}
Aggregations