Java Code Examples for org.eclipse.swt.widgets.Combo#setText()

The following examples show how to use org.eclipse.swt.widgets.Combo#setText() . 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: OptionsConfigurationBlock.java    From typescript.java with MIT License 6 votes vote down vote up
protected Combo newComboControl(Composite composite, Key key, String[] values, String[] valueLabels,
		boolean readOnly) {
	Combo comboBox = new Combo(composite, readOnly ? SWT.READ_ONLY : SWT.NONE);
	comboBox.setItems(valueLabels);
	comboBox.setFont(JFaceResources.getDialogFont());

	makeScrollableCompositeAware(comboBox);

	String currValue = getValue(key);
	if (readOnly) {
		ControlData data = new ControlData(key, values);
		comboBox.setData(data);
		comboBox.addSelectionListener(getSelectionListener());
		comboBox.select(data.getSelection(currValue));
	} else {
		comboBox.setData(key);
		if (currValue != null) {
			comboBox.setText(currValue);
		}
		comboBox.addModifyListener(getTextModifyListener());
	}

	fComboBoxes.add(comboBox);
	return comboBox;
}
 
Example 2
Source File: ReportConfigurationTab.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void createPriorityGroup(Composite parent) {
    Composite prioGroup = new Composite(parent, SWT.NONE);
    prioGroup.setLayout(new GridLayout(2, false));

    Label minPrioLabel = new Label(prioGroup, SWT.NONE);
    minPrioLabel.setText(getMessage("property.minPriority"));
    minPrioLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

    minPriorityCombo = new Combo(prioGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    minPriorityCombo.add(ProjectFilterSettings.HIGH_PRIORITY);
    minPriorityCombo.add(ProjectFilterSettings.MEDIUM_PRIORITY);
    minPriorityCombo.add(ProjectFilterSettings.LOW_PRIORITY);
    minPriorityCombo.setText(propertyPage.getOriginalUserPreferences().getFilterSettings().getMinPriority());
    minPriorityCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    minPriorityCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            String data = minPriorityCombo.getText();
            getCurrentProps().getFilterSettings().setMinPriority(data);
        }
    });


}
 
Example 3
Source File: GuiToolbarWidgets.java    From hop with Apache License 2.0 6 votes vote down vote up
public void selectComboItem( String id, String string ) {
  GuiToolbarItem item = guiToolBarMap.get( id );
  if ( item != null ) {
    Control control = widgetsMap.get( id );
    if ( control != null ) {
      if ( control instanceof Combo ) {
        Combo combo = (Combo) control;
        combo.setText( Const.NVL( string, "" ) );
        int index = Const.indexOfString( string, combo.getItems() );
        if ( index >= 0 ) {
          combo.select( index );
        }
      }
    }
  }
}
 
Example 4
Source File: LineWrappingTabPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateCombo(Combo combo, Map<Object, Integer> map, final String[] items) {
    String[] newItems= new String[items.length];
    int maxCount= 0, maxStyle= 0;

    for(int i = 0; i < items.length; i++) {
        Integer count= map.get(new Integer(i));
        int val= (count == null) ? 0 : count.intValue();
        if (val > maxCount) {
            maxCount= val;
            maxStyle= i;
        }
        newItems[i]= getLabelText(items[i], val, fElements.size());
    }
    combo.setItems(newItems);
    combo.setText(newItems[maxStyle]);
}
 
Example 5
Source File: JVoiceXmlBrowserUI.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Convenience method to set a combo box value from a configuration.
 * 
 * @param configuration
 *            The configuration.
 * @param attribute
 *            Name of the attribute.
 * @param def
 *            Default value.
 * @param combo
 *            The combo box to use for display.
 */
private void getAttribute(final ILaunchConfiguration configuration,
        final String attribute, final String def, final Combo combo) {
    if ((configuration == null) || (combo == null)) {
        return;
    }

    try {
        final Object value = configuration.getAttribute(attribute, def);
        if (value == null) {
            return;
        }

        String str = value.toString();
        if (str.length() == 0) {
            str = def;
        }

        combo.setText(str);
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: GroupDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void setKeyExpression( Combo chooser, String key )
{
	chooser.deselectAll( );
	key = StringUtil.trimString( key );
	if ( StringUtil.isBlank( key ) )
	{
		chooser.setText( "" ); //$NON-NLS-1$
		return;
	}

	IExpressionConverter converter = ExpressionButtonUtil.getCurrentExpressionConverter( chooser );
	for ( int i = 0; i < columnList.size( ); i++ )
	{
		if ( key.equals( ExpressionUtility.getExpression( columnList.get( i ),
				converter ) ) )
		{
			// chooser.select( i );
			chooser.setText( ( (ComputedColumnHandle) columnList.get( i ) ).getName( ) );
			return;
		}
	}
	chooser.setText( key );
}
 
Example 7
Source File: InputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected Combo createInputMappingAssignedToCombo(final Composite outputMappingControl, final InputMapping mapping) {
    final Combo assignationTypeCombo = new Combo(outputMappingControl, SWT.BORDER | SWT.READ_ONLY);
    getWidgetFactory().adapt(assignationTypeCombo);
    assignationTypeCombo.setItems(new String[] { Messages.assignToContractInput, Messages.assignToData });
    switch (mapping.getAssignationType()) {
        case CONTRACT_INPUT:
            assignationTypeCombo.setText(Messages.assignToContractInput);
            break;
        case DATA:
            assignationTypeCombo.setText(Messages.assignToData);
            break;
        default:
            assignationTypeCombo.setText(Messages.assignToContractInput);
            break;
    }
    assignationTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    assignationTypeCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
            SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_ASSIGNATIONTYPE);
    return assignationTypeCombo;
}
 
Example 8
Source File: TimeGraphFindDialog.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates the combo with the history.
 *
 * @param combo
 *            to be updated
 * @param history
 *            to be put into the combo
 */
private static void updateHistory(Combo combo, List<String> history) {
    String findString = combo.getText();
    int index = history.indexOf(findString);
    if (index != 0) {
        if (index != -1) {
            history.remove(index);
        }
        history.add(0, findString);
        Point selection = combo.getSelection();
        updateCombo(combo, history);
        combo.setText(findString);
        combo.setSelection(selection);
    }
}
 
Example 9
Source File: RemoteProfilesPreferencePage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
public DetailsPanel(Composite parent) {
    fComposite = new Composite(parent, SWT.BORDER);
    GridLayout gl = new GridLayout(2, false);
    fComposite.setLayout(gl);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    Combo combo = new Combo(fComposite, SWT.BORDER);
    combo.setText("*"); //$NON-NLS-1$
    gd.heightHint = 2 * gl.marginHeight + gl.verticalSpacing + 2 * (combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    fComposite.setLayoutData(gd);
    combo.dispose();
}
 
Example 10
Source File: CompositeFactory.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
public static Combo createFileEncodingCombo(final String defaultCharset, final AbstractDialog dialog, final Composite composite, final String title, final int span) {
    final Combo fileEncodingCombo = createReadOnlyCombo(dialog, composite, title, span, -1);

    for (final Charset charset : Charset.availableCharsets().values()) {
        fileEncodingCombo.add(charset.displayName());
    }

    fileEncodingCombo.setText(defaultCharset);

    return fileEncodingCombo;
}
 
Example 11
Source File: StringSelectionTemplateVariable.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createWidget(ParameterComposite parameterComposite, Composite parent) {
	combo = new Combo(parent, SWT.READ_ONLY);
	combo.setItems(getPossibleValues());
	combo.setText(getValue());
	combo.setToolTipText(getDescription());
	combo.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			setValue(combo.getText());
			parameterComposite.update();
		}
	});
}
 
Example 12
Source File: HopGuiPipelineGraph.java    From hop with Apache License 2.0 5 votes vote down vote up
public void setZoomLabel() {
  Combo combo = (Combo) toolBarWidgets.getWidgetsMap().get( TOOLBAR_ITEM_ZOOM_LEVEL );
  if ( combo == null ) {
    return;
  }
  String newString = Math.round( magnification * 100 ) + "%";
  String oldString = combo.getText();
  if ( !newString.equals( oldString ) ) {
    combo.setText( Math.round( magnification * 100 ) + "%" );
  }
}
 
