use of org.eclipse.swt.events.VerifyEvent in project translationstudio8 by heartsome.
the class SetSplitPointByWordNumDialog method createSegCmp.
/**
* 创建片段
* @param bean
*/
private void createSegCmp(SegPointBean bean) {
final Composite curSegCmp = new Composite(segParentCmp, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(curSegCmp);
GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(5).applyTo(curSegCmp);
// 第一列,一个label
Label segLbl = new Label(curSegCmp, SWT.NONE);
segLbl.setText(Messages.getString("SetSplitPointByWordNumDialog.segLbl"));
Label segIndexLbl = new Label(curSegCmp, SWT.LEFT);
segIndexLbl.setText("");
GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).hint(20, SWT.DEFAULT).applyTo(segIndexLbl);
final Text wordNumTxt = new Text(curSegCmp, SWT.BORDER);
GridDataFactory.swtDefaults().hint(60, SWT.DEFAULT).applyTo(wordNumTxt);
wordNumTxt.setText(bean.getWordNumber() + "");
wordNumTxt.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
String addText = e.text;
if (addText.length() > 0) {
e.doit = addText.matches("\\d+");
}
}
});
Button addBtn = new Button(curSegCmp, SWT.NONE);
addBtn.setImage(addImg);
Button deleteBtn = new Button(curSegCmp, SWT.NONE);
deleteBtn.setImage(deleteImg);
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int addedWordNum = 0;
for (Control control : segParentCmp.getChildren()) {
if (control instanceof Composite) {
Control childControl = ((Composite) control).getChildren()[2];
if (childControl instanceof Text) {
addedWordNum += Integer.parseInt(((Text) childControl).getText());
}
}
}
SegPointBean addBean = new SegPointBean((totalWordNum - addedWordNum) > 0 ? (totalWordNum - addedWordNum) : 0);
// 开始创建片断列表
createSegCmp(addBean);
wordNumberScroll.setMinSize(segParentCmp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
segParentCmp.layout();
wordNumberScroll.layout();
}
});
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.getSource() instanceof Button) {
Composite parentCmp = ((Button) e.getSource()).getParent();
parentCmp.dispose();
wordNumberScroll.setMinSize(segParentCmp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
segParentCmp.layout();
wordNumberScroll.layout();
refreshSegListArea();
}
}
});
refreshSegListArea();
}
use of org.eclipse.swt.events.VerifyEvent in project cubrid-manager by CUBRID.
the class SQLEditorComposite method addListener.
/**
* Add listener for text
*/
private void addListener() {
text.addModifyListener(new ModifyListener() {
IAction undoAction = ActionManager.getInstance().getAction(UndoAction.ID);
IAction redoAction = ActionManager.getInstance().getAction(RedoAction.ID);
public void modifyText(ModifyEvent event) {
setDirty(true);
if (!undoAction.isEnabled()) {
FocusAction.changeActionStatus(undoAction, text);
}
if (!redoAction.isEnabled()) {
FocusAction.changeActionStatus(redoAction, text);
}
ServerInfo serverInfo = queryEditor == null || queryEditor.getSelectedServer() == null ? null : queryEditor.getSelectedServer().getServerInfo();
boolean isLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
boolean isNoAutoUpperCase = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
if (!isLowerCase && !isNoAutoUpperCase) {
autoReplaceKeyword();
}
}
// FIXME extract method?
// replace keyword to upper case automatically
public void autoReplaceKeyword() {
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.addVerifyKeyListener(new VerifyKeyListener() {
public void verifyKey(VerifyEvent event) {
if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
event.doit = false;
return;
}
if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
event.doit = false;
return;
}
if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.stateMask & SWT.ALT) != 0) {
event.doit = false;
return;
}
if (event.keyCode == SWT.TAB) {
event.doit = false;
} else {
event.doit = true;
}
}
});
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) {
queryEditor.runQuery(false);
return;
}
}
}
if (event.keyCode == SWT.F5 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'e') {
queryEditor.runQuery(false);
} else if (event.keyCode == SWT.F6 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'l') {
queryEditor.runQuery(true);
} else if (event.keyCode == SWT.F7) {
queryEditor.getCombinedQueryComposite().showQueryHistory();
} else if (event.keyCode == SWT.F8) {
queryEditor.runMultiQuery();
} else if (event.keyCode == SWT.F1) {
ActionManager.getInstance().getAction(HelpDocumentAction.ID).run();
} else if (event.keyCode == SWT.F3) {
if ((event.stateMask & SWT.SHIFT) == 0) {
TextEditorFindReplaceMediator.findNext();
} else {
TextEditorFindReplaceMediator.findPrevious();
}
} else if (event.keyCode == SWT.F9) {
queryEditor.setTuningModeButton(!queryEditor.isTuningModeButton());
} else if (event.keyCode == SWT.F11) {
queryEditor.getCombinedQueryComposite().rotateQueryPlanDisplayMode();
} else if ((event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == SWT.ESC) {
int cursorOffset = text.getCaretOffset();
text.setSelectionRange(cursorOffset, 0);
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == ',') {
new QuickBuilderDialog(getShell(), SWT.NONE).open();
} 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.keyCode == 'd') {
deleteRow();
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && event.keyCode == SWT.ARROW_DOWN) {
duplicateRow();
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0 && event.keyCode == 't') {
//add sql tab
queryEditor.addEditorTab();
} else if (((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'f' || event.keyCode == 'F')) {
format();
} else if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == '/') {
contentAssist();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'o') {
// Open a SQL file...
ActionManager.getInstance().getAction(QueryOpenAction.ID).run();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 's') {
// Save SQL to a file...
try {
save();
} catch (IOException e) {
MessageDialog.openError(getShell(), Messages.error, Messages.errCanNotSaveASQLFile);
}
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0) {
if (event.keyCode == '/') {
inputComment(false, false);
} else if (event.keyCode == 'z') {
event.doit = false;
undo();
} else if (event.keyCode == 'y') {
redo();
} else if (event.keyCode == 'f' || event.keyCode == 'h') {
find();
} else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
// NOPMD
queryEditor.runQueryPlanInCursorLine();
} else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
queryEditor.runQueryInCursorLine();
} else if (event.keyCode == 'g') {
gotoLine();
}
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) {
if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
// NOPMD
queryEditor.runQuery(true);
} else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
queryEditor.runQuery(false);
} else if (event.keyCode == 'x') {
toUpperCase();
} else if (event.keyCode == 'y') {
toLowerCase();
}
} else if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode == SWT.TAB) {
indent();
} else if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
unindent();
}
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;
}
// ctrl + alt + 1 ~ 9 : change editor tab
if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
IWorkbenchPage page = LayoutUtil.getActivePage();
if (page != null) {
int index = event.keyCode - '1';
IEditorReference[] refs = page.getEditorReferences();
for (int i = 0, selected = 0; i < refs.length; i++) {
IEditorReference ref = refs[i];
if (QueryEditorPart.ID.equals(ref.getId())) {
if (index == selected) {
IEditorPart part = ref.getEditor(true);
page.activate(part);
}
selected++;
}
}
}
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
// ctrl + 1 ~ 9 : change middle tab
ITabSelection selector = queryEditor.getCombinedQueryComposite();
selector.select(event.keyCode - '1', -1);
} else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
// alt + 1 ~ 9 : change bottom tab
ITabSelection selector = queryEditor.getCombinedQueryComposite();
selector.select(-1, event.keyCode - '1');
}
}
});
text.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
* @param event an event containing information about the selection
*/
public void widgetSelected(SelectionEvent event) {
IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
copyAction.setEnabled(false);
IAction cutAction = ActionManager.getInstance().getAction(CutAction.ID);
cutAction.setEnabled(false);
IAction reformatColumnsAliasAction = ActionManager.getInstance().getAction(ReformatColumnsAliasAction.ID);
reformatColumnsAliasAction.setEnabled(false);
// show schema info view with a selected text
IAction showSchemaAction = ActionManager.getInstance().getAction(ShowSchemaAction.ID);
showSchemaAction.setEnabled(false);
if (event.getSource() instanceof StyledText) {
StyledText stext = (StyledText) event.getSource();
if (stext != null && stext.getSelectionText() != null && stext.getSelectionText().length() > 0) {
copyAction.setEnabled(true);
cutAction.setEnabled(true);
reformatColumnsAliasAction.setEnabled(true);
CubridDatabase db = queryEditor.getSelectedDatabase();
if (DatabaseNavigatorMenu.SELF_DATABASE_ID.equals(db.getId()) && ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
showSchemaAction.setEnabled(false);
} else {
showSchemaAction.setEnabled(true);
}
}
}
}
});
text.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(text);
}
});
TextEditorFindReplaceMediator editorDialogMediator = new TextEditorFindReplaceMediator();
text.addFocusListener(editorDialogMediator);
}
use of org.eclipse.swt.events.VerifyEvent in project cubrid-manager by CUBRID.
the class IndexTableItemEditor method init.
/**
*
* Initial the table column editor
*
*/
private void init() {
final TableEditor editor = new TableEditor(table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
if (columnEditorType == COLUMN_EDITOR_TYPE_CCOMBO) {
combo = new CCombo(table, SWT.NONE);
combo.setEditable(false);
combo.addListener(SWT.Selection, this);
combo.addListener(SWT.FocusOut, this);
combo.addListener(SWT.Traverse, this);
editor.setEditor(combo, item, column);
//$NON-NLS-1$
combo.add("ASC");
//$NON-NLS-1$
combo.add("DESC");
if (item.getText(column).equals("ASC")) {
//$NON-NLS-1$
combo.select(0);
} else {
combo.select(1);
}
combo.setFocus();
} else if (columnEditorType == COLUMN_EDITOR_TYPE_TEXT) {
text = new Text(table, SWT.MULTI | SWT.WRAP);
text.setTextLimit(10);
text.addListener(SWT.FocusOut, this);
text.addListener(SWT.Traverse, this);
editor.setEditor(text, item, column);
text.setText(item.getText(column));
text.selectAll();
text.setFocus();
text.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event) {
event.doit = false;
char ch = event.character;
if (Character.isDigit(ch)) {
event.doit = true;
}
if (ch == '\b' || ch == SWT.DEL) {
event.doit = true;
}
}
});
}
}
use of org.eclipse.swt.events.VerifyEvent in project dbeaver by serge-rider.
the class ExtendedDirectEditManager method initCellEditor.
/**
* @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
*/
@Override
protected void initCellEditor() {
Text text = (Text) getCellEditor().getControl();
//add the verifyListener to apply changes to the control size
verifyListener = new VerifyListener() {
/**
* Changes the size of the editor control to reflect the changed
* text
*/
@Override
public void verifyText(VerifyEvent event) {
Text text = (Text) getCellEditor().getControl();
String oldText = text.getText();
String leftText = oldText.substring(0, event.start);
String rightText = oldText.substring(event.end, oldText.length());
GC gc = new GC(text);
if (leftText == null)
leftText = "";
if (rightText == null)
rightText = "";
String s = leftText + event.text + rightText;
Point size = gc.textExtent(leftText + event.text + rightText);
gc.dispose();
if (size.x != 0)
size = text.computeSize(size.x, SWT.DEFAULT);
else {
//just make it square
size.x = size.y;
}
getCellEditor().getControl().setSize(size.x, size.y);
}
};
text.addVerifyListener(verifyListener);
//set the initial value of the
originalValue = this.label.getText();
getCellEditor().setValue(originalValue);
//calculate the font size of the underlying
IFigure figure = getEditPart().getFigure();
figureFont = figure.getFont();
FontData data = figureFont.getFontData()[0];
Dimension fontSize = new Dimension(0, data.getHeight());
//set the font to be used
this.label.translateToAbsolute(fontSize);
data.setHeight(fontSize.height);
figureFont = new Font(null, data);
//set the validator for the CellEditor
getCellEditor().setValidator(validator);
text.setFont(figureFont);
text.selectAll();
}
use of org.eclipse.swt.events.VerifyEvent in project cubrid-manager by CUBRID.
the class ShardGeneralInfoPanel method initial.
private void initial() {
masterShmIdText.addModifyListener(modifyListener);
masterShmIdText.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event) {
if ("".equals(event.text)) {
return;
}
if (ValidateUtil.isNumber(event.text)) {
event.doit = true;
} else {
event.doit = false;
}
}
});
adminLogFileText.addModifyListener(modifyListener);
}
Aggregations