Пример #1
0
  /** 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.");
    }
  }
Пример #2
0
 public void processExistingSelection(EventObject e) {
   EmbeddableDisplayEvent ede =
       new EmbeddableDisplayEvent(
           this,
           mediator.getCurrentEmbeddable(),
           mediator.getCurrentDataMap(),
           (DataChannelDescriptor) mediator.getProject().getRootNode());
   mediator.fireEmbeddableDisplayEvent(ede);
 }
  static void fireEmbeddableEvent(
      Object src, ProjectController mediator, DataMap dataMap, Embeddable embeddable) {

    mediator.fireEmbeddableEvent(new EmbeddableEvent(src, embeddable, MapEvent.ADD), dataMap);
    EmbeddableDisplayEvent displayEvent =
        new EmbeddableDisplayEvent(
            src, embeddable, dataMap, (DataChannelDescriptor) mediator.getProject().getRootNode());
    displayEvent.setMainTabFocus(true);
    mediator.fireEmbeddableDisplayEvent(displayEvent);
  }
  @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));
  }
  @Override
  public void undo() throws CannotUndoException {
    if (node != null) {
      node.getDataMapNames().remove(map.getName());
      mediator.fireDataNodeEvent(new DataNodeEvent(this, node));
    }

    if (!unlinkedNodes.isEmpty()) {
      for (DataNodeDescriptor unlinkedNode : unlinkedNodes) {
        unlinkedNode.getDataMapNames().add(map.getName());
        mediator.fireDataNodeEvent(new DataNodeEvent(this, unlinkedNode));
      }
    }
  }
Пример #6
0
  private void initController() {
    BindingBuilder builder =
        new BindingBuilder(eventController.getApplication().getBindingFactory(), this);

    builder.bindToStateChange(dbEntity, "dbEntityFilter").updateView();
    builder.bindToStateChange(objEntity, "objEntityFilter").updateView();
    builder.bindToStateChange(embeddable, "embeddableFilter").updateView();
    builder.bindToStateChange(procedure, "procedureFilter").updateView();
    builder.bindToStateChange(query, "queryFilter").updateView();
    builder.bindToStateChange(all, "allFilter").updateView();

    dbEntity.addActionListener(new CheckListener("dbEntity"));
    objEntity.addActionListener(new CheckListener("objEntity"));
    embeddable.addActionListener(new CheckListener("embeddable"));
    procedure.addActionListener(new CheckListener("procedure"));
    query.addActionListener(new CheckListener("query"));

    all.setEnabled(false);
    all.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dbEntity.setSelected(true);
            objEntity.setSelected(true);
            embeddable.setSelected(true);
            procedure.setSelected(true);
            query.setSelected(true);
            all.setEnabled(false);

            filterController.getTreeModel().setFiltered(filterController.getFilterMap());
            filterController.getTree().updateUI();
          }
        });
  }
Пример #7
0
  /** Initializes Query qualifier from string. */
  void setQueryQualifier(String text) {
    if (text != null && text.trim().length() == 0) {
      text = null;
    }

    Expression qualifier = createQualifier(text);
    if (qualifier != null) {
      // getQuery() is not null if we reached here
      getQuery().setQualifier(qualifier);
      mediator.fireQueryEvent(new QueryEvent(this, getQuery()));
    }
  }
Пример #8
0
  /**
   * 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);
  }
Пример #9
0
  public void setNodeName(String newName) {
    if (node == null) {
      return;
    }

    // validate...
    if (newName == null) {
      throw new ValidationException("Empty DataNode Name");
    }

    ProjectController parent = (ProjectController) getParent();
    DataNodeDefaults oldPref = parent.getDataNodePreferences();
    DataChannelDescriptor dataChannelDescriptor =
        (DataChannelDescriptor) getApplication().getProject().getRootNode();

    Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();

    Iterator<DataNodeDescriptor> it = matchingNode.iterator();
    while (it.hasNext()) {
      DataNodeDescriptor node = it.next();
      if (node.getName().equals(newName)) {
        // there is an entity with the same name
        throw new ValidationException(
            "There is another DataNode named '" + newName + "'. Use a different name.");
      }
    }

    // passed validation, set value...

    // TODO: fixme....there is a slight chance that domain is different than the one
    // cached node belongs to
    ProjectUtil.setDataNodeName(
        (DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);

    oldPref.copyPreferences(newName);
  }
Пример #10
0
 protected SelectQuery getQuery() {
   return (mediator.getCurrentQuery() instanceof SelectQuery)
       ? (SelectQuery) mediator.getCurrentQuery()
       : null;
 }
Пример #11
0
  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 + "'.");
    }
  }
Пример #12
0
 private void initController() {
   mediator.addEmbeddableDisplayListener(this);
 }