Search in sources :

Example 1 with CompilationUnitEditor

use of org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor in project jbosstools-hibernate by jbosstools.

the class JPAMapToolActionDelegate method isCUSelected.

public boolean isCUSelected() {
    IWorkbench workbench = Activator.getDefault().getWorkbench();
    if (workbench == null || workbench.getActiveWorkbenchWindow() == null) {
        return false;
    }
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    if (page == null) {
        return false;
    }
    IEditorPart editor = page.getActiveEditor();
    if (editor instanceof CompilationUnitEditor) {
        return true;
    }
    return false;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CompilationUnitEditor(org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 2 with CompilationUnitEditor

use of org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor in project jbosstools-hibernate by jbosstools.

the class JPAMapToolActor method updateOpen.

/**
 * update compilation unit of currently opened editor
 * @param depth - process depth
 */
public void updateOpen(int depth) {
    IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return;
    }
    IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
    if (page == null) {
        return;
    }
    IEditorPart editor = page.getActiveEditor();
    if (editor instanceof CompilationUnitEditor) {
        CompilationUnitEditor cue = (CompilationUnitEditor) editor;
        ICompilationUnit cu = (ICompilationUnit) cue.getViewPartInput();
        if (cu != null) {
            addCompilationUnit(cu);
            collector.initCollector();
            collector.collect(cu, depth);
            collector.resolveRelations();
            if (collector.getNonInterfaceCUNumber() > 0) {
                Map<String, EntityInfo> mapCUs_Info = collector.getMapCUs_Info();
                IStructuredSelection selection2Update = createSelection2Update();
                processor.modify(mapCUs_Info, true, selection2Update);
            } else {
                MessageDialog.openInformation(getShell(), JdtUiMessages.JPAMapToolActor_message_title, JdtUiMessages.JPAMapToolActor_message);
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CompilationUnitEditor(org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with CompilationUnitEditor

use of org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor in project jbosstools-hibernate by jbosstools.

the class JavaHBMQueryTest method testJavaHQLQueryCodeCompletion.

@SuppressWarnings("unused")
public void testJavaHQLQueryCodeCompletion() throws JavaModelException, CoreException, NoSuchFieldException, IllegalAccessException {
    IPackageFragment pack = project.getTestClassType().getPackageFragment();
    String testCP = "TestCompletionProposals.java";
    ICompilationUnit cu = pack.createCompilationUnit(testCP, "", true, // $NON-NLS-1$
    null);
    cu.createPackageDeclaration(pack.getElementName(), null);
    IType type = cu.createType("public class " + testCP + " {}", null, false, // $NON-NLS-1$//$NON-NLS-2$
    null);
    type.createMethod("public static void main(String[] args){String query = \"from \";}", null, false, // $NON-NLS-1$
    null);
    IWorkbenchPage p = JavaPlugin.getActivePage();
    IEditorPart part = EditorUtility.openInEditor(type, true);
    if (part instanceof CompilationUnitEditor) {
        CompilationUnitEditor editor = (CompilationUnitEditor) part;
        IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        HQLJavaCompletionProposalComputer proposalComputer = new HQLJavaCompletionProposalComputer();
        ContentAssistInvocationContext context = new JavaContentAssistInvocationContext(editor.getViewer(), 125, editor);
        List<ICompletionProposal> computeCompletionProposals = proposalComputer.computeCompletionProposals(context, null);
        assertTrue(computeCompletionProposals.size() > 0);
        for (ICompletionProposal iCompletionProposal : computeCompletionProposals) {
            Class<? extends ICompletionProposal> class1 = iCompletionProposal.getClass();
            if (class1.getPackage().getName().indexOf("org.jboss.tools.hibernate") == 0) {
                // this is our completion proposal
                Field declaredField = class1.getDeclaredField("documentOffset");
                declaredField.setAccessible(true);
                Integer offset = (Integer) declaredField.get(iCompletionProposal);
                Assert.assertTrue(offset > 0);
            }
        }
    } else {
        fail("Can't open CompilationUnitEditor");
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext) JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) CompilationUnitEditor(org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) IEditorPart(org.eclipse.ui.IEditorPart) IType(org.eclipse.jdt.core.IType) Field(java.lang.reflect.Field) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) HQLJavaCompletionProposalComputer(org.hibernate.eclipse.jdt.ui.internal.HQLJavaCompletionProposalComputer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

CompilationUnitEditor (org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor)3 IEditorPart (org.eclipse.ui.IEditorPart)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 Field (java.lang.reflect.Field)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IType (org.eclipse.jdt.core.IType)1 ContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext)1 JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)1 IDocument (org.eclipse.jface.text.IDocument)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 HQLJavaCompletionProposalComputer (org.hibernate.eclipse.jdt.ui.internal.HQLJavaCompletionProposalComputer)1 EntityInfo (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo)1