Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Update View after command has changed model
Update View after command has changed model [message #676475] Sat, 04 June 2011 18:40 Go to next message
AmFreak Missing name is currently offline AmFreak Missing name
Messages: 25
Registered: June 2011
Junior Member
Hi,

i have a TreeView with a list of Projects and Persons in this Projects (leaf).
Now i want to make a new Project. I have a Command for that. This command opens a dialog to insert the details of the new Project. But how do i update the treeView now?
I do it like this currently:

		NewProjectDialog dialog = new NewProjectDialog(window.getShell());
		if (dialog.open() == Window.OK) {
			Project project = dialog.getProject();
                        // Saving the new project in databank
			dbModel = new DatabankModel();
			dbModel.persistEntity(project);
			dbModel.save();
                        // Update treeViewer
			projects = new ProjectsModel();
			view.getViewer().setInput(projects.getProjects());
		}	


but it seems a little ugly to me to update the view from the command?
Re: Update View after command has changed model [message #676697 is a reply to message #676475] Mon, 06 June 2011 07:52 Go to previous messageGo to next message
Eclipse User
Originally posted by:

On 2011-06-04 20:40, AmFreak wrote:
> Hi,
>
> i have a TreeView with a list of Projects and Persons in this Projects
> (leaf).
> Now i want to make a new Project. I have a Command for that. This
> command opens a dialog to insert the details of the new Project. But how
> do i update the treeView now?
> I do it like this currently:
>
> NewProjectDialog dialog = new NewProjectDialog(window.getShell());
> if (dialog.open() == Window.OK) {
> Project project = dialog.getProject();
> // Saving the new project in databank
> dbModel = new DatabankModel();
> dbModel.persistEntity(project);
> dbModel.save();
> // Update treeViewer
> projects = new ProjectsModel();
> view.getViewer().setInput(projects.getProjects());
> }
>
> but it seems a little ugly to me to update the view from the command?

I agree. IMO your model should be able to send model-change events and
the content provider of your viewer should listen to these events,
eventually ensuring the refresh.

HTH & Greetings from Bremen,

Daniel Kr├╝gler
Re: Update View after command has changed model [message #677304 is a reply to message #676697] Wed, 08 June 2011 06:09 Go to previous message
AmFreak Missing name is currently offline AmFreak Missing name
Messages: 25
Registered: June 2011
Junior Member
Thanks for the reply!

The problem is the model is in the view class. Sure i could implement a getMethod for the model so that my command class can get it, but than i would again change the view class from the command class :-/

With a button i would just create a listener in the view and when the dialog to add a new project is closed i would get the new project from the dialog and add it to the model in the view, but with a command that isn't possible Sad
Previous Topic:auto saving preferences
Next Topic:Problem with the RCP Texteditor example
Goto Forum:
  


Current Time: Tue Sep 16 23:46:52 GMT 2014

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

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