Java Code Examples for org.eclipse.swt.widgets.Text#setFocus()

The following examples show how to use org.eclipse.swt.widgets.Text#setFocus() . 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: ModelPropertiesDialog.java    From erflute with Apache License 2.0 7 votes vote down vote up
private void edit(final TableItem item, final TableEditor tableEditor) {
    final Text text = new Text(table, SWT.NONE);
    text.setText(item.getText(targetColumn));

    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            item.setText(targetColumn, text.getText());
            text.dispose();
        }
    });

    tableEditor.setEditor(text, item, targetColumn);
    text.setFocus();
    text.selectAll();
}
 
Example 2
Source File: ModelPropertiesDialog.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private void edit(final TableItem item, final TableEditor tableEditor) {
	final Text text = new Text(table, SWT.NONE);
	text.setText(item.getText(targetColumn));

	text.addFocusListener(new FocusAdapter() {

		@Override
		public void focusLost(FocusEvent e) {
			item.setText(targetColumn, text.getText());
			text.dispose();
		}

	});

	tableEditor.setEditor(text, item, targetColumn);
	text.setFocus();
	text.selectAll();
}
 
Example 3
Source File: ModelPropertiesDialog.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private void edit(final TableItem item, final TableEditor tableEditor) {
    final Text text = new Text(table, SWT.NONE);
    text.setText(item.getText(targetColumn));

    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent e) {
            item.setText(targetColumn, text.getText());
            text.dispose();
        }

    });

    tableEditor.setEditor(text, item, targetColumn);
    text.setFocus();
    text.selectAll();
}
 
Example 4
Source File: IntroduceParameterObjectWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createClassNameInput(Composite result) {
	Label label= new Label(result, SWT.LEAD);
	label.setText(RefactoringMessages.IntroduceParameterObjectWizard_classnamefield_label);
	final Text text= new Text(result, SWT.SINGLE | SWT.BORDER);
	text.setText(fProcessor.getClassName());
	text.selectAll();
	text.setFocus();
	text.addModifyListener(new ModifyListener() {

		public void modifyText(ModifyEvent e) {
			fProcessor.setClassName(text.getText());
			updateSignaturePreview();
			validateRefactoring();
		}

	});
	text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
 
Example 5
Source File: ExtractClassWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createClassNameInput(Composite result) {
	Label label= new Label(result, SWT.LEAD);
	label.setText(RefactoringMessages.ExtractClassWizard_label_class_name);
	final Text text= new Text(result, SWT.SINGLE | SWT.BORDER);
	fClassNameDecoration= new ControlDecoration(text, SWT.TOP | SWT.LEAD);
	text.setText(fDescriptor.getClassName());
	text.selectAll();
	text.setFocus();
	text.addModifyListener(new ModifyListener() {

		public void modifyText(ModifyEvent e) {
			fDescriptor.setClassName(text.getText());
			validateRefactoring();
		}

	});
	GridData gridData= new GridData(GridData.FILL_HORIZONTAL);
	gridData.horizontalIndent= FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
	text.setLayoutData(gridData);
}
 
Example 6
Source File: CopyTraceDialog.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void createNewTraceNameGroup(Composite parent) {
    Font font = parent.getFont();
    Composite folderGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    folderGroup.setLayout(layout);
    folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    String name = fTrace.getName();

    // New trace name label
    Label newTraceLabel = new Label(folderGroup, SWT.NONE);
    newTraceLabel.setFont(font);
    newTraceLabel.setText(Messages.CopyTraceDialog_TraceNewName);

    // New trace name entry field
    fNewTraceName = new Text(folderGroup, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    fNewTraceName.setLayoutData(data);
    fNewTraceName.setFont(font);
    fNewTraceName.setFocus();
    fNewTraceName.setText(name);
    fNewTraceName.setSelection(0, name.length());
    fNewTraceName.addListener(SWT.Modify, event -> validateNewTraceName());
}
 
Example 7
Source File: ConvertAnonymousToNestedWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void createControl(Composite parent) {
	Composite result= new Composite(parent, SWT.NONE);
	setControl(result);
	GridLayout layout= new GridLayout();
	layout.numColumns= 2;
	layout.verticalSpacing= 8;
	result.setLayout(layout);

	initializeDefaultSettings();
	addVisibilityControl(result);
	Text textField= addFieldNameField(result);
	addDeclareFinalCheckbox(result);
	addDeclareAsStaticCheckbox(result);

	textField.setFocus();
	setPageComplete(false);
	Dialog.applyDialogFont(result);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_WIZARD_PAGE);
}
 
Example 8
Source File: RnDialogs.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent){
	Composite ret = new Composite(parent, SWT.NONE);
	ret.setLayout(new GridLayout());
	ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_date); //$NON-NLS-1$
	dp = new DatePickerCombo(ret, SWT.NONE);
	dp.setDate(new Date());
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_amount); //$NON-NLS-1$
	// nf=NumberFormat.getCurrencyInstance();
	amount = new Text(ret, SWT.BORDER);
	// amount.setText(rn.getOffenerBetrag().getAmountAsString());
	amount.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_remark); //$NON-NLS-1$
	bemerkung = new Text(ret, SWT.MULTI | SWT.BORDER);
	bemerkung.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	amount.setFocus();
	return ret;
}
 
