package com.redhat.ceylon.eclipse.imp.editorActionContributions;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.search.ui.IReplacePage;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;

import com.redhat.ceylon.eclipse.imp.parser.CeylonParseController;

public class CeylonSearchDialogPage extends DialogPage 
		implements ISearchPage, IReplacePage {

	private String searchString="";
	private boolean caseSensitive = false;
	private boolean references = true;
	private boolean declarations = true;
	private ISearchPageContainer container;
	
	public CeylonSearchDialogPage() {
		super("Ceylon Search");
	}
	
	@Override
	public void createControl(Composite parent) {
		Composite result = new Composite(parent, SWT.NONE);
		setControl(result);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		result.setLayout(layout);
		Label title = new Label(result, SWT.RIGHT);  
		title.setText("Search string");
		GridData gd = new GridData();
		gd.horizontalSpan=2;
		title.setLayoutData(gd);
		final Combo text = new Combo(result, 0);
		text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
		text.setText(searchString);
		text.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent event) {
				searchString = text.getText();
			}
		});
		final Button caseSense = new Button(result, SWT.CHECK);
		caseSense.setText("Case sensitive");
		caseSense.setSelection(caseSensitive);
		caseSense.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				caseSensitive = !caseSensitive;
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent event) {}
		});
		Group sub = new Group(result, SWT.SHADOW_ETCHED_IN);
		sub.setText("Search For");
		GridLayout sgl = new GridLayout();
		sgl.numColumns = 2;
		sub.setLayout(sgl);
		final Button refs = new Button(sub, SWT.CHECK);
		refs.setText("References");
		refs.setSelection(references);
		refs.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				references = !references;
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent event) {}
		});		
		final Button decs = new Button(sub, SWT.CHECK);
		decs.setText("Declarations");
		decs.setSelection(declarations);
		decs.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				declarations = !declarations;
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent event) {}
		});		
	}

	@Override
	public boolean performAction() {
		int scope = container.getSelectedScope();
		String[] projectNames = container.getSelectedProjectNames();
		//CeylonParseController cpc = (CeylonParseController) editor.getParseController();
		CeylonParseController cpc = new CeylonParseController();
		IFile file = null;
		cpc.parse(file.getFullPath().toPortableString(), null);
		NewSearchUI.runQueryInBackground(new CeylonSearchQuery(cpc, 
				searchString, file, references, declarations, 
				caseSensitive));
		return true;
	}

	@Override
	public boolean performReplace() {
		// TODO Auto-generated method stub
		return true;
	}
	
	@Override
	public void setContainer(ISearchPageContainer container) {
		this.container = container;
	}
	
}

@@ -149,51 +149,8 @@
 ge;%0A
-import org.eclipse.search.ui.IReplacePage;%0A
 impo
@@ -918,16 +918,18 @@
 archPage
+/*
 , IRepla
@@ -934,16 +934,18 @@
 lacePage
+*/
  %7B%0A%0A%09pri
@@ -3681,24 +3681,26 @@
  true;%0A%09%7D%0A%0A%09
+/*
 @Override%0A%09p
@@ -3782,24 +3782,26 @@
 urn true;%0A%09%7D
+*/
 %0A%09%0A%09@Overrid

remove "replace" button