Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Programmactically Change Application Window Title (Text) at Runtime...
Programmactically Change Application Window Title (Text) at Runtime... [message #463817] Thu, 15 February 2007 18:31 Go to next message
Eclipse UserFriend
Originally posted by: games.insight.com

Hi Everyone,

My application modifies an underlying master document. I would like to
include the File Name / Path as part of the Application window title. I
tried to access the ApplicationWorkbenchWindowAdvisor without success. I got
a thread violation.

Can anyone give a tip on how to do this.

Thanks in advance
-Gene
Re: Programmactically Change Application Window Title (Text) at Runtime... [message #463829 is a reply to message #463817] Fri, 16 February 2007 05:27 Go to previous messageGo to next message
Eclipse UserFriend
thread violation always means that you tried to access SWT resources
from a none GUI-Thread. Have you tried to use Display#asyncExec()? The
easiest thing to change the title is I think:

--------------8<--------------
Display.asyncExec( new Runnable() {
public void run() {

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().setText()
}
}
--------------8<--------------

Tom

Gene Ames schrieb:
> Hi Everyone,
>
> My application modifies an underlying master document. I would like to
> include the File Name / Path as part of the Application window title. I
> tried to access the ApplicationWorkbenchWindowAdvisor without success. I got
> a thread violation.
>
> Can anyone give a tip on how to do this.
>
> Thanks in advance
> -Gene
>
>
Re: Programmactically Change Application Window Title (Text) at Runtime... [message #463852 is a reply to message #463829] Fri, 16 February 2007 17:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: games.insight.com

Tom,

Thanks for the tip. This works great!!

For the benefit of others who may read this thread, what I had to do is
expose the Display object that is created by my IPlatformRunnable
implementation:
/**
* This class controls all aspects of the application's execution
*/
public class Application implements IPlatformRunnable {
// Member Variables
private static Application instance = null;
private Display display = null;

// Default Constructor Override
public Application(){
instance = this;
}

/**
* Single access getter for the IPlatformRunnable object
*/
public static Application getInstance(){
return instance;
}

public Object run(Object args) throws Exception {
// Local Variables
this.display = PlatformUI.createDisplay();

// Initialize Display & State Service
try{
// Start Up...
int returnCode =
PlatformUI.createAndRunWorkbench(display, new
ApplicationWorkbenchAdvisor());
if(returnCode == PlatformUI.RETURN_RESTART){
return IPlatformRunnable.EXIT_RESTART;
}
else{
return IPlatformRunnable.EXIT_OK;
}
}
finally{
// Clean Up
display.dispose();
}
}

/**
* Getter for Display object UI object
*/
public Display getDisplay(){
return this.display;
}
}

Then to use this per Tom's recommendation, I implemented this to set the
Application Window text dynamically at runtime:

// Change App Window Title
Application.getInstance().getDisplay().asyncExec( new Runnable() {
public void run() {
try {
StringBuffer titleBuffer = new
StringBuffer(DefinitionsPlugin.getResourceString("application.title "));
titleBuffer.append(" - ");
titleBuffer.append(DefinitionsFileDAO.getInstance().getFileN ame());
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().setText(titleBuffer.toString());
}
catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

Thanks again Tom...

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:er40t2$37b$1@utils.eclipse.org...
> thread violation always means that you tried to access SWT resources from
> a none GUI-Thread. Have you tried to use Display#asyncExec()? The easiest
> thing to change the title is I think:
>
> --------------8<--------------
> Display.asyncExec( new Runnable() {
> public void run() {
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().setText()
> }
> }
> --------------8<--------------
>
> Tom
>
> Gene Ames schrieb:
>> Hi Everyone,
>>
>> My application modifies an underlying master document. I would like to
>> include the File Name / Path as part of the Application window title. I
>> tried to access the ApplicationWorkbenchWindowAdvisor without success. I
>> got a thread violation.
>>
>> Can anyone give a tip on how to do this.
>>
>> Thanks in advance
>> -Gene
Re: Programmactically Change Application Window Title (Text) at Runtime... [message #463860 is a reply to message #463852] Sat, 17 February 2007 06:47 Go to previous message
Eclipse UserFriend
Hi,

why the hell do you have to remember the display in an variable. That's
not needed, a call like
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().getDisplay().asyncExec(...
would be sufficient in your code!

Tom

Gene Ames schrieb:
> Tom,
>
> Thanks for the tip. This works great!!
>
> For the benefit of others who may read this thread, what I had to do is
> expose the Display object that is created by my IPlatformRunnable
> implementation:
> /**
> * This class controls all aspects of the application's execution
> */
> public class Application implements IPlatformRunnable {
> // Member Variables
> private static Application instance = null;
> private Display display = null;
>
> // Default Constructor Override
> public Application(){
> instance = this;
> }
>
> /**
> * Single access getter for the IPlatformRunnable object
> */
> public static Application getInstance(){
> return instance;
> }
>
> public Object run(Object args) throws Exception {
> // Local Variables
> this.display = PlatformUI.createDisplay();
>
> // Initialize Display & State Service
> try{
> // Start Up...
> int returnCode =
> PlatformUI.createAndRunWorkbench(display, new
> ApplicationWorkbenchAdvisor());
> if(returnCode == PlatformUI.RETURN_RESTART){
> return IPlatformRunnable.EXIT_RESTART;
> }
> else{
> return IPlatformRunnable.EXIT_OK;
> }
> }
> finally{
> // Clean Up
> display.dispose();
> }
> }
>
> /**
> * Getter for Display object UI object
> */
> public Display getDisplay(){
> return this.display;
> }
> }
>
> Then to use this per Tom's recommendation, I implemented this to set the
> Application Window text dynamically at runtime:
>
> // Change App Window Title
> Application.getInstance().getDisplay().asyncExec( new Runnable() {
> public void run() {
> try {
> StringBuffer titleBuffer = new
> StringBuffer(DefinitionsPlugin.getResourceString("application.title "));
> titleBuffer.append(" - ");
> titleBuffer.append(DefinitionsFileDAO.getInstance().getFileN ame());
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().setText(titleBuffer.toString());
> }
> catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> });
>
> Thanks again Tom...
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:er40t2$37b$1@utils.eclipse.org...
>> thread violation always means that you tried to access SWT resources from
>> a none GUI-Thread. Have you tried to use Display#asyncExec()? The easiest
>> thing to change the title is I think:
>>
>> --------------8<--------------
>> Display.asyncExec( new Runnable() {
>> public void run() {
>>
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l().setText()
>> }
>> }
>> --------------8<--------------
>>
>> Tom
>>
>> Gene Ames schrieb:
>>> Hi Everyone,
>>>
>>> My application modifies an underlying master document. I would like to
>>> include the File Name / Path as part of the Application window title. I
>>> tried to access the ApplicationWorkbenchWindowAdvisor without success. I
>>> got a thread violation.
>>>
>>> Can anyone give a tip on how to do this.
>>>
>>> Thanks in advance
>>> -Gene
>
>
Previous Topic:Creating View by Dragging the Leaf of theTree and Dropping it in the Editor Area
Next Topic:ErrorDialog.openError() doesn't do anythiing in ActionDelegate class
Goto Forum:
  


Current Time: Tue Mar 18 01:02:40 EDT 2025

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

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

Back to the top