Example 9
Source File: Reporter.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {

	Composite area = (Composite) super.createDialogArea(parent);
	Composite container = new Composite(area, SWT.NONE);
	container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	GridLayout layout = new GridLayout(1, false);
	container.setLayout(layout);

	txtTitle = new Text(container, SWT.BORDER);
	txtTitle.setMessage("Please enter issue title...");
	txtTitle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	txtIssue = new Text(container, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
	txtIssue.setMessage("Please enter issue description...");
	txtIssue.setFocus();
	txtIssue.setLayoutData(new GridData(GridData.FILL_BOTH));

	Composite container2 = new Composite(container, SWT.NONE);
	GridLayout layout2 = new GridLayout(2, false);
	container2.setLayout(layout2);

	Label lbtInfo = new Label(container2, SWT.NONE);
	lbtInfo.setText("Additonaly, to the issue description CogniCrypt will send:");
	GridData dataGrid = new GridData();
	dataGrid.grabExcessHorizontalSpace = true;
	dataGrid.horizontalAlignment = GridData.FILL;

	combo = new Combo(container2, SWT.DROP_DOWN | SWT.READ_ONLY);
	String[] items = new String[] {fileName, "Method", "None"};
	combo.setItems(items);
	combo.setLayoutData(dataGrid);
	combo.select(1);

	return area;
}
 
Example 10
Source File: AbstractPythonWizardPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void setFocusOn(Text txt, String string) {
    if (txt != null) {
        //System.out.println("seting focus on:"+string);
        txt.setFocus();
        lastWithFocus = txt;
        lastWithFocusStr = string;
    }
}
 
Example 11
Source File: TrimTraceDialog.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void createNewTraceNameGroup(Composite parent) {
    setStatusLineAboveButtons(true);
    Font font = parent.getFont();
    Composite folderGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    folderGroup.setLayout(layout);
    folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    String name = fElement.getName();

    // New trace name label
    Label newTaceLabel = new Label(folderGroup, SWT.NONE);
    newTaceLabel.setFont(font);
    newTaceLabel.setText(Messages.RenameTraceDialog_TraceNewName);

    // New trace name entry field

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    Text newElementName = new Text(folderGroup, SWT.BORDER);
    newElementName.setLayoutData(data);
    newElementName.setFont(font);
    newElementName.setFocus();
    newElementName.setText(name);
    newElementName.setSelection(0, name.length());
    newElementName.addListener(SWT.Modify, event -> validateNewTraceName());
    fNewElementName = newElementName;
    validateNewTraceName();
}
 
Example 12
Source File: RenameExperimentDialog.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void createNewExperimentNameGroup(Composite parent) {
    Font font = parent.getFont();
    Composite folderGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    folderGroup.setLayout(layout);
    folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    String name = fExperiment.getName();

    // New experiment name label
    Label newExperimentLabel = new Label(folderGroup, SWT.NONE);
    newExperimentLabel.setFont(font);
    newExperimentLabel.setText(Messages.RenameExperimentDialog_ExperimentNewName);

    // New experiment name entry field
    fNewExperimentName = new Text(folderGroup, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    fNewExperimentName.setLayoutData(data);
    fNewExperimentName.setFont(font);
    fNewExperimentName.setFocus();
    fNewExperimentName.setText(name);
    fNewExperimentName.setSelection(0, name.length());

    fNewExperimentName.addListener(SWT.Modify, event -> validateNewExperimentName());
}
 
Example 13
Source File: RnDialogs.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent){
	Composite ret = new Composite(parent, SWT.NONE);
	ret.setLayout(new GridLayout());
	ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_date); //$NON-NLS-1$
	dp = new DatePickerCombo(ret, SWT.NONE);
	dp.setDate(new Date());
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_amount); //$NON-NLS-1$
	// nf=NumberFormat.getCurrencyInstance();
	amount = new Text(ret, SWT.BORDER);
	// amount.setText(rn.getOffenerBetrag().getAmountAsString());
	amount.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_remark); //$NON-NLS-1$
	bemerkung = new Text(ret, SWT.MULTI | SWT.BORDER);
	bemerkung.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	amount.setFocus();
	
	tableViewer = new TableViewer(ret, SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
	GridData gd_Table = new GridData();
	gd_Table.grabExcessHorizontalSpace = true;
	gd_Table.horizontalSpan = 1;
	gd_Table.minimumHeight = 100;
	gd_Table.heightHint = 100;
	tableViewer.getTable().setLayoutData(gd_Table);
	tableViewer.getTable().setHeaderVisible(true);
	tableViewer.getTable().setLinesVisible(false);
	tableViewer.setContentProvider(new ArrayContentProvider());
	TableViewerColumn colRnNumber = new TableViewerColumn(tableViewer, SWT.NONE);
	colRnNumber.getColumn().setWidth(200);
	colRnNumber.getColumn().setText(Messages.RnDialogs_invoiceNumber);
	colRnNumber.setLabelProvider(new ColumnLabelProvider());
	
	tableViewer.setInput(rnNumbers);
	
	return ret;
}
 
