Java Code Examples for org.eclipse.swt.custom.StyledText#insert()

The following examples show how to use org.eclipse.swt.custom.StyledText#insert() . 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: CompositeTabFolder.java    From ldparteditor with MIT License 6 votes vote down vote up
public void delete() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) {
        if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){
            return;
        }
        final StyledText ct = selection.getTextComposite();
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        final int x2 = ct.getSelection().x;
        if (ct.getSelection().y == x2) {
            ct.forceFocus();
            return;
        }
        ct.insert(""); //$NON-NLS-1$
        ct.setSelection(new Point(x, x));
        ct.forceFocus();
    }
}
 
Example 2
Source File: ExpressionBuilder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
protected void insertText( String text )
{
	StyledText textWidget = sourceViewer.getTextWidget( );
	if ( !textWidget.isEnabled( ) )
	{
		return;
	}
	int selectionStart = textWidget.getSelection( ).x;
	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );

	if ( text.endsWith( "()" ) ) //$NON-NLS-1$
	{
		textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move
	}
}
 
Example 3
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将指定文本添加到光标所在位置。 robert 2011-12-21
 * @param canonicalValue
 *            ;
 */
public void insertCanonicalValue(Object canonicalValue) {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}

	int offset = text.getCaretOffset();
	text.insert(canonicalValue.toString());
	text.setCaretOffset(offset + canonicalValue.toString().length());
}
 
Example 4
Source File: CellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void insertCanonicalValue(Object canonicalValue) {
	StyledText text = textViewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}

	int offset = text.getCaretOffset();
	text.insert(canonicalValue.toString());
	text.setCaretOffset(offset + canonicalValue.toString().length());
}
 
Example 5
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将指定文本添加到光标所在位置。 robert 2011-12-21
 * @param canonicalValue
 *            ;
 */
public void insertCanonicalValue(Object canonicalValue) {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}

	int offset = text.getCaretOffset();
	text.insert(canonicalValue.toString());
	text.setCaretOffset(offset + canonicalValue.toString().length());
}
 
Example 6
Source File: SQLDataSetEditorPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
private void insertText( String text )
{
	if ( text == null )
		return;

	StyledText textWidget = viewer.getTextWidget( );
	int selectionStart = textWidget.getSelection( ).x;
	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );
}
 
Example 7
Source File: ExpressionTreeSupport.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
protected void insertText( String text )
{
	StyledText textWidget = expressionViewer.getTextWidget( );
	if ( !textWidget.isEnabled( ) )
	{
		return;
	}
	int selectionStart = textWidget.getSelection( ).x;
	if ( text.equalsIgnoreCase( "x++" ) ) //$NON-NLS-1$
	{
		text = textWidget.getSelectionText( ) + "++";//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "x--" ) )//$NON-NLS-1$
	{
		text = textWidget.getSelectionText( ) + "--";//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "++x" ) )//$NON-NLS-1$
	{
		text = "++" + textWidget.getSelectionText( );//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "--x" ) )//$NON-NLS-1$
	{
		text = "--" + textWidget.getSelectionText( );//$NON-NLS-1$
	}

	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );

	if ( text.endsWith( "()" ) ) //$NON-NLS-1$
	{
		textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move
	}
}