|
|
|
| Re: Starting command at startup [message #902792 is a reply to message #902613] |
Mon, 20 August 2012 09:23   |
Joseph Carroll Messages: 156 Registered: May 2012 Location: Milwaukee, WI |
Senior Member |

|
|
The main problem I see is that you want to be aware of something that the model doesn't know about (there isn't a "shell" model object). The workbench is aware of the shell, so once you are operating within the workbench you can have a shell injected, however, this is purely convenience.
The way you can accomplish this (albeit a hack), is to listen for the creation of a workbench window. You would still want to use the life-cycle hook @PostContextCreate (or @ProcessAdittions doesn't matter), but only you would register an event handler with the event admin on the topic UIEvents.Window.TOPIC_ALL and look for the create event (testable through the method isCREATE). Then you would be able to get the active shell (atleast in theory). Once you have executed your code, I would recommend removing your listener from the event admin service.
I'll double check later today to make sure this works. The one issue you may run into is the selection service may not have been populated at this point. IF that is the case, I would believe that to be a bug, but as I said that would be the one caveat that might creep up.
I'll try to model this myself later today and post.
JD
|
|
|
| Re: Starting command at startup [message #902807 is a reply to message #902792] |
Mon, 20 August 2012 10:36   |
Christoph Keimel Messages: 277 Registered: December 2010 Location: Germany |
Senior Member |
|
|
Another possibility is to create an AddOn. We have an Addon that maximizes the shell when a MWindow gets created. The EventHandler is only added when a specific Argument is passed to the application:
public class MaximizeAddon {
@SuppressWarnings("unused")
private Logger logger = LoggerFactory.getLogger(MaximizeAddon.class);
public static final String APP_ARG_MAXIMIZE = "-maximize";
private EventHandler handler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (!UIEvents.isSET(event))
return;
Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(objElement instanceof MWindow))
return;
MWindow windowModel = (MWindow) objElement;
windowModel.getTags().add("shellMaximized");
}
};
@PostConstruct
public void init(IEventBroker eventBroker, IEclipseContext context) {
if (Arrays.asList(Platform.getApplicationArgs()).contains(APP_ARG_MAXIMIZE)) {
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, handler);
}
}
@PreDestroy
public void dispose(IEventBroker eventBroker) {
if (Arrays.asList(Platform.getApplicationArgs()).contains(APP_ARG_MAXIMIZE)) {
eventBroker.unsubscribe(handler);
}
}
}
Greetings
Christoph
[Updated on: Fri, 24 August 2012 05:53] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02299 seconds