Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Change the composite
Change the composite [message #633902] Tue, 19 October 2010 18:25 Go to next message
ash is currently offline ashFriend
Messages: 142
Registered: July 2010
Senior Member
Hi

how to change the composite programmaticly

suppose i have

three

----------------------------------------------------------
| Radio button 1 | composite area |
| Radio button 2 | |
| Radio buttion 3 | |
-----------------------------------------------------------

when user select radio button 1 one composite has to be displayed in composite area.

when user select radio button 2 change to diff composit has to be displayed . in composite area.

and so on

Can any 1 tell t how tell how to implements this
if it is not possible with composite

how this can be done ?

Thanks
ashok
Re: Change the composite [message #633910 is a reply to message #633902] Tue, 19 October 2010 19:51 Go to previous messageGo to next message
eshvar60  is currently offline eshvar60 Friend
Messages: 51
Registered: March 2010
Member
Have all the composites in the area and show/hide all except for one using setVisible and depending on which button is selected.
Re: Change the composite [message #633965 is a reply to message #633902] Wed, 20 October 2010 05:42 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 19/10/10 11:55 PM, ashok_kumar_rr@yahoo.com wrote:
> Hi
> how to change the composite programmaticly
> suppose i have
> three
> ----------------------------------------------------------
> | Radio button 1 | composite area |
> | Radio button 2 | |
> | Radio buttion 3 | |
> -----------------------------------------------------------
>
> when user select radio button 1 one composite has to be displayed in
> composite area.
>
> when user select radio button 2 change to diff composit has to be
> displayed . in composite area.

Try stack layout.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Change the composite [message #634080 is a reply to message #633965] Wed, 20 October 2010 13:18 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Example snippets:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet98. java
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet249 .java

Grant


"Prakash G.R." <grprakash@gmail.com> wrote in message
news:i9lv95$88m$2@news.eclipse.org...
> On 19/10/10 11:55 PM, ashok_kumar_rr@yahoo.com wrote:
>> Hi
>> how to change the composite programmaticly
>> suppose i have
>> three
>> ----------------------------------------------------------
>> | Radio button 1 | composite area |
>> | Radio button 2 | |
>> | Radio buttion 3 | |
>> -----------------------------------------------------------
>>
>> when user select radio button 1 one composite has to be displayed in
>> composite area.
>>
>> when user select radio button 2 change to diff composit has to be
>> displayed . in composite area.
>
> Try stack layout.
>
> --
> - Prakash
> Platform UI Team, IBM
>
> www.eclipse-tips.com
Re: Change the composite [message #634089 is a reply to message #634080] Wed, 20 October 2010 13:51 Go to previous messageGo to next message
eshvar60  is currently offline eshvar60 Friend
Messages: 51
Registered: March 2010
Member
Sweet I learned something really useful today Smile
Re: Change the composite [message #634099 is a reply to message #634089] Wed, 20 October 2010 14:02 Go to previous message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

Other way to show/hide composites using GridLayout
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

public class SampleDialog extends Dialog {

	private Button firstButton;
	private Button secondButton;
	private Composite firstComposite;
	private Composite secondComposite;
	private GridData firstCompositeData;
	private GridData secondCompositeData;
	private Composite composite;

	protected SampleDialog(Shell parentShell) {
		super(parentShell);
		setShellStyle(getShellStyle() | SWT.RESIZE);
	}

	protected Control createDialogArea(Composite parent) {
		composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		firstButton = new Button(composite, SWT.RADIO);
		firstButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
		firstButton.setText("First");
		secondButton = new Button(composite, SWT.RADIO);
		secondButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
		secondButton.setText("Second");

		firstComposite = new Composite(composite, SWT.NONE);
		firstComposite.setLayout(new GridLayout(1, false));
		firstCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
		firstCompositeData.horizontalSpan = 2;
		firstComposite.setLayoutData(firstCompositeData);
		Button button1 = new Button(firstComposite, SWT.NONE);
		button1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		button1.setText("Button1");
		Button button2 = new Button(firstComposite, SWT.NONE);
		button2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		button2.setText("Button2");

		secondComposite = new Composite(composite, SWT.NONE);
		secondComposite.setLayout(new GridLayout(2, false));
		secondCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
		secondCompositeData.horizontalSpan = 2;
		secondComposite.setLayoutData(secondCompositeData);

		Button button3 = new Button(secondComposite, SWT.NONE);
		button3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		button3.setText("Button3");
		Button button4 = new Button(secondComposite, SWT.NONE);
		button4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		button4.setText("Button4");
		attachListeners();
		firstButton.setSelection(true);
		return composite;
	}

	private void attachListeners() {
		SelectionListener selectionListener = new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				boolean isFirstVisible = firstButton.getSelection();
				resetControls(isFirstVisible);
			}

		};
		firstButton.addSelectionListener(selectionListener);
		secondButton.addSelectionListener(selectionListener);
	}
	
	private void resetControls(boolean isFirstVisible) {
		firstComposite.setVisible(isFirstVisible);
		firstCompositeData.exclude = !isFirstVisible;
		secondComposite.setVisible(!isFirstVisible);
		secondCompositeData.exclude = isFirstVisible;
		composite.layout();
		getShell().setSize(getShell().computeSize(composite.getSize().x, SWT.DEFAULT));
	}
	
	public void create() {
		super.create();
		resetControls(true);
	}

	public static void main(String[] args) {
		SampleDialog sampleDialog = new SampleDialog(null);
		sampleDialog.open();
	}

}





Previous Topic:remove "Open Perspective" button
Next Topic:How to save editor
Goto Forum:
  


Current Time: Thu Mar 28 18:38:06 GMT 2024

Powered by FUDForum. Page generated in 0.02324 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top