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

Work in progress - start of new C Path Container Wizard

This commit is contained in:
David Inglis 2004-04-15 19:56:41 +00:00
parent 8462a05691
commit e20be2336b
20 changed files with 1063 additions and 49 deletions

View file

@ -1,10 +1,25 @@
2004-05-15 David Inglis
Work in Progress - start of new C Path Container Wizard
* plugin.xml
* src/org/eclipse/cdt/internal/ui/CPluginImages.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java
* src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
* icons/full/wizban/addpath_wiz.gif
2004-04-15 David Inglis
simple refactor
- refactor/org/eclipse/cdt/internal/ui/refactoring/ListContentProvider.java
* refactor/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java
+ src/org/eclipse/cdt/internal/ui/viewsupport/ListContentProvider.java
- refactor/org/eclipse/cdt/internal/ui/refactoring/ListContentProvider.java
* refactor/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java
+ src/org/eclipse/cdt/internal/ui/viewsupport/ListContentProvider.java
2004-04-15 Chris Wiebe

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -31,6 +31,8 @@
<extension-point id="CCompletionContributor" name="%completionContributorName"/>
<extension-point id="CElementFilters" name="%elementFiltersName"/>
<extension-point id="BinaryParserPage" name="%binaryParserPage"/>
<extension-point id="CPathContainerPage" name="%CPathContainerPageExtensionPoint" schema="schema/CPathContainerPage.exsd"/>
<!-- =========================================================================== -->
<!-- Extension point: org.eclipse.cdt.ui.textHovers -->
<!-- Extension Implementation: must implement org.eclipse.jface.text.ITextHover -->

View file

@ -0,0 +1,116 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.ui">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="CPathContainerPage" name="%CPathContainerPageExtensionPoint"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<complexType>
<sequence>
<element ref="CPathContainerPage"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="CPathContainerPage">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java"/>
</appInfo>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiInfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
</documentation>
</annotation>
</schema>

View file

@ -173,6 +173,7 @@ public class CPluginImages {
public static final ImageDescriptor DESC_TOOL_NEWCLASS= create(T_TOOL, "newclass_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_ADD_LIBRARY = create(T_WIZBAN, "addpath_wiz.gif"); //$NON-NLS-1$
// For the build image
public static final String IMG_OBJS_BUILD= NAME_PREFIX + "build_menu.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_BUILD_MENU = createManaged(T_OBJ, IMG_OBJS_BUILD);

View file

@ -21,10 +21,10 @@ 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.util.CoreUtility;
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;
@ -277,7 +277,7 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
CPListElement entry = ((CPListElement) cPathEntries.get(i));
IResource res = entry.getResource();
if ((res instanceof IFolder) && !res.exists()) {
createFolder((IFolder) res, true, true, null);
CoreUtility.createFolder((IFolder) res, true, true, null);
}
cpath.add(entry.getPathEntry());
}
@ -304,19 +304,4 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
monitor.done();
}
}
/**
* Creates a folder and all parent folders if not existing. Project must
* exist. <code> org.eclipse.ui.dialogs.ContainerGenerator</code> is too
* heavy (creates a runnable)
*/
private void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent, force, local, null);
}
folder.create(force, local, monitor);
}
}
}

View file

