How to use dialog in e4 application model [message #1749638] |
Thu, 08 December 2016 18:35  |
Eclipse User |
|
|
|
I'm trying to figure out how to use a dialog that I've defined in my application model. Google is not providing a solution. The only thing I'm finding on the web is examples like this:
http://www.asegno.com/2015/eclipse/tutorial-create-login-dialog-for-your-eclipse-e4-application/
But that explains how to use a Dialog that is fully defined in code. I want to use a dialog that I have specified in my Application.dialogs feature of the application model.
So far, I'm able to get a hold of my MDialog like this:
@Execute
public void execute(MApplication application, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
for(MDialog d : application.getDialogs()) {
if("dialog.appPreferences".equals(d.getElementId())) {
// SOME CODE TO OPEN THE DIALOG
break
}
}
}
But, I can't figure out what code to put in the if statement to cause the dialog window to appear.
|
|
|
|
Re: How to use dialog in e4 application model [message #1749818 is a reply to message #1749694] |
Mon, 12 December 2016 15:23  |
Eclipse User |
|
|
|
After much experimenting and digging on the web, I came up with a solution that works. I still haven't found a concrete way for opening and reopening windows that are defined in the application model xmi. Hopefully, the way I am doing it is a good and stable way.
First, I had to move my Dialog XMI from Application.dialogs to Application.snippets. I did this with a model fragment, but it could be done directly in Application.e4xmi. Anyway, once my Dialog was living under Application.snippets, this code allowed me to open the dialog every time it was executed:
@Execute
public void execute(MApplication application, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, EModelService modelService) {
MUIElement dia = modelService.cloneSnippet(application, "dialog.appPreferences", null);
if(dia instanceof MDialog) {
MDialog d = (MDialog) dia;
Monitor mon = shell.getMonitor();
Rectangle monitorRect = mon.getBounds();
d.setX(monitorRect.x + (monitorRect.width - d.getWidth())/2);
d.setY(monitorRect.y + (monitorRect.height - d.getHeight())/2);
application.getChildren().add(d);
d.setOnTop(true);
}
}
The shell argument and the lines that set the X and Y of the dialog are obviously optional, but it is useful for centering the dialog on the screen.
|
|
|
Powered by
FUDForum. Page generated in 0.03548 seconds