1 /*******************************************************************************
2 * Copyright (c) 2007, 2008 Symbian Software Limited and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Bala Torati (Symbian) - Initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.cdt.ui.templateengine.uitree.uiwidgets;
13 import java.util.HashMap;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement;
26 import org.eclipse.cdt.ui.templateengine.uitree.UIAttributes;
27 import org.eclipse.cdt.ui.templateengine.uitree.UIElement;
31 * This gives a Label and Boolean widget.
33 public class UIBooleanWidget extends InputUIElement {
37 protected Button button;
40 * Label of this widget.
42 protected Label label;
45 * Composite to which this widget control is added.
47 protected UIComposite uiComposite;
49 private boolean booleanValue;
55 * attribute associated with this widget.
57 public UIBooleanWidget(UIAttributes uiAttributes, boolean defaultValue) {
59 this.booleanValue= defaultValue;
63 * @return HashMap which contains the values in the Boolean Widget.
66 public Map<String, String> getValues() {
67 Map<String, String> values = new HashMap<String, String>();
68 values.put(uiAttributes.get(InputUIElement.ID), Boolean.toString(booleanValue));
73 * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#setValues(java.util.Map)
76 public void setValues(Map<String, String> valueMap) {
77 booleanValue = new Boolean(valueMap.get(uiAttributes.get(InputUIElement.ID))).booleanValue();
81 * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#createWidgets(org.eclipse.cdt.ui.templateengine.uitree.uiwidgets.UIComposite)
84 public void createWidgets(UIComposite uiComposite) {
85 GridData gridData = null;
86 this.uiComposite = uiComposite;
88 label = new Label(uiComposite, SWT.LEFT);
89 label.setText(uiAttributes.get(InputUIElement.WIDGETLABEL));
91 if (uiAttributes.get(InputUIElement.DESCRIPTION) != null){
92 String tipText = uiAttributes.get(UIElement.DESCRIPTION);
93 tipText = tipText.replaceAll("\\\\r\\\\n", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
94 label.setToolTipText(tipText);
96 gridData = new GridData();
97 gridData.horizontalAlignment = GridData.FILL;
98 gridData.grabExcessHorizontalSpace = true;
99 Composite booleanContainer = new Composite(uiComposite, SWT.NONE);
100 GridData gridcData = new GridData(GridData.FILL_HORIZONTAL);
101 booleanContainer.setLayout(new GridLayout());
102 booleanContainer.setLayoutData(gridcData);
103 button = new Button(booleanContainer, SWT.CHECK);
104 button.setData(".uid", uiAttributes.get(UIElement.ID)); //$NON-NLS-1$
105 button.setSelection(new Boolean(booleanValue).booleanValue());
106 button.addSelectionListener(new SelectionAdapter() {
108 public void widgetSelected(SelectionEvent e) {
109 booleanValue = button.getSelection();
115 * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#isValid()
118 public boolean isValid() {
119 boolean retVal= true;
120 String mandatory= uiAttributes.get(InputUIElement.MANDATORY);
121 if (!booleanValue && Boolean.parseBoolean(mandatory)) {
128 * @see org.eclipse.cdt.ui.templateengine.uitree.UIElement#disposeWidget()
131 public void disposeWidget() {