4

I'm trying to update the title of a view (ie : the text displayed in the tab) programmatically.

When i do that :

view.setPartName(newTitle);

The view name is well updated but the UI is not. So how can i do that ?

Thank you in advance!

l1sq0u48
  • 371
  • 2
  • 12
  • @david & @Duncan Krebs : You are both right! We must call the `setPartname`method inside the `init` method. So, to fix my issue, i used a special object which store the name of my `IViewPart` and I retrieve this one in the `init` method of my `IViewPart`! Thanks a lot for both of you – l1sq0u48 Nov 22 '12 at 11:17

2 Answers2

9

You need to make sure you are setting partName in the correct init method and that you make a call to super before setting part name like this. I know this example works pasted from my app.

@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    String scannerName = site.getSecondaryId();
    setPartName("MyName");
}
Duncan Krebs
  • 3,366
  • 2
  • 33
  • 53
2

I'm updating a view's title without a problem ... when are you invoking the setPartName method?

In my class, which extends ViewPart, I'm invoking the setPartName method in the init method.

David G
  • 3,940
  • 1
  • 22
  • 30
  • The problem is i call the `setPartName` method outside the `ViewPart`. – l1sq0u48 Nov 21 '12 at 17:14
  • How are you calling the setPartName method? It's protected. At least as far as I can tell. http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/part/ViewPart.html#setPartName(java.lang.String) – David G Nov 21 '12 at 17:26
  • In my `ViewPart` class,I wrote a public method called `changePartName(String newName)` which calls the `setPartName` method. And I use my method `changePartName` elsewhere. – l1sq0u48 Nov 21 '12 at 18:14
  • I dug into the WorkbenchPart code and noticed that, when the content description method is invoked, they fire the `IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION` event. Maybe you can do something similar in your changePartName method? – David G Nov 21 '12 at 18:42
  • Unfortunately, this solution does not work... I tried both `firePropertyChange(IWorkbenchPartConstants.PROP_PART_NAME);` and `firePropertyChange(IWorkbenchPart.PROP_TITLE);` – l1sq0u48 Nov 22 '12 at 10:14