1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 03:05:39 +02:00

2004-07-15 Chris Wiebe

Initial draft for the type hierarchy view.
	* browser/*
	* icons/*
This commit is contained in:
Alain Magloire 2004-07-15 18:27:15 +00:00
parent 143ff15904
commit b1ee9d479f
103 changed files with 7219 additions and 35 deletions

View file

@ -1,3 +1,9 @@
2004-07-15 Chris Wiebe
Initial draft for the type hierarchy view.
* browser/*
* icons/*
2004-07-15 Hoda Amer 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) 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)

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.browser.AllTypesCache;
import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference; import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.TypeSearchScope; 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.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; 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) { for (int j = 0; j < enclosedTypes.length; ++j) {
ITypeInfo enclosedType = enclosedTypes[j]; ITypeInfo enclosedType = enclosedTypes[j];
if (enclosedType.getResolvedReference() != null) { 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)))) { if (typeElem != null && (typeElem.equals(cElem) || (typeElem instanceof IParent && hasChild(typeElem, cElem)))) {
return namespaces[i]; return namespaces[i];
} }
@ -819,7 +820,7 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
for (int j = 0; j < enclosedTypes.length; ++j) { for (int j = 0; j < enclosedTypes.length; ++j) {
ITypeInfo enclosedType = enclosedTypes[j]; ITypeInfo enclosedType = enclosedTypes[j];
if (enclosedType.getResolvedReference() != null) { 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)))) { if (typeElem != null && (typeElem.equals(cElem) || (typeElem instanceof IParent && hasChild(typeElem, cElem)))) {
return enclosedType; return enclosedType;
} }

View file

@ -16,6 +16,7 @@ import java.util.Iterator;
import org.eclipse.cdt.core.browser.AllTypesCache; import org.eclipse.cdt.core.browser.AllTypesCache;
import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference; 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.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
@ -184,7 +185,7 @@ class MembersViewContentProvider extends CBrowsingContentProvider {
ICElement elem = null; ICElement elem = null;
if (location != null) if (location != null)
elem = info.getCElement(); elem = TypeUtil.getElementForType(info);
if (location == null) { if (location == null) {
// could not resolve location // could not resolve location

View file

@ -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());
}
});
}
}

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -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 <code>OpenTypeDialog</code>.
* @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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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());
}
}
}

View file

@ -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);
}

View file

@ -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.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
*
* @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 <code>null</code>
* 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
* <code>IMember</code> (types, methods, fields..), <code>IPackageFragment</code>, <code>IPackageFragmentRoot</code>
* and <code>IJavaProject</code>.
*
* @param element the input element of this type hierarchy view, or <code>null</code>
* 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 <code>null</code> 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 <code>null</code> if no input element is set
* @see #setInputElement(IJavaElement)
*
* @since 2.0
*/
public ICElement getInputElement();
}

View file

@ -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() {
}
}

View file

@ -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;
}
}

View file

@ -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 <code>true</code> if inherited methods are shown.
*/
public boolean isShowInheritedMethods() {
return ((MethodsContentProvider) getContentProvider()).isShowInheritedMethods();
}
/**
* Returns <code>true</code> 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;
}
}

View file

@ -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.
* <p>
* The action is applicable to selections containing elements of type
* <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class OpenTypeHierarchyAction extends SelectionDispatchAction {
private CEditor fEditor;
/**
* Creates a new <code>OpenTypeHierarchyAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @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);
}
}

View file

@ -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;
}
}

View file

@ -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) {
}
}

View file

@ -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;
}
}

View file

@ -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());
}
});
}
}

View file

@ -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());
}
});
}
}

View file

@ -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());
}
});
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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());
}
}

View file

@ -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();
}
}
}

View file

@ -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);
}
}

View file

@ -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 <code>null</code> 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 <code>null</code> if member filtering is disabled.
*/
public IMember[] getMemberFilter() {
return fMemberFilter;
}
/**
* Sets a filter representing a working set or <code>null</code> 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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -7,18 +7,8 @@
# #
# Contributors: # Contributors:
# IBM Corporation - initial API and implementation # 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 # QNX Software Systems - adapted for use in CDT
#*******************************************************************************/ ###############################################################################
EnableMemberFilterAction.label=Members in Hierarchy EnableMemberFilterAction.label=Members in Hierarchy
EnableMemberFilterAction.tooltip=Lock View and Show 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.tooltip=Vertical View Orientation
ToggleOrientationAction.vertical.description=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.label=Hierarchy View Only
ToggleOrientationAction.single.tooltip=Hierarchy View Only ToggleOrientationAction.single.tooltip=Hierarchy View Only
ToggleOrientationAction.single.description=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.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.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.nodecl=No declarations of selected members\nin the chosen hierarchy of ''{0}''
TypeHierarchyViewPart.exception.title=Type Hierarchy TypeHierarchyViewPart.exception.title=Type Hierarchy
TypeHierarchyViewPart.exception.message=Creating hierarchy failed. Check log for details. TypeHierarchyViewPart.exception.message=Creating hierarchy failed. Check log for details.

