Java Code Examples for org.eclipse.swt.SWT#DEL

The following examples show how to use org.eclipse.swt.SWT#DEL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedNamesAssistProposal.java    From typescript.java with MIT License 6 votes vote down vote up
@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
}
 
Example 2
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
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
}
 
Example 3
Source File: HorizontalSpinner.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Verify the entry and store the value in the field storedValue
 *
 * @param entry entry to check
 * @param keyCode code of the typed key
 * @return <code>true</code> if the entry if correct, <code>false</code>
 *         otherwise
 */
private boolean verifyEntryAndStoreValue(final String entry, final int keyCode) {
	final String work;
	if (keyCode == SWT.DEL) {
		work = StringUtil.removeCharAt(text.getText(), text.getCaretPosition());
	} else if (keyCode == SWT.BS && text.getCaretPosition() == 0) {
		work = StringUtil.removeCharAt(text.getText(), text.getCaretPosition() - 1);
	} else if (keyCode == 0) {
		work = entry;
	} else {
		work = StringUtil.insertString(text.getText(), entry, text.getCaretPosition());
	}

	try {
		final double d = Double.parseDouble(work.replace(decimalFormatSeparator, '.'));
		storedValue = (int) (d * Math.pow(10, getDigits()));
	} catch (final NumberFormatException nfe) {
		return false;
	}

	for (final SelectionListener s : selectionListeners) {
		s.widgetSelected(null);
	}

	return true;
}
 
Example 4
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @see org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse.swt.events.VerifyEvent)
 */
@Override
public void verifyText(VerifyEvent e) {

  boolean doit = true;

  // only let digits pass (and del, backspace)
  if (!(Character.isDigit(e.character) || e.character == SWT.DEL || e.character == SWT.BS)) {
    doit = false;
  }

  // check if inserted text is an integer
  if (!doit) {
    try {
      Integer.parseInt(e.text);
      doit = true;
    } catch (NumberFormatException ex) {
      doit = false;
    }
  }

  e.doit = doit;
  if (!e.doit) {
    Display.getCurrent().beep();
  }
}
 
Example 5
Source File: GraphicalViewerKeyHandler.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public boolean keyPressed( KeyEvent event )
{
	List selectedParts = viewer.getSelectedEditParts( );
	if ( selectedParts != null && selectedParts.size( ) > 0 )
	{
		Iterator editPartsIterator = selectedParts.iterator( );
		EditPart selectedEditPart = (EditPart) editPartsIterator.next( );
		if ( selectedEditPart instanceof JoinConditionEditPart )
		{
			if ( event.keyCode == SWT.DEL )
			{
				DeleteJoinCondition( (JoinConditionEditPart) selectedEditPart );
			}
		}
	}
	return super.keyPressed( event );
}
 
Example 6
Source File: ResolvablePropertiesDialog.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
 */
@Override
public void keyReleased(KeyEvent e) {
  if (e.widget == mTableViewer.getTable()) {
    if (e.character == SWT.DEL) {
      removePropertyItems();
    }
    if (e.character == ' ') {
      IStructuredSelection selection = (IStructuredSelection) mTableViewer.getSelection();

      ResolvableProperty prop = (ResolvableProperty) selection.getFirstElement();
      openPropertyItemEditor(prop);
    }
  }
}
 
Example 7
Source File: MapPreferencePage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleTableKeyPressEvent( KeyEvent e )
{
	if ( e.keyCode == SWT.DEL )
	{
		delete( );
	}
}
 
Example 8
Source File: FormPropertyDescriptor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleTableKeyPressEvent( KeyEvent e )
{
	if ( !( (IFormProvider) getDescriptorProvider( ) ).isEditable( ) )
		return;
	if ( e.keyCode == SWT.DEL )
	{
		int itemCount = table.getItemCount( );
		int pos = table.getSelectionIndex( );

		if ( pos < 0 ) // select nothing
		{
			return;
		}
		if ( selectIndex == itemCount - 1 )
		{
			selectIndex--;
		}
		try
		{
			( (IFormProvider) getDescriptorProvider( ) ).doDeleteItem( pos );
		}
		catch ( Exception e1 )
		{
			WidgetUtil.processError( table.getShell( ), e1 );
		}
	}
	else if ( e.character == '\r' ) // return is pressed
	{
		if ( style == FULL_FUNCTION || style == FULL_FUNCTION_HORIZONTAL )
		{
			edit( );
		}
	}
}
 
Example 9
Source File: EditActionProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a key pressed event by invoking the appropriate action.
 *
 * @param event
 *            The Key Event
 */
public void handleKeyPressed(final KeyEvent event) {
	if (event.character == SWT.DEL && event.stateMask == 0) {
		if (deleteAction.isEnabled()) {
			deleteAction.run();
		}

		// Swallow the event.
		event.doit = false;
	}
}
 
Example 10
Source File: ListDialogField.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles key events in the table viewer. Specifically when the delete key
 * is pressed.
 */
protected void handleKeyPressed(KeyEvent event) {
	if (event.character == SWT.DEL && event.stateMask == 0) {
		if (fRemoveButtonIndex != -1
				&& isButtonEnabled(fTable.getSelection(),
						fRemoveButtonIndex)) {
			managedButtonPressed(fRemoveButtonIndex);
		}
	}
}
 
Example 11
Source File: AbstractTreeNodePanel.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent event) {
    switch(event.keyCode) {
        case SWT.DEL: {
            AbstractTreeNodePanel.this.removeSelected();
            break;
        }
    };
}
 
