Program: 35655
Project: 35655
Buggy source:
public ElementForm(Dispatcher dispatcher,final AsyncCallback<UpdateModelResult> callback,final FlexibleElementDTO flexibleElement,ProjectModelDTO projectModelToUpdate,OrgUnitModelDTO orgUnitModelToUpdate){
  final VBoxLayout mainPanelLayout=new VBoxLayout();
  mainPanelLayout.setVBoxLayoutAlign(VBoxLayout.VBoxLayoutAlign.STRETCH);
  setLayout(mainPanelLayout);
  setHeaderVisible(false);
  if (projectModelToUpdate != null) {
    isProject=true;
  }
 else {
    isProject=false;
  }
  this.dispatcher=dispatcher;
  this.projectModelToUpdate=projectModelToUpdate;
  this.orgUnitModelToUpdate=orgUnitModelToUpdate;
  this.flexibleElementToUpdate=flexibleElement;
  UIConstants constants=GWT.create(UIConstants.class);
  specificsPanel=new FormPanel();
  specificsPanel.setHeaderVisible(false);
  specificsPanel.setBorders(true);
  specificsPanel.hide();
  reportModelList=new ComboBox<ReportModelDTO>();
  reportModelList.setEditable(false);
  reportModelList.hide();
  reportModelList.setFieldLabel(I18N.CONSTANTS.adminReportName());
  reportModelList.setDisplayField("String_Node_Str");
  reportModelList.setValueField("String_Node_Str");
  reportModelList.setTriggerAction(TriggerAction.ALL);
  reportModelsStore=new ListStore<ReportModelDTO>();
  dispatcher.execute(new GetReportModels(),null,new AsyncCallback<ReportModelsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      reportModelList.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    ReportModelsListResult result){
      reportModelList.setEmptyText(I18N.CONSTANTS.adminReportName());
      reportModelsStore.removeAll();
      if (result != null) {
        reportModelsStore.add(result.getList());
        reportModelsStore.commitChanges();
      }
      if (flexibleElement != null) {
        if (flexibleElement instanceof ReportElementDTO) {
          if (((ReportElementDTO)flexibleElement).getModelId() != null) {
            for (            ReportModelDTO reportModel : reportModelsStore.getModels()) {
              if (reportModel.getId() == ((ReportElementDTO)flexibleElement).getModelId()) {
                reportModelList.setValue(reportModel);
              }
            }
          }
        }
      }
    }
  }
);
  reportModelList.setStore(reportModelsStore);
  maxLimitField=new NumberField();
  maxLimitField.setFieldLabel(I18N.CONSTANTS.adminFlexibleMaxLimit());
  maxLimitField.hide();
  textAreaTypeList=new SimpleComboBox<String>();
  textAreaTypeList.setTriggerAction(TriggerAction.ALL);
  textAreaTypeList.setEditable(false);
  textAreaTypeList.hide();
  textAreaTypeList.setFieldLabel(I18N.CONSTANTS.adminFlexibleTextType());
  List<String> textTypes=new ArrayList<String>();
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeP());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeT());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeN());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeD());
  textAreaTypeList.add(textTypes);
  minLimitField=new NumberField();
  minLimitField.setFieldLabel(I18N.CONSTANTS.adminFlexibleMinLimit());
  minLimitField.hide();
  lengthField=new NumberField();
  lengthField.setFieldLabel(I18N.CONSTANTS.adminFlexibleLength());
  lengthField.hide();
  isDecimal=new CheckBox();
  isDecimal.hide();
  isDecimal.setBoxLabel("String_Node_Str");
  isDecimal.setFieldLabel(I18N.CONSTANTS.adminFlexibleDecimal());
  isDecimal.setLabelSeparator("String_Node_Str");
  isMultipleQ=new CheckBox();
  isMultipleQ.hide();
  isMultipleQ.setBoxLabel("String_Node_Str");
  isMultipleQ.setFieldLabel(I18N.CONSTANTS.adminFlexibleMultipleQ());
  isMultipleQ.setLabelSeparator("String_Node_Str");
  isLinkedToQuality=new CheckBox();
  isLinkedToQuality.hide();
  isLinkedToQuality.setBoxLabel("String_Node_Str");
  isLinkedToQuality.setFieldLabel(I18N.CONSTANTS.adminFlexibleLinkedToQuality());
  isLinkedToQuality.setLabelSeparator("String_Node_Str");
  defaultNoCategory.setLabel(I18N.CONSTANTS.adminFlexibleNoLinkedCategory());
  defaultNoCategory.setId(-1);
  linkedCategory=new ComboBox<CategoryTypeDTO>();
  linkedCategory.setEditable(false);
  linkedCategory.hide();
  linkedCategory.setDisplayField(I18N.CONSTANTS.adminFlexibleNoLinkedCategory());
  linkedCategory.setFieldLabel(I18N.CONSTANTS.adminFlexibleLinkedCategory());
  linkedCategory.setDisplayField("String_Node_Str");
  linkedCategory.setValueField("String_Node_Str");
  linkedCategory.setTriggerAction(TriggerAction.ALL);
  final ListStore<CategoryTypeDTO> linkedCategoriesStore=new ListStore<CategoryTypeDTO>();
  linkedCategoriesStore.add(defaultNoCategory);
  dispatcher.execute(new GetCategories(),null,new AsyncCallback<CategoriesListResult>(){
    @Override public void onFailure(    Throwable arg0){
      linkedCategory.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    CategoriesListResult result){
      linkedCategory.setEmptyText(I18N.CONSTANTS.adminUserCreationProfileChoice());
      linkedCategoriesStore.removeAll();
      linkedCategoriesStore.add(defaultNoCategory);
      if (result != null) {
        linkedCategoriesStore.add(result.getList());
        linkedCategoriesStore.commitChanges();
      }
    }
  }
);
  linkedCategory.setStore(linkedCategoriesStore);
  for (int i=0; i < MAX_TENTATIVES_FOR_CHOICES; i++) {
    final ClickableLabel label=new ClickableLabel();
    label.addClickHandler(new ClickHandler(){
      @Override public void onClick(      ClickEvent arg0){
        label.hide();
        selectedChoicesLabels.remove(label.getText());
        if (selectedChoicesLabels.size() == 0) {
          linkedCategory.setEnabled(true);
        }
      }
    }
);
    label.hide();
    selectableChoices.put(i,label);
  }
  questionChoice=new TextField<String>();
  questionChoice.hide();
  qChoicesAddGrid.setVisible(false);
  qChoicesAddGrid.getCellFormatter().setWidth(0,0,(LABEL_WIDTH) + "String_Node_Str");
  qChoicesAddGrid.setCellPadding(0);
  qChoicesAddGrid.setCellSpacing(0);
  qChoicesAddGrid.setWidget(0,0,new LabelField(I18N.CONSTANTS.adminFlexibleQChoices() + "String_Node_Str"));
  qChoicesAddGrid.setWidget(0,1,questionChoice);
  questionChoice.setHideLabel(false);
  addChoiceButton.hide();
  addChoiceButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      if (questionChoice.getValue() != null) {
        if (!selectedChoicesLabels.contains(questionChoice.getValue())) {
          if (num < MAX_TENTATIVES_FOR_CHOICES) {
            linkedCategory.setEnabled(false);
            selectableChoices.get(num).setText(questionChoice.getValue());
            selectableChoices.get(num).show();
            num++;
            selectedChoicesLabels.add(questionChoice.getValue());
          }
 else {
            MessageBox.alert(I18N.CONSTANTS.adminMaxAttempts(),I18N.CONSTANTS.adminMaxAttemptsQChoices(),null);
            ElementForm.this.removeFromParent();
          }
        }
      }
    }
  }
);
  qChoicesAddGrid.setWidget(0,2,addChoiceButton);
  linkedCategory.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      if (linkedCategory.getValue() == null || defaultNoCategory.equals(linkedCategory.getValue())) {
        questionChoice.setEnabled(true);
        addChoiceButton.setEnabled(true);
      }
 else {
        questionChoice.setEnabled(false);
        addChoiceButton.setEnabled(false);
        for (        ClickableLabel selected : selectableChoices.values()) {
          selected.setEnabled(false);
        }
      }
    }
  }
);
  posBanner=new SimpleComboBox<Integer>();
  posBanner.setTriggerAction(TriggerAction.ALL);
  posBanner.setEditable(false);
  posBanner.setFieldLabel(constants.adminFlexibleBannerPosition());
  posBanner.removeAll();
  for (int i=1; i < 7; i++) {
    posBanner.add(i);
  }
  posBanner.setAllowBlank(true);
  posBanner.setEnabled(false);
  posBanner.hide();
  isBanner=new CheckBox();
  isBanner.setFieldLabel(constants.Admin_BANNER());
  isBanner.setBoxLabel("String_Node_Str");
  isBanner.setValue(false);
  isBanner.addListener(Events.Change,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      if (isBanner.getValue()) {
        posBanner.removeAll();
        for (int i=1; i < 7; i++) {
          posBanner.add(i);
        }
        posBanner.setEnabled(true);
        posBanner.setAllowBlank(false);
      }
 else {
        posBanner.removeAll();
        posBanner.setValue(null);
        posBanner.setAllowBlank(true);
        posBanner.setEnabled(false);
      }
    }
  }
);
  isBanner.hide();
  specificsPanel.add(isBanner);
  specificsPanel.add(posBanner);
  specificsPanel.add(reportModelList);
  specificsPanel.add(textAreaTypeList);
  specificsPanel.add(lengthField);
  specificsPanel.add(isDecimal);
  specificsPanel.add(minLimitField);
  specificsPanel.add(maxLimitField);
  specificsPanel.add(isMultipleQ);
  specificsPanel.add(isLinkedToQuality);
  specificsPanel.add(linkedCategory);
  specificsPanel.add(qChoicesAddGrid);
  for (  ClickableLabel selected : selectableChoices.values()) {
    selected.hide();
    specificsPanel.add(selected);
  }
  commonPanel=new FormPanel();
  commonPanel.setHeaderVisible(false);
  htmlArea=new HtmlEditor();
  htmlArea.hide();
  htmlArea.setEnableAlignments(false);
  htmlArea.setEnableLinks(false);
  htmlArea.setEnableFont(false);
  htmlArea.setEnableLists(false);
  htmlArea.setEnableColors(false);
  htmlArea.setSourceEditMode(false);
  htmlArea.setHeight(75);
  htmlArea.setFieldLabel(constants.adminFlexibleName());
  if (flexibleElement != null && flexibleElement.getLabel() != null) {
    htmlArea.setValue(flexibleElement.getLabel());
    oldFieldProperties.put(AdminUtil.PROP_FX_NAME,flexibleElement.getLabel());
  }
  LabelField label=new LabelField();
  label.hide();
  label.setFieldLabel(constants.adminFlexibleName());
  if (flexibleElement != null && flexibleElement.getElementType() != null) {
    if (ElementTypeEnum.DEFAULT.equals(flexibleElement.getElementType())) {
      label.setText(DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
      label.show();
      oldFieldProperties.put(AdminUtil.PROP_FX_NAME,DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
      htmlArea.setValue(DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
    }
 else {
      htmlArea.show();
    }
  }
 else {
    htmlArea.show();
  }
  commonPanel.add(label);
  commonPanel.add(htmlArea);
  typeList=new SimpleComboBox<String>();
  typeList.setEditable(false);
  typeList.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      hideAllSpecificAttributes();
      showSpecificAttributes(typeList.getSimpleValue(),flexibleElementToUpdate,true);
    }
  }
);
  typeList.setFieldLabel(constants.adminFlexibleType());
  typeList.setAllowBlank(false);
  typeList.setTriggerAction(TriggerAction.ALL);
  List<String> values=new ArrayList<String>();
  for (  ElementTypeEnum e : ElementTypeEnum.values()) {
    if (!ElementTypeEnum.DEFAULT.equals(e) && !ElementTypeEnum.TRIPLETS.equals(e) && !ElementTypeEnum.INDICATORS.equals(e))     values.add(ElementTypeEnum.getName(e));
  }
  typeList.add(values);
  if (flexibleElement != null && flexibleElement.getElementType() != null) {
    String typeOfElement=ElementTypeEnum.getName(flexibleElement.getElementType());
    typeList.setSimpleValue(typeOfElement);
    showSpecificAttributes(typeOfElement,flexibleElement,false);
    oldFieldProperties.put(AdminUtil.PROP_FX_TYPE,flexibleElement.getElementType());
    if (ElementTypeEnum.DEFAULT.equals(flexibleElement.getElementType())) {
      typeList.setEnabled(false);
    }
  }
 else   typeList.setEmptyText(I18N.CONSTANTS.adminFlexibleType());
  commonPanel.add(typeList);
  final ListStore<BaseModelData> containersStore=new ListStore<BaseModelData>();
  containerList=new ComboBox<BaseModelData>();
  containerList.setEditable(false);
  containerList.setDisplayField("String_Node_Str");
  containerList.setValueField("String_Node_Str");
  containerList.setFieldLabel(I18N.CONSTANTS.adminFlexibleContainer());
  containerList.setAllowBlank(false);
  containerList.setTriggerAction(TriggerAction.ALL);
  if (flexibleElement == null)   containerList.setEmptyText(I18N.CONSTANTS.adminFlexibleContainerChoice());
  final ListStore<LayoutGroupDTO> groupsStore=new ListStore<LayoutGroupDTO>();
  groupList=new ComboBox<LayoutGroupDTO>();
  groupList.setEditable(false);
  groupList.setFieldLabel(constants.adminFlexibleGroup());
  groupList.setDisplayField("String_Node_Str");
  groupList.setValueField("String_Node_Str");
  groupList.setTriggerAction(TriggerAction.ALL);
  containerList.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      LayoutDTO container=null;
      if (containerList.getValue() != null) {
        if (containerList.getValue() instanceof ProjectBannerDTO) {
          container=((ProjectBannerDTO)containerList.getValue()).getLayoutDTO();
          isBanner.setValue(true);
          posBanner.setAllowBlank(false);
          posBanner.setEnabled(true);
        }
 else         if (containerList.getValue() instanceof ProjectDetailsDTO) {
          container=((ProjectDetailsDTO)containerList.getValue()).getLayoutDTO();
        }
 else         if (containerList.getValue() instanceof PhaseModelDTO) {
          container=((PhaseModelDTO)containerList.getValue()).getLayoutDTO();
        }
 else         if (containerList.getValue() instanceof OrgUnitDetailsDTO) {
          container=((OrgUnitDetailsDTO)containerList.getValue()).getLayout();
        }
      }
      if (container != null) {
        groupsStore.removeAll();
        for (        LayoutGroupDTO lg : container.getLayoutGroupsDTO()) {
          groupsStore.add(lg);
        }
        groupList.setValue(groupsStore.getAt(0));
      }
    }
  }
);
  orderField=new NumberField();
  orderField.setAllowBlank(false);
  orderField.setFieldLabel(constants.adminFlexibleOrder());
  orderField.clear();
  oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,false);
  oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,-1);
  if (isProject) {
    if (flexibleElement != null) {
      BaseModelData container=flexibleElement.getContainerModel();
      containerList.setValue(flexibleElement.getContainerModel());
      groupList.setValue(flexibleElement.getConstraint().getParentLayoutGroupDTO());
      orderField.setValue(flexibleElement.getConstraint().getSortOrder());
      groupsStore.removeAll();
      if (container instanceof PhaseModelDTO) {
        for (        LayoutGroupDTO groupChoice : ((PhaseModelDTO)container).getLayoutDTO().getLayoutGroupsDTO()) {
          groupsStore.add(groupChoice);
        }
      }
 else {
        for (        LayoutGroupDTO groupChoice : ((ProjectDetailsDTO)container).getLayoutDTO().getLayoutGroupsDTO()) {
          groupsStore.add(groupChoice);
        }
      }
      if (flexibleElement.getBannerConstraint() != null) {
        posBanner.setSimpleValue(flexibleElement.getBannerConstraint().getSortOrder());
        isBanner.setValue(true);
        oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,true);
        oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,flexibleElement.getBannerConstraint().getSortOrder());
        oldFieldProperties.put(AdminUtil.PROP_FX_LC_BANNER,flexibleElement.getBannerConstraint());
      }
      oldFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,new Integer(flexibleElement.getConstraint().getSortOrder()));
      oldFieldProperties.put(AdminUtil.PROP_FX_GROUP,flexibleElement.getConstraint().getParentLayoutGroupDTO());
      oldFieldProperties.put(AdminUtil.PROP_FX_LC,flexibleElement.getConstraint());
    }
    containersStore.add(projectModelToUpdate.getProjectDetailsDTO());
    for (    PhaseModelDTO p : projectModelToUpdate.getPhaseModelsDTO()) {
      containersStore.add(p);
    }
  }
 else {
    if (flexibleElement != null) {
      BaseModelData container=flexibleElement.getContainerModel();
      containerList.setValue(flexibleElement.getContainerModel());
      groupList.setValue(flexibleElement.getConstraint().getParentLayoutGroupDTO());
      orderField.setValue(flexibleElement.getConstraint().getSortOrder());
      groupsStore.removeAll();
      for (      LayoutGroupDTO groupChoice : ((OrgUnitDetailsDTO)container).getLayout().getLayoutGroupsDTO()) {
        groupsStore.add(groupChoice);
      }
      if (flexibleElement.getBannerConstraint() != null) {
        posBanner.setSimpleValue(flexibleElement.getBannerConstraint().getSortOrder());
        isBanner.setValue(true);
        oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,true);
        oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,flexibleElement.getBannerConstraint().getSortOrder());
        oldFieldProperties.put(AdminUtil.PROP_FX_LC_BANNER,flexibleElement.getBannerConstraint());
      }
      oldFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,new Integer(flexibleElement.getConstraint().getSortOrder()));
      oldFieldProperties.put(AdminUtil.PROP_FX_GROUP,flexibleElement.getConstraint().getParentLayoutGroupDTO());
      oldFieldProperties.put(AdminUtil.PROP_FX_LC,flexibleElement.getConstraint());
    }
    containersStore.add(orgUnitModelToUpdate.getDetails());
  }
  containerList.setStore(containersStore);
  commonPanel.add(containerList);
  groupList.setStore(groupsStore);
  commonPanel.add(groupList);
  commonPanel.add(orderField);
  validates=new CheckBox();
  validates.setFieldLabel(constants.adminFlexibleCompulsory());
  validates.setBoxLabel("String_Node_Str");
  validates.setValue(false);
  if (flexibleElement != null) {
    validates.setValue(flexibleElement.getValidates());
    oldFieldProperties.put(AdminUtil.PROP_FX_IS_COMPULSARY,flexibleElement.getValidates());
  }
  commonPanel.add(validates);
  privacyGroupsListCombo=new ComboBox<PrivacyGroupDTO>();
  privacyGroupsListCombo.setEditable(false);
  privacyGroupsListCombo.setFieldLabel(constants.adminPrivacyGroups());
  privacyGroupsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsListCombo.setValueField("String_Node_Str");
  privacyGroupsListCombo.setTriggerAction(TriggerAction.ALL);
  final ListStore<PrivacyGroupDTO> privacyGroupsStore=new ListStore<PrivacyGroupDTO>();
  dispatcher.execute(new GetPrivacyGroups(),null,new AsyncCallback<PrivacyGroupsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    PrivacyGroupsListResult result){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminPrivacyGroupChoice());
      privacyGroupsStore.removeAll();
      if (result != null) {
        privacyGroupsStore.add(result.getList());
        privacyGroupsStore.commitChanges();
      }
    }
  }
);
  privacyGroupsListCombo.setStore(privacyGroupsStore);
  if (flexibleElement != null && flexibleElement.getPrivacyGroup() != null) {
    privacyGroupsListCombo.setValue(flexibleElement.getPrivacyGroup());
    oldFieldProperties.put(AdminUtil.PROP_FX_PRIVACY_GROUP,flexibleElement.getPrivacyGroup());
  }
  commonPanel.add(privacyGroupsListCombo);
  isAmendable=new CheckBox();
  isAmendable.setBoxLabel("String_Node_Str");
  isAmendable.setFieldLabel(constants.adminFlexibleAmendable());
  isAmendable.setValue(false);
  if (flexibleElement != null) {
    isAmendable.setValue(flexibleElement.getAmendable());
    oldFieldProperties.put(AdminUtil.PROP_FX_AMENDABLE,flexibleElement.getAmendable());
  }
  commonPanel.add(isAmendable);
  final Button createButton=new Button(I18N.CONSTANTS.save(),IconImageBundle.ICONS.save());
  createButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      createFlexibleElement(callback);
    }
  }
);
  final ContentPanel form=new ContentPanel();
  form.setHeight(450);
  form.setHeaderVisible(false);
  form.setLayout(new BorderLayout());
  final BorderLayoutData leftLayoutData=new BorderLayoutData(LayoutRegion.WEST);
  leftLayoutData.setSize(320);
  form.add(commonPanel,leftLayoutData);
  final BorderLayoutData rightLayoutData=new BorderLayoutData(LayoutRegion.CENTER);
  rightLayoutData.setMargins(new Margins(0,0,2,4));
  rightLayoutData.setSize(200);
  form.add(specificsPanel,rightLayoutData);
  final VBoxLayoutData topVBoxLayoutData=new VBoxLayoutData();
  topVBoxLayoutData.setFlex(1.0);
  add(form,topVBoxLayoutData);
  ToolBar toolbar=new ToolBar();
  toolbar.setAlignment(HorizontalAlignment.CENTER);
  toolbar.add(createButton);
  setBottomComponent(toolbar);
  layout();
}

