Search in sources :

Example 1 with ISearchPage

use of org.eclipse.search.ui.ISearchPage in project eclipse.platform.text by eclipse.

the class SearchDialog method createPageControl.

private Control createPageControl(Composite parent, final SearchPageDescriptor descriptor) {
    // Page wrapper
    final Composite pageWrapper = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    pageWrapper.setLayout(layout);
    applyDialogFont(pageWrapper);
    BusyIndicator.showWhile(getShell().getDisplay(), () -> SafeRunner.run(new ISafeRunnable() {

        @Override
        public void run() throws Exception {
            // create page and control
            ISearchPage page = descriptor.createObject(SearchDialog.this);
            if (page != null) {
                page.createControl(pageWrapper);
            }
        }

        @Override
        public void handleException(Throwable ex) {
            if (ex instanceof CoreException) {
                ExceptionHandler.handle((CoreException) ex, getShell(), SearchMessages.Search_Error_createSearchPage_title, Messages.format(SearchMessages.Search_Error_createSearchPage_message, descriptor.getLabel()));
            } else {
                ExceptionHandler.displayMessageDialog(ex, getShell(), SearchMessages.Search_Error_createSearchPage_title, Messages.format(SearchMessages.Search_Error_createSearchPage_message, descriptor.getLabel()));
            }
        }
    }));
    ISearchPage page = descriptor.getPage();
    if (page == null || page.getControl() == null) {
        Composite container = new Composite(parent, SWT.NONE);
        Label label = new Label(container, SWT.WRAP);
        label.setText(Messages.format(SearchMessages.SearchDialog_error_pageCreationFailed, descriptor.getLabel()));
        container.setLayout(new GridLayout());
        label.setLayoutData(new GridData());
        return container;
    }
    page.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // Search scope
    boolean showScope = descriptor.showScopeSection();
    if (showScope) {
        Composite c = new Composite(pageWrapper, SWT.NONE);
        c.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        c.setLayout(new GridLayout());
        int index = fDescriptors.indexOf(descriptor);
        fScopeParts[index] = new ScopePart(this, descriptor.canSearchInProjects());
        Control part = fScopeParts[index].createPart(c);
        applyDialogFont(part);
        part.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        fScopeParts[index].setVisible(true);
    }
    return pageWrapper;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) CoreException(org.eclipse.core.runtime.CoreException) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ISearchPage(org.eclipse.search.ui.ISearchPage) Point(org.eclipse.swt.graphics.Point)

Example 2 with ISearchPage

use of org.eclipse.search.ui.ISearchPage in project eclipse.platform.text by eclipse.

the class SearchDialog method turnToPage.

private void turnToPage(SelectionEvent event) {
    final CTabItem item = (CTabItem) event.item;
    CTabFolder folder = item.getParent();
    // $NON-NLS-1$
    SearchPageDescriptor descriptor = (SearchPageDescriptor) item.getData("descriptor");
    if (item.getControl() == null) {
        item.setControl(createPageControl(folder, descriptor));
    }
    Control oldControl = folder.getItem(fCurrentIndex).getControl();
    Point oldSize = oldControl.getSize();
    Control newControl = item.getControl();
    Point newSize = newControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    resizeDialogIfNeeded(oldSize, newSize);
    ISearchPage oldPage = fCurrentPage;
    if (oldPage != null) {
        oldPage.setVisible(false);
    }
    fCurrentPage = descriptor.getPage();
    fDialogSettings.put(STORE_PREVIOUS_PAGE, descriptor.getId());
    fCurrentIndex = folder.getSelectionIndex();
    setPerformActionEnabled(fCurrentPage != null);
    if (fCurrentPage != null) {
        fCurrentPage.setVisible(true);
        Control pageControl = fCurrentPage.getControl();
        if (pageControl instanceof Composite)
            ((Composite) pageControl).layout(false, true);
    }
    fReplaceButton.setVisible(fCurrentPage instanceof IReplacePage);
    notifyPageChanged();
}
Also used : Control(org.eclipse.swt.widgets.Control) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) IReplacePage(org.eclipse.search.ui.IReplacePage) Point(org.eclipse.swt.graphics.Point) CTabItem(org.eclipse.swt.custom.CTabItem) ISearchPage(org.eclipse.search.ui.ISearchPage)

Aggregations

ISearchPage (org.eclipse.search.ui.ISearchPage)2 Point (org.eclipse.swt.graphics.Point)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 CoreException (org.eclipse.core.runtime.CoreException)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 IReplacePage (org.eclipse.search.ui.IReplacePage)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Label (org.eclipse.swt.widgets.Label)1