Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Empty annotation for the source GMF_DIAGRAMS
Empty annotation for the source GMF_DIAGRAMS [message #1753601] Wed, 08 February 2017 06:14 Go to next message
Martin Jedlicka is currently offline Martin JedlickaFriend
Messages: 122
Registered: January 2016
Senior Member
Hi,

I had a question about the programmatically create graphical representations of data.

I have DSL (xText) and programmatically creating proper graphical representation of data (see code below). Sometimes it when creating a graphical representation happens that is not created AnnotationAntry for source GMF_DIAGRAMS (chidren is null, see pictures aird.png and annotation_children_null.png).

When you open this diagram is then thrown exception (see exception below) and in the graphics area are no nodes (or edges), but they are seen Outline (see picture graphical_area_empty.png).

You do not know how it can happen that the annotation for GMF_DIAGRAMS are empty? Optionally, you can fix it somehow?

Thanks for any advice.

Martin

Code creating graphical representations of data:
	private void createGraphicalRepresentation(final ComponentVersion componentVersion, final URI uriDSL, final URI uriAird) {
		IProgressMonitor monitor = new NullProgressMonitor();
		try {

			cleanEnvironment(monitor);

			// create session
			createSession(uriDSL, uriAird, monitor);

			// find and setting viewpoint
			boolean status = findAndSetViepoint(monitor);
			if (!status) {
				LOGGER.error("Could not found viewport for fileextension " + WorkspaceService.UFOPROCESS_FILE_SUFFIX);
				monitor.done();
			}

			// create representation
			createRepresentation(componentVersion.getFullText(), monitor);

		} catch (IOException | CoreException e) {
			LOGGER.error(e.getCause());
			monitor.done();
		}
	}

	private void createSession(final URI modelURI, final URI representationURI, IProgressMonitor monitor) throws IOException, CoreException {
		// create session
		final SessionCreationOperation creationOperation = new DefaultLocalSessionCreationOperation(representationURI, monitor);
		creationOperation.execute();
		session = creationOperation.getCreatedSession();

		// command for add semantic model
		// add semanticResources item to aird file
		AddSemanticResourceCommand addSemanticResourceCommand = new AddSemanticResourceCommand(session, modelURI, monitor);
		session.getTransactionalEditingDomain().getCommandStack().execute(addSemanticResourceCommand);
		session.save(monitor);

		// init SessionUIManager
		final IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(session);
		editingSession.open();
	}

	private boolean findAndSetViepoint(IProgressMonitor monitor) {
		Set<Viewpoint> availableViewpoints = ViewpointSelection.getViewpoints(WorkspaceService.UFOPROCESS_FILE_SUFFIX);
		if (availableViewpoints.isEmpty()) {
			return false;
		}
		Set<Viewpoint> viewpoints = new HashSet<>();
		for (Viewpoint viewpoint : availableViewpoints) {
			viewpoints.add(SiriusResourceHelper.getCorrespondingViewpoint(session, viewpoint));
		}

		if (viewpoints.isEmpty()) {
			return false;
		}

		ViewpointSelection.Callback callback = new ViewpointSelectionCallbackWithConfimation();

		RecordingCommand command = new ChangeViewpointSelectionCommand(session, callback, viewpoints, new HashSet<Viewpoint>(), true, monitor);
		TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
		domain.getCommandStack().execute(command);

		return true;
	}

	private void createRepresentation(String diagramName, IProgressMonitor monitor) {

		// get resource from session
		Resource resource = null;
		Collection<Resource> resources = session.getSemanticResources();
		for (Resource res : resources) {
			if (res instanceof LazyLinkingResource) {
				resource = res;
			}
		}

		EObject semanticModel = null;
		if (resource != null) {
			semanticModel = resource.getContents().get(0);
		}

		// get representation
		final RepresentationDescription descriptionToUse = getRepresentationDescriptionInEditingDomain(getRepresentationDescription(GraphicalProcessEditor.PROCESS_DIAGRAM_NAME), semanticModel);
		final Option<DRepresentation> optionalRepresentation = findRepresentation(descriptionToUse, semanticModel);

		if (optionalRepresentation.some()) {
			representation = optionalRepresentation.get();
		}
		else {
			CreateRepresentationCommand command = new CreateRepresentationCommand(session, descriptionToUse, semanticModel, diagramName, monitor);
			session.getTransactionalEditingDomain().getCommandStack().execute(command);
			representation = command.getCreatedRepresentation();
		}

		// change diagram name
		final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
		final CommandStack commandStack = domain.getCommandStack();
		commandStack.execute(new RecordingCommand(domain) {
			@Override
			protected void doExecute() {
				if (representation.getName().equals(GraphicalProcessEditor.PROCESS_DIAGRAM_NAME)) {
					representation.setName(diagramName);
				}
			}
		});
	}

	private Option<DRepresentation> findRepresentation(RepresentationDescription representationDescriptionUsed, EObject semanticElement) {
		if (session != null && representationDescriptionUsed != null && semanticElement != null) {
			Collection<DView> views = session.getOwnedViews();
			for (final DView view : views) {
				List<DRepresentation> representations = new DViewQuery(view).getLoadedRepresentations();
				for (final DRepresentation representation : representations) {
					RepresentationDescription reprDesc = DialectManager.INSTANCE.getDescription(representation);
					if (representation instanceof DSemanticDecorator && representationDescriptionUsed.equals(reprDesc)) {
						return Options.newSome(representation);
					}
				}
			}
		}
		return Options.newNone();
	}

	private RepresentationDescription getRepresentationDescriptionInEditingDomain(final RepresentationDescription representationDescription, final EObject semanticModel) {
		Collection<RepresentationDescription> representationDescriptions = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), semanticModel);
		for (final RepresentationDescription representationDescriptionInEditingDomain : representationDescriptions) {
			if (representationDescriptionInEditingDomain.getName().equals(representationDescription.getName())) {
				return representationDescriptionInEditingDomain;
			}
		}
		return null;
	}

	private RepresentationDescription getRepresentationDescription(final String wantedName) {
		URI viewpointURI = URI.createURI(GraphicalProcessEditor.VIEWPOINT);
		for (final RepresentationDescription representationDescription : getSirius(viewpointURI).getOwnedRepresentations()) {
			if (wantedName.equals(representationDescription.getName())) {
				return representationDescription;
			}
		}
		throw new RuntimeException();
	}

	private Viewpoint getSirius(URI viewpointURI) {
		return ViewpointRegistry.getInstance().getViewpoint(viewpointURI);
	}

	public void cleanEnvironment(IProgressMonitor monitor) {
		if (session != null) {
			session.close(monitor);
		}
	}