View file

@ -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();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B

View file

@ -20,7 +20,6 @@ editorRulerActionsName=Editor Ruler Actions
completionContributorName=Completion Contribution completionContributorName=Completion Contribution
nature.name=C Nature nature.name=C Nature
perspective.name=C/C++ perspective.name=C/C++
CBrowsing.perspective.name=C/C++ Browsing
viewsCategory.name=&C viewsCategory.name=&C
CView.name=C/C++ Projects CView.name=C/C++ Projects
@ -181,7 +180,7 @@ CEditorPresentation.label= Editor
CDTIndexerMarker.label= C/C++ Indexer Markers CDTIndexerMarker.label= C/C++ Indexer Markers
#Browsing #Browsing
CBrowsing.perspectiveName= C/C++ Browsing CBrowsing.perspective.name=C/C++ Browsing
CBrowsing.viewCategoryName= C/C++ Browsing CBrowsing.viewCategoryName= C/C++ Browsing
CBrowsing.projectsViewName= Projects CBrowsing.projectsViewName= Projects
CBrowsing.namespacesViewName= Namespaces CBrowsing.namespacesViewName= Namespaces
@ -189,6 +188,24 @@ CBrowsing.typesViewName= Types
CBrowsing.membersViewName= Members CBrowsing.membersViewName= Members
CBrowsing.preferencePageName= Browsing 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 # hovering contribution
CEditorTextHoversName=C Editor Text Hovers CEditorTextHoversName=C Editor Text Hovers
sourceHover= Source sourceHover= Source

View file

@ -171,6 +171,12 @@
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPerspectiveFactory" class="org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPerspectiveFactory"
id="org.eclipse.cdt.ui.CBrowsingPerspective"> id="org.eclipse.cdt.ui.CBrowsingPerspective">
</perspective> </perspective>
<perspective
name="%CHierarchy.perspective.name"
icon="icons/full/eview16/chierch_persp.gif"
class="org.eclipse.cdt.internal.ui.CHierarchyPerspectiveFactory"
id="org.eclipse.cdt.ui.CHierarchyPerspective">
</perspective>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.perspectiveExtensions"> point="org.eclipse.ui.perspectiveExtensions">
@ -259,6 +265,17 @@
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.MembersView" class="org.eclipse.cdt.internal.ui.browser.cbrowsing.MembersView"
id="org.eclipse.cdt.ui.MembersView"> id="org.eclipse.cdt.ui.MembersView">
</view> </view>
<category
name="%CHierarchy.viewCategoryName"
id="org.eclipse.cdt.ui.c.hierarchy">
</category>
<view
name="%CHierarchy.hierarchyViewName"
icon="icons/full/eview16/class_hi.gif"
category="org.eclipse.cdt.ui.c.hierarchy"
class="org.eclipse.cdt.internal.ui.browser.typehierarchy.TypeHierarchyViewPart"
id="org.eclipse.cdt.ui.TypeHierarchyView">
</view>
</extension> </extension>
<!-- The wizards --> <!-- The wizards -->
<!-- For C Wizards --> <!-- For C Wizards -->
@ -618,6 +635,18 @@
string="Ctrl+G" string="Ctrl+G"
scope="org.eclipse.cdt.ui.cEditorScope" scope="org.eclipse.cdt.ui.cEditorScope"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration"/> configuration="org.eclipse.ui.defaultAcceleratorConfiguration"/>
<command
name="%ActionDefinition.openTypeHierarchy.name"
description="%ActionDefinition.openTypeHierarchy.description"
category="org.eclipse.ui.category.navigate"
id="org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy">
</command>
<keyBinding
string="F4"
scope="org.eclipse.ui.globalScope"
command="org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</keyBinding>
</extension> </extension>
<extension <extension
id="org.eclipse.cdt.ui.CSearchPage" id="org.eclipse.cdt.ui.CSearchPage"
@ -685,6 +714,22 @@
menubarPath="navigate/open.ext2" menubarPath="navigate/open.ext2"
tooltip="%OpenTypeAction.tooltip"> tooltip="%OpenTypeAction.tooltip">
</action> </action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"
label="%OpenTypeHierarchyAction.label"
retarget="true"
menubarPath="navigate/open.ext"
id="org.eclipse.cdt.ui.actions.OpenTypeHierarchy">
</action>
<action
id="org.eclipse.cdt.ui.actions.openTypeInHierarchy"
class="org.eclipse.cdt.internal.ui.browser.typehierarchy.OpenTypeInHierarchyAction"
definitionId="org.eclipse.cdt.ui.navigate.open.type.in.hierarchy"
label="%OpenTypeInHierarchyAction.label"
helpContextId="org.eclipse.cdt.ui.open_type_in_hierarchy_action"
menubarPath="navigate/open.ext2"
tooltip="%OpenTypeInHierarchyAction.tooltip">
</action>
<menu <menu
label="%searchMenu.label" label="%searchMenu.label"
id="org.eclipse.search.menu"> id="org.eclipse.search.menu">

