Search in sources :

Example 1 with IHSearchService

use of org.jboss.tools.hibernate.search.runtime.spi.IHSearchService in project jbosstools-hibernate by jbosstools.

the class IndexRebuildHandler method run.

private void run(final ConsoleConfiguration consoleConfig, final Set<Class> classes) {
    try {
        consoleConfig.execute(new Command() {

            public Object execute() {
                final IConfiguration cfg = consoleConfig.getConfiguration();
                if (cfg == null) {
                    return null;
                }
                IHSearchService service = HSearchServiceLookup.findService(HSearchConsoleConfigurationPreferences.getHSearchVersion(consoleConfig.getName()));
                service.newIndexRebuild(consoleConfig.getSessionFactory(), classes);
                return null;
            }
        });
        MessageDialog.openInformation(HibernateConsolePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Initial index rebuild", "Initial index rebuild succesfully finished");
    } catch (Exception e) {
        MessageDialog.openError(HibernateConsolePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Initial index rebuild failed", e.getMessage());
    }
}
Also used : IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) Command(org.hibernate.console.execution.ExecutionContext.Command) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with IHSearchService

use of org.jboss.tools.hibernate.search.runtime.spi.IHSearchService in project jbosstools-hibernate by jbosstools.

the class AnalyzersTabBuilder method buildTab.

protected Composite buildTab(CTabFolder folder, ConsoleConfiguration consoleConfig) {
    final String consoleConfigName = consoleConfig.getName();
    Composite container = new Composite(folder, SWT.TOP);
    container.setLayout(new GridLayout(2, true));
    GridData comboGridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_CENTER, false, false);
    comboGridData.horizontalSpan = 2;
    analyzersCombo = new AnalyzersCombo(container, comboGridData, consoleConfigName);
    final Text input = new Text(container, SWT.MULTI | SWT.BORDER);
    input.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    final Text output = new Text(container, SWT.MULTI | SWT.BORDER);
    output.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    output.setEditable(false);
    input.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            IHSearchService service = HSearchServiceLookup.findService(HSearchConsoleConfigurationPreferences.getHSearchVersion(consoleConfigName));
            String result = service.doAnalyze(((Text) e.getSource()).getText(), analyzersCombo.getAnalyzer());
            output.setText(result);
        }
    });
    container.pack();
    container.update();
    return container;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text)

Example 3 with IHSearchService

use of org.jboss.tools.hibernate.search.runtime.spi.IHSearchService in project jbosstools-hibernate by jbosstools.

the class ExploreDocsTabBuilder method createOperatingConrols.

protected void createOperatingConrols(Composite parent, final ConsoleConfiguration consoleConfig) {
    createEntityCheckBoxes(parent, consoleConfig);
    Composite block = new Composite(parent, SWT.NONE);
    block.setLayout(new RowLayout());
    Button execButton = new Button(block, SWT.PUSH);
    new Label(block, SWT.NONE).setText("Document #");
    Button preButton = new Button(block, SWT.PUSH);
    preButton.setText("<---");
    this.docNumberLbl = new Label(block, SWT.NONE);
    this.docNumberLbl.setText("   ");
    Button nextButton = new Button(block, SWT.PUSH);
    nextButton.setText("--->");
    preButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (docs.isEmpty()) {
                return;
            }
            int curNum = Integer.valueOf(docNumberLbl.getText());
            if (curNum > 0) {
                tableInsert(docs.get(curNum - 1));
                docNumberLbl.setText(String.valueOf(curNum - 1));
            }
        }
    });
    nextButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (docs.isEmpty()) {
                return;
            }
            int curNum = Integer.valueOf(docNumberLbl.getText());
            if (curNum < docs.size() - 1) {
                tableInsert(docs.get(curNum + 1));
                docNumberLbl.setText(String.valueOf(curNum + 1));
            }
        }
    });
    execButton.setImage(EclipseImages.getImage(ImageConstants.EXECUTE));
    execButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            ClassLoader classloader = ConsoleConfigurationUtils.getClassLoader(consoleConfig);
            Set<Class> classes = new HashSet<Class>();
            for (Button entityBtn : entityCheckBoxes) {
                if (entityBtn.getSelection()) {
                    try {
                        classes.add(Class.forName(entityBtn.getText(), true, classloader));
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (classes.isEmpty()) {
                return;
            }
            IHSearchService service = HSearchServiceLookup.findService(HSearchConsoleConfigurationPreferences.getHSearchVersion(consoleConfig.getName()));
            docs = service.getEntityDocuments(consoleConfig.getSessionFactory(), classes.toArray(new Class[0]));
            if (docs.isEmpty()) {
                tableViewer.getTable().removeAll();
                tableViewer.add(new TableObject("No Lucene index found", ""));
                tableViewer.add(new TableObject("or your console configuration is out of sync", ""));
                return;
            }
            tableInsert(docs.get(0));
            docNumberLbl.setText("0");
        }
    });
}
Also used : IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) Listener(org.eclipse.swt.widgets.Listener) HashSet(java.util.HashSet) Set(java.util.Set) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) Event(org.eclipse.swt.widgets.Event)

Example 4 with IHSearchService

use of org.jboss.tools.hibernate.search.runtime.spi.IHSearchService in project jbosstools-hibernate by jbosstools.

the class SearchTabBuilder method buildTab.

protected Composite buildTab(CTabFolder folder, ConsoleConfiguration consoleConfig) {
    final String consoleConfigName = consoleConfig.getName();
    Composite container = new Composite(folder, SWT.VERTICAL);
    container.setLayout(new GridLayout());
    Composite entitiesContainer = new Composite(container, SWT.TOP);
    GridData entitiesGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    entitiesContainer.setLayoutData(entitiesGridData);
    createEntityCombo(entitiesContainer, consoleConfig);
    entitiesContainer.pack();
    Composite searchDataComposite = new Composite(container, SWT.TOP);
    searchDataComposite.setLayout(new GridLayout(2, true));
    final Text query = new Text(searchDataComposite, SWT.MULTI | SWT.BORDER);
    GridData queryGridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
    queryGridData.heightHint = 5 * query.getLineHeight();
    queryGridData.verticalSpan = 2;
    query.setLayoutData(queryGridData);
    analyzersCombo = new AnalyzersCombo(searchDataComposite, new GridData(), consoleConfigName);
    Button searchButton = new Button(searchDataComposite, SWT.PUSH);
    searchButton.setText("Search");
    searchButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            ClassLoader classloader = ConsoleConfigurationUtils.getClassLoader(consoleConfig);
            Class<?> entity = null;
            try {
                entity = Class.forName(entityCombo.getText(), true, classloader);
            } catch (ClassNotFoundException e) {
                entity = null;
            }
            IHSearchService service = HSearchServiceLookup.findService(HSearchConsoleConfigurationPreferences.getHSearchVersion(consoleConfigName));
            resultTable.showResults(service.search(consoleConfig.getSessionFactory(), entity, fieldsCombo.getText(), analyzersCombo.getAnalyzer(), query.getText()), consoleConfig.getSessionFactory().getAllClassMetadata().get(entityCombo.getText()));
        }
    });
    searchDataComposite.pack();
    this.resultTable = new SearchResultTable(container, consoleConfig);
    // container.pack();
    container.update();
    return container;
}
Also used : IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) ModifyListener(org.eclipse.swt.events.ModifyListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) AnalyzersCombo(org.jboss.tools.hibernate.search.toolkit.analyzers.AnalyzersCombo)

Aggregations

IHSearchService (org.jboss.tools.hibernate.search.runtime.spi.IHSearchService)4 Composite (org.eclipse.swt.widgets.Composite)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Text (org.eclipse.swt.widgets.Text)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Label (org.eclipse.swt.widgets.Label)1 Command (org.hibernate.console.execution.ExecutionContext.Command)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1 AnalyzersCombo (org.jboss.tools.hibernate.search.toolkit.analyzers.AnalyzersCombo)1