Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.findrefs;
  
 
 import  org.eclipse.jface.action.IAction;
 import  org.eclipse.jface.action.IToolBarManager;
 import  org.eclipse.jface.util.OpenStrategy;
 import  org.eclipse.jface.viewers.ISelection;
 import  org.eclipse.jface.viewers.IStructuredSelection;
 import  org.eclipse.jface.viewers.OpenEvent;
 import  org.eclipse.jface.viewers.TreeViewer;
 import  org.eclipse.search.ui.IContextMenuConstants;
 import  org.eclipse.search.ui.IQueryListener;
 import  org.eclipse.search.ui.ISearchQuery;
 import  org.eclipse.search.ui.ISearchResult;
 import  org.eclipse.search.ui.ISearchResultPage;
 import  org.eclipse.search.ui.ISearchResultViewPart;
 import  org.eclipse.search.ui.NewSearchUI;
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.layout.FillLayout;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 import  org.eclipse.swt.widgets.Display;
 import  org.eclipse.swt.widgets.Table;
 import  org.eclipse.swt.widgets.TableItem;
 import  org.eclipse.ui.IActionBars;
 import  org.eclipse.ui.IMemento;
 import  org.eclipse.ui.OpenAndLinkWithEditorHelper;
 import  org.eclipse.ui.actions.ActionFactory;
 import  org.eclipse.ui.part.IPageSite;
 import  org.eclipse.ui.part.Page;
 import  org.eclipse.ui.part.PageBook;
 
 
 public class ReferenceSearchViewPage extends Page implements ISearchResultPage {
 
 	private String id;
 
 	private ISearchResult searchResult;
 
 	private PageBook pagebook;
 
 	private Table busyLabel;
 
 	private Composite control;
 
 	private TreeViewer viewer;
 
 	private ISearchResultViewPart part;
 
 	private IAction showNextAction;
 
 	private IAction showPreviousAction;
 
 	private IAction expandAllAction;
 
 	private IAction collapseAllAction;
 
 
 
 	
 
 	private boolean isBusyShowing;
 
 	private IQueryListener queryListener;
 
 	}
 
 	public String getID() {
 		return ;
 	}
 
	public void setID(String id) {
		this. = id;
	}
	public String getLabel() {
		return  == null ? "" : .getLabel();
	}
	public Object getUIState() {
		return .getSelection();
	}
	public void restoreState(IMemento memento) {
	}
	public void saveState(IMemento memento) {
	}
	public void init(IPageSite pageSite) {
		super.init(pageSite);
	}
	public void setInput(ISearchResult newSearchResultObject uiState) {
		synchronized () {
			this.searchResult = newSearchResult;
			if (searchResult != null) {
				viewer.setInput(newSearchResult);
				if (uiState instanceof ISelection) {
					viewer.setSelection((ISelection) uiState);
				}
			}
			part.updateLabel();
		}
	}
	public void setViewPart(ISearchResultViewPart part) {
		this. = part;
	}
	public void createControl(Composite parent) {
		 = new PageBook(parent, SWT.NULL);
		.setLayoutData(new GridData(GridData.FILL_BOTH));
		 = new Table(, SWT.NONE);
		TableItem item = new TableItem(, SWT.NONE);
		.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		 = new Composite(, SWT.NULL);
		.setLayoutData(new GridData(GridData.FILL_BOTH));
		.setSize(100, 100);
		.setLayout(new FillLayout());
		 = new TreeViewer(, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		.setContentProvider();
		.setLabelProvider();
		.setSorter();
		IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
		tbm.update(true);
		.showPage();
		 = false;
		NewSearchUI.addQueryListener();
	}
	protected OpenAndLinkWithEditorHelper createOpenAndLinkWithEditorHandler() {
		return new OpenAndLinkWithEditorHelper() {
			protected void activate(ISelection selection) {
				final int currentMode = OpenStrategy.getOpenMethod();
				try {
					OpenStrategy.setOpenMethod(OpenStrategy.DOUBLE_CLICK);
					handleOpen(new OpenEvent(selection));
finally {
					OpenStrategy.setOpenMethod(currentMode);
				}
			}
			protected void linkToEditor(ISelection selection) {
				// not supported by this part
			}
			protected void open(ISelection selectionboolean activate) {
				handleOpen(new OpenEvent(selection));
			}
		};
	}
	protected IQueryListener createQueryListener() {
		return new IQueryListener() {
			public void queryStarting(ISearchQuery query) {
			}
			public void queryRemoved(ISearchQuery query) {
			}
			public void queryFinished(ISearchQuery query) {
			}
			public void queryAdded(ISearchQuery query) {
			}
		};
	}
	public void dispose() {
		NewSearchUI.removeQueryListener();
		super.dispose();
	}
	protected void showBusyLabel(final boolean shouldShowBusy) {
		if (shouldShowBusy != ) {
			Display.getDefault().asyncExec(new Runnable() {
				public void run() {
					if (shouldShowBusy)
					else
						.showPage();
				}
			});
			 = shouldShowBusy;
		}
	}
	protected void fillToolbar(IToolBarManager tbm) {
		tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, );
		tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, );
		IActionBars actionBars = getSite().getActionBars();
		if (actionBars != null) {
			actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), );
			actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), );
		}
		tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, );
		tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, );
	}
	protected void handleOpen(OpenEvent openEvent) {
		ISelection selection = openEvent.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
			for (Iterator<?> i = structuredSelection.iterator(); i.hasNext();) {
				Object selectedObject = i.next();
				if (selectedObject instanceof ReferenceSearchViewTreeNode) {
					Object description = treeNode.getDescription();
					if (description instanceof IReferenceDescription) {
						IReferenceDescription referenceDescription = (IReferenceDescriptiondescription;
								referenceDescription.getEReference(), referenceDescription.getIndexInList(), true);
else if (description instanceof IResourceDescription) {
						.open(((IResourceDescriptiondescription).getURI(), true);
					}
				}
			}
		}
	}
	public Control getControl() {
		return ;
	}
	public void setFocus() {
		Control control = .getControl();
		if (control != null && !control.isDisposed())
			control.setFocus();
	}
	public TreeViewer getViewer() {
		return ;
	}
New to GrepCode? Check out our FAQ X