View file

@ -16,7 +16,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.CElement; import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.corext.refactoring.RenameRefactoring; 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.editor.CEditor;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages;
import org.eclipse.cdt.internal.ui.refactoring.UserInterfaceStarter; import org.eclipse.cdt.internal.ui.refactoring.UserInterfaceStarter;

View file

@ -74,8 +74,8 @@ public class CElementImageProvider {
*/ */
public final static int OVERLAY_IMPLEMENTS= 0x40; public final static int OVERLAY_IMPLEMENTS= 0x40;
private static final Point SMALL_SIZE= new Point(16, 16); public static final Point SMALL_SIZE= new Point(16, 16);
private static final Point BIG_SIZE= new Point(22, 16); public static final Point BIG_SIZE= new Point(22, 16);
private static ImageDescriptor DESC_OBJ_PROJECT_CLOSED; private static ImageDescriptor DESC_OBJ_PROJECT_CLOSED;
private static ImageDescriptor DESC_OBJ_PROJECT; private static ImageDescriptor DESC_OBJ_PROJECT;

View file

@ -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_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_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_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_PROBLEM= createManaged(T_OBJ, IMG_OBJS_FIXABLE_PROBLEM);
public static final ImageDescriptor DESC_OBJS_FIXABLE_ERROR= createManaged(T_OBJ, IMG_OBJS_FIXABLE_ERROR); 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. * Sets all available image descriptors for the given action.
*/ */
public static void setImageDescriptors(IAction action, String type, String relPath) { 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.setDisabledImageDescriptor(create(T + "d" + type, relPath)); //$NON-NLS-1$
action.setHoverImageDescriptor(create(T + "c" + 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$ action.setImageDescriptor(create(T + "e" + type, relPath)); //$NON-NLS-1$

View file

@ -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_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_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_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 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 PREVIOUS_CHANGE_ACTION=PREFIX + "previous_change_action"; //$NON-NLS-1$
public static final String NEXT_PROBLEM_ACTION= PREFIX + "next_problem_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 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 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_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_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_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_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 PROJECT_INDEXER_PROPERTIES = PREFIX + "std_prop_indexer"; //$NON-NLS-1$
public static final String CEDITOR_VIEW = PREFIX + "editor_view"; //$NON-NLS-1$ public static final String CEDITOR_VIEW = PREFIX + "editor_view"; //$NON-NLS-1$

View file

@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.ui;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchActionConstants;
/** /**
@ -15,6 +16,29 @@ import org.eclipse.ui.IWorkbenchActionConstants;
*/ */
public interface IContextMenuConstants { public interface IContextMenuConstants {
/**
* Type hierarchy view part: pop-up menu target ID for supertype hierarchy viewer
* (value <code>"org.eclipse.cdt.ui.TypeHierarchy.supertypes"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.TypeHierarchy.subtypes"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.TypeHierarchy.members"</code>).
*
* @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 <code>"group.open"</code>). * Pop-up menu: name of group for goto actions (value <code>"group.open"</code>).

View file

@ -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();
}

View file

@ -17,8 +17,8 @@ NavigateMenu.label=&Navigate
BuildAction.label=&Build Project BuildAction.label=&Build Project
RebuildAction.label=Rebuild Pro&ject RebuildAction.label=Rebuild Pro&ject
SelectionConverter.codeResolveOrInput_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 Java element SelectionConverter.codeResolve_failed=Couldn't convert text selection into a C element
OpenAction.label=&Open OpenAction.label=&Open
OpenAction.tooltip=Open an editor on the selected element 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.message=Cannot open default editor.
OpenAction.error.messageArgs=Cannot open default editor on {0}. {1} OpenAction.error.messageArgs=Cannot open default editor on {0}. {1}
OpenAction.error.messageProblems=Problems Opening Editor 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.label=Open S&uper Implementation
OpenSuperImplementationAction.tooltip=Open the Implementation in the Super Type 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.description=Open a type hierarchy on the selected element
OpenTypeHierarchyAction.dialog.title=Open Type Hierarchy OpenTypeHierarchyAction.dialog.title=Open Type Hierarchy
OpenTypeHierarchyAction.messages.title=Can\'t create type hierarchy OpenTypeHierarchyAction.messages.title=Can\'t create type hierarchy
OpenTypeHierarchyAction.messages.no_java_element=No Java element selected. OpenTypeHierarchyAction.messages.no_c_element=No C element selected.
OpenTypeHierarchyAction.messages.no_java_resources=Selected package fragment doesn\'t contain any Java resource. OpenTypeHierarchyAction.messages.no_c_resources=Selected package fragment doesn\'t contain any C resource.
OpenTypeHierarchyAction.messages.no_types=Selected compilation unit doesn\'t contain a type. OpenTypeHierarchyAction.messages.no_types=Selected translation unit doesn\'t contain a type.
OpenTypeHierarchyAction.messages.no_valid_java_element=No valid Java element selected. OpenTypeHierarchyAction.messages.no_valid_c_element=No valid C element selected.
ShowInPackageViewAction.label=Show in Pac&kage Explorer ShowInPackageViewAction.label=Show in Pac&kage Explorer
ShowInPackageViewAction.description=Show the selected element in Package 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.monitor.message=Creating {0} methods...
AddDelegateMethodsAction.selectioninfo.one={0} method selected. AddDelegateMethodsAction.selectioninfo.one={0} method selected.
AddDelegateMethodsAction.selectioninfo.more={0} methods selected. AddDelegateMethodsAction.selectioninfo.more={0} methods selected.
ToggleLinkingAction.label=Lin&k With Editor
ToggleLinkingAction.tooltip=Link with Editor
ToggleLinkingAction.description=Link with active editor

View file

@ -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;
}
}

View file

@ -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();
}
}
}

View file

@ -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;
}
}

View file

@ -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());
}
}

View file

@ -9,7 +9,7 @@
* QNX Software Systems - Initial API and implementation * 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.ArrayList;
import java.util.Iterator; 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.CModelException;
import org.eclipse.cdt.core.model.ICElement; 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.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; 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.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.core.resources.IResource; 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.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditor;
public class SelectionConverter { public class SelectionConverter {
protected static final ICElement[] EMPTY_RESULT= new ICElement[0];
public static IStructuredSelection convertSelectionToCElements(ISelection s) { public static IStructuredSelection convertSelectionToCElements(ISelection s) {
List converted = new ArrayList(); List converted = new ArrayList();
if (s instanceof StructuredSelection) { if (s instanceof StructuredSelection) {
@ -126,6 +133,10 @@ public class SelectionConverter {
return getElementAtOffset(getInput(editor), (ITextSelection) editor.getSelectionProvider().getSelection()); 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 { public static ICElement getElementAtOffset(ICElement input, ITextSelection selection) throws CModelException {
if (input instanceof ITranslationUnit) { if (input instanceof ITranslationUnit) {
ITranslationUnit tunit = (ITranslationUnit) input; ITranslationUnit tunit = (ITranslationUnit) input;
@ -145,6 +156,25 @@ public class SelectionConverter {
return null; 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) { public static ICElement getInput(ITextEditor editor) {
if (editor == null) return null; if (editor == null) return null;
IEditorInput input = editor.getEditorInput(); IEditorInput input = editor.getEditorInput();
@ -169,4 +199,91 @@ public class SelectionConverter {
return (resource.getType() & resourceMask) != 0; 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 <code>null</code> 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;
}
} }

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; 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.DelegatingDragAdapter;
import org.eclipse.cdt.internal.ui.drag.FileTransferDragAdapter; import org.eclipse.cdt.internal.ui.drag.FileTransferDragAdapter;
import org.eclipse.cdt.internal.ui.drag.LocalSelectionTransferDragAdapter; import org.eclipse.cdt.internal.ui.drag.LocalSelectionTransferDragAdapter;

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.cview; 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.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.IContextMenuConstants; 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.editor.OpenIncludeAction;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup; import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceReference; 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.cdt.internal.ui.util.EditorUtility;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.cview; package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
import org.eclipse.cdt.ui.CElementContentProvider; import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup; import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.cdt.ui.actions.RefactoringActionGroup;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; 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.swt.widgets.Menu;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.part.IPageSite;
@ -61,6 +63,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
private ActionGroup fSelectionSearchGroup; private ActionGroup fSelectionSearchGroup;
private ActionGroup fRefactoringActionGroup; private ActionGroup fRefactoringActionGroup;
private ActionGroup fOpenViewActionGroup;
public CContentOutlinePage(CEditor editor) { public CContentOutlinePage(CEditor editor) {
this("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$ this("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
@ -123,6 +126,13 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
protected void contextMenuAboutToShow(IMenuManager menu) { protected void contextMenuAboutToShow(IMenuManager menu) {
CUIPlugin.createStandardGroups(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())) { if (OpenIncludeAction.canActionBeAdded(getSelection())) {
menu.add(fOpenIncludeAction); menu.add(fOpenIncludeAction);
} }
@ -182,6 +192,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
fSelectionSearchGroup = new SelectionSearchGroup(this); fSelectionSearchGroup = new SelectionSearchGroup(this);
fRefactoringActionGroup = new RefactoringActionGroup(this, null); fRefactoringActionGroup = new RefactoringActionGroup(this, null);
fOpenViewActionGroup = new OpenViewActionGroup(this);
treeViewer.setInput(fInput); treeViewer.setInput(fInput);
WorkbenchHelp.setHelp(control, ICHelpContextIds.COUTLINE_VIEW); WorkbenchHelp.setHelp(control, ICHelpContextIds.COUTLINE_VIEW);
@ -208,6 +219,10 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
fRefactoringActionGroup.dispose(); fRefactoringActionGroup.dispose();
fRefactoringActionGroup= null; fRefactoringActionGroup= null;
} }
if (fOpenViewActionGroup != null) {
fOpenViewActionGroup.dispose();
fOpenViewActionGroup= null;
}
if (fSelectionSearchGroup != null) { if (fSelectionSearchGroup != null) {
fSelectionSearchGroup.dispose(); fSelectionSearchGroup.dispose();

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.IContextMenuConstants; 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.editor.asm.AsmTextTools;
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; 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); action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
setAction("OpenDeclarations", action); //$NON-NLS-1$ 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); fShowInCViewAction = new ShowInCViewAction(this);
action = fShowInCViewAction; action = fShowInCViewAction;
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW); 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, "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, "ContentAssistProposal"); //$NON-NLS-1$
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$

View file

@ -79,6 +79,7 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
* (value <code>"org.eclipse.cdt.ui.edit.text.redo.action"</code>). * (value <code>"org.eclipse.cdt.ui.edit.text.redo.action"</code>).
*/ */
public static final String REDO_ACTION= "org.eclipse.cdt.ui.edit.text.redo.action"; //$NON-NLS-1$ 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 * Action definition ID of the find references in workspace action
* (value <code>"org.eclipse.cdt.ui.search.findrefs"</code>). * (value <code>"org.eclipse.cdt.ui.search.findrefs"</code>).
@ -89,4 +90,16 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
* (value <code>"org.eclipse.cdt.ui.search.finddecl"</code>). * (value <code>"org.eclipse.cdt.ui.search.finddecl"</code>).
*/ */
public static final String FIND_DECL= "org.eclipse.cdt.ui.search.finddecl"; //$NON-NLS-1$ 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 <code>"org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.edit.text.c.open.editor"</code>).
*/
public static final String OPEN_EDITOR= "org.eclipse.cdt.ui.edit.text.c.open.editor"; //$NON-NLS-1$
} }

View file

@ -29,6 +29,7 @@ public class MemberFilter extends ViewerFilter{
public static final int FILTER_NONPUBLIC= 1; public static final int FILTER_NONPUBLIC= 1;
public static final int FILTER_STATIC= 2; public static final int FILTER_STATIC= 2;
public static final int FILTER_FIELDS= 4; public static final int FILTER_FIELDS= 4;
public static final int FILTER_LOCALTYPES= 8;
private int fFilterProperties; private int fFilterProperties;

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.CElementImageProvider;
import org.eclipse.cdt.internal.ui.ErrorTickAdornmentProvider; import org.eclipse.cdt.internal.ui.ErrorTickAdornmentProvider;
import org.eclipse.cdt.internal.ui.IAdornmentProvider; import org.eclipse.cdt.internal.ui.IAdornmentProvider;
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider; 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(); public final static int SHOW_DEFAULT= new Integer(SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue();
private WorkbenchLabelProvider fWorkbenchLabelProvider; private WorkbenchLabelProvider fWorkbenchLabelProvider;
private CElementImageProvider fImageLabelProvider; protected CElementImageProvider fImageLabelProvider;
private IAdornmentProvider[] fAdornmentProviders; private IAdornmentProvider[] fAdornmentProviders;
private int fFlags; private int fFlags;
@ -186,6 +187,7 @@ public class CElementLabelProvider extends LabelProvider {
IBinary bin = (IBinary)celem; IBinary bin = (IBinary)celem;
name.append(" - [" + bin.getCPU() + (bin.isLittleEndian() ? "le" : "be") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ name.append(" - [" + bin.getCPU() + (bin.isLittleEndian() ? "le" : "be") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
} }
return name.toString(); return name.toString();
} catch (CModelException e) { } catch (CModelException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
@ -198,13 +200,27 @@ public class CElementLabelProvider extends LabelProvider {
* @see ILabelProvider#getImage * @see ILabelProvider#getImage
*/ */
public Image getImage(Object element) { public Image getImage(Object element) {
return fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element));
}
protected int evaluateImageFlags(Object element) {
int imageFlags= getImageFlags(); int imageFlags= getImageFlags();
if (fAdornmentProviders != null) { if (fAdornmentProviders != null) {
for (int i= 0; i < fAdornmentProviders.length; i++) { for (int i= 0; i < fAdornmentProviders.length; i++) {
imageFlags |= fAdornmentProviders[i].computeAdornmentFlags(element); 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)) { if (getFlag(SHOW_EXCEPTION)) {
fTextFlags |= CElementLabels.M_EXCEPTIONS; fTextFlags |= CElementLabels.M_EXCEPTIONS;
} }
if (getFlag(SHOW_POST_QUALIFIED)) {
fTextFlags |= CElementLabels.M_POST_QUALIFIED;
}
return fTextFlags; return fTextFlags;
} }

View file

@ -228,19 +228,45 @@ public class CElementSorter extends ViewerSorter {
} }
String name1; String name1;
boolean e1destructor = false;
String name2; String name2;
boolean e2destructor = false;
if (e1 instanceof ICElement) { if (e1 instanceof ICElement) {
name1 = ((ICElement)e1).getElementName(); 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 { } else {
name1 = e1.toString(); name1 = e1.toString();
} }
if (e2 instanceof ICElement) { if (e2 instanceof ICElement) {
name2 = ((ICElement)e2).getElementName(); 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 { } else {
name2 = e2.toString(); 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) { private ISourceRoot getSourceRoot(Object element) {

View file

@ -161,6 +161,21 @@ public class CUIPlugin extends AbstractUIPlugin {
*/ */
public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$ public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$
/**
* The view part id of the type hierarchy part
* (value <code>"org.eclipse.cdt.ui.TypeHierarchy"</code>).
* <p>
* When this id is used to access
* a view part with <code>IWorkbenchPage.findView</code> or
* <code>showView</code>, the returned <code>IViewPart</code>
* can be safely cast to an <code>ITypeHierarchyViewPart</code>.
* </p>
*
* @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 -------- // -------- static methods --------

View file

@ -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$ 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.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE</code> or <code>
* OPEN_TYPE_HIERARCHY_IN_VIEW_PART</code>.
* </p>
*
* @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 <code>OPEN_TYPE_HIERARCHY</code>.
*
* @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 <code>OPEN_TYPE_HIERARCHY</code>.
*
* @see #OPEN_TYPE_HIERARCHY
*/
public static final String OPEN_TYPE_HIERARCHY_IN_VIEW_PART= "viewPart"; //$NON-NLS-1$
/** /**
* Returns the JDT-UI preference store. * Returns the JDT-UI preference store.
* *

View file

@ -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.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class CdtActionConstants {
// Navigate menu
/**
* Navigate menu: name of standard Goto Type global action
* (value <code>"org.eclipse.cdt.ui.actions.GoToType"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.GoToPackage"</code>).
*/
public static final String GOTO_PACKAGE= "org.eclipse.cdt.ui.actions.GoToPackage"; //$NON-NLS-1$
/**
* Navigate menu: name of standard Open global action
* (value <code>"org.eclipse.cdt.ui.actions.Open"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.OpenSuperImplementation"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.OpenTypeHierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.OpenCallHierarchy"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.OpenExternalJavaDoc"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ShowInPackagesView"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ShowInNaviagtorView"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ShowJavaDoc"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ContentAssist"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.Comment"</code>).
*/
public static final String COMMENT= "org.eclipse.cdt.ui.actions.Comment"; //$NON-NLS-1$
/**
* Source menu: name of standard Uncomment global action
* (value <code>"org.eclipse.cdt.ui.actions.Uncomment"</code>).
*/
public static final String UNCOMMENT= "org.eclipse.cdt.ui.actions.Uncomment"; //$NON-NLS-1$
/**
* Source menu: name of standard ToggleComment global action
* (value <code>"org.eclipse.cdt.ui.actions.ToggleComment"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.AddBlockComment"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.RemoveBlockComment"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.Indent"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ShiftRight"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ShiftLeft"</code>).
*/
public static final String SHIFT_LEFT= "org.eclipse.cdt.ui.actions.ShiftLeft"; //$NON-NLS-1$
/**
* Source menu: name of standard Format global action
* (value <code>"org.eclipse.cdt.ui.actions.Format"</code>).
*/
public static final String FORMAT= "org.eclipse.cdt.ui.actions.Format"; //$NON-NLS-1$
/**
* Source menu: name of standard Format Element global action
* (value <code>"org.eclipse.cdt.ui.actions.FormatElement"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.AddImport"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.OrganizeImports"</code>).
*/
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
* <code>"org.eclipse.cdt.ui.actions.SortMembers"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.SurroundWithTryCatch"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.OverrideMethods"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.GenerateGetterSetter"</code>).
*/
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
* <code>"org.eclipse.cdt.ui.actions.GenerateDelegateMethods"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.AddConstructorFromSuperclass"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.GenerateConstructorUsingFields"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.AddJavaDocComment"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.FindStringsToExternalize"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ExternalizeStrings"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ConvertLineDelimitersToWindows"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ConvertLineDelimitersToUNIX"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ConvertLineDelimitersToMac"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.SelfEncapsulateField"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ModifyParameters"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.PullUp"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.PushDown"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.Move"</code>).
*/
public static final String MOVE= "org.eclipse.cdt.ui.actions.Move"; //$NON-NLS-1$
/**
* Refactor menu: name of standard Rename Element global action
* (value <code>"org.eclipse.cdt.ui.actions.Rename"</code>).
*/
public static final String RENAME= "org.eclipse.cdt.ui.actions.Rename"; //$NON-NLS-1$
/**
* Refactor menu: name of standard Inline Temp global action
* (value <code>"org.eclipse.cdt.ui.actions.InlineTemp"</code>).
* @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 <code>"org.eclipse.cdt.ui.actions.ExtractTemp"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ExtractConstant"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.IntroduceParameter"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.IntroduceFactory"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ExtractMethod"</code>).
*/
public static final String EXTRACT_METHOD= "org.eclipse.cdt.ui.actions.ExtractMethod"; //$NON-NLS-1$
/**
* Refactor menu: name of standard Inline global action
* (value <code>"org.eclipse.cdt.ui.actions.Inline"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ExtractInterface"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ChangeType"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.MoveInnerToTop"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.UseSupertype"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ConvertLocalToField"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ConvertAnonymousToNested"</code>).
*
* @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 <code>"org.eclipse.cdt.ui.actions.ReferencesInWorkspace"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReferencesInProject"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReferencesInHierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReferencesInWorkingSet"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.DeclarationsInWorkspace"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.DeclarationsInProject"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.DeclarationsInHierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.DeclarationsInWorkingSet"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ImplementorsInWorkspace"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ImplementorsInProject"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ImplementorsInWorkingSet"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReadAccessInWorkspace"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReadAccessInProject"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReadAccessInHierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.ReadAccessInWorkingSet"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.WriteAccessInWorkspace"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.WriteAccessInProject"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.WriteAccessInHierarchy"</code>).
*/
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 <code>"org.eclipse.cdt.ui.actions.WriteAccessInWorkingSet"</code>).
*/
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
* <code>"org.eclipse.cdt.ui.actions.OccurrencesInFile"</code>).
*
* @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
* <code>"org.eclipse.cdt.ui.actions.ExceptionOccurrences"</code>).
*
* @since 3.0
*/
public static final String FIND_EXCEPTION_OCCURRENCES= "org.eclipse.cdt.ui.actions.ExceptionOccurrences"; //$NON-NLS-1$
}

View file

@ -20,9 +20,12 @@ package org.eclipse.cdt.ui.actions;
* state of the buttons changes. * state of the buttons changes.
* <p> * <p>
*/ */
import java.util.ArrayList;
import org.eclipse.cdt.internal.ui.viewsupport.MemberFilter; import org.eclipse.cdt.internal.ui.viewsupport.MemberFilter;
import org.eclipse.cdt.internal.ui.viewsupport.MemberFilterAction; import org.eclipse.cdt.internal.ui.viewsupport.MemberFilterAction;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.ui.actions.ActionMessages; import org.eclipse.cdt.internal.ui.actions.ActionMessages;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager; 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_STATIC= MemberFilter.FILTER_STATIC;
public static final int FILTER_FIELDS= MemberFilter.FILTER_FIELDS; 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_HIDEFIELDS= "hidefields"; //$NON-NLS-1$
private static final String TAG_HIDESTATIC= "hidestatic"; //$NON-NLS-1$ private static final String TAG_HIDESTATIC= "hidestatic"; //$NON-NLS-1$
private static final String TAG_HIDENONPUBLIC= "hidenonpublic"; //$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); fViewer.addFilter(fFilter);
} }
/**
* Creates a new <code>MemberFilterActionGroup</code>.
*
* @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 <code>true</code> the actions are added to the view
* menu. If <code>false</code> they are added to the toobar.
* @param availableFilters Specifies which filter action should be contained. <code>FILTER_NONPUBLIC</code>,
* <code>FILTER_STATIC</code>, <code>FILTER_FIELDS</code> and <code>FILTER_LOCALTYPES</code>
* or a combination of these constants are possible values. Use <code>ALL_FILTERS</code> 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) { private String getPreferenceKey(int filterProperty) {
return "MemberFilterActionGroup." + fViewerId + '.' + String.valueOf(filterProperty); //$NON-NLS-1$ return "MemberFilterActionGroup." + fViewerId + '.' + String.valueOf(filterProperty); //$NON-NLS-1$
} }

Some files were not shown because too many files have changed in this diff Show more