java - Replacing a text box with DateChooserCombo in org.eclipse.swt.layout.GridData -


i had dialog created in swt using griddata having:

label1: combobox
label2: textbox1
label3: textbox2

checkbox1 label4
checkbox2 label5

based on comobox selected value, need replace textbox2 datechoosercombo or datechoosercombo textbox2.

below class implementation method createtextbox create textbox2 when loading dialog. setdatepicker called on change of combo box value. please provide assistance on implementation in below class on how can achieve it. in advance.

public class confgelementinsertdialog extends dialogex {     private text typename;     private text defaultvaluetext;     private combo templatetype;     private button iskeycheckbox;     private button iseditablecheckbox;     private button todisplaycheckbox;     private button okbutton;     private boolean isinstanceconfig;     private list<string> configelementname;     private boolean iskey = false;     private boolean todisplay = false;     private boolean iseditable = false;     private string label;     private string name;     private string defaultval;     private boolean isedit;     private text configelementnametext;     private list<string> dateitem = arrays.aslist("effectivedate", "enddate", "premiumeffectivedate ","premiumenddate");     private boolean isdatepicker;     private date defauldatetval;     datechoosercombo enumdatechooser;     group templatetypegroup;       public confgelementinsertdialog (shell shell) {         super(shell);         setshellstyle(getshellstyle() | swt.resize);     }      public confgelementinsertdialog (shell shell, boolean isinstanceconfig,             boolean isedit) {         super(shell);         this.isinstanceconfig = isinstanceconfig;         this.isedit = isedit;         setshellstyle(getshellstyle() | swt.resize);     }      protected void configureshell(shell shell) {         super.configureshell(shell);         shell.setsize(300, 300);         if (!isedit)             shell.settext(tabletemplateconfigconstants.add_config_dialog);         else             shell.settext(tabletemplateconfigconstants.edit_config_dialog);      }      protected control createdialogarea(composite parent) {         composite child = new composite(parent, swt.fill);         child.setlayout(new gridlayout(1, false));         child.setlayoutdata(new griddata(swt.fill, swt.fill, true, true));          templatetypegroup = new group(child, swt.fill);         templatetypegroup.setlayoutdata(new griddata(swt.fill, swt.fill, true,                 true));         templatetypegroup.setlayout(new gridlayout(3, false));          griddata data = new griddata(swt.none, swt.fill, false, false, 2, 1);         data.widthhint = 100;         if(isinstanceconfig)             templatetypegroup.settext(tabletemplateconfigconstants.add_config_group_instance_text);         else             templatetypegroup.settext(tabletemplateconfigconstants.add_config_group_template_text);          label label1 = new label(templatetypegroup, swt.null);         label1.settext(tabletemplateconfigconstants.name_label);         if (!isedit) {             templatetype = new combo(templatetypegroup, swt.v_scroll);             templatetype.setlayoutdata(data);              templatetype.setitems(getconfigelementname().toarray(                     new string[getconfigelementname().size()]));             templatetype.addselectionlistener(new selectionadapter() {                 @override                 public void widgetselected(selectionevent e) {                     if (templatetype.getselection() != null                             && !templatetype.getitem(templatetype.getselectionindex()).isempty()) {                         setname(templatetype.getitem(templatetype.getselectionindex()));                                                 setdatepicker(templatetype.getitem(templatetype.getselectionindex()),templatetypegroup);                         okbutton.setenabled(true);                     } else                         okbutton.setenabled(false);                  }             });         } else {             configelementnametext = new text(templatetypegroup, swt.border);             configelementnametext.setlayoutdata(data);             configelementnametext.setenabled(false);             if(getname()!=null){             configelementnametext.settext(getname());             setname(getname());             setdatepicker(getname(),templatetypegroup);             }         }          label label = new label(templatetypegroup, swt.null);         label.settext(tabletemplateconfigconstants.label_text);          typename = new text(templatetypegroup, swt.border);         typename.setlayoutdata(data);         typename.addmodifylistener(new modifylistener() {              @override             public void modifytext(modifyevent e) {                 setlabel(typename.gettext());              }         });           createtextbox(templatetypegroup, data);  //      }         iskeycheckbox = new button(templatetypegroup, swt.check);         iskeycheckbox.settext(tabletemplateconfigconstants.required_label);         iskeycheckbox.setlayoutdata(new griddata(swt.fill, swt.fill, true,                 true, 1, 1));          iskeycheckbox.addselectionlistener(new selectionadapter() {             @override             public void widgetselected(selectionevent e) {                 if (iskeycheckbox.getselection())                     setkey(true);                 else                     setkey(false);             }         });          iseditablecheckbox = new button(templatetypegroup, swt.check);         iseditablecheckbox.setselection(true);         if (!isedit)             seteditable(true);         if(getdefaultval()==null || getdefaultval().isempty())             {iseditablecheckbox.setenabled(false);              }         iseditablecheckbox.settext(tabletemplateconfigconstants.editable_label);         iseditablecheckbox.setlayoutdata(new griddata(swt.fill, swt.fill, true,                 true, 1, 1));         iseditablecheckbox.addselectionlistener(new selectionadapter() {             @override             public void widgetselected(selectionevent e) {                 if (iseditablecheckbox.getselection())                     seteditable(true);                 else                     seteditable(false);             }         });          if (!isinstanceconfig) {             todisplaycheckbox = new button(templatetypegroup, swt.check);             todisplaycheckbox.setselection(true);             if(getdefaultval()==null || getdefaultval().isempty())                 todisplaycheckbox.setenabled(false);             todisplaycheckbox.settext(tabletemplateconfigconstants.display_label);             todisplaycheckbox.setlayoutdata(new griddata(swt.fill, swt.fill,                     true, true, 1, 1));             todisplaycheckbox.setselection(true);             if (!isedit)                 settodisplay(true);             todisplaycheckbox.addselectionlistener(new selectionadapter() {                 @override                 public void widgetselected(selectionevent e) {                     if (todisplaycheckbox.getselection())                         settodisplay(true);                     else                         settodisplay(false);                 }             });             if (isedit) {                 todisplaycheckbox.setselection(istodisplay());             }         }         if (isedit) {             iskeycheckbox.setselection(iskey());             if(getlabel()!=null)             typename.settext(getlabel());             if(getdefaultval()!=null)                 defaultvaluetext.settext(getdefaultval());             iseditablecheckbox.setselection(iseditable());         }         return child;     }      protected void createbuttonsforbuttonbar(composite parent) {         super.createbuttonsforbuttonbar(parent);         okbutton = getbutton(idialogconstants.ok_id);         if(isedit)             okbutton.setenabled(true);         else         okbutton.setenabled(false);     }      public list<string> getconfigelementname() {         return configelementname;     }      public void setconfigelementname(list<string> configelementname) {         this.configelementname = configelementname;     }      public boolean iskey() {         return iskey;     }      public void setkey(boolean iskey) {         this.iskey = iskey;     }      public boolean istodisplay() {         return todisplay;     }      public void settodisplay(boolean todisplay) {         this.todisplay = todisplay;     }      public boolean iseditable() {         return iseditable;     }      public void seteditable(boolean iseditable) {         this.iseditable = iseditable;     }      public string getlabel() {         return label;     }      public void setlabel(string label) {         this.label = label;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }     public string getdefaultval() {         return defaultval;     }      public void setdefaultval(string defaultval) {         this.defaultval = defaultval;     }      public list<string> getlistfordatepickere() {         return dateitem;     }      public void setdatepicker(string value, group templatetypegroup) {         if(dateitem.contains(value) && null != defaultvaluetext){             object grd = defaultvaluetext.getlayoutdata();             defaultvaluetext.dispose();             defaultvaluetext = null;             createdatecontrol(templatetypegroup,grd);         }else if(!dateitem.contains(value) && null != enumdatechooser){             object grd = enumdatechooser.getlayoutdata();             enumdatechooser.dispose();             enumdatechooser = null;             createtextbox(templatetypegroup,enumdatechooser.getlayoutdata());         }     }      /**      * @return defauldatetval      */     public date getdefauldatetval() {         return defauldatetval;     }      /**      * @param defauldatetval defauldatetval set      */     public void setdefauldatetval(date defauldatetval) {         this.defauldatetval = defauldatetval;     }      public void createtextbox(composite templatetypegroup, object data){         label defaultlabel = new label(templatetypegroup, swt.null);         defaultlabel.settext(tabletemplateconfigconstants.default_val_text);          defaultvaluetext = new text(templatetypegroup, swt.border);         defaultvaluetext.setlayoutdata(data);         defaultvaluetext.addmodifylistener(new modifylistener() {              @override             public void modifytext(modifyevent e) {                 setdefaultval(defaultvaluetext.gettext());                 if(!isedit && (defaultvaluetext.gettext()==null || defaultvaluetext.gettext().isempty()))                 {                     settodisplay(true);                     todisplaycheckbox.setselection(true);                     todisplaycheckbox.setenabled(false);                     seteditable(true);                     iseditablecheckbox.setselection(true);                     iseditablecheckbox.setenabled(false);                  }                 if(!isedit && (defaultvaluetext.gettext()!=null && !defaultvaluetext.gettext().isempty()))                 {                     iseditablecheckbox.setenabled(true);                     todisplaycheckbox.setenabled(true);                 }             }         });     }      public void createdatecontrol(composite templatetypegroup, object data){         label defaultlbl = new label(templatetypegroup, swt.null);         defaultlbl.settext(tabletemplateconfigconstants.default_val_text);         enumdatechooser = new datechoosercombo(                 templatetypegroup, swt.border | cdt.drop_down                         | cdt.date_short);         enumdatechooser.setformatter(new dateformatter(                 itabledataconstants.date_format_table_viewer));         enumdatechooser.setvalue(new date(system.currenttimemillis()));         enumdatechooser.setlayoutdata((griddata)data);         enumdatechooser.addmodifylistener(new modifylistener() {              @override             public void modifytext(modifyevent e) {                  setdefauldatetval(enumdatechooser.getvalue());                 if(!isedit && (enumdatechooser.getvalue()==null))                 {                     settodisplay(true);                     todisplaycheckbox.setselection(true);                     todisplaycheckbox.setenabled(false);                     seteditable(true);                     iseditablecheckbox.setselection(true);                     iseditablecheckbox.setenabled(false);                  }                 if(!isedit && (defaultvaluetext.gettext()!=null && !defaultvaluetext.gettext().isempty()))                 {                     iseditablecheckbox.setenabled(true);                     todisplaycheckbox.setenabled(true);                 }             }         });     } } 

implemented method on selection change event of combo box i.e. setcontrol(templatetype.getitem(templatetype.getselectionindex()),templatetypegroup);

it take layout , display details before disposing old control , create new control passing details of old controls.

public void setcontrol(string value, group templatetypegroup) {     object grd = null;     point pt = null;     rectangle rct = null;        if(tabletemplateconfigconstants.dateitems.contains(value) && null != defaultvaluetext){         grd = defaultvaluetext.getlayoutdata();         pt = defaultvaluetext.getlocation();         rct = defaultvaluetext.getbounds();         defaultvaluetext.dispose();         cleancontrols();         createdatecontrol(templatetypegroup,grd,pt,rct,value);}}   public void createdatecontrol(composite templatetypegroup, object data, point pt, rectangle rectangle,string value){     **enumdatechooser = new datechoosercombo(             templatetypegroup, swt.border | cdt.drop_down                     | cdt.date_short);     enumdatechooser.setformatter(new dateformatter(             itabledataconstants.date_format_table_viewer));          enumdatechooser.setlayoutdata((griddata)data);     if(null != pt && null != rectangle){         enumdatechooser.setlocation(pt);         enumdatechooser.setbounds(rectangle);     }     enumdatechooser.setlocation(pt)**     try {     if(!isedit){               if (tabletemplateconfigconstants.enddatelst.contains(value)) {             enumdatechooser                     .setvalue(checkformat(tabletemplateconfigconstants.enddate));             dateformat formatter = new simpledateformat(tabletemplateconfigconstants.date_format_table_viewer);              setdefaultval(formatter.format(checkformat(enumdatechooser.gettext())));         } else if (tabletemplateconfigconstants.effectivedate                 .contains(value)) {             enumdatechooser.setvalue(new date());             dateformat formatter = new simpledateformat(tabletemplateconfigconstants.date_format_table_viewer);              setdefaultval(formatter.format(checkformat(enumdatechooser.gettext())));         } else if (null != getdefaultval() && !getdefaultval().isempty()) {             enumdatechooser.setvalue(checkformat(getdefaultval()));             setdefaultval(value);         }     }else{         enumdatechooser         .setvalue(checkformat(getdefaultval()));     }     } catch (parseexception e1) {         palogger.logerror("unable parse date",                 paeventcategory.others, activator.plugin_id,e1);     }      setdatedecoration(false);     enumdatechooser.addmodifylistener(new modifylistener() {          @override         public void modifytext(modifyevent e) {                          system.out.println(enumdatechooser.gettext());             if (null != enumdatechooser && !enumdatechooser.isdisposed()                     ) {                 setdatedecoration(true);             }             setdatecheckboxes();         }     }); } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -