📄 hiddentextcelleditor.java
字号:
* This framework method performs validation and sets the error message * accordingly, and then reports a change via <code>fireEditorValueChanged</code>. * Subclasses should call this method at appropriate times. Subclasses * may extend or reimplement. * * @param e the SWT modify event */ protected void editOccured(ModifyEvent e) { String value = text.getText(); if (value == null) { value = "";//$NON-NLS-1$ } Object typedValue = value; boolean oldValidState = isValueValid(); boolean newValidState = isCorrect(typedValue); if (typedValue == null && newValidState) { Assert.isTrue(false, "Validator isn't limiting the cell editor's type range");//$NON-NLS-1$ } if (!newValidState) { // try to insert the current value into the error message. setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { value })); } valueChanged(oldValidState, newValidState); } /** * Since a text editor field is scrollable we don't * set a minimumSize. */ public LayoutData getLayoutData() { return new LayoutData(); } /** * Return the modify listener. */ private ModifyListener getModifyListener() { if (modifyListener == null) { modifyListener = new ModifyListener() { public void modifyText(ModifyEvent e) { editOccured(e); } }; } return modifyListener; } /** * Handles a default selection event from the text control by applying the editor * value and deactivating this cell editor. * * @param event the selection event * * @since 3.0 */ protected void handleDefaultSelection(SelectionEvent event) { // same with enter-key handling code in keyReleaseOccured(e); fireApplyEditorValue(); deactivate(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method returns <code>true</code> if * the current selection is not empty. */ public boolean isCopyEnabled() { if (text == null || text.isDisposed()) { return false; } return text.getSelectionCount() > 0; } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method returns <code>true</code> if * the current selection is not empty. */ public boolean isCutEnabled() { if (text == null || text.isDisposed()) { return false; } return text.getSelectionCount() > 0; } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method returns <code>true</code> * if there is a selection or if the caret is not positioned * at the end of the text. */ public boolean isDeleteEnabled() { if (text == null || text.isDisposed()) { return false; } return text.getSelectionCount() > 0 || text.getCaretPosition() < text.getCharCount(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method always returns <code>true</code>. */ public boolean isPasteEnabled() { if (text == null || text.isDisposed()) { return false; } return true; } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method always returns <code>true</code>. */ public boolean isSaveAllEnabled() { if (text == null || text.isDisposed()) { return false; } return true; } /** * Returns <code>true</code> if this cell editor is * able to perform the select all action. * <p> * This default implementation always returns * <code>false</code>. * </p> * <p> * Subclasses may override * </p> * @return <code>true</code> if select all is possible, * <code>false</code> otherwise */ public boolean isSelectAllEnabled() { if (text == null || text.isDisposed()) { return false; } return text.getCharCount() > 0; } /** * Processes a key release event that occurred in this cell editor. * <p> * The <code>TextCellEditor</code> implementation of this framework method * ignores when the RETURN key is pressed since this is handled in * <code>handleDefaultSelection</code>. * An exception is made for Ctrl+Enter for multi-line texts, since * a default selection event is not sent in this case. * </p> * * @param keyEvent the key event */ protected void keyReleaseOccured(KeyEvent keyEvent) { if (keyEvent.character == '\r') { // Return key // Enter is handled in handleDefaultSelection. // Do not apply the editor value in response to an Enter key event // since this can be received from the IME when the intent is -not- // to apply the value. // See bug 39074 [CellEditors] [DBCS] canna input mode fires bogus event from Text Control // // An exception is made for Ctrl+Enter for multi-line texts, since // a default selection event is not sent in this case. if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) { if ((keyEvent.stateMask & SWT.CTRL) != 0) { super.keyReleaseOccured(keyEvent); } } return; } super.keyReleaseOccured(keyEvent); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method copies the * current selection to the clipboard. */ public void performCopy() { text.copy(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method cuts the * current selection to the clipboard. */ public void performCut() { text.cut(); checkSelection(); checkDeleteable(); checkSelectable(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method deletes the * current selection or, if there is no selection, * the character next character from the current position. */ public void performDelete() { if (text.getSelectionCount() > 0) { // remove the contents of the current selection text.insert(""); //$NON-NLS-1$ } else { // remove the next character int pos = text.getCaretPosition(); if (pos < text.getCharCount()) { text.setSelection(pos, pos + 1); text.insert(""); //$NON-NLS-1$ } } checkSelection(); checkDeleteable(); checkSelectable(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method pastes the * the clipboard contents over the current selection. */ public void performPaste() { text.paste(); checkSelection(); checkDeleteable(); checkSelectable(); } /** * The <code>TextCellEditor</code> implementation of this * <code>CellEditor</code> method selects all of the * current text. */ public void performSelectAll() { text.selectAll(); checkSelection(); checkDeleteable(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -