Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Layout exception when opening editor
Layout exception when opening editor [message #119409] Fri, 23 January 2009 16:55 Go to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
Hi all,

I have the following simple editor:


public class MyEditor extends EditorPart
{
@Override
public void doSave(IProgressMonitor monitor){}

@Override
public void doSaveAs(){}

@Override
public boolean isDirty(){return false;}

@Override
public boolean isSaveAsAllowed(){return false;}

@Override
public void init(IEditorSite site, IEditorInput input) throws
PartInitException
{
setSite(site);
setInput(input);
}

@Override
public void createPartControl(final Composite parent)
{
Composite container = new Composite(parent,SWT.NONE);
container.setLayoutData(GridDataFactory.fillDefaults().grab( true,true).create());
}

@Override
public void setFocus(){}
}


When I open the editor the following exception is thrown:

Jan 23, 2009 11:44:07 PM org.eclipse.rwt.internal.lifecycle.RWTLifeCycle
afterPhaseExecution
SEVERE: Could not execute PhaseListener after phase 'PROCESS_ACTION'.
java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be
cast to org.eclipse.swt.layout.FillData
at org.eclipse.swt.layout.FillLayout.flushCache(FillLayout.java :180)
at org.eclipse.swt.widgets.Composite.changed(Composite.java:493 )
at
org.eclipse.swt.internal.graphics.TextSizeDeterminationHandl er$1.doVisit(TextSizeDeterminationHandler.java:79)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor$AllWidget TreeVisitor.visit(WidgetTreeVisitor.java:32)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:46)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
at
org.eclipse.swt.internal.graphics.TextSizeDeterminationHandl er.afterPhase(TextSizeDeterminationHandler.java:126)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.afterPhaseEx ecution(RWTLifeCycle.java:390)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:191)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.sleep(RWTLif eCycle.java:297)
at org.eclipse.swt.widgets.Display.sleep(Display.java:706)
at
org.eclipse.ui.application.WorkbenchAdvisor.eventLoopIdle(Wo rkbenchAdvisor.java:361)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2347)
at org.eclipse.ui.internal.Workbench.access$5(Workbench.java:22 00)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:425)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:408)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:157)
at
com.farbeyond.input.ui.application.DemoEntryPoint.createUI(D emoEntryPoint.java:12)
at
org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
at java.lang.Thread.run(Thread.java:619)


What's wrong ?


Regards,

