/** * {@inheritDoc} * * If the entered character is not a valid identifier part, it is processed after linked editing has been quit. * Exceptions are the {@link #exitCharacters} that have been passed into the constructor. */ @Override public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) { if (event.character == '\0') return null; for (char c : exitCharacters) { if (event.character == c) { return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } } switch (event.character) { case SWT.CR: return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); default: { if (!Character.isJavaIdentifierPart(event.character)) { return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true); } return null; } } }
private void attachKeyValidator(final Text text) { text.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent e) { txtDecorator.hide(); String currentText = ((Text) e.widget).getText(); String newName = (currentText.substring(0, e.start) + e.text + currentText.substring(e.end)); Matcher matchName = Pattern.compile("[\\@]{1}[\\{]{1}[\\w]*[\\}]{1}||[\\w]*").matcher(newName); if(!matchName.matches()){ text.setToolTipText(Messages.CHARACTERSET); txtDecorator=WidgetUtility.addDecorator(text,Messages.CHARACTERSET); txtDecorator.setDescriptionText(Messages.CHARACTERSET); txtDecorator.show(); e.doit=false; } else { text.setToolTipText(""); text.setMessage(""); txtDecorator.hide(); } } }); }
private void initializeViewer(IDocument document) { fAnnotationPreferences = EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); setDocument(document); installViewerConfiguration(); setEditable(true); Font font = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT); getTextWidget().setFont(font); getTextWidget().setData("document",document); Control control = getControl(); GridData data = new GridData(GridData.FILL_BOTH); control.setLayoutData(data); prependVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { handleVerifyKeyPressed(event); } }); addDocumentListener(document); }
public static void addVerifyListnerToOutputEditingSupport(JoinMappingEditingSupport outputEditingSupport) { ((Text)outputEditingSupport.getEditor().getControl()).addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent e) { String text=e.text; Matcher matcher=Pattern.compile(Constants.REGEX).matcher(text); if(matcher.matches()){ e.doit=true; }else{ e.doit=false; } } }); }
private void createJumpPageTextBox(Composite composite_3) { Text jumpPageTextBox = new Text(composite_3, SWT.BORDER); jumpPageTextBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); jumpPageTextBox.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent e) { String currentText = ((Text) e.widget).getText(); String pageNumberText = currentText.substring(0, e.start) + e.text + currentText.substring(e.end); try { long pageNumber = Long.valueOf(pageNumberText); if (pageNumber < 1) { e.doit = false; } } catch (NumberFormatException ex) { if (!pageNumberText.equals("")) e.doit = false; } } }); dataViewerListeners.attachJumpPageListener(jumpPageTextBox); windowControls.put(ControlConstants.JUMP_TEXT, jumpPageTextBox); }
private void validateForSingleAndDuplicateCharacter(VerifyEvent e, String textBoxValue, ControlDecoration singleCharactorDecorator, ControlDecoration duplicateDecorator, ControlDecoration emptyDecorator) { singleCharactorDecorator.hide(); duplicateDecorator.hide(); emptyDecorator.hide(); String value = ((Text) e.widget).getText(); String currentValue = (value.substring(0, e.start) + e.text + value.substring(e.end)); if (StringUtils.isNotEmpty(currentValue)) { validateDelimiterAndQuoteCharactorProperty(currentValue, textBoxValue, singleCharactorDecorator, duplicateDecorator); } else { getButton(0).setEnabled(false); emptyDecorator.show(); warningLabel.setText(Messages.WARNING_MESSAGE); warningLabel.setVisible(true); warningImageLabel.setVisible(true); } }
private void refreshThePaletteBasedOnSearchString(final PaletteRoot paletteRoot, final ELTGraphicalEditor editor, final Map<String, PaletteDrawer> categoryPaletteContainer, final Text text, final List<Component> componentsConfig, final Composite container) { text.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent e) { boolean matchFound = false; final List<Component> matchingComponents = new ArrayList<>(); paletteRoot.getChildren().clear(); String currentText = ((Text) e.widget).getText(); createPaletteContainers(paletteRoot, categoryPaletteContainer, editor); String searchedString = (currentText.substring(0, e.start) + e.text + currentText.substring(e.end)) .toUpperCase(); if (StringUtils.isEmpty(searchedString)) { showAllContainers(paletteRoot, editor, categoryPaletteContainer, componentsConfig); } else { showOpenPaletteContainers(paletteRoot.getChildren()); matchFound = checkSearchedComponentFoundInPalette(editor, categoryPaletteContainer, componentsConfig, matchingComponents, searchedString); showMessageWhenComponentNotFound(container, matchFound); showMatchingContainers(paletteRoot, categoryPaletteContainer, matchingComponents); } } }); }
/** * Constructor. Creates data structures and adds listener to note modifications. * * @param note */ public UndoRedoManager(final Note note) { undoDeque = new ArrayDeque<>(); redoDeque = new ArrayDeque<>(); this.note = note; // Listen to text modifications. note.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent event) { // Last modification was due to an undo/redo action: do not record it. if (lastActionUndoOrRedo) { lastActionUndoOrRedo = false; return; } recordNoteModification(event, note.getStyleRanges()); } }); }
/** * Records history for undo/redo functions. * * @param event * @param styles */ public void recordNoteModification(VerifyEvent event, StyleRange[] styles) { // Previous action cannot be an undo: empty redo deque and remove stylesBeforeUndo. redoDeque.clear(); stylesBeforeUndo = null; // Construct modification record depending on whether the function was called by a style or a text // modification and push it on the deque. if (event != null) { undoDeque.push(new ModificationRecord(styles, event.start, event.text.length(), note.getText().substring(event.start, event.end), event.text)); } else { undoDeque.push(new ModificationRecord(styles, 0, 0, null, null)); } // Limit maximum size of deque by clearing oldest records. if (undoDeque.size() > MAX_DEQUE_SIZES) { undoDeque.pollLast(); } }
private void createPackageField(Composite parent) { Label packageNameLabel = new Label(parent, SWT.LEAD); packageNameLabel.setText(Messages.getString("java.package")); //$NON-NLS-1$ javaPackageField = new Text(parent, SWT.BORDER); javaPackageField.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { revalidate(); } }); javaPackageField.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent event) { // if the user ever changes the package name field, then we never auto-generate again. if (!javaPackageProgrammaticUpdate) { autoGeneratePackageName = false; } } }); }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (fSize == fStack.size() && !isMasked(offset)) { if (event.character == fExitCharacter) { BracketLevel level= (BracketLevel) fStack.peek(); if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset) return null; if (level.fSecondPosition.offset == offset && length == 0) // don't enter the character if if its the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } // when entering an anonymous class between the parenthesis', we don't want // to jump after the closing parenthesis when return is pressed if (event.character == SWT.CR && offset > 0) { IDocument document= sourceViewer.getDocument(); try { if (document.getChar(offset - 1) == '{') return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } catch (BadLocationException e) { } } } return null; }
private void preventDelAndBackspace(VerifyEvent e) { // one char max between start and end boolean isSingleSelect = (e.end - e.start < 2); // (e.start == e.end); // prevent backspace on start of line int xIndex = getCurrentXIndex(); if (lastKeyCode == SWT.BS && xIndex == 0 && isSingleSelect && e.text.equals("")) { logger.debug("preventing bs"); e.doit = false; return; } // prevent del on end of line int lineLength = text.getLine(text.getLineAtOffset(text.getCaretOffset())).length(); if (lastKeyCode == SWT.DEL && xIndex == lineLength && isSingleSelect && e.text.equals("")) { logger.debug("preventing del"); e.doit = false; return; } }
@Override public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) { LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP)); if (position != null) { if (event.character == SWT.BS) { if (offset - 1 < position.getOffset()) { //skip backspace at beginning of linked position event.doit= false; } } else /* event.character == SWT.DEL */ { if (offset + 1 > position.getOffset() + position.getLength()) { //skip delete at end of linked position event.doit= false; } } } } return null; // don't change behavior }
private void handleVerifyKeyPressed(VerifyEvent event) { if (!event.doit) return; if (event.stateMask != SWT.MOD1) return; switch (event.character) { case ' ': fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); event.doit = false; break; // CTRL-Z case 'z' - 'a' + 1: fPatternEditor.doOperation(ITextOperationTarget.UNDO); event.doit = false; break; } }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (fSize == fStack.size() && !isMasked(offset)) { if (event.character == fExitCharacter) { BracketLevel level = (BracketLevel) fStack.peek(); if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset) return null; if (level.fSecondPosition.offset == offset && length == 0) // don't enter the character if if its the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } // when entering an anonymous class between the parenthesis', we // don't want // to jump after the closing parenthesis when return is pressed if (event.character == SWT.CR && offset > 0) { IDocument document = getSourceViewer().getDocument(); try { if (document.getChar(offset - 1) == '{') return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } catch (BadLocationException e) { } } } return null; }
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) { if (event.character == '\0') return null; for (char c: exitCharacters) { if (event.character == c) { return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } } switch (event.character) { case SWT.CR: return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); default: return null; } }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF); if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) { LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP)); if (position != null) { if (event.character == SWT.BS) { if (offset - 1 < position.getOffset()) { // skip backspace at beginning of linked position event.doit = false; } } else /* event.character == SWT.DEL */{ if (offset + 1 > position.getOffset() + position.getLength()) { // skip delete at end of linked position event.doit = false; } } } } return null; // don't change behavior }
private String getText(VerifyEvent e) { if (e.getSource() instanceof Text) { final String old = ((Text)e.getSource()).getText(); String current = old.substring(0, e.start) + e.text + old.substring(e.end); if (current.isEmpty()) { return current; } if (current.indexOf(".") == current.length()-1 || current.indexOf(",") == current.length()-1) { // allow one decimal separator at the end return current.substring(0, current.length()-1); } return current; } return e.text; }
@Override public void verifyText(VerifyEvent e) { try { final String str = text.getText(); final String pre = str.substring(0, e.start); final String app = str.substring(e.end, str.length()); final String res = pre + e.text + app; if (res.isEmpty()) { e.doit = true; return; } if (isDouble) Double.parseDouble(res); else Integer.parseInt(res); e.doit = true; } catch (NumberFormatException ex) { e.doit = false; } }
/*************************************************************************** * Control changes of host and port fields **************************************************************************/ public void verifyText(VerifyEvent e) { boolean ok = true; String id = (String) e.widget.getData("ID"); if (id.equals("PORT")) { if ((e.keyCode != SWT.BS) && (e.keyCode != SWT.DEL)) { try { Integer.parseInt(e.text); } catch (NumberFormatException ex) { ok = false; } } } e.doit = ok; }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (!isMasked(offset)) { if (event.character == fExit) return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); if (event.character == '\r' || event.character == '\n' && offset > 0) { try { if (fDocument.getChar(offset - 1) == '{') { return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } } catch (BadLocationException e) { } } } return null; }
/** * Verifies key events by notifying the registered listeners. Each listener is allowed to indicate that the * event has been handled and should not be further processed. * * @param e * the verify event * @see VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) */ public void verifyKey(VerifyEvent e) { IContentAssistListener[] listeners = fListeners.clone(); for (int i = 0; i < listeners.length; i++) { if (listeners[i] != null) { if (!listeners[i].verifyKey(e) || !e.doit) { break; } } } if (fAutoAssistListener != null) { fAutoAssistListener.keyPressed(e); } }
/** * @see org.eclipse.jface.text.IEventConsumer#processEvent(org.eclipse.swt.events.VerifyEvent) */ public void processEvent(VerifyEvent event) { installKeyListener(); IContentAssistListener[] listeners = fListeners.clone(); for (int i = 0; i < listeners.length; i++) { if (listeners[i] != null) { listeners[i].processEvent(event); if (!event.doit) { return; } } } }
/** * Allows quick return if we happen to be in a partition where we don't want auto-closed tags. Currently will only * auto-close when in HTML partitions. * * @param document * @param offset * @param event * @return */ protected boolean shouldAutoClose(IDocument document, int offset, VerifyEvent event) { // Only auto-close XML Tags ITypedRegion partition = document.getDocumentPartitioner().getPartition(offset - 1); if (partition != null) { if (!validPartition(partition)) { return false; } try { int length = Math.min(partition.getLength(), offset - partition.getOffset()); String tagContents = document.get(partition.getOffset(), length); return !inString(tagContents, length); } catch (BadLocationException e) { IdeLog.logError(XMLPlugin.getDefault(), e); } } return false; }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (shouldInsertNewline()) { if (event.character == '\n' || event.character == '\r') { return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } } if (event.character != fExitCharacter) return null; if (fSize == fStack.size() && !isEscaped(offset)) { BracketLevel level = fStack.peek(); if (offset < level.fFirstPosition.offset || level.fSecondPosition.offset < offset) return null; if (level.fSecondPosition.offset == offset && length == 0) // don't enter the character if it is the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } return null; }
public static VerifyListener verifyListenerInteger(final boolean canBeNegative) { return new VerifyListener() { @Override public void verifyText(final VerifyEvent e) { // check backspace and del key if (e.character == SWT.BS || e.character == SWT.DEL) { return; } // check '-' key if (canBeNegative && e.character == '-') { return; } try { Integer.parseInt(e.text); } catch (final NumberFormatException ex) { e.doit = false; } } }; }
public static VerifyListener verifyFilenameInput() { return new VerifyListener() { @Override public void verifyText(final VerifyEvent e) { // check invalid chars for (final char invalidChar : INVALID_FILENAME_CHARS) { if (invalidChar == e.character) { e.doit = false; return; } } } }; }
public static VerifyListener verifyFilePathInput() { return new VerifyListener() { @Override public void verifyText(final VerifyEvent e) { // check invalid chars for (final char invalidChar : INVALID_FILEPATH_CHARS) { if (invalidChar == e.character) { e.doit = false; return; } } } }; }
public static VerifyListener verifyListenerTypeLong() { return new VerifyListener() { @Override public void verifyText(final VerifyEvent e) { if (e.text.equals(EMPTY_STRING)) { return; } try { Long.parseLong(e.text); } catch (final NumberFormatException e1) { e.doit = false; } } }; }
public static VerifyListener verifyListenerInteger(final boolean canBeNegative) { return new VerifyListener() { public void verifyText(final VerifyEvent e) { // check backspace and del key if (e.character == SWT.BS || e.character == SWT.DEL) { return; } // check '-' key if (canBeNegative && e.character == '-') { return; } try { Integer.parseInt(e.text); } catch (final NumberFormatException ex) { e.doit = false; } } }; }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) { LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP)); if (position != null) { if (event.character == SWT.BS) { if (offset - 1 < position.getOffset()) { //skip backspace at beginning of linked position event.doit= false; } } else /* event.character == SWT.DEL */ { if (offset + 1 > position.getOffset() + position.getLength()) { //skip delete at end of linked position event.doit= false; } } } } return null; // don't change behavior }
/** * {@inheritDoc} */ @Override public void verifyText(VerifyEvent e) { switch (e.keyCode) { case SWT.BS: case SWT.DEL: case SWT.HOME: case SWT.END: case SWT.ARROW_LEFT: case SWT.ARROW_RIGHT: return; } if (!Character.isLetter(e.character)) { e.doit = false; } }
@Override public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (fSize == fStack.size() && !isMasked(offset)) { if (event.character == fExitCharacter) { BracketLevel level = fStack.peek(); if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset) return null; if (level.fSecondPosition.offset == offset && length == 0) // don't enter the character if if its the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } // when entering an anonymous class between the parenthesis', we don't want // to jump after the closing parenthesis when return is pressed if (event.character == SWT.CR && offset > 0) { IDocument document = getSourceViewer().getDocument(); try { if (document.getChar(offset - 1) == '{') return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } catch (BadLocationException e) {} } } return null; }
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { if (fSize == fStack.size() && !isMasked(offset)) { if (event.character == fExitCharacter) { BracketLevel level= fStack.peek(); if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset) return null; if (level.fSecondPosition.offset == offset && length == 0) // don't enter the character if if its the closing peer return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); } // when entering an anonymous class between the parenthesis', we don't want // to jump after the closing parenthesis when return is pressed if (event.character == SWT.CR && offset > 0) { IDocument document= getSourceViewer().getDocument(); try { if (document.getChar(offset - 1) == '{') return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); } catch (BadLocationException e) { } } } return null; }
public void verifyText(VerifyEvent event) { ParameterData parameter = (ParameterData)event.widget.getData(); String text = event.text; char [] chars = new char [text.length ()]; text.getChars(0, chars.length, chars, 0); String type = parameter.getType(); if (type.equals("int") || type.equals("java.lang.Integer") || type.equals("long") || type.equals("java.lang.Long")) { for (int i=0; i<chars.length; i++) { if (!('0' <= chars [i] && chars [i] <= '9')) { event.doit = false; return; } } } }
/** * @see com.mulgasoft.emacsplus.minibuffer.WithMinibuffer#noCharEvent(org.eclipse.swt.events.VerifyEvent) */ protected void noCharEvent(VerifyEvent event) { switch (event.keyCode) { // remove minimal support for in line editing case SWT.HOME: case SWT.END: case SWT.ARROW_LEFT: case SWT.ARROW_RIGHT: case SWT.PAGE_DOWN: case SWT.PAGE_UP: // Since we've disabled the key filter force the action by // disabling the key, and calling the command directly // since Mac doesn't handle simple resendEvent well event.doit = false; ITextEditor ed= this.getEditor(); leave(); executeBinding(ed, event.stateMask, event); break; default: super.noCharEvent(event); break; } }
/** * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) */ public void verifyKey(VerifyEvent event) { // ignore the stateMask keyCodes, otherwise require a match if (!isSpecial(event.keyCode)) { // A real (user) key event must have happened if (event.keyCode != keyCode || event.stateMask != stateMask) { event.doit = false; // short circuit and beep setInterrupted(true); Beeper.beep(); // this will notify } else { // detect kbd macro key event clearKeyEvent(); notifyLock(); PlatformUI.getWorkbench().getDisplay().post(upEvent(event)); } } }
/** * @see com.mulgasoft.emacsplus.minibuffer.KeyHandlerMinibuffer#charEvent(org.eclipse.swt.events.VerifyEvent) */ @Override protected void charEvent(VerifyEvent event) { event.doit = false; if (!hasTrigger()) { // accumulate multiple u-a invocations, or reset on delayed repeat if (isUniversalKey(event)) { processUniversal(); } else if (!restart && (Character.isDigit(event.character) && ((event.stateMask & SWT.MODIFIER_MASK)== 0 || event.stateMask == triggerMask))) { // if plain number // build up the number string setArgumentCount(1); addToCount(event.character); } else if (!restart && isMinus(event)) { resetToMinus(event.keyCode, event.stateMask); } else { // else building trigger sequence addToTrigger(event); } } else { // continue with trigger sequence addToTrigger(event); } updatePrefix(); }
protected void handleKey(VerifyEvent event) { try { if (!event.doit) return; if (event.character != 0) { // process typed character charEvent(event); } else { // some other key down noCharEvent(event); } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } finally { setLastKeyCode(event.keyCode); } }