Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Extract a subpart of the model to an XML file(I would like to extract some subparts of the model to a new XML file.)
Extract a subpart of the model to an XML file [message #1849353] Thu, 13 January 2022 13:16 Go to next message
Simon Tulia is currently offline Simon TuliaFriend
Messages: 14
Registered: January 2022
Junior Member
Hello all,

I created an .odesign project and I am able to create new items that I need. Now, I would like to extract some subparts of the model to a new XML file. For example, my model is just like below:
<?xml version:"1.0" encoding="UTF-8"?>
<mydomain:Model>
    <Element id="1">
    </Element>
    <Element id="2">
    </Element>
</mydomain:Model>


I need a separated XML file that contains only this part:
<?xml version:"1.0" encoding="UTF-8"?>
<Element id="1">
</Element>


So, I created an operation action menu in diagram and now I can call a Java service for the Element item. In that Java service, I want to create an XML file that contains only the Element item. It is possible to traverse items under Element and create my own XML file. However, I think maybe there is an already implemented method in Sirius libraries for this.

Thanks in advance.

Re: Extract a subpart of the model to an XML file [message #1849470 is a reply to message #1849353] Thu, 20 January 2022 23:23 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hi Simon,

Indeed, we have that functionality on Sirius. From the Model Explorer view, if you select a semantic element that is not at the root of your model, you have the contextual action "Control...". This will open a wizard that will lead you to create a sub-model where the selected semantic element is the root. The main model will reference the sub-model so the hierarchy is kept. The wizard will also ask you if you want to split the representations to a new representation file as well. Note that as the sub-model is of the same extension, you can export it in a new modeling project and work on it separatly.

If you still want to implement your own action to do this, you can have a look at the code of org.eclipse.sirius.business.internal.command.control.ControlCommand

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Extract a subpart of the model to an XML file [message #1849628 is a reply to message #1849470] Thu, 27 January 2022 11:29 Go to previous message
Simon Tulia is currently offline Simon TuliaFriend
Messages: 14
Registered: January 2022
Junior Member
Hello Steve, Thanks for the answer. Unfortunately, I could not achieve to create a sub-model by using Control... menu. First of all I should state that I cannot see the enabled Control... menu on semantic elements (or maybe I am confused with the meaning of semantic elements). I can see it as enabled when I right click to a diagram description item in Model Explorer. Actually, this is OK for me, but maybe this is the reason of my problems. Anyway, after I clicked to the Control... menu, the wizard requests these two preferences from me respectively:
1. . Resource URI (probably this is the file path that new representation_**.aird file will be saved)
2. Selection of representations to export. In this menu I can see all items in my model, but I can select only diagram description items.

In the second menu, when I checked the related diagram description items I am getting the following Java exceptions. If I do not check any elements, then a representation file that is linked to the actual diagram description is created. However, this file is almost empty and it cannot be used by itself. What I mean is that when I open this new representation file with a text editor, it only contains some references to the actual model.

!ENTRY org.eclipse.sirius.ui 4 0 2022-01-27 13:58:50.184
!MESSAGE 
!STACK 0
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:445)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:352)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:469)
	at org.eclipse.sirius.ui.tools.internal.actions.control.DesignerControlAction.run(DesignerControlAction.java:69)
	at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:171)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:579)
	at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:413)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4213)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4030)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3630)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1158)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1047)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:658)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:557)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:154)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1447)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1420)
Caused by: java.lang.NullPointerException
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl.moveRepresentation(DAnalysisSessionImpl.java:522)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.moveRepresentations(SiriusControlCommand.java:289)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.createNewRepresentationsFileAndMoveRepresentations(SiriusControlCommand.java:223)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.doExecute(SiriusControlCommand.java:148)
	at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:496)
	at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	at org.eclipse.sirius.ui.tools.api.control.SiriusControlHandler.performControl(SiriusControlHandler.java:124)
	at org.eclipse.sirius.ui.tools.internal.actions.control.DesignerControlAction$1.execute(DesignerControlAction.java:81)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:110)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:131)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:436)
	... 33 more
Root exception:
java.lang.NullPointerException
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl.moveRepresentation(DAnalysisSessionImpl.java:522)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.moveRepresentations(SiriusControlCommand.java:289)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.createNewRepresentationsFileAndMoveRepresentations(SiriusControlCommand.java:223)
	at org.eclipse.sirius.business.api.control.SiriusControlCommand.doExecute(SiriusControlCommand.java:148)
	at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:496)
	at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	at org.eclipse.sirius.ui.tools.api.control.SiriusControlHandler.performControl(SiriusControlHandler.java:124)
	at org.eclipse.sirius.ui.tools.internal.actions.control.DesignerControlAction$1.execute(DesignerControlAction.java:81)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:110)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:131)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:436)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:352)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:469)
	at org.eclipse.sirius.ui.tools.internal.actions.control.DesignerControlAction.run(DesignerControlAction.java:69)
	at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:171)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:579)
	at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:413)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4213)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4030)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3630)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1158)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1047)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:658)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:557)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:154)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1447)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1420)


Previous Topic:Why DiagramDialectUIServices by default uses setSelection() instead of selectAndReveal() ?
Next Topic:Loading Model created using Eclipse-Sirius
Goto Forum:
  


Current Time: Fri Dec 13 10:13:20 GMT 2024

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

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

Back to the top