Search in sources :

Example 1 with Proposals

use of org.eclipse.che.ide.ext.java.shared.dto.Proposals in project che by eclipse.

the class CodeAssist method convertProposals.

private Proposals convertProposals(int offset, ICompilationUnit compilationUnit, TextViewer viewer, List<ICompletionProposal> proposals) {
    Proposals result = DtoFactory.getInstance().createDto(Proposals.class);
    String sessionId = UUID.randomUUID().toString();
    result.setSessionId(sessionId);
    ArrayList<ProposalPresentation> presentations = new ArrayList<>();
    for (int i = 0; i < proposals.size(); i++) {
        ProposalPresentation presentation = DtoFactory.getInstance().createDto(ProposalPresentation.class);
        ICompletionProposal proposal = proposals.get(i);
        presentation.setIndex(i);
        presentation.setDisplayString(proposal.getDisplayString());
        String image = proposal.getImage() == null ? null : proposal.getImage().getImg();
        presentation.setImage(image);
        if (proposal instanceof ICompletionProposalExtension4) {
            presentation.setAutoInsertable(((ICompletionProposalExtension4) proposal).isAutoInsertable());
        }
        if (proposal instanceof CheActionAcces) {
            String actionId = ((CheActionAcces) proposal).getActionId();
            if (actionId != null) {
                presentation.setActionId(actionId);
            }
        }
        presentations.add(presentation);
    }
    result.setProposals(presentations);
    cache.put(sessionId, new CodeAssistContext(viewer, offset, proposals, compilationUnit));
    return result;
}
Also used : CheActionAcces(org.eclipse.che.jdt.ui.CheActionAcces) ProposalPresentation(org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals) ICompletionProposalExtension4(org.eclipse.che.jface.text.contentassist.ICompletionProposalExtension4) Point(org.eclipse.swt.graphics.Point)

Example 2 with Proposals

use of org.eclipse.che.ide.ext.java.shared.dto.Proposals in project che by eclipse.

the class JavaCodeAssistProcessor method computeCompletionProposals.

@Override
public void computeCompletionProposals(final TextEditor textEditor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
    if (errorMessage != null) {
        return;
    }
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
        client.computeProposals(project.get().getLocation().toString(), resolveFQN(file), offset, textEditor.getDocument().getContents(), new AsyncRequestCallback<Proposals>(unmarshaller) {

            @Override
            protected void onSuccess(Proposals proposals) {
                showProposals(callback, proposals);
            }

            @Override
            protected void onFailure(Throwable throwable) {
                Log.error(JavaCodeAssistProcessor.class, throwable);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) ImageResource(com.google.gwt.resources.client.ImageResource) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals)

Example 3 with Proposals

use of org.eclipse.che.ide.ext.java.shared.dto.Proposals in project che by eclipse.

the class JavaQuickAssistProcessor method setupProposals.

private void setupProposals(final CodeAssistCallback callback, final TextEditor textEditor, final int offset, final List<Problem> annotations) {
    final VirtualFile file = textEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
        client.computeAssistProposals(project.get().getLocation().toString(), resolveFQN(file), offset, annotations, new AsyncRequestCallback<Proposals>(unmarshaller) {

            @Override
            protected void onSuccess(Proposals proposals) {
                showProposals(callback, proposals, textEditor);
            }

            @Override
            protected void onFailure(Throwable throwable) {
                Log.error(JavaCodeAssistProcessor.class, throwable);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals)

Aggregations

Proposals (org.eclipse.che.ide.ext.java.shared.dto.Proposals)3 Project (org.eclipse.che.ide.api.resources.Project)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)2 ImageResource (com.google.gwt.resources.client.ImageResource)1 ArrayList (java.util.ArrayList)1 ProposalPresentation (org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation)1 CheActionAcces (org.eclipse.che.jdt.ui.CheActionAcces)1 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)1 ICompletionProposalExtension4 (org.eclipse.che.jface.text.contentassist.ICompletionProposalExtension4)1 Point (org.eclipse.swt.graphics.Point)1 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)1