private void setTranslationForAttribute(Attribute attr, EntityAttributeTableModel model) { List<TranslationVO> lstTranslation = new ArrayList<TranslationVO>(); for (LocaleInfo info : LocaleDelegate.getInstance().getAllLocales(false)) { Map<String, String> mpValues = new HashMap<String, String>(); mpValues.put(TranslationVO.labelsField[0], attr.getLabel()); mpValues.put(TranslationVO.labelsField[1], attr.getDescription()); TranslationVO voTranslation = new TranslationVO(info.localeId, info.title, info.language, mpValues); lstTranslation.add(voTranslation); } model.addTranslation(attr, lstTranslation); }
@Override public void applyState() throws InvalidStateException { if (rbCopyAttributes.isSelected() || rbAssignAttributes.isSelected()) { EntityAttributeSelectTableModel model = (EntityAttributeSelectTableModel) tblFields.getModel(); List<Attribute> lstAttribute = model.getAttributes(); EntityAttributeTableModel modelAttribute = new EntityAttributeTableModel(); for (Attribute attr : lstAttribute) { if (attr.isForResume()) modelAttribute.addAttribute(attr); } for (Attribute attr : modelAttribute.getAttributes()) { if (!existAttribute(attr)) { if (attr.getInternalId() == null) attr.setInternalId(getHighestInternalId()); if (this.model.isEditMode()) { // attr.setDistinct(false); // @todo uncomment this. some databases can not handle // unique and nullable fields attr.setMandatory(false); } this.model.getAttributeModel().addAttribute(attr); setTranslationForAttribute(attr, this.model.getAttributeModel()); } } } else if (rbTemplateAttributes.isSelected()) { EntityAttributeSelectTableModel model = (EntityAttributeSelectTableModel) tblFields.getModel(); List<Attribute> lstAttribute = model.getAttributes(); EntityAttributeTableModel modelAttribute = new EntityAttributeTableModel(); for (Attribute attr : this.model.getAttributeModel().getAttributes()) { modelAttribute.addAttribute(attr); modelAttribute.addTranslation( attr, this.model.getAttributeModel().getTranslation().get(attr)); } for (Attribute attr : lstAttribute) { if (!existAttribute(attr)) { attr.setInternalId(getHighestInternalId()); modelAttribute.addAttribute(attr); setTranslationForAttribute(attr, modelAttribute); } } this.model.setAttributeModel(modelAttribute); } else if (rbImportTable.isSelected()) { String jdbc = getJDBCUrl(); this.model.setJdbcUrl(jdbc); this.model.setExternalUser(tfImportUser.getText().trim()); this.model.setExternalPassword(tfImportPassword.getText().trim()); this.model.setExternalTable((String) cbxImportTables.getSelectedItem()); this.model.setImportTable(true); List<MasterDataVO> lstVO = MetaDataDelegate.getInstance() .transformTable( jdbc, model.getExternalUser(), model.getExternalPassword(), model.getExternalUser().trim().toUpperCase(), model.getExternalTable()); EntityAttributeTableModel modelAttribute = new EntityAttributeTableModel(); for (MasterDataVO vo : lstVO) { Attribute attr = new Attribute(); attr.setField((String) vo.getField("name")); attr.setInternalName((String) vo.getField("name")); attr.setDbName((String) vo.getField("dbfield")); attr.setDescription((String) vo.getField("description")); DataTyp datatyp = new DataTyp(); datatyp.setJavaType((String) vo.getField("datatype")); datatyp.setPrecision((Integer) vo.getField("dataprecision")); datatyp.setScale((Integer) vo.getField("datascale")); attr.setDatatyp(datatyp); attr.setLogBook((Boolean) vo.getField("logbook")); attr.setDistinct((Boolean) vo.getField("unique")); attr.setMandatory((Boolean) vo.getField("nullable")); attr.setLabel((String) vo.getField("label")); modelAttribute.addAttribute(attr); } this.model.setAttributeModel(modelAttribute); } super.applyState(); }