true
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.
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfo.java
index 84519f65cc9..6943508b7ce 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfo.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfo.java
@@ -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 null
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 null
if not found.
+ */
+ public ITypeInfo getEnclosingType(int[] kinds);
+
+ /** Gets the root namespace, i.e. the outermost namespace
+ * which contains this type.
+ * @param includeGlobalNamespace true
if the global (default) namespace should be returned
+ * @return the namespace, or null
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 null
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);
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfoVisitor.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfoVisitor.java
index 39769d2dff8..87dfaa9a3fd 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfoVisitor.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeInfoVisitor.java
@@ -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();
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java
index 47581b047ea..0c0783fc1c9 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java
@@ -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 enclosingType;
+ return null;
+ }
+
+ public ITypeInfo getEnclosingType() {
+ return getEnclosingType(KNOWN_TYPES);
}
+ public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
+ if (fTypeCache != null) {
+ return fTypeCache.getRootNamespace(this, true);
+ }
+ 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;
-
- default:
- return false;
- }
+ return ArrayUtil.contains(KNOWN_TYPES, type);
+ }
+
+ public ITypeCache getCache() {
+ return fTypeCache;
+ }
+
+ public void setCache(ITypeCache typeCache) {
+ fTypeCache = typeCache;
}
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/UnknownTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/UnknownTypeInfo.java
new file mode 100644
index 00000000000..71e6fd68005
--- /dev/null
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/UnknownTypeInfo.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java
index 2a5a6f631f1..2f632033c6a 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java
@@ -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 null
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 true
if the global (default) namespace should be returned
+ * @return the enclosing namespace, or null
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 true
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();
}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerTypesJob.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerTypesJob.java
index 33bdc1bc1b4..03002c1eb9f 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerTypesJob.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/IndexerTypesJob.java
@@ -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);
- fTypeCache.insert(info);
- } else {
- info.setCElementType(type);
- }
+ // add new type to cache
+ info = new TypeInfo(type, qualifiedName);
+ fTypeCache.insert(info);
+
for (int i = 0; i < references.length; ++i) {
if (monitor.isCanceled())
throw new InterruptedException();
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
index d36fd10e347..546fb504685 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
@@ -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,7 +48,8 @@ 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) {
+ 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 typeName = info.getQualifiedTypeName().getEnclosingTypeName();
- if (typeName != null) {
- while (!typeName.isEmpty()) {
+ IQualifiedTypeName enclosingName = newType.getQualifiedTypeName().getEnclosingTypeName();
+ if (enclosingName != null) {
+ while (!enclosingName.isEmpty()) {
boolean foundType = false;
- Collection typeCollection = (Collection) fTypeNameMap.get(typeName.getName());
- if (typeCollection == null) {
- typeCollection = new HashSet();
- fTypeNameMap.put(typeName.getName(), typeCollection);
+ Collection enclosingCollection = (Collection) fTypeNameMap.get(enclosingName.getName());
+ if (enclosingCollection == null) {
+ enclosingCollection = new HashSet();
+ fTypeNameMap.put(enclosingName.getName(), enclosingCollection);
} else {
- for (Iterator typeIter = typeCollection.iterator(); typeIter.hasNext(); ) {
+ 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();
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheMessages.properties b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheMessages.properties
index bfdf6461efa..059511df834 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheMessages.properties
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeCacheMessages.properties
@@ -17,3 +17,5 @@ TypeCacherJob.taskName=Updating Type Cache...
TypeLocatorJob.jobName=Type Locator
TypeLocatorJob.taskName=Searching for Type Declaration...
+
+TypeCache.globalNamespace=(global)
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java
index a2e50588490..a6e31a798a2 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java
@@ -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);
- fTypeCache.insert(info);
- } else {
- info.setCElementType(type);
- }
+ // add new type to cache
+ info = new TypeInfo(type, qualifiedName);
+ fTypeCache.insert(info);
TypeReference location;
if (originalRef instanceof IWorkingCopy) {
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index bed54b1b9ec..1cc91783c42 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -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
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/AppearanceAwareLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/AppearanceAwareLabelProvider.java
new file mode 100644
index 00000000000..da124b7a2ef
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/AppearanceAwareLabelProvider.java
@@ -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;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingContentProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingContentProvider.java
new file mode 100644
index 00000000000..2f97bd9f5a3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingContentProvider.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.java
new file mode 100644
index 00000000000..1a71e67ddd3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.properties b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.properties
index fb3e25c0d9c..e9fe8baee02 100644
--- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.properties
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingMessages.properties
@@ -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)
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java
new file mode 100644
index 00000000000..7686d25971e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java
@@ -0,0 +1,1685 @@
+/*******************************************************************************
+ * 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.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.core.browser.AllTypesCache;
+import org.eclipse.cdt.core.browser.ITypeInfo;
+import org.eclipse.cdt.core.browser.ITypeReference;
+import org.eclipse.cdt.core.browser.TypeSearchScope;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+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.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.resources.FileStorage;
+import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages;
+import org.eclipse.cdt.internal.ui.editor.CEditor;
+import org.eclipse.cdt.internal.ui.search.CElementLabels;
+import org.eclipse.cdt.internal.ui.util.EditorUtility;
+import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
+import org.eclipse.cdt.internal.ui.util.ProblemTableViewer;
+import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
+import org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilterActionGroup;
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+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.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.IShowInSource;
+import org.eclipse.ui.part.ShowInContext;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public abstract class CBrowsingPart extends ViewPart implements IMenuListener, ISelectionListener, IViewPartInputProvider {
+
+ private static final String TAG_SELECTED_ELEMENTS= "selectedElements"; //$NON-NLS-1$
+ private static final String TAG_SELECTED_ELEMENT= "selectedElement"; //$NON-NLS-1$
+ private static final String TAG_LOGICAL_PACKAGE= "logicalPackage"; //$NON-NLS-1$
+ private static final String TAG_SELECTED_ELEMENT_PATH= "selectedElementPath"; //$NON-NLS-1$
+
+ private LabelProvider fLabelProvider;
+ private ILabelProvider fTitleProvider;
+ private StructuredViewer fViewer;
+ private IMemento fMemento;
+ private TypeInfoComparator fTypeComparator;
+
+ // Actions
+ private WorkingSetFilterActionGroup fWorkingSetFilterActionGroup;
+ private boolean fHasWorkingSetFilter= true;
+ private boolean fHasCustomFilter= true;
+// private OpenEditorActionGroup fOpenEditorGroup;
+// private CCPActionGroup fCCPActionGroup;
+// private BuildActionGroup fBuildActionGroup;
+// private ToggleLinkingAction fToggleLinkingAction;
+// protected CompositeActionGroup fActionGroups;
+
+
+// // Filters
+// private CustomFiltersActionGroup fCustomFiltersActionGroup;
+
+ protected IWorkbenchPart fPreviousSelectionProvider;
+ protected Object fPreviousSelectedElement;
+
+ // Linking
+ private boolean fLinkingEnabled;
+
+ /*
+ * Ensure selection changed events being processed only if
+ * initiated by user interaction with this part.
+ */
+ private boolean fProcessSelectionEvents= true;
+
+ private IPartListener2 fPartListener= new IPartListener2() {
+ public void partActivated(IWorkbenchPartReference ref) {
+ setSelectionFromEditor(ref);
+ }
+ public void partBroughtToTop(IWorkbenchPartReference ref) {
+ setSelectionFromEditor(ref);
+ }
+ public void partInputChanged(IWorkbenchPartReference ref) {
+ setSelectionFromEditor(ref);
+ }
+ public void partClosed(IWorkbenchPartReference ref) {
+ }
+ public void partDeactivated(IWorkbenchPartReference ref) {
+ }
+ public void partOpened(IWorkbenchPartReference ref) {
+ }
+ public void partVisible(IWorkbenchPartReference ref) {
+ if (ref != null && ref.getId() == getSite().getId()){
+ fProcessSelectionEvents= true;
+ IWorkbenchPage page= getSite().getWorkbenchWindow().getActivePage();
+ if (page != null)
+ selectionChanged(page.getActivePart(), page.getSelection());
+ }
+ }
+ public void partHidden(IWorkbenchPartReference ref) {
+ if (ref != null && ref.getId() == getSite().getId())
+ fProcessSelectionEvents= false;
+ }
+ };
+
+ public CBrowsingPart() {
+ super();
+ initLinkingEnabled();
+ }
+
+ /*
+ * Implements method from IViewPart.
+ */
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ super.init(site, memento);
+ fMemento= memento;
+ }
+
+ /*
+ * Implements method from IViewPart.
+ */
+ public void saveState(IMemento memento) {
+ if (fViewer == null) {
+ // part has not been created
+ if (fMemento != null) //Keep the old state;
+ memento.putMemento(fMemento);
+ return;
+ }
+ if (fHasWorkingSetFilter)
+ fWorkingSetFilterActionGroup.saveState(memento);
+// if (fHasCustomFilter)
+// fCustomFiltersActionGroup.saveState(memento);
+ saveSelectionState(memento);
+ saveLinkingEnabled(memento);
+ }
+
+ private void saveLinkingEnabled(IMemento memento) {
+ memento.putInteger(getLinkToEditorKey(), fLinkingEnabled ? 1 : 0);
+ }
+
+ private void saveSelectionState(IMemento memento) {
+/* Object elements[]= ((IStructuredSelection) fViewer.getSelection()).toArray();
+ if (elements.length > 0) {
+ IMemento selectionMem= memento.createChild(TAG_SELECTED_ELEMENTS);
+ for (int i= 0; i < elements.length; i++) {
+ IMemento elementMem= selectionMem.createChild(TAG_SELECTED_ELEMENT);
+ Object o= elements[i];
+ if (o instanceof ICElement)
+ elementMem.putString(TAG_SELECTED_ELEMENT_PATH, ((ICElement) elements[i]).getHandleIdentifier());
+ else if (o instanceof LogicalPackage) {
+ IPackageFragment[] packages=((LogicalPackage)o).getFragments();
+ for (int j= 0; j < packages.length; j++) {
+ IMemento packageMem= elementMem.createChild(TAG_LOGICAL_PACKAGE);
+ packageMem.putString(TAG_SELECTED_ELEMENT_PATH, packages[j].getHandleIdentifier());
+ }
+ }
+ }
+ }
+*/
+ }
+
+ protected void restoreState(IMemento memento) {
+ if (fHasWorkingSetFilter)
+ fWorkingSetFilterActionGroup.restoreState(memento);
+// if (fHasCustomFilter)
+// fCustomFiltersActionGroup.restoreState(memento);
+
+ if (fHasCustomFilter || fHasWorkingSetFilter) {
+ fViewer.getControl().setRedraw(false);
+ fViewer.refresh();
+ fViewer.getControl().setRedraw(true);
+ }
+ }
+
+ private ISelection restoreSelectionState(IMemento memento) {
+/*
+ if (memento == null)
+ return null;
+
+ IMemento childMem;
+ childMem= memento.getChild(TAG_SELECTED_ELEMENTS);
+ if (childMem != null) {
+ ArrayList list= new ArrayList();
+ IMemento[] elementMem= childMem.getChildren(TAG_SELECTED_ELEMENT);
+ for (int i= 0; i < elementMem.length; i++) {
+ String javaElementHandle= elementMem[i].getString(TAG_SELECTED_ELEMENT_PATH);
+ if (javaElementHandle == null) {
+ // logical package
+ IMemento[] packagesMem= elementMem[i].getChildren(TAG_LOGICAL_PACKAGE);
+ LogicalPackage lp= null;
+ for (int j= 0; j < packagesMem.length; j++) {
+ javaElementHandle= packagesMem[j].getString(TAG_SELECTED_ELEMENT_PATH);
+ Object pack= (IPackageFragment)JavaCore.create(javaElementHandle);
+ if (pack instanceof IPackageFragment && ((IPackageFragment)pack).exists()) {
+ if (lp == null)
+ lp= new LogicalPackage((IPackageFragment)pack);
+ else
+ lp.add((IPackageFragment)pack);
+ }
+ }
+ if (lp != null)
+ list.add(lp);
+ } else {
+ ICElement element= JavaCore.create(javaElementHandle);
+ if (element != null && element.exists())
+ list.add(element);
+ }
+ }
+ return new StructuredSelection(list);
+ }
+*/
+ return null;
+ }
+
+ private void restoreLinkingEnabled(IMemento memento) {
+ Integer val= memento.getInteger(getLinkToEditorKey());
+ if (val != null) {
+ fLinkingEnabled= val.intValue() != 0;
+ }
+ }
+
+ /**
+ * Creates the search list inner viewer.
+ */
+ public void createPartControl(Composite parent) {
+ Assert.isTrue(fViewer == null);
+
+
+ fTypeComparator= new TypeInfoComparator();
+
+ // Setup viewer
+ fViewer= createViewer(parent);
+
+ initDragAndDrop();
+
+ fLabelProvider= createLabelProvider();
+ fViewer.setLabelProvider(fLabelProvider);
+
+ fViewer.setSorter(createTypeInfoSorter());
+ fViewer.setUseHashlookup(true);
+ fTitleProvider= createTitleProvider();
+
+ createContextMenu();
+ getSite().setSelectionProvider(fViewer);
+
+ if (fMemento != null) { // initialize linking state before creating the actions
+ restoreLinkingEnabled(fMemento);
+ }
+
+ createActions(); // call before registering for selection changes
+ addKeyListener();
+
+ if (fMemento != null)
+ restoreState(fMemento);
+
+ getSite().setSelectionProvider(fViewer);
+
+ // Status line
+ IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager();
+ fViewer.addSelectionChangedListener(createStatusBarUpdater(slManager));
+
+
+ hookViewerListeners();
+
+ // Filters
+ addFilters();
+
+ // Initialize viewer input
+ fViewer.setContentProvider(createContentProvider());
+ setInitialInput();
+
+ // Initialize selecton
+ setInitialSelection();
+ fMemento= null;
+
+ // Listen to page changes
+ getViewSite().getPage().addPostSelectionListener(this);
+ getViewSite().getPage().addPartListener(fPartListener);
+
+ fillActionBars(getViewSite().getActionBars());
+
+ setHelp();
+ }
+
+ /**
+ * Answer the property defined by key.
+ */
+ public Object getAdapter(Class key) {
+ if (key == IShowInSource.class) {
+ return getShowInSource();
+ }
+ return super.getAdapter(key);
+ }
+
+ /**
+ * Returns the IShowInSource
for this view.
+ */
+ protected IShowInSource getShowInSource() {
+ return new IShowInSource() {
+ public ShowInContext getShowInContext() {
+ return new ShowInContext(
+ null,
+ getSite().getSelectionProvider().getSelection());
+ }
+ };
+ }
+
+// protected DecoratingLabelProvider createDecoratingLabelProvider(CUILabelProvider provider) {
+//// XXX: Work in progress for problem decorator being a workbench decorator//
+//// return new ExcludingDecoratingLabelProvider(provider, decorationMgr, "org.eclipse.jdt.ui.problem.decorator"); //$NON-NLS-1$
+// return new DecoratingCLabelProvider(provider);
+// }
+
+ protected TypeInfoSorter createTypeInfoSorter() {
+ return new TypeInfoSorter();
+ }
+
+ protected StatusBarUpdater createStatusBarUpdater(IStatusLineManager slManager) {
+ return new StatusBarUpdater(slManager);
+ }
+
+ protected void createContextMenu() {
+ MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(this);
+ Menu contextMenu= menuManager.createContextMenu(fViewer.getControl());
+ fViewer.getControl().setMenu(contextMenu);
+ getSite().registerContextMenu(menuManager, fViewer);
+ }
+
+ protected void initDragAndDrop() {
+/* int ops= DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+ // drop
+ Transfer[] dropTransfers= new Transfer[] {
+ LocalSelectionTransfer.getInstance()
+ };
+ TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
+ new SelectionTransferDropAdapter(fViewer)
+ };
+ fViewer.addDropSupport(ops | DND.DROP_DEFAULT, dropTransfers, new DelegatingDropAdapter(dropListeners));
+
+ // Drag
+ Transfer[] dragTransfers= new Transfer[] {
+ LocalSelectionTransfer.getInstance(),
+ ResourceTransfer.getInstance()};
+ TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
+ new SelectionTransferDragAdapter(fViewer),
+ new ResourceTransferDragAdapter(fViewer)
+ };
+ fViewer.addDragSupport(ops, dragTransfers, new JdtViewerDragAdapter(fViewer, dragListeners));
+*/ }
+
+ protected void fillActionBars(IActionBars actionBars) {
+ IToolBarManager toolBar= actionBars.getToolBarManager();
+ fillToolBar(toolBar);
+
+
+ if (fHasWorkingSetFilter)
+ fWorkingSetFilterActionGroup.fillActionBars(getViewSite().getActionBars());
+
+ actionBars.updateActionBars();
+
+// fActionGroups.fillActionBars(actionBars);
+//
+// if (fHasCustomFilter)
+// fCustomFiltersActionGroup.fillActionBars(actionBars);
+//
+// IMenuManager menu= actionBars.getMenuManager();
+// menu.add(fToggleLinkingAction);
+ }
+
+ //---- IWorkbenchPart ------------------------------------------------------
+
+
+ public void setFocus() {
+ fViewer.getControl().setFocus();
+ }
+
+ public void dispose() {
+ if (fViewer != null) {
+ getViewSite().getPage().removePostSelectionListener(this);
+ getViewSite().getPage().removePartListener(fPartListener);
+ fViewer= null;
+ }
+// if (fActionGroups != null)
+// fActionGroups.dispose();
+
+ if (fWorkingSetFilterActionGroup != null) {
+ fWorkingSetFilterActionGroup.dispose();
+ }
+
+ super.dispose();
+ }
+
+ /**
+ * Adds the KeyListener
+ */
+ protected void addKeyListener() {
+ fViewer.getControl().addKeyListener(new KeyAdapter() {
+ public void keyReleased(KeyEvent event) {
+ handleKeyReleased(event);
+ }
+ });
+ }
+
+ protected void handleKeyReleased(KeyEvent event) {
+ if (event.stateMask != 0)
+ return;
+
+ int key= event.keyCode;
+ if (key == SWT.F5) {
+// IAction action= fBuildActionGroup.getRefreshAction();
+// if (action.isEnabled())
+// action.run();
+ }
+ }
+
+ //---- Adding Action to Toolbar -------------------------------------------
+
+ protected void fillToolBar(IToolBarManager tbm) {
+ }
+
+ /**
+ * Called when the context menu is about to open.
+ * Override to add your own context dependent menu contributions.
+ */
+ public void menuAboutToShow(IMenuManager menu) {
+ CUIPlugin.createStandardGroups(menu);
+
+ IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection();
+ int size= selection.size();
+ Object element= selection.getFirstElement();
+
+ if (size == 1)
+ addOpenNewWindowAction(menu, element);
+// fActionGroups.setContext(new ActionContext(selection));
+// fActionGroups.fillContextMenu(menu);
+// fActionGroups.setContext(null);
+ }
+
+ private void addOpenNewWindowAction(IMenuManager menu, Object element) {
+ if (element instanceof ICElement) {
+ element= ((ICElement)element).getResource();
+ }
+ if (!(element instanceof IContainer))
+ return;
+// menu.appendToGroup(
+// IContextMenuConstants.GROUP_OPEN,
+// new PatchedOpenInNewWindowAction(getSite().getWorkbenchWindow(), (IContainer)element));
+ }
+
+ protected void createActions() {
+// fActionGroups= new CompositeActionGroup(new ActionGroup[] {
+// new NewWizardsActionGroup(this.getSite()),
+// fOpenEditorGroup= new OpenEditorActionGroup(this),
+// new OpenViewActionGroup(this),
+// fCCPActionGroup= new CCPActionGroup(this),
+// new GenerateActionGroup(this),
+// new RefactorActionGroup(this),
+// new ImportActionGroup(this),
+// fBuildActionGroup= new BuildActionGroup(this),
+// new JavaSearchActionGroup(this)});
+
+
+ if (fHasWorkingSetFilter) {
+ String viewId= getConfigurationElement().getAttribute("id"); //$NON-NLS-1$
+ Assert.isNotNull(viewId);
+ IPropertyChangeListener workingSetListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ doWorkingSetChanged(event);
+ }
+ };
+ fWorkingSetFilterActionGroup= new WorkingSetFilterActionGroup(viewId, getShell(), workingSetListener);
+ fViewer.addFilter(fWorkingSetFilterActionGroup.getWorkingSetFilter());
+ }
+
+// // Custom filter group
+// if (fHasCustomFilter)
+// fCustomFiltersActionGroup= new CustomFiltersActionGroup(this, fViewer);
+//
+// fToggleLinkingAction= new ToggleLinkingAction(this);
+ }
+
+ private void doWorkingSetChanged(PropertyChangeEvent event) {
+ String property= event.getProperty();
+ if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property))
+ updateTitle();
+ else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) {
+ updateTitle();
+ fViewer.getControl().setRedraw(false);
+ fViewer.refresh();
+ fViewer.getControl().setRedraw(true);
+ }
+
+ }
+
+
+ /**
+ * Returns the shell to use for opening dialogs.
+ * Used in this class, and in the actions.
+ */
+ Shell getShell() {
+ return fViewer.getControl().getShell();
+ }
+
+ protected final Display getDisplay() {
+ return fViewer.getControl().getDisplay();
+ }
+
+ /**
+ * Returns the selection provider.
+ */
+ ISelectionProvider getSelectionProvider() {
+ return fViewer;
+ }
+
+ /**
+ * Answers if the given element
is a valid
+ * input for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * element for this part.
+ *
+ * @param element the object to test
+ * @return true
if the input has to be set
+ * @since 3.0
+ */
+ private boolean mustSetNewInput(Object elementToSelect, Object oldInput, Object newInput) {
+ return (newInput == null || !newInput.equals(oldInput))
+ && (elementToSelect == null
+ || oldInput == null);
+// return (newInput == null || !newInput.equals(oldInput))
+// && (elementToSelect == null
+// || oldInput == null
+// || (!((elementToSelect instanceof IDeclaration)
+// && (elementToSelect.getParent().equals(oldInput.getParent()))
+// && (!isAncestorOf(getViewPartInput(), elementToSelect)))));
+ }
+
+ /**
+ * Finds the closest Java element which can be used as input for
+ * this part and has the given Java element as child
+ *
+ * @param je the Java element for which to search the closest input
+ * @return the closest Java element used as input for this part
+ */
+ abstract protected Object findInputForElement(Object element);
+
+ /**
+ * Finds the element which has to be selected in this part.
+ *
+ * @param je the Java element which has the focus
+ */
+ abstract protected Object findElementToSelect(Object obj);
+
+ /**
+ * Converts the given Java element to one which is suitable for this
+ * view. It takes into account wether the view shows working copies or not.
+ *
+ * @param element the Java element to be converted
+ * @return an element suitable for this view
+ */
+ Object getSuitableElement(Object obj) {
+ if (!(obj instanceof ICElement) && !(obj instanceof ITypeInfo))
+ return null;
+ if (fTypeComparator.compare(obj, ICElement.C_UNIT) > 0)
+ return obj;
+ return obj;
+// if (element.getElementType() == IJavaElement.CLASS_FILE)
+// return element;
+// if (isInputAWorkingCopy()) {
+// IJavaElement wc= getWorkingCopy(element);
+// if (wc != null)
+// element= wc;
+// return element;
+// }
+// else {
+// return element.getPrimaryElement();
+// }
+ }
+
+ protected final Object getSingleElementFromSelection(ISelection selection) {
+ if (!(selection instanceof StructuredSelection) || selection.isEmpty())
+ return null;
+
+ Iterator iter= ((StructuredSelection)selection).iterator();
+ Object firstElement= iter.next();
+ if (!(firstElement instanceof ICElement) && !(firstElement instanceof ITypeInfo)) {
+// if (SearchUtil.isISearchResultViewEntry(firstElement)) {
+// ICElement je= SearchUtil.getJavaElement(firstElement);
+// if (je != null)
+// return je;
+// firstElement= SearchUtil.getResource(firstElement);
+// }
+ if (firstElement instanceof IAdaptable) {
+ ICElement je= (ICElement)((IAdaptable)firstElement).getAdapter(ICElement.class);
+ if (je == null && firstElement instanceof IFile) {
+ IContainer parent= ((IFile)firstElement).getParent();
+ if (parent != null)
+ return (ICElement)parent.getAdapter(ICElement.class);
+ else return null;
+ } else
+ return je;
+
+ } else
+ return firstElement;
+ }
+ Object currentInput= getViewer().getInput();
+ if (currentInput == null || !currentInput.equals(findInputForElement(firstElement)))
+ if (iter.hasNext())
+ // multi selection and view is empty
+ return null;
+ else
+ // ok: single selection and view is empty
+ return firstElement;
+
+ // be nice to multi selection
+ while (iter.hasNext()) {
+ Object element= iter.next();
+ if (!(element instanceof ICElement) && !(element instanceof ITypeInfo))
+// if (!(element instanceof ICElement))
+ return null;
+ if (!currentInput.equals(findInputForElement(element)))
+ return null;
+ }
+ return firstElement;
+ }
+
+ /**
+ * Gets the typeComparator.
+ * @return Returns a JavaElementTypeComparator
+ */
+ protected Comparator getTypeComparator() {
+ return fTypeComparator;
+ }
+
+ /**
+ * Links to editor (if option enabled)
+ */
+ private void linkToEditor(IStructuredSelection selection) {
+ Object obj= selection.getFirstElement();
+
+ if (selection.size() == 1) {
+ IEditorPart part= EditorUtility.isOpenInEditor(obj);
+ if (part != null) {
+ IWorkbenchPage page= getSite().getPage();
+ page.bringToTop(part);
+ if (obj instanceof ICElement)
+ EditorUtility.revealInEditor(part, (ICElement) obj);
+ }
+ }
+ }
+
+ private void setSelectionFromEditor(IWorkbenchPartReference ref) {
+ IWorkbenchPart part= ref.getPart(false);
+ setSelectionFromEditor(part);
+ }
+
+ void setSelectionFromEditor(IWorkbenchPart part) {
+ if (!linkBrowsingViewSelectionToEditor())
+ return;
+
+ if (part == null)
+ return;
+ IWorkbenchPartSite site= part.getSite();
+ if (site == null)
+ return;
+ ISelectionProvider provider= site.getSelectionProvider();
+ if (provider != null)
+ setSelectionFromEditor(part, provider.getSelection());
+ }
+
+ private void setSelectionFromEditor(IWorkbenchPart part, ISelection selection) {
+ if (part instanceof IEditorPart) {
+ ICElement element= null;
+ if (selection instanceof IStructuredSelection) {
+ Object obj= getSingleElementFromSelection(selection);
+ if (obj instanceof ICElement)
+ element= (ICElement)obj;
+ }
+ IEditorInput ei= ((IEditorPart)part).getEditorInput();
+ if (selection instanceof ITextSelection) {
+ int offset= ((ITextSelection)selection).getOffset();
+ element= getElementAt(ei, offset);
+ }
+ if (element != null) {
+ adjustInputAndSetSelection(element);
+ return;
+ }
+ if (ei instanceof IFileEditorInput) {
+ IFile file= ((IFileEditorInput)ei).getFile();
+ ICElement je= (ICElement)file.getAdapter(ICElement.class);
+ if (je == null) {
+ IContainer container= ((IFileEditorInput)ei).getFile().getParent();
+ if (container != null)
+ je= (ICElement)container.getAdapter(ICElement.class);
+ }
+ if (je == null) {
+ setSelection(null, false);
+ return;
+ }
+ adjustInputAndSetSelection(je);
+// } else if (ei instanceof IClassFileEditorInput) {
+// IClassFile cf= ((IClassFileEditorInput)ei).getClassFile();
+// adjustInputAndSetSelection(cf);
+ }
+ }
+ }
+
+ /**
+ * Returns the element contained in the EditorInput
+ */
+ Object getElementOfInput(IEditorInput input) {
+// if (input instanceof IClassFileEditorInput)
+// return ((IClassFileEditorInput)input).getClassFile();
+// else
+ if (input instanceof IFileEditorInput)
+ return ((IFileEditorInput)input).getFile();
+// else if (input instanceof JarEntryEditorInput)
+// return ((JarEntryEditorInput)input).getStorage();
+ return null;
+ }
+
+ protected void setSelection(ISelection selection, boolean reveal) {
+ if (selection != null && selection.equals(fViewer.getSelection()))
+ return;
+ fProcessSelectionEvents= false;
+ fViewer.setSelection(selection, reveal);
+ fProcessSelectionEvents= true;
+ }
+
+ /**
+ * Tries to find the given element in a workingcopy.
+ */
+ protected static ICElement getWorkingCopy(ICElement input) {
+ // MA: with new working copy story original == working copy
+ return input;
+ }
+
+//
+// boolean isInputAWorkingCopy() {
+// return ((BaseCElementContentProvider)getViewer().getContentProvider()).getProvideWorkingCopy();
+// }
+
+ /**
+ * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#getElementAt(int)
+ */
+ protected ICElement getElementAt(IEditorInput input, int offset) {
+// if (input instanceof IClassFileEditorInput) {
+// try {
+// return ((IClassFileEditorInput)input).getClassFile().getElementAt(offset);
+// } catch (CModelException ex) {
+// return null;
+// }
+// }
+
+ IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
+ ITranslationUnit unit= manager.getWorkingCopy(input);
+ if (unit != null)
+ try {
+ if (unit.isConsistent())
+ return unit.getElementAtOffset(offset);
+ else {
+ /*
+ * XXX: We should set the selection later when the
+ * CU is reconciled.
+ * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=51290
+ */
+ }
+ } catch (CModelException ex) {
+ // fall through
+ }
+ return null;
+ }
+
+/* protected ICElement getTypeForCU(ITranslationUnit cu) {
+ cu= (ITranslationUnit)getSuitableCElement(cu);
+
+// // Use primary type if possible
+// ICElement primaryType= cu.findPrimaryType();
+// if (primaryType != null)
+// return primaryType;
+
+ // Use first top-level type
+ try {
+ final ICElement[] fTypes = new ICElement[]{ null };
+ cu.accept(new ICElementVisitor() {
+ public boolean visit(ICElement element) throws CoreException {
+ // TODO Auto-generated method stub
+ switch(element.getElementType()) {
+ case ICElement.C_NAMESPACE:
+ case ICElement.C_TEMPLATE_CLASS:
+ case ICElement.C_CLASS:
+ case ICElement.C_STRUCT:
+ case ICElement.C_UNION:
+ case ICElement.C_ENUMERATION:
+ case ICElement.C_TYPEDEF:
+ fTypes[0] = element;
+ return false;
+ }
+ return true;
+ }
+ });
+// ICElement[] types= cu.getTypes();
+// if (types.length > 0)
+// return types[0];
+// else
+// return null;
+ return fTypes[0];
+ } catch (CoreException ex) {
+ return null;
+ }
+ }
+*/
+ void setProcessSelectionEvents(boolean state) {
+ fProcessSelectionEvents= state;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
+ */
+ public Object getViewPartInput() {
+ if (fViewer != null) {
+ return fViewer.getInput();
+ }
+ return null;
+ }
+
+// protected void setActionGroups(CompositeActionGroup actionGroups) {
+// fActionGroups= actionGroups;
+// }
+//
+// protected void setBuildActionGroup(BuildActionGroup actionGroup) {
+// fBuildActionGroup= actionGroup;
+// }
+//
+// protected void setCCPActionGroup(CCPActionGroup actionGroup) {
+// fCCPActionGroup= actionGroup;
+// }
+//
+// protected void setCustomFiltersActionGroup(CustomFiltersActionGroup customFiltersActionGroup) {
+// fCustomFiltersActionGroup= customFiltersActionGroup;
+// }
+
+ protected boolean hasCustomFilter() {
+ return fHasCustomFilter;
+ }
+
+ protected boolean hasWorkingSetFilter() {
+ return fHasWorkingSetFilter;
+ }
+
+// protected void setOpenEditorGroup(OpenEditorActionGroup openEditorGroup) {
+// fOpenEditorGroup= openEditorGroup;
+// }
+//
+// protected OpenEditorActionGroup getOpenEditorGroup() {
+// return fOpenEditorGroup;
+// }
+//
+// protected BuildActionGroup getBuildActionGroup() {
+// return fBuildActionGroup;
+// }
+//
+// protected CCPActionGroup getCCPActionGroup() {
+// return fCCPActionGroup;
+// }
+
+ private boolean linkBrowsingViewSelectionToEditor() {
+ return isLinkingEnabled();
+ }
+
+ public void setLinkingEnabled(boolean enabled) {
+ fLinkingEnabled= enabled;
+ PreferenceConstants.getPreferenceStore().setValue(getLinkToEditorKey(), enabled);
+ if (enabled) {
+ IEditorPart editor = getSite().getPage().getActiveEditor();
+ if (editor != null) {
+ setSelectionFromEditor(editor);
+ }
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPerspectiveFactory.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPerspectiveFactory.java
new file mode 100644
index 00000000000..9aebaf81ead
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPerspectiveFactory.java
@@ -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;
+ }
+}
+
+
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CUILabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CUILabelProvider.java
new file mode 100644
index 00000000000..2feefa3eae3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CUILabelProvider.java
@@ -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 JavaElementLabels
.
+ * @param imageFlags Flags defined in JavaElementImageProvider
.
+ */
+ 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;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/DecoratingCLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/DecoratingCLabelProvider.java
new file mode 100644
index 00000000000..b9a22020261
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/DecoratingCLabelProvider.java
@@ -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);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/FilterUpdater.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/FilterUpdater.java
new file mode 100644
index 00000000000..aeb4aecb44e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/FilterUpdater.java
@@ -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);
+ }
+ });
+ }
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/LexicalSortingAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/LexicalSortingAction.java
new file mode 100644
index 00000000000..dbefbe28273
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/LexicalSortingAction.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersView.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersView.java
new file mode 100644
index 00000000000..ff7c2ce4a37
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersView.java
@@ -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 element
is a valid
+ * input for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * element for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * input for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * element for this part.
+ *
+ * @param element the object to test
+ * @return + * This class may be instantiated; it is not intended to be subclassed. + *
+ * + * @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 newOpenProjectAction
. The action requires
+ * that the selection provided by the site's selection provider is of type
+ * org.eclipse.jface.viewers.IStructuredSelection
.
+ *
+ * @param site the site providing context information for this action
+ */
+ public 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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProblemsLabelDecorator.java
new file mode 100644
index 00000000000..fba095e9721
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProblemsLabelDecorator.java
@@ -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 IMarker.PROBLEM
.
+ * + * Note: Only images for elements in Java projects are currently updated on marker changes. + *
+ * + * @since 2.0 + */ +public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator { + + /** + * This is a specialLabelProviderChangedEvent
carring additional
+ * information whether the event orgins from a maker change.
+ *
+ * ProblemsLabelChangedEvent
s are only generated by
+ * ProblemsLabelDecorator
s.
+ *
false
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 ProblemsLabelDecorator
.
+ */
+ public ProblemsLabelDecorator() {
+ this(null);
+ fUseNewRegistry= true;
+ }
+
+ /*
+ * Creates decorator with a shared image registry.
+ *
+ * @param registry The registry to use or null
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 true
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);
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectActionGroup.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectActionGroup.java
new file mode 100644
index 00000000000..22cd5ee8001
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectActionGroup.java
@@ -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.
+ *
+ * + * This class may be instantiated; it is not intended to be subclassed. + *
+ * + * @since 2.0 + */ +public class ProjectActionGroup extends ActionGroup { + + private IWorkbenchSite fSite; + + private OpenProjectAction fOpenAction; + private CloseResourceAction fCloseAction; + + /** + * Creates a newProjectActionGroup
. The group requires
+ * that the selection provided by the site's selection provider is of type
+ * org.eclipse.jface.viewers.IStructuredSelection
.
+ *
+ * @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();
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectsView.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectsView.java
new file mode 100644
index 00000000000..be8da09c486
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/ProjectsView.java
@@ -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 element
is a valid
+ * input for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * element for this part.
+ *
+ * @param element the object to test
+ * @return StatusBarUpdater
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();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/StorageLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/StorageLabelProvider.java
new file mode 100644
index 00000000000..2bba629c743
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/StorageLabelProvider.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoComparator.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoComparator.java
new file mode 100644
index 00000000000..643915fb747
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoComparator.java
@@ -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;
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoSorter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoSorter.java
new file mode 100644
index 00000000000..c0b7860d82c
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypeInfoSorter.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypesView.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypesView.java
new file mode 100644
index 00000000000..42141621d38
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypesView.java
@@ -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 element
is a valid
+ * input for this part.
+ *
+ * @param element the object to test
+ * @return element
is a valid
+ * element for this part.
+ *
+ * @param element the object to test
+ * @return ICElement
. 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 true
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 false
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;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
index 5caefdbbfae..3c3fb36b899 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
@@ -82,5 +82,24 @@ public interface ICHelpContextIds {
public static final String RENAME_TYPE_WIZARD_PAGE= PREFIX + "rename_type_wizard_page_context"; //$NON-NLS-1$
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$
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java
index f33cec321f2..654b321b430 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java
@@ -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,8 +274,16 @@ public class CElementLabels {
public static void getElementLabel(ICElement element, int flags, StringBuffer buf) {
int type= element.getElementType();
+ ISourceRoot root= null;
- switch( type ){
+ 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 :
getMethodLabel( (IMethod) element, flags, buf );
break;
@@ -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;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTableViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTableViewer.java
new file mode 100644
index 00000000000..2bb41e8dac4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTableViewer.java
@@ -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 ProblemItemMapper
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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ResourceToItemsMapper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ResourceToItemsMapper.java
new file mode 100644
index 00000000000..0fd29eb379f
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ResourceToItemsMapper.java
@@ -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 resourceChanged
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;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IViewPartInputProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IViewPartInputProvider.java
new file mode 100644
index 00000000000..524a601eb1a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IViewPartInputProvider.java
@@ -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();
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ImageImageDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ImageImageDescriptor.java
new file mode 100644
index 00000000000..3fc2fad603e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ImageImageDescriptor.java
@@ -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();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/ClearWorkingSetAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/ClearWorkingSetAction.java
new file mode 100644
index 00000000000..db978b77902
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/ClearWorkingSetAction.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/EditWorkingSetAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/EditWorkingSetAction.java
new file mode 100644
index 00000000000..53cacd0a16b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/EditWorkingSetAction.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/SelectWorkingSetAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/SelectWorkingSetAction.java
new file mode 100644
index 00000000000..bfbfb159efa
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/SelectWorkingSetAction.java
@@ -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);
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetComparator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetComparator.java
new file mode 100644
index 00000000000..572ac12bed2
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetComparator.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilter.java
new file mode 100644
index 00000000000..ff57161f7f9
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilter.java
@@ -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;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java
new file mode 100644
index 00000000000..d00296ebe71
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java
@@ -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.
+ * + * Note: This method does not refresh the viewer. + *
+ * @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); + } + } + } + + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java new file mode 100644 index 00000000000..15d89972fd8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java @@ -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$ + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index 08501853c22..382a4f1f677 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -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; @@ -101,6 +102,61 @@ public class CUIPlugin extends AbstractUIPlugin { static String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ private static final String CONTENTASSIST = CUIPlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$ + + + /** + * The id of the C perspective + * (value"org.eclipse.cdt.ui.CPerspective"
).
+ */
+ public static final String ID_CPERSPECTIVE = PLUGIN_ID + ".CPerspective"; //$NON-NLS-1$
+
+ /**
+ * The id of the C hierarchy perspective
+ * (value "org.eclipse.cdt.ui.CHierarchyPerspective"
).
+ */
+ public static final String ID_CHIERARCHY_PERSPECTIVE = PLUGIN_ID + ".CHierarchyPerspective"; //$NON-NLS-1$
+
+ /**
+ * The id of the C Browsing Perspective
+ * (value "org.eclipse.cdt.ui.CBrowsingPerspective"
).
+ *
+ * @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 "org.eclipse.cdt.ui.ProjectsView"
).
+ *
+ * @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 "org.eclipse.cdt.ui.NamespacesView"
).
+ *
+ * @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 "org.eclipse.cdt.ui.TypesView"
).
+ *
+ * @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 "org.eclipse.cdt.ui.MembersView"
).
+ *
+ * @since 2.0
+ */
+ public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$
+
+
// -------- static methods --------
@@ -182,6 +238,11 @@ public class CUIPlugin extends AbstractUIPlugin {
public void log(IStatus status) {
getLog().log(status);
}
+
+ public void logErrorMessage(String message) {
+ log(new Status(IStatus.ERROR, getPluginId(), ICStatusConstants.INTERNAL_ERROR, message, null));
+ }
+
/**
* Utility method with conventions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
index d41492b4112..60fd15f01dc 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
@@ -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.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
. If true
the views are stacked vertical.
+ * If
false
they are stacked horizontal.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *