Java Code Examples for org.eclipse.swt.widgets.Control#setData()

The following examples show how to use org.eclipse.swt.widgets.Control#setData() . These examples are extracted from open source projects. 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
public static ExpressionButton createExpressionButton( Composite parent,
		final Control control, final IExpressionProvider provider,
		Object contextObject, final Listener listener,
		boolean allowConstant, int style, ExpressionHelper helper )
{

	final ExpressionButton button = UIUtil.createExpressionButton( parent,
			style,
			allowConstant );
	helper.setProvider( provider );
	helper.setListener( listener );
	helper.setControl( control );
	helper.setExpressionButton( button );
	helper.setContextObject( contextObject );
	button.setExpressionHelper( helper );

	control.setData( EXPR_BUTTON, button );
	control.setData( ExpressionButtonUtil.EXPR_TYPE,
			helper.getExpressionType( ) );
	button.refresh( );

	return button;
}
 
Example 2
public static ExpressionButton createExpressionButton( Composite parent,
		final Control control, final IExpressionProvider provider,
		Object contextObject, final Listener listener,
		boolean allowConstant, int style, ExpressionHelper helper,
		boolean showOnlyLeafInThirdColumn )
{

	final ExpressionButton button = UIUtil.createExpressionButton( parent,
			style,
			allowConstant,
			showOnlyLeafInThirdColumn );
	helper.setProvider( provider );
	helper.setListener( listener );
	helper.setControl( control );
	helper.setExpressionButton( button );
	helper.setContextObject( contextObject );
	button.setExpressionHelper( helper );

	control.setData( EXPR_BUTTON, button );
	control.setData( ExpressionButtonUtil.EXPR_TYPE,
			helper.getExpressionType( ) );
	button.refresh( );

	return button;
}
 
Example 3
Source Project: hop   File: ControlSpaceKeyAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private static final void applyChanges( Shell shell, List list, Control control, int position,
                                        IInsertText insertTextInterface ) {
  String selection =
    list.getSelection()[ 0 ].contains( Const.getDeprecatedPrefix() )
      ? list.getSelection()[ 0 ].replace( Const.getDeprecatedPrefix(), "" )
      : list.getSelection()[ 0 ];
  String extra = "${" + selection + "}";
  if ( insertTextInterface != null ) {
    insertTextInterface.insertText( extra, position );
  } else {
    if ( control.isDisposed() ) {
      return;
    }

    if ( list.getSelectionCount() <= 0 ) {
      return;
    }
    if ( control instanceof Text ) {
      ( (Text) control ).insert( extra );
    } else if ( control instanceof CCombo ) {
      CCombo combo = (CCombo) control;
      combo.setText( extra ); // We can't know the location of the cursor yet. All we can do is overwrite.
    } else if ( control instanceof StyledTextComp ) {
      ( (StyledTextComp) control ).insert( extra );
    } else if ( control instanceof StyledText ) {
      ( (StyledText) control ).insert( extra );
    }
  }
  if ( !shell.isDisposed() ) {
    shell.dispose();
  }
  if ( !control.isDisposed() ) {
    control.setData( Boolean.FALSE );
  }
}
 
Example 4
Source Project: nebula   File: SWTGraphicUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Disable all widgets of a control
 *
 * @param control control to enable/disable
 * @param enable <code>true</code> to enable, <code>false</code> to disable
 */
public static void disableAllChildrenWidgets(final Control control) {
	if (control instanceof Composite) {
		for (final Control c : ((Composite) control).getChildren()) {
			disableAllChildrenWidgets(c);
		}
	}
	control.setData(SWTGraphicUtil.class.toString() + "_enableState", control.isEnabled());
	control.setEnabled(false);
}
 
Example 5
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <p>
 * Sets the prompt text on <code>control</code>
 * </p>
 *
 * @param promptText
 * @param textComponent
 * @exception IllegalArgumentException if the control is not a Text Box, a
 *                Combo Box, a StyledText or a CCombo
 */
public static void setPrompt(final String promptText, final Control control) {
	checkControl(control);

	final boolean alreadySet = control.getData(SET) == null ? false : (Boolean) control.getData(SET);
	if (alreadySet) {
		throw new IllegalArgumentException("A prompt has already been set on this control !");
	}
	control.setData(PROMPT, promptText);

	final BaseFocusControlListener focusControlListener = FocusControlListenerFactory.getFocusControlListenerFor(control);
	control.addFocusListener(focusControlListener);
	control.addControlListener(focusControlListener);
	control.setData(SET, true);
}
 
