Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to dynamically set the View Part Name and Content
How to dynamically set the View Part Name and Content [message #630174] Thu, 30 September 2010 21:33 Go to next message
Jean Bovet is currently offline Jean BovetFriend
Messages: 34
Registered: September 2009
Member
Hi,

The situation I am facing is the following: I need to dynamically
create one or more views where each view displays a different content
(1) and have a different title (2). The number of views and their title
is known only at runtime and may be different between each restart of
the application.

I've read many posts about that subject (e.g. "How to dynamically set
View Part Name before it is activated") but haven't found a solution
that works 100% without some hacks.

I solved problem (1) by using the secondary view ID to display a
different content for each view. However, I am stuck with problem (2):
how to set the name of each view when they are displayed? I can use
setPartName() in createControlPart() but this won't work for the views
that are not created yet (the workbench will display the name defined
in the extension until the user clicks on the view title to make it
active). I tried to follow the suggestion in the thread "How to
dynamically set View Part Name before it is activated" but there I am
facing a problem upon restart: the window is gray and no views is
displayed (if I delete the workspace data and restart it works again).

Does anyone know a good solution to solve this problem? Any help would
be appreciated.

Regards,

Jean
Re: How to dynamically set the View Part Name and Content [message #900823 is a reply to message #630174] Wed, 08 August 2012 15:45 Go to previous messageGo to next message
David Casas is currently offline David CasasFriend
Messages: 58
Registered: November 2011
Location: Barcelona
Member

Hi,

I am sorry I am maybe too late, but I want to post the solution for other people who wants to know how to do it.

You have two options... one could be with an action like this:

private Action changeTitleAction = new Action() {
		public void run() {
			String title = getPartName();
			ChangeTitleDialog dialog = new ChangeTitleDialog(getViewSite().getShell(), title);
			if (dialog.open() == org.eclipse.jface.window.Window.OK) {
				changePartName(dialog.getTitle());
			}
		}

		public String getText() {
			return Messages.lblChangeTitle;
		};

		public org.eclipse.jface.resource.ImageDescriptor getImageDescriptor() {
			return null;

		};
	}

public void changePartName(String name) {
		setPartName(name);
		Display.getCurrent().update();
	};
;


or yout could dinamically change the ViewPart name with

setPartName(name);
Display.getCurrent().update();


once the view is initialited.

Hope that helps Wink
Re: How to dynamically set the View Part Name and Content [message #900824 is a reply to message #900823] Wed, 08 August 2012 15:47 Go to previous message
David Casas is currently offline David CasasFriend
Messages: 58
Registered: November 2011
Location: Barcelona
Member

I forgot to say that I put the name in a field in my constructor, but mine maybe is simpler because I just modify a number at the end of the title...
Previous Topic:Get selected project name when action is executed
Next Topic:Allow to rearrange views inside of one area only?
Goto Forum:
  


Current Time: Sat Nov 09 02:03:13 GMT 2024

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

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

Back to the top