Skip to main content



      Home
Home » Eclipse Projects » Sirius » External Java Action to set a value
icon5.gif  External Java Action to set a value [message #1741058] Mon, 22 August 2016 10:48 Go to next message
Eclipse UserFriend
Hello there,

I hope you can help me with the following problem: I started from scratch using the BasicFamily example files. All went fine when importing. I modified the basicfamily.odesign in a way that when I double-click on a Man node a JFace Dialog is shown. Therefor I used a External Java Action having the following code:

package org.eclipse.sirius.sample.basicfamily.design.services;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.window.Window;
import org.eclipse.sirius.business.api.action.AbstractExternalJavaAction;
import org.eclipse.sirius.sample.basicfamily.BasicfamilyPackage;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
import org.eclipse.ui.PlatformUI;

public class Test extends AbstractExternalJavaAction implements IExternalJavaAction {

	@Override
	public boolean canExecute(Collection<? extends EObject> args) {
		return true;
	}

	@Override
	public void execute(Collection<? extends EObject> args, Map<String, Object> options) {
		MyTitleAreaDialog dialog = new MyTitleAreaDialog(
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
		dialog.create();
		if (dialog.open() == Window.OK) {
				EStructuralFeature feature =  object.eClass().getEStructuralFeature(BasicfamilyPackage.MAN__NAME);
				object.eSet(feature , (Object)dialog.getFirstName());
			}
		}
	}
}


The class MyTitleAreaDialog is pretty unspectular. It is a TitleAreaDialog and has a method getFirstName() which is called when the user presses the OK button and retrieves the firstname the user entered before.
As you can see I just want to set the name of the Man node I double clicked on with the value the user entered in the dialog, especially using this line:
object.eSet(feature , (Object)dialog.getFirstName());


When I do so i receive the following ClassCastException pointing to that single line:
Quote:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.emf.ecore.EObject
at org.eclipse.sirius.viewpoint.impl.DRepresentationElementImpl.eSet(DRepresentationElementImpl.java:259)
at org.eclipse.sirius.diagram.impl.DDiagramElementImpl.eSet(DDiagramElementImpl.java:348)
at org.eclipse.sirius.diagram.impl.DNodeImpl.eSet(DNodeImpl.java:734)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
at org.eclipse.sirius.sample.basicfamily.design.services.Test.execute(Test.java:48)
at org.eclipse.sirius.business.internal.helper.task.operations.ExternalJavaActionTask.execute(ExternalJavaActionTask.java:93)
at org.eclipse.sirius.business.internal.helper.task.ExecuteToolOperationTask.executeTask(ExecuteToolOperationTask.java:106)
at org.eclipse.sirius.business.internal.helper.task.ExecuteToolOperationTask.executeTask(ExecuteToolOperationTask.java:117)
at org.eclipse.sirius.business.internal.helper.task.ExecuteToolOperationTask.execute(ExecuteToolOperationTask.java:90)
at org.eclipse.sirius.business.api.helper.task.TaskExecutor.execute(TaskExecutor.java:64)
at org.eclipse.sirius.tools.api.command.SiriusCommand.doExecute(SiriusCommand.java:80)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.sirius.diagram.ui.tools.api.command.GMFCommandWrapper.doExecuteWithResult(GMFCommandWrapper.java:102)
at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:247)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
at org.eclipse.sirius.diagram.ui.tools.internal.commands.WrappingCommandIgnoringAffectedFiles.execute(WrappingCommandIgnoringAffectedFiles.java:124)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
... 41 more


Can someone please give me a hint what I do wrong? Is there maybe another even more easier way to set an attribute's value of a node that has been visually created before?

Thanks in advance!

