From e20be2336bb6f55b60a6d84bdeac85a664966deb Mon Sep 17 00:00:00 2001 From: David Inglis Date: Thu, 15 Apr 2004 19:56:41 +0000 Subject: [PATCH] Work in progress - start of new C Path Container Wizard --- core/org.eclipse.cdt.ui/ChangeLog | 21 +- .../icons/full/wizban/addpath_wiz.gif | Bin 0 -> 2068 bytes core/org.eclipse.cdt.ui/plugin.xml | 2 + .../schema/CPathContainerPage.exsd | 116 ++++++++++ .../cdt/internal/ui/CPluginImages.java | 1 + .../cpaths/AbstractPathOptionBlock.java | 19 +- .../cpaths/CPathContainerDefaultPage.java | 134 ++++++++++++ .../cpaths/CPathContainerDescriptor.java | 107 ++++++++++ .../cpaths/CPathContainerSelectionPage.java | 144 +++++++++++++ .../dialogs/cpaths/CPathContainerWizard.java | 202 ++++++++++++++++++ .../cpaths/CPathEntryMessages.properties | 17 +- .../dialogs/cpaths/CPathIncludeEntryPage.java | 50 ++++- .../dialogs/cpaths/ExtendedCPathBasePage.java | 18 +- .../cpaths/MultipleFolderSelectionDialog.java | 3 +- .../dialogs/cpaths/NewSourceFolderDialog.java | 13 +- .../cdt/internal/ui/util/CoreUtility.java | 72 +++++++ .../ui/wizards/NewElementWizardPage.java | 82 +++++++ .../ui/wizards/NewWizardMessages.properties | 11 - .../cdt/ui/wizards/ICPathContainerPage.java | 75 +++++++ .../wizards/ICPathContainerPageExtension.java | 25 +++ 20 files changed, 1063 insertions(+), 49 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/icons/full/wizban/addpath_wiz.gif create mode 100644 core/org.eclipse.cdt.ui/schema/CPathContainerPage.exsd create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDefaultPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerSelectionPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewElementWizardPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPage.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPageExtension.java diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index d13c3845de8..bc00814bbd6 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.ui/icons/full/wizban/addpath_wiz.gif b/core/org.eclipse.cdt.ui/icons/full/wizban/addpath_wiz.gif new file mode 100644 index 0000000000000000000000000000000000000000..e0eea42216a836b03f134ddb6f873f47c9aef7e5 GIT binary patch literal 2068 zcmds$`8V4O8pgkgrIxxEwN%S(Xw*>*m$pOIttBF8tK6yvO+%EbeQ9r1b?mWAl%j$V zA@-n_HcCQBtP@KuMTCY5u>_aSbf%_e{)>6f=R7~Y@AI7Vymt0*Q!_6|;3{wk9M93w z(U$1zmgumfcWP*2d1zvZFWB7_eKmJaxA4fY@JP2rWm%#!tsi7tqqA+iaJHBnm=_L? z$$?|=h=;Fk`oDGxC~ykMcMd9a2`ao3^2RNU;1*Wo9$DfZS$zKw;)AGi^f6_aXp-+s zvVUAvU_y0Ba&2gGO+;$_(~QRF*-bGyEiw4!g#7lz{PwhBT6%FOoo09&6OUn4G!NEvj5g3X?Y&bS%;}!tdG;7@Vs346?#tAIU}kZh%io$`7OrmW z@dcu5o*BR0&$RGNzmCefj>@z`XT!XIq`=!fdY=Ty+~q;7mgcTPojUKOLThDoHdOB-24DvQ)ISlK#U-7#8E z<1}<~n!3i{GA3!PnXZ9PjNy6K7;k8Dd1Q*unOz;7=13wf*CT>hqT z=b)gbmr&nV`ePxLRoOON-^pobPIV1_V*Z`W9_I~CE=|m@ab{OWr$0||1^o5h<+Yvl z?Sr+=ebzW{Wcu^O{Fjeh!3=MGadmrvzd5(Ov9WWozWwLg=HB++*R9>dRpB0gU9`5f zzq$Lrn*6sb|97H)oap!$0I4HDOiCR=B{CAEPF?h5Q_Fg>^5-20h^F$sbTCGO!ww^{ z?y1|vGo_kH1Gsa)m#YuBoFB+H!u)ipP((uDOe5BFl>=g(N^_un6@u|f=VF8vSVR7f zVs%wx`D-oY+e$={J^uSinLk~t8_|xsYI-eovq`Wf-%M@UM;r=@k);uh9*A>(rfKCa zA@H`VJsT#;oo&8riqz3tq?Hbn~N5Wyw@?t=NNdT9C1cPu%i~Y()U;lz(;dRWP zGygfpv;w3CN(?-t%5Rf=@vRMG-0M{gx^%5SQlHH+j^6{>E^DqpY;q(aD6@f*?* zBW>;0Nqy~dnC{VUa=K4)rn0jr*S#zL4Fe2N>P{t};RIEGB9@2t0*eWy0s6wDh|DTg zpVihjRCK2NSc=XmGaPVg#=@#k;yx}8e8#XNju3vOBkr8|g7Tv`D7^jCUjl@`&L9$C z@?~t8B>)hUPA5~nun`>9Wm&qk-Fb1CioK7xtyU@@FAu~Ocsm*;^B%8N`@u5q^;6id zQ#&O=e(3nwiqt5JRfM8m&2)-_q3-}$E0w9{tbaKk=q-M>T3uBF0Zu$b=~nu$ zrj&)l#p8;vUs_)y;jCrE)QcFJ71jWqLs1kPo;;;bf_gD^Bm-TfKnYU2V!-V{MfwF$ z%@KvC5aj(%J3mzkC#9956q^Do{JxWhHj&$rF~Ct=m|7C*S}@I8$rNOr%o)Zn8OGc* zeuVcbydY47qcA=#Yr>3D&c< zWFTpcJ<%HKRB))klHp(-2yZ&+DPG%fC1ZznCD_=|_weyqzs3(&qS>02U-g8DlDjt? zq4k%%F}|SSI%;MpT^6h3zWjc(z4C=@u>Eqguo}u%9B!cP#4j~4>JBc4fGv6jCf(dO z;mw1eRmfuiwX^Q+h>26WT929eze2}cC45EW(qf_Teh_L}6?)aJKBU3w#8C_aq-zHa zu0kF9G&F}sTsy42EQTic7!MYNH01v6+o7hmgweA(h^Cyq9vtB9*Gd|4cg_pr!y-Q3 z-QL(-DUkiX4e%v_wi#7N^A-U}5)uRsB`~(gj2>eVy#GRsNG5Vq$;9DqT zj*SiTDP7qR)H2*@w`injpK=bek@9}4elUl#HHHqsp6l|F?Y?+Tz0Ey{(m-o4{5D94 zKtkoQ$*W0DkX-lqeMJbg4X>x-<@kD7hHbhBLK`BekRo*@vr<8N0Gu>Kr~A=YH7GBO zIu=_4^Xm7*Mq&(XJ^_YsMskv&0}er~RWYSRx60pwoa8nA0}bz0yo-aVC}oLBdz-F+ zh{+(CQpNs+o^K$8E9Ww4d^_a3vB!x6>8E0Fst1 z%hhTuzCz7$A5f?@aUIBn;}FFMFt&MKQ~U1Y8eiaVmFb)yE->SWK&j@yf4^S dyBzxE8`}RC-RD*6#+@oyr;1aQj4lK){|`ayo+|(V literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 4b339f72f39..97f7e8e25a3 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -31,6 +31,8 @@ + + diff --git a/core/org.eclipse.cdt.ui/schema/CPathContainerPage.exsd b/core/org.eclipse.cdt.ui/schema/CPathContainerPage.exsd new file mode 100644 index 00000000000..5dbdb034ca0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/schema/CPathContainerPage.exsd @@ -0,0 +1,116 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 521c83dfea5..2f7da3db330 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -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); 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 index fdb8654f042..1bc8961de0f 100644 --- 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 @@ -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. org.eclipse.ui.dialogs.ContainerGenerator 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); - } - } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDefaultPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDefaultPage.java new file mode 100644 index 00000000000..29845fb4f3a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDefaultPage.java @@ -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$ + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java new file mode 100644 index 00000000000..60206ef8f7f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDescriptor.java @@ -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()]); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerSelectionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerSelectionPage.java new file mode 100644 index 00000000000..6fd564134d3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerSelectionPage.java @@ -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); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java new file mode 100644 index 00000000000..2fb7ecd7c08 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerWizard.java @@ -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(); + } + +} \ No newline at end of file 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 06bc53ba94c..9ea195bd625 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 @@ -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... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java index 10419c2ee79..71262dfc715 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java @@ -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; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java index 7335cfd8738..d0276f29d6b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java @@ -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(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java index 7c3a11d5fb4..50de5233ecc 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java @@ -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) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java index a29ddb7b669..2e28cca618f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java @@ -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(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java new file mode 100644 index 00000000000..81b764dfd25 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java @@ -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. + * org.eclipse.ui.dialogs.ContainerGenerator 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]; + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewElementWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewElementWizardPage.java new file mode 100644 index 00000000000..f817f171c40 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewElementWizardPage.java @@ -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 IStatus object. + * + * @since 2.0 + */ +public abstract class NewElementWizardPage extends WizardPage { + + private IStatus fCurrStatus; + + private boolean fPageVisible; + + /** + * Creates a NewElementWizardPage. + * + * @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)); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties index 4393a41423c..96c2cb898ef 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties @@ -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... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPage.java new file mode 100644 index 00000000000..60c35b33291 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPage.java @@ -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. + *

+ * 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 org.eclipse.cdt.ui.pathContainerPage + * ). + *

+ *

+ * Clients implementing this interface may subclass from + * org.eclipse.jface.wizard.WizardPage. + *

+ */ + +public interface ICPathContainerPage extends IWizardPage { + + /** + * Method initialize() is called before IClasspathContainerPage.setSelection + * 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 null. + * @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 + * true, 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 null + * if a new entry should be created. + * + * @param containerEntry the classpath entry to edit or null. + * If unequals null then the classpath entry must be of + * kind IClasspathEntry.CPE_CONTAINER + */ + public void setSelection(IPathEntry containerEntry); +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPageExtension.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPageExtension.java new file mode 100644 index 00000000000..4cc1aa994de --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/ICPathContainerPageExtension.java @@ -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(); + +}