diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index 2c05810360c..43f65312244 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -173,7 +173,7 @@ public class CProject extends Openable implements ICProject { for (int i = 0; i < binConfigs.length; i++) { IBinaryFile bin; try { - bin = binConfigs[i].getBinaryParser().getBinary(entry.getPath()); + bin = binConfigs[i].getBinaryParser().getBinary(entry.getFullLibraryPath()); if (bin != null) { if (bin.getType() == IBinaryFile.ARCHIVE) { lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java new file mode 100644 index 00000000000..27ea0aaa47d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java @@ -0,0 +1,101 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +/** + * ArchiveFileFilter + */ +/** + * Viewer filter for archive selection dialogs. + * Archives are files with file extension "a", "dll", "so. + * The filter is not case sensitive. + */ +public class ArchiveFileFilter extends ViewerFilter { + + private static final String[] fgArchiveExtensions= { "a", "so", "dll" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private List fExcludes; + private boolean fRecursive; + + /** + * @param excludedFiles Excluded files will not pass the filter. + * null is allowed if no files should be excluded. + * @param recusive Folders are only shown if, searched recursivly, contain + * an archive + */ + public ArchiveFileFilter(IFile[] excludedFiles, boolean recusive) { + if (excludedFiles != null) { + fExcludes= Arrays.asList(excludedFiles); + } else { + fExcludes= null; + } + fRecursive= recusive; + } + + /* + * @see ViewerFilter#select + */ + public boolean select(Viewer viewer, Object parent, Object element) { + if (element instanceof IFile) { + if (fExcludes != null && fExcludes.contains(element)) { + return false; + } + return isArchivePath(((IFile)element).getFullPath()); + } else if (element instanceof IContainer) { // IProject, IFolder + if (!fRecursive) { + return true; + } + try { + IResource[] resources= ((IContainer)element).members(); + for (int i= 0; i < resources.length; i++) { + // recursive! Only show containers that contain an archive + if (select(viewer, parent, resources[i])) { + return true; + } + } + } catch (CoreException e) { + CUIPlugin.getDefault().log(e.getStatus()); + } + } + return false; + } + + public static boolean isArchivePath(IPath path) { + String ext= path.getFileExtension(); + if (ext != null && ext.length() != 0) { + return isArchiveFileExtension(ext); + } + return false; + } + + public static boolean isArchiveFileExtension(String ext) { + for (int i= 0; i < fgArchiveExtensions.length; i++) { + if (ext.equalsIgnoreCase(fgArchiveExtensions[i])) { + return true; + } + } + return false; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties index 9c216aa0d8d..533f0c69612 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties @@ -159,6 +159,9 @@ LibrariesEntryPage.libraries.addcontriblib.button=Add &Contributed... LibrariesEntryPage.libraries.addworkspacelib.button=Add from Workspace... LibrariesEntryPage.libraries.edit.button=&Edit... +LibrariesEntryPage.ContainerDialog.new.title=Contributed Library Path Selection +LibrariesEntryPage.ContainerDialog.edit.title=Contributed Library Path Selection + LibrariesWorkbookPage.ExistingClassFolderDialog.new.title=Class Folder Selection LibrariesWorkbookPage.ExistingClassFolderDialog.new.description=&Choose class folders to be added to the build path: @@ -241,3 +244,39 @@ NewSourceFolderDialog.error.pathexists=The folder is already in the list. FolderSelectionDialog.button=Create &New Folder... MultipleFolderSelectionDialog.button=Create &New Folder... + +# ------- SourceAttachmentBlock------- + +SourceAttachmentBlock.message=Select the location (folder, JAR or zip) containing the source for ''{0}'': +SourceAttachmentBlock.filename.description=Source attachments for variable entries are defined by variable paths. The first segment of such a path describes a variable name, the rest is an optional path extension. + +SourceAttachmentBlock.filename.label=Lo&cation path: +SourceAttachmentBlock.filename.externalfile.button=External &File... +SourceAttachmentBlock.filename.externalfolder.button=External F&older... +SourceAttachmentBlock.filename.internal.button=&Workspace... + +SourceAttachmentBlock.filename.varlabel=Lo&cation variable path: +SourceAttachmentBlock.filename.variable.button=&Variable... +SourceAttachmentBlock.filename.external.varbutton=&Extension.... + +SourceAttachmentBlock.filename.error.notvalid= The archive path is not a valid path. +SourceAttachmentBlock.filename.error.filenotexists= The path ''{0}'' does not exist. +SourceAttachmentBlock.filename.error.varnotexists= The variable in the location variable path does not exist. +SourceAttachmentBlock.filename.error.deviceinpath= The location variable path must begin with a variable. +SourceAttachmentBlock.filename.warning.varempty= The location variable path is empty. + +SourceAttachmentBlock.intjardialog.title=Source Location Selection +SourceAttachmentBlock.intjardialog.message=&Select folder or JAR/zip archive containing the source: + +SourceAttachmentBlock.extvardialog.title=Variable Extension Selection +SourceAttachmentBlock.extvardialog.description=Select source location: + +SourceAttachmentBlock.extjardialog.text=JAR/ZIP File Selection +SourceAttachmentBlock.extfolderdialog.text=Folder Selection + +SourceAttachmentBlock.putoncpdialog.title=Setting Source Attachment +SourceAttachmentBlock.putoncpdialog.message=Source can only be attached to libraries on the build path.\nDo you want to add the library to the build path? + +SourceAttachmentDialog.title=Source Attachment Configuration +SourceAttachmentDialog.error.title=Error Attaching Source +SourceAttachmentDialog.error.message=An error occurred while associating the source. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java index ab4414b4367..b9dd45e6b6b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java @@ -219,7 +219,7 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage { title = CPathEntryMessages.getString("IncludeEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$ elem = existing.getPathEntry(); } - CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawClasspath(), + CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), IPathEntry.CDT_INCLUDE); wizard.setWindowTitle(title); if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java index ce12fcabe6f..398e4122bb0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java @@ -16,6 +16,7 @@ import java.util.HashSet; import java.util.List; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.util.PixelConverter; @@ -39,6 +40,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ILabelProvider; 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.events.KeyEvent; @@ -177,11 +179,11 @@ public class CPathLibraryEntryPage extends CPathBasePage { } public void doubleClicked(TreeListDialogField field) { - //libraryPageDoubleClicked(field); + libraryPageDoubleClicked(field); } public void keyPressed(TreeListDialogField field, KeyEvent event) { - //libraryPageKeyPressed(field, event); + libraryPageKeyPressed(field, event); } public Object[] getChildren(TreeListDialogField field, Object element) { @@ -205,7 +207,6 @@ public class CPathLibraryEntryPage extends CPathBasePage { // ---------- IDialogFieldListener -------- public void dialogFieldChanged(DialogField field) { - //libaryPageDialogFieldChanged(field); } } @@ -219,7 +220,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { libentries= openExtLibFileDialog(null); break; case IDX_ADD_CONTRIBUTED: /* add variable */ - //libentries= openVariableSelectionDialog(null); + libentries= openContainerSelectionDialog(null); break; case IDX_EDIT: /* edit */ editEntry(); @@ -246,6 +247,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { } fLibrariesList.addElements(elementsToAdd); + fCPathList.addElements(elementsToAdd); if (index == IDX_ADD_LIB) { fLibrariesList.refresh(); } @@ -263,14 +265,14 @@ public class CPathLibraryEntryPage extends CPathBasePage { } } - protected void libaryPageDoubleClicked(TreeListDialogField field) { + protected void libraryPageDoubleClicked(TreeListDialogField field) { List selection= fLibrariesList.getSelectedElements(); if (canEdit(selection)) { editEntry(); } } - protected void libaryPageKeyPressed(TreeListDialogField field, KeyEvent event) { + protected void libraryPageKeyPressed(TreeListDialogField field, KeyEvent event) { if (field == fLibrariesList) { if (event.character == SWT.DEL && event.stateMask == 0) { List selection= field.getSelectedElements(); @@ -295,6 +297,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { fLibrariesList.refresh(); fCPathList.dialogFieldChanged(); // validate } else { + fCPathList.removeElements(selElements); fLibrariesList.removeElements(selElements); } } @@ -336,35 +339,27 @@ public class CPathLibraryEntryPage extends CPathBasePage { } private void editAttributeEntry(CPElementAttribute elem) { - //String key= elem.getKey(); - //if (key.equals(CPElement.SOURCEATTACHMENT)) { - // CPElement selElement= elem.getParent(); - - // IPath containerPath= null; - // boolean applyChanges= false; - // Object parentContainer= selElement.getParentContainer(); - // if (parentContainer instanceof CPElement) { - // containerPath= ((CPElement) parentContainer).getPath(); - // applyChanges= true; - // } - // SourceAttachmentDialog dialog= new SourceAttachmentDialog(getShell(), selElement.getPathEntry(), containerPath, fCurrCProject, applyChanges); - // if (dialog.open() == Window.OK) { - // selElement.setAttribute(CPElement.SOURCEATTACHMENT, dialog.getSourceAttachmentPath()); - // fLibrariesList.refresh(); - // fCPathList.refresh(); // images - // } - //} + String key= elem.getKey(); + if (key.equals(CPElement.SOURCEATTACHMENT)) { + CPElement selElement= elem.getParent(); + ILibraryEntry libEntry = (ILibraryEntry)selElement.getPathEntry(); + SourceAttachmentDialog dialog= new SourceAttachmentDialog(getShell(), libEntry, fCurrCProject, true); + if (dialog.open() == Window.OK) { + selElement.setAttribute(CPElement.SOURCEATTACHMENT, dialog.getSourceAttachmentPath()); + fLibrariesList.refresh(); + fCPathList.refresh(); // images + } + } } private void editElementEntry(CPElement elem) { CPElement[] res= null; - switch (elem.getEntryKind()) { case IPathEntry.CDT_LIBRARY: - IResource resource= elem.getResource(); - if (resource == null) { + IPath p = (IPath)elem.getAttribute(CPElement.LIBRARY); + if (p.isAbsolute()) { res= openExtLibFileDialog(elem); - } else if (resource.getType() == IResource.FILE) { + } else { res= openLibFileDialog(elem); } break; @@ -382,20 +377,20 @@ public class CPathLibraryEntryPage extends CPathBasePage { fLibrariesList.enableButton(IDX_REMOVE, canRemove(selElements)); } - //private IFile[] getUsedLibFiles(CPElement existing) { - // List res= new ArrayList(); - // List cplist= fLibrariesList.getElements(); - // for (int i= 0; i < cplist.size(); i++) { - // CPElement elem= (CPElement)cplist.get(i); - // if (elem.getEntryKind() == IPathEntry.CDT_LIBRARY && (elem != existing)) { - // IResource resource= elem.getResource(); - // if (resource instanceof IFile) { - // res.add(resource); - // } - // } - // } - // return (IFile[]) res.toArray(new IFile[res.size()]); - //} + private IFile[] getUsedLibFiles(CPElement existing) { + List res= new ArrayList(); + List cplist= fLibrariesList.getElements(); + for (int i= 0; i < cplist.size(); i++) { + CPElement elem= (CPElement)cplist.get(i); + if (elem.getEntryKind() == IPathEntry.CDT_LIBRARY && (elem != existing)) { + IResource resource= elem.getResource(); + if (resource instanceof IFile) { + res.add(resource); + } + } + } + return (IFile[]) res.toArray(new IFile[res.size()]); + } private CPElement newCPLibraryElement(IPath libraryPath) { CPElement element = new CPElement(fCurrCProject, IPathEntry.CDT_LIBRARY, fProjPath, null); @@ -435,7 +430,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { private CPElement[] openLibFileDialog(CPElement existing) { Class[] acceptedClasses= new Class[] { IFile.class }; TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, existing == null); - //ViewerFilter filter= new ArchiveFileFilter(getUsedJARFiles(existing), true); + ViewerFilter filter= new ArchiveFileFilter(getUsedLibFiles(existing), true); ILabelProvider lp= new WorkbenchLabelProvider(); ITreeContentProvider cp= new WorkbenchContentProvider(); @@ -447,7 +442,7 @@ public class CPathLibraryEntryPage extends CPathBasePage { dialog.setValidator(validator); dialog.setTitle(title); dialog.setMessage(message); - //dialog.addFilter(filter); + dialog.addFilter(filter); dialog.setInput(fWorkspaceRoot); dialog.setSorter(new ResourceSorter(ResourceSorter.NAME)); if (existing == null) { @@ -467,6 +462,45 @@ public class CPathLibraryEntryPage extends CPathBasePage { } return null; } + + protected IPathEntry[] getRawPathEntries() { + IPathEntry[] currEntries = new IPathEntry[fCPathList.getSize()]; + for (int i = 0; i < currEntries.length; i++) { + CPElement curr = (CPElement) fCPathList.getElement(i); + currEntries[i] = curr.getPathEntry(); + } + return currEntries; + } + + protected CPElement[] openContainerSelectionDialog(CPElement existing) { + IPathEntry elem = null; + String title; + if (existing == null) { + title = CPathEntryMessages.getString("LibrariesEntryPage.ContainerDialog.new.title"); //$NON-NLS-1$ + } else { + title = CPathEntryMessages.getString("LibrariesEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$ + elem = existing.getPathEntry(); + } + CPathContainerWizard wizard = new CPathContainerWizard(elem, null, fCurrCProject, getRawPathEntries(), + IPathEntry.CDT_LIBRARY); + wizard.setWindowTitle(title); + if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { + IPathEntry parent = wizard.getEntriesParent(); + IPathEntry[] elements = wizard.getEntries(); + + if (elements != null) { + CPElement[] res = new CPElement[elements.length]; + for (int i = 0; i < res.length; i++) { + res[i] = new CPElement(fCurrCProject, IPathEntry.CDT_LIBRARY, fProjPath, null); + res[i].setAttribute(CPElement.LIBRARY, ((ILibraryEntry)elements[i]).getLibraryPath()); + res[i].setAttribute(CPElement.BASE_REF, parent.getPath()); + } + return res; + } + } + return null; + } + private boolean canEdit(List selElements) { if (selElements.size() != 1) { return false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java index 247914e1314..e0e3cce5d4e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java @@ -156,7 +156,7 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage { title = CPathEntryMessages.getString("SymbolEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$ elem = existing.getPathEntry(); } - CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawClasspath(), + CPathContainerWizard wizard = new CPathContainerWizard(elem, null, (ICElement)getSelection().get(0), getRawPathEntries(), IPathEntry.CDT_MACRO); wizard.setWindowTitle(title); if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java index 97649dd49dc..90ad879cf7b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java @@ -268,7 +268,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { return fCPathList; } - protected IPathEntry[] getRawClasspath() { + protected IPathEntry[] getRawPathEntries() { IPathEntry[] currEntries = new IPathEntry[fCPathList.size()]; for (int i = 0; i < currEntries.length; i++) { CPElement curr = (CPElement) fCPathList.get(i); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/FolderSelectionDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/FolderSelectionDialog.java new file mode 100644 index 00000000000..90eccc398d0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/FolderSelectionDialog.java @@ -0,0 +1,107 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import org.eclipse.core.resources.IContainer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; + +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.NewFolderDialog; +import org.eclipse.ui.views.navigator.ResourceSorter; + + +/** + */ +public class FolderSelectionDialog extends ElementTreeSelectionDialog implements ISelectionChangedListener { + + private Button fNewFolderButton; + private IContainer fSelectedContainer; + + public FolderSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) { + super(parent, labelProvider, contentProvider); + setSorter(new ResourceSorter(ResourceSorter.NAME)); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite result= (Composite)super.createDialogArea(parent); + + getTreeViewer().addSelectionChangedListener(this); + + Button button = new Button(result, SWT.PUSH); + button.setText(CPathEntryMessages.getString("FolderSelectionDialog.button")); //$NON-NLS-1$ + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + newFolderButtonPressed(); + } + }); + button.setFont(parent.getFont()); + GridData data= new GridData(); + data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); + button.setLayoutData(data); + fNewFolderButton= button; + + applyDialogFont(result); + return result; + } + + private void updateNewFolderButtonState() { + IStructuredSelection selection= (IStructuredSelection) getTreeViewer().getSelection(); + fSelectedContainer= null; + if (selection.size() == 1) { + Object first= selection.getFirstElement(); + if (first instanceof IContainer) { + fSelectedContainer= (IContainer) first; + } + } + fNewFolderButton.setEnabled(fSelectedContainer != null); + } + + protected void newFolderButtonPressed() { + NewFolderDialog dialog= new NewFolderDialog(getShell(), fSelectedContainer); + if (dialog.open() == Window.OK) { + TreeViewer treeViewer= getTreeViewer(); + treeViewer.refresh(fSelectedContainer); + Object createdFolder= dialog.getResult()[0]; + treeViewer.reveal(createdFolder); + treeViewer.setSelection(new StructuredSelection(createdFolder)); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + updateNewFolderButtonState(); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java new file mode 100644 index 00000000000..3439f78407c --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentBlock.java @@ -0,0 +1,483 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ILibraryEntry; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.corext.Assert; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +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.IStringButtonAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +/** + * UI to set the source attachment archive and root. + * Same implementation for both setting attachments for libraries from + * variable entries and for normal (internal or external) jar. + * + * SourceAttachmentBlock + */ +public class SourceAttachmentBlock { + + private IStatusChangeListener fContext; + + private StringButtonDialogField fFileNameField; + private SelectionButtonDialogField fWorkspaceButton; + private SelectionButtonDialogField fExternalFolderButton; + + private IStatus fNameStatus; + + private IWorkspaceRoot fWorkspaceRoot; + + private Control fSWTWidget; + private CLabel fFullPathResolvedLabel; + + private ICProject fProject; + private ILibraryEntry fEntry; + + /** + * @deprecated + */ + public SourceAttachmentBlock(IWorkspaceRoot root, IStatusChangeListener context, ILibraryEntry oldEntry) { + this(context, oldEntry, null); + } + + /** + * @param context listeners for status updates + * @param entry The entry to edit + * @param containerPath Path of the container that contains the given entry or + * null if the entry does not belong to a container. + * @param project Project to which the entry belongs. Can be + * null if getRunnable is not run and the entry + * does not belong to a container. + * + */ + public SourceAttachmentBlock(IStatusChangeListener context, ILibraryEntry entry, ICProject project) { + Assert.isNotNull(entry); + + fContext= context; + fEntry= entry; + fProject= project; + + fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); + + fNameStatus= new StatusInfo(); + + SourceAttachmentAdapter adapter= new SourceAttachmentAdapter(); + + fFileNameField= new StringButtonDialogField(adapter); + fFileNameField.setDialogFieldListener(adapter); + fFileNameField.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.label")); //$NON-NLS-1$ + fFileNameField.setButtonLabel(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfile.button")); //$NON-NLS-1$ + + fWorkspaceButton= new SelectionButtonDialogField(SWT.PUSH); + fWorkspaceButton.setDialogFieldListener(adapter); + fWorkspaceButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.internal.button")); //$NON-NLS-1$ + + fExternalFolderButton= new SelectionButtonDialogField(SWT.PUSH); + fExternalFolderButton.setDialogFieldListener(adapter); + fExternalFolderButton.setLabelText(CPathEntryMessages.getString("SourceAttachmentBlock.filename.externalfolder.button")); //$NON-NLS-1$ + + // set the old settings + setDefaults(); + } + + public void setDefaults() { + if (fEntry.getSourceAttachmentPath() != null) { + fFileNameField.setText(fEntry.getSourceAttachmentPath().toString()); + } else { + fFileNameField.setText(""); //$NON-NLS-1$ + } + } + + /** + * Gets the source attachment path chosen by the user + */ + public IPath getSourceAttachmentPath() { + if (fFileNameField.getText().length() == 0) { + return null; + } + return new Path(fFileNameField.getText()); + } + + /** + * Gets the source attachment root chosen by the user + * Returns null to let JCore automatically detect the root. + */ + public IPath getSourceAttachmentRootPath() { + return null; + } + + /** + * Null for now + * @return + */ + public IPath getSourceAttachmentPrefixMapping() { + return null; + } + + /** + * Creates the control + */ + public Control createControl(Composite parent) { + PixelConverter converter= new PixelConverter(parent); + + fSWTWidget= parent; + + Composite composite= new Composite(parent, SWT.NONE); + + GridLayout layout= new GridLayout(); + layout.marginHeight= 0; + layout.marginWidth= 0; + layout.numColumns= 4; + composite.setLayout(layout); + + int widthHint= converter.convertWidthInCharsToPixels(60); + + GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan= 3; + + Label message= new Label(composite, SWT.LEFT); + message.setLayoutData(gd); + message.setText(CPathEntryMessages.getFormattedString("SourceAttachmentBlock.message", fEntry.getLibraryPath().lastSegment())); //$NON-NLS-1$ + + fWorkspaceButton.doFillIntoGrid(composite, 1); + + // archive name field + fFileNameField.doFillIntoGrid(composite, 4); + LayoutUtil.setWidthHint(fFileNameField.getTextControl(null), widthHint); + LayoutUtil.setHorizontalGrabbing(fFileNameField.getTextControl(null)); + + // aditional 'browse workspace' button for normal jars + DialogField.createEmptySpace(composite, 3); + + fExternalFolderButton.doFillIntoGrid(composite, 1); + + fFileNameField.postSetFocusOnDialogField(parent.getDisplay()); + + Dialog.applyDialogFont(composite); + + //WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.SOURCE_ATTACHMENT_BLOCK); + return composite; + } + + + private class SourceAttachmentAdapter implements IStringButtonAdapter, IDialogFieldListener { + + // -------- IStringButtonAdapter -------- + public void changeControlPressed(DialogField field) { + attachmentChangeControlPressed(field); + } + + // ---------- IDialogFieldListener -------- + public void dialogFieldChanged(DialogField field) { + attachmentDialogFieldChanged(field); + } + } + + private void attachmentChangeControlPressed(DialogField field) { + if (field == fFileNameField) { + IPath jarFilePath= chooseExtJarFile(); + if (jarFilePath != null) { + fFileNameField.setText(jarFilePath.toString()); + } + } + } + + // ---------- IDialogFieldListener -------- + + private void attachmentDialogFieldChanged(DialogField field) { + if (field == fFileNameField) { + fNameStatus= updateFileNameStatus(); + } else if (field == fWorkspaceButton) { + IPath jarFilePath= chooseInternalJarFile(); + if (jarFilePath != null) { + fFileNameField.setText(jarFilePath.toString()); + } + return; + } else if (field == fExternalFolderButton) { + IPath folderPath= chooseExtFolder(); + if (folderPath != null) { + fFileNameField.setText(folderPath.toString()); + } + return; + } + doStatusLineUpdate(); + } + + private void doStatusLineUpdate() { + fFileNameField.enableButton(canBrowseFileName()); + + // set the resolved path for variable jars + if (fFullPathResolvedLabel != null) { + fFullPathResolvedLabel.setText(getResolvedLabelString(fFileNameField.getText(), true)); + } + + IStatus status= StatusUtil.getMostSevere(new IStatus[] { fNameStatus }); + fContext.statusChanged(status); + } + + private boolean canBrowseFileName() { + return true; + } + + private String getResolvedLabelString(String path, boolean osPath) { + IPath resolvedPath= getResolvedPath(new Path(path)); + if (resolvedPath != null) { + if (osPath) { + return resolvedPath.toOSString(); + } else { + return resolvedPath.toString(); + } + } + return ""; //$NON-NLS-1$ + } + + /* + * Do substitution here + */ + private IPath getResolvedPath(IPath path) { + return path; + } + + private IStatus updateFileNameStatus() { + StatusInfo status= new StatusInfo(); + + String fileName= fFileNameField.getText(); + if (fileName.length() == 0) { + // no source attachment + return status; + } else { + if (!Path.EMPTY.isValidPath(fileName)) { + status.setError(CPathEntryMessages.getString("SourceAttachmentBlock.filename.error.notvalid")); //$NON-NLS-1$ + return status; + } + IPath filePath= new Path(fileName); + File file= filePath.toFile(); + IResource res= fWorkspaceRoot.findMember(filePath); + if (res != null && res.getLocation() != null) { + file= res.getLocation().toFile(); + } + if (!file.exists()) { + String message= CPathEntryMessages.getFormattedString("SourceAttachmentBlock.filename.error.filenotexists", filePath.toString()); //$NON-NLS-1$ + status.setError(message); + return status; + } + } + return status; + } + + /* + * Opens a dialog to choose a jar from the file system. + */ + private IPath chooseExtJarFile() { + IPath currPath= new Path(fFileNameField.getText()); + if (currPath.isEmpty()) { + currPath= fEntry.getPath(); + } + + if (ArchiveFileFilter.isArchivePath(currPath)) { + currPath= currPath.removeLastSegments(1); + } + + FileDialog dialog= new FileDialog(getShell()); + dialog.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extjardialog.text")); //$NON-NLS-1$ + dialog.setFilterExtensions(new String[] {"*.jar;*.zip"}); //$NON-NLS-1$ + dialog.setFilterPath(currPath.toOSString()); + String res= dialog.open(); + if (res != null) { + return new Path(res).makeAbsolute(); + } + return null; + } + + private IPath chooseExtFolder() { + IPath currPath= new Path(fFileNameField.getText()); + if (currPath.isEmpty()) { + currPath= fEntry.getPath(); + } + if (ArchiveFileFilter.isArchivePath(currPath)) { + currPath= currPath.removeLastSegments(1); + } + + DirectoryDialog dialog= new DirectoryDialog(getShell()); + dialog.setText(CPathEntryMessages.getString("SourceAttachmentBlock.extfolderdialog.text")); //$NON-NLS-1$ + dialog.setFilterPath(currPath.toOSString()); + String res= dialog.open(); + if (res != null) { + return new Path(res).makeAbsolute(); + } + return null; + } + + + /* + * Opens a dialog to choose an internal jar. + */ + private IPath chooseInternalJarFile() { + String initSelection= fFileNameField.getText(); + + Class[] acceptedClasses= new Class[] { IFolder.class, IFile.class }; + TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, false); + + ViewerFilter filter= new ArchiveFileFilter(null, false); + + ILabelProvider lp= new WorkbenchLabelProvider(); + ITreeContentProvider cp= new WorkbenchContentProvider(); + + IResource initSel= null; + if (initSelection.length() > 0) { + initSel= fWorkspaceRoot.findMember(new Path(initSelection)); + } + if (initSel == null) { + initSel= fWorkspaceRoot.findMember(fEntry.getPath()); + } + + FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp); + dialog.setAllowMultiple(false); + dialog.setValidator(validator); + dialog.addFilter(filter); + dialog.setTitle(CPathEntryMessages.getString("SourceAttachmentBlock.intjardialog.title")); //$NON-NLS-1$ + dialog.setMessage(CPathEntryMessages.getString("SourceAttachmentBlock.intjardialog.message")); //$NON-NLS-1$ + dialog.setInput(fWorkspaceRoot); + dialog.setInitialSelection(initSel); + if (dialog.open() == Window.OK) { + IResource res= (IResource) dialog.getFirstResult(); + return res.getFullPath(); + } + return null; + } + + private Shell getShell() { + if (fSWTWidget != null) { + return fSWTWidget.getShell(); + } + return CUIPlugin.getActiveWorkbenchShell(); + } + + /** + * Creates a runnable that sets the source attachment by modifying the project's classpath. + */ + public IRunnableWithProgress getRunnable(final ICProject jproject, final Shell shell) { + fProject= jproject; + return getRunnable(shell); + } + + /** + * Creates a runnable that sets the source attachment by modifying the + * project's classpath or updating a container. + */ + public IRunnableWithProgress getRunnable(final Shell shell) { + return new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException { + try { + attachSource(shell, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + } + + protected void attachSource(final Shell shell, IProgressMonitor monitor) throws CoreException { + boolean isExported= fEntry.isExported(); + ILibraryEntry newEntry; + newEntry= CoreModel.newLibraryEntry(fEntry.getPath(), fEntry.getBasePath(), fEntry.getLibraryPath(), + getSourceAttachmentPath(), getSourceAttachmentRootPath(), getSourceAttachmentPrefixMapping(), isExported); + updateProjectPathEntry(shell, fProject, newEntry, monitor); + } + + private void updateProjectPathEntry(Shell shell, ICProject cproject, ILibraryEntry newEntry, IProgressMonitor monitor) throws CModelException { + IPathEntry[] oldClasspath= cproject.getRawPathEntries(); + int nEntries= oldClasspath.length; + ArrayList newEntries= new ArrayList(nEntries + 1); + int entryKind= newEntry.getEntryKind(); + IPath jarPath= newEntry.getPath(); + boolean found= false; + for (int i= 0; i < nEntries; i++) { + IPathEntry curr= oldClasspath[i]; + if (curr.getEntryKind() == entryKind && curr.getPath().equals(jarPath)) { + // add modified entry + newEntries.add(newEntry); + found= true; + } else { + newEntries.add(curr); + } + } + if (!found) { + if (newEntry.getSourceAttachmentPath() == null || !putJarOnClasspathDialog(shell)) { + return; + } + // add new + newEntries.add(newEntry); + } + IPathEntry[] newPathEntries= (IPathEntry[]) newEntries.toArray(new IPathEntry[newEntries.size()]); + cproject.setRawPathEntries(newPathEntries, monitor); + } + + private boolean putJarOnClasspathDialog(Shell shell) { + final boolean[] result= new boolean[1]; + shell.getDisplay().syncExec(new Runnable() { + public void run() { + String title= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.title"); //$NON-NLS-1$ + String message= CPathEntryMessages.getString("SourceAttachmentBlock.putoncpdialog.message"); //$NON-NLS-1$ + result[0]= MessageDialog.openQuestion(CUIPlugin.getActiveWorkbenchShell(), title, message); + } + }); + return result[0]; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentDialog.java new file mode 100644 index 00000000000..1e9707cbc4b --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/SourceAttachmentDialog.java @@ -0,0 +1,175 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ILibraryEntry; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +/** + * A dialog to configure the source attachment of a library (library and zip archive). + * + * SourceAttachmentDialog + */ +public class SourceAttachmentDialog extends StatusDialog { + + private SourceAttachmentBlock fSourceAttachmentBlock; + private boolean fApplyChanges; + + /** + * Creates an instance of the SourceAttachmentDialog. After + * open, the edited paths can be access with + * getSourceAttachmentPath and + * getSourceAttachmentRootPath. + * @param parent Parent shell for the dialog + * @param entry The entry to edit + * @param containerPath Path of the container that contains the given entry or + * null if the entry does not belong to a container. + * @param project Project to which the entry belongs. Can be + * null if applyChanges is false and the entry + * does not belong to a container. + * @param applyChanges If set to true, changes are applied on + * OK. If set to false, no changes are commited. When changes are applied, + * classpath entries which are not found on the classpath will be added as + * new libraries. + */ + public SourceAttachmentDialog(Shell parent, ILibraryEntry entry, ICProject project, boolean applyChanges) { + super(parent); + fApplyChanges= applyChanges; + + IStatusChangeListener listener= new IStatusChangeListener() { + public void statusChanged(IStatus status) { + updateStatus(status); + } + }; + fSourceAttachmentBlock= new SourceAttachmentBlock(listener, entry, project); + + setTitle(CPathEntryMessages.getString("SourceAttachmentDialog.title")); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + //WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.SOURCE_ATTACHMENT_DIALOG); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite= (Composite) super.createDialogArea(parent); + + Control inner= createSourceAttachmentControls(composite); + inner.setLayoutData(new GridData(GridData.FILL_BOTH)); + applyDialogFont(composite); + return composite; + } + + /** + * Creates the controls for the source attachment configuration. + */ + protected Control createSourceAttachmentControls(Composite composite) { + return fSourceAttachmentBlock.createControl(composite); + } + + + /** + * Returns the configured source attachment path. + */ + public IPath getSourceAttachmentPath() { + return fSourceAttachmentBlock.getSourceAttachmentPath(); + } + + /** + * Returns the configured source attachment path root. Sonce 2.1 source + * attachment roots are autodetected. The value returned is therefore always + * null. + */ + public IPath getSourceAttachmentRootPath() { + return fSourceAttachmentBlock.getSourceAttachmentRootPath(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + super.okPressed(); + if (fApplyChanges) { + try { + IRunnableWithProgress runnable= getRunnable(); + new ProgressMonitorDialog(getShell()).run(true, true, runnable); + + } catch (InvocationTargetException e) { + String title= CPathEntryMessages.getString("SourceAttachmentDialog.error.title"); //$NON-NLS-1$ + String message= CPathEntryMessages.getString("SourceAttachmentDialog.error.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, getShell(), title, message); + + } catch (InterruptedException e) { + // cancelled + } + } + } + + /** + * Creates the runnable that configures the project with the new source + * attachements. + */ + protected IRunnableWithProgress getRunnable() { + return fSourceAttachmentBlock.getRunnable(getShell()); + } + + /** + * Helper method that tests if an classpath entry can be found in a + * container. null is returned if the entry can not be found + * or if the container does not allows the configuration of source + * attachments + * @param jproject The container's parent project + * @param containerPath The path of the container + * @param libPath The path of the bibrary to be found + * @return IClasspathEntry A classpath entry from the container of + * null if the container can not be modified. + */ + public static IPathEntry getPathEntryToEdit(ICProject jproject, IPath containerPath, IPath libPath) throws CModelException { + //IPathEntryContainer container= CoreModel.getPathEntryContainer(containerPath, jproject); + //PathEntryContainerInitializer initializer= CoreModel.getPathEntryContainerInitializer(containerPath.segment(0)); + //if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) { + // IPathEntry[] entries= container.getPathEntries(); + // for (int i= 0; i < entries.length; i++) { + // IPathEntry curr= entries[i]; + // IPathEntry resolved= CoreModel.getResolvedPathEntry(curr); + // if (resolved != null && libPath.equals(resolved.getPath())) { + // return curr; // return the real entry + // } + // } + //} + return null; // attachment not possible + } + + + +}