mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Type Hierarchy: initial version as work in progress
This commit is contained in:
parent
46d063e89e
commit
8d9f8b03aa
30 changed files with 3027 additions and 205 deletions
|
@ -1,5 +1,5 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2003, 2006 IBM Corporation and others.
|
||||
# Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
|
@ -351,6 +351,7 @@ indexerPage.name = Indexer Page
|
|||
proposalFilter.name = Code Completion Proposal Filter
|
||||
includeBrowser.name = Include Browser
|
||||
callHierarchy.name = Call Hierarchy
|
||||
typeHierarchy.name = Type Hierarchy
|
||||
cSearchPage.name = CSearchPage
|
||||
|
||||
# dummy label (not displayed)
|
||||
|
|
|
@ -261,6 +261,12 @@
|
|||
icon="icons/view16/call_hierarchy.gif"
|
||||
id="org.eclipse.cdt.ui.callHierarchy"
|
||||
name="%callHierarchy.name"/>
|
||||
<view
|
||||
category="org.eclipse.cdt.ui.views"
|
||||
class="org.eclipse.cdt.internal.ui.typehierarchy.THViewPart"
|
||||
icon="icons/view16/class_hi.gif"
|
||||
id="org.eclipse.cdt.ui.typeHierarchy"
|
||||
name="%typeHierarchy.name"/>
|
||||
<!--category
|
||||
name="%CBrowsing.viewCategoryName"
|
||||
id="org.eclipse.cdt.ui.c.browsing">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -204,9 +204,21 @@ public class CPluginImages {
|
|||
public static final String IMG_ACTION_HIDE_MACROS = NAME_PREFIX + "filterDefines.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_SHOW_NEXT= NAME_PREFIX + "search_next.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_SHOW_PREV= NAME_PREFIX + "search_prev.gif"; //$NON-NLS-1$
|
||||
|
||||
public static final String IMG_REFRESH= NAME_PREFIX + "refresh_nav.gif"; //$NON-NLS-1$
|
||||
|
||||
|
||||
public static final String IMG_LCL_CANCEL= NAME_PREFIX + "progress_stop.gif"; //$NON-NLS-1$
|
||||
|
||||
// view orientation
|
||||
public static final String IMG_LCL_HORIZONTAL_ORIENTATION= NAME_PREFIX + "th_horizontal.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_LCL_VERTICAL_ORIENTATION= NAME_PREFIX + "th_vertical.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_LCL_AUTOMATIC_ORIENTATION= NAME_PREFIX + "th_automatic.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_LCL_SINGLE_ORIENTATION= NAME_PREFIX + "th_single.gif"; //$NON-NLS-1$
|
||||
|
||||
// hierarchy kind
|
||||
public static final String IMG_LCL_TYPE_HIERARCHY= NAME_PREFIX + "hierarchy_co.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_LCL_SUB_TYPE_HIERARCHY= NAME_PREFIX + "sub_co.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_LCL_SUPER_TYPE_HIERARCHY= NAME_PREFIX + "super_co.gif"; //$NON-NLS-1$
|
||||
|
||||
public static final ImageDescriptor DESC_OBJS_TEMPLATE= createManaged(T_OBJ, IMG_OBJS_TEMPLATE);
|
||||
|
||||
public static final ImageDescriptor DESC_OVR_STATIC= create(T_OVR, "static_co.gif"); //$NON-NLS-1$
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -11,39 +11,18 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.IPositionConverter;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
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.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -51,7 +30,6 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
|||
* @since 4.0
|
||||
*/
|
||||
public class CHQueries {
|
||||
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
|
||||
private static final CHNode[] EMPTY_NODES= new CHNode[0];
|
||||
|
||||
private CHQueries() {}
|
||||
|
@ -67,51 +45,12 @@ public class CHQueries {
|
|||
if (! (callee instanceof ISourceReference)) {
|
||||
return EMPTY_NODES;
|
||||
}
|
||||
IBinding calleeBinding= elementToBinding(index, callee);
|
||||
IBinding calleeBinding= IndexUI.elementToBinding(index, callee);
|
||||
findCalledBy(index, calleeBinding, callee.getCProject(), result);
|
||||
|
||||
return cp.createNodes(node, result);
|
||||
}
|
||||
|
||||
private static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException {
|
||||
IIndexName name= elementToName(index, element);
|
||||
if (name != null) {
|
||||
return index.findBinding(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IIndexName elementToName(IIndex index, ICElement element) throws CoreException {
|
||||
if (element instanceof ISourceReference) {
|
||||
ISourceReference sf = ((ISourceReference)element);
|
||||
ITranslationUnit tu= sf.getTranslationUnit();
|
||||
if (tu != null) {
|
||||
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
|
||||
if (location != null) {
|
||||
IIndexFile file= index.getFile(location);
|
||||
if (file != null) {
|
||||
String elementName= element.getElementName();
|
||||
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
||||
ISourceRange pos= sf.getSourceRange();
|
||||
IRegion region= new Region(pos.getIdStartPos()+idx, pos.getIdLength());
|
||||
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp());
|
||||
if (converter != null) {
|
||||
region= converter.actualToHistoric(region);
|
||||
}
|
||||
IIndexName[] names= file.findNames(region.getOffset(), region.getLength());
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
IIndexName name = names[i];
|
||||
if (!name.isReference() && elementName.endsWith(new String(name.toCharArray()))) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result) throws CoreException, DOMException {
|
||||
if (callee != null) {
|
||||
IIndexName[] names= index.findReferences(callee);
|
||||
|
@ -119,7 +58,7 @@ public class CHQueries {
|
|||
IIndexName rname = names[i];
|
||||
IIndexName caller= rname.getEnclosingDefinition();
|
||||
if (caller != null) {
|
||||
ICElement elem= getCElementForName(project, index, caller);
|
||||
ICElement elem= IndexUI.getCElementForName(project, index, caller);
|
||||
if (elem != null) {
|
||||
result.add(elem, rname);
|
||||
}
|
||||
|
@ -128,16 +67,6 @@ public class CHQueries {
|
|||
}
|
||||
}
|
||||
|
||||
private static ITranslationUnit getTranslationUnit(ICProject cproject, IName name) {
|
||||
IPath path= Path.fromOSString(name.getFileLocation().getFileName());
|
||||
try {
|
||||
return CModelUtil.findTranslationUnitForLocation(path, cproject);
|
||||
} catch (CModelException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for all calls that are made within a given range.
|
||||
* @throws DOMException
|
||||
|
@ -145,20 +74,14 @@ public class CHQueries {
|
|||
public static CHNode[] findCalls(CHContentProvider cp, CHNode node, IIndex index, IProgressMonitor pm) throws CoreException, DOMException {
|
||||
ICElement caller= node.getRepresentedDeclaration();
|
||||
CallsToResult result= new CallsToResult();
|
||||
IIndexName callerName= elementToName(index, caller);
|
||||
IIndexName callerName= IndexUI.elementToName(index, caller);
|
||||
if (callerName != null) {
|
||||
IIndexName[] refs= callerName.getEnclosedNames();
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
IIndexName name = refs[i];
|
||||
IBinding binding= index.findBinding(name);
|
||||
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
|
||||
ICElement[] defs = findAllDefinitions(index, binding);
|
||||
if (defs.length == 0) {
|
||||
ICElement elem = findAnyDeclaration(index, null, binding);
|
||||
if (elem != null) {
|
||||
defs = new ICElement[] { elem };
|
||||
}
|
||||
}
|
||||
ICElement[] defs = IndexUI.findRepresentative(index, binding);
|
||||
if (defs != null && defs.length > 0) {
|
||||
result.add(defs, name);
|
||||
}
|
||||
|
@ -167,66 +90,4 @@ public class CHQueries {
|
|||
}
|
||||
return cp.createNodes(node, result);
|
||||
}
|
||||
|
||||
public static ICElement[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException, DOMException {
|
||||
if (binding != null) {
|
||||
IIndexName[] defs= index.findDefinitions(binding);
|
||||
|
||||
ArrayList result= new ArrayList();
|
||||
for (int i = 0; i < defs.length; i++) {
|
||||
IIndexName in = defs[i];
|
||||
ICElement definition= getCElementForName(null, index, in);
|
||||
if (definition != null) {
|
||||
result.add(definition);
|
||||
}
|
||||
|
||||
}
|
||||
return (ICElement[]) result.toArray(new ICElement[result.size()]);
|
||||
}
|
||||
return EMPTY_ELEMENTS;
|
||||
}
|
||||
|
||||
static ICElement getCElementForName(ICProject preferProject, IIndex index, IASTName declName) throws CoreException, DOMException {
|
||||
assert !declName.isReference();
|
||||
IBinding binding= declName.resolveBinding();
|
||||
if (binding != null) {
|
||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||
if (tu != null) {
|
||||
IFile file= (IFile) tu.getResource();
|
||||
long timestamp= file.getLocalTimeStamp();
|
||||
IASTFileLocation loc= declName.getFileLocation();
|
||||
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(file, timestamp);
|
||||
if (converter != null) {
|
||||
region= converter.actualToHistoric(region);
|
||||
}
|
||||
return CElementHandleFactory.create(tu, binding, region, timestamp);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static ICElement getCElementForName(ICProject preferProject, IIndex index, IIndexName declName) throws CoreException, DOMException {
|
||||
assert !declName.isReference();
|
||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||
if (tu != null) {
|
||||
IRegion region= new Region(declName.getNodeOffset(), declName.getNodeLength());
|
||||
long timestamp= declName.getFile().getTimestamp();
|
||||
return CElementHandleFactory.create(tu, index.findBinding(declName), region, timestamp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ICElement findAnyDeclaration(IIndex index, ICProject preferProject, IBinding binding) throws CoreException, DOMException {
|
||||
if (binding != null) {
|
||||
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
ICElement elem= getCElementForName(preferProject, index, names[i]);
|
||||
if (elem != null) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -25,7 +25,6 @@ import org.eclipse.ui.IWorkbenchWindow;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
|
@ -35,15 +34,13 @@ import org.eclipse.cdt.core.index.IIndex;
|
|||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
||||
public class CallHierarchyUI {
|
||||
private static boolean sIsJUnitTest= false;
|
||||
|
@ -128,22 +125,22 @@ public class CallHierarchyUI {
|
|||
|
||||
index.acquireReadLock();
|
||||
try {
|
||||
IASTName name= getSelectedName(index, editorInput, sel);
|
||||
IASTName name= IndexUI.getSelectedName(index, editorInput, sel);
|
||||
if (name != null) {
|
||||
IBinding binding= name.resolveBinding();
|
||||
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
|
||||
if (name.isDefinition()) {
|
||||
ICElement elem= CHQueries.getCElementForName(project, index, name);
|
||||
ICElement elem= IndexUI.getCElementForName(project, index, name);
|
||||
if (elem != null) {
|
||||
return new ICElement[]{elem};
|
||||
}
|
||||
}
|
||||
else {
|
||||
ICElement[] elems= CHQueries.findAllDefinitions(index, binding);
|
||||
ICElement[] elems= IndexUI.findAllDefinitions(index, binding);
|
||||
if (elems.length == 0) {
|
||||
elems= CHQueries.findAllDefinitions(index, binding);
|
||||
elems= IndexUI.findAllDefinitions(index, binding);
|
||||
if (elems.length == 0) {
|
||||
ICElement elem= CHQueries.findAnyDeclaration(index, project, binding);
|
||||
ICElement elem= IndexUI.findAnyDeclaration(index, project, binding);
|
||||
if (elems != null) {
|
||||
elems= new ICElement[]{elem};
|
||||
}
|
||||
|
@ -171,21 +168,6 @@ public class CallHierarchyUI {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||
int selectionStart = selection.getOffset();
|
||||
int selectionLength = selection.getLength();
|
||||
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
if (workingCopy == null)
|
||||
return null;
|
||||
|
||||
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
IASTTranslationUnit ast = workingCopy.getAST(index, options);
|
||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||
ast.accept(finder);
|
||||
return finder.getSelectedName();
|
||||
}
|
||||
|
||||
public static boolean isRelevantForCallHierarchy(IBinding binding) {
|
||||
if (binding instanceof ICExternalBinding ||
|
||||
binding instanceof IEnumerator ||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* IBM Corporation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
@ -124,7 +125,7 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
* 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$
|
||||
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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
|
@ -85,6 +86,7 @@ public class WorkInProgressPreferencePage extends PreferencePage implements IWor
|
|||
|
||||
// Add your controls here
|
||||
addCheckBox(result, "Use new model builder", CCorePlugin.PREF_USE_NEW_MODEL_BUILDER); //$NON-NLS-1$
|
||||
addCheckBox(result, "Show context menus for type hierarchy", "showCtxMenuTypeHierarchy"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
applyDialogFont(result);
|
||||
return result;
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.typehierarchy.messages"; //$NON-NLS-1$
|
||||
public static String OpenTypeHierarchyAction_label;
|
||||
public static String OpenTypeHierarchyAction_tooltip;
|
||||
public static String THHierarchyModel_Job_title;
|
||||
public static String THHistoryDropDownAction_ClearHistory;
|
||||
public static String THHistoryDropDownAction_tooltip;
|
||||
public static String THHistoryListAction_HistoryList_label;
|
||||
public static String THHistoryListAction_HistoryList_title;
|
||||
public static String THHistoryListAction_label;
|
||||
public static String THHistoryListAction_Remove;
|
||||
public static String THViewPart_AutomaticOrientation;
|
||||
public static String THViewPart_Cancel;
|
||||
public static String THViewPart_Cancel_tooltip;
|
||||
public static String THViewPart_CompleteTypeHierarchy;
|
||||
public static String THViewPart_CompleteTypeHierarchy_tooltip;
|
||||
public static String THViewPart_FocusOn;
|
||||
public static String THViewPart_HorizontalOrientation;
|
||||
public static String THViewPart_instruction;
|
||||
public static String THViewPart_LayoutMenu;
|
||||
public static String THViewPart_MethodPane_title;
|
||||
public static String THViewPart_Open;
|
||||
public static String THViewPart_Open_tooltip;
|
||||
public static String THViewPart_Refresh;
|
||||
public static String THViewPart_Refresh_tooltip;
|
||||
public static String THViewPart_ShowFileNames;
|
||||
public static String THViewPart_ShowFileNames_tooltip;
|
||||
public static String THViewPart_SinglePaneOrientation;
|
||||
public static String THViewPart_SubtypeHierarchy;
|
||||
public static String THViewPart_SubtypeHierarchy_tooltip;
|
||||
public static String THViewPart_SupertypeHierarchy;
|
||||
public static String THViewPart_SupertypeHierarchy_tooltip;
|
||||
public static String THViewPart_VerticalOrientation;
|
||||
public static String TypeHierarchyUI_OpenTypeHierarchy;
|
||||
public static String TypeHierarchyUI_SelectFromList;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
|
||||
public class OpenTypeHierarchyAction extends SelectionDispatchAction {
|
||||
|
||||
private CEditor fEditor;
|
||||
|
||||
public OpenTypeHierarchyAction(IWorkbenchSite site) {
|
||||
super(site);
|
||||
setText(Messages.OpenTypeHierarchyAction_label);
|
||||
setToolTipText(Messages.OpenTypeHierarchyAction_tooltip);
|
||||
}
|
||||
|
||||
public OpenTypeHierarchyAction(CEditor editor) {
|
||||
this(editor.getSite());
|
||||
fEditor= editor;
|
||||
setEnabled(fEditor != null && fEditor.getInputCElement() != null);
|
||||
}
|
||||
|
||||
public void run(ITextSelection sel) {
|
||||
TypeHierarchyUI.open(fEditor, sel);
|
||||
}
|
||||
|
||||
public void run(IStructuredSelection selection) {
|
||||
if (!selection.isEmpty()) {
|
||||
Object selectedObject= selection.getFirstElement();
|
||||
ICElement elem= (ICElement) getAdapter(selectedObject, ICElement.class);
|
||||
if (elem != null) {
|
||||
TypeHierarchyUI.open(elem, getSite().getWorkbenchWindow());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void selectionChanged(ITextSelection sel) {
|
||||
}
|
||||
|
||||
public void selectionChanged(IStructuredSelection selection) {
|
||||
if (selection.isEmpty()) {
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Object selectedObject= selection.getFirstElement();
|
||||
ICElement elem= (ICElement) getAdapter(selectedObject, ICElement.class);
|
||||
if (elem != null) {
|
||||
setEnabled(TypeHierarchyUI.isValidInput(elem));
|
||||
}
|
||||
else {
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Object getAdapter(Object object, Class desiredClass) {
|
||||
if (desiredClass.isInstance(object)) {
|
||||
return object;
|
||||
}
|
||||
if (object instanceof IAdaptable) {
|
||||
IAdaptable adaptable= (IAdaptable) object;
|
||||
return adaptable.getAdapter(desiredClass);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
public class THContentProvider implements ITreeContentProvider {
|
||||
private static final Object[] NO_CHILDREN= new Object[0];
|
||||
private THHierarchyModel fModel;
|
||||
|
||||
public THContentProvider() {
|
||||
}
|
||||
|
||||
final public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
fModel= (THHierarchyModel) newInput;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fModel= null;
|
||||
}
|
||||
|
||||
final public Object[] getElements(Object inputElement) {
|
||||
if (fModel == null) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return fModel.getHierarchyRootElements();
|
||||
}
|
||||
|
||||
final public boolean hasChildren(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
return ((THNode) element).hasChildren();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object[] getChildren(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
return ((THNode) element).getChildren();
|
||||
}
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
public Object getParent(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
return ((THNode) element).getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.util.LocalSelectionTransfer;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.dnd.DND;
|
||||
import org.eclipse.swt.dnd.DropTargetEvent;
|
||||
import org.eclipse.swt.dnd.DropTargetListener;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
|
||||
public class THDropTargetListener implements DropTargetListener {
|
||||
|
||||
private THViewPart fTypeHierarchy;
|
||||
private ICElement fInput;
|
||||
private boolean fEnabled= true;
|
||||
|
||||
public THDropTargetListener(THViewPart view) {
|
||||
fTypeHierarchy= view;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean val) {
|
||||
fEnabled= val;
|
||||
}
|
||||
|
||||
public void dragEnter(DropTargetEvent event) {
|
||||
fInput= null;
|
||||
checkOperation(event);
|
||||
if (event.detail != DND.DROP_NONE) {
|
||||
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
|
||||
fInput= checkLocalSelection();
|
||||
if (!TypeHierarchyUI.isValidInput(fInput)) {
|
||||
event.detail= DND.DROP_NONE;
|
||||
fInput= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ICElement checkLocalSelection() {
|
||||
ISelection sel= LocalSelectionTransfer.getTransfer().getSelection();
|
||||
if (sel instanceof IStructuredSelection) {
|
||||
for (Iterator iter = ((IStructuredSelection)sel).iterator(); iter.hasNext();) {
|
||||
Object element = iter.next();
|
||||
if (element instanceof ICElement) {
|
||||
return (ICElement) element;
|
||||
}
|
||||
if (element instanceof IAdaptable) {
|
||||
ICElement adapter= (ICElement) ((IAdaptable) element).getAdapter(ICElement.class);
|
||||
if (adapter != null) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dragLeave(DropTargetEvent event) {
|
||||
}
|
||||
|
||||
public void dragOperationChanged(DropTargetEvent event) {
|
||||
checkOperation(event);
|
||||
}
|
||||
|
||||
public void dragOver(DropTargetEvent event) {
|
||||
}
|
||||
|
||||
public void drop(DropTargetEvent event) {
|
||||
if (fInput == null) {
|
||||
Display.getCurrent().beep();
|
||||
}
|
||||
else {
|
||||
fTypeHierarchy.setInput(fInput);
|
||||
}
|
||||
}
|
||||
|
||||
public void dropAccept(DropTargetEvent event) {
|
||||
}
|
||||
|
||||
private void checkOperation(DropTargetEvent event) {
|
||||
if (fEnabled && (event.operations & DND.DROP_COPY) != 0) {
|
||||
event.detail= DND.DROP_COPY;
|
||||
}
|
||||
else {
|
||||
event.detail= DND.DROP_NONE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
public class THGraph {
|
||||
private HashSet fRootNodes= new HashSet();
|
||||
private HashSet fLeaveNodes= new HashSet();
|
||||
private HashMap fNodes= new HashMap();
|
||||
|
||||
public void clear() {
|
||||
fRootNodes.clear();
|
||||
fLeaveNodes.clear();
|
||||
fNodes.clear();
|
||||
}
|
||||
|
||||
public THGraphNode getNode(ICElement elem) {
|
||||
return (THGraphNode) fNodes.get(elem);
|
||||
}
|
||||
|
||||
public THGraphNode addNode(ICElement elem) {
|
||||
THGraphNode node= (THGraphNode) fNodes.get(elem);
|
||||
|
||||
if (node == null) {
|
||||
node= new THGraphNode(elem);
|
||||
fNodes.put(elem, node);
|
||||
fRootNodes.add(node);
|
||||
fLeaveNodes.add(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public THGraphEdge addEdge(THGraphNode from, THGraphNode to) {
|
||||
if (createsLoop(from, to)) {
|
||||
return null;
|
||||
}
|
||||
THGraphEdge edge= new THGraphEdge(from, to);
|
||||
from.startEdge(edge);
|
||||
to.endEdge(edge);
|
||||
fRootNodes.remove(to);
|
||||
fLeaveNodes.remove(from);
|
||||
return edge;
|
||||
}
|
||||
|
||||
private boolean createsLoop(THGraphNode from, THGraphNode to) {
|
||||
if (to.getOutgoing().isEmpty() || from.getIncoming().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HashSet checked= new HashSet();
|
||||
ArrayList stack= new ArrayList();
|
||||
stack.add(to);
|
||||
|
||||
while (!stack.isEmpty()) {
|
||||
THGraphNode node= (THGraphNode) stack.remove(stack.size()-1);
|
||||
List out= node.getOutgoing();
|
||||
for (Iterator iterator = out.iterator(); iterator.hasNext();) {
|
||||
THGraphEdge edge= (THGraphEdge) iterator.next();
|
||||
node= edge.getEndNode();
|
||||
if (node == from) {
|
||||
return true;
|
||||
}
|
||||
if (checked.add(node)) {
|
||||
stack.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection getRootNodes() {
|
||||
return fRootNodes;
|
||||
}
|
||||
|
||||
public Collection getLeaveNodes() {
|
||||
return fLeaveNodes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
class THGraphEdge {
|
||||
private THGraphNode fFrom;
|
||||
private THGraphNode fTo;
|
||||
|
||||
THGraphEdge(THGraphNode from, THGraphNode to) {
|
||||
fFrom= from;
|
||||
fTo= to;
|
||||
}
|
||||
|
||||
THGraphNode getStartNode() {
|
||||
return fFrom;
|
||||
}
|
||||
|
||||
THGraphNode getEndNode() {
|
||||
return fTo;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
class THGraphNode {
|
||||
private List fOutgoing= Collections.EMPTY_LIST;
|
||||
private List fIncoming= Collections.EMPTY_LIST;
|
||||
private ICElement fElement;
|
||||
private Object[] fMembers;
|
||||
|
||||
THGraphNode(ICElement element) {
|
||||
fElement= element;
|
||||
}
|
||||
|
||||
void startEdge(THGraphEdge outgoing) {
|
||||
fOutgoing= addElement(fOutgoing, outgoing);
|
||||
}
|
||||
|
||||
void endEdge(THGraphEdge incoming) {
|
||||
fIncoming= addElement(fIncoming, incoming);
|
||||
}
|
||||
|
||||
ICElement getElement() {
|
||||
return fElement;
|
||||
}
|
||||
|
||||
private List addElement(List list, Object elem) {
|
||||
switch (list.size()) {
|
||||
case 0:
|
||||
return Collections.singletonList(elem);
|
||||
case 1:
|
||||
list= new ArrayList(list);
|
||||
list.add(elem);
|
||||
return list;
|
||||
}
|
||||
list.add(elem);
|
||||
return list;
|
||||
}
|
||||
|
||||
List getOutgoing() {
|
||||
return fOutgoing;
|
||||
}
|
||||
|
||||
List getIncoming() {
|
||||
return fIncoming;
|
||||
}
|
||||
|
||||
public void setMembers(Object[] array) {
|
||||
fMembers= array;
|
||||
}
|
||||
|
||||
public Object[] getMembers() {
|
||||
return fMembers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,366 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
||||
public class THHierarchyModel {
|
||||
public class BackgroundJob extends Job {
|
||||
public BackgroundJob() {
|
||||
super(Messages.THHierarchyModel_Job_title);
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
return onComputeGraph(this, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
static final int TYPE_HIERARCHY = 0;
|
||||
static final int SUB_TYPE_HIERARCHY = 1;
|
||||
static final int SUPER_TYPE_HIERARCHY = 2;
|
||||
|
||||
static final int END_OF_COMPUTATION = 0;
|
||||
|
||||
private static final ISchedulingRule RULE = new THSchedulingRule();
|
||||
private static final Object[] NO_CHILDREN= new Object[0];
|
||||
|
||||
private ICElement fInput;
|
||||
private int fHierarchyKind;
|
||||
|
||||
private THGraph fGraph;
|
||||
private Object[] fRootNodes;
|
||||
private THNode fHierarchySelection;
|
||||
private ICElement fHierarchySelectionToRestore;
|
||||
|
||||
private Job fJob;
|
||||
private Display fDisplay;
|
||||
private THViewPart fView;
|
||||
|
||||
public THHierarchyModel(THViewPart view, Display display) {
|
||||
fDisplay= display;
|
||||
fView= view;
|
||||
}
|
||||
|
||||
public ICElement getInput() {
|
||||
return fInput;
|
||||
}
|
||||
|
||||
public int getHierarchyKind() {
|
||||
return fHierarchyKind;
|
||||
}
|
||||
|
||||
public void setHierarchyKind(int hierarchyKind) {
|
||||
fHierarchyKind = hierarchyKind;
|
||||
computeNodes();
|
||||
}
|
||||
|
||||
public Object[] getHierarchyRootElements() {
|
||||
if (fRootNodes == null) {
|
||||
return new Object[] {"..."}; //$NON-NLS-1$
|
||||
}
|
||||
return fRootNodes;
|
||||
}
|
||||
|
||||
// public void setWorkingSetFilter(WorkingSetFilterUI filterUI) {
|
||||
//
|
||||
// }
|
||||
|
||||
synchronized public void setInput(ICElement input) {
|
||||
stopGraphComputation();
|
||||
fInput= input;
|
||||
fRootNodes= null;
|
||||
fHierarchySelection= null;
|
||||
fHierarchySelectionToRestore= input;
|
||||
}
|
||||
|
||||
synchronized public void computeGraph() {
|
||||
if (fJob != null) {
|
||||
fJob.cancel();
|
||||
}
|
||||
fJob= new BackgroundJob();
|
||||
fJob.setRule(RULE);
|
||||
IWorkbenchSiteProgressService ps= (IWorkbenchSiteProgressService) fView.getSite().getAdapter(IWorkbenchSiteProgressService.class);
|
||||
if (ps != null) {
|
||||
ps.schedule(fJob, 0L, true);
|
||||
}
|
||||
else {
|
||||
fJob.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public void stopGraphComputation() {
|
||||
if (fJob != null) {
|
||||
fJob.cancel();
|
||||
}
|
||||
fJob= null;
|
||||
}
|
||||
|
||||
protected IStatus onComputeGraph(Job job, IProgressMonitor monitor) {
|
||||
THGraph graph= new THGraph();
|
||||
try {
|
||||
ICProject[] scope= CoreModel.getDefault().getCModel().getCProjects();
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
|
||||
index.acquireReadLock();
|
||||
try {
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
addSuperClasses(graph, index, monitor);
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
addSubClasses(graph, monitor);
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
finally {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
} catch (InterruptedException e) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
finally {
|
||||
onJobDone(graph, job);
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private void addSuperClasses(THGraph graph, IIndex index, IProgressMonitor monitor) {
|
||||
if (fInput == null) {
|
||||
return;
|
||||
}
|
||||
HashSet handled= new HashSet();
|
||||
ArrayList stack= new ArrayList();
|
||||
stack.add(fInput);
|
||||
handled.add(fInput);
|
||||
while (!stack.isEmpty()) {
|
||||
ICElement elem= (ICElement) stack.remove(stack.size()-1);
|
||||
THGraphNode graphNode= graph.addNode(elem);
|
||||
try {
|
||||
IBinding binding = IndexUI.elementToBinding(index, elem);
|
||||
if (binding instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) binding;
|
||||
addMembers(index, graphNode, ct);
|
||||
ICPPBase[] bases= ct.getBases();
|
||||
for (int i = 0; i < bases.length; i++) {
|
||||
ICPPBase base= bases[i];
|
||||
IBinding basecl= base.getBaseClass();
|
||||
ICElement[] baseElems= IndexUI.findRepresentative(index, basecl);
|
||||
if (baseElems.length > 0) {
|
||||
ICElement baseElem= baseElems[0];
|
||||
THGraphNode baseGraphNode= graph.addNode(baseElem);
|
||||
addMembers(index, baseGraphNode, basecl);
|
||||
graph.addEdge(graphNode, baseGraphNode);
|
||||
if (handled.add(baseElem)) {
|
||||
stack.add(baseElem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addMembers(IIndex index, THGraphNode graphNode, IBinding binding) throws DOMException, CoreException {
|
||||
if (graphNode.getMembers() == null) {
|
||||
if (binding instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) binding;
|
||||
ArrayList memberList= new ArrayList();
|
||||
IBinding[] members= ct.getDeclaredFields();
|
||||
addMemberElements(index, members, memberList);
|
||||
members= ct.getDeclaredMethods();
|
||||
addMemberElements(index, members, memberList);
|
||||
graphNode.setMembers(memberList.toArray());
|
||||
}
|
||||
else if (binding instanceof ICompositeType) {
|
||||
ICompositeType ct= (ICompositeType) binding;
|
||||
ArrayList memberList= new ArrayList();
|
||||
IBinding[] members= ct.getFields();
|
||||
addMemberElements(index, members, memberList);
|
||||
graphNode.setMembers(memberList.toArray());
|
||||
}
|
||||
else if (binding instanceof IEnumeration) {
|
||||
IEnumeration ct= (IEnumeration) binding;
|
||||
ArrayList memberList= new ArrayList();
|
||||
IBinding[] members= ct.getEnumerators();
|
||||
addMemberElements(index, members, memberList);
|
||||
graphNode.setMembers(memberList.toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addMemberElements(IIndex index, IBinding[] members, ArrayList memberList) throws CoreException, DOMException {
|
||||
for (int i = 0; i < members.length; i++) {
|
||||
IBinding binding = members[i];
|
||||
ICElement[] elems= IndexUI.findRepresentative(index, binding);
|
||||
if (elems.length > 0) {
|
||||
memberList.add(elems[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSubClasses(THGraph graph, IProgressMonitor monitor) {
|
||||
// mstodo Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
protected void computeNodes() {
|
||||
if (fGraph == null) {
|
||||
return;
|
||||
}
|
||||
boolean fwd= fHierarchyKind == SUPER_TYPE_HIERARCHY;
|
||||
ArrayList stack= new ArrayList();
|
||||
ArrayList roots= new ArrayList();
|
||||
ArrayList leaves= new ArrayList();
|
||||
|
||||
THNode[] newSelection= new THNode[2];
|
||||
Collection groots;
|
||||
if (fHierarchyKind == TYPE_HIERARCHY) {
|
||||
groots= fGraph.getLeaveNodes();
|
||||
}
|
||||
else {
|
||||
THGraphNode node= fGraph.getNode(fInput);
|
||||
if (node != null) {
|
||||
groots= Collections.singleton(node);
|
||||
}
|
||||
else {
|
||||
groots= Collections.EMPTY_SET;
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator iterator = groots.iterator(); iterator.hasNext();) {
|
||||
THGraphNode gnode = (THGraphNode) iterator.next();
|
||||
THNode node = createNode(newSelection, null, gnode);
|
||||
roots.add(node);
|
||||
stack.add(node);
|
||||
}
|
||||
|
||||
while(!stack.isEmpty()) {
|
||||
THNode node= (THNode) stack.remove(stack.size()-1);
|
||||
THGraphNode gnode= fGraph.getNode(node.getRepresentedDeclaration());
|
||||
List edges= fwd ? gnode.getOutgoing() : gnode.getIncoming();
|
||||
if (edges.isEmpty()) {
|
||||
leaves.add(node);
|
||||
}
|
||||
else {
|
||||
for (Iterator iterator = edges.iterator(); iterator.hasNext();) {
|
||||
THGraphEdge edge = (THGraphEdge) iterator.next();
|
||||
THGraphNode gchildNode= fwd ? edge.getEndNode() : edge.getStartNode();
|
||||
THNode childNode= createNode(newSelection, node, gchildNode);
|
||||
node.addChild(childNode);
|
||||
stack.add(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
fHierarchySelection= newSelection[0];
|
||||
if (fHierarchySelection == null) {
|
||||
fHierarchySelection= newSelection[1];
|
||||
}
|
||||
if (fHierarchySelection != null) {
|
||||
fHierarchySelectionToRestore= fHierarchySelection.getRepresentedDeclaration();
|
||||
}
|
||||
fRootNodes= roots.toArray();
|
||||
}
|
||||
|
||||
private THNode createNode(THNode[] newSelection, THNode parent, THGraphNode gnode) {
|
||||
ICElement element = gnode.getElement();
|
||||
THNode node= new THNode(parent, element);
|
||||
if (newSelection[0] == null) {
|
||||
if (node.equals(fHierarchySelection)) {
|
||||
newSelection[0]= node;
|
||||
}
|
||||
else if (newSelection[1] == null) {
|
||||
if (element.equals(fHierarchySelectionToRestore)) {
|
||||
newSelection[1]= node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
synchronized private void onJobDone(final THGraph graph, Job job) {
|
||||
if (fJob == job) {
|
||||
fJob= null;
|
||||
fDisplay.asyncExec(new Runnable(){
|
||||
public void run() {
|
||||
fGraph= graph;
|
||||
computeNodes();
|
||||
notifyEvent(END_OF_COMPUTATION);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyEvent(int event) {
|
||||
fView.onEvent(event);
|
||||
}
|
||||
|
||||
synchronized public void refresh() {
|
||||
computeGraph();
|
||||
}
|
||||
|
||||
public boolean isComputed() {
|
||||
return fRootNodes!=null;
|
||||
}
|
||||
|
||||
public THNode getSelectionInHierarchy() {
|
||||
return fHierarchySelection;
|
||||
}
|
||||
|
||||
public void onHierarchySelectionChanged(THNode node) {
|
||||
fHierarchySelection= node;
|
||||
if (node != null) {
|
||||
fHierarchySelectionToRestore= node.getRepresentedDeclaration();
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getMembers() {
|
||||
if (fHierarchySelection != null) {
|
||||
THGraphNode gnode= fGraph.getNode(fHierarchySelection.getRepresentedDeclaration());
|
||||
return gnode.getMembers();
|
||||
}
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||
|
||||
|
||||
/**
|
||||
* Action used for the include browser forward / backward buttons
|
||||
*/
|
||||
public class THHistoryAction extends Action {
|
||||
final static int LABEL_OPTIONS=
|
||||
CElementLabels.M_PARAMETER_TYPES |
|
||||
CElementLabels.ALL_FULLY_QUALIFIED |
|
||||
CElementLabels.MF_POST_FILE_QUALIFIED;
|
||||
|
||||
private THViewPart fViewPart;
|
||||
private ICElement fElement;
|
||||
|
||||
public THHistoryAction(THViewPart hierarchyView, ICElement element) {
|
||||
super("", AS_RADIO_BUTTON); //$NON-NLS-1$
|
||||
fViewPart= hierarchyView;
|
||||
fElement= element;
|
||||
|
||||
String elementName= CElementLabels.getElementLabel(element, LABEL_OPTIONS);
|
||||
setText(elementName);
|
||||
setImageDescriptor(getImageDescriptor(element));
|
||||
}
|
||||
|
||||
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.setInput(fElement);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.ActionContributionItem;
|
||||
import org.eclipse.jface.action.IMenuCreator;
|
||||
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;
|
||||
|
||||
public class THHistoryDropDownAction extends Action implements IMenuCreator {
|
||||
|
||||
public static class ClearHistoryAction extends Action {
|
||||
|
||||
private THViewPart fView;
|
||||
|
||||
public ClearHistoryAction(THViewPart view) {
|
||||
super(Messages.THHistoryDropDownAction_ClearHistory);
|
||||
fView= view;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
fView.setHistoryEntries(new ICElement[0]);
|
||||
fView.setInput(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static final int RESULTS_IN_DROP_DOWN= 10;
|
||||
|
||||
private THViewPart fHierarchyView;
|
||||
private Menu fMenu;
|
||||
|
||||
public THHistoryDropDownAction(THViewPart viewPart) {
|
||||
fHierarchyView= viewPart;
|
||||
fMenu= null;
|
||||
setToolTipText(Messages.THHistoryDropDownAction_tooltip);
|
||||
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "history_list.gif"); //$NON-NLS-1$
|
||||
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();
|
||||
addEntries(fMenu, elements);
|
||||
new MenuItem(fMenu, SWT.SEPARATOR);
|
||||
addActionToMenu(fMenu, new THHistoryListAction(fHierarchyView));
|
||||
addActionToMenu(fMenu, new ClearHistoryAction(fHierarchyView));
|
||||
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++) {
|
||||
THHistoryAction action= new THHistoryAction(fHierarchyView, elements[i]);
|
||||
action.setChecked(elements[i].equals(fHierarchyView.getInput()));
|
||||
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 THHistoryListAction(fHierarchyView)).run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.StatusDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.window.Window;
|
||||
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.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
|
||||
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;
|
||||
|
||||
public class THHistoryListAction extends Action {
|
||||
|
||||
private class HistoryListDialog extends StatusDialog {
|
||||
|
||||
private ListDialogField fHistoryList;
|
||||
private IStatus fHistoryStatus;
|
||||
private ICElement fResult;
|
||||
|
||||
private HistoryListDialog(Shell shell, ICElement[] historyEntries) {
|
||||
super(shell);
|
||||
setHelpAvailable(false);
|
||||
setTitle(Messages.THHistoryListAction_HistoryList_title);
|
||||
String[] buttonLabels= new String[] {
|
||||
Messages.THHistoryListAction_Remove,
|
||||
};
|
||||
|
||||
IListAdapter adapter= new IListAdapter() {
|
||||
public void customButtonPressed(ListDialogField field, int index) {
|
||||
doCustomButtonPressed();
|
||||
}
|
||||
public void selectionChanged(ListDialogField field) {
|
||||
doSelectionChanged();
|
||||
}
|
||||
|
||||
public void doubleClicked(ListDialogField field) {
|
||||
doDoubleClicked();
|
||||
}
|
||||
};
|
||||
|
||||
LabelProvider labelProvider= new CUILabelProvider(THHistoryAction.LABEL_OPTIONS, CElementImageProvider.OVERLAY_ICONS);
|
||||
|
||||
fHistoryList= new ListDialogField(adapter, buttonLabels, labelProvider);
|
||||
fHistoryList.setLabelText(Messages.THHistoryListAction_HistoryList_label);
|
||||
fHistoryList.setElements(Arrays.asList(historyEntries));
|
||||
|
||||
ISelection sel;
|
||||
if (historyEntries.length > 0) {
|
||||
sel= new StructuredSelection(historyEntries[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.setFont(parent.getFont());
|
||||
|
||||
inner.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
LayoutUtil.doDefaultLayout(inner, new DialogField[] { fHistoryList }, true, 0, 0);
|
||||
LayoutUtil.setHeightHint(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);
|
||||
// PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, ...);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.window.Window#create()
|
||||
*/
|
||||
public void create() {
|
||||
setShellStyle(getShellStyle() | SWT.RESIZE);
|
||||
super.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private THViewPart fView;
|
||||
|
||||
public THHistoryListAction(THViewPart hierarchyView) {
|
||||
fView= hierarchyView;
|
||||
setText(Messages.THHistoryListAction_label);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IAction#run()
|
||||
*/
|
||||
public void run() {
|
||||
ICElement[] historyEntries= fView.getHistoryEntries();
|
||||
HistoryListDialog dialog= new HistoryListDialog(fView.getSite().getShell(), historyEntries);
|
||||
if (dialog.open() == Window.OK) {
|
||||
fView.setHistoryEntries(dialog.getRemaining());
|
||||
fView.setInput(dialog.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.IColorProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor;
|
||||
|
||||
public class THLabelProvider extends LabelProvider implements IColorProvider {
|
||||
private final static int LABEL_OPTIONS_SIMPLE= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES;
|
||||
private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementLabels.MF_POST_FILE_QUALIFIED;
|
||||
|
||||
private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0);
|
||||
private THHierarchyModel fModel;
|
||||
private HashMap fCachedImages= new HashMap();
|
||||
private Color fColorInactive;
|
||||
|
||||
public THLabelProvider(Display display, THHierarchyModel model) {
|
||||
fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY);
|
||||
fModel= model;
|
||||
}
|
||||
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
THNode node= (THNode) element;
|
||||
ICElement decl= node.getRepresentedDeclaration();
|
||||
if (decl != null) {
|
||||
Image image= fCLabelProvider.getImage(decl);
|
||||
if (image != null) {
|
||||
return decorateImage(image, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
public String getText(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
THNode node= (THNode) element;
|
||||
ICElement decl= node.getRepresentedDeclaration();
|
||||
if (decl != null) {
|
||||
String label= fCLabelProvider.getText(decl);
|
||||
return label;
|
||||
}
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fCLabelProvider.dispose();
|
||||
for (Iterator iter = fCachedImages.values().iterator(); iter.hasNext();) {
|
||||
Image image = (Image) iter.next();
|
||||
image.dispose();
|
||||
}
|
||||
fCachedImages.clear();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private Image decorateImage(Image image, THNode node) {
|
||||
int flags= 0;
|
||||
if (node.hasChildren()) {
|
||||
if (fModel.getHierarchyKind() == THHierarchyModel.SUPER_TYPE_HIERARCHY) {
|
||||
flags |= CElementImageDescriptor.RELATES_TO;
|
||||
}
|
||||
else {
|
||||
flags |= CElementImageDescriptor.REFERENCED_BY;
|
||||
}
|
||||
}
|
||||
|
||||
String key= image.toString()+String.valueOf(flags);
|
||||
Image result= (Image) fCachedImages.get(key);
|
||||
if (result == null) {
|
||||
ImageDescriptor desc= new CElementImageDescriptor(
|
||||
new ImageImageDescriptor(image), flags, new Point(20,16));
|
||||
result= desc.createImage();
|
||||
fCachedImages.put(key, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Color getBackground(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Color getForeground(Object element) {
|
||||
if (element instanceof THNode) {
|
||||
THNode node= (THNode) element;
|
||||
if (node.isFiltered()) {
|
||||
return fColorInactive;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setShowFiles(boolean show) {
|
||||
fCLabelProvider.setTextFlags(show ? LABEL_OPTIONS_SHOW_FILES : LABEL_OPTIONS_SIMPLE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
public class THMethodContentProvider implements IStructuredContentProvider {
|
||||
private static final Object[] NO_CHILDREN= new Object[0];
|
||||
private THHierarchyModel fModel;
|
||||
|
||||
public THMethodContentProvider() {
|
||||
}
|
||||
|
||||
final public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
fModel= (THHierarchyModel) newInput;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fModel= null;
|
||||
}
|
||||
|
||||
final public Object[] getElements(Object inputElement) {
|
||||
if (fModel == null) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return fModel.getMembers();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||
|
||||
public class THNode implements IAdaptable {
|
||||
private THNode fParent;
|
||||
private ICElement fRepresentedDecl;
|
||||
private List fChildren= Collections.EMPTY_LIST;
|
||||
|
||||
private int fHashCode;
|
||||
private boolean fIsFiltered;
|
||||
|
||||
/**
|
||||
* Creates a new node for the include browser
|
||||
*/
|
||||
public THNode(THNode parent, ICElement decl) {
|
||||
fParent= parent;
|
||||
fRepresentedDecl= decl;
|
||||
fHashCode= computeHashCode();
|
||||
}
|
||||
|
||||
private int computeHashCode() {
|
||||
int hashCode= 0;
|
||||
if (fParent != null) {
|
||||
hashCode= fParent.hashCode() * 31;
|
||||
}
|
||||
if (fRepresentedDecl != null) {
|
||||
hashCode+= fRepresentedDecl.hashCode();
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return fHashCode;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof THNode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
THNode rhs = (THNode) o;
|
||||
if (fHashCode != rhs.fHashCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CoreUtility.safeEquals(fRepresentedDecl, rhs.fRepresentedDecl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent node or <code>null</code> for the root node.
|
||||
*/
|
||||
public THNode getParent() {
|
||||
return fParent;
|
||||
}
|
||||
|
||||
|
||||
public ICElement getRepresentedDeclaration() {
|
||||
return fRepresentedDecl;
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
if (adapter.isAssignableFrom(ICElement.class)) {
|
||||
return getRepresentedDeclaration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isFiltered() {
|
||||
return fIsFiltered;
|
||||
}
|
||||
|
||||
public void setIsFiltered(boolean val) {
|
||||
fIsFiltered= val;
|
||||
}
|
||||
|
||||
public void addChild(THNode childNode) {
|
||||
switch(fChildren.size()) {
|
||||
case 0:
|
||||
fChildren= Collections.singletonList(childNode);
|
||||
break;
|
||||
case 1:
|
||||
fChildren= new ArrayList(fChildren);
|
||||
fChildren.add(childNode);
|
||||
break;
|
||||
default:
|
||||
fChildren.add(childNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChildren() {
|
||||
return !fChildren.isEmpty();
|
||||
}
|
||||
|
||||
public Object[] getChildren() {
|
||||
return fChildren.toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
|
||||
public class THSchedulingRule implements ISchedulingRule {
|
||||
|
||||
public boolean contains(ISchedulingRule rule) {
|
||||
return rule==this;
|
||||
}
|
||||
|
||||
public boolean isConflicting(ISchedulingRule rule) {
|
||||
return rule==this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,863 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.action.ToolBarManager;
|
||||
import org.eclipse.jface.util.LocalSelectionTransfer;
|
||||
import org.eclipse.jface.viewers.IOpenListener;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.OpenEvent;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.custom.SashForm;
|
||||
import org.eclipse.swt.custom.ViewForm;
|
||||
import org.eclipse.swt.dnd.DND;
|
||||
import org.eclipse.swt.dnd.DropTarget;
|
||||
import org.eclipse.swt.dnd.Transfer;
|
||||
import org.eclipse.swt.events.ControlEvent;
|
||||
import org.eclipse.swt.events.ControlListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.IViewSite;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchPartSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.actions.ActionFactory;
|
||||
import org.eclipse.ui.part.PageBook;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.AdaptingSelectionProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.SelectionProviderMediator;
|
||||
|
||||
/**
|
||||
* The view part for the include browser.
|
||||
*/
|
||||
public class THViewPart extends ViewPart {
|
||||
private static final int MAX_HISTORY_SIZE = 10;
|
||||
private static final String TRUE = String.valueOf(true);
|
||||
// private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$
|
||||
private static final String KEY_SHOW_FILES= "showFilesInLabels"; //$NON-NLS-1$
|
||||
private static final String KEY_MODE= "hierarchyMode"; //$NON-NLS-1$
|
||||
private static final String KEY_ORIENTATION= "viewOrientation"; //$NON-NLS-1$
|
||||
private static final String KEY_SPLITTER_W1 = "splitterWeight1"; //$NON-NLS-1$
|
||||
private static final String KEY_SPLITTER_W2 = "splitterWeight2"; //$NON-NLS-1$
|
||||
|
||||
// constants for view orientation
|
||||
private static final int ORIENTATION_AUTOMATIC = 0;
|
||||
private static final int ORIENTATION_HORIZONTAL = 1;
|
||||
private static final int ORIENTATION_VERTICAL = 2;
|
||||
private static final int ORIENTATION_SINGLE = 3;
|
||||
private static final int METHOD_LABEL_OPTIONS_SIMPLE = CElementLabels.M_PARAMETER_TYPES;
|
||||
// private static final int METHOD_LABEL_OPTIONS_QUALIFIED = METHOD_LABEL_OPTIONS_SIMPLE | CElementLabels.M_FULLY_QUALIFIED;
|
||||
|
||||
private IMemento fMemento;
|
||||
private boolean fShowsMessage= true;
|
||||
private int fCurrentViewOrientation= -1;
|
||||
private boolean fInComputeOrientation= false;
|
||||
|
||||
private ArrayList fHistoryEntries= new ArrayList(MAX_HISTORY_SIZE);
|
||||
|
||||
// widgets
|
||||
private PageBook fPagebook;
|
||||
private Composite fInfoPage;
|
||||
private Text fInfoText;
|
||||
private SashForm fSplitter;
|
||||
private ViewForm fHierarchyViewForm;
|
||||
private ViewForm fMethodViewForm;
|
||||
private CLabel fMethodLabel;
|
||||
|
||||
// viewers
|
||||
private THHierarchyModel fModel;
|
||||
private THLabelProvider fHierarchyLabelProvider;
|
||||
private CUILabelProvider fMethodLabelProvider;
|
||||
private TableViewer fMethodViewer;
|
||||
private TreeViewer fHierarchyTreeViewer;
|
||||
|
||||
// filters, sorter
|
||||
// private WorkingSetFilterUI fWorkingSetFilterUI;
|
||||
|
||||
// actions
|
||||
private ToolBarManager fMethodToolbarManager;
|
||||
private Action fShowSuperTypeHierarchyAction;
|
||||
private Action fShowSubTypeHierarchyAction;
|
||||
private Action fShowTypeHierarchyAction;
|
||||
private Action fShowFilesInLabelsAction;
|
||||
private Action fRefreshAction;
|
||||
private Action fCancelAction;
|
||||
private Action fHistoryAction;
|
||||
private Action fOpenElement;
|
||||
private Action fHorizontalOrientation;
|
||||
private Action fVerticalOrientation;
|
||||
private Action fAutomaticOrientation;
|
||||
private Action fSingleOrientation;
|
||||
|
||||
// action groups
|
||||
private OpenViewActionGroup fOpenViewActionGroup;
|
||||
private SelectionSearchGroup fSelectionSearchGroup;
|
||||
private CRefactoringActionGroup fRefactoringActionGroup;
|
||||
private int fIgnoreSelectionChanges= 0;
|
||||
|
||||
|
||||
public void setFocus() {
|
||||
fPagebook.setFocus();
|
||||
}
|
||||
|
||||
public void setMessage(String msg) {
|
||||
fInfoText.setText(msg);
|
||||
fPagebook.showPage(fInfoPage);
|
||||
fShowsMessage= true;
|
||||
updateDescription();
|
||||
updateActionEnablement();
|
||||
}
|
||||
|
||||
public void setInput(ICElement input) {
|
||||
if (input == null) {
|
||||
setMessage(Messages.THViewPart_instruction);
|
||||
fHierarchyTreeViewer.setInput(null);
|
||||
fMethodViewer.setInput(null);
|
||||
return;
|
||||
}
|
||||
fShowsMessage= false;
|
||||
fModel.setInput(input);
|
||||
fHierarchyTreeViewer.setInput(fModel);
|
||||
fMethodViewer.setInput(fModel);
|
||||
fPagebook.showPage(fSplitter);
|
||||
updateDescription();
|
||||
updateHistory(input);
|
||||
updateActionEnablement();
|
||||
fModel.computeGraph();
|
||||
}
|
||||
|
||||
public void createPartControl(Composite parent) {
|
||||
fPagebook = new PageBook(parent, SWT.NULL);
|
||||
fPagebook.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
createInfoPage();
|
||||
createViewerPage();
|
||||
|
||||
initSelectionProvider();
|
||||
|
||||
initDragAndDrop();
|
||||
createActions();
|
||||
createContextMenu();
|
||||
|
||||
setMessage(Messages.THViewPart_instruction);
|
||||
initializeActionStates();
|
||||
}
|
||||
|
||||
private void initSelectionProvider() {
|
||||
SelectionProviderMediator mediator= new SelectionProviderMediator();
|
||||
mediator.addViewer(fHierarchyTreeViewer);
|
||||
mediator.addViewer(fMethodViewer);
|
||||
getSite().setSelectionProvider(new AdaptingSelectionProvider(ICElement.class, mediator));
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (fOpenViewActionGroup != null) {
|
||||
fOpenViewActionGroup.dispose();
|
||||
fOpenViewActionGroup= null;
|
||||
}
|
||||
if (fSelectionSearchGroup != null) {
|
||||
fSelectionSearchGroup.dispose();
|
||||
fSelectionSearchGroup= null;
|
||||
}
|
||||
if (fRefactoringActionGroup != null) {
|
||||
fRefactoringActionGroup.dispose();
|
||||
fRefactoringActionGroup= null;
|
||||
}
|
||||
// if (fWorkingSetFilterUI != null) {
|
||||
// fWorkingSetFilterUI.dispose();
|
||||
// fWorkingSetFilterUI= null;
|
||||
// }
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void initializeActionStates() {
|
||||
int mode= THHierarchyModel.TYPE_HIERARCHY;
|
||||
int orientation= ORIENTATION_AUTOMATIC;
|
||||
boolean showFiles= false;
|
||||
int[] weights= {35,65};
|
||||
|
||||
if (fMemento != null) {
|
||||
showFiles= TRUE.equals(fMemento.getString(KEY_SHOW_FILES));
|
||||
Integer intval= fMemento.getInteger(KEY_MODE);
|
||||
if (intval != null) {
|
||||
mode= intval.intValue();
|
||||
}
|
||||
intval= fMemento.getInteger(KEY_ORIENTATION);
|
||||
if (intval != null) {
|
||||
orientation= intval.intValue();
|
||||
}
|
||||
intval= fMemento.getInteger(KEY_SPLITTER_W1);
|
||||
Integer intval2= fMemento.getInteger(KEY_SPLITTER_W2);
|
||||
if (intval != null && intval2 != null) {
|
||||
weights[0]= intval.intValue();
|
||||
weights[1]= intval2.intValue();
|
||||
}
|
||||
}
|
||||
restoreOrientation(orientation);
|
||||
restoreHierarchyKind(mode);
|
||||
fSplitter.setWeights(weights);
|
||||
|
||||
fHierarchyLabelProvider.setShowFiles(showFiles);
|
||||
fShowFilesInLabelsAction.setChecked(showFiles);
|
||||
|
||||
fMethodToolbarManager.update(true);
|
||||
}
|
||||
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
fMemento= memento;
|
||||
super.init(site, memento);
|
||||
}
|
||||
|
||||
|
||||
public void saveState(IMemento memento) {
|
||||
// if (fWorkingSetFilterUI != null) {
|
||||
// fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
|
||||
// }
|
||||
memento.putString(KEY_SHOW_FILES, String.valueOf(fShowFilesInLabelsAction.isChecked()));
|
||||
int[] weights= fSplitter.getWeights();
|
||||
memento.putInteger(KEY_SPLITTER_W1, weights[0]);
|
||||
memento.putInteger(KEY_SPLITTER_W2, weights[1]);
|
||||
if (fAutomaticOrientation.isChecked()) {
|
||||
memento.putInteger(KEY_ORIENTATION, ORIENTATION_AUTOMATIC);
|
||||
}
|
||||
else {
|
||||
memento.putInteger(KEY_ORIENTATION, fCurrentViewOrientation);
|
||||
}
|
||||
super.saveState(memento);
|
||||
}
|
||||
|
||||
private void createContextMenu() {
|
||||
IWorkbenchPartSite site = getSite();
|
||||
|
||||
// hierarchy
|
||||
MenuManager manager = new MenuManager();
|
||||
manager.setRemoveAllWhenShown(true);
|
||||
manager.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager m) {
|
||||
onContextMenuAboutToShow(m, true);
|
||||
}
|
||||
});
|
||||
Menu menu = manager.createContextMenu(fHierarchyTreeViewer.getControl());
|
||||
fHierarchyTreeViewer.getControl().setMenu(menu);
|
||||
site.registerContextMenu(CUIPlugin.ID_TYPE_HIERARCHY, manager, fHierarchyTreeViewer);
|
||||
|
||||
|
||||
manager = new MenuManager();
|
||||
manager.setRemoveAllWhenShown(true);
|
||||
manager.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager m) {
|
||||
onContextMenuAboutToShow(m, false);
|
||||
}
|
||||
});
|
||||
menu = manager.createContextMenu(fMethodViewer.getControl());
|
||||
fMethodViewer.getControl().setMenu(menu);
|
||||
site.registerContextMenu(CUIPlugin.ID_TYPE_HIERARCHY + ".methods", manager, fMethodViewer); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void onContextMenuAboutToShow(IMenuManager menu, boolean hierarchyView) {
|
||||
CUIPlugin.createStandardGroups(menu);
|
||||
StructuredViewer viewer= hierarchyView ? (StructuredViewer) fHierarchyTreeViewer : fMethodViewer;
|
||||
final ICElement elem= selectionToElement(viewer.getSelection());
|
||||
if (elem != null) {
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenElement);
|
||||
if (hierarchyView && !elem.equals(fModel.getInput())) {
|
||||
String label= MessageFormat.format(Messages.THViewPart_FocusOn,
|
||||
new Object[] {
|
||||
CElementLabels.getTextLabel(elem, CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES)
|
||||
});
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, new Action(label) {
|
||||
public void run() {
|
||||
setInput(elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// action groups
|
||||
ISelection selection = getSite().getSelectionProvider().getSelection();
|
||||
if (OpenViewActionGroup.canActionBeAdded(selection)){
|
||||
fOpenViewActionGroup.fillContextMenu(menu);
|
||||
}
|
||||
|
||||
if (SelectionSearchGroup.canActionBeAdded(selection)){
|
||||
fSelectionSearchGroup.fillContextMenu(menu);
|
||||
}
|
||||
fRefactoringActionGroup.fillContextMenu(menu);
|
||||
}
|
||||
|
||||
private void createViewerPage() {
|
||||
fSplitter= new SashForm(fPagebook, SWT.VERTICAL);
|
||||
fSplitter.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
fSplitter.addControlListener(new ControlListener() {
|
||||
public void controlMoved(ControlEvent e) {
|
||||
}
|
||||
public void controlResized(ControlEvent e) {
|
||||
if (fAutomaticOrientation.isChecked()) {
|
||||
setOrientation(ORIENTATION_AUTOMATIC);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fHierarchyViewForm= new ViewForm(fSplitter, SWT.NONE);
|
||||
Control hierarchyControl= createHierarchyControl(fHierarchyViewForm);
|
||||
fHierarchyViewForm.setContent(hierarchyControl);
|
||||
|
||||
fMethodViewForm= new ViewForm(fSplitter, SWT.NONE);
|
||||
Control methodControl= createMethodControl(fMethodViewForm);
|
||||
fMethodViewForm.setContent(methodControl);
|
||||
|
||||
fMethodLabel = new CLabel(fMethodViewForm, SWT.NONE);
|
||||
fMethodLabel.setText(Messages.THViewPart_MethodPane_title);
|
||||
fMethodViewForm.setTopLeft(fMethodLabel);
|
||||
}
|
||||
|
||||
private Control createMethodControl(ViewForm parent) {
|
||||
fMethodLabelProvider= new CUILabelProvider(METHOD_LABEL_OPTIONS_SIMPLE, 0);
|
||||
fMethodViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
||||
fMethodViewer.setContentProvider(new THMethodContentProvider());
|
||||
fMethodViewer.setLabelProvider(fMethodLabelProvider);
|
||||
fMethodViewer.addOpenListener(new IOpenListener() {
|
||||
public void open(OpenEvent event) {
|
||||
onOpenElement(event.getSelection());
|
||||
}
|
||||
});
|
||||
fMethodViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(final SelectionChangedEvent event) {
|
||||
onMethodSelectionChanged(event);
|
||||
}
|
||||
});
|
||||
fMethodViewer.setSorter(new ViewerSorter() {
|
||||
public int category(Object element) {
|
||||
if (element instanceof ICElement) {
|
||||
ICElement celem= (ICElement)element;
|
||||
switch (celem.getElementType()) {
|
||||
case ICElement.C_FIELD: return 1;
|
||||
}
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
});
|
||||
|
||||
ToolBar methodToolBar= new ToolBar(parent, SWT.FLAT | SWT.WRAP);
|
||||
parent.setTopCenter(methodToolBar);
|
||||
fMethodToolbarManager= new ToolBarManager(methodToolBar);
|
||||
return fMethodViewer.getControl();
|
||||
}
|
||||
|
||||
protected void onMethodSelectionChanged(SelectionChangedEvent event) {
|
||||
if (fIgnoreSelectionChanges == 0) {
|
||||
}
|
||||
}
|
||||
|
||||
private Control createHierarchyControl(ViewForm parent) {
|
||||
Display display= getSite().getShell().getDisplay();
|
||||
fModel= new THHierarchyModel(this, display);
|
||||
fHierarchyLabelProvider= new THLabelProvider(display, fModel);
|
||||
fHierarchyTreeViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
||||
fHierarchyTreeViewer.setContentProvider(new THContentProvider());
|
||||
fHierarchyTreeViewer.setLabelProvider(fHierarchyLabelProvider);
|
||||
fHierarchyTreeViewer.setSorter(new ViewerSorter());
|
||||
fHierarchyTreeViewer.setUseHashlookup(true);
|
||||
fHierarchyTreeViewer.addOpenListener(new IOpenListener() {
|
||||
public void open(OpenEvent event) {
|
||||
onOpenElement(event.getSelection());
|
||||
}
|
||||
});
|
||||
|
||||
fHierarchyTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(final SelectionChangedEvent event) {
|
||||
onHierarchySelectionChanged(event);
|
||||
}
|
||||
});
|
||||
|
||||
return fHierarchyTreeViewer.getControl();
|
||||
}
|
||||
|
||||
protected void onHierarchySelectionChanged(SelectionChangedEvent event) {
|
||||
if (fIgnoreSelectionChanges == 0) {
|
||||
THNode node= selectionToNode(event.getSelection());
|
||||
fModel.onHierarchySelectionChanged(node);
|
||||
fMethodViewer.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void createInfoPage() {
|
||||
fInfoPage = new Composite(fPagebook, SWT.NULL);
|
||||
fInfoPage.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
fInfoPage.setSize(100, 100);
|
||||
fInfoPage.setLayout(new FillLayout());
|
||||
|
||||
fInfoText= new Text(fInfoPage, SWT.WRAP | SWT.READ_ONLY);
|
||||
}
|
||||
|
||||
private void initDragAndDrop() {
|
||||
THDropTargetListener dropListener= new THDropTargetListener(this);
|
||||
Transfer[] localSelectionTransfer= new Transfer[] {
|
||||
LocalSelectionTransfer.getTransfer()
|
||||
};
|
||||
DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_COPY);
|
||||
dropTarget.setTransfer(localSelectionTransfer);
|
||||
dropTarget.addDropListener(dropListener);
|
||||
}
|
||||
|
||||
private void createActions() {
|
||||
// action gruops
|
||||
fOpenViewActionGroup= new OpenViewActionGroup(this);
|
||||
fSelectionSearchGroup= new SelectionSearchGroup(getSite());
|
||||
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||
|
||||
// fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
||||
// protected void onWorkingSetChange() {
|
||||
// updateWorkingSetFilter(this);
|
||||
// }
|
||||
// protected void onWorkingSetNameChange() {
|
||||
// updateDescription();
|
||||
// }
|
||||
// };
|
||||
|
||||
fHorizontalOrientation= new Action(Messages.THViewPart_HorizontalOrientation, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
setOrientation(ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
};
|
||||
CPluginImages.setImageDescriptors(fHorizontalOrientation, CPluginImages.T_LCL, CPluginImages.IMG_LCL_HORIZONTAL_ORIENTATION);
|
||||
|
||||
fVerticalOrientation= new Action(Messages.THViewPart_VerticalOrientation, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
setOrientation(ORIENTATION_VERTICAL);
|
||||
}
|
||||
};
|
||||
CPluginImages.setImageDescriptors(fVerticalOrientation, CPluginImages.T_LCL, CPluginImages.IMG_LCL_VERTICAL_ORIENTATION);
|
||||
|
||||
fAutomaticOrientation= new Action(Messages.THViewPart_AutomaticOrientation, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
setOrientation(ORIENTATION_AUTOMATIC);
|
||||
}
|
||||
};
|
||||
CPluginImages.setImageDescriptors(fAutomaticOrientation, CPluginImages.T_LCL, CPluginImages.IMG_LCL_AUTOMATIC_ORIENTATION);
|
||||
|
||||
fSingleOrientation= new Action(Messages.THViewPart_SinglePaneOrientation, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
setOrientation(ORIENTATION_SINGLE);
|
||||
}
|
||||
};
|
||||
CPluginImages.setImageDescriptors(fSingleOrientation, CPluginImages.T_LCL, CPluginImages.IMG_LCL_SINGLE_ORIENTATION);
|
||||
|
||||
fShowTypeHierarchyAction= new Action(Messages.THViewPart_CompleteTypeHierarchy, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetHierarchyKind(THHierarchyModel.TYPE_HIERARCHY);
|
||||
}
|
||||
}
|
||||
};
|
||||
fShowTypeHierarchyAction.setToolTipText(Messages.THViewPart_CompleteTypeHierarchy_tooltip);
|
||||
CPluginImages.setImageDescriptors(fShowTypeHierarchyAction, CPluginImages.T_LCL, CPluginImages.IMG_LCL_TYPE_HIERARCHY);
|
||||
|
||||
fShowSubTypeHierarchyAction= new Action(Messages.THViewPart_SubtypeHierarchy, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetHierarchyKind(THHierarchyModel.SUB_TYPE_HIERARCHY);
|
||||
}
|
||||
}
|
||||
};
|
||||
fShowSubTypeHierarchyAction.setToolTipText(Messages.THViewPart_SubtypeHierarchy_tooltip);
|
||||
CPluginImages.setImageDescriptors(fShowSubTypeHierarchyAction, CPluginImages.T_LCL, CPluginImages.IMG_LCL_SUB_TYPE_HIERARCHY);
|
||||
|
||||
fShowSuperTypeHierarchyAction= new Action(Messages.THViewPart_SupertypeHierarchy, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetHierarchyKind(THHierarchyModel.SUPER_TYPE_HIERARCHY);
|
||||
}
|
||||
}
|
||||
};
|
||||
fShowSuperTypeHierarchyAction.setToolTipText(Messages.THViewPart_SupertypeHierarchy_tooltip);
|
||||
CPluginImages.setImageDescriptors(fShowSuperTypeHierarchyAction, CPluginImages.T_LCL, CPluginImages.IMG_LCL_SUPER_TYPE_HIERARCHY);
|
||||
|
||||
fOpenElement= new Action(Messages.THViewPart_Open) {
|
||||
public void run() {
|
||||
onOpenElement(getSite().getSelectionProvider().getSelection());
|
||||
}
|
||||
};
|
||||
fOpenElement.setToolTipText(Messages.THViewPart_Open_tooltip);
|
||||
|
||||
fShowFilesInLabelsAction= new Action(Messages.THViewPart_ShowFileNames, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
onShowFilesInLabels(isChecked());
|
||||
}
|
||||
};
|
||||
fShowFilesInLabelsAction.setToolTipText(Messages.THViewPart_ShowFileNames_tooltip);
|
||||
|
||||
fRefreshAction = new Action(Messages.THViewPart_Refresh) {
|
||||
public void run() {
|
||||
onRefresh();
|
||||
}
|
||||
};
|
||||
fRefreshAction.setToolTipText(Messages.THViewPart_Refresh_tooltip);
|
||||
CPluginImages.setImageDescriptors(fRefreshAction, CPluginImages.T_LCL, CPluginImages.IMG_REFRESH);
|
||||
|
||||
fCancelAction = new Action(Messages.THViewPart_Cancel) {
|
||||
public void run() {
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
fCancelAction.setToolTipText(Messages.THViewPart_Cancel_tooltip);
|
||||
CPluginImages.setImageDescriptors(fCancelAction, CPluginImages.T_LCL, CPluginImages.IMG_LCL_CANCEL);
|
||||
|
||||
fHistoryAction = new THHistoryDropDownAction(this);
|
||||
|
||||
// setup action bar
|
||||
// global action hooks
|
||||
IActionBars actionBars = getViewSite().getActionBars();
|
||||
fRefactoringActionGroup.fillActionBars(actionBars);
|
||||
fOpenViewActionGroup.fillActionBars(actionBars);
|
||||
fSelectionSearchGroup.fillActionBars(actionBars);
|
||||
|
||||
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction);
|
||||
actionBars.updateActionBars();
|
||||
|
||||
// local toolbar
|
||||
IToolBarManager tm = actionBars.getToolBarManager();
|
||||
tm.add(fShowTypeHierarchyAction);
|
||||
tm.add(fShowSuperTypeHierarchyAction);
|
||||
tm.add(fShowSubTypeHierarchyAction);
|
||||
tm.add(fHistoryAction);
|
||||
tm.add(fRefreshAction);
|
||||
tm.add(fCancelAction);
|
||||
|
||||
// local menu
|
||||
IMenuManager mm = actionBars.getMenuManager();
|
||||
|
||||
// fWorkingSetFilterUI.fillActionBars(actionBars);
|
||||
// mm.add(new Separator(IContextMenuConstants.GROUP_SHOW));
|
||||
mm.add(fShowTypeHierarchyAction);
|
||||
mm.add(fShowSuperTypeHierarchyAction);
|
||||
mm.add(fShowSubTypeHierarchyAction);
|
||||
mm.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
|
||||
|
||||
MenuManager submenu= new MenuManager(Messages.THViewPart_LayoutMenu);
|
||||
submenu.add(fHorizontalOrientation);
|
||||
submenu.add(fVerticalOrientation);
|
||||
submenu.add(fAutomaticOrientation);
|
||||
submenu.add(fSingleOrientation);
|
||||
|
||||
mm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, submenu);
|
||||
|
||||
// mm.add(fReferencedByAction);
|
||||
// mm.add(fMakesReferenceToAction);
|
||||
mm.add(new Separator());
|
||||
mm.add(fShowFilesInLabelsAction);
|
||||
}
|
||||
|
||||
protected void onOpenElement(ISelection selection) {
|
||||
ICElement elem= selectionToElement(selection);
|
||||
openElement(elem);
|
||||
}
|
||||
|
||||
private void openElement(ICElement elem) {
|
||||
if (elem != null) {
|
||||
IWorkbenchPage page= getSite().getPage();
|
||||
try {
|
||||
EditorOpener.open(page, elem);
|
||||
} catch (CModelException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRefresh() {
|
||||
fModel.refresh();
|
||||
updateActionEnablement();
|
||||
}
|
||||
|
||||
protected void onCancel() {
|
||||
fModel.stopGraphComputation();
|
||||
updateView();
|
||||
}
|
||||
|
||||
protected void onShowFilesInLabels(boolean show) {
|
||||
fHierarchyLabelProvider.setShowFiles(show);
|
||||
fHierarchyTreeViewer.refresh();
|
||||
}
|
||||
|
||||
private void updateHistory(ICElement input) {
|
||||
if (input != null) {
|
||||
fHistoryEntries.remove(input);
|
||||
fHistoryEntries.add(0, input);
|
||||
if (fHistoryEntries.size() > MAX_HISTORY_SIZE) {
|
||||
fHistoryEntries.remove(MAX_HISTORY_SIZE-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDescription() {
|
||||
String message= ""; //$NON-NLS-1$
|
||||
if (!fShowsMessage) {
|
||||
ICElement elem= getInput();
|
||||
if (elem != null) {
|
||||
String label;
|
||||
|
||||
// label
|
||||
label= CElementLabels.getElementLabel(elem, 0);
|
||||
|
||||
// scope
|
||||
IWorkingSet workingSet= null;
|
||||
// workingSet= fWorkingSetFilterUI.getWorkingSet();
|
||||
if (workingSet == null) {
|
||||
message= label;
|
||||
}
|
||||
else {
|
||||
String scope= workingSet.getLabel();
|
||||
message= MessageFormat.format("{0} - {1}", new Object[] {label, scope}); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
setContentDescription(message);
|
||||
}
|
||||
|
||||
private void updateActionEnablement() {
|
||||
fHistoryAction.setEnabled(!fHistoryEntries.isEmpty());
|
||||
fRefreshAction.setEnabled(!fShowsMessage);
|
||||
fCancelAction.setEnabled(!fShowsMessage && !fModel.isComputed());
|
||||
fShowSubTypeHierarchyAction.setEnabled(!fShowsMessage);
|
||||
fShowSuperTypeHierarchyAction.setEnabled(!fShowsMessage);
|
||||
fShowTypeHierarchyAction.setEnabled(!fShowsMessage);
|
||||
}
|
||||
|
||||
// private void updateWorkingSetFilter(WorkingSetFilterUI filterUI) {
|
||||
// fModel.setWorkingSetFilter(filterUI);
|
||||
// updateView();
|
||||
// }
|
||||
|
||||
protected void onSetHierarchyKind(int kind) {
|
||||
if (fModel.getHierarchyKind() != kind) {
|
||||
fModel.setHierarchyKind(kind);
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateView() {
|
||||
if (!fShowsMessage) {
|
||||
fIgnoreSelectionChanges++;
|
||||
try {
|
||||
fHierarchyTreeViewer.refresh();
|
||||
fMethodViewer.refresh();
|
||||
updateDescription();
|
||||
updateActionEnablement();
|
||||
setSelections();
|
||||
}
|
||||
finally {
|
||||
fIgnoreSelectionChanges--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setSelections() {
|
||||
fIgnoreSelectionChanges++;
|
||||
try {
|
||||
THNode node= fModel.getSelectionInHierarchy();
|
||||
if (node != null) {
|
||||
fHierarchyTreeViewer.setSelection(new StructuredSelection(node));
|
||||
fHierarchyTreeViewer.expandToLevel(node, 1);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fIgnoreSelectionChanges--;
|
||||
}
|
||||
}
|
||||
|
||||
private ICElement selectionToElement(ISelection selection) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection ss= (IStructuredSelection) selection;
|
||||
for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
|
||||
Object cand= iter.next();
|
||||
if (cand instanceof ICElement) {
|
||||
return (ICElement) cand;
|
||||
}
|
||||
if (cand instanceof IAdaptable) {
|
||||
ICElement elem= (ICElement) ((IAdaptable) cand).getAdapter(ICElement.class);
|
||||
if (elem != null) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private THNode selectionToNode(ISelection selection) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection ss= (IStructuredSelection) selection;
|
||||
for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
|
||||
Object cand= iter.next();
|
||||
if (cand instanceof THNode) {
|
||||
return (THNode) cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Control getPageBook() {
|
||||
return fPagebook;
|
||||
}
|
||||
|
||||
public ICElement[] getHistoryEntries() {
|
||||
return (ICElement[]) fHistoryEntries.toArray(new ICElement[fHistoryEntries.size()]);
|
||||
}
|
||||
|
||||
public void setHistoryEntries(ICElement[] remaining) {
|
||||
fHistoryEntries.clear();
|
||||
fHistoryEntries.addAll(Arrays.asList(remaining));
|
||||
}
|
||||
|
||||
public ICElement getInput() {
|
||||
Object input= fModel.getInput();
|
||||
if (input instanceof ICElement) {
|
||||
return (ICElement) input;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TreeViewer getHiearchyViewer() {
|
||||
return fHierarchyTreeViewer;
|
||||
}
|
||||
|
||||
public TableViewer getMethodViewer() {
|
||||
return fMethodViewer;
|
||||
}
|
||||
|
||||
private void restoreOrientation(int orientation) {
|
||||
switch(orientation) {
|
||||
case ORIENTATION_HORIZONTAL:
|
||||
fHorizontalOrientation.setChecked(true);
|
||||
break;
|
||||
case ORIENTATION_VERTICAL:
|
||||
fVerticalOrientation.setChecked(true);
|
||||
break;
|
||||
case ORIENTATION_SINGLE:
|
||||
fSingleOrientation.setChecked(true);
|
||||
break;
|
||||
default:
|
||||
orientation= ORIENTATION_AUTOMATIC;
|
||||
fAutomaticOrientation.setChecked(true);
|
||||
break;
|
||||
}
|
||||
setOrientation(orientation);
|
||||
}
|
||||
|
||||
private void restoreHierarchyKind(int kind) {
|
||||
switch(kind) {
|
||||
case THHierarchyModel.SUB_TYPE_HIERARCHY:
|
||||
fShowSubTypeHierarchyAction.setChecked(true);
|
||||
break;
|
||||
case THHierarchyModel.SUPER_TYPE_HIERARCHY:
|
||||
fShowSuperTypeHierarchyAction.setChecked(true);
|
||||
break;
|
||||
default:
|
||||
kind= THHierarchyModel.TYPE_HIERARCHY;
|
||||
fShowTypeHierarchyAction.setChecked(true);
|
||||
break;
|
||||
}
|
||||
fModel.setHierarchyKind(kind);
|
||||
}
|
||||
|
||||
public void setOrientation(int orientation) {
|
||||
if (fInComputeOrientation) {
|
||||
return;
|
||||
}
|
||||
fInComputeOrientation= true;
|
||||
try {
|
||||
if (fCurrentViewOrientation != orientation) {
|
||||
if (fSplitter != null && !fSplitter.isDisposed()) {
|
||||
if (orientation == ORIENTATION_AUTOMATIC) {
|
||||
orientation= getBestOrientation();
|
||||
}
|
||||
if (orientation == ORIENTATION_SINGLE) {
|
||||
fMethodViewForm.setVisible(false);
|
||||
} else {
|
||||
if (fCurrentViewOrientation == ORIENTATION_SINGLE) {
|
||||
fMethodViewForm.setVisible(true);
|
||||
}
|
||||
boolean horizontal= orientation == ORIENTATION_HORIZONTAL;
|
||||
fSplitter.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
|
||||
}
|
||||
fSplitter.layout();
|
||||
}
|
||||
fCurrentViewOrientation= orientation;
|
||||
}
|
||||
} finally {
|
||||
fInComputeOrientation= false;
|
||||
}
|
||||
}
|
||||
|
||||
private int getBestOrientation() {
|
||||
Point size= fSplitter.getSize();
|
||||
if (size.x != 0 && size.y != 0) {
|
||||
if (3*size.x < 2*size.y)
|
||||
return ORIENTATION_VERTICAL;
|
||||
}
|
||||
return ORIENTATION_HORIZONTAL;
|
||||
}
|
||||
|
||||
public void onEvent(int event) {
|
||||
switch (event) {
|
||||
case THHierarchyModel.END_OF_COMPUTATION:
|
||||
updateView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.typehierarchy;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
||||
public class TypeHierarchyUI {
|
||||
private static boolean sIsJUnitTest= false;
|
||||
|
||||
public static void setIsJUnitTest(boolean val) {
|
||||
sIsJUnitTest= val;
|
||||
}
|
||||
|
||||
public static THViewPart open(ICElement input, IWorkbenchWindow window) {
|
||||
if (input != null) {
|
||||
return openInViewPart(window, input);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static THViewPart openInViewPart(IWorkbenchWindow window, ICElement input) {
|
||||
IWorkbenchPage page= window.getActivePage();
|
||||
try {
|
||||
THViewPart result= (THViewPart)page.showView(CUIPlugin.ID_TYPE_HIERARCHY);
|
||||
result.setInput(input);
|
||||
return result;
|
||||
} catch (CoreException e) {
|
||||
ExceptionHandler.handle(e, window.getShell(), Messages.TypeHierarchyUI_OpenTypeHierarchy, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static THViewPart openInViewPart(IWorkbenchWindow window, ICElement[] input) {
|
||||
ICElement elem = null;
|
||||
switch (input.length) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
elem = input[0];
|
||||
break;
|
||||
default:
|
||||
if (sIsJUnitTest) {
|
||||
throw new RuntimeException("ambigous input"); //$NON-NLS-1$
|
||||
}
|
||||
elem = OpenActionUtil.selectCElement(input, window.getShell(),
|
||||
Messages.TypeHierarchyUI_OpenTypeHierarchy, Messages.TypeHierarchyUI_SelectFromList,
|
||||
CElementLabels.ALL_DEFAULT | CElementLabels.MF_POST_FILE_QUALIFIED, 0);
|
||||
break;
|
||||
}
|
||||
if (elem != null) {
|
||||
return openInViewPart(window, elem);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void open(final CEditor editor, final ITextSelection sel) {
|
||||
if (editor != null) {
|
||||
final ICProject project= editor.getInputCElement().getCProject();
|
||||
final IEditorInput editorInput = editor.getEditorInput();
|
||||
final Display display= Display.getCurrent();
|
||||
|
||||
Job job= new Job(Messages.TypeHierarchyUI_OpenTypeHierarchy) {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
final ICElement[] elems= findDefinitions(project, editorInput, sel);
|
||||
if (elems != null && elems.length > 0) {
|
||||
display.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
openInViewPart(editor.getSite().getWorkbenchWindow(), elems);
|
||||
}});
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
};
|
||||
job.setUser(true);
|
||||
job.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
|
||||
try {
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
|
||||
|
||||
index.acquireReadLock();
|
||||
try {
|
||||
IASTName name= getSelectedName(index, editorInput, sel);
|
||||
if (name != null) {
|
||||
IBinding binding= name.resolveBinding();
|
||||
if (isValidInput(binding)) {
|
||||
if (name.isDefinition()) {
|
||||
ICElement elem= IndexUI.getCElementForName(project, index, name);
|
||||
if (elem != null) {
|
||||
return new ICElement[]{elem};
|
||||
}
|
||||
}
|
||||
else {
|
||||
ICElement[] elems= IndexUI.findAllDefinitions(index, binding);
|
||||
if (elems.length == 0) {
|
||||
elems= IndexUI.findAllDefinitions(index, binding);
|
||||
if (elems.length == 0) {
|
||||
ICElement elem= IndexUI.findAnyDeclaration(index, project, binding);
|
||||
if (elems != null) {
|
||||
elems= new ICElement[]{elem};
|
||||
}
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (index != null) {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
catch (DOMException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||
int selectionStart = selection.getOffset();
|
||||
int selectionLength = selection.getLength();
|
||||
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
if (workingCopy == null)
|
||||
return null;
|
||||
|
||||
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
IASTTranslationUnit ast = workingCopy.getAST(index, options);
|
||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||
ast.accept(finder);
|
||||
return finder.getSelectedName();
|
||||
}
|
||||
|
||||
public static boolean isValidInput(IBinding binding) {
|
||||
if (binding instanceof ICompositeType) {
|
||||
// || binding instanceof ITypedef ||
|
||||
// binding instanceof IField || binding instanceof ICPPMethod) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidInput(ICElement elem) {
|
||||
if (elem == null) {
|
||||
return false;
|
||||
}
|
||||
switch (elem.getElementType()) {
|
||||
case ICElement.C_CLASS:
|
||||
case ICElement.C_STRUCT:
|
||||
case ICElement.C_UNION:
|
||||
case ICElement.C_CLASS_DECLARATION:
|
||||
case ICElement.C_STRUCT_DECLARATION:
|
||||
case ICElement.C_UNION_DECLARATION:
|
||||
// case ICElement.C_TYPEDEF:
|
||||
// case ICElement.C_CLASS_CTOR:
|
||||
// case ICElement.C_CLASS_DTOR:
|
||||
// case ICElement.C_FIELD:
|
||||
// case ICElement.C_METHOD:
|
||||
// case ICElement.C_METHOD_DECLARATION:
|
||||
// case ICElement.C_TEMPLATE_METHOD:
|
||||
// case ICElement.C_TEMPLATE_METHOD_DECLARATION:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# Markus Schorn (Wind River Systems)
|
||||
###############################################################################
|
||||
THHistoryDropDownAction_ClearHistory=Clear History
|
||||
THHistoryListAction_HistoryList_title=Type Hierarchy History
|
||||
THHistoryListAction_HistoryList_label=Select the input for the Type Hierarchy:
|
||||
THViewPart_SupertypeHierarchy_tooltip=Show the Supertype Hierarchy
|
||||
THHistoryDropDownAction_tooltip=Show History List
|
||||
THViewPart_AutomaticOrientation=Automatic View Orientation
|
||||
THHistoryListAction_Remove=Remove
|
||||
THHierarchyModel_Job_title=Open Type Hierarchy
|
||||
THViewPart_Refresh_tooltip=Refresh
|
||||
THHistoryListAction_label=Open History...
|
||||
THViewPart_instruction=To display the type hierarchy, select a type or member and select the 'Open Type Hierarchy' menu option.
|
||||
THViewPart_MethodPane_title=Content
|
||||
THViewPart_HorizontalOrientation=Horizontal View Orientation
|
||||
THViewPart_VerticalOrientation=Vertical View Orientation
|
||||
THViewPart_SinglePaneOrientation=Hierarchy View Only
|
||||
THViewPart_CompleteTypeHierarchy=Type Hieararchy
|
||||
THViewPart_CompleteTypeHierarchy_tooltip=Show the Type Hierarchy
|
||||
THViewPart_SubtypeHierarchy=Subtype Hieararchy
|
||||
THViewPart_SubtypeHierarchy_tooltip=Show the Subtype Hierarchy
|
||||
THViewPart_SupertypeHierarchy=Supertype Hieararchy
|
||||
THViewPart_Open=Open
|
||||
THViewPart_Open_tooltip=Open
|
||||
THViewPart_ShowFileNames=Show File Names
|
||||
THViewPart_Cancel_tooltip=Cancel
|
||||
THViewPart_ShowFileNames_tooltip=Show File Names
|
||||
THViewPart_Refresh=Refresh
|
||||
THViewPart_LayoutMenu=Layout
|
||||
THViewPart_FocusOn=Focus On ''{0}''
|
||||
THViewPart_Cancel=Cancel
|
||||
TypeHierarchyUI_OpenTypeHierarchy=Open Type Hierarchy
|
||||
TypeHierarchyUI_SelectFromList=Select one element from the list
|
||||
OpenTypeHierarchyAction_label=Open Type Hierarchy
|
||||
OpenTypeHierarchyAction_tooltip=Open Type Hierarchy
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -689,7 +689,8 @@ public class CElementLabels {
|
|||
}
|
||||
}
|
||||
if (isQualifier) {
|
||||
getTypeLabel(parent, flags, buf);
|
||||
int qflags= flags & ~MF_POST_FILE_QUALIFIED;
|
||||
getTypeLabel(parent, qflags, buf);
|
||||
buf.append("::"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
@ -720,6 +721,14 @@ public class CElementLabels {
|
|||
if (elem instanceof ITemplate) {
|
||||
getTemplateParameters((ITemplate)elem, flags, buf);
|
||||
}
|
||||
|
||||
if( getFlag(flags, MF_POST_FILE_QUALIFIED)) {
|
||||
IPath path= elem.getPath();
|
||||
if (path != null) {
|
||||
buf.append( CONCAT_STRING );
|
||||
buf.append(path.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.IPositionConverter;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
|
||||
public class IndexUI {
|
||||
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
|
||||
|
||||
public static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException {
|
||||
IIndexName name= elementToName(index, element);
|
||||
if (name != null) {
|
||||
return index.findBinding(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IIndexName elementToName(IIndex index, ICElement element) throws CoreException {
|
||||
if (element instanceof ISourceReference) {
|
||||
ISourceReference sf = ((ISourceReference)element);
|
||||
ITranslationUnit tu= sf.getTranslationUnit();
|
||||
if (tu != null) {
|
||||
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
|
||||
if (location != null) {
|
||||
IIndexFile file= index.getFile(location);
|
||||
if (file != null) {
|
||||
String elementName= element.getElementName();
|
||||
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
||||
ISourceRange pos= sf.getSourceRange();
|
||||
IRegion region= new Region(pos.getIdStartPos()+idx, pos.getIdLength());
|
||||
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp());
|
||||
if (converter != null) {
|
||||
region= converter.actualToHistoric(region);
|
||||
}
|
||||
IIndexName[] names= file.findNames(region.getOffset(), region.getLength());
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
IIndexName name = names[i];
|
||||
if (!name.isReference() && elementName.endsWith(new String(name.toCharArray()))) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ICElement[] findRepresentative(IIndex index, IBinding binding)
|
||||
throws CoreException, DOMException {
|
||||
ICElement[] defs = IndexUI.findAllDefinitions(index, binding);
|
||||
if (defs.length == 0) {
|
||||
ICElement elem = IndexUI.findAnyDeclaration(index, null, binding);
|
||||
if (elem != null) {
|
||||
defs = new ICElement[] { elem };
|
||||
}
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
public static ICElement[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException, DOMException {
|
||||
if (binding != null) {
|
||||
IIndexName[] defs= index.findDefinitions(binding);
|
||||
|
||||
ArrayList result= new ArrayList();
|
||||
for (int i = 0; i < defs.length; i++) {
|
||||
IIndexName in = defs[i];
|
||||
ICElement definition= getCElementForName(null, index, in);
|
||||
if (definition != null) {
|
||||
result.add(definition);
|
||||
}
|
||||
|
||||
}
|
||||
return (ICElement[]) result.toArray(new ICElement[result.size()]);
|
||||
}
|
||||
return EMPTY_ELEMENTS;
|
||||
}
|
||||
|
||||
public static ICElement getCElementForName(ICProject preferProject, IIndex index, IASTName declName) throws CoreException, DOMException {
|
||||
assert !declName.isReference();
|
||||
IBinding binding= declName.resolveBinding();
|
||||
if (binding != null) {
|
||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||
if (tu != null) {
|
||||
IFile file= (IFile) tu.getResource();
|
||||
long timestamp= file.getLocalTimeStamp();
|
||||
IASTFileLocation loc= declName.getFileLocation();
|
||||
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(file, timestamp);
|
||||
if (converter != null) {
|
||||
region= converter.actualToHistoric(region);
|
||||
}
|
||||
return CElementHandleFactory.create(tu, binding, region, timestamp);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ITranslationUnit getTranslationUnit(ICProject cproject, IName name) {
|
||||
IPath path= Path.fromOSString(name.getFileLocation().getFileName());
|
||||
try {
|
||||
return CModelUtil.findTranslationUnitForLocation(path, cproject);
|
||||
} catch (CModelException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ICElement getCElementForName(ICProject preferProject, IIndex index, IIndexName declName) throws CoreException, DOMException {
|
||||
assert !declName.isReference();
|
||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||
if (tu != null) {
|
||||
IRegion region= new Region(declName.getNodeOffset(), declName.getNodeLength());
|
||||
long timestamp= declName.getFile().getTimestamp();
|
||||
return CElementHandleFactory.create(tu, index.findBinding(declName), region, timestamp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ICElement findAnyDeclaration(IIndex index, ICProject preferProject, IBinding binding) throws CoreException, DOMException {
|
||||
if (binding != null) {
|
||||
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
ICElement elem= getCElementForName(preferProject, index, names[i]);
|
||||
if (elem != null) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||
int selectionStart = selection.getOffset();
|
||||
int selectionLength = selection.getLength();
|
||||
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
if (workingCopy == null)
|
||||
return null;
|
||||
|
||||
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
IASTTranslationUnit ast = workingCopy.getAST(index, options);
|
||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||
ast.accept(finder);
|
||||
return finder.getSelectedName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.FocusListener;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
public class SelectionProviderMediator implements ISelectionProvider {
|
||||
private Map fProviders= new HashMap();
|
||||
private ISelectionProvider fActiveProvider = null;
|
||||
private ISelectionChangedListener fSelectionChangedListener;
|
||||
private FocusListener fFocusListener;
|
||||
|
||||
private ListenerList fListenerList= new ListenerList();
|
||||
|
||||
public SelectionProviderMediator() {
|
||||
fSelectionChangedListener= new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
onSelectionChanged(event);
|
||||
}
|
||||
};
|
||||
fFocusListener = new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
onFocusGained(e);
|
||||
}
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
final public void addSelectionChangedListener(ISelectionChangedListener listener) {
|
||||
fListenerList.add(listener);
|
||||
}
|
||||
|
||||
final public void removeSelectionChangedListener(ISelectionChangedListener listener) {
|
||||
fListenerList.remove(listener);
|
||||
}
|
||||
|
||||
final protected void fireSelectionChanged() {
|
||||
Object[] listeners= fListenerList.getListeners();
|
||||
if (listeners.length > 0) {
|
||||
SelectionChangedEvent event= new SelectionChangedEvent(this, getSelection());
|
||||
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
ISelectionChangedListener listener= (ISelectionChangedListener) listeners[i];
|
||||
listener.selectionChanged(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addViewer(Viewer viewer) {
|
||||
addSelectionProvider(viewer.getControl(), viewer);
|
||||
}
|
||||
|
||||
public void addSelectionProvider(Control ctrl, ISelectionProvider sp) {
|
||||
fProviders.put(ctrl, sp);
|
||||
sp.addSelectionChangedListener(fSelectionChangedListener);
|
||||
ctrl.addFocusListener(fFocusListener);
|
||||
}
|
||||
|
||||
// overrider
|
||||
public ISelection getSelection() {
|
||||
if (fActiveProvider != null) {
|
||||
return fActiveProvider.getSelection();
|
||||
}
|
||||
return StructuredSelection.EMPTY;
|
||||
}
|
||||
// overrider
|
||||
public void setSelection(ISelection selection) {
|
||||
if (fActiveProvider != null) {
|
||||
fActiveProvider.setSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onFocusGained(FocusEvent e) {
|
||||
ISelectionProvider provider= (ISelectionProvider) fProviders.get(e.widget);
|
||||
if (provider != null) {
|
||||
fActiveProvider= provider;
|
||||
fireSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSelectionChanged(SelectionChangedEvent event) {
|
||||
if (event.getSelectionProvider() == fActiveProvider) {
|
||||
fireSelectionChanged();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -96,6 +96,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
|
||||
public static final String ID_INCLUDE_BROWSER= PLUGIN_ID + ".includeBrowser"; //$NON-NLS-1$
|
||||
public static final String ID_CALL_HIERARCHY= PLUGIN_ID + ".callHierarchy"; //$NON-NLS-1$
|
||||
public static final String ID_TYPE_HIERARCHY = PLUGIN_ID + ".typeHierarchy"; //$NON-NLS-1$
|
||||
|
||||
public static final String C_PROJECT_WIZARD_ID = PLUGIN_ID + ".wizards.StdCWizard"; //$NON-NLS-1$
|
||||
public static final String CPP_PROJECT_WIZARD_ID = PLUGIN_ID + ".wizards.StdCCWizard"; //$NON-NLS-1$
|
||||
|
@ -180,12 +181,6 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
*/
|
||||
public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The view part id of the type hierarchy part
|
||||
* (value <code>"org.eclipse.cdt.ui.TypeHierarchy"</code>).
|
||||
*/
|
||||
public static final String ID_TYPE_HIERARCHY = "org.eclipse.cdt.ui.TypeHierarchyView"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The key to store customized templates.
|
||||
* @since 3.0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -27,12 +27,15 @@ import org.eclipse.ui.dialogs.PropertyDialogAction;
|
|||
import org.eclipse.ui.part.Page;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.callhierarchy.CHViewPart;
|
||||
import org.eclipse.cdt.internal.ui.callhierarchy.OpenCallHierarchyAction;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
||||
import org.eclipse.cdt.internal.ui.typehierarchy.OpenTypeHierarchyAction;
|
||||
import org.eclipse.cdt.internal.ui.typehierarchy.THViewPart;
|
||||
|
||||
/**
|
||||
* Action group that adds actions to open a new CDT view part or an external
|
||||
|
@ -47,14 +50,14 @@ import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
|||
public class OpenViewActionGroup extends ActionGroup {
|
||||
|
||||
private boolean fEditorIsOwner;
|
||||
// private boolean fIsTypeHiararchyViewerOwner;
|
||||
private boolean fIsTypeHiararchyViewerOwner;
|
||||
private boolean fIsCallHiararchyViewerOwner;
|
||||
private IWorkbenchSite fSite;
|
||||
private String fGroupName= IContextMenuConstants.GROUP_OPEN;
|
||||
|
||||
// private OpenSuperImplementationAction fOpenSuperImplementation;
|
||||
// private OpenExternalJavadocAction fOpenExternalJavadoc;
|
||||
// private OpenTypeHierarchyAction fOpenTypeHierarchy;
|
||||
private OpenTypeHierarchyAction fOpenTypeHierarchy;
|
||||
private PropertyDialogAction fOpenPropertiesDialog;
|
||||
private OpenCallHierarchyAction fOpenCallHierarchy;
|
||||
|
||||
|
@ -78,8 +81,8 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
*/
|
||||
public OpenViewActionGroup(IViewPart part) {
|
||||
createSiteActions(part.getSite());
|
||||
// fIsTypeHiararchyViewerOwner= part instanceof TypeHierarchyViewPart;
|
||||
fIsCallHiararchyViewerOwner= part instanceof CHViewPart;
|
||||
fIsTypeHiararchyViewerOwner= part instanceof THViewPart;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,10 +99,12 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
// fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC);
|
||||
// part.setAction("OpenExternalJavadoc", fOpenExternalJavadoc); //$NON-NLS-1$
|
||||
|
||||
// fOpenTypeHierarchy= new OpenTypeHierarchyAction(part);
|
||||
// fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||
// part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$
|
||||
|
||||
fOpenTypeHierarchy= new OpenTypeHierarchyAction(part);
|
||||
fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||
if (useTypeHierarchy()) {
|
||||
part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
fOpenCallHierarchy= new OpenCallHierarchyAction(part);
|
||||
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$
|
||||
|
@ -107,6 +112,10 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
initialize(part.getEditorSite());
|
||||
}
|
||||
|
||||
private boolean useTypeHierarchy() {
|
||||
return CUIPlugin.getDefault().getPluginPreferences().getBoolean("showCtxMenuTypeHierarchy"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void createSiteActions(IWorkbenchSite site) {
|
||||
// fOpenSuperImplementation= new OpenSuperImplementationAction(site);
|
||||
// fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION);
|
||||
|
@ -114,9 +123,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
// fOpenExternalJavadoc= new OpenExternalJavadocAction(site);
|
||||
// fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC);
|
||||
|
||||
// fOpenTypeHierarchy= new OpenTypeHierarchyAction(site);
|
||||
// fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||
|
||||
fOpenTypeHierarchy= new OpenTypeHierarchyAction(site);
|
||||
fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||
|
||||
fOpenCallHierarchy= new OpenCallHierarchyAction(site);
|
||||
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||
|
||||
|
@ -132,7 +141,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
ISelection selection= provider.getSelection();
|
||||
// fOpenSuperImplementation.update(selection);
|
||||
// fOpenExternalJavadoc.update(selection);
|
||||
// fOpenTypeHierarchy.update(selection);
|
||||
fOpenTypeHierarchy.update(selection);
|
||||
fOpenCallHierarchy.update(selection);
|
||||
if (!fEditorIsOwner) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
|
@ -143,7 +152,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
}
|
||||
// provider.addSelectionChangedListener(fOpenSuperImplementation);
|
||||
// provider.addSelectionChangedListener(fOpenExternalJavadoc);
|
||||
// provider.addSelectionChangedListener(fOpenTypeHierarchy);
|
||||
provider.addSelectionChangedListener(fOpenTypeHierarchy);
|
||||
provider.addSelectionChangedListener(fOpenCallHierarchy);
|
||||
// no need to register the open properties dialog action since it registers itself
|
||||
}
|
||||
|
@ -162,15 +171,18 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
*/
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
super.fillContextMenu(menu);
|
||||
// if (!fIsTypeHiararchyViewerOwner)
|
||||
// appendToGroup(menu, fOpenTypeHierarchy);
|
||||
if (useTypeHierarchy() && !fIsTypeHiararchyViewerOwner && fOpenTypeHierarchy.isEnabled()) {
|
||||
menu.appendToGroup(fGroupName, fOpenTypeHierarchy);
|
||||
}
|
||||
if (!fIsCallHiararchyViewerOwner && fOpenCallHierarchy.isEnabled()) {
|
||||
menu.appendToGroup(fGroupName, fOpenCallHierarchy);
|
||||
}
|
||||
// appendToGroup(menu, fOpenSuperImplementation);
|
||||
IStructuredSelection selection= getStructuredSelection();
|
||||
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection)) {
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
|
||||
if (!fIsCallHiararchyViewerOwner && !fIsTypeHiararchyViewerOwner) {
|
||||
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection)) {
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,7 +193,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
ISelectionProvider provider= fSite.getSelectionProvider();
|
||||
// provider.removeSelectionChangedListener(fOpenSuperImplementation);
|
||||
// provider.removeSelectionChangedListener(fOpenExternalJavadoc);
|
||||
// provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
||||
provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
||||
provider.removeSelectionChangedListener(fOpenCallHierarchy);
|
||||
if (fOpenPropertiesDialog != null) {
|
||||
fOpenPropertiesDialog.dispose();
|
||||
|
@ -192,7 +204,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
|||
private void setGlobalActionHandlers(IActionBars actionBars) {
|
||||
// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_SUPER_IMPLEMENTATION, fOpenSuperImplementation);
|
||||
// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc);
|
||||
// actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy);
|
||||
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy);
|
||||
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy);
|
||||
if (fOpenPropertiesDialog != null) {
|
||||
actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog);
|
||||
|
|
Loading…
Add table
Reference in a new issue