下面列出了org.eclipse.jface.viewers.ICheckStateListener#org.eclipse.jface.viewers.ISelection 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets the selected project, or null if a project is not selected. If multiple things
* are selected, only the first selected item is considered.
*
* @param selection A selection from which to get a project.
* @return The selected project, or null if a project is not selected.
*/
public static IProject getSelectedProject(ISelection selection) {
IProject project = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IResource) {
project = ((IResource) (firstElement)).getProject();
}
else if (firstElement instanceof IJavaElement) {
project = ((IJavaElement) (firstElement)).getResource().getProject();
}
}
return project;
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part != this.view.fEditor && part instanceof ITextEditor && (LapseView.getJavaInput((ITextEditor) part) != null))
{
try {
if(LapseView.TRACE) {
System.out.println("In selectionChanged: setting the input");
}
this.view.setInput((ITextEditor) part);
if(this.view.fEditor == null) {
throw new RuntimeException("Couldn't set the editor properly");
}
} catch (CoreException e) {
JavaPlugin.logErrorMessage("Caught exception: " + e.toString());
return;
}
}
}
protected void handleSelectionChanged ( final ISelection sel )
{
if ( sel == null || sel.isEmpty () )
{
return;
}
if ( ! ( sel instanceof IStructuredSelection ) )
{
return;
}
final Object o = ( (IStructuredSelection)sel ).getFirstElement ();
if ( ! ( o instanceof ChartViewer ) )
{
return;
}
setChartViewer ( (ChartViewer)o );
}
@Override
public void selectionChanged(SelectionChangedEvent event) {
Object source = event.getSource();
if (source == mFilterList) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
if (selectedElement instanceof IFilter) {
IFilter filterDef = (IFilter) selectedElement;
mTxtFilterDescription.setText(filterDef.getDescription());
// activate edit button
mBtnEditFilter.setEnabled(PluginFilterEditors.hasEditor(filterDef));
}
}
}
}
/**
* @generated
*/
private ISelection getNavigatorSelection() {
IDiagramDocument document = getDiagramDocument();
if (document == null) {
return StructuredSelection.EMPTY;
}
Diagram diagram = document.getDiagram();
if (diagram == null || diagram.eResource() == null) {
return StructuredSelection.EMPTY;
}
IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
if (file != null) {
CrossflowNavigatorItem item = new CrossflowNavigatorItem(diagram, file, false);
return new StructuredSelection(item);
}
return StructuredSelection.EMPTY;
}
private void makeActions() {
actionUpdate = new Action() {
@Override
public void run() {
updateComparison();
}
};
actionUpdate.setText("Update");
actionUpdate.setToolTipText(
"Recompute comparison for all API project and their implementation projects in the workspace.");
// action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
// getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
actionOpenInEditor = new Action() {
@Override
public void run() {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof ProjectComparisonEntry)
showInEditor((ProjectComparisonEntry) obj, true, true);
}
};
actionOpenInEditor.setText("Open in Editor");
actionOpenInEditor.setToolTipText(
"Open the currently selected API element and its implementations in N4JS editors.");
}
private void setSelection ( final ISelection selection )
{
this.entries = new LinkedList<ListEntry> ();
if ( selection instanceof IStructuredSelection )
{
final Iterator<?> i = ( (IStructuredSelection)selection ).iterator ();
while ( i.hasNext () )
{
final Object o = i.next ();
if ( o instanceof ListEntry )
{
this.entries.add ( (ListEntry)o );
}
}
}
}
/**
* @generated
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.size() != 1) {
return null;
}
if (structuredSelection.getFirstElement() instanceof EditPart
&& ((EditPart) structuredSelection.getFirstElement()).getModel() instanceof View) {
EObject modelElement = ((View) ((EditPart) structuredSelection.getFirstElement()).getModel())
.getElement();
List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
for (Iterator it = editPolicies.iterator(); it.hasNext();) {
CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy) it.next();
nextEditPolicy.refresh();
}
}
}
return null;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
ISelection selection = window.getSelectionService().getSelection();
WizardDialog dialog =
new WizardDialog(window.getShell(), new LinkGhidraWizard(selection));
dialog.open();
return null;
}
@Override
public void launch(ISelection selection, String mode) {
IProject project = GhidraProjectUtils.getSelectedProject(selection);
if (project != null) {
launch(JavaCore.create(project), mode);
}
}
/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection<IAction> generateCreateChildActions ( Collection<?> descriptors, ISelection selection )
{
Collection<IAction> actions = new ArrayList<IAction> ();
if ( descriptors != null )
{
for ( Object descriptor : descriptors )
{
actions.add ( new CreateChildAction ( activeEditorPart, selection, descriptor ) );
}
}
return actions;
}
/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateSiblingAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection<IAction> generateCreateSiblingActions ( Collection<?> descriptors, ISelection selection )
{
Collection<IAction> actions = new ArrayList<IAction> ();
if ( descriptors != null )
{
for ( Object descriptor : descriptors )
{
actions.add ( new CreateSiblingAction ( activeEditorPart, selection, descriptor ) );
}
}
return actions;
}
protected void addSelectionListener ()
{
if ( this.selectionListener == null )
{
getViewSite ().getWorkbenchWindow ().getSelectionService ().addSelectionListener ( this.selectionListener = new ISelectionListener () {
public void selectionChanged ( final IWorkbenchPart part, final ISelection selection )
{
AbstractQueryViewPart.this.setSelection ( selection );
}
} );
}
}
private void addLogFileSubMenu(IMenuManager menu) {
final ICommonViewerSite viewSite = getActionSite().getViewSite();
ISelection selection = viewSite.getSelectionProvider().getSelection();
if (!(selection instanceof IStructuredSelection)) {
return;
}
IStructuredSelection sel = (IStructuredSelection) selection;
if (sel.size() == 1) {
Object obj = sel.getFirstElement();
if (obj instanceof CodewindEclipseApplication) {
final CodewindEclipseApplication app = (CodewindEclipseApplication) obj;
if (app.isAvailable() && app.getLogInfos() != null && !app.getLogInfos().isEmpty()) {
MenuManager menuMgr = new MenuManager(Messages.ShowLogFilesMenu, "ShowLogFiles");
showAllLogsAction.setApp(app);
menuMgr.add(showAllLogsAction);
hideAllLogsAction.setApp(app);
menuMgr.add(hideAllLogsAction);
menuMgr.add(new Separator());
for (ProjectLogInfo logInfo : app.getLogInfos()) {
menuMgr.add(new LogFileAction(app, logInfo, viewSite));
}
menu.add(menuMgr);
}
}
}
}
/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection<IAction> generateCreateChildActions(Collection<?> descriptors, ISelection selection) {
Collection<IAction> actions = new ArrayList<IAction>();
if (descriptors != null) {
for (Object descriptor : descriptors) {
actions.add(new CreateChildAction(activeEditorPart, selection, descriptor));
}
}
return actions;
}
/**
* This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection.
* Calling this result will notify the listeners.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setSelection ( ISelection selection )
{
editorSelection = selection;
for ( ISelectionChangedListener listener : selectionChangedListeners )
{
listener.selectionChanged ( new SelectionChangedEvent ( this, selection ) );
}
setStatusLineManager ( selection );
}
@Override
public void selectionChanged ( final IAction action, final ISelection selection )
{
if ( selection == null )
{
return;
}
if ( ! ( selection instanceof IStructuredSelection ) )
{
return;
}
this.selection = (IStructuredSelection)selection;
}
/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection<IAction> generateCreateChildActions ( Collection<?> descriptors, ISelection selection )
{
Collection<IAction> actions = new ArrayList<IAction> ();
if ( descriptors != null )
{
for ( Object descriptor : descriptors )
{
actions.add ( new CreateChildAction ( activeEditorPart, selection, descriptor ) );
}
}
return actions;
}
@Override
public void launch(ISelection selection, String mode) {
IProject selected = null;
if (selection instanceof StructuredSelection) {
Object firstElement = ((StructuredSelection) selection).getFirstElement();
if (firstElement instanceof IResource) {
selected = ((IResource) firstElement).getProject();
}
}
launchProject(selected, mode);
}
@Override
public void launch(ISelection selection, String mode) {
if (selection instanceof StructuredSelection) {
Object firstElement = ((StructuredSelection) selection).getFirstElement();
if (firstElement instanceof IFile) {
IFile file = (IFile) firstElement;
launch(file.getLocation(), null);
}
}
}
public static <T> T first ( final ISelection selection, final Class<T> clazz )
{
final Iterator<T> i = iterator ( selection, clazz );
if ( i.hasNext () )
{
return i.next ();
}
return null;
}
/**
* This method gets the project that is currently selected.
*
* @return Currently selected project.
*/
public static IProject getCurrentlySelectedIProject() {
ISelection curSel = getCurrentSelection();
Object resource = null;
if ((resource = getIResourceFromSelection(curSel)) != null) {
return ((IProject) resource).getProject();
} else {
return getJavaProjectFromSelection(curSel);
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setStatusLineManager ( ISelection selection )
{
IStatusLineManager statusLineManager = currentViewer != null && currentViewer == contentOutlineViewer ? contentOutlineStatusLineManager : getActionBars ().getStatusLineManager ();
if ( statusLineManager != null )
{
if ( selection instanceof IStructuredSelection )
{
Collection<?> collection = ( (IStructuredSelection)selection ).toList ();
switch ( collection.size () )
{
case 0:
{
statusLineManager.setMessage ( getString ( "_UI_NoObjectSelected" ) ); //$NON-NLS-1$
break;
}
case 1:
{
String text = new AdapterFactoryItemDelegator ( adapterFactory ).getText ( collection.iterator ().next () );
statusLineManager.setMessage ( getString ( "_UI_SingleObjectSelected", text ) ); //$NON-NLS-1$
break;
}
default:
{
statusLineManager.setMessage ( getString ( "_UI_MultiObjectSelected", Integer.toString ( collection.size () ) ) ); //$NON-NLS-1$
break;
}
}
}
else
{
statusLineManager.setMessage ( "" ); //$NON-NLS-1$
}
}
}
/**
* This deals with how we want selection in the outliner to affect the other views.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void handleContentOutlineSelection ( ISelection selection )
{
if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
{
Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
if ( selectedElements.hasNext () )
{
// Get the first selected element.
//
Object selectedElement = selectedElements.next ();
// If it's the selection viewer, then we want it to select the same selection as this selection.
//
if ( currentViewerPane.getViewer () == selectionViewer )
{
ArrayList<Object> selectionList = new ArrayList<Object> ();
selectionList.add ( selectedElement );
while ( selectedElements.hasNext () )
{
selectionList.add ( selectedElements.next () );
}
// Set the selection to the widget.
//
selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
}
else
{
// Set the input to the widget.
//
if ( currentViewerPane.getViewer ().getInput () != selectedElement )
{
currentViewerPane.getViewer ().setInput ( selectedElement );
currentViewerPane.setTitle ( selectedElement );
}
}
}
}
}
@Override
public void launch ( final ISelection selection, final String mode )
{
final IResource resource = SelectionHelper.first ( selection, IResource.class );
if ( resource != null )
{
performLanuch ( resource, mode );
}
}
protected void attachSelectionService ()
{
getViewSite ().getWorkbenchWindow ().getSelectionService ().addPostSelectionListener ( new ISelectionListener () {
@Override
public void selectionChanged ( final IWorkbenchPart part, final ISelection selection )
{
handleSelectionChanged ( selection );
}
} );
handleSelectionChanged ( getViewSite ().getWorkbenchWindow ().getSelectionService ().getSelection () );
}
protected synchronized void setSelection ( final ISelection selection )
{
final BrowserEntryBean browserEntry = SelectionHelper.first ( selection, BrowserEntryBean.class );
if ( browserEntry != this.entry && browserEntry != null && isSupported ( browserEntry ) )
{
clear ();
if ( browserEntry != null )
{
setEntry ( browserEntry );
}
}
}
public static <T> List<T> list ( final ISelection selection, final Class<T> clazz )
{
final List<T> result = new LinkedList<T> ();
if ( selection instanceof IStructuredSelection )
{
final Iterator<?> i = ( (IStructuredSelection)selection ).iterator ();
while ( i.hasNext () )
{
final Object o = i.next ();
if ( o == null )
{
continue;
}
if ( clazz.isAssignableFrom ( o.getClass () ) )
{
result.add ( clazz.cast ( o ) );
}
else
{
final T ro = AdapterHelper.adapt ( o, clazz );
if ( ro != null )
{
result.add ( ro );
}
}
}
}
return result;
}
/**
* This generates a {@link org.eclipse.emf.edit.ui.action.CreateSiblingAction} for each object in <code>descriptors</code>,
* and returns the collection of these actions.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection<IAction> generateCreateSiblingActions ( Collection<?> descriptors, ISelection selection )
{
Collection<IAction> actions = new ArrayList<IAction> ();
if ( descriptors != null )
{
for ( Object descriptor : descriptors )
{
actions.add ( new CreateSiblingAction ( activeEditorPart, selection, descriptor ) );
}
}
return actions;
}
/**
* This deals with how we want selection in the outliner to affect the other views.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void handleContentOutlineSelection ( ISelection selection )
{
if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
{
Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
if ( selectedElements.hasNext () )
{
// Get the first selected element.
//
Object selectedElement = selectedElements.next ();
// If it's the selection viewer, then we want it to select the same selection as this selection.
//
if ( currentViewerPane.getViewer () == selectionViewer )
{
ArrayList<Object> selectionList = new ArrayList<Object> ();
selectionList.add ( selectedElement );
while ( selectedElements.hasNext () )
{
selectionList.add ( selectedElements.next () );
}
// Set the selection to the widget.
//
selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
}
else
{
// Set the input to the widget.
//
if ( currentViewerPane.getViewer ().getInput () != selectedElement )
{
currentViewerPane.getViewer ().setInput ( selectedElement );
currentViewerPane.setTitle ( selectedElement );
}
}
}
}
}