use of org.eclipse.swt.events.KeyAdapter in project tdi-studio-se by Talend.
the class DB2ExplainPlanExecution method displayResults.
private void displayResults(final ExplainNode node) {
Display.getDefault().asyncExec(new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
clearCanvas();
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 2;
gLayout.marginLeft = 0;
gLayout.horizontalSpacing = 0;
gLayout.verticalSpacing = 0;
gLayout.marginWidth = 0;
gLayout.marginHeight = 0;
composite.setLayout(gLayout);
try {
//$NON-NLS-1$
composite.setData("parenttab", parentTab);
Composite pp = new Composite(composite, SWT.NULL);
pp.setLayout(new FillLayout());
pp.setLayoutData(new GridData(GridData.FILL_BOTH));
TreeViewer tv = new TreeViewer(pp, SWT.BORDER | SWT.FULL_SELECTION);
Tree tree = tv.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
TreeColumn tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText("");
tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText(Messages.getString("DB2ExplainPlanExecution.tableColumnText1"));
tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText(Messages.getString("DB2ExplainPlanExecution.tableColumnText2"));
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(6, 150, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tree.setLayout(tableLayout);
tv.setContentProvider(new ITreeContentProvider() {
@Override
public void dispose() {
}
@Override
public Object[] getChildren(Object parentElement) {
return ((ExplainNode) parentElement).getChildren();
}
@Override
public Object[] getElements(Object inputElement) {
ExplainNode nd = ((ExplainNode) inputElement);
return nd.getChildren();
}
@Override
public Object getParent(Object element) {
return ((ExplainNode) element).getParent();
}
@Override
public boolean hasChildren(Object element) {
if (((ExplainNode) element).getChildren().length > 0) {
return true;
}
return false;
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
tv.setLabelProvider(new TreeLabelProvider() {
});
tv.setInput(node);
tv.refresh();
tv.expandAll();
// make columns full size
for (int i = 0; i < tree.getColumnCount(); i++) {
tree.getColumn(i).pack();
}
final Composite parent = composite;
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
switch(e.keyCode) {
case SWT.F5:
// refresh SQL Results
try {
//$NON-NLS-1$
Object o = parent.getData("parenttab");
if (o != null) {
AbstractSQLExecution sqlExec = (AbstractSQLExecution) ((TabItem) o).getData();
if (sqlExec != null) {
sqlExec.startExecution();
}
}
} catch (Exception e1) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanExecution.logMessageError1"), e1);
}
break;
default:
return;
}
}
});
} catch (Exception e) {
// add message
String message = e.getMessage();
Label errorLabel = new Label(composite, SWT.FILL);
errorLabel.setText(message);
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanExecution.logMessageError2"), e);
}
composite.layout();
composite.redraw();
}
;
});
}
use of org.eclipse.swt.events.KeyAdapter in project tdi-studio-se by Talend.
the class OracleExplainPlanExecution method displayResults.
private void displayResults(final ExplainNode node) {
Display.getDefault().asyncExec(new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
clearCanvas();
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 2;
gLayout.marginLeft = 0;
gLayout.horizontalSpacing = 0;
gLayout.verticalSpacing = 0;
gLayout.marginWidth = 0;
gLayout.marginHeight = 0;
composite.setLayout(gLayout);
try {
//$NON-NLS-1$
composite.setData("parenttab", parentTab);
Composite pp = new Composite(composite, SWT.NULL);
pp.setLayout(new FillLayout());
pp.setLayoutData(new GridData(GridData.FILL_BOTH));
TreeViewer tv = new TreeViewer(pp, SWT.BORDER | SWT.FULL_SELECTION);
Tree tree = tv.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
TreeColumn tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText("");
tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText(Messages.getString("OracleExplainPlanExecution.tableColumnText1"));
tc = new TreeColumn(tree, SWT.NULL);
//$NON-NLS-1$
tc.setText(Messages.getString("OracleExplainPlanExecution.tableColumnText2"));
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(6, 150, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tree.setLayout(tableLayout);
tv.setContentProvider(new ITreeContentProvider() {
@Override
public void dispose() {
}
@Override
public Object[] getChildren(Object parentElement) {
return ((ExplainNode) parentElement).getChildren();
}
@Override
public Object[] getElements(Object inputElement) {
ExplainNode nd = ((ExplainNode) inputElement);
return nd.getChildren();
}
@Override
public Object getParent(Object element) {
return ((ExplainNode) element).getParent();
}
@Override
public boolean hasChildren(Object element) {
if (((ExplainNode) element).getChildren().length > 0) {
return true;
}
return false;
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
tv.setLabelProvider(new TreeLabelProvider() {
});
tv.setInput(node);
tv.refresh();
tv.expandAll();
// make columns full size
for (int i = 0; i < tree.getColumnCount(); i++) {
tree.getColumn(i).pack();
}
final Composite parent = composite;
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
switch(e.keyCode) {
case SWT.F5:
// refresh SQL Results
try {
//$NON-NLS-1$
Object o = parent.getData("parenttab");
if (o != null) {
AbstractSQLExecution sqlExec = (AbstractSQLExecution) ((TabItem) o).getData();
if (sqlExec != null) {
sqlExec.startExecution();
}
}
} catch (Exception e1) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanExecution.logMessage1"), e1);
}
break;
default:
return;
}
}
});
} catch (Exception e) {
// add message
String message = e.getMessage();
Label errorLabel = new Label(composite, SWT.FILL);
errorLabel.setText(message);
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanExecution.logMessage2"), e);
}
composite.layout();
composite.redraw();
}
;
});
}
use of org.eclipse.swt.events.KeyAdapter in project tdi-studio-se by Talend.
the class SchemaDetailsCheckBoxCellEditor method createControl.
@Override
protected Control createControl(Composite parent) {
checkBtn = new Button(parent, SWT.CHECK);
checkBtn.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.character == '') {
// Escape
fireCancelEditor();
}
}
});
checkBtn.addFocusListener(getButtonFocusListener());
checkBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
markDirty();
doSetValue(checkBtn.getSelection());
// fireApplyEditorValue();
}
});
setValueValid(true);
return checkBtn;
}
use of org.eclipse.swt.events.KeyAdapter in project tdi-studio-se by Talend.
the class JSONFileOutputStep3Form method addFieldsListeners.
@Override
protected void addFieldsListeners() {
metadataNameText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
MetadataToolHelper.validateSchema(metadataNameText.getText());
metadataTable.setLabel(metadataNameText.getText());
checkFieldsValue();
}
});
metadataNameText.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
MetadataToolHelper.checkSchema(getShell(), e);
}
});
metadataCommentText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
metadataTable.setComment(metadataCommentText.getText());
}
});
tableEditorView.getMetadataEditor().addAfterOperationListListener(new IListenableListListener() {
public void handleEvent(ListenableListEvent event) {
checkFieldsValue();
}
});
}
use of org.eclipse.swt.events.KeyAdapter 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