Example 12
Source File: TreeListDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
* Handles key events in the table viewer. Specifically
* when the delete key is pressed.
*/
protected void handleKeyPressed(KeyEvent event) {
	if (event.character == SWT.DEL && event.stateMask == 0) {
		if (fRemoveButtonIndex != -1 && isButtonEnabled(fTree.getSelection(), fRemoveButtonIndex)) {
			managedButtonPressed(fRemoveButtonIndex);
			return;
		}
	}
	fTreeAdapter.keyPressed(this, event);
}
 
Example 13
Source File: IDEClassPathBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void libaryPageKeyPressed( TreeListDialogField field,
		KeyEvent event )
{
	if ( field == fLibrariesList )
	{
		if ( event.character == SWT.DEL && event.stateMask == 0 )
		{
			List selection = field.getSelectedElements( );
			if ( canRemove( selection ) )
			{
				removeEntry( );
			}
		}
	}
}
 
Example 14
Source File: VerifyKeyRecorder.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected KeyCommand toKeyCommand(VerifyEvent event) {
	switch(event.character) {
	case SWT.BS: return KeyCommand.BACKSPACE; 
	case SWT.DEL: return KeyCommand.DELETE;
	case SWT.CR: return KeyCommand.ENTER;
	default: return KeyCommand.OTHER;
	}
}
 
Example 15
Source File: AddRowOnEnterCellNavigationStrategy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ViewerCell findSelectedCell(final ColumnViewer viewer, final ViewerCell currentSelectedCell, final Event event) {
    setCancelEvent(false);
    if (currentSelectedCell != null) {
        switch (event.keyCode) {
            case SWT.CR:
                return addNewRow(currentSelectedCell, event);
            case SWT.DEL:
                return removeRow(currentSelectedCell);
            default:
                break;
        }
    }
    return super.findSelectedCell(viewer, currentSelectedCell, event);
}
 
Example 16
Source File: MaskFormatter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles a <code>VerifyEvent</code> sent when the text is about to be
 * modified. This method is the entry point of all operations of formatting.
 *
 * @see org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse.swt.events.VerifyEvent)
 */
public void verifyText(VerifyEvent e) {
	if (ignore) {
		return;
	}
	e.doit = false;
	if (e.keyCode == SWT.BS || e.keyCode == SWT.DEL) {
		// Clears
		clearText(e.start, (e.end > e.start) ? e.end - e.start : 1);
		updateText(editValue.toString(), e.start);
	} else {
		// Inserts
		int p;
		try {
			p = insertText(e.text, e.start);
			if (e.end - e.start > e.text.length()) {
				clearText(e.start + e.text.length(), e.end - e.start - e.text.length());
			}
		} catch (IllegalArgumentException iae) {
			beep();
			p = e.start;
		}

		// Computes new position of the cursor
		char c;
		while (p < editPattern.length()
				&& (c = editPattern.charAt(p)) != P_DIGIT
				&& c != P_ALPHANUM && c != P_UPPERCASE && c != P_LOWERCASE
				&& c != P_UHEXDIGIT && c != P_LHEXDIGIT) {
			p++;
		}

		updateText(editValue.toString(), p);
	}
}
 
Example 17
Source File: DateTimeFormatter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
  * Handles a <code>VerifyEvent</code> sent when the text is about to be modified.
  * This method is the entry point of all operations of formatting.
  *
  * @see org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse.swt.events.VerifyEvent)
  */
public void verifyText(VerifyEvent e) {
	if (ignore) {
		return;
	}
	e.doit = false;
	if (e.keyCode == SWT.BS || e.keyCode == SWT.DEL) {
		clear(e.start, e.end);
	} else {
		e.start = insert(e.text, e.start);
	}
	updateText(inputCache.toString(), e.start);
}
 
Example 18
Source File: LibrariesWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void libaryPageKeyPressed(TreeListDialogField<CPListElement> field, KeyEvent event) {
	if (field == fLibrariesList) {
		if (event.character == SWT.DEL && event.stateMask == 0) {
			List<?> selection= field.getSelectedElements();
			if (canRemove(selection)) {
				removeEntry();
			}
		}
	}
}
 
Example 19
Source File: InternalCompositeTable.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handle a keyPressed event on any row control.
 * 
 * @param sender
 *            The row that is sending the event
 * @param e
 *            the actual KeyEvent
 */
public void keyPressed(TableRow sender, KeyEvent e) {
	if (doMakeFocusedRowVisible()) return;
	
	if ((e.stateMask & SWT.CONTROL) != 0) {
		switch (e.keyCode) {
		case SWT.HOME:
               doFocusInitialRow();
			return;
		case SWT.END:
               doFocusLastRow();
			return;
		case SWT.INSERT:
               doInsertRow();
			return;
		case SWT.DEL:
               doDeleteRow();
			return;
		default:
			return;
		}
	}
	switch (e.keyCode) {
	case SWT.ARROW_UP:
           doRowUp();
		return;
	case SWT.ARROW_DOWN:
           doRowDown();
		return;
	case SWT.PAGE_UP:
           doPageUp();
		return;
	case SWT.PAGE_DOWN:
           doPageDown();
		return;
	}
}
 
Example 20
Source File: ListDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles key events in the table viewer. Specifically
 * when the delete key is pressed.
 */
protected void handleKeyPressed(KeyEvent event) {
	if (event.character == SWT.DEL && event.stateMask == 0) {
		if (fRemoveButtonIndex != -1 && isButtonEnabled(fTable.getSelection(), fRemoveButtonIndex)) {
			managedButtonPressed(fRemoveButtonIndex);
		}
	}
}