Example 14
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void buildLoginText() {
	final Text text = new Text(shell, SWT.BORDER);
	text.setText(login == null ? "" : login);
	text.setLayoutData(new GridData(GridData.FILL, GridData.END, true, false, 3, 1));
	text.setFocus();
	text.addListener(SWT.Modify, e -> {
		login = text.getText();
		changeButtonOkState();
	});
}
 
Example 15
Source File: RnDialogs.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent){
	Composite ret = new Composite(parent, SWT.NONE);
	ret.setLayout(new GridLayout());
	ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_date); //$NON-NLS-1$
	dp = new DatePickerCombo(ret, SWT.NONE);
	dp.setDate(new Date());
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_amount); //$NON-NLS-1$
	// nf=NumberFormat.getCurrencyInstance();
	amount = new Text(ret, SWT.BORDER);
	// amount.setText(rn.getOffenerBetrag().getAmountAsString());
	amount.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	new Label(ret, SWT.NONE).setText(Messages.RnDialogs_remark); //$NON-NLS-1$
	bemerkung = new Text(ret, SWT.MULTI | SWT.BORDER);
	bemerkung.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	amount.setText(rn.getOffenerBetrag().getAmountAsString());
	amount.setFocus();
	new Label(ret, SWT.NONE).setText("Konto"); //$NON-NLS-1$
	viewer = new ComboViewer(ret, SWT.BORDER);
	viewer.setContentProvider(ArrayContentProvider.getInstance());
	viewer.setLabelProvider(new LabelProvider() {
		@Override
		public String getText(Object element){
			if (element instanceof Account) {
				return ((Account) element).getNumeric() + " - " + ((Account) element).getName();
			}
			return super.getText(element);
		}
	});
	List<Account> accounts = new ArrayList<>();
	accounts.addAll(Account.getAccounts().values());
	accounts.sort(new Comparator<Account>() {
		@Override
		public int compare(Account left, Account right){
			return Integer.valueOf(left.getNumeric())
				.compareTo(Integer.valueOf(right.getNumeric()));
		}
	});
	viewer.setInput(accounts);
	viewer.getCombo().setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	return ret;
}
 
