|
Re: Using an operation to change the style of elements in my model using an action call/operation [message #1841660 is a reply to message #1841566] |
Tue, 25 May 2021 07:40 |
|
Hi,
You can use the java action. Here is an example of code to change the border of a container:
org.eclipse.sirius.diagram.DDiagramElementContainer myContainer = AAA;
org.eclipse.sirius.diagram.ContainerStyle containerStyle = myContainer.getOwnedStyle();
org.eclipse.sirius.diagram.LineStyle newBorderLineStyle = LineStyle.BBB;
int newBorderSize = CCC;
containerStyle.setBorderSize(newBorderSize);
containerStyle.setBorderLineStyle(newBorderLineStyle);
// You hava to add the changed features to the "custom features" list to avoid that your changes are "deleted" at the next refresh.
containerStyle.getCustomFeatures().add(DiagramPackage.eINSTANCE.getBorderedStyle_BorderSize().getName());
containerStyle.getCustomFeatures().add(DiagramPackage.eINSTANCE.getBorderedStyle_BorderLineStyle().getName());
Regards,
Laurent Redor - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: Using an operation to change the style of elements in my model using an action call/operation [message #1841686 is a reply to message #1841660] |
Tue, 25 May 2021 17:10 |
Thomas Chiang Messages: 104 Registered: March 2020 |
Senior Member |
|
|
For an element that isn't a container what is the command instead of getOwnedStyle()?
Also where can I find the whole example, it looks like there is no declaration of BBB or LineStyle so the line:
org.eclipse.sirius.diagram.LineStyle newBorderLineStyle = LineStyle.BBB;
Spits out an error of undeclared variables.
One more thing to note is that I run into this error whenever I try to declare a variable as type DDiagramElement*:
Caused by: java.lang.ClassCastException: class wFP_V2.impl.Data_ElementImpl cannot be cast to class org.eclipse.sirius.diagram.DDiagramElement (wFP_V2.impl.Data_ElementImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @70161b7c; org.eclipse.sirius.diagram.DDiagramElement is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1478f7ec)
I have everything imported correctly I think so I'm not sure how to resolve this class error.
The full error message that I receive is:
!ENTRY org.eclipse.gmf.runtime.diagram.ui 4 4 2021-05-25 14:03:46.150
!MESSAGE execute
!STACK 0
org.eclipse.core.commands.ExecutionException: While executing the operation, an exception occurred
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:504)
at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramCommandStack.execute(DDiagramCommandStack.java:73)
at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramCommandStack.execute(DDiagramCommandStack.java:54)
at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:157)
at org.eclipse.sirius.diagram.ui.tools.internal.menu.PopupMenuContribution$1.run(PopupMenuContribution.java:423)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4026)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3626)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
at org.eclipse.equinox.launcher.Main.run(Main.java:1461)
at org.eclipse.equinox.launcher.Main.main(Main.java:1434)
Caused by: java.lang.ClassCastException: class wFP_V2.impl.Data_ElementImpl cannot be cast to class org.eclipse.sirius.diagram.DDiagramElement (wFP_V2.impl.Data_ElementImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @70161b7c; org.eclipse.sirius.diagram.DDiagramElement is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1478f7ec)
at WFP.design.myAction.execute(myAction.java:64)
at org.eclipse.sirius.tools.api.command.view.JavaActionFromToolCommand.doExecute(JavaActionFromToolCommand.java:95)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.emf.common.command.CompoundCommand.execute(CompoundCommand.java:261)
at org.eclipse.sirius.diagram.ui.tools.api.command.GMFCommandWrapper.doExecuteWithResult(GMFCommandWrapper.java:104)
at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:248)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
at org.eclipse.sirius.diagram.ui.tools.internal.commands.WrappingCommandIgnoringAffectedFiles.execute(WrappingCommandIgnoringAffectedFiles.java:125)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:496)
[Updated on: Tue, 25 May 2021 18:08] Report message to a moderator
|
|
|
Re: Using an operation to change the style of elements in my model using an action call/operation [message #1841694 is a reply to message #1841660] |
Tue, 25 May 2021 20:03 |
Thomas Chiang Messages: 104 Registered: March 2020 |
Senior Member |
|
|
Also if it helps here is my code where I am trying to type cast from one of my defined types to the DDiagramElement type:
public EList forwardImpactAnalysis() {
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
EList<? extends Input> inputs = getInput();
Iterator<? extends Input> itInput = inputs.iterator();
while (itInput.hasNext()) {
Input nextInput = itInput.next();
EList<? extends Output> outputs = nextInput.getTgt().getOutput();
Iterator<? extends Output> itOutput = outputs.iterator();
EList<Data_Element> dataOutputs = new BasicEList();
while (itOutput.hasNext()) {
Output nextOutput = itOutput.next();
dataOutputs.add((Data_Element) nextOutput.getTgt());
DDiagramElement myElement = (DDiagramElement) nextOutput;
System.out.println(myElement);
}
return (EList)dataOutputs;
}
//throw new UnsupportedOperationException();
EList empty = new BasicEList();
return empty;
}
The print statements are just there to help with debugging and understanding how a lot of these commands work and what their outputs are.
[Updated on: Tue, 25 May 2021 20:04] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03226 seconds