/** Initializes Query name from string. */ void setQueryName(String newName) { if (newName != null && newName.trim().length() == 0) { newName = null; } AbstractQuery query = getQuery(); if (query == null) { return; } if (Util.nullSafeEquals(newName, query.getName())) { return; } if (newName == null) { throw new ValidationException("SelectQuery name is required."); } DataMap map = mediator.getCurrentDataMap(); Query matchingQuery = map.getQuery(newName); if (matchingQuery == null) { // completely new name, set new name for entity QueryEvent e = new QueryEvent(this, query, query.getName()); ProjectUtil.setQueryName(map, query, newName); mediator.fireQueryEvent(e); } else if (matchingQuery != query) { // there is a query with the same name throw new ValidationException( "There is another query named '" + newName + "'. Use a different name."); } }
public void processExistingSelection(EventObject e) { EmbeddableDisplayEvent ede = new EmbeddableDisplayEvent( this, mediator.getCurrentEmbeddable(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()); mediator.fireEmbeddableDisplayEvent(ede); }
@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)); }
/** * Updates the view from the current model state. Invoked when a currently displayed query is * changed. */ void initFromModel() { Query query = mediator.getCurrentQuery(); if (!(query instanceof SelectQuery)) { setVisible(false); return; } SelectQuery selectQuery = (SelectQuery) query; name.setText(query.getName()); distinct.setSelected(selectQuery.isDistinct()); qualifier.setText( selectQuery.getQualifier() != null ? selectQuery.getQualifier().toString() : null); // init root choices and title label.. // - SelectQuery supports ObjEntity roots // TODO: now we only allow roots from the current map, // since query root is fully resolved during map loading, // making it impossible to reference other DataMaps. DataMap map = mediator.getCurrentDataMap(); Object[] roots = map.getObjEntities().toArray(); if (roots.length > 1) { Arrays.sort(roots, Comparators.getDataMapChildrenComparator()); } DefaultComboBoxModel model = new DefaultComboBoxModel(roots); model.setSelectedItem(selectQuery.getRoot()); queryRoot.setModel(model); properties.initFromModel(selectQuery); setVisible(true); }
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 + "'."); } }