diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 2229d180947..23eb0fff660 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,13 @@ +2004-04-07 David Inglis + + Begining of new Include/Symbols UI pages. + + * src/org/eclipse/cdt/internal/dialogs/cpaths/*.java + + Changes here due to refactor + + * src/org/eclipse/cdt/internal/ui/preferences/ + 2004-04-05 Alain Magloire From Chris Wiebe This patch cleans up the layout of the checkboxes on the Open Type dialog. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java new file mode 100644 index 00000000000..8402315291e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java @@ -0,0 +1,224 @@ +/******************************************************************************* + * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. 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.ICModelStatus; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.core.model.CModelStatus; +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.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.ui.dialogs.ICOptionPage; +import org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Preferences; + + +abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock implements ICOptionContainer { + + private StatusInfo fCPathStatus; + private StatusInfo fBuildPathStatus; + + private ICProject fCurrCProject; + + private String fUserSettingsTimeStamp; + private long fFileTimeStamp; + + private int fPageIndex, fPageCount; + private CPathBasePage fCurrPage; + + private IStatusChangeListener fContext; + + public AbstractPathOptionBlock(IStatusChangeListener context, int pageToShow) { + super(false); + + fContext = context; + fPageIndex = pageToShow; + + fCPathStatus = new StatusInfo(); + fBuildPathStatus = new StatusInfo(); + + setOptionContainer(this); + + } + + // -------- public api -------- + + /** + * @return Returns the current class path (raw). Note that the entries + * returned must not be valid. + */ + public IPathEntry[] getRawCPath() { + List elements = getCPaths(); + int nElements = elements.size(); + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = 0; i < nElements; i++) { + CPListElement currElement = (CPListElement) elements.get(i); + entries[i] = currElement.getPathEntry(); + } + return entries; + } + + protected ArrayList getExistingEntries(IPathEntry[] cPathEntries) { + ArrayList newCPath = new ArrayList(); + for (int i = 0; i < cPathEntries.length; i++) { + IPathEntry curr = cPathEntries[i]; + newCPath.add(CPListElement.createFromExisting(curr, fCurrCProject)); + } + return newCPath; + } + + abstract protected List getCPaths(); + + private String getEncodedSettings() { + StringBuffer buf = new StringBuffer(); + + int nElements = getCPaths().size(); + buf.append('[').append(nElements).append(']'); + for (int i = 0; i < nElements; i++) { + CPListElement elem = (CPListElement) getCPaths().get(i); + elem.appendEncodedSettings(buf); + } + return buf.toString(); + } + + public boolean hasChangesInDialog() { + String currSettings = getEncodedSettings(); + return !currSettings.equals(fUserSettingsTimeStamp); + } + + public boolean hasChangesInCPathFile() { + IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ + return fFileTimeStamp != file.getModificationStamp(); + } + + public void initializeTimeStamps() { + IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ + fFileTimeStamp = file.getModificationStamp(); + fUserSettingsTimeStamp = getEncodedSettings(); + } + + abstract protected void addTabs(); + + protected void setCProject(ICProject project) { + fCurrCProject = project; + } + + protected ICProject getCProject() { + return fCurrCProject; + } + + public IProject getProject() { + return fCurrCProject.getProject(); + } + + protected void doStatusLineUpdate() { + IStatus res = findMostSevereStatus(); + fContext.statusChanged(res); + } + + private IStatus findMostSevereStatus() { + return StatusUtil.getMostSevere(new IStatus[] { fCPathStatus, fBuildPathStatus}); + } + + protected StatusInfo getPathStatus() { + return fCPathStatus; + } + + // -------- tab switching ---------- + + public void setCurrentPage(ICOptionPage page) { + super.setCurrentPage(page); + CPathBasePage newPage = (CPathBasePage) page; + if (fCurrPage != null) { + List selection = fCurrPage.getSelection(); + if (!selection.isEmpty()) { + newPage.setSelection(selection); + } + } + fCurrPage = (CPathBasePage) page; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#updateContainer() + */ + public void updateContainer() { + update(); + } + + protected void updateBuildPathStatus() { + List elements = getCPaths(); + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = elements.size() - 1; i >= 0; i--) { + CPListElement currElement = (CPListElement) elements.get(i); + entries[i] = currElement.getPathEntry(); + } + + ICModelStatus status = CModelStatus.VERIFIED_OK; // CoreModelUtil.validateCPathEntries(fCurrCProject, entries); + if (!status.isOK()) { + fBuildPathStatus.setError(status.getMessage()); + return; + } + fBuildPathStatus.setOK(); + } + + public Preferences getPreferences() { + return null; + } + + protected void addPage(CPathBasePage page) { + addTab(page); + if (fPageIndex == fPageCount) { + fCurrPage = page; + } + fPageCount++; + } + + protected ICOptionPage getStartPage() { + if (fCurrPage == null) { + return super.getStartPage(); + } + return fCurrPage; + } + + abstract protected void internalConfigureCProject(List cPathEntries, IProgressMonitor monitor) throws CoreException, InterruptedException; + + // -------- creation ------------------------------- + + public void configureCProject(IProgressMonitor monitor) throws CoreException, InterruptedException { + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + monitor.setTaskName(CPathEntryMessages.getString("CPathsBlock.operationdesc_c")); //$NON-NLS-1$ + monitor.beginTask("", 10); //$NON-NLS-1$ + + try { + internalConfigureCProject(getCPaths(), monitor); + initializeTimeStamps(); + } finally { + monitor.done(); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java index 825483ae27c..cfa4f099539 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java @@ -8,24 +8,17 @@ ******************************************************************************/ package org.eclipse.cdt.internal.ui.dialogs.cpaths; -import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.resource.ImageDescriptor; public abstract class CPathBasePage extends AbstractCOptionPage { - public abstract List getSelection(); - - public abstract void setSelection(List selection); - - public abstract boolean isEntryKind(int kind); - public CPathBasePage(String title) { super(title); } @@ -33,20 +26,6 @@ public abstract class CPathBasePage extends AbstractCOptionPage { super(title, image); } - protected void filterAndSetSelection(List list) { - ArrayList res = new ArrayList(list.size()); - for (int i = list.size() - 1; i >= 0; i--) { - Object curr = list.get(i); - if (curr instanceof CPListElement) { - CPListElement elem = (CPListElement) curr; - if (elem.getParentContainer() == null && isEntryKind(elem.getEntryKind())) { - res.add(curr); - } - } - } - setSelection(res); - } - protected void fixNestingConflicts(List newEntries, List existing, Set modifiedSourceEntries) { for (int i = 0; i < newEntries.size(); i++) { CPListElement curr = (CPListElement) newEntries.get(i); @@ -74,4 +53,10 @@ public abstract class CPathBasePage extends AbstractCOptionPage { } } } + public abstract List getSelection(); + + public abstract void setSelection(List selection); + + public abstract boolean isEntryKind(int kind); + } 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 dd80fb047ce..1028b8a1390 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 @@ -20,17 +20,34 @@ CPathsPropertyPage.unsavedchanges.button.ignore=Apply Later BuildPathsBlock.tab.libraries=&Libraries -# ------- BuildPathsBlock ------- +# -------- SymbolsEntryPage --------- +SymbolEntryPage.title=Symbols +SymbolEntryPage.add=Add... +SymbolEntryPage.addFromProject=Add from project... +SymbolEntryPage.addContributed=Add contributed... +SymbolEntryPage.remove=Remove +SymbolEntryPage.defines=Defines: +SymbolEntryPage.editSourcePaths=Edit source paths... +SymbolEntryPage.sourcePath=Source Paths: +# ------- IncludeEntryPage ---------- +IncludeEntryPage.title=Include Paths +IncludeEntryPage.addFromWorksapce=Add from Workspace... +IncludeEntryPage.addExternal=Add External... +IncludeEntryPage.addContributed=Add Contributed... +IncludeEntryPage.remove=Remove +IncludeEntryPage.includePath=Include Paths: +IncludeEntryPage.editSourcePaths=Edit source paths... +IncludeEntryPage.sourcePaths=Source Paths: + +# ------- BuildPathsBlock ------- CPathsBlock.path.up.button=&Up CPathsBlock.path.down.button=&Down CPathsBlock.path.checkall.button=Select &All 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} build path entries are missing. - CPathsBlock.operationdesc_project=Creating project... CPathsBlock.operationdesc_c=Setting build paths... @@ -136,16 +153,18 @@ LibrariesWorkbookPage.AdvancedDialog.createfolder=Create &New Class Folder LibrariesWorkbookPage.AdvancedDialog.addfolder=Add &Existing Class Folder LibrariesWorkbookPage.AdvancedDialog.addcontainer=Add &Container: +# -------- OrderExportPage --------- +OrderExportsPage.title=&Order and Export +OrderExportsPage.description= + # ------- ExclusionPatternDialog ------- ExclusionPatternDialog.title=Source Folder Exclusion Patterns - ExclusionPatternDialog.pattern.label=E&xclusion patterns for ''{0}'': ExclusionPatternDialog.pattern.add=A&dd... ExclusionPatternDialog.pattern.add.multiple=Add &Multiple... ExclusionPatternDialog.pattern.remove=&Remove ExclusionPatternDialog.pattern.edit=&Edit... - ExclusionPatternDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection ExclusionPatternDialog.ChooseExclusionPattern.description=&Choose folders or files to exclude: @@ -154,36 +173,14 @@ ExclusionPatternDialog.ChooseExclusionPattern.description=&Choose folders or fil ExclusionPatternEntryDialog.add.title=Add Exclusion Pattern ExclusionPatternEntryDialog.edit.title=Edit Exclusion Pattern ExclusionPatternEntryDialog.description=Enter a pattern for excluding files from the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'java/util/A*.java', 'java/util/', '**/Test*'. - ExclusionPatternEntryDialog.pattern.label=E&xclusion pattern (Path relative to ''{0}''): ExclusionPatternEntryDialog.pattern.button=Bro&wse... - ExclusionPatternEntryDialog.error.empty=Enter a pattern. ExclusionPatternEntryDialog.error.notrelative=Pattern must be a relative path. ExclusionPatternEntryDialog.error.exists=Pattern already exists. - ExclusionPatternEntryDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection ExclusionPatternEntryDialog.ChooseExclusionPattern.description=&Choose a folder or file to exclude: -OrderExportsPage.title=&Order and Export -OrderExportsPage.description= -# ------- ClasspathContainerDefaultPage------- - -ClasspathContainerDefaultPage.title=Classpath Container -ClasspathContainerDefaultPage.description=Select classpath container path. First segment is the container type. - -ClasspathContainerDefaultPage.path.label=&Classpath container path: - -ClasspathContainerDefaultPage.path.error.enterpath=Enter path. -ClasspathContainerDefaultPage.path.error.invalidpath=Invalid path. -ClasspathContainerDefaultPage.path.error.needssegment=Path needs at least one segment. -ClasspathContainerDefaultPage.path.error.alreadyexists=Entry already exists. - -# ------- ClasspathContainerSelectionPage------- - -ClasspathContainerSelectionPage.title=Add Library -ClasspathContainerSelectionPage.description=Select the library type to add. - # ------- CPListLabelProvider ------- CPListLabelProvider.new=(new) 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 new file mode 100644 index 00000000000..8c68e86be80 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. 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.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +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.IListAdapter; +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.CElementLabelProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +public class CPathIncludeEntryPage extends CPathBasePage { + + private ListDialogField fIncludeList; + private TreeListDialogField fSrcList; + + private class IncludeListAdapter implements IListAdapter, IDialogFieldListener { + + public void dialogFieldChanged(DialogField field) { + } + + public void customButtonPressed(ListDialogField field, int index) { + } + + public void selectionChanged(ListDialogField field) { + } + + public void doubleClicked(ListDialogField field) { + } + } + + public CPathIncludeEntryPage(ITreeListAdapter adapter) { + super(CPathEntryMessages.getString("IncludeEntryPage.title")); //$NON-NLS-1$ + IncludeListAdapter includeListAdaper = new IncludeListAdapter(); + + String[] buttonLabel = new String[] { CPathEntryMessages.getString("IncludeEntryPage.addFromWorksapce"), CPathEntryMessages.getString("IncludeEntryPage.addExternal"), CPathEntryMessages.getString("IncludeEntryPage.addContributed"), null, CPathEntryMessages.getString("IncludeEntryPage.remove")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + fIncludeList = new ListDialogField(includeListAdaper, buttonLabel, new CPListLabelProvider()); + fIncludeList.setDialogFieldListener(includeListAdaper); + fIncludeList.setLabelText(CPathEntryMessages.getString("IncludeEntryPage.includePath")); //$NON-NLS-1$ + fSrcList = new TreeListDialogField(adapter, new String[] { CPathEntryMessages.getString("IncludeEntryPage.editSourcePaths")}, new CElementLabelProvider()); //$NON-NLS-1$ + fSrcList.setLabelText(CPathEntryMessages.getString("IncludeEntryPage.sourcePaths")); //$NON-NLS-1$ + } + + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + + Composite composite = new Composite(parent, SWT.NONE); + + setControl(composite); + + LayoutUtil.doDefaultLayout(composite, new DialogField[] { fSrcList, fIncludeList}, true); + LayoutUtil.setHorizontalGrabbing(fIncludeList.getListControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(30); + fIncludeList.setButtonsMinWidth(buttonBarWidth); + } + + public void init(ICProject project) { + fSrcList.setElements(project.getChildrenOfType(ICElement.C_CCONTAINER)); + } + + public List getSelection() { + return fSrcList.getSelectedElements(); + } + + public void setSelection(List selection) { + fSrcList.selectElements(new StructuredSelection(selection)); + } + + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_INCLUDE; + } + + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + public void performDefaults() { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java index 70644b99dd0..f00576ab663 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java @@ -52,7 +52,7 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; public class CPathSourceEntryPage extends CPathBasePage { - private ListDialogField fClassPathList; + private ListDialogField fCPathList; private ICProject fCurrCProject; private IPath fProjPath; @@ -72,7 +72,7 @@ public class CPathSourceEntryPage extends CPathBasePage { setDescription(CPathEntryMessages.getString("SourcePathEntryPage.description")); //$NON-NLS-1$ fWorkspaceRoot = CUIPlugin.getWorkspace().getRoot(); - fClassPathList = classPathList; + fCPathList = classPathList; SourceContainerAdapter adapter = new SourceContainerAdapter(); @@ -106,7 +106,7 @@ public class CPathSourceEntryPage extends CPathBasePage { private void updateFoldersList() { ArrayList folders = new ArrayList(); - List cpelements = fClassPathList.getElements(); + List cpelements = fCPathList.getElements(); for (int i = 0; i < cpelements.size(); i++) { CPListElement cpe = (CPListElement) cpelements.get(i); if (cpe.getEntryKind() == IPathEntry.CDT_SOURCE) { @@ -306,7 +306,7 @@ public class CPathSourceEntryPage extends CPathBasePage { if (dialog.open() == Window.OK) { selElement.setAttribute(CPListElement.EXCLUSION, dialog.getExclusionPattern()); fFoldersList.refresh(); - fClassPathList.dialogFieldChanged(); // validate + fCPathList.dialogFieldChanged(); // validate } } } @@ -331,7 +331,7 @@ public class CPathSourceEntryPage extends CPathBasePage { } if (selElements.isEmpty()) { fFoldersList.refresh(); - fClassPathList.dialogFieldChanged(); // validate + fCPathList.dialogFieldChanged(); // validate } else { fFoldersList.removeElements(selElements); } @@ -390,7 +390,7 @@ public class CPathSourceEntryPage extends CPathBasePage { private void updateClasspathList() { List srcelements = fFoldersList.getElements(); - List cpelements = fClassPathList.getElements(); + List cpelements = fCPathList.getElements(); int nEntries = cpelements.size(); // backwards, as entries will be deleted int lastRemovePos = nEntries; @@ -414,7 +414,7 @@ public class CPathSourceEntryPage extends CPathBasePage { } if (lastRemovePos != nEntries || !srcelements.isEmpty()) { - fClassPathList.setElements(cpelements); + fCPathList.setElements(cpelements); } } 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 new file mode 100644 index 00000000000..b5f375a9186 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. 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.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +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.IListAdapter; +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.CElementLabelProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +public class CPathSymbolEntryPage extends CPathBasePage { + + private ListDialogField fSymbolsList; + private TreeListDialogField fSrcList; + + private class SymbolsListAdapter implements IListAdapter, IDialogFieldListener { + + public void dialogFieldChanged(DialogField field) { + } + + public void customButtonPressed(ListDialogField field, int index) { + } + + public void selectionChanged(ListDialogField field) { + } + + public void doubleClicked(ListDialogField field) { + } + } + + public CPathSymbolEntryPage(ITreeListAdapter adapter) { + super(CPathEntryMessages.getString("SymbolEntryPage.title")); //$NON-NLS-1$ + SymbolsListAdapter includeListAdaper = new SymbolsListAdapter(); + + String[] buttonLabel = new String[] { CPathEntryMessages.getString("SymbolEntryPage.add"), CPathEntryMessages.getString("SymbolEntryPage.addFromProject"), CPathEntryMessages.getString("SymbolEntryPage.addContributed"), null, CPathEntryMessages.getString("SymbolEntryPage.remove")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + fSymbolsList = new ListDialogField(includeListAdaper, buttonLabel, new CPListLabelProvider()); + fSymbolsList.setDialogFieldListener(includeListAdaper); + fSymbolsList.setLabelText(CPathEntryMessages.getString("SymbolEntryPage.defines")); //$NON-NLS-1$ + fSrcList = new TreeListDialogField(adapter, new String[] { CPathEntryMessages.getString("SymbolEntryPage.editSourcePaths")}, new CElementLabelProvider()); //$NON-NLS-1$ + fSrcList.setLabelText(CPathEntryMessages.getString("SymbolEntryPage.sourcePath")); //$NON-NLS-1$ + } + + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + + Composite composite = new Composite(parent, SWT.NONE); + + setControl(composite); + LayoutUtil.doDefaultLayout(composite, new DialogField[] { fSrcList, fSymbolsList}, true); + LayoutUtil.setHorizontalGrabbing(fSymbolsList.getListControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(30); + fSymbolsList.setButtonsMinWidth(buttonBarWidth); + + } + + public List getSelection() { + return fSrcList.getSelectedElements(); + } + + public void setSelection(List selection) { + fSrcList.selectElements(new StructuredSelection(selection)); + } + + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_MACRO; + } + + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + public void performDefaults() { + } + + public void init(ICProject project) { + fSrcList.setElements(project.getChildrenOfType(ICElement.C_CCONTAINER)); + } +} 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 6ce5aed8f6a..baf66850105 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 @@ -12,57 +12,32 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.internal.core.model.CModelStatus; 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.wizards.dialogfields.CheckedListDialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.cdt.ui.dialogs.ICOptionPage; -import org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock; import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionContainer { +public class CPathTabBlock extends AbstractPathOptionBlock { private CheckedListDialogField fCPathList; - private StatusInfo fCPathStatus; - private StatusInfo fBuildPathStatus; - - private ICProject fCurrCProject; - - private String fUserSettingsTimeStamp; - private long fFileTimeStamp; - - private int fPageIndex, fPageCount; - private CPathSourceEntryPage fSourcePage; private CPathProjectsEntryPage fProjectsPage; private CPathOutputEntryPage fOutputPage; //private LibrariesWorkbookPage fLibrariesPage; - private CPathBasePage fCurrPage; - - private IStatusChangeListener fContext; - private CPathOrderExportPage fOrderExportPage; private class BuildPathAdapter implements IDialogFieldListener { @@ -75,15 +50,13 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta void buildPathDialogFieldChanged(DialogField field) { if (field == fCPathList) { - updateClassPathStatus(); + updateCPathStatus(); } doStatusLineUpdate(); } public CPathTabBlock(IStatusChangeListener context, int pageToShow) { - super(true); - fContext = context; - fPageIndex = pageToShow; + super(context, pageToShow); String[] buttonLabels = new String[] { /* 0 */CPathEntryMessages.getString("CPathsBlock.path.up.button"), //$NON-NLS-1$ /* 1 */CPathEntryMessages.getString("CPathsBlock.path.down.button"), //$NON-NLS-1$ @@ -101,11 +74,10 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta fCPathList.setCheckAllButtonIndex(3); fCPathList.setUncheckAllButtonIndex(4); - fCPathStatus = new StatusInfo(); - fBuildPathStatus = new StatusInfo(); + } - fCurrCProject = null; - setOptionContainer(this); + protected List getCPaths() { + return fCPathList.getElements(); } protected void addTabs() { @@ -119,26 +91,6 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta addPage(fOrderExportPage); } - private void addPage(CPathBasePage page) { - addTab(page); - if (fPageIndex == fPageCount) { - fCurrPage = page; - } - fPageCount++; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock#getStartPage() - */ - protected ICOptionPage getStartPage() { - if (fCurrPage == null) { - return super.getStartPage(); - } - return fCurrPage; - } - /* * (non-Javadoc) * @@ -146,10 +98,10 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta */ public Control createContents(Composite parent) { Control control = super.createContents(parent); - if (fCurrCProject != null) { - fSourcePage.init(fCurrCProject); - fOutputPage.init(fCurrCProject); - fProjectsPage.init(fCurrCProject); + if (getCProject() != null) { + fSourcePage.init(getCProject()); + fOutputPage.init(getCProject()); + fProjectsPage.init(getCProject()); //fLibrariesPage.init(fCurrCProject); } Dialog.applyDialogFont(control); @@ -175,18 +127,15 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta * project */ public void init(ICProject cproject, IPathEntry[] cpathEntries) { - fCurrCProject = cproject; + setCProject(cproject); boolean projectExists = false; List newClassPath = null; - IProject project = fCurrCProject.getProject(); - projectExists = (project.exists() && project.getFile(".cdtproject").exists()); //$NON-NLS-1$ - if (projectExists) { - if (cpathEntries == null) { - try { - cpathEntries = fCurrCProject.getRawPathEntries(); - } catch (CModelException e) { - } + IProject project = getProject(); + if (cpathEntries == null) { + try { + cpathEntries = getCProject().getRawPathEntries(); + } catch (CModelException e) { } } if (cpathEntries != null) { @@ -208,9 +157,9 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta fCPathList.setCheckedElements(exportedEntries); if (fProjectsPage != null) { - fSourcePage.init(fCurrCProject); - fOutputPage.init(fCurrCProject); - fProjectsPage.init(fCurrCProject); + fSourcePage.init(getCProject()); + fOutputPage.init(getCProject()); + fProjectsPage.init(getCProject()); // fLibrariesPage.init(fCurrCProject); } @@ -218,43 +167,6 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta initializeTimeStamps(); } - private ArrayList getExistingEntries(IPathEntry[] cPathEntries) { - ArrayList newCPath = new ArrayList(); - for (int i = 0; i < cPathEntries.length; i++) { - IPathEntry curr = cPathEntries[i]; - newCPath.add(CPListElement.createFromExisting(curr, fCurrCProject)); - } - return newCPath; - } - - private String getEncodedSettings() { - StringBuffer buf = new StringBuffer(); - - int nElements = fCPathList.getSize(); - buf.append('[').append(nElements).append(']'); - for (int i = 0; i < nElements; i++) { - CPListElement elem = (CPListElement) fCPathList.getElement(i); - elem.appendEncodedSettings(buf); - } - return buf.toString(); - } - - public boolean hasChangesInDialog() { - String currSettings = getEncodedSettings(); - return !currSettings.equals(fUserSettingsTimeStamp); - } - - public boolean hasChangesInCPathFile() { - IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ - return fFileTimeStamp != file.getModificationStamp(); - } - - public void initializeTimeStamps() { - IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ - fFileTimeStamp = file.getModificationStamp(); - fUserSettingsTimeStamp = getEncodedSettings(); - } - private List getDefaultCPath(ICProject cproj) { List list = new ArrayList(); // IResource srcFolder; @@ -277,33 +189,6 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta return list; } - // -------- public api -------- - - /** - * @return Returns the Java project. Can return - * null if the page has not - * been initialized. - */ - public ICProject getCProject() { - return fCurrCProject; - } - - /** - * @return Returns the current class path (raw). Note that the entries - * returned must not be valid. - */ - public IPathEntry[] getRawCPath() { - List elements = fCPathList.getElements(); - int nElements = elements.size(); - IPathEntry[] entries = new IPathEntry[elements.size()]; - - for (int i = 0; i < nElements; i++) { - CPListElement currElement = (CPListElement) elements.get(i); - entries[i] = currElement.getPathEntry(); - } - return entries; - } - // -------- evaluate default settings -------- // private List getDefaultClassPath(IJavaProject jproj) { @@ -328,20 +213,11 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta // } // - private void doStatusLineUpdate() { - IStatus res = findMostSevereStatus(); - fContext.statusChanged(res); - } - - private IStatus findMostSevereStatus() { - return StatusUtil.getMostSevere(new IStatus[] { fCPathStatus, fBuildPathStatus}); - } - /** * Validates the build path. */ - public void updateClassPathStatus() { - fCPathStatus.setOK(); + public void updateCPathStatus() { + getPathStatus().setOK(); List elements = fCPathList.getElements(); @@ -352,14 +228,14 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta for (int i = elements.size() - 1; i >= 0; i--) { CPListElement currElement = (CPListElement) elements.get(i); boolean isChecked = fCPathList.isChecked(currElement); - if ( currElement.getEntryKind() == IPathEntry.CDT_SOURCE) { + if (currElement.getEntryKind() == IPathEntry.CDT_SOURCE) { if (isChecked) { fCPathList.setCheckedWithoutUpdate(currElement, false); } } else { currElement.setExported(isChecked); } - + entries[i] = currElement.getPathEntry(); if (currElement.isMissing()) { nEntriesMissing++; @@ -371,10 +247,10 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta if (nEntriesMissing > 0) { if (nEntriesMissing == 1) { - fCPathStatus.setWarning(CPathEntryMessages.getFormattedString("BuildPathsBlock.warning.EntryMissing", //$NON-NLS-1$ + getPathStatus().setWarning(CPathEntryMessages.getFormattedString("CPathsBlock.warning.EntryMissing", //$NON-NLS-1$ entryMissing.getPath().toString())); } else { - fCPathStatus.setWarning(CPathEntryMessages.getFormattedString("BuildPathsBlock.warning.EntriesMissing", //$NON-NLS-1$ + getPathStatus().setWarning(CPathEntryMessages.getFormattedString("CPathsBlock.warning.EntriesMissing", //$NON-NLS-1$ String.valueOf(nEntriesMissing))); } } @@ -387,44 +263,12 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta updateBuildPathStatus(); } - private void updateBuildPathStatus() { - List elements = fCPathList.getElements(); - IPathEntry[] entries = new IPathEntry[elements.size()]; - - for (int i = elements.size() - 1; i >= 0; i--) { - CPListElement currElement = (CPListElement) elements.get(i); - entries[i] = currElement.getPathEntry(); - } - - ICModelStatus status = CModelStatus.VERIFIED_OK; // CoreModelUtil.validateCPathEntries(fCurrCProject, entries); - if (!status.isOK()) { - fBuildPathStatus.setError(status.getMessage()); - return; - } - fBuildPathStatus.setOK(); - } - - // -------- creation ------------------------------- - - public void configureCProject(IProgressMonitor monitor) throws CoreException, InterruptedException { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - monitor.setTaskName(CPathEntryMessages.getString("CPathsBlock.operationdesc_c")); //$NON-NLS-1$ - monitor.beginTask("", 10); //$NON-NLS-1$ - - try { - internalConfigureCProject(fCPathList.getElements(), monitor); - } finally { - monitor.done(); - } - } /* * Creates the Java project and sets the configured build path and output * location. If the project already exists only build paths are updated. */ - private void internalConfigureCProject(List cPathEntries, IProgressMonitor monitor) throws CoreException, InterruptedException { + protected void internalConfigureCProject(List cPathEntries, IProgressMonitor monitor) throws CoreException, InterruptedException { // 10 monitor steps to go monitor.worked(2); @@ -444,8 +288,7 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta monitor.worked(1); - fCurrCProject.setRawPathEntries(classpath, new SubProgressMonitor(monitor, 7)); - initializeTimeStamps(); + getCProject().setRawPathEntries(classpath, new SubProgressMonitor(monitor, 7)); } /** @@ -462,50 +305,4 @@ public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionConta folder.create(force, local, monitor); } } - - - // -------- tab switching ---------- - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock#setCurrentPage(org.eclipse.cdt.ui.dialogs.ICOptionPage) - */ - public void setCurrentPage(ICOptionPage page) { - super.setCurrentPage(page); - CPathBasePage newPage = (CPathBasePage) page; - if (fCurrPage != null) { - List selection = fCurrPage.getSelection(); - if (!selection.isEmpty()) { - newPage.setSelection(selection); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#updateContainer() - */ - public void updateContainer() { - update(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getProject() - */ - public IProject getProject() { - return fCurrCProject.getProject(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getPreferences() - */ - public Preferences getPreferences() { - return null; - } -} +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java new file mode 100644 index 00000000000..05f1593d0e8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsPropertyPage.java @@ -0,0 +1,218 @@ +/******************************************************************************* + * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. 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.CProjectNature; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; +import org.eclipse.ui.dialogs.PropertyPage; + + +public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatusChangeListener { + + private static final String PAGE_SETTINGS = "IncludeSysmbolsPropertyPage"; //$NON-NLS-1$ + private static final String INDEX = "pageIndex"; //$NON-NLS-1$ + + IncludesSymbolsTabBlock fIncludesSymbolsBlock; + + /** + * @see PropertyPage#createContents + */ + protected Control createContents(Composite parent) { + IProject project = getProject(); + Control result; + if (project == null || !isCProject(project)) { + result = createWithoutCProject(parent); + } else if (!project.isOpen()) { + result = createForClosedProject(parent); + } else { + result = createWithCProject(parent, project); + } + Dialog.applyDialogFont(result); + return result; + } + + private IDialogSettings getSettings() { + IDialogSettings cSettings = CUIPlugin.getDefault().getDialogSettings(); + IDialogSettings pageSettings = cSettings.getSection(PAGE_SETTINGS); + if (pageSettings == null) { + pageSettings = cSettings.addNewSection(PAGE_SETTINGS); + pageSettings.put(INDEX, 3); + } + return pageSettings; + } + + /* + * Content for valid projects. + */ + private Control createWithCProject(Composite parent, IProject project) { + fIncludesSymbolsBlock = new IncludesSymbolsTabBlock(this, getSettings().getInt(INDEX)); + fIncludesSymbolsBlock.init(getCElement(), null); + return fIncludesSymbolsBlock.createContents(parent); + } + + /* + * Content for non-C projects. + */ + private Control createWithoutCProject(Composite parent) { + Label label = new Label(parent, SWT.LEFT); + label.setText(CPathEntryMessages.getString("CPathsPropertyPage.no_C_project.message")); //$NON-NLS-1$ + + fIncludesSymbolsBlock = null; + setValid(true); + return label; + } + + /* + * Content for closed projects. + */ + private Control createForClosedProject(Composite parent) { + Label label = new Label(parent, SWT.LEFT); + label.setText(CPathEntryMessages.getString("CPathsPropertyPage.closed_project.message")); //$NON-NLS-1$ + + fIncludesSymbolsBlock = null; + setValid(true); + return label; + } + + public void setVisible(boolean visible) { + if (fIncludesSymbolsBlock != null) { + if (!visible) { + if (fIncludesSymbolsBlock.hasChangesInDialog()) { + String title= CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.title"); //$NON-NLS-1$ + String message= CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.message"); //$NON-NLS-1$ + String[] buttonLabels= new String[] { + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.save"), //$NON-NLS-1$ + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.discard"), //$NON-NLS-1$ + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.ignore") //$NON-NLS-1$ + }; + MessageDialog dialog= new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, buttonLabels, 0); + int res= dialog.open(); + if (res == 0) { + performOk(); + } else if (res == 1) { + fIncludesSymbolsBlock.init(getCElement(), null); + } else { + fIncludesSymbolsBlock.initializeTimeStamps(); + } + } + } else { + if (!fIncludesSymbolsBlock.hasChangesInDialog() && fIncludesSymbolsBlock.hasChangesInCPathFile()) { + fIncludesSymbolsBlock.init(getCElement(), null); + } + } + } + super.setVisible(visible); + } + + private IProject getProject() { + IAdaptable adaptable = getElement(); + if (adaptable != null) { + ICElement elem = (ICElement) adaptable.getAdapter(ICElement.class); + return elem.getCProject().getProject(); + } + return null; + } + + private ICElement getCElement() { + IAdaptable adaptable = getElement(); + if (adaptable != null) { + ICElement elem = (ICElement) adaptable.getAdapter(ICElement.class); + return elem; + } + return null; + } + + private boolean isCProject(IProject proj) { + try { + return proj.hasNature(CProjectNature.C_NATURE_ID); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + return false; + } + + /* + * @see IPreferencePage#performOk + */ + public boolean performOk() { + if (fIncludesSymbolsBlock != null) { + getSettings().put(INDEX, fIncludesSymbolsBlock.getPageIndex()); + + Shell shell = getControl().getShell(); + IRunnableWithProgress runnable = new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + fIncludesSymbolsBlock.configureCProject(monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); + try { + new ProgressMonitorDialog(shell).run(true, true, op); + } catch (InvocationTargetException e) { + String title = CPathEntryMessages.getString("CPathsPropertyPage.error.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("CPathsPropertyPage.error.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, shell, title, message); + return false; + } catch (InterruptedException e) { + // cancelled + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * + * @see IStatusChangeListener#statusChanged + */ + public void statusChanged(IStatus status) { + setValid(!status.matches(IStatus.ERROR)); + StatusUtil.applyToStatusLine(this, status); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.IPreferencePage#performCancel() + */ + public boolean performCancel() { + if (fIncludesSymbolsBlock != null) { + getSettings().put(INDEX, fIncludesSymbolsBlock.getPageIndex()); + } + return super.performCancel(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java new file mode 100644 index 00000000000..dd2d65367ef --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. 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.CModelException; +import org.eclipse.cdt.core.model.ICContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class IncludesSymbolsTabBlock extends AbstractPathOptionBlock { + + private CPathIncludeEntryPage fIncludePage; + private CPathSymbolEntryPage fSymbolsPage; + private SourceTreeAdapter fSourceTreeAdapter; + + private class SourceTreeAdapter implements ITreeListAdapter { + + public void customButtonPressed(TreeListDialogField field, int index) { + } + + public void selectionChanged(TreeListDialogField field) { + } + + public void doubleClicked(TreeListDialogField field) { + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + } + + public Object[] getChildren(TreeListDialogField field, Object element) { + List children = new ArrayList(); + if (element instanceof ICContainer) { + children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_CCONTAINER)); + children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_UNIT)); + } + return children.toArray(); + } + + public Object getParent(TreeListDialogField field, Object element) { + return ((ICElement) element).getParent(); + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + if (element instanceof ICContainer) { + return ((ICContainer) element).hasChildren(); + } + return false; + } + } + + public IncludesSymbolsTabBlock(IStatusChangeListener context, int pageToShow) { + super(context, pageToShow); + fSourceTreeAdapter = new SourceTreeAdapter(); + } + + protected void addTabs() { + fIncludePage = new CPathIncludeEntryPage(fSourceTreeAdapter); + addPage(fIncludePage); + fSymbolsPage = new CPathSymbolEntryPage(fSourceTreeAdapter); + addPage(fSymbolsPage); + } + + public Control createContents(Composite parent) { + Control control = super.createContents(parent); + if (getCProject() != null) { + fIncludePage.init(getCProject()); + fSymbolsPage.init(getCProject()); + } + Dialog.applyDialogFont(control); + return control; + } + + protected List getCPaths() { + return new ArrayList(); + } + + public void init(ICElement cElement, IPathEntry[] cpathEntries) { + setCProject(cElement.getCProject()); + boolean projectExists = false; + List newClassPath = null; + + IProject project = getProject(); + if (cpathEntries == null) { + try { + cpathEntries = getCProject().getRawPathEntries(); + } catch (CModelException e) { + } + } + if (cpathEntries != null) { + newClassPath = getExistingEntries(cpathEntries); + } + if (fIncludePage != null) { + fIncludePage.init(getCProject()); + fSymbolsPage.init(getCProject()); + } + doStatusLineUpdate(); + initializeTimeStamps(); + } + + protected void internalConfigureCProject(List cPathEntries, IProgressMonitor monitor) throws CoreException, + InterruptedException { + + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java index 633c9130a2b..1f3a384fd16 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java @@ -56,7 +56,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.internal.ui.util.EditorUtility; -import org.eclipse.cdt.internal.ui.wizards.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; /** */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskConfigurationBlock.java index 81ca19108ee..072e300e04f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskConfigurationBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskConfigurationBlock.java @@ -32,12 +32,12 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.util.PixelConverter; import org.eclipse.cdt.internal.ui.util.SWTUtil; -import org.eclipse.cdt.internal.ui.wizards.IStatusChangeListener; 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; import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; /** */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPreferencePage.java index 61a03d9d461..cb6e582f010 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPreferencePage.java @@ -25,7 +25,7 @@ import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; -import org.eclipse.cdt.internal.ui.wizards.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; /* * The page to configure the compiler options. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPropertyPage.java index f7a87a8fc2a..14786aaa00b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/TodoTaskPropertyPage.java @@ -36,7 +36,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; -import org.eclipse.cdt.internal.ui.wizards.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; 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.LayoutUtil; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java deleted file mode 100644 index 8f0f417e5e8..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -package org.eclipse.cdt.internal.ui.wizards; - -import org.eclipse.core.runtime.IStatus; - -public interface IStatusChangeListener { - - /** - * Notifies this listener that the given status has changed. - * - * @param status the new status - */ - void statusChanged(IStatus status); -}