Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to see the updated tree
how to see the updated tree [message #450896] Sun, 20 February 2005 05:14 Go to next message
Eclipse UserFriend
Originally posted by: zyang.bsu.edu

Hi All,

I have a very basic question here. There is a composite which has two
groups. Group1 has a list, and group2 has a tree, which will be updated
when a different item is selected in the list. No matter how hard I've
tried, the updated tree still doesn't want to show up. Group2 could show
the tree before I did anything with list. If I selected an item from list,
group2 would show me nothing.

Here is the modified snippet of my code. I really need the experts in this
group give me some advice:

...
public void createTTPEditorPage(){

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout (gridLayout);
// v is a vector
createGroup1(v);
createGroup2();
}

//create a list in group1
public void createGroup1(Vector v){
GridData data = new GridData (GridData.FILL_BOTH);
group1 = new Group (composite, SWT.NONE);
group1.setText ("Group1");
group1.setLayout (new GridLayout ());
group1.setLayoutData(data);

org.eclipse.swt.widgets.List list = new
org.eclipse.swt.widgets.List(group1, SWT.SINGLE | SWT.BORDER |
SWT.H_SCROLL | SWT.V_SCROLL);
data = new GridData (GridData.FILL_BOTH);
list.setLayoutData(data);

if(v != null){
for (int i=0; i<v.size(); i++){
list.add(v.get(i).toString());
System.out.println(v.get(i).toString());}

// add selectionListener to the list
SelectionListener selectionListener = new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
int index = 0;
org.eclipse.swt.widgets.List l;
if(e.getSource() instanceof org.eclipse.swt.widgets.List)
{
l =(org.eclipse.swt.widgets.List)e.getSource();
index = l.getSelectionIndex();

//reset tree
if(tree != null){
tree.dispose();}

tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
SWT.V_SCROLL);

root = new TreeItem(tree, 0);
root.setText(index);}
};
};
list.addSelectionListener(selectionListener);
}

}


public void createGroup2(){
GridData data;

data = new GridData (GridData.FILL_BOTH);
group2 = new Group (composite, SWT.NONE);
group2.setText ("Group2");
group2.setLayout (new GridLayout ());
group2.setLayoutData(data);

tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
SWT.V_SCROLL);
data = new GridData (GridData.FILL_BOTH);
tree.setLayoutData(data);

root = new TreeItem(tree,0);
root.setText("No signal was selected");

}

...
Re: how to see the updated tree [message #450897 is a reply to message #450896] Sun, 20 February 2005 11:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kent.generatescape.com

try this:


import java.util.Vector;

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.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;



public class ForumQuestion
{
Shell shell;
Tree tree;

public void run()
{
Display display = new Display();
shell = new Shell(display);
shell.setText("Text Tree Editor");

createTTPEditorPage();

shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}

public void createTTPEditorPage()
{

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
shell.setLayout(gridLayout);
// v is a vector

Vector v = new Vector();
v.add("Hello1");
v.add("Hello2");
createGroup1(v);

}

//Group group2;

public void createGroup1(Vector v)
{
GridData data = new GridData(GridData.FILL_BOTH);
final Group group1 = new Group(shell, SWT.NONE);
group1.setText("Group1");
group1.setLayout(new GridLayout());
group1.setLayoutData(data);


//final

org.eclipse.swt.widgets.List list = new
org.eclipse.swt.widgets.List(
group1, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
SWT.V_SCROLL);
data = new GridData(GridData.FILL_BOTH);
list.setLayoutData(data);


Group group2 = createGroup2();
tree = new Tree(group2, SWT.SINGLE | SWT.BORDER
| SWT.H_SCROLL | SWT.V_SCROLL);

if (v != null)
{
for (int i = 0; i < v.size(); i++)
{
list.add(v.get(i).toString());
System.out.println(v.get(i).toString());
}

// add selectionListener to the list
SelectionListener selectionListener = new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
int index = 0;
org.eclipse.swt.widgets.List l;
if (e.getSource() instanceof
org.eclipse.swt.widgets.List)
{
l = (org.eclipse.swt.widgets.List) e.getSource();
index = l.getSelectionIndex();


TreeItem root = new TreeItem(tree, 0);
root.setText(""+index);
}
};
};
list.addSelectionListener(selectionListener);
}

}

public Group createGroup2()
{
GridData data;

data = new GridData(GridData.FILL_BOTH);
Group group2 = new Group(shell, SWT.NONE);
group2.setText("Group2");
group2.setLayout(new GridLayout());
group2.setLayoutData(data);

return group2;

}