Example 6
@Override
public Object dataSourceChanged(SWTSkinObject skinObject, Object params) {
	datasource = params;
	if (soListArea != null) {
		Control control = soListArea.getControl();

		if ( !control.isDisposed()){

			control.setData("DataSource", params);
		}
	}

	return null;
}
 
Example 7
Source Project: http4e   File: LiveSashForm.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the border for a child control.
 * 
 * @param child The child control for which to set the border.
 * @param shadow One of the SWT shadow constants SHADOW_IN, SHADOW_OUT,
 *   SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_NONE.
 */  

public void setChildBorder(Control child, int shadow)
{
  checkWidget();
  if(child == null) return;
  if(shadow == SWT.SHADOW_NONE) child.setData(CHILD_SHADOW, null);
  else child.setData(CHILD_SHADOW, new Integer(shadow));
  layout();
  redraw();
  //weightsChanged();
}
 
Example 8
private ScalarParameter copeWithNextParameter(
		CascadingParameterGroup group, ScalarParameter listParam )
{
	ScalarParameter postParam = (ListingParameter) group.getPostParameter( listParam );
	if ( postParam == null )
	{
		return null;
	}
	SelectionParameterControlHelper helper = getPostParamList( ).get( listParam );
	helper.emptyControlItem( );

	Control control = helper.getControl( );
	int itemIndex = 0;
	for ( Iterator iterator = postParam.getValueList( ).iterator( ); iterator.hasNext( ); )
	{
		IParameterSelectionChoice choice = (IParameterSelectionChoice) iterator.next( );
		if ( choice.getValue( ) == null )
		{
			continue;
		}

		String label = getFormatLabelString( choice, listParam );
		if ( label != null )
		{
			itemIndex = addControlItem( control, label );
			if ( control instanceof Combo )
			{
				control.setData( String.valueOf( itemIndex ),
						choice.getValue( ) );
			}
			else
			{
				control.setData( label, choice.getValue( ) );
			}
		}
	}

	processPostParator( postParam, control );
	return postParam;
}
 
Example 9
public static IExpressionConverter getCurrentExpressionConverter(
		Control control, boolean refreshButtonType )
{
	if ( control == null )
	{
		return null;
	}
	else if ( getExpressionButton( control ) == null )
	{
		return null;
	}
	else
	{
		IExpressionSupport support = ExpressionButtonUtil.getExpressionButton( control )
				.getCurrentExpressionSupport( );
		if ( support != null && support.getConverter( ) != null )
		{
			return support.getConverter( );
		}
		else if ( refreshButtonType )
		{
			support = ExpressionButtonUtil.getExpressionButton( control )
					.getExpressionSupport( ExpressionType.JAVASCRIPT );
			if ( support != null && support.getConverter( ) != null )
			{
				control.setData( ExpressionButtonUtil.EXPR_TYPE,
						ExpressionType.JAVASCRIPT );
				getExpressionButton( control ).refresh( );
				return support.getConverter( );
			}
		}
	}
	return null;
}
 
Example 10
private static final void applyChanges( Shell shell, List list, Control control, int position,
  InsertTextInterface insertTextInterface ) {
  String selection =
      list.getSelection()[0].contains( Const.getDeprecatedPrefix() )
      ? list.getSelection()[0].replace( Const.getDeprecatedPrefix(), "" )
      : list.getSelection()[0];
  String extra = "${" + selection + "}";
  if ( insertTextInterface != null ) {
    insertTextInterface.insertText( extra, position );
  } else {
    if ( control.isDisposed() ) {
      return;
    }

    if ( list.getSelectionCount() <= 0 ) {
      return;
    }
    if ( control instanceof Text ) {
      ( (Text) control ).insert( extra );
    } else if ( control instanceof CCombo ) {
      CCombo combo = (CCombo) control;
      combo.setText( extra ); // We can't know the location of the cursor yet. All we can do is overwrite.
    } else if ( control instanceof StyledTextComp ) {
      ( (StyledTextComp) control ).insert( extra );
    } else if ( control instanceof StyledText ) {
      ( (StyledText) control ).insert( extra );
    }
  }
  if ( !shell.isDisposed() ) {
    shell.dispose();
  }
  if ( !control.isDisposed() ) {
    control.setData( Boolean.FALSE );
  }
}
 