Setya
Re: Layout exception when opening editor [message #119422 is a reply to message #119409] Fri, 23 January 2009 17:06 Go to previous messageGo to next message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 338
Registered: July 2009
Senior Member
Hi Setya,

you can't be sure that the layout of the parent composite is a
GridLayout. And using a GridData together with a non GridLayout (eg.
FillLayout as in your case) will always fail at runtime (same goes for SWT).

Be sure you only set layout data objects for composites you have created
yourself or you have set the correct layout.

Greets
Benny

Setya wrote:
> Hi all,
>
> I have the following simple editor:
>
>
> public class MyEditor extends EditorPart
> {
> @Override
> public void doSave(IProgressMonitor monitor){}
>
> @Override
> public void doSaveAs(){}
>
> @Override
> public boolean isDirty(){return false;}
>
> @Override
> public boolean isSaveAsAllowed(){return false;}
>
> @Override
> public void init(IEditorSite site, IEditorInput input) throws
> PartInitException
> {
> setSite(site);
> setInput(input);
> }
>
> @Override
> public void createPartControl(final Composite parent)
> {
> Composite container = new Composite(parent,SWT.NONE);
> container.setLayoutData(GridDataFactory.fillDefaults().grab( true,true).create());
>
> }
>
> @Override
> public void setFocus(){}
> }
>
>
> When I open the editor the following exception is thrown:
>
> Jan 23, 2009 11:44:07 PM org.eclipse.rwt.internal.lifecycle.RWTLifeCycle
> afterPhaseExecution
> SEVERE: Could not execute PhaseListener after phase 'PROCESS_ACTION'.
> java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be
> cast to org.eclipse.swt.layout.FillData
> at org.eclipse.swt.layout.FillLayout.flushCache(FillLayout.java :180)
> at org.eclipse.swt.widgets.Composite.changed(Composite.java:493 )
> at
> org.eclipse.swt.internal.graphics.TextSizeDeterminationHandl er$1.doVisit(TextSizeDeterminationHandler.java:79)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor$AllWidget TreeVisitor.visit(WidgetTreeVisitor.java:32)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:46)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
>
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:51)
>
> at
> org.eclipse.swt.internal.graphics.TextSizeDeterminationHandl er.afterPhase(TextSizeDeterminationHandler.java:126)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.afterPhaseEx ecution(RWTLifeCycle.java:390)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:191)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.sleep(RWTLif eCycle.java:297)
>
> at org.eclipse.swt.widgets.Display.sleep(Display.java:706)
> at
> org.eclipse.ui.application.WorkbenchAdvisor.eventLoopIdle(Wo rkbenchAdvisor.java:361)
>
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2347)
> at org.eclipse.ui.internal.Workbench.access$5(Workbench.java:22 00)
> at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:425)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:408)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:157)
> at
> com.farbeyond.input.ui.application.DemoEntryPoint.createUI(D emoEntryPoint.java:12)
>
> at
> org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
>
> at java.lang.Thread.run(Thread.java:619)
>
>
> What's wrong ?
>
>
> Regards,
>
> Setya
Re: Layout exception when opening editor [message #119435 is a reply to message #119422] Fri, 23 January 2009 18:02 Go to previous messageGo to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
Hi,

From my snippet I only set the layout of Composite that I create, I didn't
touch the parent's layout at all.

Setya
Re: Layout exception when opening editor [message #119448 is a reply to message #119435] Fri, 23 January 2009 18:04 Go to previous messageGo to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
Hi,

Besides, the exception only thrown when I open the editor for the 1st time.


Setya
Re: Layout exception when opening editor [message #119461 is a reply to message #119448] Fri, 23 January 2009 18:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi,

the exception is only thrown once because the layout is only created once, when starting the editor for the first time.

regarding the layouting, setting a LayoutData on a composite is also connected to the Layout of its parent composite! the LayoutDate defines how the composite, 'container' in this case, behaves inside
the parent composite. FillLayout is the default Layout when nothing else is set, therefore the parent comp, which is contributed by the method call, has a FillLayout and can't use the GridData of the
container comp. adding the Line

parent.setLayout(GridLayoutFactory.swtDefaults().create());

should avoid the exception if i'm not mistaken.


greetings,
ben



Setya schrieb:
> Hi,
>
> Besides, the exception only thrown when I open the editor for the 1st time.
>
>
> Setya
>
Re: Layout exception when opening editor [message #119474 is a reply to message #119461] Fri, 23 January 2009 18:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

i have to correct my last posting, since it is not a good idea to modify the Layout of the parent comp it would be best if you don't set a LayoutData on the container comp. Simply add a GridLayout to
the container comp and use the container to layout the children (buttons etc.) using Grid Layouting. that's how do it.

greetings,
ben



Ben W. schrieb:
> Hi,
>
> the exception is only thrown once because the layout is only created
> once, when starting the editor for the first time.
>
> regarding the layouting, setting a LayoutData on a composite is also
> connected to the Layout of its parent composite! the LayoutDate defines
> how the composite, 'container' in this case, behaves inside the parent
> composite. FillLayout is the default Layout when nothing else is set,
> therefore the parent comp, which is contributed by the method call, has
> a FillLayout and can't use the GridData of the container comp. adding
> the Line
>
> parent.setLayout(GridLayoutFactory.swtDefaults().create());
>
> should avoid the exception if i'm not mistaken.
>
>
> greetings,
> ben
>
>
>
> Setya schrieb:
>> Hi,
>>
>> Besides, the exception only thrown when I open the editor for the 1st
>> time.
>>
>>
>> Setya
>>
Re: Layout exception when opening editor [message #119546 is a reply to message #119474] Sun, 25 January 2009 06:48 Go to previous messageGo to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
Hi,

Thanks for your advice. Actually removing the GridLayoutData assignment
makes no difference.

But, I've put the same editor part in my RCP app to test, no exception was
thrown, should I expected incompatibility here ?


Regards,

Setya
Re: Layout exception when opening editor [message #119570 is a reply to message #119546] Sun, 25 January 2009 12:27 Go to previous messageGo to next message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 338
Registered: July 2009
Senior Member
Hi Setya,

it may be that the exception is thrown in RAP but not in SWT because SWT
does not call flushCache(). But in fact it is an error in your code if
you provide incompatible layout datas for a layout.

See also the newsgroup posting "ClassCastException in
FillLayout.flushCache()" for some more informations.

Cheers
Benny

Setya wrote:
> Hi,
>
> Thanks for your advice. Actually removing the GridLayoutData assignment
> makes no difference.
>
> But, I've put the same editor part in my RCP app to test, no exception
> was thrown, should I expected incompatibility here ?
>
>
> Regards,
>
> Setya
>
Re: Layout exception when opening editor [message #667170 is a reply to message #119409] Wed, 27 April 2011 08:25 Go to previous messageGo to next message
Alexander Kunin is currently offline Alexander KuninFriend
Messages: 1
Registered: July 2009
Junior Member
2 years later I got the same exception. The problem was:
parent's layout was a FillLayout. It was not allowed to setLayoutData (GridData).


@Override
public void createPartControl(final Composite parent)
{
Composite container = new Composite(parent,SWT.NONE);
container.setLayoutData(GridDataFactory.fillDefaults().grab( true,true).create()); // BAD
}






Re: Layout exception when opening editor [message #901681 is a reply to message #667170] Tue, 14 August 2012 06:58 Go to previous message
Thongchai Sukosi is currently offline Thongchai SukosiFriend
Messages: 7
Registered: August 2012
Junior Member
Just to avoid other people getting confused like I am. It's no defect here. The thing is you tried to set GridData to a composite that has FillLayout as it layout manager (by default). You need to assign GridLayout to the composite before assigning GridData. That's it.

[Updated on: Tue, 14 August 2012 07:01]

Report message to a moderator

Previous Topic:tiling views in a folder
Next Topic:Memory-Problems
Goto Forum:
  


Current Time: Fri Apr 19 20:37:50 GMT 2024

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

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

Back to the top