Samuell Gretkins
Samuell Gretkins

Reputation: 197

How do I create controls in child class in SWT. And then working with it in that parent class

I need to create property tab with error view and data view (should I call it view?) in it. I want to do something like this. I have two classes. First:AbstractContentProvider:

 abstract public class AbstractContentProvider {
          Text errtext;
    public void createControls(Composite parent){
        super.createControls(Composite parent);
        StackLayout sl=new StackLayout();
        parent.setLayout(sl);
        Composite pane=new Composite(parent,SWT.NONE);
        //pane init code is ommitted
        errtext=new Text(pane,SWT.WRAP);
        sl.topControl=text;
    }
    public void setErrText(String text){
        errText=text;
    }
}

So this is my code for abstractClass, which makes a little text and StackLayout for changing views around. Here's createControls from second (child) class:

public class ContentProvider extends AbstractContentProvider{
    public void createControls(Composite parent){
        super.createControls(Composite parent);
        //this methods are omitted, but they just creating swt toolbar and table
        createToolBar(parent);
        createTable(parent);

        setErrText("ERROR");
    }
}

There can be different content on the property page, but, there is always the same errText view should be created for each tab. How do I add data view from child class and then work with it by calling methods of parent class?

Upvotes: 0

Views: 81

Answers (1)

Martin Frank
Martin Frank

Reputation: 3474

I think i still didn't get your question clear :-$

so maybe you tell me if i'm going to the right direction ^^

keep your common part as private variable - then you can access the parent easily...

private Object commonPart; //i don't know it's class
public class ContentProvider extends AbstractContentProvider{
    public void createControls(Composite parent, Object commonPart){
        super.createControls(Composite parent);
        this.commonPart= commonPart;
        //this methods are omitted, but they just creating swt toolbar and table
        createToolBar(parent);
        createTable(parent);

        setText("ERROR");      
        commonPart.doSomething(); //i don't know the common part      
    }
}

Upvotes: 1

Related Questions