Example 16
Source File: PyUnitPrefsPage2.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e) {
    String comboValue = comboField.getComboValue();
    int val = 0;
    try {
        val = Integer.parseInt(comboValue);
    } catch (NumberFormatException e1) {
        Log.log(e1);
    }

    int testRunner = val;
    String tag;
    boolean addEquals = true;
    boolean addSpace = false;
    if (testRunner == TEST_RUNNER_PYDEV) {
        tag = "--" + fTag;

    } else if (testRunner == TEST_RUNNER_PY_TEST) {
        if ("n".equals(fTag)) {
            tag = "-" + fTag;
            addEquals = false;
            addSpace = true;
        } else if ("showlocals".equals(fTag) || "runxfail".equals(fTag)) {
            tag = "--" + fTag;
            addEquals = false;
        } else {
            //durations, maxfail, tb
            tag = "--" + fTag;
        }

    } else {
        tag = fTag;
    }

    Text textControl = parametersField.getTextControl();
    String currentText = textControl.getText();
    StringTokenizer stringTokenizer = new StringTokenizer(currentText);
    FastStringBuffer buf = new FastStringBuffer(currentText.length() * 2);

    boolean found = false;
    while (stringTokenizer.hasMoreTokens()) {
        String tok = stringTokenizer.nextToken();
        if (tok.startsWith(tag)) {
            found = true;
        }
        buf.append(tok);
        buf.append('\n');
    }
    if (!found) {
        buf.append(tag);
        if (addEquals) {
            buf.append('=');
        }
        if (addSpace) {
            buf.append(' ');
        }
    } else {
        buf.deleteLast(); //remove the last '\n'
    }
    textControl.setText(buf.toString());
    textControl.setSelection(textControl.getSize());
    textControl.setFocus();
}
 
Example 17
Source File: ExtendedPropertyEditorComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void widgetSelected( SelectionEvent e )
{
	if ( e.getSource( ).equals( btnAdd ) )
	{
		String sKey = txtNewKey.getText( );
		if ( sKey.length( ) > 0 && !propMap.containsKey( sKey ) )
		{
			String[] sProperty = new String[2];
			sProperty[0] = sKey;
			sProperty[1] = ""; //$NON-NLS-1$

			TableItem tiProp = new TableItem( table, SWT.NONE );
			tiProp.setText( sProperty );
			table.select( table.getItemCount( ) - 1 );

			updateModel( sProperty[0], sProperty[1] );
			txtNewKey.setText( "" ); //$NON-NLS-1$
		}
	}
	else if ( e.getSource( ).equals( btnRemove ) )
	{
		if ( table.getSelection( ).length != 0 )
		{
			int index = table.getSelectionIndex( );
			String key = table.getSelection( )[0].getText( 0 );
			ExtendedProperty property = propMap.get( key );
			if ( property != null )
			{
				extendedProperties.remove( property );
				propMap.remove( key );
				table.remove( table.getSelectionIndex( ) );
				table.select( index<table.getItemCount( ) ?index:table.getItemCount( )- 1 );
			}
			Control editor = editorValue.getEditor( );
			if ( editor != null )
			{
				editor.dispose( );
			}
		}
	}
	else if ( e.getSource( ).equals( table ) )
	{
		Control oldEditor = editorValue.getEditor( );
		if ( oldEditor != null )
			oldEditor.dispose( );

		// Identify the selected row
		final TableItem item = (TableItem) e.item;
		if ( item == null )
		{
			return;
		}

		// The control that will be the editor must be a child of the Table
		Text newEditor = new Text( table, SWT.NONE );
		newEditor.setText( item.getText( 1 ) );
		newEditor.addListener( SWT.FocusOut, new Listener( ) {

			public void handleEvent( Event event )
			{
				Text text = (Text) event.widget;
				editorValue.getItem( ).setText( 1, text.getText( ) );
				updateModel( item.getText( 0 ), text.getText( ) );
			}
		} );
		newEditor.selectAll( );
		newEditor.setFocus( );
		editorValue.setEditor( newEditor, item, 1 );
	}
	btnRemove.setEnabled( !propDisabledMap.containsKey( table.getSelection( )[0].getText( 0 ) ) );
}
 
