Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » GraphitiUi.getUiLayoutService().calculateTextSize
GraphitiUi.getUiLayoutService().calculateTextSize [message #810209] Wed, 29 February 2012 21:00 Go to next message
Patrick Talbot is currently offline Patrick TalbotFriend
Messages: 36
Registered: November 2011
Member
Is there any way other than
GraphitiUi.getUiLayoutService().calculateTextSize(text, font);
to calculate a text dimension?

I have a wizard which is generating a diagram and dark mode and my IAddFeature implementations are calling layoutPictogramElement(containerShape)

The problem is that in the related ILayoutFeature, I need to calculate the dimensions of my ga based on the dimensions of the contained Text, especially the maximum width.

But when I do that, I get:

Quote:
org.eclipse.emf.common.util.WrappedException: An exception was ignored during command execution
at org.eclipse.emf.common.command.BasicCommandStack.handleError(BasicCommandStack.java:287)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.handleError(AbstractTransactionalCommandStack.java:125)
at org.eclipse.emf.common.command.BasicCommandStack.execute(BasicCommandStack.java:118)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.basicExecute(AbstractTransactionalCommandStack.java:241)
at org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl.doExecute(TransactionalCommandStackImpl.java:63)
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.graphiti.internal.command.CommandExec.executeCommand(CommandExec.java:75)
at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.layoutIfPossible(AbstractFeatureProvider.java:288)
at org.eclipse.graphiti.features.impl.AbstractFeature.layoutPictogramElement(AbstractFeature.java:181)
at net.stuff.servoy.eclipse.graphiti.features.tables.TableAddFeature.add(TableAddFeature.java:148)
at org.eclipse.graphiti.internal.command.AddFeatureCommandWithContext.execute(AddFeatureCommandWithContext.java:76)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.doExecute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.emf.common.command.BasicCommandStack.execute(BasicCommandStack.java:84)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.basicExecute(AbstractTransactionalCommandStack.java:241)
at org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl.doExecute(TransactionalCommandStackImpl.java:63)
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.graphiti.internal.command.CommandExec.executeCommand(CommandExec.java:75)
at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.addIfPossible(AbstractFeatureProvider.java:361)
at org.eclipse.graphiti.features.impl.AbstractFeature.addGraphicalRepresentation(AbstractFeature.java:108)
at net.stuff.servoy.eclipse.graphiti.features.FileAddFeature.addTable(FileAddFeature.java:601)
at net.stuff.servoy.eclipse.graphiti.features.FileAddFeature.addIFile(FileAddFeature.java:168)
at net.stuff.servoy.eclipse.graphiti.features.FileAddFeature.add(FileAddFeature.java:142)
at net.stuff.servoy.eclipse.graphiti.ui.wizards.AddFilesCommand.doExecute(AddFilesCommand.java:90)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.emf.common.command.BasicCommandStack.execute(BasicCommandStack.java:84)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.basicExecute(AbstractTransactionalCommandStack.java:241)
at org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl.doExecute(TransactionalCommandStackImpl.java:63)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
at net.stuff.servoy.eclipse.graphiti.ui.wizards.CreateDiagramWizard.doFinish(CreateDiagramWizard.java:244)
at net.stuff.servoy.eclipse.graphiti.ui.wizards.CreateDiagramWizard$1.run(CreateDiagramWizard.java:146)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4083)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.SWT.error(SWT.java:3969)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:282)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:273)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:223)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:158)
at org.eclipse.draw2d.FigureUtilities.getGC(FigureUtilities.java:74)
at org.eclipse.draw2d.FigureUtilities.setFont(FigureUtilities.java:363)
at org.eclipse.draw2d.FigureUtilities.getStringDimension(FigureUtilities.java:124)
at org.eclipse.draw2d.FigureUtilities.getStringExtents(FigureUtilities.java:154)
at org.eclipse.draw2d.TextUtilities.getStringExtents(TextUtilities.java:43)
at org.eclipse.graphiti.ui.internal.services.impl.GefService.calculateTextSize(GefService.java:525)
at org.eclipse.graphiti.ui.internal.services.impl.UiLayoutService.calculateTextSize(UiLayoutService.java:118)
at net.stuff.servoy.eclipse.graphiti.features.tables.TableLayoutFeature.layout(TableLayoutFeature.java:74)
at org.eclipse.graphiti.features.impl.AbstractLayoutFeature.execute(AbstractLayoutFeature.java:56)
at org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext.execute(GenericFeatureCommandWithContext.java:64)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.doExecute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.emf.common.command.BasicCommandStack.execute(BasicCommandStack.java:84)
... 32 more


So I suppose GraphitiUi.getUiLayoutService() is not meant to be used in dark mode.
But I fail to find out how to calculate text dimensions apart from using this service...

Any tips/guidance would be welcome.

Thanks in advance,
-Patrick
Re: GraphitiUi.getUiLayoutService().calculateTextSize [message #819499 is a reply to message #810209] Tue, 13 March 2012 01:21 Go to previous message
Aljoscha Hark is currently offline Aljoscha HarkFriend
Messages: 24
Registered: March 2012
Junior Member
i came across the same problem (in the same situation @ an handler started by the "create from existing"-wizard) and filed bug @374020 (cannot post a link by now)

a workaround (of course not recommended) could be to create a wrapper for "GraphitiUi.getUiLayoutService().calculateTextSize(String, Font)" which runs the method synchronously in the UI thread. all accesses to the method which could be processed during the "dark feature" should use this wrapper method.

example:
public class CalculateUtil {
	private static class CalculateRunnable implements Runnable {
		private final String text;
		private final Font font;
		private IDimension dimension;

		public CalculateRunnable(String text, Font font) {
			this.text = text;
			this.font = font;
		}

		@Override
		public void run() {
			dimension = GraphitiUi.getUiLayoutService().calculateTextSize(text, font);
		}

		public IDimension getDimension() {
			return dimension;
		}
	}

	public static IDimension calculateTextSize(String text, Font font) {
		CalculateRunnable runnable = new CalculateRunnable(text, font);

		PlatformUI.getWorkbench().getDisplay().syncExec(runnable);

		return runnable.getDimension();
	}
}

[Updated on: Tue, 13 March 2012 01:22]

Report message to a moderator

Previous Topic:Continuing issues with BoxRelativeAnchor
Next Topic:Show anchor shapes when connection tool enabled
Goto Forum:
  


Current Time: Wed Apr 24 15:18:04 GMT 2024

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

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

Back to the top