Examples of CMAttributeDeclaration


Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

   * Computes the hover help for the attribute name
   */
  protected String computeTagAttNameHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) {
    CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode);
    String attName = flatNode.getText(region);
    CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName);
    return getAdditionalInfo(elementDecl, attDecl);
  }
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

  protected String computeTagAttValueHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) {
    CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode);
    ITextRegion attrNameRegion = getAttrNameRegion(xmlnode, region);

    String attName = flatNode.getText(attrNameRegion);
    CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName);
    return getAdditionalInfo(elementDecl, attDecl);
  }
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

  /**
   * Retreives CMAttributeDeclaration indicated by attribute name within
   * elementDecl
   */
  protected CMAttributeDeclaration getCMAttributeDeclaration(IDOMNode node, CMElementDeclaration elementDecl, String attName) {
    CMAttributeDeclaration attrDecl = null;

    if (elementDecl != null) {
      CMNamedNodeMap attributes = elementDecl.getAttributes();
     
      CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

            sb.append(description + PARAGRAPH_END);
          }
        }
      }
      else if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
        CMAttributeDeclaration ad = (CMAttributeDeclaration) node;
        sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Attribute____3 + SPACE + BOLD_END);
        sb.append(node.getNodeName());
        sb.append(PARAGRAPH_END);
        printDocumentation(sb, node);
        CMDataType dataType = ad.getAttrType();
        if (dataType != null) {
          printDataTypeInfo(sb, dataType);
        }
      }
      else if (node.getNodeType() == CMNode.DATA_TYPE) {
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

      //                                                     
      CMNamedNodeMap map = ed.getAttributes();
      int mapLength = map.getLength();
      for (int i = 0; i < mapLength; i++)
      {                                                          
        CMAttributeDeclaration ad = (CMAttributeDeclaration)map.item(i);
        String attributeName = DOMNamespaceHelper.computeName(ad, element, null);
        if (ad.getUsage() == CMAttributeDeclaration.REQUIRED)
        {              
           Attr attr = element.getAttributeNode(attributeName);
           if (attr == null)
           {
             result = false;
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

      int nodeType = node.getNodeType();
      switch (nodeType)
      {
        case Node.ATTRIBUTE_NODE:
        {
          CMAttributeDeclaration ad = getCMAttributeDeclaration((Attr)node);
          if (ad != null)
          {
            result = (ad.getUsage() == CMAttributeDeclaration.OPTIONAL);
          }
          break;
        }
        case Node.ELEMENT_NODE:
        {
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

          
  protected void addValuesForXSIType(Element element, CMNode cmNode, List list)
  {              
    if (cmNode != null && cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION)
    {                        
      CMAttributeDeclaration ad = (CMAttributeDeclaration)cmNode;                             
      if (valueHelper.isXSIType(ad))
      {            
        NamespaceTable table = new NamespaceTable(element.getOwnerDocument());
        table.addElementLineage(element);
        list.addAll(valueHelper.getQualifiedXSITypes(ad, table));    
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

      // only add proposals for the attributes whose names begin with
      // the matchstring
      if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
          CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);

          int isRequired = 0;
          if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
            isRequired = XMLRelevanceConstants.R_REQUIRED;
          }

          boolean showAttribute = true;
          showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
          AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
          ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
          // nameRegion.getEndOffset() + 1 is required to allow for
          // matches against the full name of an existing Attr
          showAttribute = showAttribute && (attr == null || nameRegion == null || (nameRegion != null && (sdRegion.getStartOffset(nameRegion) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength())));
          if (showAttribute) {
            Image attrImage = CMImageUtil.getImage(attrDecl);
            if (attrImage == null) {
              if (isRequired > 0) {
                attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
              }
              else {
                attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
              }
            }

            String proposedText = null;
            String proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
            CustomCompletionProposal proposal = null;
            // attribute is at this location and already exists
            if (attrAtLocationHasValue) {
              // only propose the name
              proposedText = getRequiredName(node, attrDecl);
              proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), attrImage, proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true);
            }
            // no attribute exists or is elsewhere, generate
            // minimally
            else {
              Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
              String value = null;
              if (existingAttrNode != null && existingAttrNode.getSpecified()) {
                value = existingAttrNode.getNodeValue();
              }
              if ((value != null) && (value.length() > 0)) {
                proposedText = getRequiredName(node, attrDecl);
              }
              else {
                proposedText = getRequiredText(node, attrDecl);
              }
              proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), attrDecl.getNodeName().length() + 2, attrImage,
              // if the value isn't empty (no empty set of
                    // quotes), show it
              // BUG 203494, content strings may have "", but not be empty
              // An empty string is when there's no content between double quotes
              // and there is no single quote that may be encasing a double quote
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

      CMElementDeclaration elementDecl = getCMElementDeclaration(node);

      // String attributeName = nameRegion.getText();
      String attributeName = open.getText(nameRegion);

      CMAttributeDeclaration attrDecl = null;

      // No CMElementDeclaration means no attribute metadata, but
      // retrieve the
      // declaration for the attribute otherwise
      if (elementDecl != null) {
        CMNamedNodeMap attributes = elementDecl.getAttributes();

        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes) {
          private Map caseInsensitive;
         
          private Map getCaseInsensitiveMap() {
            if(caseInsensitive == null)
              caseInsensitive = new HashMap();
            return caseInsensitive;
          }

          public CMNode getNamedItem(String name) {
            CMNode node = super.getNamedItem(name);
            if (node == null) {
              node = (CMNode) getCaseInsensitiveMap().get(name.toLowerCase(Locale.US));
            }
            return node;
          }

          public void put(CMNode cmNode) {
            super.put(cmNode);
            getCaseInsensitiveMap().put(cmNode.getNodeName().toLowerCase(Locale.US), cmNode);
          }
        };
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
          for (int k = 0; k < nodes.size(); k++) {
            CMNode cmnode = (CMNode) nodes.get(k);
            if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
              allAttributes.put(cmnode);
            }
          }
        }
        attributes = allAttributes;

        String noprefixName = DOMNamespaceHelper.getUnprefixedName(attributeName);
        if (attributes != null) {
          attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName);
          if (attrDecl == null) {
            attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attributeName);
          }
        }
        if (attrDecl == null) {
          setErrorMessage(UNKNOWN_ATTR, attributeName);
        }
      }

      String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue();
      String proposedInfo = null;
      Image image = CMImageUtil.getImage(attrDecl);
      if (image == null) {
        if ((attrDecl != null) && (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED)) {
          image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
        }
        else {
          image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
        }
      }

      if ((attrDecl != null) && (attrDecl.getAttrType() != null)) {
        // attribute is known, prompt with values from the declaration
        proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
        List possibleValues = getPossibleDataTypeValues(node, attrDecl);
        String defaultValue = attrDecl.getAttrType().getImpliedValue();
        if (possibleValues.size() > 0 || defaultValue != null) {
          // ENUMERATED VALUES
          String matchString = contentAssistRequest.getMatchString();
          if (matchString == null) {
            matchString = ""; //$NON-NLS-1$
          }
          if ((matchString.length() > 0) && (matchString.startsWith("\"") || matchString.startsWith("'"))) {
            matchString = matchString.substring(1);
          }
          boolean currentValid = false;

          // d210858, if the region's a container, don't suggest the
          // enumerated values as they probably won't help
          boolean existingComplicatedValue = (contentAssistRequest.getRegion() != null) && (contentAssistRequest.getRegion() instanceof ITextRegionContainer);
          if (!existingComplicatedValue) {
            int rOffset = contentAssistRequest.getReplacementBeginPosition();
            int rLength = contentAssistRequest.getReplacementLength();
            for (Iterator j = possibleValues.iterator(); j.hasNext();) {
              String possibleValue = (String) j.next();
              if(!possibleValue.equals(defaultValue)) {
                currentValid = currentValid || possibleValue.equals(currentValue);
                if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
                  String rString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
                  CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, possibleValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                  contentAssistRequest.addProposal(proposal);
                }
              }
            }
            if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
              String rString = "\"" + defaultValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
              CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, defaultValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
              contentAssistRequest.addProposal(proposal);
            }
          }
        }
        else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrDecl.getAttrType().getImpliedValue() != null)) {
          // FIXED values
          String value = attrDecl.getAttrType().getImpliedValue();
          if ((value != null) && (value.length() > 0)) {
            String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$
            CustomCompletionProposal proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
            contentAssistRequest.addProposal(proposal);
            if ((currentValue.length() > 0) && !value.equals(currentValue)) {
View Full Code Here

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration

                    allAttributes.put(cmnode);
                  }
                }
                attributeDeclarationMap = allAttributes;

                CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributeDeclarationMap.getNamedItem(attrName);
                if (attrDecl != null) {
                  if ((attrDecl.getAttrType() != null) && (CMDataType.ID.equals(attrDecl.getAttrType().getDataTypeName()))) {
                    idTypedAttribute = attr;
                  }
                  else if ((attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) && (requiredAttribute == null)) {
                    // as a backup, keep tabs on
                    // any required
                    // attributes
                    requiredAttribute = attr;
                  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.