diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java index f82fcb250d9..3a97d3d97ef 100644 --- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/TemplateEngineHelper.java @@ -242,8 +242,8 @@ public class TemplateEngineHelper { } public static String externalizeTemplateString(String pluginId, String location, String key) { - String value = key; - if (key.startsWith(STRING_EXTERNALIZATION_MARKER)) { + String value= null; + if (key != null && key.startsWith(STRING_EXTERNALIZATION_MARKER)) { try { value = location != null ? getValueFromProperties(pluginId, location, key.substring(1)) : null; if (value == null) { @@ -253,18 +253,13 @@ public class TemplateEngineHelper { value = key; e.printStackTrace(); } - - if (value == null) { - value = key; - } } - return value; + return value == null ? key : value; } private static String getValueFromProperties(String pluginId, String propertiesFile, String key) throws IOException { String value = null; Bundle b = Platform.getBundle(pluginId); -// URL url= b.getResource(propertiesFile); URL url= getResourceURL(b, propertiesFile); if (url != null) { InputStream in= url.openStream(); diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml index 8a98421c5b1..1072a81b42a 100644 --- a/core/org.eclipse.cdt.ui.tests/plugin.xml +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -114,6 +114,11 @@ pagesAfterTemplateSelectionProvider="org.eclipse.cdt.ui.tests.templateengine.TestExtraPagesProvider" projectType="org.eclipse.cdt.build.core.buildArtefactType.exe"> + diff --git a/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/hello.cpp b/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/hello.cpp new file mode 100644 index 00000000000..7658866233b --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/hello.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int main() { + cout << "$(projectName)" << endl; + cout << "$(TestWidget1)" << endl; + cout << "$(TestWidget2)" << endl; + cout << "$(TestWidget3)" << endl; + cout << "$(TestWidget4)" << endl; + cout << "$(TestWidget5)" << endl; + cout << "$(TestWidget6)" << endl; + cout << "$(TestWidget7)" << endl; + cout << "$(TestWidget8)" << endl; + cout << "$(TestWidget9)" << endl; + cout << "$(TestWidget10)" << endl; + cout << "$(TestWidget11)" << endl; + cout << "$(TestWidget12)" << endl; + cout << "$(TestWidget13)" << endl; + cout << "$(TestWidget14)" << endl; + return 0; +} + diff --git a/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/template.xml b/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/template.xml new file mode 100644 index 00000000000..12e72b82975 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/template.xml @@ -0,0 +1,61 @@ + + diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java index c9bc05300be..e470b9e10f7 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/ProjectSelectionPage.java @@ -301,7 +301,7 @@ public class ProjectSelectionPage extends WizardPage implements IWizardDataPage return true; } } catch (CoreException e) { - CUIPlugin.getDefault().log(e); + CUIPlugin.log(e); currentCProject= null; } @@ -314,7 +314,7 @@ public class ProjectSelectionPage extends WizardPage implements IWizardDataPage try { projects= CoreModel.create(workspaceRoot).getCProjects(); } catch (CModelException e) { - CUIPlugin.getDefault().log(e); + CUIPlugin.log(e); projects= new ICProject[0]; } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/event/PatternEvent.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/event/PatternEvent.java index 1d79d21a685..caf513b8727 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/event/PatternEvent.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/event/PatternEvent.java @@ -16,7 +16,7 @@ import java.util.EventObject; * * PatternEvent class instances are created, when there is an unexpected input * in the InputUIElement. Which results in a mismatch to the pattern of input - * data exptected. This has to be updated in the UIPage. To do this, + * data expected. This has to be updated in the UIPage. To do this, * PatternEvent is fired. For which, the UIPage will be the registered listener. * Here UIPage stands for WizardPage. * diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/messages.properties b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/messages.properties index 56ecdc5258d..0fca1e90653 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/messages.properties +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/messages.properties @@ -35,6 +35,10 @@ ProjectSelectionPage.8=The project does not exist ProjectSelectionPage.9=Please select a CDT project ProjectSelectionPage.10=Project Selection ProjectSelectionPage.11=Choose a Project +UIElementTreeBuilderHelper.InvalidEmptyLabel=Invalid item element in with id="{0}": attributes 'label' and 'value' must be present. +UIElementTreeBuilderHelper.InvalidNonUniqueValue=Mappings between labels and values in not reversible for with id="{0}" +UIElementTreeBuilderHelper.UnknownWidgetType0=Unknown widget type: {0} +UISelectWidget_ErrorNoneSelected0=Please choose a value for {0} UITextWidget.0=\ Project already exists in workspace. SimpleElementException.0=This Operation not supported on InputUIElement diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java index bf604d6161d..6f66652b58c 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPage.java @@ -17,9 +17,7 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.templateengine.TemplateEngineUtil; @@ -27,7 +25,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.templateengine.uitree.UIElement; import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite; - /** * * The UIPage extends DialogPage, it implements the createControl() abstract @@ -35,13 +32,11 @@ import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite; * UIComposite, which extends a SWT composite. The SWT widgets are added to * UIComposite. */ - public abstract class UIPage extends DialogPage { - /** * The Composite belonging to this page. The SWT widgets are added to this Composite. UIComposite instance is the top level control of this page. This top level control is initialized in createControl method. */ - private UIComposite uiComposite; + protected UIComposite uiComposite; /** * resources ID which will be displayed as F1 help in Title area. @@ -51,12 +46,12 @@ public abstract class UIPage extends DialogPage { /** * The UIElement (group), to which this page corresponds. Every UIElement group corresponds to a UIPage. The children of this goup are UIElement's (SWT widgets). Which are added to the UIComposite. */ - private UIElement uiElement; + protected final UIElement uiElement; /** * ValueStore for this instance of Template. */ - private Map valueStore; + protected final Map valueStore; /** * Title set for this WizardPage. @@ -103,27 +98,6 @@ public abstract class UIPage extends DialogPage { pageId = CUIPlugin.getPluginId() + "." + (uiElement.getAttributes()).get(UIElement.ID); //$NON-NLS-1$ } - /** - * Creates the top level control for this dialog page under the given parent - * composite. - * - * @param parent - * the parent composite - */ - public void createControl(Composite parent) { - initializeDialogUnits(parent); - uiComposite = new UIComposite(parent, uiElement, valueStore); - - // set the focus so that InfoPop is displayed when F1 is Pressed. - uiComposite.setFocus(); - - setControl(uiComposite); - - // Setting InfoPop help context ID(plugin-id+ContextID). - PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), pageId); - - } - /** * The data contained in the Input elements (SWT widgets), on this page is * extracted and put into an HashMap. The same is returned. @@ -144,7 +118,6 @@ public abstract class UIPage extends DialogPage { return uiComposite; } - // This method is provided for unit tesing the UIComposite instance. /** * * This returns UICompostie as UIComposite instance. Unlike the getControl. @@ -154,5 +127,4 @@ public abstract class UIPage extends DialogPage { public UIComposite getComposite() { return uiComposite; } - } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java index a0ce51ade16..2b3416bec71 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIPagesProvider.java @@ -93,9 +93,9 @@ public class UIPagesProvider { } else { if ((hasChildUIElement(uiElement))) { - String title = uiElement.getAttributes().get(UIElement.TITLE); + String label = uiElement.getAttributes().get(UIElement.TITLE); String description = (uiElement.getAttributes()).get(UIElement.DESCRIPTION); - UIWizardPage uiPage = new UIWizardPage(title, description, uiElement, valueStore); + UIWizardPage uiPage = new UIWizardPage(label, description, uiElement, valueStore); pageMap.put((uiElement.getAttributes()).get(UIElement.ID), uiPage); addToOrderVector((uiElement.getAttributes()).get(UIElement.ID)); diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java index 914773af11f..ffb2a00a9cc 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/UIWizardPage.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.ui.templateengine.IWizardDataPage; import org.eclipse.cdt.ui.templateengine.event.PatternEvent; import org.eclipse.cdt.ui.templateengine.event.PatternEventListener; import org.eclipse.cdt.ui.templateengine.uitree.UIElement; +import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite; /** @@ -108,7 +109,7 @@ public class UIWizardPage extends UIPage implements IWizardDataPage, PatternEven } /** - * Retruns the dialog setting for this wizard page. null, if none exists. + * Returns the dialog setting for this wizard page. null, if none exists. * * @return IDialogSettings, if Wizard is not set null. */ @@ -258,25 +259,35 @@ public class UIWizardPage extends UIPage implements IWizardDataPage, PatternEven /** * Creates the top level control for this dialog page under the given parent - * composite. call the super createControl, get the Composite and set this - * page as PatternEventListener. + * composite. * * @param parent * the parent composite */ public void createControl(Composite parent) { - super.createControl(parent); - (super.getComposite()).addPatternListener(this); + initializeDialogUnits(parent); + uiComposite = new UIComposite(parent, uiElement, valueStore); + uiComposite.addPatternListener(this); + uiElement.createWidgets(uiComposite); + + // set the focus so that InfoPop is displayed when F1 is Pressed. + uiComposite.setFocus(); + + + setControl(uiComposite); + + // Setting InfoPop help context ID(plugin-id+ContextID). + PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), pageId); // Page complete is set true of false, based on Mandatory attribute // and Widgets contents. - setPageComplete(super.getComposite().isValid()); + setPageComplete(uiComposite.isValid()); PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), pageId); } /** * This method is implemented to handle the PatternEvent's generated by SWT - * widges contained in this page. When the user enters data violating the + * widgets contained in this page. When the user enters data violating the * pattern of data expected by this SWT widgets, a PatternEvent is fired to * the Container. Which has to reflect the same as an ErrorMeesage. Get the * source of the PatternEvent, and the error String causing the @@ -285,15 +296,15 @@ public class UIWizardPage extends UIPage implements IWizardDataPage, PatternEven */ public void patternPerformed(PatternEvent patternEvent) { if (!patternEvent.getValid()) { - + validInvalid.put(patternEvent.getSource(), patternEvent.toString()); setErrorMessage(getErrorString()); - setPageComplete(validInvalid.isEmpty() && super.getComposite().isValid()); + setPageComplete(validInvalid.isEmpty() && uiComposite.isValid()); } else { - + validInvalid.remove(patternEvent.getSource()); - setPageComplete(validInvalid.isEmpty() && super.getComposite().isValid()); + setPageComplete(validInvalid.isEmpty() && uiComposite.isValid()); if (validInvalid.isEmpty()) { setErrorMessage(null); } else { @@ -306,7 +317,7 @@ public class UIWizardPage extends UIPage implements IWizardDataPage, PatternEven /** * Iterate through the validInvalid HashMap, formulate the error string - * retrun the same. This will ensure that the proper error string is + * return the same. This will ensure that the proper error string is * updated. * * @return @@ -321,6 +332,5 @@ public class UIWizardPage extends UIPage implements IWizardDataPage, PatternEven } return message; } - } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/GenericUIElementGroup.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/GenericUIElementGroup.java index d66d5ca9e23..536c89377b2 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/GenericUIElementGroup.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/GenericUIElementGroup.java @@ -18,8 +18,8 @@ import java.util.Map; import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite; /** - * The GenericUIElementGroup extends UIElement, implements the default behaviour - * expected from UIElementGroup. This gives behaviour expected for PAGES-ONLY + * The GenericUIElementGroup extends UIElement, implements the default behavior + * expected from UIElementGroup. This gives behavior expected for PAGES-ONLY * type. Any other type of UIElement groups can override the definitions given * to methods in this class. * @@ -47,12 +47,12 @@ public class GenericUIElementGroup extends UIElement { private List childList; /** - * Call UIElement constructor by passing Attributes as param. + * Call UIElement constructor by passing Attributes as parameter. * - * @param attribute + * @param attributes */ - public GenericUIElementGroup(UIGroupTypeEnum type, UIAttributes/**/ attribute) { - super(attribute); + public GenericUIElementGroup(UIGroupTypeEnum type, UIAttributes attributes) { + super(attributes); this.type = type; this.childList = new ArrayList(); } @@ -98,11 +98,8 @@ public class GenericUIElementGroup extends UIElement { } } - /** - * dispose the Widget, releasing any resources occupied by this widget. The - * same is called on the child list. - * - * @see UIElement + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#disposeWidget() */ public void disposeWidget() { int childCount = getChildCount(); diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/InputUIElement.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/InputUIElement.java index 611cee1284e..8d73fdbb979 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/InputUIElement.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/InputUIElement.java @@ -20,28 +20,40 @@ import org.eclipse.cdt.ui.templateengine.SimpleElementException; * */ public abstract class InputUIElement extends UIElement { - - public static final String INPUTTYPE = new String("input"); //$NON-NLS-1$ - public static final String MULTILINETYPE = new String("multiline"); //$NON-NLS-1$ - public static final String SELECTTYPE = new String("select"); //$NON-NLS-1$ - public static final String BOOLEANTYPE = new String("boolean"); //$NON-NLS-1$ - public static final String BROWSETYPE = new String("browse"); //$NON-NLS-1$ - public static final String STRINGLISTTYPE = new String("stringlist"); //$NON-NLS-1$ - public static final String SPECIALLISTTYPE = new String("speciallist"); //$NON-NLS-1$ - public static final String MANDATORY = new String("mandatory"); //$NON-NLS-1$ - public static final String INPUTPATTERN = new String("pattern"); //$NON-NLS-1$ - public static final String DEFAULT = new String("default"); //$NON-NLS-1$ - public static final String WIDGETLABEL = new String("label"); //$NON-NLS-1$ - public static final String BROWSELABEL = new String(" Browse.. "); //$NON-NLS-1$ - public static final String CONTENTS = new String(" contents"); //$NON-NLS-1$ - public static final String ISINVALID = new String(" is Invalid. "); //$NON-NLS-1$ - public static final String CHECKPROJECT = new String("checkproject"); //$NON-NLS-1$ - public static final String NULL = new String("null"); //$NON-NLS-1$ - public static final String SIZE = new String("size"); //$NON-NLS-1$ - public static final String HIDDEN = new String("hidden"); //$NON-NLS-1$ - public static final String NAME = new String("name"); //$NON-NLS-1$ - public static final String SELECTED = new String("selected"); //$NON-NLS-1$ - + public static final String INPUTTYPE= "input"; //$NON-NLS-1$ + public static final String MULTILINETYPE= "multiline"; //$NON-NLS-1$ + public static final String SELECTTYPE= "select"; //$NON-NLS-1$ + public static final String BOOLEANTYPE= "boolean"; //$NON-NLS-1$ + public static final String BROWSETYPE= "browse"; //$NON-NLS-1$ + public static final String STRINGLISTTYPE= "stringlist"; //$NON-NLS-1$ + public static final String SPECIALLISTTYPE= "speciallist"; //$NON-NLS-1$ + public static final String MANDATORY= "mandatory"; //$NON-NLS-1$ + public static final String INPUTPATTERN="pattern"; //$NON-NLS-1$ + public static final String DEFAULT= "default"; //$NON-NLS-1$ + public static final String WIDGETLABEL= "label"; //$NON-NLS-1$ + public static final String BROWSELABEL= " Browse.. "; //$NON-NLS-1$ + public static final String CONTENTS= " contents"; //$NON-NLS-1$ + public static final String ISINVALID= " is Invalid. "; //$NON-NLS-1$ + public static final String CHECKPROJECT= "checkproject"; //$NON-NLS-1$ + public static final String NULL= "null"; //$NON-NLS-1$ + public static final String SIZE= "size"; //$NON-NLS-1$ + public static final String HIDDEN= "hidden"; //$NON-NLS-1$ + + /** + * The string appearing in the Combo box + */ + public static final String COMBOITEM_LABEL= "label"; //$NON-NLS-1$ + + /** + * Alternative attribute name for the value stored when the corresponding Combo item is selected. + * See Bugzilla 222954. + */ + public static final String COMBOITEM_NAME= "name"; //$NON-NLS-1$ + + /** + * Preferred attribute name for the value stored when the corresponding Combo item is selected. + */ + public static final String COMBOITEM_VALUE= "value"; //$NON-NLS-1$ protected InputUIElement(UIAttributes uiAttribute) { super(uiAttribute); diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElement.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElement.java index f87a65cf0dd..e41e34e1e36 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElement.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElement.java @@ -17,12 +17,16 @@ import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite; /** - * UIElement describes the abstract behaviour expected from GenericUIElementGroup and + * UIElement describes the abstract behavior expected from GenericUIElementGroup and * InputUIElement. Some of the methods are meaningful to group Element. They will throw * SimpleElementException when invoked on InputUIElement. */ - public abstract class UIElement { + public static final String ID = "id"; //$NON-NLS-1$ + public static final String TYPE = "type"; //$NON-NLS-1$ + public static final String DESCRIPTION = "description"; //$NON-NLS-1$ + public static final String TITLE = "label"; //$NON-NLS-1$ + public static final String IMAGELOCATION = "image"; //$NON-NLS-1$ /** * Parent of this UIElement @@ -32,16 +36,10 @@ public abstract class UIElement { /** * Attributes of this UIElement */ - protected UIAttributes/**/ attribute; - public static final String ID = "id"; //$NON-NLS-1$ - public static final String TYPE = "type"; //$NON-NLS-1$ - public static final String DESCRIPTION = "description"; //$NON-NLS-1$ - public static final String TITLE = "label"; //$NON-NLS-1$ - public static final String IMAGELOCATION = "image"; //$NON-NLS-1$ - + protected UIAttributes uiAttributes; - public UIElement(UIAttributes/* */uiAttribute) { - attribute = uiAttribute; + public UIElement(UIAttributes uiAttributes) { + this.uiAttributes = uiAttributes; } /** @@ -62,7 +60,7 @@ public abstract class UIElement { * get the attributes of this UIElement */ public UIAttributes getAttributes() { - return attribute; + return uiAttributes; } /** diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderHelper.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderHelper.java index ed2d484ca9c..393b7e3fae2 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderHelper.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderHelper.java @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.ui.templateengine.uitree; -import java.util.HashMap; +import java.text.MessageFormat; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -19,8 +21,9 @@ import org.w3c.dom.Node; import org.eclipse.cdt.core.templateengine.TemplateDescriptor; import org.eclipse.cdt.core.templateengine.TemplateEngine; -import org.eclipse.cdt.core.templateengine.TemplateEngineHelper; import org.eclipse.cdt.core.templateengine.TemplateInfo; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.templateengine.Messages; import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIBooleanWidget; import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIBrowseWidget; import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UISelectWidget; @@ -33,15 +36,12 @@ import org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UITextWidget; * UIElement. The UIElement can be a simple UI Widget or a group. */ public class UIElementTreeBuilderHelper implements IUIElementTreeBuilderHelper { - /** * TemplateDescriptor representing the TemplaeDescriptor XML. */ private TemplateDescriptor templateDescriptor = null; private TemplateInfo templateInfo; - private Element element; - /** * Constructor, takes an TemplateDescriptor instance as parameter. * @@ -70,20 +70,15 @@ public class UIElementTreeBuilderHelper implements IUIElementTreeBuilderHelper { * @return UIElement. */ public UIElement getUIElement(Element element) { - - this.element = element; - UIElement retUIElement = null; - UIAttributes/**/ uiAttributes = new UIAttributes/**/(templateInfo); + UIAttributes uiAttributes = new UIAttributes(templateInfo); NamedNodeMap list = element.getAttributes(); - for (int i = 0, s = list.getLength(); i < s; i++) { + for (int i=0; i*/ uiAttributes) { - + private UIElement getUIWidget(Element element, UIAttributes uiAttributes) { + UIElement widgetElement= null; + String id= uiAttributes.get(InputUIElement.ID); String type= uiAttributes.get(InputUIElement.TYPE); - - UIElement widgetElement = null; - String itemName = null; - String itemValue = null; - String itemSelected = null; - String nameStr = null; - String valueStr = null; - String selected = null; - - if (new Boolean(uiAttributes.get(InputUIElement.HIDDEN)).booleanValue()) + + if (type == null || type.length()==0 ) { return null; - if (type.equalsIgnoreCase("") || type == null) //$NON-NLS-1$ - return null; - - // UIWidgets - if (type.equalsIgnoreCase(InputUIElement.INPUTTYPE)) { - widgetElement = new UITextWidget(uiAttributes); - } - - if (type.equalsIgnoreCase(InputUIElement.MULTILINETYPE)) { - widgetElement = new UITextWidget(uiAttributes); - } - - if (type.equalsIgnoreCase(InputUIElement.SELECTTYPE)) { - - HashMap itemMap = new HashMap(); - List itemList = TemplateEngine.getChildrenOfElement(element); - - for (int i = 0, l = itemList.size(); i < l; i++) { - Element itemElement = itemList.get(i); - NamedNodeMap itemAttrList = itemElement.getAttributes(); - - for (int j = 0, l1 = itemAttrList.getLength(); j < l1; j++) { - Node itemAttr = itemAttrList.item(j); - itemName = itemAttr.getNodeName(); - itemValue = itemAttr.getNodeValue(); - - if (itemName.equals(InputUIElement.TITLE)) { - - selected = itemValue; - nameStr = new String(itemValue); - } else if (itemName.equals(InputUIElement.NAME)) - valueStr = new String(itemValue); - - if (itemName.equals(InputUIElement.SELECTED)) - if (itemValue.equals(TemplateEngineHelper.BOOLTRUE)) - itemSelected = selected; - - itemMap.put(nameStr, valueStr); - } - } - - widgetElement = new UISelectWidget(uiAttributes, itemMap, itemSelected); - } - - if (type.equalsIgnoreCase(InputUIElement.BOOLEANTYPE)) { - widgetElement = new UIBooleanWidget(uiAttributes); - } - - if (type.equalsIgnoreCase(InputUIElement.BROWSETYPE)) { - widgetElement = new UIBrowseWidget(uiAttributes); - } - - if (type.equalsIgnoreCase(InputUIElement.STRINGLISTTYPE)) { - widgetElement = new UIStringListWidget(uiAttributes); } - if (type.equalsIgnoreCase(InputUIElement.SPECIALLISTTYPE)) { + if (new Boolean(uiAttributes.get(InputUIElement.HIDDEN)).booleanValue()) { + return null; + } + + if (type.equalsIgnoreCase(InputUIElement.INPUTTYPE)) { + widgetElement = new UITextWidget(uiAttributes); + } else if (type.equalsIgnoreCase(InputUIElement.MULTILINETYPE)) { + widgetElement = new UITextWidget(uiAttributes); + } else if (type.equalsIgnoreCase(InputUIElement.SELECTTYPE)) { + String defaultValue= element.getAttribute(InputUIElement.DEFAULT); + + Map value2name= new LinkedHashMap(); + for(Element item : TemplateEngine.getChildrenOfElement(element)) { + String label= item.getAttribute(InputUIElement.COMBOITEM_LABEL); // item displayed in Combo + String value= item.getAttribute(InputUIElement.COMBOITEM_NAME); // value stored when its selected + if(value.length() == 0) { + value= item.getAttribute(InputUIElement.COMBOITEM_VALUE); + } + if(label==null || value==null) { + String msg= Messages.getString("UIElementTreeBuilderHelper.InvalidEmptyLabel"); //$NON-NLS-1$ + CUIPlugin.log(MessageFormat.format(msg, id), null); + } else { + if(value2name.put(value, label)!=null) { + String msg= Messages.getString("UIElementTreeBuilderHelper.InvalidNonUniqueValue"); //$NON-NLS-1$ + CUIPlugin.log(MessageFormat.format(msg, id), null); + } + } + } + + widgetElement = new UISelectWidget(uiAttributes, value2name, defaultValue); + } else if (type.equalsIgnoreCase(InputUIElement.BOOLEANTYPE)) { + String defaultValue= element.getAttribute(InputUIElement.DEFAULT); + boolean b= Boolean.parseBoolean(defaultValue); + widgetElement = new UIBooleanWidget(uiAttributes, b); + } else if (type.equalsIgnoreCase(InputUIElement.BROWSETYPE)) { + widgetElement = new UIBrowseWidget(uiAttributes); + } else if (type.equalsIgnoreCase(InputUIElement.STRINGLISTTYPE)) { + widgetElement = new UIStringListWidget(uiAttributes); + } else if (type.equalsIgnoreCase(InputUIElement.SPECIALLISTTYPE)) { widgetElement = new UISpecialListWidget(uiAttributes); - } - - // PAGES(Groups). - - if (type.equalsIgnoreCase(UIGroupTypeEnum.PAGES_ONLY.getId())) { + } else if (type.equalsIgnoreCase(UIGroupTypeEnum.PAGES_ONLY.getId())) { widgetElement = new SimpleUIElementGroup(uiAttributes); - } - - if (type.equalsIgnoreCase(UIGroupTypeEnum.PAGES_TAB.getId())) { + } else if (type.equalsIgnoreCase(UIGroupTypeEnum.PAGES_TAB.getId())) { // Note: This is not implemented now as we haven't found a use case // for generating UI pages as TABS in a single page. + } else { + String msg= MessageFormat.format(Messages.getString("UIElementTreeBuilderHelper.UnknownWidgetType0"), type); //$NON-NLS-1$ + CUIPlugin.log(msg, null); } return widgetElement; diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderManager.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderManager.java index 7296f6a22ce..b7e05016fad 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderManager.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/UIElementTreeBuilderManager.java @@ -47,7 +47,7 @@ import org.eclipse.cdt.ui.templateengine.SimpleElementException; public class UIElementTreeBuilderManager implements IUIElementTreeBuilderManager { /** - * referenc to iUIElementTreeBuilderHelper, which returns UIElement for Element. + * reference to iUIElementTreeBuilderHelper, which returns UIElement for Element. */ private UIElementTreeBuilderHelper uiElementTreeBuilderHelper; @@ -75,9 +75,9 @@ public class UIElementTreeBuilderManager implements IUIElementTreeBuilderManager } if ((uiParent != null) && (uiParent instanceof GenericUIElementGroup)) { - List/**/ childList = TemplateEngine.getChildrenOfElement(element); + List childList = TemplateEngine.getChildrenOfElement(element); for (int listIndex = 0, l = childList.size(); listIndex < l; listIndex++) { - UIElement uiElement = uiElementTreeBuilderHelper.getUIElement((Element) childList.get(listIndex)); + UIElement uiElement = uiElementTreeBuilderHelper.getUIElement(childList.get(listIndex)); if (uiElement != null) { uiElement.setParent(uiParent); } else { @@ -88,7 +88,7 @@ public class UIElementTreeBuilderManager implements IUIElementTreeBuilderManager } catch (SimpleElementException exp) { TemplateEngineUtil.log(exp); } - createUIElementTree(uiElement, (Element) childList.get(listIndex)); + createUIElementTree(uiElement, childList.get(listIndex)); } } } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBooleanWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBooleanWidget.java index a340a1bdd3a..6acedd1b2bd 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBooleanWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBooleanWidget.java @@ -22,7 +22,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -import org.eclipse.cdt.core.templateengine.TemplateEngineHelper; import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement; import org.eclipse.cdt.ui.templateengine.uitree.UIAttributes; import org.eclipse.cdt.ui.templateengine.uitree.UIElement; @@ -31,14 +30,7 @@ import org.eclipse.cdt.ui.templateengine.uitree.UIElement; /** * This gives a Label and Boolean widget. */ - public class UIBooleanWidget extends InputUIElement { - - /** - * Attributes associated with this widget. - */ - protected UIAttributes/**/ uiAttribute; - /** * Boolean widget. */ @@ -59,64 +51,54 @@ public class UIBooleanWidget extends InputUIElement { /** * Constructor. * - * @param uiAttribute + * @param uiAttributes * attribute associated with this widget. */ - public UIBooleanWidget(UIAttributes/**/ uiAttribute) { - super(uiAttribute); - this.uiAttribute = uiAttribute; - this.booleanValue = false; + public UIBooleanWidget(UIAttributes uiAttributes, boolean defaultValue) { + super(uiAttributes); + this.booleanValue= defaultValue; } /** * @return HashMap which contains the values in the Boolean Widget. */ public Map getValues() { - - Map retMap = new HashMap(); - retMap.put(uiAttribute.get(InputUIElement.ID), new Boolean(booleanValue).toString()); - - return retMap; + Map values = new HashMap(); + values.put(uiAttributes.get(InputUIElement.ID), Boolean.toString(booleanValue)); + return values; } - /** - * Set the Boolean widget with new value. - * - * @param valueMap + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#setValues(java.util.Map) */ - @Override public void setValues(Map valueMap) { - booleanValue = new Boolean(valueMap.get(uiAttribute.get(InputUIElement.ID))).booleanValue(); + booleanValue = new Boolean(valueMap.get(uiAttributes.get(InputUIElement.ID))).booleanValue(); } - /** - * create a Label and Boolean widget, add it to UIComposite. set Layout for - * the widgets to be added to UIComposite. set required parameters to the - * Widgets. - * - * @param uiComposite + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#createWidgets(org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite) */ public void createWidgets(UIComposite uiComposite) { GridData gridData = null; this.uiComposite = uiComposite; label = new Label(uiComposite, SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); - if (uiAttribute.get(InputUIElement.DESCRIPTION) != null){ - String tipText = uiAttribute.get(UIElement.DESCRIPTION); + if (uiAttributes.get(InputUIElement.DESCRIPTION) != null){ + String tipText = uiAttributes.get(UIElement.DESCRIPTION); tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ label.setToolTipText(tipText); } gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; - Composite booleanConatiner = new Composite(uiComposite, SWT.NONE); + Composite booleanContainer = new Composite(uiComposite, SWT.NONE); GridData gridcData = new GridData(GridData.FILL_HORIZONTAL); - booleanConatiner.setLayout(new GridLayout()); - booleanConatiner.setLayoutData(gridcData); - button = new Button(booleanConatiner, SWT.CHECK); - button.setData(".uid", uiAttribute.get(UIElement.ID)); //$NON-NLS-1$ + booleanContainer.setLayout(new GridLayout()); + booleanContainer.setLayoutData(gridcData); + button = new Button(booleanContainer, SWT.CHECK); + button.setData(".uid", uiAttributes.get(UIElement.ID)); //$NON-NLS-1$ button.setSelection(new Boolean(booleanValue).booleanValue()); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { @@ -125,31 +107,23 @@ public class UIBooleanWidget extends InputUIElement { }); } - /** - * Based on the stae of this Widget return true or false. This return value - * will be used by the UIPage to update its(UIPage) state. Return value - * depends on the value contained in Boolean Widget. If boolean value - * contained is false and Mandatory value from attributes. - * - * @return boolean. + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#isValid() */ public boolean isValid() { - boolean retVal = true; - String mandatory = uiAttribute.get(InputUIElement.MANDATORY); - - if (!booleanValue && mandatory.equalsIgnoreCase(TemplateEngineHelper.BOOLTRUE)) { - retVal = false; + boolean retVal= true; + String mandatory= uiAttributes.get(InputUIElement.MANDATORY); + if (!booleanValue && Boolean.parseBoolean(mandatory)) { + retVal= false; } return retVal; } - /** - * call the dispose method on the widgets. This is to ensure that the - * widgets are properly disposed. + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#disposeWidget() */ public void disposeWidget() { label.dispose(); button.dispose(); } - } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBrowseWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBrowseWidget.java index a4c39d38dd2..b57db84d3f8 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBrowseWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIBrowseWidget.java @@ -46,7 +46,6 @@ public class UIBrowseWidget extends UITextWidget implements ModifyListener { */ public UIBrowseWidget(UIAttributes uiAttribute) { super(uiAttribute); - this.uiAttribute = uiAttribute; this.textValue = uiAttribute.get(InputUIElement.DEFAULT); } @@ -61,11 +60,11 @@ public class UIBrowseWidget extends UITextWidget implements ModifyListener { uiComposite = composite; label = new Label(uiComposite, SWT.NONE | SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); // set the tool tip text - if (uiAttribute.get(UIElement.DESCRIPTION) != null){ - String tipText = uiAttribute.get(UIElement.DESCRIPTION); + if (uiAttributes.get(UIElement.DESCRIPTION) != null){ + String tipText = uiAttributes.get(UIElement.DESCRIPTION); tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$, //$NON-NLS-2$ label.setToolTipText(tipText); } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIComposite.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIComposite.java index ae1be36a522..d6c8539fc46 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIComposite.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIComposite.java @@ -25,7 +25,7 @@ import org.eclipse.cdt.ui.templateengine.uitree.UIElement; /** * By extending Composite we can create our own Container. UIComposite can act - * as the brdige between the UIPage and the UIWidgets contained in that page. + * as the bridge between the UIPage and the UIWidgets contained in that page. * The PatternEvents generated by the UIWidgets will be fired to the UIPage * which is a PatternEventListener. */ @@ -33,7 +33,7 @@ import org.eclipse.cdt.ui.templateengine.uitree.UIElement; public class UIComposite extends Composite { /** - * The gruop UIElement corresponding to this UIPage. + * The group UIElement corresponding to this UIPage. */ private UIElement uiElement; @@ -59,7 +59,6 @@ public class UIComposite extends Composite { this.setLayoutData(new GridData(GridData.FILL_BOTH)); this.uiElement = uiElement; - this.uiElement.createWidgets(this); } /** diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISelectWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISelectWidget.java index e5f965c7283..f13b82bd704 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISelectWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISelectWidget.java @@ -11,58 +11,46 @@ package org.eclipse.cdt.ui.templateengine.uitree.uiwidgets; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import java.util.Set; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -import org.eclipse.cdt.core.templateengine.TemplateEngineHelper; +import com.ibm.icu.text.MessageFormat; + +import org.eclipse.cdt.ui.templateengine.Messages; +import org.eclipse.cdt.ui.templateengine.event.PatternEvent; import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement; import org.eclipse.cdt.ui.templateengine.uitree.UIAttributes; import org.eclipse.cdt.ui.templateengine.uitree.UIElement; - /** * This gives a Label and Combo widget. */ public class UISelectWidget extends InputUIElement { - /** - * Attributes associated with this widget. - */ - protected UIAttributes uiAttribute; - - /** - * Select widget. - */ - protected Combo combo = null; - - /** - * Label of this widget. - */ protected Label label; + protected Combo combo; /** - * Composite to which this widget control is added. + * Mapping from values stored by this combo, to their associated names in UI */ - protected UIComposite uiComposite; + protected Map value2name; /** - * Map contains the values of Select Widget + * The default name to select */ - protected HashMap/**/ itemMap; + protected String defaultValue; /** - * Default value of Select Widget + * The currently selected name. May be null. */ - protected String itemSelected; + protected String currentValue; /** * Constructor for Select Widget. @@ -70,34 +58,32 @@ public class UISelectWidget extends InputUIElement { * @param attribute * attribute associated with this widget. */ - public UISelectWidget(UIAttributes/**/ attribute, HashMap/**/ itemMap, - String itemSelected) { + public UISelectWidget(UIAttributes attribute, Map value2name, String defaultValue) { super(attribute); - uiAttribute = attribute; - this.itemMap = itemMap; - this.itemSelected = itemSelected; + this.value2name= value2name; + this.defaultValue= defaultValue; } + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#getValues() + */ public Map getValues() { - - Map retMap = new HashMap(); - retMap.put(uiAttribute.get(InputUIElement.ID), itemSelected); - - return retMap; + Map values = new HashMap(); + if(currentValue != null) { + values.put(uiAttributes.get(InputUIElement.ID), currentValue); + } + return values; } - /** - * Set the Text widget with new value. - * - * @param valueMap + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#setValues(java.util.Map) */ public void setValues(Map valueMap) { - itemSelected = valueMap.get(uiAttribute.get(InputUIElement.ID)); - + defaultValue= valueMap.get(uiAttributes.get(InputUIElement.ID)); if (combo != null) { - String[] items = combo.getItems(); + String[] items= combo.getItems(); for (int i=0; i < items.length; i++) { - if (items[i].equals(itemSelected)) { + if (items[i].equals(defaultValue)) { combo.select(i); break; } @@ -105,84 +91,73 @@ public class UISelectWidget extends InputUIElement { } } - /** - * create a Label and Text widget, add it to UIComposite. set Layout for the - * widgets to be added to UIComposite. set required parameters to the - * Widgets. - * - * @param composite + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#createWidgets(org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite) */ - public void createWidgets(UIComposite composite) { - GridData gridData = null; - uiComposite = composite; + public void createWidgets(final UIComposite uiComposite) { + label= new Label(uiComposite, SWT.LEFT); + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); - label = new Label(composite, SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); + Composite comboComposite = new Composite(uiComposite, SWT.NONE); + comboComposite.setLayout(GridLayoutFactory.swtDefaults().create()); + comboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; + combo= new Combo(comboComposite, SWT.DROP_DOWN | SWT.READ_ONLY); + combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); + combo.setData(".uid", uiAttributes.get(UIElement.ID)); //$NON-NLS-1$ - Composite comboComposite = new Composite(composite, SWT.NONE); - - gridData = new GridData(GridData.FILL_HORIZONTAL); - comboComposite.setLayout(new GridLayout()); - comboComposite.setLayoutData(gridData); - - combo = new Combo(comboComposite, SWT.DROP_DOWN | SWT.READ_ONLY); - - Set keySet = itemMap.keySet(); - Iterator mapIterator = keySet.iterator(); - - int index = 0; - int i = 0; - while (mapIterator.hasNext()) { - - String key = (String) mapIterator.next(); - combo.add(key); - if (itemSelected.equals(key)) - index = i; - i++; - } - - combo.select(index); - combo.setData(".uid", uiAttribute.get(UIElement.ID)); //$NON-NLS-1$ - combo.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - itemSelected = combo.getItem(combo.getSelectionIndex()); + // populate combo + int index= 0, defaultIndex= 0; + for(String name : value2name.values()) { + combo.add(name); + if(name.equals(defaultValue)) { + defaultIndex= index; } - - public void widgetDefaultSelected(SelectionEvent e) { + index++; + + } + combo.select(defaultIndex); + combo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + currentValue= getValue(combo.getItem(combo.getSelectionIndex())); + uiComposite.firePatternEvent(createPatternEvent()); } }); + uiComposite.firePatternEvent(createPatternEvent()); + } + + private PatternEvent createPatternEvent() { + String msg= MessageFormat.format(Messages.getString("UISelectWidget_ErrorNoneSelected0"), new String[] {label.getText()}); //$NON-NLS-1$ + return new PatternEvent(this, msg, isValid()); } /** - * Based on the stae of this Widget return true or false. This return value - * will be used by the UIPage to update its(UIPage) state. Return value - * depends on the value contained in Select Widget. If value contained is - * null, "" and Mandatory value from attributes. - * - * @return boolean. + * @return whether this widget has been set to a valid state. For this + * widget type that means whether the user has selected a non-empty string name. */ public boolean isValid() { boolean retVal = true; - String mandatory = uiAttribute.get(InputUIElement.MANDATORY); - - if ((itemSelected == null || itemSelected.equals("") //$NON-NLS-1$ - || itemSelected.trim().length() < 1) && (mandatory.equalsIgnoreCase(TemplateEngineHelper.BOOLTRUE))) { - retVal = false; + if(Boolean.parseBoolean(uiAttributes.get(InputUIElement.MANDATORY))) { + retVal= currentValue!= null && currentValue.trim().length()>0; } return retVal; } - /** - * call the dispose method on the widgets. This is to ensure that the - * widgets are properly disposed. + private String getValue(String name) { + for(String value : value2name.keySet()) { + if(value2name.get(value).equals(name)) { + return value; + } + } + throw new IllegalStateException(); + } + + + /* + * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#disposeWidget() */ public void disposeWidget() { label.dispose(); combo.dispose(); } - } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISpecialListWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISpecialListWidget.java index 708079204e2..bcd5a8d23da 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISpecialListWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UISpecialListWidget.java @@ -30,7 +30,6 @@ import org.eclipse.cdt.utils.ui.controls.IFileListChangeListener; * */ public class UISpecialListWidget extends UIStringListWidget { - /** * Constructor. * @@ -39,7 +38,6 @@ public class UISpecialListWidget extends UIStringListWidget { */ public UISpecialListWidget(UIAttributes attribute) { super(attribute); - uiAttribute = attribute; } /** @@ -47,38 +45,40 @@ public class UISpecialListWidget extends UIStringListWidget { * widgets to be added to UIComposite. set required parameters to the * Widgets. * - * @param composite + * @param uiComposite */ - public void createWidgets(UIComposite composite) { + public void createWidgets(final UIComposite uiComposite) { GridData gridData = null; - uiComposite = composite; - label = new Label(composite, SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); + label = new Label(uiComposite, SWT.LEFT); + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); GridData gd = new GridData(); gd.verticalAlignment = SWT.BEGINNING; gd.verticalIndent = 5; label.setLayoutData(gd); - if (uiAttribute.get(InputUIElement.DESCRIPTION) != null){ - String tipText = uiAttribute.get(UIElement.DESCRIPTION); + if (uiAttributes.get(InputUIElement.DESCRIPTION) != null){ + String tipText = uiAttributes.get(UIElement.DESCRIPTION); tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$, //$NON-NLS-2$ label.setToolTipText(tipText); } - Composite flcComposite = new Composite(composite, SWT.NONE); + Composite flcComposite = new Composite(uiComposite, SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL); flcComposite.setLayout(new GridLayout()); flcComposite.setLayoutData(gridData); - fileListControl = new FileListControl(flcComposite, uiAttribute.get(InputUIElement.WIDGETLABEL), 1); - fileListControl.setList((String[])itemsList.toArray()); + fileListControl = new FileListControl(flcComposite, uiAttributes.get(InputUIElement.WIDGETLABEL), 1); + fileListControl.setList(itemsList.toArray(new String[itemsList.size()])); fileListControl.setSelection(0); fileListControl.addChangeListener(new IFileListChangeListener(){ public void fileListChanged(FileListControl fileList, String oldValue[], String newValue[]) { + itemsList.clear(); itemsList.addAll(Arrays.asList(newValue)); + uiComposite.firePatternEvent(createPatternEvent()); } }); + uiComposite.firePatternEvent(createPatternEvent()); } /** diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIStringListWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIStringListWidget.java index 97255ef5f45..6a918d1e787 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIStringListWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UIStringListWidget.java @@ -24,7 +24,10 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; +import com.ibm.icu.text.MessageFormat; + import org.eclipse.cdt.core.templateengine.TemplateEngineHelper; +import org.eclipse.cdt.ui.templateengine.event.PatternEvent; import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement; import org.eclipse.cdt.ui.templateengine.uitree.UIAttributes; import org.eclipse.cdt.ui.templateengine.uitree.UIElement; @@ -36,14 +39,7 @@ import org.eclipse.cdt.utils.ui.controls.IFileListChangeListener; * This gives a Label and StringList Widget. * */ - public class UIStringListWidget extends InputUIElement { - - /** - * Attributes associated with this widget. - */ - protected UIAttributes/**/ uiAttribute; - /** * StringList widget. */ @@ -54,11 +50,6 @@ public class UIStringListWidget extends InputUIElement { */ protected Label label; - /** - * Composite to which this widget control is added. - */ - protected UIComposite uiComposite; - protected List itemsList; /** @@ -69,7 +60,6 @@ public class UIStringListWidget extends InputUIElement { */ public UIStringListWidget(UIAttributes attribute) { super(attribute); - uiAttribute = attribute; itemsList = new ArrayList(); } @@ -82,7 +72,7 @@ public class UIStringListWidget extends InputUIElement { for (int i = 0; i < itemsList.size(); i++) { itemString = itemString + itemsList.get(i) + "|"; //$NON-NLS-1$ } - retMap.put(uiAttribute.get(InputUIElement.ID), itemString); + retMap.put(uiAttributes.get(InputUIElement.ID), itemString); return retMap; } @@ -92,8 +82,8 @@ public class UIStringListWidget extends InputUIElement { * * @param valueMap */ - public void setValues(Map/**/ valueMap) { - String items = (String) valueMap.get(uiAttribute.get(InputUIElement.ID)); + public void setValues(Map valueMap) { + String items = (String) valueMap.get(uiAttributes.get(InputUIElement.ID)); if (items != null) { items = items.trim(); @@ -109,22 +99,21 @@ public class UIStringListWidget extends InputUIElement { * for the widgets to be added to UIComposite. set required parameters to * the Widgets. * - * @param composite + * @param uiComposite */ - public void createWidgets(UIComposite composite) { + public void createWidgets(final UIComposite uiComposite) { GridData gridData = null; - uiComposite = composite; - label = new Label(composite, SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); + label = new Label(uiComposite, SWT.LEFT); + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); GridData gd = new GridData(); gd.verticalAlignment = SWT.BEGINNING; gd.verticalIndent = 5; label.setLayoutData(gd); - if (uiAttribute.get(InputUIElement.DESCRIPTION) != null){ - String tipText = uiAttribute.get(UIElement.DESCRIPTION); + if (uiAttributes.get(InputUIElement.DESCRIPTION) != null){ + String tipText = uiAttributes.get(UIElement.DESCRIPTION); tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$, $NON-NLS-2$ label.setToolTipText(tipText); } @@ -133,15 +122,23 @@ public class UIStringListWidget extends InputUIElement { flcComposite.setLayout(new GridLayout()); flcComposite.setLayoutData(gridData); - fileListControl = new FileListControl(flcComposite, uiAttribute.get(InputUIElement.WIDGETLABEL), 0); - fileListControl.setList((String[])itemsList.toArray()); + fileListControl = new FileListControl(flcComposite, uiAttributes.get(InputUIElement.WIDGETLABEL), 0); + fileListControl.setList(itemsList.toArray(new String[itemsList.size()])); fileListControl.setSelection(0); fileListControl.addChangeListener(new IFileListChangeListener(){ public void fileListChanged(FileListControl fileList, String oldValue[], String newValue[]) { + itemsList.clear(); itemsList.addAll(Arrays.asList(newValue)); + uiComposite.firePatternEvent(createPatternEvent()); } }); - + + uiComposite.firePatternEvent(createPatternEvent()); + } + + protected PatternEvent createPatternEvent() { + String msg= MessageFormat.format("Please add an item to {0}", new String[] {label.getText()}); //$NON-NLS-1$ + return new PatternEvent(this, msg, isValid()); } /** @@ -154,7 +151,7 @@ public class UIStringListWidget extends InputUIElement { */ public boolean isValid() { boolean retVal = true; - String mandatory = uiAttribute.get(InputUIElement.MANDATORY); + String mandatory = uiAttributes.get(InputUIElement.MANDATORY); if ((itemsList == null || itemsList.size() == 0) && (mandatory.equalsIgnoreCase(TemplateEngineHelper.BOOLTRUE))) { retVal = false; diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UITextWidget.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UITextWidget.java index 876ef54eb3d..b1413e72921 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UITextWidget.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/uitree/uiwidgets/UITextWidget.java @@ -45,10 +45,6 @@ import org.eclipse.cdt.ui.templateengine.uitree.UIElement; * but should set the same for UITextWidget(super). */ public class UITextWidget extends InputUIElement implements ModifyListener { - /** - * Attributes associated with this widget. - */ - protected UIAttributes uiAttribute; /** * Text widget. @@ -76,7 +72,6 @@ public class UITextWidget extends InputUIElement implements ModifyListener { */ public UITextWidget(UIAttributes uiAttribute) { super(uiAttribute); - this.uiAttribute = uiAttribute; this.textValue = new String(); } @@ -85,7 +80,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { */ public Map getValues() { Map retMap = new HashMap(); - retMap.put(uiAttribute.get(InputUIElement.ID), textValue); + retMap.put(uiAttributes.get(InputUIElement.ID), textValue); return retMap; } @@ -96,7 +91,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { * @param valueMap */ public void setValues(Map valueMap) { - String val = valueMap.get(uiAttribute.get(InputUIElement.ID)); + String val = valueMap.get(uiAttributes.get(InputUIElement.ID)); String key = null; String subString = null; if (val != null) { @@ -126,22 +121,22 @@ public class UITextWidget extends InputUIElement implements ModifyListener { this.uiComposite = uiComposite; label = new Label(uiComposite, SWT.LEFT); - label.setText(uiAttribute.get(InputUIElement.WIDGETLABEL)); - if ((uiAttribute.get(UIElement.TYPE)).equalsIgnoreCase(InputUIElement.MULTILINETYPE)) { + label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL)); + if ((uiAttributes.get(UIElement.TYPE)).equalsIgnoreCase(InputUIElement.MULTILINETYPE)) { gd = new GridData(); gd.verticalAlignment = SWT.BEGINNING; gd.verticalIndent = 5; label.setLayoutData(gd); } - if (uiAttribute.get(UIElement.DESCRIPTION) != null){ - String tipText = uiAttribute.get(UIElement.DESCRIPTION); + if (uiAttributes.get(UIElement.DESCRIPTION) != null){ + String tipText = uiAttributes.get(UIElement.DESCRIPTION); tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ label.setToolTipText(tipText); } - text = getTextWidget(uiAttribute.get(UIElement.TYPE)); + text = getTextWidget(uiAttributes.get(UIElement.TYPE)); text.addModifyListener(this); - text.setData(".uid", uiAttribute.get(UIElement.ID)); //$NON-NLS-1$ + text.setData(".uid", uiAttributes.get(UIElement.ID)); //$NON-NLS-1$ text.setText(textValue); } @@ -179,7 +174,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { uiComposite.firePatternEvent(new PatternEvent(this, message, false)); } else { - String checkproject = attribute.get(InputUIElement.CHECKPROJECT); + String checkproject = uiAttributes.get(InputUIElement.CHECKPROJECT); if ((checkproject != null) && (checkproject.equalsIgnoreCase(TemplateEngineHelper.BOOLTRUE)) && TemplateEngineHelper.checkDirectoryInWorkspace(userInputText)) { @@ -197,7 +192,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { * evaluatePattern. */ public void modifyText(ModifyEvent e) { - String patternName = uiAttribute.get(InputUIElement.INPUTPATTERN); + String patternName = uiAttributes.get(InputUIElement.INPUTPATTERN); if (patternName == null) { patternValue = null; @@ -220,7 +215,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { if ((patternValue == null) || (textValue == null)) return; - String mandatory = attribute.get(InputUIElement.MANDATORY); + String mandatory = uiAttributes.get(InputUIElement.MANDATORY); if ((mandatory == null || !mandatory.equalsIgnoreCase("true")) && textValue.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$ return; } @@ -260,7 +255,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { */ public boolean isValid() { boolean retVal = true; - String mandatory = uiAttribute.get(InputUIElement.MANDATORY); + String mandatory = uiAttributes.get(InputUIElement.MANDATORY); if (((mandatory != null) && (mandatory.equalsIgnoreCase(TemplateEngineHelper.BOOLTRUE))) && ((textValue == null) || (textValue.equals("")) || //$NON-NLS-1$ @@ -297,7 +292,7 @@ public class UITextWidget extends InputUIElement implements ModifyListener { GridData multiTextData = new GridData(GridData.FILL_HORIZONTAL); multiTextData.widthHint = 70; - String line = uiAttribute.get(InputUIElement.SIZE); + String line = uiAttributes.get(InputUIElement.SIZE); int cnt = 1; if (line != null) { cnt = Integer.parseInt(line); diff --git a/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/Howtodeveloptemplates.html b/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/Howtodeveloptemplates.html index 1efadb18ea6..ab94521fc7c 100644 --- a/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/Howtodeveloptemplates.html +++ b/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/Howtodeveloptemplates.html @@ -79,7 +79,6 @@ For a project template the type should be ProjTempl.
  • version: Use this attribute to specify the major version -number of the template.

  • @@ -235,7 +234,7 @@ property The syntax for the property elements included by the property-group element is as follows:

    -

    <property
    id="propertyId"
    label="User visible label of the property"
    description="A brief description of the property"
    type="type of the property"
    pattern="Regular expression of the expected property"
    default="Default value of the property"
    size="size"
    mandatory="true|false"
    hidden="true|false"
    persist="true|false">

         <item
         name="name of the item"
         label="User visible label of the item"
         selected="true|false">
         ...
         </item>
    </property>

    +

    <property
    id="propertyId"
    label="User visible label of the property"
    description="A brief description of the property"
    type="type of the property"
    pattern="Regular expression of the expected property"
    default="Default value of the property"
    size="size"
    mandatory="true|false"
    hidden="true|false"
    persist="true|false">

         <item
         value="value of the item"
         label="User visible label of the item"
         ...
         </item>
    </property>

    Here is a list of attributes of the property element:

    @@ -339,27 +338,20 @@ If the property type is select or specify the items to be listed. There is no limitation on the number of items that can be listed. Here is the syntax for the item element:

    -

    <item
    name="name of the item"
    label="User visible label of the item"
    selected="true|false">
    </item>

    +

    <item
    value="value of the item"
    label="User visible label of the item"
    </item>

    Here is a list of attributes of the item element:

    • -name: Used to specify a unique name for the list item. -

      -
    • -

      label: Used to specify a label that is displayed to the user.

    • -selected: Used to specify whether the list item is -selected by default. The value for this attribute can either be -true or false. +value: Used to specify a unique value for the list item. This will be the value used in macro expansions.

      -

    process diff --git a/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/exampletemplate.html b/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/exampletemplate.html index dd644908d85..a06285bd123 100644 --- a/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/exampletemplate.html +++ b/doc/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/exampletemplate.html @@ -94,14 +94,15 @@ The following is an example template to create a simple Symbian OS             label="Target Type"
                description="Select the target type"
                type="select"
    +            default="app"
                hidden="false"
                mandatory="true"
                persist="true">
    -            <item label="APP" selected="true" name="app"/>
    -            <item label="LIB" selected="false" name="lib"/>
    -            <item label="DLL" selected="false" name="dll"/>
    -            <item label="EXE" selected="false" name="exe"/>
    -            <item label="EXEDLL" selected="false" name="exedll"/>
    +            <item label="APP" value="app"/>
    +            <item label="LIB" value="lib"/>
    +            <item label="DLL" value="dll"/>
    +            <item label="EXE" value="exe"/>
    +            <item label="EXEDLL" value="exedll"/>
            </property>
        </property-group>