/**
* The application entry point
*
* @param args
* the command line arguments
*/
public static void main(String[] args)
{
new ForumQuestion().run();
}

}


"Rui k-yang " <zyang@bsu.edu> wrote in message
news:cv96ba$gbu$1@www.eclipse.org...
> Hi All,
>
> I have a very basic question here. There is a composite which has two
> groups. Group1 has a list, and group2 has a tree, which will be updated
> when a different item is selected in the list. No matter how hard I've
> tried, the updated tree still doesn't want to show up. Group2 could show
> the tree before I did anything with list. If I selected an item from list,
> group2 would show me nothing.
> Here is the modified snippet of my code. I really need the experts in this
> group give me some advice:
>
> ..
> public void createTTPEditorPage(){
> GridLayout gridLayout = new GridLayout();
> gridLayout.numColumns = 2;
> composite.setLayout (gridLayout);
> // v is a vector createGroup1(v);
> createGroup2();
> }
>
> //create a list in group1
> public void createGroup1(Vector v){
> GridData data = new GridData (GridData.FILL_BOTH);
> group1 = new Group (composite, SWT.NONE);
> group1.setText ("Group1");
> group1.setLayout (new GridLayout ());
> group1.setLayoutData(data);
>
> org.eclipse.swt.widgets.List list = new
> org.eclipse.swt.widgets.List(group1, SWT.SINGLE | SWT.BORDER |
> SWT.H_SCROLL | SWT.V_SCROLL);
> data = new GridData (GridData.FILL_BOTH);
> list.setLayoutData(data);
>
> if(v != null){
> for (int i=0; i<v.size(); i++){
> list.add(v.get(i).toString());
> System.out.println(v.get(i).toString());}
>
> // add selectionListener to the list
> SelectionListener selectionListener = new SelectionAdapter () {
> public void widgetSelected (SelectionEvent e) {
> int index = 0;
> org.eclipse.swt.widgets.List l;
> if(e.getSource() instanceof org.eclipse.swt.widgets.List)
> {
> l =(org.eclipse.swt.widgets.List)e.getSource();
> index = l.getSelectionIndex();
>
> //reset tree
> if(tree != null){
> tree.dispose();}
>
> tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
> SWT.V_SCROLL);
>
> root = new TreeItem(tree, 0);
> root.setText(index);}
> };
> };
> list.addSelectionListener(selectionListener);
> }
>
> }
>
>
> public void createGroup2(){
> GridData data;
>
> data = new GridData (GridData.FILL_BOTH);
> group2 = new Group (composite, SWT.NONE);
> group2.setText ("Group2");
> group2.setLayout (new GridLayout ());
> group2.setLayoutData(data);
>
> tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
> SWT.V_SCROLL);
> data = new GridData (GridData.FILL_BOTH);
> tree.setLayoutData(data);
>
> root = new TreeItem(tree,0);
> root.setText("No signal was selected");
>
> }
>
> ..
>
Re: how to see the updated tree [message #451003 is a reply to message #450897] Sun, 20 February 2005 22:47 Go to previous message
Eclipse UserFriend
Originally posted by: zyang.bsu.edu

Thanks, Kent. Problem has been solved.


kent wrote:

> try this:


> import java.util.Vector;

> 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.Display;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Tree;
> import org.eclipse.swt.widgets.TreeItem;



> public class ForumQuestion
> {
> Shell shell;
> Tree tree;

> public void run()
> {
> Display display = new Display();
> shell = new Shell(display);
> shell.setText("Text Tree Editor");

> createTTPEditorPage();

> shell.open();
> while (!shell.isDisposed())
> {
> if (!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> display.dispose();
> }

> public void createTTPEditorPage()
> {

> GridLayout gridLayout = new GridLayout();
> gridLayout.numColumns = 2;
> shell.setLayout(gridLayout);
> // v is a vector

> Vector v = new Vector();
> v.add("Hello1");
> v.add("Hello2");
> createGroup1(v);

> }

> //Group group2;

> public void createGroup1(Vector v)
> {
> GridData data = new GridData(GridData.FILL_BOTH);
> final Group group1 = new Group(shell, SWT.NONE);
> group1.setText("Group1");
> group1.setLayout(new GridLayout());
> group1.setLayoutData(data);


> //final

> org.eclipse.swt.widgets.List list = new
> org.eclipse.swt.widgets.List(
> group1, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
> SWT.V_SCROLL);
> data = new GridData(GridData.FILL_BOTH);
> list.setLayoutData(data);


> Group group2 = createGroup2();
> tree = new Tree(group2, SWT.SINGLE | SWT.BORDER
> | SWT.H_SCROLL | SWT.V_SCROLL);

> if (v != null)
> {
> for (int i = 0; i < v.size(); i++)
> {
> list.add(v.get(i).toString());
> System.out.println(v.get(i).toString());
> }

> // add selectionListener to the list
> SelectionListener selectionListener = new SelectionAdapter()
> {
> public void widgetSelected(SelectionEvent e)
> {
> int index = 0;
> org.eclipse.swt.widgets.List l;
> if (e.getSource() instanceof
> org.eclipse.swt.widgets.List)
> {
> l = (org.eclipse.swt.widgets.List) e.getSource();
> index = l.getSelectionIndex();


> TreeItem root = new TreeItem(tree, 0);
> root.setText(""+index);
> }
> };
> };
> list.addSelectionListener(selectionListener);
> }

> }

> public Group createGroup2()
> {
> GridData data;

> data = new GridData(GridData.FILL_BOTH);
> Group group2 = new Group(shell, SWT.NONE);
> group2.setText("Group2");
> group2.setLayout(new GridLayout());
> group2.setLayoutData(data);

> return group2;

> }

> /**
> * The application entry point
> *
> * @param args
> * the command line arguments
> */
> public static void main(String[] args)
> {
> new ForumQuestion().run();
> }

> }


> "Rui k-yang " <zyang@bsu.edu> wrote in message
> news:cv96ba$gbu$1@www.eclipse.org...
>> Hi All,
>>
>> I have a very basic question here. There is a composite which has two
>> groups. Group1 has a list, and group2 has a tree, which will be updated
>> when a different item is selected in the list. No matter how hard I've
>> tried, the updated tree still doesn't want to show up. Group2 could show
>> the tree before I did anything with list. If I selected an item from list,
>> group2 would show me nothing.
>> Here is the modified snippet of my code. I really need the experts in this
>> group give me some advice:
>>
>> ..
>> public void createTTPEditorPage(){
>> GridLayout gridLayout = new GridLayout();
>> gridLayout.numColumns = 2;
>> composite.setLayout (gridLayout);
>> // v is a vector createGroup1(v);
>> createGroup2();
>> }
>>
>> //create a list in group1
>> public void createGroup1(Vector v){
>> GridData data = new GridData (GridData.FILL_BOTH);
>> group1 = new Group (composite, SWT.NONE);
>> group1.setText ("Group1");
>> group1.setLayout (new GridLayout ());
>> group1.setLayoutData(data);
>>
>> org.eclipse.swt.widgets.List list = new
>> org.eclipse.swt.widgets.List(group1, SWT.SINGLE | SWT.BORDER |
>> SWT.H_SCROLL | SWT.V_SCROLL);
>> data = new GridData (GridData.FILL_BOTH);
>> list.setLayoutData(data);
>>
>> if(v != null){
>> for (int i=0; i<v.size(); i++){
>> list.add(v.get(i).toString());
>> System.out.println(v.get(i).toString());}
>>
>> // add selectionListener to the list
>> SelectionListener selectionListener = new SelectionAdapter () {
>> public void widgetSelected (SelectionEvent e) {
>> int index = 0;
>> org.eclipse.swt.widgets.List l;
>> if(e.getSource() instanceof org.eclipse.swt.widgets.List)
>> {
>> l =(org.eclipse.swt.widgets.List)e.getSource();
>> index = l.getSelectionIndex();
>>
>> //reset tree
>> if(tree != null){
>> tree.dispose();}
>>
>> tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
>> SWT.V_SCROLL);
>>
>> root = new TreeItem(tree, 0);
>> root.setText(index);}
>> };
>> };
>> list.addSelectionListener(selectionListener);
>> }
>>
>> }
>>
>>
>> public void createGroup2(){
>> GridData data;
>>
>> data = new GridData (GridData.FILL_BOTH);
>> group2 = new Group (composite, SWT.NONE);
>> group2.setText ("Group2");
>> group2.setLayout (new GridLayout ());
>> group2.setLayoutData(data);
>>
>> tree = new Tree(group2, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
>> SWT.V_SCROLL);
>> data = new GridData (GridData.FILL_BOTH);
>> tree.setLayoutData(data);
>>
>> root = new TreeItem(tree,0);
>> root.setText("No signal was selected");
>>
>> }
>>
>> ..
>>
Previous Topic:Lists
Next Topic:setLocation Problem when resizing shell
Goto Forum:
  


Current Time: Tue Apr 16 21:21:03 GMT 2024

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

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

Back to the top