Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Dynamically changing the label of a Part
Dynamically changing the label of a Part [message #948911] Thu, 18 October 2012 14:04 Go to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
Hello!

How do i change the label of a Part dynamically?

I tried to retrieve the MPart via injection or via the EPartService, and call setLabel() on it. It worked but the change was not reflected on the rendered part. How do i update the rendered part to apply the model change?

My Part contains a CTabFolder, and i would like to set the active tab's text as the Part label:

	public void showTab(String tab) {
		CTabItem item = tabs.get(tab);
		if (item != null) {
			tabFolder.setSelection(item);
			createContentsForActiveTab();
			partService.findPart(PART_ID).setLabel(item.getText());
		}
	}


Thanks!
Re: Dynamically changing the label of a Part [message #948939 is a reply to message #948911] Thu, 18 October 2012 14:32 Go to previous messageGo to next message
Eclipse UserFriend
Are you in a handler? Try injecting the MPart directly.
Re: Dynamically changing the label of a Part [message #948962 is a reply to message #948939] Thu, 18 October 2012 14:54 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
I'm in the part implementation itself.
Re: Dynamically changing the label of a Part [message #948996 is a reply to message #948962] Thu, 18 October 2012 15:30 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Try something like this:
public class PartOne {
	@Inject private MPart part;
	public void setPartLabel(String label) {
		part.setLabel(label);
	}
	
	...
}
Re: Dynamically changing the label of a Part [message #949636 is a reply to message #948996] Fri, 19 October 2012 06:28 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
Just figured out what the problem is. If i run the code from a handler, it works perfectly. I guess the framework can detect the change after running the handler. The only problem is that i need to change the label not only from a handler. There is a SelectionListener bound to the CTabFolder i use in the part, and the label change is triggered from there.

Is there any way to manually tell the framework to scan for model changes and apply them?
Re: Dynamically changing the label of a Part [message #949678 is a reply to message #949636] Fri, 19 October 2012 07:26 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
The framework will listen to model changes and apply them. Like Sopot said, you should inject the MPart directly into your contribution class.

Try this example:

public class MyPart {
	
	@Inject private MPart part;
	
	@PostConstruct
	public void postConstruct(Composite parent) {
		final Text text = new Text(parent, SWT.MULTI);
		text.setText("New Part Label");
		final Button btn = new Button(parent, SWT.PUSH);
		btn.setText("Change Part Label");
		btn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				part.setLabel(text.getText());
			}
		});
	}
	
}
Previous Topic:Creating menu items at runtime
Next Topic:Problem with events and lazy part rendering
Goto Forum:
  


Current Time: Fri Apr 19 11:21:08 GMT 2024

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

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

Back to the top