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;
}
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();
}
Aggregations