package tool.search;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.swt.SWT;
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.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
public class ToolSearchPage extends DialogPage implements ISearchPage{
// search for
private final static int TYPE= IToolSearchConstants.TYPE;
private final static int METHOD= IToolSearchConstants.METHOD;
private final static int PACKAGE= IToolSearchConstants.PACKAGE;
private final static int CONSTRUCTOR= IToolSearchConstants.CONSTRUCTOR;
private final static int FIELD= IToolSearchConstants.FIELD;
// limit to
private final static int DECLARATIONS= IToolSearchConstants.DECLARATIONS;
private final static int IMPLEMENTORS= IToolSearchConstants.IMPLEMENTORS;
private final static int REFERENCES= IToolSearchConstants.REFERENCES;
private final static int SPECIFIC_REFERENCES= IToolSearchConstants.CAST_TYPE_REFERENCE;
private final static int ALL_OCCURRENCES= IToolSearchConstants.ALL_OCCURRENCES;
private final static int READ_ACCESSES= IToolSearchConstants.READ_ACCESSES;
private final static int WRITE_ACCESSES= IToolSearchConstants.WRITE_ACCESSES;
public static final String PARTICIPANT_EXTENSION_POINT= "org.eclipse.jdt.ui.queryParticipants"; //$NON-NLS-1$
public static final String EXTENSION_POINT_ID= "org.eclipse.jdt.ui.JavaSearchPage"; //$NON-NLS-1$
private static final int HISTORY_SIZE= 12;
// Dialog store id constants
private final static String PAGE_NAME= "JavaSearchPage"; //$NON-NLS-1$
private final static String STORE_CASE_SENSITIVE= "CASE_SENSITIVE"; //$NON-NLS-1$
private final static String STORE_INCLUDE_MASK= "INCLUDE_MASK"; //$NON-NLS-1$
private final static String STORE_HISTORY= "HISTORY"; //$NON-NLS-1$
private final static String STORE_HISTORY_SIZE= "HISTORY_SIZE"; //$NON-NLS-1$
private final List<SearchPatternData> fPreviousSearchPatterns;
private SearchPatternData fInitialData;
//private IJavaElement fJavaElement;
private boolean fFirstTime= true;
private IDialogSettings fDialogSettings;
private boolean fIsCaseSensitive;
private Combo fPattern;
private ISearchPageContainer fContainer;
private Button fCaseSensitive;
private Button[] fSearchFor;
private int fMatchLocations;
private Link fMatchLocationsLink;
public ToolSearchPage() {
fPreviousSearchPatterns= new ArrayList<SearchPatternData>();
}
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite result= new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout(2, true);
layout.horizontalSpacing= 10;
result.setLayout(layout);
Label separator= new Label(result, SWT.NONE);
separator.setVisible(false);
GridData data= new GridData(GridData.FILL, GridData.FILL, false, false, 2, 1);
data.heightHint= convertHeightInCharsToPixels(1) / 3;
separator.setLayoutData(data);
setControl(result);
Dialog.applyDialogFont(result);
}
final void updateOKStatus() {
}
@Override
public boolean performAction() {
return false;
}
@Override
public void setContainer(ISearchPageContainer container) {
fContainer= container;
}
private String getPattern() {
return fPattern.getText();
}
private static class SearchPatternData {
private final int searchFor;
private final int limitTo;
private final String pattern;
private final boolean isCaseSensitive;
private final int includeMask;
private final int matchLocations;
private final int scope;
private final IWorkingSet[] workingSets;
// private IJavaElement javaElement;
public SearchPatternData(int searchFor, int limitTo, int matchLocations, boolean isCaseSensitive, String pattern, /*IJavaElement element,*/ int includeMask) {
this(searchFor, limitTo, matchLocations, pattern, isCaseSensitive, /*element,*/ ISearchPageContainer.WORKSPACE_SCOPE, null, includeMask);
}
public SearchPatternData(int searchFor, int limitTo, int matchLocations, String pattern, boolean isCaseSensitive, /*IJavaElement element,*/ int scope, IWorkingSet[] workingSets, int includeMask) {
this.searchFor= searchFor;
this.limitTo= limitTo;
this.matchLocations= matchLocations;
this.pattern= pattern;
this.isCaseSensitive= isCaseSensitive;
this.scope= scope;
this.workingSets= workingSets;
this.includeMask= includeMask;
// setJavaElement(element);
}
// public void setJavaElement(IJavaElement javaElement) {
// this.javaElement= javaElement;
// }
public boolean isCaseSensitive() {
return isCaseSensitive;
}
// public IJavaElement getJavaElement() {
// return javaElement;
// }
public int getLimitTo() {
return limitTo;
}
public String getPattern() {
return pattern;
}
public int getScope() {
return scope;
}
public int getSearchFor() {
return searchFor;
}
public IWorkingSet[] getWorkingSets() {
return workingSets;
}
public int getIncludeMask() {
return includeMask;
}
public int getMatchLocations() {
return matchLocations;
}
public void store(IDialogSettings settings) {
settings.put("searchFor", searchFor); //$NON-NLS-1$
settings.put("scope", scope); //$NON-NLS-1$
settings.put("pattern", pattern); //$NON-NLS-1$
settings.put("limitTo", limitTo); //$NON-NLS-1$
settings.put("matchLocations", matchLocations); //$NON-NLS-1$
// settings.put("javaElement", javaElement != null ? javaElement.getHandleIdentifier() : ""); //$NON-NLS-1$ //$NON-NLS-2$
settings.put("isCaseSensitive", isCaseSensitive); //$NON-NLS-1$
if (workingSets != null) {
String[] wsIds= new String[workingSets.length];
for (int i= 0; i < workingSets.length; i++) {
wsIds[i]= workingSets[i].getName();
}
settings.put("workingSets", wsIds); //$NON-NLS-1$
} else {
settings.put("workingSets", new String[0]); //$NON-NLS-1$
}
settings.put("includeMask", includeMask); //$NON-NLS-1$
}
public static SearchPatternData create(IDialogSettings settings) {
String pattern= settings.get("pattern"); //$NON-NLS-1$
if (pattern.length() == 0) {
return null;
}
String[] wsIds= settings.getArray("workingSets"); //$NON-NLS-1$
IWorkingSet[] workingSets= null;
if (wsIds != null && wsIds.length > 0) {
IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
workingSets= new IWorkingSet[wsIds.length];
for (int i= 0; workingSets != null && i < wsIds.length; i++) {
workingSets[i]= workingSetManager.getWorkingSet(wsIds[i]);
if (workingSets[i] == null) {
workingSets= null;
}
}
}
try {
int searchFor= settings.getInt("searchFor"); //$NON-NLS-1$
int scope= settings.getInt("scope"); //$NON-NLS-1$
int limitTo= settings.getInt("limitTo"); //$NON-NLS-1$
int matchLocations= 0;
if (settings.get("matchLocations") != null) { //$NON-NLS-1$
matchLocations= settings.getInt("matchLocations"); //$NON-NLS-1$
}
boolean isCaseSensitive= settings.getBoolean("isCaseSensitive"); //$NON-NLS-1$
int includeMask = 0;
if (settings.get("includeMask") != null) { //$NON-NLS-1$
includeMask= settings.getInt("includeMask"); //$NON-NLS-1$
}
return new SearchPatternData(searchFor, limitTo, matchLocations, pattern, isCaseSensitive, /*elem,*/ scope, workingSets, includeMask);
} catch (NumberFormatException e) {
return null;
}
}
}
}