Example 13
Source File: TermBaseSearchDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the combo with the history.
 * @param combo
 *            to be updated
 * @param history
 *            to be put into the combo
 */
private void updateHistory(Combo combo, List<String> history) {
	String findString = combo.getText();
	int index = history.indexOf(findString);
	if (index != 0) {
		if (index != -1) {
			history.remove(index);
		}
		history.add(0, findString);
		Point selection = combo.getSelection();
		updateCombo(combo, history);
		combo.setText(findString);
		combo.setSelection(selection);
	}
}
 
Example 14
Source File: EditAllAttributesDialog.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private Combo createTypeCombo(NormalColumn targetColumn) {
	GridData gridData = new GridData();
	gridData.widthHint = 100;

	final Combo typeCombo = new Combo(this.attributeTable, SWT.READ_ONLY);
	initializeTypeCombo(typeCombo);
	typeCombo.setLayoutData(gridData);

	typeCombo.addSelectionListener(new SelectionAdapter() {

		/**
		 * {@inheritDoc}
		 */
		@Override
		public void widgetSelected(SelectionEvent event) {
			validate();
		}

	});

	SqlType sqlType = targetColumn.getType();

	String database = this.diagram.getDatabase();

	if (sqlType != null && sqlType.getAlias(database) != null) {
		typeCombo.setText(sqlType.getAlias(database));
	}

	return typeCombo;
}
 
Example 15
Source File: ConcordanceSearchDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the combo with the history.
 * @param combo
 *            to be updated
 * @param history
 *            to be put into the combo
 */
private void updateHistory(Combo combo, List<String> history) {
	String findString = combo.getText();
	int index = history.indexOf(findString);
	if (index != 0) {
		if (index != -1) {
			history.remove(index);
		}
		history.add(0, findString);
		Point selection = combo.getSelection();
		updateCombo(combo, history);
		combo.setText(findString);
		combo.setSelection(selection);
	}
}
 
Example 16
Source File: HopGuiWorkflowGraph.java    From hop with Apache License 2.0 5 votes vote down vote up
public void setZoomLabel() {
  Combo zoomLabel = (Combo) toolBarWidgets.getWidgetsMap().get( TOOLBAR_ITEM_ZOOM_LEVEL );
  if ( zoomLabel == null ) {
    return;
  }
  String newString = Math.round( magnification * 100 ) + "%";
  String oldString = zoomLabel.getText();
  if ( !newString.equals( oldString ) ) {
    zoomLabel.setText( Math.round( magnification * 100 ) + "%" );
  }
}
 
Example 17
Source File: CrosstabMapRuleBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void selectMultiValues( Combo combo )
{
	String[] retValue = null;

	try
	{
		List selectValueList = getSelectValueList( );
		if ( selectValueList == null || selectValueList.size( ) == 0 )
		{
			MessageDialog.openInformation( null,
					Messages.getString( "SelectValueDialog.selectValue" ), //$NON-NLS-1$
					Messages.getString( "SelectValueDialog.messages.info.selectVauleUnavailable" ) ); //$NON-NLS-1$
		}
		else
		{
			SelectValueDialog dialog = new SelectValueDialog( PlatformUI.getWorkbench( )
					.getDisplay( )
					.getActiveShell( ),
					Messages.getString( "ExpressionValueCellEditor.title" ) ); //$NON-NLS-1$
			dialog.setSelectedValueList( selectValueList );
			dialog.setMultipleSelection( true );

			if ( dialog.open( ) == IDialogConstants.OK_ID )
			{
				retValue = dialog.getSelectedExprValues( );
			}
		}
	}
	catch ( Exception ex )
	{
		MessageDialog.openError( null,
				Messages.getString( "SelectValueDialog.selectValue" ), //$NON-NLS-1$
				Messages.getString( "SelectValueDialog.messages.error.selectVauleUnavailable" ) //$NON-NLS-1$
						+ "\n" //$NON-NLS-1$
						+ ex.getMessage( ) );
	}

	if ( retValue != null )
	{
		addBtn.setEnabled( false );

		if ( retValue.length == 1 )
		{
			combo.setText( DEUtil.resolveNull( retValue[0] ) );
		}
		else if ( retValue.length > 1 )
		{
			combo.setText( "" ); //$NON-NLS-1$
		}

		boolean change = false;
		for ( int i = 0; i < retValue.length; i++ )
		{
			Expression expression = new Expression( retValue[i],
					ExpressionButtonUtil.getExpression( combo ).getType( ) );
			if ( valueList.indexOf( expression ) < 0 )
			{
				valueList.add( expression );
				change = true;
			}
		}
		if ( change )
		{
			tableViewer.refresh( );
			updateButtons( );
			combo.setFocus( );
		}
	}
}
 
