mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Call Hierarchy: added context menu
This commit is contained in:
parent
8cdf94585a
commit
5c2049ef4f
7 changed files with 226 additions and 50 deletions
|
@ -26,6 +26,8 @@ public class CHMessages extends NLS {
|
||||||
public static String CHViewPart_HideMacros_tooltip;
|
public static String CHViewPart_HideMacros_tooltip;
|
||||||
public static String CHViewPart_NextReference_label;
|
public static String CHViewPart_NextReference_label;
|
||||||
public static String CHViewPart_NextReference_tooltip;
|
public static String CHViewPart_NextReference_tooltip;
|
||||||
|
public static String CHViewPart_Open_label;
|
||||||
|
public static String CHViewPart_Open_tooltip;
|
||||||
public static String CHViewPart_OpenReference_label;
|
public static String CHViewPart_OpenReference_label;
|
||||||
public static String CHViewPart_PreviousReference_label;
|
public static String CHViewPart_PreviousReference_label;
|
||||||
public static String CHViewPart_PreviousReference_tooltip;
|
public static String CHViewPart_PreviousReference_tooltip;
|
||||||
|
@ -37,6 +39,8 @@ public class CHMessages extends NLS {
|
||||||
public static String CHViewPart_ShowCallers_tooltip;
|
public static String CHViewPart_ShowCallers_tooltip;
|
||||||
public static String CHViewPart_ShowFiles_label;
|
public static String CHViewPart_ShowFiles_label;
|
||||||
public static String CHViewPart_ShowFiles_tooltip;
|
public static String CHViewPart_ShowFiles_tooltip;
|
||||||
|
public static String CHViewPart_ShowReference_label;
|
||||||
|
public static String CHViewPart_ShowReference_tooltip;
|
||||||
public static String CHViewPart_Title_callees;
|
public static String CHViewPart_Title_callees;
|
||||||
public static String CHViewPart_Title_callers;
|
public static String CHViewPart_Title_callers;
|
||||||
public static String CHViewPart_WorkspaceScope;
|
public static String CHViewPart_WorkspaceScope;
|
||||||
|
|
|
@ -3,6 +3,8 @@ CHViewPart_ShowCallers_label=Show Callers
|
||||||
CHViewPart_ShowCallers_tooltip=Show Callers
|
CHViewPart_ShowCallers_tooltip=Show Callers
|
||||||
CHViewPart_ShowCallees_label=Show Callees
|
CHViewPart_ShowCallees_label=Show Callees
|
||||||
CHViewPart_ShowCallees_tooltip=Show Callees
|
CHViewPart_ShowCallees_tooltip=Show Callees
|
||||||
|
CHViewPart_ShowReference_label=Show Reference
|
||||||
|
CHViewPart_ShowReference_tooltip=Show Reference
|
||||||
CHViewPart_FilterVariables_label=Filter Variables
|
CHViewPart_FilterVariables_label=Filter Variables
|
||||||
CHViewPart_FilterVariables_tooltip=Hide Variables, Constents and Enumerators
|
CHViewPart_FilterVariables_tooltip=Hide Variables, Constents and Enumerators
|
||||||
CHViewPart_HideMacros_label=Hide Macros
|
CHViewPart_HideMacros_label=Hide Macros
|
||||||
|
@ -19,6 +21,8 @@ CHViewPart_Refresh_tooltip=Refresh View Content
|
||||||
CHViewPart_WorkspaceScope=workspace
|
CHViewPart_WorkspaceScope=workspace
|
||||||
CHViewPart_Title_callers=Callers of {0} - in {1}
|
CHViewPart_Title_callers=Callers of {0} - in {1}
|
||||||
CHViewPart_Title_callees=Calls made by {0} - in {1}
|
CHViewPart_Title_callees=Calls made by {0} - in {1}
|
||||||
|
CHViewPart_Open_label=Open
|
||||||
|
CHViewPart_Open_tooltip=Open
|
||||||
CHViewPart_OpenReference_label=Open Reference
|
CHViewPart_OpenReference_label=Open Reference
|
||||||
CHHistoryDropDownAction_ClearHistory_label=Clear History
|
CHHistoryDropDownAction_ClearHistory_label=Clear History
|
||||||
CHHistoryListAction_HistoryDialog_title=Call Hierarchy History
|
CHHistoryListAction_HistoryDialog_title=Call Hierarchy History
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IMacro;
|
import org.eclipse.cdt.core.model.IMacro;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -23,7 +25,7 @@ import org.eclipse.cdt.core.model.IVariableDeclaration;
|
||||||
/**
|
/**
|
||||||
* Represents a node in the include browser
|
* Represents a node in the include browser
|
||||||
*/
|
*/
|
||||||
public class CHNode {
|
public class CHNode implements IAdaptable {
|
||||||
private CHNode fParent;
|
private CHNode fParent;
|
||||||
private ICElement fRepresentedDecl;
|
private ICElement fRepresentedDecl;
|
||||||
private ITranslationUnit fFileOfReferences;
|
private ITranslationUnit fFileOfReferences;
|
||||||
|
@ -138,4 +140,11 @@ public class CHNode {
|
||||||
public ITranslationUnit getFileOfReferences() {
|
public ITranslationUnit getFileOfReferences() {
|
||||||
return fFileOfReferences;
|
return fFileOfReferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getAdapter(Class adapter) {
|
||||||
|
if (adapter.isAssignableFrom(ICElement.class)) {
|
||||||
|
return getRepresentedDeclaration();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
import org.eclipse.jface.viewers.ViewerComparator;
|
import org.eclipse.jface.viewers.ViewerComparator;
|
||||||
import org.eclipse.jface.viewers.ViewerFilter;
|
import org.eclipse.jface.viewers.ViewerFilter;
|
||||||
import org.eclipse.search.ui.IContextMenuConstants;
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.dnd.DND;
|
import org.eclipse.swt.dnd.DND;
|
||||||
import org.eclipse.swt.dnd.DropTarget;
|
import org.eclipse.swt.dnd.DropTarget;
|
||||||
|
@ -59,11 +58,16 @@ import org.eclipse.ui.part.ViewPart;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
|
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||||
|
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.AdaptingSelectionProvider;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener;
|
import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.ExtendedTreeViewer;
|
import org.eclipse.cdt.internal.ui.viewsupport.ExtendedTreeViewer;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.TreeNavigator;
|
import org.eclipse.cdt.internal.ui.viewsupport.TreeNavigator;
|
||||||
|
@ -114,6 +118,13 @@ public class CHViewPart extends ViewPart {
|
||||||
private Action fPreviousAction;
|
private Action fPreviousAction;
|
||||||
private Action fRefreshAction;
|
private Action fRefreshAction;
|
||||||
private Action fHistoryAction;
|
private Action fHistoryAction;
|
||||||
|
private Action fShowReference;
|
||||||
|
|
||||||
|
// action groups
|
||||||
|
private OpenViewActionGroup fOpenViewActionGroup;
|
||||||
|
private SelectionSearchGroup fSelectionSearchGroup;
|
||||||
|
private CRefactoringActionGroup fRefactoringActionGroup;
|
||||||
|
private Action fOpenElement;
|
||||||
|
|
||||||
|
|
||||||
public void setFocus() {
|
public void setFocus() {
|
||||||
|
@ -161,16 +172,33 @@ public class CHViewPart extends ViewPart {
|
||||||
createInfoPage();
|
createInfoPage();
|
||||||
createViewerPage();
|
createViewerPage();
|
||||||
|
|
||||||
|
getSite().setSelectionProvider(new AdaptingSelectionProvider(ICElement.class, fTreeViewer));
|
||||||
|
|
||||||
initDragAndDrop();
|
initDragAndDrop();
|
||||||
createActions();
|
createActions();
|
||||||
createContextMenu();
|
createContextMenu();
|
||||||
|
|
||||||
getSite().setSelectionProvider(fTreeViewer);
|
|
||||||
setMessage(CHMessages.CHViewPart_emptyPageMessage);
|
setMessage(CHMessages.CHViewPart_emptyPageMessage);
|
||||||
|
|
||||||
initializeActionStates();
|
initializeActionStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
if (fOpenViewActionGroup != null) {
|
||||||
|
fOpenViewActionGroup.dispose();
|
||||||
|
fOpenViewActionGroup= null;
|
||||||
|
}
|
||||||
|
if (fSelectionSearchGroup != null) {
|
||||||
|
fSelectionSearchGroup.dispose();
|
||||||
|
fSelectionSearchGroup= null;
|
||||||
|
}
|
||||||
|
if (fRefactoringActionGroup != null) {
|
||||||
|
fRefactoringActionGroup.dispose();
|
||||||
|
fRefactoringActionGroup= null;
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeActionStates() {
|
private void initializeActionStates() {
|
||||||
boolean referencedBy= true;
|
boolean referencedBy= true;
|
||||||
boolean filterVariables= false;
|
boolean filterVariables= false;
|
||||||
|
@ -236,9 +264,7 @@ public class CHViewPart extends ViewPart {
|
||||||
fTreeViewer.setAutoExpandLevel(2);
|
fTreeViewer.setAutoExpandLevel(2);
|
||||||
fTreeViewer.addOpenListener(new IOpenListener() {
|
fTreeViewer.addOpenListener(new IOpenListener() {
|
||||||
public void open(OpenEvent event) {
|
public void open(OpenEvent event) {
|
||||||
fNavigationDetail= 0;
|
onShowSelectedReference(event.getSelection());
|
||||||
fNavigationNode= selectionToNode(event.getSelection());
|
|
||||||
onShowReference();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -263,6 +289,11 @@ public class CHViewPart extends ViewPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createActions() {
|
private void createActions() {
|
||||||
|
// action gruops
|
||||||
|
fOpenViewActionGroup= new OpenViewActionGroup(this);
|
||||||
|
fSelectionSearchGroup= new SelectionSearchGroup(getSite());
|
||||||
|
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||||
|
|
||||||
WorkingSetFilterUI wsFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
WorkingSetFilterUI wsFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
||||||
protected void onWorkingSetChange() {
|
protected void onWorkingSetChange() {
|
||||||
updateWorkingSetFilter(this);
|
updateWorkingSetFilter(this);
|
||||||
|
@ -364,6 +395,19 @@ public class CHViewPart extends ViewPart {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fShowReference= new Action(CHMessages.CHViewPart_ShowReference_label) {
|
||||||
|
public void run() {
|
||||||
|
onShowSelectedReference(fTreeViewer.getSelection());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fShowReference.setToolTipText(CHMessages.CHViewPart_ShowReference_tooltip);
|
||||||
|
fOpenElement= new Action(CHMessages.CHViewPart_Open_label) {
|
||||||
|
public void run() {
|
||||||
|
onOpenElement(fTreeViewer.getSelection());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fOpenElement.setToolTipText(CHMessages.CHViewPart_Open_tooltip);
|
||||||
|
|
||||||
fShowFilesInLabelsAction= new Action(CHMessages.CHViewPart_ShowFiles_label, IAction.AS_CHECK_BOX) {
|
fShowFilesInLabelsAction= new Action(CHMessages.CHViewPart_ShowFiles_label, IAction.AS_CHECK_BOX) {
|
||||||
public void run() {
|
public void run() {
|
||||||
onShowFilesInLabels(isChecked());
|
onShowFilesInLabels(isChecked());
|
||||||
|
@ -457,15 +501,44 @@ public class CHViewPart extends ViewPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
fNavigationNode= (CHNode) selectedItem.getData();
|
||||||
|
if (!forward && fNavigationNode != null) {
|
||||||
|
fNavigationDetail= Math.max(0, fNavigationNode.getReferenceCount()-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fNavigationDetail= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onShowSelectedReference(ISelection selection) {
|
||||||
|
fNavigationDetail= 0;
|
||||||
|
fNavigationNode= selectionToNode(selection);
|
||||||
|
showReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onOpenElement(ISelection selection) {
|
||||||
|
CHNode node= selectionToNode(selection);
|
||||||
|
if (node != null) {
|
||||||
|
ICElement elem= node.getRepresentedDeclaration();
|
||||||
|
if (elem != null) {
|
||||||
|
IWorkbenchPage page= getSite().getPage();
|
||||||
|
try {
|
||||||
|
EditorOpener.open(page, elem);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void onNextOrPrevious(boolean forward) {
|
protected void onNextOrPrevious(boolean forward) {
|
||||||
setNextNode(forward);
|
setNextNode(forward);
|
||||||
if (fNavigationNode != null) {
|
if (fNavigationNode != null) {
|
||||||
StructuredSelection sel= new StructuredSelection(fNavigationNode);
|
StructuredSelection sel= new StructuredSelection(fNavigationNode);
|
||||||
fTreeViewer.setSelection(sel);
|
fTreeViewer.setSelection(sel);
|
||||||
onShowReference();
|
showReference();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,42 +637,30 @@ public class CHViewPart extends ViewPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onContextMenuAboutToShow(IMenuManager m) {
|
protected void onContextMenuAboutToShow(IMenuManager menu) {
|
||||||
// final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
|
CUIPlugin.createStandardGroups(menu);
|
||||||
// final CHNode node= IBConversions.selectionToNode(selection);
|
|
||||||
//
|
|
||||||
// if (node != null) {
|
|
||||||
// // open reference
|
|
||||||
// if (node.getParent() != null && node.getDirectiveFile() != null) {
|
|
||||||
// m.add(new Action(CHMessages.CHViewPart_OpenReference_label) {
|
|
||||||
// public void run() {
|
|
||||||
// onShowReference(selection);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// support for opening the function/method
|
CHNode node= selectionToNode(fTreeViewer.getSelection());
|
||||||
// final ITranslationUnit tu= node.getRepresentedTranslationUnit();
|
if (node != null) {
|
||||||
// if (tu != null) {
|
if (node.getReferenceCount() > 0) {
|
||||||
// // open
|
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fShowReference);
|
||||||
// OpenFileAction ofa= new OpenFileAction(page);
|
}
|
||||||
// ofa.selectionChanged(selection);
|
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenElement);
|
||||||
// m.add(ofa);
|
}
|
||||||
//
|
|
||||||
// // open with
|
// action groups
|
||||||
// // keep the menu shorter, no open with support
|
ISelection selection = getSite().getSelectionProvider().getSelection();
|
||||||
//// final IResource r= tu.getResource();
|
if (OpenViewActionGroup.canActionBeAdded(selection)){
|
||||||
//// if (r != null) {
|
fOpenViewActionGroup.fillContextMenu(menu);
|
||||||
//// IMenuManager submenu= new MenuManager(IBMessages.IBViewPart_OpenWithMenu_label);
|
}
|
||||||
//// submenu.add(new OpenWithMenu(page, r));
|
|
||||||
//// m.add(submenu);
|
if (SelectionSearchGroup.canActionBeAdded(selection)){
|
||||||
//// }
|
fSelectionSearchGroup.fillContextMenu(menu);
|
||||||
// }
|
}
|
||||||
// }
|
fRefactoringActionGroup.fillContextMenu(menu);
|
||||||
m.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onShowReference() {
|
private void showReference() {
|
||||||
if (fNavigationNode != null) {
|
if (fNavigationNode != null) {
|
||||||
ITranslationUnit file= fNavigationNode.getFileOfReferences();
|
ITranslationUnit file= fNavigationNode.getFileOfReferences();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* QNX Software System
|
* QNX Software System
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
|
@ -234,9 +235,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
||||||
|
|
||||||
ISelection selection= getSelection();
|
ISelection selection= getSelection();
|
||||||
if (OpenViewActionGroup.canActionBeAdded(selection)){
|
if (OpenViewActionGroup.canActionBeAdded(selection)){
|
||||||
fOpenViewActionGroup.setContext(new ActionContext(selection));
|
|
||||||
fOpenViewActionGroup.fillContextMenu(menu);
|
fOpenViewActionGroup.fillContextMenu(menu);
|
||||||
fOpenViewActionGroup.setContext(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OpenIncludeAction.canActionBeAdded(selection)) {
|
if (OpenIncludeAction.canActionBeAdded(selection)) {
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2006 Wind River Systems, Inc. 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
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.core.runtime.ListenerList;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||||
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||||
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A selection provider that adapts the elements of structured selections
|
||||||
|
* to a requested type.
|
||||||
|
* @author markus.schorn@windriver.com
|
||||||
|
*/
|
||||||
|
public class AdaptingSelectionProvider implements ISelectionProvider, ISelectionChangedListener {
|
||||||
|
|
||||||
|
private Class fTargetType;
|
||||||
|
private ListenerList fListenerList;
|
||||||
|
private ISelectionProvider fProvider;
|
||||||
|
|
||||||
|
public AdaptingSelectionProvider(Class targetType, ISelectionProvider provider) {
|
||||||
|
fProvider= provider;
|
||||||
|
fTargetType= targetType;
|
||||||
|
fListenerList= new ListenerList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISelection convertSelection(ISelection selection) {
|
||||||
|
if (selection != null) {
|
||||||
|
if (selection instanceof IStructuredSelection) {
|
||||||
|
IStructuredSelection ss= (IStructuredSelection) selection;
|
||||||
|
ArrayList adapted= new ArrayList();
|
||||||
|
for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
|
||||||
|
Object elem= adaptElem(iter.next());
|
||||||
|
if (elem != null) {
|
||||||
|
adapted.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new StructuredSelection(adapted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object adaptElem(Object elem) {
|
||||||
|
if (fTargetType.isInstance(elem)) {
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
if (elem instanceof IAdaptable) {
|
||||||
|
return ((IAdaptable) elem).getAdapter(fTargetType);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSelectionChangedListener(ISelectionChangedListener listener) {
|
||||||
|
if (fListenerList.isEmpty()) {
|
||||||
|
fProvider.addSelectionChangedListener(this);
|
||||||
|
}
|
||||||
|
fListenerList.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISelection getSelection() {
|
||||||
|
return convertSelection(fProvider.getSelection());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
|
||||||
|
fListenerList.remove(listener);
|
||||||
|
if (fListenerList.isEmpty()) {
|
||||||
|
fProvider.removeSelectionChangedListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelection(ISelection selection) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
|
SelectionChangedEvent event2= new SelectionChangedEvent(this, convertSelection(event.getSelection()));
|
||||||
|
Object[] listeners= fListenerList.getListeners();
|
||||||
|
for (int i = 0; i < listeners.length; i++) {
|
||||||
|
ISelectionChangedListener l= (ISelectionChangedListener) listeners[i];
|
||||||
|
l.selectionChanged(event2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.IViewPart;
|
import org.eclipse.ui.IViewPart;
|
||||||
import org.eclipse.ui.IWorkbenchSite;
|
import org.eclipse.ui.IWorkbenchSite;
|
||||||
import org.eclipse.ui.actions.ActionContext;
|
|
||||||
import org.eclipse.ui.actions.ActionFactory;
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
import org.eclipse.ui.actions.ActionGroup;
|
import org.eclipse.ui.actions.ActionGroup;
|
||||||
import org.eclipse.ui.dialogs.PropertyDialogAction;
|
import org.eclipse.ui.dialogs.PropertyDialogAction;
|
||||||
|
@ -195,11 +194,11 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
private IStructuredSelection getStructuredSelection() {
|
private IStructuredSelection getStructuredSelection() {
|
||||||
ActionContext context= getContext();
|
if (fSite != null) {
|
||||||
if (context != null) {
|
ISelection selection= fSite.getSelectionProvider().getSelection();
|
||||||
ISelection selection= getContext().getSelection();
|
if (selection instanceof IStructuredSelection) {
|
||||||
if (selection instanceof IStructuredSelection)
|
|
||||||
return (IStructuredSelection)selection;
|
return (IStructuredSelection)selection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue