Search in sources :

Example 51 with ConsoleConfiguration

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

the class CriteriaEditor method getImports.

private String[] getImports() {
    final ConsoleConfiguration consoleConfiguration = getConsoleConfiguration();
    if (!consoleConfiguration.hasConfiguration()) {
        try {
            consoleConfiguration.build();
            consoleConfiguration.buildMappings();
        } catch (Exception e) {
            String mess = NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc, consoleConfiguration.getName());
            HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
        }
    }
    Set<String> imports = new HashSet<String>();
    IConfiguration configuration = consoleConfiguration.getConfiguration();
    if (configuration != null) {
        Iterator<IPersistentClass> classMappings = configuration.getClassMappings();
        while (classMappings.hasNext()) {
            IPersistentClass clazz = classMappings.next();
            String className = clazz.getClassName();
            if (className != null) {
                imports.add(className);
            }
        }
    }
    // $NON-NLS-1$
    imports.add("org.hibernate.*");
    // $NON-NLS-1$
    imports.add("org.hibernate.criterion.*");
    return imports.toArray(new String[imports.size()]);
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HashSet(java.util.HashSet)

Example 52 with ConsoleConfiguration

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

the class StructuredTextViewerConfigurationUtil method getService.

public static IService getService(ISourceViewer sourceViewer) {
    IJavaProject javaProject = findJavaProject(sourceViewer);
    HibernateNature hibnat = HibernateNature.getHibernateNature(javaProject);
    if (hibnat != null) {
        ConsoleConfiguration cc = hibnat.getDefaultConsoleConfiguration();
        if (cc != null) {
            HibernateExtension extension = cc.getHibernateExtension();
            if (extension != null) {
                return extension.getHibernateService();
            }
        }
    }
    return ServiceLookup.getDefault();
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateExtension(org.hibernate.eclipse.console.common.HibernateExtension) HibernateNature(org.hibernate.eclipse.nature.HibernateNature)

Example 53 with ConsoleConfiguration

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

the class IndexToolkitView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, true));
    this.consoleConfigCombo = new ConfigurationCombo(parent, initialConsoleConfig == null ? null : initialConsoleConfig.getName());
    final CTabFolder folder = new CTabFolder(parent, SWT.TOP);
    folder.setLayoutData(new GridData(GridData.FILL, SWT.FILL, true, true));
    ConsoleConfiguration consoleConfig = KnownConfigurations.getInstance().find(this.consoleConfigCombo.getConsoleConfigSelected());
    final CTabItem analyzersTab = new CTabItem(folder, SWT.NONE);
    analyzersTab.setText(ANALYZERS_TAB_NAME);
    final AnalyzersTabBuilder analyzersBuilder = AnalyzersTabBuilder.getInstance();
    analyzersTab.setControl(analyzersBuilder.getTab(folder, consoleConfig));
    final CTabItem exploreDocsTab = new CTabItem(folder, SWT.NONE);
    exploreDocsTab.setText(EXPLORE_DOCS_TAB_NAME);
    final ExploreDocsTabBuilder exploreDocsBuilder = ExploreDocsTabBuilder.getInstance();
    exploreDocsTab.setControl(exploreDocsBuilder.getTab(folder, consoleConfig));
    final CTabItem searchTab = new CTabItem(folder, SWT.NONE);
    searchTab.setText(SEARCH_TAB_NAME);
    final SearchTabBuilder searchBuilder = SearchTabBuilder.getInstance();
    searchTab.setControl(searchBuilder.getTab(folder, consoleConfig));
    folder.setSelection(0);
    this.consoleConfigCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            ConsoleConfiguration consoleConfig = KnownConfigurations.getInstance().find(((Combo) e.getSource()).getText());
            analyzersTab.setControl(analyzersBuilder.getTab(folder, consoleConfig));
            exploreDocsTab.setControl(exploreDocsBuilder.getTab(folder, consoleConfig));
            searchTab.setControl(searchBuilder.getTab(folder, consoleConfig));
        }
    });
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ModifyListener(org.eclipse.swt.events.ModifyListener) Combo(org.eclipse.swt.widgets.Combo) CTabItem(org.eclipse.swt.custom.CTabItem) ExploreDocsTabBuilder(org.jboss.tools.hibernate.search.toolkit.docs.ExploreDocsTabBuilder) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AnalyzersTabBuilder(org.jboss.tools.hibernate.search.toolkit.analyzers.AnalyzersTabBuilder) GridData(org.eclipse.swt.layout.GridData) SearchTabBuilder(org.jboss.tools.hibernate.search.toolkit.search.SearchTabBuilder)

Example 54 with ConsoleConfiguration

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

the class IndexToolkitViewLaunchHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel.isEmpty()) {
        return null;
    }
    ITreeSelection selection = (ITreeSelection) sel;
    if (selection.getFirstElement() instanceof ConsoleConfiguration) {
        ConsoleConfiguration consoleConfig = (ConsoleConfiguration) selection.getFirstElement();
        if (ConsoleConfigurationUtils.isConnectionExist(consoleConfig)) {
            HibernateSearchConsolePlugin.getDefault().showIndexToolkitView(consoleConfig);
        }
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ISelection(org.eclipse.jface.viewers.ISelection)

Example 55 with ConsoleConfiguration

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

the class HibernateSearchEnabledPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof ITreeSelection)) {
        return false;
    }
    ITreeSelection selection = (ITreeSelection) receiver;
    Set<ConsoleConfiguration> consoleConfigs = new HashSet<ConsoleConfiguration>();
    for (TreePath path : selection.getPaths()) {
        if (path.getFirstSegment() instanceof ConsoleConfiguration) {
            consoleConfigs.add((ConsoleConfiguration) path.getFirstSegment());
        } else {
            return false;
        }
    }
    for (ConsoleConfiguration consoleConfig : consoleConfigs) {
        boolean isHibernateSearch = false;
        URL[] classPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfig.getPreferences());
        for (URL url : classPathURLs) {
            if (url.getFile().contains("hibernate-search")) {
                isHibernateSearch = true;
                break;
            }
        }
        if (!isHibernateSearch) {
            return false;
        }
    }
    return true;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) TreePath(org.eclipse.jface.viewers.TreePath) URL(java.net.URL) HashSet(java.util.HashSet)

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