Fixed version (ground truth):
public ElementForm(Dispatcher dispatcher,final AsyncCallback<UpdateModelResult> callback,final FlexibleElementDTO flexibleElement,ProjectModelDTO projectModelToUpdate,OrgUnitModelDTO orgUnitModelToUpdate){
  final VBoxLayout mainPanelLayout=new VBoxLayout();
  mainPanelLayout.setVBoxLayoutAlign(VBoxLayout.VBoxLayoutAlign.STRETCH);
  setLayout(mainPanelLayout);
  setHeaderVisible(false);
  if (projectModelToUpdate != null) {
    isProject=true;
  }
 else {
    isProject=false;
  }
  this.dispatcher=dispatcher;
  this.projectModelToUpdate=projectModelToUpdate;
  this.orgUnitModelToUpdate=orgUnitModelToUpdate;
  this.flexibleElementToUpdate=flexibleElement;
  UIConstants constants=GWT.create(UIConstants.class);
  specificsPanel=new FormPanel();
  specificsPanel.setHeaderVisible(false);
  specificsPanel.setBorders(true);
  specificsPanel.hide();
  reportModelList=new ComboBox<ReportModelDTO>();
  reportModelList.setEditable(false);
  reportModelList.hide();
  reportModelList.setFieldLabel(I18N.CONSTANTS.adminReportName());
  reportModelList.setDisplayField("String_Node_Str");
  reportModelList.setValueField("String_Node_Str");
  reportModelList.setTriggerAction(TriggerAction.ALL);
  reportModelsStore=new ListStore<ReportModelDTO>();
  dispatcher.execute(new GetReportModels(),null,new AsyncCallback<ReportModelsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      reportModelList.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    ReportModelsListResult result){
      reportModelList.setEmptyText(I18N.CONSTANTS.adminReportName());
      reportModelsStore.removeAll();
      if (result != null) {
        reportModelsStore.add(result.getList());
        reportModelsStore.commitChanges();
      }
      if (flexibleElement != null) {
        if (flexibleElement instanceof ReportElementDTO) {
          if (((ReportElementDTO)flexibleElement).getModelId() != null) {
            for (            ReportModelDTO reportModel : reportModelsStore.getModels()) {
              if (reportModel.getId() == ((ReportElementDTO)flexibleElement).getModelId()) {
                reportModelList.setValue(reportModel);
              }
            }
          }
        }
      }
    }
  }
);
  reportModelList.setStore(reportModelsStore);
  maxLimitField=new NumberField();
  maxLimitField.setFieldLabel(I18N.CONSTANTS.adminFlexibleMaxLimit());
  maxLimitField.hide();
  textAreaTypeList=new SimpleComboBox<String>();
  textAreaTypeList.setTriggerAction(TriggerAction.ALL);
  textAreaTypeList.setEditable(false);
  textAreaTypeList.hide();
  textAreaTypeList.setFieldLabel(I18N.CONSTANTS.adminFlexibleTextType());
  List<String> textTypes=new ArrayList<String>();
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeP());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeT());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeN());
  textTypes.add(I18N.CONSTANTS.adminFlexibleTextTypeD());
  textAreaTypeList.add(textTypes);
  minLimitField=new NumberField();
  minLimitField.setFieldLabel(I18N.CONSTANTS.adminFlexibleMinLimit());
  minLimitField.hide();
  lengthField=new NumberField();
  lengthField.setFieldLabel(I18N.CONSTANTS.adminFlexibleLength());
  lengthField.hide();
  isDecimal=new CheckBox();
  isDecimal.hide();
  isDecimal.setBoxLabel("String_Node_Str");
  isDecimal.setFieldLabel(I18N.CONSTANTS.adminFlexibleDecimal());
  isDecimal.setLabelSeparator("String_Node_Str");
  isMultipleQ=new CheckBox();
  isMultipleQ.hide();
  isMultipleQ.setBoxLabel("String_Node_Str");
  isMultipleQ.setFieldLabel(I18N.CONSTANTS.adminFlexibleMultipleQ());
  isMultipleQ.setLabelSeparator("String_Node_Str");
  isLinkedToQuality=new CheckBox();
  isLinkedToQuality.hide();
  isLinkedToQuality.setBoxLabel("String_Node_Str");
  isLinkedToQuality.setFieldLabel(I18N.CONSTANTS.adminFlexibleLinkedToQuality());
  isLinkedToQuality.setLabelSeparator("String_Node_Str");
  defaultNoCategory.setLabel(I18N.CONSTANTS.adminFlexibleNoLinkedCategory());
  defaultNoCategory.setId(-1);
  linkedCategory=new ComboBox<CategoryTypeDTO>();
  linkedCategory.setEditable(false);
  linkedCategory.hide();
  linkedCategory.setDisplayField(I18N.CONSTANTS.adminFlexibleNoLinkedCategory());
  linkedCategory.setFieldLabel(I18N.CONSTANTS.adminFlexibleLinkedCategory());
  linkedCategory.setDisplayField("String_Node_Str");
  linkedCategory.setValueField("String_Node_Str");
  linkedCategory.setTriggerAction(TriggerAction.ALL);
  final ListStore<CategoryTypeDTO> linkedCategoriesStore=new ListStore<CategoryTypeDTO>();
  linkedCategoriesStore.add(defaultNoCategory);
  dispatcher.execute(new GetCategories(),null,new AsyncCallback<CategoriesListResult>(){
    @Override public void onFailure(    Throwable arg0){
      linkedCategory.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    CategoriesListResult result){
      linkedCategory.setEmptyText(I18N.CONSTANTS.adminUserCreationProfileChoice());
      linkedCategoriesStore.removeAll();
      linkedCategoriesStore.add(defaultNoCategory);
      if (result != null) {
        linkedCategoriesStore.add(result.getList());
        linkedCategoriesStore.commitChanges();
      }
    }
  }
);
  linkedCategory.setStore(linkedCategoriesStore);
  for (int i=0; i < MAX_TENTATIVES_FOR_CHOICES; i++) {
    final ClickableLabel label=new ClickableLabel();
    label.addClickHandler(new ClickHandler(){
      @Override public void onClick(      ClickEvent arg0){
        label.hide();
        selectedChoicesLabels.remove(label.getText());
        if (selectedChoicesLabels.size() == 0) {
          linkedCategory.setEnabled(true);
        }
      }
    }
);
    label.hide();
    selectableChoices.put(i,label);
  }
  questionChoice=new TextField<String>();
  questionChoice.hide();
  qChoicesAddGrid.setVisible(false);
  qChoicesAddGrid.getCellFormatter().setWidth(0,0,(LABEL_WIDTH) + "String_Node_Str");
  qChoicesAddGrid.setCellPadding(0);
  qChoicesAddGrid.setCellSpacing(0);
  qChoicesAddGrid.setWidget(0,0,new LabelField(I18N.CONSTANTS.adminFlexibleQChoices() + "String_Node_Str"));
  qChoicesAddGrid.setWidget(0,1,questionChoice);
  questionChoice.setHideLabel(false);
  addChoiceButton.hide();
  addChoiceButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      if (questionChoice.getValue() != null) {
        if (!selectedChoicesLabels.contains(questionChoice.getValue())) {
          if (num < MAX_TENTATIVES_FOR_CHOICES) {
            linkedCategory.setEnabled(false);
            selectableChoices.get(num).setText(questionChoice.getValue());
            selectableChoices.get(num).show();
            num++;
            selectedChoicesLabels.add(questionChoice.getValue());
          }
 else {
            MessageBox.alert(I18N.CONSTANTS.adminMaxAttempts(),I18N.CONSTANTS.adminMaxAttemptsQChoices(),null);
            ElementForm.this.removeFromParent();
          }
        }
      }
    }
  }
);
  qChoicesAddGrid.setWidget(0,2,addChoiceButton);
  linkedCategory.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      if (linkedCategory.getValue() == null || defaultNoCategory.equals(linkedCategory.getValue())) {
        questionChoice.setEnabled(true);
        addChoiceButton.setEnabled(true);
      }
 else {
        questionChoice.setEnabled(false);
        addChoiceButton.setEnabled(false);
        for (        ClickableLabel selected : selectableChoices.values()) {
          selected.setEnabled(false);
        }
      }
    }
  }
);
  posBanner=new SimpleComboBox<Integer>();
  posBanner.setTriggerAction(TriggerAction.ALL);
  posBanner.setEditable(false);
  posBanner.setFieldLabel(constants.adminFlexibleBannerPosition());
  posBanner.removeAll();
  for (int i=1; i < 7; i++) {
    posBanner.add(i);
  }
  posBanner.setAllowBlank(true);
  posBanner.setEnabled(false);
  posBanner.hide();
  isBanner=new CheckBox();
  isBanner.setFieldLabel(constants.Admin_BANNER());
  isBanner.setBoxLabel("String_Node_Str");
  isBanner.setValue(false);
  isBanner.addListener(Events.Change,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      if (isBanner.getValue()) {
        posBanner.removeAll();
        for (int i=1; i < 7; i++) {
          posBanner.add(i);
        }
        posBanner.setEnabled(true);
        posBanner.setAllowBlank(false);
      }
 else {
        posBanner.removeAll();
        posBanner.setValue(null);
        posBanner.setAllowBlank(true);
        posBanner.setEnabled(false);
      }
    }
  }
);
  isBanner.hide();
  specificsPanel.add(isBanner);
  specificsPanel.add(posBanner);
  specificsPanel.add(reportModelList);
  specificsPanel.add(textAreaTypeList);
  specificsPanel.add(lengthField);
  specificsPanel.add(isDecimal);
  specificsPanel.add(minLimitField);
  specificsPanel.add(maxLimitField);
  specificsPanel.add(isMultipleQ);
  specificsPanel.add(isLinkedToQuality);
  specificsPanel.add(linkedCategory);
  specificsPanel.add(qChoicesAddGrid);
  for (  ClickableLabel selected : selectableChoices.values()) {
    selected.hide();
    specificsPanel.add(selected);
  }
  commonPanel=new FormPanel();
  commonPanel.setHeaderVisible(false);
  htmlArea=new HtmlEditor();
  htmlArea.hide();
  htmlArea.setEnableAlignments(false);
  htmlArea.setEnableLinks(false);
  htmlArea.setEnableFont(false);
  htmlArea.setEnableLists(false);
  htmlArea.setEnableColors(false);
  htmlArea.setSourceEditMode(false);
  htmlArea.setHeight(75);
  htmlArea.setFieldLabel(constants.adminFlexibleName());
  if (flexibleElement != null && flexibleElement.getLabel() != null) {
    htmlArea.setValue(flexibleElement.getLabel());
    oldFieldProperties.put(AdminUtil.PROP_FX_NAME,flexibleElement.getLabel());
  }
  LabelField label=new LabelField();
  label.hide();
  label.setFieldLabel(constants.adminFlexibleName());
  if (flexibleElement != null && flexibleElement.getElementType() != null) {
    if (ElementTypeEnum.DEFAULT.equals(flexibleElement.getElementType())) {
      label.setText(DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
      label.show();
      oldFieldProperties.put(AdminUtil.PROP_FX_NAME,DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
      htmlArea.setValue(DefaultFlexibleElementType.getName(((DefaultFlexibleElementDTO)flexibleElement).getType()));
    }
 else {
      htmlArea.show();
    }
  }
 else {
    htmlArea.show();
  }
  commonPanel.add(label);
  commonPanel.add(htmlArea);
  typeList=new SimpleComboBox<String>();
  typeList.setEditable(false);
  typeList.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      hideAllSpecificAttributes();
      showSpecificAttributes(typeList.getSimpleValue(),flexibleElementToUpdate,true);
    }
  }
);
  typeList.setFieldLabel(constants.adminFlexibleType());
  typeList.setAllowBlank(false);
  typeList.setTriggerAction(TriggerAction.ALL);
  List<String> values=new ArrayList<String>();
  for (  ElementTypeEnum e : ElementTypeEnum.values()) {
    if (!ElementTypeEnum.DEFAULT.equals(e) && !ElementTypeEnum.INDICATORS.equals(e))     values.add(ElementTypeEnum.getName(e));
  }
  typeList.add(values);
  if (flexibleElement != null && flexibleElement.getElementType() != null) {
    String typeOfElement=ElementTypeEnum.getName(flexibleElement.getElementType());
    typeList.setSimpleValue(typeOfElement);
    showSpecificAttributes(typeOfElement,flexibleElement,false);
    oldFieldProperties.put(AdminUtil.PROP_FX_TYPE,flexibleElement.getElementType());
    if (ElementTypeEnum.DEFAULT.equals(flexibleElement.getElementType())) {
      typeList.setEnabled(false);
    }
  }
 else   typeList.setEmptyText(I18N.CONSTANTS.adminFlexibleType());
  commonPanel.add(typeList);
  final ListStore<BaseModelData> containersStore=new ListStore<BaseModelData>();
  containerList=new ComboBox<BaseModelData>();
  containerList.setEditable(false);
  containerList.setDisplayField("String_Node_Str");
  containerList.setValueField("String_Node_Str");
  containerList.setFieldLabel(I18N.CONSTANTS.adminFlexibleContainer());
  containerList.setAllowBlank(false);
  containerList.setTriggerAction(TriggerAction.ALL);
  if (flexibleElement == null)   containerList.setEmptyText(I18N.CONSTANTS.adminFlexibleContainerChoice());
  final ListStore<LayoutGroupDTO> groupsStore=new ListStore<LayoutGroupDTO>();
  groupList=new ComboBox<LayoutGroupDTO>();
  groupList.setEditable(false);
  groupList.setFieldLabel(constants.adminFlexibleGroup());
  groupList.setDisplayField("String_Node_Str");
  groupList.setValueField("String_Node_Str");
  groupList.setTriggerAction(TriggerAction.ALL);
  containerList.addListener(Events.Select,new Listener<BaseEvent>(){
    @Override public void handleEvent(    BaseEvent be){
      LayoutDTO container=null;
      if (containerList.getValue() != null) {
        if (containerList.getValue() instanceof ProjectBannerDTO) {
          container=((ProjectBannerDTO)containerList.getValue()).getLayoutDTO();
          isBanner.setValue(true);
          posBanner.setAllowBlank(false);
          posBanner.setEnabled(true);
        }
 else         if (containerList.getValue() instanceof ProjectDetailsDTO) {
          container=((ProjectDetailsDTO)containerList.getValue()).getLayoutDTO();
        }
 else         if (containerList.getValue() instanceof PhaseModelDTO) {
          container=((PhaseModelDTO)containerList.getValue()).getLayoutDTO();
        }
 else         if (containerList.getValue() instanceof OrgUnitDetailsDTO) {
          container=((OrgUnitDetailsDTO)containerList.getValue()).getLayout();
        }
      }
      if (container != null) {
        groupsStore.removeAll();
        for (        LayoutGroupDTO lg : container.getLayoutGroupsDTO()) {
          groupsStore.add(lg);
        }
        groupList.setValue(groupsStore.getAt(0));
      }
    }
  }
);
  orderField=new NumberField();
  orderField.setAllowBlank(false);
  orderField.setFieldLabel(constants.adminFlexibleOrder());
  orderField.clear();
  oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,false);
  oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,-1);
  if (isProject) {
    if (flexibleElement != null) {
      BaseModelData container=flexibleElement.getContainerModel();
      containerList.setValue(flexibleElement.getContainerModel());
      groupList.setValue(flexibleElement.getConstraint().getParentLayoutGroupDTO());
      orderField.setValue(flexibleElement.getConstraint().getSortOrder());
      groupsStore.removeAll();
      if (container instanceof PhaseModelDTO) {
        for (        LayoutGroupDTO groupChoice : ((PhaseModelDTO)container).getLayoutDTO().getLayoutGroupsDTO()) {
          groupsStore.add(groupChoice);
        }
      }
 else {
        for (        LayoutGroupDTO groupChoice : ((ProjectDetailsDTO)container).getLayoutDTO().getLayoutGroupsDTO()) {
          groupsStore.add(groupChoice);
        }
      }
      if (flexibleElement.getBannerConstraint() != null) {
        posBanner.setSimpleValue(flexibleElement.getBannerConstraint().getSortOrder());
        isBanner.setValue(true);
        oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,true);
        oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,flexibleElement.getBannerConstraint().getSortOrder());
        oldFieldProperties.put(AdminUtil.PROP_FX_LC_BANNER,flexibleElement.getBannerConstraint());
      }
      oldFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,new Integer(flexibleElement.getConstraint().getSortOrder()));
      oldFieldProperties.put(AdminUtil.PROP_FX_GROUP,flexibleElement.getConstraint().getParentLayoutGroupDTO());
      oldFieldProperties.put(AdminUtil.PROP_FX_LC,flexibleElement.getConstraint());
    }
    containersStore.add(projectModelToUpdate.getProjectDetailsDTO());
    for (    PhaseModelDTO p : projectModelToUpdate.getPhaseModelsDTO()) {
      containersStore.add(p);
    }
  }
 else {
    if (flexibleElement != null) {
      BaseModelData container=flexibleElement.getContainerModel();
      containerList.setValue(flexibleElement.getContainerModel());
      groupList.setValue(flexibleElement.getConstraint().getParentLayoutGroupDTO());
      orderField.setValue(flexibleElement.getConstraint().getSortOrder());
      groupsStore.removeAll();
      for (      LayoutGroupDTO groupChoice : ((OrgUnitDetailsDTO)container).getLayout().getLayoutGroupsDTO()) {
        groupsStore.add(groupChoice);
      }
      if (flexibleElement.getBannerConstraint() != null) {
        posBanner.setSimpleValue(flexibleElement.getBannerConstraint().getSortOrder());
        isBanner.setValue(true);
        oldFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,true);
        oldFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,flexibleElement.getBannerConstraint().getSortOrder());
        oldFieldProperties.put(AdminUtil.PROP_FX_LC_BANNER,flexibleElement.getBannerConstraint());
      }
      oldFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,new Integer(flexibleElement.getConstraint().getSortOrder()));
      oldFieldProperties.put(AdminUtil.PROP_FX_GROUP,flexibleElement.getConstraint().getParentLayoutGroupDTO());
      oldFieldProperties.put(AdminUtil.PROP_FX_LC,flexibleElement.getConstraint());
    }
    containersStore.add(orgUnitModelToUpdate.getDetails());
  }
  containerList.setStore(containersStore);
  commonPanel.add(containerList);
  groupList.setStore(groupsStore);
  commonPanel.add(groupList);
  commonPanel.add(orderField);
  validates=new CheckBox();
  validates.setFieldLabel(constants.adminFlexibleCompulsory());
  validates.setBoxLabel("String_Node_Str");
  validates.setValue(false);
  if (flexibleElement != null) {
    validates.setValue(flexibleElement.getValidates());
    oldFieldProperties.put(AdminUtil.PROP_FX_IS_COMPULSARY,flexibleElement.getValidates());
  }
  commonPanel.add(validates);
  privacyGroupsListCombo=new ComboBox<PrivacyGroupDTO>();
  privacyGroupsListCombo.setEditable(false);
  privacyGroupsListCombo.setFieldLabel(constants.adminPrivacyGroups());
  privacyGroupsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsListCombo.setValueField("String_Node_Str");
  privacyGroupsListCombo.setTriggerAction(TriggerAction.ALL);
  final ListStore<PrivacyGroupDTO> privacyGroupsStore=new ListStore<PrivacyGroupDTO>();
  dispatcher.execute(new GetPrivacyGroups(),null,new AsyncCallback<PrivacyGroupsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    PrivacyGroupsListResult result){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminPrivacyGroupChoice());
      privacyGroupsStore.removeAll();
      if (result != null) {
        privacyGroupsStore.add(result.getList());
        privacyGroupsStore.commitChanges();
      }
    }
  }
);
  privacyGroupsListCombo.setStore(privacyGroupsStore);
  if (flexibleElement != null && flexibleElement.getPrivacyGroup() != null) {
    privacyGroupsListCombo.setValue(flexibleElement.getPrivacyGroup());
    oldFieldProperties.put(AdminUtil.PROP_FX_PRIVACY_GROUP,flexibleElement.getPrivacyGroup());
  }
  commonPanel.add(privacyGroupsListCombo);
  isAmendable=new CheckBox();
  isAmendable.setBoxLabel("String_Node_Str");
  isAmendable.setFieldLabel(constants.adminFlexibleAmendable());
  isAmendable.setValue(false);
  if (flexibleElement != null) {
    isAmendable.setValue(flexibleElement.getAmendable());
    oldFieldProperties.put(AdminUtil.PROP_FX_AMENDABLE,flexibleElement.getAmendable());
  }
  commonPanel.add(isAmendable);
  final Button createButton=new Button(I18N.CONSTANTS.save(),IconImageBundle.ICONS.save());
  createButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      createFlexibleElement(callback);
    }
  }
);
  final ContentPanel form=new ContentPanel();
  form.setHeight(450);
  form.setHeaderVisible(false);
  form.setLayout(new BorderLayout());
  final BorderLayoutData leftLayoutData=new BorderLayoutData(LayoutRegion.WEST);
  leftLayoutData.setSize(320);
  form.add(commonPanel,leftLayoutData);
  final BorderLayoutData rightLayoutData=new BorderLayoutData(LayoutRegion.CENTER);
  rightLayoutData.setMargins(new Margins(0,0,2,4));
  rightLayoutData.setSize(200);
  form.add(specificsPanel,rightLayoutData);
  final VBoxLayoutData topVBoxLayoutData=new VBoxLayoutData();
  topVBoxLayoutData.setFlex(1.0);
  add(form,topVBoxLayoutData);
  ToolBar toolbar=new ToolBar();
  toolbar.setAlignment(HorizontalAlignment.CENTER);
  toolbar.add(createButton);
  setBottomComponent(toolbar);
  layout();
}