mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2004-05-26 Alain Magloire
Jumbo Patch from Chris Wiebe. Putting a starting skeleton for C Browsing.
This commit is contained in:
parent
09a4ea370c
commit
ccfe7d8f5f
64 changed files with 7308 additions and 210 deletions
|
@ -1,3 +1,8 @@
|
|||
2004-05-26 Alain Magloire
|
||||
|
||||
Jumbo Patch from Chris Wiebe.
|
||||
Putting a starting skeleton for C Browsing.
|
||||
|
||||
2004-05-25 Alain Magloire
|
||||
Update the necessary classes to use the new
|
||||
ResolverModel.
|
||||
|
|
|
@ -17,8 +17,10 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.browser.cache.ITypeCache;
|
||||
import org.eclipse.cdt.internal.core.browser.cache.TypeCacheMessages;
|
||||
import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
|
||||
import org.eclipse.cdt.internal.core.browser.util.ArrayUtil;
|
||||
|
@ -130,9 +132,11 @@ public class AllTypesCache {
|
|||
TypeSearchScope workspaceScope = new TypeSearchScope(true);
|
||||
IProject[] projects = workspaceScope.getEnclosingProjects();
|
||||
ITypeInfoVisitor visitor = new ITypeInfoVisitor() {
|
||||
public void visit(ITypeInfo info) {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
fAllTypes.add(info);
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
};
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
fgTypeCacheManager.getCache(projects[i]).accept(visitor);
|
||||
|
@ -153,11 +157,14 @@ public class AllTypesCache {
|
|||
final int[] fKinds = kinds;
|
||||
IProject[] projects = scope.getEnclosingProjects();
|
||||
ITypeInfoVisitor visitor = new ITypeInfoVisitor() {
|
||||
public void visit(ITypeInfo info) {
|
||||
if (info.isEnclosed(fScope) && ArrayUtil.contains(fKinds, info.getCElementType())) {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
if (ArrayUtil.contains(fKinds, info.getCElementType())
|
||||
&& (fScope != null && info.isEnclosed(fScope))) {
|
||||
fTypesFound.add(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
};
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
fgTypeCacheManager.getCache(projects[i]).accept(visitor);
|
||||
|
@ -180,12 +187,15 @@ public class AllTypesCache {
|
|||
final IQualifiedTypeName fQualifiedName = qualifiedName;
|
||||
IProject[] projects = scope.getEnclosingProjects();
|
||||
ITypeInfoVisitor visitor = new ITypeInfoVisitor() {
|
||||
public void visit(ITypeInfo info) {
|
||||
if ((fScope != null && info.isEnclosed(fScope)) && fQualifiedName.equals(info.getQualifiedTypeName())
|
||||
&& ArrayUtil.contains(fKinds, info.getCElementType())) {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
if (ArrayUtil.contains(fKinds, info.getCElementType())
|
||||
&& fQualifiedName.equals(info.getQualifiedTypeName())
|
||||
&& (fScope != null && info.isEnclosed(fScope))) {
|
||||
fTypesFound.add(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
};
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
fgTypeCacheManager.getCache(projects[i]).accept(visitor);
|
||||
|
@ -193,6 +203,36 @@ public class AllTypesCache {
|
|||
return (ITypeInfo[]) fTypesFound.toArray(new ITypeInfo[fTypesFound.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all namespaces in the given scope.
|
||||
*
|
||||
* @param scope The search scope
|
||||
* @param includeGlobalNamespace <code>true</code> if the global (default) namespace should be returned
|
||||
*/
|
||||
public static ITypeInfo[] getNamespaces(ITypeSearchScope scope, boolean includeGlobalNamespace) {
|
||||
final Collection fTypesFound = new ArrayList();
|
||||
final ITypeSearchScope fScope = scope;
|
||||
IProject[] projects = scope.getEnclosingProjects();
|
||||
ITypeInfoVisitor visitor = new ITypeInfoVisitor() {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
if (info.getCElementType() == ICElement.C_NAMESPACE
|
||||
&& (fScope != null && info.isEnclosed(fScope))) {
|
||||
fTypesFound.add(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
};
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
ITypeCache cache = fgTypeCacheManager.getCache(projects[i]);
|
||||
cache.accept(visitor);
|
||||
if (includeGlobalNamespace) {
|
||||
fTypesFound.add(cache.getGlobalNamespace());
|
||||
}
|
||||
}
|
||||
return (ITypeInfo[]) fTypesFound.toArray(new ITypeInfo[fTypesFound.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the type cache is up to date.
|
||||
*/
|
||||
|
|
|
@ -10,34 +10,31 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.browser;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.core.browser.cache.ITypeCache;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
/**
|
||||
* Type information.
|
||||
*/
|
||||
public interface ITypeInfo {
|
||||
public interface ITypeInfo extends Comparable {
|
||||
|
||||
public static final int KNOWN_TYPES[] = {
|
||||
ICElement.C_NAMESPACE,
|
||||
ICElement.C_CLASS,
|
||||
ICElement.C_STRUCT,
|
||||
ICElement.C_UNION,
|
||||
ICElement.C_ENUMERATION,
|
||||
ICElement.C_TYPEDEF
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the CElement type.
|
||||
* @return ICElement.C_NAMESPACE, C_CLASS, C_STRUCT, C_UNION, C_ENUMERATION, or C_TYPEDEF,
|
||||
* or zero if unknown type.
|
||||
*/
|
||||
public int getCElementType();
|
||||
|
||||
/**
|
||||
* Sets the CElement type.
|
||||
*/
|
||||
public void setCElementType(int type);
|
||||
|
||||
/**
|
||||
* Returns true if the element type is unknown.
|
||||
*/
|
||||
public boolean isUndefinedType();
|
||||
|
||||
/**
|
||||
* Returns true if this type can enclose other types,
|
||||
* i.e. it is a namespace, class, or struct.
|
||||
*/
|
||||
public boolean isQualifierType();
|
||||
|
||||
/**
|
||||
* Gets the type name.
|
||||
*/
|
||||
|
@ -49,10 +46,73 @@ public interface ITypeInfo {
|
|||
public IQualifiedTypeName getQualifiedTypeName();
|
||||
|
||||
/**
|
||||
* Gets the enclosing type.
|
||||
* Returns true if the type exists.
|
||||
*/
|
||||
public boolean exists();
|
||||
|
||||
/**
|
||||
* Returns true if the element type is unknown.
|
||||
*/
|
||||
public boolean isUndefinedType();
|
||||
|
||||
/**
|
||||
* Returns true if this type is enclosed by other types,
|
||||
* i.e. declared an inside another namespace or class.
|
||||
*/
|
||||
public boolean isEnclosedType();
|
||||
|
||||
/** Gets the enclosing type, i.e. the outer class or namespace which contains this type.
|
||||
* @return the enclosing type, or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeInfo getEnclosingType();
|
||||
|
||||
/** Gets the first enclosing type which matches one of the given kinds.
|
||||
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS, C_STRUCT
|
||||
* @return the enclosing type, or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeInfo getEnclosingType(int[] kinds);
|
||||
|
||||
/** Gets the root namespace, i.e. the outermost namespace
|
||||
* which contains this type.
|
||||
* @param includeGlobalNamespace <code>true</code> if the global (default) namespace should be returned
|
||||
* @return the namespace, or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace);
|
||||
|
||||
/**
|
||||
* Returns true if this type is capable of enclosing other types,
|
||||
* i.e. it is a namespace, class, or struct.
|
||||
*/
|
||||
public boolean isEnclosingType();
|
||||
|
||||
/**
|
||||
* Returns true if this type encloses other types, i.e. contains
|
||||
* inner classes or namespaces.
|
||||
*/
|
||||
public boolean hasEnclosedTypes();
|
||||
|
||||
/**
|
||||
* Returns true if this type encloses the given type.
|
||||
*/
|
||||
public boolean encloses(ITypeInfo info);
|
||||
|
||||
/**
|
||||
* Returns true if this type is enclosed by the given type.
|
||||
*/
|
||||
public boolean isEnclosed(ITypeInfo info);
|
||||
|
||||
/** Gets the enclosed types, i.e. inner classes or classes inside this namespace.
|
||||
* @return array of inner types, or empty array if not found.
|
||||
*/
|
||||
public ITypeInfo[] getEnclosedTypes();
|
||||
|
||||
/** Gets the enclosed types, i.e. inner classes or classes inside this namespace.
|
||||
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS, C_STRUCT,
|
||||
* C_UNION, C_ENUMERATION, C_TYPEDEF
|
||||
* @return array of inner types, or empty array if not found.
|
||||
*/
|
||||
public ITypeInfo[] getEnclosedTypes(int kinds[]);
|
||||
|
||||
/**
|
||||
* Gets the enclosing project.
|
||||
*/
|
||||
|
@ -68,13 +128,23 @@ public interface ITypeInfo {
|
|||
*/
|
||||
public void addReference(ITypeReference location);
|
||||
|
||||
/**
|
||||
* Returns all known source references.
|
||||
/** Gets the originating locations where this type was declared.
|
||||
* @return all known source references, or an empty
|
||||
* array if none found.
|
||||
*/
|
||||
public ITypeReference[] getReferences();
|
||||
|
||||
/**
|
||||
* Returns parsed source location with offset and length.
|
||||
/** Gets the real location where type was declared.
|
||||
* @return the parsed source reference (with offset and length),
|
||||
* or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeReference getResolvedReference();
|
||||
|
||||
/**
|
||||
* Returns true if the type can be substituted.
|
||||
*/
|
||||
public boolean canSubstituteFor(ITypeInfo info);
|
||||
|
||||
public ITypeCache getCache();
|
||||
public void setCache(ITypeCache typeCache);
|
||||
}
|
||||
|
|
|
@ -11,5 +11,8 @@
|
|||
package org.eclipse.cdt.core.browser;
|
||||
|
||||
public interface ITypeInfoVisitor {
|
||||
public void visit(ITypeInfo info);
|
||||
|
||||
public boolean visit(ITypeInfo info);
|
||||
|
||||
public boolean shouldContinue();
|
||||
}
|
||||
|
|
|
@ -16,19 +16,20 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.core.browser.cache.ITypeCache;
|
||||
import org.eclipse.cdt.internal.core.browser.util.ArrayUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
public class TypeInfo implements ITypeInfo, Comparable
|
||||
public class TypeInfo implements ITypeInfo
|
||||
{
|
||||
private ITypeCache fTypeCache;
|
||||
private int fElementType;
|
||||
private QualifiedTypeName fQualifiedName;
|
||||
private Set fSourceRefs = new HashSet();
|
||||
protected ITypeCache fTypeCache;
|
||||
protected int fElementType;
|
||||
protected QualifiedTypeName fQualifiedName;
|
||||
protected Set fSourceRefs = new HashSet();
|
||||
protected final static ITypeInfo[] EMPTY_TYPES = new ITypeInfo[0];
|
||||
|
||||
public TypeInfo(int elementType, IQualifiedTypeName typeName, ITypeCache typeCache) {
|
||||
public TypeInfo(int elementType, IQualifiedTypeName typeName) {
|
||||
fElementType = elementType;
|
||||
fQualifiedName = new QualifiedTypeName(typeName);
|
||||
fTypeCache = typeCache;
|
||||
}
|
||||
|
||||
public void addReference(ITypeReference location) {
|
||||
|
@ -57,10 +58,28 @@ public class TypeInfo implements ITypeInfo, Comparable
|
|||
return fElementType == 0;
|
||||
}
|
||||
|
||||
public boolean isQualifierType() {
|
||||
return (fElementType == ICElement.C_NAMESPACE
|
||||
|| fElementType == ICElement.C_CLASS
|
||||
|| fElementType == ICElement.C_STRUCT);
|
||||
public boolean canSubstituteFor(ITypeInfo info) {
|
||||
return isExactMatch(info);
|
||||
}
|
||||
|
||||
protected boolean isExactMatch(ITypeInfo info) {
|
||||
if (hashCode() != info.hashCode())
|
||||
return false;
|
||||
if (fElementType == info.getCElementType()
|
||||
&& fQualifiedName.equals(info.getQualifiedTypeName())) {
|
||||
IProject project1 = getEnclosingProject();
|
||||
IProject project2 = info.getEnclosingProject();
|
||||
if (project1 == null && project2 == null)
|
||||
return true;
|
||||
if (project1 == null || project2 == null)
|
||||
return false;
|
||||
return project1.equals(project2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
return fTypeCache != null;
|
||||
}
|
||||
|
||||
public int getCElementType() {
|
||||
|
@ -79,33 +98,68 @@ public class TypeInfo implements ITypeInfo, Comparable
|
|||
return fQualifiedName.getName();
|
||||
}
|
||||
|
||||
public ITypeInfo getEnclosingType() {
|
||||
ITypeInfo enclosingType = null;
|
||||
public boolean isEnclosedType() {
|
||||
return (fQualifiedName.getEnclosingNames() != null);
|
||||
}
|
||||
|
||||
public ITypeInfo getEnclosingType(int kinds[]) {
|
||||
if (fTypeCache != null) {
|
||||
IQualifiedTypeName parentName = fQualifiedName.getEnclosingTypeName();
|
||||
if (parentName != null) {
|
||||
ITypeInfo[] types = fTypeCache.getTypes(parentName);
|
||||
for (int i = 0; i < types.length; ++i) {
|
||||
ITypeInfo info = types[i];
|
||||
if (info.isQualifierType()) {
|
||||
enclosingType = info;
|
||||
break;
|
||||
} else if (info.isUndefinedType()) {
|
||||
enclosingType = info;
|
||||
// don't break, in case we can still find a defined type
|
||||
return fTypeCache.getEnclosingType(this, kinds);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITypeInfo getEnclosingType() {
|
||||
return getEnclosingType(KNOWN_TYPES);
|
||||
}
|
||||
|
||||
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
|
||||
if (fTypeCache != null) {
|
||||
return fTypeCache.getRootNamespace(this, true);
|
||||
}
|
||||
return enclosingType;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEnclosingType() {
|
||||
return (fElementType == ICElement.C_NAMESPACE
|
||||
|| fElementType == ICElement.C_CLASS
|
||||
|| fElementType == ICElement.C_STRUCT);
|
||||
}
|
||||
|
||||
public boolean encloses(ITypeInfo info) {
|
||||
if (isEnclosingType() && fTypeCache == info.getCache()) {
|
||||
return fQualifiedName.isPrefixOf(info.getQualifiedTypeName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnclosed(ITypeInfo info) {
|
||||
return info.encloses(this);
|
||||
}
|
||||
|
||||
public boolean hasEnclosedTypes() {
|
||||
if (isEnclosingType() && fTypeCache != null) {
|
||||
return fTypeCache.hasEnclosedTypes(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ITypeInfo[] getEnclosedTypes() {
|
||||
return getEnclosedTypes(KNOWN_TYPES);
|
||||
}
|
||||
|
||||
public ITypeInfo[] getEnclosedTypes(int kinds[]) {
|
||||
if (fTypeCache != null) {
|
||||
return fTypeCache.getEnclosedTypes(this, kinds);
|
||||
}
|
||||
return EMPTY_TYPES;
|
||||
}
|
||||
|
||||
public IProject getEnclosingProject() {
|
||||
if (fTypeCache != null) {
|
||||
return fTypeCache.getProject();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -141,20 +195,7 @@ public class TypeInfo implements ITypeInfo, Comparable
|
|||
if (!(obj instanceof TypeInfo)) {
|
||||
return false;
|
||||
}
|
||||
ITypeInfo info= (TypeInfo)obj;
|
||||
if (hashCode() != info.hashCode())
|
||||
return false;
|
||||
if (fElementType == info.getCElementType()
|
||||
&& fQualifiedName.equals(info.getQualifiedTypeName())) {
|
||||
IProject project1 = getEnclosingProject();
|
||||
IProject project2 = info.getEnclosingProject();
|
||||
if (project1 == null && project2 == null)
|
||||
return true;
|
||||
if (project1 == null || project2 == null)
|
||||
return false;
|
||||
return project1.equals(project2);
|
||||
}
|
||||
return false;
|
||||
return isExactMatch((TypeInfo)obj);
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
|
@ -171,17 +212,14 @@ public class TypeInfo implements ITypeInfo, Comparable
|
|||
}
|
||||
|
||||
public static boolean isValidType(int type) {
|
||||
switch (type) {
|
||||
case ICElement.C_NAMESPACE:
|
||||
case ICElement.C_CLASS:
|
||||
case ICElement.C_STRUCT:
|
||||
case ICElement.C_UNION:
|
||||
case ICElement.C_ENUMERATION:
|
||||
case ICElement.C_TYPEDEF:
|
||||
return true;
|
||||
return ArrayUtil.contains(KNOWN_TYPES, type);
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
public ITypeCache getCache() {
|
||||
return fTypeCache;
|
||||
}
|
||||
|
||||
public void setCache(ITypeCache typeCache) {
|
||||
fTypeCache = typeCache;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.browser;
|
||||
|
||||
public class UnknownTypeInfo extends TypeInfo {
|
||||
|
||||
public UnknownTypeInfo(IQualifiedTypeName typeName) {
|
||||
super(0, typeName);
|
||||
}
|
||||
|
||||
public boolean isUndefinedType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canSubstituteFor(ITypeInfo info) {
|
||||
if (fTypeCache == info.getCache()) {
|
||||
int compareType = info.getCElementType();
|
||||
if (fElementType == 0 || compareType == 0 || fElementType == compareType) {
|
||||
return fQualifiedName.equals(info.getQualifiedTypeName());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -100,6 +100,40 @@ public interface ITypeCache extends ISchedulingRule {
|
|||
*/
|
||||
public ITypeInfo getType(int type, IQualifiedTypeName qualifiedName);
|
||||
|
||||
/** Gets the first enclosing type which matches one of the given kinds.
|
||||
*
|
||||
* @param info the given type
|
||||
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS, C_STRUCT
|
||||
*
|
||||
* @return the enclosing type, or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeInfo getEnclosingType(ITypeInfo info, int[] kinds);
|
||||
|
||||
|
||||
/** Gets the root namespace of which encloses the given type.
|
||||
*
|
||||
* @param info the given type
|
||||
* @param includeGlobalNamespace <code>true</code> if the global (default) namespace should be returned
|
||||
* @return the enclosing namespace, or <code>null</code> if not found.
|
||||
*/
|
||||
public ITypeInfo getRootNamespace(ITypeInfo info, boolean includeGlobalNamespace);
|
||||
|
||||
/** Returns whether any types are enclosed by the given type.
|
||||
*
|
||||
* @param info the given type
|
||||
* @return <code>true</code> if the given type encloses other types.
|
||||
*/
|
||||
public boolean hasEnclosedTypes(ITypeInfo info);
|
||||
|
||||
/** Gets the types which are enclosed by the given type.
|
||||
*
|
||||
* @param info the given type
|
||||
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS,
|
||||
* C_UNION, C_ENUMERATION, C_TYPEDEF
|
||||
* @return the enclosed types, or an empty array if not found.
|
||||
*/
|
||||
public ITypeInfo[] getEnclosedTypes(ITypeInfo info, int kinds[]);
|
||||
|
||||
/** Returns the project associated with this cache.
|
||||
*
|
||||
* @return the project
|
||||
|
@ -120,4 +154,5 @@ public interface ITypeCache extends ISchedulingRule {
|
|||
public void locateType(ITypeInfo info, int priority, int delay);
|
||||
public ITypeReference locateTypeAndWait(ITypeInfo info, int priority, IProgressMonitor monitor);
|
||||
|
||||
public ITypeInfo getGlobalNamespace();
|
||||
}
|
||||
|
|
|
@ -148,12 +148,10 @@ public class IndexerTypesJob extends IndexerJob {
|
|||
if (info == null || info.isUndefinedType()) {
|
||||
int[] references = entry.getFileReferences();
|
||||
if (references != null && references.length > 0) {
|
||||
if (info == null) {
|
||||
info = new TypeInfo(type, qualifiedName, fTypeCache);
|
||||
// add new type to cache
|
||||
info = new TypeInfo(type, qualifiedName);
|
||||
fTypeCache.insert(info);
|
||||
} else {
|
||||
info.setCElementType(type);
|
||||
}
|
||||
|
||||
for (int i = 0; i < references.length; ++i) {
|
||||
if (monitor.isCanceled())
|
||||
throw new InterruptedException();
|
||||
|
|
|
@ -24,8 +24,11 @@ import org.eclipse.cdt.core.browser.ITypeInfoVisitor;
|
|||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.browser.ITypeSearchScope;
|
||||
import org.eclipse.cdt.core.browser.IWorkingCopyProvider;
|
||||
import org.eclipse.cdt.core.browser.QualifiedTypeName;
|
||||
import org.eclipse.cdt.core.browser.TypeInfo;
|
||||
import org.eclipse.cdt.core.browser.TypeSearchScope;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.core.browser.util.ArrayUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -45,6 +48,7 @@ public class TypeCache implements ITypeCache {
|
|||
private final IProject fProject;
|
||||
private final IWorkingCopyProvider fWorkingCopyProvider;
|
||||
private final Collection fDeltas = new ArrayList();
|
||||
private final ITypeInfo fGlobalNamespace;
|
||||
|
||||
private IJobChangeListener fJobChangeListener = new IJobChangeListener() {
|
||||
public void aboutToRun(IJobChangeEvent event) {
|
||||
|
@ -87,10 +91,128 @@ public class TypeCache implements ITypeCache {
|
|||
}
|
||||
};
|
||||
|
||||
private static class GlobalNamespace implements IQualifiedTypeName {
|
||||
|
||||
private static final String GLOBAL_NAMESPACE = TypeCacheMessages.getString("TypeCache.globalNamespace"); //$NON-NLS-1$
|
||||
|
||||
public GlobalNamespace() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return GLOBAL_NAMESPACE;
|
||||
}
|
||||
|
||||
public String[] getEnclosingNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFullyQualifiedName() {
|
||||
return GLOBAL_NAMESPACE;
|
||||
}
|
||||
|
||||
public IQualifiedTypeName getEnclosingTypeName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int segmentCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String[] segments() {
|
||||
return new String[] { GLOBAL_NAMESPACE };
|
||||
}
|
||||
|
||||
public String segment(int index) {
|
||||
if (index > 0)
|
||||
return null;
|
||||
return GLOBAL_NAMESPACE;
|
||||
}
|
||||
|
||||
public String lastSegment() {
|
||||
return GLOBAL_NAMESPACE;
|
||||
}
|
||||
|
||||
public int matchingFirstSegments(IQualifiedTypeName typeName) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isPrefixOf(IQualifiedTypeName typeName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public IQualifiedTypeName append(String[] names) {
|
||||
return new QualifiedTypeName(names);
|
||||
}
|
||||
|
||||
public IQualifiedTypeName append(IQualifiedTypeName typeName) {
|
||||
return new QualifiedTypeName(typeName);
|
||||
}
|
||||
|
||||
public IQualifiedTypeName append(String qualifiedName) {
|
||||
return new QualifiedTypeName(qualifiedName);
|
||||
}
|
||||
|
||||
public IQualifiedTypeName removeFirstSegments(int count) {
|
||||
return new QualifiedTypeName(this);
|
||||
}
|
||||
|
||||
public IQualifiedTypeName removeLastSegments(int count) {
|
||||
return new QualifiedTypeName(this);
|
||||
}
|
||||
|
||||
public boolean isLowLevel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean validate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return GLOBAL_NAMESPACE.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getFullyQualifiedName();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof IQualifiedTypeName)) {
|
||||
return false;
|
||||
}
|
||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
||||
return (typeName instanceof GlobalNamespace);
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
if (obj == this) {
|
||||
return 0;
|
||||
}
|
||||
if (!(obj instanceof IQualifiedTypeName)) {
|
||||
throw new ClassCastException();
|
||||
}
|
||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
||||
return getFullyQualifiedName().compareTo(typeName.getFullyQualifiedName());
|
||||
}
|
||||
}
|
||||
|
||||
public TypeCache(IProject project, IWorkingCopyProvider workingCopyProvider) {
|
||||
fProject = project;
|
||||
fWorkingCopyProvider = workingCopyProvider;
|
||||
fDeltas.add(new TypeCacheDelta(fProject));
|
||||
fGlobalNamespace = new TypeInfo(ICElement.C_NAMESPACE, new GlobalNamespace());
|
||||
fGlobalNamespace.setCache(this);
|
||||
}
|
||||
|
||||
public boolean contains(ISchedulingRule rule) {
|
||||
|
@ -121,20 +243,38 @@ public class TypeCache implements ITypeCache {
|
|||
return fTypeNameMap.isEmpty();
|
||||
}
|
||||
|
||||
public synchronized void insert(ITypeInfo info) {
|
||||
// check if enclosing types are already in cache
|
||||
IQualifiedTypeName typeName = info.getQualifiedTypeName().getEnclosingTypeName();
|
||||
if (typeName != null) {
|
||||
while (!typeName.isEmpty()) {
|
||||
boolean foundType = false;
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(typeName.getName());
|
||||
if (typeCollection == null) {
|
||||
typeCollection = new HashSet();
|
||||
fTypeNameMap.put(typeName.getName(), typeCollection);
|
||||
} else {
|
||||
public synchronized void insert(ITypeInfo newType) {
|
||||
// check if type already exists
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(newType.getName());
|
||||
if (typeCollection != null) {
|
||||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo currType = (ITypeInfo) typeIter.next();
|
||||
if (currType.canSubstituteFor(newType)) {
|
||||
// merge references into new type
|
||||
ITypeReference[] refs = currType.getReferences();
|
||||
for (int i = 0; i < refs.length; ++i) {
|
||||
newType.addReference(refs[i]);
|
||||
}
|
||||
// remove the old type
|
||||
currType.setCache(null);
|
||||
typeIter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if enclosing types are already in cache
|
||||
IQualifiedTypeName enclosingName = newType.getQualifiedTypeName().getEnclosingTypeName();
|
||||
if (enclosingName != null) {
|
||||
while (!enclosingName.isEmpty()) {
|
||||
boolean foundType = false;
|
||||
Collection enclosingCollection = (Collection) fTypeNameMap.get(enclosingName.getName());
|
||||
if (enclosingCollection == null) {
|
||||
enclosingCollection = new HashSet();
|
||||
fTypeNameMap.put(enclosingName.getName(), enclosingCollection);
|
||||
} else {
|
||||
for (Iterator typeIter = enclosingCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo curr = (ITypeInfo) typeIter.next();
|
||||
if (curr.getQualifiedTypeName().equals(typeName)) {
|
||||
if (curr.getQualifiedTypeName().equals(enclosingName)) {
|
||||
foundType = true;
|
||||
break;
|
||||
}
|
||||
|
@ -142,24 +282,27 @@ public class TypeCache implements ITypeCache {
|
|||
}
|
||||
if (!foundType) {
|
||||
// create a dummy type to take this place (type 0 == unknown)
|
||||
ITypeInfo dummyType = new TypeInfo(0, typeName, this);
|
||||
typeCollection.add(dummyType);
|
||||
ITypeInfo dummyType = new TypeInfo(0, enclosingName);
|
||||
enclosingCollection.add(dummyType);
|
||||
dummyType.setCache(this);
|
||||
}
|
||||
typeName = typeName.removeLastSegments(1);
|
||||
enclosingName = enclosingName.removeLastSegments(1);
|
||||
}
|
||||
}
|
||||
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(info.getName());
|
||||
typeCollection = (Collection) fTypeNameMap.get(newType.getName());
|
||||
if (typeCollection == null) {
|
||||
typeCollection = new HashSet();
|
||||
fTypeNameMap.put(info.getName(), typeCollection);
|
||||
fTypeNameMap.put(newType.getName(), typeCollection);
|
||||
}
|
||||
typeCollection.add(info);
|
||||
typeCollection.add(newType);
|
||||
newType.setCache(this);
|
||||
}
|
||||
|
||||
public synchronized void remove(ITypeInfo info) {
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(info.getName());
|
||||
if (typeCollection != null) {
|
||||
info.setCache(null);
|
||||
typeCollection.remove(info);
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +317,7 @@ public class TypeCache implements ITypeCache {
|
|||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo info = (ITypeInfo) typeIter.next();
|
||||
if (info.isEnclosed(scope)) {
|
||||
info.setCache(null);
|
||||
typeIter.remove();
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +335,13 @@ public class TypeCache implements ITypeCache {
|
|||
|
||||
public synchronized void flushAll() {
|
||||
// flush the entire cache
|
||||
accept(new ITypeInfoVisitor() {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
info.setCache(null);
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
});
|
||||
fTypeNameMap.clear();
|
||||
}
|
||||
|
||||
|
@ -200,40 +351,44 @@ public class TypeCache implements ITypeCache {
|
|||
Collection typeCollection = (Collection) entry.getValue();
|
||||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo info = (ITypeInfo) typeIter.next();
|
||||
if (!visitor.shouldContinue())
|
||||
return; // stop visiting
|
||||
visitor.visit(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized IPath[] getPaths(ITypeSearchScope scope) {
|
||||
final Set fPathSet = new HashSet();
|
||||
final ITypeSearchScope fScope = scope;
|
||||
public synchronized IPath[] getPaths(final ITypeSearchScope scope) {
|
||||
final Set pathSet = new HashSet();
|
||||
accept(new ITypeInfoVisitor() {
|
||||
public void visit(ITypeInfo info) {
|
||||
if (fScope == null || info.isEnclosed(fScope)) {
|
||||
public boolean visit(ITypeInfo info) {
|
||||
if (scope == null || info.isEnclosed(scope)) {
|
||||
ITypeReference[] refs = info.getReferences();
|
||||
for (int i = 0; i < refs.length; ++i) {
|
||||
IPath path = refs[i].getPath();
|
||||
if (fScope == null || fScope.encloses(path))
|
||||
fPathSet.add(path);
|
||||
if (scope == null || scope.encloses(path))
|
||||
pathSet.add(path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
});
|
||||
return (IPath[]) fPathSet.toArray(new IPath[fPathSet.size()]);
|
||||
return (IPath[]) pathSet.toArray(new IPath[pathSet.size()]);
|
||||
}
|
||||
|
||||
public synchronized ITypeInfo[] getTypes(ITypeSearchScope scope) {
|
||||
final Collection fTypesFound = new ArrayList();
|
||||
final ITypeSearchScope fScope = scope;
|
||||
public synchronized ITypeInfo[] getTypes(final ITypeSearchScope scope) {
|
||||
final Collection results = new ArrayList();
|
||||
accept(new ITypeInfoVisitor() {
|
||||
public void visit(ITypeInfo info) {
|
||||
if (fScope == null || info.isEnclosed(fScope)) {
|
||||
fTypesFound.add(info);
|
||||
public boolean visit(ITypeInfo info) {
|
||||
if (scope == null || info.isEnclosed(scope)) {
|
||||
results.add(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
});
|
||||
return (ITypeInfo[]) fTypesFound.toArray(new ITypeInfo[fTypesFound.size()]);
|
||||
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
||||
}
|
||||
|
||||
public synchronized ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName) {
|
||||
|
@ -255,8 +410,8 @@ public class TypeCache implements ITypeCache {
|
|||
if (typeCollection != null) {
|
||||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo info = (ITypeInfo) typeIter.next();
|
||||
if (info.getQualifiedTypeName().equals(qualifiedName)
|
||||
&& (info.getCElementType() == type || info.getCElementType() == 0)) {
|
||||
if ((info.getCElementType() == type || info.getCElementType() == 0)
|
||||
&& info.getQualifiedTypeName().equals(qualifiedName)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
@ -264,6 +419,104 @@ public class TypeCache implements ITypeCache {
|
|||
return null;
|
||||
}
|
||||
|
||||
public synchronized ITypeInfo getEnclosingType(ITypeInfo info, final int[] kinds) {
|
||||
IQualifiedTypeName enclosingName = info.getQualifiedTypeName().getEnclosingTypeName();
|
||||
if (enclosingName != null) {
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(enclosingName.getName());
|
||||
if (typeCollection != null) {
|
||||
// try namespace, class, struct, then undefined
|
||||
final int[] validKinds = {ICElement.C_NAMESPACE, ICElement.C_CLASS, ICElement.C_STRUCT, 0};
|
||||
for (int i = 0; i < validKinds.length; ++i) {
|
||||
if (ArrayUtil.contains(kinds, validKinds[i])) {
|
||||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo type = (ITypeInfo) typeIter.next();
|
||||
if (type.getCElementType() == validKinds[i]
|
||||
&& type.getQualifiedTypeName().equals(enclosingName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized ITypeInfo getRootNamespace(ITypeInfo info, boolean includeGlobalNamespace) {
|
||||
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
|
||||
if (qualifiedName.isGlobal()) {
|
||||
if (info.getCElementType() == ICElement.C_NAMESPACE)
|
||||
return info;
|
||||
if (includeGlobalNamespace)
|
||||
return fGlobalNamespace;
|
||||
return null;
|
||||
}
|
||||
String[] segments = qualifiedName.segments();
|
||||
String namespace = segments[0];
|
||||
Collection typeCollection = (Collection) fTypeNameMap.get(namespace);
|
||||
if (typeCollection != null) {
|
||||
// try namespace, then undefined
|
||||
final int[] kinds = {ICElement.C_NAMESPACE, 0};
|
||||
for (int i = 0; i < kinds.length; ++i) {
|
||||
for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
|
||||
ITypeInfo type = (ITypeInfo) typeIter.next();
|
||||
if (type.getCElementType() == kinds[i]
|
||||
&& type.getQualifiedTypeName().isGlobal()) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized boolean hasEnclosedTypes(final ITypeInfo info) {
|
||||
final IQualifiedTypeName parentName = info.getQualifiedTypeName();
|
||||
final boolean[] foundTypes = { false };
|
||||
accept(new ITypeInfoVisitor() {
|
||||
public boolean visit(ITypeInfo type) {
|
||||
if (type != info && parentName.isPrefixOf(type.getQualifiedTypeName())) {
|
||||
foundTypes[0] = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() {
|
||||
return !foundTypes[0];
|
||||
}
|
||||
});
|
||||
return foundTypes[0];
|
||||
}
|
||||
|
||||
public synchronized ITypeInfo[] getEnclosedTypes(final ITypeInfo enclosedBy, final int kinds[]) {
|
||||
final IQualifiedTypeName parentName = enclosedBy.getQualifiedTypeName();
|
||||
final Collection results = new ArrayList();
|
||||
accept(new ITypeInfoVisitor() {
|
||||
public boolean visit(ITypeInfo type) {
|
||||
if (ArrayUtil.contains(kinds, type.getCElementType())) {
|
||||
IQualifiedTypeName enclosingName = type.getQualifiedTypeName().getEnclosingTypeName();
|
||||
if (enclosedBy == fGlobalNamespace) {
|
||||
if (enclosingName == null) {
|
||||
results.add(type);
|
||||
} else {
|
||||
// // check if enclosing parent is namespace
|
||||
// getRootNamespace(type);
|
||||
}
|
||||
} else if (parentName.equals(enclosingName)) {
|
||||
results.add(type);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldContinue() { return true; }
|
||||
});
|
||||
|
||||
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
||||
}
|
||||
|
||||
public ITypeInfo getGlobalNamespace() {
|
||||
return fGlobalNamespace;
|
||||
}
|
||||
|
||||
public boolean isUpToDate() {
|
||||
synchronized(fDeltas) {
|
||||
return fDeltas.isEmpty();
|
||||
|
|
|
@ -17,3 +17,5 @@ TypeCacherJob.taskName=Updating Type Cache...
|
|||
|
||||
TypeLocatorJob.jobName=Type Locator
|
||||
TypeLocatorJob.taskName=Searching for Type Declaration...
|
||||
|
||||
TypeCache.globalNamespace=(global)
|
||||
|
|
|
@ -186,6 +186,9 @@ public class TypeParser implements ISourceElementRequestor {
|
|||
|
||||
fScope = new TypeSearchScope();
|
||||
ITypeReference[] refs = info.getReferences();
|
||||
if (refs == null || refs.length == 0)
|
||||
return false; // no source references
|
||||
|
||||
fScope.add(refs[0].getPath(), false, null);
|
||||
// for (int i = 0; i < refs.length; ++i) {
|
||||
// ITypeReference location = refs[i];
|
||||
|
@ -420,15 +423,13 @@ public class TypeParser implements ISourceElementRequestor {
|
|||
IParser parser = ParserFactory.createParser(scanner, this, ParserMode.STRUCTURAL_PARSE, language, ParserUtil.getParserLogService());
|
||||
parser.parse();
|
||||
} catch (ParserFactoryError e) {
|
||||
e.printStackTrace();
|
||||
CCorePlugin.log(e);
|
||||
} catch (ParseError e) {
|
||||
e.printStackTrace();
|
||||
CCorePlugin.log(e);
|
||||
} catch (OperationCanceledException e) {
|
||||
throw new InterruptedException();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (VirtualMachineError e) {
|
||||
e.printStackTrace();
|
||||
CCorePlugin.log(e);
|
||||
} finally {
|
||||
fProgressMonitor = null;
|
||||
}
|
||||
|
@ -671,12 +672,9 @@ public class TypeParser implements ISourceElementRequestor {
|
|||
QualifiedTypeName qualifiedName = new QualifiedTypeName(name, enclosingNames);
|
||||
ITypeInfo info = fTypeCache.getType(type, qualifiedName);
|
||||
if (info == null || info.isUndefinedType()) {
|
||||
if (info == null) {
|
||||
info = new TypeInfo(type, qualifiedName, fTypeCache);
|
||||
// add new type to cache
|
||||
info = new TypeInfo(type, qualifiedName);
|
||||
fTypeCache.insert(info);
|
||||
} else {
|
||||
info.setCElementType(type);
|
||||
}
|
||||
|
||||
TypeReference location;
|
||||
if (originalRef instanceof IWorkingCopy) {
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2004-05-26 Alain Magloire
|
||||
|
||||
Jumbo Patch from Chris Wiebe.
|
||||
Putting a starting skeleton for C Browsing.
|
||||
|
||||
2004-05-26 Alain Magloire
|
||||
|
||||
PR 61965
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.search.CElementLabels;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
|
||||
|
||||
/**
|
||||
* JavaUILabelProvider that respects settings from the Appearance preference page.
|
||||
* Triggers a viewer update when a preference changes.
|
||||
*/
|
||||
public class AppearanceAwareLabelProvider extends CUILabelProvider implements IPropertyChangeListener {
|
||||
|
||||
public final static int DEFAULT_TEXTFLAGS= CElementLabels.ROOT_VARIABLE | CElementLabels.M_PARAMETER_TYPES |
|
||||
CElementLabels.M_APP_RETURNTYPE | CElementLabels.REFERENCED_ROOT_POST_QUALIFIED;
|
||||
public final static int DEFAULT_IMAGEFLAGS= CElementImageProvider.OVERLAY_ICONS;
|
||||
|
||||
private int fTextFlagMask;
|
||||
private int fImageFlagMask;
|
||||
|
||||
/**
|
||||
* Constructor for AppearanceAwareLabelProvider.
|
||||
*/
|
||||
public AppearanceAwareLabelProvider(int textFlags, int imageFlags) {
|
||||
super(textFlags, imageFlags);
|
||||
initMasks();
|
||||
PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a labelProvider with DEFAULT_TEXTFLAGS and DEFAULT_IMAGEFLAGS
|
||||
*/
|
||||
public AppearanceAwareLabelProvider() {
|
||||
this(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS);
|
||||
}
|
||||
|
||||
private void initMasks() {
|
||||
IPreferenceStore store= PreferenceConstants.getPreferenceStore();
|
||||
fTextFlagMask= -1;
|
||||
// if (!store.getBoolean(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE)) {
|
||||
// fTextFlagMask ^= CElementLabels.M_APP_RETURNTYPE;
|
||||
// }
|
||||
// if (!store.getBoolean(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) {
|
||||
// fTextFlagMask ^= CElementLabels.P_COMPRESSED;
|
||||
// }
|
||||
|
||||
fImageFlagMask= -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
String property= event.getProperty();
|
||||
// if (property.equals(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE)
|
||||
// || property.equals(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW)
|
||||
// || property.equals(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) {
|
||||
// initMasks();
|
||||
// LabelProviderChangedEvent lpEvent= new LabelProviderChangedEvent(this, null); // refresh all
|
||||
// fireLabelProviderChanged(lpEvent);
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see JavaUILabelProvider#evaluateImageFlags()
|
||||
*/
|
||||
protected int evaluateImageFlags(Object element) {
|
||||
return getImageFlags() & fImageFlagMask;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see JavaUILabelProvider#evaluateTextFlags()
|
||||
*/
|
||||
protected int evaluateTextFlags(Object element) {
|
||||
return getTextFlags() & fTextFlagMask;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
public abstract class CBrowsingContentProvider implements ITreeContentProvider, IElementChangedListener {
|
||||
|
||||
protected StructuredViewer fViewer;
|
||||
protected Object fInput;
|
||||
protected CBrowsingPart fBrowsingPart;
|
||||
protected int fReadsInDisplayThread;
|
||||
protected static final Object[] NO_CHILDREN = new Object[0];
|
||||
|
||||
public CBrowsingContentProvider(CBrowsingPart browsingPart) {
|
||||
fBrowsingPart= browsingPart;
|
||||
fViewer= fBrowsingPart.getViewer();
|
||||
CoreModel.getDefault().addElementChangedListener(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (newInput instanceof Collection) {
|
||||
// Get a template object from the collection
|
||||
Collection col = (Collection) newInput;
|
||||
if (!col.isEmpty())
|
||||
newInput = col.iterator().next();
|
||||
else
|
||||
newInput = null;
|
||||
}
|
||||
fInput = newInput;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
CoreModel.getDefault().removeElementChangedListener(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent)
|
||||
*/
|
||||
public void elementChanged(ElementChangedEvent event) {
|
||||
// TODO listen for cache updates
|
||||
// try {
|
||||
// processDelta(event.getDelta());
|
||||
// } catch(CModelException e) {
|
||||
// CUIPlugin.getDefault().log(e.getStatus());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
protected void startReadInDisplayThread() {
|
||||
if (isDisplayThread())
|
||||
fReadsInDisplayThread++;
|
||||
}
|
||||
|
||||
protected void finishedReadInDisplayThread() {
|
||||
if (isDisplayThread())
|
||||
fReadsInDisplayThread--;
|
||||
}
|
||||
|
||||
private boolean isDisplayThread() {
|
||||
Control ctrl= fViewer.getControl();
|
||||
if (ctrl == null)
|
||||
return false;
|
||||
|
||||
Display currentDisplay= Display.getCurrent();
|
||||
return currentDisplay != null && currentDisplay.equals(ctrl.getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is for internal use only. Clients should not call this method.
|
||||
*/
|
||||
protected static Object[] concatenate(Object[] a1, Object[] a2) {
|
||||
int a1Len = a1.length;
|
||||
int a2Len = a2.length;
|
||||
Object[] res = new Object[a1Len + a2Len];
|
||||
System.arraycopy(a1, 0, res, 0, a1Len);
|
||||
System.arraycopy(a2, 0, res, a1Len, a2Len);
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class CBrowsingMessages {
|
||||
|
||||
private static final String RESOURCE_BUNDLE= CBrowsingMessages.class.getName();
|
||||
|
||||
private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
||||
|
||||
private CBrowsingMessages() {
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return fgResourceBundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with the argument
|
||||
*
|
||||
* @param key the string used to get the bundle value, must not be null
|
||||
*/
|
||||
public static String getFormattedString(String key, Object[] args) {
|
||||
String format= null;
|
||||
try {
|
||||
format= fgResourceBundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
||||
}
|
||||
return MessageFormat.format(format, args);
|
||||
}
|
||||
}
|
|
@ -23,3 +23,6 @@ ClassesView.LayoutActionGroup.layout.label= &Layout
|
|||
|
||||
# the first argument is the string to which the second one is appended
|
||||
StatusBar.concat= {0}, {1}
|
||||
|
||||
ClassPathContainer.unbound_label={0} (unbound)
|
||||
ClassPathContainer.unknown_label={0} (unknown)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,212 @@
|
|||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.search.ui.SearchUI;
|
||||
import org.eclipse.ui.IFolderLayout;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.IPerspectiveFactory;
|
||||
import org.eclipse.ui.IPlaceholderFolderLayout;
|
||||
import org.eclipse.ui.console.IConsoleConstants;
|
||||
|
||||
public class CBrowsingPerspectiveFactory implements IPerspectiveFactory {
|
||||
|
||||
/*
|
||||
* XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070
|
||||
*/
|
||||
static ICElement fgCElementFromAction;
|
||||
|
||||
/**
|
||||
* Constructs a new Default layout engine.
|
||||
*/
|
||||
public CBrowsingPerspectiveFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IPerspectiveFactory#createInitialLayout
|
||||
*/
|
||||
public void createCViewInitialLayout(IPageLayout layout) {
|
||||
String editorArea = layout.getEditorArea();
|
||||
|
||||
IFolderLayout folder1= layout.createFolder("topLeft", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$
|
||||
folder1.addView(CUIPlugin.CVIEW_ID);
|
||||
folder1.addView(IPageLayout.ID_RES_NAV);
|
||||
folder1.addPlaceholder(IPageLayout.ID_BOOKMARKS);
|
||||
|
||||
IFolderLayout folder2= layout.createFolder("bottom", IPageLayout.BOTTOM, (float)0.75, editorArea); //$NON-NLS-1$
|
||||
folder2.addView(IPageLayout.ID_PROBLEM_VIEW);
|
||||
folder2.addView(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
folder2.addView(IPageLayout.ID_PROP_SHEET);
|
||||
|
||||
IFolderLayout folder3= layout.createFolder("topRight", IPageLayout.RIGHT,(float)0.75, editorArea); //$NON-NLS-1$
|
||||
folder3.addView(IPageLayout.ID_OUTLINE);
|
||||
|
||||
layout.addActionSet(CUIPlugin.SEARCH_ACTION_SET_ID);
|
||||
layout.addActionSet(CUIPlugin.FOLDER_ACTION_SET_ID);
|
||||
|
||||
// views - build console
|
||||
layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
|
||||
// views - searching
|
||||
layout.addShowViewShortcut(SearchUI.SEARCH_RESULT_VIEW_ID);
|
||||
|
||||
// views - standard workbench
|
||||
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
|
||||
layout.addShowViewShortcut(CUIPlugin.CVIEW_ID);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_PROP_SHEET);
|
||||
|
||||
// link - things we should do
|
||||
layout.addShowInPart(CUIPlugin.CVIEW_ID);
|
||||
layout.addShowInPart(IPageLayout.ID_RES_NAV);
|
||||
|
||||
// new actions - C project creation wizard
|
||||
layout.addNewWizardShortcut(CUIPlugin.CLASS_WIZARD_ID);
|
||||
layout.addNewWizardShortcut(CUIPlugin.FILE_WIZARD_ID);
|
||||
layout.addNewWizardShortcut(CUIPlugin.FOLDER_WIZARD_ID);
|
||||
}
|
||||
|
||||
public void createInitialLayout(IPageLayout layout) {
|
||||
if (stackBrowsingViewsVertically())
|
||||
createVerticalLayout(layout);
|
||||
else
|
||||
createHorizontalLayout(layout);
|
||||
|
||||
// action sets
|
||||
layout.addActionSet(CUIPlugin.SEARCH_ACTION_SET_ID);
|
||||
layout.addActionSet(CUIPlugin.FOLDER_ACTION_SET_ID);
|
||||
// layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET);
|
||||
// layout.addActionSet(JavaUI.ID_ACTION_SET);
|
||||
// layout.addActionSet(JavaUI.ID_ELEMENT_CREATION_ACTION_SET);
|
||||
layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET);
|
||||
|
||||
// views - java
|
||||
// layout.addShowViewShortcut(CUIPlugin.ID_TYPE_HIERARCHY);
|
||||
layout.addShowViewShortcut(CUIPlugin.CVIEW_ID);
|
||||
layout.addShowViewShortcut(CUIPlugin.ID_PROJECTS_VIEW);
|
||||
layout.addShowViewShortcut(CUIPlugin.ID_NAMESPACES_VIEW);
|
||||
layout.addShowViewShortcut(CUIPlugin.ID_TYPES_VIEW);
|
||||
layout.addShowViewShortcut(CUIPlugin.ID_MEMBERS_VIEW);
|
||||
// layout.addShowViewShortcut(CUIPlugin.ID_SOURCE_VIEW);
|
||||
// layout.addShowViewShortcut(CUIPlugin.ID_JAVADOC_VIEW);
|
||||
|
||||
// views - search
|
||||
layout.addShowViewShortcut(SearchUI.SEARCH_RESULT_VIEW_ID);
|
||||
|
||||
// views - debugging
|
||||
layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
|
||||
// views - standard workbench
|
||||
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
|
||||
|
||||
// new actions - C project creation wizard
|
||||
layout.addNewWizardShortcut(CUIPlugin.CLASS_WIZARD_ID);
|
||||
layout.addNewWizardShortcut(CUIPlugin.FILE_WIZARD_ID);
|
||||
layout.addNewWizardShortcut(CUIPlugin.FOLDER_WIZARD_ID);
|
||||
}
|
||||
|
||||
private void createVerticalLayout(IPageLayout layout) {
|
||||
String relativePartId= IPageLayout.ID_EDITOR_AREA;
|
||||
int relativePos= IPageLayout.LEFT;
|
||||
|
||||
IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
|
||||
// placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY);
|
||||
placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE);
|
||||
placeHolderLeft.addPlaceholder(CUIPlugin.CVIEW_ID);
|
||||
placeHolderLeft.addPlaceholder(IPageLayout.ID_RES_NAV);
|
||||
|
||||
if (shouldShowProjectsView()) {
|
||||
layout.addView(CUIPlugin.ID_PROJECTS_VIEW, IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA);
|
||||
relativePartId= CUIPlugin.ID_PROJECTS_VIEW;
|
||||
relativePos= IPageLayout.BOTTOM;
|
||||
}
|
||||
if (shouldShowNamespacesView()) {
|
||||
layout.addView(CUIPlugin.ID_NAMESPACES_VIEW, relativePos, (float)0.25, relativePartId);
|
||||
relativePartId= CUIPlugin.ID_NAMESPACES_VIEW;
|
||||
relativePos= IPageLayout.BOTTOM;
|
||||
}
|
||||
layout.addView(CUIPlugin.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId);
|
||||
layout.addView(CUIPlugin.ID_MEMBERS_VIEW, IPageLayout.BOTTOM, (float)0.50, CUIPlugin.ID_TYPES_VIEW);
|
||||
|
||||
IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
|
||||
placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW);
|
||||
placeHolderBottom.addPlaceholder(SearchUI.SEARCH_RESULT_VIEW_ID);
|
||||
placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS);
|
||||
// placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW);
|
||||
// placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW);
|
||||
}
|
||||
|
||||
private void createHorizontalLayout(IPageLayout layout) {
|
||||
String relativePartId= IPageLayout.ID_EDITOR_AREA;
|
||||
int relativePos= IPageLayout.TOP;
|
||||
|
||||
if (shouldShowProjectsView()) {
|
||||
layout.addView(CUIPlugin.ID_PROJECTS_VIEW, IPageLayout.TOP, (float)0.25, IPageLayout.ID_EDITOR_AREA);
|
||||
relativePartId= CUIPlugin.ID_PROJECTS_VIEW;
|
||||
relativePos= IPageLayout.RIGHT;
|
||||
}
|
||||
if (shouldShowNamespacesView()) {
|
||||
layout.addView(CUIPlugin.ID_NAMESPACES_VIEW, relativePos, (float)0.25, relativePartId);
|
||||
relativePartId= CUIPlugin.ID_NAMESPACES_VIEW;
|
||||
relativePos= IPageLayout.RIGHT;
|
||||
}
|
||||
layout.addView(CUIPlugin.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId);
|
||||
layout.addView(CUIPlugin.ID_MEMBERS_VIEW, IPageLayout.RIGHT, (float)0.50, CUIPlugin.ID_TYPES_VIEW);
|
||||
|
||||
IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
|
||||
// placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY);
|
||||
placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE);
|
||||
placeHolderLeft.addPlaceholder(CUIPlugin.CVIEW_ID);
|
||||
placeHolderLeft.addPlaceholder(IPageLayout.ID_RES_NAV);
|
||||
|
||||
IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
|
||||
placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW);
|
||||
placeHolderBottom.addPlaceholder(SearchUI.SEARCH_RESULT_VIEW_ID);
|
||||
placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
|
||||
placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS);
|
||||
// placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW);
|
||||
// placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW);
|
||||
}
|
||||
|
||||
private boolean shouldShowProjectsView() {
|
||||
return true;
|
||||
// RETURN FGCELEMENTFROMACTION == NULL || FGCELEMENTFROMACTION.GETELEMENTTYPE() == ICELEMENT.C_MODEL;
|
||||
}
|
||||
|
||||
private boolean shouldShowNamespacesView() {
|
||||
return true;
|
||||
// if (fgCElementFromAction == null)
|
||||
// return true;
|
||||
// int type= fgCElementFromAction.getElementType();
|
||||
// return type == ICElement.C_MODEL || type == ICElement.C_PROJECT;
|
||||
//// return type == ICElement.C_MODEL || type == ICElement.C_PROJECT || type == ICElement.PACKAGE_FRAGMENT_ROOT;
|
||||
}
|
||||
|
||||
private boolean stackBrowsingViewsVertically() {
|
||||
return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.BROWSING_STACK_VERTICALLY);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070
|
||||
*/
|
||||
static void setInputFromAction(IAdaptable input) {
|
||||
if (input instanceof ICElement)
|
||||
fgCElementFromAction= (ICElement)input;
|
||||
else
|
||||
fgCElementFromAction= null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.search.CElementLabels;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
import org.eclipse.jface.viewers.IColorProvider;
|
||||
import org.eclipse.jface.viewers.ILabelDecorator;
|
||||
import org.eclipse.jface.viewers.ILabelProviderListener;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
|
||||
public class CUILabelProvider extends LabelProvider implements IColorProvider {
|
||||
|
||||
protected static final TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED);
|
||||
protected CElementImageProvider fImageLabelProvider;
|
||||
protected StorageLabelProvider fStorageLabelProvider;
|
||||
|
||||
private ArrayList fLabelDecorators;
|
||||
|
||||
private int fImageFlags;
|
||||
private int fTextFlags;
|
||||
|
||||
/**
|
||||
* Creates a new label provider with default flags.
|
||||
*/
|
||||
public CUILabelProvider() {
|
||||
this(CElementLabels.M_PARAMETER_TYPES, CElementImageProvider.OVERLAY_ICONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param textFlags Flags defined in <code>JavaElementLabels</code>.
|
||||
* @param imageFlags Flags defined in <code>JavaElementImageProvider</code>.
|
||||
*/
|
||||
public CUILabelProvider(int textFlags, int imageFlags) {
|
||||
fImageLabelProvider= new CElementImageProvider();
|
||||
fLabelDecorators= null;
|
||||
|
||||
fStorageLabelProvider= new StorageLabelProvider();
|
||||
fImageFlags= imageFlags;
|
||||
fTextFlags= textFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a decorator to the label provider
|
||||
*/
|
||||
public void addLabelDecorator(ILabelDecorator decorator) {
|
||||
if (fLabelDecorators == null) {
|
||||
fLabelDecorators= new ArrayList(2);
|
||||
}
|
||||
fLabelDecorators.add(decorator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the textFlags.
|
||||
* @param textFlags The textFlags to set
|
||||
*/
|
||||
public final void setTextFlags(int textFlags) {
|
||||
fTextFlags= textFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the imageFlags
|
||||
* @param imageFlags The imageFlags to set
|
||||
*/
|
||||
public final void setImageFlags(int imageFlags) {
|
||||
fImageFlags= imageFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image flags.
|
||||
* Can be overwriten by super classes.
|
||||
* @return Returns a int
|
||||
*/
|
||||
public final int getImageFlags() {
|
||||
return fImageFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text flags.
|
||||
* @return Returns a int
|
||||
*/
|
||||
public final int getTextFlags() {
|
||||
return fTextFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the image flags for a element.
|
||||
* Can be overwriten by super classes.
|
||||
* @return Returns a int
|
||||
*/
|
||||
protected int evaluateImageFlags(Object element) {
|
||||
return getImageFlags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the text flags for a element. Can be overwriten by super classes.
|
||||
* @return Returns a int
|
||||
*/
|
||||
protected int evaluateTextFlags(Object element) {
|
||||
return getTextFlags();
|
||||
}
|
||||
|
||||
protected Image decorateImage(Image image, Object element) {
|
||||
if (fLabelDecorators != null && image != null) {
|
||||
for (int i= 0; i < fLabelDecorators.size(); i++) {
|
||||
ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i);
|
||||
image= decorator.decorateImage(image, element);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelProvider#getImage
|
||||
*/
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof ITypeInfo)
|
||||
return fTypeInfoLabelProvider.getImage(element);
|
||||
|
||||
Image result= fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element));
|
||||
if (result == null && (element instanceof IStorage)) {
|
||||
result= fStorageLabelProvider.getImage(element);
|
||||
}
|
||||
|
||||
return decorateImage(result, element);
|
||||
}
|
||||
|
||||
protected String decorateText(String text, Object element) {
|
||||
if (fLabelDecorators != null && text.length() > 0) {
|
||||
for (int i= 0; i < fLabelDecorators.size(); i++) {
|
||||
ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i);
|
||||
text= decorator.decorateText(text, element);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelProvider#getText
|
||||
*/
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ITypeInfo)
|
||||
return fTypeInfoLabelProvider.getText(element);
|
||||
|
||||
String result= CElementLabels.getTextLabel(element, evaluateTextFlags(element));
|
||||
if (result.length() == 0 && (element instanceof IStorage)) {
|
||||
result= fStorageLabelProvider.getText(element);
|
||||
}
|
||||
|
||||
return decorateText(result, element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#dispose
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fLabelDecorators != null) {
|
||||
for (int i= 0; i < fLabelDecorators.size(); i++) {
|
||||
ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i);
|
||||
decorator.dispose();
|
||||
}
|
||||
fLabelDecorators= null;
|
||||
}
|
||||
fStorageLabelProvider.dispose();
|
||||
fImageLabelProvider.dispose();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
||||
*/
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
if (fLabelDecorators != null) {
|
||||
for (int i= 0; i < fLabelDecorators.size(); i++) {
|
||||
ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i);
|
||||
decorator.addListener(listener);
|
||||
}
|
||||
}
|
||||
super.addListener(listener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
||||
*/
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
if (fLabelDecorators != null) {
|
||||
for (int i= 0; i < fLabelDecorators.size(); i++) {
|
||||
ILabelDecorator decorator= (ILabelDecorator) fLabelDecorators.get(i);
|
||||
decorator.removeListener(listener);
|
||||
}
|
||||
}
|
||||
super.removeListener(listener);
|
||||
}
|
||||
|
||||
public static ILabelDecorator[] getDecorators(boolean errortick, ILabelDecorator extra) {
|
||||
if (errortick) {
|
||||
if (extra == null) {
|
||||
return new ILabelDecorator[] {};
|
||||
} else {
|
||||
return new ILabelDecorator[] { extra };
|
||||
}
|
||||
}
|
||||
if (extra != null) {
|
||||
return new ILabelDecorator[] { extra };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
|
||||
*/
|
||||
public Color getForeground(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
|
||||
*/
|
||||
public Color getBackground(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
|
||||
import org.eclipse.jface.viewers.DecoratingLabelProvider;
|
||||
import org.eclipse.jface.viewers.IColorProvider;
|
||||
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
public class DecoratingCLabelProvider extends DecoratingLabelProvider implements IColorProvider {
|
||||
|
||||
/**
|
||||
* Decorating label provider for Java. Combines a JavaUILabelProvider
|
||||
* with problem and override indicuator with the workbench decorator (label
|
||||
* decorator extension point).
|
||||
*/
|
||||
public DecoratingCLabelProvider(CUILabelProvider labelProvider) {
|
||||
this(labelProvider, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorating label provider for Java. Combines a JavaUILabelProvider
|
||||
* (if enabled with problem indicator) with the workbench
|
||||
* decorator (label decorator extension point).
|
||||
*/
|
||||
public DecoratingCLabelProvider(CUILabelProvider labelProvider, boolean errorTick) {
|
||||
super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
|
||||
if (errorTick) {
|
||||
labelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
|
||||
*/
|
||||
public Color getForeground(Object element) {
|
||||
// label provider is a JavaUILabelProvider
|
||||
return ((IColorProvider) getLabelProvider()).getForeground(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
|
||||
*/
|
||||
public Color getBackground(Object element) {
|
||||
// label provider is a JavaUILabelProvider
|
||||
return ((IColorProvider) getLabelProvider()).getBackground(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.IResourceChangeListener;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
|
||||
|
||||
public class FilterUpdater implements IResourceChangeListener {
|
||||
|
||||
private StructuredViewer fViewer;
|
||||
|
||||
public FilterUpdater(StructuredViewer viewer) {
|
||||
Assert.isNotNull(viewer);
|
||||
fViewer= viewer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
|
||||
*/
|
||||
public void resourceChanged(IResourceChangeEvent event) {
|
||||
IResourceDelta delta= event.getDelta();
|
||||
if (delta == null)
|
||||
return;
|
||||
|
||||
IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
|
||||
for (int i= 0; i < projDeltas.length; i++) {
|
||||
IResourceDelta pDelta= projDeltas[i];
|
||||
if ((pDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
|
||||
final Control ctrl= fViewer.getControl();
|
||||
if (ctrl != null && !ctrl.isDisposed()) {
|
||||
// async is needed due to bug 33783
|
||||
ctrl.getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
if (!ctrl.isDisposed())
|
||||
fViewer.refresh(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.swt.custom.BusyIndicator;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
|
||||
/*
|
||||
* XXX: This class should become part of the MemberFilterActionGroup
|
||||
* which should be renamed to MemberActionsGroup
|
||||
*/
|
||||
public class LexicalSortingAction extends Action {
|
||||
private TypeInfoSorter fSorter= new TypeInfoSorter();
|
||||
private StructuredViewer fViewer;
|
||||
private String fPreferenceKey;
|
||||
|
||||
public LexicalSortingAction(StructuredViewer viewer, String id) {
|
||||
super();
|
||||
fViewer= viewer;
|
||||
fPreferenceKey= "LexicalSortingAction." + id + ".isChecked"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
setText(CBrowsingMessages.getString("LexicalSortingAction.label")); //$NON-NLS-1$
|
||||
CPluginImages.setImageDescriptors(this, "T_LCL", CPluginImages.IMG_ALPHA_SORTING); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
setToolTipText(CBrowsingMessages.getString("LexicalSortingAction.tooltip")); //$NON-NLS-1$
|
||||
setDescription(CBrowsingMessages.getString("LexicalSortingAction.description")); //$NON-NLS-1$
|
||||
boolean checked= CUIPlugin.getDefault().getPreferenceStore().getBoolean(fPreferenceKey); //$NON-NLS-1$
|
||||
valueChanged(checked, false);
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.LEXICAL_SORTING_BROWSING_ACTION);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
valueChanged(isChecked(), true);
|
||||
}
|
||||
|
||||
private void valueChanged(final boolean on, boolean store) {
|
||||
setChecked(on);
|
||||
BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() {
|
||||
public void run() {
|
||||
if (on)
|
||||
fViewer.setSorter(fSorter);
|
||||
else
|
||||
fViewer.setSorter(null);
|
||||
}
|
||||
});
|
||||
|
||||
if (store)
|
||||
CUIPlugin.getDefault().getPreferenceStore().setValue(fPreferenceKey, on);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IMember;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.search.CElementLabels;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.part.IShowInTargetList;
|
||||
|
||||
public class MembersView extends CBrowsingPart implements IPropertyChangeListener {
|
||||
|
||||
// private MemberFilterActionGroup fMemberFilterActionGroup;
|
||||
|
||||
|
||||
public MembersView() {
|
||||
setHasWorkingSetFilter(false);
|
||||
setHasCustomSetFilter(true);
|
||||
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the property defined by key.
|
||||
*/
|
||||
public Object getAdapter(Class key) {
|
||||
if (key == IShowInTargetList.class) {
|
||||
return new IShowInTargetList() {
|
||||
public String[] getShowInTargetIds() {
|
||||
return new String[] { CUIPlugin.CVIEW_ID };
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
return super.getAdapter(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the label provider for this part.
|
||||
*
|
||||
* @return the label provider
|
||||
* @see org.eclipse.jface.viewers.ILabelProvider
|
||||
*/
|
||||
protected LabelProvider createLabelProvider() {
|
||||
return new AppearanceAwareLabelProvider(
|
||||
AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementLabels.F_APP_TYPE_SIGNATURE,
|
||||
AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context ID for the Help system
|
||||
*
|
||||
* @return the string used as ID for the Help context
|
||||
*/
|
||||
protected String getHelpContextId() {
|
||||
return ICHelpContextIds.MEMBERS_VIEW;
|
||||
}
|
||||
|
||||
protected String getLinkToEditorKey() {
|
||||
return PreferenceConstants.LINK_BROWSING_MEMBERS_TO_EDITOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the the viewer of this part.
|
||||
*
|
||||
* @param parent the parent for the viewer
|
||||
*/
|
||||
protected StructuredViewer createViewer(Composite parent) {
|
||||
ProblemTreeViewer viewer= new ProblemTreeViewer(parent, SWT.MULTI);
|
||||
// fMemberFilterActionGroup= new MemberFilterActionGroup(viewer, JavaUI.ID_MEMBERS_VIEW);
|
||||
return viewer;
|
||||
}
|
||||
|
||||
protected void fillToolBar(IToolBarManager tbm) {
|
||||
tbm.add(new LexicalSortingAction(getViewer(), CUIPlugin.ID_MEMBERS_VIEW));
|
||||
// fMemberFilterActionGroup.contributeToToolBar(tbm);
|
||||
super.fillToolBar(tbm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* input for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid input
|
||||
*/
|
||||
protected boolean isValidInput(Object element) {
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo type= (ITypeInfo)element;
|
||||
if (type.getCElementType() == ICElement.C_NAMESPACE && exists(type))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* element for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid element
|
||||
*/
|
||||
protected boolean isValidElement(Object element) {
|
||||
if (element instanceof ICElement) {
|
||||
if (element instanceof ICModel || element instanceof ICProject || element instanceof ISourceRoot)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implements method from IViewPart.
|
||||
*/
|
||||
public void saveState(IMemento memento) {
|
||||
super.saveState(memento);
|
||||
// fMemberFilterActionGroup.saveState(memento);
|
||||
}
|
||||
|
||||
protected void restoreState(IMemento memento) {
|
||||
super.restoreState(memento);
|
||||
// fMemberFilterActionGroup.restoreState(memento);
|
||||
getViewer().getControl().setRedraw(false);
|
||||
getViewer().refresh();
|
||||
getViewer().getControl().setRedraw(true);
|
||||
}
|
||||
|
||||
protected void hookViewerListeners() {
|
||||
super.hookViewerListeners();
|
||||
getViewer().addDoubleClickListener(new IDoubleClickListener() {
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
TreeViewer viewer= (TreeViewer)getViewer();
|
||||
Object element= ((IStructuredSelection)event.getSelection()).getFirstElement();
|
||||
if (viewer.isExpandable(element))
|
||||
viewer.setExpandedState(element, !viewer.getExpandedState(element));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean isInputAWorkingCopy() {
|
||||
Object input= getViewer().getInput();
|
||||
// if (input instanceof ICElement) {
|
||||
// ICompilationUnit cu= (ICompilationUnit)((IJavaElement)input).getAncestor(IJavaElement.COMPILATION_UNIT);
|
||||
// if (cu != null)
|
||||
// return cu.isWorkingCopy();
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void restoreSelection() {
|
||||
IEditorPart editor= getViewSite().getPage().getActiveEditor();
|
||||
if (editor != null)
|
||||
setSelectionFromEditor(editor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
// if (MembersOrderPreferenceCache.isMemberOrderProperty(event.getProperty())) {
|
||||
// getViewer().refresh();
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
// if (fMemberFilterActionGroup != null) {
|
||||
// fMemberFilterActionGroup.dispose();
|
||||
// fMemberFilterActionGroup= null;
|
||||
// }
|
||||
super.dispose();
|
||||
CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#createContentProvider()
|
||||
*/
|
||||
protected IContentProvider createContentProvider() {
|
||||
return new MembersViewContentProvider(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findInputForElement(java.lang.Object)
|
||||
*/
|
||||
protected Object findInputForElement(Object element) {
|
||||
return getMembersInput(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findElementToSelect(java.lang.Object)
|
||||
*/
|
||||
protected Object findElementToSelect(Object element) {
|
||||
if (element instanceof ICModel || element instanceof ICProject || element instanceof ISourceRoot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (element instanceof ICElement) {
|
||||
ICElement parent = (ICElement)element;
|
||||
while (parent != null) {
|
||||
if (parent instanceof IMember && exists(parent))
|
||||
return parent;
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.browser.AllTypesCache;
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableContext;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
class MembersViewContentProvider extends CBrowsingContentProvider {
|
||||
|
||||
MembersViewContentProvider(CBrowsingPart browsingPart) {
|
||||
super(browsingPart);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||
*/
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo) element;
|
||||
return (info.getCElementType() != ICElement.C_TYPEDEF);
|
||||
}
|
||||
|
||||
return false;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof IStructuredSelection) {
|
||||
Assert.isLegal(false);
|
||||
Object[] result= new Object[0];
|
||||
Class clazz= null;
|
||||
Iterator iter= ((IStructuredSelection)element).iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object item= iter.next();
|
||||
if (clazz == null)
|
||||
clazz= item.getClass();
|
||||
if (clazz == item.getClass())
|
||||
result= concatenate(result, getChildren(item));
|
||||
else
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo) element;
|
||||
if (info.getCElementType() == ICElement.C_NAMESPACE) {
|
||||
return NO_CHILDREN; // shouldn't get here...
|
||||
}
|
||||
ICElement elem = getCElement(info);
|
||||
if (elem != null && elem instanceof IParent) {
|
||||
return ((IParent)elem).getChildren();
|
||||
}
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
return NO_CHILDREN;
|
||||
} catch (CModelException e) {
|
||||
return NO_CHILDREN;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||
*/
|
||||
public Object getParent(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
if (info.isEnclosedType()) {
|
||||
return info.getEnclosingType();
|
||||
} else {
|
||||
// return info.getEnclosingProject();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
|
||||
private ICElement getCElement(ITypeInfo info) {
|
||||
ITypeReference location = info.getResolvedReference();
|
||||
if (location == null) {
|
||||
final ITypeInfo[] typesToResolve = new ITypeInfo[] { info };
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
AllTypesCache.resolveTypeLocation(typesToResolve[0], monitor);
|
||||
if (monitor.isCanceled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IRunnableContext runnableContext = new ProgressMonitorDialog(getShell());
|
||||
try {
|
||||
runnableContext.run(true, true, runnable);
|
||||
} catch (InvocationTargetException e) {
|
||||
String title = OpenTypeMessages.getString("OpenTypeAction.exception.title"); //$NON-NLS-1$
|
||||
String message = OpenTypeMessages.getString("OpenTypeAction.exception.message"); //$NON-NLS-1$
|
||||
ExceptionHandler.handle(e, title, message);
|
||||
return null;
|
||||
} catch (InterruptedException e) {
|
||||
// cancelled by user
|
||||
return null;
|
||||
}
|
||||
|
||||
location = info.getResolvedReference();
|
||||
}
|
||||
|
||||
ICElement elem = null;
|
||||
if (location != null)
|
||||
elem = location.getCElement();
|
||||
|
||||
if (elem == null) {
|
||||
// could not resolve location
|
||||
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$
|
||||
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorTypeNotFound", info.getQualifiedTypeName().toString()); //$NON-NLS-1$
|
||||
MessageDialog.openError(getShell(), title, message);
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
protected Shell getShell() {
|
||||
return CUIPlugin.getActiveWorkbenchShell();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTableViewer;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.part.IShowInTargetList;
|
||||
|
||||
public class NamespacesView extends CBrowsingPart {
|
||||
|
||||
// private SelectAllAction fSelectAllAction;
|
||||
|
||||
/**
|
||||
* Creates and returns the label provider for this part.
|
||||
*
|
||||
* @return the label provider
|
||||
* @see org.eclipse.jface.viewers.ILabelProvider
|
||||
*/
|
||||
protected LabelProvider createLabelProvider() {
|
||||
return new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the property defined by key.
|
||||
*/
|
||||
public Object getAdapter(Class key) {
|
||||
if (key == IShowInTargetList.class) {
|
||||
return new IShowInTargetList() {
|
||||
public String[] getShowInTargetIds() {
|
||||
return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_RES_NAV };
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
return super.getAdapter(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the viewer of this part dependent on the current
|
||||
* layout.
|
||||
*
|
||||
* @param parent the parent for the viewer
|
||||
*/
|
||||
protected StructuredViewer createViewer(Composite parent) {
|
||||
StructuredViewer viewer;
|
||||
// if(isInListState())
|
||||
viewer= createTableViewer(parent);
|
||||
// else
|
||||
// viewer= createTreeViewer(parent);
|
||||
|
||||
// fWrappedViewer.setViewer(viewer);
|
||||
// return fWrappedViewer;
|
||||
return viewer;
|
||||
}
|
||||
private ProblemTableViewer createTableViewer(Composite parent) {
|
||||
return new ProblemTableViewer(parent, SWT.MULTI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the the content provider of this part.
|
||||
*/
|
||||
protected IContentProvider createContentProvider() {
|
||||
return new NamespacesViewContentProvider(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds filters the viewer of this part.
|
||||
*/
|
||||
protected void addFilters() {
|
||||
super.addFilters();
|
||||
// getViewer().addFilter(new NonCElementFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* input for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid input
|
||||
*/
|
||||
protected boolean isValidInput(Object element) {
|
||||
return (element instanceof ICProject || element instanceof ISourceRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* element for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid element
|
||||
*/
|
||||
protected boolean isValidElement(Object element) {
|
||||
return isValidNamespace(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context ID for the Help system
|
||||
*
|
||||
* @return the string used as ID for the Help context
|
||||
*/
|
||||
protected String getHelpContextId() {
|
||||
return ICHelpContextIds.TYPES_VIEW;
|
||||
}
|
||||
|
||||
protected String getLinkToEditorKey() {
|
||||
return PreferenceConstants.LINK_BROWSING_TYPES_TO_EDITOR;
|
||||
}
|
||||
|
||||
protected void createActions() {
|
||||
super.createActions();
|
||||
// fSelectAllAction= new SelectAllAction((TableViewer)getViewer());
|
||||
}
|
||||
|
||||
protected void fillActionBars(IActionBars actionBars) {
|
||||
super.fillActionBars(actionBars);
|
||||
|
||||
// Add selectAll action handlers.
|
||||
// actionBars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, fSelectAllAction);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findInputForElement(java.lang.Object)
|
||||
*/
|
||||
protected Object findInputForElement(Object element) {
|
||||
return getNamespaceInput(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findElementToSelect(java.lang.Object)
|
||||
*/
|
||||
protected Object findElementToSelect(Object element) {
|
||||
return getTypesInput(element);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.browser.AllTypesCache;
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.browser.ITypeSearchScope;
|
||||
import org.eclipse.cdt.core.browser.TypeSearchScope;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableContext;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
class NamespacesViewContentProvider extends CBrowsingContentProvider {
|
||||
|
||||
NamespacesViewContentProvider(CBrowsingPart browsingPart) {
|
||||
super(browsingPart);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||
*/
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ICProject) {
|
||||
return true;
|
||||
// TypeSearchScope scope = new TypeSearchScope();
|
||||
// scope.add((ICProject)element);
|
||||
// return AllTypesCache.getNamespaces(scope, true);
|
||||
}
|
||||
|
||||
if (element instanceof ISourceRoot) {
|
||||
return true;
|
||||
// TypeSearchScope scope = new TypeSearchScope();
|
||||
// scope.add((ISourceRoot)element);
|
||||
// return AllTypesCache.getNamespaces(scope, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof IStructuredSelection) {
|
||||
Assert.isLegal(false);
|
||||
Object[] result= new Object[0];
|
||||
Class clazz= null;
|
||||
Iterator iter= ((IStructuredSelection)element).iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object item= iter.next();
|
||||
if (clazz == null)
|
||||
clazz= item.getClass();
|
||||
if (clazz == item.getClass())
|
||||
result= concatenate(result, getChildren(item));
|
||||
else
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (element instanceof ICProject) {
|
||||
TypeSearchScope scope = new TypeSearchScope();
|
||||
scope.add((ICProject)element);
|
||||
return getNamespaces(scope);
|
||||
}
|
||||
|
||||
if (element instanceof ISourceRoot) {
|
||||
TypeSearchScope scope = new TypeSearchScope();
|
||||
scope.add((ISourceRoot)element);
|
||||
return getNamespaces(scope);
|
||||
}
|
||||
|
||||
return NO_CHILDREN;
|
||||
// } catch (CModelException e) {
|
||||
// return NO_CHILDREN;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||
*/
|
||||
public Object getParent(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
if (info.isEnclosedType()) {
|
||||
return info.getEnclosingType();
|
||||
} else {
|
||||
// return info.getEnclosingProject();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
|
||||
private Object[] getNamespaces(final ITypeSearchScope scope) {
|
||||
if (!AllTypesCache.isCacheUpToDate(scope)) {
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
AllTypesCache.updateCache(scope, monitor);
|
||||
if (monitor.isCanceled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IRunnableContext runnableContext = new ProgressMonitorDialog(getShell());
|
||||
try {
|
||||
runnableContext.run(true, true, runnable);
|
||||
} catch (InvocationTargetException e) {
|
||||
String title = OpenTypeMessages.getString("OpenTypeAction.exception.title"); //$NON-NLS-1$
|
||||
String message = OpenTypeMessages.getString("OpenTypeAction.exception.message"); //$NON-NLS-1$
|
||||
ExceptionHandler.handle(e, title, message);
|
||||
return NO_CHILDREN;
|
||||
} catch (InterruptedException e) {
|
||||
// cancelled by user
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
}
|
||||
return AllTypesCache.getNamespaces(scope, true);
|
||||
}
|
||||
|
||||
protected Shell getShell() {
|
||||
return CUIPlugin.getActiveWorkbenchShell();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.IResourceChangeListener;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.window.Window;
|
||||
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.OpenResourceAction;
|
||||
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
|
||||
/**
|
||||
* Action to open a closed project. Action either opens the closed projects
|
||||
* provided by the strucutured selection or present a dialog from which the
|
||||
* user can select the projects to be opened.
|
||||
*
|
||||
* <p>
|
||||
* This class may be instantiated; it is not intended to be subclassed.
|
||||
* </p>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class OpenProjectAction extends SelectionDispatchAction implements IResourceChangeListener {
|
||||
|
||||
private static final int EMPTY_SELECTION= 1;
|
||||
private static final int ELEMENT_SELECTION= 2;
|
||||
|
||||
private int fMode;
|
||||
private OpenResourceAction fWorkbenchAction;
|
||||
|
||||
/**
|
||||
* Creates a new <code>OpenProjectAction</code>. The action requires
|
||||
* that the selection provided by the site's selection provider is of type <code>
|
||||
* org.eclipse.jface.viewers.IStructuredSelection</code>.
|
||||
*
|
||||
* @param site the site providing context information for this action
|
||||
*/
|
||||
public OpenProjectAction(IWorkbenchSite site) {
|
||||
super(site);
|
||||
fWorkbenchAction= new OpenResourceAction(site.getShell());
|
||||
setText(fWorkbenchAction.getText());
|
||||
setToolTipText(fWorkbenchAction.getToolTipText());
|
||||
setEnabled(hasCloseProjects());
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.OPEN_PROJECT_ACTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
|
||||
*/
|
||||
public void resourceChanged(IResourceChangeEvent event) {
|
||||
fWorkbenchAction.resourceChanged(event);
|
||||
switch (fMode) {
|
||||
case ELEMENT_SELECTION:
|
||||
setEnabled(fWorkbenchAction.isEnabled());
|
||||
break;
|
||||
case EMPTY_SELECTION:
|
||||
internalResourceChanged(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void internalResourceChanged(IResourceChangeEvent event) {
|
||||
IResourceDelta delta = event.getDelta();
|
||||
if (delta != null) {
|
||||
IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
|
||||
for (int i = 0; i < projDeltas.length; ++i) {
|
||||
IResourceDelta projDelta = projDeltas[i];
|
||||
if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) {
|
||||
setEnabled(hasCloseProjects());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---- normal selection -------------------------------------
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(ISelection selection) {
|
||||
setEnabled(hasCloseProjects());
|
||||
fMode= EMPTY_SELECTION;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void run(ISelection selection) {
|
||||
internalRun();
|
||||
}
|
||||
|
||||
//---- structured selection ---------------------------------------
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
|
||||
*/
|
||||
public void selectionChanged(IStructuredSelection selection) {
|
||||
if (selection.isEmpty()) {
|
||||
setEnabled(hasCloseProjects());
|
||||
fMode= EMPTY_SELECTION;
|
||||
return;
|
||||
}
|
||||
fWorkbenchAction.selectionChanged(selection);
|
||||
setEnabled(fWorkbenchAction.isEnabled());
|
||||
fMode= ELEMENT_SELECTION;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection)
|
||||
*/
|
||||
public void run(IStructuredSelection selection) {
|
||||
if (selection.isEmpty()) {
|
||||
internalRun();
|
||||
return;
|
||||
}
|
||||
fWorkbenchAction.run();
|
||||
}
|
||||
|
||||
private void internalRun() {
|
||||
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new CElementLabelProvider());
|
||||
dialog.setTitle(ActionMessages.getString("OpenProjectAction.dialog.title")); //$NON-NLS-1$
|
||||
dialog.setMessage(ActionMessages.getString("OpenProjectAction.dialog.message")); //$NON-NLS-1$
|
||||
dialog.setElements(getClosedProjects());
|
||||
dialog.setMultipleSelection(true);
|
||||
int result= dialog.open();
|
||||
if (result != Window.OK)
|
||||
return;
|
||||
final Object[] projects= dialog.getResult();
|
||||
IWorkspaceRunnable runnable= createRunnable(projects);
|
||||
try {
|
||||
PlatformUI.getWorkbench().getProgressService().run(true, true, new WorkbenchRunnableAdapter(runnable));
|
||||
} catch (InvocationTargetException e) {
|
||||
ExceptionHandler.handle(e, getShell(),
|
||||
ActionMessages.getString("OpenProjectAction.dialog.title"), //$NON-NLS-1$
|
||||
ActionMessages.getString("OpenProjectAction.error.message")); //$NON-NLS-1$
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private IWorkspaceRunnable createRunnable(final Object[] projects) {
|
||||
return new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
monitor.beginTask("", projects.length); //$NON-NLS-1$
|
||||
MultiStatus errorStatus= null;
|
||||
for (int i = 0; i < projects.length; i++) {
|
||||
IProject project= (IProject)projects[i];
|
||||
try {
|
||||
project.open(new SubProgressMonitor(monitor, 1));
|
||||
} catch (CoreException e) {
|
||||
if (errorStatus == null)
|
||||
errorStatus = new MultiStatus(CUIPlugin.getPluginId(), IStatus.ERROR, ActionMessages.getString("OpenProjectAction.error.message"), e); //$NON-NLS-1$
|
||||
errorStatus.merge(e.getStatus());
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
if (errorStatus != null)
|
||||
throw new CoreException(errorStatus);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Object[] getClosedProjects() {
|
||||
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
List result= new ArrayList(5);
|
||||
for (int i = 0; i < projects.length; i++) {
|
||||
IProject project= projects[i];
|
||||
if (!project.isOpen())
|
||||
result.add(project);
|
||||
}
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
private boolean hasCloseProjects() {
|
||||
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for (int i = 0; i < projects.length; i++) {
|
||||
if (!projects[i].isOpen())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,371 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.corext.refactoring.ListenerList;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.util.IProblemChangedListener;
|
||||
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor;
|
||||
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceStatus;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.IDecoration;
|
||||
import org.eclipse.jface.viewers.ILabelDecorator;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.ILabelProviderListener;
|
||||
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
|
||||
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
|
||||
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.ui.texteditor.MarkerAnnotation;
|
||||
|
||||
/**
|
||||
* LabelDecorator that decorates an element's image with error and warning overlays that
|
||||
* represent the severity of markers attached to the element's underlying resource. To see
|
||||
* a problem decoration for a marker, the marker needs to be a subtype of <code>IMarker.PROBLEM</code>.
|
||||
* <p>
|
||||
* Note: Only images for elements in Java projects are currently updated on marker changes.
|
||||
* </p>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator {
|
||||
|
||||
/**
|
||||
* This is a special <code>LabelProviderChangedEvent</code> carring additional
|
||||
* information whether the event orgins from a maker change.
|
||||
* <p>
|
||||
* <code>ProblemsLabelChangedEvent</code>s are only generated by <code>
|
||||
* ProblemsLabelDecorator</code>s.
|
||||
* </p>
|
||||
*/
|
||||
public static class ProblemsLabelChangedEvent extends LabelProviderChangedEvent {
|
||||
|
||||
private boolean fMarkerChange;
|
||||
|
||||
/**
|
||||
* Note: This constructor is for internal use only. Clients should not call this constructor.
|
||||
*/
|
||||
public ProblemsLabelChangedEvent(IBaseLabelProvider source, IResource[] changedResource, boolean isMarkerChange) {
|
||||
super(source, changedResource);
|
||||
fMarkerChange= isMarkerChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this event origins from marker changes. If <code>false</code> an annotation
|
||||
* model change is the origin. In this case viewers not displaying working copies can ignore these
|
||||
* events.
|
||||
*
|
||||
* @return if this event origins from a marker change.
|
||||
*/
|
||||
public boolean isMarkerChange() {
|
||||
return fMarkerChange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING;
|
||||
private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR;
|
||||
|
||||
private ImageDescriptorRegistry fRegistry;
|
||||
private boolean fUseNewRegistry= false;
|
||||
private IProblemChangedListener fProblemChangedListener;
|
||||
|
||||
private ListenerList fListeners;
|
||||
|
||||
/**
|
||||
* Creates a new <code>ProblemsLabelDecorator</code>.
|
||||
*/
|
||||
public ProblemsLabelDecorator() {
|
||||
this(null);
|
||||
fUseNewRegistry= true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates decorator with a shared image registry.
|
||||
*
|
||||
* @param registry The registry to use or <code>null</code> to use the Java plugin's
|
||||
* image registry.
|
||||
*/
|
||||
/**
|
||||
* Note: This constructor is for internal use only. Clients should not call this constructor.
|
||||
*/
|
||||
public ProblemsLabelDecorator(ImageDescriptorRegistry registry) {
|
||||
fRegistry= registry;
|
||||
fProblemChangedListener= null;
|
||||
}
|
||||
|
||||
private ImageDescriptorRegistry getRegistry() {
|
||||
if (fRegistry == null) {
|
||||
fRegistry= fUseNewRegistry ? new ImageDescriptorRegistry() : CUIPlugin.getImageDescriptorRegistry();
|
||||
}
|
||||
return fRegistry;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelDecorator#decorateText(String, Object)
|
||||
*/
|
||||
public String decorateText(String text, Object element) {
|
||||
return text;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelDecorator#decorateImage(Image, Object)
|
||||
*/
|
||||
public Image decorateImage(Image image, Object obj) {
|
||||
int adornmentFlags= computeAdornmentFlags(obj);
|
||||
if (adornmentFlags != 0) {
|
||||
ImageDescriptor baseImage= new ImageImageDescriptor(image);
|
||||
Rectangle bounds= image.getBounds();
|
||||
return getRegistry().get(new CElementImageDescriptor(baseImage, adornmentFlags, new Point(bounds.width, bounds.height)));
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is for internal use only. Clients should not call this method.
|
||||
*/
|
||||
protected int computeAdornmentFlags(Object obj) {
|
||||
try {
|
||||
if (obj instanceof ICElement) {
|
||||
ICElement element= (ICElement) obj;
|
||||
int type= element.getElementType();
|
||||
switch (type) {
|
||||
case ICElement.C_PROJECT:
|
||||
case ICElement.C_CCONTAINER:
|
||||
return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_INFINITE, null);
|
||||
// case ICElement.PACKAGE_FRAGMENT:
|
||||
// case ICElement.CLASS_FILE:
|
||||
// return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_ONE, null);
|
||||
// case ICElement.COMPILATION_UNIT:
|
||||
// case ICElement.PACKAGE_DECLARATION:
|
||||
// case ICElement.IMPORT_DECLARATION:
|
||||
// case ICElement.IMPORT_CONTAINER:
|
||||
// case ICElement.TYPE:
|
||||
// case ICElement.INITIALIZER:
|
||||
// case ICElement.METHOD:
|
||||
// case ICElement.FIELD:
|
||||
// case ICElement.LOCAL_VARIABLE:
|
||||
// ICompilationUnit cu= (ICompilationUnit) element.getAncestor(ICElement.COMPILATION_UNIT);
|
||||
// if (cu != null) {
|
||||
// ISourceReference ref= (type == ICElement.COMPILATION_UNIT) ? null : (ISourceReference) element;
|
||||
// // The assumption is that only source elements in compilation unit can have markers
|
||||
// if (cu.isWorkingCopy()) {
|
||||
// // working copy: look at annotation model
|
||||
// return getErrorTicksFromWorkingCopy(cu, ref);
|
||||
// }
|
||||
// return getErrorTicksFromMarkers(cu.getResource(), IResource.DEPTH_ONE, ref);
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
}
|
||||
} else if (obj instanceof IResource) {
|
||||
return getErrorTicksFromMarkers((IResource) obj, IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
if (e instanceof CModelException) {
|
||||
// if (((CModelException) e).isDoesNotExist()) {
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException {
|
||||
if (res == null || !res.isAccessible()) {
|
||||
return 0;
|
||||
}
|
||||
int info= 0;
|
||||
|
||||
IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
|
||||
if (markers != null) {
|
||||
for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
|
||||
IMarker curr= markers[i];
|
||||
if (sourceElement == null || isMarkerInRange(curr, sourceElement)) {
|
||||
int priority= curr.getAttribute(IMarker.SEVERITY, -1);
|
||||
if (priority == IMarker.SEVERITY_WARNING) {
|
||||
info= ERRORTICK_WARNING;
|
||||
} else if (priority == IMarker.SEVERITY_ERROR) {
|
||||
info= ERRORTICK_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private boolean isMarkerInRange(IMarker marker, ISourceReference sourceElement) throws CoreException {
|
||||
if (marker.isSubtypeOf(IMarker.TEXT)) {
|
||||
int pos= marker.getAttribute(IMarker.CHAR_START, -1);
|
||||
return isInside(pos, sourceElement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private int getErrorTicksFromWorkingCopy(ITranslationUnit original, ISourceReference sourceElement) throws CoreException {
|
||||
int info= 0;
|
||||
FileEditorInput editorInput= new FileEditorInput((IFile) original.getResource());
|
||||
// IAnnotationModel model= CUIPlugin.getDefault().getTranslationUnitDocumentProvider().getAnnotationModel(editorInput);
|
||||
// if (model != null) {
|
||||
// Iterator iter= model.getAnnotationIterator();
|
||||
// while ((info != ERRORTICK_ERROR) && iter.hasNext()) {
|
||||
// Annotation curr= (Annotation) iter.next();
|
||||
// IMarker marker= isAnnotationInRange(model, curr, sourceElement);
|
||||
// if (marker != null) {
|
||||
// int priority= marker.getAttribute(IMarker.SEVERITY, -1);
|
||||
// if (priority == IMarker.SEVERITY_WARNING) {
|
||||
// info= ERRORTICK_WARNING;
|
||||
// } else if (priority == IMarker.SEVERITY_ERROR) {
|
||||
// info= ERRORTICK_ERROR;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return info;
|
||||
}
|
||||
|
||||
private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
|
||||
if (annot instanceof MarkerAnnotation) {
|
||||
IMarker marker= ((MarkerAnnotation) annot).getMarker();
|
||||
if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) {
|
||||
Position pos= model.getPosition(annot);
|
||||
if (pos != null && (sourceElement == null || isInside(pos.getOffset(), sourceElement))) {
|
||||
return marker;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a position is inside the source range of an element.
|
||||
* @param pos Position to be tested.
|
||||
* @param sourceElement Source element (must be a ICElement)
|
||||
* @return boolean Return <code>true</code> if position is located inside the source element.
|
||||
* @throws CoreException Exception thrown if element range could not be accessed.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
protected boolean isInside(int pos, ISourceReference sourceElement) throws CoreException {
|
||||
ISourceRange range= sourceElement.getSourceRange();
|
||||
if (range != null) {
|
||||
int rangeOffset= range.getStartPos();
|
||||
return (rangeOffset <= pos && rangeOffset + range.getLength() > pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fProblemChangedListener != null) {
|
||||
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(fProblemChangedListener);
|
||||
fProblemChangedListener= null;
|
||||
}
|
||||
if (fRegistry != null && fUseNewRegistry) {
|
||||
fRegistry.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
||||
*/
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
||||
*/
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
if (fListeners == null) {
|
||||
fListeners= new ListenerList();
|
||||
}
|
||||
fListeners.add(listener);
|
||||
// if (fProblemChangedListener == null) {
|
||||
// fProblemChangedListener= new IProblemChangedListener() {
|
||||
// public void problemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
||||
// fireProblemsChanged(changedResources, isMarkerChange);
|
||||
// }
|
||||
// };
|
||||
// CUIPlugin.getDefault().getProblemMarkerManager().addListener(fProblemChangedListener);
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
if (fListeners != null) {
|
||||
fListeners.remove(listener);
|
||||
if (fListeners.isEmpty() && fProblemChangedListener != null) {
|
||||
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(fProblemChangedListener);
|
||||
fProblemChangedListener= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
||||
if (fListeners != null && !fListeners.isEmpty()) {
|
||||
LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange);
|
||||
Object[] listeners= fListeners.getListeners();
|
||||
for (int i= 0; i < listeners.length; i++) {
|
||||
((ILabelProviderListener) listeners[i]).labelProviderChanged(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
|
||||
*/
|
||||
public void decorate(Object element, IDecoration decoration) {
|
||||
int adornmentFlags= computeAdornmentFlags(element);
|
||||
if (adornmentFlags == ERRORTICK_ERROR) {
|
||||
decoration.addOverlay(CPluginImages.DESC_OVR_ERROR);
|
||||
} else if (adornmentFlags == ERRORTICK_WARNING) {
|
||||
decoration.addOverlay(CPluginImages.DESC_OVR_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.ui.actions.CloseResourceAction;
|
||||
import org.eclipse.ui.ide.IDEActionFactory;
|
||||
|
||||
/**
|
||||
* Adds actions to open and close a project to the global menu bar.
|
||||
*
|
||||
* <p>
|
||||
* This class may be instantiated; it is not intended to be subclassed.
|
||||
* </p>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ProjectActionGroup extends ActionGroup {
|
||||
|
||||
private IWorkbenchSite fSite;
|
||||
|
||||
private OpenProjectAction fOpenAction;
|
||||
private CloseResourceAction fCloseAction;
|
||||
|
||||
/**
|
||||
* Creates a new <code>ProjectActionGroup</code>. The group requires
|
||||
* that the selection provided by the site's selection provider is of type <code>
|
||||
* org.eclipse.jface.viewers.IStructuredSelection</code>.
|
||||
*
|
||||
* @param part the view part that owns this action group
|
||||
*/
|
||||
public ProjectActionGroup(IViewPart part) {
|
||||
fSite = part.getSite();
|
||||
Shell shell= fSite.getShell();
|
||||
ISelectionProvider provider= fSite.getSelectionProvider();
|
||||
ISelection selection= provider.getSelection();
|
||||
|
||||
fCloseAction= new CloseResourceAction(shell);
|
||||
fCloseAction.setActionDefinitionId("org.eclipse.ui.project.closeProject"); //$NON-NLS-1$
|
||||
fOpenAction= new OpenProjectAction(fSite);
|
||||
fOpenAction.setActionDefinitionId("org.eclipse.ui.project.openProject"); //$NON-NLS-1$
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection s= (IStructuredSelection)selection;
|
||||
fOpenAction.selectionChanged(s);
|
||||
fCloseAction.selectionChanged(s);
|
||||
}
|
||||
provider.addSelectionChangedListener(fOpenAction);
|
||||
provider.addSelectionChangedListener(fCloseAction);
|
||||
IWorkspace workspace= ResourcesPlugin.getWorkspace();
|
||||
workspace.addResourceChangeListener(fOpenAction);
|
||||
workspace.addResourceChangeListener(fCloseAction);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* Method declared in ActionGroup
|
||||
*/
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
super.fillActionBars(actionBars);
|
||||
actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), fCloseAction);
|
||||
actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), fOpenAction);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* Method declared in ActionGroup
|
||||
*/
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
super.fillContextMenu(menu);
|
||||
if (fOpenAction.isEnabled())
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fOpenAction);
|
||||
if (fCloseAction.isEnabled())
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fCloseAction);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see ActionGroup#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
ISelectionProvider provider= fSite.getSelectionProvider();
|
||||
provider.removeSelectionChangedListener(fOpenAction);
|
||||
provider.removeSelectionChangedListener(fCloseAction);
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
workspace.removeResourceChangeListener(fOpenAction);
|
||||
workspace.removeResourceChangeListener(fCloseAction);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.part.IShowInTargetList;
|
||||
|
||||
public class ProjectsView extends CBrowsingPart {
|
||||
|
||||
// private FilterUpdater fFilterUpdater;
|
||||
|
||||
/**
|
||||
* Creates the the viewer of this part.
|
||||
*
|
||||
* @param parent the parent for the viewer
|
||||
*/
|
||||
protected StructuredViewer createViewer(Composite parent) {
|
||||
ProblemTreeViewer result= new ProblemTreeViewer(parent, SWT.MULTI);
|
||||
// fFilterUpdater= new FilterUpdater(result);
|
||||
// ResourcesPlugin.getWorkspace().addResourceChangeListener(fFilterUpdater);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected LabelProvider createLabelProvider() {
|
||||
return new CUILabelProvider();
|
||||
// return new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
// if (fFilterUpdater != null)
|
||||
// ResourcesPlugin.getWorkspace().removeResourceChangeListener(fFilterUpdater);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the property defined by key.
|
||||
*/
|
||||
public Object getAdapter(Class key) {
|
||||
if (key == IShowInTargetList.class) {
|
||||
return new IShowInTargetList() {
|
||||
public String[] getShowInTargetIds() {
|
||||
return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_RES_NAV };
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
return super.getAdapter(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the the content provider of this part.
|
||||
*/
|
||||
protected IContentProvider createContentProvider() {
|
||||
return new ProjectsViewContentProvider(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context ID for the Help system.
|
||||
*
|
||||
* @return the string used as ID for the Help context
|
||||
*/
|
||||
protected String getHelpContextId() {
|
||||
return ICHelpContextIds.PROJECTS_VIEW;
|
||||
}
|
||||
|
||||
protected String getLinkToEditorKey() {
|
||||
return PreferenceConstants.LINK_BROWSING_PROJECTS_TO_EDITOR;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds additional listeners to this view.
|
||||
*/
|
||||
protected void hookViewerListeners() {
|
||||
super.hookViewerListeners();
|
||||
getViewer().addDoubleClickListener(new IDoubleClickListener() {
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
TreeViewer viewer= (TreeViewer)getViewer();
|
||||
Object element= ((IStructuredSelection)event.getSelection()).getFirstElement();
|
||||
if (viewer.isExpandable(element))
|
||||
viewer.setExpandedState(element, !viewer.getExpandedState(element));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setInitialInput() {
|
||||
ICElement root= CoreModel.create(CUIPlugin.getWorkspace().getRoot());
|
||||
getViewer().setInput(root);
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* input for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid input
|
||||
*/
|
||||
protected boolean isValidInput(Object element) {
|
||||
return element instanceof ICModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* element for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid element
|
||||
*/
|
||||
protected boolean isValidElement(Object element) {
|
||||
return element instanceof ICProject || element instanceof ICContainer;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see JavaBrowsingPart#setInput(Object)
|
||||
*/
|
||||
protected void setInput(Object input) {
|
||||
// Don't allow to clear input for this view
|
||||
if (input != null)
|
||||
super.setInput(input);
|
||||
else
|
||||
getViewer().setSelection(null);
|
||||
}
|
||||
|
||||
protected void createActions() {
|
||||
super.createActions();
|
||||
// fActionGroups.addGroup(new ProjectActionGroup(this));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findInputForElement(java.lang.Object)
|
||||
*/
|
||||
protected Object findInputForElement(Object element) {
|
||||
if (element instanceof ICModel) {
|
||||
if (exists(element))
|
||||
return element;
|
||||
}
|
||||
|
||||
if (element instanceof ICElement) { //ICProject || element instanceof ISourceRoot) {
|
||||
ICModel model = ((ICElement)element).getCModel();
|
||||
if (exists(model))
|
||||
return model;
|
||||
}
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ICProject cProject = findCProject((ITypeInfo)element);
|
||||
if (cProject != null) {
|
||||
ICModel model = cProject.getCModel();
|
||||
if (exists(model))
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findElementToSelect(java.lang.Object)
|
||||
*/
|
||||
protected Object findElementToSelect(Object element) {
|
||||
return getNamespaceInput(element);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
||||
class ProjectsViewContentProvider extends CBrowsingContentProvider {
|
||||
|
||||
ProjectsViewContentProvider(CBrowsingPart browsingPart) {
|
||||
super(browsingPart);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||
*/
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ICModel) {
|
||||
ICModel cModel = (ICModel)element;
|
||||
return cModel.hasChildren();
|
||||
}
|
||||
|
||||
if (element instanceof ICProject) {
|
||||
ICProject cProject = (ICProject)element;
|
||||
if (cProject.exists() && cProject.isOpen())
|
||||
return cProject.hasChildren();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element instanceof ISourceRoot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof IStructuredSelection) {
|
||||
Assert.isLegal(false);
|
||||
Object[] result= new Object[0];
|
||||
Class clazz= null;
|
||||
Iterator iter= ((IStructuredSelection)element).iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object item= iter.next();
|
||||
if (clazz == null)
|
||||
clazz= item.getClass();
|
||||
if (clazz == item.getClass())
|
||||
result= concatenate(result, getChildren(item));
|
||||
else
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (element instanceof ICModel) {
|
||||
ICModel cModel = (ICModel)element;
|
||||
return cModel.getCProjects();
|
||||
}
|
||||
|
||||
if (element instanceof ICProject)
|
||||
return getSourceRoots((ICProject)element);
|
||||
|
||||
if (element instanceof ISourceRoot)
|
||||
return NO_CHILDREN;
|
||||
|
||||
return NO_CHILDREN;
|
||||
} catch (CModelException e) {
|
||||
return NO_CHILDREN;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||
*/
|
||||
public Object getParent(Object element) {
|
||||
if (element == null || (element instanceof ICElement && !((ICElement)element).exists())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ICModel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (element instanceof ICProject) {
|
||||
ICProject cProject = (ICProject)element;
|
||||
return cProject.getCModel();
|
||||
}
|
||||
|
||||
if (element instanceof ISourceRoot) {
|
||||
ISourceRoot cSourceRoot = (ISourceRoot)element;
|
||||
return cSourceRoot.getCProject();
|
||||
}
|
||||
|
||||
return null;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
|
||||
protected Object[] getSourceRoots(ICProject project) throws CModelException {
|
||||
if (!project.getProject().isOpen())
|
||||
return NO_CHILDREN;
|
||||
|
||||
ISourceRoot[] roots= project.getSourceRoots();
|
||||
List list= new ArrayList(roots.length);
|
||||
// filter out package fragments that correspond to projects and
|
||||
// replace them with the package fragments directly
|
||||
for (int i= 0; i < roots.length; i++) {
|
||||
ISourceRoot root= roots[i];
|
||||
if (!isProjectSourceRoot(root))
|
||||
list.add(root);
|
||||
}
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
protected boolean isProjectSourceRoot(ISourceRoot root) {
|
||||
IResource resource= root.getResource();
|
||||
return (resource instanceof IProject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CElementLabels;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
import org.eclipse.jface.action.IStatusLineManager;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
|
||||
/**
|
||||
* Add the <code>StatusBarUpdater</code> to your ViewPart to have the statusbar
|
||||
* describing the selected elements.
|
||||
*/
|
||||
public class StatusBarUpdater implements ISelectionChangedListener {
|
||||
|
||||
private final int LABEL_FLAGS= CElementLabels.DEFAULT_QUALIFIED | CElementLabels.ROOT_POST_QUALIFIED | CElementLabels.APPEND_ROOT_PATH |
|
||||
CElementLabels.M_PARAMETER_TYPES | CElementLabels.M_PARAMETER_NAMES | CElementLabels.M_APP_RETURNTYPE | CElementLabels.M_EXCEPTIONS |
|
||||
CElementLabels.F_APP_TYPE_SIGNATURE;
|
||||
|
||||
private final TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED + TypeInfoLabelProvider.SHOW_PATH);
|
||||
|
||||
private IStatusLineManager fStatusLineManager;
|
||||
|
||||
public StatusBarUpdater(IStatusLineManager statusLineManager) {
|
||||
fStatusLineManager= statusLineManager;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ISelectionChangedListener#selectionChanged
|
||||
*/
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
String statusBarMessage= formatMessage(event.getSelection());
|
||||
fStatusLineManager.setMessage(statusBarMessage);
|
||||
}
|
||||
|
||||
|
||||
protected String formatMessage(ISelection sel) {
|
||||
if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
|
||||
IStructuredSelection selection= (IStructuredSelection) sel;
|
||||
|
||||
int nElements= selection.size();
|
||||
if (nElements > 1) {
|
||||
return CUIMessages.getFormattedString("StatusBarUpdater.num_elements_selected", String.valueOf(nElements)); //$NON-NLS-1$
|
||||
} else {
|
||||
Object elem= selection.getFirstElement();
|
||||
if (elem instanceof ICElement) {
|
||||
return formatCElementMessage((ICElement) elem);
|
||||
} else if (elem instanceof ITypeInfo) {
|
||||
return formatTypeInfoMessage((ITypeInfo) elem);
|
||||
} else if (elem instanceof IResource) {
|
||||
return formatResourceMessage((IResource) elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String formatCElementMessage(ICElement element) {
|
||||
return CElementLabels.getElementLabel(element, LABEL_FLAGS);
|
||||
}
|
||||
|
||||
private String formatTypeInfoMessage(ITypeInfo info) {
|
||||
return fTypeInfoLabelProvider.getText(info);
|
||||
}
|
||||
|
||||
private String formatResourceMessage(IResource element) {
|
||||
IContainer parent= element.getParent();
|
||||
if (parent != null && parent.getType() != IResource.ROOT)
|
||||
return element.getName() + CElementLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString();
|
||||
else
|
||||
return element.getName();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
|
||||
import org.eclipse.ui.IEditorRegistry;
|
||||
import org.eclipse.ui.IFileEditorMapping;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Standard label provider for IStorage objects.
|
||||
* Use this class when you want to present IStorage objects in a viewer.
|
||||
*/
|
||||
public class StorageLabelProvider extends LabelProvider {
|
||||
|
||||
private IEditorRegistry fEditorRegistry= PlatformUI.getWorkbench().getEditorRegistry();
|
||||
private Map fJarImageMap= new HashMap(10);
|
||||
private Image fDefaultImage;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelProvider#getImage
|
||||
*/
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof IStorage)
|
||||
return getImageForJarEntry((IStorage)element);
|
||||
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ILabelProvider#getText
|
||||
*/
|
||||
public String getText(Object element) {
|
||||
if (element instanceof IStorage)
|
||||
return ((IStorage)element).getName();
|
||||
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see IBaseLabelProvider#dispose
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fJarImageMap != null) {
|
||||
Iterator each= fJarImageMap.values().iterator();
|
||||
while (each.hasNext()) {
|
||||
Image image= (Image)each.next();
|
||||
image.dispose();
|
||||
}
|
||||
fJarImageMap= null;
|
||||
}
|
||||
if (fDefaultImage != null)
|
||||
fDefaultImage.dispose();
|
||||
fDefaultImage= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets and caches an image for a JarEntryFile.
|
||||
* The image for a JarEntryFile is retrieved from the EditorRegistry.
|
||||
*/
|
||||
private Image getImageForJarEntry(IStorage element) {
|
||||
if (fJarImageMap == null)
|
||||
return getDefaultImage();
|
||||
|
||||
if (element == null || element.getName() == null)
|
||||
return getDefaultImage();
|
||||
|
||||
// Try to find icon for full name
|
||||
String name= element.getName();
|
||||
Image image= (Image)fJarImageMap.get(name);
|
||||
if (image != null)
|
||||
return image;
|
||||
IFileEditorMapping[] mappings= fEditorRegistry.getFileEditorMappings();
|
||||
int i= 0;
|
||||
while (i < mappings.length) {
|
||||
if (mappings[i].getLabel().equals(name))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
String key= name;
|
||||
if (i == mappings.length) {
|
||||
// Try to find icon for extension
|
||||
IPath path= element.getFullPath();
|
||||
if (path == null)
|
||||
return getDefaultImage();
|
||||
key= path.getFileExtension();
|
||||
if (key == null)
|
||||
return getDefaultImage();
|
||||
image= (Image)fJarImageMap.get(key);
|
||||
if (image != null)
|
||||
return image;
|
||||
}
|
||||
|
||||
// Get the image from the editor registry
|
||||
ImageDescriptor desc= fEditorRegistry.getImageDescriptor(name);
|
||||
image= desc.createImage();
|
||||
|
||||
fJarImageMap.put(key, image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private Image getDefaultImage() {
|
||||
if (fDefaultImage == null)
|
||||
fDefaultImage= fEditorRegistry.getImageDescriptor((String)null).createImage();
|
||||
return fDefaultImage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
public class TypeInfoComparator implements Comparator {
|
||||
/**
|
||||
* Compares two ITypeInfo/ICElement types. A type is considered to be
|
||||
* greater if it may contain the other.
|
||||
*
|
||||
* @return an int less than 0 if object1 is less than object2,
|
||||
* 0 if they are equal, and > 0 if object1 is greater
|
||||
*
|
||||
* @see Comparator#compare(Object, Object)
|
||||
*/
|
||||
public int compare(Object o1, Object o2) {
|
||||
int t1 = getElementType(o1);
|
||||
int t2 = getElementType(o2);
|
||||
return getIdForElementType(t1) - getIdForElementType(t2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two C element types. A type is considered to be
|
||||
* greater if it may contain the other.
|
||||
*
|
||||
* @return an int < 0 if object1 is less than object2,
|
||||
* 0 if they are equal, and > 0 if object1 is greater
|
||||
*
|
||||
* @see Comparator#compare(Object, Object)
|
||||
*/
|
||||
public int compare(Object o1, int elementType) {
|
||||
int t1 = getElementType(o1);
|
||||
if (t1 == 0)
|
||||
throw new ClassCastException();
|
||||
return getIdForElementType(t1) - getIdForElementType(elementType);
|
||||
}
|
||||
|
||||
int getElementType(Object obj) {
|
||||
if (obj instanceof ICElement) {
|
||||
return ((ICElement)obj).getElementType();
|
||||
} else if (obj instanceof ITypeInfo) {
|
||||
return ((ITypeInfo)obj).getCElementType();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int getIdForElementType(int elementType) {
|
||||
switch (elementType) {
|
||||
case ICElement.C_MODEL:
|
||||
return 100;
|
||||
case ICElement.C_PROJECT:
|
||||
return 90;
|
||||
case ICElement.C_CCONTAINER:
|
||||
return 80;
|
||||
case ICElement.C_UNIT:
|
||||
return 70;
|
||||
case ICElement.C_NAMESPACE:
|
||||
return 60;
|
||||
case ICElement.C_CLASS:
|
||||
return 50;
|
||||
case ICElement.C_STRUCT:
|
||||
return 40;
|
||||
case ICElement.C_UNION:
|
||||
return 30;
|
||||
case ICElement.C_ENUMERATION:
|
||||
return 20;
|
||||
case ICElement.C_TYPEDEF:
|
||||
return 10;
|
||||
default :
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Created on May 18, 2004
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
|
||||
/**
|
||||
* A sorter to sort the file and the folders in the C viewer in the following order:
|
||||
* 1 Project
|
||||
* 2 BinaryContainer
|
||||
* 3 ArchiveContainer
|
||||
* 4 LibraryContainer
|
||||
* 5 IncludeContainer
|
||||
* 6 Source roots
|
||||
* 5 C Elements
|
||||
* 6 non C Elements
|
||||
*/
|
||||
public class TypeInfoSorter extends ViewerSorter {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
if (e1 instanceof ITypeInfo) {
|
||||
return compare((ITypeInfo)e1, e2);
|
||||
} else if (e1 instanceof ICElement) {
|
||||
return compare((ICElement)e1, e2);
|
||||
}
|
||||
return 0;
|
||||
// return getCollator().compare(name1, name2);
|
||||
}
|
||||
|
||||
int compare(ITypeInfo t1, Object o2) {
|
||||
if (o2 instanceof ITypeInfo) {
|
||||
ITypeInfo t2 = (ITypeInfo)o2;
|
||||
return t1.compareTo(t2);
|
||||
} else if (o2 instanceof ICElement) {
|
||||
ICElement e2 = (ICElement)o2;
|
||||
return getCollator().compare(t1.getName(), e2.getElementName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compare(ICElement e1, Object o2) {
|
||||
if (o2 instanceof ITypeInfo) {
|
||||
ITypeInfo t2 = (ITypeInfo)o2;
|
||||
return getCollator().compare(e1.getElementName(), t2.getName());
|
||||
} else if (o2 instanceof ICElement) {
|
||||
ICElement e2 = (ICElement)o2;
|
||||
return getCollator().compare(e1.getElementName(), e2.getElementName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTableViewer;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.part.IShowInTargetList;
|
||||
|
||||
public class TypesView extends CBrowsingPart {
|
||||
|
||||
// private SelectAllAction fSelectAllAction;
|
||||
|
||||
/**
|
||||
* Creates and returns the label provider for this part.
|
||||
*
|
||||
* @return the label provider
|
||||
* @see org.eclipse.jface.viewers.ILabelProvider
|
||||
*/
|
||||
protected LabelProvider createLabelProvider() {
|
||||
return new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the property defined by key.
|
||||
*/
|
||||
public Object getAdapter(Class key) {
|
||||
if (key == IShowInTargetList.class) {
|
||||
return new IShowInTargetList() {
|
||||
public String[] getShowInTargetIds() {
|
||||
return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_RES_NAV };
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
return super.getAdapter(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the viewer of this part dependent on the current
|
||||
* layout.
|
||||
*
|
||||
* @param parent the parent for the viewer
|
||||
*/
|
||||
protected StructuredViewer createViewer(Composite parent) {
|
||||
StructuredViewer viewer;
|
||||
// if(isInListState())
|
||||
viewer= createTableViewer(parent);
|
||||
// else
|
||||
// viewer= createTreeViewer(parent);
|
||||
|
||||
// fWrappedViewer.setViewer(viewer);
|
||||
// return fWrappedViewer;
|
||||
return viewer;
|
||||
}
|
||||
private ProblemTableViewer createTableViewer(Composite parent) {
|
||||
return new ProblemTableViewer(parent, SWT.MULTI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the the content provider of this part.
|
||||
*/
|
||||
protected IContentProvider createContentProvider() {
|
||||
return new TypesViewContentProvider(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds filters the viewer of this part.
|
||||
*/
|
||||
protected void addFilters() {
|
||||
super.addFilters();
|
||||
// getViewer().addFilter(new NonCElementFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* input for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid input
|
||||
*/
|
||||
protected boolean isValidInput(Object element) {
|
||||
return isValidNamespace(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers if the given <code>element</code> is a valid
|
||||
* element for this part.
|
||||
*
|
||||
* @param element the object to test
|
||||
* @return <true> if the given element is a valid element
|
||||
*/
|
||||
protected boolean isValidElement(Object element) {
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
if (info.exists()) {
|
||||
switch (info.getCElementType()) {
|
||||
case ICElement.C_CLASS:
|
||||
case ICElement.C_STRUCT:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context ID for the Help system
|
||||
*
|
||||
* @return the string used as ID for the Help context
|
||||
*/
|
||||
protected String getHelpContextId() {
|
||||
return ICHelpContextIds.TYPES_VIEW;
|
||||
}
|
||||
|
||||
protected String getLinkToEditorKey() {
|
||||
return PreferenceConstants.LINK_BROWSING_TYPES_TO_EDITOR;
|
||||
}
|
||||
|
||||
protected void createActions() {
|
||||
super.createActions();
|
||||
// fSelectAllAction= new SelectAllAction((TableViewer)getViewer());
|
||||
}
|
||||
|
||||
protected void fillActionBars(IActionBars actionBars) {
|
||||
super.fillActionBars(actionBars);
|
||||
|
||||
// Add selectAll action handlers.
|
||||
// actionBars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, fSelectAllAction);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findInputForElement(java.lang.Object)
|
||||
*/
|
||||
protected Object findInputForElement(Object element) {
|
||||
return getTypesInput(element);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findElementToSelect(java.lang.Object)
|
||||
*/
|
||||
protected Object findElementToSelect(Object element) {
|
||||
return getMembersInput(element);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
||||
class TypesViewContentProvider extends CBrowsingContentProvider {
|
||||
|
||||
TypesViewContentProvider(CBrowsingPart browsingPart) {
|
||||
super(browsingPart);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||
*/
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
return info.hasEnclosedTypes();
|
||||
}
|
||||
|
||||
return false;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof IStructuredSelection) {
|
||||
Assert.isLegal(false);
|
||||
Object[] result= new Object[0];
|
||||
Class clazz= null;
|
||||
Iterator iter= ((IStructuredSelection)element).iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object item= iter.next();
|
||||
if (clazz == null)
|
||||
clazz= item.getClass();
|
||||
if (clazz == item.getClass())
|
||||
result= concatenate(result, getChildren(item));
|
||||
else
|
||||
return NO_CHILDREN;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
final int kinds[] = { ICElement.C_CLASS, ICElement.C_STRUCT };
|
||||
// ICElement.C_UNION, ICElement.C_ENUMERATION,
|
||||
// ICElement.C_TYPEDEF};
|
||||
return info.getEnclosedTypes(kinds);
|
||||
}
|
||||
|
||||
return NO_CHILDREN;
|
||||
// } catch (CModelException e) {
|
||||
// return NO_CHILDREN;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||
*/
|
||||
public Object getParent(Object element) {
|
||||
if (element == null || (element instanceof ITypeInfo && !((ITypeInfo)element).exists())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
startReadInDisplayThread();
|
||||
|
||||
if (element instanceof ITypeInfo) {
|
||||
ITypeInfo info = (ITypeInfo)element;
|
||||
if (info.isEnclosedType()) {
|
||||
return info.getEnclosingType();
|
||||
} else {
|
||||
// return info.getEnclosingProject();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// } catch (CModelException e) {
|
||||
// return false;
|
||||
} finally {
|
||||
finishedReadInDisplayThread();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ public class TypeInfoLabelProvider extends LabelProvider {
|
|||
|
||||
public static final int SHOW_TYPE_ONLY= 0x01;
|
||||
public static final int SHOW_ENCLOSING_TYPE_ONLY= 0x02;
|
||||
public static final int SHOW_PATH= 0x04;
|
||||
public static final int SHOW_FULLY_QUALIFIED= 0x04;
|
||||
public static final int SHOW_PATH= 0x08;
|
||||
|
||||
private static final Image HEADER_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TUNIT_HEADER);
|
||||
private static final Image SOURCE_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TUNIT);
|
||||
|
@ -71,6 +72,8 @@ public class TypeInfoLabelProvider extends LabelProvider {
|
|||
} else {
|
||||
buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.globalScope")); //$NON-NLS-1$
|
||||
}
|
||||
} else if (isSet(SHOW_FULLY_QUALIFIED)) {
|
||||
buf.append(qualifiedName.getFullyQualifiedName());
|
||||
}
|
||||
|
||||
if (isSet(SHOW_PATH)) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.Set;
|
|||
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.browser.QualifiedTypeName;
|
||||
import org.eclipse.cdt.core.browser.TypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.util.StringMatcher;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -55,7 +54,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
|||
|
||||
private StringMatcher fNameMatcher = null;
|
||||
private StringMatcher[] fSegmentMatchers = null;
|
||||
private boolean fMatchRootQualifier = false;
|
||||
private boolean fMatchGlobalNamespace = false;
|
||||
private Collection fVisibleTypes = new HashSet();
|
||||
private boolean fShowLowLevelTypes = false;
|
||||
|
||||
|
@ -71,7 +70,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
|||
// append wildcard to innermost segment
|
||||
segments[length-1] = adjustPattern(segments[length-1]);
|
||||
|
||||
fMatchRootQualifier = false;
|
||||
fMatchGlobalNamespace = false;
|
||||
fSegmentMatchers = new StringMatcher[length];
|
||||
int count = 0;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
|
@ -80,7 +79,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
|||
fSegmentMatchers[count++] = new StringMatcher(segments[i], ignoreCase, ignoreWildCards);
|
||||
} else if (i == 0) {
|
||||
// allow outermost segment to be blank (e.g. "::foo*")
|
||||
fMatchRootQualifier = true;
|
||||
fMatchGlobalNamespace = true;
|
||||
} else {
|
||||
// skip over blank segments (e.g. treat "foo::::b*" as "foo::b*")
|
||||
}
|
||||
|
@ -125,7 +124,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
|||
if (!(element instanceof ITypeInfo))
|
||||
return false;
|
||||
|
||||
TypeInfo info = (TypeInfo) element;
|
||||
ITypeInfo info = (ITypeInfo) element;
|
||||
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
|
||||
|
||||
if (fVisibleTypes != null && !fVisibleTypes.contains(new Integer(info.getCElementType())))
|
||||
|
@ -134,58 +133,34 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
|||
if (!fShowLowLevelTypes && qualifiedName.isLowLevel())
|
||||
return false;
|
||||
|
||||
if (!fMatchRootQualifier && !fNameMatcher.match(qualifiedName.getName()))
|
||||
if (fSegmentMatchers.length == 1 && !fMatchGlobalNamespace)
|
||||
return fNameMatcher.match(qualifiedName.getName());
|
||||
|
||||
return matchQualifiedName(info);
|
||||
}
|
||||
|
||||
private boolean matchQualifiedName(ITypeInfo info) {
|
||||
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
|
||||
String[] segments = qualifiedName.segments();
|
||||
if (fSegmentMatchers.length != segments.length)
|
||||
return false;
|
||||
|
||||
return matchQualifiedName(qualifiedName);
|
||||
}
|
||||
|
||||
private boolean matchQualifiedName(IQualifiedTypeName qualifiedName) {
|
||||
String[] segments = qualifiedName.segments();
|
||||
boolean matchFound = false;
|
||||
boolean moreNames = true;
|
||||
int matchOffset = 0;
|
||||
while (!matchFound && moreNames) {
|
||||
matchFound = true;
|
||||
for (int i = 0; i < fSegmentMatchers.length; ++i) {
|
||||
int dropOut = 0;
|
||||
if (i < (segments.length - matchOffset)) {
|
||||
// ok to continue
|
||||
// dropOut = false;
|
||||
} else {
|
||||
++dropOut;
|
||||
}
|
||||
|
||||
if (matchOffset + i >= segments.length) {
|
||||
++dropOut;
|
||||
}
|
||||
|
||||
if (dropOut > 0) {
|
||||
if (dropOut != 2) {
|
||||
// shouldn't get here
|
||||
matchFound = false;
|
||||
moreNames = false;
|
||||
}
|
||||
matchFound = false;
|
||||
moreNames = false;
|
||||
break;
|
||||
if (fMatchGlobalNamespace) {
|
||||
// must match global namespace (eg ::foo)
|
||||
if (info.getRootNamespace(false) != null)
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean matchFound = true;
|
||||
int max = Math.min(fSegmentMatchers.length, segments.length);
|
||||
for (int i = 0; i < max; ++i) {
|
||||
StringMatcher matcher = fSegmentMatchers[i];
|
||||
String name = segments[matchOffset + i];
|
||||
String name = segments[i];
|
||||
if (name == null || !matcher.match(name)) {
|
||||
matchFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fMatchRootQualifier) {
|
||||
// must match outermost name (eg ::foo)
|
||||
moreNames = false;
|
||||
} else {
|
||||
++matchOffset;
|
||||
}
|
||||
}
|
||||
return matchFound;
|
||||
}
|
||||
|
||||
|
|
BIN
core/org.eclipse.cdt.ui/icons/full/cview16/cbrowsing_pers.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/cview16/cbrowsing_pers.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 B |
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/cbrowsing_pers.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/cbrowsing_pers.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 B |
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/cprojects.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/cprojects.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 366 B |
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/members.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/members.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 345 B |
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/namespaces.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/namespaces.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/types.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/eview16/types.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 365 B |
|
@ -10,6 +10,7 @@ editorRulerActionsName=Editor Ruler Actions
|
|||
completionContributorName=Completion Contribution
|
||||
nature.name=C Nature
|
||||
perspective.name=C/C++
|
||||
CBrowsing.perspective.name=C/C++ Browsing
|
||||
viewsCategory.name=&C
|
||||
CView.name=C/C++ Projects
|
||||
|
||||
|
@ -171,3 +172,12 @@ CPresentation.label= C/C++
|
|||
CEditorPresentation.label= Editor
|
||||
|
||||
CDTIndexerMarker.label= C/C++ Indexer Markers
|
||||
|
||||
#Browsing
|
||||
CBrowsing.perspectiveName= C/C++ Browsing
|
||||
CBrowsing.viewCategoryName= C/C++ Browsing
|
||||
CBrowsing.projectsViewName= Projects
|
||||
CBrowsing.namespacesViewName= Namespaces
|
||||
CBrowsing.typesViewName= Types
|
||||
CBrowsing.membersViewName= Members
|
||||
CBrowsing.preferencePageName= Browsing
|
||||
|
|
|
@ -131,6 +131,12 @@
|
|||
class="org.eclipse.cdt.internal.ui.CPerspectiveFactory"
|
||||
id="org.eclipse.cdt.ui.CPerspective">
|
||||
</perspective>
|
||||
<perspective
|
||||
name="%CBrowsing.perspective.name"
|
||||
icon="icons/full/cview16/cbrowsing_pers.gif"
|
||||
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPerspectiveFactory"
|
||||
id="org.eclipse.cdt.ui.CBrowsingPerspective">
|
||||
</perspective>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.perspectiveExtensions">
|
||||
|
@ -139,17 +145,17 @@
|
|||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CPerspective">
|
||||
</perspectiveShortcut>
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CBrowsingPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.debug.ui.DebugPerspective">
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.cdt.ui.CPerspective">
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CPerspective">
|
||||
id="org.eclipse.cdt.ui.CBrowsingPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
|
@ -157,18 +163,21 @@
|
|||
<perspectiveShortcut
|
||||
id="org.eclipse.debug.ui.DebugPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.cdt.ui.CPerspective">
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.vcm.ui.vcmPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.cdt.ui.CPerspective">
|
||||
<actionSet
|
||||
id="org.eclipse.debug.ui.launchActionSet">
|
||||
</actionSet>
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CBrowsingPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.cdt.ui.CBrowsingPerspective">
|
||||
<perspectiveShortcut
|
||||
id="org.eclipse.cdt.ui.CPerspective">
|
||||
</perspectiveShortcut>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
<extension
|
||||
|
@ -184,6 +193,38 @@
|
|||
class="org.eclipse.cdt.internal.ui.cview.CView"
|
||||
id="org.eclipse.cdt.ui.CView">
|
||||
</view>
|
||||
<category
|
||||
name="%CBrowsing.viewCategoryName"
|
||||
id="org.eclipse.cdt.ui.c.browsing">
|
||||
</category>
|
||||
<view
|
||||
name="%CBrowsing.projectsViewName"
|
||||
icon="icons/full/eview16/cprojects.gif"
|
||||
category="org.eclipse.cdt.ui.c.browsing"
|
||||
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.ProjectsView"
|
||||
id="org.eclipse.cdt.ui.ProjectsView">
|
||||
</view>
|
||||
<view
|
||||
name="%CBrowsing.namespacesViewName"
|
||||
icon="icons/full/eview16/namespaces.gif"
|
||||
category="org.eclipse.cdt.ui.c.browsing"
|
||||
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.NamespacesView"
|
||||
id="org.eclipse.cdt.ui.NamespacesView">
|
||||
</view>
|
||||
<view
|
||||
name="%CBrowsing.typesViewName"
|
||||
icon="icons/full/eview16/types.gif"
|
||||
category="org.eclipse.cdt.ui.c.browsing"
|
||||
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.TypesView"
|
||||
id="org.eclipse.cdt.ui.TypesView">
|
||||
</view>
|
||||
<view
|
||||
name="%CBrowsing.membersViewName"
|
||||
icon="icons/full/eview16/members.gif"
|
||||
category="org.eclipse.cdt.ui.c.browsing"
|
||||
class="org.eclipse.cdt.internal.ui.browser.cbrowsing.MembersView"
|
||||
id="org.eclipse.cdt.ui.MembersView">
|
||||
</view>
|
||||
</extension>
|
||||
<!-- The wizards -->
|
||||
<!-- For C Wizards -->
|
||||
|
|
|
@ -10,9 +10,13 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.corext.util;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
public class CModelUtil {
|
||||
/**
|
||||
|
@ -35,4 +39,37 @@ public class CModelUtil {
|
|||
}
|
||||
return unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source root of <code>ICElement</code>. If the given
|
||||
* element is already a source root, the element itself is returned.
|
||||
*/
|
||||
public static ISourceRoot getSourceRoot(ICElement element) {
|
||||
ICElement root = element;
|
||||
while (root != null) {
|
||||
if (root instanceof ISourceRoot)
|
||||
return (ISourceRoot)root;
|
||||
ICElement parent = root.getAncestor(ICElement.C_CCONTAINER);
|
||||
if (parent == root)
|
||||
return null;
|
||||
root = parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given source root is
|
||||
* referenced. This means it is own by a different project but is referenced
|
||||
* by the root's parent. Returns <code>false</code> if the given root
|
||||
* doesn't have an underlying resource.
|
||||
*/
|
||||
public static boolean isReferenced(ISourceRoot root) {
|
||||
IResource resource= root.getResource();
|
||||
if (resource != null) {
|
||||
IProject project= resource.getProject();
|
||||
IProject container= root.getCProject().getProject();
|
||||
return !container.equals(project);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,4 +83,23 @@ public interface ICHelpContextIds {
|
|||
public static final String RENAME_FIELD_WIZARD_PAGE= PREFIX + "rename_field_wizard_page_context"; //$NON-NLS-1$
|
||||
public static final String RENAME_RESOURCE_WIZARD_PAGE= PREFIX + "rename_resource_wizard_page_context"; //$NON-NLS-1$
|
||||
|
||||
public static final String EDIT_WORKING_SET_ACTION= PREFIX + "edit_working_set_action"; //$NON-NLS-1$
|
||||
public static final String CLEAR_WORKING_SET_ACTION= PREFIX + "clear_working_set_action"; //$NON-NLS-1$
|
||||
public static final String SELECT_WORKING_SET_ACTION= PREFIX + "select_working_set_action"; //$NON-NLS-1$
|
||||
|
||||
// view parts
|
||||
public static final String TYPE_HIERARCHY_VIEW= PREFIX + "type_hierarchy_view_context"; //$NON-NLS-1$
|
||||
public static final String PACKAGES_VIEW= PREFIX + "package_view_context"; //$NON-NLS-1$
|
||||
public static final String PROJECTS_VIEW= PREFIX + "projects_view_context"; //$NON-NLS-1$
|
||||
public static final String PACKAGES_BROWSING_VIEW= PREFIX + "packages_browsing_view_context"; //$NON-NLS-1$
|
||||
public static final String TYPES_VIEW= PREFIX + "types_view_context"; //$NON-NLS-1$
|
||||
public static final String MEMBERS_VIEW= PREFIX + "members_view_context"; //$NON-NLS-1$
|
||||
|
||||
public static final String OPEN_C_BROWSING_PERSPECTIVE_ACTION = PREFIX + "open_c_browsing_perspective_action"; //$NON-NLS-1$
|
||||
public static final String OPEN_PROJECT_ACTION = PREFIX + "open_project_action"; //$NON-NLS-1$
|
||||
|
||||
public static final String OPEN_TYPE_ACTION = PREFIX + "open_type_action"; //$NON-NLS-1$
|
||||
public static final String OPEN_TYPE_IN_HIERARCHY_ACTION = PREFIX + "open_type_in_hierarchy_action"; //$NON-NLS-1$
|
||||
|
||||
public static final String LEXICAL_SORTING_BROWSING_ACTION= PREFIX + "lexical_sorting_browsing_action"; //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -14,10 +14,16 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IMethod;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.core.model.IStructure;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.ui.model.IWorkbenchAdapter;
|
||||
|
||||
|
@ -268,6 +274,14 @@ public class CElementLabels {
|
|||
|
||||
public static void getElementLabel(ICElement element, int flags, StringBuffer buf) {
|
||||
int type= element.getElementType();
|
||||
ISourceRoot root= null;
|
||||
|
||||
if (type != ICElement.C_MODEL && type != ICElement.C_PROJECT && !(type == ICElement.C_CCONTAINER && element instanceof ISourceRoot))
|
||||
root= CModelUtil.getSourceRoot(element);
|
||||
if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) {
|
||||
getSourceRootLabel(root, ROOT_QUALIFIED, buf);
|
||||
buf.append(CONCAT_STRING);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ICElement.C_METHOD :
|
||||
|
@ -277,7 +291,29 @@ public class CElementLabels {
|
|||
case ICElement.C_STRUCT:
|
||||
case ICElement.C_UNION:
|
||||
case ICElement.C_ENUMERATION:
|
||||
// getTypeLabel( (IType) element, flags, buf );
|
||||
getTypeLabel( element, flags, buf );
|
||||
break;
|
||||
case ICElement.C_UNIT:
|
||||
getTranslationUnitLabel((ITranslationUnit) element, flags, buf);
|
||||
break;
|
||||
case ICElement.C_CCONTAINER:
|
||||
ICContainer container = (ICContainer) element;
|
||||
if (container instanceof ISourceRoot)
|
||||
getSourceRootLabel((ISourceRoot) container, flags, buf);
|
||||
else
|
||||
getContainerLabel(container, flags, buf);
|
||||
break;
|
||||
case ICElement.C_PROJECT:
|
||||
case ICElement.C_MODEL:
|
||||
buf.append(element.getElementName());
|
||||
break;
|
||||
default:
|
||||
buf.append(element.getElementName());
|
||||
}
|
||||
|
||||
if (root != null && getFlag(flags, APPEND_ROOT_PATH)) {
|
||||
buf.append(CONCAT_STRING);
|
||||
getSourceRootLabel(root, ROOT_QUALIFIED, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,12 +391,104 @@ public class CElementLabels {
|
|||
}
|
||||
}
|
||||
|
||||
public static void getTypeLabel(ICElement type, int flags, StringBuffer buf) {
|
||||
if( !(type instanceof IStructure) ){
|
||||
return;
|
||||
/**
|
||||
* Appends the label for a source root to a StringBuffer. Considers the ROOT_* flags.
|
||||
*/
|
||||
public static void getSourceRootLabel(ISourceRoot root, int flags, StringBuffer buf) {
|
||||
// if (root.isArchive())
|
||||
// getArchiveLabel(root, flags, buf);
|
||||
// else
|
||||
getFolderLabel(root, flags, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the label for a container to a StringBuffer. Considers the ROOT_* flags.
|
||||
*/
|
||||
public static void getContainerLabel(ICContainer container, int flags, StringBuffer buf) {
|
||||
getFolderLabel(container, flags, buf);
|
||||
}
|
||||
|
||||
private static void getFolderLabel(ICContainer container, int flags, StringBuffer buf) {
|
||||
IResource resource= container.getResource();
|
||||
boolean rootQualified= getFlag(flags, ROOT_QUALIFIED);
|
||||
boolean referencedQualified= getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)
|
||||
&& (container instanceof ISourceRoot && CModelUtil.isReferenced((ISourceRoot)container))
|
||||
&& resource != null;
|
||||
if (rootQualified) {
|
||||
buf.append(container.getPath().makeRelative().toString());
|
||||
} else {
|
||||
if (resource != null)
|
||||
buf.append(resource.getProjectRelativePath().toString());
|
||||
else
|
||||
buf.append(container.getElementName());
|
||||
if (referencedQualified) {
|
||||
buf.append(CONCAT_STRING);
|
||||
buf.append(resource.getProject().getName());
|
||||
} else if (getFlag(flags, ROOT_POST_QUALIFIED)) {
|
||||
buf.append(CONCAT_STRING);
|
||||
buf.append(container.getParent().getElementName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the label for a translation unit to a StringBuffer. Considers the CU_* flags.
|
||||
*/
|
||||
public static void getTranslationUnitLabel(ITranslationUnit tu, int flags, StringBuffer buf) {
|
||||
if (getFlag(flags, CU_QUALIFIED)) {
|
||||
ISourceRoot root= CModelUtil.getSourceRoot(tu);
|
||||
// if (!pack.isDefaultPackage()) {
|
||||
buf.append(root.getElementName());
|
||||
buf.append('.');
|
||||
// }
|
||||
}
|
||||
buf.append(tu.getElementName());
|
||||
|
||||
if (getFlag(flags, CU_POST_QUALIFIED)) {
|
||||
buf.append(CONCAT_STRING);
|
||||
getSourceRootLabel((ISourceRoot) tu.getParent(), 0, buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the label for a type to a StringBuffer. Considers the T_* flags.
|
||||
*/
|
||||
public static void getTypeLabel(ICElement elem, int flags, StringBuffer buf) {
|
||||
if (getFlag(flags, T_FULLY_QUALIFIED)) {
|
||||
ISourceRoot root= CModelUtil.getSourceRoot(elem);
|
||||
getSourceRootLabel(root, (flags & P_COMPRESSED), buf);
|
||||
buf.append(root.getElementName());
|
||||
buf.append('.');
|
||||
}
|
||||
|
||||
String typeName= elem.getElementName();
|
||||
if (typeName.length() == 0) { // anonymous
|
||||
// try {
|
||||
// String superclassName= Signature.getSimpleName(type.getSuperclassName());
|
||||
// typeName= CUIMessages.getFormattedString("JavaElementLabels.anonym_type" , superclassName); //$NON-NLS-1$
|
||||
// } catch (CModelException e) {
|
||||
// //ignore
|
||||
// typeName= CUIMessages.getString("JavaElementLabels.anonym"); //$NON-NLS-1$
|
||||
// }
|
||||
}
|
||||
buf.append(typeName);
|
||||
|
||||
// // post qualification
|
||||
// if (getFlag(flags, T_POST_QUALIFIED)) {
|
||||
// buf.append(CONCAT_STRING);
|
||||
// IType declaringType= type.getDeclaringType();
|
||||
// if (declaringType != null) {
|
||||
// getTypeLabel(declaringType, T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf);
|
||||
// int parentType= type.getParent().getElementType();
|
||||
// if (parentType == ICElement.METHOD || parentType == ICElement.FIELD || parentType == ICElement.INITIALIZER) { // anonymous or local
|
||||
// buf.append('.');
|
||||
// getElementLabel(type.getParent(), 0, buf);
|
||||
// }
|
||||
// } else {
|
||||
// getPackageFragmentLabel(type.getPackageFragment(), (flags & P_COMPRESSED), buf);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private static boolean getFlag(int flags, int flag) {
|
||||
return (flags & flag) != 0;
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.browser.cbrowsing.ProblemsLabelDecorator.ProblemsLabelChangedEvent;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Item;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.Widget;
|
||||
|
||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
|
||||
/**
|
||||
* Extends a TableViewer to allow more performance when showing error ticks.
|
||||
* A <code>ProblemItemMapper</code> is contained that maps all items in
|
||||
* the tree to underlying resource
|
||||
*/
|
||||
public class ProblemTableViewer extends TableViewer {
|
||||
|
||||
protected ResourceToItemsMapper fResourceToItemsMapper;
|
||||
|
||||
/**
|
||||
* Constructor for ProblemTableViewer.
|
||||
* @param parent
|
||||
*/
|
||||
public ProblemTableViewer(Composite parent) {
|
||||
super(parent);
|
||||
initMapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for ProblemTableViewer.
|
||||
* @param parent
|
||||
* @param style
|
||||
*/
|
||||
public ProblemTableViewer(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
initMapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for ProblemTableViewer.
|
||||
* @param table
|
||||
*/
|
||||
public ProblemTableViewer(Table table) {
|
||||
super(table);
|
||||
initMapper();
|
||||
}
|
||||
|
||||
private void initMapper() {
|
||||
fResourceToItemsMapper= new ResourceToItemsMapper(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see StructuredViewer#mapElement(Object, Widget)
|
||||
*/
|
||||
protected void mapElement(Object element, Widget item) {
|
||||
super.mapElement(element, item);
|
||||
if (item instanceof Item) {
|
||||
fResourceToItemsMapper.addToMap(element, (Item) item);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see StructuredViewer#unmapElement(Object, Widget)
|
||||
*/
|
||||
protected void unmapElement(Object element, Widget item) {
|
||||
if (item instanceof Item) {
|
||||
fResourceToItemsMapper.removeFromMap(element, (Item) item);
|
||||
}
|
||||
super.unmapElement(element, item);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see StructuredViewer#unmapAllElements()
|
||||
*/
|
||||
protected void unmapAllElements() {
|
||||
fResourceToItemsMapper.clearMap();
|
||||
super.unmapAllElements();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ContentViewer#handleLabelProviderChanged(LabelProviderChangedEvent)
|
||||
*/
|
||||
protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
|
||||
if (event instanceof ProblemsLabelChangedEvent) {
|
||||
ProblemsLabelChangedEvent e= (ProblemsLabelChangedEvent) event;
|
||||
if (!e.isMarkerChange() && canIgnoreChangesFromAnnotionModel()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Object[] changed= event.getElements();
|
||||
if (changed != null && !fResourceToItemsMapper.isEmpty()) {
|
||||
ArrayList others= new ArrayList(changed.length);
|
||||
for (int i= 0; i < changed.length; i++) {
|
||||
Object curr= changed[i];
|
||||
if (curr instanceof IResource) {
|
||||
fResourceToItemsMapper.resourceChanged((IResource) curr);
|
||||
} else {
|
||||
others.add(curr);
|
||||
}
|
||||
}
|
||||
if (others.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
event= new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray());
|
||||
}
|
||||
super.handleLabelProviderChanged(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers whether this viewer can ignore label provider changes resulting from
|
||||
* marker changes in annotation models
|
||||
*/
|
||||
private boolean canIgnoreChangesFromAnnotionModel() {
|
||||
// Object contentProvider= getContentProvider();
|
||||
// return contentProvider instanceof IWorkingCopyProvider && !((IWorkingCopyProvider)contentProvider).providesWorkingCopies();
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Item;
|
||||
|
||||
import org.eclipse.jface.viewers.ContentViewer;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.IViewerLabelProvider;
|
||||
import org.eclipse.jface.viewers.ViewerLabel;
|
||||
|
||||
/**
|
||||
* Helper class for updating error markers and other decorators that work on resources.
|
||||
* Items are mapped to their element's underlying resource.
|
||||
* Method <code>resourceChanged</code> updates all items that are affected from the changed
|
||||
* elements.
|
||||
*/
|
||||
public class ResourceToItemsMapper {
|
||||
|
||||
private static final int NUMBER_LIST_REUSE= 10;
|
||||
|
||||
// map from resource to item
|
||||
private HashMap fResourceToItem;
|
||||
private Stack fReuseLists;
|
||||
|
||||
private ContentViewer fContentViewer;
|
||||
|
||||
public ResourceToItemsMapper(ContentViewer viewer) {
|
||||
fResourceToItem= new HashMap();
|
||||
fReuseLists= new Stack();
|
||||
|
||||
fContentViewer= viewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called from the UI thread.
|
||||
*/
|
||||
public void resourceChanged(IResource changedResource) {
|
||||
Object obj= fResourceToItem.get(changedResource);
|
||||
if (obj == null) {
|
||||
// not mapped
|
||||
} else if (obj instanceof Item) {
|
||||
updateItem((Item) obj);
|
||||
} else { // List of Items
|
||||
List list= (List) obj;
|
||||
for (int k= 0; k < list.size(); k++) {
|
||||
updateItem((Item) list.get(k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(Item item) {
|
||||
if (!item.isDisposed()) { // defensive code
|
||||
ILabelProvider lprovider= (ILabelProvider) fContentViewer.getLabelProvider();
|
||||
|
||||
Object data= item.getData();
|
||||
|
||||
// If it is an IItemLabelProvider than short circuit: patch Tod (bug 55012)
|
||||
if (lprovider instanceof IViewerLabelProvider) {
|
||||
IViewerLabelProvider provider= (IViewerLabelProvider) lprovider;
|
||||
|
||||
ViewerLabel updateLabel= new ViewerLabel(item.getText(), item.getImage());
|
||||
provider.updateLabel(updateLabel, data);
|
||||
|
||||
if (updateLabel.hasNewImage()) {
|
||||
item.setImage(updateLabel.getImage());
|
||||
}
|
||||
if (updateLabel.hasNewText()) {
|
||||
item.setText(updateLabel.getText());
|
||||
}
|
||||
} else {
|
||||
Image oldImage= item.getImage();
|
||||
Image image= lprovider.getImage(data);
|
||||
if (image != null && !image.equals(oldImage)) {
|
||||
item.setImage(image);
|
||||
}
|
||||
String oldText= item.getText();
|
||||
String text= lprovider.getText(data);
|
||||
if (text != null && !text.equals(oldText)) {
|
||||
item.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new item to the map.
|
||||
* @param element Element to map
|
||||
* @param item The item used for the element
|
||||
*/
|
||||
public void addToMap(Object element, Item item) {
|
||||
IResource resource= getCorrespondingResource(element);
|
||||
if (resource != null) {
|
||||
Object existingMapping= fResourceToItem.get(resource);
|
||||
if (existingMapping == null) {
|
||||
fResourceToItem.put(resource, item);
|
||||
} else if (existingMapping instanceof Item) {
|
||||
if (existingMapping != item) {
|
||||
List list= getNewList();
|
||||
list.add(existingMapping);
|
||||
list.add(item);
|
||||
fResourceToItem.put(resource, list);
|
||||
}
|
||||
} else { // List
|
||||
List list= (List) existingMapping;
|
||||
if (!list.contains(item)) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element from the map.
|
||||
*/
|
||||
public void removeFromMap(Object element, Item item) {
|
||||
IResource resource= getCorrespondingResource(element);
|
||||
if (resource != null) {
|
||||
Object existingMapping= fResourceToItem.get(resource);
|
||||
if (existingMapping == null) {
|
||||
return;
|
||||
} else if (existingMapping instanceof Item) {
|
||||
fResourceToItem.remove(resource);
|
||||
} else { // List
|
||||
List list= (List) existingMapping;
|
||||
list.remove(item);
|
||||
if (list.isEmpty()) {
|
||||
fResourceToItem.remove(list);
|
||||
releaseList(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List getNewList() {
|
||||
if (!fReuseLists.isEmpty()) {
|
||||
return (List) fReuseLists.pop();
|
||||
}
|
||||
return new ArrayList(2);
|
||||
}
|
||||
|
||||
private void releaseList(List list) {
|
||||
if (fReuseLists.size() < NUMBER_LIST_REUSE) {
|
||||
fReuseLists.push(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the map.
|
||||
*/
|
||||
public void clearMap() {
|
||||
fResourceToItem.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the map is empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return fResourceToItem.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that decides which elements can have error markers
|
||||
* Returns null if an element can not have error markers.
|
||||
*/
|
||||
private static IResource getCorrespondingResource(Object element) {
|
||||
if (element instanceof ICElement) {
|
||||
ICElement elem= (ICElement) element;
|
||||
if (!elem.isReadOnly()) { // only modifieable elements can get error ticks
|
||||
IResource res= elem.getResource();
|
||||
if (res == null) {
|
||||
ITranslationUnit cu= (ITranslationUnit) elem.getAncestor(ICElement.C_UNIT);
|
||||
if (cu != null) {
|
||||
// elements in compilation units are mapped to the underlying resource of the original cu
|
||||
res= cu.getResource();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
} else if (element instanceof IResource) {
|
||||
return (IResource) element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
/**
|
||||
* Interface common to all view parts that provide an input.
|
||||
*/
|
||||
public interface IViewPartInputProvider {
|
||||
|
||||
/**
|
||||
* Returns the input.
|
||||
*
|
||||
* @return the input object
|
||||
*/
|
||||
public Object getViewPartInput();
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ImageImageDescriptor extends ImageDescriptor {
|
||||
|
||||
private Image fImage;
|
||||
|
||||
/**
|
||||
* Constructor for ImagImageDescriptor.
|
||||
*/
|
||||
public ImageImageDescriptor(Image image) {
|
||||
super();
|
||||
fImage= image;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ImageDescriptor#getImageData()
|
||||
*/
|
||||
public ImageData getImageData() {
|
||||
return fImage.getImageData();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see Object#equals(Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
return (obj != null) && getClass().equals(obj.getClass()) && fImage.equals(((ImageImageDescriptor)obj).fImage);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return fImage.hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.workingsets.WorkingSetMessages;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
|
||||
/**
|
||||
* Clears the selected working set in the action group's view.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ClearWorkingSetAction extends Action {
|
||||
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public ClearWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
|
||||
super(WorkingSetMessages.getString("ClearWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("ClearWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
setEnabled(actionGroup.getWorkingSet() != null);
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.CLEAR_WORKING_SET_ACTION);
|
||||
fActionGroup= actionGroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
fActionGroup.setWorkingSet(null, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
|
||||
|
||||
/**
|
||||
* Displays an IWorkingSetEditWizard for editing a working set.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class EditWorkingSetAction extends Action {
|
||||
private Shell fShell;
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
|
||||
super(WorkingSetMessages.getString("EditWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("EditWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
setEnabled(actionGroup.getWorkingSet() != null);
|
||||
fShell= shell;
|
||||
fActionGroup= actionGroup;
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.EDIT_WORKING_SET_ACTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
if (fShell == null)
|
||||
fShell= CUIPlugin.getActiveWorkbenchShell();
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
IWorkingSet workingSet= fActionGroup.getWorkingSet();
|
||||
if (workingSet == null) {
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet);
|
||||
if (wizard == null) {
|
||||
String title= WorkingSetMessages.getString("EditWorkingSetAction.nowizard.title"); //$NON-NLS-1$
|
||||
String message= WorkingSetMessages.getString("EditWorkingSetAction.nowizard.message"); //$NON-NLS-1$
|
||||
MessageDialog.openError(fShell, title, message);
|
||||
return;
|
||||
}
|
||||
WizardDialog dialog= new WizardDialog(fShell, wizard);
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK)
|
||||
fActionGroup.setWorkingSet(wizard.getSelection(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
|
||||
/**
|
||||
* Displays an IWorkingSetSelectionDialog and sets the selected
|
||||
* working set in the action group's view.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SelectWorkingSetAction extends Action {
|
||||
private Shell fShell;
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
|
||||
super(WorkingSetMessages.getString("SelectWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("SelectWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
|
||||
fShell= shell;
|
||||
fActionGroup= actionGroup;
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.SELECT_WORKING_SET_ACTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
if (fShell == null)
|
||||
fShell= CUIPlugin.getActiveWorkbenchShell();
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
IWorkingSetSelectionDialog dialog= manager.createWorkingSetSelectionDialog(fShell, false);
|
||||
IWorkingSet workingSet= fActionGroup.getWorkingSet();
|
||||
if (workingSet != null)
|
||||
dialog.setSelection(new IWorkingSet[]{workingSet});
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
IWorkingSet[] result= dialog.getSelection();
|
||||
if (result != null && result.length > 0) {
|
||||
fActionGroup.setWorkingSet(result[0], true);
|
||||
manager.addRecentWorkingSet(result[0]);
|
||||
}
|
||||
else
|
||||
fActionGroup.setWorkingSet(null, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
class WorkingSetComparator implements Comparator {
|
||||
|
||||
private Collator fCollator= Collator.getInstance();
|
||||
|
||||
/*
|
||||
* @see Comparator#compare(Object, Object)
|
||||
*/
|
||||
public int compare(Object o1, Object o2) {
|
||||
String name1= null;
|
||||
String name2= null;
|
||||
|
||||
if (o1 instanceof IWorkingSet)
|
||||
name1= ((IWorkingSet)o1).getName();
|
||||
|
||||
if (o2 instanceof IWorkingSet)
|
||||
name2= ((IWorkingSet)o2).getName();
|
||||
|
||||
return fCollator.compare(name1, name2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IPathEntryContainer;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
/**
|
||||
* Working set filter for Java viewers.
|
||||
*/
|
||||
public class WorkingSetFilter extends ViewerFilter {
|
||||
private IWorkingSet fWorkingSet= null;
|
||||
private IAdaptable[] fCachedWorkingSet= null;
|
||||
|
||||
/**
|
||||
* Returns the working set which is used by this filter.
|
||||
*
|
||||
* @return the working set
|
||||
*/
|
||||
public IWorkingSet getWorkingSet() {
|
||||
return fWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this filter's working set.
|
||||
*
|
||||
* @param workingSet the working set
|
||||
*/
|
||||
public void setWorkingSet(IWorkingSet workingSet) {
|
||||
fWorkingSet= workingSet;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ViewerFilter.
|
||||
*/
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (fWorkingSet == null)
|
||||
return true;
|
||||
|
||||
if (element instanceof ICElement)
|
||||
return isEnclosing((ICElement)element);
|
||||
|
||||
if (element instanceof IResource)
|
||||
return isEnclosing(((IResource)element).getFullPath());
|
||||
|
||||
if (element instanceof IPathEntryContainer) {
|
||||
return isEnclosing((IPathEntryContainer)element);
|
||||
}
|
||||
|
||||
if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable= (IAdaptable)element;
|
||||
ICElement je= (ICElement)adaptable.getAdapter(ICElement.class);
|
||||
if (je != null)
|
||||
return isEnclosing(je);
|
||||
|
||||
IResource resource= (IResource)adaptable.getAdapter(IResource.class);
|
||||
if (resource != null)
|
||||
return isEnclosing(resource.getFullPath());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IPathEntryContainer container) {
|
||||
// check whether the containing packagefragment root is enclosed
|
||||
return isEnclosing(container.getPath());
|
||||
// IPathEntry[] entries = container.getPathEntries();
|
||||
// if (entries != null && entries.length > 0) {
|
||||
// return isEnclosing(entries[0].getPath());
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ViewerFilter
|
||||
*/
|
||||
public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
|
||||
Object[] result= null;
|
||||
if (fWorkingSet != null)
|
||||
fCachedWorkingSet= fWorkingSet.getElements();
|
||||
try {
|
||||
result= super.filter(viewer, parent, elements);
|
||||
} finally {
|
||||
fCachedWorkingSet= null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IPath elementPath) {
|
||||
if (elementPath == null)
|
||||
return false;
|
||||
|
||||
IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
|
||||
if (cachedWorkingSet == null)
|
||||
cachedWorkingSet= fWorkingSet.getElements();
|
||||
|
||||
int length= cachedWorkingSet.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
if (isEnclosing(cachedWorkingSet[i], elementPath))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnclosing(ICElement element) {
|
||||
IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
|
||||
if (cachedWorkingSet == null)
|
||||
cachedWorkingSet= fWorkingSet.getElements();
|
||||
|
||||
boolean isElementPathComputed= false;
|
||||
IPath elementPath= null; // will be lazy computed if needed
|
||||
|
||||
int length= cachedWorkingSet.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
ICElement scopeElement= (ICElement)cachedWorkingSet[i].getAdapter(ICElement.class);
|
||||
if (scopeElement != null) {
|
||||
// compare Java elements
|
||||
ICElement searchedElement= element;
|
||||
while (scopeElement != null && searchedElement != null) {
|
||||
if (searchedElement.equals(scopeElement))
|
||||
return true;
|
||||
else {
|
||||
if (scopeElement instanceof ICProject && searchedElement instanceof ISourceRoot) {
|
||||
// ISourceRoot pkgRoot= (ISourceRoot)searchedElement;
|
||||
// if (pkgRoot.isExternal() && pkgRoot.isArchive()) {
|
||||
// if (((ICProject)scopeElement).isOnClasspath(searchedElement))
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
searchedElement= searchedElement.getParent();
|
||||
if (searchedElement != null && searchedElement.getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit cu= (ITranslationUnit)searchedElement;
|
||||
cu= CModelUtil.toOriginal(cu);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (scopeElement != null && element != null) {
|
||||
if (element.equals(scopeElement))
|
||||
return true;
|
||||
else
|
||||
scopeElement= scopeElement.getParent();
|
||||
}
|
||||
} else {
|
||||
// compare resource paths
|
||||
if (!isElementPathComputed) {
|
||||
IResource elementResource= (IResource)element.getAdapter(IResource.class);
|
||||
if (elementResource != null)
|
||||
elementPath= elementResource.getFullPath();
|
||||
}
|
||||
if (isEnclosing(cachedWorkingSet[i], elementPath))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IAdaptable element, IPath path) {
|
||||
if (path == null)
|
||||
return false;
|
||||
|
||||
IPath elementPath= null;
|
||||
|
||||
IResource elementResource= (IResource)element.getAdapter(IResource.class);
|
||||
if (elementResource != null)
|
||||
elementPath= elementResource.getFullPath();
|
||||
|
||||
if (elementPath == null) {
|
||||
ICElement cElement= (ICElement)element.getAdapter(ICElement.class);
|
||||
if (cElement != null)
|
||||
elementPath= cElement.getPath();
|
||||
}
|
||||
|
||||
if (elementPath == null && element instanceof IStorage)
|
||||
elementPath= ((IStorage)element).getFullPath();
|
||||
|
||||
if (elementPath == null)
|
||||
return false;
|
||||
|
||||
if (elementPath.isPrefixOf(path))
|
||||
return true;
|
||||
|
||||
if (path.isPrefixOf(elementPath))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
|
||||
/**
|
||||
* Working set filter actions (set / clear)
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class WorkingSetFilterActionGroup extends ActionGroup {
|
||||
|
||||
private static final String TAG_WORKING_SET_NAME= "workingSetName"; //$NON-NLS-1$
|
||||
private static final String SEPARATOR_ID= "workingSetGroupSeparator"; //$NON-NLS-1$
|
||||
|
||||
private WorkingSetFilter fWorkingSetFilter;
|
||||
|
||||
private IWorkingSet fWorkingSet= null;
|
||||
|
||||
private ClearWorkingSetAction fClearWorkingSetAction;
|
||||
private SelectWorkingSetAction fSelectWorkingSetAction;
|
||||
private EditWorkingSetAction fEditWorkingSetAction;
|
||||
|
||||
private IPropertyChangeListener fWorkingSetListener;
|
||||
|
||||
private IPropertyChangeListener fChangeListener;
|
||||
|
||||
private int fLRUMenuCount;
|
||||
private IMenuManager fMenuManager;
|
||||
private IMenuListener fMenuListener;
|
||||
|
||||
public WorkingSetFilterActionGroup(String viewId, Shell shell, IPropertyChangeListener changeListener) {
|
||||
Assert.isNotNull(viewId);
|
||||
Assert.isNotNull(shell);
|
||||
Assert.isNotNull(changeListener);
|
||||
|
||||
fChangeListener= changeListener;
|
||||
fClearWorkingSetAction= new ClearWorkingSetAction(this);
|
||||
fSelectWorkingSetAction= new SelectWorkingSetAction(this, shell);
|
||||
fEditWorkingSetAction= new EditWorkingSetAction(this, shell);
|
||||
|
||||
fWorkingSetListener= new IPropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
doPropertyChange(event);
|
||||
}
|
||||
};
|
||||
|
||||
fWorkingSetFilter= new WorkingSetFilter();
|
||||
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
manager.addPropertyChangeListener(fWorkingSetListener);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current working set filters the given element
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param object the elemnt to test
|
||||
* @return the working set
|
||||
*/
|
||||
public boolean isFiltered(Object parent, Object object) {
|
||||
if (fWorkingSetFilter == null)
|
||||
return false;
|
||||
return !fWorkingSetFilter.select(null, parent, object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the working set which is used by the filter.
|
||||
*
|
||||
* @return the working set
|
||||
*/
|
||||
public IWorkingSet getWorkingSet() {
|
||||
return fWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this filter's working set.
|
||||
*
|
||||
* @param workingSet the working set
|
||||
* @param refreshViewer Indiactes if the viewer should be refreshed.
|
||||
*/
|
||||
public void setWorkingSet(IWorkingSet workingSet, boolean refreshViewer) {
|
||||
// Update action
|
||||
fClearWorkingSetAction.setEnabled(workingSet != null);
|
||||
fEditWorkingSetAction.setEnabled(workingSet != null);
|
||||
|
||||
fWorkingSet= workingSet;
|
||||
|
||||
fWorkingSetFilter.setWorkingSet(workingSet);
|
||||
if (refreshViewer) {
|
||||
fChangeListener.propertyChange(new PropertyChangeEvent(this, IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null, workingSet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the state of the filter actions in a memento.
|
||||
*
|
||||
* @param memento the memento
|
||||
*/
|
||||
public void saveState(IMemento memento) {
|
||||
String workingSetName= ""; //$NON-NLS-1$
|
||||
if (fWorkingSet != null)
|
||||
workingSetName= fWorkingSet.getName();
|
||||
memento.putString(TAG_WORKING_SET_NAME, workingSetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the state of the filter actions from a memento.
|
||||
* <p>
|
||||
* Note: This method does not refresh the viewer.
|
||||
* </p>
|
||||
* @param memento
|
||||
*/
|
||||
public void restoreState(IMemento memento) {
|
||||
String workingSetName= memento.getString(TAG_WORKING_SET_NAME);
|
||||
IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
|
||||
setWorkingSet(ws, false);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ActionGroup#fillActionBars(IActionBars)
|
||||
*/
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
contributeToToolBar(actionBars.getToolBarManager());
|
||||
contributeToMenu(actionBars.getMenuManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filter actions to the tool bar
|
||||
*
|
||||
* @param tbm the tool bar manager
|
||||
*/
|
||||
public void contributeToToolBar(IToolBarManager tbm) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filter actions to the menu
|
||||
*
|
||||
* @param mm the menu manager
|
||||
*/
|
||||
public void contributeToMenu(IMenuManager mm) {
|
||||
mm.add(fSelectWorkingSetAction);
|
||||
mm.add(fClearWorkingSetAction);
|
||||
mm.add(fEditWorkingSetAction);
|
||||
mm.add(new Separator());
|
||||
mm.add(new Separator(SEPARATOR_ID));
|
||||
addLRUWorkingSetActions(mm);
|
||||
|
||||
fMenuManager= mm;
|
||||
fMenuListener= new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
removePreviousLRUWorkingSetActions(manager);
|
||||
addLRUWorkingSetActions(manager);
|
||||
}
|
||||
};
|
||||
fMenuManager.addMenuListener(fMenuListener);
|
||||
}
|
||||
|
||||
private void removePreviousLRUWorkingSetActions(IMenuManager mm) {
|
||||
for (int i= 1; i <= fLRUMenuCount; i++)
|
||||
mm.remove(WorkingSetMenuContributionItem.getId(i));
|
||||
}
|
||||
|
||||
private void addLRUWorkingSetActions(IMenuManager mm) {
|
||||
IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getRecentWorkingSets();
|
||||
List sortedWorkingSets= Arrays.asList(workingSets);
|
||||
Collections.sort(sortedWorkingSets, new WorkingSetComparator());
|
||||
|
||||
Iterator iter= sortedWorkingSets.iterator();
|
||||
int i= 0;
|
||||
while (iter.hasNext()) {
|
||||
IWorkingSet workingSet= (IWorkingSet)iter.next();
|
||||
if (workingSet != null) {
|
||||
IContributionItem item= new WorkingSetMenuContributionItem(++i, this, workingSet);
|
||||
mm.insertBefore(SEPARATOR_ID, item);
|
||||
}
|
||||
}
|
||||
fLRUMenuCount= i;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ActionGroup#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fMenuManager != null)
|
||||
fMenuManager.removeMenuListener(fMenuListener);
|
||||
|
||||
if (fWorkingSetListener != null) {
|
||||
PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(fWorkingSetListener);
|
||||
fWorkingSetListener= null;
|
||||
}
|
||||
fChangeListener= null; // clear the reference to the viewer
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns viewer filter always confugured with the current working set.
|
||||
*/
|
||||
public ViewerFilter getWorkingSetFilter() {
|
||||
return fWorkingSetFilter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the working set change listener
|
||||
*/
|
||||
private void doPropertyChange(PropertyChangeEvent event) {
|
||||
String property= event.getProperty();
|
||||
if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property)) {
|
||||
fChangeListener.propertyChange(event);
|
||||
} else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) {
|
||||
IWorkingSet newWorkingSet= (IWorkingSet) event.getNewValue();
|
||||
if (newWorkingSet.equals(fWorkingSet)) {
|
||||
fChangeListener.propertyChange(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Menu contribution item which shows and lets select a working set.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class WorkingSetMenuContributionItem extends ContributionItem {
|
||||
|
||||
private int fId;
|
||||
private IWorkingSet fWorkingSet;
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
private Image fImage;
|
||||
|
||||
/**
|
||||
* Constructor for WorkingSetMenuContributionItem.
|
||||
*
|
||||
* @param id the id
|
||||
* @param actionGroup the action group
|
||||
* @param workingSet the working set
|
||||
*/
|
||||
public WorkingSetMenuContributionItem(int id, WorkingSetFilterActionGroup actionGroup, IWorkingSet workingSet) {
|
||||
super(getId(id));
|
||||
Assert.isNotNull(actionGroup);
|
||||
Assert.isNotNull(workingSet);
|
||||
fId= id;
|
||||
fActionGroup= actionGroup;
|
||||
fWorkingSet= workingSet;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ContributionItem.
|
||||
*/
|
||||
public void fill(Menu menu, int index) {
|
||||
MenuItem mi= new MenuItem(menu, SWT.RADIO, index);
|
||||
mi.setText("&" + fId + " " + fWorkingSet.getName()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (fImage == null)
|
||||
fImage= fWorkingSet.getImage().createImage();
|
||||
mi.setImage(fImage);
|
||||
mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
|
||||
mi.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
fActionGroup.setWorkingSet(fWorkingSet, true);
|
||||
manager.addRecentWorkingSet(fWorkingSet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.action.ContributionItem#dispose()
|
||||
* @since 3.0
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fImage != null && !fImage.isDisposed())
|
||||
fImage.dispose();
|
||||
fImage= null;
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.action.IContributionItem#isDynamic()
|
||||
*/
|
||||
public boolean isDynamic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static String getId(int id) {
|
||||
return WorkingSetMenuContributionItem.class.getName() + "." + id; //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
|||
import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring;
|
||||
import org.eclipse.cdt.internal.ui.CElementAdapterFactory;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.ICStatusConstants;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.ResourceAdapterFactory;
|
||||
import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager;
|
||||
|
@ -102,6 +103,61 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
|
||||
private static final String CONTENTASSIST = CUIPlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* The id of the C perspective
|
||||
* (value <code>"org.eclipse.cdt.ui.CPerspective"</code>).
|
||||
*/
|
||||
public static final String ID_CPERSPECTIVE = PLUGIN_ID + ".CPerspective"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The id of the C hierarchy perspective
|
||||
* (value <code>"org.eclipse.cdt.ui.CHierarchyPerspective"</code>).
|
||||
*/
|
||||
public static final String ID_CHIERARCHY_PERSPECTIVE = PLUGIN_ID + ".CHierarchyPerspective"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The id of the C Browsing Perspective
|
||||
* (value <code>"org.eclipse.cdt.ui.CBrowsingPerspective"</code>).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final String ID_CBROWSING_PERSPECTIVE = PLUGIN_ID + ".CBrowsingPerspective"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The view part id of the C Browsing Projects view
|
||||
* (value <code>"org.eclipse.cdt.ui.ProjectsView"</code>).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static String ID_PROJECTS_VIEW = PLUGIN_ID + ".ProjectsView"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The view part id of the C Browsing Namespaces view
|
||||
* (value <code>"org.eclipse.cdt.ui.NamespacesView"</code>).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static String ID_NAMESPACES_VIEW = PLUGIN_ID + ".NamespacesView"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The view part id of the C Browsing Types view
|
||||
* (value <code>"org.eclipse.cdt.ui.TypesView"</code>).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static String ID_TYPES_VIEW = PLUGIN_ID + ".TypesView"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The view part id of the C Browsing Members view
|
||||
* (value <code>"org.eclipse.cdt.ui.MembersView"</code>).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$
|
||||
|
||||
|
||||
|
||||
// -------- static methods --------
|
||||
|
||||
static {
|
||||
|
@ -183,6 +239,11 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
getLog().log(status);
|
||||
}
|
||||
|
||||
public void logErrorMessage(String message) {
|
||||
log(new Status(IStatus.ERROR, getPluginId(), ICStatusConstants.INTERNAL_ERROR, message, null));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility method with conventions
|
||||
*/
|
||||
|
|
|
@ -147,6 +147,74 @@ public class PreferenceConstants {
|
|||
public static final String REFACTOR_OK_SEVERITY= "0"; //$NON-NLS-1$
|
||||
public static final String REFACTOR_SAVE_ALL_EDITORS= "Refactoring.savealleditors"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* A named preference that controls if the C Browsing views are linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*
|
||||
* @see #LINK_PACKAGES_TO_EDITOR
|
||||
*/
|
||||
public static final String BROWSING_LINK_VIEW_TO_EDITOR= "org.eclipse.cdt.ui.browsing.linktoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls the layout of the C Browsing views vertically. Boolean value.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>. If <code>true<code> the views are stacked vertical.
|
||||
* If <code>false</code> they are stacked horizontal.
|
||||
* </p>
|
||||
*/
|
||||
public static final String BROWSING_STACK_VERTICALLY= "org.eclipse.cdt.ui.browsing.stackVertically"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the hierarchy view's selection is linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
*/
|
||||
public static final String LINK_TYPEHIERARCHY_TO_EDITOR= "org.eclipse.cdt.ui.packages.linktypehierarchytoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the projects view's selection is
|
||||
* linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
* @since 2.1
|
||||
*/
|
||||
public static final String LINK_BROWSING_PROJECTS_TO_EDITOR= "org.eclipse.cdt.ui.browsing.projectstoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the namespace view's selection is
|
||||
* linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
* @since 2.1
|
||||
*/
|
||||
public static final String LINK_BROWSING_PACKAGES_TO_EDITOR= "org.eclipse.cdt.ui.browsing.packagestoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the types view's selection is
|
||||
* linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
* @since 2.1
|
||||
*/
|
||||
public static final String LINK_BROWSING_TYPES_TO_EDITOR= "org.eclipse.cdt.ui.browsing.typestoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the members view's selection is
|
||||
* linked to the active editor.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
* @since 2.1
|
||||
*/
|
||||
public static final String LINK_BROWSING_MEMBERS_TO_EDITOR= "org.eclipse.cdt.ui.browsing.memberstoeditor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the JDT-UI preference store.
|
||||
*
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.core.browser.ITypeInfo;
|
|||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.browser.ITypeSearchScope;
|
||||
import org.eclipse.cdt.core.browser.QualifiedTypeName;
|
||||
import org.eclipse.cdt.core.browser.TypeInfo;
|
||||
import org.eclipse.cdt.core.browser.UnknownTypeInfo;
|
||||
import org.eclipse.cdt.core.browser.TypeSearchScope;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
|
@ -1064,7 +1064,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
if (elements == null || elements.length == 0)
|
||||
return null;
|
||||
|
||||
TypeInfo key = new TypeInfo(0, typeName, null);
|
||||
ITypeInfo key = new UnknownTypeInfo(typeName);
|
||||
int index = Arrays.binarySearch(elements, key, TYPE_NAME_COMPARATOR);
|
||||
if (index >= 0 && index < elements.length) {
|
||||
for (int i = index - 1; i >= 0; --i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue