use of org.eclipse.swt.events.KeyEvent in project cubrid-manager by CUBRID.
the class EditFunctionDialog method createFunctionSettingComposite.
/**
* Create the function setting composite
*
* @return the composite
*/
private Composite createFunctionSettingComposite() {
final Composite composite = new Composite(tabFolder, SWT.LEFT | SWT.WRAP);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layoutComp;
layoutComp = new GridLayout();
layoutComp.marginWidth = 10;
layoutComp.marginHeight = 10;
layoutComp.numColumns = 2;
composite.setLayout(layoutComp);
final Label functionNameLabel = new Label(composite, SWT.NONE);
functionNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
functionNameLabel.setText(Messages.lblFunctionName);
funcNameText = new Text(composite, SWT.BORDER);
funcNameText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH);
funcNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
funcNameText.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyPressed(KeyEvent event) {
}
public void keyReleased(KeyEvent event) {
String userName = funcNameText.getText();
if (userName == null || StringUtil.isEmpty(userName)) {
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
});
if (isCommentSupport) {
final Label commentLabel = new Label(composite, SWT.NONE);
commentLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
commentLabel.setText(Messages.lblFunctionDescription);
funcDescriptionText = new Text(composite, SWT.BORDER);
funcDescriptionText.setTextLimit(ValidateUtil.MAX_DB_OBJECT_COMMENT);
funcDescriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
final String[] userColumnNameArr = isCommentSupport ? new String[] { Messages.tblColFunctionParamName, Messages.tblColFunctionParamType, Messages.tblColFunctionJavaParamType, Messages.tblColFunctionModel, Messages.tblColFunctionMemo } : new String[] { Messages.tblColFunctionParamName, Messages.tblColFunctionParamType, Messages.tblColFunctionJavaParamType, Messages.tblColFunctionModel };
funcParamsTableViewer = CommonUITool.createCommonTableViewer(composite, null, userColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 6, 4, -1, 200));
funcParamsTable = funcParamsTableViewer.getTable();
funcParamsTableViewer.getTable().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
}
public void widgetSelected(SelectionEvent event) {
if (funcParamsTableViewer.getTable().getSelectionCount() > 0) {
getButton(BUTTON_EDIT_ID).setEnabled(true);
getButton(BUTTON_UP_ID).setEnabled(true);
getButton(BUTTON_DOWN_ID).setEnabled(true);
getButton(BUTTON_DROP_ID).setEnabled(true);
}
}
});
funcParamsTableViewer.setInput(funcParamsListData);
funcParamsTable.setLinesVisible(true);
funcParamsTable.setHeaderVisible(true);
funcParamsTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// setBtnEnableDisable();
}
});
barComp = new Composite(composite, SWT.NONE);
final GridData gdbarComp = new GridData(GridData.FILL_HORIZONTAL);
gdbarComp.horizontalSpan = 2;
barComp.setLayoutData(gdbarComp);
GridLayout layout = new GridLayout();
layout.marginWidth = 10;
layout.marginHeight = 10;
barComp.setLayout(layout);
Label returnSQLTypeLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
returnSQLTypeLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
returnSQLTypeLabel.setText(Messages.lblReturnSQLType);
returnTypeCombo = new Combo(composite, SWT.SINGLE);
returnTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
returnTypeCombo.setVisibleItemCount(10);
returnTypeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String name = returnTypeCombo.getText();
String level = sqlTypeMap.get(name.toUpperCase(Locale.getDefault()));
returnTypeCombo.setData(level);
if (sqlTypeMap.containsKey(name.toUpperCase(Locale.getDefault()))) {
setJavaTypeEnable(true);
} else {
setJavaTypeEnable(false);
}
if (level == null) {
return;
}
if ("4".equals(level)) {
javaTypeList.setEnabled(false);
javaTypeList.setSelection(-1);
javaTypeText.setEnabled(true);
javaTypeLabel2.setEnabled(true);
javaTypeLabel.setEnabled(false);
} else {
javaTypeList.setEnabled(true);
javaTypeText.setEnabled(false);
javaTypeLabel2.setEnabled(false);
javaTypeLabel.setEnabled(true);
List<String> list = javaTypeMap.get(level);
javaTypeList.removeAll();
if (list == null) {
return;
}
for (String tmp : list) {
javaTypeList.add(tmp);
}
javaTypeList.select(0);
}
setJavaTypeList();
}
});
returnTypeCombo.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
List<String> list = javaTypeMap.get("1");
javaTypeList.removeAll();
for (String tmp : list) {
javaTypeList.add(tmp);
}
}
public void widgetSelected(SelectionEvent event) {
String name = returnTypeCombo.getText();
String level = sqlTypeMap.get(name);
returnTypeCombo.setData(level);
if (("4").equals(level)) {
javaTypeList.setEnabled(false);
javaTypeList.setSelection(-1);
javaTypeText.setEnabled(true);
javaTypeLabel2.setEnabled(true);
javaTypeLabel.setEnabled(false);
} else {
javaTypeList.setEnabled(true);
javaTypeText.setEnabled(false);
javaTypeLabel2.setEnabled(false);
javaTypeLabel.setEnabled(true);
List<String> list = javaTypeMap.get(level);
javaTypeList.removeAll();
if (list == null) {
return;
}
for (String tmp : list) {
javaTypeList.add(tmp);
}
javaTypeList.select(0);
}
}
});
final Label javaNameLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
javaNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
javaNameLabel.setText(Messages.lblJavaFunctionName);
javaNameText = new Text(composite, SWT.BORDER);
GridData gdJavaNameText = new GridData(GridData.FILL_HORIZONTAL);
javaNameText.setLayoutData(gdJavaNameText);
javaTypeLabel2 = new Label(composite, SWT.LEFT | SWT.WRAP);
javaTypeLabel2.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
javaTypeLabel2.setText(Messages.lblSpecialJavaType);
javaTypeLabel2.setEnabled(false);
javaTypeText = new Text(composite, SWT.BORDER);
javaTypeText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
javaTypeText.setEnabled(false);
javaTypeLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
javaTypeLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
javaTypeLabel.setText(Messages.lblReturnJavaType);
javaTypeList = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gdJavaTypeList = new GridData(GridData.FILL_HORIZONTAL);
gdJavaTypeList.heightHint = 60;
javaTypeList.setLayoutData(gdJavaTypeList);
return composite;
}
use of org.eclipse.swt.events.KeyEvent 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);
}
use of org.eclipse.swt.events.KeyEvent in project cubrid-manager by CUBRID.
the class QueryExecuter method bindEvents.
private void bindEvents() {
selectableSupport.getTableCursor().addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
}
public void mouseDoubleClick(MouseEvent e) {
performEdit();
}
});
selectableSupport.getTableCursor().addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
performEdit();
}
}
});
selectableSupport.getTableCursor().addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyReleased(KeyEvent event) {
if (isEditMode() && event.keyCode == SWT.DEL) {
deleteRecord(tblResult, null);
} else if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.keyCode == 'c' || event.character == '')) {
// key press 'ctrl + c' is intercept by editor text so add
// here
copySelectedItems();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'a') {
selectableSupport.selectAll();
}
}
});
}
use of org.eclipse.swt.events.KeyEvent in project cubrid-manager by CUBRID.
the class MultiDBQueryComposite method initialize.
/**
* Create the SQL history composite
*/
public void initialize() {
Composite toolBarComposite = new Composite(this, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 10;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
toolBarComposite.setLayout(gridLayout);
toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
refreshToolItem.setText(Messages.lblItemRefreshMulti);
refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setToolTipText(Messages.refresh);
refreshToolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//refresh may set tree to group type or not
//so mark the select db then set it to checked after set input
// Object[] checkedObject = ctv.getCheckedElements();
setInput();
// for (Object o : checkedObject) {
// if (o instanceof CubridDatabase) {
// ctv.setChecked(o, true);
// }
// }
// refresh(editor.getSelectedDatabase());
}
});
runItem = new ToolItem(toolBar, SWT.PUSH);
runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
runItem.setText(Messages.lblItemRunMulti);
runItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
editor.runMultiQuery();
}
});
Label lblNotice = new Label(toolBarComposite, SWT.None);
lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
// create the query result tab folder
multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
multiDBQueryCompTabFolder.setSimple(false);
multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
//TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
//tabContextMenuManager.createContextMenu();
multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
multiDBQueryCompTabItem.setControl(this);
multiDBQueryCompTabItem.setShowClose(false);
SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
bottomSash.SASH_WIDTH = SASH_WIDTH;
bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
tailSash.SASH_WIDTH = SASH_WIDTH;
tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
Composite treeComp = new Composite(tailSash, SWT.NONE);
{
treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
treeComp.setLayout(new GridLayout());
}
ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
ctv.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
ctv.setChecked(event.getElement(), true);
return;
}
ctv.setChecked(event.getElement(), false);
lastSelectedTime = System.currentTimeMillis() + 100;
if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
editor.setMultiQueryRunItemStatus(true);
} else if (getQueryDatabaseList().size() == 0) {
editor.setMultiQueryRunItemStatus(false);
}
//if (!event.getChecked()) {
selectedNodes.remove(event.getElement());
if (event.getElement() instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) event.getElement();
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(event.getElement(), false);
selectedNodes.remove(database);
} else {
if (database.getData(INDEXKEY) == null) {
database.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
}
} else if (event.getElement() instanceof CubridServer) {
CubridServer serverNode = (CubridServer) event.getElement();
for (ICubridNode dbFolderNode : serverNode.getChildren()) {
for (ICubridNode dbNode : dbFolderNode.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(dbNode, false);
selectedNodes.remove(database);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, true);
}
}
}
//only has one db folder so first time break it
break;
}
} else if (event.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) event.getElement();
if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
for (ICubridNode dbNode : node.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
ctv.setChecked(dbNode, false);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, false);
}
}
}
}
// else if (node.getType().equals(NodeType.GROUP)) {
// for (ICubridNode childNode : node.getChildren()) {
// //CQB tree
// if(childNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) childNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// if (childNode.getData(INDEXKEY) == null) {
// childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// }
// continue;
// }
// //CM tree
// for (ICubridNode dbFolderNode : childNode.getChildren()) {
// for (ICubridNode dbNode : dbFolderNode.getChildren()) {
// if(dbNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) dbNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// ctv.setChecked(dbNode, false);
// } else if (ctv.getChecked(dbNode)) {
// ctv.setChecked(dbNode, true);
// if (dbNode.getData(INDEXKEY) == null) {
// dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// } else {
// ctv.setChecked(dbNode, false);
// }
// }
// }
// }
// //only has one db folder so first time break it
// break;
// }
// }
}
ctv.refresh();
}
});
ctv.getTree().addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
//mac can't drag and drop,so support copy and paste db node
if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
String plainText = (String) cb.getContents(TextTransfer.getInstance());
String[] databaseNameArray = plainText.split(",");
selectedNodes.addAll(getDatabaseNode(databaseNameArray));
setInput();
}
}
});
// ctv.addDoubleClickListener(LayoutManager.getInstance());
// ctv.addTreeListener(new ITreeViewerListener() {
// public void treeCollapsed(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
//
// public void treeExpanded(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
// });
final Tree tableTree = ctv.getTree();
tableTree.setHeaderVisible(true);
tableTree.setLinesVisible(true);
final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
dbCol.getColumn().setWidth(250);
dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
indexCol.getColumn().setWidth(50);
indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
indexCol.setEditingSupport(new EditingSupport(ctv) {
TextCellEditor textCellEditor;
protected boolean canEdit(Object element) {
if (element instanceof ICubridNode) {
ICubridNode node = (ICubridNode) element;
if (node.getType() == NodeType.DATABASE) {
CubridDatabase database = (CubridDatabase) element;
if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
return true;
}
}
}
return false;
}
protected CellEditor getCellEditor(Object element) {
if (textCellEditor == null) {
textCellEditor = new TextCellEditor(ctv.getTree());
textCellEditor.setValidator(new IndexCellEditorValidator());
textCellEditor.addListener(new ICellEditorListener() {
public void applyEditorValue() {
}
public void cancelEditor() {
}
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
}
});
}
return textCellEditor;
}
protected Object getValue(Object element) {
final ICubridNode node = (ICubridNode) element;
String index = (String) node.getData(INDEXKEY);
if (index == null) {
return "";
} else {
return index;
}
}
protected void setValue(Object element, Object value) {
if (value == null) {
return;
}
try {
Integer.valueOf((String) value);
} catch (Exception e) {
return;
}
final ICubridNode node = (ICubridNode) element;
node.setData(INDEXKEY, value);
// setAllParentExpandOrCollapse(node.getParent(), true);
ctv.refresh();
}
/**
* MyCellEditorValidator
*
* @author fulei
*
*/
class IndexCellEditorValidator implements ICellEditorValidator {
/**
* isValid
*
* @param value Object
* @return String
*/
public String isValid(Object value) {
try {
Integer.valueOf((String) value);
} catch (Exception e) {
CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
return Messages.qedit_multiDBQueryComp_tree_indexErr;
}
return null;
}
}
});
final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
commentCol.getColumn().setWidth(200);
commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
tabItem.setControl(bottomSash);
tabItem.setShowClose(false);
setInput();
// HostNodePersistManager.getInstance().getAllServer();
multiDBQueryCompTabFolder.setSelection(tabItem);
dragController = new MultiDBQueryDNDController(this, ctv);
dragController.registerDropTarget();
}
use of org.eclipse.swt.events.KeyEvent in project cubrid-manager by CUBRID.
the class QuickBuilderDialog method createContents.
protected void createContents() {
sqlComp = CommonUITool.getActiveSQLEditorComposite();
if (sqlComp == null) {
closeThisDialog();
return;
}
CubridDatabase cubridDatabase = sqlComp.getQueryEditorPart().getSelectedDatabase();
if (CubridDatabase.hasValidDatabaseInfo(cubridDatabase)) {
databaseInfo = cubridDatabase.getDatabaseInfo();
}
boolean loadedProposal = true;
proposal = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
if (proposal == null) {
proposal = new ColumnProposal();
if (databaseInfo != null) {
startTimerForUpdateProposal();
}
loadedProposal = false;
}
isSupportLimit = CompatibleUtil.isSupportLimit(cubridDatabase.getDatabaseInfo());
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
{
GridLayout gl = new GridLayout();
gl.numColumns = 1;
shell.setLayout(gl);
}
shell.setSize(450, 300);
shell.setText(Messages.quickQueryBuilderTitle);
final Composite composite = new Composite(shell, SWT.NONE);
{
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gd);
GridLayout gl = new GridLayout();
composite.setLayout(gl);
}
final Label findWhatLabel = new Label(composite, SWT.NONE);
findWhatLabel.setText(Messages.quickQueryBuilderLabel);
inputText = new Text(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
inputText.setLayoutData(gd);
}
inputText.setEditable(true);
inputText.addKeyListener(inputTextKeyListener);
searchView = new TableViewer(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
searchView.getTable().setLayoutData(gd);
}
searchView.setContentProvider(searchViewContentProvider);
searchView.setLabelProvider(searchViewLabelProvider);
searchView.setInput(proposal);
searchView.getTable().addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR) {
makeQueryAndClose(0);
}
}
});
TableColumn col1 = new TableColumn(searchView.getTable(), SWT.NONE);
col1.setWidth(200);
TableColumn col2 = new TableColumn(searchView.getTable(), SWT.NONE);
col2.setWidth(200);
if (!loadedProposal) {
updateNoticeBanner = new Label(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
updateNoticeBanner.setLayoutData(gd);
}
updateNoticeBanner.setText(Messages.quickQueryBuilderLoading);
updateNoticeBanner.setBackground(ResourceManager.getColor(255, 255, 255));
}
Composite bottomPanel = new Composite(composite, SWT.NONE);
{
GridLayout gl = new GridLayout();
gl.numColumns = 4;
bottomPanel.setLayout(gl);
GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
bottomPanel.setLayoutData(gd);
}
createButtons(bottomPanel);
}
Aggregations