Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-19-2009, 04:22 AM
Member
 
Join Date: Nov 2007
Posts: 3
Rep Power: 0
tojas is on a distinguished road
Default Relation between 2 views
So I have two view. One view for my table and one view for my buttons.
I want to change the table when I click a button...

I have some code, so I paste here the most of it.

ControlView
Code:
public class ControlView extends ViewPart implements SelectionListener {
           // class level variables

	@Override
	public void createPartControl(final Composite parent) {
		IViewRegistry viewRegistry = PlatformUI.getWorkbench().getViewRegistry();
		IViewDescriptor desc = viewRegistry.find(TableView.ID);
		try {
			tableView = (TableView) desc.createView();
		} catch (CoreException e) {
			e.printStackTrace();
		}
                      //code to create the gui, I also add here
                      //the listeners for the buttons
	}

	@Override
	public void setFocus() {
	}

	@Override
	public void widgetDefaultSelected(final SelectionEvent arg0) {
	}

	@Override
	public void widgetSelected(final SelectionEvent event) {
		if (event.getSource().equals(b1)) {
			add();
			return;
		}
		if (event.getSource().equals(b2)) {
			delete();
			return;
		}
		if (event.getSource().equals(b3)) {
			modify();
			return;
		}
		if (event.getSource().equals(b4)) {
			ok();
			return;
		}
		if (event.getSource().equals(b5)) {
			cancel();
			return;
		}
	}

	private void add() {
                 // code
	}

           // code

	private void ok() {
		if ("".equals(t2.getText()) || "".equals(t3.getText())) {
			return;
		}
		if ("Add".equals(l1.getText())) {
			StudentManagerServiceFactory.getInstance().getTableManagerService().add(new Student("", t2.getText(), t3.getText()));
			showHide(false);
			tableView.myReload();
			return;
		}
		if ("Delete".equals(l1.getText())) {
			StudentManagerServiceFactory.getInstance().getTableManagerService().delete(
					new Student(t1.getText(), t2.getText(), t3.getText()));
			showHide(false);
			return;
		}
                      //code
	}
           // code
}
TableView
Code:
public class TableView extends ViewPart {
	public static final String	ID	= "Lab6.tableView";

	private TableViewer			viewer;

	@Override
	public void createPartControl(final Composite parent) {
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
		createColumns(viewer);
		viewer.setContentProvider(new StudentContentProvider());
		viewer.setLabelProvider(new StudentLabelProvider());
		viewer.setInput(StudentModelProvider.getInstance().getStudents());
	}

	private void createColumns(final TableViewer viewer) {
		Table table = viewer.getTable();
		String[] titles = { "Student ID", "Student Name", "Group ID" };
		int[] bounds = { 100, 100, 100 };

		for (int i = 0; i < titles.length; i++) {
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
			column.getColumn().setText(titles[i]);
			column.getColumn().setWidth(bounds[i]);
			column.getColumn().setResizable(true);
			column.getColumn().setMoveable(true);
		}
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
	}

	@Override
	public void setFocus() {
		viewer.getControl().setFocus();
	}

	public Student getCurrentRow() {
                // So here I want to return the selected row in a Student Object...
	}

	public void myReload() {
                 // Here I want to reload my table, because I got the source of the table
                 // from a database, and when I update the database I also
                 // want to update my table
	}
}
So you can see, that in TableView class I need to implement the getCurrentRow() and myReload() methods...
And in this line: "tableView = (TableView) desc.createView();"
do you think I get the current instance of TableView?
Please correct me if I am wrong..

Maybe do you have any idea or solution?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple views on user interface application dand_dd SWT / JFace 36 04-24-2009 10:05 AM
Detached views JavaForums Java Blogs 0 10-19-2008 03:50 PM
List views, a type of object Leprechaun New To Java 2 02-06-2008 04:07 AM
Relation between Polymorphism and Inheritance janakiram.attuluri Advanced Java 1 12-27-2007 12:32 AM


All times are GMT +2. The time now is 07:43 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org