mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 21:45:22 +02:00
Work in progress for LibraryEntries.
This commit is contained in:
parent
ab74918aec
commit
190a4343ae
3 changed files with 328 additions and 42 deletions
|
@ -281,8 +281,12 @@ public class CPElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getChildren() {
|
public Object[] getChildren() {
|
||||||
if (fEntryKind == IPathEntry.CDT_OUTPUT || fEntryKind == IPathEntry.CDT_SOURCE) {
|
switch(fEntryKind) {
|
||||||
|
case IPathEntry.CDT_OUTPUT:
|
||||||
|
case IPathEntry.CDT_SOURCE:
|
||||||
return new Object[] { findAttributeElement(EXCLUSION)};
|
return new Object[] { findAttributeElement(EXCLUSION)};
|
||||||
|
case IPathEntry.CDT_LIBRARY:
|
||||||
|
return new Object[] { findAttributeElement(SOURCEATTACHMENT) };
|
||||||
}
|
}
|
||||||
return fChildren.toArray();
|
return fChildren.toArray();
|
||||||
}
|
}
|
||||||
|
@ -335,6 +339,7 @@ public class CPElement {
|
||||||
int hashCode = fPath.hashCode() + fEntryKind;
|
int hashCode = fPath.hashCode() + fEntryKind;
|
||||||
switch (fEntryKind) {
|
switch (fEntryKind) {
|
||||||
case IPathEntry.CDT_LIBRARY:
|
case IPathEntry.CDT_LIBRARY:
|
||||||
|
hashCode = hashCode * HASH_FACTOR + getAttribute(LIBRARY).hashCode();
|
||||||
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
|
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE).hashCode();
|
||||||
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
|
hashCode = hashCode * HASH_FACTOR + getAttribute(BASE_REF).hashCode();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
||||||
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
@ -29,7 +28,7 @@ import org.eclipse.ui.ide.IDE;
|
||||||
class CPElementLabelProvider extends LabelProvider {
|
class CPElementLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
private String fNewLabel, fCreateLabel;
|
private String fNewLabel, fCreateLabel;
|
||||||
private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon, fExtLibIcon, fExtLibWSrcIcon;
|
private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon;
|
||||||
private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage;
|
private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage;
|
||||||
|
|
||||||
private ImageDescriptorRegistry fRegistry;
|
private ImageDescriptorRegistry fRegistry;
|
||||||
|
@ -39,8 +38,8 @@ class CPElementLabelProvider extends LabelProvider {
|
||||||
fCreateLabel = CPathEntryMessages.getString("CPListLabelProvider.willbecreated"); //$NON-NLS-1$
|
fCreateLabel = CPathEntryMessages.getString("CPListLabelProvider.willbecreated"); //$NON-NLS-1$
|
||||||
fRegistry = CUIPlugin.getImageDescriptorRegistry();
|
fRegistry = CUIPlugin.getImageDescriptorRegistry();
|
||||||
|
|
||||||
fExtLibIcon = fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE;
|
fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE;
|
||||||
fExtLibWSrcIcon = fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC;
|
fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC;
|
||||||
fIncludeIcon = CPluginImages.DESC_OBJS_INCLUDES_FOLDER;
|
fIncludeIcon = CPluginImages.DESC_OBJS_INCLUDES_FOLDER;
|
||||||
fMacroIcon = CPluginImages.DESC_OBJS_MACRO;
|
fMacroIcon = CPluginImages.DESC_OBJS_MACRO;
|
||||||
fFolderImage = CPluginImages.DESC_OBJS_SOURCE_ROOT;
|
fFolderImage = CPluginImages.DESC_OBJS_SOURCE_ROOT;
|
||||||
|
@ -104,8 +103,19 @@ class CPElementLabelProvider extends LabelProvider {
|
||||||
public String getCPElementText(CPElement cpentry) {
|
public String getCPElementText(CPElement cpentry) {
|
||||||
IPath path = cpentry.getPath();
|
IPath path = cpentry.getPath();
|
||||||
switch (cpentry.getEntryKind()) {
|
switch (cpentry.getEntryKind()) {
|
||||||
case IPathEntry.CDT_LIBRARY :
|
case IPathEntry.CDT_LIBRARY : {
|
||||||
return path.makeRelative().toString();
|
StringBuffer str = new StringBuffer( ((IPath)cpentry.getAttribute(CPElement.LIBRARY)).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_PROJECT :
|
case IPathEntry.CDT_PROJECT :
|
||||||
return path.lastSegment();
|
return path.lastSegment();
|
||||||
case IPathEntry.CDT_INCLUDE :
|
case IPathEntry.CDT_INCLUDE :
|
||||||
|
@ -193,23 +203,11 @@ class CPElementLabelProvider extends LabelProvider {
|
||||||
return fFolderImage;
|
return fFolderImage;
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_LIBRARY :
|
case IPathEntry.CDT_LIBRARY :
|
||||||
IResource res = cpentry.getResource();
|
|
||||||
IPath path = (IPath)cpentry.getAttribute(CPElement.SOURCEATTACHMENT);
|
IPath path = (IPath)cpentry.getAttribute(CPElement.SOURCEATTACHMENT);
|
||||||
if (res == null) {
|
|
||||||
if (path == null || path.isEmpty()) {
|
|
||||||
return fExtLibIcon;
|
|
||||||
} else {
|
|
||||||
return fExtLibWSrcIcon;
|
|
||||||
}
|
|
||||||
} else if (res instanceof IFile) {
|
|
||||||
if (path == null || path.isEmpty()) {
|
if (path == null || path.isEmpty()) {
|
||||||
return fLibIcon;
|
return fLibIcon;
|
||||||
} else {
|
}
|
||||||
return fLibWSrcIcon;
|
return fLibWSrcIcon;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fFolderImage;
|
|
||||||
}
|
|
||||||
case IPathEntry.CDT_PROJECT :
|
case IPathEntry.CDT_PROJECT :
|
||||||
return fProjectImage;
|
return fProjectImage;
|
||||||
case IPathEntry.CDT_CONTAINER :
|
case IPathEntry.CDT_CONTAINER :
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
|
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IPathEntry;
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
||||||
|
import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
|
||||||
|
@ -25,16 +27,28 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
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.IWorkspaceRoot;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
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.StructuredSelection;
|
||||||
|
import org.eclipse.jface.window.Window;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.KeyEvent;
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.FileDialog;
|
||||||
|
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
|
||||||
|
import org.eclipse.ui.internal.ide.dialogs.ResourceSorter;
|
||||||
|
import org.eclipse.ui.model.WorkbenchContentProvider;
|
||||||
|
import org.eclipse.ui.model.WorkbenchLabelProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CPathLibraryEntryPage
|
* CPathLibraryEntryPage
|
||||||
|
@ -43,13 +57,16 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
|
|
||||||
private ListDialogField fCPathList;
|
private ListDialogField fCPathList;
|
||||||
private ICProject fCurrCProject;
|
private ICProject fCurrCProject;
|
||||||
|
private IPath fProjPath;
|
||||||
private TreeListDialogField fLibrariesList;
|
private TreeListDialogField fLibrariesList;
|
||||||
|
|
||||||
private IWorkspaceRoot fWorkspaceRoot;
|
private IWorkspaceRoot fWorkspaceRoot;
|
||||||
|
|
||||||
private final int IDX_ADD = 0;
|
private final int IDX_ADD_LIBEXT = 0;
|
||||||
private final int IDX_EDIT = 2;
|
private final int IDX_ADD_LIB = 1;
|
||||||
private final int IDX_REMOVE = 3;
|
private final int IDX_ADD_CONTRIBUTED = 2;
|
||||||
|
private final int IDX_EDIT = 4;
|
||||||
|
private final int IDX_REMOVE = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param title
|
* @param title
|
||||||
|
@ -64,8 +81,9 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
LibrariesAdapter adapter = new LibrariesAdapter();
|
LibrariesAdapter adapter = new LibrariesAdapter();
|
||||||
|
|
||||||
String[] buttonLabels= new String[] {
|
String[] buttonLabels= new String[] {
|
||||||
/* IDX_ADDLIB*/ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addworkspacelib.button"), //$NON-NLS-1$
|
/* IDX_ADD_LIBEXT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addextlib.button"), //$NON-NLS-1$
|
||||||
/* IDX_ADDEXT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addextlib.button"), //$NON-NLS-1$
|
/* IDX_ADD_LIB*/ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addworkspacelib.button"), //$NON-NLS-1$
|
||||||
|
/* IDX_ADD_CONTRIBUTED*/ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addcontriblib.button"), //$NON-NLS-1$
|
||||||
/* */ null,
|
/* */ null,
|
||||||
/* IDX_EDIT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.edit.button"), //$NON-NLS-1$
|
/* IDX_EDIT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.edit.button"), //$NON-NLS-1$
|
||||||
/* IDX_REMOVE */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.remove.button") //$NON-NLS-1$
|
/* IDX_REMOVE */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.remove.button") //$NON-NLS-1$
|
||||||
|
@ -85,21 +103,13 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
|
|
||||||
public void init(ICProject cproject) {
|
public void init(ICProject cproject) {
|
||||||
fCurrCProject = cproject;
|
fCurrCProject = cproject;
|
||||||
|
fProjPath = fCurrCProject.getProject().getFullPath();
|
||||||
updateLibrariesList();
|
updateLibrariesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLibrariesList() {
|
private void updateLibrariesList() {
|
||||||
List cpelements = filterList(fCPathList.getElements());
|
List cpelements = filterList(fCPathList.getElements());
|
||||||
List libelements= new ArrayList(cpelements.size());
|
fLibrariesList.setElements(cpelements);
|
||||||
|
|
||||||
int nElements= cpelements.size();
|
|
||||||
for (int i= 0; i < nElements; i++) {
|
|
||||||
CPElement cpe= (CPElement)cpelements.get(i);
|
|
||||||
if (isEntryKind(cpe.getEntryKind())) {
|
|
||||||
libelements.add(cpe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fLibrariesList.setElements(libelements);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -120,7 +130,7 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
* @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#isEntryKind(int)
|
* @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#isEntryKind(int)
|
||||||
*/
|
*/
|
||||||
public boolean isEntryKind(int kind) {
|
public boolean isEntryKind(int kind) {
|
||||||
return kind == IPathEntry.CDT_LIBRARY || kind == IPathEntry.CDT_CONTAINER;
|
return kind == IPathEntry.CDT_LIBRARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -159,11 +169,11 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
|
|
||||||
// -------- IListAdapter --------
|
// -------- IListAdapter --------
|
||||||
public void customButtonPressed(TreeListDialogField field, int index) {
|
public void customButtonPressed(TreeListDialogField field, int index) {
|
||||||
//libraryPageCustomButtonPressed(field, index);
|
libraryPageCustomButtonPressed(field, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectionChanged(TreeListDialogField field) {
|
public void selectionChanged(TreeListDialogField field) {
|
||||||
//libraryPageSelectionChanged(field);
|
libraryPageSelectionChanged(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doubleClicked(TreeListDialogField field) {
|
public void doubleClicked(TreeListDialogField field) {
|
||||||
|
@ -199,4 +209,277 @@ public class CPathLibraryEntryPage extends CPathBasePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void libraryPageCustomButtonPressed(DialogField field, int index) {
|
||||||
|
CPElement[] libentries= null;
|
||||||
|
switch (index) {
|
||||||
|
case IDX_ADD_LIB: /* add jar */
|
||||||
|
libentries= openLibFileDialog(null);
|
||||||
|
break;
|
||||||
|
case IDX_ADD_LIBEXT: /* add external jar */
|
||||||
|
libentries= openExtLibFileDialog(null);
|
||||||
|
break;
|
||||||
|
case IDX_ADD_CONTRIBUTED: /* add variable */
|
||||||
|
//libentries= openVariableSelectionDialog(null);
|
||||||
|
break;
|
||||||
|
case IDX_EDIT: /* edit */
|
||||||
|
editEntry();
|
||||||
|
return;
|
||||||
|
case IDX_REMOVE: /* remove */
|
||||||
|
removeEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (libentries != null) {
|
||||||
|
int nElementsChosen= libentries.length;
|
||||||
|
// remove duplicates
|
||||||
|
List cplist= fLibrariesList.getElements();
|
||||||
|
List elementsToAdd= new ArrayList(nElementsChosen);
|
||||||
|
|
||||||
|
for (int i= 0; i < nElementsChosen; i++) {
|
||||||
|
CPElement curr= libentries[i];
|
||||||
|
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
|
||||||
|
elementsToAdd.add(curr);
|
||||||
|
//curr.setAttribute(CPElement.SOURCEATTACHMENT, BuildPathSupport.guessSourceAttachment(curr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!elementsToAdd.isEmpty()) {
|
||||||
|
askForAddingExclusionPatternsDialog(elementsToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
fLibrariesList.addElements(elementsToAdd);
|
||||||
|
if (index == IDX_ADD_LIB) {
|
||||||
|
fLibrariesList.refresh();
|
||||||
|
}
|
||||||
|
fLibrariesList.postSetSelection(new StructuredSelection(libentries));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void askForAddingExclusionPatternsDialog(List newEntries) {
|
||||||
|
HashSet modified= new HashSet();
|
||||||
|
fixNestingConflicts(newEntries, fCPathList.getElements(), modified);
|
||||||
|
if (!modified.isEmpty()) {
|
||||||
|
String title= CPathEntryMessages.getString("LibrariesWorkbookPage.exclusion_added.title"); //$NON-NLS-1$
|
||||||
|
String message= CPathEntryMessages.getString("LibrariesWorkbookPage.exclusion_added.message"); //$NON-NLS-1$
|
||||||
|
MessageDialog.openInformation(getShell(), title, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void libaryPageDoubleClicked(TreeListDialogField field) {
|
||||||
|
List selection= fLibrariesList.getSelectedElements();
|
||||||
|
if (canEdit(selection)) {
|
||||||
|
editEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void libaryPageKeyPressed(TreeListDialogField field, KeyEvent event) {
|
||||||
|
if (field == fLibrariesList) {
|
||||||
|
if (event.character == SWT.DEL && event.stateMask == 0) {
|
||||||
|
List selection= field.getSelectedElements();
|
||||||
|
if (canRemove(selection)) {
|
||||||
|
removeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeEntry() {
|
||||||
|
List selElements= fLibrariesList.getSelectedElements();
|
||||||
|
for (int i= selElements.size() - 1; i >= 0 ; i--) {
|
||||||
|
Object elem= selElements.get(i);
|
||||||
|
if (elem instanceof CPElementAttribute) {
|
||||||
|
CPElementAttribute attrib= (CPElementAttribute) elem;
|
||||||
|
attrib.getParent().setAttribute(attrib.getKey(), null);
|
||||||
|
selElements.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selElements.isEmpty()) {
|
||||||
|
fLibrariesList.refresh();
|
||||||
|
fCPathList.dialogFieldChanged(); // validate
|
||||||
|
} else {
|
||||||
|
fLibrariesList.removeElements(selElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canRemove(List selElements) {
|
||||||
|
if (selElements.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i= 0; i < selElements.size(); i++) {
|
||||||
|
Object elem= selElements.get(i);
|
||||||
|
if (elem instanceof CPElementAttribute) {
|
||||||
|
if (((CPElementAttribute)elem).getValue() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (elem instanceof CPElement) {
|
||||||
|
CPElement curr= (CPElement) elem;
|
||||||
|
if (curr.getParentContainer() != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method editEntry.
|
||||||
|
*/
|
||||||
|
private void editEntry() {
|
||||||
|
List selElements= fLibrariesList.getSelectedElements();
|
||||||
|
if (selElements.size() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object elem= selElements.get(0);
|
||||||
|
if (fLibrariesList.getIndexOfElement(elem) != -1) {
|
||||||
|
editElementEntry((CPElement) elem);
|
||||||
|
} else if (elem instanceof CPElementAttribute) {
|
||||||
|
editAttributeEntry((CPElementAttribute) elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editElementEntry(CPElement elem) {
|
||||||
|
CPElement[] res= null;
|
||||||
|
|
||||||
|
switch (elem.getEntryKind()) {
|
||||||
|
case IPathEntry.CDT_LIBRARY:
|
||||||
|
IResource resource= elem.getResource();
|
||||||
|
if (resource == null) {
|
||||||
|
res= openExtLibFileDialog(elem);
|
||||||
|
} else if (resource.getType() == IResource.FILE) {
|
||||||
|
res= openLibFileDialog(elem);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (res != null && res.length > 0) {
|
||||||
|
CPElement curr= res[0];
|
||||||
|
curr.setExported(elem.isExported());
|
||||||
|
fLibrariesList.replaceElement(elem, curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void libraryPageSelectionChanged(DialogField field) {
|
||||||
|
List selElements= fLibrariesList.getSelectedElements();
|
||||||
|
fLibrariesList.enableButton(IDX_EDIT, canEdit(selElements));
|
||||||
|
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 CPElement newCPLibraryElement(IPath libraryPath) {
|
||||||
|
CPElement element = new CPElement(fCurrCProject, IPathEntry.CDT_LIBRARY, fProjPath, null);
|
||||||
|
element.setAttribute(CPElement.LIBRARY, libraryPath);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CPElement[] openExtLibFileDialog(CPElement existing) {
|
||||||
|
String title= CPathEntryMessages.getString("LibrariesWorkbookPage.ExtLibDialog.new.title"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
FileDialog dialog= new FileDialog(getShell(), existing == null ? SWT.MULTI : SWT.SINGLE);
|
||||||
|
dialog.setText(title);
|
||||||
|
dialog.setFilterExtensions(new String[] {"*.a;*.so;*.dll"}); //$NON-NLS-1$
|
||||||
|
//dialog.setFilterPath(lastUsedPath);
|
||||||
|
if (existing != null) {
|
||||||
|
dialog.setFileName(existing.getPath().lastSegment());
|
||||||
|
}
|
||||||
|
|
||||||
|
String res= dialog.open();
|
||||||
|
if (res == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String[] fileNames= dialog.getFileNames();
|
||||||
|
int nChosen= fileNames.length;
|
||||||
|
|
||||||
|
IPath filterPath= new Path(dialog.getFilterPath());
|
||||||
|
CPElement[] elems= new CPElement[nChosen];
|
||||||
|
for (int i= 0; i < nChosen; i++) {
|
||||||
|
IPath path= filterPath.append(fileNames[i]).makeAbsolute();
|
||||||
|
elems[i]= newCPLibraryElement(path);
|
||||||
|
}
|
||||||
|
//fDialogSettings.put(IUIConstants.DIALOGSTORE_LASTEXTJAR, filterPath.toOSString());
|
||||||
|
|
||||||
|
return elems;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
ILabelProvider lp= new WorkbenchLabelProvider();
|
||||||
|
ITreeContentProvider cp= new WorkbenchContentProvider();
|
||||||
|
|
||||||
|
String title= (existing == null) ? CPathEntryMessages.getString("LibrariesWorkbookPage.JARArchiveDialog.new.title") : CPathEntryMessages.getString("LibrariesWorkbookPage.JARArchiveDialog.edit.title"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
String message= (existing == null) ? CPathEntryMessages.getString("LibrariesWorkbookPage.JARArchiveDialog.new.description") : CPathEntryMessages.getString("LibrariesWorkbookPage.JARArchiveDialog.edit.description"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp);
|
||||||
|
dialog.setValidator(validator);
|
||||||
|
dialog.setTitle(title);
|
||||||
|
dialog.setMessage(message);
|
||||||
|
//dialog.addFilter(filter);
|
||||||
|
dialog.setInput(fWorkspaceRoot);
|
||||||
|
dialog.setSorter(new ResourceSorter(ResourceSorter.NAME));
|
||||||
|
if (existing == null) {
|
||||||
|
dialog.setInitialSelection(fCurrCProject.getProject());
|
||||||
|
} else {
|
||||||
|
dialog.setInitialSelection(existing.getResource());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialog.open() == Window.OK) {
|
||||||
|
Object[] elements= dialog.getResult();
|
||||||
|
CPElement[] res= new CPElement[elements.length];
|
||||||
|
for (int i= 0; i < res.length; i++) {
|
||||||
|
IPath path= ((IResource)elements[i]).getLocation();
|
||||||
|
res[i]= newCPLibraryElement(path);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private boolean canEdit(List selElements) {
|
||||||
|
if (selElements.size() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Object elem= selElements.get(0);
|
||||||
|
if (elem instanceof CPElement) {
|
||||||
|
CPElement curr= (CPElement) elem;
|
||||||
|
return !(curr.getResource() instanceof IFolder) && curr.getParentContainer() == null;
|
||||||
|
}
|
||||||
|
if (elem instanceof CPElementAttribute) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue