From 972ac277a0d569b4b39d4246e9e2bd8935f72466 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 25 May 2004 18:49:32 +0000 Subject: [PATCH] new Include/symbol page --- .../internal/ui/dialogs/cpaths/CPElement.java | 271 +++--- .../ui/dialogs/cpaths/CPElementFilter.java | 47 +- .../ui/dialogs/cpaths/CPElementGroup.java | 96 ++- .../cpaths/CPElementLabelProvider.java | 89 +- .../ui/dialogs/cpaths/CPElementSorter.java | 42 +- .../dialogs/cpaths/CPListImageDescriptor.java | 108 +++ .../cpaths/CPathContainerDescriptor.java | 24 +- .../cpaths/CPathContainerEntryPage.java | 35 +- .../dialogs/cpaths/CPathContainerWizard.java | 12 +- .../cpaths/CPathEntryMessages.properties | 26 + .../ui/dialogs/cpaths/CPathFilterPage.java | 12 +- .../dialogs/cpaths/CPathIncludeEntryPage.java | 5 +- .../cpaths/CPathIncludeSymbolEntryPage.java | 787 ++++++++++++++++++ .../dialogs/cpaths/CPathLibraryEntryPage.java | 2 +- .../dialogs/cpaths/CPathOutputEntryPage.java | 89 +- .../dialogs/cpaths/CPathSourceEntryPage.java | 75 +- .../dialogs/cpaths/CPathSymbolEntryPage.java | 2 +- .../cpaths/ExclusionPatternEntryDialog.java | 3 +- .../dialogs/cpaths/ExtendedCPathBasePage.java | 83 -- .../cpaths/IncludesSymbolsPropertyPage.java | 5 +- .../cpaths/NewIncludesSymbolsTabBlock.java | 156 ++++ .../cpaths/ProjectContainerDescriptor.java | 4 +- .../dialogs/cpaths/ProjectContainerPage.java | 23 +- .../dialogs/cpaths/SourceAttachmentBlock.java | 340 ++++---- 24 files changed, 1778 insertions(+), 558 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListImageDescriptor.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeSymbolEntryPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewIncludesSymbolsTabBlock.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElement.java index 2a7afa1e519..047d20e7a4d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElement.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElement.java @@ -9,6 +9,7 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -38,77 +39,102 @@ public class CPElement { public static final String MACRO_VALUE = "macrovalue"; //$NON-NLS-1$ public static final String BASE_REF = "base-ref"; //$NON-NLS-1$ public static final String BASE = "base-path"; //$NON-NLS-1$ + public static final String PARENT = "parent"; //$NON-NLS-1$ + public static final String PARENT_CONTAINER = "parent-container"; //$NON-NLS-1$ private final int fEntryKind; private final IPath fPath; private final ICProject fCProject; private final IResource fResource; - private final ArrayList fChildren; + private final ArrayList fChildren = new ArrayList(1); private boolean fIsExported; private boolean fIsMissing; - private CPElement fParentContainer; private IPathEntry fCachedEntry; + private CPElement Inherited; // used when the path is duplicated on a child + // resource but is inherited from a parent + // resource + // these are not real path entries + + // create a inherited element and apply to path/resource + public CPElement(CPElement element, IPath path, IResource res) { + this(element.getCProject(), element.getEntryKind(), path, res); + setExported(element.isExported()); + fChildren.clear(); + for(int i = 0; i < element.fChildren.size(); i++) { + CPElementAttribute attrib = (CPElementAttribute)element.fChildren.get(i); + fChildren.add(new CPElementAttribute(this, attrib.getKey(), attrib.getValue())); + } + Inherited = element; + } public CPElement(ICProject project, int entryKind, IPath path, IResource res) { fCProject = project; fEntryKind = entryKind; fPath = path; - fChildren = new ArrayList(); fResource = res; fIsExported = false; fIsMissing = false; fCachedEntry = null; - fParentContainer = null; switch (entryKind) { - case IPathEntry.CDT_OUTPUT: + case IPathEntry.CDT_OUTPUT : createAttributeElement(EXCLUSION, new Path[0]); break; - case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_SOURCE : createAttributeElement(EXCLUSION, new Path[0]); break; - case IPathEntry.CDT_LIBRARY: + case IPathEntry.CDT_LIBRARY : createAttributeElement(LIBRARY, new Path("")); //$NON-NLS-1$ createAttributeElement(SOURCEATTACHMENT, null); createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ break; - case IPathEntry.CDT_INCLUDE: + case IPathEntry.CDT_INCLUDE : createAttributeElement(INCLUDE, new Path("")); //$NON-NLS-1$ createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(SYSTEM_INCLUDE, Boolean.valueOf(false)); createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ break; - case IPathEntry.CDT_MACRO: + case IPathEntry.CDT_MACRO : createAttributeElement(MACRO_NAME, ""); //$NON-NLS-1$ createAttributeElement(MACRO_VALUE, ""); //$NON-NLS-1$ createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ break; - case IPathEntry.CDT_CONTAINER: + case IPathEntry.CDT_CONTAINER : try { IPathEntryContainer container = CoreModel.getPathEntryContainer(fPath, fCProject); if (container != null) { IPathEntry[] entries = container.getPathEntries(); for (int i = 0; i < entries.length; i++) { CPElement curr = createFromExisting(entries[i], fCProject); - curr.setParentContainer(this); - fChildren.add(curr); + curr.createAttributeElement(PARENT_CONTAINER, this); + CPElementGroup group = new CPElementGroup(this, curr.getEntryKind()); + int indx = fChildren.indexOf(group); + if (indx == -1) { + fChildren.add(group); + } else { + group = (CPElementGroup)fChildren.get(indx); + } + group.addChild(curr); } } } catch (CModelException e) { } break; - default: + default : } } public IPathEntry getPathEntry() { + if (Inherited != null) { + return null; + } if (fCachedEntry == null) { fCachedEntry = newPathEntry(); } @@ -116,43 +142,40 @@ public class CPElement { } private IPathEntry newPathEntry() { - IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION); - IPath base = (IPath) getAttribute(BASE); - IPath baseRef = (IPath) getAttribute(BASE_REF); + IPath[] exclusionPattern = (IPath[])getAttribute(EXCLUSION); + IPath base = (IPath)getAttribute(BASE); + IPath baseRef = (IPath)getAttribute(BASE_REF); switch (fEntryKind) { - case IPathEntry.CDT_OUTPUT: + case IPathEntry.CDT_OUTPUT : return CoreModel.newOutputEntry(fPath, exclusionPattern); - case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_SOURCE : return CoreModel.newSourceEntry(fPath, exclusionPattern); - case IPathEntry.CDT_LIBRARY: + case IPathEntry.CDT_LIBRARY : IPath libraryPath = (IPath)getAttribute(LIBRARY); - IPath attach = (IPath) getAttribute(SOURCEATTACHMENT); + IPath attach = (IPath)getAttribute(SOURCEATTACHMENT); if (!baseRef.isEmpty()) { return CoreModel.newLibraryRefEntry(fPath, baseRef, libraryPath); - } else { - return CoreModel.newLibraryEntry(fPath, base, libraryPath, attach, null, null, isExported()); } - case IPathEntry.CDT_PROJECT: + return CoreModel.newLibraryEntry(fPath, base, libraryPath, attach, null, null, isExported()); + case IPathEntry.CDT_PROJECT : return CoreModel.newProjectEntry(fPath, isExported()); - case IPathEntry.CDT_CONTAINER: + case IPathEntry.CDT_CONTAINER : return CoreModel.newContainerEntry(fPath, isExported()); - case IPathEntry.CDT_INCLUDE: - IPath include = (IPath) getAttribute(INCLUDE); + case IPathEntry.CDT_INCLUDE : + IPath include = (IPath)getAttribute(INCLUDE); if (!baseRef.isEmpty()) { return CoreModel.newIncludeRefEntry(fPath, baseRef, include); - } else { - return CoreModel.newIncludeEntry(fPath, base, include, ((Boolean) getAttribute(SYSTEM_INCLUDE)).booleanValue(), - exclusionPattern); } - case IPathEntry.CDT_MACRO: - String macroName = (String) getAttribute(MACRO_NAME); - String macroValue = (String) getAttribute(MACRO_VALUE); + return CoreModel.newIncludeEntry(fPath, base, include, ((Boolean)getAttribute(SYSTEM_INCLUDE)).booleanValue(), + exclusionPattern); + case IPathEntry.CDT_MACRO : + String macroName = (String)getAttribute(MACRO_NAME); + String macroValue = (String)getAttribute(MACRO_VALUE); if (!baseRef.isEmpty()) { return CoreModel.newMacroRefEntry(fPath, baseRef, macroName); - } else { - return CoreModel.newMacroEntry(fPath, macroName, macroValue, exclusionPattern); } - default: + return CoreModel.newMacroEntry(fPath, macroName, macroValue, exclusionPattern); + default : return null; } } @@ -175,45 +198,45 @@ public class CPElement { appendEncodePath(fPath, buf).append(';'); buf.append(Boolean.valueOf(fIsExported)).append(';'); switch (fEntryKind) { - case IPathEntry.CDT_OUTPUT: - case IPathEntry.CDT_SOURCE: - case IPathEntry.CDT_INCLUDE: - case IPathEntry.CDT_MACRO: - IPath[] exclusion = (IPath[]) getAttribute(EXCLUSION); + case IPathEntry.CDT_OUTPUT : + case IPathEntry.CDT_SOURCE : + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + IPath[] exclusion = (IPath[])getAttribute(EXCLUSION); buf.append('[').append(exclusion.length).append(']'); for (int i = 0; i < exclusion.length; i++) { appendEncodePath(exclusion[i], buf); } switch (fEntryKind) { - case IPathEntry.CDT_INCLUDE: - IPath baseRef = (IPath) getAttribute(BASE_REF); + case IPathEntry.CDT_INCLUDE : + IPath baseRef = (IPath)getAttribute(BASE_REF); appendEncodePath(baseRef, buf); - IPath base = (IPath) getAttribute(BASE); + IPath base = (IPath)getAttribute(BASE); appendEncodePath(base, buf); - IPath include = (IPath) getAttribute(INCLUDE); + IPath include = (IPath)getAttribute(INCLUDE); appendEncodePath(include, buf); break; - case IPathEntry.CDT_MACRO: - baseRef = (IPath) getAttribute(BASE_REF); + case IPathEntry.CDT_MACRO : + baseRef = (IPath)getAttribute(BASE_REF); appendEncodePath(baseRef, buf); - base = (IPath) getAttribute(BASE); + base = (IPath)getAttribute(BASE); appendEncodePath(base, buf); - String symbol = (String) getAttribute(MACRO_NAME); + String symbol = (String)getAttribute(MACRO_NAME); buf.append(symbol).append(';'); - default: + default : } break; - case IPathEntry.CDT_LIBRARY: - IPath baseRef = (IPath) getAttribute(BASE_REF); + case IPathEntry.CDT_LIBRARY : + IPath baseRef = (IPath)getAttribute(BASE_REF); appendEncodePath(baseRef, buf); - IPath base = (IPath) getAttribute(BASE); + IPath base = (IPath)getAttribute(BASE); appendEncodePath(base, buf); - IPath sourceAttach = (IPath) getAttribute(SOURCEATTACHMENT); + IPath sourceAttach = (IPath)getAttribute(SOURCEATTACHMENT); appendEncodePath(sourceAttach, buf); - IPath library = (IPath) getAttribute(LIBRARY); + IPath library = (IPath)getAttribute(LIBRARY); appendEncodePath(library, buf); break; - default: + default : } buf.setLength(buf.length() - 1); return buf; @@ -245,6 +268,31 @@ public class CPElement { return fResource; } + public CPElement getParentContainer() { + CPElementAttribute attribute = findAttributeElement(PARENT_CONTAINER); + if (attribute != null) { + return (CPElement)attribute.getValue(); + } + return null; + } + + public void setParent(CPElementGroup group) { + CPElementAttribute attribute = findAttributeElement(PARENT); + if (attribute == null && group != null) { + createAttributeElement(PARENT, group); + return; + } + attribute.setValue(group); + } + + public CPElementGroup getParent() { + CPElementAttribute attribute = findAttributeElement(PARENT); + if (attribute != null) { + return (CPElementGroup)attribute.getValue(); + } + return null; + } + public CPElementAttribute setAttribute(String key, Object value) { CPElementAttribute attribute = findAttributeElement(key); if (attribute == null) { @@ -259,7 +307,7 @@ public class CPElement { for (int i = 0; i < fChildren.size(); i++) { Object curr = fChildren.get(i); if (curr instanceof CPElementAttribute) { - CPElementAttribute elem = (CPElementAttribute) curr; + CPElementAttribute elem = (CPElementAttribute)curr; if (key.equals(elem.getKey())) { return elem; } @@ -281,27 +329,32 @@ public class CPElement { } public Object[] getChildren() { - switch(fEntryKind) { - case IPathEntry.CDT_OUTPUT: - case IPathEntry.CDT_SOURCE: - return new Object[] { findAttributeElement(EXCLUSION)}; - case IPathEntry.CDT_LIBRARY: -// return new Object[] { findAttributeElement(SOURCEATTACHMENT) }; - case IPathEntry.CDT_INCLUDE: - case IPathEntry.CDT_MACRO: - return new Object[0]; + switch (fEntryKind) { + case IPathEntry.CDT_OUTPUT : + case IPathEntry.CDT_SOURCE : + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + if (getInherited() == null && getParentContainer() == null) { + return new Object[]{findAttributeElement(EXCLUSION)}; + } + break; + // case IPathEntry.CDT_LIBRARY : + // return new Object[] { findAttributeElement(SOURCEATTACHMENT) }; + + case IPathEntry.CDT_CONTAINER : { + List list = new ArrayList(); + for (int i = 0; i < fChildren.size(); i++) { + Object curr = fChildren.get(i); + if (curr instanceof CPElementGroup) { + list.add(curr); + } + } + return list.toArray(); + } } - return fChildren.toArray(); + return new Object[0]; } - - private void setParentContainer(CPElement element) { - fParentContainer = element; - } - - public CPElement getParentContainer() { - return fParentContainer; - } - + private void attributeChanged(String key) { fCachedEntry = null; } @@ -311,20 +364,20 @@ public class CPElement { */ public boolean equals(Object other) { if (other != null && other.getClass().equals(getClass())) { - CPElement elem = (CPElement) other; + CPElement elem = (CPElement)other; if (elem.fEntryKind != fEntryKind || !elem.fPath.equals(fPath)) { return false; } switch (fEntryKind) { - case IPathEntry.CDT_LIBRARY: + case IPathEntry.CDT_LIBRARY : return (getAttribute(LIBRARY).equals(elem.getAttribute(LIBRARY)) - && getAttribute(BASE).equals(elem.getAttribute(BASE)) - && getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF))); - case IPathEntry.CDT_INCLUDE: + && getAttribute(BASE).equals(elem.getAttribute(BASE)) && getAttribute(BASE_REF).equals( + elem.getAttribute(BASE_REF))); + case IPathEntry.CDT_INCLUDE : return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE)) && getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals( elem.getAttribute(BASE))); - case IPathEntry.CDT_MACRO: + case IPathEntry.CDT_MACRO : return (getAttribute(MACRO_NAME).equals(elem.getAttribute(MACRO_NAME)) && getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals( elem.getAttribute(BASE))); @@ -341,17 +394,17 @@ public class CPElement { final int HASH_FACTOR = 89; int hashCode = fPath.hashCode() + fEntryKind; switch (fEntryKind) { - case IPathEntry.CDT_LIBRARY: + case IPathEntry.CDT_LIBRARY : hashCode = hashCode * HASH_FACTOR + getAttribute(LIBRARY).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); break; - case IPathEntry.CDT_INCLUDE: + case IPathEntry.CDT_INCLUDE : hashCode = hashCode * HASH_FACTOR + getAttribute(INCLUDE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); break; - case IPathEntry.CDT_MACRO: + case IPathEntry.CDT_MACRO : hashCode = hashCode * HASH_FACTOR + getAttribute(MACRO_NAME).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); @@ -405,6 +458,10 @@ public class CPElement { } } + public CPElement getInherited() { + return Inherited; + } + /** * Gets the project. * @@ -432,14 +489,14 @@ public class CPElement { boolean isMissing = false; switch (curr.getEntryKind()) { - case IPathEntry.CDT_CONTAINER: + case IPathEntry.CDT_CONTAINER : res = null; try { isMissing = (CoreModel.getPathEntryContainer(path, project) == null); } catch (CModelException e) { } break; - case IPathEntry.CDT_LIBRARY: + case IPathEntry.CDT_LIBRARY : res = root.findMember(path); if (res == null) { // if (!ArchiveFileFilter.isArchivePath(path)) { @@ -449,12 +506,12 @@ public class CPElement { } isMissing = !path.toFile().isFile(); // look for external } - library = ((ILibraryEntry) curr).getLibraryPath(); - sourceAttachment = ((ILibraryEntry) curr).getSourceAttachmentPath(); - base = ((ILibraryEntry) curr).getBasePath(); - baseRef = ((ILibraryEntry) curr).getBaseReference(); + library = ((ILibraryEntry)curr).getLibraryPath(); + sourceAttachment = ((ILibraryEntry)curr).getSourceAttachmentPath(); + base = ((ILibraryEntry)curr).getBasePath(); + baseRef = ((ILibraryEntry)curr).getBaseReference(); break; - case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_SOURCE : path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { @@ -463,9 +520,9 @@ public class CPElement { } isMissing = true; } - exclusion = ((ISourceEntry) curr).getExclusionPatterns(); + exclusion = ((ISourceEntry)curr).getExclusionPatterns(); break; - case IPathEntry.CDT_OUTPUT: + case IPathEntry.CDT_OUTPUT : path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { @@ -474,9 +531,9 @@ public class CPElement { } isMissing = true; } - exclusion = ((IOutputEntry) curr).getExclusionPatterns(); + exclusion = ((IOutputEntry)curr).getExclusionPatterns(); break; - case IPathEntry.CDT_INCLUDE: + case IPathEntry.CDT_INCLUDE : path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { @@ -487,13 +544,13 @@ public class CPElement { if (res.getType() != IResource.ROOT && project != null) { isMissing = !project.isOnSourceRoot(res); } - exclusion = ((IIncludeEntry) curr).getExclusionPatterns(); - sysInclude = ((IIncludeEntry) curr).isSystemInclude(); - baseRef = ((IIncludeEntry) curr).getBaseReference(); - base = ((IIncludeEntry) curr).getBasePath(); - include = ((IIncludeEntry) curr).getIncludePath(); + exclusion = ((IIncludeEntry)curr).getExclusionPatterns(); + sysInclude = ((IIncludeEntry)curr).isSystemInclude(); + baseRef = ((IIncludeEntry)curr).getBaseReference(); + base = ((IIncludeEntry)curr).getBasePath(); + include = ((IIncludeEntry)curr).getIncludePath(); break; - case IPathEntry.CDT_MACRO: + case IPathEntry.CDT_MACRO : path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { @@ -504,13 +561,13 @@ public class CPElement { if (res.getType() != IResource.ROOT && project != null) { isMissing = !project.isOnSourceRoot(res); } - exclusion = ((IMacroEntry) curr).getExclusionPatterns(); - macroName = ((IMacroEntry) curr).getMacroName(); - macroValue = ((IMacroEntry) curr).getMacroValue(); - baseRef = ((IMacroEntry) curr).getBaseReference(); - base = ((IMacroEntry) curr).getBasePath(); + exclusion = ((IMacroEntry)curr).getExclusionPatterns(); + macroName = ((IMacroEntry)curr).getMacroName(); + macroValue = ((IMacroEntry)curr).getMacroValue(); + baseRef = ((IMacroEntry)curr).getBaseReference(); + base = ((IMacroEntry)curr).getBasePath(); break; - case IPathEntry.CDT_PROJECT: + case IPathEntry.CDT_PROJECT : res = root.findMember(path); isMissing = (res == null); break; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementFilter.java index cce0cd96e3d..e0974b42298 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementFilter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementFilter.java @@ -22,8 +22,9 @@ import org.eclipse.jface.viewers.ViewerFilter; public class CPElementFilter extends ViewerFilter { protected List fExcludes; - protected int fKind; + protected int[] fKind; protected boolean fExportedOnly; + protected boolean fShowInherited; /** * @param excludedFiles @@ -31,16 +32,17 @@ public class CPElementFilter extends ViewerFilter { * @param recusive * Folders are only shown if, searched recursivly, contain an archive */ - public CPElementFilter(Object[] excludedElements, int kind, boolean exportedOnly) { + public CPElementFilter(Object[] excludedElements, int[] kind, boolean exportedOnly, boolean showInherited) { if (excludedElements != null) { fExcludes = Arrays.asList(excludedElements); } fKind = kind; fExportedOnly = exportedOnly; + fShowInherited = showInherited; } - public CPElementFilter(int kind, boolean exportedOnly) { - this(null, kind, exportedOnly); + public CPElementFilter(int[] kind, boolean exportedOnly, boolean showInherited) { + this(null, kind, exportedOnly, showInherited); } /* @@ -48,22 +50,41 @@ public class CPElementFilter extends ViewerFilter { */ public boolean select(Viewer viewer, Object parent, Object element) { if (element instanceof CPElement) { - if ( ((CPElement)element).getEntryKind() == fKind) { - if (fExcludes == null || !fExcludes.contains(element)) { - if (fExportedOnly == true) { - return ((CPElement)element).isExported(); + for (int i = 0; i < fKind.length; i++) { + if ( ((CPElement)element).getEntryKind() == fKind[i]) { + if (fExcludes == null || !fExcludes.contains(element)) { + if (fExportedOnly == true) { + if ( !fShowInherited ) { + return ((CPElement)element).getInherited() == null && ((CPElement)element).isExported(); + } + return ((CPElement)element).isExported(); + } + if ( !fShowInherited ) { + return ((CPElement)element).getInherited() == null; + } + return true; } - return true; } } } else if (element instanceof IPathEntry) { - if ( ((IPathEntry)element).getEntryKind() == fKind) { - if (fExcludes == null || !fExcludes.contains(element)) { - if (fExportedOnly == true) { - return ((IPathEntry)element).isExported(); + for (int i = 0; i < fKind.length; i++) { + if ( ((IPathEntry)element).getEntryKind() == fKind[i]) { + if (fExcludes == null || !fExcludes.contains(element)) { + if (fExportedOnly == true) { + return ((IPathEntry)element).isExported(); + } + return true; } } } + } else if (element instanceof CPElementGroup) { + for (int i = 0; i < fKind.length; i++) { + if ( ((CPElementGroup)element).getEntryKind() == fKind[i]) { + return true; + } + } + } else { + return true; } return false; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementGroup.java index 1fc7855f913..a7de4a88506 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementGroup.java @@ -11,32 +11,96 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; + public class CPElementGroup { - CPElement element; - int kind; + private CPElement parent; + private final int kind; + private IResource resource; + private List children = new ArrayList(1); - public CPElementGroup(CPElement element, int kind) { - this.element = element; + public CPElementGroup(IResource resource) { + this.kind = -1; + this.resource = resource; + this.children = new ArrayList(); + } + + public CPElementGroup(CPElement parent, int kind) { + this.parent = parent; this.kind = kind; } - public CPElement getElement() { - return element; + public IResource getResource() { + return resource; } - - public int getEntryType() { + + public IPath getPath() { + return resource != null ? resource.getFullPath() : parent.getPath(); + } + + public CPElement getParent() { + return parent; + } + + public int getEntryKind() { return kind; } - public Object[] getChildren() { - Object[] children = element.getChildren(); - List rv = new ArrayList(); - for (int i = 0; i < children.length; i++) { - if ((children[i] instanceof CPElement) && ((CPElement)children[i]).getEntryKind() == kind) { - rv.add(children[i]); + public boolean equals(Object arg0) { + if (arg0 == this) { + return true; + } + if (arg0 instanceof CPElementGroup) { + CPElementGroup other = (CPElementGroup)arg0; + return (kind == other.kind && ( (parent == null && other.parent == null) || parent.equals(other.parent)) && ( (resource == null && other.resource == null) || resource.equals(other.resource))); + } + return false; + } + + public int hashCode() { + int hashCode = parent != null ? parent.hashCode() : 0; + hashCode += resource != null ? resource.hashCode() : 0; + return hashCode + kind; + } + + public void addChild(CPElement element) { + int indx = children.indexOf(element); + if (indx == -1) { + children.add(element); + element.setParent(this); + } else { // add element with closes matching resource path. + CPElement other = (CPElement)children.get(indx); + if ( other.getInherited() != null && element.getInherited() != null) { + IPath otherPath = other.getInherited().getPath(); + IPath elemPath = element.getInherited().getPath(); + if (!otherPath.equals(elemPath) && otherPath.isPrefixOf(elemPath)) { + children.remove(indx); + other.setParent(null); + children.add(element); + element.setParent(this); + } } } - return rv.toArray(); } -} + + public void addChildren(CPElement[] elements) { + for (int i = 0; i < elements.length; i++) { + addChild(elements[i]); + } + } + + public boolean removeChild(CPElement element) { + boolean removed = children.remove(element); + if (removed) { + element.setParent(null); + } + return removed; + } + + public CPElement[] getChildren() { + return (CPElement[])children.toArray(new CPElement[children.size()]); + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java index dcbbd76974f..c6b3555e24d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java @@ -12,36 +12,45 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntryContainer; +import org.eclipse.cdt.internal.ui.CElementImageProvider; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; -import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.ide.IDE; -class CPElementLabelProvider extends LabelProvider { +class CPElementLabelProvider extends LabelProvider implements IColorProvider { + + private final Color inDirect = new Color(Display.getDefault(), new RGB(170, 170, 170)); private String fNewLabel, fCreateLabel; private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon; private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage; private boolean bShowExported; + private boolean bShowParentInfo; private ImageDescriptorRegistry fRegistry; - + private CElementImageProvider fCImages; + public CPElementLabelProvider() { - this(true); + this(true, false); } - public CPElementLabelProvider(boolean showExported) { + public CPElementLabelProvider(boolean showExported, boolean showParentInfo) { fNewLabel = CPathEntryMessages.getString("CPElementLabelProvider.new"); //$NON-NLS-1$ fCreateLabel = CPathEntryMessages.getString("CPElementLabelProvider.willbecreated"); //$NON-NLS-1$ fRegistry = CUIPlugin.getImageDescriptorRegistry(); - + fCImages = new CElementImageProvider(); + fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE; fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC; fIncludeIcon = CPluginImages.DESC_OBJS_INCLUDES_FOLDER; @@ -54,6 +63,7 @@ class CPElementLabelProvider extends LabelProvider { fProjectImage = workbench.getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT); bShowExported = showExported; + bShowParentInfo = showParentInfo; } public String getText(Object element) { @@ -70,13 +80,18 @@ class CPElementLabelProvider extends LabelProvider { } private String getCPContainerGroupText(CPElementGroup group) { - switch (group.getEntryType()) { + switch (group.getEntryKind()) { case IPathEntry.CDT_INCLUDE : return CPathEntryMessages.getString("CPElementLabelProvider.Includes"); //$NON-NLS-1$ case IPathEntry.CDT_MACRO : return CPathEntryMessages.getString("CPElementLabelProvider.PreprocessorSymbols"); //$NON-NLS-1$ case IPathEntry.CDT_LIBRARY : return CPathEntryMessages.getString("CPElementLabelProvider.Libraries"); //$NON-NLS-1$ + case -1: + if (group.getResource().getType() == IResource.PROJECT) { + return group.getResource().getName(); + } + return group.getResource().getProjectRelativePath().toString(); } return ""; //$NON-NLS-1$ } @@ -128,6 +143,7 @@ class CPElementLabelProvider extends LabelProvider { StringBuffer str = new StringBuffer(); addBaseString(libPath, cpentry, str); addExport(cpentry, str); + addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_PROJECT : @@ -138,6 +154,7 @@ class CPElementLabelProvider extends LabelProvider { StringBuffer str = new StringBuffer(); addBaseString(incPath, cpentry, str); addExport(cpentry, str); + addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_MACRO : @@ -146,6 +163,7 @@ class CPElementLabelProvider extends LabelProvider { + (String)cpentry.getAttribute(CPElement.MACRO_VALUE)); addBaseString(null, cpentry, str); addExport(cpentry, str); + addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_CONTAINER : @@ -182,6 +200,28 @@ class CPElementLabelProvider extends LabelProvider { } return CPathEntryMessages.getString("CPElementLabelProvider.unknown_element.label"); //$NON-NLS-1$ } + /** + * @param cpentry + * @param str + */ + private void addParentInfo(CPElement cpentry, StringBuffer str) { + if (bShowParentInfo) { + CPElement parent = cpentry.getParentContainer(); + if (parent != null) { + str.append(" ["); //$NON-NLS-1$ + try { + IPathEntryContainer container = CoreModel.getPathEntryContainer(cpentry.getPath(), cpentry.getCProject()); + if (container != null) { + str.append(container.getDescription()); + } + } catch (CModelException e) { + str.append(parent.getPath()); + } + str.append(']'); + } + } + } + private void addExport(CPElement cpentry, StringBuffer str) { if (bShowExported && cpentry.isExported()) { str.append(' '); @@ -244,15 +284,13 @@ class CPElementLabelProvider extends LabelProvider { case IPathEntry.CDT_OUTPUT : if (cpentry.getPath().segmentCount() == 1) { return fProjectImage; - } else { - return fOutputImage; } + return fOutputImage; case IPathEntry.CDT_SOURCE : if (cpentry.getPath().segmentCount() == 1) { return fProjectImage; - } else { - return fFolderImage; } + return fFolderImage; case IPathEntry.CDT_LIBRARY : IPath path = (IPath)cpentry.getAttribute(CPElement.SOURCEATTACHMENT); if (path == null || path.isEmpty()) { @@ -280,7 +318,10 @@ class CPElementLabelProvider extends LabelProvider { ImageDescriptor imageDescriptor = getCPElementBaseImage(cpentry); if (imageDescriptor != null) { if (cpentry.isMissing()) { - imageDescriptor = new CElementImageDescriptor(imageDescriptor, CElementImageDescriptor.WARNING, SMALL_SIZE); + imageDescriptor = new CPListImageDescriptor(imageDescriptor, CPListImageDescriptor.WARNING, SMALL_SIZE); + } + if (cpentry.getInherited() != null) { + imageDescriptor = new CPListImageDescriptor(imageDescriptor, CPListImageDescriptor.PATH_INHERIT, SMALL_SIZE); } return fRegistry.get(imageDescriptor); } @@ -294,15 +335,37 @@ class CPElementLabelProvider extends LabelProvider { } else if (element instanceof IPathEntry) { return getImage(CPElement.createFromExisting((IPathEntry)element, null)); } else if (element instanceof CPElementGroup) { - switch ( ((CPElementGroup)element).getEntryType()) { + switch ( ((CPElementGroup)element).getEntryKind()) { case IPathEntry.CDT_INCLUDE : return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_CONTAINER); case IPathEntry.CDT_MACRO : return fRegistry.get(fMacroIcon); case IPathEntry.CDT_LIBRARY : return CPluginImages.get(CPluginImages.IMG_OBJS_LIBRARY); + case -1: + return fCImages.getImageLabel(((CPElementGroup)element).getResource(), CElementImageProvider.SMALL_ICONS); } } return null; } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) + */ + public Color getForeground(Object element) { + if (element instanceof CPElement) { + if (((CPElement)element).getInherited() != null) { + return inDirect; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) + */ + public Color getBackground(Object element) { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementSorter.java index 5c0377d289e..6f0b9b7bd67 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementSorter.java @@ -9,6 +9,8 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; public class CPElementSorter extends ViewerSorter { @@ -24,18 +26,46 @@ public class CPElementSorter extends ViewerSorter { */ public int category(Object obj) { if (obj instanceof CPElement) { - switch (((CPElement) obj).getEntryKind()) { - case IPathEntry.CDT_LIBRARY: + switch ( ((CPElement)obj).getEntryKind()) { + case IPathEntry.CDT_LIBRARY : return LIBRARY; - case IPathEntry.CDT_PROJECT: + case IPathEntry.CDT_PROJECT : return PROJECT; - case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_SOURCE : return SOURCE; - case IPathEntry.CDT_CONTAINER: + case IPathEntry.CDT_CONTAINER : return CONTAINER; } + } else if (obj instanceof CPElementGroup) { + switch ( ((CPElementGroup)obj).getEntryKind()) { + case IPathEntry.CDT_LIBRARY : + return LIBRARY; + case IPathEntry.CDT_PROJECT : + return PROJECT; + case IPathEntry.CDT_SOURCE : + return SOURCE; + case IPathEntry.CDT_CONTAINER : + return CONTAINER; + case -1 : + if ( ((CPElementGroup)obj).getResource() instanceof IProject) { + return PROJECT; + } + } } return OTHER; } -} + public void sort(Viewer viewer, Object[] elements) { + // include paths and symbol definitions must not be sorted + if (elements.length > 0 && elements[0] instanceof CPElement) { + CPElement firstElement = (CPElement)elements[0]; + switch (firstElement.getEntryKind()) { + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + return; + } + } + super.sort(viewer, elements); + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListImageDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListImageDescriptor.java new file mode 100644 index 00000000000..05cfdb0d665 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListImageDescriptor.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; + +public class CPListImageDescriptor extends CompositeImageDescriptor { + + /** Flag to render the waring adornment */ + public final static int WARNING= 0x1; + + /** Flag to render the inherited adornment */ + public final static int ERROR= 0x2; + + /** Flag to render the inherited adornment */ + public final static int PATH_INHERIT= 0x4; + + private ImageDescriptor fBaseImage; + private int flags; + private Point fSize; + + public CPListImageDescriptor(ImageDescriptor baseImage, int flags, Point size) { + fBaseImage = baseImage; + this.flags = flags; + fSize = size; + } + + /** + * @see CompositeImageDescriptor#getSize() + */ + protected Point getSize() { + if (fSize == null) { + ImageData data = fBaseImage.getImageData(); + setSize(new Point(data.width, data.height)); + } + return fSize; + } + + /** + * @see Object#equals(java.lang.Object) + */ + public boolean equals(Object object) { + if (!(object instanceof CPListImageDescriptor)) { + return false; + } + + CPListImageDescriptor other = (CPListImageDescriptor) object; + return fBaseImage.equals(other.fBaseImage) && flags == other.flags && fSize.equals(other.fSize); + } + + /** + * @see Object#hashCode() + */ + public int hashCode() { + return fBaseImage.hashCode() & flags | fSize.hashCode(); + } + + /** + * @see CompositeImageDescriptor#drawCompositeImage(int, int) + */ + protected void drawCompositeImage(int width, int height) { + ImageData bg = fBaseImage.getImageData(); + if (bg == null) { + bg = DEFAULT_IMAGE_DATA; + } + drawImage(bg, 0, 0); + drawOverlays(); + } + + /** + * Add any overlays to the image as specified in the flags. + */ + protected void drawOverlays() { + Point size= getSize(); + ImageData data = null; + int x= getSize().x; + if ((flags & PATH_INHERIT) == PATH_INHERIT) { + data = CPluginImages.DESC_OVR_PATH_INHERIT.getImageData(); + drawImage(data, x, 0); + } + x= 0; + if ((flags & ERROR) != 0) { + data= CPluginImages.DESC_OVR_ERROR.getImageData(); + drawImage(data, x, size.y - data.height); + x+= data.width; + } + if ((flags & WARNING) != 0) { + data= CPluginImages.DESC_OVR_WARNING.getImageData(); + drawImage(data, x, size.y - data.height); + x+= data.width; + } + } + + protected void setSize(Point size) { + fSize = size; + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java index c6abc365dd9..fe707d0cbb3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java @@ -20,13 +20,13 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWTException; import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Bundle; public class CPathContainerDescriptor implements IContainerDescriptor { @@ -63,11 +63,10 @@ public class CPathContainerDescriptor implements IContainerDescriptor { Object elem = CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS); if (elem instanceof ICPathContainerPage) { return (ICPathContainerPage) elem; - } else { - String id = fConfigElement.getAttribute(ATT_ID); - throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, - "Invalid extension (page not of type IClasspathContainerPage): " + id, null)); //$NON-NLS-1$ - } + } + String id = fConfigElement.getAttribute(ATT_ID); + throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, + "Invalid extension (page not of type IClasspathContainerPage): " + id, null)); //$NON-NLS-1$ } public String getName() { @@ -79,17 +78,18 @@ public class CPathContainerDescriptor implements IContainerDescriptor { String imageName = fConfigElement.getAttribute(ATT_ICON); if (imageName != null) { IExtension extension = fConfigElement.getDeclaringExtension(); - IPluginDescriptor pd = extension.getDeclaringPluginDescriptor(); - Image image = getImageFromPlugin(pd, imageName); + String plugin = extension.getNamespace(); + Image image = getImageFromPlugin(plugin, imageName); pageImage = image; } } return pageImage; } - public Image getImageFromPlugin(IPluginDescriptor pluginDescriptor, String subdirectoryAndFilename) { - URL installURL = pluginDescriptor.getInstallURL(); - return getImageFromURL(installURL, subdirectoryAndFilename); + public Image getImageFromPlugin(String plugin, String subdirectoryAndFilename) { + Bundle bundle = Platform.getBundle(plugin); + URL iconURL = bundle.getEntry("/"); //$NON-NLS-1$ + return getImageFromURL(iconURL, subdirectoryAndFilename); } public Image getImageFromURL(URL installURL, String subdirectoryAndFilename) { @@ -120,7 +120,7 @@ public class CPathContainerDescriptor implements IContainerDescriptor { public static IContainerDescriptor[] getDescriptors() { ArrayList containers = new ArrayList(); - IExtensionPoint extensionPoint = Platform.getPluginRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, ATT_EXTENSION); + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, ATT_EXTENSION); if (extensionPoint != null) { IContainerDescriptor defaultPage = null; String defaultPageName = CPathContainerDefaultPage.class.getName(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerEntryPage.java index 0d6b09921bb..d0a873b5d89 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerEntryPage.java @@ -22,7 +22,6 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; @@ -140,13 +139,7 @@ public class CPathContainerEntryPage extends CPathBasePage { public Object[] getChildren(TreeListDialogField field, Object element) { if (element instanceof CPElement) { - CPElement cpElem = (CPElement)element; - if (cpElem.getEntryKind() == IPathEntry.CDT_CONTAINER) { - return new Object[]{new CPElementGroup(cpElem, IPathEntry.CDT_MACRO), - new CPElementGroup(cpElem, IPathEntry.CDT_INCLUDE), new CPElementGroup(cpElem, IPathEntry.CDT_LIBRARY)}; - } else { - return ((CPElement)element).getChildren(); - } + return ((CPElement)element).getChildren(); } else if (element instanceof CPElementGroup) { return ((CPElementGroup)element).getChildren(); } @@ -157,7 +150,7 @@ public class CPathContainerEntryPage extends CPathBasePage { if (element instanceof CPElementAttribute) { return ((CPElementAttribute)element).getParent(); } else if (element instanceof CPElementGroup) { - return ((CPElementGroup)element).getElement(); + return ((CPElementGroup)element).getParent(); } return null; } @@ -322,17 +315,17 @@ public class CPathContainerEntryPage extends CPathBasePage { } private void editAttributeEntry(CPElementAttribute elem) { - String key = elem.getKey(); - if (key.equals(CPElement.SOURCEATTACHMENT)) { - CPElement selElement = elem.getParent(); - - IPath containerPath = null; - boolean applyChanges = false; - Object parentContainer = selElement.getParentContainer(); - if (parentContainer instanceof CPElement) { - containerPath = ((CPElement)parentContainer).getPath(); - applyChanges = true; - } +// String key = elem.getKey(); +// if (key.equals(CPElement.SOURCEATTACHMENT)) { +// CPElement selElement = elem.getParent(); +// +// IPath containerPath = null; +// boolean applyChanges = false; +// Object parentContainer = selElement.getParentContainer(); +// if (parentContainer instanceof CPElement) { +// containerPath = ((CPElement)parentContainer).getPath(); +// applyChanges = true; +// } // SourceAttachmentDialog dialog = new SourceAttachmentDialog(getShell(), (ILibraryEntry)selElement.getPathEntry(), containerPath, // fCurrCProject, applyChanges); // if (dialog.open() == Window.OK) { @@ -340,7 +333,7 @@ public class CPathContainerEntryPage extends CPathBasePage { // fContainersList.refresh(); // fCPathList.refresh(); // images // } - } +// } } private void editElementEntry(CPElement elem) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java index 75cf06045ff..a6b7e665038 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java @@ -38,24 +38,24 @@ public class CPathContainerWizard extends Wizard { private CPathFilterPage fFilterPage; private CPathContainerSelectionPage fSelectionWizardPage; - private int fFilterType; + private int[] fFilterType; /** * Constructor for ClasspathContainerWizard. */ public CPathContainerWizard(IPathEntry entryToEdit, ICElement currElement, IPathEntry[] currEntries) { - this(entryToEdit, null, currElement, currEntries, -1); + this(entryToEdit, null, currElement, currEntries, null); } /** * Constructor for ClasspathContainerWizard. */ public CPathContainerWizard(IContainerDescriptor pageDesc, ICElement currElement, IPathEntry[] currEntries) { - this(null, pageDesc, currElement, currEntries, -1); + this(null, pageDesc, currElement, currEntries, null); } public CPathContainerWizard(IPathEntry entryToEdit, IContainerDescriptor pageDesc, ICElement currElement, - IPathEntry[] currEntries, int filterType) { + IPathEntry[] currEntries, int[] filterType) { fEntryToEdit = entryToEdit; fPageDesc = pageDesc; fNewEntries = null; @@ -108,7 +108,7 @@ public class CPathContainerWizard extends Wizard { // first page IContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors(); List allContainers = new ArrayList(Arrays.asList(containers)); - if (fFilterType != -1) { + if (fFilterType != null) { allContainers.add(0, new ProjectContainerDescriptor(fFilterType)); } fSelectionWizardPage = new CPathContainerSelectionPage( @@ -124,7 +124,7 @@ public class CPathContainerWizard extends Wizard { fContainerPage = getContainerPage(descriptor); addPage(fContainerPage); } - if (fFilterType != -1) { + if (fFilterType != null) { fFilterPage = new CPathFilterPage(fCurrElement, fFilterType); addPage(fFilterPage); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties index 49023f355b8..3fbb5bdb0b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties @@ -52,6 +52,32 @@ ProjectContainerPage.label=C/C++ Projects: # -------- ExtendingCPathBasePage --------- ExtendingCPathBasePage.sourcePaths=Source Paths: +# -------- CPathIncludeSymbolEntryPage -------- +IncludeSymbolEntryPage.title=Include/Symbols +IncludeSymbolEntryPage.label=Include Paths and Preprocessor Symbols: +IncludeSymbolEntryPage.addFolderFile=Add Folder/File... +IncludeSymbolEntryPage.addUserSymbol=Add Preprocessor Symbol... +IncludeSymbolEntryPage.addExternalInclude=Add External Include Path... +IncludeSymbolEntryPage.addFromWorkspace=Add Include Path from Workspace... +IncludeSymbolEntryPage.addContributed=Add Contributed... +IncludeSymbolEntryPage.edit=Edit... +IncludeSymbolEntryPage.remove=Remove +IncludeSymbolEntryPage.export=Export +IncludeSymbolEntryPage.up=Up +IncludeSymbolEntryPage.down=Down +IncludeSymbolsEntryPage.show_inherited.check=Show Inherited Paths +IncludeSymbolEntryPage.addSymbol.title=Add Preprocessor Symbol +IncludeSymbolEntryPage.addSymbol.message=Symbol definition: +IncludeSymbolEntryPage.addExternal.button.browse=Browse... +IncludeSymbolEntryPage.addExternal.title=Add External Include Path +IncludeSymbolEntryPage.addExternal.message=Include path: +IncludeSymbolEntryPage.ContainerDialog.new.title=Contributed Include Path Selection +IncludeSymbolEntryPage.ContainerDialog.edit.title=Contributed Include Path Selection +IncludeSymbolEntryPage.fromWorkspaceDialog.new.title=New Include Path from Workspace +IncludeSymbolEntryPage.fromWorkspaceDialog.new.description=Select a folder as a include path from the workspace. +IncludeSymbolEntryPage.fromWorkspaceDialog.edit.title=Edit Include Path from Workspace +IncludeSymbolEntryPage.fromWorkspaceDialog.edit.description=Select a folder as a include path from the workspace. + # -------- SymbolsEntryPage --------- SymbolEntryPage.title=Symbols SymbolEntryPage.addUser=Add User Defined... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathFilterPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathFilterPage.java index 0b0a362e606..284877aa1f2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathFilterPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathFilterPage.java @@ -36,7 +36,7 @@ import org.eclipse.swt.widgets.Label; public class CPathFilterPage extends WizardPage { - private final int fFilterType; + private final int[] fFilterType; private CheckboxTableViewer viewer; private IPathEntry fParentEntry; @@ -46,7 +46,7 @@ public class CPathFilterPage extends WizardPage { protected ICElement fCElement; - protected CPathFilterPage(ICElement cElement, int filterType) { + protected CPathFilterPage(ICElement cElement, int[] filterType) { super("CPathFilterPage"); //$NON-NLS-1$ setTitle(CPathEntryMessages.getString("CPathFilterPage.title")); //$NON-NLS-1$ setDescription(CPathEntryMessages.getString("CPathFilterPage.description")); //$NON-NLS-1$ @@ -68,7 +68,7 @@ public class CPathFilterPage extends WizardPage { label.setLayoutData(gd); viewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); viewer.setContentProvider(new ListContentProvider()); - viewer.setLabelProvider(new CPElementLabelProvider(false)); + viewer.setLabelProvider(new CPElementLabelProvider(false, false)); viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { @@ -110,16 +110,16 @@ public class CPathFilterPage extends WizardPage { } catch (CModelException e) { } } - createExlusions(); + createExlusions(fParentEntry.getEntryKind() == IPathEntry.CDT_PROJECT); } - private void createExlusions() { + private void createExlusions(boolean showExported) { fExclusions = new ArrayList(); if (filter != null) { viewer.removeFilter(filter); } - filter = new CPElementFilter(fExclusions.toArray(), fFilterType, true); + filter = new CPElementFilter(fExclusions.toArray(), fFilterType, showExported, false); viewer.addFilter(filter); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java index b9dd45e6b6b..efe34c1d643 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java @@ -17,7 +17,6 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages; import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator; import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; @@ -172,7 +171,7 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage { String title = (existing == null) ? CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.new.title") //$NON-NLS-1$ : CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.title"); //$NON-NLS-1$ String message = (existing == null) ? CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.new.description") //$NON-NLS-1$ - : NewWizardMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.description"); //$NON-NLS-1$ + : CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.description"); //$NON-NLS-1$ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new CElementContentProvider()); @@ -220,7 +219,7 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage { elem = existing.getPathEntry(); } CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), - IPathEntry.CDT_INCLUDE); + new int[] {IPathEntry.CDT_INCLUDE}); wizard.setWindowTitle(title); if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { IPathEntry parent = wizard.getEntriesParent(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeSymbolEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeSymbolEntryPage.java new file mode 100644 index 00000000000..49982c72014 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeSymbolEntryPage.java @@ -0,0 +1,787 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.ICContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IIncludeEntry; +import org.eclipse.cdt.core.model.IMacroEntry; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator; +import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.cdt.ui.CElementContentProvider; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +public class CPathIncludeSymbolEntryPage extends CPathBasePage { + + private TreeListDialogField fIncludeSymPathsList; + private SelectionButtonDialogField fShowInheritedPaths; + private ICProject fCurrCProject; + private ListDialogField fCPathList; + private CPElementFilter fFilter; + + private final int IDX_ADD_FOLDER_FILE = 0; + private final int IDX_ADD_SYMBOL = 2; + private final int IDX_ADD_EXT_INCLUDE = 4; + private final int IDX_ADD_WS_INCLUDE = 5; + private final int IDX_ADD_CONTRIBUTED = 7; + private final int IDX_EDIT = 9; + private final int IDX_REMOVE = 10; + private final int IDX_EXPORT = 12; + private final int IDX_UP = 14; + private final int IDX_DOWN = 15; + + private static final String[] buttonLabel = new String[]{ + + /* 0 */CPathEntryMessages.getString("IncludeSymbolEntryPage.addFolderFile"), //$NON-NLS-1$ + null, + /* 2 */CPathEntryMessages.getString("IncludeSymbolEntryPage.addUserSymbol"), //$NON-NLS-1$ + null, + /* 4 */CPathEntryMessages.getString("IncludeSymbolEntryPage.addExternalInclude"), //$NON-NLS-1$ + /* 5 */CPathEntryMessages.getString("IncludeSymbolEntryPage.addFromWorkspace"), //$NON-NLS-1$ + null, + /* 7 */CPathEntryMessages.getString("IncludeSymbolEntryPage.addContributed"), //$NON-NLS-1$ + null, + /* 9 */CPathEntryMessages.getString("IncludeSymbolEntryPage.edit"), //$NON-NLS-1$ + /* 10 */CPathEntryMessages.getString("IncludeSymbolEntryPage.remove"), //$NON-NLS-1$ + null, + /* 12 */CPathEntryMessages.getString("IncludeSymbolEntryPage.export"), //$NON-NLS-1$ + null, + /* 14 */CPathEntryMessages.getString("IncludeSymbolEntryPage.down"), //$NON-NLS-1$ + /* 15 */CPathEntryMessages.getString("IncludeSymbolEntryPage.up")}; //$NON-NLS-1$ + + private class IncludeSymbolAdapter implements IDialogFieldListener, ITreeListAdapter { + + private final Object[] EMPTY_ARR = new Object[0]; + + // -------- IListAdapter -------- + public void customButtonPressed(TreeListDialogField field, int index) { + ListCustomButtonPressed(field, index); + } + + public void selectionChanged(TreeListDialogField field) { + ListPageSelectionChanged(field); + } + + public void doubleClicked(TreeListDialogField field) { + ListPageDoubleClicked(field); + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + ListPageKeyPressed(field, event); + } + + public Object[] getChildren(TreeListDialogField field, Object element) { + if (element instanceof CPElement) { + return ((CPElement)element).getChildren(); + } else if (element instanceof CPElementGroup) { + return ((CPElementGroup)element).getChildren(); + } + return EMPTY_ARR; + } + + public Object getParent(TreeListDialogField field, Object element) { + if (element instanceof CPElementGroup) { + return ((CPElementGroup)element).getParent(); + } else if (element instanceof CPElement) { + return ((CPElement)element).getParent(); + } + return null; + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + if (element instanceof CPElementGroup) { + return true; + } + if (element instanceof CPElement) { + return ((CPElement)element).getChildren().length > 0; + } + return false; + } + + // ---------- IDialogFieldListener -------- + + public void dialogFieldChanged(DialogField field) { + ListPageDialogFieldChanged(field); + + } + + } + + public CPathIncludeSymbolEntryPage(ListDialogField cPathList) { + super(CPathEntryMessages.getString("IncludeSymbolEntryPage.title")); //$NON-NLS-1$ + fCPathList = cPathList; + IncludeSymbolAdapter adapter = new IncludeSymbolAdapter(); + fIncludeSymPathsList = new TreeListDialogField(adapter, buttonLabel, new CPElementLabelProvider(true, + true)) { + + protected int getTreeStyle() { + return super.getTreeStyle() & ~SWT.MULTI; + } + }; + fIncludeSymPathsList.setLabelText(CPathEntryMessages.getString("IncludeSymbolEntryPage.label")); //$NON-NLS-1$ + fIncludeSymPathsList.enableButton(IDX_REMOVE, false); + fIncludeSymPathsList.enableButton(IDX_EDIT, false); + fIncludeSymPathsList.enableButton(IDX_ADD_CONTRIBUTED, false); + fIncludeSymPathsList.enableButton(IDX_ADD_EXT_INCLUDE, false); + fIncludeSymPathsList.enableButton(IDX_ADD_WS_INCLUDE, false); + fIncludeSymPathsList.enableButton(IDX_ADD_SYMBOL, false); + fIncludeSymPathsList.enableButton(IDX_EXPORT, false); + fIncludeSymPathsList.enableButton(IDX_UP, false); + fIncludeSymPathsList.enableButton(IDX_DOWN, false); + + fShowInheritedPaths= new SelectionButtonDialogField(SWT.CHECK); + fShowInheritedPaths.setSelection(true); + fShowInheritedPaths.setLabelText(CPathEntryMessages.getString("IncludeSymbolsEntryPage.show_inherited.check")); //$NON-NLS-1$ + fShowInheritedPaths.setDialogFieldListener(adapter); + + fFilter = new CPElementFilter(new int[]{-1, IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO, IPathEntry.CDT_CONTAINER}, false, true); + } + + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + + Composite composite = new Composite(parent, SWT.NONE); + + LayoutUtil.doDefaultLayout(composite, new DialogField[]{fIncludeSymPathsList, fShowInheritedPaths}, true); + LayoutUtil.setHorizontalGrabbing(fIncludeSymPathsList.getTreeControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fIncludeSymPathsList.setButtonsMinWidth(buttonBarWidth); + setControl(composite); + fIncludeSymPathsList.getTreeViewer().addFilter(fFilter); + fIncludeSymPathsList.getTreeViewer().setSorter(new CPElementSorter()); + } + + public Image getImage() { + return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_CONTAINER); + } + + public void init(ICProject cproject) { + fCurrCProject = cproject; + List elements = createGroups(); + fIncludeSymPathsList.setElements(elements); + } + + private List createGroups() { + List cpelements = fCPathList.getElements(); + + // create resource groups + List resourceGroups = new ArrayList(5); + CPElementGroup projectGroup = new CPElementGroup(fCurrCProject.getResource()); + resourceGroups.add(projectGroup); + for (int i = 0; i < cpelements.size(); i++) { + CPElement element = (CPElement)cpelements.get(i); + switch (element.getEntryKind()) { + case IPathEntry.CDT_CONTAINER : + projectGroup.addChild(element); + break; + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + CPElementGroup resGroup = new CPElementGroup(element.getResource()); + int ndx = resourceGroups.indexOf(resGroup); + if (ndx == -1) { + resourceGroups.add(resGroup); + } else { + resGroup = (CPElementGroup)resourceGroups.get(ndx); + } + resGroup.addChild(element); + } + } + + // place each path in its appropriate inherited group (or not if + // excluded) + for (int i = 0; i < cpelements.size(); i++) { + CPElement element = (CPElement)cpelements.get(i); + switch (element.getEntryKind()) { + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + addPathToResourceGroups(element, null, resourceGroups); + } + } + return resourceGroups; + } + + private void addPathToResourceGroup(CPElement element, CPElementGroup parent, CPElementGroup group) { + IPath resPath = element.getPath(); + IPath[] exclusions = (IPath[])element.getAttribute(CPElement.EXCLUSION); + if ( (group != parent || !group.getResource().equals(element.getResource())) + && resPath.isPrefixOf(group.getPath()) + && (resPath.equals(group.getPath()) || !CoreModelUtil.isExcludedPath( + group.getResource().getFullPath().removeFirstSegments(resPath.segmentCount()), exclusions))) { + group.addChild(new CPElement(element, group.getPath(), group.getResource())); + } + } + + private void addPathToResourceGroups(CPElement element, CPElementGroup parent, List groups) { + if (parent != null) { + parent.addChild(element); + } + for (int i = 0; i < groups.size(); i++) { + CPElementGroup group = (CPElementGroup)groups.get(i); + addPathToResourceGroup(element, parent, group); + } + } + + private void updatePathOnResourceGroups(CPElement element, List groups) { + CPElementGroup parent = element.getParent(); + for (int i = 0; i < groups.size(); i++) { + CPElementGroup group = (CPElementGroup)groups.get(i); + if (group != parent) { + CPElement[] elements = group.getChildren(); + for (int j = 0; j < elements.length; j++) { + if (elements[j].getInherited() == element) { + group.removeChild(elements[j]); + } + } + addPathToResourceGroup(element, parent, group); + } + } + } + + private CPElement removePathFromResourceGroups(CPElement element, List groups) { + CPElement Inherited = element.getInherited(); + CPElementGroup resGroup = element.getParent(); + resGroup.removeChild(element); + if (Inherited != null) { // applied exclusion to orig. + IPath exclude = element.getPath().removeFirstSegments(Inherited.getPath().segmentCount()); + IPath[] exclusions = (IPath[])Inherited.getAttribute(CPElement.EXCLUSION); + IPath[] newExlusions = new IPath[exclusions.length + 1]; + System.arraycopy(exclusions, 0, newExlusions, 0, exclusions.length); + newExlusions[exclusions.length] = exclude; + Inherited.setAttribute(CPElement.EXCLUSION, newExlusions); + } else { // remove all inherited + for (int i = 0; i < groups.size(); i++) { + CPElementGroup group = (CPElementGroup)groups.get(i); + CPElement elements[] = group.getChildren(); + for (int j = 0; j < elements.length; j++) { + if (elements[j].getInherited() == element) { + group.removeChild(elements[j]); + break; + } + } + } + return element; + } + return null; + } + + protected boolean canRemove(List selected) { + if (selected.size() != 1) { + return false; + } + Object elem = selected.get(0); + if (elem instanceof CPElement) { + CPElement element = (CPElement)elem; + if (element.getParentContainer() == null) { + return element.getEntryKind() == IPathEntry.CDT_INCLUDE || element.getEntryKind() == IPathEntry.CDT_MACRO; + } + } else if (elem instanceof CPElementAttribute) { + CPElementAttribute attrib = (CPElementAttribute)elem; + if (attrib.getKey().equals(CPElement.EXCLUSION)) { + if ( ((IPath[])attrib.getValue()).length > 0) { + return true; + } + } + } + return false; + } + + protected boolean canEdit(List selected) { + if (selected.size() != 1) { + return false; + } + Object elem = selected.get(0); + if (elem instanceof CPElement) { + CPElement element = (CPElement)selected.get(0); + if (element.getParentContainer() == null && element.getInherited() == null) { + return element.getEntryKind() == IPathEntry.CDT_INCLUDE || element.getEntryKind() == IPathEntry.CDT_MACRO; + } + } + if (elem instanceof CPElementAttribute) { + return true; + } + return false; + } + + protected void ListPageDialogFieldChanged(DialogField field) { + if (field == fShowInheritedPaths) { + boolean showInherited = fShowInheritedPaths.isSelected(); + if(fFilter != null) { + fIncludeSymPathsList.getTreeViewer().removeFilter(fFilter); + } + fFilter = new CPElementFilter(new int[]{-1, IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO, IPathEntry.CDT_CONTAINER}, false, showInherited); + fIncludeSymPathsList.getTreeViewer().addFilter(fFilter); + fIncludeSymPathsList.refresh(); + } + } + + protected void ListPageSelectionChanged(TreeListDialogField field) { + List selected = field.getSelectedElements(); + field.enableButton(IDX_REMOVE, canRemove(selected)); + field.enableButton(IDX_EDIT, canEdit(selected)); + field.enableButton(IDX_ADD_CONTRIBUTED, canAddPath(selected)); + field.enableButton(IDX_ADD_EXT_INCLUDE, canAddPath(selected)); + field.enableButton(IDX_ADD_WS_INCLUDE, canAddPath(selected)); + field.enableButton(IDX_ADD_SYMBOL, canAddPath(selected)); + } + + /** + * @param selected + * @return + */ + private boolean canAddPath(List selected) { + CPElementGroup group = getSelectedGroup(); + if (group != null) { + return group.getEntryKind() == -1; // resource group + } + return false; + } + + private CPElementGroup getSelectedGroup() { + List selected = fIncludeSymPathsList.getSelectedElements(); + if (!selected.isEmpty()) { + Object item = selected.get(0); + if (item instanceof CPElement) { + item = ((CPElement)item).getParent(); + } + if (item instanceof CPElementGroup) { + return (CPElementGroup)item; + } + } + return null; + } + + protected void ListCustomButtonPressed(TreeListDialogField field, int index) { + switch (index) { + case IDX_ADD_FOLDER_FILE : + addNewPathResource(); + break; + case IDX_ADD_SYMBOL : + addSymbol(); + break; + case IDX_ADD_EXT_INCLUDE : + addInclude(); + break; + case IDX_ADD_WS_INCLUDE : + addFromWorkspace(); + break; + case IDX_ADD_CONTRIBUTED : + addContributed(); + break; + case IDX_EDIT : + if (canEdit(field.getSelectedElements())) { + editEntry(); + } + break; + case IDX_REMOVE : + if (canRemove(field.getSelectedElements())) { + removeEntry(); + } + } + } + + private void addNewPathResource() { + Class[] acceptedClasses = new Class[]{ICProject.class, ICContainer.class, ITranslationUnit.class}; + TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, false); + ViewerFilter filter = new TypedViewerFilter(acceptedClasses); + + String title = CPathEntryMessages.getString("IncludeSymbolEntryPage.newResource.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("IncludeSymbolEntryPage.newResource.description"); //$NON-NLS-1$ + + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), + new CElementContentProvider()); + dialog.setValidator(validator); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.addFilter(filter); + dialog.setInput(fCurrCProject); + dialog.setInitialSelection(fCurrCProject); + + if (dialog.open() == Window.OK) { + Object[] elements = dialog.getResult(); + IResource resource; + if (elements[0] instanceof IResource) { + resource = (IResource)elements[0]; + } else { + resource = ((ICElement)elements[0]).getResource(); + } + CPElementGroup newGroup = new CPElementGroup(resource); + if (!fIncludeSymPathsList.getElements().contains(newGroup)) { + List cpelements = fCPathList.getElements(); + for (int i = 0; i < cpelements.size(); i++) { + CPElement element = (CPElement)cpelements.get(i); + if (element.getPath().isPrefixOf(newGroup.getPath())) { + switch (element.getEntryKind()) { + case IPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_MACRO : + addPathToResourceGroup(element, null, newGroup); + } + } + } + fIncludeSymPathsList.addElement(newGroup); + } + fIncludeSymPathsList.selectElements(new StructuredSelection(newGroup)); + fIncludeSymPathsList.expandElement(newGroup, 1); + } + } + + private void editEntry() { + List selElements = fIncludeSymPathsList.getSelectedElements(); + if (selElements.size() != 1) { + return; + } + Object element = selElements.get(0); + + if (element instanceof CPElement) { + } else if (element instanceof CPElementAttribute) { + editAttributeEntry((CPElementAttribute)element); + } + } + + private void editAttributeEntry(CPElementAttribute elem) { + String key = elem.getKey(); + if (key.equals(CPElement.EXCLUSION)) { + CPElement selElement = elem.getParent(); + ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement); + if (dialog.open() == Window.OK) { + selElement.setAttribute(CPElement.EXCLUSION, dialog.getExclusionPattern()); + fCPathList.dialogFieldChanged(); // validate + updatePathOnResourceGroups(selElement, fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + } + } + } + + private void removeEntry() { + List selected = getSelection(); + Object elem = selected.get(0); + if (elem instanceof CPElement) { + CPElement removed = removePathFromResourceGroups((CPElement)elem, fIncludeSymPathsList.getElements()); + if (removed != null) { + fCPathList.removeElement(removed); + } + fCPathList.dialogFieldChanged(); // validate + fIncludeSymPathsList.refresh(); + } else if (elem instanceof CPElementAttribute) { + CPElementAttribute attrib = (CPElementAttribute)elem; + String key = attrib.getKey(); + Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null; + attrib.getParent().setAttribute(key, value); + updatePathOnResourceGroups(attrib.getParent(), fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + } + + } + + protected void ListPageDoubleClicked(TreeListDialogField field) { + if (canEdit(fIncludeSymPathsList.getSelectedElements())) { + editEntry(); + } + } + + protected void ListPageKeyPressed(TreeListDialogField field, KeyEvent event) { + if (field == fIncludeSymPathsList) { + if (event.character == SWT.DEL && event.stateMask == 0) { + List selection = field.getSelectedElements(); + if (canEdit(selection)) { + removeEntry(); + } + } + } + } + + protected IPathEntry[] getRawPathEntries() { + IPathEntry[] currEntries = new IPathEntry[fCPathList.getElements().size()]; + for (int i = 0; i < currEntries.length; i++) { + CPElement curr = (CPElement)fCPathList.getElement(i); + currEntries[i] = curr.getPathEntry(); + } + return currEntries; + } + + protected void addSymbol() { + // Popup an entry dialog + InputDialog dialog = new InputDialog(getShell(), CPathEntryMessages.getString("IncludeSymbolEntryPage.addSymbol.title"), //$NON-NLS-1$ + CPathEntryMessages.getString("IncludeSymbolEntryPage.addSymbol.message"), "", //$NON-NLS-1$ //$NON-NLS-2$ + null); + String symbol = null; + if (dialog.open() == Window.OK) { + symbol = dialog.getValue(); + if (symbol != null && symbol.length() > 0) { + List cplist = fCPathList.getElements(); + CPElementGroup group = getSelectedGroup(); + CPElement newPath = new CPElement(fCurrCProject, IPathEntry.CDT_MACRO, group.getResource().getFullPath(), + group.getResource()); + String name, value = ""; //$NON-NLS-1$ + int index = symbol.indexOf("="); //$NON-NLS-1$ + if (index != -1) { + name = symbol.substring(0, index).trim(); + value = symbol.substring(index + 1).trim(); + } else { + name = symbol.trim(); + } + newPath.setAttribute(CPElement.MACRO_NAME, name); + newPath.setAttribute(CPElement.MACRO_VALUE, value); + + if (!cplist.contains(newPath)) { + fCPathList.addElement(newPath); + addPathToResourceGroups(newPath, getSelectedGroup(), fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + fIncludeSymPathsList.expandElement(getSelectedGroup(), 1); + } + } + } + } + + protected void addInclude() { + InputDialog dialog = new SelectPathInputDialog(getShell(), + CPathEntryMessages.getString("IncludeSymbolEntryPage.addExternal.title"), //$NON-NLS-1$ + CPathEntryMessages.getString("IncludeSymbolEntryPage.addExternal.message"), null, null); //$NON-NLS-1$ + String newItem = null; + if (dialog.open() == Window.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals("")) { //$NON-NLS-1$ + List cplist = fCPathList.getElements(); + CPElementGroup group = getSelectedGroup(); + CPElement newPath = new CPElement(fCurrCProject, IPathEntry.CDT_INCLUDE, group.getResource().getFullPath(), + group.getResource()); + newPath.setAttribute(CPElement.INCLUDE, new Path(newItem)); + if (!cplist.contains(newPath)) { + fCPathList.addElement(newPath); + addPathToResourceGroups(newPath, getSelectedGroup(), fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + fIncludeSymPathsList.expandElement(getSelectedGroup(), 1); + } + } + } + } + + protected void addFromWorkspace() { + CPElement[] includes = openWorkspacePathEntryDialog(null); + if (includes != null) { + int nElementsChosen = includes.length; + // remove duplicates + List cplist = fCPathList.getElements(); + for (int i = 0; i < nElementsChosen; i++) { + CPElement curr = includes[i]; + if (!cplist.contains(curr)) { + fCPathList.addElement(curr); + addPathToResourceGroups(curr, getSelectedGroup(), fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + fIncludeSymPathsList.expandElement(getSelectedGroup(), 1); + } + } + } + + } + + protected CPElement[] openWorkspacePathEntryDialog(CPElement existing) { + Class[] acceptedClasses = new Class[]{ICProject.class, IProject.class, IContainer.class, ICContainer.class}; + TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, existing == null); + ViewerFilter filter = new TypedViewerFilter(acceptedClasses); + + String title = (existing == null) ? CPathEntryMessages.getString("IncludeSymbolEntryPage.fromWorkspaceDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("IncludeSymbolEntryPage.fromWorkspaceDialog.edit.title"); //$NON-NLS-1$ + String message = (existing == null) + ? CPathEntryMessages.getString("IncludeSymbolEntryPage.fromWorkspaceDialog.new.description") //$NON-NLS-1$ + : CPathEntryMessages.getString("IncludeSymbolEntryPage.fromWorkspaceDialog.edit.description"); //$NON-NLS-1$ + + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), + new CElementContentProvider()); + dialog.setValidator(validator); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.addFilter(filter); + dialog.setInput(CoreModel.getDefault().getCModel()); + if (existing == null) { + dialog.setInitialSelection(fCurrCProject); + } else { + dialog.setInitialSelection(existing.getCProject()); + } + + if (dialog.open() == Window.OK) { + Object[] elements = dialog.getResult(); + CPElement[] res = new CPElement[elements.length]; + for (int i = 0; i < res.length; i++) { + IProject project; + IPath includePath; + if (elements[i] instanceof IResource) { + project = ((IResource)elements[i]).getProject(); + includePath = ((IResource)elements[i]).getProjectRelativePath(); + } else { + project = ((ICElement)elements[i]).getCProject().getProject(); + includePath = ((ICElement)elements[i]).getResource().getProjectRelativePath(); + } + CPElementGroup group = getSelectedGroup(); + res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_INCLUDE, group.getResource().getFullPath(), + group.getResource()); + res[i].setAttribute(CPElement.BASE, project.getFullPath().makeRelative()); + res[i].setAttribute(CPElement.INCLUDE, includePath); + } + return res; + } + return null; + } + + protected CPElement[] openContainerSelectionDialog(CPElement existing) { + IPathEntry elem = null; + String title; + if (existing == null) { + title = CPathEntryMessages.getString("IncludeSymbolEntryPage.ContainerDialog.new.title"); //$NON-NLS-1$ + } else { + title = CPathEntryMessages.getString("IncludeSymbolEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$ + elem = existing.getPathEntry(); + } + CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawPathEntries(), new int[]{ + IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO}); + wizard.setWindowTitle(title); + if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { + IPathEntry parent = wizard.getEntriesParent(); + IPathEntry[] elements = wizard.getEntries(); + + if (elements != null) { + CPElement[] res = new CPElement[elements.length]; + CPElementGroup group = getSelectedGroup(); + for (int i = 0; i < res.length; i++) { + if (elements[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { + res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_INCLUDE, group.getResource().getFullPath(), + group.getResource()); + res[i].setAttribute(CPElement.INCLUDE, ((IIncludeEntry)elements[i]).getIncludePath()); + res[i].setAttribute(CPElement.BASE_REF, parent.getPath()); + } else if (elements[i].getEntryKind() == IPathEntry.CDT_MACRO) { + res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_MACRO, group.getResource().getFullPath(), + group.getResource()); + res[i].setAttribute(CPElement.MACRO_NAME, ((IMacroEntry)elements[i]).getMacroName()); + res[i].setAttribute(CPElement.BASE_REF, parent.getPath()); + + } + + } + return res; + } + } + return null; + } + + protected void addContributed() { + CPElement[] includes = openContainerSelectionDialog(null); + if (includes != null) { + int nElementsChosen = includes.length; + // remove duplicates + List cplist = fCPathList.getElements(); + + for (int i = 0; i < nElementsChosen; i++) { + CPElement curr = includes[i]; + if (!cplist.contains(curr)) { + fCPathList.addElement(curr); + addPathToResourceGroups(curr, getSelectedGroup(), fIncludeSymPathsList.getElements()); + fIncludeSymPathsList.refresh(); + fIncludeSymPathsList.expandElement(getSelectedGroup(), 1); + } + } + } + } + + private class SelectPathInputDialog extends InputDialog { + + public SelectPathInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, + IInputValidator validator) { + super(parentShell, dialogTitle, dialogMessage, initialValue, validator); + } + + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + Button browse = createButton(parent, 3, + CPathEntryMessages.getString("IncludeSymbolEntryPage.addExternal.button.browse"), //$NON-NLS-1$ + true); //$NON-NLS-1$ + browse.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent ev) { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN); + String currentName = getText().getText(); + if (currentName != null && currentName.trim().length() != 0) { + dialog.setFilterPath(currentName); + } + String dirname = dialog.open(); + if (dirname != null) { + getText().setText(dirname); + } + } + }); + } + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#getSelection() + */ + public List getSelection() { + return fIncludeSymPathsList.getSelectedElements(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#setSelection(java.util.List) + */ + public void setSelection(List selElements) { + fIncludeSymPathsList.selectElements(new StructuredSelection(selElements)); + } + + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_INCLUDE || kind == IPathEntry.CDT_MACRO; + } + + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + public void performDefaults() { + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java index 3a53d74c079..eeddc2dfed2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java @@ -506,7 +506,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { elem = existing.getPathEntry(); } CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawPathEntries(), - IPathEntry.CDT_LIBRARY); + new int[] {IPathEntry.CDT_LIBRARY}); wizard.setWindowTitle(title); if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { IPathEntry parent = wizard.getEntriesParent(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java index 9ca11b2a4c1..58632d66f0f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java @@ -1,11 +1,10 @@ -/******************************************************************************* - * 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 +/*********************************************************************************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: QNX Software Systems - initial API and implementation - ******************************************************************************/ + **********************************************************************************************************************************/ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; @@ -78,9 +77,9 @@ public class CPathOutputEntryPage extends CPathBasePage { String[] buttonLabels; - buttonLabels = new String[] { + buttonLabels = new String[]{ /* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("OutputPathEntryPage.folders.add.button"), //$NON-NLS-1$ - /* 1 */ null, /* 2 = IDX_EDIT */CPathEntryMessages.getString("OutputPathEntryPage.folders.edit.button"), //$NON-NLS-1$ + /* 1 */null, /* 2 = IDX_EDIT */CPathEntryMessages.getString("OutputPathEntryPage.folders.edit.button"), //$NON-NLS-1$ /* 3 = IDX_REMOVE */CPathEntryMessages.getString("OutputPathEntryPage.folders.remove.button") //$NON-NLS-1$ }; @@ -92,8 +91,7 @@ public class CPathOutputEntryPage extends CPathBasePage { fOutputList.enableButton(IDX_EDIT, false); fOutputList.enableButton(IDX_REMOVE, false); } - - + public Image getImage() { return CPluginImages.get(CPluginImages.IMG_OBJS_CONTAINER); } @@ -105,13 +103,13 @@ public class CPathOutputEntryPage extends CPathBasePage { } private void updateFoldersList() { - + List folders = filterList(fCPathList.getElements()); fOutputList.setElements(folders); for (int i = 0; i < folders.size(); i++) { - CPElement cpe = (CPElement) folders.get(i); - IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION); + CPElement cpe = (CPElement)folders.get(i); + IPath[] patterns = (IPath[])cpe.getAttribute(CPElement.EXCLUSION); if (patterns.length > 0) { fOutputList.expandElement(cpe, 3); } @@ -122,7 +120,7 @@ public class CPathOutputEntryPage extends CPathBasePage { PixelConverter converter = new PixelConverter(parent); Composite composite = new Composite(parent, SWT.NONE); - LayoutUtil.doDefaultLayout(composite, new DialogField[] { fOutputList}, true); + LayoutUtil.doDefaultLayout(composite, new DialogField[]{fOutputList}, true); LayoutUtil.setHorizontalGrabbing(fOutputList.getTreeControl(null)); int buttonBarWidth = converter.convertWidthInCharsToPixels(24); @@ -131,8 +129,8 @@ public class CPathOutputEntryPage extends CPathBasePage { // expand List elements = fOutputList.getElements(); for (int i = 0; i < elements.size(); i++) { - CPElement elem = (CPElement) elements.get(i); - IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION); + CPElement elem = (CPElement)elements.get(i); + IPath[] patterns = (IPath[])elem.getAttribute(CPElement.EXCLUSION); if (patterns.length > 0) { fOutputList.expandElement(elem, 3); } @@ -163,14 +161,14 @@ public class CPathOutputEntryPage extends CPathBasePage { public Object[] getChildren(TreeListDialogField field, Object element) { if (element instanceof CPElement) { - return ((CPElement) element).getChildren(); + return ((CPElement)element).getChildren(); } return EMPTY_ARR; } public Object getParent(TreeListDialogField field, Object element) { if (element instanceof CPElementAttribute) { - return ((CPElementAttribute) element).getParent(); + return ((CPElementAttribute)element).getParent(); } return null; } @@ -276,9 +274,9 @@ public class CPathOutputEntryPage extends CPathBasePage { } Object elem = selElements.get(0); if (fOutputList.getIndexOfElement(elem) != -1) { - editElementEntry((CPElement) elem); + editElementEntry((CPElement)elem); } else if (elem instanceof CPElementAttribute) { - editAttributeEntry((CPElementAttribute) elem); + editAttributeEntry((CPElementAttribute)elem); } } @@ -316,7 +314,7 @@ public class CPathOutputEntryPage extends CPathBasePage { for (int i = selElements.size() - 1; i >= 0; i--) { Object elem = selElements.get(i); if (elem instanceof CPElementAttribute) { - CPElementAttribute attrib = (CPElementAttribute) elem; + CPElementAttribute attrib = (CPElementAttribute)elem; String key = attrib.getKey(); Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null; attrib.getParent().setAttribute(key, value); @@ -338,16 +336,16 @@ public class CPathOutputEntryPage extends CPathBasePage { for (int i = 0; i < selElements.size(); i++) { Object elem = selElements.get(i); if (elem instanceof CPElementAttribute) { - CPElementAttribute attrib = (CPElementAttribute) elem; + CPElementAttribute attrib = (CPElementAttribute)elem; if (attrib.getKey().equals(CPElement.EXCLUSION)) { - if (((IPath[]) attrib.getValue()).length == 0) { + if ( ((IPath[])attrib.getValue()).length == 0) { return false; } } else if (attrib.getValue() == null) { return false; } } else if (elem instanceof CPElement) { - CPElement curr = (CPElement) elem; + CPElement curr = (CPElement)elem; if (curr.getParentContainer() != null) { return false; } @@ -390,7 +388,7 @@ public class CPathOutputEntryPage extends CPathBasePage { int lastRemovePos = nEntries; int afterLastSourcePos = 0; for (int i = nEntries - 1; i >= 0; i--) { - CPElement cpe = (CPElement) cpelements.get(i); + CPElement cpe = (CPElement)cpelements.get(i); int kind = cpe.getEntryKind(); if (isEntryKind(kind)) { if (!srcelements.remove(cpe)) { @@ -416,25 +414,22 @@ public class CPathOutputEntryPage extends CPathBasePage { if (includeLinked) { NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); if (dialog.open() == Window.OK) { - IResource createdFolder = (IResource) dialog.getResult()[0]; + IResource createdFolder = (IResource)dialog.getResult()[0]; return newCPOutputElement(createdFolder); } return null; - } else { - String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ - : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ - - IProject proj = fCurrCProject.getProject(); - NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), - existing); - dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ - fProjPath.toString())); - if (dialog.open() == Window.OK) { - IResource folder = dialog.getSourceFolder(); - return newCPOutputElement(folder); - } - return null; } + String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ + IProject proj = fCurrCProject.getProject(); + NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), existing); + dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ + fProjPath.toString())); + if (dialog.open() == Window.OK) { + IResource folder = dialog.getSourceFolder(); + return newCPOutputElement(folder); + } + return null; } private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) { @@ -448,7 +443,7 @@ public class CPathOutputEntryPage extends CPathBasePage { private CPElement[] openOutputContainerDialog(CPElement existing) { - Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class}; + Class[] acceptedClasses = new Class[]{IProject.class, IFolder.class}; List existingContainers = getExistingContainers(null); IProject[] allProjects = fWorkspaceRoot.getProjects(); @@ -465,9 +460,11 @@ public class CPathOutputEntryPage extends CPathBasePage { ILabelProvider lp = new WorkbenchLabelProvider(); ITreeContentProvider cp = new BaseWorkbenchContentProvider(); - String title = (existing == null) ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.title") //$NON-NLS-1$ + String title = (existing == null) + ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.title") //$NON-NLS-1$ : CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.edit.title"); //$NON-NLS-1$ - String message = (existing == null) ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.description") //$NON-NLS-1$ + String message = (existing == null) + ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.description") //$NON-NLS-1$ : CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.edit.description"); //$NON-NLS-1$ MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); @@ -485,7 +482,7 @@ public class CPathOutputEntryPage extends CPathBasePage { Object[] elements = dialog.getResult(); CPElement[] res = new CPElement[elements.length]; for (int i = 0; i < res.length; i++) { - IResource elem = (IResource) elements[i]; + IResource elem = (IResource)elements[i]; res[i] = newCPOutputElement(elem); } return res; @@ -497,7 +494,7 @@ public class CPathOutputEntryPage extends CPathBasePage { List res = new ArrayList(); List cplist = fOutputList.getElements(); for (int i = 0; i < cplist.size(); i++) { - CPElement elem = (CPElement) cplist.get(i); + CPElement elem = (CPElement)cplist.get(i); if (elem != existing) { IResource resource = elem.getResource(); if (resource instanceof IContainer) { // defensive code @@ -552,4 +549,4 @@ public class CPathOutputEntryPage extends CPathBasePage { public void performDefaults() { } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java index 3c9bf8d5999..f5f7981d277 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java @@ -78,7 +78,7 @@ public class CPathSourceEntryPage extends CPathBasePage { String[] buttonLabels; - buttonLabels = new String[] { + buttonLabels = new String[]{ /* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("SourcePathEntryPage.folders.add.button"), //$NON-NLS-1$ /* 1 */null, /* 2 = IDX_EDIT */CPathEntryMessages.getString("SourcePathEntryPath.folders.edit.button"), //$NON-NLS-1$ /* 3 = IDX_REMOVE */CPathEntryMessages.getString("SourcePathEntryPage.folders.remove.button") //$NON-NLS-1$ @@ -93,11 +93,10 @@ public class CPathSourceEntryPage extends CPathBasePage { fFoldersList.enableButton(IDX_REMOVE, false); } - public Image getImage() { return CPluginImages.get(CPluginImages.IMG_OBJS_SOURCE_ROOT); } - + public void init(ICProject cproject) { fCurrCProject = cproject; fProjPath = fCurrCProject.getProject().getFullPath(); @@ -109,8 +108,8 @@ public class CPathSourceEntryPage extends CPathBasePage { fFoldersList.setElements(folders); for (int i = 0; i < folders.size(); i++) { - CPElement cpe = (CPElement) folders.get(i); - IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION); + CPElement cpe = (CPElement)folders.get(i); + IPath[] patterns = (IPath[])cpe.getAttribute(CPElement.EXCLUSION); if (patterns.length > 0) { fFoldersList.expandElement(cpe, 3); } @@ -121,7 +120,7 @@ public class CPathSourceEntryPage extends CPathBasePage { PixelConverter converter = new PixelConverter(parent); Composite composite = new Composite(parent, SWT.NONE); - LayoutUtil.doDefaultLayout(composite, new DialogField[] { fFoldersList}, true); + LayoutUtil.doDefaultLayout(composite, new DialogField[]{fFoldersList}, true); LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null)); int buttonBarWidth = converter.convertWidthInCharsToPixels(24); @@ -130,8 +129,8 @@ public class CPathSourceEntryPage extends CPathBasePage { // expand List elements = fFoldersList.getElements(); for (int i = 0; i < elements.size(); i++) { - CPElement elem = (CPElement) elements.get(i); - IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION); + CPElement elem = (CPElement)elements.get(i); + IPath[] patterns = (IPath[])elem.getAttribute(CPElement.EXCLUSION); if (patterns.length > 0) { fFoldersList.expandElement(elem, 3); } @@ -162,14 +161,14 @@ public class CPathSourceEntryPage extends CPathBasePage { public Object[] getChildren(TreeListDialogField field, Object element) { if (element instanceof CPElement) { - return ((CPElement) element).getChildren(); + return ((CPElement)element).getChildren(); } return EMPTY_ARR; } public Object getParent(TreeListDialogField field, Object element) { if (element instanceof CPElementAttribute) { - return ((CPElementAttribute) element).getParent(); + return ((CPElementAttribute)element).getParent(); } return null; } @@ -275,9 +274,9 @@ public class CPathSourceEntryPage extends CPathBasePage { } Object elem = selElements.get(0); if (fFoldersList.getIndexOfElement(elem) != -1) { - editElementEntry((CPElement) elem); + editElementEntry((CPElement)elem); } else if (elem instanceof CPElementAttribute) { - editAttributeEntry((CPElementAttribute) elem); + editAttributeEntry((CPElementAttribute)elem); } } @@ -315,7 +314,7 @@ public class CPathSourceEntryPage extends CPathBasePage { for (int i = selElements.size() - 1; i >= 0; i--) { Object elem = selElements.get(i); if (elem instanceof CPElementAttribute) { - CPElementAttribute attrib = (CPElementAttribute) elem; + CPElementAttribute attrib = (CPElementAttribute)elem; String key = attrib.getKey(); Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null; attrib.getParent().setAttribute(key, value); @@ -337,16 +336,16 @@ public class CPathSourceEntryPage extends CPathBasePage { for (int i = 0; i < selElements.size(); i++) { Object elem = selElements.get(i); if (elem instanceof CPElementAttribute) { - CPElementAttribute attrib = (CPElementAttribute) elem; + CPElementAttribute attrib = (CPElementAttribute)elem; if (attrib.getKey().equals(CPElement.EXCLUSION)) { - if (((IPath[]) attrib.getValue()).length == 0) { + if ( ((IPath[])attrib.getValue()).length == 0) { return false; } } else if (attrib.getValue() == null) { return false; } } else if (elem instanceof CPElement) { - CPElement curr = (CPElement) elem; + CPElement curr = (CPElement)elem; if (curr.getParentContainer() != null) { return false; } @@ -389,7 +388,7 @@ public class CPathSourceEntryPage extends CPathBasePage { int lastRemovePos = nEntries; int afterLastSourcePos = 0; for (int i = nEntries - 1; i >= 0; i--) { - CPElement cpe = (CPElement) cpelements.get(i); + CPElement cpe = (CPElement)cpelements.get(i); int kind = cpe.getEntryKind(); if (isEntryKind(kind)) { if (!srcelements.remove(cpe)) { @@ -415,25 +414,23 @@ public class CPathSourceEntryPage extends CPathBasePage { if (includeLinked) { NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); if (dialog.open() == Window.OK) { - IResource createdFolder = (IResource) dialog.getResult()[0]; + IResource createdFolder = (IResource)dialog.getResult()[0]; return newCPSourceElement(createdFolder); } return null; - } else { - String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ - : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ - - IProject proj = fCurrCProject.getProject(); - NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), - existing); - dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ - fProjPath.toString())); - if (dialog.open() == Window.OK) { - IResource folder = dialog.getSourceFolder(); - return newCPSourceElement(folder); - } - return null; } + String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ + + IProject proj = fCurrCProject.getProject(); + NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), existing); + dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ + fProjPath.toString())); + if (dialog.open() == Window.OK) { + IResource folder = dialog.getSourceFolder(); + return newCPSourceElement(folder); + } + return null; } private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) { @@ -447,7 +444,7 @@ public class CPathSourceEntryPage extends CPathBasePage { private CPElement[] openSourceContainerDialog(CPElement existing) { - Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class}; + Class[] acceptedClasses = new Class[]{IProject.class, IFolder.class}; List existingContainers = getExistingContainers(null); IProject[] allProjects = fWorkspaceRoot.getProjects(); @@ -464,9 +461,11 @@ public class CPathSourceEntryPage extends CPathBasePage { ILabelProvider lp = new WorkbenchLabelProvider(); ITreeContentProvider cp = new BaseWorkbenchContentProvider(); - String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.title") //$NON-NLS-1$ + String title = (existing == null) + ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.title") //$NON-NLS-1$ : CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.edit.title"); //$NON-NLS-1$ - String message = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.description") //$NON-NLS-1$ + String message = (existing == null) + ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.description") //$NON-NLS-1$ : CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.edit.description"); //$NON-NLS-1$ MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); @@ -484,7 +483,7 @@ public class CPathSourceEntryPage extends CPathBasePage { Object[] elements = dialog.getResult(); CPElement[] res = new CPElement[elements.length]; for (int i = 0; i < res.length; i++) { - IResource elem = (IResource) elements[i]; + IResource elem = (IResource)elements[i]; res[i] = newCPSourceElement(elem); } return res; @@ -496,7 +495,7 @@ public class CPathSourceEntryPage extends CPathBasePage { List res = new ArrayList(); List cplist = fFoldersList.getElements(); for (int i = 0; i < cplist.size(); i++) { - CPElement elem = (CPElement) cplist.get(i); + CPElement elem = (CPElement)cplist.get(i); if (elem != existing) { IResource resource = elem.getResource(); if (resource instanceof IContainer) { // defensive code @@ -550,4 +549,4 @@ public class CPathSourceEntryPage extends CPathBasePage { */ public void performDefaults() { } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java index e0e3cce5d4e..dce31e4be8e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java @@ -157,7 +157,7 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage { elem = existing.getPathEntry(); } CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), - IPathEntry.CDT_MACRO); + new int[] {IPathEntry.CDT_MACRO}); wizard.setWindowTitle(title); if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { IPathEntry parent = wizard.getEntriesParent(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java index 2866cf731d8..6f8e1cbe3b7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java @@ -219,9 +219,8 @@ public class ExclusionPatternEntryDialog extends StatusDialog { IPath path = res.getFullPath().removeFirstSegments(fCurrSourceFolder.getFullPath().segmentCount()).makeRelative(); if (res instanceof IContainer) { return path.addTrailingSeparator(); - } else { - return path; } + return path; } return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java index 80bc617ed7e..38585a9326c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.util.PixelConverter; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; @@ -32,15 +31,11 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; @@ -74,84 +69,6 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { private final Color inDirect = new Color(Display.getDefault(), new RGB(170, 170, 170)); - private class CPListImageDescriptor extends CompositeImageDescriptor { - - private Image fBaseImage; - private boolean showInherited; - private Point fSize; - - public CPListImageDescriptor(Image baseImage, boolean inherited) { - fBaseImage = baseImage; - showInherited = inherited; - } - - /** - * @see CompositeImageDescriptor#getSize() - */ - protected Point getSize() { - if (fSize == null) { - ImageData data = fBaseImage.getImageData(); - setSize(new Point(data.width, data.height)); - } - return fSize; - } - - /** - * @see Object#equals(java.lang.Object) - */ - public boolean equals(Object object) { - if (!(object instanceof CPListImageDescriptor)) { - return false; - } - - CPListImageDescriptor other = (CPListImageDescriptor) object; - return (fBaseImage.equals(other.fBaseImage) && showInherited == other.showInherited); - } - - /** - * @see Object#hashCode() - */ - public int hashCode() { - return fBaseImage.hashCode() & (showInherited ? ~0x1 : ~0); - } - - /** - * @see CompositeImageDescriptor#drawCompositeImage(int, int) - */ - protected void drawCompositeImage(int width, int height) { - ImageData bg = fBaseImage.getImageData(); - if (bg == null) { - bg = DEFAULT_IMAGE_DATA; - } - drawImage(bg, 0, 0); - drawOverlays(); - } - - /** - * Add any overlays to the image as specified in the flags. - */ - protected void drawOverlays() { - ImageData data = null; - if (showInherited) { - data = CPluginImages.DESC_OVR_PATH_INHERIT.getImageData(); - drawImage(data, 0, 0); - } - } - - protected void setSize(Point size) { - fSize = size; - } - - } - - public Image getImage(Object element) { - Image image = super.getImage(element); - if (isPathInheritedFromSelected((CPElement) element)) { - image = new CPListImageDescriptor(image, true).createImage(); - } - return image; - } - public Color getBackground(Object element) { return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java index 4814910d4d4..45f6fabdd26 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java @@ -40,7 +40,7 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus private static final String PAGE_SETTINGS = "IncludeSysmbolsPropertyPage"; //$NON-NLS-1$ private static final String INDEX = "pageIndex"; //$NON-NLS-1$ - IncludesSymbolsTabBlock fIncludesSymbolsBlock; + NewIncludesSymbolsTabBlock fIncludesSymbolsBlock; /** * @see PropertyPage#createContents @@ -56,6 +56,7 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus result = createWithCProject(parent, project); } Dialog.applyDialogFont(result); + noDefaultAndApplyButton(); return result; } @@ -73,7 +74,7 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus * Content for valid projects. */ private Control createWithCProject(Composite parent, IProject project) { - fIncludesSymbolsBlock = new IncludesSymbolsTabBlock(this, getSettings().getInt(INDEX)); + fIncludesSymbolsBlock = new NewIncludesSymbolsTabBlock(this, getSettings().getInt(INDEX)); fIncludesSymbolsBlock.init(getCElement(), null); return fIncludesSymbolsBlock.createContents(parent); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewIncludesSymbolsTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewIncludesSymbolsTabBlock.java new file mode 100644 index 00000000000..48966a51576 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewIncludesSymbolsTabBlock.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class NewIncludesSymbolsTabBlock extends AbstractPathOptionBlock { + + private int[] pathTypes = { IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO, IPathEntry.CDT_CONTAINER}; + + private CPathIncludeSymbolEntryPage fIncludeSymbols; + + private CheckedListDialogField fCPathList; + + private List fCPaths; + + private class BuildPathAdapter implements IDialogFieldListener { + + // ---------- IDialogFieldListener -------- + public void dialogFieldChanged(DialogField field) { + buildPathDialogFieldChanged(field); + } + } + + void buildPathDialogFieldChanged(DialogField field) { + if (field == fCPathList) { + updateCPathStatus(); + } + doStatusLineUpdate(); + } + + public NewIncludesSymbolsTabBlock(IStatusChangeListener context, int pageToShow) { + super(context, pageToShow); + + String[] buttonLabels = new String[] { /* 0 */CPathEntryMessages.getString("CPathsBlock.path.up.button"), //$NON-NLS-1$ + /* 1 */CPathEntryMessages.getString("CPathsBlock.path.down.button"), //$NON-NLS-1$ + /* 2 */null, /* 3 */CPathEntryMessages.getString("CPathsBlock.path.checkall.button"), //$NON-NLS-1$ + /* 4 */CPathEntryMessages.getString("CPathsBlock.path.uncheckall.button") //$NON-NLS-1$ + + }; + BuildPathAdapter adapter = new BuildPathAdapter(); + + fCPathList = new CheckedListDialogField(null, buttonLabels, new CPElementLabelProvider()); + fCPathList.setDialogFieldListener(adapter); + fCPathList.setLabelText(CPathEntryMessages.getString("CPathsBlock.path.label")); //$NON-NLS-1$ + fCPathList.setUpButtonIndex(0); + fCPathList.setDownButtonIndex(1); + fCPathList.setCheckAllButtonIndex(3); + fCPathList.setUncheckAllButtonIndex(4); + } + + protected void addTabs() { + fIncludeSymbols = new CPathIncludeSymbolEntryPage(fCPathList); + addPage(fIncludeSymbols); + } + + public Control createContents(Composite parent) { + Control control = super.createContents(parent); + if (getCProject() != null) { + fIncludeSymbols.init(getCProject()); + } + Dialog.applyDialogFont(control); + return control; + } + + protected List getCPaths() { + return fCPathList.getElements(); + } + + protected int[] getFilteredTypes() { + return pathTypes; + } + + /** + * Validates the build path. + */ + public void updateCPathStatus() { + getPathStatus().setOK(); + + List elements = fCPathList.getElements(); + + CPElement entryMissing = null; + int nEntriesMissing = 0; + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = elements.size() - 1; i >= 0; i--) { + CPElement currElement = (CPElement) elements.get(i); + boolean isChecked = fCPathList.isChecked(currElement); + if (currElement.getEntryKind() == IPathEntry.CDT_SOURCE) { + if (isChecked) { + fCPathList.setCheckedWithoutUpdate(currElement, false); + } + } else { + currElement.setExported(isChecked); + } + + entries[i] = currElement.getPathEntry(); + if (currElement.isMissing()) { + nEntriesMissing++; + if (entryMissing == null) { + entryMissing = currElement; + } + } + } + + if (nEntriesMissing > 0) { + if (nEntriesMissing == 1) { + getPathStatus().setWarning(CPathEntryMessages.getFormattedString("CPathsBlock.warning.EntryMissing", //$NON-NLS-1$ + entryMissing.getPath().toString())); + } else { + getPathStatus().setWarning(CPathEntryMessages.getFormattedString("CPathsBlock.warning.EntriesMissing", //$NON-NLS-1$ + String.valueOf(nEntriesMissing))); + } + } + + updateBuildPathStatus(); + } + + protected void initialize(ICElement element, List cPaths) { + fCPaths = cPaths; + + List exportedEntries = new ArrayList(); + for (int i = 0; i < fCPaths.size(); i++) { + CPElement curr = (CPElement) fCPaths.get(i); + if (curr.isExported()) { + exportedEntries.add(curr); + } + } + + fCPathList.setElements(cPaths); + fCPathList.setCheckedElements(exportedEntries); + + if (fIncludeSymbols != null) { + fIncludeSymbols.init(getCProject()); + } + doStatusLineUpdate(); + initializeTimeStamps(); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerDescriptor.java index 5e3d3c7e1d3..4d98b835255 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerDescriptor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerDescriptor.java @@ -16,9 +16,9 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.ui.ide.IDE; public class ProjectContainerDescriptor implements IContainerDescriptor { - private int fFilterType; + private int[] fFilterType; - public ProjectContainerDescriptor(int filterType) { + public ProjectContainerDescriptor(int[] filterType) { fFilterType = filterType; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerPage.java index 78b81dada8e..40311e5009f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ProjectContainerPage.java @@ -1,11 +1,10 @@ -/******************************************************************************* - * 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 +/*********************************************************************************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: QNX Software Systems - initial API and implementation - ******************************************************************************/ + **********************************************************************************************************************************/ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; @@ -37,11 +36,11 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; public class ProjectContainerPage extends WizardPage implements ICPathContainerPage { - private int fFilterType; + private int[] fFilterType; private TableViewer viewer; private ICProject fCProject; - protected ProjectContainerPage(int filterType) { + protected ProjectContainerPage(int[] filterType) { super("projectContainerPage"); //$NON-NLS-1$ setTitle(CPathEntryMessages.getString("ProjectContainerPage.title")); //$NON-NLS-1$ setDescription(CPathEntryMessages.getString("ProjectContainerPage.description")); //$NON-NLS-1$ @@ -121,9 +120,11 @@ public class ProjectContainerPage extends WizardPage implements ICPathContainerP if (!cProjects[i].equals(fCProject) && !current.contains(CoreModel.newProjectEntry(cProjects[i].getPath()))) { IPathEntry[] projEntries = cProjects[i].getRawPathEntries(); for (int j = 0; j < projEntries.length; j++) { - if (projEntries[j].getEntryKind() == fFilterType && projEntries[j].isExported()) { - list.add(cProjects[i]); - break; + for (int k = 0; k < fFilterType.length; k++) { + if (projEntries[j].getEntryKind() == fFilterType[k] && projEntries[j].isExported()) { + list.add(cProjects[i]); + break; + } } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java index 3439f78407c..3964b2d67a0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java @@ -64,85 +64,87 @@ import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; /** - * UI to set the source attachment archive and root. - * Same implementation for both setting attachments for libraries from - * variable entries and for normal (internal or external) jar. + * UI to set the source attachment archive and root. Same implementation for both setting attachments for libraries from variable + * entries and for normal (internal or external) jar. * * SourceAttachmentBlock */ public class SourceAttachmentBlock { - + private IStatusChangeListener fContext; - + private StringButtonDialogField fFileNameField; private SelectionButtonDialogField fWorkspaceButton; private SelectionButtonDialogField fExternalFolderButton; - + private IStatus fNameStatus; - + private IWorkspaceRoot fWorkspaceRoot; - + private Control fSWTWidget; private CLabel fFullPathResolvedLabel; - + private ICProject fProject; private ILibraryEntry fEntry; /** - * @deprecated + * @deprecated */ public SourceAttachmentBlock(IWorkspaceRoot root, IStatusChangeListener context, ILibraryEntry oldEntry) { this(context, oldEntry, null); - } - + } + /** - * @param context listeners for status updates - * @param entry The entry to edit - * @param containerPath Path of the container that contains the given entry or - * null if the entry does not belong to a container. - * @param project Project to which the entry belongs. Can be - * null if getRunnable is not run and the entry - * does not belong to a container. - * + * @param context + * listeners for status updates + * @param entry + * The entry to edit + * @param containerPath + * Path of the container that contains the given entry or null if the entry does not belong to a + * container. + * @param project + * Project to which the entry belongs. Can be null if getRunnable is not run and the + * entry does not belong to a container. + * */ public SourceAttachmentBlock(IStatusChangeListener context, ILibraryEntry entry, ICProject project) { Assert.isNotNull(entry); - - fContext= context; - fEntry= entry; - fProject= project; - - fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); - - fNameStatus= new StatusInfo(); - - SourceAttachmentAdapter adapter= new SourceAttachmentAdapter(); - - fFileNameField= new StringButtonDialogField(adapter); + + fContext = context; + fEntry = entry; + fProject = project; + + fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + + fNameStatus = new StatusInfo(); + + SourceAttachmentAdapter adapter = new SourceAttachmentAdapter(); + + fFileNameField = new StringButtonDialogField(adapter); fFileNameField.setDialogFieldListener(adapter); fFileNameField.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.label")); //$NON-NLS-1$ fFileNameField.setButtonLabel(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfile.button")); //$NON-NLS-1$ - - fWorkspaceButton= new SelectionButtonDialogField(SWT.PUSH); + + fWorkspaceButton = new SelectionButtonDialogField(SWT.PUSH); fWorkspaceButton.setDialogFieldListener(adapter); fWorkspaceButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.internal.button")); //$NON-NLS-1$ - fExternalFolderButton= new SelectionButtonDialogField(SWT.PUSH); + fExternalFolderButton = new SelectionButtonDialogField(SWT.PUSH); fExternalFolderButton.setDialogFieldListener(adapter); fExternalFolderButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfolder.button")); //$NON-NLS-1$ - + // set the old settings setDefaults(); } - + public void setDefaults() { if (fEntry.getSourceAttachmentPath() != null) { fFileNameField.setText(fEntry.getSourceAttachmentPath().toString()); } else { fFileNameField.setText(""); //$NON-NLS-1$ - } + } } - + /** * Gets the source attachment path chosen by the user */ @@ -154,8 +156,7 @@ public class SourceAttachmentBlock { } /** - * Gets the source attachment root chosen by the user - * Returns null to let JCore automatically detect the root. + * Gets the source attachment root chosen by the user Returns null to let JCore automatically detect the root. */ public IPath getSourceAttachmentRootPath() { return null; @@ -163,6 +164,7 @@ public class SourceAttachmentBlock { /** * Null for now + * * @return */ public IPath getSourceAttachmentPrefixMapping() { @@ -173,29 +175,30 @@ public class SourceAttachmentBlock { * Creates the control */ public Control createControl(Composite parent) { - PixelConverter converter= new PixelConverter(parent); - - fSWTWidget= parent; - - Composite composite= new Composite(parent, SWT.NONE); - - GridLayout layout= new GridLayout(); - layout.marginHeight= 0; - layout.marginWidth= 0; - layout.numColumns= 4; + PixelConverter converter = new PixelConverter(parent); + + fSWTWidget = parent; + + Composite composite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 4; composite.setLayout(layout); - int widthHint= converter.convertWidthInCharsToPixels(60); - - GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan= 3; + int widthHint = converter.convertWidthInCharsToPixels(60); - Label message= new Label(composite, SWT.LEFT); + GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan = 3; + + Label message = new Label(composite, SWT.LEFT); message.setLayoutData(gd); - message.setText(CPathEntryMessages.getFormattedString("SourceAttachmentBlock.message", fEntry.getLibraryPath().lastSegment())); //$NON-NLS-1$ - + message.setText(CPathEntryMessages.getFormattedString( + "SourceAttachmentBlock.message", fEntry.getLibraryPath().lastSegment())); //$NON-NLS-1$ + fWorkspaceButton.doFillIntoGrid(composite, 1); - + // archive name field fFileNameField.doFillIntoGrid(composite, 4); LayoutUtil.setWidthHint(fFileNameField.getTextControl(null), widthHint); @@ -203,190 +206,187 @@ public class SourceAttachmentBlock { // aditional 'browse workspace' button for normal jars DialogField.createEmptySpace(composite, 3); - + fExternalFolderButton.doFillIntoGrid(composite, 1); - + fFileNameField.postSetFocusOnDialogField(parent.getDisplay()); - + Dialog.applyDialogFont(composite); - + //WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.SOURCE_ATTACHMENT_BLOCK); return composite; } - - + private class SourceAttachmentAdapter implements IStringButtonAdapter, IDialogFieldListener { - + // -------- IStringButtonAdapter -------- public void changeControlPressed(DialogField field) { - attachmentChangeControlPressed(field); + attachmentChangeControlPressed(field); } - + // ---------- IDialogFieldListener -------- public void dialogFieldChanged(DialogField field) { attachmentDialogFieldChanged(field); } } - + private void attachmentChangeControlPressed(DialogField field) { if (field == fFileNameField) { - IPath jarFilePath= chooseExtJarFile(); + IPath jarFilePath = chooseExtJarFile(); if (jarFilePath != null) { fFileNameField.setText(jarFilePath.toString()); } - } + } } - + // ---------- IDialogFieldListener -------- private void attachmentDialogFieldChanged(DialogField field) { if (field == fFileNameField) { - fNameStatus= updateFileNameStatus(); + fNameStatus = updateFileNameStatus(); } else if (field == fWorkspaceButton) { - IPath jarFilePath= chooseInternalJarFile(); + IPath jarFilePath = chooseInternalJarFile(); if (jarFilePath != null) { fFileNameField.setText(jarFilePath.toString()); } return; } else if (field == fExternalFolderButton) { - IPath folderPath= chooseExtFolder(); + IPath folderPath = chooseExtFolder(); if (folderPath != null) { fFileNameField.setText(folderPath.toString()); } return; } doStatusLineUpdate(); - } - + } + private void doStatusLineUpdate() { fFileNameField.enableButton(canBrowseFileName()); - + // set the resolved path for variable jars if (fFullPathResolvedLabel != null) { fFullPathResolvedLabel.setText(getResolvedLabelString(fFileNameField.getText(), true)); } - - IStatus status= StatusUtil.getMostSevere(new IStatus[] { fNameStatus }); + + IStatus status = StatusUtil.getMostSevere(new IStatus[]{fNameStatus}); fContext.statusChanged(status); } - + private boolean canBrowseFileName() { return true; } - + private String getResolvedLabelString(String path, boolean osPath) { - IPath resolvedPath= getResolvedPath(new Path(path)); + IPath resolvedPath = getResolvedPath(new Path(path)); if (resolvedPath != null) { if (osPath) { return resolvedPath.toOSString(); - } else { - return resolvedPath.toString(); } + return resolvedPath.toString(); } return ""; //$NON-NLS-1$ - } + } /* * Do substitution here */ private IPath getResolvedPath(IPath path) { return path; - } - + } + private IStatus updateFileNameStatus() { - StatusInfo status= new StatusInfo(); - - String fileName= fFileNameField.getText(); + StatusInfo status = new StatusInfo(); + + String fileName = fFileNameField.getText(); if (fileName.length() == 0) { // no source attachment return status; - } else { - if (!Path.EMPTY.isValidPath(fileName)) { - status.setError(CPathEntryMessages.getString("SourceAttachmentBlock.filename.error.notvalid")); //$NON-NLS-1$ - return status; - } - IPath filePath= new Path(fileName); - File file= filePath.toFile(); - IResource res= fWorkspaceRoot.findMember(filePath); - if (res != null && res.getLocation() != null) { - file= res.getLocation().toFile(); - } - if (!file.exists()) { - String message= CPathEntryMessages.getFormattedString("SourceAttachmentBlock.filename.error.filenotexists", filePath.toString()); //$NON-NLS-1$ - status.setError(message); - return status; - } + } + if (!Path.EMPTY.isValidPath(fileName)) { + status.setError(CPathEntryMessages.getString("SourceAttachmentBlock.filename.error.notvalid")); //$NON-NLS-1$ + return status; + } + IPath filePath = new Path(fileName); + File file = filePath.toFile(); + IResource res = fWorkspaceRoot.findMember(filePath); + if (res != null && res.getLocation() != null) { + file = res.getLocation().toFile(); + } + if (!file.exists()) { + String message = CPathEntryMessages.getFormattedString( + "SourceAttachmentBlock.filename.error.filenotexists", filePath.toString()); //$NON-NLS-1$ + status.setError(message); + return status; } return status; } - + /* * Opens a dialog to choose a jar from the file system. */ private IPath chooseExtJarFile() { - IPath currPath= new Path(fFileNameField.getText()); + IPath currPath = new Path(fFileNameField.getText()); if (currPath.isEmpty()) { - currPath= fEntry.getPath(); - } - - if (ArchiveFileFilter.isArchivePath(currPath)) { - currPath= currPath.removeLastSegments(1); + currPath = fEntry.getPath(); } - - FileDialog dialog= new FileDialog(getShell()); + + if (ArchiveFileFilter.isArchivePath(currPath)) { + currPath = currPath.removeLastSegments(1); + } + + FileDialog dialog = new FileDialog(getShell()); dialog.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extjardialog.text")); //$NON-NLS-1$ - dialog.setFilterExtensions(new String[] {"*.jar;*.zip"}); //$NON-NLS-1$ + dialog.setFilterExtensions(new String[]{"*.jar;*.zip"}); //$NON-NLS-1$ dialog.setFilterPath(currPath.toOSString()); - String res= dialog.open(); + String res = dialog.open(); if (res != null) { return new Path(res).makeAbsolute(); } return null; } - + private IPath chooseExtFolder() { - IPath currPath= new Path(fFileNameField.getText()); + IPath currPath = new Path(fFileNameField.getText()); if (currPath.isEmpty()) { - currPath= fEntry.getPath(); + currPath = fEntry.getPath(); } if (ArchiveFileFilter.isArchivePath(currPath)) { - currPath= currPath.removeLastSegments(1); + currPath = currPath.removeLastSegments(1); } - - DirectoryDialog dialog= new DirectoryDialog(getShell()); + + DirectoryDialog dialog = new DirectoryDialog(getShell()); dialog.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extfolderdialog.text")); //$NON-NLS-1$ dialog.setFilterPath(currPath.toOSString()); - String res= dialog.open(); + String res = dialog.open(); if (res != null) { return new Path(res).makeAbsolute(); } return null; - } - + } /* * Opens a dialog to choose an internal jar. - */ + */ private IPath chooseInternalJarFile() { - String initSelection= fFileNameField.getText(); - - Class[] acceptedClasses= new Class[] { IFolder.class, IFile.class }; - TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, false); - - ViewerFilter filter= new ArchiveFileFilter(null, false); + String initSelection = fFileNameField.getText(); - ILabelProvider lp= new WorkbenchLabelProvider(); - ITreeContentProvider cp= new WorkbenchContentProvider(); + Class[] acceptedClasses = new Class[]{IFolder.class, IFile.class}; + TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, false); - IResource initSel= null; + ViewerFilter filter = new ArchiveFileFilter(null, false); + + ILabelProvider lp = new WorkbenchLabelProvider(); + ITreeContentProvider cp = new WorkbenchContentProvider(); + + IResource initSel = null; if (initSelection.length() > 0) { - initSel= fWorkspaceRoot.findMember(new Path(initSelection)); + initSel = fWorkspaceRoot.findMember(new Path(initSelection)); } if (initSel == null) { - initSel= fWorkspaceRoot.findMember(fEntry.getPath()); + initSel = fWorkspaceRoot.findMember(fEntry.getPath()); } - FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp); + FolderSelectionDialog dialog = new FolderSelectionDialog(getShell(), lp, cp); dialog.setAllowMultiple(false); dialog.setValidator(validator); dialog.addFilter(filter); @@ -395,34 +395,34 @@ public class SourceAttachmentBlock { dialog.setInput(fWorkspaceRoot); dialog.setInitialSelection(initSel); if (dialog.open() == Window.OK) { - IResource res= (IResource) dialog.getFirstResult(); + IResource res = (IResource)dialog.getFirstResult(); return res.getFullPath(); } return null; } - + private Shell getShell() { if (fSWTWidget != null) { return fSWTWidget.getShell(); } - return CUIPlugin.getActiveWorkbenchShell(); + return CUIPlugin.getActiveWorkbenchShell(); } - + /** * Creates a runnable that sets the source attachment by modifying the project's classpath. */ public IRunnableWithProgress getRunnable(final ICProject jproject, final Shell shell) { - fProject= jproject; + fProject = jproject; return getRunnable(shell); } /** - * Creates a runnable that sets the source attachment by modifying the - * project's classpath or updating a container. + * Creates a runnable that sets the source attachment by modifying the project's classpath or updating a container. */ public IRunnableWithProgress getRunnable(final Shell shell) { return new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException { + + public void run(IProgressMonitor monitor) throws InvocationTargetException { try { attachSource(shell, monitor); } catch (CoreException e) { @@ -430,29 +430,30 @@ public class SourceAttachmentBlock { } } }; - } + } protected void attachSource(final Shell shell, IProgressMonitor monitor) throws CoreException { - boolean isExported= fEntry.isExported(); + boolean isExported = fEntry.isExported(); ILibraryEntry newEntry; - newEntry= CoreModel.newLibraryEntry(fEntry.getPath(), fEntry.getBasePath(), fEntry.getLibraryPath(), + newEntry = CoreModel.newLibraryEntry(fEntry.getPath(), fEntry.getBasePath(), fEntry.getLibraryPath(), getSourceAttachmentPath(), getSourceAttachmentRootPath(), getSourceAttachmentPrefixMapping(), isExported); updateProjectPathEntry(shell, fProject, newEntry, monitor); } - private void updateProjectPathEntry(Shell shell, ICProject cproject, ILibraryEntry newEntry, IProgressMonitor monitor) throws CModelException { - IPathEntry[] oldClasspath= cproject.getRawPathEntries(); - int nEntries= oldClasspath.length; - ArrayList newEntries= new ArrayList(nEntries + 1); - int entryKind= newEntry.getEntryKind(); - IPath jarPath= newEntry.getPath(); - boolean found= false; - for (int i= 0; i < nEntries; i++) { - IPathEntry curr= oldClasspath[i]; + private void updateProjectPathEntry(Shell shell, ICProject cproject, ILibraryEntry newEntry, IProgressMonitor monitor) + throws CModelException { + IPathEntry[] oldClasspath = cproject.getRawPathEntries(); + int nEntries = oldClasspath.length; + ArrayList newEntries = new ArrayList(nEntries + 1); + int entryKind = newEntry.getEntryKind(); + IPath jarPath = newEntry.getPath(); + boolean found = false; + for (int i = 0; i < nEntries; i++) { + IPathEntry curr = oldClasspath[i]; if (curr.getEntryKind() == entryKind && curr.getPath().equals(jarPath)) { // add modified entry newEntries.add(newEntry); - found= true; + found = true; } else { newEntries.add(curr); } @@ -462,22 +463,23 @@ public class SourceAttachmentBlock { return; } // add new - newEntries.add(newEntry); + newEntries.add(newEntry); } - IPathEntry[] newPathEntries= (IPathEntry[]) newEntries.toArray(new IPathEntry[newEntries.size()]); + IPathEntry[] newPathEntries = (IPathEntry[])newEntries.toArray(new IPathEntry[newEntries.size()]); cproject.setRawPathEntries(newPathEntries, monitor); } - + private boolean putJarOnClasspathDialog(Shell shell) { - final boolean[] result= new boolean[1]; + final boolean[] result = new boolean[1]; shell.getDisplay().syncExec(new Runnable() { + public void run() { - String title= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.title"); //$NON-NLS-1$ - String message= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.message"); //$NON-NLS-1$ - result[0]= MessageDialog.openQuestion(CUIPlugin.getActiveWorkbenchShell(), title, message); + String title = CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.message"); //$NON-NLS-1$ + result[0] = MessageDialog.openQuestion(CUIPlugin.getActiveWorkbenchShell(), title, message); } }); return result[0]; } -} +} \ No newline at end of file