Define composite controls

     After using the model to write a SWT interface, if the interface is reusable, it can be defined as a composite control.

     The main methods of defining composite models are as follows.

  • First use the model to write the prototype of the composite control.
  • Create a model, implement the create() method, create a Java object through the prototype in the create() method, and make some settings based on the current model.
  • Compound control models usually need to inherit the LayoutDatas model.
  • Register the control model under the control master index so that it can be used when writing the SWT model.

    The following 40-second GIF video demonstrates how to define composite controls.

    The Groovy code for the create() method in the above example is as follows.

import xworker.swt.util.ThingCompositeCreator;

//Usually use ThingCompositeCreator to help create objects
def cc = new ThingCompositeCreator(self, actionContext);

//Set prototype
def prototype = world.getThing("xworker.example.util.barcode.ZXingSwtExample/@mainComposite");
cc.setCompositeThing(prototype);

//Create
def composite = cc.create();

//To avoid polluting variables in the current context, it is common to use a separate context
def ac = cc.getNewActionContext();

//Save variable. The saved variable is usually used for interaction later.
actionContext.g().put(self.getMetadata().getName(), ac.get("messageText"));

return composite;

 

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号