Search in sources :

Example 36 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HQLExpressionCompilerParticipant method buildStarting.

public void buildStarting(BuildContext[] files, boolean isBatch) {
    for (int i = 0; i < files.length; i++) {
        BuildContext context = files[i];
        ConsoleConfiguration consoleConfiguration = getConsoleConfiguration(ProjectUtils.findJavaProject(context.getFile().getProject().getName()));
        if (consoleConfiguration != null && consoleConfiguration.isSessionFactoryCreated()) {
            ASTParser parser = ASTParser.newParser(AST.JLS9);
            parser.setKind(ASTParser.K_COMPILATION_UNIT);
            parser.setSource(context.getContents());
            parser.setResolveBindings(false);
            ASTNode node = parser.createAST(null);
            CompilationUnit cu = null;
            if (node instanceof CompilationUnit) {
                cu = (CompilationUnit) node;
            }
            HQLDetector hqlDetector = new HQLDetector(cu, consoleConfiguration, context.getFile());
            node.accept(hqlDetector);
            if (!hqlDetector.getProblems().isEmpty()) {
                CategorizedProblem[] toArray = hqlDetector.getProblems().toArray(new CategorizedProblem[0]);
                context.recordNewProblems(toArray);
            }
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BuildContext(org.eclipse.jdt.core.compiler.BuildContext) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTParser(org.eclipse.jdt.core.dom.ASTParser)

Example 37 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 38 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class ConfigurationCombo method createControl.

protected Control createControl(Composite parent) {
    selectionAdapter = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            editor.setConsoleConfigurationName(comboControl.getText());
        }
    };
    Control control = super.createControl(parent);
    listener = new KnownConfigurationsAdapter() {

        public void sessionFactoryClosing(ConsoleConfiguration configuration, ISessionFactory closingFactory) {
        }

        public void sessionFactoryBuilt(ConsoleConfiguration ccfg, ISessionFactory builtFactory) {
        }

        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            populateComboBox();
        }

        public void configurationAdded(ConsoleConfiguration root) {
            populateComboBox();
        }
    };
    KnownConfigurations.getInstance().addConsoleConfigurationListener(listener);
    return control;
}
Also used : Control(org.eclipse.swt.widgets.Control) KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory)

Example 39 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernateConsolePlugin method listenForConfigurations.

private void listenForConfigurations() {
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    kcl = new KnownConfigurationsAdapter() {

        /**
         * @param root
         * @param forUpdate - shows whether physical removal necessary
         */
        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            if (!forUpdate) {
                try {
                    removeConfiguration(root.getName());
                } catch (CoreException e) {
                    logErrorMessage(HibernateConsoleMessages.HibernateConsolePlugin_could_not_delete_launch_config_for + root.getName(), e);
                }
            }
        }
    };
    KnownConfigurations.getInstance().addConsoleConfigurationListener(kcl);
    icl = new ILaunchConfigurationListener() {

        boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
            try {
                return configuration.getType().getIdentifier().equals(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
            } catch (CoreException e) {
            // HibernateConsolePlugin.getDefault().log( e );
            // ignore since it occurs on delete
            }
            return false;
        }

        public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
            ConsoleConfiguration cfg = KnownConfigurations.getInstance().find(configuration.getName());
            if (cfg != null) {
                // file system removal have been made already.
                KnownConfigurations.getInstance().removeConfiguration(cfg, true);
            }
        }

        public void launchConfigurationChanged(ILaunchConfiguration configuration) {
            if (configuration.isWorkingCopy() || isTemporary(configuration)) {
                return;
            }
            if (isConsoleConfiguration(configuration)) {
                KnownConfigurations instance = KnownConfigurations.getInstance();
                ConsoleConfiguration oldcfg = instance.find(configuration.getName());
                if (oldcfg != null) {
                    // reset it no matter what.
                    oldcfg.reset();
                } else {
                    // A new one!
                    ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
                    instance.addConfiguration(new ConsoleConfiguration(adapter), true);
                }
            }
        }

        private ConsoleConfigurationPreferences buildConfigurationPreferences(ILaunchConfiguration configuration) {
            return new EclipseLaunchConsoleConfigurationPreferences(configuration);
        }

        public void launchConfigurationAdded(ILaunchConfiguration configuration) {
            if (isConsoleConfiguration(configuration)) {
                ILaunchConfiguration movedFrom = launchManager.getMovedFrom(configuration);
                if (movedFrom != null && isConsoleConfiguration(movedFrom)) {
                    KnownConfigurations instance = KnownConfigurations.getInstance();
                    ConsoleConfiguration oldcfg = instance.find(movedFrom.getName());
                    if (oldcfg != null) {
                        // call this before we remove old configuration
                        refactor(movedFrom, configuration);
                        // reset it no matter what.
                        oldcfg.reset();
                        instance.removeConfiguration(oldcfg, false);
                    }
                }
                KnownConfigurations instance = KnownConfigurations.getInstance();
                ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
                boolean temporary = isTemporary(configuration);
                if (!temporary) {
                    instance.addConfiguration(new ConsoleConfiguration(adapter), true);
                }
            }
        }

        private void refactor(ILaunchConfiguration oldConfiguration, ILaunchConfiguration newConfiguration) {
            if (!oldConfiguration.getName().equals(newConfiguration.getName())) {
                // only rename of console configuration refactoring is supported.
                ConsoleConfigurationRenameProcessor proc = new ConsoleConfigurationRenameProcessor(oldConfiguration, newConfiguration.getName());
                // Refactor for rename
                PerformRefactoringOperation refOperation = new PerformRefactoringOperation(new ProcessorBasedRefactoring(proc), CheckConditionsOperation.ALL_CONDITIONS);
                try {
                    ResourcesPlugin.getWorkspace().run(refOperation, null);
                } catch (OperationCanceledException oce) {
                    throw new OperationCanceledException();
                } catch (CoreException ce) {
                    HibernateConsolePlugin.openError(new Shell(), HibernateConsoleMessages.EditConsoleConfiguration_rename_refactoring_error_totle, ce.getLocalizedMessage(), ce, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
                }
            }
        }

        private boolean isTemporary(ILaunchConfiguration configuration) {
            boolean temporary = true;
            try {
                temporary = configuration.getAttribute(AddConfigurationAction.TEMPORARY_CONFIG_FLAG, false);
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.HibernateConsolePlugin_problem_to_get_flag, e);
            }
            return temporary;
        }
    };
    launchManager.addLaunchConfigurationListener(icl);
}
Also used : KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ConsoleConfigurationRenameProcessor(org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameProcessor) ILaunchManager(org.eclipse.debug.core.ILaunchManager) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) ILaunchConfigurationListener(org.eclipse.debug.core.ILaunchConfigurationListener) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Example 40 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class ReloadConfigurationAction method doRun.

protected void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        try {
            Object node = i.next();
            if (node instanceof ConsoleConfiguration) {
                ConsoleConfiguration config = (ConsoleConfiguration) node;
                config.reset();
                updateState(config);
                viewer.refresh(node);
            }
        } catch (HibernateConsoleRuntimeException he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.ReloadConfigurationAction_exception_while_start_hibernate, he);
        } catch (UnsupportedClassVersionError ucve) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.ReloadConfigurationAction_starting_hibernate_resulted_exception, ucve);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6