Esempio n. 1
0
  public void checkDimension() throws SemanticException {
    if (element instanceof TabularDimension) {
      Dimension sharedDimension =
          TabularDimensionPropSearchStrategy.getSharedDimension(module, element);
      if (sharedDimension != null) {
        String name = (String) element.getName();
        String sharedName = sharedDimension.getName();

        if (!sharedName.equals(name)) {
          NameExecutor nameExecutor = new NameExecutor(module, element);
          INameHelper nameHelper = nameExecutor.getNameHelper();
          NameSpace namespace = nameExecutor.getNameSpace();
          String namespaceId = nameExecutor.getNameSpaceId();
          DesignElement existedElement = namespace.getElement(name);
          if (existedElement == null) {
            // the name is not put in name space, then simply rename
            // it to the name of the shared element
            setName(sharedName);
          } else {
            if (existedElement == element) {
              // remove it from the name space and then rename it
              getActivityStack()
                  .execute(new NameSpaceRecord(nameHelper, namespaceId, element, false));
              setName(sharedName);
            } else {
              // do nothing and simply rename it to the name of
              // the shared element
              setName(sharedName);
            }
          }
        }
      }
    }
  }
Esempio n. 2
0
 /**
  * Implementation of dropping a symbol from a name space. No need to do the drop if the current
  * name is null.
  */
 private void dropSymbol() {
   if (element.getName() == null || !element.isManagedByNameSpace()) return;
   NameExecutor executor = new NameExecutor(module, element);
   INameHelper nameHelper = executor.getNameHelper();
   if (nameHelper != null) {
     String ns = executor.getNameSpaceId();
     NameSpace namespace = executor.getNameSpace();
     if (namespace.getElement(element.getName()) != element) return;
     getActivityStack().execute(new NameSpaceRecord(nameHelper, ns, element, false));
   }
 }
Esempio n. 3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.birt.report.model.core.namespace.INameHelper#getUniqueName
   * (org.eclipse.birt.report.model.core.DesignElement, java.lang.String)
   */
  public String getUniqueName(int namespaceId, DesignElement element, String namePrefix) {
    if (element == null) return null;

    ElementDefn eDefn = (ElementDefn) element.getDefn();

    String name = element.getName();
    if (StringUtil.isBlank(name)) {
      // Use the given prefix if the element name is null
      name = namePrefix;
    }

    name = StringUtil.trimString(name);
    // replace all the illegal chars with '_'
    name = NamePropertyType.validateName(name);

    // Some elements can have a blank name.
    if (eDefn.getNameOption() == MetaDataConstants.NO_NAME) return null;

    if (eDefn.getNameOption() == MetaDataConstants.OPTIONAL_NAME
        && name == null
        && module instanceof ReportDesign) return null;

    if (module instanceof Library
        && element instanceof StyleElement
        && element.getContainer() == null
        && name != null) {
      return name;
    }

    // If the element already has a unique name, return it.
    NameSpace nameSpace = getCachedNameSpace(namespaceId);
    List<String> cachedContentNames = getCachedContentNames(namespaceId);
    NameSpace moduleNameSpace = nameContexts[namespaceId].getNameSpace();

    String validName = name;
    if (element instanceof StyleElement)
      validName = validName == null ? null : validName.toLowerCase();
    if (validName != null
        && isValidInNameSpace(nameSpace, element, validName)
        && isValidInNameSpace(moduleNameSpace, element, validName)
        && !cachedContentNames.contains(validName)) return name;

    // If the element has no name, create it as "New<new name>" where
    // "<new name>" is the new element display name for the element. Both
    // "New" and the new element display name are localized to the user's
    // locale.

    if (name == null) {
      // When creating a new report element which requires a name, the
      // default name will be "New" followed by the element name, such as
      // "New Label"; also, if "NewLabel" already exists, then a number
      // will be appended, such as "NewLabel1", etc.

      if (element instanceof ExtendedItem) {
        ExtensionElementDefn extDefn = ((ExtendedItem) element).getExtDefn();

        PeerExtensionElementDefn peerDefn = (PeerExtensionElementDefn) extDefn;
        IReportItemFactory peerFactory = peerDefn.getReportItemFactory();

        assert peerFactory != null;

        String extensionDefaultName = null;
        IMessages msgs = peerFactory.getMessages();
        if (msgs != null)
          extensionDefaultName =
              msgs.getMessage((String) extDefn.getDisplayNameKey(), module.getLocale());

        if (StringUtil.isBlank(extensionDefaultName)) extensionDefaultName = peerDefn.getName();

        name = ModelMessages.getMessage(MessageConstants.NAME_PREFIX_NEW_MESSAGE);

        name = name + extensionDefaultName;

      } else {
        name =
            ModelMessages.getMessage(
                "New." //$NON-NLS-1$
                    + element.getDefn().getName());
        name = name.trim();
      }
    }

    // Add a numeric suffix that makes the name unique.

    int index = 0;
    String baseName = name;
    validName = name;
    if (element instanceof StyleElement)
      validName = validName == null ? null : validName.toLowerCase();
    while (nameSpace.contains(validName)
        || moduleNameSpace.contains(validName)
        || cachedContentNames.contains(validName)) {
      name = baseName + ++index;
      validName = name;
      if (element instanceof StyleElement)
        validName = validName == null ? null : validName.toLowerCase();
    }

    return name;
  }