1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 05:15:43 +02:00

new Include/symbol page

This commit is contained in:
David Inglis 2004-05-25 18:49:32 +00:00
parent 116d4e034b
commit 972ac277a0
24 changed files with 1778 additions and 558 deletions

View file

@ -9,6 +9,7 @@
package org.eclipse.cdt.internal.ui.dialogs.cpaths; package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -38,77 +39,102 @@ public class CPElement {
public static final String MACRO_VALUE = "macrovalue"; //$NON-NLS-1$ 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_REF = "base-ref"; //$NON-NLS-1$
public static final String BASE = "base-path"; //$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 int fEntryKind;
private final IPath fPath; private final IPath fPath;
private final ICProject fCProject; private final ICProject fCProject;
private final IResource fResource; private final IResource fResource;
private final ArrayList fChildren; private final ArrayList fChildren = new ArrayList(1);
private boolean fIsExported; private boolean fIsExported;
private boolean fIsMissing; private boolean fIsMissing;
private CPElement fParentContainer;
private IPathEntry fCachedEntry; 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) { public CPElement(ICProject project, int entryKind, IPath path, IResource res) {
fCProject = project; fCProject = project;
fEntryKind = entryKind; fEntryKind = entryKind;
fPath = path; fPath = path;
fChildren = new ArrayList();
fResource = res; fResource = res;
fIsExported = false; fIsExported = false;
fIsMissing = false; fIsMissing = false;
fCachedEntry = null; fCachedEntry = null;
fParentContainer = null;
switch (entryKind) { switch (entryKind) {
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(EXCLUSION, new Path[0]);
break; break;
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(EXCLUSION, new Path[0]);
break; break;
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
createAttributeElement(LIBRARY, new Path("")); //$NON-NLS-1$ createAttributeElement(LIBRARY, new Path("")); //$NON-NLS-1$
createAttributeElement(SOURCEATTACHMENT, null); createAttributeElement(SOURCEATTACHMENT, null);
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break; break;
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
createAttributeElement(INCLUDE, new Path("")); //$NON-NLS-1$ createAttributeElement(INCLUDE, new Path("")); //$NON-NLS-1$
createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(EXCLUSION, new Path[0]);
createAttributeElement(SYSTEM_INCLUDE, Boolean.valueOf(false)); createAttributeElement(SYSTEM_INCLUDE, Boolean.valueOf(false));
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break; break;
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
createAttributeElement(MACRO_NAME, ""); //$NON-NLS-1$ createAttributeElement(MACRO_NAME, ""); //$NON-NLS-1$
createAttributeElement(MACRO_VALUE, ""); //$NON-NLS-1$ createAttributeElement(MACRO_VALUE, ""); //$NON-NLS-1$
createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(EXCLUSION, new Path[0]);
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break; break;
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
try { try {
IPathEntryContainer container = CoreModel.getPathEntryContainer(fPath, fCProject); IPathEntryContainer container = CoreModel.getPathEntryContainer(fPath, fCProject);
if (container != null) { if (container != null) {
IPathEntry[] entries = container.getPathEntries(); IPathEntry[] entries = container.getPathEntries();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
CPElement curr = createFromExisting(entries[i], fCProject); CPElement curr = createFromExisting(entries[i], fCProject);
curr.setParentContainer(this); curr.createAttributeElement(PARENT_CONTAINER, this);
fChildren.add(curr); 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) { } catch (CModelException e) {
} }
break; break;
default: default :
} }
} }
public IPathEntry getPathEntry() { public IPathEntry getPathEntry() {
if (Inherited != null) {
return null;
}
if (fCachedEntry == null) { if (fCachedEntry == null) {
fCachedEntry = newPathEntry(); fCachedEntry = newPathEntry();
} }
@ -116,43 +142,40 @@ public class CPElement {
} }
private IPathEntry newPathEntry() { private IPathEntry newPathEntry() {
IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION); IPath[] exclusionPattern = (IPath[])getAttribute(EXCLUSION);
IPath base = (IPath) getAttribute(BASE); IPath base = (IPath)getAttribute(BASE);
IPath baseRef = (IPath) getAttribute(BASE_REF); IPath baseRef = (IPath)getAttribute(BASE_REF);
switch (fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
return CoreModel.newOutputEntry(fPath, exclusionPattern); return CoreModel.newOutputEntry(fPath, exclusionPattern);
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
return CoreModel.newSourceEntry(fPath, exclusionPattern); return CoreModel.newSourceEntry(fPath, exclusionPattern);
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
IPath libraryPath = (IPath)getAttribute(LIBRARY); IPath libraryPath = (IPath)getAttribute(LIBRARY);
IPath attach = (IPath) getAttribute(SOURCEATTACHMENT); IPath attach = (IPath)getAttribute(SOURCEATTACHMENT);
if (!baseRef.isEmpty()) { if (!baseRef.isEmpty()) {
return CoreModel.newLibraryRefEntry(fPath, baseRef, libraryPath); 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()); return CoreModel.newProjectEntry(fPath, isExported());
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
return CoreModel.newContainerEntry(fPath, isExported()); return CoreModel.newContainerEntry(fPath, isExported());
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
IPath include = (IPath) getAttribute(INCLUDE); IPath include = (IPath)getAttribute(INCLUDE);
if (!baseRef.isEmpty()) { if (!baseRef.isEmpty()) {
return CoreModel.newIncludeRefEntry(fPath, baseRef, include); return CoreModel.newIncludeRefEntry(fPath, baseRef, include);
} else {
return CoreModel.newIncludeEntry(fPath, base, include, ((Boolean) getAttribute(SYSTEM_INCLUDE)).booleanValue(),
exclusionPattern);
} }
case IPathEntry.CDT_MACRO: return CoreModel.newIncludeEntry(fPath, base, include, ((Boolean)getAttribute(SYSTEM_INCLUDE)).booleanValue(),
String macroName = (String) getAttribute(MACRO_NAME); exclusionPattern);
String macroValue = (String) getAttribute(MACRO_VALUE); case IPathEntry.CDT_MACRO :
String macroName = (String)getAttribute(MACRO_NAME);
String macroValue = (String)getAttribute(MACRO_VALUE);
if (!baseRef.isEmpty()) { if (!baseRef.isEmpty()) {
return CoreModel.newMacroRefEntry(fPath, baseRef, macroName); 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; return null;
} }
} }
@ -175,45 +198,45 @@ public class CPElement {
appendEncodePath(fPath, buf).append(';'); appendEncodePath(fPath, buf).append(';');
buf.append(Boolean.valueOf(fIsExported)).append(';'); buf.append(Boolean.valueOf(fIsExported)).append(';');
switch (fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
IPath[] exclusion = (IPath[]) getAttribute(EXCLUSION); IPath[] exclusion = (IPath[])getAttribute(EXCLUSION);
buf.append('[').append(exclusion.length).append(']'); buf.append('[').append(exclusion.length).append(']');
for (int i = 0; i < exclusion.length; i++) { for (int i = 0; i < exclusion.length; i++) {
appendEncodePath(exclusion[i], buf); appendEncodePath(exclusion[i], buf);
} }
switch (fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
IPath baseRef = (IPath) getAttribute(BASE_REF); IPath baseRef = (IPath)getAttribute(BASE_REF);
appendEncodePath(baseRef, buf); appendEncodePath(baseRef, buf);
IPath base = (IPath) getAttribute(BASE); IPath base = (IPath)getAttribute(BASE);
appendEncodePath(base, buf); appendEncodePath(base, buf);
IPath include = (IPath) getAttribute(INCLUDE); IPath include = (IPath)getAttribute(INCLUDE);
appendEncodePath(include, buf); appendEncodePath(include, buf);
break; break;
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
baseRef = (IPath) getAttribute(BASE_REF); baseRef = (IPath)getAttribute(BASE_REF);
appendEncodePath(baseRef, buf); appendEncodePath(baseRef, buf);
base = (IPath) getAttribute(BASE); base = (IPath)getAttribute(BASE);
appendEncodePath(base, buf); appendEncodePath(base, buf);
String symbol = (String) getAttribute(MACRO_NAME); String symbol = (String)getAttribute(MACRO_NAME);
buf.append(symbol).append(';'); buf.append(symbol).append(';');
default: default :
} }
break; break;
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
IPath baseRef = (IPath) getAttribute(BASE_REF); IPath baseRef = (IPath)getAttribute(BASE_REF);
appendEncodePath(baseRef, buf); appendEncodePath(baseRef, buf);
IPath base = (IPath) getAttribute(BASE); IPath base = (IPath)getAttribute(BASE);
appendEncodePath(base, buf); appendEncodePath(base, buf);
IPath sourceAttach = (IPath) getAttribute(SOURCEATTACHMENT); IPath sourceAttach = (IPath)getAttribute(SOURCEATTACHMENT);
appendEncodePath(sourceAttach, buf); appendEncodePath(sourceAttach, buf);
IPath library = (IPath) getAttribute(LIBRARY); IPath library = (IPath)getAttribute(LIBRARY);
appendEncodePath(library, buf); appendEncodePath(library, buf);
break; break;
default: default :
} }
buf.setLength(buf.length() - 1); buf.setLength(buf.length() - 1);
return buf; return buf;
@ -245,6 +268,31 @@ public class CPElement {
return fResource; 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) { public CPElementAttribute setAttribute(String key, Object value) {
CPElementAttribute attribute = findAttributeElement(key); CPElementAttribute attribute = findAttributeElement(key);
if (attribute == null) { if (attribute == null) {
@ -259,7 +307,7 @@ public class CPElement {
for (int i = 0; i < fChildren.size(); i++) { for (int i = 0; i < fChildren.size(); i++) {
Object curr = fChildren.get(i); Object curr = fChildren.get(i);
if (curr instanceof CPElementAttribute) { if (curr instanceof CPElementAttribute) {
CPElementAttribute elem = (CPElementAttribute) curr; CPElementAttribute elem = (CPElementAttribute)curr;
if (key.equals(elem.getKey())) { if (key.equals(elem.getKey())) {
return elem; return elem;
} }
@ -281,25 +329,30 @@ public class CPElement {
} }
public Object[] getChildren() { public Object[] getChildren() {
switch(fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
return new Object[] { findAttributeElement(EXCLUSION)}; case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_MACRO :
// return new Object[] { findAttributeElement(SOURCEATTACHMENT) }; if (getInherited() == null && getParentContainer() == null) {
case IPathEntry.CDT_INCLUDE: return new Object[]{findAttributeElement(EXCLUSION)};
case IPathEntry.CDT_MACRO: }
return new Object[0]; 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) { private void attributeChanged(String key) {
@ -311,20 +364,20 @@ public class CPElement {
*/ */
public boolean equals(Object other) { public boolean equals(Object other) {
if (other != null && other.getClass().equals(getClass())) { if (other != null && other.getClass().equals(getClass())) {
CPElement elem = (CPElement) other; CPElement elem = (CPElement)other;
if (elem.fEntryKind != fEntryKind || !elem.fPath.equals(fPath)) { if (elem.fEntryKind != fEntryKind || !elem.fPath.equals(fPath)) {
return false; return false;
} }
switch (fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
return (getAttribute(LIBRARY).equals(elem.getAttribute(LIBRARY)) return (getAttribute(LIBRARY).equals(elem.getAttribute(LIBRARY))
&& getAttribute(BASE).equals(elem.getAttribute(BASE)) && getAttribute(BASE).equals(elem.getAttribute(BASE)) && getAttribute(BASE_REF).equals(
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF))); elem.getAttribute(BASE_REF)));
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE)) return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals( && getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals(
elem.getAttribute(BASE))); elem.getAttribute(BASE)));
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
return (getAttribute(MACRO_NAME).equals(elem.getAttribute(MACRO_NAME)) return (getAttribute(MACRO_NAME).equals(elem.getAttribute(MACRO_NAME))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals( && getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals(
elem.getAttribute(BASE))); elem.getAttribute(BASE)));
@ -341,17 +394,17 @@ public class CPElement {
final int HASH_FACTOR = 89; final int HASH_FACTOR = 89;
int hashCode = fPath.hashCode() + fEntryKind; int hashCode = fPath.hashCode() + fEntryKind;
switch (fEntryKind) { switch (fEntryKind) {
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
hashCode = hashCode * HASH_FACTOR + getAttribute(LIBRARY).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(LIBRARY).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
break; break;
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
hashCode = hashCode * HASH_FACTOR + getAttribute(INCLUDE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(INCLUDE).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
break; break;
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
hashCode = hashCode * HASH_FACTOR + getAttribute(MACRO_NAME).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(MACRO_NAME).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode(); hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
@ -405,6 +458,10 @@ public class CPElement {
} }
} }
public CPElement getInherited() {
return Inherited;
}
/** /**
* Gets the project. * Gets the project.
* *
@ -432,14 +489,14 @@ public class CPElement {
boolean isMissing = false; boolean isMissing = false;
switch (curr.getEntryKind()) { switch (curr.getEntryKind()) {
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
res = null; res = null;
try { try {
isMissing = (CoreModel.getPathEntryContainer(path, project) == null); isMissing = (CoreModel.getPathEntryContainer(path, project) == null);
} catch (CModelException e) { } catch (CModelException e) {
} }
break; break;
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
res = root.findMember(path); res = root.findMember(path);
if (res == null) { if (res == null) {
// if (!ArchiveFileFilter.isArchivePath(path)) { // if (!ArchiveFileFilter.isArchivePath(path)) {
@ -449,12 +506,12 @@ public class CPElement {
} }
isMissing = !path.toFile().isFile(); // look for external isMissing = !path.toFile().isFile(); // look for external
} }
library = ((ILibraryEntry) curr).getLibraryPath(); library = ((ILibraryEntry)curr).getLibraryPath();
sourceAttachment = ((ILibraryEntry) curr).getSourceAttachmentPath(); sourceAttachment = ((ILibraryEntry)curr).getSourceAttachmentPath();
base = ((ILibraryEntry) curr).getBasePath(); base = ((ILibraryEntry)curr).getBasePath();
baseRef = ((ILibraryEntry) curr).getBaseReference(); baseRef = ((ILibraryEntry)curr).getBaseReference();
break; break;
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
path = path.removeTrailingSeparator(); path = path.removeTrailingSeparator();
res = root.findMember(path); res = root.findMember(path);
if (res == null) { if (res == null) {
@ -463,9 +520,9 @@ public class CPElement {
} }
isMissing = true; isMissing = true;
} }
exclusion = ((ISourceEntry) curr).getExclusionPatterns(); exclusion = ((ISourceEntry)curr).getExclusionPatterns();
break; break;
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
path = path.removeTrailingSeparator(); path = path.removeTrailingSeparator();
res = root.findMember(path); res = root.findMember(path);
if (res == null) { if (res == null) {
@ -474,9 +531,9 @@ public class CPElement {
} }
isMissing = true; isMissing = true;
} }
exclusion = ((IOutputEntry) curr).getExclusionPatterns(); exclusion = ((IOutputEntry)curr).getExclusionPatterns();
break; break;
case IPathEntry.CDT_INCLUDE: case IPathEntry.CDT_INCLUDE :
path = path.removeTrailingSeparator(); path = path.removeTrailingSeparator();
res = root.findMember(path); res = root.findMember(path);
if (res == null) { if (res == null) {
@ -487,13 +544,13 @@ public class CPElement {
if (res.getType() != IResource.ROOT && project != null) { if (res.getType() != IResource.ROOT && project != null) {
isMissing = !project.isOnSourceRoot(res); isMissing = !project.isOnSourceRoot(res);
} }
exclusion = ((IIncludeEntry) curr).getExclusionPatterns(); exclusion = ((IIncludeEntry)curr).getExclusionPatterns();
sysInclude = ((IIncludeEntry) curr).isSystemInclude(); sysInclude = ((IIncludeEntry)curr).isSystemInclude();
baseRef = ((IIncludeEntry) curr).getBaseReference(); baseRef = ((IIncludeEntry)curr).getBaseReference();
base = ((IIncludeEntry) curr).getBasePath(); base = ((IIncludeEntry)curr).getBasePath();
include = ((IIncludeEntry) curr).getIncludePath(); include = ((IIncludeEntry)curr).getIncludePath();
break; break;
case IPathEntry.CDT_MACRO: case IPathEntry.CDT_MACRO :
path = path.removeTrailingSeparator(); path = path.removeTrailingSeparator();
res = root.findMember(path); res = root.findMember(path);
if (res == null) { if (res == null) {
@ -504,13 +561,13 @@ public class CPElement {
if (res.getType() != IResource.ROOT && project != null) { if (res.getType() != IResource.ROOT && project != null) {
isMissing = !project.isOnSourceRoot(res); isMissing = !project.isOnSourceRoot(res);
} }
exclusion = ((IMacroEntry) curr).getExclusionPatterns(); exclusion = ((IMacroEntry)curr).getExclusionPatterns();
macroName = ((IMacroEntry) curr).getMacroName(); macroName = ((IMacroEntry)curr).getMacroName();
macroValue = ((IMacroEntry) curr).getMacroValue(); macroValue = ((IMacroEntry)curr).getMacroValue();
baseRef = ((IMacroEntry) curr).getBaseReference(); baseRef = ((IMacroEntry)curr).getBaseReference();
base = ((IMacroEntry) curr).getBasePath(); base = ((IMacroEntry)curr).getBasePath();
break; break;
case IPathEntry.CDT_PROJECT: case IPathEntry.CDT_PROJECT :
res = root.findMember(path); res = root.findMember(path);
isMissing = (res == null); isMissing = (res == null);
break; break;

View file

@ -22,8 +22,9 @@ import org.eclipse.jface.viewers.ViewerFilter;
public class CPElementFilter extends ViewerFilter { public class CPElementFilter extends ViewerFilter {
protected List fExcludes; protected List fExcludes;
protected int fKind; protected int[] fKind;
protected boolean fExportedOnly; protected boolean fExportedOnly;
protected boolean fShowInherited;
/** /**
* @param excludedFiles * @param excludedFiles
@ -31,16 +32,17 @@ public class CPElementFilter extends ViewerFilter {
* @param recusive * @param recusive
* Folders are only shown if, searched recursivly, contain an archive * 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) { if (excludedElements != null) {
fExcludes = Arrays.asList(excludedElements); fExcludes = Arrays.asList(excludedElements);
} }
fKind = kind; fKind = kind;
fExportedOnly = exportedOnly; fExportedOnly = exportedOnly;
fShowInherited = showInherited;
} }
public CPElementFilter(int kind, boolean exportedOnly) { public CPElementFilter(int[] kind, boolean exportedOnly, boolean showInherited) {
this(null, kind, exportedOnly); this(null, kind, exportedOnly, showInherited);
} }
/* /*
@ -48,22 +50,41 @@ public class CPElementFilter extends ViewerFilter {
*/ */
public boolean select(Viewer viewer, Object parent, Object element) { public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof CPElement) { if (element instanceof CPElement) {
if ( ((CPElement)element).getEntryKind() == fKind) { for (int i = 0; i < fKind.length; i++) {
if (fExcludes == null || !fExcludes.contains(element)) { if ( ((CPElement)element).getEntryKind() == fKind[i]) {
if (fExportedOnly == true) { if (fExcludes == null || !fExcludes.contains(element)) {
return ((CPElement)element).isExported(); 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) { } else if (element instanceof IPathEntry) {
if ( ((IPathEntry)element).getEntryKind() == fKind) { for (int i = 0; i < fKind.length; i++) {
if (fExcludes == null || !fExcludes.contains(element)) { if ( ((IPathEntry)element).getEntryKind() == fKind[i]) {
if (fExportedOnly == true) { if (fExcludes == null || !fExcludes.contains(element)) {
return ((IPathEntry)element).isExported(); 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; return false;
} }

View file

@ -11,32 +11,96 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
public class CPElementGroup { public class CPElementGroup {
CPElement element; private CPElement parent;
int kind; private final int kind;
private IResource resource;
private List children = new ArrayList(1);
public CPElementGroup(CPElement element, int kind) { public CPElementGroup(IResource resource) {
this.element = element; this.kind = -1;
this.resource = resource;
this.children = new ArrayList();
}
public CPElementGroup(CPElement parent, int kind) {
this.parent = parent;
this.kind = kind; this.kind = kind;
} }
public CPElement getElement() { public IResource getResource() {
return element; 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; return kind;
} }
public Object[] getChildren() { public boolean equals(Object arg0) {
Object[] children = element.getChildren(); if (arg0 == this) {
List rv = new ArrayList(); return true;
for (int i = 0; i < children.length; i++) { }
if ((children[i] instanceof CPElement) && ((CPElement)children[i]).getEntryKind() == kind) { if (arg0 instanceof CPElementGroup) {
rv.add(children[i]); 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()]);
}
} }

View file

@ -12,35 +12,44 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer; 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.CPluginImages;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
import org.eclipse.cdt.ui.CElementImageDescriptor;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point; 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.IWorkbench;
import org.eclipse.ui.ide.IDE; 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 String fNewLabel, fCreateLabel;
private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon; private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon;
private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage; private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage;
private boolean bShowExported; private boolean bShowExported;
private boolean bShowParentInfo;
private ImageDescriptorRegistry fRegistry; private ImageDescriptorRegistry fRegistry;
private CElementImageProvider fCImages;
public CPElementLabelProvider() { 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$ fNewLabel = CPathEntryMessages.getString("CPElementLabelProvider.new"); //$NON-NLS-1$
fCreateLabel = CPathEntryMessages.getString("CPElementLabelProvider.willbecreated"); //$NON-NLS-1$ fCreateLabel = CPathEntryMessages.getString("CPElementLabelProvider.willbecreated"); //$NON-NLS-1$
fRegistry = CUIPlugin.getImageDescriptorRegistry(); fRegistry = CUIPlugin.getImageDescriptorRegistry();
fCImages = new CElementImageProvider();
fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE; fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE;
fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC; fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC;
@ -54,6 +63,7 @@ class CPElementLabelProvider extends LabelProvider {
fProjectImage = workbench.getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT); fProjectImage = workbench.getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
bShowExported = showExported; bShowExported = showExported;
bShowParentInfo = showParentInfo;
} }
public String getText(Object element) { public String getText(Object element) {
@ -70,13 +80,18 @@ class CPElementLabelProvider extends LabelProvider {
} }
private String getCPContainerGroupText(CPElementGroup group) { private String getCPContainerGroupText(CPElementGroup group) {
switch (group.getEntryType()) { switch (group.getEntryKind()) {
case IPathEntry.CDT_INCLUDE : case IPathEntry.CDT_INCLUDE :
return CPathEntryMessages.getString("CPElementLabelProvider.Includes"); //$NON-NLS-1$ return CPathEntryMessages.getString("CPElementLabelProvider.Includes"); //$NON-NLS-1$
case IPathEntry.CDT_MACRO : case IPathEntry.CDT_MACRO :
return CPathEntryMessages.getString("CPElementLabelProvider.PreprocessorSymbols"); //$NON-NLS-1$ return CPathEntryMessages.getString("CPElementLabelProvider.PreprocessorSymbols"); //$NON-NLS-1$
case IPathEntry.CDT_LIBRARY : case IPathEntry.CDT_LIBRARY :
return CPathEntryMessages.getString("CPElementLabelProvider.Libraries"); //$NON-NLS-1$ 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$ return ""; //$NON-NLS-1$
} }
@ -128,6 +143,7 @@ class CPElementLabelProvider extends LabelProvider {
StringBuffer str = new StringBuffer(); StringBuffer str = new StringBuffer();
addBaseString(libPath, cpentry, str); addBaseString(libPath, cpentry, str);
addExport(cpentry, str); addExport(cpentry, str);
addParentInfo(cpentry, str);
return str.toString(); return str.toString();
} }
case IPathEntry.CDT_PROJECT : case IPathEntry.CDT_PROJECT :
@ -138,6 +154,7 @@ class CPElementLabelProvider extends LabelProvider {
StringBuffer str = new StringBuffer(); StringBuffer str = new StringBuffer();
addBaseString(incPath, cpentry, str); addBaseString(incPath, cpentry, str);
addExport(cpentry, str); addExport(cpentry, str);
addParentInfo(cpentry, str);
return str.toString(); return str.toString();
} }
case IPathEntry.CDT_MACRO : case IPathEntry.CDT_MACRO :
@ -146,6 +163,7 @@ class CPElementLabelProvider extends LabelProvider {
+ (String)cpentry.getAttribute(CPElement.MACRO_VALUE)); + (String)cpentry.getAttribute(CPElement.MACRO_VALUE));
addBaseString(null, cpentry, str); addBaseString(null, cpentry, str);
addExport(cpentry, str); addExport(cpentry, str);
addParentInfo(cpentry, str);
return str.toString(); return str.toString();
} }
case IPathEntry.CDT_CONTAINER : case IPathEntry.CDT_CONTAINER :
@ -182,6 +200,28 @@ class CPElementLabelProvider extends LabelProvider {
} }
return CPathEntryMessages.getString("CPElementLabelProvider.unknown_element.label"); //$NON-NLS-1$ 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) { private void addExport(CPElement cpentry, StringBuffer str) {
if (bShowExported && cpentry.isExported()) { if (bShowExported && cpentry.isExported()) {
str.append(' '); str.append(' ');
@ -244,15 +284,13 @@ class CPElementLabelProvider extends LabelProvider {
case IPathEntry.CDT_OUTPUT : case IPathEntry.CDT_OUTPUT :
if (cpentry.getPath().segmentCount() == 1) { if (cpentry.getPath().segmentCount() == 1) {
return fProjectImage; return fProjectImage;
} else {
return fOutputImage;
} }
return fOutputImage;
case IPathEntry.CDT_SOURCE : case IPathEntry.CDT_SOURCE :
if (cpentry.getPath().segmentCount() == 1) { if (cpentry.getPath().segmentCount() == 1) {
return fProjectImage; return fProjectImage;
} else {
return fFolderImage;
} }
return fFolderImage;
case IPathEntry.CDT_LIBRARY : case IPathEntry.CDT_LIBRARY :
IPath path = (IPath)cpentry.getAttribute(CPElement.SOURCEATTACHMENT); IPath path = (IPath)cpentry.getAttribute(CPElement.SOURCEATTACHMENT);
if (path == null || path.isEmpty()) { if (path == null || path.isEmpty()) {
@ -280,7 +318,10 @@ class CPElementLabelProvider extends LabelProvider {
ImageDescriptor imageDescriptor = getCPElementBaseImage(cpentry); ImageDescriptor imageDescriptor = getCPElementBaseImage(cpentry);
if (imageDescriptor != null) { if (imageDescriptor != null) {
if (cpentry.isMissing()) { 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); return fRegistry.get(imageDescriptor);
} }
@ -294,15 +335,37 @@ class CPElementLabelProvider extends LabelProvider {
} else if (element instanceof IPathEntry) { } else if (element instanceof IPathEntry) {
return getImage(CPElement.createFromExisting((IPathEntry)element, null)); return getImage(CPElement.createFromExisting((IPathEntry)element, null));
} else if (element instanceof CPElementGroup) { } else if (element instanceof CPElementGroup) {
switch ( ((CPElementGroup)element).getEntryType()) { switch ( ((CPElementGroup)element).getEntryKind()) {
case IPathEntry.CDT_INCLUDE : case IPathEntry.CDT_INCLUDE :
return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_CONTAINER); return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_CONTAINER);
case IPathEntry.CDT_MACRO : case IPathEntry.CDT_MACRO :
return fRegistry.get(fMacroIcon); return fRegistry.get(fMacroIcon);
case IPathEntry.CDT_LIBRARY : case IPathEntry.CDT_LIBRARY :
return CPluginImages.get(CPluginImages.IMG_OBJS_LIBRARY); return CPluginImages.get(CPluginImages.IMG_OBJS_LIBRARY);
case -1:
return fCImages.getImageLabel(((CPElementGroup)element).getResource(), CElementImageProvider.SMALL_ICONS);
} }
} }
return null; 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;
}
} }

View file

@ -9,6 +9,8 @@
package org.eclipse.cdt.internal.ui.dialogs.cpaths; package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import org.eclipse.cdt.core.model.IPathEntry; 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; import org.eclipse.jface.viewers.ViewerSorter;
public class CPElementSorter extends ViewerSorter { public class CPElementSorter extends ViewerSorter {
@ -24,18 +26,46 @@ public class CPElementSorter extends ViewerSorter {
*/ */
public int category(Object obj) { public int category(Object obj) {
if (obj instanceof CPElement) { if (obj instanceof CPElement) {
switch (((CPElement) obj).getEntryKind()) { switch ( ((CPElement)obj).getEntryKind()) {
case IPathEntry.CDT_LIBRARY: case IPathEntry.CDT_LIBRARY :
return LIBRARY; return LIBRARY;
case IPathEntry.CDT_PROJECT: case IPathEntry.CDT_PROJECT :
return PROJECT; return PROJECT;
case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_SOURCE :
return SOURCE; return SOURCE;
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
return 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; 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);
}
} }

View file

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

View file

@ -20,13 +20,13 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWTException; import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
public class CPathContainerDescriptor implements IContainerDescriptor { public class CPathContainerDescriptor implements IContainerDescriptor {
@ -63,11 +63,10 @@ public class CPathContainerDescriptor implements IContainerDescriptor {
Object elem = CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS); Object elem = CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS);
if (elem instanceof ICPathContainerPage) { if (elem instanceof ICPathContainerPage) {
return (ICPathContainerPage) elem; 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() { public String getName() {
@ -79,17 +78,18 @@ public class CPathContainerDescriptor implements IContainerDescriptor {
String imageName = fConfigElement.getAttribute(ATT_ICON); String imageName = fConfigElement.getAttribute(ATT_ICON);
if (imageName != null) { if (imageName != null) {
IExtension extension = fConfigElement.getDeclaringExtension(); IExtension extension = fConfigElement.getDeclaringExtension();
IPluginDescriptor pd = extension.getDeclaringPluginDescriptor(); String plugin = extension.getNamespace();
Image image = getImageFromPlugin(pd, imageName); Image image = getImageFromPlugin(plugin, imageName);
pageImage = image; pageImage = image;
} }
} }
return pageImage; return pageImage;
} }
public Image getImageFromPlugin(IPluginDescriptor pluginDescriptor, String subdirectoryAndFilename) { public Image getImageFromPlugin(String plugin, String subdirectoryAndFilename) {
URL installURL = pluginDescriptor.getInstallURL(); Bundle bundle = Platform.getBundle(plugin);
return getImageFromURL(installURL, subdirectoryAndFilename); URL iconURL = bundle.getEntry("/"); //$NON-NLS-1$
return getImageFromURL(iconURL, subdirectoryAndFilename);
} }
public Image getImageFromURL(URL installURL, String subdirectoryAndFilename) { public Image getImageFromURL(URL installURL, String subdirectoryAndFilename) {
@ -120,7 +120,7 @@ public class CPathContainerDescriptor implements IContainerDescriptor {
public static IContainerDescriptor[] getDescriptors() { public static IContainerDescriptor[] getDescriptors() {
ArrayList containers = new ArrayList(); 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) { if (extensionPoint != null) {
IContainerDescriptor defaultPage = null; IContainerDescriptor defaultPage = null;
String defaultPageName = CPathContainerDefaultPage.class.getName(); String defaultPageName = CPathContainerDefaultPage.class.getName();

View file

@ -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.cdt.internal.ui.wizards.dialogfields.TreeListDialogField;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
@ -140,13 +139,7 @@ public class CPathContainerEntryPage extends CPathBasePage {
public Object[] getChildren(TreeListDialogField field, Object element) { public Object[] getChildren(TreeListDialogField field, Object element) {
if (element instanceof CPElement) { if (element instanceof CPElement) {
CPElement cpElem = (CPElement)element; return ((CPElement)element).getChildren();
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();
}
} else if (element instanceof CPElementGroup) { } else if (element instanceof CPElementGroup) {
return ((CPElementGroup)element).getChildren(); return ((CPElementGroup)element).getChildren();
} }
@ -157,7 +150,7 @@ public class CPathContainerEntryPage extends CPathBasePage {
if (element instanceof CPElementAttribute) { if (element instanceof CPElementAttribute) {
return ((CPElementAttribute)element).getParent(); return ((CPElementAttribute)element).getParent();
} else if (element instanceof CPElementGroup) { } else if (element instanceof CPElementGroup) {
return ((CPElementGroup)element).getElement(); return ((CPElementGroup)element).getParent();
} }
return null; return null;
} }
@ -322,17 +315,17 @@ public class CPathContainerEntryPage extends CPathBasePage {
} }
private void editAttributeEntry(CPElementAttribute elem) { private void editAttributeEntry(CPElementAttribute elem) {
String key = elem.getKey(); // String key = elem.getKey();
if (key.equals(CPElement.SOURCEATTACHMENT)) { // if (key.equals(CPElement.SOURCEATTACHMENT)) {
CPElement selElement = elem.getParent(); // CPElement selElement = elem.getParent();
//
IPath containerPath = null; // IPath containerPath = null;
boolean applyChanges = false; // boolean applyChanges = false;
Object parentContainer = selElement.getParentContainer(); // Object parentContainer = selElement.getParentContainer();
if (parentContainer instanceof CPElement) { // if (parentContainer instanceof CPElement) {
containerPath = ((CPElement)parentContainer).getPath(); // containerPath = ((CPElement)parentContainer).getPath();
applyChanges = true; // applyChanges = true;
} // }
// SourceAttachmentDialog dialog = new SourceAttachmentDialog(getShell(), (ILibraryEntry)selElement.getPathEntry(), containerPath, // SourceAttachmentDialog dialog = new SourceAttachmentDialog(getShell(), (ILibraryEntry)selElement.getPathEntry(), containerPath,
// fCurrCProject, applyChanges); // fCurrCProject, applyChanges);
// if (dialog.open() == Window.OK) { // if (dialog.open() == Window.OK) {
@ -340,7 +333,7 @@ public class CPathContainerEntryPage extends CPathBasePage {
// fContainersList.refresh(); // fContainersList.refresh();
// fCPathList.refresh(); // images // fCPathList.refresh(); // images
// } // }
} // }
} }
private void editElementEntry(CPElement elem) { private void editElementEntry(CPElement elem) {

View file

@ -38,24 +38,24 @@ public class CPathContainerWizard extends Wizard {
private CPathFilterPage fFilterPage; private CPathFilterPage fFilterPage;
private CPathContainerSelectionPage fSelectionWizardPage; private CPathContainerSelectionPage fSelectionWizardPage;
private int fFilterType; private int[] fFilterType;
/** /**
* Constructor for ClasspathContainerWizard. * Constructor for ClasspathContainerWizard.
*/ */
public CPathContainerWizard(IPathEntry entryToEdit, ICElement currElement, IPathEntry[] currEntries) { public CPathContainerWizard(IPathEntry entryToEdit, ICElement currElement, IPathEntry[] currEntries) {
this(entryToEdit, null, currElement, currEntries, -1); this(entryToEdit, null, currElement, currEntries, null);
} }
/** /**
* Constructor for ClasspathContainerWizard. * Constructor for ClasspathContainerWizard.
*/ */
public CPathContainerWizard(IContainerDescriptor pageDesc, ICElement currElement, IPathEntry[] currEntries) { 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, public CPathContainerWizard(IPathEntry entryToEdit, IContainerDescriptor pageDesc, ICElement currElement,
IPathEntry[] currEntries, int filterType) { IPathEntry[] currEntries, int[] filterType) {
fEntryToEdit = entryToEdit; fEntryToEdit = entryToEdit;
fPageDesc = pageDesc; fPageDesc = pageDesc;
fNewEntries = null; fNewEntries = null;
@ -108,7 +108,7 @@ public class CPathContainerWizard extends Wizard {
// first page // first page
IContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors(); IContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
List allContainers = new ArrayList(Arrays.asList(containers)); List allContainers = new ArrayList(Arrays.asList(containers));
if (fFilterType != -1) { if (fFilterType != null) {
allContainers.add(0, new ProjectContainerDescriptor(fFilterType)); allContainers.add(0, new ProjectContainerDescriptor(fFilterType));
} }
fSelectionWizardPage = new CPathContainerSelectionPage( fSelectionWizardPage = new CPathContainerSelectionPage(
@ -124,7 +124,7 @@ public class CPathContainerWizard extends Wizard {
fContainerPage = getContainerPage(descriptor); fContainerPage = getContainerPage(descriptor);
addPage(fContainerPage); addPage(fContainerPage);
} }
if (fFilterType != -1) { if (fFilterType != null) {
fFilterPage = new CPathFilterPage(fCurrElement, fFilterType); fFilterPage = new CPathFilterPage(fCurrElement, fFilterType);
addPage(fFilterPage); addPage(fFilterPage);
} }

View file

@ -52,6 +52,32 @@ ProjectContainerPage.label=C/C++ Projects:
# -------- ExtendingCPathBasePage --------- # -------- ExtendingCPathBasePage ---------
ExtendingCPathBasePage.sourcePaths=Source Paths: 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 --------- # -------- SymbolsEntryPage ---------
SymbolEntryPage.title=Symbols SymbolEntryPage.title=Symbols
SymbolEntryPage.addUser=Add User Defined... SymbolEntryPage.addUser=Add User Defined...

View file

@ -36,7 +36,7 @@ import org.eclipse.swt.widgets.Label;
public class CPathFilterPage extends WizardPage { public class CPathFilterPage extends WizardPage {
private final int fFilterType; private final int[] fFilterType;
private CheckboxTableViewer viewer; private CheckboxTableViewer viewer;
private IPathEntry fParentEntry; private IPathEntry fParentEntry;
@ -46,7 +46,7 @@ public class CPathFilterPage extends WizardPage {
protected ICElement fCElement; protected ICElement fCElement;
protected CPathFilterPage(ICElement cElement, int filterType) { protected CPathFilterPage(ICElement cElement, int[] filterType) {
super("CPathFilterPage"); //$NON-NLS-1$ super("CPathFilterPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("CPathFilterPage.title")); //$NON-NLS-1$ setTitle(CPathEntryMessages.getString("CPathFilterPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("CPathFilterPage.description")); //$NON-NLS-1$ setDescription(CPathEntryMessages.getString("CPathFilterPage.description")); //$NON-NLS-1$
@ -68,7 +68,7 @@ public class CPathFilterPage extends WizardPage {
label.setLayoutData(gd); label.setLayoutData(gd);
viewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); viewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
viewer.setContentProvider(new ListContentProvider()); viewer.setContentProvider(new ListContentProvider());
viewer.setLabelProvider(new CPElementLabelProvider(false)); viewer.setLabelProvider(new CPElementLabelProvider(false, false));
viewer.addCheckStateListener(new ICheckStateListener() { viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) { public void checkStateChanged(CheckStateChangedEvent event) {
@ -110,16 +110,16 @@ public class CPathFilterPage extends WizardPage {
} catch (CModelException e) { } catch (CModelException e) {
} }
} }
createExlusions(); createExlusions(fParentEntry.getEntryKind() == IPathEntry.CDT_PROJECT);
} }
private void createExlusions() { private void createExlusions(boolean showExported) {
fExclusions = new ArrayList(); fExclusions = new ArrayList();
if (filter != null) { if (filter != null) {
viewer.removeFilter(filter); viewer.removeFilter(filter);
} }
filter = new CPElementFilter(fExclusions.toArray(), fFilterType, true); filter = new CPElementFilter(fExclusions.toArray(), fFilterType, showExported, false);
viewer.addFilter(filter); viewer.addFilter(filter);
} }

View file

@ -17,7 +17,6 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IPathEntry; 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.TypedElementSelectionValidator;
import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; 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$ String title = (existing == null) ? CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.new.title") //$NON-NLS-1$
: CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.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$ 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(), ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(),
new CElementContentProvider()); new CElementContentProvider());
@ -220,7 +219,7 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
elem = existing.getPathEntry(); elem = existing.getPathEntry();
} }
CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(),
IPathEntry.CDT_INCLUDE); new int[] {IPathEntry.CDT_INCLUDE});
wizard.setWindowTitle(title); wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry parent = wizard.getEntriesParent(); IPathEntry parent = wizard.getEntriesParent();

View file

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

View file

@ -506,7 +506,7 @@ public class CPathLibraryEntryPage extends CPathBasePage {
elem = existing.getPathEntry(); elem = existing.getPathEntry();
} }
CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawPathEntries(), CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawPathEntries(),
IPathEntry.CDT_LIBRARY); new int[] {IPathEntry.CDT_LIBRARY});
wizard.setWindowTitle(title); wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry parent = wizard.getEntriesParent(); IPathEntry parent = wizard.getEntriesParent();

View file

@ -1,11 +1,10 @@
/******************************************************************************* /***********************************************************************************************************************************
* Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This program and the accompanying materials are made
* program and the accompanying materials are made available under the terms of * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
* the Common Public License v1.0 which accompanies this distribution, and is * http://www.eclipse.org/legal/cpl-v10.html
* available at http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: QNX Software Systems - initial API and implementation * Contributors: QNX Software Systems - initial API and implementation
******************************************************************************/ **********************************************************************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths; package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
@ -78,9 +77,9 @@ public class CPathOutputEntryPage extends CPathBasePage {
String[] buttonLabels; String[] buttonLabels;
buttonLabels = new String[] { buttonLabels = new String[]{
/* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("OutputPathEntryPage.folders.add.button"), //$NON-NLS-1$ /* 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$ /* 3 = IDX_REMOVE */CPathEntryMessages.getString("OutputPathEntryPage.folders.remove.button") //$NON-NLS-1$
}; };
@ -93,7 +92,6 @@ public class CPathOutputEntryPage extends CPathBasePage {
fOutputList.enableButton(IDX_REMOVE, false); fOutputList.enableButton(IDX_REMOVE, false);
} }
public Image getImage() { public Image getImage() {
return CPluginImages.get(CPluginImages.IMG_OBJS_CONTAINER); return CPluginImages.get(CPluginImages.IMG_OBJS_CONTAINER);
} }
@ -110,8 +108,8 @@ public class CPathOutputEntryPage extends CPathBasePage {
fOutputList.setElements(folders); fOutputList.setElements(folders);
for (int i = 0; i < folders.size(); i++) { for (int i = 0; i < folders.size(); i++) {
CPElement cpe = (CPElement) folders.get(i); CPElement cpe = (CPElement)folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION); IPath[] patterns = (IPath[])cpe.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) { if (patterns.length > 0) {
fOutputList.expandElement(cpe, 3); fOutputList.expandElement(cpe, 3);
} }
@ -122,7 +120,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
PixelConverter converter = new PixelConverter(parent); PixelConverter converter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NONE); 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)); LayoutUtil.setHorizontalGrabbing(fOutputList.getTreeControl(null));
int buttonBarWidth = converter.convertWidthInCharsToPixels(24); int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
@ -131,8 +129,8 @@ public class CPathOutputEntryPage extends CPathBasePage {
// expand // expand
List elements = fOutputList.getElements(); List elements = fOutputList.getElements();
for (int i = 0; i < elements.size(); i++) { for (int i = 0; i < elements.size(); i++) {
CPElement elem = (CPElement) elements.get(i); CPElement elem = (CPElement)elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION); IPath[] patterns = (IPath[])elem.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) { if (patterns.length > 0) {
fOutputList.expandElement(elem, 3); fOutputList.expandElement(elem, 3);
} }
@ -163,14 +161,14 @@ public class CPathOutputEntryPage extends CPathBasePage {
public Object[] getChildren(TreeListDialogField field, Object element) { public Object[] getChildren(TreeListDialogField field, Object element) {
if (element instanceof CPElement) { if (element instanceof CPElement) {
return ((CPElement) element).getChildren(); return ((CPElement)element).getChildren();
} }
return EMPTY_ARR; return EMPTY_ARR;
} }
public Object getParent(TreeListDialogField field, Object element) { public Object getParent(TreeListDialogField field, Object element) {
if (element instanceof CPElementAttribute) { if (element instanceof CPElementAttribute) {
return ((CPElementAttribute) element).getParent(); return ((CPElementAttribute)element).getParent();
} }
return null; return null;
} }
@ -276,9 +274,9 @@ public class CPathOutputEntryPage extends CPathBasePage {
} }
Object elem = selElements.get(0); Object elem = selElements.get(0);
if (fOutputList.getIndexOfElement(elem) != -1) { if (fOutputList.getIndexOfElement(elem) != -1) {
editElementEntry((CPElement) elem); editElementEntry((CPElement)elem);
} else if (elem instanceof CPElementAttribute) { } 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--) { for (int i = selElements.size() - 1; i >= 0; i--) {
Object elem = selElements.get(i); Object elem = selElements.get(i);
if (elem instanceof CPElementAttribute) { if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem; CPElementAttribute attrib = (CPElementAttribute)elem;
String key = attrib.getKey(); String key = attrib.getKey();
Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null; Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null;
attrib.getParent().setAttribute(key, value); attrib.getParent().setAttribute(key, value);
@ -338,16 +336,16 @@ public class CPathOutputEntryPage extends CPathBasePage {
for (int i = 0; i < selElements.size(); i++) { for (int i = 0; i < selElements.size(); i++) {
Object elem = selElements.get(i); Object elem = selElements.get(i);
if (elem instanceof CPElementAttribute) { if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem; CPElementAttribute attrib = (CPElementAttribute)elem;
if (attrib.getKey().equals(CPElement.EXCLUSION)) { if (attrib.getKey().equals(CPElement.EXCLUSION)) {
if (((IPath[]) attrib.getValue()).length == 0) { if ( ((IPath[])attrib.getValue()).length == 0) {
return false; return false;
} }
} else if (attrib.getValue() == null) { } else if (attrib.getValue() == null) {
return false; return false;
} }
} else if (elem instanceof CPElement) { } else if (elem instanceof CPElement) {
CPElement curr = (CPElement) elem; CPElement curr = (CPElement)elem;
if (curr.getParentContainer() != null) { if (curr.getParentContainer() != null) {
return false; return false;
} }
@ -390,7 +388,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
int lastRemovePos = nEntries; int lastRemovePos = nEntries;
int afterLastSourcePos = 0; int afterLastSourcePos = 0;
for (int i = nEntries - 1; i >= 0; i--) { for (int i = nEntries - 1; i >= 0; i--) {
CPElement cpe = (CPElement) cpelements.get(i); CPElement cpe = (CPElement)cpelements.get(i);
int kind = cpe.getEntryKind(); int kind = cpe.getEntryKind();
if (isEntryKind(kind)) { if (isEntryKind(kind)) {
if (!srcelements.remove(cpe)) { if (!srcelements.remove(cpe)) {
@ -416,25 +414,22 @@ public class CPathOutputEntryPage extends CPathBasePage {
if (includeLinked) { if (includeLinked) {
NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject());
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
IResource createdFolder = (IResource) dialog.getResult()[0]; IResource createdFolder = (IResource)dialog.getResult()[0];
return newCPOutputElement(createdFolder); return newCPOutputElement(createdFolder);
} }
return null; 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) { private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) {
@ -448,7 +443,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
private CPElement[] openOutputContainerDialog(CPElement existing) { 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); List existingContainers = getExistingContainers(null);
IProject[] allProjects = fWorkspaceRoot.getProjects(); IProject[] allProjects = fWorkspaceRoot.getProjects();
@ -465,9 +460,11 @@ public class CPathOutputEntryPage extends CPathBasePage {
ILabelProvider lp = new WorkbenchLabelProvider(); ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new BaseWorkbenchContentProvider(); 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$ : 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$ : CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.edit.description"); //$NON-NLS-1$
MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp);
@ -485,7 +482,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
Object[] elements = dialog.getResult(); Object[] elements = dialog.getResult();
CPElement[] res = new CPElement[elements.length]; CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) { for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i]; IResource elem = (IResource)elements[i];
res[i] = newCPOutputElement(elem); res[i] = newCPOutputElement(elem);
} }
return res; return res;
@ -497,7 +494,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
List res = new ArrayList(); List res = new ArrayList();
List cplist = fOutputList.getElements(); List cplist = fOutputList.getElements();
for (int i = 0; i < cplist.size(); i++) { for (int i = 0; i < cplist.size(); i++) {
CPElement elem = (CPElement) cplist.get(i); CPElement elem = (CPElement)cplist.get(i);
if (elem != existing) { if (elem != existing) {
IResource resource = elem.getResource(); IResource resource = elem.getResource();
if (resource instanceof IContainer) { // defensive code if (resource instanceof IContainer) { // defensive code

View file

@ -78,7 +78,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
String[] buttonLabels; String[] buttonLabels;
buttonLabels = new String[] { buttonLabels = new String[]{
/* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("SourcePathEntryPage.folders.add.button"), //$NON-NLS-1$ /* 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$ /* 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$ /* 3 = IDX_REMOVE */CPathEntryMessages.getString("SourcePathEntryPage.folders.remove.button") //$NON-NLS-1$
@ -93,7 +93,6 @@ public class CPathSourceEntryPage extends CPathBasePage {
fFoldersList.enableButton(IDX_REMOVE, false); fFoldersList.enableButton(IDX_REMOVE, false);
} }
public Image getImage() { public Image getImage() {
return CPluginImages.get(CPluginImages.IMG_OBJS_SOURCE_ROOT); return CPluginImages.get(CPluginImages.IMG_OBJS_SOURCE_ROOT);
} }
@ -109,8 +108,8 @@ public class CPathSourceEntryPage extends CPathBasePage {
fFoldersList.setElements(folders); fFoldersList.setElements(folders);
for (int i = 0; i < folders.size(); i++) { for (int i = 0; i < folders.size(); i++) {
CPElement cpe = (CPElement) folders.get(i); CPElement cpe = (CPElement)folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION); IPath[] patterns = (IPath[])cpe.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) { if (patterns.length > 0) {
fFoldersList.expandElement(cpe, 3); fFoldersList.expandElement(cpe, 3);
} }
@ -121,7 +120,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
PixelConverter converter = new PixelConverter(parent); PixelConverter converter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NONE); 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)); LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null));
int buttonBarWidth = converter.convertWidthInCharsToPixels(24); int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
@ -130,8 +129,8 @@ public class CPathSourceEntryPage extends CPathBasePage {
// expand // expand
List elements = fFoldersList.getElements(); List elements = fFoldersList.getElements();
for (int i = 0; i < elements.size(); i++) { for (int i = 0; i < elements.size(); i++) {
CPElement elem = (CPElement) elements.get(i); CPElement elem = (CPElement)elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION); IPath[] patterns = (IPath[])elem.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) { if (patterns.length > 0) {
fFoldersList.expandElement(elem, 3); fFoldersList.expandElement(elem, 3);
} }
@ -162,14 +161,14 @@ public class CPathSourceEntryPage extends CPathBasePage {
public Object[] getChildren(TreeListDialogField field, Object element) { public Object[] getChildren(TreeListDialogField field, Object element) {
if (element instanceof CPElement) { if (element instanceof CPElement) {
return ((CPElement) element).getChildren(); return ((CPElement)element).getChildren();
} }
return EMPTY_ARR; return EMPTY_ARR;
} }
public Object getParent(TreeListDialogField field, Object element) { public Object getParent(TreeListDialogField field, Object element) {
if (element instanceof CPElementAttribute) { if (element instanceof CPElementAttribute) {
return ((CPElementAttribute) element).getParent(); return ((CPElementAttribute)element).getParent();
} }
return null; return null;
} }
@ -275,9 +274,9 @@ public class CPathSourceEntryPage extends CPathBasePage {
} }
Object elem = selElements.get(0); Object elem = selElements.get(0);
if (fFoldersList.getIndexOfElement(elem) != -1) { if (fFoldersList.getIndexOfElement(elem) != -1) {
editElementEntry((CPElement) elem); editElementEntry((CPElement)elem);
} else if (elem instanceof CPElementAttribute) { } 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--) { for (int i = selElements.size() - 1; i >= 0; i--) {
Object elem = selElements.get(i); Object elem = selElements.get(i);
if (elem instanceof CPElementAttribute) { if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem; CPElementAttribute attrib = (CPElementAttribute)elem;
String key = attrib.getKey(); String key = attrib.getKey();
Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null; Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null;
attrib.getParent().setAttribute(key, value); attrib.getParent().setAttribute(key, value);
@ -337,16 +336,16 @@ public class CPathSourceEntryPage extends CPathBasePage {
for (int i = 0; i < selElements.size(); i++) { for (int i = 0; i < selElements.size(); i++) {
Object elem = selElements.get(i); Object elem = selElements.get(i);
if (elem instanceof CPElementAttribute) { if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem; CPElementAttribute attrib = (CPElementAttribute)elem;
if (attrib.getKey().equals(CPElement.EXCLUSION)) { if (attrib.getKey().equals(CPElement.EXCLUSION)) {
if (((IPath[]) attrib.getValue()).length == 0) { if ( ((IPath[])attrib.getValue()).length == 0) {
return false; return false;
} }
} else if (attrib.getValue() == null) { } else if (attrib.getValue() == null) {
return false; return false;
} }
} else if (elem instanceof CPElement) { } else if (elem instanceof CPElement) {
CPElement curr = (CPElement) elem; CPElement curr = (CPElement)elem;
if (curr.getParentContainer() != null) { if (curr.getParentContainer() != null) {
return false; return false;
} }
@ -389,7 +388,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
int lastRemovePos = nEntries; int lastRemovePos = nEntries;
int afterLastSourcePos = 0; int afterLastSourcePos = 0;
for (int i = nEntries - 1; i >= 0; i--) { for (int i = nEntries - 1; i >= 0; i--) {
CPElement cpe = (CPElement) cpelements.get(i); CPElement cpe = (CPElement)cpelements.get(i);
int kind = cpe.getEntryKind(); int kind = cpe.getEntryKind();
if (isEntryKind(kind)) { if (isEntryKind(kind)) {
if (!srcelements.remove(cpe)) { if (!srcelements.remove(cpe)) {
@ -415,25 +414,23 @@ public class CPathSourceEntryPage extends CPathBasePage {
if (includeLinked) { if (includeLinked) {
NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject());
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
IResource createdFolder = (IResource) dialog.getResult()[0]; IResource createdFolder = (IResource)dialog.getResult()[0];
return newCPSourceElement(createdFolder); return newCPSourceElement(createdFolder);
} }
return null; 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) { private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) {
@ -447,7 +444,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
private CPElement[] openSourceContainerDialog(CPElement existing) { 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); List existingContainers = getExistingContainers(null);
IProject[] allProjects = fWorkspaceRoot.getProjects(); IProject[] allProjects = fWorkspaceRoot.getProjects();
@ -464,9 +461,11 @@ public class CPathSourceEntryPage extends CPathBasePage {
ILabelProvider lp = new WorkbenchLabelProvider(); ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new BaseWorkbenchContentProvider(); 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$ : 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$ : CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.edit.description"); //$NON-NLS-1$
MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp);
@ -484,7 +483,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
Object[] elements = dialog.getResult(); Object[] elements = dialog.getResult();
CPElement[] res = new CPElement[elements.length]; CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) { for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i]; IResource elem = (IResource)elements[i];
res[i] = newCPSourceElement(elem); res[i] = newCPSourceElement(elem);
} }
return res; return res;
@ -496,7 +495,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
List res = new ArrayList(); List res = new ArrayList();
List cplist = fFoldersList.getElements(); List cplist = fFoldersList.getElements();
for (int i = 0; i < cplist.size(); i++) { for (int i = 0; i < cplist.size(); i++) {
CPElement elem = (CPElement) cplist.get(i); CPElement elem = (CPElement)cplist.get(i);
if (elem != existing) { if (elem != existing) {
IResource resource = elem.getResource(); IResource resource = elem.getResource();
if (resource instanceof IContainer) { // defensive code if (resource instanceof IContainer) { // defensive code

View file

@ -157,7 +157,7 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage {
elem = existing.getPathEntry(); elem = existing.getPathEntry();
} }
CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(),
IPathEntry.CDT_MACRO); new int[] {IPathEntry.CDT_MACRO});
wizard.setWindowTitle(title); wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry parent = wizard.getEntriesParent(); IPathEntry parent = wizard.getEntriesParent();

View file

@ -219,9 +219,8 @@ public class ExclusionPatternEntryDialog extends StatusDialog {
IPath path = res.getFullPath().removeFirstSegments(fCurrSourceFolder.getFullPath().segmentCount()).makeRelative(); IPath path = res.getFullPath().removeFirstSegments(fCurrSourceFolder.getFullPath().segmentCount()).makeRelative();
if (res instanceof IContainer) { if (res instanceof IContainer) {
return path.addTrailingSeparator(); return path.addTrailingSeparator();
} else {
return path;
} }
return path;
} }
return null; return null;
} }

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ISourceRoot; 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.util.PixelConverter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; 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.IDialogFieldListener;
@ -32,15 +31,11 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; 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.graphics.RGB;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display; 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 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) { public Color getBackground(Object element) {
return null; return null;
} }

View file

@ -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 PAGE_SETTINGS = "IncludeSysmbolsPropertyPage"; //$NON-NLS-1$
private static final String INDEX = "pageIndex"; //$NON-NLS-1$ private static final String INDEX = "pageIndex"; //$NON-NLS-1$
IncludesSymbolsTabBlock fIncludesSymbolsBlock; NewIncludesSymbolsTabBlock fIncludesSymbolsBlock;
/** /**
* @see PropertyPage#createContents * @see PropertyPage#createContents
@ -56,6 +56,7 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus
result = createWithCProject(parent, project); result = createWithCProject(parent, project);
} }
Dialog.applyDialogFont(result); Dialog.applyDialogFont(result);
noDefaultAndApplyButton();
return result; return result;
} }
@ -73,7 +74,7 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus
* Content for valid projects. * Content for valid projects.
*/ */
private Control createWithCProject(Composite parent, IProject project) { 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); fIncludesSymbolsBlock.init(getCElement(), null);
return fIncludesSymbolsBlock.createContents(parent); return fIncludesSymbolsBlock.createContents(parent);
} }

View file

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

View file

@ -16,9 +16,9 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IDE;
public class ProjectContainerDescriptor implements IContainerDescriptor { public class ProjectContainerDescriptor implements IContainerDescriptor {
private int fFilterType; private int[] fFilterType;
public ProjectContainerDescriptor(int filterType) { public ProjectContainerDescriptor(int[] filterType) {
fFilterType = filterType; fFilterType = filterType;
} }

View file

@ -1,11 +1,10 @@
/******************************************************************************* /***********************************************************************************************************************************
* Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This program and the accompanying materials are made
* program and the accompanying materials are made available under the terms of * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
* the Common Public License v1.0 which accompanies this distribution, and is * http://www.eclipse.org/legal/cpl-v10.html
* available at http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: QNX Software Systems - initial API and implementation * Contributors: QNX Software Systems - initial API and implementation
******************************************************************************/ **********************************************************************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths; package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,11 +36,11 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
public class ProjectContainerPage extends WizardPage implements ICPathContainerPage { public class ProjectContainerPage extends WizardPage implements ICPathContainerPage {
private int fFilterType; private int[] fFilterType;
private TableViewer viewer; private TableViewer viewer;
private ICProject fCProject; private ICProject fCProject;
protected ProjectContainerPage(int filterType) { protected ProjectContainerPage(int[] filterType) {
super("projectContainerPage"); //$NON-NLS-1$ super("projectContainerPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("ProjectContainerPage.title")); //$NON-NLS-1$ setTitle(CPathEntryMessages.getString("ProjectContainerPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("ProjectContainerPage.description")); //$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()))) { if (!cProjects[i].equals(fCProject) && !current.contains(CoreModel.newProjectEntry(cProjects[i].getPath()))) {
IPathEntry[] projEntries = cProjects[i].getRawPathEntries(); IPathEntry[] projEntries = cProjects[i].getRawPathEntries();
for (int j = 0; j < projEntries.length; j++) { for (int j = 0; j < projEntries.length; j++) {
if (projEntries[j].getEntryKind() == fFilterType && projEntries[j].isExported()) { for (int k = 0; k < fFilterType.length; k++) {
list.add(cProjects[i]); if (projEntries[j].getEntryKind() == fFilterType[k] && projEntries[j].isExported()) {
break; list.add(cProjects[i]);
break;
}
} }
} }
} }

View file

@ -64,9 +64,8 @@ import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.model.WorkbenchLabelProvider;
/** /**
* UI to set the source attachment archive and root. * UI to set the source attachment archive and root. Same implementation for both setting attachments for libraries from variable
* Same implementation for both setting attachments for libraries from * entries and for normal (internal or external) jar.
* variable entries and for normal (internal or external) jar.
* *
* SourceAttachmentBlock * SourceAttachmentBlock
*/ */
@ -96,38 +95,41 @@ public class SourceAttachmentBlock {
} }
/** /**
* @param context listeners for status updates * @param context
* @param entry The entry to edit * listeners for status updates
* @param containerPath Path of the container that contains the given entry or * @param entry
* <code>null</code> if the entry does not belong to a container. * The entry to edit
* @param project Project to which the entry belongs. Can be * @param containerPath
* <code>null</code> if <code>getRunnable</code> is not run and the entry * Path of the container that contains the given entry or <code>null</code> if the entry does not belong to a
* does not belong to a container. * container.
* @param project
* Project to which the entry belongs. Can be <code>null</code> if <code>getRunnable</code> is not run and the
* entry does not belong to a container.
* *
*/ */
public SourceAttachmentBlock(IStatusChangeListener context, ILibraryEntry entry, ICProject project) { public SourceAttachmentBlock(IStatusChangeListener context, ILibraryEntry entry, ICProject project) {
Assert.isNotNull(entry); Assert.isNotNull(entry);
fContext= context; fContext = context;
fEntry= entry; fEntry = entry;
fProject= project; fProject = project;
fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
fNameStatus= new StatusInfo(); fNameStatus = new StatusInfo();
SourceAttachmentAdapter adapter= new SourceAttachmentAdapter(); SourceAttachmentAdapter adapter = new SourceAttachmentAdapter();
fFileNameField= new StringButtonDialogField(adapter); fFileNameField = new StringButtonDialogField(adapter);
fFileNameField.setDialogFieldListener(adapter); fFileNameField.setDialogFieldListener(adapter);
fFileNameField.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.label")); //$NON-NLS-1$ fFileNameField.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.label")); //$NON-NLS-1$
fFileNameField.setButtonLabel(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfile.button")); //$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.setDialogFieldListener(adapter);
fWorkspaceButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.internal.button")); //$NON-NLS-1$ 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.setDialogFieldListener(adapter);
fExternalFolderButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfolder.button")); //$NON-NLS-1$ fExternalFolderButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfolder.button")); //$NON-NLS-1$
@ -154,8 +156,7 @@ public class SourceAttachmentBlock {
} }
/** /**
* Gets the source attachment root chosen by the user * Gets the source attachment root chosen by the user Returns null to let JCore automatically detect the root.
* Returns null to let JCore automatically detect the root.
*/ */
public IPath getSourceAttachmentRootPath() { public IPath getSourceAttachmentRootPath() {
return null; return null;
@ -163,6 +164,7 @@ public class SourceAttachmentBlock {
/** /**
* Null for now * Null for now
*
* @return * @return
*/ */
public IPath getSourceAttachmentPrefixMapping() { public IPath getSourceAttachmentPrefixMapping() {
@ -173,26 +175,27 @@ public class SourceAttachmentBlock {
* Creates the control * Creates the control
*/ */
public Control createControl(Composite parent) { public Control createControl(Composite parent) {
PixelConverter converter= new PixelConverter(parent); PixelConverter converter = new PixelConverter(parent);
fSWTWidget= parent; fSWTWidget = parent;
Composite composite= new Composite(parent, SWT.NONE); Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout(); GridLayout layout = new GridLayout();
layout.marginHeight= 0; layout.marginHeight = 0;
layout.marginWidth= 0; layout.marginWidth = 0;
layout.numColumns= 4; layout.numColumns = 4;
composite.setLayout(layout); composite.setLayout(layout);
int widthHint= converter.convertWidthInCharsToPixels(60); int widthHint = converter.convertWidthInCharsToPixels(60);
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 3; gd.horizontalSpan = 3;
Label message= new Label(composite, SWT.LEFT); Label message = new Label(composite, SWT.LEFT);
message.setLayoutData(gd); 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); fWorkspaceButton.doFillIntoGrid(composite, 1);
@ -214,7 +217,6 @@ public class SourceAttachmentBlock {
return composite; return composite;
} }
private class SourceAttachmentAdapter implements IStringButtonAdapter, IDialogFieldListener { private class SourceAttachmentAdapter implements IStringButtonAdapter, IDialogFieldListener {
// -------- IStringButtonAdapter -------- // -------- IStringButtonAdapter --------
@ -230,7 +232,7 @@ public class SourceAttachmentBlock {
private void attachmentChangeControlPressed(DialogField field) { private void attachmentChangeControlPressed(DialogField field) {
if (field == fFileNameField) { if (field == fFileNameField) {
IPath jarFilePath= chooseExtJarFile(); IPath jarFilePath = chooseExtJarFile();
if (jarFilePath != null) { if (jarFilePath != null) {
fFileNameField.setText(jarFilePath.toString()); fFileNameField.setText(jarFilePath.toString());
} }
@ -241,15 +243,15 @@ public class SourceAttachmentBlock {
private void attachmentDialogFieldChanged(DialogField field) { private void attachmentDialogFieldChanged(DialogField field) {
if (field == fFileNameField) { if (field == fFileNameField) {
fNameStatus= updateFileNameStatus(); fNameStatus = updateFileNameStatus();
} else if (field == fWorkspaceButton) { } else if (field == fWorkspaceButton) {
IPath jarFilePath= chooseInternalJarFile(); IPath jarFilePath = chooseInternalJarFile();
if (jarFilePath != null) { if (jarFilePath != null) {
fFileNameField.setText(jarFilePath.toString()); fFileNameField.setText(jarFilePath.toString());
} }
return; return;
} else if (field == fExternalFolderButton) { } else if (field == fExternalFolderButton) {
IPath folderPath= chooseExtFolder(); IPath folderPath = chooseExtFolder();
if (folderPath != null) { if (folderPath != null) {
fFileNameField.setText(folderPath.toString()); fFileNameField.setText(folderPath.toString());
} }
@ -266,7 +268,7 @@ public class SourceAttachmentBlock {
fFullPathResolvedLabel.setText(getResolvedLabelString(fFileNameField.getText(), true)); fFullPathResolvedLabel.setText(getResolvedLabelString(fFileNameField.getText(), true));
} }
IStatus status= StatusUtil.getMostSevere(new IStatus[] { fNameStatus }); IStatus status = StatusUtil.getMostSevere(new IStatus[]{fNameStatus});
fContext.statusChanged(status); fContext.statusChanged(status);
} }
@ -275,13 +277,12 @@ public class SourceAttachmentBlock {
} }
private String getResolvedLabelString(String path, boolean osPath) { private String getResolvedLabelString(String path, boolean osPath) {
IPath resolvedPath= getResolvedPath(new Path(path)); IPath resolvedPath = getResolvedPath(new Path(path));
if (resolvedPath != null) { if (resolvedPath != null) {
if (osPath) { if (osPath) {
return resolvedPath.toOSString(); return resolvedPath.toOSString();
} else {
return resolvedPath.toString();
} }
return resolvedPath.toString();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@ -294,28 +295,28 @@ public class SourceAttachmentBlock {
} }
private IStatus updateFileNameStatus() { private IStatus updateFileNameStatus() {
StatusInfo status= new StatusInfo(); StatusInfo status = new StatusInfo();
String fileName= fFileNameField.getText(); String fileName = fFileNameField.getText();
if (fileName.length() == 0) { if (fileName.length() == 0) {
// no source attachment // no source attachment
return status; return status;
} else { }
if (!Path.EMPTY.isValidPath(fileName)) { if (!Path.EMPTY.isValidPath(fileName)) {
status.setError(CPathEntryMessages.getString("SourceAttachmentBlock.filename.error.notvalid")); //$NON-NLS-1$ status.setError(CPathEntryMessages.getString("SourceAttachmentBlock.filename.error.notvalid")); //$NON-NLS-1$
return status; return status;
} }
IPath filePath= new Path(fileName); IPath filePath = new Path(fileName);
File file= filePath.toFile(); File file = filePath.toFile();
IResource res= fWorkspaceRoot.findMember(filePath); IResource res = fWorkspaceRoot.findMember(filePath);
if (res != null && res.getLocation() != null) { if (res != null && res.getLocation() != null) {
file= res.getLocation().toFile(); file = res.getLocation().toFile();
} }
if (!file.exists()) { if (!file.exists()) {
String message= CPathEntryMessages.getFormattedString("SourceAttachmentBlock.filename.error.filenotexists", filePath.toString()); //$NON-NLS-1$ String message = CPathEntryMessages.getFormattedString(
status.setError(message); "SourceAttachmentBlock.filename.error.filenotexists", filePath.toString()); //$NON-NLS-1$
return status; status.setError(message);
} return status;
} }
return status; return status;
} }
@ -324,20 +325,20 @@ public class SourceAttachmentBlock {
* Opens a dialog to choose a jar from the file system. * Opens a dialog to choose a jar from the file system.
*/ */
private IPath chooseExtJarFile() { private IPath chooseExtJarFile() {
IPath currPath= new Path(fFileNameField.getText()); IPath currPath = new Path(fFileNameField.getText());
if (currPath.isEmpty()) { if (currPath.isEmpty()) {
currPath= fEntry.getPath(); currPath = fEntry.getPath();
} }
if (ArchiveFileFilter.isArchivePath(currPath)) { if (ArchiveFileFilter.isArchivePath(currPath)) {
currPath= currPath.removeLastSegments(1); currPath = currPath.removeLastSegments(1);
} }
FileDialog dialog= new FileDialog(getShell()); FileDialog dialog = new FileDialog(getShell());
dialog.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extjardialog.text")); //$NON-NLS-1$ 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()); dialog.setFilterPath(currPath.toOSString());
String res= dialog.open(); String res = dialog.open();
if (res != null) { if (res != null) {
return new Path(res).makeAbsolute(); return new Path(res).makeAbsolute();
} }
@ -345,48 +346,47 @@ public class SourceAttachmentBlock {
} }
private IPath chooseExtFolder() { private IPath chooseExtFolder() {
IPath currPath= new Path(fFileNameField.getText()); IPath currPath = new Path(fFileNameField.getText());
if (currPath.isEmpty()) { if (currPath.isEmpty()) {
currPath= fEntry.getPath(); currPath = fEntry.getPath();
} }
if (ArchiveFileFilter.isArchivePath(currPath)) { 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.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extfolderdialog.text")); //$NON-NLS-1$
dialog.setFilterPath(currPath.toOSString()); dialog.setFilterPath(currPath.toOSString());
String res= dialog.open(); String res = dialog.open();
if (res != null) { if (res != null) {
return new Path(res).makeAbsolute(); return new Path(res).makeAbsolute();
} }
return null; return null;
} }
/* /*
* Opens a dialog to choose an internal jar. * Opens a dialog to choose an internal jar.
*/ */
private IPath chooseInternalJarFile() { private IPath chooseInternalJarFile() {
String initSelection= fFileNameField.getText(); String initSelection = fFileNameField.getText();
Class[] acceptedClasses= new Class[] { IFolder.class, IFile.class }; Class[] acceptedClasses = new Class[]{IFolder.class, IFile.class};
TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, false); TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, false);
ViewerFilter filter= new ArchiveFileFilter(null, false); ViewerFilter filter = new ArchiveFileFilter(null, false);
ILabelProvider lp= new WorkbenchLabelProvider(); ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp= new WorkbenchContentProvider(); ITreeContentProvider cp = new WorkbenchContentProvider();
IResource initSel= null; IResource initSel = null;
if (initSelection.length() > 0) { if (initSelection.length() > 0) {
initSel= fWorkspaceRoot.findMember(new Path(initSelection)); initSel = fWorkspaceRoot.findMember(new Path(initSelection));
} }
if (initSel == null) { 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.setAllowMultiple(false);
dialog.setValidator(validator); dialog.setValidator(validator);
dialog.addFilter(filter); dialog.addFilter(filter);
@ -395,7 +395,7 @@ public class SourceAttachmentBlock {
dialog.setInput(fWorkspaceRoot); dialog.setInput(fWorkspaceRoot);
dialog.setInitialSelection(initSel); dialog.setInitialSelection(initSel);
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
IResource res= (IResource) dialog.getFirstResult(); IResource res = (IResource)dialog.getFirstResult();
return res.getFullPath(); return res.getFullPath();
} }
return null; return null;
@ -412,16 +412,16 @@ public class SourceAttachmentBlock {
* Creates a runnable that sets the source attachment by modifying the project's classpath. * Creates a runnable that sets the source attachment by modifying the project's classpath.
*/ */
public IRunnableWithProgress getRunnable(final ICProject jproject, final Shell shell) { public IRunnableWithProgress getRunnable(final ICProject jproject, final Shell shell) {
fProject= jproject; fProject = jproject;
return getRunnable(shell); return getRunnable(shell);
} }
/** /**
* Creates a runnable that sets the source attachment by modifying the * Creates a runnable that sets the source attachment by modifying the project's classpath or updating a container.
* project's classpath or updating a container.
*/ */
public IRunnableWithProgress getRunnable(final Shell shell) { public IRunnableWithProgress getRunnable(final Shell shell) {
return new IRunnableWithProgress() { return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException { public void run(IProgressMonitor monitor) throws InvocationTargetException {
try { try {
attachSource(shell, monitor); attachSource(shell, monitor);
@ -433,26 +433,27 @@ public class SourceAttachmentBlock {
} }
protected void attachSource(final Shell shell, IProgressMonitor monitor) throws CoreException { protected void attachSource(final Shell shell, IProgressMonitor monitor) throws CoreException {
boolean isExported= fEntry.isExported(); boolean isExported = fEntry.isExported();
ILibraryEntry newEntry; ILibraryEntry newEntry;
newEntry= CoreModel.newLibraryEntry(fEntry.getPath(), fEntry.getBasePath(), fEntry.getLibraryPath(), newEntry = CoreModel.newLibraryEntry(fEntry.getPath(), fEntry.getBasePath(), fEntry.getLibraryPath(),
getSourceAttachmentPath(), getSourceAttachmentRootPath(), getSourceAttachmentPrefixMapping(), isExported); getSourceAttachmentPath(), getSourceAttachmentRootPath(), getSourceAttachmentPrefixMapping(), isExported);
updateProjectPathEntry(shell, fProject, newEntry, monitor); updateProjectPathEntry(shell, fProject, newEntry, monitor);
} }
private void updateProjectPathEntry(Shell shell, ICProject cproject, ILibraryEntry newEntry, IProgressMonitor monitor) throws CModelException { private void updateProjectPathEntry(Shell shell, ICProject cproject, ILibraryEntry newEntry, IProgressMonitor monitor)
IPathEntry[] oldClasspath= cproject.getRawPathEntries(); throws CModelException {
int nEntries= oldClasspath.length; IPathEntry[] oldClasspath = cproject.getRawPathEntries();
ArrayList newEntries= new ArrayList(nEntries + 1); int nEntries = oldClasspath.length;
int entryKind= newEntry.getEntryKind(); ArrayList newEntries = new ArrayList(nEntries + 1);
IPath jarPath= newEntry.getPath(); int entryKind = newEntry.getEntryKind();
boolean found= false; IPath jarPath = newEntry.getPath();
for (int i= 0; i < nEntries; i++) { boolean found = false;
IPathEntry curr= oldClasspath[i]; for (int i = 0; i < nEntries; i++) {
IPathEntry curr = oldClasspath[i];
if (curr.getEntryKind() == entryKind && curr.getPath().equals(jarPath)) { if (curr.getEntryKind() == entryKind && curr.getPath().equals(jarPath)) {
// add modified entry // add modified entry
newEntries.add(newEntry); newEntries.add(newEntry);
found= true; found = true;
} else { } else {
newEntries.add(curr); newEntries.add(curr);
} }
@ -464,17 +465,18 @@ public class SourceAttachmentBlock {
// add new // 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); cproject.setRawPathEntries(newPathEntries, monitor);
} }
private boolean putJarOnClasspathDialog(Shell shell) { private boolean putJarOnClasspathDialog(Shell shell) {
final boolean[] result= new boolean[1]; final boolean[] result = new boolean[1];
shell.getDisplay().syncExec(new Runnable() { shell.getDisplay().syncExec(new Runnable() {
public void run() { public void run() {
String title= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.title"); //$NON-NLS-1$ String title = CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.title"); //$NON-NLS-1$
String message= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.message"); //$NON-NLS-1$ String message = CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.message"); //$NON-NLS-1$
result[0]= MessageDialog.openQuestion(CUIPlugin.getActiveWorkbenchShell(), title, message); result[0] = MessageDialog.openQuestion(CUIPlugin.getActiveWorkbenchShell(), title, message);
} }
}); });
return result[0]; return result[0];