Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314280 - Wrong Text size determination when executing UI code from Display.asyncExec(...
Summary: Wrong Text size determination when executing UI code from Display.asyncExec(...
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: Workbench (show other bugs)
Version: 1.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.4 RC1   Edit
Assignee: Frank Appel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-25 10:27 EDT by Lukas Dziadkowiec CLA
Modified: 2011-05-05 06:23 EDT (History)
1 user (show)

See Also:


Attachments
Demo project to reproduce (37.80 KB, application/x-zip-compressed)
2010-05-25 10:30 EDT, Lukas Dziadkowiec CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Dziadkowiec CLA 2010-05-25 10:27:25 EDT
Build Identifier: Eclipse 3.5.2.R35x, RAP 1.3.0.20100518-1222

I have RAP workbench application that renders UI in an Editor according to background Thread. I'm using Display.syncExec(...) and I'm creating some labels in the Editor composite. For the several few first times there is wrong TextSizeDetermination. I have traced this and for every Label and new Font there is FontProbing and StringMeasurements correctly created. The TextSizeDeterminationHandler is correctly registered as listened i the IPhaseListerner, but before RENDER phase occur, it is removed and cannot be called.

Reproducible: Always

Steps to Reproduce:
1. Have a simple RAP Workbench application.
2. Have an action which opens an Editor.
3. Have an separate Thread and exec Display.syncExec(.... in there.  Create some labels in there.
4. For the first 1-2 times, there will be wrong text widths, because 
if( event.getPhaseId() == PhaseId.RENDER ) {
          probes = TextSizeDeterminationFacade.writeFontProbing();
          calculationItems
            = TextSizeDeterminationFacade.writeStringMeasurements();
          renderDone = true;
        }
is not called. The TextSizeDeterminationHandler listener is removed in class TextSizeDeterminationHandler
if( renderDone && event.getPhaseId() == PhaseId.PROCESS_ACTION ) {
  LifeCycleFactory.getLifeCycle().removePhaseListener( this );
  ISessionStore session = ContextProvider.getSession();
  session.removeAttribute( CALCULATION_HANDLER );
}


example code in DemoActionBarAdvisor class.

protected void makeActions(final IWorkbenchWindow window) {
	newEditorAction = new Action() {
	public void run() {
		ProgramEditorInput MyEditorInput = new MyEditorInput("yep");
		try {
			final MyEditor editor = (MyEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(MyEditorInput, MyEditor.ID, true);
			editor.getComposite().getDisplay().syncExec(new Runnable() {
				public void run() {
					Label label = new Label(editor.getComposite(), SWT.NONE);
					label.setText("Testing lenght of the text END");
					label.setFont(new Font(editor.getComposite().getDisplay(), "Courier New", 14, 0));
					label.pack();
				}
			});
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
};
Comment 1 Lukas Dziadkowiec CLA 2010-05-25 10:30:02 EDT
Created attachment 169838 [details]
Demo project to reproduce
Comment 2 Frank Appel CLA 2011-05-05 03:45:55 EDT
Fixed in CVS Head. Feel free to reopen if problem persists.