Starting command at startup [message #902496] |
Fri, 17 August 2012 22:48 |
|
Hi again,
I want to call a command at startup of application, which should open a specific shell anytime I'm starting my e4-application with a special command line argument.
Reading the arguments I've succeded, but where should I call the command itself?
The command is not implemented in the plugin, where I have defined my product in and I don't want any dependency from product-plugin to plugin which includes the command. Are there any lifecycle hooks available in this constellation?
Can you give me any best practice for this scenario?
Thanks by now
Markus
|
|
|
|
|
Re: Starting command at startup [message #902792 is a reply to message #902613] |
Mon, 20 August 2012 13:23 |
|
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 14:36 |
Christoph Keimel Messages: 482 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 09:53] Report message to a moderator
|
|
|
Re: Starting command at startup [message #903550 is a reply to message #902807] |
Fri, 24 August 2012 09:10 |
|
Hi Christoph,
just for reference, if you always want to maximize you could use the tag "shellMaximized" on the Window application model element.
I assume you know this already, but wanted to add this is someone else reads this thread.
Best regards, Lars
|
|
|
|
|
Re: Starting command at startup [message #908469 is a reply to message #908463] |
Wed, 05 September 2012 12:39 |
Eclipse User |
|
|
|
It may look complicated but taking a look at the e4 renderers will prove really useful. Investing an afternoon looking at them will save a lot of unnecessary pain.
I myself have seen this thing first with Lars when looking at the renderers' code. The e4 renderers (esp. Stack and Part) have lots of behavior tags that you can easily specify to the model and save yourself a lot of trouble. The bad thing is that they are poorly documented, or to better say they are not documented anywhere but in the code. Also Eric the guy who wrote most of the renderers doesn't hang out on the forums.
So my humble advice is to keep org.eclipse.e4.ui.workbench.renderers.swt in some remote place just for reference if something looks complicated. Truth is most of things are easy to achieve in e4 but we haven't had time to document them yet (except Lars' epic tutorials ).
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06485 seconds