Search in sources :

Example 1 with ConsoleExtension

use of org.hibernate.eclipse.console.common.ConsoleExtension in project jbosstools-hibernate by jbosstools.

the class HQLCompletionProcessor method computeProposals.

ICompletionProposal[] computeProposals(IDocument doc, int lineStart, final int currentOffset, final ConsoleConfiguration consoleConfiguration) {
    ICompletionProposal[] result = null;
    errorMessage = null;
    if (doc != null && currentOffset >= 0) {
        List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
        String startWord = null;
        int startOffset = findNearestWhiteSpace(doc, currentOffset, lineStart);
        int wordLength = currentOffset - startOffset;
        startWord = getWord(doc, startOffset, wordLength);
        if (startWord != null) {
            try {
                doc.get(0, doc.getLength()).toCharArray();
            } catch (BadLocationException e) {
                errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_could_not_get_document_contents;
                return result;
            }
            if (consoleConfiguration != null) {
                ConsoleExtension consoleExtension = consoleConfiguration.getHibernateExtension().getConsoleExtension();
                if (consoleExtension != null) {
                    CompletionProposalsResult codeCompletions = consoleExtension.hqlCodeComplete(doc.get(), 0, currentOffset);
                    proposalList.addAll(codeCompletions.getCompletionProposals());
                    // eclipseHQLCompletionCollector.getLastErrorMessage();
                    errorMessage = codeCompletions.getErrorMessage();
                    result = proposalList.toArray(new ICompletionProposal[proposalList.size()]);
                    if (result.length == 0 && errorMessage == null) {
                        errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_no_hql_completions_available;
                    }
                } else {
                    errorMessage = // $NON-NLS-1$
                    "There is no completion proposal implementation for this hibernate version \'" + consoleConfiguration.getHibernateExtension().getHibernateVersion() + // $NON-NLS-1$
                    "\'";
                }
            }
        } else {
            errorMessage = HibernateConsoleMessages.HQLCompletionProcessor_no_start_word_found;
        }
    }
    return result;
}
Also used : CompletionProposalsResult(org.hibernate.eclipse.console.common.CompletionProposalsResult) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ConsoleExtension

use of org.hibernate.eclipse.console.common.ConsoleExtension in project jbosstools-hibernate by jbosstools.

the class HQLJavaCompletionProposalComputer method computeCompletionProposals.

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    errorMessage = null;
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        return proposals;
    }
    JavaContentAssistInvocationContext ctx = (JavaContentAssistInvocationContext) context;
    try {
        ConsoleConfiguration consoleConfiguration = getConfiguration(ctx.getProject());
        if (consoleConfiguration != null) {
            // $NON-NLS-1$
            String query = "";
            int stringStart = getStringStart(ctx.getDocument(), ctx.getInvocationOffset());
            int stringEnd = getStringEnd(ctx.getDocument(), ctx.getInvocationOffset());
            query = ctx.getDocument().get(stringStart, stringEnd - stringStart);
            ConsoleExtension consoleExtension = consoleConfiguration.getHibernateExtension().getConsoleExtension();
            if (consoleExtension != null) {
                CompletionProposalsResult codeCompletions = consoleExtension.hqlCodeComplete(query, stringStart, ctx.getInvocationOffset() - stringStart);
                errorMessage = codeCompletions.getErrorMessage();
                proposals = codeCompletions.getCompletionProposals();
            } else {
                errorMessage = // $NON-NLS-1$
                "There is no completion proposal implementation for this hibernate version \'" + consoleConfiguration.getHibernateExtension().getHibernateVersion() + // $NON-NLS-1$
                "\'";
            }
        }
    } catch (RuntimeException re) {
        HibernateConsolePlugin.getDefault().logErrorMessage(JdtUiMessages.HQLJavaCompletionProposalComputer_errormessage, re);
    } catch (BadLocationException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage(JdtUiMessages.HQLJavaCompletionProposalComputer_errormessage, e);
    }
    return proposals;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) CompletionProposalsResult(org.hibernate.eclipse.console.common.CompletionProposalsResult) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with ConsoleExtension

use of org.hibernate.eclipse.console.common.ConsoleExtension in project jbosstools-hibernate by jbosstools.

