Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » how to configure Application Title at runtime?
how to configure Application Title at runtime? [message #460036] Tue, 12 December 2006 03:14 Go to next message
Eclipse UserFriend
as we all know, the title is configured by using
IWorkbenchWindowConfigurer.setTitle(String title)

but at runtime, how shall we get IWorkbenchWindowConfigurer to reset the
title?

Thanks

Chandler
Re: how to configure Application Title at runtime? [message #460040 is a reply to message #460036] Tue, 12 December 2006 04:21 Go to previous messageGo to next message
Eclipse UserFriend
Chandler wrote:

> as we all know, the title is configured by using
> IWorkbenchWindowConfigurer.setTitle(String title)
>
> but at runtime, how shall we get IWorkbenchWindowConfigurer to reset the
> title?

I've used the following technique:

public static void changeAppTitle(String newTitle) {
Display display = Display.getDefault();
if (display != null) {
// Look at all the shells and pick the first one
// that is a workbench window.
Shell shells[] = display.getShells();
for (int i = 0; i < shells.length; i++) {
Object data = shells[i].getData();
// Check whether this shell points to the Application main window's
shell:
if (data instanceof IWorkbenchWindow) {
shells[i].setText(newTitle);
break;
}
}
}
}

--
With best regards, Michael Spector
Re: how to configure Application Title at runtime? [message #460048 is a reply to message #460040] Tue, 12 December 2006 09:25 Go to previous messageGo to next message
Eclipse UserFriend
I've used a different method, that I *think* is safer, but requires setting up a suitable
listener-mechanism to respond to whatever it is that you want to have determine the new title; in my
case, it's a preference. I do it all in the WorkbenchWindowAdvisor, note calls to setTitle() in two
places:

MyWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor implements IPropertyChangeListener {
....
@Override
public void preWindowOpen() {
super.preWindowOpen();
_configurer = getWindowConfigurer();
<other code>
setTitle();
PreferencesImpl.store().addPropertyChangeListener(this);
}

public void propertyChange(final PropertyChangeEvent event) {
if (event.getProperty().equals(MY_PREFERENCE_KEY)) {
if (!event.getOldValue().equals(event.getNewValue())) {
setTitle();
}
}
}

protected void setTitle() {
final String title = computeNewTitleHoweverYouLike();
_configurer.setTitle(title);
}

protected IWorkbenchWindowConfigurer _configurer;
}

HTH,
Paul
Re: how to configure Application Title at runtime? [message #460075 is a reply to message #460040] Wed, 13 December 2006 01:36 Go to previous message
Eclipse UserFriend
Thanks a lot, I got the solution now:

I pass a WorkbenchWindow parameter into Action constructor when create
the instance in ActionBarAdvisor.

Then in the action, we can use window.getShell().setText()....

Michael Spector wrote:

>
> I've used the following technique:
>
> public static void changeAppTitle(String newTitle) {
> Display display = Display.getDefault();
> if (display != null) {
> // Look at all the shells and pick the first one
> // that is a workbench window.
> Shell shells[] = display.getShells();
> for (int i = 0; i < shells.length; i++) {
> Object data = shells[i].getData();
> // Check whether this shell points to the Application main window's
> shell:
> if (data instanceof IWorkbenchWindow) {
> shells[i].setText(newTitle);
> break;
> }
> }
> }
> }
>
Previous Topic:Automatic Updates and New Features
Next Topic:Add javadoc for context help to a plugin
Goto Forum:
  


Current Time: Mon Mar 17 21:51:18 EDT 2025

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

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

Back to the top