Community
Participate
Working Groups
Build Identifier: 20100617-1415 Whenever I create a UI with XWT and embed it in another UI, the embedded UI is duplicated in the application. For example, I have a xwt UI call CashForm ( I am using Instantiation's/Google Designer to create the UI and using the Forms API). I now create a xwt Forms application and embed the CashForm it. Runing the application displays two CashForms UI! This consistently occurs whenever the process is repeated with different UI forms. I contacted support at Google/Instantiation and the following is there response "It seems that XWT first creates the CashForm Composite and then renders its XWT file one more time. You should contact the XWT authors and suggest that they should not do this. I don't see any problem when I drop a CashForm Composite on a normal Java SWT application, so this appears to be an XWT rendering bug." Hence now I am contacting you. Please see the relevant attachements/ Reproducible: Always Steps to Reproduce: 1.import *.forms.* plugins from e4 and swt 2.Create an xwt Form composite 3.Create a xwt JFace forms application. 4.Add 2. to 3 5.Execute 4. 6. observe the result for the duplicated embedded UI 7.OR DROP THE resource below in the same package with the appropriate names: package biz.epims.reg.ui.account; import biz.epims.reg.data.account.Cash; import biz.epims.shared.time.DateAccessor; import java.net.URL; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.eclipse.e4.xwt.IConstants; import org.eclipse.e4.xwt.IXWTLoader; import org.eclipse.e4.xwt.forms.XWTForms; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.DateTime; import org.eclipse.swt.widgets.Event; import static org.eclipse.e4.xwt.XWT.*; public class CashForm extends Composite { //~ public ----------------------------------------------------------------- public CashForm( Composite parent, int style ) { super( parent, style ); setLayout( new FillLayout() ); // load XWT String name = CashForm.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX; try { URL url = CashForm.class.getResource( name ); Map< String, Object > options = new HashMap< String, Object >(); options.put( IXWTLoader.CLASS_PROPERTY, this ); options.put( IXWTLoader.CONTAINER_PROPERTY, this ); XWTForms.loadWithOptions( url, options ); } catch( Throwable e ) { throw( new Error( "Unable to load " + name, e ) ); } // end try-catch } // end ctor CashForm //~ Methods ---------------------------------------------------------------- public void onModify( Event event ) { DateTime dt = ( DateTime ) findElementByName( event.widget, "paymentDT" ); Date date = new DateAccessor( dt ).getDate(); Cash dataContext = ( Cash ) getDataContext( dt ); dataContext.setDate( date ); System.out.println( date ); } // end method onModify } // end class CashForm <!-- Forms API --> <Composite xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" xmlns:p1="clr-namespace:org.eclipse.nebula.widgets.cdatetime" x:Name="root" x:Class="biz.epims.reg.ui.account.CashForm" dataContext="{StaticResource cash}" xmlns:account="clr-namespace:biz.epims.reg.data.account" xmlns:c0="clr-namespace:biz.epims.shared.converters" xmlns:v0="clr-namespace:biz.epims.shared.validators"> <Composite.layout> <GridLayout numColumns="2"/> </Composite.layout> <Composite.Resources> <account:Cash x:Key="cash" /> </Composite.Resources> <Label text="Payment"> <Label.layoutData> <GridData horizontalAlignment="CENTER"/> </Label.layoutData> </Label> <Label text="Amount" x:Name="amountLbl"> <Label.layoutData> <GridData horizontalAlignment="CENTER"/> </Label.layoutData> </Label> <DateTime x:Style="BORDER | DROP_DOWN" x:Name="paymentDT"/> <Text x:Style="BORDER" x:Name="amountText" text="{Binding Path=amount, converter=c0:DoubleStringConverter, validationRule=v0:CurrencyValidationRule}" ModifyEvent="onModify"> <Text.layoutData> <GridData grabExcessHorizontalSpace="true" horizontalAlignment="FILL"/> </Text.layoutData> </Text> </Composite> package biz.epims.reg.ui.account; import java.net.URL; import org.eclipse.e4.xwt.IConstants; import org.eclipse.e4.xwt.forms.XWTForms; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * The domain|UI model for the {@link} UI. * * @revision $Revision$ $Date$ * @since 1.0 */ public class CashFormApp1 { //~ Methods ---------------------------------------------------------------- public static void main( String[] args ) throws Exception { URL url = CashFormApp1.class.getResource( CashFormApp1.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX ); Control control = XWTForms.load( url ); Shell shell = control.getShell(); shell.layout(); // centerInDisplay( shell ); // run events loop shell.open(); while( !shell.isDisposed() ) { if( !shell.getDisplay().readAndDispatch() ) { shell.getDisplay().sleep(); } // end if } // end while } // end method main // private static void centerInDisplay( Shell shell ) // { // Rectangle displayArea = shell.getDisplay().getClientArea(); // shell.setBounds( displayArea.width / 4, displayArea.height / 4, // displayArea.width / 2, displayArea.height / 2 ); // } } // end class CashFormApp1 <Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:Class="biz.epims.reg.ui.account.CashFormApp1" text="XWT Forms Application" xmlns:p1="clr-namespace:biz.epims.reg.ui.account"> <Shell.layout> <GridLayout/> </Shell.layout> <p1:CashForm/> </Shell> <!-- Forms API -->
Please provide an executable and independent testcase. Your example imports and use other classes.
We have checked out this case. It is not a bug. It is the code issue: the loading of XWT resource in CashForm is not necessary. It is done by XWT automatically. The constructor could be: public CashForm( Composite parent, int style ) { super( parent, style ); // setLayout( new FillLayout() ); this should be in XML }