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

cpath ui update

This commit is contained in:
David Inglis 2004-04-28 17:46:29 +00:00
parent 54aa75f147
commit 9b4b4cabc4
26 changed files with 1007 additions and 584 deletions

View file

@ -77,7 +77,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
List entries = new ArrayList();
for (int i = 0; i < nElements; i++) {
CPListElement currElement = (CPListElement) elements.get(i);
CPElement currElement = (CPElement) elements.get(i);
entries.add(currElement.getPathEntry());
}
entries.addAll(fFilteredOut);
@ -128,7 +128,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
for (int i = 0; i < cPathEntries.length; i++) {
IPathEntry curr = cPathEntries[i];
if (contains(types, curr.getEntryKind())) {
newCPath.add(CPListElement.createFromExisting(curr, fCurrCProject));
newCPath.add(CPElement.createFromExisting(curr, fCurrCProject));
} else {
fFilteredOut.add(curr);
}
@ -155,7 +155,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
int nElements = getCPaths().size();
buf.append('[').append(nElements).append(']');
for (int i = 0; i < nElements; i++) {
CPListElement elem = (CPListElement) getCPaths().get(i);
CPElement elem = (CPElement) getCPaths().get(i);
elem.appendEncodedSettings(buf);
}
return buf.toString();
@ -232,7 +232,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
IPathEntry[] entries = new IPathEntry[elements.size()];
for (int i = elements.size() - 1; i >= 0; i--) {
CPListElement currElement = (CPListElement) elements.get(i);
CPElement currElement = (CPElement) elements.get(i);
entries[i] = currElement.getPathEntry();
}
@ -274,7 +274,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
// create and set the paths
for (int i = 0; i < cPathEntries.size(); i++) {
CPListElement entry = ((CPListElement) cPathEntries.get(i));
CPElement entry = ((CPElement) cPathEntries.get(i));
IResource res = entry.getResource();
if ((res instanceof IFolder) && !res.exists()) {
CoreUtility.createFolder((IFolder) res, true, true, null);

View file

@ -20,12 +20,13 @@ import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class CPListElement {
public class CPElement {
public static final String SOURCEATTACHMENT = "sourcepath"; //$NON-NLS-1$
public static final String SOURCEATTACHMENTROOT = "rootpath"; //$NON-NLS-1$
@ -46,10 +47,10 @@ public class CPListElement {
private boolean fIsExported;
private boolean fIsMissing;
private CPListElement fParentContainer;
private CPElement fParentContainer;
private IPathEntry fCachedEntry;
public CPListElement(ICProject project, int entryKind, IPath path, IResource res) {
public CPElement(ICProject project, int entryKind, IPath path, IResource res) {
fCProject = project;
fEntryKind = entryKind;
fPath = path;
@ -62,38 +63,38 @@ public class CPListElement {
fParentContainer = null;
switch (entryKind) {
case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_OUTPUT:
createAttributeElement(EXCLUSION, new Path[0]);
break;
case IPathEntry.CDT_SOURCE :
case IPathEntry.CDT_SOURCE:
createAttributeElement(EXCLUSION, new Path[0]);
break;
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
createAttributeElement(SOURCEATTACHMENT, null);
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break;
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
createAttributeElement(INCLUDE, new Path("")); //$NON-NLS-1$
createAttributeElement(EXCLUSION, new Path[0]);
createAttributeElement(SYSTEM_INCLUDE, Boolean.valueOf(false));
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break;
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
createAttributeElement(MACRO_NAME, ""); //$NON-NLS-1$
createAttributeElement(MACRO_VALUE, ""); //$NON-NLS-1$
createAttributeElement(EXCLUSION, new Path[0]);
createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$
createAttributeElement(BASE, new Path("")); //$NON-NLS-1$
break;
case IPathEntry.CDT_CONTAINER :
case IPathEntry.CDT_CONTAINER:
try {
IPathEntryContainer container = CoreModel.getDefault().getPathEntryContainer(fPath, fCProject);
IPathEntryContainer container = CoreModel.getPathEntryContainer(fPath, fCProject);
if (container != null) {
IPathEntry[] entries = container.getPathEntries();
for (int i = 0; i < entries.length; i++) {
CPListElement curr = createFromExisting(entries[i], fCProject);
CPElement curr = createFromExisting(entries[i], fCProject);
curr.setParentContainer(this);
fChildren.add(curr);
}
@ -101,7 +102,7 @@ public class CPListElement {
} catch (CModelException e) {
}
break;
default :
default:
}
}
@ -117,41 +118,42 @@ public class CPListElement {
IPath base = (IPath) getAttribute(BASE);
IPath baseRef = (IPath) getAttribute(BASE_REF);
switch (fEntryKind) {
case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_OUTPUT:
return CoreModel.newOutputEntry(fPath, exclusionPattern);
case IPathEntry.CDT_SOURCE :
case IPathEntry.CDT_SOURCE:
return CoreModel.newSourceEntry(fPath, exclusionPattern);
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
IPath attach = (IPath) getAttribute(SOURCEATTACHMENT);
if (baseRef != null) {
if (!baseRef.isEmpty()) {
return CoreModel.newLibraryRefEntry(baseRef, fPath);
} else {
return CoreModel.newLibraryEntry(base, fPath, attach, null, null, isExported());
}
case IPathEntry.CDT_PROJECT :
case IPathEntry.CDT_PROJECT:
return CoreModel.newProjectEntry(fPath, isExported());
case IPathEntry.CDT_CONTAINER :
case IPathEntry.CDT_CONTAINER:
return CoreModel.newContainerEntry(fPath, isExported());
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
IPath include = (IPath) getAttribute(INCLUDE);
if (baseRef != null) {
if (!baseRef.isEmpty()) {
return CoreModel.newIncludeRefEntry(fPath, baseRef, include);
} else {
return CoreModel.newIncludeEntry(fPath, base, include, ((Boolean) getAttribute(SYSTEM_INCLUDE)).booleanValue(),
exclusionPattern);
}
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
String macroName = (String) getAttribute(MACRO_NAME);
String macroValue = (String) getAttribute(MACRO_VALUE);
if (baseRef != null) {
if (!baseRef.isEmpty()) {
return CoreModel.newMacroRefEntry(fPath, baseRef, macroName);
} else {
return CoreModel.newMacroEntry(fPath, macroName, macroValue, exclusionPattern);
}
default :
default:
return null;
}
}
public static StringBuffer appendEncodePath(IPath path, StringBuffer buf) {
if (path != null) {
String str = path.toString();
@ -170,17 +172,17 @@ public class CPListElement {
appendEncodePath(fPath, buf).append(';');
buf.append(Boolean.valueOf(fIsExported)).append(';');
switch (fEntryKind) {
case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_SOURCE :
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_OUTPUT:
case IPathEntry.CDT_SOURCE:
case IPathEntry.CDT_INCLUDE:
case IPathEntry.CDT_MACRO:
IPath[] exclusion = (IPath[]) getAttribute(EXCLUSION);
buf.append('[').append(exclusion.length).append(']');
for (int i = 0; i < exclusion.length; i++) {
appendEncodePath(exclusion[i], buf);
}
switch (fEntryKind) {
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
IPath baseRef = (IPath) getAttribute(BASE_REF);
appendEncodePath(baseRef, buf);
IPath base = (IPath) getAttribute(BASE);
@ -188,17 +190,17 @@ public class CPListElement {
IPath include = (IPath) getAttribute(INCLUDE);
appendEncodePath(include, buf);
break;
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
baseRef = (IPath) getAttribute(BASE_REF);
appendEncodePath(baseRef, buf);
base = (IPath) getAttribute(BASE);
appendEncodePath(base, buf);
String symbol = (String) getAttribute(MACRO_NAME);
buf.append(symbol).append(';');
default :
default:
}
break;
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
IPath baseRef = (IPath) getAttribute(BASE_REF);
appendEncodePath(baseRef, buf);
IPath base = (IPath) getAttribute(BASE);
@ -206,7 +208,7 @@ public class CPListElement {
IPath sourceAttach = (IPath) getAttribute(SOURCEATTACHMENT);
appendEncodePath(sourceAttach, buf);
break;
default :
default:
}
buf.setLength(buf.length() - 1);
return buf;
@ -231,14 +233,15 @@ public class CPListElement {
}
/**
* Entries without resource are either non existing or a variable entry External jars do not have a resource
* Entries without resource are either non existing or a variable entry
* External jars do not have a resource
*/
public IResource getResource() {
return fResource;
}
public CPListElementAttribute setAttribute(String key, Object value) {
CPListElementAttribute attribute = findAttributeElement(key);
public CPElementAttribute setAttribute(String key, Object value) {
CPElementAttribute attribute = findAttributeElement(key);
if (attribute == null) {
return null;
}
@ -247,11 +250,11 @@ public class CPListElement {
return attribute;
}
private CPListElementAttribute findAttributeElement(String key) {
private CPElementAttribute findAttributeElement(String key) {
for (int i = 0; i < fChildren.size(); i++) {
Object curr = fChildren.get(i);
if (curr instanceof CPListElementAttribute) {
CPListElementAttribute elem = (CPListElementAttribute) curr;
if (curr instanceof CPElementAttribute) {
CPElementAttribute elem = (CPElementAttribute) curr;
if (key.equals(elem.getKey())) {
return elem;
}
@ -261,7 +264,7 @@ public class CPListElement {
}
public Object getAttribute(String key) {
CPListElementAttribute attrib = findAttributeElement(key);
CPElementAttribute attrib = findAttributeElement(key);
if (attrib != null) {
return attrib.getValue();
}
@ -269,21 +272,21 @@ public class CPListElement {
}
private void createAttributeElement(String key, Object value) {
fChildren.add(new CPListElementAttribute(this, key, value));
fChildren.add(new CPElementAttribute(this, key, value));
}
public Object[] getChildren() {
if (fEntryKind == IPathEntry.CDT_OUTPUT || fEntryKind == IPathEntry.CDT_SOURCE) {
return new Object[]{findAttributeElement(EXCLUSION)};
return new Object[] { findAttributeElement(EXCLUSION)};
}
return fChildren.toArray();
}
private void setParentContainer(CPListElement element) {
private void setParentContainer(CPElement element) {
fParentContainer = element;
}
public CPListElement getParentContainer() {
public CPElement getParentContainer() {
return fParentContainer;
}
@ -296,19 +299,19 @@ public class CPListElement {
*/
public boolean equals(Object other) {
if (other != null && other.getClass().equals(getClass())) {
CPListElement elem = (CPListElement) other;
CPElement elem = (CPElement) other;
if (elem.fEntryKind != fEntryKind || !elem.fPath.equals(fPath)) {
return false;
}
switch (fEntryKind) {
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
return getAttribute(BASE).equals(elem.getAttribute(BASE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF));
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals(
elem.getAttribute(BASE)));
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
return (getAttribute(MACRO_NAME).equals(elem.getAttribute(MACRO_NAME))
&& getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && getAttribute(BASE).equals(
elem.getAttribute(BASE)));
@ -325,16 +328,16 @@ public class CPListElement {
final int HASH_FACTOR = 89;
int hashCode = fPath.hashCode() + fEntryKind;
switch (fEntryKind) {
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
break;
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
hashCode = hashCode * HASH_FACTOR + getAttribute(INCLUDE).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
break;
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
hashCode = hashCode * HASH_FACTOR + getAttribute(MACRO_NAME).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
@ -397,9 +400,9 @@ public class CPListElement {
return fCProject;
}
public static CPListElement createFromExisting(IPathEntry curr, ICProject project) {
public static CPElement createFromExisting(IPathEntry curr, ICProject project) {
IPath path = curr.getPath();
IWorkspaceRoot root = project.getProject().getWorkspace().getRoot();
IWorkspaceRoot root = CUIPlugin.getWorkspace().getRoot();
IPath sourceAttachment = null;
IPath[] exclusion = null;
IPath include = null;
@ -412,17 +415,16 @@ public class CPListElement {
// get the resource
IResource res = null;
boolean isMissing = false;
// URL javaDocLocation = null;
switch (curr.getEntryKind()) {
case IPathEntry.CDT_CONTAINER :
case IPathEntry.CDT_CONTAINER:
res = null;
try {
isMissing = (CoreModel.getDefault().getPathEntryContainer(path, project) == null);
isMissing = (CoreModel.getPathEntryContainer(path, project) == null);
} catch (CModelException e) {
}
break;
case IPathEntry.CDT_LIBRARY :
case IPathEntry.CDT_LIBRARY:
res = root.findMember(path);
if (res == null) {
// if (!ArchiveFileFilter.isArchivePath(path)) {
@ -436,7 +438,7 @@ public class CPListElement {
base = ((ILibraryEntry) curr).getBasePath();
baseRef = ((ILibraryEntry) curr).getBaseReference();
break;
case IPathEntry.CDT_SOURCE :
case IPathEntry.CDT_SOURCE:
path = path.removeTrailingSeparator();
res = root.findMember(path);
if (res == null) {
@ -447,7 +449,7 @@ public class CPListElement {
}
exclusion = ((ISourceEntry) curr).getExclusionPatterns();
break;
case IPathEntry.CDT_OUTPUT :
case IPathEntry.CDT_OUTPUT:
path = path.removeTrailingSeparator();
res = root.findMember(path);
if (res == null) {
@ -458,7 +460,7 @@ public class CPListElement {
}
exclusion = ((IOutputEntry) curr).getExclusionPatterns();
break;
case IPathEntry.CDT_INCLUDE :
case IPathEntry.CDT_INCLUDE:
path = path.removeTrailingSeparator();
res = root.findMember(path);
if (res == null) {
@ -475,7 +477,7 @@ public class CPListElement {
base = ((IIncludeEntry) curr).getBasePath();
include = ((IIncludeEntry) curr).getIncludePath();
break;
case IPathEntry.CDT_MACRO :
case IPathEntry.CDT_MACRO:
path = path.removeTrailingSeparator();
res = root.findMember(path);
if (res == null) {
@ -490,14 +492,14 @@ public class CPListElement {
macroName = ((IMacroEntry) curr).getMacroName();
macroValue = ((IMacroEntry) curr).getMacroValue();
baseRef = ((IMacroEntry) curr).getBaseReference();
base = ((IIncludeEntry) curr).getBasePath();
base = ((IMacroEntry) curr).getBasePath();
break;
case IPathEntry.CDT_PROJECT :
case IPathEntry.CDT_PROJECT:
res = root.findMember(path);
isMissing = (res == null);
break;
}
CPListElement elem = new CPListElement(project, curr.getEntryKind(), path, res);
CPElement elem = new CPElement(project, curr.getEntryKind(), path, res);
elem.setAttribute(SOURCEATTACHMENT, sourceAttachment);
elem.setAttribute(EXCLUSION, exclusion);
elem.setAttribute(INCLUDE, include);

View file

@ -8,19 +8,19 @@
******************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
public class CPListElementAttribute {
public class CPElementAttribute {
private CPListElement fParent;
private CPElement fParent;
private String fKey;
private Object fValue;
public CPListElementAttribute(CPListElement parent, String key, Object value) {
public CPElementAttribute(CPElement parent, String key, Object value) {
fKey = key;
fValue = value;
fParent = parent;
}
public CPListElement getParent() {
public CPElement getParent() {
return fParent;
}

View file

@ -11,10 +11,10 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
* Viewer filter for archive selection dialogs. Archives are files with file extension '.so', '.dll' and '.a'. The filter is not
* case sensitive.
* Viewer filter for archive selection dialogs. Archives are files with file
* extension '.so', '.dll' and '.a'. The filter is not case sensitive.
*/
public class CPListElementFilter extends ViewerFilter {
public class CPElementFilter extends ViewerFilter {
private List fExcludes;
private int fKind;
@ -22,26 +22,32 @@ public class CPListElementFilter extends ViewerFilter {
/**
* @param excludedFiles
* Excluded paths will not pass the filter. <code>null</code> is allowed if no files should be excluded.
* Excluded paths will not pass the filter. <code>null</code> is
* allowed if no files should be excluded.
* @param recusive
* Folders are only shown if, searched recursivly, contain an archive
* Folders are only shown if, searched recursivly, contain an archive
*/
public CPListElementFilter(CPListElement[] excludedElements, int kind, boolean exportedOnly) {
public CPElementFilter(CPElement[] excludedElements, int kind, boolean exportedOnly) {
if (excludedElements != null) {
fExcludes = Arrays.asList(excludedElements);
}
fKind = kind;
fExportedOnly = exportedOnly;
}
public CPElementFilter(int kind, boolean exportedOnly) {
this(null, kind, exportedOnly);
}
/*
* @see ViewerFilter#select
*/
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof CPListElement) {
if (((CPListElement) element).getEntryKind() == fKind) {
if (element instanceof CPElement) {
if (((CPElement) element).getEntryKind() == fKind) {
if (fExcludes != null && !fExcludes.contains(element)) {
if (fExportedOnly == true && !((CPListElement) element).isExported()) {
if (fExportedOnly == true && !((CPElement) element).isExported()) {
return false;
}
return true;
@ -51,13 +57,19 @@ public class CPListElementFilter extends ViewerFilter {
try {
IPathEntry[] entries = ((ICProject) element).getRawPathEntries();
for (int i = 0; i < entries.length; i++) {
if (select(viewer, parent, CPListElement.createFromExisting(entries[i], (ICProject) element))) {
if (select(viewer, parent, CPElement.createFromExisting(entries[i], (ICProject) element))) {
return true;
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e.getStatus());
}
} else if (element instanceof IPathEntry) {
boolean bShow = ((IPathEntry) element).getEntryKind() == fKind;
if (bShow && fExportedOnly == true) {
return ((IPathEntry) element).isExported();
}
return bShow;
}
return false;
}

View file

@ -27,7 +27,7 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.ide.IDE;
class CPListLabelProvider extends LabelProvider {
class CPElementLabelProvider extends LabelProvider {
private String fNewLabel, fClassLabel, fCreateLabel;
private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon, fExtLibIcon, fExtLibWSrcIcon;
@ -35,7 +35,7 @@ class CPListLabelProvider extends LabelProvider {
private ImageDescriptorRegistry fRegistry;
public CPListLabelProvider() {
public CPElementLabelProvider() {
fNewLabel = CPathEntryMessages.getString("CPListLabelProvider.new"); //$NON-NLS-1$
fClassLabel = CPathEntryMessages.getString("CPListLabelProvider.classcontainer"); //$NON-NLS-1$
fCreateLabel = CPathEntryMessages.getString("CPListLabelProvider.willbecreated"); //$NON-NLS-1$
@ -55,19 +55,21 @@ class CPListLabelProvider extends LabelProvider {
}
public String getText(Object element) {
if (element instanceof CPListElement) {
return getCPListElementText((CPListElement) element);
} else if (element instanceof CPListElementAttribute) {
return getCPListElementAttributeText((CPListElementAttribute) element);
if (element instanceof CPElement) {
return getCPListElementText((CPElement) element);
} else if (element instanceof CPElementAttribute) {
return getCPListElementAttributeText((CPElementAttribute) element);
} else if (element instanceof IPathEntry) {
return getCPListElementText(CPElement.createFromExisting((IPathEntry) element, null));
}
return super.getText(element);
}
public String getCPListElementAttributeText(CPListElementAttribute attrib) {
public String getCPListElementAttributeText(CPElementAttribute attrib) {
String notAvailable = CPathEntryMessages.getString("CPListLabelProvider.none"); //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
String key = attrib.getKey();
if (key.equals(CPListElement.SOURCEATTACHMENT)) {
if (key.equals(CPElement.SOURCEATTACHMENT)) {
buf.append(CPathEntryMessages.getString("CPListLabelProvider.source_attachment.label")); //$NON-NLS-1$
IPath path = (IPath) attrib.getValue();
if (path != null && !path.isEmpty()) {
@ -75,7 +77,7 @@ class CPListLabelProvider extends LabelProvider {
} else {
buf.append(notAvailable);
}
} else if (key.equals(CPListElement.SOURCEATTACHMENTROOT)) {
} else if (key.equals(CPElement.SOURCEATTACHMENTROOT)) {
buf.append(CPathEntryMessages.getString("CPListLabelProvider.source_attachment_root.label")); //$NON-NLS-1$
IPath path = (IPath) attrib.getValue();
if (path != null && !path.isEmpty()) {
@ -84,7 +86,7 @@ class CPListLabelProvider extends LabelProvider {
buf.append(notAvailable);
}
}
if (key.equals(CPListElement.EXCLUSION)) {
if (key.equals(CPElement.EXCLUSION)) {
buf.append(CPathEntryMessages.getString("CPListLabelProvider.exclusion_filter.label")); //$NON-NLS-1$
IPath[] patterns = (IPath[]) attrib.getValue();
if (patterns != null && patterns.length > 0) {
@ -101,7 +103,7 @@ class CPListLabelProvider extends LabelProvider {
return buf.toString();
}
public String getCPListElementText(CPListElement cpentry) {
public String getCPListElementText(CPElement cpentry) {
IPath path = cpentry.getPath();
switch (cpentry.getEntryKind()) {
case IPathEntry.CDT_LIBRARY:
@ -128,21 +130,24 @@ class CPListLabelProvider extends LabelProvider {
return path.lastSegment();
case IPathEntry.CDT_INCLUDE:
{
StringBuffer str = new StringBuffer(((IPath) cpentry.getAttribute(CPListElement.INCLUDE)).toOSString());
IPath base = (IPath) cpentry.getAttribute(CPListElement.BASE_REF);
if (base != null && base.segmentCount() > 0) {
str.append('(');
StringBuffer str = new StringBuffer(((IPath) cpentry.getAttribute(CPElement.INCLUDE)).toOSString());
IPath base = (IPath) cpentry.getAttribute(CPElement.BASE_REF);
if (!base.isEmpty()) {
str.append(" - ("); //$NON-NLS-1$
str.append(base);
str.append(')');
} else {
path = ((IPath) cpentry.getAttribute(CPElement.BASE)).addTrailingSeparator();
str.insert(0, path.toOSString());
}
return str.toString();
}
case IPathEntry.CDT_MACRO:
{
StringBuffer str = new StringBuffer((String) cpentry.getAttribute(CPListElement.MACRO_NAME) + "=" //$NON-NLS-1$
+ (String) cpentry.getAttribute(CPListElement.MACRO_VALUE));
IPath base = (IPath) cpentry.getAttribute(CPListElement.BASE_REF);
if (base != null && base.segmentCount() > 0) {
StringBuffer str = new StringBuffer((String) cpentry.getAttribute(CPElement.MACRO_NAME) + "=" //$NON-NLS-1$
+ (String) cpentry.getAttribute(CPElement.MACRO_VALUE));
IPath base = (IPath) cpentry.getAttribute(CPElement.BASE_REF);
if (!base.isEmpty()) {
str.append('(');
str.append(base);
str.append(')');
@ -151,8 +156,7 @@ class CPListLabelProvider extends LabelProvider {
}
case IPathEntry.CDT_CONTAINER:
try {
IPathEntryContainer container = CoreModel.getDefault().getPathEntryContainer(cpentry.getPath(),
cpentry.getCProject());
IPathEntryContainer container = CoreModel.getPathEntryContainer(cpentry.getPath(), cpentry.getCProject());
if (container != null) {
return container.getDescription();
}
@ -181,17 +185,20 @@ class CPListLabelProvider extends LabelProvider {
}
private String getPathString(IPath path, boolean isExternal) {
// if (ArchiveFileFilter.isArchivePath(path)) {
// IPath appendedPath = path.removeLastSegments(1);
// String appended = isExternal ? appendedPath.toOSString() : appendedPath.makeRelative().toString();
// return CPathEntryMessages.getFormattedString("CPListLabelProvider.twopart", //$NON-NLS-1$
// new String[] { path.lastSegment(), appended});
// } else {
return isExternal ? path.toOSString() : path.makeRelative().toString();
// }
// if (ArchiveFileFilter.isArchivePath(path)) {
// IPath appendedPath = path.removeLastSegments(1);
// String appended = isExternal ? appendedPath.toOSString() :
// appendedPath.makeRelative().toString();
// return
// CPathEntryMessages.getFormattedString("CPListLabelProvider.twopart",
// //$NON-NLS-1$
// new String[] { path.lastSegment(), appended});
// } else {
return isExternal ? path.toOSString() : path.makeRelative().toString();
// }
}
private ImageDescriptor getCPListElementBaseImage(CPListElement cpentry) {
private ImageDescriptor getCPListElementBaseImage(CPElement cpentry) {
switch (cpentry.getEntryKind()) {
case IPathEntry.CDT_OUTPUT:
if (cpentry.getPath().segmentCount() == 1) {
@ -207,7 +214,7 @@ class CPListLabelProvider extends LabelProvider {
}
case IPathEntry.CDT_LIBRARY:
IResource res = cpentry.getResource();
IPath path = (IPath) cpentry.getAttribute(CPListElement.SOURCEATTACHMENT);
IPath path = (IPath) cpentry.getAttribute(CPElement.SOURCEATTACHMENT);
if (res == null) {
if (path == null || path.isEmpty()) {
return fExtLibIcon;
@ -239,8 +246,8 @@ class CPListLabelProvider extends LabelProvider {
private static final Point SMALL_SIZE = new Point(16, 16);
public Image getImage(Object element) {
if (element instanceof CPListElement) {
CPListElement cpentry = (CPListElement) element;
if (element instanceof CPElement) {
CPElement cpentry = (CPElement) element;
ImageDescriptor imageDescriptor = getCPListElementBaseImage(cpentry);
if (imageDescriptor != null) {
if (cpentry.isMissing()) {
@ -248,14 +255,16 @@ class CPListLabelProvider extends LabelProvider {
}
return fRegistry.get(imageDescriptor);
}
} else if (element instanceof CPListElementAttribute) {
String key = ((CPListElementAttribute) element).getKey();
if (key.equals(CPListElement.SOURCEATTACHMENT)) {
} else if (element instanceof CPElementAttribute) {
String key = ((CPElementAttribute) element).getKey();
if (key.equals(CPElement.SOURCEATTACHMENT)) {
// return
// fRegistry.get(CPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB);
} else if (key.equals(CPListElement.EXCLUSION)) {
} else if (key.equals(CPElement.EXCLUSION)) {
return CPluginImages.get(CPluginImages.IMG_OBJS_EXCLUDSION_FILTER_ATTRIB);
}
} else if (element instanceof IPathEntry) {
return getImage(CPElement.createFromExisting((IPathEntry) element, null));
}
return null;
}

View file

@ -11,7 +11,7 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.jface.viewers.ViewerSorter;
public class CPListElementSorter extends ViewerSorter {
public class CPElementSorter extends ViewerSorter {
private static final int SOURCE = 0;
private static final int PROJECT = 1;
@ -23,8 +23,8 @@ public class CPListElementSorter extends ViewerSorter {
* @see ViewerSorter#category(Object)
*/
public int category(Object obj) {
if (obj instanceof CPListElement) {
switch (((CPListElement) obj).getEntryKind()) {
if (obj instanceof CPElement) {
switch (((CPElement) obj).getEntryKind()) {
case IPathEntry.CDT_LIBRARY:
return LIBRARY;
case IPathEntry.CDT_PROJECT:

View file

@ -30,25 +30,25 @@ public abstract class CPathBasePage extends AbstractCOptionPage {
protected void fixNestingConflicts(List newEntries, List existing, Set modifiedSourceEntries) {
for (int i = 0; i < newEntries.size(); i++) {
CPListElement curr = (CPListElement) newEntries.get(i);
CPElement curr = (CPElement) newEntries.get(i);
addExclusionPatterns(curr, existing, modifiedSourceEntries);
}
}
private void addExclusionPatterns(CPListElement newEntry, List existing, Set modifiedEntries) {
private void addExclusionPatterns(CPElement newEntry, List existing, Set modifiedEntries) {
IPath entryPath = newEntry.getPath();
for (int i = 0; i < existing.size(); i++) {
CPListElement curr = (CPListElement) existing.get(i);
CPElement curr = (CPElement) existing.get(i);
if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) {
IPath currPath = curr.getPath();
if (currPath.isPrefixOf(entryPath) && !currPath.equals(entryPath)) {
IPath[] exclusionFilters = (IPath[]) curr.getAttribute(CPListElement.EXCLUSION);
IPath[] exclusionFilters = (IPath[]) curr.getAttribute(CPElement.EXCLUSION);
if (!CoreModelUtil.isExcludedPath(entryPath.removeFirstSegments(1), exclusionFilters)) {
IPath pathToExclude = entryPath.removeFirstSegments(currPath.segmentCount()).addTrailingSeparator();
IPath[] newExclusionFilters = new IPath[exclusionFilters.length + 1];
System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length);
newExclusionFilters[exclusionFilters.length] = pathToExclude;
curr.setAttribute(CPListElement.EXCLUSION, newExclusionFilters);
curr.setAttribute(CPElement.EXCLUSION, newExclusionFilters);
modifiedEntries.add(curr);
}
}
@ -67,7 +67,7 @@ public abstract class CPathBasePage extends AbstractCOptionPage {
List cpelements = input;
for (int i = 0; i < cpelements.size(); i++) {
CPListElement cpe = (CPListElement) cpelements.get(i);
CPElement cpe = (CPElement) cpelements.get(i);
if (isEntryKind(cpe.getEntryKind())) {
filtered.add(cpe);
}

View file

@ -23,10 +23,10 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
public class CPathContainerDescriptor {
public class CPathContainerDescriptor implements IContainerDescriptor {
private IConfigurationElement fConfigElement;
private static final String ATT_EXTENSION = "CPathContainerPage"; //$NON-NLS-1$
private static final String ATT_EXTENSION = "PathContainerPage"; //$NON-NLS-1$
private static final String ATT_ID = "id"; //$NON-NLS-1$
private static final String ATT_NAME = "name"; //$NON-NLS-1$
@ -75,12 +75,12 @@ public class CPathContainerDescriptor {
return false;
}
public static CPathContainerDescriptor[] getDescriptors() {
public static IContainerDescriptor[] getDescriptors() {
ArrayList containers= new ArrayList();
IExtensionPoint extensionPoint = Platform.getPluginRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, ATT_EXTENSION);
if (extensionPoint != null) {
CPathContainerDescriptor defaultPage= null;
IContainerDescriptor defaultPage= null;
String defaultPageName= CPathContainerDefaultPage.class.getName();
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();

View file

@ -39,7 +39,7 @@ public class CPathContainerSelectionPage extends WizardPage {
private static class ClasspathContainerLabelProvider extends LabelProvider {
public String getText(Object element) {
return ((CPathContainerDescriptor) element).getName();
return ((IContainerDescriptor) element).getName();
}
}
@ -47,14 +47,14 @@ public class CPathContainerSelectionPage extends WizardPage {
}
private ListViewer fListViewer;
private CPathContainerDescriptor[] fContainers;
private IContainerDescriptor[] fContainers;
private IDialogSettings fDialogSettings;
/**
* Constructor for ClasspathContainerWizardPage.
* @param containerPages
*/
protected CPathContainerSelectionPage(CPathContainerDescriptor[] containerPages) {
protected CPathContainerSelectionPage(IContainerDescriptor[] containerPages) {
super("CPathContainerWizardPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("CPathContainerSelectionPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("CPathContainerSelectionPage.description")); //$NON-NLS-1$
@ -109,10 +109,10 @@ public class CPathContainerSelectionPage extends WizardPage {
}
public CPathContainerDescriptor getSelected() {
public IContainerDescriptor getSelected() {
if (fListViewer != null) {
ISelection selection= fListViewer.getSelection();
return (CPathContainerDescriptor) SelectionUtil.getSingleElement(selection);
return (IContainerDescriptor) SelectionUtil.getSingleElement(selection);
}
return null;
}

View file

@ -1,15 +1,17 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Common Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
@ -25,62 +27,56 @@ import org.eclipse.swt.widgets.Shell;
*/
public class CPathContainerWizard extends Wizard {
private CPathContainerDescriptor fPageDesc;
private IContainerDescriptor fPageDesc;
private IPathEntry fEntryToEdit;
private IPathEntry[] fNewEntries;
private IPathEntry[] fContainerEntries;
private ICPathContainerPage fContainerPage;
private ICProject fCurrProject;
private IPathEntry[] fCurrClasspath;
private CPathFilterPage fFilterPage;
private CPathContainerSelectionPage fSelectionWizardPage;
private int fFilterType;
/**
* Constructor for ClasspathContainerWizard.
*/
public CPathContainerWizard(IPathEntry entryToEdit, ICProject currProject, IPathEntry[] currEntries) {
this(entryToEdit, null, currProject, currEntries);
this(entryToEdit, null, currProject, currEntries, -1);
}
/**
* Constructor for ClasspathContainerWizard.
*/
public CPathContainerWizard(CPathContainerDescriptor pageDesc, ICProject currProject, IPathEntry[] currEntries) {
this(null, pageDesc, currProject, currEntries);
public CPathContainerWizard(IContainerDescriptor pageDesc, ICProject currProject, IPathEntry[] currEntries) {
this(null, pageDesc, currProject, currEntries, -1);
}
/**
* @deprecated
*/
public CPathContainerWizard(CPathContainerDescriptor pageDesc) {
this(null, pageDesc, null, null);
}
private CPathContainerWizard(IPathEntry entryToEdit, CPathContainerDescriptor pageDesc, ICProject currProject,
IPathEntry[] currEntries) {
public CPathContainerWizard(IPathEntry entryToEdit, IContainerDescriptor pageDesc, ICProject currProject,
IPathEntry[] currEntries, int filterType) {
fEntryToEdit = entryToEdit;
fPageDesc = pageDesc;
fNewEntries = null;
fFilterType = filterType;
fCurrProject = currProject;
fCurrClasspath = currEntries;
}
/**
* @deprecated use getNewEntries()
*/
public IPathEntry getNewEntry() {
IPathEntry[] entries = getNewEntries();
if (entries != null) {
return entries[0];
}
return null;
public IPathEntry getEntriesParent() {
return fContainerEntries[0];
}
public IPathEntry[] getNewEntries() {
public IPathEntry[] getEntries() {
return fNewEntries;
}
public IPathEntry[] getContainers() {
return fContainerEntries;
}
/*
* (non-Javadoc)
*
@ -89,7 +85,11 @@ public class CPathContainerWizard extends Wizard {
public boolean performFinish() {
if (fContainerPage != null) {
if (fContainerPage.finish()) {
fNewEntries = fContainerPage.getContainerEntries();
if (fFilterType != -1 && fFilterPage.isPageComplete()) {
fNewEntries = fFilterPage.getSelectedEntries();
} else {
fContainerEntries = fContainerPage.getContainerEntries();
}
return true;
}
}
@ -105,25 +105,33 @@ public class CPathContainerWizard extends Wizard {
if (fPageDesc != null) {
fContainerPage = getContainerPage(fPageDesc);
addPage(fContainerPage);
} else if (fEntryToEdit == null) { // new entry: show selection page as first page
CPathContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
fSelectionWizardPage = new CPathContainerSelectionPage(containers);
} else if (fEntryToEdit == null) { // new entry: show selection page as
// first page
IContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
List allContainers = new ArrayList(Arrays.asList(containers));
if (fFilterType != -1) {
allContainers.add(0, new ProjectContainerDescriptor(fFilterType));
}
fSelectionWizardPage = new CPathContainerSelectionPage(
(IContainerDescriptor[]) allContainers.toArray(new IContainerDescriptor[0]));
addPage(fSelectionWizardPage);
// add as dummy, will not be shown
fContainerPage = new CPathContainerDefaultPage();
addPage(fContainerPage);
} else { // fPageDesc == null && fEntryToEdit != null
CPathContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
CPathContainerDescriptor descriptor = findDescriptorPage(containers, fEntryToEdit);
IContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
IContainerDescriptor descriptor = findDescriptorPage(containers, fEntryToEdit);
fContainerPage = getContainerPage(descriptor);
addPage(fContainerPage);
}
if (fFilterType != -1) {
fFilterPage = new CPathFilterPage(fFilterType);
}
super.addPages();
}
private ICPathContainerPage getContainerPage(CPathContainerDescriptor pageDesc) {
private ICPathContainerPage getContainerPage(IContainerDescriptor pageDesc) {
ICPathContainerPage containerPage = null;
if (pageDesc != null) {
try {
@ -133,11 +141,9 @@ public class CPathContainerWizard extends Wizard {
containerPage = null;
}
}
if (containerPage == null) {
containerPage = new CPathContainerDefaultPage();
}
containerPage.initialize(fCurrProject, fCurrClasspath);
containerPage.setSelection(fEntryToEdit);
containerPage.setWizard(this);
@ -152,9 +158,11 @@ public class CPathContainerWizard extends Wizard {
public IWizardPage getNextPage(IWizardPage page) {
if (page == fSelectionWizardPage) {
CPathContainerDescriptor selected = fSelectionWizardPage.getSelected();
IContainerDescriptor selected = fSelectionWizardPage.getSelected();
fContainerPage = getContainerPage(selected);
return fContainerPage;
} else if (page == fContainerPage) {
fFilterPage.setEntries(fContainerPage.getContainerEntries()[0]);
}
return super.getNextPage(page);
}
@ -165,7 +173,7 @@ public class CPathContainerWizard extends Wizard {
ExceptionHandler.handle(e, getShell(), title, message);
}
private CPathContainerDescriptor findDescriptorPage(CPathContainerDescriptor[] containers, IPathEntry entry) {
private IContainerDescriptor findDescriptorPage(IContainerDescriptor[] containers, IPathEntry entry) {
for (int i = 0; i < containers.length; i++) {
if (containers[i].canEdit(entry)) {
return containers[i];
@ -188,6 +196,9 @@ public class CPathContainerWizard extends Wizard {
if (fContainerPage != null) {
return fContainerPage.isPageComplete();
}
if (fFilterPage != null) {
return fFilterPage.isPageComplete();
}
return false;
}

View file

@ -20,32 +20,36 @@ CPathsPropertyPage.unsavedchanges.button.ignore=Apply Later
BuildPathsBlock.tab.libraries=&Libraries
ProjectContainer.label=Project Path Entries
# -------- ExtendingCPathBasePage ---------
ExtendingCPathBasePage.editSourcePaths=Edit Source Paths...
ExtendingCPathBasePage.sourcePaths=Source Paths:
# -------- SymbolsEntryPage ---------
SymbolEntryPage.title=Symbols
SymbolEntryPage.add=Add User Defined...
SymbolEntryPage.addFromWorkspace=Add from Workspace...
SymbolEntryPage.addUser=Add User Defined...
SymbolEntryPage.addContributed=Add Contributed...
SymbolEntryPage.remove=Remove
SymbolEntryPage.edit=Edit...
SymbolEntryPage.listName=Defines:
SymbolEntryPage.editSourcePaths=Edit Source Paths...
SymbolEntryPage.sourcePaths=Source Paths:
IncludeEntryPage.addExternal.title=Add User Symbol
IncludeEntryPage.addExternal.message=Symbol definition:
SymbolEntryPage.addExternal.title=Add User Symbol
SymbolEntryPage.addExternal.message=Symbol definition:
SymbolEntryPage.ContainerDialog.new.title=Contributed Symbols Selection
SymbolEntryPage.ContainerDialog.edit.title=Contributed Symbols Path Selection
# ------- IncludeEntryPage ----------
IncludeEntryPage.title=Include Paths
IncludeEntryPage.add=Add External...
IncludeEntryPage.addExternal=Add External...
IncludeEntryPage.addFromWorkspace=Add From Workspace...
IncludeEntryPage.addContributed=Add Contributed...
IncludeEntryPage.remove=Remove
IncludeEntryPage.edit=Edit...
IncludeEntryPage.listName=Include Paths:
IncludeEntryPage.editSourcePaths=Edit Source Paths...
IncludeEntryPage.sourcePaths=Source Paths:
IncludeEntryPage.addExternal.button.browse=Browse...
IncludeEntryPage.addExternal.title=Add External Include Path
IncludeEntryPage.addExternal.message=Include path:
IncludeEntryPage.ContainerDialog.new.title=Contributed Include Path Selection
IncludeEntryPage.ContainerDialog.edit.title=Contributed Include Path Selection
# ------- BuildPathsBlock -------
CPathsBlock.path.up.button=&Up
@ -55,7 +59,6 @@ CPathsBlock.path.uncheckall.button=D&eselect All
CPathsBlock.path.label=Path order and exported entries:\n(Exported entries are contributed to dependent projects)
CPathsBlock.warning.EntryMissing=Build path entry is missing: {0}
CPathsBlock.warning.EntriesMissing={0} project path entries are missing.
CPathsBlock.operationdesc_project=Creating project...
CPathsBlock.operationdesc_c=Setting project paths...
# ------- SourcePathEntryPage-------

View file

@ -0,0 +1,96 @@
/*
* Created on Apr 26, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.List;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.viewsupport.ListContentProvider;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class CPathFilterPage extends WizardPage {
private final int fFilterType;
private CheckboxTableViewer viewer;
private IPathEntry fContainerPath;
private List fPaths;
protected CPathFilterPage(int filterType) {
super("CPathFilterPage"); //$NON-NLS-1$
fFilterType = filterType;
}
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
container.setLayout(layout);
Label label = new Label(container, SWT.NULL);
label.setText(CPathEntryMessages.getString("CPathFilterPage.label")); //$NON-NLS-1$
GridData gd = new GridData();
gd.horizontalSpan = 2;
label.setLayoutData(gd);
viewer =
CheckboxTableViewer.newCheckList(
container,
SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
viewer.setContentProvider(new ListContentProvider());
viewer.setLabelProvider(new CPElementLabelProvider());
viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
// Prevent user to change checkbox states
viewer.setChecked(event.getElement(), !event.getChecked());
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent e) {
handleSelectionChanged((IStructuredSelection) e.getSelection());
}
});
viewer.addFilter(new CPElementFilter(fFilterType, true));
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 300;
viewer.getTable().setLayoutData(gd);
setControl(container);
Dialog.applyDialogFont(container);
}
public void setVisible(boolean visible) {
if (fPaths != null) {
viewer.setInput(fPaths);
}
}
protected void handleSelectionChanged(IStructuredSelection selection) {
}
public void setEntries(IPathEntry entry) {
fContainerPath = entry;
}
public IPathEntry[] getSelectedEntries() {
return (IPathEntry[]) viewer.getCheckedElements();
}
}

View file

@ -0,0 +1,20 @@
/*
* Created on Apr 26, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import org.eclipse.jface.wizard.Wizard;
public class CPathFilterPathPage extends Wizard {
public boolean performFinish() {
return true;
}
}

View file

@ -9,16 +9,29 @@
******************************************************************************/
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.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.IPathEntry;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator;
import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
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.IPath;
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.SelectionAdapter;
@ -27,18 +40,88 @@ 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 CPathIncludeEntryPage extends ExtendedCPathBasePage {
private static final int IDX_ADD_USER = 0;
private static final int IDX_ADD_WORKSPACE = 1;
private static final int IDX_ADD_CONTRIBUTED = 2;
private static final int IDX_EDIT = 4;
private static final int IDX_REMOVE = 5;
private static final String[] buttonLabel = new String[] {
/* 0 */CPathEntryMessages.getString("IncludeEntryPage.addExternal"), //$NON-NLS-1$
/* 1 */CPathEntryMessages.getString("IncludeEntryPage.addFromWorkspace"), //$NON-NLS-1$
/* 2 */CPathEntryMessages.getString("IncludeEntryPage.addContributed"), null, //$NON-NLS-1$
/* 4 */CPathEntryMessages.getString("IncludeEntryPage.edit"), //$NON-NLS-1$
/* 5 */CPathEntryMessages.getString("IncludeEntryPage.remove")}; //$NON-NLS-1$
public CPathIncludeEntryPage(ITreeListAdapter adapter) {
super(adapter, "IncludeEntryPage"); //$NON-NLS-1$
super(adapter, CPathEntryMessages.getString("IncludeEntryPage.title"), //$NON-NLS-1$
CPathEntryMessages.getString("IncludeEntryPage.listName"), buttonLabel); //$NON-NLS-1$
}
public int getEntryKind() {
return IPathEntry.CDT_INCLUDE;
protected void buttonPressed(int indx, List selected) {
switch (indx) {
case IDX_ADD_USER:
addInclude();
break;
case IDX_ADD_WORKSPACE:
addFromWorkspace();
break;
case IDX_ADD_CONTRIBUTED:
addContributed();
break;
case IDX_EDIT:
if (canEdit(selected)) {
editInclude((CPElement) selected.get(0));
}
break;
case IDX_REMOVE:
if (canRemove(selected)) {
removeInclude((CPElement) selected.get(0));
}
break;
}
}
protected void addPath() {
public boolean isEntryKind(int kind) {
return IPathEntry.CDT_INCLUDE == kind;
}
protected void pathSelectionChanged() {
List selected = getPathList().getSelectedElements();
getPathList().enableButton(IDX_REMOVE, canRemove(selected));
getPathList().enableButton(IDX_EDIT, canEdit(selected));
}
public void createControl(Composite parent) {
super.createControl(parent);
getPathList().enableButton(IDX_REMOVE, false);
getPathList().enableButton(IDX_EDIT, false);
}
protected boolean canRemove(List selected) {
return !selected.isEmpty();
}
protected boolean canEdit(List selected) {
if (!selected.isEmpty()) {
return !isPathInheritedFromSelected((CPElement) selected.get(0));
}
return false;
}
protected void editInclude(CPElement element) {
}
protected void removeInclude(CPElement element) {
removeFromSelectedPath(element);
}
protected void addInclude() {
InputDialog dialog = new SelectPathInputDialog(getShell(),
CPathEntryMessages.getString("IncludeEntryPage.addExternal.title"), //$NON-NLS-1$
CPathEntryMessages.getString("IncludeEntryPage.addExternal.message"), null, null); //$NON-NLS-1$
@ -46,19 +129,138 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
if (dialog.open() == Window.OK) {
newItem = dialog.getValue();
if (newItem != null && !newItem.equals("")) { //$NON-NLS-1$
List cplist = fPathList.getElements();
CPListElement newPath = newCPElement(((ICElement) getSelection().get(0)).getResource(), null);
newPath.setAttribute(CPListElement.INCLUDE, new Path(newItem));
List cplist = getPathList().getElements();
ICElement element = (ICElement) getSelection().get(0);
CPElement newPath = new CPElement(element.getCProject(), IPathEntry.CDT_INCLUDE, element.getPath(),
element.getResource());
newPath.setAttribute(CPElement.INCLUDE, new Path(newItem));
if (!cplist.contains(newPath)) {
fPathList.addElement(newPath);
getPathList().addElement(newPath);
fCPathList.add(newPath);
fPathList.postSetSelection(new StructuredSelection(newPath));
getPathList().postSetSelection(new StructuredSelection(newPath));
}
}
}
}
protected void addFromWorkspace() {
CPElement[] includes = openWorkspacePathEntryDialog(null);
if (includes != null) {
int nElementsChosen = includes.length;
// remove duplicates
List cplist = getPathList().getElements();
List elementsToAdd = new ArrayList(nElementsChosen);
for (int i = 0; i < nElementsChosen; i++) {
CPElement curr = includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
}
}
getPathList().addElements(elementsToAdd);
fCPathList.addAll(elementsToAdd);
getPathList().postSetSelection(new StructuredSelection(elementsToAdd));
}
}
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("IncludeEntryPage.fromWorkspaceDialog.new.title") //$NON-NLS-1$
: CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.title"); //$NON-NLS-1$
String message = (existing == null) ? CPathEntryMessages.getString("IncludeEntryPage.fromWorkspaceDialog.new.description") //$NON-NLS-1$
: NewWizardMessages.getString("IncludeEntryPage.fromWorkspaceDialog.edit.description"); //$NON-NLS-1$
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];
ICElement element = (ICElement) getSelection().get(0);
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();
}
res[i] = new CPElement(element.getCProject(), IPathEntry.CDT_INCLUDE, element.getPath(), element.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("IncludeEntryPage.ContainerDialog.new.title"); //$NON-NLS-1$
} else {
title = CPathEntryMessages.getString("IncludeEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$
elem = existing.getPathEntry();
}
CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawClasspath(), IPathEntry.CDT_INCLUDE);
wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry parent = wizard.getEntriesParent();
IPathEntry[] elements = wizard.getEntries();
IResource resource = ((ICElement) getSelection().get(0)).getResource();
if (elements != null) {
CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) {
res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_INCLUDE, resource.getFullPath(), resource);
res[i].setAttribute(CPElement.INCLUDE, ((IIncludeEntry)elements[i]).getIncludePath());
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 = getPathList().getElements();
List elementsToAdd = new ArrayList(nElementsChosen);
for (int i = 0; i < nElementsChosen; i++) {
CPElement curr = includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
}
}
getPathList().addElements(elementsToAdd);
fCPathList.addAll(elementsToAdd);
getPathList().postSetSelection(new StructuredSelection(includes));
}
}
private class SelectPathInputDialog extends InputDialog {
public SelectPathInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue,
@ -87,14 +289,4 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
}
}
protected CPListElement newCPElement(IResource resource, CPListElement copyFrom) {
CPListElement element = new CPListElement(fCurrCProject, getEntryKind(), resource.getFullPath(), resource);
if (copyFrom != null) {
element.setAttribute(CPListElement.INCLUDE, copyFrom.getAttribute(CPListElement.INCLUDE));
element.setAttribute(CPListElement.SYSTEM_INCLUDE, copyFrom.getAttribute(CPListElement.SYSTEM_INCLUDE));
}
return element;
}
}

View file

@ -84,11 +84,11 @@ public class CPathOutputEntryPage extends CPathBasePage {
/* 3 = IDX_REMOVE */CPathEntryMessages.getString("OutputPathEntryPage.folders.remove.button") //$NON-NLS-1$
};
fOutputList = new TreeListDialogField(adapter, buttonLabels, new CPListLabelProvider());
fOutputList = new TreeListDialogField(adapter, buttonLabels, new CPElementLabelProvider());
fOutputList.setDialogFieldListener(adapter);
fOutputList.setLabelText(CPathEntryMessages.getString("OutputPathEntryPage.folders.label")); //$NON-NLS-1$
fOutputList.setViewerSorter(new CPListElementSorter());
fOutputList.setViewerSorter(new CPElementSorter());
fOutputList.enableButton(IDX_EDIT, false);
}
@ -109,8 +109,8 @@ public class CPathOutputEntryPage extends CPathBasePage {
fOutputList.setElements(folders);
for (int i = 0; i < folders.size(); i++) {
CPListElement cpe = (CPListElement) folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION);
CPElement cpe = (CPElement) folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) {
fOutputList.expandElement(cpe, 3);
}
@ -130,8 +130,8 @@ public class CPathOutputEntryPage extends CPathBasePage {
// expand
List elements = fOutputList.getElements();
for (int i = 0; i < elements.size(); i++) {
CPListElement elem = (CPListElement) elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPListElement.EXCLUSION);
CPElement elem = (CPElement) elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) {
fOutputList.expandElement(elem, 3);
}
@ -161,21 +161,21 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
public Object[] getChildren(TreeListDialogField field, Object element) {
if (element instanceof CPListElement) {
return ((CPListElement) element).getChildren();
if (element instanceof CPElement) {
return ((CPElement) element).getChildren();
}
return EMPTY_ARR;
}
public Object getParent(TreeListDialogField field, Object element) {
if (element instanceof CPListElementAttribute) {
return ((CPListElementAttribute) element).getParent();
if (element instanceof CPElementAttribute) {
return ((CPElementAttribute) element).getParent();
}
return null;
}
public boolean hasChildren(TreeListDialogField field, Object element) {
return (element instanceof CPListElement);
return (element instanceof CPElement);
}
// ---------- IDialogFieldListener --------
@ -226,20 +226,20 @@ public class CPathOutputEntryPage extends CPathBasePage {
IProject project = fCurrCProject.getProject();
if (project.exists()) {
if (hasFolders(project)) {
CPListElement[] srcentries = openOutputContainerDialog(null);
CPElement[] srcentries = openOutputContainerDialog(null);
if (srcentries != null) {
for (int i = 0; i < srcentries.length; i++) {
elementsToAdd.add(srcentries[i]);
}
}
} else {
CPListElement entry = openNewOutputContainerDialog(null, true);
CPElement entry = openNewOutputContainerDialog(null, true);
if (entry != null) {
elementsToAdd.add(entry);
}
}
} else {
CPListElement entry = openNewOutputContainerDialog(null, false);
CPElement entry = openNewOutputContainerDialog(null, false);
if (entry != null) {
elementsToAdd.add(entry);
}
@ -275,14 +275,14 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
Object elem = selElements.get(0);
if (fOutputList.getIndexOfElement(elem) != -1) {
editElementEntry((CPListElement) elem);
} else if (elem instanceof CPListElementAttribute) {
editAttributeEntry((CPListElementAttribute) elem);
editElementEntry((CPElement) elem);
} else if (elem instanceof CPElementAttribute) {
editAttributeEntry((CPElementAttribute) elem);
}
}
private void editElementEntry(CPListElement elem) {
CPListElement res = null;
private void editElementEntry(CPElement elem) {
CPElement res = null;
res = openNewOutputContainerDialog(elem, true);
@ -291,13 +291,13 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
}
private void editAttributeEntry(CPListElementAttribute elem) {
private void editAttributeEntry(CPElementAttribute elem) {
String key = elem.getKey();
if (key.equals(CPListElement.EXCLUSION)) {
CPListElement selElement = elem.getParent();
if (key.equals(CPElement.EXCLUSION)) {
CPElement selElement = elem.getParent();
ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement);
if (dialog.open() == Window.OK) {
selElement.setAttribute(CPListElement.EXCLUSION, dialog.getExclusionPattern());
selElement.setAttribute(CPElement.EXCLUSION, dialog.getExclusionPattern());
fOutputList.refresh();
fCPathList.dialogFieldChanged(); // validate
}
@ -314,10 +314,10 @@ public class CPathOutputEntryPage extends CPathBasePage {
List selElements = fOutputList.getSelectedElements();
for (int i = selElements.size() - 1; i >= 0; i--) {
Object elem = selElements.get(i);
if (elem instanceof CPListElementAttribute) {
CPListElementAttribute attrib = (CPListElementAttribute) elem;
if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem;
String key = attrib.getKey();
Object value = key.equals(CPListElement.EXCLUSION) ? new Path[0] : null;
Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null;
attrib.getParent().setAttribute(key, value);
selElements.remove(i);
}
@ -336,17 +336,17 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
for (int i = 0; i < selElements.size(); i++) {
Object elem = selElements.get(i);
if (elem instanceof CPListElementAttribute) {
CPListElementAttribute attrib = (CPListElementAttribute) elem;
if (attrib.getKey().equals(CPListElement.EXCLUSION)) {
if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem;
if (attrib.getKey().equals(CPElement.EXCLUSION)) {
if (((IPath[]) attrib.getValue()).length == 0) {
return false;
}
} else if (attrib.getValue() == null) {
return false;
}
} else if (elem instanceof CPListElement) {
CPListElement curr = (CPListElement) elem;
} else if (elem instanceof CPElement) {
CPElement curr = (CPElement) elem;
if (curr.getParentContainer() != null) {
return false;
}
@ -360,10 +360,10 @@ public class CPathOutputEntryPage extends CPathBasePage {
return false;
}
Object elem = selElements.get(0);
if (elem instanceof CPListElement) {
if (elem instanceof CPElement) {
return false;
}
if (elem instanceof CPListElementAttribute) {
if (elem instanceof CPElementAttribute) {
return true;
}
return false;
@ -389,7 +389,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
int lastRemovePos = nEntries;
int afterLastSourcePos = 0;
for (int i = nEntries - 1; i >= 0; i--) {
CPListElement cpe = (CPListElement) cpelements.get(i);
CPElement cpe = (CPElement) cpelements.get(i);
int kind = cpe.getEntryKind();
if (isEntryKind(kind)) {
if (!srcelements.remove(cpe)) {
@ -411,7 +411,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
}
private CPListElement openNewOutputContainerDialog(CPListElement existing, boolean includeLinked) {
private CPElement openNewOutputContainerDialog(CPElement existing, boolean includeLinked) {
if (includeLinked) {
NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject());
if (dialog.open() == Window.OK) {
@ -445,7 +445,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
}
private CPListElement[] openOutputContainerDialog(CPListElement existing) {
private CPElement[] openOutputContainerDialog(CPElement existing) {
Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class};
List existingContainers = getExistingContainers(null);
@ -482,7 +482,7 @@ public class CPathOutputEntryPage extends CPathBasePage {
}
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
CPListElement[] res = new CPListElement[elements.length];
CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = newCPOutputElement(elem);
@ -492,11 +492,11 @@ public class CPathOutputEntryPage extends CPathBasePage {
return null;
}
private List getExistingContainers(CPListElement existing) {
private List getExistingContainers(CPElement existing) {
List res = new ArrayList();
List cplist = fOutputList.getElements();
for (int i = 0; i < cplist.size(); i++) {
CPListElement elem = (CPListElement) cplist.get(i);
CPElement elem = (CPElement) cplist.get(i);
if (elem != existing) {
IResource resource = elem.getResource();
if (resource instanceof IContainer) { // defensive code
@ -507,9 +507,9 @@ public class CPathOutputEntryPage extends CPathBasePage {
return res;
}
private CPListElement newCPOutputElement(IResource res) {
private CPElement newCPOutputElement(IResource res) {
Assert.isNotNull(res);
return new CPListElement(fCurrCProject, IPathEntry.CDT_OUTPUT, res.getFullPath(), res);
return new CPElement(fCurrCProject, IPathEntry.CDT_OUTPUT, res.getFullPath(), res);
}
/*

View file

@ -46,13 +46,13 @@ public class CPathProjectsEntryPage extends CPathBasePage {
String[] buttonLabels = new String[] { /* 0 */CPathEntryMessages.getString("ProjectsEntryPage.projects.checkall.button"), //$NON-NLS-1$
/* 1 */CPathEntryMessages.getString("ProjectsEntryWorkbookPage.projects.uncheckall.button")}; //$NON-NLS-1$
fProjectsList = new CheckedListDialogField(null, buttonLabels, new CPListLabelProvider());
fProjectsList = new CheckedListDialogField(null, buttonLabels, new CPElementLabelProvider());
fProjectsList.setDialogFieldListener(listener);
fProjectsList.setLabelText(CPathEntryMessages.getString("ProjectsEntryPage.projects.label")); //$NON-NLS-1$
fProjectsList.setCheckAllButtonIndex(0);
fProjectsList.setUncheckAllButtonIndex(1);
fProjectsList.setViewerSorter(new CPListElementSorter());
fProjectsList.setViewerSorter(new CPElementSorter());
fCPathList = cPathList;
}
@ -126,7 +126,7 @@ public class CPathProjectsEntryPage extends CPathBasePage {
// add the projects-cpentries that are already on the C Path
List cpelements = fCPathList.getElements();
for (int i = cpelements.size() - 1; i >= 0; i--) {
CPListElement cpelem = (CPListElement) cpelements.get(i);
CPElement cpelem = (CPElement) cpelements.get(i);
if (isEntryKind(cpelem.getEntryKind())) {
existingProjects.add(cpelem.getResource());
projects.add(cpelem);
@ -137,7 +137,7 @@ public class CPathProjectsEntryPage extends CPathBasePage {
for (int i = 0; i < cprojects.length; i++) {
IProject proj = cprojects[i].getProject();
if (!existingProjects.contains(proj)) {
projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj));
projects.add(new CPElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj));
}
}
} catch (CModelException e) {
@ -155,7 +155,7 @@ public class CPathProjectsEntryPage extends CPathBasePage {
List pelements = fCPathList.getElements();
// backwards, as entries will be deleted
for (int i = pelements.size() - 1; i >= 0; i--) {
CPListElement pe = (CPListElement) pelements.get(i);
CPElement pe = (CPElement) pelements.get(i);
if (isEntryKind(pe.getEntryKind())) {
if (!projelements.remove(pe)) {
pelements.remove(i);

View file

@ -84,11 +84,11 @@ public class CPathSourceEntryPage extends CPathBasePage {
/* 3 = IDX_REMOVE */CPathEntryMessages.getString("SourcePathEntryPage.folders.remove.button") //$NON-NLS-1$
};
fFoldersList = new TreeListDialogField(adapter, buttonLabels, new CPListLabelProvider());
fFoldersList = new TreeListDialogField(adapter, buttonLabels, new CPElementLabelProvider());
fFoldersList.setDialogFieldListener(adapter);
fFoldersList.setLabelText(CPathEntryMessages.getString("SourcePathEntryPage.folders.label")); //$NON-NLS-1$
fFoldersList.setViewerSorter(new CPListElementSorter());
fFoldersList.setViewerSorter(new CPElementSorter());
fFoldersList.enableButton(IDX_EDIT, false);
}
@ -108,8 +108,8 @@ public class CPathSourceEntryPage extends CPathBasePage {
fFoldersList.setElements(folders);
for (int i = 0; i < folders.size(); i++) {
CPListElement cpe = (CPListElement) folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION);
CPElement cpe = (CPElement) folders.get(i);
IPath[] patterns = (IPath[]) cpe.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) {
fFoldersList.expandElement(cpe, 3);
}
@ -129,8 +129,8 @@ public class CPathSourceEntryPage extends CPathBasePage {
// expand
List elements = fFoldersList.getElements();
for (int i = 0; i < elements.size(); i++) {
CPListElement elem = (CPListElement) elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPListElement.EXCLUSION);
CPElement elem = (CPElement) elements.get(i);
IPath[] patterns = (IPath[]) elem.getAttribute(CPElement.EXCLUSION);
if (patterns.length > 0) {
fFoldersList.expandElement(elem, 3);
}
@ -160,21 +160,21 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
public Object[] getChildren(TreeListDialogField field, Object element) {
if (element instanceof CPListElement) {
return ((CPListElement) element).getChildren();
if (element instanceof CPElement) {
return ((CPElement) element).getChildren();
}
return EMPTY_ARR;
}
public Object getParent(TreeListDialogField field, Object element) {
if (element instanceof CPListElementAttribute) {
return ((CPListElementAttribute) element).getParent();
if (element instanceof CPElementAttribute) {
return ((CPElementAttribute) element).getParent();
}
return null;
}
public boolean hasChildren(TreeListDialogField field, Object element) {
return (element instanceof CPListElement);
return (element instanceof CPElement);
}
// ---------- IDialogFieldListener --------
@ -225,20 +225,20 @@ public class CPathSourceEntryPage extends CPathBasePage {
IProject project = fCurrCProject.getProject();
if (project.exists()) {
if (hasFolders(project)) {
CPListElement[] srcentries = openSourceContainerDialog(null);
CPElement[] srcentries = openSourceContainerDialog(null);
if (srcentries != null) {
for (int i = 0; i < srcentries.length; i++) {
elementsToAdd.add(srcentries[i]);
}
}
} else {
CPListElement entry = openNewSourceContainerDialog(null, true);
CPElement entry = openNewSourceContainerDialog(null, true);
if (entry != null) {
elementsToAdd.add(entry);
}
}
} else {
CPListElement entry = openNewSourceContainerDialog(null, false);
CPElement entry = openNewSourceContainerDialog(null, false);
if (entry != null) {
elementsToAdd.add(entry);
}
@ -274,14 +274,14 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
Object elem = selElements.get(0);
if (fFoldersList.getIndexOfElement(elem) != -1) {
editElementEntry((CPListElement) elem);
} else if (elem instanceof CPListElementAttribute) {
editAttributeEntry((CPListElementAttribute) elem);
editElementEntry((CPElement) elem);
} else if (elem instanceof CPElementAttribute) {
editAttributeEntry((CPElementAttribute) elem);
}
}
private void editElementEntry(CPListElement elem) {
CPListElement res = null;
private void editElementEntry(CPElement elem) {
CPElement res = null;
res = openNewSourceContainerDialog(elem, true);
@ -290,13 +290,13 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
}
private void editAttributeEntry(CPListElementAttribute elem) {
private void editAttributeEntry(CPElementAttribute elem) {
String key = elem.getKey();
if (key.equals(CPListElement.EXCLUSION)) {
CPListElement selElement = elem.getParent();
if (key.equals(CPElement.EXCLUSION)) {
CPElement selElement = elem.getParent();
ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement);
if (dialog.open() == Window.OK) {
selElement.setAttribute(CPListElement.EXCLUSION, dialog.getExclusionPattern());
selElement.setAttribute(CPElement.EXCLUSION, dialog.getExclusionPattern());
fFoldersList.refresh();
fCPathList.dialogFieldChanged(); // validate
}
@ -313,10 +313,10 @@ public class CPathSourceEntryPage extends CPathBasePage {
List selElements = fFoldersList.getSelectedElements();
for (int i = selElements.size() - 1; i >= 0; i--) {
Object elem = selElements.get(i);
if (elem instanceof CPListElementAttribute) {
CPListElementAttribute attrib = (CPListElementAttribute) elem;
if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem;
String key = attrib.getKey();
Object value = key.equals(CPListElement.EXCLUSION) ? new Path[0] : null;
Object value = key.equals(CPElement.EXCLUSION) ? new Path[0] : null;
attrib.getParent().setAttribute(key, value);
selElements.remove(i);
}
@ -335,17 +335,17 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
for (int i = 0; i < selElements.size(); i++) {
Object elem = selElements.get(i);
if (elem instanceof CPListElementAttribute) {
CPListElementAttribute attrib = (CPListElementAttribute) elem;
if (attrib.getKey().equals(CPListElement.EXCLUSION)) {
if (elem instanceof CPElementAttribute) {
CPElementAttribute attrib = (CPElementAttribute) elem;
if (attrib.getKey().equals(CPElement.EXCLUSION)) {
if (((IPath[]) attrib.getValue()).length == 0) {
return false;
}
} else if (attrib.getValue() == null) {
return false;
}
} else if (elem instanceof CPListElement) {
CPListElement curr = (CPListElement) elem;
} else if (elem instanceof CPElement) {
CPElement curr = (CPElement) elem;
if (curr.getParentContainer() != null) {
return false;
}
@ -359,10 +359,10 @@ public class CPathSourceEntryPage extends CPathBasePage {
return false;
}
Object elem = selElements.get(0);
if (elem instanceof CPListElement) {
if (elem instanceof CPElement) {
return false;
}
if (elem instanceof CPListElementAttribute) {
if (elem instanceof CPElementAttribute) {
return true;
}
return false;
@ -388,7 +388,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
int lastRemovePos = nEntries;
int afterLastSourcePos = 0;
for (int i = nEntries - 1; i >= 0; i--) {
CPListElement cpe = (CPListElement) cpelements.get(i);
CPElement cpe = (CPElement) cpelements.get(i);
int kind = cpe.getEntryKind();
if (isEntryKind(kind)) {
if (!srcelements.remove(cpe)) {
@ -410,7 +410,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
}
private CPListElement openNewSourceContainerDialog(CPListElement existing, boolean includeLinked) {
private CPElement openNewSourceContainerDialog(CPElement existing, boolean includeLinked) {
if (includeLinked) {
NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject());
if (dialog.open() == Window.OK) {
@ -444,7 +444,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
}
private CPListElement[] openSourceContainerDialog(CPListElement existing) {
private CPElement[] openSourceContainerDialog(CPElement existing) {
Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class};
List existingContainers = getExistingContainers(null);
@ -481,7 +481,7 @@ public class CPathSourceEntryPage extends CPathBasePage {
}
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
CPListElement[] res = new CPListElement[elements.length];
CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = newCPSourceElement(elem);
@ -491,11 +491,11 @@ public class CPathSourceEntryPage extends CPathBasePage {
return null;
}
private List getExistingContainers(CPListElement existing) {
private List getExistingContainers(CPElement existing) {
List res = new ArrayList();
List cplist = fFoldersList.getElements();
for (int i = 0; i < cplist.size(); i++) {
CPListElement elem = (CPListElement) cplist.get(i);
CPElement elem = (CPElement) cplist.get(i);
if (elem != existing) {
IResource resource = elem.getResource();
if (resource instanceof IContainer) { // defensive code
@ -506,9 +506,9 @@ public class CPathSourceEntryPage extends CPathBasePage {
return res;
}
private CPListElement newCPSourceElement(IResource res) {
private CPElement newCPSourceElement(IResource res) {
Assert.isNotNull(res);
return new CPListElement(fCurrCProject, IPathEntry.CDT_SOURCE, res.getFullPath(), res);
return new CPElement(fCurrCProject, IPathEntry.CDT_SOURCE, res.getFullPath(), res);
}
/*

View file

@ -9,27 +9,93 @@
******************************************************************************/
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.IMacroEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Composite;
public class CPathSymbolEntryPage extends ExtendedCPathBasePage {
private static final int IDX_ADD = 0;
private static final int IDX_ADD_CONTRIBUTED = 1;
private static final int IDX_EDIT = 3;
private static final int IDX_REMOVE = 4;
private final static String[] buttonLabel = new String[]{
/* 0 */CPathEntryMessages.getString("SymbolEntryPage.addUser"), //$NON-NLS-1$
/* 1 */CPathEntryMessages.getString("SymbolEntryPage.addContributed"), //$NON-NLS-1$
null, //$NON-NLS-1$
/* 3 */CPathEntryMessages.getString("SymbolEntryPage.edit"), //$NON-NLS-1$
/* 4 */CPathEntryMessages.getString("SymbolEntryPage.remove")}; //$NON-NLS-1$
public CPathSymbolEntryPage(ITreeListAdapter adapter) {
super(adapter, "SymbolEntryPage"); //$NON-NLS-1$
super(adapter, CPathEntryMessages.getString("SymbolEntryPage.title"), //$NON-NLS-1$
CPathEntryMessages.getString("SymbolEntryPage.listName"), buttonLabel); //$NON-NLS-1$
}
protected int getEntryKind() {
return IPathEntry.CDT_MACRO;
protected void buttonPressed(int indx, List selected) {
switch (indx) {
case IDX_ADD :
addSymbol();
break;
case IDX_ADD_CONTRIBUTED :
break;
case IDX_EDIT :
if (canEdit(selected)) {
editSymbol((CPElement) selected.get(0));
}
break;
case IDX_REMOVE :
if (canRemove(selected)) {
removeSymbol((CPElement) selected.get(0));
}
break;
}
}
protected void addPath() {
protected void pathSelectionChanged() {
List selected = getPathList().getSelectedElements();
getPathList().enableButton(IDX_REMOVE, canRemove(selected));
getPathList().enableButton(IDX_EDIT, canEdit(selected));
}
protected boolean canRemove(List selected) {
return !selected.isEmpty();
}
protected boolean canEdit(List selected) {
if (!selected.isEmpty()) {
return !isPathInheritedFromSelected((CPElement) selected.get(0));
}
return false;
}
protected void editSymbol(CPElement element) {
}
protected void removeSymbol(CPElement element) {
removeFromSelectedPath(element);
}
public void createControl(Composite parent) {
super.createControl(parent);
getPathList().enableButton(IDX_REMOVE, false);
getPathList().enableButton(IDX_EDIT, false);
}
public boolean isEntryKind(int kind) {
return IPathEntry.CDT_MACRO == kind;
}
protected void addSymbol() {
// Popup an entry dialog
InputDialog dialog = new InputDialog(getShell(), CPathEntryMessages.getString("SymbolEntryPage.addExternal.title"), //$NON-NLS-1$
CPathEntryMessages.getString("SymbolEntryPage.addExternal.message"), "", //$NON-NLS-1$ //$NON-NLS-2$
@ -38,9 +104,9 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage {
if (dialog.open() == Window.OK) {
symbol = dialog.getValue();
if (symbol != null && symbol.length() > 0) {
List cplist = fPathList.getElements();
CPListElement newPath = newCPElement(((ICElement) getSelection().get(0)).getResource(), null);
List cplist = getPathList().getElements();
IResource resource = ((ICElement) getSelection().get(0)).getResource();
CPElement newPath = new CPElement(fCurrCProject, IPathEntry.CDT_MACRO, resource.getFullPath(), resource);
String name, value = ""; //$NON-NLS-1$
int index = symbol.indexOf("="); //$NON-NLS-1$
if (index != -1) {
@ -49,22 +115,63 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage {
} else {
name = symbol.trim();
}
newPath.setAttribute(CPListElement.MACRO_NAME, name);
newPath.setAttribute(CPListElement.MACRO_VALUE, value);
newPath.setAttribute(CPElement.MACRO_NAME, name);
newPath.setAttribute(CPElement.MACRO_VALUE, value);
if (!cplist.contains(newPath)) {
fPathList.addElement(newPath);
getPathList().addElement(newPath);
fCPathList.add(newPath);
fPathList.postSetSelection(new StructuredSelection(newPath));
getPathList().postSetSelection(new StructuredSelection(newPath));
}
}
}
}
protected CPListElement newCPElement(IResource resource, CPListElement copyFrom) {
CPListElement element = new CPListElement(fCurrCProject, getEntryKind(), resource.getFullPath(), resource);
if (copyFrom != null) {
element.setAttribute(CPListElement.MACRO_NAME, copyFrom.getAttribute(CPListElement.MACRO_NAME));
protected void addContributed() {
CPElement[] includes = openContainerSelectionDialog(null);
if (includes != null) {
int nElementsChosen = includes.length;
// remove duplicates
List cplist = getPathList().getElements();
List elementsToAdd = new ArrayList(nElementsChosen);
for (int i = 0; i < nElementsChosen; i++) {
CPElement curr = includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
}
}
getPathList().addElements(elementsToAdd);
fCPathList.addAll(elementsToAdd);
getPathList().postSetSelection(new StructuredSelection(includes));
}
return element;
}
protected CPElement[] openContainerSelectionDialog(CPElement existing) {
IPathEntry elem = null;
String title;
if (existing == null) {
title = CPathEntryMessages.getString("SymbolEntryPage.ContainerDialog.new.title"); //$NON-NLS-1$
} else {
title = CPathEntryMessages.getString("SymbolEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$
elem = existing.getPathEntry();
}
CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawClasspath(), IPathEntry.CDT_INCLUDE);
wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry parent = wizard.getEntriesParent();
IPathEntry[] elements = wizard.getEntries();
IResource resource = ((ICElement) getSelection().get(0)).getResource();
if (elements != null) {
CPElement[] res = new CPElement[elements.length];
for (int i = 0; i < res.length; i++) {
res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_MACRO, resource.getFullPath(), resource);
res[i].setAttribute(CPElement.MACRO_NAME, ((IMacroEntry)elements[i]).getMacroName());
res[i].setAttribute(CPElement.BASE_REF, parent.getPath());
}
return res;
}
}
return null;
}
}

View file

@ -60,7 +60,7 @@ public class CPathTabBlock extends AbstractPathOptionBlock {
};
BuildPathAdapter adapter = new BuildPathAdapter();
fCPathList = new CheckedListDialogField(null, buttonLabels, new CPListLabelProvider());
fCPathList = new CheckedListDialogField(null, buttonLabels, new CPElementLabelProvider());
fCPathList.setDialogFieldListener(adapter);
fCPathList.setLabelText(CPathEntryMessages.getString("CPathsBlock.path.label")); //$NON-NLS-1$
fCPathList.setUpButtonIndex(0);
@ -107,7 +107,7 @@ public class CPathTabBlock extends AbstractPathOptionBlock {
List exportedEntries = new ArrayList();
for (int i = 0; i < cPaths.size(); i++) {
CPListElement curr = (CPListElement) cPaths.get(i);
CPElement curr = (CPElement) cPaths.get(i);
if (curr.isExported() && curr.getEntryKind() != IPathEntry.CDT_SOURCE) {
exportedEntries.add(curr);
}
@ -140,12 +140,12 @@ public class CPathTabBlock extends AbstractPathOptionBlock {
List elements = fCPathList.getElements();
CPListElement entryMissing = null;
CPElement entryMissing = null;
int nEntriesMissing = 0;
IPathEntry[] entries = new IPathEntry[elements.size()];
for (int i = elements.size() - 1; i >= 0; i--) {
CPListElement currElement = (CPListElement) elements.get(i);
CPElement currElement = (CPElement) elements.get(i);
boolean isChecked = fCPathList.isChecked(currElement);
if (currElement.getEntryKind() == IPathEntry.CDT_SOURCE) {
if (isChecked) {

View file

@ -66,7 +66,7 @@ public class ExclusionPatternDialog extends StatusDialog {
private ListDialogField fExclusionPatternList;
private CPListElement fCurrElement;
private CPElement fCurrElement;
private IProject fCurrProject;
private IContainer fCurrSourceFolder;
@ -77,7 +77,7 @@ public class ExclusionPatternDialog extends StatusDialog {
private static final int IDX_REMOVE= 4;
public ExclusionPatternDialog(Shell parent, CPListElement entryToEdit) {
public ExclusionPatternDialog(Shell parent, CPElement entryToEdit) {
super(parent);
fCurrElement= entryToEdit;
setTitle(CPathEntryMessages.getString("ExclusionPatternDialog.title")); //$NON-NLS-1$
@ -107,7 +107,7 @@ public class ExclusionPatternDialog extends StatusDialog {
fCurrSourceFolder= (IContainer) res;
}
IPath[] pattern= (IPath[]) entryToEdit.getAttribute(CPListElement.EXCLUSION);
IPath[] pattern= (IPath[]) entryToEdit.getAttribute(CPElement.EXCLUSION);
ArrayList elements= new ArrayList(pattern.length);
for (int i= 0; i < pattern.length; i++) {

View file

@ -52,7 +52,7 @@ public class ExclusionPatternEntryDialog extends StatusDialog {
private String fExclusionPattern;
private List fExistingPatterns;
public ExclusionPatternEntryDialog(Shell parent, String patternToEdit, List existingPatterns, CPListElement entryToEdit) {
public ExclusionPatternEntryDialog(Shell parent, String patternToEdit, List existingPatterns, CPElement entryToEdit) {
super(parent);
fExistingPatterns = existingPatterns;
if (patternToEdit == null) {

View file

@ -14,7 +14,6 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -22,8 +21,6 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator;
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.IListAdapter;
@ -33,18 +30,13 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
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.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
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.graphics.Color;
import org.eclipse.swt.graphics.Image;
@ -53,23 +45,14 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
public abstract class ExtendedCPathBasePage extends CPathBasePage {
protected ListDialogField fPathList;
protected TreeListDialogField fSrcList;
protected List fCPathList;
protected ICProject fCurrCProject;
private static final int IDX_ADD = 0;
private static final int IDX_ADD_WORKSPACE = 1;
private static final int IDX_ADD_CONTRIBUTED = 2;
private static final int IDX_EDIT = 4;
private static final int IDX_REMOVE = 5;
private String fPrefix;
private ListDialogField fPathList;
private TreeListDialogField fSrcList;
private class IncludeListAdapter implements IListAdapter, IDialogFieldListener {
@ -77,40 +60,18 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
}
public void customButtonPressed(ListDialogField field, int index) {
switch (index) {
case IDX_ADD:
addPath();
break;
case IDX_ADD_WORKSPACE:
addFromWorkspace();
break;
case IDX_ADD_CONTRIBUTED:
addContributed();
break;
case IDX_EDIT:
if (canEdit(field.getSelectedElements())) {
editPath((CPListElement) field.getSelectedElements().get(0));
}
break;
case IDX_REMOVE:
if (canRemove(field.getSelectedElements())) {
removePath((CPListElement) field.getSelectedElements().get(0));
}
break;
}
buttonPressed(index, field.getSelectedElements());
}
public void selectionChanged(ListDialogField field) {
List selected = fPathList.getSelectedElements();
fPathList.enableButton(IDX_REMOVE, canRemove(selected));
fPathList.enableButton(IDX_EDIT, canEdit(selected));
pathSelectionChanged();
}
public void doubleClicked(ListDialogField field) {
}
}
private class ModifiedCPListLabelProvider extends CPListLabelProvider implements IColorProvider {
private class ModifiedCPListLabelProvider extends CPElementLabelProvider implements IColorProvider {
private final Color inDirect = new Color(Display.getDefault(), new RGB(170, 170, 170));
@ -186,7 +147,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
public Image getImage(Object element) {
Image image = super.getImage(element);
if (isPathInheritedFromSelected((CPListElement) element)) {
if (isPathInheritedFromSelected((CPElement) element)) {
image = new CPListImageDescriptor(image, true).createImage();
}
return image;
@ -197,39 +158,34 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
}
public Color getForeground(Object element) {
if (isPathInheritedFromSelected((CPListElement) element)) {
if (isPathInheritedFromSelected((CPElement) element)) {
return inDirect;
}
return null;
}
}
public ExtendedCPathBasePage(ITreeListAdapter adapter, String prefix) {
super(CPathEntryMessages.getString(prefix + ".title")); //$NON-NLS-1$
fPrefix = prefix;
public ExtendedCPathBasePage(ITreeListAdapter adapter, String title, String pathTitle, String[] buttons) {
super(title);
IncludeListAdapter includeListAdaper = new IncludeListAdapter();
String[] buttonLabel = new String[] { /* 0 */CPathEntryMessages.getString(prefix + ".add"), //$NON-NLS-1$
/* 1 */CPathEntryMessages.getString(prefix + ".addFromWorkspace"), //$NON-NLS-1$
/* 2 */CPathEntryMessages.getString(prefix + ".addContributed"), null, //$NON-NLS-1$
/* 4 */CPathEntryMessages.getString(prefix + ".edit"), //$NON-NLS-1$
/* 5 */CPathEntryMessages.getString(prefix + ".remove")}; //$NON-NLS-1$
fPathList = new ListDialogField(includeListAdaper, buttonLabel, new ModifiedCPListLabelProvider()) {
fPathList = new ListDialogField(includeListAdaper, buttons, new ModifiedCPListLabelProvider()) {
protected int getListStyle() {
return super.getListStyle() & ~SWT.MULTI;
}
};
fPathList.setDialogFieldListener(includeListAdaper);
fPathList.setLabelText(CPathEntryMessages.getString(prefix + ".listName")); //$NON-NLS-1$
fSrcList = new TreeListDialogField(adapter, new String[] { CPathEntryMessages.getString(prefix + ".editSourcePaths")}, //$NON-NLS-1$
fPathList.setLabelText(pathTitle);
fSrcList = new TreeListDialogField(adapter,
null /*new String[]{CPathEntryMessages.getString("ExtendingCPathBasePage.editSourcePaths")}*/, //$NON-NLS-1$
new CElementLabelProvider()) {
protected int getTreeStyle() {
return super.getTreeStyle() & ~SWT.MULTI;
}
};
fSrcList.setLabelText(CPathEntryMessages.getString(prefix + ".sourcePaths")); //$NON-NLS-1$
fSrcList.setLabelText(CPathEntryMessages.getString("ExtendingCPathBasePage.sourcePaths")); //$NON-NLS-1$
}
public void createControl(Composite parent) {
@ -239,24 +195,22 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
setControl(composite);
LayoutUtil.doDefaultLayout(composite, new DialogField[] { fSrcList, fPathList}, true);
LayoutUtil.doDefaultLayout(composite, new DialogField[]{fSrcList, fPathList}, true);
LayoutUtil.setHorizontalGrabbing(fPathList.getListControl(null));
int buttonBarWidth = converter.convertWidthInCharsToPixels(30);
fPathList.setButtonsMinWidth(buttonBarWidth);
fPathList.enableButton(IDX_REMOVE, false);
fPathList.enableButton(IDX_EDIT, false);
}
public boolean isEntryKind(int kind) {
return kind == getEntryKind();
protected ListDialogField getPathList() {
return fPathList;
}
abstract protected void buttonPressed(int indx, List selected);
abstract protected void addPath();
protected abstract void pathSelectionChanged();
abstract int getEntryKind();
protected boolean isPathInheritedFromSelected(CPListElement element) {
protected boolean isPathInheritedFromSelected(CPElement element) {
IPath resPath = element.getPath();
List sel = getSelection();
if (!sel.isEmpty()) {
@ -270,29 +224,15 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
return false;
}
protected boolean canRemove(List selected) {
return !selected.isEmpty();
}
protected boolean canEdit(List selected) {
if( !selected.isEmpty() ) {
return !isPathInheritedFromSelected((CPListElement) selected.get(0));
}
return false;
}
protected void editPath(CPListElement element) {
}
protected void removePath(CPListElement element) {
protected void removeFromSelectedPath(CPElement element) {
ICElement celem = (ICElement) getSelection().get(0);
if (!celem.getPath().equals(element.getPath())) {
IPath exclude = celem.getPath().removeFirstSegments(element.getPath().segmentCount()).addTrailingSeparator();
IPath[] exclusions = (IPath[]) element.getAttribute(CPListElement.EXCLUSION);
IPath[] exclusions = (IPath[]) element.getAttribute(CPElement.EXCLUSION);
IPath[] newExlusions = new IPath[exclusions.length + 1];
System.arraycopy(exclusions, 0, newExlusions, 0, exclusions.length);
newExlusions[exclusions.length] = exclude;
element.setAttribute(CPListElement.EXCLUSION, newExlusions);
element.setAttribute(CPElement.EXCLUSION, newExlusions);
selectionChanged(new StructuredSelection(getSelection()));
} else {
fCPathList.remove(element);
@ -332,7 +272,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
protected IPathEntry[] getRawClasspath() {
IPathEntry[] currEntries = new IPathEntry[fCPathList.size()];
for (int i = 0; i < currEntries.length; i++) {
CPListElement curr = (CPListElement) fCPathList.get(i);
CPElement curr = (CPElement) fCPathList.get(i);
currEntries[i] = curr.getPathEntry();
}
return currEntries;
@ -350,7 +290,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
fPathList.setElements(filterList(getCPaths(), selection));
}
private List filterList(List list, IStructuredSelection selection) {
protected List filterList(List list, IStructuredSelection selection) {
if (selection.isEmpty()) {
return list;
}
@ -360,10 +300,10 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
List newList = new ArrayList(list.size());
Iterator iter = list.iterator();
while (iter.hasNext()) {
CPListElement element = (CPListElement) iter.next();
CPElement element = (CPElement) iter.next();
if (element.getPath().isPrefixOf(resPath)
&& (element.getPath().equals(resPath) || !CoreModelUtil.isExcludedPath(resPath.removeFirstSegments(1),
(IPath[]) element.getAttribute(CPListElement.EXCLUSION)))) {
(IPath[]) element.getAttribute(CPElement.EXCLUSION)))) {
newList.add(element);
}
}
@ -376,179 +316,6 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
public void performDefaults() {
}
protected CPListElement[] openContainerSelectionDialog(CPListElement existing) {
IPathEntry elem = null;
String title;
if (existing == null) {
title = CPathEntryMessages.getString(fPrefix + ".ContainerDialog.new.title"); //$NON-NLS-1$
} else {
title = CPathEntryMessages.getString(fPrefix + ".ContainerDialog.edit.title"); //$NON-NLS-1$
elem = existing.getPathEntry();
}
CPathContainerWizard wizard = new CPathContainerWizard(elem, fCurrCProject, getRawClasspath());
wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry[] elements = wizard.getNewEntries();
if (elements != null) {
CPListElement[] res = new CPListElement[elements.length];
for (int i = 0; i < res.length; i++) {
res[i] = newCPElement(((ICElement) getSelection().get(0)).getResource(), (CPListElement) elements[i]);
res[i].setAttribute(CPListElement.BASE_REF, elements[i].getPath());
}
return res;
}
}
return null;
}
abstract protected CPListElement newCPElement(IResource resource, CPListElement copyFrom);
private class WorkbenchCPathLabelProvider extends CPListLabelProvider {
WorkbenchLabelProvider fWorkbenchLabelProvider = new WorkbenchLabelProvider();
public String getText(Object element) {
if (element instanceof CPListElement) {
return super.getText(element);
}
return fWorkbenchLabelProvider.getText(element);
}
public Image getImage(Object element) {
if (element instanceof CPListElement) {
return super.getImage(element);
}
return fWorkbenchLabelProvider.getImage(element);
}
}
private class WorkbenchCPathContentProvider extends WorkbenchContentProvider {
public Object[] getChildren(Object element) {
if (element instanceof ICProject) {
try {
IPathEntry[] entries = ((ICProject) element).getRawPathEntries();
List list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
if (entries[i].isExported()) {
list.add(CPListElement.createFromExisting(entries[i], (ICProject) element));
}
}
return list.toArray();
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return new Object[0];
}
}
return super.getChildren(element);
}
public boolean hasChildren(Object element) {
if (element instanceof ICProject) {
try {
IPathEntry[] entries = ((ICProject) element).getRawPathEntries();
for (int i = 0; i < entries.length; i++) {
if (entries[i].isExported()) {
return true;
}
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return false;
}
}
return super.hasChildren(element);
}
public Object getParent(Object element) {
if (element instanceof CPListElement) {
return ((CPListElement) element).getCProject().getProject();
}
return super.getParent(element);
}
}
protected CPListElement[] openWorkspacePathEntryDialog(CPListElement existing) {
Class[] acceptedClasses = new Class[] { CPListElement.class};
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, existing == null);
ViewerFilter filter = new CPListElementFilter((CPListElement[]) fPathList.getElements().toArray(new CPListElement[0]),
getEntryKind(), true);
ILabelProvider lp = new WorkbenchCPathLabelProvider();
ITreeContentProvider cp = new WorkbenchCPathContentProvider();
String title = (existing == null) ? CPathEntryMessages.getString(fPrefix + ".fromWorkspaceDialog.new.title") //$NON-NLS-1$
: CPathEntryMessages.getString(fPrefix + ".fromWorkspaceDialog.edit.title"); //$NON-NLS-1$
String message = (existing == null) ? CPathEntryMessages.getString(fPrefix + ".fromWorkspaceDialog.new.description") //$NON-NLS-1$
: NewWizardMessages.getString(fPrefix + ".fromWorkspaceDialog.edit.description"); //$NON-NLS-1$
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
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();
CPListElement[] res = new CPListElement[elements.length];
for (int i = 0; i < res.length; i++) {
res[i] = newCPElement(((ICElement) getSelection().get(0)).getResource(), (CPListElement)elements[i]);
res[i].setAttribute(CPListElement.BASE_REF, ((CPListElement)elements[i]).getCProject().getPath());
}
return res;
}
return null;
}
protected void addContributed() {
CPListElement[] includes = openContainerSelectionDialog(null);
if (includes != null) {
int nElementsChosen = includes.length;
// remove duplicates
List cplist = fPathList.getElements();
List elementsToAdd = new ArrayList(nElementsChosen);
for (int i = 0; i < nElementsChosen; i++) {
CPListElement curr = includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
}
}
fPathList.addElements(elementsToAdd);
fCPathList.addAll(elementsToAdd);
fPathList.postSetSelection(new StructuredSelection(includes));
}
}
protected void addFromWorkspace() {
CPListElement[] includes = openWorkspacePathEntryDialog(null);
if (includes != null) {
int nElementsChosen = includes.length;
// remove duplicates
List cplist = fPathList.getElements();
List elementsToAdd = new ArrayList(nElementsChosen);
for (int i = 0; i < nElementsChosen; i++) {
CPListElement curr = includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
}
}
fPathList.addElements(elementsToAdd);
fCPathList.addAll(elementsToAdd);
fPathList.postSetSelection(new StructuredSelection(elementsToAdd));
}
}
// private IPathEntry[] getUsedPathFiles(CPListElement existing) {
// List res= new ArrayList();
// List cplist= fPathList.getElements();

View file

@ -0,0 +1,20 @@
/*
* Created on Apr 27, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.core.runtime.CoreException;
public interface IContainerDescriptor {
public abstract ICPathContainerPage createPage() throws CoreException;
public abstract String getName();
public abstract boolean canEdit(IPathEntry entry);
}

View file

@ -41,7 +41,7 @@ public class NewSourceFolderDialog extends StatusDialog {
private List fExistingFolders;
private IProject fCurrProject;
public NewSourceFolderDialog(Shell parent, String title, IProject project, List existingFolders, CPListElement entryToEdit) {
public NewSourceFolderDialog(Shell parent, String title, IProject project, List existingFolders, CPElement entryToEdit) {
super(parent);
setTitle(title);

View file

@ -0,0 +1,35 @@
/*
* Created on Apr 27, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.core.runtime.CoreException;
public class ProjectContainerDescriptor implements IContainerDescriptor {
private int fFilterType;
public ProjectContainerDescriptor(int filterType) {
fFilterType = filterType;
}
public ICPathContainerPage createPage() throws CoreException {
return new ProjectContainerPage(fFilterType);
}
public String getName() {
return CPathEntryMessages.getString("ProjectContainer.label"); //$NON-NLS-1$
}
public boolean canEdit(IPathEntry entry) {
return false;
}
}

View file

@ -0,0 +1,149 @@
/*
* Created on Apr 27, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* 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.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.model.WorkbenchContentProvider;
public class ProjectContainerPage extends WizardPage implements ICPathContainerPage {
private int fFilterType;
private CheckboxTableViewer viewer;
private class WorkbenchCPathContentProvider extends WorkbenchContentProvider {
public Object[] getChildren(Object element) {
if (element instanceof ICProject) {
try {
IPathEntry[] entries = ((ICProject) element).getRawPathEntries();
List list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
if (entries[i].isExported()) {
list.add(CPElement.createFromExisting(entries[i], (ICProject) element));
}
}
return list.toArray();
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return new Object[0];
}
}
return super.getChildren(element);
}
public boolean hasChildren(Object element) {
if (element instanceof ICProject) {
try {
IPathEntry[] entries = ((ICProject) element).getRawPathEntries();
for (int i = 0; i < entries.length; i++) {
if (entries[i].isExported()) {
return true;
}
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return false;
}
}
return super.hasChildren(element);
}
public Object getParent(Object element) {
if (element instanceof CPElement) {
return ((CPElement) element).getCProject().getProject();
}
return super.getParent(element);
}
}
protected ProjectContainerPage(int filterType) {
super("projectContainerPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("ProjectContainerPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("ProjectContainerPage.description")); //$NON-NLS-1$
setImageDescriptor(CPluginImages.DESC_WIZBAN_ADD_LIBRARY);
fFilterType = filterType;
}
public void initialize(ICProject project, IPathEntry[] currentEntries) {
}
public boolean finish() {
return false;
}
public IPathEntry[] getContainerEntries() {
return new IPathEntry[0];
}
public void setSelection(IPathEntry containerEntry) {
}
public void createControl(Composite parent) {
// create a composite with standard margins and spacing
Composite container = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
container.setLayout(layout);
Label label = new Label(container, SWT.NULL);
label.setText(CPathEntryMessages.getString("ProjectContainerPage.label")); //$NON-NLS-1$
GridData gd = new GridData();
gd.horizontalSpan = 2;
label.setLayoutData(gd);
viewer =
CheckboxTableViewer.newCheckList(
container,
SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
viewer.setContentProvider(new WorkbenchCPathContentProvider());
viewer.setLabelProvider(new CPElementLabelProvider());
viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
// Prevent user to change checkbox states
viewer.setChecked(event.getElement(), !event.getChecked());
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent e) {
handleSelectionChanged((IStructuredSelection) e.getSelection());
}
});
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 300;
viewer.getTable().setLayoutData(gd);
setControl(container);
}
protected void handleSelectionChanged(IStructuredSelection selection) {
// dinglis-TODO Auto-generated method stub
}
}