Programmactically Change Application Window Title (Text) at Runtime... [message #463817] |
Thu, 15 February 2007 18:31  |
Eclipse User |
|
|
|
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 #463860 is a reply to message #463852] |
Sat, 17 February 2007 06:47  |
Eclipse User |
|
|
|
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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.05150 seconds