Exception by opening diagram:
!ENTRY org.eclipse.emf.common 2 0 2017-02-07 13:31:27.387
!MESSAGE An exception was ignored during command execution
!STACK 0
org.eclipse.emf.common.util.WrappedException: An exception was ignored during command execution
	at org.eclipse.emf.common.command.BasicCommandStack.handleError(BasicCommandStack.java:281)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.handleError(AbstractTransactionalCommandStack.java:125)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:229)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.launchRefresh(DDiagramEditorImpl.java:1253)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.initializeGraphicalViewer(DDiagramEditorImpl.java:1435)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.createOriginalGraphicalViewer(DDiagramEditorImpl.java:1392)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.createMainDiagramSection(DDiagramEditorImpl.java:1318)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.createGraphicalViewer(DDiagramEditorImpl.java:1307)
	at org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:171)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.createPartControl(DiagramEditor.java:1580)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette.createPartControl(DiagramEditorWithFlyOutPalette.java:328)
	at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.createPartControl(DiagramDocumentEditor.java:1514)
	at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.createPartControl(DDiagramEditorImpl.java:509)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:341)
	at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:898)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:879)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:121)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:345)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:264)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:971)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:640)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:746)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:717)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:711)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:695)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1306)
	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:72)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:85)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:59)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:572)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:536)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:724)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:396)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1166)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3252)
	at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3167)
	at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3149)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3144)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3108)
	at com.ge.eufo.ui.utils.UiUtils.openEditor(UiUtils.java:153)
	at com.ge.eufo.workspace.managers.ComponentTypeManager.openEditorInternal(ComponentTypeManager.java:138)
	at com.ge.eufo.workspace.managers.ComponentTypeManager.openEditor(ComponentTypeManager.java:110)
	at com.ge.eufo.workspace.managers.ComponentTypeManager.openEditor(ComponentTypeManager.java:90)
	at com.ge.eufo.navigationpanel.navigator.ComponentNavigator$3.run(ComponentNavigator.java:149)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at com.ge.eufo.navigationpanel.navigator.ComponentNavigator.openEditor(ComponentNavigator.java:145)
	at com.ge.eufo.navigationpanel.navigator.ComponentNavigator.handleDoubleClick(ComponentNavigator.java:139)
	at com.ge.eufo.ui.navigator.AbstractNavigatorView$1.doubleClick(AbstractNavigatorView.java:83)
	at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:832)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
	at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:829)
	at org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1470)
	at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1263)
	at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:252)
	at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:249)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:311)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at com.ness.eufo.starter.intro.Application.start(Application.java:251)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	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:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: org.eclipse.emf.transaction.RollbackException: Uncaught exception during pre-commit trigger processing
	at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:213)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	... 111 more
Re: Empty annotation for the source GMF_DIAGRAMS [message #1753622 is a reply to message #1753601] Wed, 08 February 2017 08:56 Go to previous message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
Hi,

The GMF diagram is syncrhonized during the
CreateRepresentationCommand
in the method
org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(String, EObject, RepresentationDescription, Session, IProgressMonitor)
. You can debug it and look in
canonicalSynchronizer.synchronize();
to understand why in your case, sometimes it works and sometimes it fails.

Regards,

Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Java Services in diagram exported as update site
Next Topic:Diagram for selected elements
Goto Forum:
  


Current Time: Tue Apr 16 04:11:26 GMT 2024

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

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

Back to the top