Example 18
Source File: GuiCompositeWidgets.java    From hop with Apache License 2.0 4 votes vote down vote up
private void setWidgetsData( Object sourceData, GuiElements guiElements ) {

    if ( guiElements.isIgnored() ) {
      return;
    }

    // Do we add the element or the children?
    //
    if ( guiElements.getId() != null ) {

      Control control = widgetsMap.get( guiElements.getId() );
      if ( control != null ) {

        // What's the value?
        //
        Object value = null;
        try {
          value = new PropertyDescriptor( guiElements.getFieldName(), sourceData.getClass() )
            .getReadMethod()
            .invoke( sourceData )
          ;
        } catch ( Exception e ) {
          System.err.println( "Unable to get value for field: '" + guiElements.getFieldName() + "' : " + e.getMessage() );
          e.printStackTrace();
        }
        String stringValue = value == null ? "" : Const.NVL( value.toString(), "" );

        switch ( guiElements.getType() ) {
          case TEXT:
            if ( guiElements.isVariablesEnabled() ) {
              TextVar textVar = (TextVar) control;
              textVar.setText( stringValue );
            } else {
              Text text = (Text) control;
              text.setText( stringValue );
            }
            break;
          case CHECKBOX:
            Button button = (Button) control;
            button.setSelection( (Boolean) value );
            break;
          case COMBO:
            if ( guiElements.isVariablesEnabled() ) {
              ComboVar comboVar = (ComboVar) control;
              comboVar.setText( stringValue );
            } else {
              Combo combo = (Combo) control;
              combo.setText( stringValue );
            }
            break;
          default:
            System.err.println( "WARNING: setting data on widget with ID " + guiElements.getId() + " : not implemented type " + guiElements.getType() + " yet." );
            break;
        }

      } else {
        System.err.println( "Widget not found to set value on for id: " + guiElements.getId()+", label: "+guiElements.getLabel() );
      }
    } else {

      // Add the children
      //
      for ( GuiElements child : guiElements.getChildren() ) {
        setWidgetsData( sourceData, child );
      }
    }
  }
 
