1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Work in progress, for the Library Entry UI

This commit is contained in:
Alain Magloire 2004-05-04 20:05:27 +00:00
parent c8bbe7c2eb
commit 771e8d51cf
10 changed files with 117 additions and 83 deletions

View file

@ -146,7 +146,7 @@ public class CPathEntryTest extends TestCase {
entries = new IPathEntry[3];
entries[0] = CoreModel.newIncludeEntry(new Path(""), null, new Path("/usr/include"), true);
entries[1] = CoreModel.newIncludeEntry(new Path("cpaththest/foo.c"), null, new Path("/usr/include"), true);
entries[2] = CoreModel.newLibraryEntry(null, new Path("/usr/lib/libc.so.1"), null, null, null, false);
entries[2] = CoreModel.newLibraryEntry(new Path(""), null, new Path("/usr/lib/libc.so.1"), null, null, null, false);
testProject.setRawPathEntries(entries, new NullProgressMonitor());
entries = testProject.getResolvedPathEntries();
// We always have at least two entries:
@ -171,7 +171,7 @@ public class CPathEntryTest extends TestCase {
IPathEntry[] entries = new IPathEntry[3];
entries[0] = CoreModel.newIncludeEntry(new Path(""), null, new Path("/usr/include"), true);
entries[1] = CoreModel.newIncludeEntry(new Path("foo"), null, new Path("/usr/include"), true);
entries[2] = CoreModel.newLibraryEntry(null, new Path("/usr/lib/libc.so.1"), null, null, null, false);
entries[2] = CoreModel.newLibraryEntry(new Path(""), null, new Path("/usr/lib/libc.so.1"), null, null, null, false);
CElementListener listener = new CElementListener();
CoreModel.getDefault().addElementChangedListener(listener);
testProject.setRawPathEntries(entries, new NullProgressMonitor());
@ -198,7 +198,7 @@ public class CPathEntryTest extends TestCase {
IPathEntry[] entries = new IPathEntry[3];
entries[0] = CoreModel.newIncludeEntry(new Path(""), null, new Path("/usr/include"), true);
entries[1] = CoreModel.newIncludeEntry(new Path("foo.c"), null, new Path("/usr/include"), true);
entries[2] = CoreModel.newLibraryEntry(null, new Path("/usr/lib/libc.so.1"), null, null, null, true);
entries[2] = CoreModel.newLibraryEntry(new Path(""), null, new Path("/usr/lib/libc.so.1"), null, null, null, true);
return entries;
}

View file

@ -359,6 +359,8 @@ public class CoreModel {
* Creates and returns a new entry of kind <code>CDT_LIBRARY</code>
* for the archive or folder identified by the given absolute path.
*
* @param resourcePath
* the affected project-relative resource path
* @param baseRef
* the base reference path to find the library
* @param libraryPath
@ -366,8 +368,8 @@ public class CoreModel {
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryRefEntry(IPath baseRef, IPath libraryPath) {
return new LibraryEntry(null, baseRef, libraryPath, null, null, null, false);
public static ILibraryEntry newLibraryRefEntry(IPath resourcePath, IPath baseRef, IPath libraryPath) {
return new LibraryEntry(resourcePath, null, baseRef, libraryPath, null, null, null, false);
}
@ -379,6 +381,8 @@ public class CoreModel {
* resources at the given paths.
* <p>
*
* @param resourcePath
* the affected project-relative resource path
* @param basePath
* the base path of the library
* @param libraryPath
@ -396,9 +400,9 @@ public class CoreModel {
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryEntry(IPath basePath, IPath libraryPath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
public static ILibraryEntry newLibraryEntry(IPath resourcePath, IPath basePath, IPath libraryPath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
IPath sourceAttachmentPrefixMapping, boolean isExported) {
return new LibraryEntry(basePath, null, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported);
return new LibraryEntry(resourcePath, basePath, null, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported);
}
/**

View file

@ -70,6 +70,12 @@ public interface ILibraryEntry extends IPathEntry {
*/
IPath getBaseReference();
/**
* Return the library path.
* @return
*/
IPath getLibraryPath();
/**
* Returns the complete path, equivalent to:
* getBasepath().append(getPath());

View file

@ -34,9 +34,10 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
* @param sourceAttachmentPrefixMapping
* @param isExported
*/
public LibraryEntry(IPath basePath, IPath baseRef, IPath libraryPath, IPath sourceAttachmentPath,
public LibraryEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath libraryPath, IPath sourceAttachmentPath,
IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) {
super(ILibraryEntry.CDT_LIBRARY, basePath, baseRef, libraryPath, APathEntry.NO_EXCLUSION_PATTERNS, isExported);
super(ILibraryEntry.CDT_LIBRARY, basePath, baseRef, resourcePath, APathEntry.NO_EXCLUSION_PATTERNS, isExported);
this.libraryPath = libraryPath;
this.sourceAttachmentPath = sourceAttachmentPath;
this.sourceAttachmentRootPath = sourceAttachmentRootPath;
this.sourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping;
@ -96,7 +97,17 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
if (!super.equals(obj)) {
return false;
}
IPath otherPath = otherEntry.getSourceAttachmentPath();
IPath otherPath = otherEntry.getLibraryPath();
if (libraryPath == null) {
if (otherPath != null) {
return false;
}
} else {
if (!libraryPath.equals(otherPath)) {
return false;
}
}
otherPath = otherEntry.getSourceAttachmentPath();
if (sourceAttachmentPath == null) {
if (otherPath != null) {
return false;
@ -137,4 +148,11 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
return p;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ILibraryEntry#getLibraryPath()
*/
public IPath getLibraryPath() {
return libraryPath;
}
}

View file

@ -20,7 +20,7 @@ public class LibraryReference extends Parent implements ILibraryReference {
ILibraryEntry entry;
public LibraryReference(ICElement parent, ILibraryEntry e) {
super(parent, e.getPath().lastSegment(), ICElement.C_VCONTAINER);
super(parent, e.getLibraryPath().lastSegment(), ICElement.C_VCONTAINER);
entry = e;
}
@ -42,7 +42,7 @@ public class LibraryReference extends Parent implements ILibraryReference {
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
public IPath getPath() {
return entry.getPath();
return entry.getFullLibraryPath();
}
/* (non-Javadoc)

View file

@ -209,7 +209,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ILibraryEntry libEntry = (ILibraryEntry)entry;
IPath refPath = libEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) {
IPath libraryPath = libEntry.getPath();
IPath libraryPath = libEntry.getLibraryPath();
if (refPath.isAbsolute()) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath);
if (res != null && res.getType() == IResource.PROJECT) {
@ -220,8 +220,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getPath().equals(libraryPath)) {
return CoreModel.newLibraryEntry(refEntry.getBasePath(),
refEntry.getPath(), refEntry.getSourceAttachmentPath(),
return CoreModel.newLibraryEntry(entry.getPath(), refEntry.getBasePath(),
refEntry.getLibraryPath(), refEntry.getSourceAttachmentPath(),
refEntry.getSourceAttachmentRootPath(),
refEntry.getSourceAttachmentPrefixMapping(), false);
}
@ -237,8 +237,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getPath().equals(libraryPath)) {
return CoreModel.newLibraryEntry(refEntry.getBasePath(),
refEntry.getPath(), refEntry.getSourceAttachmentPath(),
return CoreModel.newLibraryEntry(entry.getPath(), refEntry.getBasePath(),
refEntry.getLibraryPath(), refEntry.getSourceAttachmentPath(),
refEntry.getSourceAttachmentRootPath(),
refEntry.getSourceAttachmentPrefixMapping(), false);
}

View file

@ -57,6 +57,7 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
static String ATTRIBUTE_PREFIXMAPPING = "prefixmapping"; //$NON-NLS-1$
static String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$
static String ATTRIBUTE_INCLUDE = "include"; //$NON-NLS-1$
static String ATTRIBUTE_LIBRARY = "library"; //$NON-NLS-1$
static String ATTRIBUTE_SYSTEM = "system"; //$NON-NLS-1$
static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
static String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
@ -142,14 +143,6 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
// get the base ref
IPath baseRef = new Path(element.getAttribute(ATTRIBUTE_BASE_REF));
// source attachment info (optional)
IPath sourceAttachmentPath = element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(
element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null;
IPath sourceAttachmentRootPath = element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path(
element.getAttribute(ATTRIBUTE_ROOTPATH)) : null;
IPath sourceAttachmentPrefixMapping = element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(
element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null;
// exclusion patterns (optional)
String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING);
IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS;
@ -168,61 +161,64 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
switch (kind) {
case IPathEntry.CDT_PROJECT :
return CoreModel.newProjectEntry(path, isExported);
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY : {
IPath libraryPath = new Path(element.getAttribute(ATTRIBUTE_LIBRARY));
// source attachment info (optional)
IPath sourceAttachmentPath = element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(
element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null;
IPath sourceAttachmentRootPath = element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path(
element.getAttribute(ATTRIBUTE_ROOTPATH)) : null;
IPath sourceAttachmentPrefixMapping = element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(
element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null;
if (baseRef != null && !baseRef.isEmpty()) {
return CoreModel.newLibraryRefEntry(baseRef, path);
return CoreModel.newLibraryRefEntry(path, baseRef, libraryPath);
}
return CoreModel.newLibraryEntry(basePath, path, sourceAttachmentPath, sourceAttachmentRootPath,
return CoreModel.newLibraryEntry(path, basePath, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath,
sourceAttachmentPrefixMapping, isExported);
case IPathEntry.CDT_SOURCE :
{
// must be an entry in this project or specify another
}
case IPathEntry.CDT_SOURCE : {
// must be an entry in this project or specify another
// project
String projSegment = path.segment(0);
if (projSegment != null && projSegment.equals(project.getName())) { // this
// project
String projSegment = path.segment(0);
if (projSegment != null && projSegment.equals(project.getName())) { // this
// project
return CoreModel.newSourceEntry(path, exclusionPatterns);
} else { // another project
return CoreModel.newProjectEntry(path, isExported);
}
return CoreModel.newSourceEntry(path, exclusionPatterns);
} else { // another project
return CoreModel.newProjectEntry(path, isExported);
}
}
case IPathEntry.CDT_OUTPUT :
{
return CoreModel.newOutputEntry(path, exclusionPatterns);
return CoreModel.newOutputEntry(path, exclusionPatterns);
case IPathEntry.CDT_INCLUDE : {
// include path info
IPath includePath = new Path(element.getAttribute(ATTRIBUTE_INCLUDE));
// isSysteminclude
boolean isSystemInclude = false;
if (element.hasAttribute(ATTRIBUTE_SYSTEM)) {
isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE);
}
case IPathEntry.CDT_INCLUDE :
{
// include path info
IPath includePath = new Path(element.getAttribute(ATTRIBUTE_INCLUDE));
// isSysteminclude
boolean isSystemInclude = false;
if (element.hasAttribute(ATTRIBUTE_SYSTEM)) {
isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE);
}
if (baseRef != null && !baseRef.isEmpty()) {
return CoreModel.newIncludeRefEntry(path, baseRef, includePath);
}
return CoreModel.newIncludeEntry(path, basePath, includePath, isSystemInclude, exclusionPatterns, isExported);
if (baseRef != null && !baseRef.isEmpty()) {
return CoreModel.newIncludeRefEntry(path, baseRef, includePath);
}
case IPathEntry.CDT_MACRO :
{
String macroName = element.getAttribute(ATTRIBUTE_NAME);
String macroValue = element.getAttribute(ATTRIBUTE_VALUE);
if (baseRef != null && !baseRef.isEmpty()) {
return CoreModel.newMacroRefEntry(path, baseRef, macroName);
}
return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns, isExported);
}
case IPathEntry.CDT_CONTAINER :
{
IPath id = new Path(element.getAttribute(ATTRIBUTE_PATH));
return CoreModel.newContainerEntry(id, isExported);
}
default :
{
ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$
throw new CModelException(status);
return CoreModel.newIncludeEntry(path, basePath, includePath, isSystemInclude, exclusionPatterns, isExported);
}
case IPathEntry.CDT_MACRO : {
String macroName = element.getAttribute(ATTRIBUTE_NAME);
String macroValue = element.getAttribute(ATTRIBUTE_VALUE);
if (baseRef != null && !baseRef.isEmpty()) {
return CoreModel.newMacroRefEntry(path, baseRef, macroName);
}
return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns, isExported);
}
case IPathEntry.CDT_CONTAINER : {
IPath id = new Path(element.getAttribute(ATTRIBUTE_PATH));
return CoreModel.newContainerEntry(id, isExported);
}
default : {
ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$
throw new CModelException(status);
}
}
}
@ -267,6 +263,8 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
break;
case IPathEntry.CDT_LIBRARY: {
ILibraryEntry lib = (ILibraryEntry) entries[i];
IPath libraryPath = lib.getLibraryPath();
element.setAttribute(ATTRIBUTE_LIBRARY, libraryPath.toString());
IPath sourcePath = lib.getSourceAttachmentPath();
if (sourcePath != null) {
// translate to project relative from absolute

View file

@ -32,6 +32,7 @@ public class CPElement {
public static final String SOURCEATTACHMENTROOT = "rootpath"; //$NON-NLS-1$
public static final String EXCLUSION = "exclusion"; //$NON-NLS-1$
public static final String INCLUDE = "includepath"; //$NON-NLS-1$
public static final String LIBRARY = "librarypath"; //$NON-NLS-1$
public static final String SYSTEM_INCLUDE = "systeminclude"; //$NON-NLS-1$
public static final String MACRO_NAME = "macroname"; //$NON-NLS-1$
public static final String MACRO_VALUE = "macrovalue"; //$NON-NLS-1$
@ -70,6 +71,7 @@ public class CPElement {
createAttributeElement(EXCLUSION, new Path[0]);
break;
case IPathEntry.CDT_LIBRARY:
createAttributeElement(LIBRARY, new Path("")); //$NON-NLS-1$
createAttributeElement(SOURCEATTACHMENT, null);
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
@ -123,11 +125,12 @@ public class CPElement {
case IPathEntry.CDT_SOURCE:
return CoreModel.newSourceEntry(fPath, exclusionPattern);
case IPathEntry.CDT_LIBRARY:
IPath libraryPath = (IPath)getAttribute(LIBRARY);
IPath attach = (IPath) getAttribute(SOURCEATTACHMENT);
if (!baseRef.isEmpty()) {
return CoreModel.newLibraryRefEntry(baseRef, fPath);
return CoreModel.newLibraryRefEntry(fPath, baseRef, libraryPath);
} else {
return CoreModel.newLibraryEntry(base, fPath, attach, null, null, isExported());
return CoreModel.newLibraryEntry(fPath, base, libraryPath, attach, null, null, isExported());
}
case IPathEntry.CDT_PROJECT:
return CoreModel.newProjectEntry(fPath, isExported());
@ -207,6 +210,8 @@ public class CPElement {
appendEncodePath(base, buf);
IPath sourceAttach = (IPath) getAttribute(SOURCEATTACHMENT);
appendEncodePath(sourceAttach, buf);
IPath library = (IPath) getAttribute(LIBRARY);
appendEncodePath(library, buf);
break;
default:
}
@ -305,8 +310,9 @@ public class CPElement {
}
switch (fEntryKind) {
case IPathEntry.CDT_LIBRARY:
return getAttribute(BASE).equals(elem.getAttribute(BASE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF));
return (getAttribute(LIBRARY).equals(elem.getAttribute(LIBRARY))
&& getAttribute(BASE).equals(elem.getAttribute(BASE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)));
case IPathEntry.CDT_INCLUDE:
return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals(
@ -406,6 +412,7 @@ public class CPElement {
IPath sourceAttachment = null;
IPath[] exclusion = null;
IPath include = null;
IPath library = null;
String macroName = null;
String macroValue = null;
boolean sysInclude = false;
@ -434,6 +441,7 @@ public class CPElement {
}
isMissing = !path.toFile().isFile(); // look for external
}
library = ((ILibraryEntry) curr).getLibraryPath();
sourceAttachment = ((ILibraryEntry) curr).getSourceAttachmentPath();
base = ((ILibraryEntry) curr).getBasePath();
baseRef = ((ILibraryEntry) curr).getBaseReference();
@ -503,6 +511,7 @@ public class CPElement {
elem.setAttribute(SOURCEATTACHMENT, sourceAttachment);
elem.setAttribute(EXCLUSION, exclusion);
elem.setAttribute(INCLUDE, include);
elem.setAttribute(LIBRARY, library);
elem.setAttribute(MACRO_NAME, macroName);
elem.setAttribute(MACRO_VALUE, macroValue);
elem.setAttribute(SYSTEM_INCLUDE, Boolean.valueOf(sysInclude));

View file

@ -54,16 +54,16 @@ class CPElementLabelProvider extends LabelProvider {
public String getText(Object element) {
if (element instanceof CPElement) {
return getCPListElementText((CPElement)element);
return getCPElementText((CPElement)element);
} else if (element instanceof CPElementAttribute) {
return getCPListElementAttributeText((CPElementAttribute)element);
return getCPElementAttributeText((CPElementAttribute)element);
} else if (element instanceof IPathEntry) {
return getCPListElementText(CPElement.createFromExisting((IPathEntry)element, null));
return getCPElementText(CPElement.createFromExisting((IPathEntry)element, null));
}
return super.getText(element);
}
public String getCPListElementAttributeText(CPElementAttribute attrib) {
public String getCPElementAttributeText(CPElementAttribute attrib) {
String notAvailable = CPathEntryMessages.getString("CPListLabelProvider.none"); //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
String key = attrib.getKey();
@ -101,7 +101,7 @@ class CPElementLabelProvider extends LabelProvider {
return buf.toString();
}
public String getCPListElementText(CPElement cpentry) {
public String getCPElementText(CPElement cpentry) {
IPath path = cpentry.getPath();
switch (cpentry.getEntryKind()) {
case IPathEntry.CDT_LIBRARY :
@ -178,7 +178,7 @@ class CPElementLabelProvider extends LabelProvider {
// }
}
private ImageDescriptor getCPListElementBaseImage(CPElement cpentry) {
private ImageDescriptor getCPElementBaseImage(CPElement cpentry) {
switch (cpentry.getEntryKind()) {
case IPathEntry.CDT_OUTPUT :
if (cpentry.getPath().segmentCount() == 1) {
@ -228,7 +228,7 @@ class CPElementLabelProvider extends LabelProvider {
public Image getImage(Object element) {
if (element instanceof CPElement) {
CPElement cpentry = (CPElement)element;
ImageDescriptor imageDescriptor = getCPListElementBaseImage(cpentry);
ImageDescriptor imageDescriptor = getCPElementBaseImage(cpentry);
if (imageDescriptor != null) {
if (cpentry.isMissing()) {
imageDescriptor = new CElementImageDescriptor(imageDescriptor, CElementImageDescriptor.WARNING, SMALL_SIZE);

View file

@ -89,7 +89,6 @@ public class CPathLibraryEntryPage extends CPathBasePage {
}
private void updateLibrariesList() {
//List cpelements= fLibrariesList.getElements();
List cpelements = filterList(fCPathList.getElements());
List libelements= new ArrayList(cpelements.size());