Examples of CustomCompletionProposal


Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

          }
          String tagname = getRequiredName(document, ed);
          // account for the < and >
          int markupAdjustment = getCursorPositionForProposedText(proposedText);
          String proposedInfo = getAdditionalInfo(null, ed);
          CustomCompletionProposal proposal = new CustomCompletionProposal(
              proposedText, contentAssistRequest.getReplacementBeginPosition(),
              contentAssistRequest.getReplacementLength(), markupAdjustment, image,
              tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
          contentAssistRequest.addProposal(proposal);
        }
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

   *         display (element type: {@link ICompletionProposal})
   */
  protected List filterAndSortProposals(List proposals, IProgressMonitor monitor, CompletionProposalInvocationContext context) {
    for(int i=0; i<proposals.size(); i++){
      if(proposals.get(i) instanceof CustomCompletionProposal){
        CustomCompletionProposal ccp = (CustomCompletionProposal) proposals.get(i);
        if(ccp.getDisplayString().startsWith("t:"))
          ccp.setImage(tapestryImage);
      }
    }
    return proposals;
  }
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

 
              String tagname = getContentGenerator().getRequiredName(node, ed);
              StringBuffer contents = new StringBuffer("\""); //$NON-NLS-1$
              getContentGenerator().generateTag(node, ed, contents);
              contents.append('"'); //$NON-NLS-1$
              CustomCompletionProposal proposal = new CustomCompletionProposal(contents.toString(), contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), contents.length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), tagname, null, null, XMLRelevanceConstants.R_JSP_ATTRIBUTE_VALUE);
              contentAssistRequest.addProposal(proposal);
            }
          }
       
        }
      }
    }
    else if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
      try {
        // Create a new model for Content Assist to operate on. This
        // will simulate
        // a full Document and then adjust the offset numbers in the
        // list of results.
        IStructuredModel internalModel = null;
        IModelManager mmanager = StructuredModelManager.getModelManager();
        internalModel = mmanager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
        IDOMNode xmlNode = null;
        IDOMModel xmlOuterModel = null;
        if (contentAssistRequest.getNode() instanceof IDOMNode) {
          xmlNode = (IDOMNode) contentAssistRequest.getNode();
          xmlOuterModel = xmlNode.getModel();
          internalModel.setResolver(xmlOuterModel.getResolver());
          internalModel.setBaseLocation(xmlOuterModel.getBaseLocation());
        }
        String contents = StringUtils.strip(contentAssistRequest.getText());
        if (xmlNode != null && contents != null) {
          int additionalShifts = 0;
          // Be sure that custom tags from taglibs also show up
          // by
          // adding taglib declarations to the internal model.
          TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(xmlOuterModel.getStructuredDocument());
          if (mgr != null) {
            List trackers = mgr.getCMDocumentTrackers(contentAssistRequest.getReplacementBeginPosition());
            if (trackers != null) {
              for (i = 0; i < trackers.size(); i++) {
                CMDocumentTracker tracker = (CMDocumentTracker) trackers.get(i);
                String declaration = tracker.getStructuredDocumentRegion().getText();
                if (declaration != null) {
                  contents = declaration + contents;
                  additionalShifts += declaration.length();
                }
              }
            }
          }
          // Also copy any jsp:useBean tags so that
          // jsp:[gs]etProperty will function
          Document doc = null;
          if (contentAssistRequest.getNode().getNodeType() == Node.DOCUMENT_NODE)
            doc = (Document) node;
          else
            doc = node.getOwnerDocument();
          NodeList useBeans = doc.getElementsByTagName(JSP12Namespace.ElementName.USEBEAN);
          for (int k = 0; k < useBeans.getLength(); k++) {
            IDOMNode useBean = (IDOMNode) useBeans.item(k);
            if (useBean.getStartOffset() < contentAssistRequest.getReplacementBeginPosition()) {
              StringBuffer useBeanText = new StringBuffer("<jsp:useBean"); //$NON-NLS-1$
              for (int j = 0; j < useBean.getAttributes().getLength(); j++) {
                Attr attr = (Attr) useBean.getAttributes().item(j);
                useBeanText.append(' ');
                useBeanText.append(attr.getName());
                useBeanText.append("=\""); //$NON-NLS-1$
                useBeanText.append(attr.getValue());
                useBeanText.append('"');
              }
              useBeanText.append("/>"); //$NON-NLS-1$
              additionalShifts += useBeanText.length();
              contents = useBeanText.toString() + contents;
            }
          }
          internalModel.getStructuredDocument().set(contents);
          int internalOffset = 0;
          boolean quoted = false;
          // if quoted, use position inside and shift by one
          if (contentAssistRequest.getMatchString().length() > 0 && (contentAssistRequest.getMatchString().charAt(0) == '\'' || contentAssistRequest.getMatchString().charAt(0) == '"')) {
            internalOffset = contentAssistRequest.getMatchString().length() - 1 + additionalShifts;
            quoted = true;
          }
          // if unquoted, use position inside
          else if (contentAssistRequest.getMatchString().length() > 0 && contentAssistRequest.getMatchString().charAt(0) == '<')
            internalOffset = contentAssistRequest.getMatchString().length() + additionalShifts;
          else
            internalOffset = contentAssistRequest.getReplacementBeginPosition() - contentAssistRequest.getStartOffset() + additionalShifts;
          depthCount++;
          IndexedRegion internalNode = null;
          int tmpOffset = internalOffset;
          while (internalNode == null && tmpOffset >= 0)
            internalNode = internalModel.getIndexedRegion(tmpOffset--);

          if (internalModel.getFactoryRegistry() != null) {
            // set up the internal model
            if (internalModel.getFactoryRegistry().getFactoryFor(PageDirectiveAdapter.class) == null) {
              internalModel.getFactoryRegistry().addFactory(new PageDirectiveAdapterFactory());
            }
            PageDirectiveAdapter outerEmbeddedTypeAdapter = (PageDirectiveAdapter) xmlOuterModel.getDocument().getAdapterFor(PageDirectiveAdapter.class);
            PageDirectiveAdapter internalEmbeddedTypeAdapter = (PageDirectiveAdapter) ((INodeNotifier) ((Node) internalNode).getOwnerDocument()).getAdapterFor(PageDirectiveAdapter.class);
            internalEmbeddedTypeAdapter.setEmbeddedType(outerEmbeddedTypeAdapter.getEmbeddedType());
          }

          AdapterFactoryRegistry adapterRegistry = JSPUIPlugin.getDefault().getAdapterFactoryRegistry();
          Iterator adapterList = adapterRegistry.getAdapterFactories();
          // And all those appropriate for this particular type
          // of content
          while (adapterList.hasNext()) {
            try {
              AdapterFactoryProvider provider = (AdapterFactoryProvider) adapterList.next();
              if (provider.isFor(internalModel.getModelHandler())) {
                provider.addAdapterFactories(internalModel);
              }
            }
            catch (Exception e) {
              Logger.logException(e);
            }
          }

          /**
           * the internal adapter does all the real work of using
           * the JSP content model to form proposals
           */
          ICompletionProposal[] results = null;
          depthCount--;
          if (results != null) {
            for (i = 0; i < results.length; i++) {
              contentAssistRequest.addProposal(new CustomCompletionProposal(((CustomCompletionProposal) results[i]).getReplacementString(), ((CustomCompletionProposal) results[i]).getReplacementOffset() - additionalShifts + contentAssistRequest.getStartOffset() + (quoted ? 1 : 0), ((CustomCompletionProposal) results[i]).getReplacementLength(), ((CustomCompletionProposal) results[i]).getCursorPosition(), results[i].getImage(), results[i].getDisplayString(), ((CustomCompletionProposal) results[i]).getContextInformation(), ((CustomCompletionProposal) results[i]).getAdditionalProposalInfo(), (results[i] instanceof IRelevanceCompletionProposal) ? ((IRelevanceCompletionProposal) results[i]).getRelevance() : IRelevanceConstants.R_NONE));
            }
          }
        }
      }
      catch (Exception e) {
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

    String[] directiveNames = {"page", "include", "taglib"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    // suggest JSP Expression inside of XML comments
    if (completionRegion.getType() == DOMRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) {
      if (request == null)
        request = newContentAssistRequest(treeNode, xmlnode, sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
      request.addProposal(new CustomCompletionProposal("<%=  %>", documentPosition, 0, 4, JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), "jsp:expression", null, "&lt;%= %&gt;", XMLRelevanceConstants.R_JSP)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }
    // handle proposals in and around JSP_DIRECTIVE_OPEN and
    // JSP_DIRECTIVE_NAME
    else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition >= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition <= sdRegion.getTextEndOffset(completionRegion))) {
      if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) {
        if (request == null)
          request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, documentPosition, 0, matchString);
        Iterator regions = sdRegion.getRegions().iterator();
        String nameString = null;
        int begin = request.getReplacementBeginPosition();
        int length = request.getReplacementLength();
        while (regions.hasNext()) {
          ITextRegion region = (ITextRegion) regions.next();
          if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
            nameString = sdRegion.getText(region);
            begin = sdRegion.getStartOffset(region);
            length = region.getTextLength();
            break;
          }
        }
        if (nameString == null)
          nameString = ""; //$NON-NLS-1$
        for (int i = 0; i < directiveNames.length; i++) {
          if (directiveNames[i].startsWith(nameString) || documentPosition <= begin)
            request.addProposal(new CustomCompletionProposal(directiveNames[i], begin, length, directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
        }
      }
      else { // by default, JSP_DIRECTIVE_NAME
        if (request == null)
          request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
        for (int i = 0; i < directiveNames.length; i++) {
          if (directiveNames[i].startsWith(matchString))
            request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
        }
      }
    }
    else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition > sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion))) {
      if (request == null)
        request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
      super.addTagCloseProposals(request);
      // CMVC 274033, this is being added for all <jsp:* tags
      // in addAttributeNameProposals(contentAssistRequest)
      // super.addAttributeNameProposals(request);
    }
    // no name?: <%@ %>
    else if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion)) {
      if (request != null)
        request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
      Iterator regions = sdRegion.getRegions().iterator();
      String nameString = null;
      while (regions.hasNext()) {
        ITextRegion region = (ITextRegion) regions.next();
        if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
          nameString = sdRegion.getText(region);
          break;
        }
      }
      if (nameString == null) {
        for (int i = 0; i < directiveNames.length; i++) {
          request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
        }
      }
    }

    // bug115927 use original document position for all/any region
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

        int selectionLength = viewer.getSelectedRange().y;
        if (documentPosition > realCaretPosition) {
          adjustedDocPosition -= selectionLength;
        }

        CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
        results.add(cdataProposal);
      }
    }

    return results;
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

  protected JSPProposalCollector getProposalCollector(ICompilationUnit cu, JSPTranslation translation) {
    return new JSPProposalCollector(cu, translation);
  }
 
  private CustomCompletionProposal createCDATAProposal(int adjustedDocPosition, int selectionLength) {
    return new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$
          adjustedDocPosition, selectionLength, // should be the selection length
          9, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION),
          "CDATA Section", //$NON-NLS-1$
          null, null, XMLRelevanceConstants.R_CDATA);
  }
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

      int selectionLength = viewer.getSelectedRange().y;
      if (documentPosition > realCaretPosition) {
        adjustedDocPosition -= selectionLength;
      }

      CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
      ICompletionProposal[] newResults = new ICompletionProposal[results.length + 1];
      System.arraycopy(results, 0, newResults, 0, results.length);
      newResults[results.length] = cdataProposal;
      results = newResults;
    }
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

    return results;
  }

  private CustomCompletionProposal createCDATAProposal(int adjustedDocPosition, int selectionLength) {
    return new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$
          adjustedDocPosition, selectionLength, // should be the selection length
          9, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION),
          "CDATA Section", //$NON-NLS-1$
          null, null, XMLRelevanceConstants.R_CDATA);
  }
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

        int selectionLength = viewer.getSelectedRange().y;
        if (documentPosition > realCaretPosition) {
          adjustedDocPosition -= selectionLength;
        }

        CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
        results.add(cdataProposal);
      }
    }

    return results;
View Full Code Here

Examples of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal

  protected JSPProposalCollector getProposalCollector(ICompilationUnit cu, JSPTranslation translation) {
    return new JSPProposalCollector(cu, translation);
  }
 
  private CustomCompletionProposal createCDATAProposal(int adjustedDocPosition, int selectionLength) {
    return new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$
          adjustedDocPosition, selectionLength, // should be the selection length
          9, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION),
          "CDATA Section", //$NON-NLS-1$
          null, null, XMLRelevanceConstants.R_CDATA);
  }
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.