Example 19
Source File: HighlightRuleBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void selectMultiValues( Combo combo )
{
	String[] retValue = null;

	bindingName = getExpressionBindingName( );

	if ( bindingName == null && getExpression( ).length( ) > 0 )
		bindingName = getExpression( );

	if ( bindingName != null )
	{
		try
		{
			List selectValueList = getSelectValueList( );
			SelectValueDialog dialog = new SelectValueDialog( PlatformUI.getWorkbench( )
					.getDisplay( )
					.getActiveShell( ),
					Messages.getString( "ExpressionValueCellEditor.title" ) ); //$NON-NLS-1$

			dialog.setMultipleSelection( true );

			dialog.setSelectedValueList( selectValueList );
			if ( bindingParams != null )
			{
				dialog.setBindingParams( bindingParams );
			}
			if ( dialog.open( ) == IDialogConstants.OK_ID )
			{
				retValue = dialog.getSelectedExprValues( ExpressionButtonUtil.getCurrentExpressionConverter( combo ) );
			}
		}
		catch ( Exception ex )
		{
			MessageDialog.openError( null,
					Messages.getString( "SelectValueDialog.selectValue" ), //$NON-NLS-1$
					Messages.getString( "SelectValueDialog.messages.error.selectVauleUnavailable" ) //$NON-NLS-1$
							+ "\n" //$NON-NLS-1$
							+ ex.getMessage( ) );
		}
	}
	else
	{
		MessageDialog.openInformation( null,
				Messages.getString( "SelectValueDialog.selectValue" ), //$NON-NLS-1$
				Messages.getString( "SelectValueDialog.messages.info.selectVauleUnavailable" ) ); //$NON-NLS-1$
	}

	if ( retValue != null )
	{
		addBtn.setEnabled( false );

		if ( retValue.length == 1 )
		{
			combo.setText( DEUtil.resolveNull( retValue[0] ) );
		}
		else if ( retValue.length > 1 )
		{
			combo.setText( "" ); //$NON-NLS-1$
		}

		boolean change = false;
		for ( int i = 0; i < retValue.length; i++ )
		{
			Expression expression = new Expression( retValue[i],
					ExpressionButtonUtil.getExpression( combo ).getType( ) );
			if ( valueList.indexOf( expression ) < 0 )
			{
				valueList.add( expression );
				change = true;
			}
		}
		if ( change )
		{
			tableViewer.refresh( );
			updateButtons( );
			combo.setFocus( );
		}
	}
}
 
Example 20
Source File: PickWorkspaceDialog.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Control createDialogArea(final Composite parent) {
	setTitle("Choose a Workspace to store your models, settings, etc.");
	setMessage(strMsg);

	try {
		final Composite inner = new Composite(parent, SWT.NONE);
		final GridLayout l = new GridLayout(4, false);
		// double[][] layout =
		// new double[][] {
		// { 5, LatticeConstants.PREFERRED, 5, 250, 5,
		// LatticeConstants.PREFERRED, 5 },
		// { 5, LatticeConstants.PREFERRED, 5, LatticeConstants.PREFERRED,
		// 40 } };
		inner.setLayout(l);
		inner.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true));

		/* Label on the left */
		final CLabel label = new CLabel(inner, SWT.NONE);
		label.setText("GAMA Workspace");
		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

		/* Combo in the middle */
		workspacePathCombo = new Combo(inner, SWT.BORDER);
		final GridData data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		data.widthHint = 200;
		workspacePathCombo.setLayoutData(data);
		final String wsRoot = WorkspacePreferences.getLastSetWorkspaceDirectory();
		workspacePathCombo.setText(wsRoot);

		/* Checkbox below */
		rememberWorkspaceButton = new Button(inner, SWT.CHECK);
		rememberWorkspaceButton.setText("Remember");
		rememberWorkspaceButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
		rememberWorkspaceButton.setSelection(WorkspacePreferences.isRememberWorkspace());

		final String lastUsed = WorkspacePreferences.getLastUsedWorkspaces();
		lastUsedWorkspaces = new ArrayList<>();
		if ( lastUsed != null ) {
			final String[] all = lastUsed.split(splitChar);
			for ( final String str : all ) {
				lastUsedWorkspaces.add(str);
			}
		}
		for ( final String last : lastUsedWorkspaces ) {
			workspacePathCombo.add(last);
		}

		/* Browse button on the right */
		final Button browse = new Button(inner, SWT.PUSH);
		browse.setText("Browse...");
		browse.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
		browse.addListener(SWT.Selection, event -> {
			final DirectoryDialog dd = new DirectoryDialog(getParentShell());
			dd.setText("Select Workspace Root");
			dd.setMessage(strInfo);
			dd.setFilterPath(workspacePathCombo.getText());
			final String pick = dd.open();
			if ( pick == null ) {
				if ( workspacePathCombo.getText().length() == 0 ) {
					setMessage(strError, IMessageProvider.ERROR);
				}
			} else {
				setMessage(strMsg);
				workspacePathCombo.setText(pick);
			}
		});
		return inner;
	} catch (final RuntimeException err) {
		err.printStackTrace();
		return null;
	}
}