Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to use dialog in e4 application model
How to use dialog in e4 application model [message #1749638] Thu, 08 December 2016 23:35 Go to next message
Ken Keefe is currently offline Ken KeefeFriend
Messages: 23
Registered: April 2012
Junior Member
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 #1749694 is a reply to message #1749638] Fri, 09 December 2016 18:58 Go to previous messageGo to next message
Ken Keefe is currently offline Ken KeefeFriend
Messages: 23
Registered: April 2012
Junior Member
Ok, I've made a little progress. I can now get the dialog to appear once with this code.

@Execute
	public void execute(MApplication application, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
		for(MDialog d : application.getDialogs()) {
			if("dialog.appPreferences".equals(d.getElementId())) {
				application.getChildren().remove(d);
				application.getChildren().add(d);
				d.setVisible(true);
				break;
			}
		}
		
	}


However, when I close the dialog and run this handler again, it doesn't reappear. I'm closing it by clicking the X button in the corner of the window. The first time this code runs, the dialog is in the application's dialogs collection, but not in its children. Adding it to the children seems to make it appear. The second time this code is executed, the dialog is still in the application's children collection. I was hoping that by removing it and adding it back that it would appear. But, no luck.

Am I doing this correctly? How do I get the dialog to reappear?

Thanks!
Re: How to use dialog in e4 application model [message #1749818 is a reply to message #1749694] Mon, 12 December 2016 20:23 Go to previous message
Ken Keefe is currently offline Ken KeefeFriend
Messages: 23
Registered: April 2012
Junior Member
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.
Previous Topic:e4xmi view class uri
Next Topic:Indent by spaces, move by tabs
Goto Forum:
  


Current Time: Fri Nov 24 00:16:47 GMT 2017

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

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