From b1ee9d479fde08fa0a039e1432919b3c2ed769e2 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 15 Jul 2004 18:27:15 +0000 Subject: [PATCH] 2004-07-15 Chris Wiebe Initial draft for the type hierarchy view. * browser/* * icons/* --- core/org.eclipse.cdt.ui/ChangeLog | 6 + .../ui/browser/cbrowsing/CBrowsingPart.java | 5 +- .../cbrowsing/MembersViewContentProvider.java | 3 +- .../EnableMemberFilterAction.java | 51 + .../typehierarchy/FocusOnSelectionAction.java | 69 + .../typehierarchy/FocusOnTypeAction.java | 139 ++ .../typehierarchy/FocusOnTypeDialog.java | 39 + .../typehierarchy/HierarchyLabelProvider.java | 208 +++ .../typehierarchy/HierarchyViewerSorter.java | 184 ++ .../browser/typehierarchy/HistoryAction.java | 58 + .../typehierarchy/HistoryDropDownAction.java | 94 + .../typehierarchy/HistoryListAction.java | 184 ++ .../ITypeHierarchyLifeCycleListener.java | 26 + .../typehierarchy/ITypeHierarchyViewPart.java | 69 + .../typehierarchy/MethodsContentProvider.java | 134 ++ .../typehierarchy/MethodsLabelProvider.java | 138 ++ .../browser/typehierarchy/MethodsViewer.java | 302 ++++ .../OpenTypeHierarchyAction.java | 251 +++ .../typehierarchy/OpenTypeHierarchyUtil.java | 180 ++ .../OpenTypeInHierarchyAction.java | 130 ++ .../SelectionProviderMediator.java | 200 ++ .../ShowInheritedMembersAction.java | 57 + .../ShowQualifiedTypeNamesAction.java | 51 + .../SortByDefiningTypeAction.java | 56 + .../typehierarchy/SubTypeHierarchyViewer.java | 94 + .../SuperTypeHierarchyViewer.java | 80 + .../typehierarchy/ToggleLinkingAction.java | 41 + .../ToggleOrientationAction.java | 72 + .../typehierarchy/ToggleViewAction.java | 63 + .../TypeHierarchyContentProvider.java | 300 +++ .../typehierarchy/TypeHierarchyLifeCycle.java | 285 +++ .../typehierarchy/TypeHierarchyMessages.java | 51 + .../TypeHierarchyMessages.properties | 17 +- .../typehierarchy/TypeHierarchyViewPart.java | 1601 +++++++++++++++++ .../typehierarchy/TypeHierarchyViewer.java | 186 ++ .../full/clcl16/definingtype_sort_co.gif | Bin 0 -> 323 bytes .../icons/full/clcl16/history_list.gif | Bin 0 -> 586 bytes .../icons/full/clcl16/impl_co.gif | Bin 0 -> 145 bytes .../icons/full/clcl16/inher_co.gif | Bin 0 -> 200 bytes .../icons/full/clcl16/sub_co.gif | Bin 0 -> 209 bytes .../icons/full/clcl16/super_co.gif | Bin 0 -> 208 bytes .../icons/full/clcl16/th_automatic.gif | Bin 0 -> 358 bytes .../icons/full/clcl16/th_horizontal.gif | Bin 0 -> 374 bytes .../icons/full/clcl16/th_showqualified.gif | Bin 0 -> 222 bytes .../icons/full/clcl16/th_single.gif | Bin 0 -> 370 bytes .../icons/full/clcl16/th_vertical.gif | Bin 0 -> 352 bytes .../full/dlcl16/definingtype_sort_co.gif | Bin 0 -> 220 bytes .../icons/full/dlcl16/history_list.gif | Bin 0 -> 225 bytes .../icons/full/dlcl16/impl_co.gif | Bin 0 -> 143 bytes .../icons/full/dlcl16/inher_co.gif | Bin 0 -> 199 bytes .../icons/full/dlcl16/sub_co.gif | Bin 0 -> 209 bytes .../icons/full/dlcl16/super_co.gif | Bin 0 -> 206 bytes .../icons/full/dlcl16/th_automatic.gif | Bin 0 -> 338 bytes .../icons/full/dlcl16/th_horizontal.gif | Bin 0 -> 245 bytes .../icons/full/dlcl16/th_showqualified.gif | Bin 0 -> 156 bytes .../icons/full/dlcl16/th_single.gif | Bin 0 -> 222 bytes .../icons/full/dlcl16/th_vertical.gif | Bin 0 -> 222 bytes .../full/elcl16/definingtype_sort_co.gif | Bin 0 -> 323 bytes .../icons/full/elcl16/history_list.gif | Bin 0 -> 586 bytes .../icons/full/elcl16/impl_co.gif | Bin 0 -> 145 bytes .../icons/full/elcl16/inher_co.gif | Bin 0 -> 200 bytes .../icons/full/elcl16/sub_co.gif | Bin 0 -> 209 bytes .../icons/full/elcl16/super_co.gif | Bin 0 -> 208 bytes .../icons/full/elcl16/th_automatic.gif | Bin 0 -> 358 bytes .../icons/full/elcl16/th_horizontal.gif | Bin 0 -> 374 bytes .../icons/full/elcl16/th_showqualified.gif | Bin 0 -> 222 bytes .../icons/full/elcl16/th_single.gif | Bin 0 -> 370 bytes .../icons/full/elcl16/th_vertical.gif | Bin 0 -> 352 bytes .../icons/full/eview16/chierch_pers.gif | Bin 0 -> 172 bytes .../icons/full/eview16/class_hi.gif | Bin 0 -> 200 bytes .../icons/full/ovr16/focus_ovr.gif | Bin 0 -> 75 bytes core/org.eclipse.cdt.ui/plugin.properties | 21 +- core/org.eclipse.cdt.ui/plugin.xml | 45 + .../actions/RenameRefactoringAction.java | 2 +- .../internal/ui/CElementImageProvider.java | 4 +- .../cdt/internal/ui/CPluginImages.java | 4 +- .../cdt/internal/ui/ICHelpContextIds.java | 24 +- .../internal/ui/IContextMenuConstants.java | 24 + .../actions/AbstractToggleLinkingAction.java | 41 + .../ui/actions/ActionMessages.properties | 18 +- .../cdt/internal/ui/actions/ActionUtil.java | 77 + .../ui/actions/CompositeActionGroup.java | 98 + .../internal/ui/actions/OpenActionUtil.java | 99 + .../internal/ui/actions/SelectAllAction.java | 48 + .../SelectionConverter.java | 119 +- .../eclipse/cdt/internal/ui/cview/CView.java | 1 + .../internal/ui/cview/GotoActionGroup.java | 1 + .../internal/ui/cview/MainActionGroup.java | 1 + .../cdt/internal/ui/cview/OpenFileGroup.java | 1 + .../ui/cview/RefactorActionGroup.java | 1 + .../ui/editor/CContentOutlinePage.java | 15 + .../cdt/internal/ui/editor/CEditor.java | 7 + .../editor/ICEditorActionDefinitionIds.java | 13 + .../internal/ui/viewsupport/MemberFilter.java | 1 + .../eclipse/cdt/ui/CElementLabelProvider.java | 25 +- .../org/eclipse/cdt/ui/CElementSorter.java | 28 +- .../src/org/eclipse/cdt/ui/CUIPlugin.java | 15 + .../eclipse/cdt/ui/PreferenceConstants.java | 28 + .../cdt/ui/actions/CdtActionConstants.java | 530 ++++++ .../ui/actions/MemberFilterActionGroup.java | 104 ++ .../eclipse/cdt/ui/actions/OpenAction.java | 208 +++ .../cdt/ui/actions/OpenViewActionGroup.java | 225 +++ .../cdt/ui/actions/ShowInCViewAction.java | 2 +- 103 files changed, 7219 insertions(+), 35 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/EnableMemberFilterAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnSelectionAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeDialog.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyLabelProvider.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyViewerSorter.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryDropDownAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryListAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyLifeCycleListener.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyViewPart.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsContentProvider.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsLabelProvider.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsViewer.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyUtil.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeInHierarchyAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SelectionProviderMediator.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowInheritedMembersAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowQualifiedTypeNamesAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SortByDefiningTypeAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SubTypeHierarchyViewer.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SuperTypeHierarchyViewer.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleLinkingAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleOrientationAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleViewAction.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyContentProvider.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyLifeCycle.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewPart.java create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewer.java create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/definingtype_sort_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/history_list.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/impl_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/inher_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/sub_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/super_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/th_automatic.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/th_horizontal.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/th_showqualified.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/th_single.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/clcl16/th_vertical.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/definingtype_sort_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/history_list.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/impl_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/inher_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/sub_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/super_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/th_automatic.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/th_horizontal.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/th_showqualified.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/th_single.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/dlcl16/th_vertical.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/definingtype_sort_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/history_list.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/impl_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/inher_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/sub_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/super_co.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/th_automatic.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/th_horizontal.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/th_showqualified.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/th_single.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/elcl16/th_vertical.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/eview16/chierch_pers.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/eview16/class_hi.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/ovr16/focus_ovr.gif create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractToggleLinkingAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionUtil.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CompositeActionGroup.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectAllAction.java rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/{cview => actions}/SelectionConverter.java (56%) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CdtActionConstants.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenViewActionGroup.java diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 15439f1e9b5..1f1d4807d0f 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,9 @@ +2004-07-15 Chris Wiebe + + Initial draft for the type hierarchy view. + * browser/* + * icons/* + 2004-07-15 Hoda Amer Fix for PR 68500: [Outline View] After doing a rename of a class, the outline viewer does not display the new name (just the old name) diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java index 89fe9b8c88e..62c0b833e0b 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.browser.AllTypesCache; import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeReference; import org.eclipse.cdt.core.browser.TypeSearchScope; +import org.eclipse.cdt.core.browser.TypeUtil; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; @@ -758,7 +759,7 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I for (int j = 0; j < enclosedTypes.length; ++j) { ITypeInfo enclosedType = enclosedTypes[j]; if (enclosedType.getResolvedReference() != null) { - ICElement typeElem = enclosedType.getCElement(); + ICElement typeElem = TypeUtil.getElementForType(enclosedType); if (typeElem != null && (typeElem.equals(cElem) || (typeElem instanceof IParent && hasChild(typeElem, cElem)))) { return namespaces[i]; } @@ -819,7 +820,7 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I for (int j = 0; j < enclosedTypes.length; ++j) { ITypeInfo enclosedType = enclosedTypes[j]; if (enclosedType.getResolvedReference() != null) { - ICElement typeElem = enclosedType.getCElement(); + ICElement typeElem = TypeUtil.getElementForType(enclosedType); if (typeElem != null && (typeElem.equals(cElem) || (typeElem instanceof IParent && hasChild(typeElem, cElem)))) { return enclosedType; } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersViewContentProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersViewContentProvider.java index c2b7ab5fde2..9509f085a40 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersViewContentProvider.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersViewContentProvider.java @@ -16,6 +16,7 @@ import java.util.Iterator; import org.eclipse.cdt.core.browser.AllTypesCache; import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeReference; +import org.eclipse.cdt.core.browser.TypeUtil; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IParent; @@ -184,7 +185,7 @@ class MembersViewContentProvider extends CBrowsingContentProvider { ICElement elem = null; if (location != null) - elem = info.getCElement(); + elem = TypeUtil.getElementForType(info); if (location == null) { // could not resolve location diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/EnableMemberFilterAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/EnableMemberFilterAction.java new file mode 100644 index 00000000000..2a03e19d74c --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/EnableMemberFilterAction.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.custom.BusyIndicator; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Action enable / disable member filtering + */ +public class EnableMemberFilterAction extends Action { + + private TypeHierarchyViewPart fView; + + public EnableMemberFilterAction(TypeHierarchyViewPart v, boolean initValue) { + super(TypeHierarchyMessages.getString("EnableMemberFilterAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("EnableMemberFilterAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("EnableMemberFilterAction.tooltip")); //$NON-NLS-1$ + + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "impl_co.gif"); //$NON-NLS-1$ + + fView= v; + setChecked(initValue); + +// WorkbenchHelp.setHelp(this, ICHelpContextIds.ENABLE_METHODFILTER_ACTION); + } + + /* + * @see Action#actionPerformed + */ + public void run() { + BusyIndicator.showWhile(fView.getSite().getShell().getDisplay(), new Runnable() { + public void run() { + fView.enableMemberFilter(isChecked()); + } + }); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnSelectionAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnSelectionAction.java new file mode 100644 index 00000000000..cc81347c05e --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnSelectionAction.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.util.SelectionUtil; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Refocuses the type hierarchy on the currently selection type. + */ +public class FocusOnSelectionAction extends Action { + + private TypeHierarchyViewPart fViewPart; + + public FocusOnSelectionAction(TypeHierarchyViewPart part) { + super(TypeHierarchyMessages.getString("FocusOnSelectionAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("FocusOnSelectionAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("FocusOnSelectionAction.tooltip")); //$NON-NLS-1$ + fViewPart= part; + + WorkbenchHelp.setHelp(this, ICHelpContextIds.FOCUS_ON_SELECTION_ACTION); + } + + private ISelection getSelection() { + ISelectionProvider provider= fViewPart.getSite().getSelectionProvider(); + if (provider != null) { + return provider.getSelection(); + } + return null; + } + + + /* + * @see Action#run + */ + public void run() { + Object element= SelectionUtil.getSingleElement(getSelection()); + if (element instanceof ICElement) { + fViewPart.setInputElement((ICElement)element); + } + } + + public boolean canActionBeAdded() { + Object element= SelectionUtil.getSingleElement(getSelection()); + if (element instanceof ICElement) { + ICElement type= (ICElement)element; + setText(TypeHierarchyMessages.getFormattedString( + "FocusOnSelectionAction.label", //$NON-NLS-1$ + CElementLabels.getTextLabel(type, 0))); + return true; + } + return false; + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeAction.java new file mode 100644 index 00000000000..38546815af0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeAction.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.cdt.core.browser.AllTypesCache; +import org.eclipse.cdt.core.browser.ITypeInfo; +import org.eclipse.cdt.core.browser.ITypeReference; +import org.eclipse.cdt.core.browser.ITypeSearchScope; +import org.eclipse.cdt.core.browser.TypeSearchScope; +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeDialog; +import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; + +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.progress.IProgressService; + +/** + * Refocuses the type hierarchy on a type selection from a all types dialog. + */ +public class FocusOnTypeAction extends Action { + + private TypeHierarchyViewPart fViewPart; + + public FocusOnTypeAction(TypeHierarchyViewPart part) { + super(TypeHierarchyMessages.getString("FocusOnTypeAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("FocusOnTypeAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("FocusOnTypeAction.tooltip")); //$NON-NLS-1$ + + fViewPart= part; + WorkbenchHelp.setHelp(this, ICHelpContextIds.FOCUS_ON_TYPE_ACTION); + } + + /* + * @see Action#run + */ + public void run() { + + final ITypeSearchScope fScope = new TypeSearchScope(true); + if (!AllTypesCache.isCacheUpToDate(fScope)) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + AllTypesCache.updateCache(fScope, monitor); + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + } + }; + + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + try { + service.busyCursorWhile(runnable); + } catch (InvocationTargetException e) { + String title = OpenTypeMessages.getString("OpenTypeAction.exception.title"); //$NON-NLS-1$ + String message = OpenTypeMessages.getString("OpenTypeAction.exception.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, title, message); + return; + } catch (InterruptedException e) { + // cancelled by user + return; + } + } + + final int[] kinds = {ICElement.C_CLASS, ICElement.C_STRUCT}; + ITypeInfo[] elements = AllTypesCache.getTypes(fScope, kinds); + if (elements.length == 0) { + String title = OpenTypeMessages.getString("OpenTypeAction.notypes.title"); //$NON-NLS-1$ + String message = OpenTypeMessages.getString("OpenTypeAction.notypes.message"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), title, message); + return; + } + + FocusOnTypeDialog dialog = new FocusOnTypeDialog(getShell()); + dialog.setElements(elements); + int result = dialog.open(); + if (result != IDialogConstants.OK_ID) + return; + + ITypeInfo info = (ITypeInfo) dialog.getFirstResult(); + if (info == null) + return; + + final ITypeInfo[] typesToResolve = new ITypeInfo[] { info }; + final ICElement[] foundElement = new ICElement[] { null }; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + foundElement[0] = TypeUtil.getElementForType(typesToResolve[0], monitor); + } + }; + + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + try { + service.busyCursorWhile(runnable); + } catch (InvocationTargetException e) { + String title = OpenTypeMessages.getString("OpenTypeAction.exception.title"); //$NON-NLS-1$ + String message = OpenTypeMessages.getString("OpenTypeAction.exception.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, title, message); + return; + } catch (InterruptedException e) { + // cancelled by user + return; + } + + if (foundElement[0] == null) { + // could not resolve location + String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$ + String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorTypeNotFound", info.getQualifiedTypeName().toString()); //$NON-NLS-1$ + MessageDialog.openError(getShell(), title, message); + } else { + fViewPart.setInputElement(foundElement[0]); + } + } + + protected Shell getShell() { + return CUIPlugin.getActiveWorkbenchShell(); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeDialog.java new file mode 100644 index 00000000000..7168bcc084a --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/FocusOnTypeDialog.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * QNX Software Systems - adapted for use in CDT + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog; +import org.eclipse.swt.widgets.Shell; + +/** + * A dialog to select a type from a list of types. The selected type will be + * opened in the editor. + */ +public class FocusOnTypeDialog extends TypeSelectionDialog { + + private static final String DIALOG_SETTINGS = FocusOnTypeDialog.class.getName(); + + private final int[] VISIBLE_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT }; + + /** + * Constructs an instance of OpenTypeDialog. + * @param parent the parent shell. + */ + public FocusOnTypeDialog(Shell parent) { + super(parent); + setTitle(TypeHierarchyMessages.getString("FocusOnTypeAction.dialog.title")); //$NON-NLS-1$ + setMessage(TypeHierarchyMessages.getString("FocusOnTypeAction.dialog.message")); //$NON-NLS-1$ + setVisibleTypes(VISIBLE_TYPES); + setDialogSettings(DIALOG_SETTINGS); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyLabelProvider.java new file mode 100644 index 00000000000..dbb587bbc79 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyLabelProvider.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.Flags; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.core.model.IStructure; +import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager; +import org.eclipse.cdt.internal.ui.CElementImageProvider; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.AppearanceAwareLabelProvider; +import org.eclipse.cdt.ui.CElementImageDescriptor; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ViewerFilter; + +/** + * Label provider for the hierarchy viewers. Types in the hierarchy that are not belonging to the + * input scope are rendered differntly. + */ +public class HierarchyLabelProvider extends StandardCElementLabelProvider // AppearanceAwareLabelProvider { +{ + private static class FocusDescriptor extends CompositeImageDescriptor { + private ImageDescriptor fBase; + public FocusDescriptor(ImageDescriptor base) { + fBase= base; + } + protected void drawCompositeImage(int width, int height) { + drawImage(getImageData(fBase), 0, 0); + drawImage(getImageData(CPluginImages.DESC_OVR_FOCUS), 0, 0); + } + + private ImageData getImageData(ImageDescriptor descriptor) { + ImageData data= descriptor.getImageData(); // see bug 51965: getImageData can return null + if (data == null) { + data= DEFAULT_IMAGE_DATA; + CUIPlugin.getDefault().logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$ + } + return data; + } + + protected Point getSize() { + return CElementImageProvider.BIG_SIZE; + } + public int hashCode() { + return fBase.hashCode(); + } + public boolean equals(Object object) { + return object != null && FocusDescriptor.class.equals(object.getClass()) && ((FocusDescriptor)object).fBase.equals(fBase); + } + } + + private Color fGrayedColor; + private Color fSpecialColor; + + private ViewerFilter fFilter; + + private TypeHierarchyLifeCycle fHierarchy; + + public HierarchyLabelProvider(TypeHierarchyLifeCycle lifeCycle) { +// super(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS); + super(); + fHierarchy= lifeCycle; + fFilter= null; + } + + + /** + * @return Returns the filter. + */ + public ViewerFilter getFilter() { + return fFilter; + } + + /** + * @param filter The filter to set. + */ + public void setFilter(ViewerFilter filter) { + fFilter= filter; + } + + protected boolean isDifferentScope(ICElement type) { + if (fFilter != null && !fFilter.select(null, null, type)) { + return true; + } + + ICElement input= fHierarchy.getInputElement(); + if (input == null || TypeUtil.isClassOrStruct(input)) { + return false; + } + + ICElement parent= type.getAncestor(input.getElementType()); + if (input.getElementType() == ICElement.C_CCONTAINER) { + if (parent == null || parent.getElementName().equals(input.getElementName())) { + return false; + } + } else if (input.equals(parent)) { + return false; + } + return true; + } + + /* (non-Javadoc) + * @see ILabelProvider#getText + */ + public String getText(Object element) { + String text= super.getText(element); +// return decorateText(text, element); + return text; + } + + + /* (non-Javadoc) + * @see ILabelProvider#getImage + */ + public Image getImage(Object element) { +// return super.getImage(element); + Image result= null; + if (element instanceof ICElement) { + ImageDescriptor desc= getTypeImageDescriptor((ICElement) element); + if (desc != null) { + if (element.equals(fHierarchy.getInputElement())) { + desc= new FocusDescriptor(desc); + } + result= CUIPlugin.getImageDescriptorRegistry().get(desc); + } + } else { + result= fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element)); + } + return decorateImage(result, element); + } + + private ImageDescriptor getTypeImageDescriptor(ICElement type) { + ITypeHierarchy hierarchy= fHierarchy.getHierarchy(); + if (hierarchy == null) { + return new CElementImageDescriptor(CPluginImages.DESC_OBJS_CLASS, 0, CElementImageProvider.BIG_SIZE); + } + + ImageDescriptor desc; + if (isDifferentScope(type)) { + desc = fImageLabelProvider.getClassImageDescriptor(); + } else { + desc= fImageLabelProvider.getBaseImageDescriptor(type, 0); + } + + int adornmentFlags= 0; + if (type instanceof IMethodDeclaration) { + IMethodDeclaration method = (IMethodDeclaration) type; + try { + if (method.isStatic()) + adornmentFlags |= CElementImageDescriptor.STATIC; +// if (method.isVirtual()) +// adornmentFlags |= CElementImageDescriptor.VIRTUAL; + } catch (CModelException e) { + } + } + + if (type instanceof IStructure) { +// hierarchy.getSupertypes(type); +// TypeCacheManager.getInstance().getCache(type.getCProject().getProject()).getSupertypeAccess(); + } + + return new CElementImageDescriptor(desc, adornmentFlags, CElementImageProvider.BIG_SIZE); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) + */ + public Color getForeground(Object element) { + if (element instanceof IMethod) { + if (fSpecialColor == null) { + fSpecialColor= Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE); + } + return fSpecialColor; + } else if (element instanceof ICElement && isDifferentScope((ICElement) element)) { + if (fGrayedColor == null) { + fGrayedColor= Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); + } + return fGrayedColor; + } + return null; + } + + + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyViewerSorter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyViewerSorter.java new file mode 100644 index 00000000000..d0333380359 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HierarchyViewerSorter.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.Flags; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.internal.corext.util.CModelUtil; +import org.eclipse.cdt.ui.CElementSorter; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; + +/** + */ +public class HierarchyViewerSorter extends ViewerSorter { + + private static final int OTHER= 0; + private static final int CLASS= 1; + private static final int FIELD= 2; + private static final int METHOD= 3; + + private TypeHierarchyLifeCycle fHierarchy; + private boolean fSortByDefiningType; + private CElementSorter fNormalSorter; + + public HierarchyViewerSorter(TypeHierarchyLifeCycle cycle) { + fHierarchy= cycle; + fNormalSorter= new CElementSorter(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object) + */ +// public int category(Object element) { +// if (element instanceof ICElement) { +// ICElement type= (ICElement) element; +// ITypeHierarchy hierarchy= fHierarchy.getHierarchy(); +// if (hierarchy != null) { +// return CLASS; +// } +// } +// return OTHER; +// } + +// public boolean isSorterProperty(Object element, Object property) { +// return true; +// } + + public int category(Object obj) { + if (obj instanceof ICElement) { + ICElement elem= (ICElement)obj; + switch (elem.getElementType()) { + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + return CLASS; +// case ICElement.C_UNION: +// return 3; + case ICElement.C_FIELD: + return FIELD; + + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + return METHOD; +// { +// IMethodDeclaration method = (IMethodDeclaration) elem; +// try { +// // sort constructor and destructor first +// if (method.isConstructor() || method.isDestructor()) +// return 10; +// } catch (CModelException e) { +// } +// return 20; +// } + } + + } + return OTHER; + } + + public boolean isSortByDefiningType() { + return fSortByDefiningType; + } + + public void setSortByDefiningType(boolean sortByDefiningType) { + fSortByDefiningType= sortByDefiningType; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerSorter#compare(null, null, null) + */ + public int compare(Viewer viewer, Object e1, Object e2) { + int cat1= category(e1); + int cat2= category(e2); + + if (cat1 != cat2) + return cat1 - cat2; + + ITypeHierarchy hierarchy= fHierarchy.getHierarchy(); + if (hierarchy == null) { + return fNormalSorter.compare(viewer, e1, e2); + } + + if (cat1 == FIELD || cat1 == METHOD) { // method or field + if (fSortByDefiningType) { + try { + ICElement def1= (e1 instanceof IMethodDeclaration) ? getDefiningType(hierarchy, (IMethodDeclaration) e1) : null; + ICElement def2= (e2 instanceof IMethodDeclaration) ? getDefiningType(hierarchy, (IMethodDeclaration) e2) : null; + if (def1 != null) { + if (def2 != null) { + if (!def2.equals(def1)) { + return compareInHierarchy(hierarchy, def1, def2); + } + } else { + return -1; + } + } else { + if (def2 != null) { + return 1; + } + } + } catch (CModelException e) { + // ignore, default to normal comparison + } + } + return fNormalSorter.compare(viewer, e1, e2); // use appearance pref page settings + } else { + String name1= ((ICElement) e1).getElementName(); //$NON-NLS-1$ + String name2= ((ICElement) e2).getElementName(); //$NON-NLS-1$ + return getCollator().compare(name1, name2); + } + } + + private ICElement getDefiningType(ITypeHierarchy hierarchy, IMethodDeclaration method) throws CModelException { + ICElement declaringType= TypeUtil.getDeclaringType(method); + if ((method.getVisibility() == ASTAccessVisibility.PRIVATE) || method.isStatic() || method.isConstructor() || method.isDestructor()) { + return null; + } + + ICElement res= TypeUtil.findMethodDeclarationInHierarchy(hierarchy, declaringType, method.getElementName(), method.getParameterTypes(), false, false); + if (res == null || method.equals(res)) { + return null; + } + return TypeUtil.getDeclaringType(res); + } + + + private int compareInHierarchy(ITypeHierarchy hierarchy, ICElement def1, ICElement def2) { + if (isSuperType(hierarchy, def1, def2)) { + return 1; + } else if (isSuperType(hierarchy, def2, def1)) { + return -1; + } + String name1= def1.getElementName(); + String name2= def2.getElementName(); + + return getCollator().compare(name1, name2); + } + + private boolean isSuperType(ITypeHierarchy hierarchy, ICElement def1, ICElement def2) { + ICElement[] superTypes= hierarchy.getSupertypes(def1); + if (superTypes != null) { + for (int i = 0; i < superTypes.length; ++i) { + if (superTypes[i].equals(def2) || isSuperType(hierarchy, superTypes[i], def2)) { + return true; + } + } + } + return false; + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryAction.java new file mode 100644 index 00000000000..95f4d2a260d --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryAction.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.CElementImageProvider; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Action used for the type hierarchy forward / backward buttons + */ +public class HistoryAction extends Action { + + private TypeHierarchyViewPart fViewPart; + private ICElement fElement; + + public HistoryAction(TypeHierarchyViewPart viewPart, ICElement element) { + super(); + fViewPart= viewPart; + fElement= element; + + String elementName= CElementLabels.getElementLabel(element, CElementLabels.ALL_POST_QUALIFIED | CElementLabels.M_PARAMETER_TYPES); + setText(elementName); + setImageDescriptor(getImageDescriptor(element)); + + setDescription(TypeHierarchyMessages.getFormattedString("HistoryAction.description", elementName)); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getFormattedString("HistoryAction.tooltip", elementName)); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.HISTORY_ACTION); + } + + private ImageDescriptor getImageDescriptor(ICElement elem) { + CElementImageProvider imageProvider= new CElementImageProvider(); + ImageDescriptor desc= imageProvider.getBaseImageDescriptor(elem, 0); + imageProvider.dispose(); + return desc; + } + + /* + * @see Action#run() + */ + public void run() { + fViewPart.gotoHistoryEntry(fElement); + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryDropDownAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryDropDownAction.java new file mode 100644 index 00000000000..43604cbdd50 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryDropDownAction.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IMenuCreator; + +import org.eclipse.ui.help.WorkbenchHelp; + +public class HistoryDropDownAction extends Action implements IMenuCreator { + + + public static final int RESULTS_IN_DROP_DOWN= 10; + + private TypeHierarchyViewPart fHierarchyView; + private Menu fMenu; + + public HistoryDropDownAction(TypeHierarchyViewPart view) { + fHierarchyView= view; + fMenu= null; + setToolTipText(TypeHierarchyMessages.getString("HistoryDropDownAction.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "history_list.gif"); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.TYPEHIERARCHY_HISTORY_ACTION); + setMenuCreator(this); + } + + public void dispose() { + // action is reused, can be called several times. + if (fMenu != null) { + fMenu.dispose(); + fMenu= null; + } + } + + public Menu getMenu(Menu parent) { + return null; + } + + public Menu getMenu(Control parent) { + if (fMenu != null) { + fMenu.dispose(); + } + fMenu= new Menu(parent); + ICElement[] elements= fHierarchyView.getHistoryEntries(); + boolean checked= addEntries(fMenu, elements); + if (elements.length > RESULTS_IN_DROP_DOWN) { + new MenuItem(fMenu, SWT.SEPARATOR); + Action others= new HistoryListAction(fHierarchyView); + others.setChecked(checked); + addActionToMenu(fMenu, others); + } + return fMenu; + } + + private boolean addEntries(Menu menu, ICElement[] elements) { + boolean checked= false; + + int min= Math.min(elements.length, RESULTS_IN_DROP_DOWN); + for (int i= 0; i < min; i++) { + HistoryAction action= new HistoryAction(fHierarchyView, elements[i]); + action.setChecked(elements[i].equals(fHierarchyView.getInputElement())); + checked= checked || action.isChecked(); + addActionToMenu(menu, action); + } + return checked; + } + + + protected void addActionToMenu(Menu parent, Action action) { + ActionContributionItem item= new ActionContributionItem(action); + item.fill(parent, -1); + } + + public void run() { + (new HistoryListAction(fHierarchyView)).run(); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryListAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryListAction.java new file mode 100644 index 00000000000..30f0f6e17f3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/HistoryListAction.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; + +import org.eclipse.ui.help.WorkbenchHelp; + +public class HistoryListAction extends Action { + + private class HistoryListDialog extends StatusDialog { + + private ListDialogField fHistoryList; + private IStatus fHistoryStatus; + private ICElement fResult; + + private HistoryListDialog(Shell shell, ICElement[] elements) { + super(shell); + setTitle(TypeHierarchyMessages.getString("HistoryListDialog.title")); //$NON-NLS-1$ + + String[] buttonLabels= new String[] { + /* 0 */ TypeHierarchyMessages.getString("HistoryListDialog.remove.button"), //$NON-NLS-1$ + }; + + IListAdapter adapter= new IListAdapter() { + public void customButtonPressed(ListDialogField field, int index) { + doCustomButtonPressed(); + } + public void selectionChanged(ListDialogField field) { + doSelectionChanged(); + } + + public void doubleClicked(ListDialogField field) { + doDoubleClicked(); + } + }; + + CElementLabelProvider labelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_QUALIFIED /*| CElementLabelProvider.SHOW_ROOT*/); + + fHistoryList= new ListDialogField(adapter, buttonLabels, labelProvider); + fHistoryList.setLabelText(TypeHierarchyMessages.getString("HistoryListDialog.label")); //$NON-NLS-1$ + fHistoryList.setElements(Arrays.asList(elements)); + + ISelection sel; + if (elements.length > 0) { + sel= new StructuredSelection(elements[0]); + } else { + sel= new StructuredSelection(); + } + + fHistoryList.selectElements(sel); + } + + + /* + * @see Dialog#createDialogArea(Composite) + */ + protected Control createDialogArea(Composite parent) { + initializeDialogUnits(parent); + + Composite composite= (Composite) super.createDialogArea(parent); + + Composite inner= new Composite(composite, SWT.NONE); + inner.setLayoutData(new GridData(GridData.FILL_BOTH)); + + LayoutUtil.doDefaultLayout(inner, new DialogField[] { fHistoryList }, true, 0, 0); + LayoutUtil.setHeigthHint(fHistoryList.getListControl(null), convertHeightInCharsToPixels(12)); + LayoutUtil.setHorizontalGrabbing(fHistoryList.getListControl(null)); + + applyDialogFont(composite); + return composite; + } + + /** + * Method doCustomButtonPressed. + */ + private void doCustomButtonPressed() { + fHistoryList.removeElements(fHistoryList.getSelectedElements()); + } + + private void doDoubleClicked() { + if (fHistoryStatus.isOK()) { + okPressed(); + } + } + + + private void doSelectionChanged() { + StatusInfo status= new StatusInfo(); + List selected= fHistoryList.getSelectedElements(); + if (selected.size() != 1) { + status.setError(""); //$NON-NLS-1$ + fResult= null; + } else { + fResult= (ICElement) selected.get(0); + } + fHistoryList.enableButton(0, fHistoryList.getSize() > selected.size() && selected.size() != 0); + fHistoryStatus= status; + updateStatus(status); + } + + public ICElement getResult() { + return fResult; + } + + public ICElement[] getRemaining() { + List elems= fHistoryList.getElements(); + return (ICElement[]) elems.toArray(new ICElement[elems.size()]); + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + WorkbenchHelp.setHelp(newShell, ICHelpContextIds.HISTORY_LIST_DIALOG); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#create() + */ + public void create() { + setShellStyle(getShellStyle() | SWT.RESIZE); + super.create(); + } + + } + + private TypeHierarchyViewPart fView; + + public HistoryListAction(TypeHierarchyViewPart view) { + fView= view; + setText(TypeHierarchyMessages.getString("HistoryListAction.label")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "history_list.gif"); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.HISTORY_LIST_ACTION); + } + + /* + * @see IAction#run() + */ + public void run() { + ICElement[] historyEntries= fView.getHistoryEntries(); + HistoryListDialog dialog= new HistoryListDialog(CUIPlugin.getActiveWorkbenchShell(), historyEntries); + if (dialog.open() == Window.OK) { + fView.setHistoryEntries(dialog.getRemaining()); + fView.setInputElement(dialog.getResult()); + } + } + +} + diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyLifeCycleListener.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyLifeCycleListener.java new file mode 100644 index 00000000000..c6ad8e8e859 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyLifeCycleListener.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.model.ICElement; + +/** + * Used by the TypeHierarchyLifeCycle to inform listeners about a change in the + * type hierarchy + */ +public interface ITypeHierarchyLifeCycleListener { + + /** + * A Java element changed. + */ + void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchyProvider, ICElement[] changedTypes); + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyViewPart.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyViewPart.java new file mode 100644 index 00000000000..98837532e60 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ITypeHierarchyViewPart.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.ui.IViewPart; + +/** + * The standard type hierarchy view presents a type hierarchy for a given input class + * or interface. Visually, this view consists of a pair of viewers, one showing the type + * hierarchy, the other showing the members of the type selected in the first. + *

+ * This interface is not intended to be implemented by clients. + *

+ * + * @see JavaUI#ID_TYPE_HIERARCHY + */ +public interface ITypeHierarchyViewPart extends IViewPart { + + /** + * Sets the input element of this type hierarchy view to a type. + * + * @param type the input element of this type hierarchy view, or null + * to clear any input element + * @deprecated use setInputElement instead + */ + public void setInput(ICElement type); + + /** + * Sets the input element of this type hierarchy view. The following input types are possible + * IMember (types, methods, fields..), IPackageFragment, IPackageFragmentRoot + * and IJavaProject. + * + * @param element the input element of this type hierarchy view, or null + * to clear any input + * + * @since 2.0 + */ + public void setInputElement(ICElement element); + + /** + * Returns the input element of this type hierarchy view. + * + * @return the input element, or null if no input element is set + * @see #setInput(IType) + * @deprecated use getInputElement instead + */ + public ICElement getInput(); + + + /** + * Returns the input element of this type hierarchy view. + * + * @return the input element, or null if no input element is set + * @see #setInputElement(IJavaElement) + * + * @since 2.0 + */ + public ICElement getInputElement(); +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsContentProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsContentProvider.java new file mode 100644 index 00000000000..0343cac679b --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsContentProvider.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.browser.IWorkingCopyProvider; +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.ui.CElementContentProvider; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; + +/** + * Content provider used for the method view. + * Allows also seeing methods inherited from base classes. + */ +public class MethodsContentProvider extends CElementContentProvider //implements IStructuredContentProvider //, IWorkingCopyProvider +{ + private static final Object[] NO_ELEMENTS = new Object[0]; + + private boolean fShowInheritedMethods; + private TypeHierarchyLifeCycle fHierarchyLifeCycle; + private TableViewer fViewer; + + public MethodsContentProvider(TypeHierarchyLifeCycle lifecycle) { + fHierarchyLifeCycle= lifecycle; + fShowInheritedMethods= false; + fViewer= null; + } + + /** + * Turn on / off showing of inherited methods + */ + public void showInheritedMethods(boolean show) { + if (show != fShowInheritedMethods) { + fShowInheritedMethods= show; + if (fViewer != null) { + fViewer.refresh(); + } + } + } + + /* (non-Javadoc) + * @see IStructuredContentProvider#providesWorkingCopies() + */ + public boolean providesWorkingCopies() { + return true; + } + + /** + * Returns true if inherited methods are shown + */ + public boolean isShowInheritedMethods() { + return fShowInheritedMethods; + } + + + private void addAll(Object[] arr, List res) { + if (arr != null) { + for (int j= 0; j < arr.length; j++) { + res.add(arr[j]); + } + } + } + + /* + * @see IStructuredContentProvider#getElements + */ + public Object[] getElements(Object element) { + if (element instanceof ICElement) { + ICElement type= (ICElement)element; + + List res= new ArrayList(); +// try { + ITypeHierarchy hierarchy= fHierarchyLifeCycle.getHierarchy(); + if (fShowInheritedMethods && hierarchy != null) { + ICElement[] allSupertypes= hierarchy.getAllSupertypes(type); + // sort in from last to first: elements with same name + // will show up in hierarchy order + for (int i= allSupertypes.length - 1; i >= 0; i--) { + ICElement superType= allSupertypes[i]; + if (superType.exists()) { + addAll(TypeUtil.getMethods(superType), res); + //addAll(TypeUtil.getInitializers(superType), res); + addAll(TypeUtil.getFields(superType), res); + } + } + } + if (type.exists()) { + addAll(TypeUtil.getMethods(type), res); + //addAll(TypeUtil.getInitializers(type), res); + addAll(TypeUtil.getFields(type), res); + } +// } catch (CModelException e) { +// CUIPlugin.getDefault().log(e); +// } + return res.toArray(); + } + return NO_ELEMENTS; + } + + + /* + * @see IContentProvider#inputChanged + */ + public void inputChanged(Viewer input, Object oldInput, Object newInput) { + Assert.isTrue(input instanceof TableViewer); + + fViewer= (TableViewer) input; + } + + /* + * @see IContentProvider#dispose + */ + public void dispose() { + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsLabelProvider.java new file mode 100644 index 00000000000..f903bf5af39 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsLabelProvider.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMember; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.internal.corext.util.CModelUtil; +import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.AppearanceAwareLabelProvider; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +/** + * Label provider for the hierarchy method viewers. + */ +public class MethodsLabelProvider extends StandardCElementLabelProvider //extends AppearanceAwareLabelProvider +{ + private Color fResolvedBackground; + + private boolean fShowDefiningType; + private TypeHierarchyLifeCycle fHierarchy; + private MethodsViewer fMethodsViewer; + + public MethodsLabelProvider(TypeHierarchyLifeCycle lifeCycle, MethodsViewer methodsViewer) { +// super(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS); + super(); + fHierarchy= lifeCycle; + fShowDefiningType= false; + fMethodsViewer= methodsViewer; + fResolvedBackground= null; + } + + public void setShowDefiningType(boolean showDefiningType) { + fShowDefiningType= showDefiningType; + } + + public boolean isShowDefiningType() { + return fShowDefiningType; + } + + + private ICElement getDefiningType(Object element) throws CModelException { + if (!(element instanceof ICElement)) + return null; + + ICElement elem = (ICElement) element; + int kind= elem.getElementType(); + if (kind != ICElement.C_METHOD_DECLARATION && kind != ICElement.C_FIELD) { + return null; + } + ICElement declaringType= TypeUtil.getDeclaringType(elem); + if (kind != ICElement.C_METHOD_DECLARATION) { + return declaringType; + } + ITypeHierarchy hierarchy= fHierarchy.getHierarchy(); + if (hierarchy == null) { + return declaringType; + } + IMethodDeclaration method= (IMethodDeclaration) element; + if ((method.getVisibility() == ASTAccessVisibility.PRIVATE) || method.isStatic() || method.isConstructor() || method.isDestructor()) { + return declaringType; + } + IMethodDeclaration res= TypeUtil.findMethodDeclarationInHierarchy(hierarchy, declaringType, method.getElementName(), method.getParameterTypes(), false, false); + if (res == null || method.equals(res)) { + return declaringType; + } + return TypeUtil.getDeclaringType(res); + } + + /* (non-Javadoc) + * @see ILabelProvider#getText + */ + public String getText(Object element) { + String text= super.getText(element); + if ((getTextFlags() & CElementLabels.M_POST_QUALIFIED) != 0) { + if (element instanceof ICElement) { + ICElement parent = ((ICElement)element).getParent(); + if (parent != null) { + StringBuffer name = new StringBuffer(); + name.append(text); + name.append(CElementLabels.CONCAT_STRING); + name.append(TypeUtil.getFullyQualifiedName(parent).toString()); + text = name.toString(); + } + } + } + + if (fShowDefiningType) { + try { + ICElement type= getDefiningType(element); + if (type != null) { + StringBuffer buf= new StringBuffer(super.getText(type)); + buf.append(CElementLabels.CONCAT_STRING); + buf.append(text); + return buf.toString(); + } + } catch (CModelException e) { + } + } + return text; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) + */ + public Color getForeground(Object element) { + if (fMethodsViewer.isShowInheritedMethods() && element instanceof IMethod) { + IMethod curr= (IMethod) element; + ICElement declaringType= TypeUtil.getDeclaringType(curr); + + if (declaringType.equals(fMethodsViewer.getInput())) { + if (fResolvedBackground == null) { + Display display= Display.getCurrent(); + fResolvedBackground= display.getSystemColor(SWT.COLOR_DARK_BLUE); + } + return fResolvedBackground; + } + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsViewer.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsViewer.java new file mode 100644 index 00000000000..2023ee811ee --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/MethodsViewer.java @@ -0,0 +1,302 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.DecoratingCLabelProvider; +import org.eclipse.cdt.internal.ui.util.ProblemTableViewer; +import org.eclipse.cdt.internal.ui.util.SelectionUtil; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.actions.MemberFilterActionGroup; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; + +/** + * Method viewer shows a list of methods of a input type. + * Offers filter actions. + * No dependency to the type hierarchy view + */ +public class MethodsViewer extends ProblemTableViewer { + + private static final String TAG_SHOWINHERITED= "showinherited"; //$NON-NLS-1$ + private static final String TAG_SORTBYDEFININGTYPE= "sortbydefiningtype"; //$NON-NLS-1$ + private static final String TAG_VERTICAL_SCROLL= "mv_vertical_scroll"; //$NON-NLS-1$ + + private MethodsLabelProvider fLabelProvider; + + private MemberFilterActionGroup fMemberFilterActionGroup; + +// private OpenAction fOpen; + private ShowInheritedMembersAction fShowInheritedMembersAction; + private SortByDefiningTypeAction fSortByDefiningTypeAction; + + public MethodsViewer(Composite parent, final TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) { + super(new Table(parent, SWT.MULTI)); + + fLabelProvider= new MethodsLabelProvider(lifeCycle, this); + +// setLabelProvider(new DecoratingCLabelProvider(fLabelProvider, true)); + setLabelProvider(fLabelProvider); + setContentProvider(new MethodsContentProvider(lifeCycle)); + + HierarchyViewerSorter sorter= new HierarchyViewerSorter(lifeCycle); + sorter.setSortByDefiningType(false); + setSorter(sorter); + +// fOpen= new OpenAction(part.getSite()); +// addOpenListener(new IOpenListener() { +// public void open(OpenEvent event) { +// fOpen.run(); +// } +// }); + + fMemberFilterActionGroup= new MemberFilterActionGroup(this, "HierarchyMethodView", false, MemberFilterActionGroup.ALL_FILTERS & ~MemberFilterActionGroup.FILTER_LOCALTYPES); //$NON-NLS-1$ + + fShowInheritedMembersAction= new ShowInheritedMembersAction(this, false); + fSortByDefiningTypeAction= new SortByDefiningTypeAction(this, false); + + showInheritedMethodsNoRedraw(false); + sortByDefiningTypeNoRedraw(false); + +// CUIHelp.setHelp(this, ICHelpContextIds.TYPE_HIERARCHY_VIEW); + } + + private void showInheritedMethodsNoRedraw(boolean on) { + MethodsContentProvider cprovider= (MethodsContentProvider) getContentProvider(); + cprovider.showInheritedMethods(on); + fShowInheritedMembersAction.setChecked(on); + if (on) { + fLabelProvider.turnOn(CElementLabelProvider.SHOW_POST_QUALIFIED); + } else { + fLabelProvider.turnOff(CElementLabelProvider.SHOW_POST_QUALIFIED); + } + if (on) { + sortByDefiningTypeNoRedraw(false); + } + fSortByDefiningTypeAction.setEnabled(!on); + + } + + /** + * Show inherited methods + */ + public void showInheritedMethods(boolean on) { + if (on == isShowInheritedMethods()) { + return; + } + try { + getTable().setRedraw(false); + showInheritedMethodsNoRedraw(on); + refresh(); + } finally { + getTable().setRedraw(true); + } + } + + private void sortByDefiningTypeNoRedraw(boolean on) { + fSortByDefiningTypeAction.setChecked(on); + fLabelProvider.setShowDefiningType(on); + ((HierarchyViewerSorter) getSorter()).setSortByDefiningType(on); + } + + /** + * Show the name of the defining type + */ + public void sortByDefiningType(boolean on) { + if (on == isShowDefiningTypes()) { + return; + } + try { + getTable().setRedraw(false); + sortByDefiningTypeNoRedraw(on); + refresh(); + } finally { + getTable().setRedraw(true); + } + } + + /* + * @see Viewer#inputChanged(Object, Object) + */ + protected void inputChanged(Object input, Object oldInput) { + super.inputChanged(input, oldInput); + } + + /** + * Returns true if inherited methods are shown. + */ + public boolean isShowInheritedMethods() { + return ((MethodsContentProvider) getContentProvider()).isShowInheritedMethods(); + } + + /** + * Returns true if defining types are shown. + */ + public boolean isShowDefiningTypes() { + return fLabelProvider.isShowDefiningType(); + } + + /** + * Saves the state of the filter actions + */ + public void saveState(IMemento memento) { + fMemberFilterActionGroup.saveState(memento); + + memento.putString(TAG_SHOWINHERITED, String.valueOf(isShowInheritedMethods())); + memento.putString(TAG_SORTBYDEFININGTYPE, String.valueOf(isShowDefiningTypes())); + + ScrollBar bar= getTable().getVerticalBar(); + int position= bar != null ? bar.getSelection() : 0; + memento.putString(TAG_VERTICAL_SCROLL, String.valueOf(position)); + } + + /** + * Restores the state of the filter actions + */ + public void restoreState(IMemento memento) { + fMemberFilterActionGroup.restoreState(memento); + getControl().setRedraw(false); + refresh(); + getControl().setRedraw(true); + + boolean showInherited= Boolean.valueOf(memento.getString(TAG_SHOWINHERITED)).booleanValue(); + showInheritedMethods(showInherited); + + boolean showDefiningTypes= Boolean.valueOf(memento.getString(TAG_SORTBYDEFININGTYPE)).booleanValue(); + sortByDefiningType(showDefiningTypes); + + ScrollBar bar= getTable().getVerticalBar(); + if (bar != null) { + Integer vScroll= memento.getInteger(TAG_VERTICAL_SCROLL); + if (vScroll != null) { + bar.setSelection(vScroll.intValue()); + } + } + } + + /** + * Attaches a contextmenu listener to the table + */ + public void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) { + MenuManager menuMgr= new MenuManager(); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(menuListener); + Menu menu= menuMgr.createContextMenu(getTable()); + getTable().setMenu(menu); + viewSite.registerContextMenu(popupId, menuMgr, this); + } + + + /** + * Fills up the context menu with items for the method viewer + * Should be called by the creator of the context menu + */ + public void contributeToContextMenu(IMenuManager menu) { + } + + /** + * Fills up the tool bar with items for the method viewer + * Should be called by the creator of the tool bar + */ + public void contributeToToolBar(ToolBarManager tbm) { + tbm.add(fShowInheritedMembersAction); + tbm.add(fSortByDefiningTypeAction); + tbm.add(new Separator()); + fMemberFilterActionGroup.contributeToToolBar(tbm); + } + + public void dispose() { + if (fMemberFilterActionGroup != null) { + fMemberFilterActionGroup.dispose(); + fMemberFilterActionGroup= null; + } + } + + /* + * @see StructuredViewer#handleInvalidSelection(ISelection, ISelection) + */ + protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) { + // on change of input, try to keep selected methods stable by selecting a method with the same + // signature: See #5466 + List oldSelections= SelectionUtil.toList(invalidSelection); + List newSelections= SelectionUtil.toList(newSelection); + if (!oldSelections.isEmpty()) { + ArrayList newSelectionElements= new ArrayList(newSelections); + try { + Object[] currElements= getFilteredChildren(getInput()); + for (int i= 0; i < oldSelections.size(); i++) { + Object curr= oldSelections.get(i); + if (curr instanceof IMethodDeclaration && !newSelections.contains(curr)) { + IMethodDeclaration method= (IMethodDeclaration) curr; + if (method.exists()) { + IMethodDeclaration similar= findSimilarMethod(method, currElements); + if (similar != null) { + newSelectionElements.add(similar); + } + } + } + } + if (!newSelectionElements.isEmpty()) { + newSelection= new StructuredSelection(newSelectionElements); + } else if (currElements.length > 0) { + newSelection= new StructuredSelection(currElements[0]); + } + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); + } + } + setSelection(newSelection); + updateSelection(newSelection); + } + + private IMethodDeclaration findSimilarMethod(IMethodDeclaration meth, Object[] elements) throws CModelException { + String name= meth.getElementName(); + String[] paramTypes= meth.getParameterTypes(); + boolean isConstructor= meth.isConstructor(); + boolean isDestructor= meth.isDestructor(); + + for (int i= 0; i < elements.length; i++) { + Object curr= elements[i]; + if (curr instanceof IMethodDeclaration && TypeUtil.isSameMethodSignature(name, paramTypes, isConstructor, isDestructor, (IMethodDeclaration) curr)) { + return (IMethodDeclaration) curr; + } + } + return null; + } + + + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyAction.java new file mode 100644 index 00000000000..5fcff0f6149 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyAction.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.core.browser.AllTypesCache; +import org.eclipse.cdt.core.browser.ITypeInfo; +import org.eclipse.cdt.core.browser.ITypeSearchScope; +import org.eclipse.cdt.core.browser.QualifiedTypeName; +import org.eclipse.cdt.core.browser.TypeSearchScope; +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.ICStatusConstants; +import org.eclipse.cdt.internal.ui.actions.ActionMessages; +import org.eclipse.cdt.internal.ui.actions.ActionUtil; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.actions.SelectionDispatchAction; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * This action opens a type hierarchy on the selected type. + *

+ * The action is applicable to selections containing elements of type + * IType. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class OpenTypeHierarchyAction extends SelectionDispatchAction { + + private CEditor fEditor; + + /** + * Creates a new OpenTypeHierarchyAction. The action requires + * that the selection provided by the site's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param site the site providing context information for this action + */ + public OpenTypeHierarchyAction(IWorkbenchSite site) { + super(site); + setText(ActionMessages.getString("OpenTypeHierarchyAction.label")); //$NON-NLS-1$ + setToolTipText(ActionMessages.getString("OpenTypeHierarchyAction.tooltip")); //$NON-NLS-1$ + setDescription(ActionMessages.getString("OpenTypeHierarchyAction.description")); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.OPEN_TYPE_HIERARCHY_ACTION); + } + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + */ + public OpenTypeHierarchyAction(CEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + setEnabled(SelectionConverter.canOperateOn(fEditor)); + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(ITextSelection selection) { +/* boolean enable = true; + ICElement selectedElement = null; + try { + ICElement[] elements = SelectionConverter.getElementsAtOffset(fEditor); + if (elements == null || elements.length == 0) { + setEnabled(false); + return; + } + // find class or struct + for (int i = 0; i < elements.length; ++i) { + if (TypeUtil.isClassOrStruct(elements[i])) { + selectedElement = elements[i]; + break; + } + } + + if (selectedElement == null) { + setEnabled(false); + return; + } + } catch (CModelException e) { + setEnabled(false); + return; + } + + ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); + + if (textSelection == null) { + setEnabled(false); + return; + } + + if( (((CElement)selectedElement).getIdStartPos() != textSelection.getOffset()) + || (((CElement)selectedElement).getIdLength() != textSelection.getLength())) { + enable = false; + } + setEnabled(enable); +*/ } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(IStructuredSelection selection) { +// setEnabled(isEnabled(selection)); + } + + private boolean isEnabled(IStructuredSelection selection) { + if (selection.size() != 1) + return false; + Object input= selection.getFirstElement(); + if (input instanceof ICElement) { + ICElement elem = (ICElement)input; + return TypeUtil.isClassOrStruct(elem); + } + return false; + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(ITextSelection selection) { + ICElement input= SelectionConverter.getInput(fEditor); + if (!ActionUtil.isProcessable(getShell(), input)) + return; + + ICElement[] elements= SelectionConverter.codeResolveOrInputHandled(fEditor, getShell(), getDialogTitle()); + if (elements == null) + return; + List candidates= new ArrayList(elements.length); + for (int i= 0; i < elements.length; i++) { + ICElement elem = elements[i]; + if (elem instanceof ITranslationUnit) { + ICElement[] realElems = findTypeDeclarations(selection.getText(), (ITranslationUnit)elem, selection.getOffset(), selection.getLength(), new NullProgressMonitor()); + if (realElems != null) { + for (int j = 0; j < realElems.length; ++j) { + ICElement[] resolvedElements= OpenTypeHierarchyUtil.getCandidates(realElems[j]); + if (resolvedElements != null) + candidates.addAll(Arrays.asList(resolvedElements)); + } + } + } else { + ICElement[] resolvedElements= OpenTypeHierarchyUtil.getCandidates(elem); + if (resolvedElements != null) + candidates.addAll(Arrays.asList(resolvedElements)); + } + } + run((ICElement[])candidates.toArray(new ICElement[candidates.size()])); + } + + private ICElement[] findTypeDeclarations(String name, ITranslationUnit unit, int offset, int length, IProgressMonitor monitor) { + final ITypeSearchScope wsScope = new TypeSearchScope(true); + if (!AllTypesCache.isCacheUpToDate(wsScope)) { + AllTypesCache.updateCache(wsScope, monitor); + } + ITypeSearchScope projectScope = new TypeSearchScope(); + projectScope.add(unit.getCProject()); + int[] kinds = {ICElement.C_CLASS, ICElement.C_STRUCT}; + ITypeInfo[] types = AllTypesCache.getTypes(projectScope, new QualifiedTypeName(name), kinds); + if (types != null) { + List elements = new ArrayList(types.length); + for (int i = 0; i < types.length; ++i) { + ICElement e = TypeUtil.getElementForType(types[i], monitor); + if (e != null && !elements.contains(e)) + elements.add(e); + } + if (!elements.isEmpty()) + return (ICElement[])elements.toArray(new ICElement[elements.size()]); + } + return null; + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(IStructuredSelection selection) { + if (selection.size() != 1) + return; + Object input= selection.getFirstElement(); + + if (!(input instanceof ICElement)) { + IStatus status= createStatus(ActionMessages.getString("OpenTypeHierarchyAction.messages.no_c_element")); //$NON-NLS-1$ + ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.getString("OpenTypeHierarchyAction.messages.title"), status); //$NON-NLS-1$ + return; + } + ICElement element= (ICElement) input; + if (!ActionUtil.isProcessable(getShell(), element)) + return; + + List result= new ArrayList(1); + IStatus status= compileCandidates(result, element); + if (status.isOK()) { + run((ICElement[]) result.toArray(new ICElement[result.size()])); + } else { + ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.getString("OpenTypeHierarchyAction.messages.title"), status); //$NON-NLS-1$ + } + } + + public void run(ICElement[] elements) { + if (elements.length == 0) { + getShell().getDisplay().beep(); + return; + } + OpenTypeHierarchyUtil.open(elements, getSite().getWorkbenchWindow()); + } + + private static String getDialogTitle() { + return ActionMessages.getString("OpenTypeHierarchyAction.dialog.title"); //$NON-NLS-1$ + } + + private static IStatus compileCandidates(List result, ICElement elem) { + IStatus ok = new Status(IStatus.OK, CUIPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$ + switch (elem.getElementType()) { + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + case ICElement.C_PROJECT: + result.add(elem); + return ok; + } + return createStatus(ActionMessages.getString("OpenTypeHierarchyAction.messages.no_valid_c_element")); //$NON-NLS-1$ + } + + private static IStatus createStatus(String message) { + return new Status(IStatus.INFO, CUIPlugin.getPluginId(), ICStatusConstants.INTERNAL_ERROR, message, null); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyUtil.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyUtil.java new file mode 100644 index 00000000000..1ed97876c0d --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeHierarchyUtil.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.security.Signature; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMember; +import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.corext.util.CModelUtil; +import org.eclipse.cdt.internal.ui.CUIMessages; +import org.eclipse.cdt.internal.ui.actions.OpenActionUtil; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.util.Assert; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.WorkbenchException; + +public class OpenTypeHierarchyUtil { + + private OpenTypeHierarchyUtil() { + } + + public static TypeHierarchyViewPart open(ICElement element, IWorkbenchWindow window) { + ICElement[] candidates= getCandidates(element); + if (candidates != null) { + return open(candidates, window); + } + return null; + } + + public static TypeHierarchyViewPart open(ICElement[] candidates, IWorkbenchWindow window) { + Assert.isTrue(candidates != null && candidates.length != 0); + + ICElement input= null; + if (candidates.length > 1) { + String title= CUIMessages.getString("OpenTypeHierarchyUtil.selectionDialog.title"); //$NON-NLS-1$ + String message= CUIMessages.getString("OpenTypeHierarchyUtil.selectionDialog.message"); //$NON-NLS-1$ + input= OpenActionUtil.selectCElement(candidates, window.getShell(), title, message); + } else { + input= candidates[0]; + } + if (input == null) + return null; + + try { + if (PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE.equals(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.OPEN_TYPE_HIERARCHY))) { + return openInPerspective(window, input); + } else { + return openInViewPart(window, input); + } + + } catch (WorkbenchException e) { + ExceptionHandler.handle(e, window.getShell(), + CUIMessages.getString("OpenTypeHierarchyUtil.error.open_perspective"), //$NON-NLS-1$ + e.getMessage()); + } catch (CModelException e) { + ExceptionHandler.handle(e, window.getShell(), + CUIMessages.getString("OpenTypeHierarchyUtil.error.open_editor"), //$NON-NLS-1$ + e.getMessage()); + } + return null; + } + + private static TypeHierarchyViewPart openInViewPart(IWorkbenchWindow window, ICElement input) { + IWorkbenchPage page= window.getActivePage(); + try { + TypeHierarchyViewPart result= (TypeHierarchyViewPart) page.findView(CUIPlugin.ID_TYPE_HIERARCHY); + if (result != null) { + result.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible' + } + result= (TypeHierarchyViewPart) page.showView(CUIPlugin.ID_TYPE_HIERARCHY); + result.setInputElement(input); + + if (input instanceof IMember) { + result.selectMember((IMember) input); + } + return result; + } catch (CoreException e) { + ExceptionHandler.handle(e, window.getShell(), + CUIMessages.getString("OpenTypeHierarchyUtil.error.open_view"), e.getMessage()); //$NON-NLS-1$ + } + return null; + } + + private static TypeHierarchyViewPart openInPerspective(IWorkbenchWindow window, ICElement input) throws WorkbenchException, CModelException { + IWorkbench workbench= CUIPlugin.getDefault().getWorkbench(); + // The problem is that the input element can be a working copy. So we first convert it to the original element if + // it exists. + ICElement perspectiveInput= input; + + if (input instanceof IMember) { +// if (input.getElementType() != ITypeElement.TYPE) { + if (TypeUtil.isClassOrStruct(input)) { +// perspectiveInput= ((IMember)input).getDeclaringType(); + perspectiveInput= TypeUtil.getDeclaringType(input); + } else { + perspectiveInput= input; + } + } + IWorkbenchPage page= workbench.showPerspective(CUIPlugin.ID_CHIERARCHY_PERSPECTIVE, window, perspectiveInput); + + TypeHierarchyViewPart part= (TypeHierarchyViewPart) page.findView(CUIPlugin.ID_TYPE_HIERARCHY); + if (part != null) { + part.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible' + } + part= (TypeHierarchyViewPart) page.showView(CUIPlugin.ID_TYPE_HIERARCHY); + part.setInputElement(perspectiveInput); + if (input instanceof IMember) { + part.selectMember((IMember) input); + + if (page.getEditorReferences().length == 0) { + openEditor(input, false); // only open when the perspecive has been created + } + } + return part; + } + + private static void openEditor(Object input, boolean activate) throws PartInitException, CModelException { + IEditorPart part= EditorUtility.openInEditor(input, activate); + if (input instanceof ICElement) + EditorUtility.revealInEditor(part, (ICElement) input); + } + + /** + * Converts the input to a possible input candidates + */ + public static ICElement[] getCandidates(Object input) { + if (!(input instanceof ICElement)) { + return null; + } +// try { + ICElement elem= (ICElement) input; + switch (elem.getElementType()) { + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + case ICElement.C_FIELD: + case ICElement.C_UNION: + case ICElement.C_ENUMERATION: + case ICElement.C_TYPEDEF: + return new ICElement[] { TypeUtil.getDeclaringType(elem) }; + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + return new ICElement[] { elem }; + case ICElement.C_NAMESPACE: + return TypeUtil.getTypes(elem); + case ICElement.C_UNIT: { + ITranslationUnit cu= (ITranslationUnit) elem.getAncestor(ICElement.C_UNIT); + if (cu != null) { + return TypeUtil.getTypes(cu); + } + break; + } + case ICElement.C_PROJECT: + default: + } +// } catch (CModelException e) { +// CUIPlugin.getDefault().log(e); +// } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeInHierarchyAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeInHierarchyAction.java new file mode 100644 index 00000000000..eb729bc010b --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/OpenTypeInHierarchyAction.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.cdt.core.browser.AllTypesCache; +import org.eclipse.cdt.core.browser.ITypeInfo; +import org.eclipse.cdt.core.browser.ITypeSearchScope; +import org.eclipse.cdt.core.browser.TypeSearchScope; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeDialog; +import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.IProgressService; + +public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate { + + private IWorkbenchWindow fWindow; + + public OpenTypeInHierarchyAction() { + super(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + final ITypeSearchScope fScope = new TypeSearchScope(true); + if (!AllTypesCache.isCacheUpToDate(fScope)) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + AllTypesCache.updateCache(fScope, monitor); + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + } + }; + + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + try { + service.busyCursorWhile(runnable); + } catch (InvocationTargetException e) { + String title = OpenTypeMessages.getString("OpenTypeAction.exception.title"); //$NON-NLS-1$ + String message = OpenTypeMessages.getString("OpenTypeAction.exception.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, title, message); + return; + } catch (InterruptedException e) { + // cancelled by user + return; + } + } + + ITypeInfo[] elements = AllTypesCache.getAllTypes(); + if (elements.length == 0) { + String title = OpenTypeMessages.getString("OpenTypeAction.notypes.title"); //$NON-NLS-1$ + String message = OpenTypeMessages.getString("OpenTypeAction.notypes.message"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), title, message); + return; + } + + OpenTypeDialog dialog = new OpenTypeDialog(getShell()); + dialog.setElements(elements); + int result = dialog.open(); + if (result != IDialogConstants.OK_ID) + return; + + ITypeInfo info = (ITypeInfo) dialog.getFirstResult(); + if (info == null) + return; + + Object[] types= dialog.getResult(); + if (types != null && types.length > 0) { + ICElement type= (ICElement)types[0]; + OpenTypeHierarchyUtil.open(new ICElement[] { type }, fWindow); + } + } + + protected Shell getShell() { + return CUIPlugin.getActiveWorkbenchShell(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + fWindow= null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) { + fWindow= window; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, + * org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SelectionProviderMediator.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SelectionProviderMediator.java new file mode 100644 index 00000000000..535ec748f3f --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SelectionProviderMediator.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Widget; + +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.util.ListenerList; +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.StructuredViewer; + +/** + * A selection provider for viewparts with more that one viewer. + * Tracks the focus of the viewers to provide the correct selection. + */ +public class SelectionProviderMediator implements IPostSelectionProvider { + + private class InternalListener implements ISelectionChangedListener, FocusListener { + /* + * @see ISelectionChangedListener#selectionChanged + */ + public void selectionChanged(SelectionChangedEvent event) { + doSelectionChanged(event); + } + + /* + * @see FocusListener#focusGained + */ + public void focusGained(FocusEvent e) { + doFocusChanged(e.widget); + } + + /* + * @see FocusListener#focusLost + */ + public void focusLost(FocusEvent e) { + // do not reset due to focus behaviour on GTK + //fViewerInFocus= null; + } + } + + private class InternalPostSelectionListener implements ISelectionChangedListener { + public void selectionChanged(SelectionChangedEvent event) { + doPostSelectionChanged(event); + } + + } + + private StructuredViewer[] fViewers; + + private StructuredViewer fViewerInFocus; + private ListenerList fSelectionChangedListeners; + private ListenerList fPostSelectionChangedListeners; + + /** + * @param viewers All viewers that can provide a selection + */ + public SelectionProviderMediator(StructuredViewer[] viewers) { + Assert.isNotNull(viewers); + fViewers= viewers; + InternalListener listener= new InternalListener(); + fSelectionChangedListeners= new ListenerList(4); + fPostSelectionChangedListeners= new ListenerList(4); + fViewerInFocus= null; + + for (int i= 0; i < fViewers.length; i++) { + StructuredViewer viewer= fViewers[i]; + viewer.addSelectionChangedListener(listener); + viewer.addPostSelectionChangedListener(new InternalPostSelectionListener()); + Control control= viewer.getControl(); + control.addFocusListener(listener); + } + } + + private void doFocusChanged(Widget control) { + for (int i= 0; i < fViewers.length; i++) { + if (fViewers[i].getControl() == control) { + propagateFocusChanged(fViewers[i]); + return; + } + } + } + + final void doPostSelectionChanged(SelectionChangedEvent event) { + ISelectionProvider provider= event.getSelectionProvider(); + if (provider == fViewerInFocus) { + firePostSelectionChanged(); + } + } + + final void doSelectionChanged(SelectionChangedEvent event) { + ISelectionProvider provider= event.getSelectionProvider(); + if (provider == fViewerInFocus) { + fireSelectionChanged(); + } + } + + final void propagateFocusChanged(StructuredViewer viewer) { + if (viewer != fViewerInFocus) { // Ok to compare by idendity + fViewerInFocus= viewer; + fireSelectionChanged(); + firePostSelectionChanged(); + } + } + + private void fireSelectionChanged() { + if (fSelectionChangedListeners != null) { + SelectionChangedEvent event= new SelectionChangedEvent(this, getSelection()); + + Object[] listeners= fSelectionChangedListeners.getListeners(); + for (int i= 0; i < listeners.length; i++) { + ISelectionChangedListener listener= (ISelectionChangedListener) listeners[i]; + listener.selectionChanged(event); + } + } + } + + private void firePostSelectionChanged() { + if (fPostSelectionChangedListeners != null) { + SelectionChangedEvent event= new SelectionChangedEvent(this, getSelection()); + + Object[] listeners= fPostSelectionChangedListeners.getListeners(); + for (int i= 0; i < listeners.length; i++) { + ISelectionChangedListener listener= (ISelectionChangedListener) listeners[i]; + listener.selectionChanged(event); + } + } + } + + /* + * @see ISelectionProvider#addSelectionChangedListener + */ + public void addSelectionChangedListener(ISelectionChangedListener listener) { + fSelectionChangedListeners.add(listener); + } + + /* + * @see ISelectionProvider#removeSelectionChangedListener + */ + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + fSelectionChangedListeners.remove(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IPostSelectionProvider#addPostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void addPostSelectionChangedListener(ISelectionChangedListener listener) { + fPostSelectionChangedListeners.add(listener); + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IPostSelectionProvider#removePostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void removePostSelectionChangedListener(ISelectionChangedListener listener) { + fPostSelectionChangedListeners.remove(listener); + } + + /* + * @see ISelectionProvider#getSelection + */ + public ISelection getSelection() { + if (fViewerInFocus != null) { + return fViewerInFocus.getSelection(); + } + return StructuredSelection.EMPTY; + } + + /* + * @see ISelectionProvider#setSelection + */ + public void setSelection(ISelection selection) { + if (fViewerInFocus != null) { + fViewerInFocus.setSelection(selection); + } + } + + /** + * Returns the viewer in focus or null if no viewer has the focus + */ + public StructuredViewer getViewerInFocus() { + return fViewerInFocus; + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowInheritedMembersAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowInheritedMembersAction.java new file mode 100644 index 00000000000..c0d73b03abb --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowInheritedMembersAction.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.custom.BusyIndicator; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Action to show / hide inherited members in the method view + * Depending in the action state a different label provider is installed in the viewer + */ +public class ShowInheritedMembersAction extends Action { + + private MethodsViewer fMethodsViewer; + + /** + * Creates the action. + */ + public ShowInheritedMembersAction(MethodsViewer viewer, boolean initValue) { + super(TypeHierarchyMessages.getString("ShowInheritedMembersAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ShowInheritedMembersAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ShowInheritedMembersAction.tooltip")); //$NON-NLS-1$ + +// CPluginImages.setLocalImageDescriptors(this, "inher_co.gif"); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "inher_co.gif"); //$NON-NLS-1$ + + fMethodsViewer= viewer; + + WorkbenchHelp.setHelp(this, ICHelpContextIds.SHOW_INHERITED_ACTION); + + setChecked(initValue); + } + + /* + * @see Action#actionPerformed + */ + public void run() { + BusyIndicator.showWhile(fMethodsViewer.getControl().getDisplay(), new Runnable() { + public void run() { + fMethodsViewer.showInheritedMethods(isChecked()); + } + }); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowQualifiedTypeNamesAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowQualifiedTypeNamesAction.java new file mode 100644 index 00000000000..9a3fee13a93 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ShowQualifiedTypeNamesAction.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.ui.help.WorkbenchHelp; + +import org.eclipse.swt.custom.BusyIndicator; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; + +/** + * Action enable / disable showing qualified type names + */ +public class ShowQualifiedTypeNamesAction extends Action { + + private TypeHierarchyViewPart fView; + + public ShowQualifiedTypeNamesAction(TypeHierarchyViewPart v, boolean initValue) { + super(TypeHierarchyMessages.getString("ShowQualifiedTypeNamesAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ShowQualifiedTypeNamesAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ShowQualifiedTypeNamesAction.tooltip")); //$NON-NLS-1$ + + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "th_showqualified.gif"); //$NON-NLS-1$ + + fView= v; + setChecked(initValue); + + WorkbenchHelp.setHelp(this, ICHelpContextIds.SHOW_QUALIFIED_NAMES_ACTION); + } + + /* + * @see Action#actionPerformed + */ + public void run() { + BusyIndicator.showWhile(fView.getSite().getShell().getDisplay(), new Runnable() { + public void run() { + fView.showQualifiedTypeNames(isChecked()); + } + }); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SortByDefiningTypeAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SortByDefiningTypeAction.java new file mode 100644 index 00000000000..9c621df8140 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SortByDefiningTypeAction.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.custom.BusyIndicator; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Action to let the label provider show the defining type of the method + */ +public class SortByDefiningTypeAction extends Action { + + private MethodsViewer fMethodsViewer; + + /** + * Creates the action. + */ + public SortByDefiningTypeAction(MethodsViewer viewer, boolean initValue) { + super(TypeHierarchyMessages.getString("SortByDefiningTypeAction.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("SortByDefiningTypeAction.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("SortByDefiningTypeAction.tooltip")); //$NON-NLS-1$ + +// CPluginImages.setLocalImageDescriptors(this, "definingtype_sort_co.gif"); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "definingtype_sort_co.gif"); //$NON-NLS-1$ + + fMethodsViewer= viewer; + + WorkbenchHelp.setHelp(this, ICHelpContextIds.SORT_BY_DEFINING_TYPE_ACTION); + + setChecked(initValue); + } + + /* + * @see Action#actionPerformed + */ + public void run() { + BusyIndicator.showWhile(fMethodsViewer.getControl().getDisplay(), new Runnable() { + public void run() { + fMethodsViewer.sortByDefiningType(isChecked()); + } + }); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SubTypeHierarchyViewer.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SubTypeHierarchyViewer.java new file mode 100644 index 00000000000..8f268da67d8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SubTypeHierarchyViewer.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.List; + +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.ui.IWorkbenchPart; + +/** + * A viewer including the content provider for the subtype hierarchy. + * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle + * on construction (shared type hierarchy) + */ +public class SubTypeHierarchyViewer extends TypeHierarchyViewer { + + public SubTypeHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) { + super(parent, new SubTypeHierarchyContentProvider(lifeCycle), lifeCycle, part); + } + + /* + * @see TypeHierarchyViewer#getTitle + */ + public String getTitle() { + if (isMethodFiltering()) { + return TypeHierarchyMessages.getString("SubTypeHierarchyViewer.filtered.title"); //$NON-NLS-1$ + } else { + return TypeHierarchyMessages.getString("SubTypeHierarchyViewer.title"); //$NON-NLS-1$ + } + } + + /* + * @see TypeHierarchyViewer#updateContent + */ + public void updateContent(boolean expand) { + getTree().setRedraw(false); + refresh(); + + if (expand) { + int expandLevel= 2; + if (isMethodFiltering()) { + expandLevel++; + } + expandToLevel(expandLevel); + } + getTree().setRedraw(true); + } + + /** + * Content provider for the subtype hierarchy + */ + public static class SubTypeHierarchyContentProvider extends TypeHierarchyContentProvider { + public SubTypeHierarchyContentProvider(TypeHierarchyLifeCycle lifeCycle) { + super(lifeCycle); + } + + protected final void getTypesInHierarchy(ICElement type, List res) { + ITypeHierarchy hierarchy= getHierarchy(); + if (hierarchy != null) { + ICElement[] types= hierarchy.getSubtypes(type); + if (types != null) { + for (int i= 0; i < types.length; i++) { + res.add(types[i]); + } + } + } + + } + + protected ICElement[] getParentTypes(ICElement type) { + ITypeHierarchy hierarchy= getHierarchy(); + if (hierarchy != null) { + return hierarchy.getSupertypes(type); + // dont handle interfaces + } + return null; + } + +} + + + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SuperTypeHierarchyViewer.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SuperTypeHierarchyViewer.java new file mode 100644 index 00000000000..b8c05eed9e7 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/SuperTypeHierarchyViewer.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.List; + +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.ui.IWorkbenchPart; + +/** + * A viewer including the content provider for the supertype hierarchy. + * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle + * on construction (shared type hierarchy) + */ +public class SuperTypeHierarchyViewer extends TypeHierarchyViewer { + + public SuperTypeHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) { + super(parent, new SuperTypeHierarchyContentProvider(lifeCycle), lifeCycle, part); + } + + /* + * @see TypeHierarchyViewer#getTitle + */ + public String getTitle() { + if (isMethodFiltering()) { + return TypeHierarchyMessages.getString("SuperTypeHierarchyViewer.filtered.title"); //$NON-NLS-1$ + } else { + return TypeHierarchyMessages.getString("SuperTypeHierarchyViewer.title"); //$NON-NLS-1$ + } + } + + /* + * @see TypeHierarchyViewer#updateContent + */ + public void updateContent(boolean expand) { + getTree().setRedraw(false); + refresh(); + if (expand) { + expandAll(); + } + getTree().setRedraw(true); + } + + /* + * Content provider for the supertype hierarchy + */ + public static class SuperTypeHierarchyContentProvider extends TypeHierarchyContentProvider { + public SuperTypeHierarchyContentProvider(TypeHierarchyLifeCycle lifeCycle) { + super(lifeCycle); + } + + protected final void getTypesInHierarchy(ICElement type, List res) { + ITypeHierarchy hierarchy= getHierarchy(); + if (hierarchy != null) { + ICElement[] types= hierarchy.getSupertypes(type); + for (int i= 0; i < types.length; i++) { + res.add(types[i]); + } + } + } + + protected ICElement[] getParentTypes(ICElement type) { + // cant handle + return null; + } + + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleLinkingAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleLinkingAction.java new file mode 100644 index 00000000000..7a1bc876204 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleLinkingAction.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.internal.ui.actions.AbstractToggleLinkingAction; + + +/** + * This action toggles whether the type hierarchy links its selection to the active + * editor. + * + * @since 3.0 + */ +public class ToggleLinkingAction extends AbstractToggleLinkingAction { + + TypeHierarchyViewPart fHierarchyViewPart; + + /** + * Constructs a new action. + */ + public ToggleLinkingAction(TypeHierarchyViewPart part) { + setChecked(part.isLinkingEnabled()); + fHierarchyViewPart= part; + } + + /** + * Runs the action. + */ + public void run() { + fHierarchyViewPart.setLinkingEnabled(isChecked()); + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleOrientationAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleOrientationAction.java new file mode 100644 index 00000000000..906ae2b796b --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleOrientationAction.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.util.Assert; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Toggles the orientationof the layout of the type hierarchy + */ +public class ToggleOrientationAction extends Action { + + private TypeHierarchyViewPart fView; + private int fActionOrientation; + + public ToggleOrientationAction(TypeHierarchyViewPart v, int orientation) { + super("", AS_RADIO_BUTTON); //$NON-NLS-1$ + if (orientation == TypeHierarchyViewPart.VIEW_ORIENTATION_HORIZONTAL) { + setText(TypeHierarchyMessages.getString("ToggleOrientationAction.horizontal.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ToggleOrientationAction.horizontal.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleOrientationAction.horizontal.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "th_horizontal.gif"); //$NON-NLS-1$ + } else if (orientation == TypeHierarchyViewPart.VIEW_ORIENTATION_VERTICAL) { + setText(TypeHierarchyMessages.getString("ToggleOrientationAction.vertical.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ToggleOrientationAction.vertical.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleOrientationAction.vertical.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "th_vertical.gif"); //$NON-NLS-1$ + } else if (orientation == TypeHierarchyViewPart.VIEW_ORIENTATION_AUTOMATIC) { + setText(TypeHierarchyMessages.getString("ToggleOrientationAction.automatic.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ToggleOrientationAction.automatic.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleOrientationAction.automatic.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "th_automatic.gif"); //$NON-NLS-1$ + } else if (orientation == TypeHierarchyViewPart.VIEW_ORIENTATION_SINGLE) { + setText(TypeHierarchyMessages.getString("ToggleOrientationAction.single.label")); //$NON-NLS-1$ + setDescription(TypeHierarchyMessages.getString("ToggleOrientationAction.single.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleOrientationAction.single.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "th_single.gif"); //$NON-NLS-1$ + } else { + Assert.isTrue(false); + } + fView= v; + fActionOrientation= orientation; + WorkbenchHelp.setHelp(this, ICHelpContextIds.TOGGLE_ORIENTATION_ACTION); + } + + public int getOrientation() { + return fActionOrientation; + } + + /* + * @see Action#actionPerformed + */ + public void run() { + if (isChecked()) { + fView.fOrientation= fActionOrientation; + fView.computeOrientation(); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleViewAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleViewAction.java new file mode 100644 index 00000000000..0c355af3fa5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/ToggleViewAction.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.util.Assert; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * Action to switch between the different hierarchy views. + */ +public class ToggleViewAction extends Action { + + private TypeHierarchyViewPart fViewPart; + private int fViewerIndex; + + public ToggleViewAction(TypeHierarchyViewPart v, int viewerIndex) { + super("", AS_RADIO_BUTTON); //$NON-NLS-1$ + String contextHelpId= null; + if (viewerIndex == TypeHierarchyViewPart.VIEW_ID_SUPER) { + setText(TypeHierarchyMessages.getString("ToggleViewAction.supertypes.label")); //$NON-NLS-1$ + contextHelpId= ICHelpContextIds.SHOW_SUPERTYPES; + setDescription(TypeHierarchyMessages.getString("ToggleViewAction.supertypes.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleViewAction.supertypes.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "super_co.gif"); //$NON-NLS-1$ + } else if (viewerIndex == TypeHierarchyViewPart.VIEW_ID_SUB) { + setText(TypeHierarchyMessages.getString("ToggleViewAction.subtypes.label")); //$NON-NLS-1$ + contextHelpId= ICHelpContextIds.SHOW_SUBTYPES; + setDescription(TypeHierarchyMessages.getString("ToggleViewAction.subtypes.description")); //$NON-NLS-1$ + setToolTipText(TypeHierarchyMessages.getString("ToggleViewAction.subtypes.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "sub_co.gif"); //$NON-NLS-1$ + } else { + Assert.isTrue(false); + } + + fViewPart= v; + fViewerIndex= viewerIndex; + + WorkbenchHelp.setHelp(this, contextHelpId); + } + + public int getViewerIndex() { + return fViewerIndex; + } + + /* + * @see Action#actionPerformed + */ + public void run() { + fViewPart.setView(fViewerIndex); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyContentProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyContentProvider.java new file mode 100644 index 00000000000..e10c0fbdd37 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyContentProvider.java @@ -0,0 +1,300 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.browser.IWorkingCopyProvider; +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMember; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.internal.corext.util.CModelUtil; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +/** + * Base class for content providers for type hierarchy viewers. + * Implementors must override 'getTypesInHierarchy'. + * Java delta processing is also performed by the content provider + */ +public abstract class TypeHierarchyContentProvider implements ITreeContentProvider //, IWorkingCopyProvider { +{ + protected static final Object[] NO_ELEMENTS= new Object[0]; + + protected TypeHierarchyLifeCycle fTypeHierarchy; + protected IMember[] fMemberFilter; + + protected TreeViewer fViewer; + + private ViewerFilter fWorkingSetFilter; + + public TypeHierarchyContentProvider(TypeHierarchyLifeCycle lifecycle) { + fTypeHierarchy= lifecycle; + fMemberFilter= null; + fWorkingSetFilter= null; + } + + /** + * Sets members to filter the hierarchy for. Set to null to disable member filtering. + * When member filtering is enabled, the hierarchy contains only types that contain + * an implementation of one of the filter members and the members themself. + * The hierarchy can be empty as well. + */ + public final void setMemberFilter(IMember[] memberFilter) { + fMemberFilter= memberFilter; + } + + /** + * The members to filter or null if member filtering is disabled. + */ + public IMember[] getMemberFilter() { + return fMemberFilter; + } + + /** + * Sets a filter representing a working set or null if working sets are disabled. + */ + public void setWorkingSetFilter(ViewerFilter filter) { + fWorkingSetFilter= filter; + } + + + protected final ITypeHierarchy getHierarchy() { + return fTypeHierarchy.getHierarchy(); + } + + + /* (non-Javadoc) + * @see IReconciled#providesWorkingCopies() + */ + public boolean providesWorkingCopies() { + return true; + } + + + /* + * Called for the root element + * @see IStructuredContentProvider#getElements + */ + public Object[] getElements(Object parent) { + ArrayList types= new ArrayList(); + getRootTypes(types); + for (int i= types.size() - 1; i >= 0; i--) { + ICElement curr= (ICElement) types.get(i); + try { + if (!isInTree(curr)) { + types.remove(i); + } + } catch (CModelException e) { + // ignore + } + } + return types.toArray(); + } + + protected void getRootTypes(List res) { + ITypeHierarchy hierarchy= getHierarchy(); + if (hierarchy != null) { + ICElement input= hierarchy.getType(); + if (input != null) { + res.add(input); + } + // opened on a region: dont show + } + } + + /** + * Hook to overwrite. Filter will be applied on the returned types + */ + protected abstract void getTypesInHierarchy(ICElement type, List res); + + /** + * Hook to overwrite. Return null if parent is ambiguous. + */ + protected abstract ICElement[] getParentTypes(ICElement type); + + + private boolean isInScope(ICElement type) { + if (fWorkingSetFilter != null && !fWorkingSetFilter.select(null, null, type)) { + return false; + } + +// ICElement input= fTypeHierarchy.getInputElement(); +// int inputType= input.getElementType(); +// if (inputType == ICElement.TYPE) { +// return true; +// } +// +// ICElement parent= type.getAncestor(input.getElementType()); +// if (inputType == ICElement.PACKAGE_FRAGMENT) { +// if (parent == null || parent.getElementName().equals(input.getElementName())) { +// return true; +// } +// } else if (input.equals(parent)) { +// return true; +// } + return true; + } + + /* + * Called for the tree children. + * @see ITreeContentProvider#getChildren + */ + public Object[] getChildren(Object element) { + if (element instanceof ICElement) { + try { + ICElement type= (ICElement)element; + + List children= new ArrayList(); + if (fMemberFilter != null) { + addFilteredMemberChildren(type, children); + } + + addTypeChildren(type, children); + + return children.toArray(); + } catch (CModelException e) { + // ignore + } + } + return NO_ELEMENTS; + } + + /* + * @see ITreeContentProvider#hasChildren + */ + public boolean hasChildren(Object element) { + if (element instanceof ICElement) { + try { + ICElement type= (ICElement) element; + return hasTypeChildren(type) || (fMemberFilter != null && hasMemberFilterChildren(type)); + } catch (CModelException e) { + return false; + } + } + return false; + } + + private void addFilteredMemberChildren(ICElement parent, List children) throws CModelException { + IMethodDeclaration[] methods= TypeUtil.getMethods(parent); + if (methods != null && methods.length > 0) { + for (int i= 0; i < fMemberFilter.length; i++) { + IMember member= fMemberFilter[i]; + if (parent.equals(TypeUtil.getDeclaringType(member))) { + if (!children.contains(member)) { + children.add(member); + } + } else if (member instanceof IMethodDeclaration) { + IMethodDeclaration curr= (IMethodDeclaration)member; + IMethodDeclaration meth= TypeUtil.findMethod(curr.getElementName(), curr.getParameterTypes(), curr.isConstructor(), curr.isDestructor(), methods); + if (meth != null && !children.contains(meth)) { + children.add(meth); + } + } + } + } + } + + private void addTypeChildren(ICElement type, List children) throws CModelException { + ArrayList types= new ArrayList(); + getTypesInHierarchy(type, types); + int len= types.size(); + for (int i= 0; i < len; i++) { + ICElement curr= (ICElement) types.get(i); + if (isInTree(curr)) { + children.add(curr); + } + } + } + + protected final boolean isInTree(ICElement type) throws CModelException { + if (isInScope(type)) { + if (fMemberFilter != null) { + return hasMemberFilterChildren(type) || hasTypeChildren(type); + } else { + return true; + } + } + return hasTypeChildren(type); + } + + private boolean hasMemberFilterChildren(ICElement type) throws CModelException { + IMethodDeclaration[] methods= TypeUtil.getMethods(type); + if (methods != null && methods.length > 0) { + for (int i= 0; i < fMemberFilter.length; i++) { + IMember member= fMemberFilter[i]; + if (type.equals(TypeUtil.getDeclaringType(member))) { + return true; + } else if (member instanceof IMethodDeclaration) { + IMethodDeclaration curr= (IMethodDeclaration)member; + IMethodDeclaration meth= TypeUtil.findMethod(curr.getElementName(), curr.getParameterTypes(), curr.isConstructor(), curr.isDestructor(), methods); + if (meth != null) { + return true; + } + } + } + } + return false; + } + + + private boolean hasTypeChildren(ICElement type) throws CModelException { + ArrayList types= new ArrayList(); + getTypesInHierarchy(type, types); + int len= types.size(); + for (int i= 0; i < len; i++) { + ICElement curr= (ICElement) types.get(i); + if (isInTree(curr)) { + return true; + } + } + return false; + } + + /* + * @see IContentProvider#inputChanged + */ + public void inputChanged(Viewer part, Object oldInput, Object newInput) { + Assert.isTrue(part instanceof TreeViewer); + fViewer= (TreeViewer)part; + } + + /* + * @see IContentProvider#dispose + */ + public void dispose() { + } + + /* + * @see ITreeContentProvider#getParent + */ + public Object getParent(Object element) { + if (element instanceof IMember) { + IMember member= (IMember) element; +// if (member.getElementType() == ICElement.TYPE) { + if (TypeUtil.isClassOrStruct(member)) { + ICElement[] parents= getParentTypes(member); + if (parents != null && parents.length == 1) + return parents[0]; + } + return TypeUtil.getDeclaringType(member); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyLifeCycle.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyLifeCycle.java new file mode 100644 index 00000000000..7c0796887ed --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyLifeCycle.java @@ -0,0 +1,285 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.browser.AllTypesCache; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchyChangedListener; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ElementChangedEvent; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICElementDelta; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IElementChangedListener; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.operation.IRunnableWithProgress; + +/** + * Manages a type hierarchy, to keep it refreshed, and to allow it to be shared. + */ +public class TypeHierarchyLifeCycle implements ITypeHierarchyChangedListener, IElementChangedListener { + + private boolean fHierarchyRefreshNeeded; + private ITypeHierarchy fHierarchy; + private ICElement fInputElement; + private boolean fIsSuperTypesOnly; + + private List fChangeListeners; + + public TypeHierarchyLifeCycle() { + this(true); + } + + public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { + fHierarchy= null; + fInputElement= null; + fIsSuperTypesOnly= isSuperTypesOnly; + fChangeListeners= new ArrayList(2); + } + + public ITypeHierarchy getHierarchy() { + return fHierarchy; + } + + public ICElement getInputElement() { + return fInputElement; + } + + + public void freeHierarchy() { + if (fHierarchy != null) { + fHierarchy.removeTypeHierarchyChangedListener(this); + CoreModel.getDefault().removeElementChangedListener(this); + fHierarchy= null; + fInputElement= null; + } + } + + public void removeChangedListener(ITypeHierarchyLifeCycleListener listener) { + fChangeListeners.remove(listener); + } + + public void addChangedListener(ITypeHierarchyLifeCycleListener listener) { + if (!fChangeListeners.contains(listener)) { + fChangeListeners.add(listener); + } + } + + private void fireChange(ICElement[] changedTypes) { + for (int i= fChangeListeners.size()-1; i>=0; i--) { + ITypeHierarchyLifeCycleListener curr= (ITypeHierarchyLifeCycleListener) fChangeListeners.get(i); + curr.typeHierarchyChanged(this, changedTypes); + } + } + + public void ensureRefreshedTypeHierarchy(final ICElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { + if (element == null || !element.exists()) { + freeHierarchy(); + return; + } + boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); + + if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { + + IRunnableWithProgress op= new IRunnableWithProgress() { + public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { + try { + doHierarchyRefresh(element, pm); + } catch (CModelException e) { + throw new InvocationTargetException(e); + } catch (OperationCanceledException e) { + throw new InterruptedException(); + } + } + }; + fHierarchyRefreshNeeded= true; + context.run(true, true, op); + fHierarchyRefreshNeeded= false; + } + } + + private ITypeHierarchy createTypeHierarchy(ICElement element, IProgressMonitor pm) throws CModelException { + if (element.getElementType() == ICElement.C_CLASS + || element.getElementType() == ICElement.C_STRUCT) { + return AllTypesCache.createTypeHierarchy(element, pm); + } +// if (element.getElementType() == ICElement.TYPE) { +// IType type= (IType) element; +// if (fIsSuperTypesOnly) { +// return type.newSupertypeHierarchy(pm); +// } else { +// return type.newTypeHierarchy(pm); +// } +// } else { +// IRegion region= JavaCore.newRegion(); +// if (element.getElementType() == ICElement.JAVA_PROJECT) { +// // for projects only add the contained source folders +// IPackageFragmentRoot[] roots= ((IJavaProject) element).getPackageFragmentRoots(); +// for (int i= 0; i < roots.length; i++) { +// if (!roots[i].isExternal()) { +// region.add(roots[i]); +// } +// } +// } else if (element.getElementType() == ICElement.PACKAGE_FRAGMENT) { +// IPackageFragmentRoot[] roots= element.getJavaProject().getPackageFragmentRoots(); +// String name= element.getElementName(); +// for (int i= 0; i < roots.length; i++) { +// IPackageFragment pack= roots[i].getPackageFragment(name); +// if (pack.exists()) { +// region.add(pack); +// } +// } +// } else { +// region.add(element); +// } +// ICProject jproject= element.getCProject(); +// return jproject.newTypeHierarchy(region, pm); +// } + return null; + } + + + public synchronized void doHierarchyRefresh(ICElement element, IProgressMonitor pm) throws CModelException { + boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); + // to ensure the order of the two listeners always remove / add listeners on operations + // on type hierarchies + if (fHierarchy != null) { + fHierarchy.removeTypeHierarchyChangedListener(this); + CoreModel.getDefault().removeElementChangedListener(this); + } + if (hierachyCreationNeeded) { + fHierarchy= createTypeHierarchy(element, pm); + if (pm != null && pm.isCanceled()) { + throw new OperationCanceledException(); + } + fInputElement= element; + } else if (fHierarchy != null) { + fHierarchy.refresh(pm); + } + if (fHierarchy != null) { + fHierarchy.addTypeHierarchyChangedListener(this); + } + CoreModel.getDefault().addElementChangedListener(this); + fHierarchyRefreshNeeded= false; + } + + /* + * @see ITypeHierarchyChangedListener#typeHierarchyChanged + */ + public void typeHierarchyChanged(ITypeHierarchy typeHierarchy) { + fHierarchyRefreshNeeded= true; + fireChange(null); + } + + /* + * @see IElementChangedListener#elementChanged(ElementChangedEvent) + */ + public void elementChanged(ElementChangedEvent event) { + if (fChangeListeners.isEmpty()) { + return; + } + + if (fHierarchyRefreshNeeded) { + return; + } else { + ArrayList changedTypes= new ArrayList(); + processDelta(event.getDelta(), changedTypes); + if (changedTypes.size() > 0) { + fireChange((ICElement[]) changedTypes.toArray(new ICElement[changedTypes.size()])); + } + } + } + + /* + * Assume that the hierarchy is intact (no refresh needed) + */ + private void processDelta(ICElementDelta delta, ArrayList changedTypes) { + ICElement element= delta.getElement(); + switch (element.getElementType()) { +// case ICElement.TYPE: + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + processTypeDelta((ICElement) element, changedTypes); + processChildrenDelta(delta, changedTypes); // (inner types) + break; + case ICElement.C_MODEL: + case ICElement.C_PROJECT: +// case ICElement.PACKAGE_FRAGMENT_ROOT: +// case ICElement.PACKAGE_FRAGMENT: + processChildrenDelta(delta, changedTypes); + break; + case ICElement.C_UNIT: + ITranslationUnit cu= (ITranslationUnit)element; +// if (!CModelUtil.isPrimary(cu)) { +// return; +// } + + if (delta.getKind() == ICElementDelta.CHANGED && isPossibleStructuralChange(delta.getFlags())) { +// try { + if (cu.exists()) { +// IType[] types= cu.getAllTypes(); + ICElement[] types= getAllTypesForTranslationUnit(cu); for (int i= 0; i < types.length; i++) { + processTypeDelta(types[i], changedTypes); + } + } +// } catch (CModelException e) { +// CUIPlugin.getDefault().log(e); +// } + } else { + processChildrenDelta(delta, changedTypes); + } + break; +// case ICElement.CLASS_FILE: +// if (delta.getKind() == ICElementDelta.CHANGED) { +// try { +// IType type= ((IClassFile) element).getType(); +// processTypeDelta(type, changedTypes); +// } catch (CModelException e) { +// CUIPlugin.getDefault().log(e); +// } +// } else { +// processChildrenDelta(delta, changedTypes); +// } +// break; + } + } + + private boolean isPossibleStructuralChange(int flags) { + return (flags & (ICElementDelta.F_CONTENT | ICElementDelta.F_FINE_GRAINED)) == ICElementDelta.F_CONTENT; + } + + private void processTypeDelta(ICElement type, ArrayList changedTypes) { + if (getHierarchy().contains(type)) { + changedTypes.add(type); + } + } + + private void processChildrenDelta(ICElementDelta delta, ArrayList changedTypes) { + ICElementDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + processDelta(children[i], changedTypes); // recursive + } + } + + private static ICElement[] getAllTypesForTranslationUnit(ITranslationUnit unit) { + return null; + } + + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.java new file mode 100644 index 00000000000..c8016cf95fd --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class TypeHierarchyMessages { + + private static final String RESOURCE_BUNDLE= TypeHierarchyMessages.class.getName(); + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private TypeHierarchyMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + */ + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } + + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.properties b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.properties index c1fa704b44f..20bf0aa4415 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.properties +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyMessages.properties @@ -7,18 +7,8 @@ # # Contributors: # IBM Corporation - initial API and implementation -############################################################################### -#******************************************************************************* -# Copyright (c) 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation # QNX Software Systems - adapted for use in CDT -#*******************************************************************************/ +############################################################################### EnableMemberFilterAction.label=Members in Hierarchy EnableMemberFilterAction.tooltip=Lock View and Show Members in Hierarchy @@ -32,6 +22,10 @@ ToggleOrientationAction.vertical.label=Vertical View Orientation ToggleOrientationAction.vertical.tooltip=Vertical View Orientation ToggleOrientationAction.vertical.description=Vertical View Orientation +ToggleOrientationAction.automatic.label=Automatic View Orientation +ToggleOrientationAction.automatic.tooltip=Automatic View Orientation +ToggleOrientationAction.automatic.description=Automatic View Orientation + ToggleOrientationAction.single.label=Hierarchy View Only ToggleOrientationAction.single.tooltip=Hierarchy View Only ToggleOrientationAction.single.description=Hierarchy View Only @@ -82,7 +76,6 @@ TypeHierarchyViewPart.error.title=Open Type Hierarchy TypeHierarchyViewPart.error.message=The selected element only exists in the editor. To perform this operation you have to save the editor first. TypeHierarchyViewPart.empty=To display the type hierarchy, select a type (for example in the outline view or in the editor), and select the \'Open Type Hierarchy\' menu option. Alternatively, you can drag and drop an element (e.g. project, package, type) onto this view. TypeHierarchyViewPart.nodecl=No declarations of selected members\nin the chosen hierarchy of ''{0}'' - TypeHierarchyViewPart.exception.title=Type Hierarchy TypeHierarchyViewPart.exception.message=Creating hierarchy failed. Check log for details. diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewPart.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewPart.java new file mode 100644 index 00000000000..f9f086736d1 --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewPart.java @@ -0,0 +1,1601 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.browser.TypeUtil; +import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMember; +import org.eclipse.cdt.core.model.IStructure; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.ui.IContextMenuConstants; +import org.eclipse.cdt.internal.ui.actions.CompositeActionGroup; +import org.eclipse.cdt.internal.ui.actions.SelectAllAction; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.CUILabelProvider; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.StatusBarUpdater; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider; +import org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilterActionGroup; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; +import org.eclipse.cdt.ui.actions.OpenViewActionGroup; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.IBasicPropertyConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.ViewForm; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.part.IShowInSource; +import org.eclipse.ui.part.IShowInTargetList; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.ShowInContext; +import org.eclipse.ui.part.ViewPart; + +/** + * view showing the super types/sub types of its input. + */ +public class TypeHierarchyViewPart extends ViewPart implements ITypeHierarchyViewPart, IViewPartInputProvider { + +// public static final int VIEW_ID_TYPE= 2; + public static final int VIEW_ID_SUPER= 0; + public static final int VIEW_ID_SUB= 1; + + public static final int VIEW_ORIENTATION_VERTICAL= 0; + public static final int VIEW_ORIENTATION_HORIZONTAL= 1; + public static final int VIEW_ORIENTATION_SINGLE= 2; + public static final int VIEW_ORIENTATION_AUTOMATIC= 3; + + private static final String DIALOGSTORE_HIERARCHYVIEW= "TypeHierarchyViewPart.hierarchyview"; //$NON-NLS-1$ + private static final String DIALOGSTORE_VIEWORIENTATION= "TypeHierarchyViewPart.orientation"; //$NON-NLS-1$ + + private static final String TAG_INPUT= "input"; //$NON-NLS-1$ + private static final String TAG_VIEW= "view"; //$NON-NLS-1$ + private static final String TAG_ORIENTATION= "orientation"; //$NON-NLS-1$ + private static final String TAG_RATIO= "ratio"; //$NON-NLS-1$ + private static final String TAG_SELECTION= "selection"; //$NON-NLS-1$ + private static final String TAG_VERTICAL_SCROLL= "vertical_scroll"; //$NON-NLS-1$ + + private static final String GROUP_FOCUS= "group.focus"; //$NON-NLS-1$ + + + // the selected type in the hierarchy view + private ICElement fSelectedType; + // input element or null + private ICElement fInputElement; + + // history of input elements. No duplicates + private ArrayList fInputHistory; + + private IMemento fMemento; +// private IDialogSettings fDialogSettings; + + private TypeHierarchyLifeCycle fHierarchyLifeCycle; + private ITypeHierarchyLifeCycleListener fTypeHierarchyLifeCycleListener; + + private IPropertyChangeListener fPropertyChangeListener; + + private SelectionProviderMediator fSelectionProviderMediator; + private ISelectionChangedListener fSelectionChangedListener; + private IPartListener2 fPartListener; + + private int fCurrentOrientation; + int fOrientation= VIEW_ORIENTATION_AUTOMATIC; + boolean fInComputeOrientation= false; + + private boolean fLinkingEnabled; + private boolean fSelectInEditor; + + private boolean fIsVisible; + private boolean fNeedRefresh; + private boolean fIsEnableMemberFilter; + private boolean fIsRefreshRunnablePosted; + + private int fCurrentViewerIndex; + private TypeHierarchyViewer[] fAllViewers; + + private MethodsViewer fMethodsViewer; + + private SashForm fTypeMethodsSplitter; + private PageBook fViewerbook; + private PageBook fPagebook; + + private Label fNoHierarchyShownLabel; + private Label fEmptyTypesViewer; + + private ViewForm fTypeViewerViewForm; + private ViewForm fMethodViewerViewForm; + + private CLabel fMethodViewerPaneLabel; + private CUILabelProvider fPaneLabelProvider; + private Composite fParent; + + private ToggleViewAction[] fViewActions; + private ToggleLinkingAction fToggleLinkingAction; + private HistoryDropDownAction fHistoryDropDownAction; + private ToggleOrientationAction[] fToggleOrientationActions; + private EnableMemberFilterAction fEnableMemberFilterAction; + private ShowQualifiedTypeNamesAction fShowQualifiedTypeNamesAction; +// private AddMethodStubAction fAddStubAction; + private FocusOnTypeAction fFocusOnTypeAction; + private FocusOnSelectionAction fFocusOnSelectionAction; + private CompositeActionGroup fActionGroups; + private SelectAllAction fSelectAllAction; + + private WorkingSetFilterActionGroup fWorkingSetActionGroup; + private Job fRestoreStateJob; + + public TypeHierarchyViewPart() { + fSelectedType= null; + fInputElement= null; + fIsVisible= false; + fIsRefreshRunnablePosted= false; + fSelectInEditor= true; + fRestoreStateJob= null; + + fHierarchyLifeCycle= new TypeHierarchyLifeCycle(); + fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() { + public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, ICElement[] changedTypes) { + doTypeHierarchyChanged(typeHierarchy, changedTypes); + } + }; + fHierarchyLifeCycle.addChangedListener(fTypeHierarchyLifeCycleListener); + + fPropertyChangeListener= new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + doPropertyChange(event); + } + }; + PreferenceConstants.getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener); + + fIsEnableMemberFilter= false; + + fInputHistory= new ArrayList(); + fAllViewers= null; + + fViewActions= new ToggleViewAction[] { +// new ToggleViewAction(this, VIEW_ID_TYPE), + new ToggleViewAction(this, VIEW_ID_SUPER), + new ToggleViewAction(this, VIEW_ID_SUB) + }; + +// fDialogSettings= CPlugin.getDefault().getDialogSettings(); +// + fHistoryDropDownAction= new HistoryDropDownAction(this); + fHistoryDropDownAction.setEnabled(false); + + fToggleOrientationActions= new ToggleOrientationAction[] { + new ToggleOrientationAction(this, VIEW_ORIENTATION_VERTICAL), + new ToggleOrientationAction(this, VIEW_ORIENTATION_HORIZONTAL), + new ToggleOrientationAction(this, VIEW_ORIENTATION_AUTOMATIC), + new ToggleOrientationAction(this, VIEW_ORIENTATION_SINGLE) + }; + + fEnableMemberFilterAction= new EnableMemberFilterAction(this, false); + fShowQualifiedTypeNamesAction= new ShowQualifiedTypeNamesAction(this, false); + + fFocusOnTypeAction= new FocusOnTypeAction(this); + + fPaneLabelProvider= new CUILabelProvider(); +// +// fAddStubAction= new AddMethodStubAction(); + fFocusOnSelectionAction= new FocusOnSelectionAction(this); + + fPartListener= new IPartListener2() { + public void partVisible(IWorkbenchPartReference ref) { + IWorkbenchPart part= ref.getPart(false); + if (part == TypeHierarchyViewPart.this) { + visibilityChanged(true); + } + } + + public void partHidden(IWorkbenchPartReference ref) { + IWorkbenchPart part= ref.getPart(false); + if (part == TypeHierarchyViewPart.this) { + visibilityChanged(false); + } + } + + public void partActivated(IWorkbenchPartReference ref) { + IWorkbenchPart part= ref.getPart(false); + if (part instanceof IEditorPart) + editorActivated((IEditorPart) part); + } + + public void partInputChanged(IWorkbenchPartReference ref) { + IWorkbenchPart part= ref.getPart(false); + if (part instanceof IEditorPart) + editorActivated((IEditorPart) part); + } + + public void partBroughtToTop(IWorkbenchPartReference ref) {} + public void partClosed(IWorkbenchPartReference ref) {} + public void partDeactivated(IWorkbenchPartReference ref) {} + public void partOpened(IWorkbenchPartReference ref) {} + }; + + fSelectionChangedListener= new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + doSelectionChanged(event); + } + }; + + fLinkingEnabled= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR); + } + + /** + * Method doPropertyChange. + * @param event + */ + protected void doPropertyChange(PropertyChangeEvent event) { + String property= event.getProperty(); + if (fMethodsViewer != null) { +// if (MembersOrderPreferenceCache.isMemberOrderProperty(event.getProperty())) { +// fMethodsViewer.refresh(); +// } + } + if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) { + updateHierarchyViewer(true); + } + } + + /** + * Adds the entry if new. Inserted at the beginning of the history entries list. + */ + private void addHistoryEntry(ICElement entry) { + if (fInputHistory.contains(entry)) { + fInputHistory.remove(entry); + } + fInputHistory.add(0, entry); + fHistoryDropDownAction.setEnabled(true); + } + + private void updateHistoryEntries() { + for (int i= fInputHistory.size() - 1; i >= 0; i--) { + ICElement type= (ICElement) fInputHistory.get(i); + if (!type.exists()) { + fInputHistory.remove(i); + } + } + fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty()); + } + + /** + * Goes to the selected entry, without updating the order of history entries. + */ + public void gotoHistoryEntry(ICElement entry) { + if (fInputHistory.contains(entry)) { + updateInput(entry); + } + } + + /** + * Gets all history entries. + */ + public ICElement[] getHistoryEntries() { + if (fInputHistory.size() > 0) { + updateHistoryEntries(); + } + return (ICElement[]) fInputHistory.toArray(new ICElement[fInputHistory.size()]); + } + + /** + * Sets the history entries + */ + public void setHistoryEntries(ICElement[] elems) { + fInputHistory.clear(); + for (int i= 0; i < elems.length; i++) { + fInputHistory.add(elems[i]); + } + updateHistoryEntries(); + } + + /** + * Selects an member in the methods list or in the current hierarchy. + */ + public void selectMember(ICElement member) { + fSelectInEditor= false; +// if (member.getElementType() != ICElement.TYPE) { + if (!(member instanceof IStructure)) { + Control methodControl= fMethodsViewer.getControl(); + if (methodControl != null && !methodControl.isDisposed()) { + methodControl.setFocus(); + } + + fMethodsViewer.setSelection(new StructuredSelection(member), true); + } else { + Control viewerControl= getCurrentViewer().getControl(); + if (viewerControl != null && !viewerControl.isDisposed()) { + viewerControl.setFocus(); + } + + if (!member.equals(fSelectedType)) { + getCurrentViewer().setSelection(new StructuredSelection(member), true); + } + } + fSelectInEditor= true; + } + + /** + * @deprecated + */ + public ICElement getInput() { + if (fInputElement instanceof ICElement) { + return (ICElement) fInputElement; + } + return null; + } + + /** + * Sets the input to a new type + * @deprecated + */ + public void setInput(ICElement type) { + setInputElement(type); + } + + /** + * Returns the input element of the type hierarchy. + * Can be of type ICElement or IPackageFragment + */ + public ICElement getInputElement() { + return fInputElement; + } + + + /** + * Sets the input to a new element. + */ + public void setInputElement(ICElement element) { + if (element != null) { + if (!(element instanceof IStructure)) { + element = TypeUtil.getDeclaringType(element); + } + if (element == null || !element.exists()) { + MessageDialog.openError(getSite().getShell(), TypeHierarchyMessages.getString("TypeHierarchyViewPart.error.title"), TypeHierarchyMessages.getString("TypeHierarchyViewPart.error.message")); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + } else { + CUIPlugin.getDefault().logErrorMessage("Invalid type hierarchy input type.");//$NON-NLS-1$ + } + if (element != null && !element.equals(fInputElement)) { + addHistoryEntry(element); + } + + updateInput(element); + } + + /** + * Changes the input to a new type + */ + private void updateInput(ICElement inputElement) { + ICElement prevInput= fInputElement; + + synchronized (this) { + if (fRestoreStateJob != null) { + fRestoreStateJob.cancel(); + try { + fRestoreStateJob.join(); + } catch (InterruptedException e) { + // ignore + } finally { + fRestoreStateJob= null; + } + } + } + + // Make sure the UI got repainted before we execute a long running + // operation. This can be removed if we refresh the hierarchy in a + // separate thread. + // Work-araound for http://dev.eclipse.org/bugs/show_bug.cgi?id=30881 + processOutstandingEvents(); + if (inputElement == null) { + clearInput(); + } else { + fInputElement= inputElement; + try { + fHierarchyLifeCycle.ensureRefreshedTypeHierarchy(inputElement, CUIPlugin.getActiveWorkbenchWindow()); + // fHierarchyLifeCycle.ensureRefreshedTypeHierarchy(inputElement, getSite().getWorkbenchWindow()); + } catch (InvocationTargetException e) { + ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.getString("TypeHierarchyViewPart.exception.title"), TypeHierarchyMessages.getString("TypeHierarchyViewPart.exception.message")); //$NON-NLS-1$ //$NON-NLS-2$ + clearInput(); + return; + } catch (InterruptedException e) { + return; + } + +// if (inputElement.getElementType() != ICElement.TYPE) { + if (!(inputElement instanceof IStructure)) { +// setView(VIEW_ID_TYPE); + setView(VIEW_ID_SUPER); + } + // turn off member filtering + fSelectInEditor= false; + setMemberFilter(null); + internalSelectType(null, false); // clear selection + fIsEnableMemberFilter= false; + if (!inputElement.equals(prevInput)) { + updateHierarchyViewer(true); + } + ICElement root= getSelectableType(inputElement); + internalSelectType(root, true); + updateMethodViewer(root); + updateToolbarButtons(); + updateTitle(); + enableMemberFilter(false); + fPagebook.showPage(fTypeMethodsSplitter); + fSelectInEditor= true; + } + } + + private void processOutstandingEvents() { + Display display= getDisplay(); + if (display != null && !display.isDisposed()) + display.update(); + } + + private void clearInput() { + fInputElement= null; + fHierarchyLifeCycle.freeHierarchy(); + + updateHierarchyViewer(false); + updateToolbarButtons(); + } + + /* + * @see IWorbenchPart#setFocus + */ + public void setFocus() { + fPagebook.setFocus(); + } + + /* + * @see IWorkbenchPart#dispose + */ + public void dispose() { + fHierarchyLifeCycle.freeHierarchy(); + fHierarchyLifeCycle.removeChangedListener(fTypeHierarchyLifeCycleListener); + fPaneLabelProvider.dispose(); + + if (fMethodsViewer != null) { + fMethodsViewer.dispose(); + } + + if (fPropertyChangeListener != null) { + CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener); + fPropertyChangeListener= null; + } + + getSite().getPage().removePartListener(fPartListener); + + if (fActionGroups != null) + fActionGroups.dispose(); + + if (fWorkingSetActionGroup != null) { + fWorkingSetActionGroup.dispose(); + } + + super.dispose(); + } + + /** + * Answer the property defined by key. + */ + public Object getAdapter(Class key) { + if (key == IShowInSource.class) { + return getShowInSource(); + } + if (key == IShowInTargetList.class) { + return new IShowInTargetList() { + public String[] getShowInTargetIds() { + return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_RES_NAV }; + } + + }; + } + return super.getAdapter(key); + } + + private Control createTypeViewerControl(Composite parent) { + fViewerbook= new PageBook(parent, SWT.NULL); + + KeyListener keyListener= createKeyListener(); + + // Create the viewers + TypeHierarchyViewer superTypesViewer= new SuperTypeHierarchyViewer(fViewerbook, fHierarchyLifeCycle, this); + initializeTypesViewer(superTypesViewer, keyListener, IContextMenuConstants.TARGET_ID_SUPERTYPES_VIEW); + + TypeHierarchyViewer subTypesViewer= new SubTypeHierarchyViewer(fViewerbook, fHierarchyLifeCycle, this); + initializeTypesViewer(subTypesViewer, keyListener, IContextMenuConstants.TARGET_ID_SUBTYPES_VIEW); + +// TypeHierarchyViewer vajViewer= new TraditionalHierarchyViewer(fViewerbook, fHierarchyLifeCycle, this); +// initializeTypesViewer(vajViewer, keyListener, IContextMenuConstants.TARGET_ID_HIERARCHY_VIEW); + +// fAllViewers= new TypeHierarchyViewer[3]; + fAllViewers= new TypeHierarchyViewer[2]; + fAllViewers[VIEW_ID_SUPER]= superTypesViewer; + fAllViewers[VIEW_ID_SUB]= subTypesViewer; +// fAllViewers[VIEW_ID_TYPE]= vajViewer; + + int currViewerIndex; +// try { +// currViewerIndex= fDialogSettings.getInt(DIALOGSTORE_HIERARCHYVIEW); +// if (currViewerIndex < 0 || currViewerIndex > 2) { +// currViewerIndex= VIEW_ID_TYPE; +// } +// } catch (NumberFormatException e) { +// currViewerIndex= VIEW_ID_TYPE; +// } + currViewerIndex= VIEW_ID_SUPER; + + fEmptyTypesViewer= new Label(fViewerbook, SWT.LEFT); + + for (int i= 0; i < fAllViewers.length; i++) { + fAllViewers[i].setInput(fAllViewers[i]); + } + + // force the update + fCurrentViewerIndex= -1; + setView(currViewerIndex); + + return fViewerbook; + } + + private KeyListener createKeyListener() { + return new KeyAdapter() { + public void keyReleased(KeyEvent event) { + if (event.stateMask == 0) { + if (event.keyCode == SWT.F5) { + ITypeHierarchy hierarchy= fHierarchyLifeCycle.getHierarchy(); + if (hierarchy != null) { + fHierarchyLifeCycle.typeHierarchyChanged(hierarchy); + doTypeHierarchyChangedOnViewers(null); + } + updateHierarchyViewer(false); + return; + } + } + } + }; + } + + + private void initializeTypesViewer(final TypeHierarchyViewer typesViewer, KeyListener keyListener, String cotextHelpId) { + typesViewer.getControl().setVisible(false); + typesViewer.getControl().addKeyListener(keyListener); + typesViewer.initContextMenu(new IMenuListener() { + public void menuAboutToShow(IMenuManager menu) { + fillTypesViewerContextMenu(typesViewer, menu); + } + }, cotextHelpId, getSite()); + typesViewer.addPostSelectionChangedListener(fSelectionChangedListener); + typesViewer.setQualifiedTypeName(isShowQualifiedTypeNames()); + typesViewer.setWorkingSetFilter(fWorkingSetActionGroup.getWorkingSetFilter()); + } + + private Control createMethodViewerControl(Composite parent) { + fMethodsViewer= new MethodsViewer(parent, fHierarchyLifeCycle, this); + fMethodsViewer.initContextMenu(new IMenuListener() { + public void menuAboutToShow(IMenuManager menu) { + fillMethodsViewerContextMenu(menu); + } + }, IContextMenuConstants.TARGET_ID_MEMBERS_VIEW, getSite()); + fMethodsViewer.addPostSelectionChangedListener(fSelectionChangedListener); + + Control control= fMethodsViewer.getTable(); + control.addKeyListener(createKeyListener()); + control.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + fSelectAllAction.setEnabled(true); + } + + public void focusLost(FocusEvent e) { + fSelectAllAction.setEnabled(false); + } + }); + + return control; + } + + private void initDragAndDrop() { +// Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance() }; +// int ops= DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; +// +// for (int i= 0; i < fAllViewers.length; i++) { +// addDragAdapters(fAllViewers[i], ops, transfers); +// addDropAdapters(fAllViewers[i], ops | DND.DROP_DEFAULT, transfers); +// } +// addDragAdapters(fMethodsViewer, ops, transfers); +// +// //DND on empty hierarchy +// DropTarget dropTarget = new DropTarget(fNoHierarchyShownLabel, ops | DND.DROP_DEFAULT); +// dropTarget.setTransfer(transfers); +// dropTarget.addDropListener(new TypeHierarchyTransferDropAdapter(this, fAllViewers[0])); + } + + private void addDropAdapters(AbstractTreeViewer viewer, int ops, Transfer[] transfers){ +// TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] { +// new TypeHierarchyTransferDropAdapter(this, viewer) +// }; +// viewer.addDropSupport(ops, transfers, new DelegatingDropAdapter(dropListeners)); + } + + private void addDragAdapters(StructuredViewer viewer, int ops, Transfer[] transfers) { +// TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] { +// new SelectionTransferDragAdapter(viewer) +// }; +// viewer.addDragSupport(ops, transfers, new JdtViewerDragAdapter(viewer, dragListeners)); + } + + /** + * Returns the inner component in a workbench part. + * @see IWorkbenchPart#createPartControl(Composite) + */ + public void createPartControl(Composite container) { + fParent= container; + addResizeListener(container); + + fPagebook= new PageBook(container, SWT.NONE); + fWorkingSetActionGroup= new WorkingSetFilterActionGroup(CUIPlugin.ID_TYPE_HIERARCHY, container.getShell(), fPropertyChangeListener); + + // page 1 of page book (no hierarchy label) + + fNoHierarchyShownLabel= new Label(fPagebook, SWT.TOP + SWT.LEFT + SWT.WRAP); + fNoHierarchyShownLabel.setText(TypeHierarchyMessages.getString("TypeHierarchyViewPart.empty")); //$NON-NLS-1$ + + // page 2 of page book (viewers) + + fTypeMethodsSplitter= new SashForm(fPagebook, SWT.VERTICAL); + fTypeMethodsSplitter.setVisible(false); + + fTypeViewerViewForm= new ViewForm(fTypeMethodsSplitter, SWT.NONE); + + Control typeViewerControl= createTypeViewerControl(fTypeViewerViewForm); + fTypeViewerViewForm.setContent(typeViewerControl); + + fMethodViewerViewForm= new ViewForm(fTypeMethodsSplitter, SWT.NONE); + fTypeMethodsSplitter.setWeights(new int[] {35, 65}); + + Control methodViewerPart= createMethodViewerControl(fMethodViewerViewForm); + fMethodViewerViewForm.setContent(methodViewerPart); + + fMethodViewerPaneLabel= new CLabel(fMethodViewerViewForm, SWT.NONE); + fMethodViewerViewForm.setTopLeft(fMethodViewerPaneLabel); + + ToolBar methodViewerToolBar= new ToolBar(fMethodViewerViewForm, SWT.FLAT | SWT.WRAP); + fMethodViewerViewForm.setTopCenter(methodViewerToolBar); + + initDragAndDrop(); + + MenuManager menu= new MenuManager(); + menu.add(fFocusOnTypeAction); + fNoHierarchyShownLabel.setMenu(menu.createContextMenu(fNoHierarchyShownLabel)); + + fPagebook.showPage(fNoHierarchyShownLabel); + +// try { +// fOrientation= fDialogSettings.getInt(DIALOGSTORE_VIEWORIENTATION); +// if (fOrientation < 0 || fOrientation > 3) { +// fOrientation= VIEW_ORIENTATION_VERTICAL; +// } +// } catch (NumberFormatException e) { +// fOrientation= VIEW_ORIENTATION_AUTOMATIC; +// } + fOrientation= VIEW_ORIENTATION_AUTOMATIC; + + // force the update + fCurrentOrientation= -1; + // will fill the main tool bar + setOrientation(fOrientation); + + if (fMemento != null) { // restore state before creating action + restoreLinkingEnabled(fMemento); + } + fToggleLinkingAction= new ToggleLinkingAction(this); + + // set the filter menu items + IActionBars actionBars= getViewSite().getActionBars(); + IMenuManager viewMenu= actionBars.getMenuManager(); + for (int i= 0; i < fViewActions.length; i++) { + ToggleViewAction action= fViewActions[i]; + viewMenu.add(action); + action.setEnabled(false); + } + viewMenu.add(new Separator()); + + fWorkingSetActionGroup.contributeToMenu(viewMenu); + + viewMenu.add(new Separator()); + + IMenuManager layoutSubMenu= new MenuManager(TypeHierarchyMessages.getString("TypeHierarchyViewPart.layout.submenu")); //$NON-NLS-1$ + viewMenu.add(layoutSubMenu); + for (int i= 0; i < fToggleOrientationActions.length; i++) { + layoutSubMenu.add(fToggleOrientationActions[i]); + } + viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + viewMenu.add(fShowQualifiedTypeNamesAction); + viewMenu.add(fToggleLinkingAction); + + + // fill the method viewer tool bar + ToolBarManager lowertbmanager= new ToolBarManager(methodViewerToolBar); + lowertbmanager.add(fEnableMemberFilterAction); + lowertbmanager.add(new Separator()); + fMethodsViewer.contributeToToolBar(lowertbmanager); + lowertbmanager.update(true); + + // selection provider + int nHierarchyViewers= fAllViewers.length; + StructuredViewer[] trackedViewers= new StructuredViewer[nHierarchyViewers + 1]; + for (int i= 0; i < nHierarchyViewers; i++) { + trackedViewers[i]= fAllViewers[i]; + } + trackedViewers[nHierarchyViewers]= fMethodsViewer; + fSelectionProviderMediator= new SelectionProviderMediator(trackedViewers); + IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); + fSelectionProviderMediator.addSelectionChangedListener(new StatusBarUpdater(slManager)); + + getSite().setSelectionProvider(fSelectionProviderMediator); + getSite().getPage().addPartListener(fPartListener); + + // see http://bugs.eclipse.org/bugs/show_bug.cgi?id=33657 + ICElement input= null; //determineInputElement(); + if (fMemento != null) { + restoreState(fMemento, input); + } else if (input != null) { + setInputElement(input); + } else { + setViewerVisibility(false); + } + +// WorkbenchHelp.setHelp(fPagebook, ICHelpContextIds.TYPE_HIERARCHY_VIEW); + + + fActionGroups= new CompositeActionGroup(new ActionGroup[] { +// new NewWizardsActionGroup(this.getSite()), +// new OpenEditorActionGroup(this), + new OpenViewActionGroup(this), +// new CCPActionGroup(this), +// new GenerateActionGroup(this), +// new RefactorActionGroup(this), +// new CSearchActionGroup(this) + }); + + fActionGroups.fillActionBars(actionBars); + fSelectAllAction= new SelectAllAction(fMethodsViewer); + + actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), fSelectAllAction); + } + + private void addResizeListener(Composite parent) { + parent.addControlListener(new ControlListener() { + public void controlMoved(ControlEvent e) { + } + public void controlResized(ControlEvent e) { + computeOrientation(); + } + }); + } + + void computeOrientation() { + // fix for bug: 63268 error while activating view + // avoid recursive calls of compute orientation + if (fInComputeOrientation) { + return; + } + fInComputeOrientation= true; + try { + if (fOrientation != VIEW_ORIENTATION_AUTOMATIC) { + setOrientation(fOrientation); + } + else { + if (fOrientation == VIEW_ORIENTATION_SINGLE) + return; + Point size= fParent.getSize(); + if (size.x != 0 && size.y != 0) { + if (size.x > size.y) + setOrientation(VIEW_ORIENTATION_HORIZONTAL); + else + setOrientation(VIEW_ORIENTATION_VERTICAL); + } + } + } finally { + fInComputeOrientation= false; + } + } + + /** + * called from ToggleOrientationAction. + * @param orientation VIEW_ORIENTATION_SINGLE, VIEW_ORIENTATION_HORIZONTAL or VIEW_ORIENTATION_VERTICAL + */ + public void setOrientation(int orientation) { + if (fCurrentOrientation != orientation) { + boolean methodViewerNeedsUpdate= false; + + if (fMethodViewerViewForm != null && !fMethodViewerViewForm.isDisposed() + && fTypeMethodsSplitter != null && !fTypeMethodsSplitter.isDisposed()) { + if (orientation == VIEW_ORIENTATION_SINGLE) { + fMethodViewerViewForm.setVisible(false); + enableMemberFilter(false); + updateMethodViewer(null); + } else { + if (fCurrentOrientation == VIEW_ORIENTATION_SINGLE) { + fMethodViewerViewForm.setVisible(true); + methodViewerNeedsUpdate= true; + } + boolean horizontal= orientation == VIEW_ORIENTATION_HORIZONTAL; + fTypeMethodsSplitter.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL); + } + updateMainToolbar(orientation); + fTypeMethodsSplitter.layout(); + } + updateCheckedState(); + if (methodViewerNeedsUpdate) { + updateMethodViewer(fSelectedType); + } +// fDialogSettings.put(DIALOGSTORE_VIEWORIENTATION, orientation); + fCurrentOrientation= orientation; + + } + } + + + private void updateCheckedState() { + for (int i= 0; i < fToggleOrientationActions.length; i++) { + fToggleOrientationActions[i].setChecked(fOrientation == fToggleOrientationActions[i].getOrientation()); + } + } + + private void updateMainToolbar(int orientation) { + IActionBars actionBars= getViewSite().getActionBars(); + IToolBarManager tbmanager= actionBars.getToolBarManager(); + + if (orientation == VIEW_ORIENTATION_HORIZONTAL) { + clearMainToolBar(tbmanager); + ToolBar typeViewerToolBar= new ToolBar(fTypeViewerViewForm, SWT.FLAT | SWT.WRAP); + fillMainToolBar(new ToolBarManager(typeViewerToolBar)); + fTypeViewerViewForm.setTopLeft(typeViewerToolBar); + } else { + fTypeViewerViewForm.setTopLeft(null); + fillMainToolBar(tbmanager); + } + } + + private void fillMainToolBar(IToolBarManager tbmanager) { + tbmanager.removeAll(); + for (int i= 0; i < fViewActions.length; i++) { + tbmanager.add(fViewActions[i]); + } + tbmanager.add(fHistoryDropDownAction); + tbmanager.update(false); + } + + private void clearMainToolBar(IToolBarManager tbmanager) { + tbmanager.removeAll(); + tbmanager.update(false); + } + + + /** + * Creates the context menu for the hierarchy viewers + */ + private void fillTypesViewerContextMenu(TypeHierarchyViewer viewer, IMenuManager menu) { + CUIPlugin.createStandardGroups(menu); + + menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, new Separator(GROUP_FOCUS)); + // viewer entries + viewer.contributeToContextMenu(menu); + + if (fFocusOnSelectionAction.canActionBeAdded()) + menu.appendToGroup(GROUP_FOCUS, fFocusOnSelectionAction); + menu.appendToGroup(GROUP_FOCUS, fFocusOnTypeAction); + + fActionGroups.setContext(new ActionContext(getSite().getSelectionProvider().getSelection())); + fActionGroups.fillContextMenu(menu); + fActionGroups.setContext(null); + } + + /** + * Creates the context menu for the method viewer + */ + private void fillMethodsViewerContextMenu(IMenuManager menu) { + CUIPlugin.createStandardGroups(menu); + // viewer entries + fMethodsViewer.contributeToContextMenu(menu); + fActionGroups.setContext(new ActionContext(getSite().getSelectionProvider().getSelection())); + fActionGroups.fillContextMenu(menu); + fActionGroups.setContext(null); +// if (fSelectedType != null && fAddStubAction.init(fSelectedType, fMethodsViewer.getSelection())) { +// IMenuManager source= menu.findMenuUsingPath(GenerateActionGroup.MENU_ID); +// if (source != null) +// source.appendToGroup(GenerateActionGroup.GROUP_GENERATE, fAddStubAction); +// } + } + + /** + * Toggles between the empty viewer page and the hierarchy + */ + private void setViewerVisibility(boolean showHierarchy) { + if (showHierarchy) { + fViewerbook.showPage(getCurrentViewer().getControl()); + } else { + fViewerbook.showPage(fEmptyTypesViewer); + } + } + + /** + * Sets the member filter. null disables member filtering. + */ + private void setMemberFilter(IMember[] memberFilter) { + Assert.isNotNull(fAllViewers); + for (int i= 0; i < fAllViewers.length; i++) { + fAllViewers[i].setMemberFilter(memberFilter); + } + } + + private ICElement getSelectableType(ICElement elem) { +// if (elem.getElementType() != ICElement.TYPE) { + if (!(elem instanceof IStructure)) { + return getCurrentViewer().getTreeRootType(); + } else { + return elem; + } + } + + private void internalSelectType(ICElement elem, boolean reveal) { + TypeHierarchyViewer viewer= getCurrentViewer(); + if (viewer != null) { + viewer.removePostSelectionChangedListener(fSelectionChangedListener); + viewer.setSelection(elem != null ? new StructuredSelection(elem) : StructuredSelection.EMPTY, reveal); + viewer.addPostSelectionChangedListener(fSelectionChangedListener); + } + } + + /** + * When the input changed or the hierarchy pane becomes visible, + * updateHierarchyViewer brings up the correct view and refreshes + * the current tree + */ + private void updateHierarchyViewer(final boolean doExpand) { + if (fInputElement == null) { + fNoHierarchyShownLabel.setText(TypeHierarchyMessages.getString("TypeHierarchyViewPart.empty")); //$NON-NLS-1$ + fPagebook.showPage(fNoHierarchyShownLabel); + } else { + final TypeHierarchyViewer viewer = getCurrentViewer(); + if (viewer != null && viewer.containsElements() != null) { + Runnable runnable= new Runnable() { + public void run() { + viewer.updateContent(doExpand); // refresh + } + }; + BusyIndicator.showWhile(getDisplay(), runnable); + if (!isChildVisible(fViewerbook, viewer.getControl())) { + setViewerVisibility(true); + } + } else { + fEmptyTypesViewer.setText(TypeHierarchyMessages.getFormattedString("TypeHierarchyViewPart.nodecl", fInputElement.getElementName())); //$NON-NLS-1$ + setViewerVisibility(false); + } + } + } + + private void updateMethodViewer(final ICElement input) { + if (!fIsEnableMemberFilter && fCurrentOrientation != VIEW_ORIENTATION_SINGLE) { + if (input == fMethodsViewer.getInput()) { + if (input != null) { + Runnable runnable= new Runnable() { + public void run() { + fMethodsViewer.refresh(); // refresh + } + }; + BusyIndicator.showWhile(getDisplay(), runnable); + } + } else { + if (input != null) { + fMethodViewerPaneLabel.setText(fPaneLabelProvider.getText(input)); + fMethodViewerPaneLabel.setImage(fPaneLabelProvider.getImage(input)); + } else { + fMethodViewerPaneLabel.setText(""); //$NON-NLS-1$ + fMethodViewerPaneLabel.setImage(null); + } + Runnable runnable= new Runnable() { + public void run() { + fMethodsViewer.setInput(input); // refresh + } + }; + BusyIndicator.showWhile(getDisplay(), runnable); + } + } + } + + protected void doSelectionChanged(SelectionChangedEvent e) { + if (e.getSelectionProvider() == fMethodsViewer) { + methodSelectionChanged(e.getSelection()); + } else { + typeSelectionChanged(e.getSelection()); + } + } + + + + private void methodSelectionChanged(ISelection sel) { + if (sel instanceof IStructuredSelection) { + List selected= ((IStructuredSelection)sel).toList(); + int nSelected= selected.size(); + if (fIsEnableMemberFilter) { + IMember[] memberFilter= null; + if (nSelected > 0) { + memberFilter= new IMember[nSelected]; + selected.toArray(memberFilter); + } + setMemberFilter(memberFilter); + updateHierarchyViewer(true); + updateTitle(); + internalSelectType(fSelectedType, true); + } + if (nSelected == 1 && fSelectInEditor) { + revealElementInEditor(selected.get(0), fMethodsViewer); + } + } + } + + private void typeSelectionChanged(ISelection sel) { + if (sel instanceof IStructuredSelection) { + List selected= ((IStructuredSelection)sel).toList(); + int nSelected= selected.size(); + if (nSelected != 0) { + List types= new ArrayList(nSelected); + for (int i= nSelected-1; i >= 0; i--) { + Object elem= selected.get(i); + if (elem instanceof ICElement && !types.contains(elem)) { + types.add(elem); + } + } + if (types.size() == 1) { + fSelectedType= (ICElement) types.get(0); + updateMethodViewer(fSelectedType); + } else if (types.size() == 0) { + // method selected, no change + } + if (nSelected == 1 && fSelectInEditor) { + revealElementInEditor(selected.get(0), getCurrentViewer()); + } + } else { + fSelectedType= null; + updateMethodViewer(null); + } + } + } + + private void revealElementInEditor(Object elem, StructuredViewer originViewer) { + // only allow revealing when the type hierarchy is the active page + // no revealing after selection events due to model changes + + if (getSite().getPage().getActivePart() != this) { + return; + } + + if (fSelectionProviderMediator.getViewerInFocus() != originViewer) { + return; + } + + IEditorPart editorPart= EditorUtility.isOpenInEditor(elem); + if (editorPart != null && (elem instanceof ICElement)) { + getSite().getPage().removePartListener(fPartListener); + getSite().getPage().bringToTop(editorPart); + EditorUtility.revealInEditor(editorPart, (ICElement) elem); + getSite().getPage().addPartListener(fPartListener); + } + } + + private Display getDisplay() { + if (fPagebook != null && !fPagebook.isDisposed()) { + return fPagebook.getDisplay(); + } + return null; + } + + private boolean isChildVisible(Composite pb, Control child) { + Control[] children= pb.getChildren(); + for (int i= 0; i < children.length; i++) { + if (children[i] == child && children[i].isVisible()) + return true; + } + return false; + } + + private void updateTitle() { + String tooltip; + String title; + String viewerTitle; + TypeHierarchyViewer viewer = getCurrentViewer(); + if (viewer != null) { + viewerTitle= viewer.getTitle(); + } else { + viewerTitle = TypeHierarchyMessages.getString("TraditionalHierarchyViewer.title"); //$NON-NLS-1$ + } + + if (fInputElement != null) { + String[] args= new String[] { viewerTitle, CElementLabels.getElementLabel(fInputElement, CElementLabels.ALL_DEFAULT) }; + title= TypeHierarchyMessages.getFormattedString("TypeHierarchyViewPart.title", args); //$NON-NLS-1$ + tooltip= TypeHierarchyMessages.getFormattedString("TypeHierarchyViewPart.tooltip", args); //$NON-NLS-1$ + } else { + title= viewerTitle; + tooltip= viewerTitle; + } + setTitle(title); + setTitleToolTip(tooltip); + } + + private void updateToolbarButtons() { + boolean isType= fInputElement instanceof ICElement; + for (int i= 0; i < fViewActions.length; i++) { + ToggleViewAction action= fViewActions[i]; +// if (action.getViewerIndex() == VIEW_ID_TYPE) { +// action.setEnabled(fInputElement != null); +// } else { + action.setEnabled(isType); +// } + } + } + + /** + * Sets the current view (see view id) + * called from ToggleViewAction. Must be called after creation of the view part. + */ + public void setView(int viewerIndex) { + Assert.isNotNull(fAllViewers); + if (viewerIndex < fAllViewers.length && fCurrentViewerIndex != viewerIndex) { + fCurrentViewerIndex= viewerIndex; + + updateHierarchyViewer(true); + if (fInputElement != null) { + ISelection currSelection= getCurrentViewer().getSelection(); + if (currSelection == null || currSelection.isEmpty()) { + internalSelectType(getSelectableType(fInputElement), false); + currSelection= getCurrentViewer().getSelection(); + } + if (!fIsEnableMemberFilter) { + typeSelectionChanged(currSelection); + } + } + updateTitle(); + +// fDialogSettings.put(DIALOGSTORE_HIERARCHYVIEW, viewerIndex); + getCurrentViewer().getTree().setFocus(); + } + for (int i= 0; i < fViewActions.length; i++) { + ToggleViewAction action= fViewActions[i]; + action.setChecked(fCurrentViewerIndex == action.getViewerIndex()); + } + } + + /** + * Gets the current active view index. + */ + public int getViewIndex() { + return fCurrentViewerIndex; + } + + private TypeHierarchyViewer getCurrentViewer() { + if (fCurrentViewerIndex != -1) + return fAllViewers[fCurrentViewerIndex]; + return null; + } + + /** + * called from EnableMemberFilterAction. + * Must be called after creation of the view part. + */ + public void enableMemberFilter(boolean on) { + if (on != fIsEnableMemberFilter) { + fIsEnableMemberFilter= on; + if (!on) { + ICElement methodViewerInput= (ICElement) fMethodsViewer.getInput(); + setMemberFilter(null); + updateHierarchyViewer(true); + updateTitle(); + + if (methodViewerInput != null && getCurrentViewer().isElementShown(methodViewerInput)) { + // avoid that the method view changes content by selecting the previous input + internalSelectType(methodViewerInput, true); + } else if (fSelectedType != null) { + // choose a input that exists + internalSelectType(fSelectedType, true); + updateMethodViewer(fSelectedType); + } + } else { + methodSelectionChanged(fMethodsViewer.getSelection()); + } + } + fEnableMemberFilterAction.setChecked(on); + } + + /** + * called from ShowQualifiedTypeNamesAction. Must be called after creation + * of the view part. + */ + public void showQualifiedTypeNames(boolean on) { + if (fAllViewers == null) { + return; + } + for (int i= 0; i < fAllViewers.length; i++) { + fAllViewers[i].setQualifiedTypeName(on); + } + } + + private boolean isShowQualifiedTypeNames() { + return fShowQualifiedTypeNamesAction.isChecked(); + } + + /** + * Called from ITypeHierarchyLifeCycleListener. + * Can be called from any thread + */ + protected void doTypeHierarchyChanged(final TypeHierarchyLifeCycle typeHierarchy, final ICElement[] changedTypes) { + if (!fIsVisible) { + fNeedRefresh= true; + return; + } + if (fIsRefreshRunnablePosted) { + return; + } + + Display display= getDisplay(); + if (display != null) { + fIsRefreshRunnablePosted= true; + display.asyncExec(new Runnable() { + public void run() { + try { + if (fPagebook != null && !fPagebook.isDisposed()) { + doTypeHierarchyChangedOnViewers(changedTypes); + } + } finally { + fIsRefreshRunnablePosted= false; + } + } + }); + } + } + + protected void doTypeHierarchyChangedOnViewers(ICElement[] changedTypes) { + if (fHierarchyLifeCycle.getHierarchy() == null || !fHierarchyLifeCycle.getHierarchy().exists()) { + clearInput(); + } else { + if (changedTypes == null) { + // hierarchy change + try { + fHierarchyLifeCycle.ensureRefreshedTypeHierarchy(fInputElement, getSite().getWorkbenchWindow()); + } catch (InvocationTargetException e) { + ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.getString("TypeHierarchyViewPart.exception.title"), TypeHierarchyMessages.getString("TypeHierarchyViewPart.exception.message")); //$NON-NLS-1$ //$NON-NLS-2$ + clearInput(); + return; + } catch (InterruptedException e) { + return; + } + fMethodsViewer.refresh(); + updateHierarchyViewer(false); + } else { + // elements in hierarchy modified + Object methodViewerInput= fMethodsViewer.getInput(); + fMethodsViewer.refresh(); + fMethodViewerPaneLabel.setText(fPaneLabelProvider.getText(methodViewerInput)); + fMethodViewerPaneLabel.setImage(fPaneLabelProvider.getImage(methodViewerInput)); + if (getCurrentViewer().isMethodFiltering()) { + if (changedTypes.length == 1) { + getCurrentViewer().refresh(changedTypes[0]); + } else { + updateHierarchyViewer(false); + } + } else { + getCurrentViewer().update(changedTypes, new String[] { IBasicPropertyConstants.P_TEXT, IBasicPropertyConstants.P_IMAGE } ); + } + } + } + } + + /* + * @see IViewPart#init + */ + public void init(IViewSite site, IMemento memento) throws PartInitException { + super.init(site, memento); + fMemento= memento; + } + + /* + * @see ViewPart#saveState(IMemento) + */ + public void saveState(IMemento memento) { +// if (fPagebook == null) { +// // part has not been created +// if (fMemento != null) { //Keep the old state; +// memento.putMemento(fMemento); +// } +// return; +// } +// if (fInputElement != null) { +// String handleIndentifier= fInputElement.getHandleIdentifier(); +// memento.putString(TAG_INPUT, handleIndentifier); +// } +// memento.putInteger(TAG_VIEW, getViewIndex()); +// memento.putInteger(TAG_ORIENTATION, fOrientation); +// int weigths[]= fTypeMethodsSplitter.getWeights(); +// int ratio= (weigths[0] * 1000) / (weigths[0] + weigths[1]); +// memento.putInteger(TAG_RATIO, ratio); +// +// ScrollBar bar= getCurrentViewer().getTree().getVerticalBar(); +// int position= bar != null ? bar.getSelection() : 0; +// memento.putInteger(TAG_VERTICAL_SCROLL, position); +// +// ICElement selection= (ICElement)((IStructuredSelection) getCurrentViewer().getSelection()).getFirstElement(); +// if (selection != null) { +// memento.putString(TAG_SELECTION, selection.getHandleIdentifier()); +// } +// +// fWorkingSetActionGroup.saveState(memento); +// +// fMethodsViewer.saveState(memento); +// +// saveLinkingEnabled(memento); + } + + private void saveLinkingEnabled(IMemento memento) { + memento.putInteger(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR, fLinkingEnabled ? 1 : 0); + } + + /** + * Restores the type hierarchy settings from a memento. + */ + private void restoreState(final IMemento memento, ICElement defaultInput) { + ICElement input= defaultInput; + String elementId= memento.getString(TAG_INPUT); +// if (elementId != null) { +// input= CCore.create(elementId); +// if (input != null && !input.exists()) { +// input= null; +// } +// } + if (input == null) { + doRestoreState(memento, input); + } else { + final ICElement hierarchyInput= input; + + synchronized (this) { + String label= TypeHierarchyMessages.getFormattedString("TypeHierarchyViewPart.restoreinput", hierarchyInput.getElementName()); //$NON-NLS-1$ + fNoHierarchyShownLabel.setText(label); + + fRestoreStateJob= new Job(label) { + protected IStatus run(IProgressMonitor monitor) { + try { + doRestoreInBackground(memento, hierarchyInput, monitor); + } catch (CModelException e) { + return e.getStatus(); + } catch (OperationCanceledException e) { + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }; + fRestoreStateJob.schedule(); + } + } + } + + private void doRestoreInBackground(final IMemento memento, final ICElement hierarchyInput, IProgressMonitor monitor) throws CModelException { + fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor); + if (!monitor.isCanceled()) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + // running async: check first if view still exists + if (fPagebook != null && !fPagebook.isDisposed()) { + doRestoreState(memento, hierarchyInput); + } + } + }); + } + } + + + final void doRestoreState(IMemento memento, ICElement input) { + synchronized (this) { + if (fRestoreStateJob == null) { + return; + } + fRestoreStateJob= null; + } + + fWorkingSetActionGroup.restoreState(memento); + setInputElement(input); + + Integer viewerIndex= memento.getInteger(TAG_VIEW); + if (viewerIndex != null) { + setView(viewerIndex.intValue()); + } + Integer orientation= memento.getInteger(TAG_ORIENTATION); + if (orientation != null) { + fOrientation= orientation.intValue(); + } + computeOrientation(); + updateCheckedState(); + + Integer ratio= memento.getInteger(TAG_RATIO); + if (ratio != null) { + fTypeMethodsSplitter.setWeights(new int[] { ratio.intValue(), 1000 - ratio.intValue() }); + } + ScrollBar bar= getCurrentViewer().getTree().getVerticalBar(); + if (bar != null) { + Integer vScroll= memento.getInteger(TAG_VERTICAL_SCROLL); + if (vScroll != null) { + bar.setSelection(vScroll.intValue()); + } + } + fMethodsViewer.restoreState(memento); + } + + private void restoreLinkingEnabled(IMemento memento) { + Integer val= memento.getInteger(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR); + if (val != null) { + fLinkingEnabled= val.intValue() != 0; + } + } + + + /** + * view part becomes visible + */ + protected void visibilityChanged(boolean isVisible) { + fIsVisible= isVisible; + if (isVisible && fNeedRefresh) { + doTypeHierarchyChangedOnViewers(null); + } + fNeedRefresh= false; + } + + + /** + * Link selection to active editor. + */ + protected void editorActivated(IEditorPart editor) { + if (!isLinkingEnabled()) { + return; + } + if (fInputElement == null) { + // no type hierarchy shown + return; + } + + ICElement elem= (ICElement)editor.getEditorInput().getAdapter(ICElement.class); +// try { + TypeHierarchyViewer currentViewer= getCurrentViewer(); +// if (elem instanceof IClassFile) { +// ICElement type= ((IClassFile)elem).getType(); +// if (currentViewer.isElementShown(type)) { +// internalSelectType(type, true); +// updateMethodViewer(type); +// } +// } else + if (elem instanceof ITranslationUnit) { +// ICElement[] allTypes= ((ITranslationUnit)elem).getAllTypes(); + ICElement[] allTypes= TypeUtil.getTypes((ITranslationUnit)elem); + for (int i= 0; i < allTypes.length; i++) { + if (currentViewer.isElementShown(allTypes[i])) { + internalSelectType(allTypes[i], true); + updateMethodViewer(allTypes[i]); + return; + } + } + } +// } catch (CModelException e) { +// CUIPlugin.getDefault().log(e); +// } + + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput() + */ + public Object getViewPartInput() { + return fInputElement; + } + + + /** + * Returns the IShowInSource for this view. + */ + protected IShowInSource getShowInSource() { + return new IShowInSource() { + public ShowInContext getShowInContext() { + return new ShowInContext( + null, + getSite().getSelectionProvider().getSelection()); + } + }; + } + + boolean isLinkingEnabled() { + return fLinkingEnabled; + } + + public void setLinkingEnabled(boolean enabled) { + fLinkingEnabled= enabled; + PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR, enabled); + + if (enabled) { + IEditorPart editor = getSite().getPage().getActiveEditor(); + if (editor != null) { + editorActivated(editor); + } + } + } + + public void clearNeededRefresh() { + fNeedRefresh= false; + } + +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewer.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewer.java new file mode 100644 index 00000000000..266f5d5f3ec --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/typehierarchy/TypeHierarchyViewer.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.browser.typehierarchy; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Tree; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMember; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.browser.cbrowsing.DecoratingCLabelProvider; +import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; +import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.ViewerFilter; + +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; + +public abstract class TypeHierarchyViewer extends ProblemTreeViewer { + +// private OpenAction fOpen; + private HierarchyLabelProvider fLabelProvider; + + public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) { + super(new Tree(parent, SWT.SINGLE)); + + fLabelProvider= new HierarchyLabelProvider(lifeCycle); + +// setLabelProvider(new DecoratingCLabelProvider(fLabelProvider, true)); + setLabelProvider(fLabelProvider); + setUseHashlookup(true); + + setContentProvider(contentProvider); + setSorter(new HierarchyViewerSorter(lifeCycle)); + +// fOpen= new OpenAction(part.getSite()); +// addOpenListener(new IOpenListener() { +// public void open(OpenEvent event) { +// fOpen.run(); +// } +// }); + +// CUIHelp.setHelp(this, ICHelpContextIds.TYPE_HIERARCHY_VIEW); + } + + public void setQualifiedTypeName(boolean on) { + if (on) { + fLabelProvider.turnOn(CElementLabelProvider.SHOW_POST_QUALIFIED); + } else { + fLabelProvider.turnOff(CElementLabelProvider.SHOW_POST_QUALIFIED); + } +// if (on) { +// fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() | CElementLabels.T_POST_QUALIFIED); +// } else { +// fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() & ~CElementLabels.T_POST_QUALIFIED); +// } + refresh(); + } + + /** + * Attaches a contextmenu listener to the tree + */ + public void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) { + MenuManager menuMgr= new MenuManager(); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(menuListener); + Menu menu= menuMgr.createContextMenu(getTree()); + getTree().setMenu(menu); + viewSite.registerContextMenu(popupId, menuMgr, this); + } + + /** + * Fills up the context menu with items for the hierarchy viewer + * Should be called by the creator of the context menu + */ + public void contributeToContextMenu(IMenuManager menu) { + } + + /** + * Set the member filter + */ + public void setMemberFilter(IMember[] memberFilter) { + TypeHierarchyContentProvider contentProvider= getHierarchyContentProvider(); + if (contentProvider != null) { + contentProvider.setMemberFilter(memberFilter); + } + } + + /** + * Returns if method filtering is enabled. + */ + public boolean isMethodFiltering() { + TypeHierarchyContentProvider contentProvider= getHierarchyContentProvider(); + if (contentProvider != null) { + return contentProvider.getMemberFilter() != null; + } + return false; + } + + public void setWorkingSetFilter(ViewerFilter filter) { + fLabelProvider.setFilter(filter); + TypeHierarchyContentProvider contentProvider= getHierarchyContentProvider(); + if (contentProvider != null) { + contentProvider.setWorkingSetFilter(filter); + } + } + + /** + * Returns true if the hierarchy contains elements. Returns one of them + * With member filtering it is possible that no elements are visible + */ + public Object containsElements() { + TypeHierarchyContentProvider contentProvider= getHierarchyContentProvider(); + if (contentProvider != null) { + Object[] elements= contentProvider.getElements(null); + if (elements.length > 0) { + return elements[0]; + } + } + return null; + } + + /** + * Returns true if the hierarchy contains elements. Returns one of them + * With member filtering it is possible that no elements are visible + */ + public ICElement getTreeRootType() { + TypeHierarchyContentProvider contentProvider= getHierarchyContentProvider(); + if (contentProvider != null) { + Object[] elements= contentProvider.getElements(null); + if (elements.length > 0 && elements[0] instanceof ICElement) { + return (ICElement) elements[0]; + } + } + return null; + } + + /** + * Returns true if the hierarchy contains element the element. + */ + public boolean isElementShown(Object element) { + return findItem(element) != null; + } + + /** + * Updates the content of this viewer: refresh and expanding the tree in the way wanted. + */ + public abstract void updateContent(boolean doExpand); + + /** + * Returns the title for the current view + */ + public abstract String getTitle(); + + /* + * @see StructuredViewer#setContentProvider + * Content provider must be of type TypeHierarchyContentProvider + */ + public void setContentProvider(IContentProvider cp) { + Assert.isTrue(cp instanceof TypeHierarchyContentProvider); + super.setContentProvider(cp); + } + + protected TypeHierarchyContentProvider getHierarchyContentProvider() { + return (TypeHierarchyContentProvider)getContentProvider(); + } + +} diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/definingtype_sort_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/definingtype_sort_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..166eaba90314f8819bdc6e3907fe6d6a07a7cd9e GIT binary patch literal 323 zcmZ?wbhEHb6krfwxXQqgU)C~V;-u8tDU5DaF|A8=Qo8;6_l9(D&hB688x=c!#`FaX z=Fgiqx2>)9^r-`cH942hW~9bo%6h(C*=f9^Aiw|JJQrw`|$6 ze*OB@t5>gDwQA+cl`B@Pm@{Y2tXZ>W%$PBG^5jXACjI~apMk1C@h1x-1A{7q4#-rH zpBUH@4ooWW(2?qQI~*XCWuSDt`Geqz2s4$gz$l?gJqaK8jiO98vr573)%%iO2RFnzkqWacTIoD7`pt_v3}b$4X2 F1_0OEYP|pe literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/history_list.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/history_list.gif new file mode 100644 index 0000000000000000000000000000000000000000..364c0e70b1d6dc48f9d9abfceafbb4f63e5e1edb GIT binary patch literal 586 zcmZ?wbhEHb6krfwc*el6W%tD&KmUCB_Pefs%iNVm(`#3L`uh9Zk3TTdfM8Hb2nXEy7Tt)cRyde`|-ygpG`u5}Z!`D9^y!!t5&5tK+PqXU%vnDpS5D*?Bx$%1I52TfB*C4 zho3Lr|9Jo9*Qam4r_5RU^xco=?|;1d`19kp-=Dty`uOeF_g{Zz%wJ?aBVon4?KL}U z=PjDIXzA<~E2ghqJ!Rv%iCZ`H?cLhBb5qa$Z5{vr|7RG2K=CIFBLjmogAT~;pg3V* zU*6#C?9|fQ*3#7Ez|qs&=g{fw$YEh_(bwZR(Vo%V(wvc%nT5gBexjZ1R0~=5wQKDr z+A^tZW!kbu#de~N$!c9=Ha2M^n~Byk^UQS?E#bAEXeGK@^s17wsMSO>DMP8dckgML zP1Ms|ZJ^B~EF!5lQC0tx{#gcn)rnjRs}(d96cimaI$9DN+l4u7Z3-qFXzuiIHmI5L XgV9NeM?!&bXM&>>OK%esBZD;nX%XK6 literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/impl_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/impl_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..98d914a4484ed587911fddb276dc66534f58ab53 GIT binary patch literal 145 zcmV;C0B-+BNk%w1VGsZi0J8u9TzaaJrN?K5vT%*Lc9g#U{qOzq#{Kce{qe{B^2hw< zo~?EcrEU$KWDEcQ{{R30A^8LW000gEEC2ui01yBW000C&(8)=wy*O(L`sM-P5Q9K1 z%hZY2Qly-PqQx6Kt8*NQf$R+2D&%Mw8wy3^mYX1#w~LX&YGPIZ;>Y^wQX&95WI95> literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/inher_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/inher_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..a326000dae6a5ae94b615497001e1aa2f259c2c2 GIT binary patch literal 200 zcmV;(05|_fNk%w1VGsZi0K@v literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/sub_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/sub_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..54871df5aa611d36a38cc4648c25b9927e5450ca GIT binary patch literal 209 zcmV;?051PWNk%w1VGsZi0K@IRw9ecIdZs1PWa L#AK3P83F)14)Rwa literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/super_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/super_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..59ac11633f229ec67ea5da51c4e203c5bebff74d GIT binary patch literal 208 zcmV;>05AVXNk%w1VGsZi0K@JScfahC|1S)G*H)8q|k{?b2dMR@OtS-bDo zbkAv?FmKA7rIwX@uRVG_ecqz?zy4qS{Qupr|1;(<`uO|**FXP%{Qdvv`~Nq;{(t!W z|I45MuYdi2|NH;vKmWh~{l9$G>aTzQ|N8ged`7~GbK7fn)XrNpZ_(1(i5c0qZr#v#^4O-mTRV4d>e;cWcmKAI;M1%8L$Dx zpDc_F3>FMJAW4v)7}%N}<`j77NOf*rQdA~#NF_jHO=q_!U*}p^R)dFKm{&lkP^@sHv;a4kBnQjRUAuR3^GULW@C$Xxu!ii}>BwLW0L<>J A3jhEB literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/th_horizontal.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/th_horizontal.gif new file mode 100644 index 0000000000000000000000000000000000000000..d590470446f37e7d83ccbcf3f3a85f82e4fc344b GIT binary patch literal 374 zcmZ?wbhEHb6krfwxXQrLHf3GM)HOZRS6zSnrGM6n@ZJ-%cHf^eXQ^f7-fw^YfBOCZ z>gWIOe*K>@f6>R^|G)nE|K`{Kx4-^>`2GLOpZ~9a{eSoS|NGznKmYmv{qO&`zyE&% z3Idh={XhBWCi58yE6#1N*-<-h(Y!@VXRlZ>eeLQg8`n+Tx}k6H*3O-qdiHPYcsFnI zgY3B16Wjj(|Ia`cQ2fcl$iSe>paaqk@)HBwT literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/th_showqualified.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/th_showqualified.gif new file mode 100644 index 0000000000000000000000000000000000000000..2556b457bcaf79243cf96444079328f1c4e36443 GIT binary patch literal 222 zcmZ?wbhEHb6krfwIKsd%Z+?AzynTIrd{a|WYinvpM@COi?!<{jOP988+B9kB&Y6b~ zFTQkX)9hJQix)NT+dKE;yF>r~|7Rc?DE?$&WMB|v&;jWH*~!2fouJZ}k~vR9a!Fv* zo(=|O&rX}ulQ?$tP3dE8St!8K*(a26P(f-om&3}50UAP$ueL4}s$gyWAns%JWy5pl llLb24c$YF=whR~XVtMQ5zk&B3GgAYzy{5KKhoB;ZH2~DxNQeLc literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/th_single.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/th_single.gif new file mode 100644 index 0000000000000000000000000000000000000000..42fca3fcc9a6dc40287b6fa55f811c2e1c963bf0 GIT binary patch literal 370 zcmZ?wbhEHb6krfwxXQq=W%tF-8N27NKAv8?vZP}}+mv-3Q`huNU)4Wr#gsWqKmY#! z?a%*DzyDwT{Qupr|1;(<`uO|**FXP%{Qdvt*Z;S_{(t!W|I45MuYdi2_xu0*-~T`V z`Tzaz|F^&Ye+26K^Z(o5|F41S|Nb|hk+9<2_L?2F^A^opv~>2071P(Qp0aV>#H}0p z_HOOmxv6LWwvPY*|1*#d6o0ZXGBD^d=zz3>{KUZ4?=Zc>{Mg*3!VRA&@utdXCDMP8Yj{R|KwZ`0-z`Uc*_vP?<+cii@jL z-B~R;RW2ioK|sw}wM{^DuIyY@XMSD@$z{uz^E-34$?)-sY~bT`=9s7?G9_D>!8WqPZmZ721N!PkPRR|F|gGhm{8!M!)JYB ziIL?Uop~2tBpE-^QJch>a=NvkZB}cGQX>xsBO}8i$+UGhJzNy0r?<^G`uO6F-`^#i z#ku)f+uFsQ#kzZXdz?jsCW$)paL3LN;Bn^UR#1?iDZuH>F;7ljFg=q&ki(gsTYhtW X9lJAIOZ#p%XV(1(4jxc+WUvMR=0bUJ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/definingtype_sort_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/definingtype_sort_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..ff83256d83b9e98818196b01ed301f9478ff44bf GIT binary patch literal 220 zcmV<203-iLNk%w1VGsZi0K@FMd^<>ln$U3Iy}i4;ySlo%xVX5swzjpkwXw0Wu&}VNudk-2rlX^yp`oFko}QYTnwOWC zd3kwrb8}l;TmS$6A^8LW0018VEC2ui01yBW000G9;3tk`X`bda2GHdMCngG&0U(rM z%3rh)g@Qt|6KxiUq+(P2TqX%df}$$%2Ajs=u^BW!g3IROHDypAOG$&WaMUBF$?bW6 WHh4UV?y0Lg8y#pRf`f)9Apkp>s&R7w literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/history_list.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/history_list.gif new file mode 100644 index 0000000000000000000000000000000000000000..131063ce97dc3d8dd80eb9c4c4611e817a2dbed0 GIT binary patch literal 225 zcmZ?wbhEHb6krfwIKsg2|NsA2uUC_h+DP*n!_m+kIl|TlTw@u$Sq&L1%1orsNmT2^ z_DiT#9(J6yH@+aEXW5*sS|(zZ+msABOEo)vH#sN@8WgTC{CY)tdVmf?ZkaB7Riz;# M6APQ6p(2Ad0Gg&?q5uE@ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/impl_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/impl_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..a727403c3acfe22e591505bd3a4c9d60ad0b36d0 GIT binary patch literal 143 zcmZ?wbhEHb6krfw*v!E2|NsBjuV0@!b!x|s9h)|7TD5A`!i5X_`uf`2+Z!4hfU*pz zK=CIFBLf2$gAPa-WCjC^O~6Ud)q5?nGk-m6TFB$#D0}=$=XJ&+25SIIem8Ic literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/inher_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/inher_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..23338d74aa743d2a463e46a3568c33fbb3e53055 GIT binary patch literal 199 zcmZ?wbhEHb6krfwIKsg2|NsB%*RLNra^&#g!~6E_+q-w~jvYI;Y}vALeQ)yeSK|hZLO`X#l^)ya~QAz#h)yU z3=9$sIv`1qoeZol3TjCwihD9&JP6lV^>It{zd&tCgxt-jok!dzj lg7cK)SIgNV3`fNsLv^-EvuIWMtTta|wcEAs@C*S4YXFG_Qhxvd literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/sub_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/sub_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..3848a251dadb77e9c5d974b87ae3f37979f6eafe GIT binary patch literal 209 zcmZ?wbhEHb6krfwIKsg2|NsB%*RLNra^&#g!~6E_+q-w~jvYI;Y}vALeQ)yeSK|hZLO`X#l^)ya~QAz#h)yU z3=9$sIv`1qoeZpg3Tk~Ro=WEvXLSnjob-xn4U7oVGv_{NqSVQ=d4`7Dp+rs1;t4ZW w9}j-AVw%Ev8CC~P*JU%hj&5Q(z2M|3;~AF|Z{2?PLTTrWBPo+&C7Bqk0q5{qN&o-= literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/super_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/super_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..45808d1d261e21714b3355d7f2eab1d21b7af439 GIT binary patch literal 206 zcmZ?wbhEHb6krfwIKsg2|NsB%*RLNra^&#g!~6E_+q-w~jvYI;Y}vALeQ)yeSK|hZLO`X#l^)ya~QAz#h)yU z3=9$sIv`1qoeZqr3Tk~Rne(o9dcAzHXQ|3*W!3;=&8bsUJ9h^Lm>zNQ(r2H*qIt7m s%f;sB(Yr#z*5tKR$ZR;+qF~@5kUFht;fKp+Vk~aX+EG3tiv$>~0aHU)Q2+n{ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_automatic.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_automatic.gif new file mode 100644 index 0000000000000000000000000000000000000000..1b93aaca769bc97f4a61782e987e62c4265b3220 GIT binary patch literal 338 zcmZ?wbhEHb6krfwxXQq=YtO+W$4>3uv+v#ek2i1K*}QG{{)0y@UAw(}{r0VU4)55t z=hyE)KY#uH@$=W$?>|0#`TFzs@4x^4{rUU%_n$wf&zw1Y7%Dk9zDB%@2&Ia4({E1^w6P02M_-L|DS<2K=CIFBLjmHgAT}eke?XX@*O4? zc<4xVE?i<%BGM)opt1R4R)I#rjKh+Q6J7*OnZUSe(-Du0X9_u4)+L3= zimh&82={&)$Jq6wbjyZosojFi0UaU?)i!!O%Dhf43~e4>ysb5LodH3;N_=6{jQEuK N=FFWpS4fe;8URukSz-VH literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_showqualified.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_showqualified.gif new file mode 100644 index 0000000000000000000000000000000000000000..f288b5965134532c5ee0634d6217d5300c79daae GIT binary patch literal 156 zcmZ?wbhEHb6krfw*v!E2`t{RQtCmflKKbOyqj&DyxP1Big$rlSo;`W!;KBd@|1)3! z#h)yU3=EtMIv^R484N6*1}8mN@13z|&V=s=pNDn?iZ~}MnjOY)L~u``wIZwF`Cp0N v9S0v82yk@TyCg^oSj<#ByUOBkX@=1n(d&<|dK?d_(B|s22;);@Vz34PEWJC+ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_single.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_single.gif new file mode 100644 index 0000000000000000000000000000000000000000..530345b360c20d9ce2f181de4e458c9ca4c75433 GIT binary patch literal 222 zcmZ?wbhEHb6krfwIKsg2|Ns974<6jSdGq4Miw6%LJaFK^{{8#+?c29^@7~?JckkM@ zYv<0LJ9g~YuwlcpWy@MyTY>5sNCApJSr{3BR_TB=f$U^pjaE?UOR*HnShY<3!9D|r z9##b#r#E7Y8Etyl4_wsXVPbGT-*#Emon8Hnfs;Y870VZK8L@tbRT@=?j~$uN@@1-o i<~qNl83#p$dQTjcS$DZxB3q9~nWwd_y-h%o!5RRGC{C9E literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_vertical.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/th_vertical.gif new file mode 100644 index 0000000000000000000000000000000000000000..0a52f1de2a36f7a031bd5a587922b9c86cd55e6f GIT binary patch literal 222 zcmZ?wbhEHb6krfwIKsg2|Ns974<6jRckkxSo7b*gyLj>9!Gi}695}Fl|NedZ_U+xf zclYkyyLRo`xpU`^9XmE`*syHbvewpCpe_dDfZ|UUMg|5U1|5)ckev*y(F;`iQY@u1 zRxMM1u+Jc&huy%%`Hh@1lS>~5!zT+7CI*-DZI@NuIn{LxgFNE7GLlZe&082Q9=e5t pSxlL&!C}KIiN(jF5>%xo_F6a`EPv+8m&T{e*V@+JCZxz<4FGcIQ2PJ? literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/definingtype_sort_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/definingtype_sort_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..166eaba90314f8819bdc6e3907fe6d6a07a7cd9e GIT binary patch literal 323 zcmZ?wbhEHb6krfwxXQqgU)C~V;-u8tDU5DaF|A8=Qo8;6_l9(D&hB688x=c!#`FaX z=Fgiqx2>)9^r-`cH942hW~9bo%6h(C*=f9^Aiw|JJQrw`|$6 ze*OB@t5>gDwQA+cl`B@Pm@{Y2tXZ>W%$PBG^5jXACjI~apMk1C@h1x-1A{7q4#-rH zpBUH@4ooWW(2?qQI~*XCWuSDt`Geqz2s4$gz$l?gJqaK8jiO98vr573)%%iO2RFnzkqWacTIoD7`pt_v3}b$4X2 F1_0OEYP|pe literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/history_list.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/history_list.gif new file mode 100644 index 0000000000000000000000000000000000000000..364c0e70b1d6dc48f9d9abfceafbb4f63e5e1edb GIT binary patch literal 586 zcmZ?wbhEHb6krfwc*el6W%tD&KmUCB_Pefs%iNVm(`#3L`uh9Zk3TTdfM8Hb2nXEy7Tt)cRyde`|-ygpG`u5}Z!`D9^y!!t5&5tK+PqXU%vnDpS5D*?Bx$%1I52TfB*C4 zho3Lr|9Jo9*Qam4r_5RU^xco=?|;1d`19kp-=Dty`uOeF_g{Zz%wJ?aBVon4?KL}U z=PjDIXzA<~E2ghqJ!Rv%iCZ`H?cLhBb5qa$Z5{vr|7RG2K=CIFBLjmogAT~;pg3V* zU*6#C?9|fQ*3#7Ez|qs&=g{fw$YEh_(bwZR(Vo%V(wvc%nT5gBexjZ1R0~=5wQKDr z+A^tZW!kbu#de~N$!c9=Ha2M^n~Byk^UQS?E#bAEXeGK@^s17wsMSO>DMP8dckgML zP1Ms|ZJ^B~EF!5lQC0tx{#gcn)rnjRs}(d96cimaI$9DN+l4u7Z3-qFXzuiIHmI5L XgV9NeM?!&bXM&>>OK%esBZD;nX%XK6 literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/impl_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/impl_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..98d914a4484ed587911fddb276dc66534f58ab53 GIT binary patch literal 145 zcmV;C0B-+BNk%w1VGsZi0J8u9TzaaJrN?K5vT%*Lc9g#U{qOzq#{Kce{qe{B^2hw< zo~?EcrEU$KWDEcQ{{R30A^8LW000gEEC2ui01yBW000C&(8)=wy*O(L`sM-P5Q9K1 z%hZY2Qly-PqQx6Kt8*NQf$R+2D&%Mw8wy3^mYX1#w~LX&YGPIZ;>Y^wQX&95WI95> literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/inher_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/inher_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..a326000dae6a5ae94b615497001e1aa2f259c2c2 GIT binary patch literal 200 zcmV;(05|_fNk%w1VGsZi0K@v literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/sub_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/sub_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..54871df5aa611d36a38cc4648c25b9927e5450ca GIT binary patch literal 209 zcmV;?051PWNk%w1VGsZi0K@IRw9ecIdZs1PWa L#AK3P83F)14)Rwa literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/super_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/super_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..59ac11633f229ec67ea5da51c4e203c5bebff74d GIT binary patch literal 208 zcmV;>05AVXNk%w1VGsZi0K@JScfahC|1S)G*H)8q|k{?b2dMR@OtS-bDo zbkAv?FmKA7rIwX@uRVG_ecqz?zy4qS{Qupr|1;(<`uO|**FXP%{Qdvv`~Nq;{(t!W z|I45MuYdi2|NH;vKmWh~{l9$G>aTzQ|N8ged`7~GbK7fn)XrNpZ_(1(i5c0qZr#v#^4O-mTRV4d>e;cWcmKAI;M1%8L$Dx zpDc_F3>FMJAW4v)7}%N}<`j77NOf*rQdA~#NF_jHO=q_!U*}p^R)dFKm{&lkP^@sHv;a4kBnQjRUAuR3^GULW@C$Xxu!ii}>BwLW0L<>J A3jhEB literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/th_horizontal.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/th_horizontal.gif new file mode 100644 index 0000000000000000000000000000000000000000..d590470446f37e7d83ccbcf3f3a85f82e4fc344b GIT binary patch literal 374 zcmZ?wbhEHb6krfwxXQrLHf3GM)HOZRS6zSnrGM6n@ZJ-%cHf^eXQ^f7-fw^YfBOCZ z>gWIOe*K>@f6>R^|G)nE|K`{Kx4-^>`2GLOpZ~9a{eSoS|NGznKmYmv{qO&`zyE&% z3Idh={XhBWCi58yE6#1N*-<-h(Y!@VXRlZ>eeLQg8`n+Tx}k6H*3O-qdiHPYcsFnI zgY3B16Wjj(|Ia`cQ2fcl$iSe>paaqk@)HBwT literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/th_showqualified.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/th_showqualified.gif new file mode 100644 index 0000000000000000000000000000000000000000..2556b457bcaf79243cf96444079328f1c4e36443 GIT binary patch literal 222 zcmZ?wbhEHb6krfwIKsd%Z+?AzynTIrd{a|WYinvpM@COi?!<{jOP988+B9kB&Y6b~ zFTQkX)9hJQix)NT+dKE;yF>r~|7Rc?DE?$&WMB|v&;jWH*~!2fouJZ}k~vR9a!Fv* zo(=|O&rX}ulQ?$tP3dE8St!8K*(a26P(f-om&3}50UAP$ueL4}s$gyWAns%JWy5pl llLb24c$YF=whR~XVtMQ5zk&B3GgAYzy{5KKhoB;ZH2~DxNQeLc literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/th_single.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/th_single.gif new file mode 100644 index 0000000000000000000000000000000000000000..42fca3fcc9a6dc40287b6fa55f811c2e1c963bf0 GIT binary patch literal 370 zcmZ?wbhEHb6krfwxXQq=W%tF-8N27NKAv8?vZP}}+mv-3Q`huNU)4Wr#gsWqKmY#! z?a%*DzyDwT{Qupr|1;(<`uO|**FXP%{Qdvt*Z;S_{(t!W|I45MuYdi2_xu0*-~T`V z`Tzaz|F^&Ye+26K^Z(o5|F41S|Nb|hk+9<2_L?2F^A^opv~>2071P(Qp0aV>#H}0p z_HOOmxv6LWwvPY*|1*#d6o0ZXGBD^d=zz3>{KUZ4?=Zc>{Mg*3!VRA&@utdXCDMP8Yj{R|KwZ`0-z`Uc*_vP?<+cii@jL z-B~R;RW2ioK|sw}wM{^DuIyY@XMSD@$z{uz^E-34$?)-sY~bT`=9s7?G9_D>!8WqPZmZ721N!PkPRR|F|gGhm{8!M!)JYB ziIL?Uop~2tBpE-^QJch>a=NvkZB}cGQX>xsBO}8i$+UGhJzNy0r?<^G`uO6F-`^#i z#ku)f+uFsQ#kzZXdz?jsCW$)paL3LN;Bn^UR#1?iDZuH>F;7ljFg=q&ki(gsTYhtW X9lJAIOZ#p%XV(1(4jxc+WUvMR=0bUJ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/eview16/chierch_pers.gif b/core/org.eclipse.cdt.ui/icons/full/eview16/chierch_pers.gif new file mode 100644 index 0000000000000000000000000000000000000000..905c3387956631701248e0bf8ebd7931954ab7a6 GIT binary patch literal 172 zcmV;d08{@*Nk%w1VGsZi0J8u9MOD9Vc7&$N@M4_5EP_i+lVeqyYFnOfQ3lc z#G(?Uz&(OcD2-B(4j^C%F}AOmC2*Nk9;OXoX!(RjF4OK2sHRq=3-K|l-Llk6?+4z3 avu5Kt{BVlS)xdSZDqFfXxY!4d0028X=t%Vd literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/eview16/class_hi.gif b/core/org.eclipse.cdt.ui/icons/full/eview16/class_hi.gif new file mode 100644 index 0000000000000000000000000000000000000000..17f927e9a4e24ec37908bdde84d7525cd3207bb1 GIT binary patch literal 200 zcmZ?wbhEHb6krfwIKse?U)G}5;9=Pwq{}~7Y#h)yU3=AR+Iv|B0I~iDA6;y*b z7WQOh*-Q>zQovvu$grGQS@-ZH$3GU8@9clH*c literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index acee703d315..7366a78d00f 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -20,7 +20,6 @@ editorRulerActionsName=Editor Ruler Actions completionContributorName=Completion Contribution nature.name=C Nature perspective.name=C/C++ -CBrowsing.perspective.name=C/C++ Browsing viewsCategory.name=&C CView.name=C/C++ Projects @@ -181,7 +180,7 @@ CEditorPresentation.label= Editor CDTIndexerMarker.label= C/C++ Indexer Markers #Browsing -CBrowsing.perspectiveName= C/C++ Browsing +CBrowsing.perspective.name=C/C++ Browsing CBrowsing.viewCategoryName= C/C++ Browsing CBrowsing.projectsViewName= Projects CBrowsing.namespacesViewName= Namespaces @@ -189,6 +188,24 @@ CBrowsing.typesViewName= Types CBrowsing.membersViewName= Members CBrowsing.preferencePageName= Browsing +#Type Hierarchy +CHierarchy.viewCategoryName= C/C++ Type Hierarchy +CHierarchy.perspective.name=C/C++ Type Hierarchy +CHierarchy.hierarchyViewName= Hierarchy +ActionDefinition.open.hierarchy.name= Open Hierarchy +ActionDefinition.open.hierarchy.description= Open the hierarchy of the selected element +OpenTypeInHierarchyAction.label=Open Type in Hierarch&y... +OpenTypeInHierarchyAction.description=Opens a type selected from the all types dialog in a type hierarchy +OpenTypeInHierarchyAction.tooltip=Opens a Type in a Type Hierarchy +ActionDefinition.openTypeInHierarchy.name= Open Type in Hierarchy +ActionDefinition.openTypeInHierarchy.description= Open a type in the type hierarchy view +ActionDefinition.openTypeHierarchy.name= Open Type Hierarchy +ActionDefinition.openTypeHierarchy.description= Open a type hierarchy on the selected element +OpenTypeHierarchyAction.label=Open Type Hie&rarchy +OpenTypeHierarchyAction.tooltip=Opens a Type Hierarchy for the Selected Element +ViewCommand.typeHierarchy.name= C Type Hierarchy +ViewCommand.typeHierarchy.description= Show the Type Hierarchy view + # hovering contribution CEditorTextHoversName=C Editor Text Hovers sourceHover= Source diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 9c5a4e0d2df..0dc341103c6 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -171,6 +171,12 @@ class="org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPerspectiveFactory" id="org.eclipse.cdt.ui.CBrowsingPerspective"> + + @@ -259,6 +265,17 @@ class="org.eclipse.cdt.internal.ui.browser.cbrowsing.MembersView" id="org.eclipse.cdt.ui.MembersView"> + + + + @@ -618,6 +635,18 @@ string="Ctrl+G" scope="org.eclipse.cdt.ui.cEditorScope" configuration="org.eclipse.ui.defaultAcceleratorConfiguration"/> + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java index 6aa3d5bc137..7afcae8cffb 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java @@ -16,7 +16,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.model.CElement; import org.eclipse.cdt.internal.corext.refactoring.RenameRefactoring; -import org.eclipse.cdt.internal.ui.cview.SelectionConverter; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.cdt.internal.ui.refactoring.UserInterfaceStarter; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java index 59049796430..3b225507906 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java @@ -74,8 +74,8 @@ public class CElementImageProvider { */ public final static int OVERLAY_IMPLEMENTS= 0x40; - private static final Point SMALL_SIZE= new Point(16, 16); - private static final Point BIG_SIZE= new Point(22, 16); + public static final Point SMALL_SIZE= new Point(16, 16); + public static final Point BIG_SIZE= new Point(22, 16); private static ImageDescriptor DESC_OBJ_PROJECT_CLOSED; private static ImageDescriptor DESC_OBJ_PROJECT; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 4dbc7e9dafd..97459c979e7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -153,6 +153,7 @@ public class CPluginImages { public static final ImageDescriptor DESC_OBJS_EXCLUSION_FILTER_ATTRIB = createManaged(T_OBJ, IMG_OBJS_EXCLUDSION_FILTER_ATTRIB); public static final ImageDescriptor DESC_OBJS_SOURCE_ATTACH_ATTRIB= createManaged(T_OBJ, IMG_OBJS_SOURCE_ATTACH_ATTRIB); public static final ImageDescriptor DESC_OVR_PATH_INHERIT= create(T_OVR, "path_inherit_co.gif"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_OVR_FOCUS= create(T_OVR, "focus_ovr.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_OBJS_FIXABLE_PROBLEM= createManaged(T_OBJ, IMG_OBJS_FIXABLE_PROBLEM); public static final ImageDescriptor DESC_OBJS_FIXABLE_ERROR= createManaged(T_OBJ, IMG_OBJS_FIXABLE_ERROR); @@ -271,7 +272,8 @@ public class CPluginImages { * Sets all available image descriptors for the given action. */ public static void setImageDescriptors(IAction action, String type, String relPath) { - relPath= relPath.substring(NAME_PREFIX_LENGTH); + if (relPath.startsWith(NAME_PREFIX)) + relPath= relPath.substring(NAME_PREFIX_LENGTH); action.setDisabledImageDescriptor(create(T + "d" + type, relPath)); //$NON-NLS-1$ action.setHoverImageDescriptor(create(T + "c" + type, relPath)); //$NON-NLS-1$ action.setImageDescriptor(create(T + "e" + type, relPath)); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java index 3ace3caeb33..f9965047fd5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java @@ -27,6 +27,8 @@ public interface ICHelpContextIds { public static final String FILTER_PUBLIC_ACTION= PREFIX + "filter_public_action"; //$NON-NLS-1$ public static final String FILTER_FIELDS_ACTION= PREFIX + "filter_fields_action"; //$NON-NLS-1$ public static final String FILTER_STATIC_ACTION= PREFIX + "filter_static_action"; //$NON-NLS-1$ + public static final String FILTER_LOCALTYPES_ACTION= PREFIX + "filter_localtypes_action"; //$NON-NLS-1$ + public static final String NEXT_CHANGE_ACTION= PREFIX + "next_change_action"; //$NON-NLS-1$ public static final String PREVIOUS_CHANGE_ACTION=PREFIX + "previous_change_action"; //$NON-NLS-1$ public static final String NEXT_PROBLEM_ACTION= PREFIX + "next_problem_action"; //$NON-NLS-1$ @@ -107,13 +109,33 @@ public interface ICHelpContextIds { public static final String TYPES_VIEW= PREFIX + "types_view_context"; //$NON-NLS-1$ public static final String MEMBERS_VIEW= PREFIX + "members_view_context"; //$NON-NLS-1$ + public static final String OPEN_ACTION = PREFIX + "open_action"; //$NON-NLS-1$ public static final String OPEN_C_BROWSING_PERSPECTIVE_ACTION = PREFIX + "open_c_browsing_perspective_action"; //$NON-NLS-1$ public static final String OPEN_PROJECT_ACTION = PREFIX + "open_project_action"; //$NON-NLS-1$ public static final String OPEN_TYPE_ACTION = PREFIX + "open_type_action"; //$NON-NLS-1$ public static final String OPEN_TYPE_IN_HIERARCHY_ACTION = PREFIX + "open_type_in_hierarchy_action"; //$NON-NLS-1$ + public static final String OPEN_TYPE_HIERARCHY_ACTION = PREFIX + "open_type_hierarchy_action"; //$NON-NLS-1$ + public static final String SELECT_ALL_ACTION = PREFIX + "select_all_action"; //$NON-NLS-1$ + public static final String LINK_EDITOR_ACTION = PREFIX + "link_editor_action"; //$NON-NLS-1$ + public static final String TYPEHIERARCHY_HISTORY_ACTION = PREFIX + "typehierarchy_history_action"; //$NON-NLS-1$ + public static final String HISTORY_ACTION = PREFIX + "history_action"; //$NON-NLS-1$ + public static final String HISTORY_LIST_ACTION = PREFIX + "history_list_action"; //$NON-NLS-1$ + public static final String TOGGLE_ORIENTATION_ACTION = PREFIX + "toggle_orientations_action"; //$NON-NLS-1$ + public static final String FOCUS_ON_TYPE_ACTION = PREFIX + "focus_on_type_action"; //$NON-NLS-1$ + public static final String FOCUS_ON_SELECTION_ACTION = PREFIX + "focus_on_selection_action"; //$NON-NLS-1$ - public static final String LEXICAL_SORTING_BROWSING_ACTION= PREFIX + "lexical_sorting_browsing_action"; //$NON-NLS-1$ + public static final String HISTORY_LIST_DIALOG = PREFIX + "history_list_dialog_context"; //$NON-NLS-1$ + + public static final String SHOW_INHERITED_ACTION = PREFIX + "show_inherited_action"; //$NON-NLS-1$ + public static final String SHOW_SUPERTYPES = PREFIX + "show_supertypes_action"; //$NON-NLS-1$ + public static final String SHOW_SUBTYPES = PREFIX + "show_subtypes_action"; //$NON-NLS-1$ + public static final String SHOW_HIERARCHY = PREFIX + "show_hierarchy_action"; //$NON-NLS-1$ + + public static final String SORT_BY_DEFINING_TYPE_ACTION = PREFIX + "sort_by_defining_type_action"; //$NON-NLS-1$ + public static final String SHOW_QUALIFIED_NAMES_ACTION = PREFIX + "show_qualified_names_action"; //$NON-NLS-1$ + + public static final String LEXICAL_SORTING_BROWSING_ACTION = PREFIX + "lexical_sorting_browsing_action"; //$NON-NLS-1$ public static final String PROJECT_INDEXER_PROPERTIES = PREFIX + "std_prop_indexer"; //$NON-NLS-1$ public static final String CEDITOR_VIEW = PREFIX + "editor_view"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java index 1651004a28b..d5af4821f11 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java @@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.ui; * All Rights Reserved. */ +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.ui.IWorkbenchActionConstants; /** @@ -15,6 +16,29 @@ import org.eclipse.ui.IWorkbenchActionConstants; */ public interface IContextMenuConstants { + /** + * Type hierarchy view part: pop-up menu target ID for supertype hierarchy viewer + * (value "org.eclipse.cdt.ui.TypeHierarchy.supertypes"). + * + * @since 2.0 + */ + public static final String TARGET_ID_SUPERTYPES_VIEW= CUIPlugin.ID_TYPE_HIERARCHY + ".supertypes"; //$NON-NLS-1$ + + /** + * Type hierarchy view part: Pop-up menu target ID for the subtype hierarchy viewer + * (value "org.eclipse.cdt.ui.TypeHierarchy.subtypes"). + * + * @since 2.0 + */ + public static final String TARGET_ID_SUBTYPES_VIEW= CUIPlugin.ID_TYPE_HIERARCHY + ".subtypes"; //$NON-NLS-1$ + + /** + * Type hierarchy view part: pop-up menu target ID for the meber viewer + * (value "org.eclipse.cdt.ui.TypeHierarchy.members"). + * + * @since 2.0 + */ + public static final String TARGET_ID_MEMBERS_VIEW= CUIPlugin.ID_TYPE_HIERARCHY + ".members"; //$NON-NLS-1$ /** * Pop-up menu: name of group for goto actions (value "group.open"). diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractToggleLinkingAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractToggleLinkingAction.java new file mode 100644 index 00000000000..c7755066d09 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractToggleLinkingAction.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.actions; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.jface.action.Action; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * This is an action template for actions that toggle whether + * it links its selection to the active editor. + * + * @since 3.0 + */ +public abstract class AbstractToggleLinkingAction extends Action { + + /** + * Constructs a new action. + */ + public AbstractToggleLinkingAction() { + super(ActionMessages.getString("ToggleLinkingAction.label")); //$NON-NLS-1$ + setDescription(ActionMessages.getString("ToggleLinkingAction.description")); //$NON-NLS-1$ + setToolTipText(ActionMessages.getString("ToggleLinkingAction.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "synced.gif"); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.LINK_EDITOR_ACTION); + } + + /** + * Runs the action. + */ + public abstract void run(); +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties index e3f3b5b4559..0d8c842a8d3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties @@ -17,8 +17,8 @@ NavigateMenu.label=&Navigate BuildAction.label=&Build Project RebuildAction.label=Rebuild Pro&ject -SelectionConverter.codeResolveOrInput_failed=Couldn't convert text selection into a Java element -SelectionConverter.codeResolve_failed=Couldn't convert text selection into a Java element +SelectionConverter.codeResolveOrInput_failed=Couldn't convert text selection into a C element +SelectionConverter.codeResolve_failed=Couldn't convert text selection into a C element OpenAction.label=&Open OpenAction.tooltip=Open an editor on the selected element @@ -30,7 +30,7 @@ OpenAction.error.title=Open OpenAction.error.message=Cannot open default editor. OpenAction.error.messageArgs=Cannot open default editor on {0}. {1} OpenAction.error.messageProblems=Problems Opening Editor -OpenAction.error.messageBadSelection=Current text selection doesn't resolve to a Java element +OpenAction.error.messageBadSelection=Current text selection doesn't resolve to a C element OpenSuperImplementationAction.label=Open S&uper Implementation OpenSuperImplementationAction.tooltip=Open the Implementation in the Super Type @@ -45,10 +45,10 @@ OpenTypeHierarchyAction.tooltip=Open a type hierarchy on the selected element OpenTypeHierarchyAction.description=Open a type hierarchy on the selected element OpenTypeHierarchyAction.dialog.title=Open Type Hierarchy OpenTypeHierarchyAction.messages.title=Can\'t create type hierarchy -OpenTypeHierarchyAction.messages.no_java_element=No Java element selected. -OpenTypeHierarchyAction.messages.no_java_resources=Selected package fragment doesn\'t contain any Java resource. -OpenTypeHierarchyAction.messages.no_types=Selected compilation unit doesn\'t contain a type. -OpenTypeHierarchyAction.messages.no_valid_java_element=No valid Java element selected. +OpenTypeHierarchyAction.messages.no_c_element=No C element selected. +OpenTypeHierarchyAction.messages.no_c_resources=Selected package fragment doesn\'t contain any C resource. +OpenTypeHierarchyAction.messages.no_types=Selected translation unit doesn\'t contain a type. +OpenTypeHierarchyAction.messages.no_valid_c_element=No valid C element selected. ShowInPackageViewAction.label=Show in Pac&kage Explorer ShowInPackageViewAction.description=Show the selected element in Package Explorer @@ -272,3 +272,7 @@ AddDelegateMethodsAction.message=Select &methods to create delegates for: AddDelegateMethodsAction.monitor.message=Creating {0} methods... AddDelegateMethodsAction.selectioninfo.one={0} method selected. AddDelegateMethodsAction.selectioninfo.more={0} methods selected. + +ToggleLinkingAction.label=Lin&k With Editor +ToggleLinkingAction.tooltip=Link with Editor +ToggleLinkingAction.description=Link with active editor diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionUtil.java new file mode 100644 index 00000000000..d82b3bf55f3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionUtil.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.actions; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=19104 + */ +public class ActionUtil { + + private ActionUtil(){ + } + + //bug 31998 we will have to disable renaming of linked packages (and cus) + public static boolean mustDisableCModelAction(Shell shell, Object element) { + return false; +// if (!(element instanceof IPackageFragment) && !(element instanceof IPackageFragmentRoot)) +// return false; +// +// IResource resource= ResourceUtil.getResource(element); +// if ((resource == null) || (! (resource instanceof IFolder)) || (! resource.isLinked())) +// return false; +// +// MessageDialog.openInformation(shell, ActionMessages.getString("ActionUtil.not_possible"), ActionMessages.getString("ActionUtil.no_linked")); //$NON-NLS-1$ //$NON-NLS-2$ +// return true; + } + + public static boolean isProcessable(Shell shell, CEditor editor) { + if (editor == null) + return true; + ICElement input= SelectionConverter.getInput(editor); + // if a Java editor doesn't have an input of type Java element + // then it is for sure not on the build path + if (input == null) { + MessageDialog.openInformation(shell, + ActionMessages.getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$ + ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$ + return false; + } + return isProcessable(shell, input); + } + + public static boolean isProcessable(Shell shell, Object element) { + if (!(element instanceof ICElement)) + return true; + + if (isOnBuildPath((ICElement)element)) + return true; + MessageDialog.openInformation(shell, + ActionMessages.getString("ActionUtil.notOnBuildPath.title"), //$NON-NLS-1$ + ActionMessages.getString("ActionUtil.notOnBuildPath.message")); //$NON-NLS-1$ + return false; + } + + public static boolean isOnBuildPath(ICElement element) { + //fix for bug http://dev.eclipse.org/bugs/show_bug.cgi?id=20051 + if (element.getElementType() == ICElement.C_PROJECT) + return true; +// ICProject project= element.getCProject(); +// if (!project.isOnSourceRoot(element.getResource())) +// return false; + return true; + } +} + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CompositeActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CompositeActionGroup.java new file mode 100644 index 00000000000..ff90faea8c5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CompositeActionGroup.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.actions; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.util.Assert; + +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.actions.ActionGroup; + +public class CompositeActionGroup extends ActionGroup { + + private ActionGroup[] fGroups; + + public CompositeActionGroup() { + } + + public CompositeActionGroup(ActionGroup[] groups) { + setGroups(groups); + } + + protected void setGroups(ActionGroup[] groups) { + Assert.isTrue(fGroups == null); + Assert.isNotNull(groups); + fGroups= groups; + } + + public ActionGroup get(int index) { + if (fGroups == null) + return null; + return fGroups[index]; + } + + public void addGroup(ActionGroup group) { + if (fGroups == null) { + fGroups= new ActionGroup[] { group }; + } else { + ActionGroup[] newGroups= new ActionGroup[fGroups.length + 1]; + System.arraycopy(fGroups, 0, newGroups, 0, fGroups.length); + newGroups[fGroups.length]= group; + fGroups= newGroups; + } + } + + public void dispose() { + super.dispose(); + if (fGroups == null) + return; + for (int i= 0; i < fGroups.length; i++) { + fGroups[i].dispose(); + } + } + + public void fillActionBars(IActionBars actionBars) { + super.fillActionBars(actionBars); + if (fGroups == null) + return; + for (int i= 0; i < fGroups.length; i++) { + fGroups[i].fillActionBars(actionBars); + } + } + + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + if (fGroups == null) + return; + for (int i= 0; i < fGroups.length; i++) { + fGroups[i].fillContextMenu(menu); + } + } + + public void setContext(ActionContext context) { + super.setContext(context); + if (fGroups == null) + return; + for (int i= 0; i < fGroups.length; i++) { + fGroups[i].setContext(context); + } + } + + public void updateActionBars() { + super.updateActionBars(); + if (fGroups == null) + return; + for (int i= 0; i < fGroups.length; i++) { + fGroups[i].updateActionBars(); + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java new file mode 100644 index 00000000000..a0d2a21a7f0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; + +public class OpenActionUtil { + + private OpenActionUtil() { + // no instance. + } + + /** + * Opens the editor on the given element and subsequently selects it. + */ + public static void open(Object element) throws CModelException, PartInitException { + open(element, true); + } + + /** + * Opens the editor on the given element and subsequently selects it. + */ + public static void open(Object element, boolean activate) throws CModelException, PartInitException { + IEditorPart part= EditorUtility.openInEditor(element, activate); + if (element instanceof ICElement) + EditorUtility.revealInEditor(part, (ICElement)element); + } + + /** + * Filters out source references from the given code resolve results. + * A utility method that can be called by subclassers. + */ + public static List filterResolveResults(ICElement[] codeResolveResults) { + int nResults= codeResolveResults.length; + List refs= new ArrayList(nResults); + for (int i= 0; i < nResults; i++) { + if (codeResolveResults[i] instanceof ISourceReference) + refs.add(codeResolveResults[i]); + } + return refs; + } + + /** + * Shows a dialog for resolving an ambigous C element. + * Utility method that can be called by subclassers. + */ + public static ICElement selectCElement(ICElement[] elements, Shell shell, String title, String message) { + + int nResults= elements.length; + + if (nResults == 0) + return null; + + if (nResults == 1) + return elements[0]; + + int flags= CElementLabelProvider.SHOW_DEFAULT + | CElementLabelProvider.SHOW_QUALIFIED; +// | CElementLabelProvider.SHOW_ROOT; + + ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, new CElementLabelProvider(flags)); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.setElements(elements); + + if (dialog.open() == Window.OK) { + Object[] selection= dialog.getResult(); + if (selection != null && selection.length > 0) { + nResults= selection.length; + for (int i= 0; i < nResults; i++) { + Object current= selection[i]; + if (current instanceof ICElement) + return (ICElement) current; + } + } + } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectAllAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectAllAction.java new file mode 100644 index 00000000000..3d34dbfb9e1 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectAllAction.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.actions; + +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.actions.ActionMessages; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.TableViewer; + +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * This action selects all entries currently showing in view. + */ +public class SelectAllAction extends Action { + + private TableViewer fViewer; + + /** + * Creates the action. + */ + public SelectAllAction(TableViewer viewer) { + super("selectAll"); //$NON-NLS-1$ + setText(ActionMessages.getString("SelectAllAction.label")); //$NON-NLS-1$ + setToolTipText(ActionMessages.getString("SelectAllAction.tooltip")); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.SELECT_ALL_ACTION); + Assert.isNotNull(viewer); + fViewer= viewer; + } + + /** + * Selects all resources in the view. + */ + public void run() { + fViewer.getTable().selectAll(); + // force viewer selection change + fViewer.setSelection(fViewer.getSelection()); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/SelectionConverter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java similarity index 56% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/SelectionConverter.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java index 843d8a67a8b..5638005305d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/SelectionConverter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java @@ -9,7 +9,7 @@ * QNX Software Systems - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.ui.cview; +package org.eclipse.cdt.internal.ui.actions; import java.util.ArrayList; import java.util.Iterator; @@ -17,8 +17,12 @@ import java.util.List; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceRange; +import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.core.resources.IResource; @@ -27,11 +31,14 @@ import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.ITextEditor; public class SelectionConverter { + protected static final ICElement[] EMPTY_RESULT= new ICElement[0]; + public static IStructuredSelection convertSelectionToCElements(ISelection s) { List converted = new ArrayList(); if (s instanceof StructuredSelection) { @@ -126,6 +133,10 @@ public class SelectionConverter { return getElementAtOffset(getInput(editor), (ITextSelection) editor.getSelectionProvider().getSelection()); } + public static ICElement[] getElementsAtOffset(ITextEditor editor) throws CModelException { + return getElementsAtOffset(getInput(editor), (ITextSelection) editor.getSelectionProvider().getSelection()); + } + public static ICElement getElementAtOffset(ICElement input, ITextSelection selection) throws CModelException { if (input instanceof ITranslationUnit) { ITranslationUnit tunit = (ITranslationUnit) input; @@ -145,6 +156,25 @@ public class SelectionConverter { return null; } + public static ICElement[] getElementsAtOffset(ICElement input, ITextSelection selection) throws CModelException { + if (input instanceof ITranslationUnit) { + ITranslationUnit tunit = (ITranslationUnit) input; + if (tunit.isWorkingCopy()) { + synchronized (tunit) { + if (tunit instanceof IWorkingCopy) { + ((IWorkingCopy) tunit).reconcile(); + } + } + } + ICElement[] refs = tunit.getElementsAtOffset(selection.getOffset()); + if (refs == null) + return new ICElement[] { input }; + else + return refs; + } + return null; + } + public static ICElement getInput(ITextEditor editor) { if (editor == null) return null; IEditorInput input = editor.getEditorInput(); @@ -169,4 +199,91 @@ public class SelectionConverter { return (resource.getType() & resourceMask) != 0; } + public static ICElement[] codeResolve(CEditor editor) throws CModelException { + return codeResolve(getInput(editor), (ITextSelection)editor.getSelectionProvider().getSelection()); + } + + public static ICElement[] codeResolve(ICElement input, ITextSelection selection) throws CModelException { + if (input instanceof ITranslationUnit) { + ITranslationUnit tunit = (ITranslationUnit) input; + if (tunit.isWorkingCopy()) { + synchronized (tunit) { + if (tunit instanceof IWorkingCopy) { + ((IWorkingCopy) tunit).reconcile(); + } + } + } + ICElement[] elems = tunit.getElementsAtOffset(selection.getOffset()); + if (elems != null) { + for (int i = 0; i < elems.length; ++i) { + ICElement elem = elems[i]; + if (elem instanceof ISourceReference) { + String text = selection.getText(); + if (text.equals(elem.getElementName())) { + return new ICElement[] { elem }; + } + } + } + for (int i = 0; i < elems.length; ++i) { + ICElement elem = elems[i]; + if (elem instanceof ISourceReference) { + ISourceRange range = ((ISourceReference)elem).getSourceRange(); + if (range.getStartPos() == selection.getOffset()) { + return new ICElement[] { elem }; + } + } + } + } + } + return EMPTY_RESULT; + } + + /** + * Converts the text selection provided by the given editor a Java element by + * asking the user if code reolve returned more than one result. If the selection + * doesn't cover a Java element null is returned. + */ + public static ICElement codeResolve(CEditor editor, Shell shell, String title, String message) throws CModelException { + ICElement[] elements= codeResolve(editor); + if (elements == null || elements.length == 0) + return null; + ICElement candidate= elements[0]; + if (elements.length > 1) { + candidate= OpenActionUtil.selectCElement(elements, shell, title, message); + } + return candidate; + } + + + /** + * Converts the text selection provided by the given editor into an array of + * C elements. If the selection doesn't cover a C element and the selection's + * length is greater than 0 the method returns the editor's input element. + */ + public static ICElement[] codeResolveOrInput(CEditor editor) throws CModelException { + ICElement input= getInput(editor); + ITextSelection selection= (ITextSelection)editor.getSelectionProvider().getSelection(); + ICElement[] result= codeResolve(input, selection); + if (result.length == 0) { + result= new ICElement[] {input}; + } + return result; + } + + public static ICElement[] codeResolveOrInputHandled(CEditor editor, Shell shell, String title) { + try { + return codeResolveOrInput(editor); + } catch(CModelException e) { + ExceptionHandler.handle(e, shell, title, ActionMessages.getString("SelectionConverter.codeResolve_failed")); //$NON-NLS-1$ + } + return null; + } + + public static boolean canOperateOn(CEditor editor) { + if (editor == null) + return false; + return getInput(editor) != null; + + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java index b0e36ae16b6..0b2ea05a92f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.cdt.internal.ui.drag.DelegatingDragAdapter; import org.eclipse.cdt.internal.ui.drag.FileTransferDragAdapter; import org.eclipse.cdt.internal.ui.drag.LocalSelectionTransferDragAdapter; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/GotoActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/GotoActionGroup.java index 500fa0c2b15..e39d69ff48b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/GotoActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/GotoActionGroup.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.cview; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java index c34b714a815..fb965ab319a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.ui.cview; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.ui.IContextMenuConstants; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/OpenFileGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/OpenFileGroup.java index 17d70c52753..ef2d17fb5d8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/OpenFileGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/OpenFileGroup.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.cview; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/RefactorActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/RefactorActionGroup.java index e33cbc559c2..3050c431373 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/RefactorActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/RefactorActionGroup.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.cview; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.core.resources.IResource; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.viewers.IStructuredSelection; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index 4fdbbf216a8..94272d5c2a6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; import org.eclipse.cdt.ui.CElementContentProvider; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.actions.MemberFilterActionGroup; +import org.eclipse.cdt.ui.actions.OpenViewActionGroup; import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -41,6 +42,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.part.IPageSite; @@ -61,6 +63,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS private ActionGroup fSelectionSearchGroup; private ActionGroup fRefactoringActionGroup; + private ActionGroup fOpenViewActionGroup; public CContentOutlinePage(CEditor editor) { this("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$ @@ -123,6 +126,13 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS protected void contextMenuAboutToShow(IMenuManager menu) { CUIPlugin.createStandardGroups(menu); + if (OpenViewActionGroup.canActionBeAdded(getSelection())){ + fOpenViewActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection())); + fOpenViewActionGroup.fillContextMenu(menu); + fOpenViewActionGroup.setContext(null); + menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + if (OpenIncludeAction.canActionBeAdded(getSelection())) { menu.add(fOpenIncludeAction); } @@ -182,6 +192,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS fSelectionSearchGroup = new SelectionSearchGroup(this); fRefactoringActionGroup = new RefactoringActionGroup(this, null); + fOpenViewActionGroup = new OpenViewActionGroup(this); treeViewer.setInput(fInput); WorkbenchHelp.setHelp(control, ICHelpContextIds.COUTLINE_VIEW); @@ -208,6 +219,10 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS fRefactoringActionGroup.dispose(); fRefactoringActionGroup= null; } + if (fOpenViewActionGroup != null) { + fOpenViewActionGroup.dispose(); + fOpenViewActionGroup= null; + } if (fSelectionSearchGroup != null) { fSelectionSearchGroup.dispose(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index 41353f22d2f..b924f930d72 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.internal.ui.IContextMenuConstants; +import org.eclipse.cdt.internal.ui.browser.typehierarchy.OpenTypeHierarchyAction; import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; @@ -549,6 +550,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL); setAction("OpenDeclarations", action); //$NON-NLS-1$ + action = new OpenTypeHierarchyAction(this); + action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); + setAction("OpenTypeHierarchy", action); //$NON-NLS-1$ + fShowInCViewAction = new ShowInCViewAction(this); action = fShowInCViewAction; action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW); @@ -579,6 +584,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDeclarations"); //$NON-NLS-1$ + addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenTypeHierarchy"); //$NON-NLS-1$ + addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java index a15915fce19..c760598f287 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java @@ -79,6 +79,7 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition * (value "org.eclipse.cdt.ui.edit.text.redo.action"). */ public static final String REDO_ACTION= "org.eclipse.cdt.ui.edit.text.redo.action"; //$NON-NLS-1$ + /** * Action definition ID of the find references in workspace action * (value "org.eclipse.cdt.ui.search.findrefs"). @@ -89,4 +90,16 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition * (value "org.eclipse.cdt.ui.search.finddecl"). */ public static final String FIND_DECL= "org.eclipse.cdt.ui.search.finddecl"; //$NON-NLS-1$ + + /** + * Action definition ID of the navigate -> open type hierarchy action + * (value "org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"). + */ + public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"; //$NON-NLS-1$ + + /** + * Action definition ID of the navigate -> open action + * (value "org.eclipse.cdt.ui.edit.text.c.open.editor"). + */ + public static final String OPEN_EDITOR= "org.eclipse.cdt.ui.edit.text.c.open.editor"; //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/MemberFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/MemberFilter.java index 239e52a07c0..c0dbdff472b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/MemberFilter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/MemberFilter.java @@ -29,6 +29,7 @@ public class MemberFilter extends ViewerFilter{ public static final int FILTER_NONPUBLIC= 1; public static final int FILTER_STATIC= 2; public static final int FILTER_FIELDS= 4; + public static final int FILTER_LOCALTYPES= 8; private int fFilterProperties; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java index 6338230ea85..0f5edb267f7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.CElementImageProvider; import org.eclipse.cdt.internal.ui.ErrorTickAdornmentProvider; import org.eclipse.cdt.internal.ui.IAdornmentProvider; import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; +import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.model.WorkbenchLabelProvider; @@ -82,7 +83,7 @@ public class CElementLabelProvider extends LabelProvider { public final static int SHOW_DEFAULT= new Integer(SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue(); private WorkbenchLabelProvider fWorkbenchLabelProvider; - private CElementImageProvider fImageLabelProvider; + protected CElementImageProvider fImageLabelProvider; private IAdornmentProvider[] fAdornmentProviders; private int fFlags; @@ -186,6 +187,7 @@ public class CElementLabelProvider extends LabelProvider { IBinary bin = (IBinary)celem; name.append(" - [" + bin.getCPU() + (bin.isLittleEndian() ? "le" : "be") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } + return name.toString(); } catch (CModelException e) { CUIPlugin.getDefault().log(e); @@ -198,13 +200,27 @@ public class CElementLabelProvider extends LabelProvider { * @see ILabelProvider#getImage */ public Image getImage(Object element) { + return fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element)); + } + + protected int evaluateImageFlags(Object element) { int imageFlags= getImageFlags(); if (fAdornmentProviders != null) { for (int i= 0; i < fAdornmentProviders.length; i++) { imageFlags |= fAdornmentProviders[i].computeAdornmentFlags(element); } - } - return fImageLabelProvider.getImageLabel(element, imageFlags); + } + return imageFlags; + } + + protected Image decorateImage(Image image, Object element) { +// if (fLabelDecorators != null && image != null) { +// for (int i= 0; i < fLabelDecorators.size(); i++) { +// ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i); +// image= decorator.decorateImage(image, element); +// } +// } + return image; } /** @@ -278,6 +294,9 @@ public class CElementLabelProvider extends LabelProvider { if (getFlag(SHOW_EXCEPTION)) { fTextFlags |= CElementLabels.M_EXCEPTIONS; } + if (getFlag(SHOW_POST_QUALIFIED)) { + fTextFlags |= CElementLabels.M_POST_QUALIFIED; + } return fTextFlags; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java index 33e13934123..96faa2ca3c7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java @@ -228,19 +228,45 @@ public class CElementSorter extends ViewerSorter { } String name1; + boolean e1destructor = false; String name2; + boolean e2destructor = false; if (e1 instanceof ICElement) { name1 = ((ICElement)e1).getElementName(); + if (e1 instanceof IMethodDeclaration) { + IMethodDeclaration method = (IMethodDeclaration)e1; + try { + if (method.isDestructor()) { + name1 = ((ICElement)e1).getElementName().substring(1); + e1destructor = true; + } + } catch (CModelException e) { + } + } } else { name1 = e1.toString(); } if (e2 instanceof ICElement) { name2 = ((ICElement)e2).getElementName(); + if (e2 instanceof IMethodDeclaration) { + IMethodDeclaration method = (IMethodDeclaration)e2; + try { + if (method.isDestructor()) { + name2 = ((ICElement)e2).getElementName().substring(1); + e2destructor = true; + } + } catch (CModelException e) { + } + } } else { name2 = e2.toString(); } - return getCollator().compare(name1, name2); + int result = getCollator().compare(name1, name2); + if (result == 0 && (e1destructor != e2destructor)) { + result = e1destructor ? 1 : -1; + } + return result; } private ISourceRoot getSourceRoot(Object element) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index e71318e8025..4de101c9e19 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -161,6 +161,21 @@ public class CUIPlugin extends AbstractUIPlugin { */ public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$ + /** + * The view part id of the type hierarchy part + * (value "org.eclipse.cdt.ui.TypeHierarchy"). + *

+ * When this id is used to access + * a view part with IWorkbenchPage.findView or + * showView, the returned IViewPart + * can be safely cast to an ITypeHierarchyViewPart. + *

+ * + * @see ITypeHierarchyViewPart + * @see org.eclipse.ui.IWorkbenchPage#findView(java.lang.String) + * @see org.eclipse.ui.IWorkbenchPage#showView(java.lang.String) + */ + public static final String ID_TYPE_HIERARCHY = "org.eclipse.cdt.ui.TypeHierarchyView"; //$NON-NLS-1$ // -------- static methods -------- diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java index 051cb32d214..88a6a7892ef 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java @@ -240,6 +240,34 @@ public class PreferenceConstants { */ public static final String LINK_BROWSING_MEMBERS_TO_EDITOR= "org.eclipse.cdt.ui.browsing.memberstoeditor"; //$NON-NLS-1$ + /** + * A named preference that controls if a new type hierarchy gets opened in a + * new type hierarchy perspective or inside the type hierarchy view part. + *

+ * Value is of type String: possible values are + * OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE or + * OPEN_TYPE_HIERARCHY_IN_VIEW_PART. + *

+ * + * @see #OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE + * @see #OPEN_TYPE_HIERARCHY_IN_VIEW_PART + */ + public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.cdt.ui.openTypeHierarchy"; //$NON-NLS-1$ + + /** + * A string value used by the named preference OPEN_TYPE_HIERARCHY. + * + * @see #OPEN_TYPE_HIERARCHY + */ + public static final String OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE= "perspective"; //$NON-NLS-1$ + + /** + * A string value used by the named preference OPEN_TYPE_HIERARCHY. + * + * @see #OPEN_TYPE_HIERARCHY + */ + public static final String OPEN_TYPE_HIERARCHY_IN_VIEW_PART= "viewPart"; //$NON-NLS-1$ + /** * Returns the JDT-UI preference store. * diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CdtActionConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CdtActionConstants.java new file mode 100644 index 00000000000..154b680bbdf --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CdtActionConstants.java @@ -0,0 +1,530 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.actions; + +/** + * Action ids for standard actions, for groups in the menu bar, and + * for actions in context menus of CDT views. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class CdtActionConstants { + + // Navigate menu + + /** + * Navigate menu: name of standard Goto Type global action + * (value "org.eclipse.cdt.ui.actions.GoToType"). + */ + public static final String GOTO_TYPE= "org.eclipse.cdt.ui.actions.GoToType"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Goto Package global action + * (value "org.eclipse.cdt.ui.actions.GoToPackage"). + */ + public static final String GOTO_PACKAGE= "org.eclipse.cdt.ui.actions.GoToPackage"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Open global action + * (value "org.eclipse.cdt.ui.actions.Open"). + */ + public static final String OPEN= "org.eclipse.cdt.ui.actions.Open"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Open Super Implementation global action + * (value "org.eclipse.cdt.ui.actions.OpenSuperImplementation"). + */ + public static final String OPEN_SUPER_IMPLEMENTATION= "org.eclipse.cdt.ui.actions.OpenSuperImplementation"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Open Type Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.OpenTypeHierarchy"). + */ + public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.cdt.ui.actions.OpenTypeHierarchy"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Open Call Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.OpenCallHierarchy"). + * @since 3.0 + */ + public static final String OPEN_CALL_HIERARCHY= "org.eclipse.cdt.ui.actions.OpenCallHierarchy"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Open External Javadoc global action + * (value "org.eclipse.cdt.ui.actions.OpenExternalJavaDoc"). + */ + public static final String OPEN_EXTERNAL_JAVA_DOC= "org.eclipse.cdt.ui.actions.OpenExternalJavaDoc"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Show in Packages View global action + * (value "org.eclipse.cdt.ui.actions.ShowInPackagesView"). + */ + public static final String SHOW_IN_PACKAGE_VIEW= "org.eclipse.cdt.ui.actions.ShowInPackagesView"; //$NON-NLS-1$ + + /** + * Navigate menu: name of standard Show in Navigator View global action + * (value "org.eclipse.cdt.ui.actions.ShowInNaviagtorView"). + */ + public static final String SHOW_IN_NAVIGATOR_VIEW= "org.eclipse.cdt.ui.actions.ShowInNaviagtorView"; //$NON-NLS-1$ + + // Edit menu + + /** + * Edit menu: name of standard Show Javadoc global action + * (value "org.eclipse.cdt.ui.actions.ShowJavaDoc"). + */ + public static final String SHOW_JAVA_DOC= "org.eclipse.cdt.ui.actions.ShowJavaDoc"; //$NON-NLS-1$ + + /** + * Edit menu: name of standard Code Assist global action + * (value "org.eclipse.cdt.ui.actions.ContentAssist"). + */ + public static final String CONTENT_ASSIST= "org.eclipse.cdt.ui.actions.ContentAssist"; //$NON-NLS-1$ + + // Source menu + + /** + * Source menu: name of standard Comment global action + * (value "org.eclipse.cdt.ui.actions.Comment"). + */ + public static final String COMMENT= "org.eclipse.cdt.ui.actions.Comment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Uncomment global action + * (value "org.eclipse.cdt.ui.actions.Uncomment"). + */ + public static final String UNCOMMENT= "org.eclipse.cdt.ui.actions.Uncomment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard ToggleComment global action + * (value "org.eclipse.cdt.ui.actions.ToggleComment"). + * @since 3.0 + */ + public static final String TOGGLE_COMMENT= "org.eclipse.cdt.ui.actions.ToggleComment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Block Comment global action + * (value "org.eclipse.cdt.ui.actions.AddBlockComment"). + * + * @since 3.0 + */ + public static final String ADD_BLOCK_COMMENT= "org.eclipse.cdt.ui.actions.AddBlockComment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Block Uncomment global action + * (value "org.eclipse.cdt.ui.actions.RemoveBlockComment"). + * + * @since 3.0 + */ + public static final String REMOVE_BLOCK_COMMENT= "org.eclipse.cdt.ui.actions.RemoveBlockComment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Indent global action + * (value "org.eclipse.cdt.ui.actions.Indent"). + * + * @since 3.0 + */ + public static final String INDENT= "org.eclipse.cdt.ui.actions.Indent"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Shift Right action + * (value "org.eclipse.cdt.ui.actions.ShiftRight"). + */ + public static final String SHIFT_RIGHT= "org.eclipse.cdt.ui.actions.ShiftRight"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Shift Left global action + * (value "org.eclipse.cdt.ui.actions.ShiftLeft"). + */ + public static final String SHIFT_LEFT= "org.eclipse.cdt.ui.actions.ShiftLeft"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Format global action + * (value "org.eclipse.cdt.ui.actions.Format"). + */ + public static final String FORMAT= "org.eclipse.cdt.ui.actions.Format"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Format Element global action + * (value "org.eclipse.cdt.ui.actions.FormatElement"). + * @since 3.0 + */ + public static final String FORMAT_ELEMENT= "org.eclipse.cdt.ui.actions.FormatElement"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Add Import global action + * (value "org.eclipse.cdt.ui.actions.AddImport"). + */ + public static final String ADD_IMPORT= "org.eclipse.cdt.ui.actions.AddImport"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Organize Imports global action + * (value "org.eclipse.cdt.ui.actions.OrganizeImports"). + */ + public static final String ORGANIZE_IMPORTS= "org.eclipse.cdt.ui.actions.OrganizeImports"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Sort Members global action (value + * "org.eclipse.cdt.ui.actions.SortMembers"). + * @since 2.1 + */ + public static final String SORT_MEMBERS= "org.eclipse.cdt.ui.actions.SortMembers"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Surround with try/catch block global action + * (value "org.eclipse.cdt.ui.actions.SurroundWithTryCatch"). + */ + public static final String SURROUND_WITH_TRY_CATCH= "org.eclipse.cdt.ui.actions.SurroundWithTryCatch"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Override Methods global action + * (value "org.eclipse.cdt.ui.actions.OverrideMethods"). + */ + public static final String OVERRIDE_METHODS= "org.eclipse.cdt.ui.actions.OverrideMethods"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Generate Getter and Setter global action + * (value "org.eclipse.cdt.ui.actions.GenerateGetterSetter"). + */ + public static final String GENERATE_GETTER_SETTER= "org.eclipse.cdt.ui.actions.GenerateGetterSetter"; //$NON-NLS-1$ + + /** + * Source menu: name of standard delegate methods global action (value + * "org.eclipse.cdt.ui.actions.GenerateDelegateMethods"). + * @since 2.1 + */ + public static final String GENERATE_DELEGATE_METHODS= "org.eclipse.cdt.ui.actions.GenerateDelegateMethods"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Add Constructor From Superclass global action + * (value "org.eclipse.cdt.ui.actions.AddConstructorFromSuperclass"). + */ + public static final String ADD_CONSTRUCTOR_FROM_SUPERCLASS= "org.eclipse.cdt.ui.actions.AddConstructorFromSuperclass"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Generate Constructor using Fields global action + * (value "org.eclipse.cdt.ui.actions.GenerateConstructorUsingFields"). + */ + public static final String GENERATE_CONSTRUCTOR_USING_FIELDS= "org.eclipse.cdt.ui.actions.GenerateConstructorUsingFields"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Add Javadoc Comment global action + * (value "org.eclipse.cdt.ui.actions.AddJavaDocComment"). + */ + public static final String ADD_JAVA_DOC_COMMENT= "org.eclipse.cdt.ui.actions.AddJavaDocComment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Find Strings to Externalize global action + * (value "org.eclipse.cdt.ui.actions.FindStringsToExternalize"). + */ + public static final String FIND_STRINGS_TO_EXTERNALIZE= "org.eclipse.cdt.ui.actions.FindStringsToExternalize"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Externalize Strings global action + * (value "org.eclipse.cdt.ui.actions.ExternalizeStrings"). + */ + public static final String EXTERNALIZE_STRINGS= "org.eclipse.cdt.ui.actions.ExternalizeStrings"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Convert Line Delimiters To Windows global action + * (value "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToWindows"). + */ + public static final String CONVERT_LINE_DELIMITERS_TO_WINDOWS= "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToWindows"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Convert Line Delimiters To UNIX global action + * (value "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToUNIX"). + */ + public static final String CONVERT_LINE_DELIMITERS_TO_UNIX= "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToUNIX"; //$NON-NLS-1$ + + /** + * Source menu: name of standardConvert Line Delimiters To Mac global action + * (value "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToMac"). + */ + public static final String CONVERT_LINE_DELIMITERS_TO_MAC= "org.eclipse.cdt.ui.actions.ConvertLineDelimitersToMac"; //$NON-NLS-1$ + + // Refactor menu + + /** + * Refactor menu: name of standard Self Encapsulate Field global action + * (value "org.eclipse.cdt.ui.actions.SelfEncapsulateField"). + */ + public static final String SELF_ENCAPSULATE_FIELD= "org.eclipse.cdt.ui.actions.SelfEncapsulateField"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Modify Parameters global action + * (value "org.eclipse.cdt.ui.actions.ModifyParameters"). + */ + public static final String MODIFY_PARAMETERS= "org.eclipse.cdt.ui.actions.ModifyParameters"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Pull Up global action + * (value "org.eclipse.cdt.ui.actions.PullUp"). + */ + public static final String PULL_UP= "org.eclipse.cdt.ui.actions.PullUp"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Push Down global action + * (value "org.eclipse.cdt.ui.actions.PushDown"). + * + * @since 2.1 + */ + public static final String PUSH_DOWN= "org.eclipse.cdt.ui.actions.PushDown"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Move Element global action + * (value "org.eclipse.cdt.ui.actions.Move"). + */ + public static final String MOVE= "org.eclipse.cdt.ui.actions.Move"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Rename Element global action + * (value "org.eclipse.cdt.ui.actions.Rename"). + */ + public static final String RENAME= "org.eclipse.cdt.ui.actions.Rename"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Inline Temp global action + * (value "org.eclipse.cdt.ui.actions.InlineTemp"). + * @deprecated Use INLINE + */ + public static final String INLINE_TEMP= "org.eclipse.cdt.ui.actions.InlineTemp"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Extract Temp global action + * (value "org.eclipse.cdt.ui.actions.ExtractTemp"). + */ + public static final String EXTRACT_TEMP= "org.eclipse.cdt.ui.actions.ExtractTemp"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Extract Constant global action + * (value "org.eclipse.cdt.ui.actions.ExtractConstant"). + * + * @since 2.1 + */ + public static final String EXTRACT_CONSTANT= "org.eclipse.cdt.ui.actions.ExtractConstant"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Introduce Parameter global action + * (value "org.eclipse.cdt.ui.actions.IntroduceParameter"). + * + * @since 3.0 + */ + public static final String INTRODUCE_PARAMETER= "org.eclipse.cdt.ui.actions.IntroduceParameter"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Introduce Factory global action + * (value "org.eclipse.cdt.ui.actions.IntroduceFactory"). + * + * @since 3.0 + */ + public static final String INTRODUCE_FACTORY= "org.eclipse.cdt.ui.actions.IntroduceFactory"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Extract Method global action + * (value "org.eclipse.cdt.ui.actions.ExtractMethod"). + */ + public static final String EXTRACT_METHOD= "org.eclipse.cdt.ui.actions.ExtractMethod"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Inline global action + * (value "org.eclipse.cdt.ui.actions.Inline"). + * + * @since 2.1 + */ + public static final String INLINE= "org.eclipse.cdt.ui.actions.Inline"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Extract Interface global action + * (value "org.eclipse.cdt.ui.actions.ExtractInterface"). + * + * @since 2.1 + */ + public static final String EXTRACT_INTERFACE= "org.eclipse.cdt.ui.actions.ExtractInterface"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Generalize Type global action + * (value "org.eclipse.cdt.ui.actions.ChangeType"). + * + * @since 3.0 + */ + public static final String CHANGE_TYPE= "org.eclipse.cdt.ui.actions.ChangeType"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard global action to convert a nested type to a top level type + * (value "org.eclipse.cdt.ui.actions.MoveInnerToTop"). + * + * @since 2.1 + */ + public static final String CONVERT_NESTED_TO_TOP= "org.eclipse.cdt.ui.actions.ConvertNestedToTop"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Use Supertype global action + * (value "org.eclipse.cdt.ui.actions.UseSupertype"). + * + * @since 2.1 + */ + public static final String USE_SUPERTYPE= "org.eclipse.cdt.ui.actions.UseSupertype"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard global action to convert a local + * variable to a field (value "org.eclipse.cdt.ui.actions.ConvertLocalToField"). + * + * @since 2.1 + */ + public static final String CONVERT_LOCAL_TO_FIELD= "org.eclipse.cdt.ui.actions.ConvertLocalToField"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Covert Anonymous to Nested global action + * (value "org.eclipse.cdt.ui.actions.ConvertAnonymousToNested"). + * + * @since 2.1 + */ + public static final String CONVERT_ANONYMOUS_TO_NESTED= "org.eclipse.cdt.ui.actions.ConvertAnonymousToNested"; //$NON-NLS-1$ + + // Search Menu + + /** + * Search menu: name of standard Find References in Workspace global action + * (value "org.eclipse.cdt.ui.actions.ReferencesInWorkspace"). + */ + public static final String FIND_REFERENCES_IN_WORKSPACE= "org.eclipse.cdt.ui.actions.ReferencesInWorkspace"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find References in Project global action + * (value "org.eclipse.cdt.ui.actions.ReferencesInProject"). + */ + public static final String FIND_REFERENCES_IN_PROJECT= "org.eclipse.cdt.ui.actions.ReferencesInProject"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find References in Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.ReferencesInHierarchy"). + */ + public static final String FIND_REFERENCES_IN_HIERARCHY= "org.eclipse.cdt.ui.actions.ReferencesInHierarchy"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find References in Working Set global action + * (value "org.eclipse.cdt.ui.actions.ReferencesInWorkingSet"). + */ + public static final String FIND_REFERENCES_IN_WORKING_SET= "org.eclipse.cdt.ui.actions.ReferencesInWorkingSet"; //$NON-NLS-1$ + + + + /** + * Search menu: name of standard Find Declarations in Workspace global action + * (value "org.eclipse.cdt.ui.actions.DeclarationsInWorkspace"). + */ + public static final String FIND_DECLARATIONS_IN_WORKSPACE= "org.eclipse.cdt.ui.actions.DeclarationsInWorkspace"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Declarations in Project global action + * (value "org.eclipse.cdt.ui.actions.DeclarationsInProject"). + */ + public static final String FIND_DECLARATIONS_IN_PROJECT= "org.eclipse.cdt.ui.actions.DeclarationsInProject"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Declarations in Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.DeclarationsInHierarchy"). + */ + public static final String FIND_DECLARATIONS_IN_HIERARCHY= "org.eclipse.cdt.ui.actions.DeclarationsInHierarchy"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Declarations in Working Set global action + * (value "org.eclipse.cdt.ui.actions.DeclarationsInWorkingSet"). + */ + public static final String FIND_DECLARATIONS_IN_WORKING_SET= "org.eclipse.cdt.ui.actions.DeclarationsInWorkingSet"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Implementors in Workspace global action + * (value "org.eclipse.cdt.ui.actions.ImplementorsInWorkspace"). + */ + public static final String FIND_IMPLEMENTORS_IN_WORKSPACE= "org.eclipse.cdt.ui.actions.ImplementorsInWorkspace"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Implementors in Project global action + * (value "org.eclipse.cdt.ui.actions.ImplementorsInProject"). + */ + public static final String FIND_IMPLEMENTORS_IN_PROJECT= "org.eclipse.cdt.ui.actions.ImplementorsInProject"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Implementors in Working Set global action + * (value "org.eclipse.cdt.ui.actions.ImplementorsInWorkingSet"). + */ + public static final String FIND_IMPLEMENTORS_IN_WORKING_SET= "org.eclipse.cdt.ui.actions.ImplementorsInWorkingSet"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Workspace global action + * (value "org.eclipse.cdt.ui.actions.ReadAccessInWorkspace"). + */ + public static final String FIND_READ_ACCESS_IN_WORKSPACE= "org.eclipse.cdt.ui.actions.ReadAccessInWorkspace"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Project global action + * (value "org.eclipse.cdt.ui.actions.ReadAccessInProject"). + */ + public static final String FIND_READ_ACCESS_IN_PROJECT= "org.eclipse.cdt.ui.actions.ReadAccessInProject"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.ReadAccessInHierarchy"). + */ + public static final String FIND_READ_ACCESS_IN_HIERARCHY= "org.eclipse.cdt.ui.actions.ReadAccessInHierarchy"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Working Set global action + * (value "org.eclipse.cdt.ui.actions.ReadAccessInWorkingSet"). + */ + public static final String FIND_READ_ACCESS_IN_WORKING_SET= "org.eclipse.cdt.ui.actions.ReadAccessInWorkingSet"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Write Access in Workspace global action + * (value "org.eclipse.cdt.ui.actions.WriteAccessInWorkspace"). + */ + public static final String FIND_WRITE_ACCESS_IN_WORKSPACE= "org.eclipse.cdt.ui.actions.WriteAccessInWorkspace"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Write Access in Project global action + * (value "org.eclipse.cdt.ui.actions.WriteAccessInProject"). + */ + public static final String FIND_WRITE_ACCESS_IN_PROJECT= "org.eclipse.cdt.ui.actions.WriteAccessInProject"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Hierarchy global action + * (value "org.eclipse.cdt.ui.actions.WriteAccessInHierarchy"). + */ + public static final String FIND_WRITE_ACCESS_IN_HIERARCHY= "org.eclipse.cdt.ui.actions.WriteAccessInHierarchy"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find Read Access in Working Set global action + * (value "org.eclipse.cdt.ui.actions.WriteAccessInWorkingSet"). + */ + public static final String FIND_WRITE_ACCESS_IN_WORKING_SET= "org.eclipse.cdt.ui.actions.WriteAccessInWorkingSet"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Occurrences in File global action (value + * "org.eclipse.cdt.ui.actions.OccurrencesInFile"). + * + * @since 2.1 + */ + public static final String FIND_OCCURRENCES_IN_FILE= "org.eclipse.cdt.ui.actions.OccurrencesInFile"; //$NON-NLS-1$ + + /** + * Search menu: name of standard Find exception occurrences global action (value + * "org.eclipse.cdt.ui.actions.ExceptionOccurrences"). + * + * @since 3.0 + */ + public static final String FIND_EXCEPTION_OCCURRENCES= "org.eclipse.cdt.ui.actions.ExceptionOccurrences"; //$NON-NLS-1$ +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/MemberFilterActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/MemberFilterActionGroup.java index d544c2d2a8d..862841187ed 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/MemberFilterActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/MemberFilterActionGroup.java @@ -20,9 +20,12 @@ package org.eclipse.cdt.ui.actions; * state of the buttons changes. *

*/ +import java.util.ArrayList; + import org.eclipse.cdt.internal.ui.viewsupport.MemberFilter; import org.eclipse.cdt.internal.ui.viewsupport.MemberFilterAction; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.internal.ui.actions.ActionMessages; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; @@ -41,6 +44,9 @@ public class MemberFilterActionGroup extends ActionGroup { public static final int FILTER_STATIC= MemberFilter.FILTER_STATIC; public static final int FILTER_FIELDS= MemberFilter.FILTER_FIELDS; + public static final int FILTER_LOCALTYPES= MemberFilter.FILTER_LOCALTYPES; + public static final int ALL_FILTERS= FILTER_NONPUBLIC | FILTER_FIELDS | FILTER_STATIC | FILTER_LOCALTYPES; + private static final String TAG_HIDEFIELDS= "hidefields"; //$NON-NLS-1$ private static final String TAG_HIDESTATIC= "hidestatic"; //$NON-NLS-1$ private static final String TAG_HIDENONPUBLIC= "hidenonpublic"; //$NON-NLS-1$ @@ -124,6 +130,104 @@ public class MemberFilterActionGroup extends ActionGroup { fViewer.addFilter(fFilter); } + /** + * Creates a new MemberFilterActionGroup. + * + * @param viewer the viewer to be filtered + * @param viewerId a unique id of the viewer. Used as a key to to store + * the last used filter settings in the preference store + * @param inViewMenu if true the actions are added to the view + * menu. If false they are added to the toobar. + * @param availableFilters Specifies which filter action should be contained. FILTER_NONPUBLIC, + * FILTER_STATIC, FILTER_FIELDS and FILTER_LOCALTYPES + * or a combination of these constants are possible values. Use ALL_FILTERS to select all available filters. + */ + public MemberFilterActionGroup(StructuredViewer viewer, String viewerId, boolean inViewMenu, int availableFilters) { + + fViewer= viewer; + fViewerId= viewerId; + fInViewMenu= inViewMenu; + + IPreferenceStore store= PreferenceConstants.getPreferenceStore(); + fFilter= new MemberFilter(); + + String title, helpContext; + ArrayList actions= new ArrayList(4); + + // fields + int filterProperty= FILTER_FIELDS; + if (isSet(filterProperty, availableFilters)) { + boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); + if (filterEnabled) { + fFilter.addFilter(filterProperty); + } + title= ActionMessages.getString("MemberFilterActionGroup.hide_fields.label"); //$NON-NLS-1$ + helpContext= ICHelpContextIds.FILTER_FIELDS_ACTION; + MemberFilterAction hideFields= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); + hideFields.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_fields.description")); //$NON-NLS-1$ + hideFields.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_fields.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(hideFields, CPluginImages.T_LCL, "fields_co.gif"); //$NON-NLS-1$ + actions.add(hideFields); + } + + // static + filterProperty= FILTER_STATIC; + if (isSet(filterProperty, availableFilters)) { + boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); + if (filterEnabled) { + fFilter.addFilter(filterProperty); + } + title= ActionMessages.getString("MemberFilterActionGroup.hide_static.label"); //$NON-NLS-1$ + helpContext= ICHelpContextIds.FILTER_STATIC_ACTION; + MemberFilterAction hideStatic= new MemberFilterAction(this, title, FILTER_STATIC, helpContext, filterEnabled); + hideStatic.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_static.description")); //$NON-NLS-1$ + hideStatic.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_static.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(hideStatic, CPluginImages.T_LCL, "static_co.gif"); //$NON-NLS-1$ + actions.add(hideStatic); + } + + // non-public + filterProperty= FILTER_NONPUBLIC; + if (isSet(filterProperty, availableFilters)) { + boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); + if (filterEnabled) { + fFilter.addFilter(filterProperty); + } + title= ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.label"); //$NON-NLS-1$ + helpContext= ICHelpContextIds.FILTER_PUBLIC_ACTION; + MemberFilterAction hideNonPublic= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); + hideNonPublic.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.description")); //$NON-NLS-1$ + hideNonPublic.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(hideNonPublic, CPluginImages.T_LCL, "public_co.gif"); //$NON-NLS-1$ + actions.add(hideNonPublic); + } + + // local types + filterProperty= FILTER_LOCALTYPES; + if (isSet(filterProperty, availableFilters)) { + boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); + if (filterEnabled) { + fFilter.addFilter(filterProperty); + } + title= ActionMessages.getString("MemberFilterActionGroup.hide_localtypes.label"); //$NON-NLS-1$ + helpContext= ICHelpContextIds.FILTER_LOCALTYPES_ACTION; + MemberFilterAction hideLocalTypes= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); + hideLocalTypes.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_localtypes.description")); //$NON-NLS-1$ + hideLocalTypes.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_localtypes.tooltip")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(hideLocalTypes, CPluginImages.T_LCL, "localtypes_co.gif"); //$NON-NLS-1$ + actions.add(hideLocalTypes); + } + + // order corresponds to order in toolbar + fFilterActions= (MemberFilterAction[]) actions.toArray(new MemberFilterAction[actions.size()]); + + fViewer.addFilter(fFilter); + } + + private boolean isSet(int flag, int set) { + return (flag & set) != 0; + } + private String getPreferenceKey(int filterProperty) { return "MemberFilterActionGroup." + fViewerId + '.' + String.valueOf(filterProperty); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenAction.java new file mode 100644 index 00000000000..5ab314f43f4 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenAction.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.actions; + +import java.util.Iterator; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.ICStatusConstants; +import org.eclipse.cdt.internal.ui.actions.ActionMessages; +import org.eclipse.cdt.internal.ui.actions.ActionUtil; +import org.eclipse.cdt.internal.ui.actions.OpenActionUtil; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.util.OpenStrategy; +import org.eclipse.jface.viewers.IStructuredSelection; + +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.texteditor.IEditorStatusLine; + +/** + * This action opens a Java editor on a Java element or file. + *

+ * The action is applicable to selections containing elements of + * type ICompilationUnit, IMember + * or IFile. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class OpenAction extends SelectionDispatchAction { + + private CEditor fEditor; + + /** + * Creates a new OpenAction. The action requires + * that the selection provided by the site's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param site the site providing context information for this action + */ + public OpenAction(IWorkbenchSite site) { + super(site); + setText(ActionMessages.getString("OpenAction.label")); //$NON-NLS-1$ + setToolTipText(ActionMessages.getString("OpenAction.tooltip")); //$NON-NLS-1$ + setDescription(ActionMessages.getString("OpenAction.description")); //$NON-NLS-1$ + WorkbenchHelp.setHelp(this, ICHelpContextIds.OPEN_ACTION); + } + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + */ + public OpenAction(CEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + setText(ActionMessages.getString("OpenAction.declaration.label")); //$NON-NLS-1$ + setEnabled(SelectionConverter.canOperateOn(fEditor)); + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(ITextSelection selection) { + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(IStructuredSelection selection) { + setEnabled(checkEnabled(selection)); + } + + private boolean checkEnabled(IStructuredSelection selection) { + if (selection.isEmpty()) + return false; + for (Iterator iter= selection.iterator(); iter.hasNext();) { + Object element= iter.next(); + if (element instanceof ISourceReference) + continue; + if (element instanceof IFile) + continue; + if (element instanceof IStorage) + continue; + return false; + } + return true; + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(ITextSelection selection) { + if (!ActionUtil.isProcessable(getShell(), fEditor)) + return; + try { + ICElement element= SelectionConverter.codeResolve(fEditor, getShell(), getDialogTitle(), + ActionMessages.getString("OpenAction.select_element")); //$NON-NLS-1$ + if (element == null) { + IEditorStatusLine statusLine= (IEditorStatusLine) fEditor.getAdapter(IEditorStatusLine.class); + if (statusLine != null) + statusLine.setMessage(true, ActionMessages.getString("OpenAction.error.messageBadSelection"), null); //$NON-NLS-1$ + getShell().getDisplay().beep(); + return; + } + ICElement input= SelectionConverter.getInput(fEditor); + int type= element.getElementType(); + if (type == ICElement.C_PROJECT || type == ICElement.C_CCONTAINER) + element= input; + run(new Object[] {element} ); + } catch (CModelException e) { + showError(e); + } + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(IStructuredSelection selection) { + if (!checkEnabled(selection)) + return; + run(selection.toArray()); + } + + /** + * Note: this method is for internal use only. Clients should not call this method. + */ + public void run(Object[] elements) { + if (elements == null) + return; + for (int i= 0; i < elements.length; i++) { + Object element= elements[i]; + try { + element= getElementToOpen(element); + boolean activateOnOpen= fEditor != null ? true : OpenStrategy.activateOnOpen(); + OpenActionUtil.open(element, activateOnOpen); + } catch (CModelException e) { + CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), + ICStatusConstants.INTERNAL_ERROR, ActionMessages.getString("OpenAction.error.message"), e)); //$NON-NLS-1$ + + ErrorDialog.openError(getShell(), + getDialogTitle(), + ActionMessages.getString("OpenAction.error.messageProblems"), //$NON-NLS-1$ + e.getStatus()); + + } catch (PartInitException x) { + + String name= null; + + if (element instanceof ICElement) { + name= ((ICElement) element).getElementName(); + } else if (element instanceof IStorage) { + name= ((IStorage) element).getName(); + } else if (element instanceof IResource) { + name= ((IResource) element).getName(); + } + + if (name != null) { + MessageDialog.openError(getShell(), + ActionMessages.getString("OpenAction.error.messageProblems"), //$NON-NLS-1$ + ActionMessages.getFormattedString("OpenAction.error.messageArgs", //$NON-NLS-1$ + new String[] { name, x.getMessage() } )); + } + } + } + } + + /** + * Note: this method is for internal use only. Clients should not call this method. + */ + public Object getElementToOpen(Object object) throws CModelException { + return object; + } + + private String getDialogTitle() { + return ActionMessages.getString("OpenAction.error.title"); //$NON-NLS-1$ + } + + private void showError(CoreException e) { + ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.getString("OpenAction.error.message")); //$NON-NLS-1$ + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenViewActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenViewActionGroup.java new file mode 100644 index 00000000000..cad98df4afb --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/OpenViewActionGroup.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.actions; + +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.IContextMenuConstants; +import org.eclipse.cdt.internal.ui.browser.typehierarchy.OpenTypeHierarchyAction; +import org.eclipse.cdt.internal.ui.browser.typehierarchy.TypeHierarchyViewPart; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; + +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.dialogs.PropertyDialogAction; +import org.eclipse.ui.part.Page; + +/** + * Action group that adds actions to open a new JDT view part or an external + * viewer to a context menu and the global menu bar. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class OpenViewActionGroup extends ActionGroup { + + private boolean fEditorIsOwner; + private boolean fIsTypeHiararchyViewerOwner; +// private boolean fIsCallHiararchyViewerOwner; + private IWorkbenchSite fSite; + +// private OpenSuperImplementationAction fOpenSuperImplementation; +// private OpenExternalJavadocAction fOpenExternalJavadoc; + private OpenTypeHierarchyAction fOpenTypeHierarchy; +// private OpenCallHierarchyAction fOpenCallHierarchy; + private PropertyDialogAction fOpenPropertiesDialog; + + /** + * Creates a new OpenActionGroup. The group requires + * that the selection provided by the page's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param page the page that owns this action group + */ + public OpenViewActionGroup(Page page) { + createSiteActions(page.getSite()); + } + + /** + * Creates a new OpenActionGroup. The group requires + * that the selection provided by the part's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param part the view part that owns this action group + */ + public OpenViewActionGroup(IViewPart part) { + createSiteActions(part.getSite()); + fIsTypeHiararchyViewerOwner= part instanceof TypeHierarchyViewPart; +// fIsCallHiararchyViewerOwner= part instanceof ICallHierarchyViewPart; + } + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + */ + public OpenViewActionGroup(CEditor part) { + fEditorIsOwner= true; + +// fOpenSuperImplementation= new OpenSuperImplementationAction(part); +// fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); +// part.setAction("OpenSuperImplementation", fOpenSuperImplementation); //$NON-NLS-1$ + +// fOpenExternalJavadoc= new OpenExternalJavadocAction(part); +// fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); +// part.setAction("OpenExternalJavadoc", fOpenExternalJavadoc); //$NON-NLS-1$ + + fOpenTypeHierarchy= new OpenTypeHierarchyAction(part); + fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); + part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$ + +// fOpenCallHierarchy= new OpenCallHierarchyAction(part); +// fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); +// part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$ + + initialize(part.getEditorSite()); + } + + private void createSiteActions(IWorkbenchSite site) { +// fOpenSuperImplementation= new OpenSuperImplementationAction(site); +// fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); +// +// fOpenExternalJavadoc= new OpenExternalJavadocAction(site); +// fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); + + fOpenTypeHierarchy= new OpenTypeHierarchyAction(site); + fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); + +// fOpenCallHierarchy= new OpenCallHierarchyAction(site); +// fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); + + fOpenPropertiesDialog= new PropertyDialogAction(site.getShell(), site.getSelectionProvider()); + fOpenPropertiesDialog.setActionDefinitionId("org.eclipse.ui.file.properties"); //$NON-NLS-1$ + + initialize(site); + } + + private void initialize(IWorkbenchSite site) { + fSite= site; + ISelectionProvider provider= fSite.getSelectionProvider(); + ISelection selection= provider.getSelection(); +// fOpenSuperImplementation.update(selection); +// fOpenExternalJavadoc.update(selection); + fOpenTypeHierarchy.update(selection); +// fOpenCallHierarchy.update(selection); + if (!fEditorIsOwner) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss= (IStructuredSelection)selection; + fOpenPropertiesDialog.selectionChanged(ss); + } else { + fOpenPropertiesDialog.selectionChanged(selection); + } +// provider.addSelectionChangedListener(fOpenSuperImplementation); +// provider.addSelectionChangedListener(fOpenExternalJavadoc); + provider.addSelectionChangedListener(fOpenTypeHierarchy); +// provider.addSelectionChangedListener(fOpenCallHierarchy); + // no need to register the open properties dialog action since it registers itself + } + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillActionBars(IActionBars actionBar) { + super.fillActionBars(actionBar); + setGlobalActionHandlers(actionBar); + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + if (!fIsTypeHiararchyViewerOwner) + appendToGroup(menu, fOpenTypeHierarchy); +// if (!fIsCallHiararchyViewerOwner) +// appendToGroup(menu, fOpenCallHierarchy); +// appendToGroup(menu, fOpenSuperImplementation); + IStructuredSelection selection= getStructuredSelection(); + if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection)) + menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); + } + + /* + * @see ActionGroup#dispose() + */ + public void dispose() { + ISelectionProvider provider= fSite.getSelectionProvider(); +// provider.removeSelectionChangedListener(fOpenSuperImplementation); +// provider.removeSelectionChangedListener(fOpenExternalJavadoc); + provider.removeSelectionChangedListener(fOpenTypeHierarchy); +// provider.removeSelectionChangedListener(fOpenCallHierarchy); + super.dispose(); + } + + private void setGlobalActionHandlers(IActionBars actionBars) { +// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_SUPER_IMPLEMENTATION, fOpenSuperImplementation); +// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc); + actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy); +// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy); + actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog); + } + + private void appendToGroup(IMenuManager menu, IAction action) { + if (action.isEnabled()) + menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action); + } + + private IStructuredSelection getStructuredSelection() { + ISelection selection= getContext().getSelection(); + if (selection instanceof IStructuredSelection) + return (IStructuredSelection)selection; + return null; + } + + public static boolean canActionBeAdded(ISelection selection) { + if(selection instanceof ITextSelection) { + return (((ITextSelection)selection).getLength() > 0); + } else { + return getElement(selection) != null; + } + } + + private static ICElement getElement(ISelection sel) { + if (!sel.isEmpty() && sel instanceof IStructuredSelection) { + List list= ((IStructuredSelection)sel).toList(); + if (list.size() == 1) { + Object element= list.get(0); + if (element instanceof ICElement) { + return (ICElement)element; + } + } + } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ShowInCViewAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ShowInCViewAction.java index e9f87666dc9..fd99d4fb895 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ShowInCViewAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ShowInCViewAction.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.ui.actions; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.ui.cview.SelectionConverter; +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.jface.text.ITextSelection;