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;
}
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);
}
}
}
}
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");
}
}
Aggregations