@ -0,0 +1,134 @@
/*******************************************************************************
* 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 org.eclipse.cdt.core.model.CoreModel;
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.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
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;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
/**
*/
public class CPathContainerDefaultPage extends NewElementWizardPage implements ICPathContainerPage {
private StringDialogField fEntryField;
private ArrayList fUsedPaths;
/**
* Constructor for ClasspathContainerDefaultPage.
*/
public CPathContainerDefaultPage() {
super("CPathContainerDefaultPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("CPathContainerDefaultPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("CPathContainerDefaultPage.description")); //$NON-NLS-1$
setImageDescriptor(CPluginImages.DESC_WIZBAN_ADD_LIBRARY);
fUsedPaths= new ArrayList();
fEntryField= new StringDialogField();
fEntryField.setLabelText(CPathEntryMessages.getString("CPathContainerDefaultPage.path.label")); //$NON-NLS-1$
fEntryField.setDialogFieldListener(new IDialogFieldListener() {
public void dialogFieldChanged(DialogField field) {
validatePath();
}
});
validatePath();
}
private void validatePath() {
StatusInfo status= new StatusInfo();
String str= fEntryField.getText();
if (str.length() == 0) {
status.setError(CPathEntryMessages.getString("CPathContainerDefaultPage.path.error.enterpath")); //$NON-NLS-1$
} else if (!Path.ROOT.isValidPath(str)) {
status.setError(CPathEntryMessages.getString("CPathContainerDefaultPage.path.error.invalidpath")); //$NON-NLS-1$
} else {
IPath path= new Path(str);
if (path.segmentCount() == 0) {
status.setError(CPathEntryMessages.getString("CPathContainerDefaultPage.path.error.needssegment")); //$NON-NLS-1$
} else if (fUsedPaths.contains(path)) {
status.setError(CPathEntryMessages.getString("CPathContainerDefaultPage.path.error.alreadyexists")); //$NON-NLS-1$
}
}
updateStatus(status);
}
/* (non-Javadoc)
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite composite= new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout();
layout.numColumns= 1;
composite.setLayout(layout);
fEntryField.doFillIntoGrid(composite, 2);
LayoutUtil.setHorizontalGrabbing(fEntryField.getTextControl(null));
fEntryField.setFocus();
setControl(composite);
Dialog.applyDialogFont(composite);
// WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.CLASSPATH_CONTAINER_DEFAULT_PAGE);
}
/* (non-Javadoc)
* @see IClasspathContainerPage#finish()
*/
public boolean finish() {
return true;
}
/* (non-Javadoc)
* @see IClasspathContainerPage#getSelection()
*/
public IPathEntry[] getNewContainers() {
return new IPathEntry[] {CoreModel.newContainerEntry(new Path(fEntryField.getText()))};
}
/* (non-Javadoc)
* @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry)
*/
public void initialize(ICProject project, IPathEntry[] currentEntries) {
for (int i= 0; i < currentEntries.length; i++) {
IPathEntry curr= currentEntries[i];
if (curr.getEntryKind() == IPathEntry.CDT_CONTAINER) {
fUsedPaths.add(curr.getPath());
}
}
}
/* (non-Javadoc)
* @see IClasspathContainerPage#setSelection(IClasspathEntry)
*/
public void setSelection(IPathEntry containerEntry) {
if (containerEntry != null) {
fUsedPaths.remove(containerEntry.getPath());
fEntryField.setText(containerEntry.getPath().toString());
} else {
fEntryField.setText(""); //$NON-NLS-1$
}
}
}

View file

