@Override public void performAction(ActionEvent e) { ProjectController mediator = getProjectController(); DataMap dataMap = mediator.getCurrentDataMap(); Embeddable embeddable = new Embeddable(); embeddable.setClassName(NameBuilder.builder(embeddable, dataMap).name()); createEmbeddable(dataMap, embeddable); application.getUndoManager().addEdit(new CreateEmbeddableUndoableEdit(dataMap, embeddable)); }
void setClassName(String newClassName) { if (newClassName != null && newClassName.trim().length() == 0) { newClassName = null; } Embeddable embeddable = mediator.getCurrentEmbeddable(); if (embeddable == null) { return; } if (Util.nullSafeEquals(newClassName, embeddable.getClassName())) { return; } if (newClassName == null) { throw new ValidationException("Embeddable name is required."); } else if (embeddable.getDataMap().getEmbeddable(newClassName) == null) { // if newClassName dupliucates in other DataMaps DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode(); if (domain != null) { for (DataMap nextMap : domain.getDataMaps()) { if (nextMap == embeddable.getDataMap()) { continue; } Embeddable conflictingEmbeddable = nextMap.getEmbeddable(newClassName); if (conflictingEmbeddable != null) { throw new ValidationException( "Duplicate Embeddable name in another DataMap: " + newClassName + "."); } } } // completely new name, set new name for embeddable EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName()); String oldName = embeddable.getClassName(); embeddable.setClassName(newClassName); mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap()); Iterator it = ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps().iterator(); while (it.hasNext()) { DataMap dataMap = (DataMap) it.next(); Iterator<ObjEntity> ent = dataMap.getObjEntities().iterator(); while (ent.hasNext()) { Collection<ObjAttribute> attr = ent.next().getAttributes(); Iterator<ObjAttribute> attrIt = attr.iterator(); while (attrIt.hasNext()) { ObjAttribute atribute = attrIt.next(); if (atribute.getType() == null || atribute.getType().equals(oldName)) { atribute.setType(newClassName); AttributeEvent ev = new AttributeEvent(this, atribute, atribute.getEntity()); mediator.fireObjAttributeEvent(ev); } } } } } else { // there is an embeddable with the same name throw new ValidationException( "There is another embeddable with name '" + newClassName + "'."); } }
private void initFromModel(Embeddable embeddable) { className.setText(embeddable.getClassName()); }