Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using same composite more than once
Using same composite more than once [message #448553] Wed, 26 April 2006 03:39 Go to next message
Eclipse UserFriend
Hi,

in my RCP application I'm using a ViewPart instance consisiting of a multitude of different composites.
I'm trying to use the same composite instance within two different composites (as the information to be displayed is identical)

Here are some code snippets:

<i>public class InfoComposite extends Composite {
private MainInfoComposite mainInfoComposite = null;</i>

InfoComposite is the first class to use the MainInfoComposite instance

<i>public class BasicInfoComposite extends Composite {
private MainInfoComposite mainComposite = null;</i>

BasicInfoComposite is to use the same MainInfoComposite instance

My problem is: after I've assigned the MainInfoComposite instance to the second class, all data entered in the GUI is not displayed if the BasicInfoComposite is made visible. The code snippet below represents my approach:

<i>basicInfo.setMainComposite(info.getMainInfoComposite()); </i>

However, if I assign the values of each composite control manually to the corresponding control of the second composite, it works:

<i> basicInfo.getMainComposite().getTextLastName().setText(info. getMainInfoComposite().getTextLastName().getText()); </i>

Any ideas how I can solve the problem just by assigning the composite using a setter method??

Thanks, Alex
Re: Using same composite more than once [message #448570 is a reply to message #448553] Wed, 26 April 2006 19:20 Go to previous messageGo to next message
Eclipse UserFriend
I'm not sure what you're trying to accomplish. Are you trying to have one Composite instance that is displayed as a child of 2 different Composites? Do you think you could provide a standalone snippet that shows what you're doing/seeing?

-brad
Re: Using same composite more than once [message #448575 is a reply to message #448570] Thu, 27 April 2006 03:02 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I want to use the same Composite instance as a child of two different Composites.
By means of the first Composite the 'shared' Composite is provided with data. This data shall be reused in the second Composite - what I'm trying to accomplish is to simply use the shared instance for this purpose.

This is the first class:

<i>class InfoComposite extends Composite {

private Label compositeLabel = null;

private MainInfoComposite mainInfoComposite = null;

private Text textStreet = null;
private Label labelStreet = null;

private Combo comboCountry = null;
private Label labelCountry = null;

private Text textZipCode = null;
private Label labelZipCode = null;

private Text textCity = null;
private Label labelCity = null;

private Button acceptDataButton = null;
private List idPrefixes = null;</i>

The MainInfoComposite class contains some more labels and text fields (nothing special about that class).

The information entered by the user shall be reused in the BasicInfoComposite class:

<i>
class BasicInfoComposite extends Composite {

private MainInfoComposite mainComposite = null;
private Label compoLabel = null;</i>

This class is scheduled to just reuse the MainInfoComposite instance and attach a label to it.

The idea is to disable the InfoComposite instance but make the BasicInfoComposite instance visible.

Hope this makes it a bit clearer ;-)

Alex
Re: Using same composite more than once [message #448591 is a reply to message #448575] Thu, 27 April 2006 08:52 Go to previous message
Eclipse UserFriend
> Yes, I want to use the same Composite instance as a child of two different Composites.

The problem is you can't have an instance of a Composite be displayed as a child of 2 separate Composites. You can pass around the reference to have access to that instance but an instance can only be displayed in one place. The parent of the Composite instance is set when it is constructed. What does the code look like that constructs your MainInfoComposite?

It sounds like what you want is to share the data that is being retrieved by your Composite and to display it in another. In order to display your Composite in 2 places you will need to construct 2 of them and one will be a child of InfoComposite and the other will be a child of BasicInfoComposite. Sharing this data between 2 Composites is normally done with a Model View Controller (MVC) pattern but you could probably come up with something simpler to just get the job done.

Also, for future reference it might be better to post this type of question to the SWT board as this is an SWT question. I'm pointing that out because there will be a higher probability of it getting answered there than here.

-brad
Previous Topic:IEditorInput for database content?
Next Topic:org.eclipse.ui.startup and threads
Goto Forum:
  


Current Time: Sun Jul 06 23:27:03 EDT 2025

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

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

Back to the top