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) {
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(elementDecl.getAttributes()) {
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);
}
};
this.addModelQueryAttributeDeclarations(node, elementDecl, allAttributes);
String noprefixName = DOMNamespaceHelper.getUnprefixedName(attributeName);
if (allAttributes != null) {
attrDecl = (CMAttributeDeclaration) allAttributes.getNamedItem(attributeName);
if (attrDecl == null) {
attrDecl = (CMAttributeDeclaration) allAttributes.getNamedItem(noprefixName);
}
}
if (attrDecl == null) {
setErrorMessage(XMLUIMessages.No_known_attribute__UI_ + attributeName);
}
}
String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue();
String proposedInfo = null;
//get proposal image
Image image = CMImageUtil.getImage(attrDecl);
if (image == null) {
if ((attrDecl != null) && (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED)) {
image = this.getRequiredAttributeImage();
} else {
image = this.getNotRequiredAttributeImage();
}
}
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();
String qualifiedDelimiter = (String) attrDecl.getProperty("qualified-delimiter"); //$NON-NLS-1$
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("'"))) { //$NON-NLS-1$ //$NON-NLS-2$
matchString = matchString.substring(1);
}
boolean currentValid = false;
//create suggestions for enumerated values
int rOffset = contentAssistRequest.getReplacementBeginPosition();
int rLength = contentAssistRequest.getReplacementLength();
for (Iterator j = possibleValues.iterator(); j.hasNext();) {
String possibleValue = (String) j.next();
String alternateMatch = null;
if (qualifiedDelimiter != null) {
int delimiter = possibleValue.lastIndexOf(qualifiedDelimiter);
if (delimiter >= 0 && delimiter < possibleValue.length() - 1) {
alternateMatch = possibleValue.substring(delimiter + 1);
}
}
if(!possibleValue.equals(defaultValue)) {
currentValid = currentValid || possibleValue.equals(currentValue);
if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
String rString = "\"" + possibleValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
alternateMatch = "\"" + alternateMatch; //$NON-NLS-1$
CustomCompletionProposal proposal = new MarkupCompletionProposal(
rString, rOffset, rLength, possibleValue.length() + 1,
XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
rString, alternateMatch, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE, true);
contentAssistRequest.addProposal(proposal);
}
}
}
if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
String rString = "\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
CustomCompletionProposal proposal = new MarkupCompletionProposal(
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 MarkupCompletionProposal(
rValue, contentAssistRequest.getReplacementBeginPosition(),
contentAssistRequest.getReplacementLength(), rValue.length() + 1,