From 87b6836f3ac66c2daf3e5a3e9bf88c6619bd48f2 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 4 May 2004 04:14:43 +0000 Subject: [PATCH] Work for Library entries.. In Progress --- .../cpaths/CPElementLabelProvider.java | 7 +- .../cpaths/CPathEntryMessages.properties | 2 + .../dialogs/cpaths/CPathLibraryEntryPage.java | 203 ++++++++++++++++++ .../ui/dialogs/cpaths/CPathTabBlock.java | 8 +- 4 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java index 83c4a6dee51..686f3953e06 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPElementLabelProvider.java @@ -39,8 +39,8 @@ class CPElementLabelProvider extends LabelProvider { fCreateLabel = CPathEntryMessages.getString("CPListLabelProvider.willbecreated"); //$NON-NLS-1$ fRegistry = CUIPlugin.getImageDescriptorRegistry(); - fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE; - fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC; + fExtLibIcon = fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE; + fExtLibWSrcIcon = fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC; fIncludeIcon = CPluginImages.DESC_OBJS_INCLUDES_FOLDER; fMacroIcon = CPluginImages.DESC_OBJS_MACRO; fFolderImage = CPluginImages.DESC_OBJS_SOURCE_ROOT; @@ -238,8 +238,7 @@ class CPElementLabelProvider extends LabelProvider { } else if (element instanceof CPElementAttribute) { String key = ((CPElementAttribute)element).getKey(); if (key.equals(CPElement.SOURCEATTACHMENT)) { - // return - // fRegistry.get(CPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); + return fRegistry.get(CPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); } else if (key.equals(CPElement.EXCLUSION)) { return CPluginImages.get(CPluginImages.IMG_OBJS_EXCLUDSION_FILTER_ATTRIB); } 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 f3157dcd624..9c216aa0d8d 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 @@ -149,6 +149,8 @@ ProjectsEntryPage.projects.checkall.button=Select &All ProjectsEntryWorkbookPage.projects.uncheckall.button=&Deselect All # ------- LibrariesWorkbookPage------- +LibrariesEntryPage.title=&Libraries +LibrariesEntryPage.description= LibrariesEntryPage.libraries.label=Libraries on the build path: LibrariesEntryPage.libraries.remove.button=&Remove 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 new file mode 100644 index 00000000000..685cc198876 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathLibraryEntryPage.java @@ -0,0 +1,203 @@ +/********************************************************************** + * 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.ArrayList; +import java.util.List; + +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.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; + +/** + * CPathLibraryEntryPage + */ +public class CPathLibraryEntryPage extends CPathBasePage { + + private ListDialogField fCPathList; + private ICProject fCurrCProject; + private TreeListDialogField fLibrariesList; + + private IWorkspaceRoot fWorkspaceRoot; + + private final int IDX_ADD = 0; + private final int IDX_EDIT = 2; + private final int IDX_REMOVE = 3; + + /** + * @param title + */ + public CPathLibraryEntryPage(ListDialogField cPathList) { + super(CPathEntryMessages.getString("LibrariesEntryPage.title")); //$NON-NLS-1$ + setDescription(CPathEntryMessages.getString("LibrariesEntryPage.description")); //$NON-NLS-1$ + + fWorkspaceRoot = CUIPlugin.getWorkspace().getRoot(); + fCPathList = cPathList; + + LibrariesAdapter adapter = new LibrariesAdapter(); + + String[] buttonLabels= new String[] { + /* IDX_ADDLIB*/ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addworkspacelib.button"), //$NON-NLS-1$ + /* IDX_ADDEXT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.addextlib.button"), //$NON-NLS-1$ + /* */ null, + /* IDX_EDIT */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.edit.button"), //$NON-NLS-1$ + /* IDX_REMOVE */ CPathEntryMessages.getString("LibrariesEntryPage.libraries.remove.button") //$NON-NLS-1$ + }; + + fLibrariesList = new TreeListDialogField(adapter, buttonLabels, new CPElementLabelProvider()); + fLibrariesList.setDialogFieldListener(adapter); + fLibrariesList.setLabelText(CPathEntryMessages.getString("LibrariesEntryPage.libraries.label")); //$NON-NLS-1$ + + fLibrariesList.setViewerSorter(new CPElementSorter()); + fLibrariesList.enableButton(IDX_EDIT, false); + } + + public Image getImage() { + return CPluginImages.get(CPluginImages.IMG_OBJS_ARCHIVE); + } + + public void init(ICProject cproject) { + fCurrCProject = cproject; + updateLibrariesList(); + } + + private void updateLibrariesList() { + //List cpelements= fLibrariesList.getElements(); + List cpelements = filterList(fCPathList.getElements()); + List libelements= new ArrayList(cpelements.size()); + + 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) + * @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#getSelection() + */ + public List getSelection() { + return fLibrariesList.getSelectedElements(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#setSelection(java.util.List) + */ + public void setSelection(List selElements) { + fLibrariesList.selectElements(new StructuredSelection(selElements)); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathBasePage#isEntryKind(int) + */ + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_LIBRARY || kind == IPathEntry.CDT_CONTAINER; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() + */ + public void performDefaults() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + Composite composite = new Composite(parent, SWT.NONE); + + LayoutUtil.doDefaultLayout(composite, new DialogField[] {fLibrariesList}, true); + LayoutUtil.setHorizontalGrabbing(fLibrariesList.getTreeControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fLibrariesList.setButtonsMinWidth(buttonBarWidth); + + fLibrariesList.getTreeViewer().setSorter(new CPElementSorter()); + + setControl(composite); + } + + private class LibrariesAdapter implements IDialogFieldListener, ITreeListAdapter { + + private final Object[] EMPTY_ARR= new Object[0]; + + // -------- IListAdapter -------- + public void customButtonPressed(TreeListDialogField field, int index) { + //libraryPageCustomButtonPressed(field, index); + } + + public void selectionChanged(TreeListDialogField field) { + //libraryPageSelectionChanged(field); + } + + public void doubleClicked(TreeListDialogField field) { + //libraryPageDoubleClicked(field); + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + //libraryPageKeyPressed(field, event); + } + + public Object[] getChildren(TreeListDialogField field, Object element) { + if (element instanceof CPElement) { + return ((CPElement) element).getChildren(); + } + return EMPTY_ARR; + } + + public Object getParent(TreeListDialogField field, Object element) { + if (element instanceof CPElementAttribute) { + return ((CPElementAttribute) element).getParent(); + } + return null; + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + return (element instanceof CPElement); + } + + // ---------- IDialogFieldListener -------- + + public void dialogFieldChanged(DialogField field) { + //libaryPageDialogFieldChanged(field); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java index 45e4e059192..77e5519357e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java @@ -31,7 +31,7 @@ public class CPathTabBlock extends AbstractPathOptionBlock { private CPathProjectsEntryPage fProjectsPage; private CPathOutputEntryPage fOutputPage; private CPathContainerEntryPage fContainerPage; - //private LibrariesWorkbookPage fLibrariesPage; + private CPathLibraryEntryPage fLibrariesPage; private CPathOrderExportPage fOrderExportPage; @@ -82,6 +82,8 @@ public class CPathTabBlock extends AbstractPathOptionBlock { addPage(fOutputPage); fProjectsPage = new CPathProjectsEntryPage(fCPathList); addPage(fProjectsPage); + fLibrariesPage = new CPathLibraryEntryPage(fCPathList); + addPage(fLibrariesPage); fContainerPage = new CPathContainerEntryPage(fCPathList); addPage(fContainerPage); fOrderExportPage = new CPathOrderExportPage(fCPathList); @@ -100,7 +102,7 @@ public class CPathTabBlock extends AbstractPathOptionBlock { fOutputPage.init(getCProject()); fProjectsPage.init(getCProject()); fContainerPage.init(getCProject()); - //fLibrariesPage.init(fCurrCProject); + fLibrariesPage.init(getCProject()); } Dialog.applyDialogFont(control); return control; @@ -125,7 +127,7 @@ public class CPathTabBlock extends AbstractPathOptionBlock { fOutputPage.init(getCProject()); fProjectsPage.init(getCProject()); fContainerPage.init(getCProject()); - // fLibrariesPage.init(fCurrCProject); + fLibrariesPage.init(getCProject()); } doStatusLineUpdate();