@ -0,0 +1,107 @@
/*******************************************************************************
* 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 org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.util.CoreUtility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
public class CPathContainerDescriptor {
private IConfigurationElement fConfigElement;
private static final String ATT_EXTENSION = "CPathContainerPage"; //$NON-NLS-1$
private static final String ATT_ID = "id"; //$NON-NLS-1$
private static final String ATT_NAME = "name"; //$NON-NLS-1$
private static final String ATT_PAGE_CLASS = "class"; //$NON-NLS-1$
public CPathContainerDescriptor(IConfigurationElement configElement) throws CoreException {
super();
fConfigElement = configElement;
String id = fConfigElement.getAttribute(ATT_ID);
String name = configElement.getAttribute(ATT_NAME);
String pageClassName = configElement.getAttribute(ATT_PAGE_CLASS);
if (name == null) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "Invalid extension (missing name): " + id, null)); //$NON-NLS-1$
}
if (pageClassName == null) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "Invalid extension (missing page class name): " + id, null)); //$NON-NLS-1$
}
}
public ICPathContainerPage createPage() throws CoreException {
Object elem= CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS);
if (elem instanceof ICPathContainerPage) {
return (ICPathContainerPage) elem;
} else {
String id= fConfigElement.getAttribute(ATT_ID);
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "Invalid extension (page not of type IClasspathContainerPage): " + id, null)); //$NON-NLS-1$
}
}
public String getName() {
return fConfigElement.getAttribute(ATT_NAME);
}
public String getPageClass() {
return fConfigElement.getAttribute(ATT_PAGE_CLASS);
}
public boolean canEdit(IPathEntry entry) {
String id = fConfigElement.getAttribute(ATT_ID);
if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) {
String type = entry.getPath().segment(0);
return id.equals(type);
}
return false;
}
public static CPathContainerDescriptor[] getDescriptors() {
ArrayList containers= new ArrayList();
IExtensionPoint extensionPoint = Platform.getPluginRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, ATT_EXTENSION);
if (extensionPoint != null) {
CPathContainerDescriptor defaultPage= null;
String defaultPageName= CPathContainerDefaultPage.class.getName();
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
try {
CPathContainerDescriptor curr= new CPathContainerDescriptor(elements[i]);
if (defaultPageName.equals(curr.getPageClass())) {
defaultPage= curr;
} else {
containers.add(curr);
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
if (defaultPageName != null && containers.isEmpty()) {
// default page only added of no other extensions found
containers.add(defaultPage);
}
}
return (CPathContainerDescriptor[]) containers.toArray(new CPathContainerDescriptor[containers.size()]);
}
}

View file

@ -0,0 +1,144 @@
/*******************************************************************************
* 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:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.Arrays;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
import org.eclipse.cdt.internal.ui.viewsupport.ListContentProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
/**
*/
public class CPathContainerSelectionPage extends WizardPage {
private static final String DIALOGSTORE_SECTION= "CPathContainerSelectionPage"; //$NON-NLS-1$
private static final String DIALOGSTORE_CONTAINER_IDX= "index"; //$NON-NLS-1$
private static class ClasspathContainerLabelProvider extends LabelProvider {
public String getText(Object element) {
return ((CPathContainerDescriptor) element).getName();
}
}
private static class ClasspathContainerSorter extends ViewerSorter {
}
private ListViewer fListViewer;
private CPathContainerDescriptor[] fContainers;
private IDialogSettings fDialogSettings;
/**
* Constructor for ClasspathContainerWizardPage.
* @param containerPages
*/
protected CPathContainerSelectionPage(CPathContainerDescriptor[] containerPages) {
super("CPathContainerWizardPage"); //$NON-NLS-1$
setTitle(CPathEntryMessages.getString("CPathContainerSelectionPage.title")); //$NON-NLS-1$
setDescription(CPathEntryMessages.getString("CPathContainerSelectionPage.description")); //$NON-NLS-1$
setImageDescriptor(CPluginImages.DESC_WIZBAN_ADD_LIBRARY);
fContainers= containerPages;
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings();
fDialogSettings= settings.getSection(DIALOGSTORE_SECTION);
if (fDialogSettings == null) {
fDialogSettings= settings.addNewSection(DIALOGSTORE_SECTION);
fDialogSettings.put(DIALOGSTORE_CONTAINER_IDX, 0);
}
validatePage();
}
/* (non-Javadoc)
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
fListViewer= new ListViewer(parent, SWT.SINGLE | SWT.BORDER);
fListViewer.setLabelProvider(new ClasspathContainerLabelProvider());
fListViewer.setContentProvider(new ListContentProvider());
fListViewer.setSorter(new ClasspathContainerSorter());
fListViewer.setInput(Arrays.asList(fContainers));
fListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
validatePage();
}
});
fListViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
doDoubleClick();
}
});
int selectionIndex= fDialogSettings.getInt(DIALOGSTORE_CONTAINER_IDX);
if (selectionIndex >= fContainers.length) {
selectionIndex= 0;
}
fListViewer.getList().select(selectionIndex);
validatePage();
setControl(fListViewer.getList());
Dialog.applyDialogFont(fListViewer.getList());
}
/**
* Method validatePage.
*/
private void validatePage() {
setPageComplete(getSelected() != null);
}
public CPathContainerDescriptor getSelected() {
if (fListViewer != null) {
ISelection selection= fListViewer.getSelection();
return (CPathContainerDescriptor) SelectionUtil.getSingleElement(selection);
}
return null;
}
protected void doDoubleClick() {
if (canFlipToNextPage()) {
getContainer().showPage(getNextPage());
}
}
/* (non-Javadoc)
* @see IWizardPage#canFlipToNextPage()
*/
public boolean canFlipToNextPage() {
return isPageComplete(); // avoid the getNextPage call to prevent potential plugin load
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
public void setVisible(boolean visible) {
if (!visible && fListViewer != null) {
fDialogSettings.put(DIALOGSTORE_CONTAINER_IDX, fListViewer.getList().getSelectionIndex());
}
super.setVisible(visible);
}
}

View file

@ -0,0 +1,202 @@
/*******************************************************************************
* 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.dialogs.cpaths;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.ui.wizards.ICPathContainerPage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
/**
*/
public class CPathContainerWizard extends Wizard {
private CPathContainerDescriptor fPageDesc;
private IPathEntry fEntryToEdit;
private IPathEntry[] fNewEntries;
private ICPathContainerPage fContainerPage;
private ICProject fCurrProject;
private IPathEntry[] fCurrClasspath;
private CPathContainerSelectionPage fSelectionWizardPage;
/**
* Constructor for ClasspathContainerWizard.
*/
public CPathContainerWizard(IPathEntry entryToEdit, ICProject currProject, IPathEntry[] currEntries) {
this(entryToEdit, null, currProject, currEntries);
}
/**
* Constructor for ClasspathContainerWizard.
*/
public CPathContainerWizard(CPathContainerDescriptor pageDesc, ICProject currProject, IPathEntry[] currEntries) {
this(null, pageDesc, currProject, currEntries);
}
/**
* @deprecated
*/
public CPathContainerWizard(CPathContainerDescriptor pageDesc) {
this(null, pageDesc, null, null);
}
private CPathContainerWizard(IPathEntry entryToEdit, CPathContainerDescriptor pageDesc, ICProject currProject,
IPathEntry[] currEntries) {
fEntryToEdit = entryToEdit;
fPageDesc = pageDesc;
fNewEntries = null;
fCurrProject = currProject;
fCurrClasspath = currEntries;
}
/**
* @deprecated use getNewEntries()
*/
public IPathEntry getNewEntry() {
IPathEntry[] entries = getNewEntries();
if (entries != null) {
return entries[0];
}
return null;
}
public IPathEntry[] getNewEntries() {
return fNewEntries;
}
/*
* (non-Javadoc)
*
* @see IWizard#performFinish()
*/
public boolean performFinish() {
if (fContainerPage != null) {
if (fContainerPage.finish()) {
fNewEntries = fContainerPage.getNewContainers();
return true;
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see IWizard#addPages()
*/
public void addPages() {
if (fPageDesc != null) {
fContainerPage = getContainerPage(fPageDesc);
addPage(fContainerPage);
} else if (fEntryToEdit == null) { // new entry: show selection page as first page
CPathContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
fSelectionWizardPage = new CPathContainerSelectionPage(containers);
addPage(fSelectionWizardPage);
// add as dummy, will not be shown
fContainerPage = new CPathContainerDefaultPage();
addPage(fContainerPage);
} else { // fPageDesc == null && fEntryToEdit != null
CPathContainerDescriptor[] containers = CPathContainerDescriptor.getDescriptors();
CPathContainerDescriptor descriptor = findDescriptorPage(containers, fEntryToEdit);
fContainerPage = getContainerPage(descriptor);
addPage(fContainerPage);
}
super.addPages();
}
private ICPathContainerPage getContainerPage(CPathContainerDescriptor pageDesc) {
ICPathContainerPage containerPage = null;
if (pageDesc != null) {
try {
containerPage = pageDesc.createPage();
} catch (CoreException e) {
handlePageCreationFailed(e);
containerPage = null;
}
}
if (containerPage == null) {
containerPage = new CPathContainerDefaultPage();
}
containerPage.initialize(fCurrProject, fCurrClasspath);
containerPage.setSelection(fEntryToEdit);
containerPage.setWizard(this);
return containerPage;
}
/*
* (non-Javadoc)
*
* @see IWizard#getNextPage(IWizardPage)
*/
public IWizardPage getNextPage(IWizardPage page) {
if (page == fSelectionWizardPage) {
CPathContainerDescriptor selected = fSelectionWizardPage.getSelected();
fContainerPage = getContainerPage(selected);
return fContainerPage;
}
return super.getNextPage(page);
}
private void handlePageCreationFailed(CoreException e) {
String title = CPathEntryMessages.getString("CPathContainerWizard.pagecreationerror.title"); //$NON-NLS-1$
String message = CPathEntryMessages.getString("CPathContainerWizard.pagecreationerror.message"); //$NON-NLS-1$
ExceptionHandler.handle(e, getShell(), title, message);
}
private CPathContainerDescriptor findDescriptorPage(CPathContainerDescriptor[] containers, IPathEntry entry) {
for (int i = 0; i < containers.length; i++) {
if (containers[i].canEdit(entry)) {
return containers[i];
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see IWizard#canFinish()
*/
public boolean canFinish() {
if (fSelectionWizardPage != null) {
if (!fContainerPage.isPageComplete()) {
return false;
}
}
if (fContainerPage != null) {
return fContainerPage.isPageComplete();
}
return false;
}
public static int openWizard(Shell shell, CPathContainerWizard wizard) {
WizardDialog dialog = new WizardDialog(shell, wizard);
PixelConverter converter = new PixelConverter(shell);
dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
dialog.create();
return dialog.open();
}
}

View file

@ -88,11 +88,6 @@ OutputPathEntryPage.ExistingOutputFolderDialog.new.description=&Choose Output fo
OutputPathEntryPage.ExistingOutputFolderDialog.edit.title=Output Folder Selection
OutputPathEntryPage.ExistingOutputFolderDialog.edit.description=&Select the Output folder:
OutputPathEntryPage.NewOutputFolderDialog.new.title=New Output Folder
OutputPathEntryPage.NewOutputFolderDialog.edit.title=Edit Output Folder
OutputPathEntryPage.NewOutputFolderDialog.description=&Enter a path relative to ''{0}'':
OutputPathEntryPage.exclusion_added.title=Output Folder Added
OutputPathEntryPage.exclusion_added.message=Exclusion filters have been added to nesting folders.
@ -193,3 +188,15 @@ CPListLabelProvider.source_attachment_root.label=Source attachment root:
CPListLabelProvider.exclusion_filter.label=Exclusion filter:
CPListLabelProvider.exclusion_filter_separator=;
CPListLabelProvider.unknown_element.label=unknown element
# ------- NewSourceFolderDialog-------
NewSourceFolderDialog.useproject.button=&Project as source folder
NewSourceFolderDialog.usefolder.button=&Folder as source folder
NewSourceFolderDialog.sourcefolder.label=&Source folder name:
NewSourceFolderDialog.error.invalidpath=Invalid folder path: ''{0}''
NewSourceFolderDialog.error.enterpath=Folder name must be entered.
NewSourceFolderDialog.error.pathexists=The folder is already in the list.
FolderSelectionDialog.button=Create &New Folder...
MultipleFolderSelectionDialog.button=Create &New Folder...

View file

@ -9,8 +9,14 @@
******************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
@ -23,7 +29,25 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
}
protected void addContributed() {
// dinglis-TODO Auto-generated method stub
CPListElement[] includes = openContainerSelectionDialog(null);
if (includes != null) {
int nElementsChosen= includes.length;
// remove duplicates
List cplist= fPathList.getElements();
List elementsToAdd= new ArrayList(nElementsChosen);
for (int i= 0; i < nElementsChosen; i++) {
CPListElement curr= includes[i];
if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) {
elementsToAdd.add(curr);
// curr.setAttribute(CPListElement.SOURCEATTACHMENT, BuildPathSupport.guessSourceAttachment(curr));
// curr.setAttribute(CPListElement.JAVADOC, JavaUI.getLibraryJavadocLocation(curr.getPath()));
}
}
fPathList.addElements(elementsToAdd);
fPathList.postSetSelection(new StructuredSelection(includes));
}
}
protected void addFromWorkspace() {
@ -35,4 +59,28 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage {
// dinglis-TODO Auto-generated method stub
}
private CPListElement[] openContainerSelectionDialog(CPListElement existing) {
IPathEntry elem= null;
String title;
if (existing == null) {
title= CPathEntryMessages.getString("IncludeEntryPage.ContainerDialog.new.title"); //$NON-NLS-1$
} else {
title= CPathEntryMessages.getString("IncludeEntryPage.ContainerDialog.edit.title"); //$NON-NLS-1$
elem= existing.getPathEntry();
}
CPathContainerWizard wizard= new CPathContainerWizard(elem, fCurrCProject, getRawClasspath());
wizard.setWindowTitle(title);
if (CPathContainerWizard.openWizard(getShell(), wizard) == Window.OK) {
IPathEntry[] created= wizard.getNewEntries();
if (created != null) {
CPListElement[] res= new CPListElement[created.length];
for (int i= 0; i < res.length; i++) {
res[i]= new CPListElement(fCurrCProject, IPathEntry.CDT_CONTAINER, created[i].getPath(), null);
}
return res;
}
}
return null;
}
}

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.model.CoreModelUtil;
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.core.model.ISourceRoot;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
@ -40,9 +41,10 @@ import org.eclipse.swt.widgets.Display;
public abstract class ExtendedCPathBasePage extends CPathBasePage {
ListDialogField fPathList;
TreeListDialogField fSrcList;
List fCPathList;
protected ListDialogField fPathList;
protected TreeListDialogField fSrcList;
protected List fCPathList;
protected ICProject fCurrCProject;
private static final int IDX_ADD = 0;
private static final int IDX_ADD_WORKSPACE = 1;
@ -173,6 +175,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
}
public void init(ICProject project, List cPaths) {
fCurrCProject = project;
List list = new ArrayList(project.getChildrenOfType(ICElement.C_CCONTAINER));
int i;
for (i = 0; i < list.size(); i++) {
@ -193,6 +196,15 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
return fCPathList;
}
protected IPathEntry[] getRawClasspath() {
IPathEntry[] currEntries= new IPathEntry[fCPathList.size()];
for (int i= 0; i < currEntries.length; i++) {
CPListElement curr= (CPListElement) fCPathList.get(i);
currEntries[i]= curr.getPathEntry();
}
return currEntries;
}
public List getSelection() {
return fSrcList.getSelectedElements();
}

View file

@ -15,7 +15,6 @@ import java.util.List;
import java.util.Set;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogConstants;
@ -231,7 +230,7 @@ public class MultipleFolderSelectionDialog extends SelectionStatusDialog impleme
treeWidget.setFont(composite.getFont());
Button button = new Button(composite, SWT.PUSH);
button.setText(NewWizardMessages.getString("MultipleFolderSelectionDialog.button")); //$NON-NLS-1$
button.setText(CPathEntryMessages.getString("MultipleFolderSelectionDialog.button")); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {

View file

@ -12,7 +12,6 @@ import java.util.List;
import org.eclipse.cdt.internal.ui.dialogs.StatusDialog;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
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.SelectionButtonDialogField;
@ -51,16 +50,16 @@ public class NewSourceFolderDialog extends StatusDialog {
SourceContainerAdapter adapter = new SourceContainerAdapter();
fUseProjectButton = new SelectionButtonDialogField(SWT.RADIO);
fUseProjectButton.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.useproject.button")); //$NON-NLS-1$
fUseProjectButton.setLabelText(CPathEntryMessages.getString("NewSourceFolderDialog.useproject.button")); //$NON-NLS-1$
fUseProjectButton.setDialogFieldListener(adapter);
fUseFolderButton = new SelectionButtonDialogField(SWT.RADIO);
fUseFolderButton.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.usefolder.button")); //$NON-NLS-1$
fUseFolderButton.setLabelText(CPathEntryMessages.getString("NewSourceFolderDialog.usefolder.button")); //$NON-NLS-1$
fUseFolderButton.setDialogFieldListener(adapter);
fContainerDialogField = new StringDialogField();
fContainerDialogField.setDialogFieldListener(adapter);
fContainerDialogField.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.sourcefolder.label")); //$NON-NLS-1$
fContainerDialogField.setLabelText(CPathEntryMessages.getString("NewSourceFolderDialog.sourcefolder.label")); //$NON-NLS-1$
fUseFolderButton.attachDialogField(fContainerDialogField);
@ -139,7 +138,7 @@ public class NewSourceFolderDialog extends StatusDialog {
if (fUseFolderButton.isSelected()) {
String pathStr = fContainerDialogField.getText();
if (pathStr.length() == 0) {
fContainerFieldStatus.setError(NewWizardMessages.getString("NewSourceFolderDialog.error.enterpath")); //$NON-NLS-1$
fContainerFieldStatus.setError(CPathEntryMessages.getString("NewSourceFolderDialog.error.enterpath")); //$NON-NLS-1$
return;
}
IPath path = fCurrProject.getFullPath().append(pathStr);
@ -147,7 +146,7 @@ public class NewSourceFolderDialog extends StatusDialog {
IStatus pathValidation = workspace.validatePath(path.toString(), IResource.FOLDER);
if (!pathValidation.isOK()) {
fContainerFieldStatus.setError(NewWizardMessages.getFormattedString("NewSourceFolderDialog.error.invalidpath", //$NON-NLS-1$
fContainerFieldStatus.setError(CPathEntryMessages.getFormattedString("NewSourceFolderDialog.error.invalidpath", //$NON-NLS-1$
pathValidation.getMessage()));
return;
}
@ -156,7 +155,7 @@ public class NewSourceFolderDialog extends StatusDialog {
folder = fCurrProject;
}
if (isExisting(folder)) {
fContainerFieldStatus.setError(NewWizardMessages.getString("NewSourceFolderDialog.error.pathexists")); //$NON-NLS-1$
fContainerFieldStatus.setError(CPathEntryMessages.getString("NewSourceFolderDialog.error.pathexists")); //$NON-NLS-1$
return;
}
fContainerFieldStatus.setOK();

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* 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.util;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.custom.BusyIndicator;
public class CoreUtility {
/**
* Creates a folder and all parent folders if not existing.
* Project must exist.
* <code> org.eclipse.ui.dialogs.ContainerGenerator</code> is too heavy
* (creates a runnable)
*/
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
if (!folder.exists()) {
IContainer parent= folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder)parent, force, local, null);
}
folder.create(force, local, monitor);
}
}
/**
* Creates an extension. If the extension plugin has not
* been loaded a busy cursor will be activated during the duration of
* the load.
*
* @param element the config element defining the extension
* @param classAttribute the name of the attribute carrying the class
* @return the extension object
*/
public static Object createExtension(final IConfigurationElement element, final String classAttribute) throws CoreException {
// If plugin has been loaded create extension.
// Otherwise, show busy cursor then create extension.
IPluginDescriptor plugin = element.getDeclaringExtension().getDeclaringPluginDescriptor();
if (plugin.isPluginActivated()) {
return element.createExecutableExtension(classAttribute);
} else {
final Object[] ret = new Object[1];
final CoreException[] exc = new CoreException[1];
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
try {
ret[0] = element.createExecutableExtension(classAttribute);
} catch (CoreException e) {
exc[0] = e;
}
}
});
if (exc[0] != null)
throw exc[0];
else
return ret[0];
}
}
}

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* 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.wizards;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.WizardPage;
/**
* Base class for wizard page responsible to create Java elements. The class
* provides API to update the wizard's statis line and OK button according to
* the value of a <code>IStatus</code> object.
*
* @since 2.0
*/
public abstract class NewElementWizardPage extends WizardPage {
private IStatus fCurrStatus;
private boolean fPageVisible;
/**
* Creates a <code>NewElementWizardPage</code>.
*
* @param name the wizard page's name
*/
public NewElementWizardPage(String name) {
super(name);
fPageVisible= false;
fCurrStatus= new StatusInfo();
}
// ---- WizardPage ----------------
/*
* @see WizardPage#becomesVisible
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
fPageVisible= visible;
// policy: wizards are not allowed to come up with an error message
if (visible && fCurrStatus.matches(IStatus.ERROR)) {
StatusInfo status= new StatusInfo();
status.setError(""); //$NON-NLS-1$
fCurrStatus= status;
}
updateStatus(fCurrStatus);
}
/**
* Updates the status line and the ok button according to the given status
*
* @param status status to apply
*/
protected void updateStatus(IStatus status) {
fCurrStatus= status;
setPageComplete(!status.matches(IStatus.ERROR));
if (fPageVisible) {
StatusUtil.applyToStatusLine(this, status);
}
}
/**
* Updates the status line and the ok button according to the status evaluate from
* an array of status. The most severe error is taken. In case that two status with
* the same severity exists, the status with lower index is taken.
*
* @param status the array of status
*/
protected void updateStatus(IStatus[] status) {
updateStatus(StatusUtil.getMostSevere(status));
}
}

View file

@ -283,14 +283,6 @@ NewSnippetFileWizardPage.open_error.message=Error in NewScrapbookPage
NewContainerDialog.error.invalidpath=Invalid folder path: ''{0}''
NewContainerDialog.error.enterpath=Folder name must be entered
NewContainerDialog.error.pathexists=This folder is already in the list or it is an output folder.
# ------- NewSourceFolderDialog-------
NewSourceFolderDialog.useproject.button=&Project as source folder
NewSourceFolderDialog.usefolder.button=&Folder as source folder
NewSourceFolderDialog.sourcefolder.label=&Source folder name:
NewSourceFolderDialog.error.invalidpath=Invalid folder path: ''{0}''
NewSourceFolderDialog.error.enterpath=Folder name must be entered.
NewSourceFolderDialog.error.pathexists=The folder is already in the list.
# ------- SourceAttachmentBlock-------
@ -417,6 +409,3 @@ OutputLocationDialog.ChooseOutputFolder.description=&Choose the folder for the b
ClasspathContainerWizard.pagecreationerror.title= Library Wizard
ClasspathContainerWizard.pagecreationerror.message=Wizard page creation failed. Check log for details.
FolderSelectionDialog.button=Create &New Folder...
MultipleFolderSelectionDialog.button=Create &New Folder...

View file

@ -0,0 +1,75 @@
/*******************************************************************************
* 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.ui.wizards;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.jface.wizard.IWizardPage;
/**
* A path container page allows the user to create a new or edit an
* existing patch container entry.
* <p>
* Clients should implement this interface and include the name of their
* class in an extension contributed to the cdt.ui's path container page
* extension point (named <code>org.eclipse.cdt.ui.pathContainerPage
* </code>).
* </p>
* <p>
* Clients implementing this interface may subclass from
* <code>org.eclipse.jface.wizard.WizardPage</code>.
* </p>
*/
public interface ICPathContainerPage extends IWizardPage {
/**
* Method <code>initialize()</code> is called before <code>IClasspathContainerPage.setSelection</code>
* to give additional information about the context the classpath container entry is configured in. This information
* only reflects the underlying dialogs current selection state. The user still can make changes after the
* the classpath container pages has been closed or decide to cancel the operation.
* @param project The project the new or modified entry is added to. The project does not have to exist.
* Project can be <code>null</code>.
* @param currentEntries The class path entries currently selected to be set as the projects classpath. This can also
* include the entry to be edited.
*/
public void initialize(ICProject project, IPathEntry[] currentEntries);
/**
* Called when the classpath container wizard is closed by selecting
* the finish button. Implementers typically override this method to
* store the page result (new/changed path entry returned in
* getSelection) into its model.
*
* @return if the operation was succesful. Only when returned
* <code>true</code>, the wizard will close.
*/
public boolean finish();
/**
* Method {@link #getNewContainers()} is called instead of {@link IClasspathContainerPage#getSelection() }
* to get the the newly added containers. {@link IClasspathContainerPage#getSelection() } is still used
* to get the edited elements.
* @return the classpath entries created on the page. All returned entries must be {@link
* IClasspathEntry#CPE_CONTAINER}
*/
public IPathEntry[] getNewContainers();
/**
* Sets the path container entry to be edited or <code>null</code>
* if a new entry should be created.
*
* @param containerEntry the classpath entry to edit or <code>null</code>.
* If unequals <code>null</code> then the classpath entry must be of
* kind <code>IClasspathEntry.CPE_CONTAINER</code>
*/
public void setSelection(IPathEntry containerEntry);
}

View file

@ -0,0 +1,25 @@
/*
* Created on Apr 14, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.wizards;
import org.eclipse.cdt.core.model.IPathEntry;
public interface ICPathContainerPageExtension extends ICPathContainerPage {
/**
* Method {@link #getNewContainers()} is called instead of {@link IClasspathContainerPage#getSelection() }
* to get the the newly added containers. {@link IClasspathContainerPage#getSelection() } is still used
* to get the edited elements.
* @return the classpath entries created on the page. All returned entries must be {@link
* IClasspathEntry#CPE_CONTAINER}
*/
public IPathEntry[] getNewContainers();
}