Example 11
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 4 votes vote down vote up
static void setPromptDisplayed(final Control control, boolean newValue) {
	control.setData(IS_PROMPT_DISPLAYED, newValue);
}
 
Example 12
public static void
 addCopyToClipMenu(
final Control				control,
final copyToClipProvider	provider )
 {
  MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY );
  
  if ( ml != null ){
  
	  control.removeMouseListener( ml );
  }
  
  ml =
	  new MouseAdapter()
	  {
		  @Override
		  public void
		  mouseDown(
			 MouseEvent e )
		  {
			  if ( control.isDisposed()){

				  return;
			  }

			  final String	text = provider.getText();

			  if ( control.getMenu() != null || text == null || text.length() == 0 ){

				  return;
			  }

			  if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){

				  return;
			  }

			  final Menu menu = new Menu(control.getShell(),SWT.POP_UP);

			  MenuItem   item = new MenuItem( menu,SWT.NONE );

			  item.setData( MENU_ITEM_KEY, "" );

			  String	msg_text_id;

			  if ( provider instanceof copyToClipProvider2 ){

				  msg_text_id = ((copyToClipProvider2)provider).getMenuResource();

			  }else{

				  msg_text_id = "label.copy.to.clipboard";
			  }

			  item.setText( MessageText.getString( msg_text_id ));

			  item.addSelectionListener(
					  new SelectionAdapter()
					  {
						  @Override
						  public void
						  widgetSelected(
								  SelectionEvent arg0)
						  {
							  new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
						  }
					  });

			  control.setMenu( menu );

			  menu.addMenuListener(
					  new MenuAdapter()
					  {
						  @Override
						  public void
						  menuHidden(
								  MenuEvent arg0 )
						  {
							  if ( control.getMenu() == menu ){

								  control.setMenu( null );
							  }
						  }
					  });

			  menu.setVisible( true );
		  }
	  };
  
  control.setData( MOUSE_LISTENER_KEY, ml );
  
  control.addMouseListener( ml );
 }
 
Example 13
public void hide(Control child) {
    child.setData(HIDDEN, true);
    child.setVisible(false);
}
 
Example 14
public void show(Control child) {
    child.setData(HIDDEN, false);
    child.setVisible(true);
}
 
Example 15
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * <p>
 * Sets the prompts background color on <code>control</code>. This
 * background color will only be used when no text is present.
 * </p>
 *
 * @param background
 * @param control
 * @exception IllegalArgumentException if the control is not a Text Box, a
 *                Combo Box, a StyledText or a CCombo
 */
public static void setBackground(final Color color, final Control control) {
	checkControl(control);
	control.setData(BACKGROUND, color);
}
 
Example 16
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the {@link FocusBehavior} on <code>control</code>, if it is the
 * focus owner.
 *
 * @param focusBehavior
 * @param control
 * @exception IllegalArgumentException if the control is not a Text Box, a
 *                Combo Box, a StyledText or a CCombo
 */
public static void setFocusBehavior(final FocusBehavior focusBehavior, final Control control) {
	checkControl(control);
	control.setData(BEHAVIOR, focusBehavior);
}
 
Example 17
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * <p>
 * Set the style of the prompt font, which is a OR mix of SWT.ITALIC,
 * SWT.NONE or SWT.BOLD
 * </p>
 *
 * @param fontStyle
 * @param control
 * @exception IllegalArgumentException if the control is not a Text Box, a
 *                Combo Box, a StyledText or a CCombo
 */
public static void setFontStyle(final int fontStyle, final Control control) {
	checkControl(control);
	control.setData(STYLE, fontStyle);
}
 
Example 18
Source Project: nebula   File: PromptSupport.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the foreground color of the prompt on <code>control</code>. This
 * color will be used when no text is present.
 *
 * @param promptTextColor
 * @param textComponent
 * @exception IllegalArgumentException if the control is not a Text Box, a
 *                Combo Box, a StyledText or a CCombo
 */
public static void setForeground(final Color color, final Control control) {
	checkControl(control);
	control.setData(FOREGROUND, color);
}