Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Filemenu popup within GMF
Filemenu popup within GMF [message #1007178] Mon, 04 February 2013 19:00 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hello,

I've created a GMF Editor which works fine so far.
What I want to do now is implementing a popup which opens when an user clicks on a node. This popup should realise some kind of a file manager, like the attached immage. The user should be able to choose a file somewhere from the drive and then the file path should be stored as an String attribute in the gmf model.
Hope you understand what I mean. Is there any chance to realise something like that? Maybe eclipse provide some support.

[Updated on: Tue, 05 February 2013 10:45]

Report message to a moderator

Re: Filemneu popup within GMF [message #1007231 is a reply to message #1007178] Tue, 05 February 2013 07:14 Go to previous messageGo to next message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
Hello Phil

You may try it with an OpenEditPolicy (http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/org.eclipse.gmf.doc/reference/api/runtime/org/eclipse/gmf/runtime/diagram/ui/editpolicies/OpenEditPolicy.html) and then open a FileDialog (http://www.vogella.com/articles/EclipseDialogs/article.html#tutorialswt).

I think this could work, but no guarantee Wink
Re: Filemenu popup within GMF [message #1007301 is a reply to message #1007178] Tue, 05 February 2013 12:53 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Thx so far! I searched a lot, but I couldn't find a good tutorial which explains the use of OpenEditPolicy from scratch. I've no idea where to implement my own OpenEditPolicy in this whole mess of generated classes. Can someone give me a hint? Is it possible to realise this outside the generated code, since I using Eugenia for generating the code?
Re: Filemenu popup within GMF [message #1007397 is a reply to message #1007301] Tue, 05 February 2013 17:51 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I'm now able to open a filedailog and read out the filepath. Furthermore I can acces my Element. But when I try to assign the filepath to an attribute, i get the following error:

java.lang.IllegalStateException: Cannot modify resource set without a write transaction


I already read about using an ICommandProxy to overcome this, bute I've no Idea how to use this in my case. Any suggestions?

public class MyOpenEditPolicy extends OpenEditPolicy {

	protected Command getOpenCommand(final Request request) {

		return new Command() {
			public void execute() {
				EditPart targetEditPart = getTargetEditPart(request);
				if (targetEditPart instanceof IGraphicalEditPart) {
					IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) targetEditPart;
					if (graphicalEditPart.getModel() instanceof View) {
						View view = (View) graphicalEditPart.getModel();
						if (view.getElement() instanceof Feature) {
							Feature feature = (Feature) view.getElement();
							Shell shell = Display.getCurrent().getActiveShell();
							FileDialog fileDialog = new FileDialog(shell);
							fileDialog.setText("Select an EFVM File");
							fileDialog
									.setFilterExtensions(new String[] { "*.efvm" });
							fileDialog
									.setFilterNames(new String[] { "*.efvm" });
							if (fileDialog.open() != null) {
								String selected = fileDialog.open();
								System.out.println("file: "
										+ feature.getFilepath());
								// feature.setFilepath(selected);
							}
						}
					}
				}

			}
		};
	}
}
Re: Filemenu popup within GMF [message #1007541 is a reply to message #1007397] Wed, 06 February 2013 11:10 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

all you need to do is get the EditDomain from the editpart then get its command stack and execute a EMF SetCommand on that stack. You can use SetCommand.Create(...) to create a new SetCommand.

Ralph

[Updated on: Wed, 06 February 2013 11:12]

Report message to a moderator

Re: Filemenu popup within GMF [message #1007559 is a reply to message #1007541] Wed, 06 February 2013 13:29 Go to previous messageGo to next message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
Here is an example:

// SetRequest and Command
int x = 4711;
EObject element = // your element with the attribute to set

TransactionalEditingDomain editingDomain = this.getEditingDomain();
SetRequest setRequestX = new SetRequest(editingDomain, element, XYZPackage.eINSTANCE.getYOURATTRIBUTE(), x);
SetValueCommand setX = new SetValueCommand(setRequestX);

try {
	setX.execute(null, null);
} catch (ExecutionException e) {
	e.printStackTrace();
}


I hope it also works for you Wink
Re: Filemenu popup within GMF [message #1007586 is a reply to message #1007178] Wed, 06 February 2013 15:19 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Big thx Daniel and Ralph, it's working now like ecpected Smile
Re: Filemenu popup within GMF [message #1036758 is a reply to message #1007586] Mon, 08 April 2013 19:22 Go to previous messageGo to next message
Simon Zutterman is currently offline Simon ZuttermanFriend
Messages: 28
Registered: October 2012
Junior Member
Hey Phil,

I'd also really like to implement something like this in my editor, but even with the previous posts, I don't have a clue how.

As I would like it, I would have a node with a normal feature name label, but in the metamodel with a second attribute (filepath), if you double click on the node in the editor, you get the file manager popup, select a file on your drive and the filepath would be stored in the attribute, displayed in the properties view.

It would be a massive help and I would be eternally grateful if you could give me a more detailed explanation on how to do this! Or if you were willing, post me your project files so i can sort it out myself?

regards,

Simon
Re: Filemenu popup within GMF [message #1052645 is a reply to message #1007178] Tue, 30 April 2013 10:47 Go to previous message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Simon,

sry I just noticed your post now.

In your diagram edit.part package you should have a generated class for your node (called NameOfYourNodeEditPart). In your method createDefaultEditPolicies() you have to install your own created EditPolicy. In my case I just added:

installEditPolicy(EditPolicyRoles.OPEN_ROLE,new FilePathOpenEditPolicy());


The mentioned policy class looks like this:

public class FilePathOpenEditPolicy extends OpenEditPolicy {

	protected Command getOpenCommand(final Request request) {

		return new Command() {
			public void execute() {
				EditPart targetEditPart = getTargetEditPart(request);
				if (targetEditPart instanceof IGraphicalEditPart) {
					IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) targetEditPart;
					TransactionalEditingDomain editingDomain = graphicalEditPart.getEditingDomain();
					if (graphicalEditPart.getModel() instanceof View) {
						View view = (View) graphicalEditPart.getModel();
						if (view.getElement() instanceof Feature) {
							Feature feature = (Feature) view.getElement();
							Shell shell = Display.getCurrent().getActiveShell();
							FileDialog fileDialog = new FileDialog(shell);
							fileDialog.setText("Select an EFVM File");
							fileDialog.setFilterExtensions(new String[] { "*.efvm" });
							fileDialog.setFilterNames(new String[] { "*.efvm" });
							try {
								String path = fileDialog.open();
								if (!path.isEmpty()) {
									SetRequest setRequestX = new SetRequest(editingDomain, feature,PldPackage.eINSTANCE.getFeature_FilePath(),path);
									SetValueCommand setX = new SetValueCommand(setRequestX);
									setX.execute(null, null);
								}
							} catch (Exception e) {
								MessageDialog.openWarning(shell, "Warning",
										"No efvm file has been selected!");
								// e.printStackTrace();
							}
						}
					}
				}
			}
		};
	}
}


Hope this helps.

Cheers,
Phil
Previous Topic:What is the best code practice to modify the domain model on diagram loading?
Next Topic:Problem with diagram initialization
Goto Forum:
  


Current Time: Fri Apr 19 08:31:27 GMT 2024

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

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

Back to the top