Example 18
Source File: OutputColumnsPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void createTextCell( Composite parent, final int index )
		throws IllegalArgumentException, IntrospectionException,
		IllegalAccessException, InvocationTargetException
{
	final Text tx = ControlProvider.createText( parent,
			(String) Utility.getProperty( data, cellProperties[index] ) );
	tx.setLayoutData( ControlProvider.getGridDataWithHSpan( 2 ) );

	if ( index < 2 )// disable name and dataTypeName
	{
		tx.setEditable( false );
	}
	else
	{
		tx.addModifyListener( new ModifyListener( ) {

			public void modifyText( ModifyEvent e )
			{
				try
				{
					if ( index == 2 )
					{
						boolean isUniqueName = isUnique( tx.getText( ), data );
						if ( !isUniqueName )
							updateStatus( getMiscStatus( IStatus.ERROR,
									Messages.getString( "OutputColumnPage.OutputColumns.DuplicatedName" ) ) ); //$NON-NLS-1$
						else
							updateStatus( getOKStatus( ) );
					}
					Object txText = tx.getText( );
					if ( tx.getText( ).trim( ).length( ) == 0 )
						txText = null;

					Utility.setProperty( data,
							cellProperties[index],
							txText );
				}
				catch ( Exception e1 )
				{
					ExceptionHandler.handle( e1 );
				}
			}

		} );
	}

	if ( index == 2 )
	{
		tx.setFocus( );
	}
}
 
Example 19
Source File: TableCellEditorListener.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * http://www.eclipse.org/swt/snippets/
 */
@Override
public void handleEvent(Event event) {

    final TableEditor editor = new TableEditor(table);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;

    Rectangle clientArea = table.getClientArea();
    if (table.getSelection().length != 1) {
        return;
    }

    Rectangle bounds = table.getSelection()[0].getBounds();
    Point pt = new Point(bounds.x, bounds.y);
    int index = table.getTopIndex();
    while (index < table.getItemCount()) {
        boolean visible = false;
        final SimpleTableItem item = (SimpleTableItem) table.getItem(index);
        for (int i = 0; i < table.getColumnCount(); i++) {
            Rectangle rect = item.getBounds(i);
            if (rect.contains(pt)) {

                final Text text = new Text(table, SWT.NONE);
                Listener textListener = new TextListener(item, text);

                text.addListener(SWT.FocusOut, textListener);
                text.addListener(SWT.Traverse, textListener);
                text.addListener(SWT.FocusOut, wizard);
                editor.setEditor(text, item, i);
                text.setText(item.getText(i));
                text.selectAll();
                text.setFocus();
                return;
            }
            if (!visible && rect.intersects(clientArea)) {
                visible = true;
            }
        }
        if (!visible) {
            return;
        }
        index++;
    }
}