Example usage for org.springframework.ide.eclipse.beans.ui.editor.util BeansEditorUtils getFile

List of usage examples for org.springframework.ide.eclipse.beans.ui.editor.util BeansEditorUtils getFile

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.beans.ui.editor.util BeansEditorUtils getFile.

Prototype

public static final IFile getFile(IDocument document) 

Source Link

Document

Returns the file the given document was read from.

Usage

From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java

public IHyperlink createHyperlink(String attrName, String target, Node node, Node parentNode,
        IDocument document, ITextViewer textViewer, IRegion hyperlinkRegion, IRegion cursor) {
    String nodeName = parentNode.getNodeName();
    IFile file = BeansEditorUtils.getFile(document);
    IType type = JdtUtils.getJavaType(file.getProject(), target);

    if ("class-a".equals(nodeName) || "class-b".equals(nodeName) || "a-hint".equals(attrName)
            || "b-hint".equals(attrName) || "a-deep-index-hint".equals(attrName)
            || "b-deep-index-hint".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }//from   w  w  w . j a  v a 2 s  . c o m
    } else if ("set-method".equals(attrName) || "get-method".equals(attrName)
            || "map-set-method".equals(attrName) || "map-get-method".equals(attrName)) {
        if ("field".equals(nodeName)) {
            String targetClassName = DozerPluginUtils.getMappingClassName(node);

            //get the first method that matches and make a hyperlink to that
            if (targetClassName != null) {
                IType targetClass = JdtUtils.getJavaType(file.getProject(), targetClassName);
                IMethod method = getMethodFromType(targetClass, target);
                if (method != null) {
                    return new JavaElementHyperlink(hyperlinkRegion, method);
                }
            }
        }
    } else if ("a-hint".equals(attrName) || "b-hint".equals(attrName)) {
        //make a simple hyperlink to the class
        if (parentNode.getParentNode() != null && "mapping".equals(parentNode.getParentNode().getNodeName())) {
            if (type != null) {
                return new JavaElementHyperlink(hyperlinkRegion, type);
            }
        }
    } else if ("custom-converter".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }
    } else if ("custom-converter-id".equals(attrName)) {
        //search spring-bean that uses our mapping file and return the mapping
        //for the customconverter-id map-property
        ISourceModelElement modelElement = getModelElementForCustomConverter(BeansEditorUtils.getFile(document),
                target);

        if (modelElement != null) {
            return new SourceModelHyperlink(modelElement, hyperlinkRegion);
        }
    } else if ("a".equals(nodeName) || "b".equals(nodeName)) {
        String targetClassName = DozerPluginUtils.getMappingClassName(node.getParentNode());
        String property = node.getNodeValue();

        if (targetClassName != null) {
            IType targetClass = JdtUtils.getJavaType(file.getProject(), targetClassName);

            try {
                //if we are doing indexed property mapping, we remove the []
                property = property.replaceAll("\\[\\]", "");

                IMethod method = Introspector.getReadableProperty(targetClass, property);

                if (method != null)
                    return new JavaElementHyperlink(hyperlinkRegion, method);
            } catch (Throwable e) {
                Logger.logException(e);
            }
        }
    } else if ("bean-factory".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }
    }

    return null;
}

From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java

@SuppressWarnings("restriction")
protected ContentAssistRequest computeDozerPropertyContentProposals(int documentPosition, String matchString,
        ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
    int offset = nodeAtOffset.getStartOffset();
    int len = nodeAtOffset.getLength();

    ContentAssistRequest contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
            getStructuredDocumentRegion(documentPosition), completionRegion, offset, len, matchString);

    IFile file = BeansEditorUtils.getFile(contentAssistRequest);
    IProject project = file.getProject();
    String className = DozerPluginUtils.getMappingClassName(nodeAtOffset.getParentNode());
    IType type = JdtUtils.getJavaType(project, className);

    //by default immer this hinzu
    DozerJavaCompletionProposal newProposal = new DozerJavaCompletionProposal("\" this", offset, len, 2,
            JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS), "this", (IContextInformation) null, 0, true,
            null);/*from  www .  j av  a2  s  .c o  m*/
    contentAssistRequest.addProposal(newProposal);

    DozerPluginUtils.addPropertyNameAttributeValueProposals(contentAssistRequest, matchString, "", type);
    convertProposals(contentAssistRequest.getProposals());

    return contentAssistRequest;
}

From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java

@SuppressWarnings("restriction")
protected ContentAssistRequest computeDozerBeanContentProposals(int documentPosition, String matchString,
        ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
    int offset = nodeAtOffset.getStartOffset() + nodeAtOffset.getNodeName().length() + 2;
    int len = nodeAtOffset.getLength() - nodeAtOffset.getNodeName().length() - 3;

    ContentAssistRequest contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
            getStructuredDocumentRegion(documentPosition), completionRegion, offset, len, matchString);
    IFile file = BeansEditorUtils.getFile(this.fTextViewer.getDocument());
    IBean bean = DozerPluginUtils.getDozerBeanForMappingFile(file);
    IModelElement[] ccwiPropertyMapEntries = DozerPluginUtils.getPossibleCCIMappingForMappingFile(bean);

    if (ccwiPropertyMapEntries != null) {
        for (IModelElement beansMapEntry : ccwiPropertyMapEntries) {
            BeansMapEntry entry = (BeansMapEntry) beansMapEntry;
            BeansTypedString key = (BeansTypedString) entry.getKey();

            if (key.getString() != null && !key.getString().equals("")) {
                DozerJavaCompletionProposal newProposal = new DozerJavaCompletionProposal(
                        "\"" + key.getString(), offset, len, 0, BeansModelImages.getImage(entry),
                        key.getString(), (IContextInformation) null, 0, true, bean);
                contentAssistRequest.addProposal(newProposal);
            }/*from   w  w  w  . ja  va2 s.c om*/
        }
    }

    return contentAssistRequest;
}

From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java

private void addGetterSetterMethodProposals(ContentAssistRequest contentAssistRequest, String prefix,
        final String className, boolean onlySetter) {
    if (BeansEditorUtils.getFile(contentAssistRequest) instanceof IFile) {
        final IFile file = BeansEditorUtils.getFile(contentAssistRequest);

        IMethodFilter filter = null;/* w  w w .  j  a va 2 s  .c  om*/
        if (onlySetter) {
            filter = new FlagsMethodFilter(FlagsMethodFilter.NOT_INTERFACE | FlagsMethodFilter.NOT_CONSTRUCTOR
                    | FlagsMethodFilter.PUBLIC, 1);

        } else {
            filter = new FlagsMethodFilter(FlagsMethodFilter.NOT_VOID | FlagsMethodFilter.NOT_INTERFACE
                    | FlagsMethodFilter.NOT_CONSTRUCTOR | FlagsMethodFilter.PUBLIC);
        }

        IContentAssistCalculator calculator = new MethodContentAssistCalculator(filter) {

            @Override
            protected IType calculateType(IContentAssistContext context) {
                return JdtUtils.getJavaType(file.getProject(), className);
            }
        };

        IContentAssistProposalRecorder recorder = new DefaultContentAssistProposalRecorder(
                contentAssistRequest);
        IContentAssistContext context = new DefaultContentAssistContext(contentAssistRequest, "xyz", //FIXME
                prefix);

        calculator.computeProposals(context, recorder); //request, prefix, null, null, null);
    }
}