the class CodeGenerationLaunchDelegate method launch.

public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(configuration);
    Assert.isNotNull(monitor);
    ExporterAttributes attributes = new ExporterAttributes(configuration);
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    ConsoleExtension consoleExtension = cc.getHibernateExtension().getConsoleExtension();
    Map<String, File[]> generatedFiles = consoleExtension.launchExporters(configuration, mode, launch, monitor);
    // code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate files!
    if (generatedFiles != null) {
        formatGeneratedCode(monitor, generatedFiles);
    }
/* The code is moved to consoleExtension and delegated method is called instead.
		
		List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
		for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
			ExporterFactory exFactory = iter.next();
			if (!exFactory.isEnabled(configuration)) {
				iter.remove();
			}
		}
		if (attributes.isUseExternalProcess()) {
			// create temporary build.xml and then erase it after code generation complete
			String fileName = null;
			try {
				fileName = getPath2GenBuildXml().toString();
		    	createBuildXmlFile(configuration, fileName);
			} catch (UnsupportedEncodingException e) {
				throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
			} catch (IOException e) {
				throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
			}
			configuration = updateLaunchConfig(configuration);
			super.launch(configuration, mode, launch, monitor);
	    	//
	    	final Properties props = new Properties();
            props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
            props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
            Set<String> outputDirs = new HashSet<String>();
			for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
				ExporterFactory exFactory = iter.next();
				exFactory.collectOutputDirectories(attributes.getOutputPath(), 
						props, outputDirs);
			}
			//
			final IProcess[] processes = launch.getProcesses();
			// codegen listener to erase build.xml file after codegen process complete
			CodeGenerationProcessListener refresher = new CodeGenerationProcessListener(
				processes[0], fileName, outputDirs);
			refresher.startBackgroundRefresh();
			return;
	    }
		try {
		    Set<String> outputDirectories = new HashSet<String>();
		    ExporterFactory[] exporters = exporterFactories.toArray( new ExporterFactory[exporterFactories.size()] );
            ArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);

            for (String path : outputDirectories) {
            	CodeGenerationUtils.refreshOutputDir(path);
			}

			RefreshTab.refreshResources(configuration, monitor);

			// code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate files!
            if(collector!=null) {
            	formatGeneratedCode( monitor, collector );
			}


		} catch(Exception e) {
			throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
		} catch(NoClassDefFoundError e) {
			throw new CoreException(HibernateConsolePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e), 666));
		} finally {
			monitor.done();
		}*/
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension)

Example 4 with ConsoleExtension

use of org.hibernate.eclipse.console.common.ConsoleExtension in project jbosstools-hibernate by jbosstools.

the class HibernatePropertySourceProvider method getPropertySource.

public IPropertySource getPropertySource(Object object) {
    if (object == null) {
        return null;
    } else if (object instanceof QueryPage) {
        return new QueryPagePropertySource((QueryPage) object);
    } else if (object instanceof IPropertySource) {
        return (IPropertySource) object;
    } else {
        QueryPage selectedQueryPage = view.getSelectedQueryPage();
        ConsoleExtension consoleExtension = selectedQueryPage.getHibernateExtension().getConsoleExtension();
        return consoleExtension.getPropertySource(object, selectedQueryPage);
    /*return (IPropertySource) selectedQueryPage.getAdapter(IPropertySource.class);
			//			 maybe we should be hooked up with the queryview to get this ?
			Session currentSession = .getSession();
			String consoleConfigName = view.getSelectedQueryPage().getConsoleConfiguration().getName();
			if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
				return new EntityPropertySource(object, currentSession, consoleConfigName);	
			} else {*/
    // return null;
    // }
    }
}
Also used : IPropertySource(org.eclipse.ui.views.properties.IPropertySource) QueryPage(org.hibernate.console.QueryPage) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension)

Aggregations

ConsoleExtension (org.hibernate.eclipse.console.common.ConsoleExtension)4 ArrayList (java.util.ArrayList)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 CompletionProposalsResult (org.hibernate.eclipse.console.common.CompletionProposalsResult)2 JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)1 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)1 QueryPage (org.hibernate.console.QueryPage)1