use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class QueryRecordListComparator method addTextViewerListener.
/**
* Add SQL viewer listener
*
* @param text
*/
private void addTextViewerListener(final StyledText text) {
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
ServerInfo serverInfo = getServerInfo();
boolean isLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
boolean isNoAutoUpperCase = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
if (!isLowerCase && !isNoAutoUpperCase) {
autoReplaceKeyword();
}
}
// replace keyword to upper case automatically
public void autoReplaceKeyword() {
// FIXME extract tokenize code to utility
if (pendingCompletionsListener) {
return;
}
int pos = text.getCaretOffset() - 1;
if (pos <= 0) {
return;
}
String currentKey = text.getText(pos, pos);
if (currentKey == null || currentKey.length() <= 0) {
return;
}
char cur = currentKey.charAt(0);
if (cur != ' ' && cur != '(' && cur != '\t' && cur != '\n' && cur != '\r' && cur != ',') {
return;
}
pos--;
if (pos < 0) {
return;
}
int spos = pos - 20;
if (spos < 0) {
spos = 0;
}
String txt = text.getText(spos, pos);
spos = pos + 1;
for (int i = txt.length() - 1; i >= 0; i--) {
char c = txt.charAt(i);
if (c == ' ' || c == '\t' || c == '\n' || c == '(') {
break;
}
spos--;
}
int epos = pos;
if (spos < 0 || epos < 0 || spos > epos) {
return;
}
String currentKeyword = text.getText(spos, epos);
if (currentKeyword == null) {
return;
}
int len = currentKeyword.length();
for (int i = 0; i < QuerySyntax.KEYWORDS_AUTO_UPPER.length; i++) {
String keyword = QuerySyntax.KEYWORDS_AUTO_UPPER[i];
if (keyword.equalsIgnoreCase(currentKeyword)) {
pendingCompletionsListener = true;
text.replaceTextRange(spos, len, keyword.toUpperCase());
pendingCompletionsListener = false;
break;
}
}
}
});
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if ((event.stateMask & SWT.COMMAND) != 0) {
//for Mac
if ((event.stateMask & SWT.SHIFT) != 0) {
if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
runQuery();
return;
}
}
}
if (event.keyCode == SWT.F5 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'e') {
runQuery();
} else if (event.keyCode == SWT.F6 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'l') {
runQueryPlan();
} else if (event.keyCode == SWT.F3) {
if ((event.stateMask & SWT.SHIFT) == 0) {
TextEditorFindReplaceMediator.findNext();
} else {
TextEditorFindReplaceMediator.findPrevious();
}
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == ' ') {
contentAssistant.showPossibleCompletions();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'r') {
recentlyUsedSQLcontentAssistant.showPossibleCompletions();
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0) {
if (event.keyCode == 'z' || event.keyCode == 'Z') {
undoManager.undo();
} else if (event.keyCode == 'y' || event.keyCode == 'Y') {
undoManager.redo();
}
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) {
if (event.keyCode == 'f' || event.keyCode == 'F') {
try {
formatHandler.execute(null);
} catch (Exception ex) {
CommonUITool.openErrorBox(ex.getMessage());
}
}
} else if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == '/') {
try {
contentAssistHandler.execute(null);
} catch (Exception ex) {
CommonUITool.openErrorBox(ex.getMessage());
}
}
if (SQLContentAssistProcessor.isShowProposal(event.character)) {
contentAssistant.showPossibleCompletions();
useCompletions = true;
} else if ((event.character >= 'A' && event.character <= 'Z') || (event.character >= 'a' && event.character <= 'z')) {
if (useCompletions) {
contentAssistant.showPossibleCompletions();
}
useCompletions = false;
} else if (event.character == ' ' || event.character == '\t' || event.keyCode == SWT.KEYPAD_CR || event.keyCode == SWT.CR || event.keyCode == SWT.BS || (text.getText().trim().length() < 1)) {
useCompletions = true;
}
}
});
TextEditorFindReplaceMediator editorDialogMediator = new TextEditorFindReplaceMediator();
text.addFocusListener(editorDialogMediator);
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class MonitoringTaskTest method testConnectServer.
public void testConnectServer() {
MonitoringTask task = new MonitoringTask(new ServerInfo());
task.cancel();
task.connectServer("8.2.0", 1000);
task.cancel();
task.stopMonitor();
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class DatabaseInfoTest method testGetServerInfo.
/**
* Test method for
* {@link com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo#getServerInfo()}
* .
*/
public void testGetServerInfo() {
bean.setServerInfo(new ServerInfo());
assertEquals(bean.getServerInfo() != null, true);
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class LoginDatabaseTaskTest method testSetDbUser.
public void testSetDbUser() {
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerVersion("8.2.0");
LoginDatabaseTask task = new LoginDatabaseTask(serverInfo);
task.setDbUser("adf");
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class LoginDatabaseTaskTest method testSetDbPasswd.
public void testSetDbPasswd() {
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerVersion("8.2.0");
LoginDatabaseTask task = new LoginDatabaseTask(serverInfo);
task.setDbPassword("adf");
}
Aggregations