Package com.volantis.mcs.eclipse.ab.editors.xml.schema

Examples of com.volantis.mcs.eclipse.ab.editors.xml.schema.InputContext


        prefix = docInfo.getNamespacePrefix(schema.getNamespaceURI());

        // If the document doesn't define a namespace prefix for the schema's
        // namespace URI, we can't do completions
        if (prefix != null) {
            InputContext ic = docInfo.getInputContext(documentOffset - 1);
           
            // If the document info could not determine an input context at
            // the specified location in the document, we can't do completions
            if (ic != null) {
                String elementName = localName(
                    ic.getContainingElementName(),
                    prefix);

                // If the local name derived from the input context containing
                // element is null, we can't do completions
                if (elementName != null) {
                    String matchName = ic.getMatchName();

                    if (!ic.isAttribute() &&
                        (matchName != null) &&
                        matchName.startsWith("/")) { //$NON-NLS-1$
                        // If the match name starts with "/" we are trying to
                        // complete the currently open element (so we must not
                        // be in attribute match mode)
                        matchName = localMatchName(matchName.substring(1),
                                                   ic.isAttribute(),
                                                   prefix);

                        if ("".equals(matchName) || //$NON-NLS-1$
                            elementName.startsWith(matchName)) {
                            // Propose closing the currently open element
                            proposals =
                                new ICompletionProposal[1];
                            String replace;
                            StringBuffer sb =
                                new StringBuffer(2 +
                                                 ic.getContainingElementName().
                                                 length());
                            sb.append('/').
                                append(ic.getContainingElementName()).
                                append('>');

                            replace = sb.toString();

                            proposals[0] =
                                new CompletionProposal(
                                    replace,
                                    documentOffset - ic.getMatchName().length(),
                                    ic.getMatchName().length(),
                                    replace.length(),
                                    null,
                                    elementName,
                                    null,
                                    null);
                        }
                    } else {
                        // We are trying to complete something other than the
                        // close element markup
                        ElementDefinition element =
                            schema.getElementDefinition(elementName);
                        matchName = localMatchName(matchName,
                                                   ic.isAttribute(),
                                                   prefix);

                        // If an element definition cannot be found for the
                        // containing element, or we can't derive a local match
                        // name from the input context we can't do completions
                        if ((element != null) && (matchName != null)) {
                            List options = new ArrayList();

                            if (ic.isAttribute()) {
                                List attributes =
                                    element.getAttributeDefinitions(matchName);
                                AttributeDefinition attribute;

                                for (int i = 0;
                                     i < attributes.size();
                                     i++) {
                                    attribute =
                                        (AttributeDefinition)attributes.get(i);

                                    options.add(attribute.getName());
                                }
                            } else {
                                List subElements =
                                    element.getSubElementNames(matchName);

                                options.addAll(subElements);
                            }

                            if (options.size() != 0) {
                                proposals =
                                    stringListToCompletionProposalArray(
                                        options,
                                        documentOffset -
                                        ic.getMatchName().length(),
                                        ic.getMatchName().length(),
                                        ic.isAttribute(),
                                        prefix);
                            }
                        }
                    }
                }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.eclipse.ab.editors.xml.schema.InputContext

Copyright © 2018 www.massapicom. 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.