Best
Alex
Re: External Java Action to set a value [message #1741102 is a reply to message #1741058] Tue, 23 August 2016 03:00 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I think that the "object" in your service is not the Man but the DDiagramElement associated to the Man. You can see that in the stack

DRepresentationElementImpl.eSet(DRepresentationElementImpl.java:259)
.
This corresponds to the code
        case ViewpointPackage.DREPRESENTATION_ELEMENT__TARGET:
            setTarget((EObject) newValue);


You must replace the lines
EStructuralFeature feature =  object.eClass().getEStructuralFeature(BasicfamilyPackage.MAN__NAME);
object.eSet(feature , (Object)dialog.getFirstName());

By something like
Man aMan = (Man) ((DDiagramElement) object).getTarget();
EStructuralFeature feature =  aMan.eClass().getEStructuralFeature(BasicfamilyPackage.MAN__NAME);
aMan..eSet(feature , (Object)dialog.getFirstName());

or
Man aMan = (Man) ((DDiagramElement) object).getTarget();
aMan.setName(dialog.getFirstName());

or change your service call with the Man as parameter.

Regards,

Laurent
Re: External Java Action to set a value [message #1741113 is a reply to message #1741102] Tue, 23 August 2016 03:53 Go to previous messageGo to next message
Eclipse UserFriend
Dear Laurent,

thank you for your help.
I tried both of your suggestions, but both did not work. The class DDiagramElement is not recognizable by the framework. Even manually adding the import import org.eclipse.sirius.viewpoint.*; did not work, since it does not recognize the class. Do you have any idea how to fix this? Maybe I need to change the classpath somehow?

Another question:
Quote:
or change your service call with the Man as parameter.
How do I do that?

Thank you!

Best
Alex
Re: External Java Action to set a value [message #1741115 is a reply to message #1741113] Tue, 23 August 2016 04:01 Go to previous messageGo to next message
Eclipse UserFriend
For compilation problem, you have to add the plug-in org.eclipse.sirius in the dependencies of your plugin (in MANIFEST.MF file).

Re: External Java Action to set a value [message #1741117 is a reply to message #1741115] Tue, 23 August 2016 04:09 Go to previous messageGo to next message
Eclipse UserFriend
It is already added as shown in the screenshot. But in the exportet packages of the plugin org.eclipse.sirius, no org.eclipse.sirius.diagram or org.eclipse.sirius.viewpoint.DDiagramElement (as the special class) appears.
https://dl.dropboxusercontent.com/u/21492015/screen.PNG
I run out of ideas... Sad
Re: External Java Action to set a value [message #1741121 is a reply to message #1741117] Tue, 23 August 2016 04:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,

DDiagramElement/DDIagram come from org.eclipse.sirius.diagram plugin.
I see two solutions: add the dependency to this plugin or cast to DSemanticDecorator which comes from org.eclipse.sirius and the Sirius core metamodel. It is the supertype of DDiagramElement which declares the target reference.

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

Re: External Java Action to set a value [message #1741123 is a reply to message #1741117] Tue, 23 August 2016 04:28 Go to previous messageGo to next message
Eclipse UserFriend
Alex B. wrote on Tue, 23 August 2016 10:09
It is already added as shown in the screenshot. But in the exportet packages of the plugin org.eclipse.sirius,


Oops, sorry, the plug-in to import is org.eclipse.sirius.diagram (as said by Maxime).
Re: External Java Action to set a value [message #1741130 is a reply to message #1741123] Tue, 23 August 2016 05:15 Go to previous messageGo to next message
Eclipse UserFriend
Dear Maxime, dear Laurent,

thanks for your help. It worked now by adding the org.eclipse.sirius.diagram plugin, as both of you proposed.

Please allow me one more question. Is there any good documention on how to use the Sirius framework with EMF besides the specifier docs (https://www.eclipse.org/sirius/doc/specifier/Sirius%20Specifier%20Manual.html)?

Thank you!
Re: External Java Action to set a value [message #1741133 is a reply to message #1741130] Tue, 23 August 2016 05:36 Go to previous messageGo to next message
Eclipse UserFriend
Dear Alex,

You might find additional information in



Regards

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius






Re: External Java Action to set a value [message #1741177 is a reply to message #1741133] Tue, 23 August 2016 10:11 Go to previous message
Eclipse UserFriend
Thank you very much!
Previous Topic:Different containers for superclass and subclass
Next Topic:Properties tab refresh problem
Goto Forum:
  


Current Time: Fri Mar 21 23:46:16 EDT 2025

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

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

Back to the top