views:

51

answers:

1

In my editor, I have a composite containing a label control right at the top which flashes informative message in red colour whenever the user enters erroneous inputs in any of the below lying fields. The text keeps changing dynamically depending on user's input. I am able to achieve the effect of displaying red coloured text on erroneous inputs and displaying nothing in the label for correct inputs.

But, I want that when there is no error to display in the label composite, the rest of the below fields shift up in display. And when there is error to display, the error should appear in it's place(at the top of all other fields) pushing the other fields down.

Is there a way to achieve this effect without redrawing all the controls again?

A: 

Yes, call layout (true) on the parent.

For example I have a view that has a search bar at the top who's visibility can be toggled. I have a method to create the search composite and one to remove it:

private void createNameSearchBar () {
    mySearchControl = new CardSearchControl (myViewComposite, SWT.NONE);
    mySearchControl.setSearchListener (this);
}


private void disposeNameSearchBar () {
    mySearchControl.dispose ();
    mySearchControl = null;
}

private CardSearchControl mySearchControl = null;
private Composite myViewComposite;
private boolean mySearchBarState;

To hide or show the search bar control I call this method (myViewComposite is the top level control that owns the search bar and all the other contorls):

public void setSearchBarState (boolean show)  {
    mySearchBarState = show;

    if (myViewComposite == null  ||  myViewComposite.isDisposed ())
        return; // no work to do

    if (mySearchBarState  &&  mySearchControl == null)  {
        createNameSearchBar ();
        mySearchControl.moveAbove (null);
        myViewComposite.layout (true);
    }  else if (!mySearchBarState  &&  mySearchControl != null)  {
        disposeNameSearchBar ();
        myViewComposite.layout (true);
    }
}
Ian Leslie