Search in sources :

Example 26 with ConsoleConfiguration

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

the class MappingTestHelper method getConsoleConfig.

private ConsoleConfiguration getConsoleConfig() {
    KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
    String consoleConfigName = testProject.getIProject().getName();
    final ConsoleConfiguration consCFG = knownConfigurations.find(consoleConfigName);
    Assert.assertNotNull(consCFG);
    return consCFG;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Example 27 with ConsoleConfiguration

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

the class MappingTestHelper method testOpenMappingFileTest.

public void testOpenMappingFileTest() {
    final Object[] persClasses = getPersistenceClasses(true);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    // $NON-NLS-1$
    final String testClass = "class";
    for (int i = 0; i < persClasses.length; i++) {
        Assert.assertTrue(persClasses[i] instanceof IPersistentClass);
        IPersistentClass persClass = (IPersistentClass) persClasses[i];
        openTest(persClass, consCFG);
        Object[] props = pcWorkbenchAdapter.getChildren(persClass);
        for (int j = 0; j < props.length; j++) {
            if (!(props[j] instanceof IProperty && ((IProperty) props[j]).classIsPropertyClass())) {
                continue;
            }
            openTest(props[j], consCFG);
            Object[] compProperties = propertyWorkbenchAdapter.getChildren(props[j]);
            for (int k = 0; k < compProperties.length; k++) {
                // test Composite properties
                if (!(compProperties[k] instanceof IProperty && ((IProperty) props[j]).classIsPropertyClass())) {
                    continue;
                }
                final IProperty prop = (IProperty) compProperties[k];
                if (testClass.equals(prop.getName()) || testClass.equals(prop.getName())) {
                    continue;
                }
                openPropertyTest((IProperty) compProperties[k], (IProperty) props[j], consCFG);
            }
        }
    }
// close all editors
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 28 with ConsoleConfiguration

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

the class SearchTabBuilder method createEntityCombo.

protected void createEntityCombo(Composite parent, final ConsoleConfiguration consoleConfig) {
    if (!ConsoleConfigurationUtils.loadSessionFactorySafely(consoleConfig)) {
        return;
    }
    ;
    Composite entitiesComposite = new Composite(parent, SWT.NONE);
    entitiesComposite.setLayout(new RowLayout());
    this.entityCombo = new Combo(entitiesComposite, SWT.NONE | SWT.READ_ONLY);
    for (Class<?> entity : ConsoleConfigurationUtils.getIndexedEntities(consoleConfig)) {
        entityCombo.add(entity.getName());
    }
    if (entityCombo.getItemCount() == 0) {
        new Label(entitiesComposite, SWT.NONE).setText("No entity classes anntotated @Indexed");
        return;
    }
    Label defaultFieldLabel = new Label(entitiesComposite, SWT.CENTER);
    defaultFieldLabel.setText("Default field:");
    this.fieldsCombo = new Combo(entitiesComposite, SWT.NONE | SWT.READ_ONLY);
    this.entityCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            ClassLoader classloader = ConsoleConfigurationUtils.getClassLoader(consoleConfig);
            try {
                fieldsCombo.removeAll();
                Class<?> clazz = Class.forName(((Combo) e.getSource()).getText(), true, classloader);
                Set<String> fields = ConsoleConfigurationUtils.getHSearchService(consoleConfig).getIndexedFields(consoleConfig.getSessionFactory(), clazz);
                fields.stream().filter(s -> !"_hibernate_class".equals(s)).forEach(s -> fieldsCombo.add(s));
                fieldsCombo.select(0);
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
        }
    });
    entityCombo.select(0);
    entitiesComposite.pack();
}
Also used : AbstractTabBuilder(org.jboss.tools.hibernate.search.toolkit.AbstractTabBuilder) AnalyzersCombo(org.jboss.tools.hibernate.search.toolkit.analyzers.AnalyzersCombo) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) HSearchConsoleConfigurationPreferences(org.jboss.tools.hibernate.search.HSearchConsoleConfigurationPreferences) CTabFolder(org.eclipse.swt.custom.CTabFolder) Set(java.util.Set) IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) Event(org.eclipse.swt.widgets.Event) RowLayout(org.eclipse.swt.layout.RowLayout) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) SWT(org.eclipse.swt.SWT) ConsoleConfigurationUtils(org.jboss.tools.hibernate.search.console.ConsoleConfigurationUtils) HSearchServiceLookup(org.jboss.tools.hibernate.search.runtime.spi.HSearchServiceLookup) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Set(java.util.Set) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) AnalyzersCombo(org.jboss.tools.hibernate.search.toolkit.analyzers.AnalyzersCombo) Combo(org.eclipse.swt.widgets.Combo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) RowLayout(org.eclipse.swt.layout.RowLayout)

Example 29 with ConsoleConfiguration

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

the class IndexRebuildHandler method execute.

@SuppressWarnings("unchecked")
@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) {
        indexRebuildForConfiguration(selection.iterator());
    }
    if (selection.getFirstElement() instanceof IPersistentClass) {
        indexRebuildForPersistentClass((ConsoleConfiguration) selection.getPaths()[0].getFirstSegment(), selection.iterator());
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ISelection(org.eclipse.jface.viewers.ISelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 30 with ConsoleConfiguration

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

the class HibernateSearchEnabledPropertyTesterTest method containsHibernateSearchLib.

@Test
public void containsHibernateSearchLib() throws MalformedURLException {
    ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
    ConsoleConfigurationPreferences prefs = mock(ConsoleConfigurationPreferences.class);
    when(consoleConfiguration.getPreferences()).thenReturn(prefs);
    when(prefs.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
    TreePath treePath = new TreePath(new Object[] { consoleConfiguration });
    ITreeSelection receiver = new TreeSelection(treePath);
    HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
    assertTrue(tester.test(receiver, "doesn't matter", null, null));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) URL(java.net.URL) HibernateSearchEnabledPropertyTester(org.jboss.tools.hibernate.search.property.testers.HibernateSearchEnabledPropertyTester) Test(org.junit.Test)

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