trace/tracebuilder/com.nokia.tracebuilder.view/src/com/nokia/tracebuilder/view/PropertyDialogUIValue.java
changeset 10 ed1c9f64298a
equal deleted inserted replaced
9:14dc2103a631 10:ed1c9f64298a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * Composite for value label, field and tag button
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.view;
       
    20 
       
    21 import org.eclipse.swt.SWT;
       
    22 import org.eclipse.swt.events.ModifyListener;
       
    23 import org.eclipse.swt.widgets.Composite;
       
    24 import org.eclipse.swt.widgets.Label;
       
    25 import org.eclipse.swt.widgets.Text;
       
    26 
       
    27 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialog;
       
    28 
       
    29 /**
       
    30  * Composite for value label, field and tag button
       
    31  * 
       
    32  */
       
    33 final class PropertyDialogUIValue extends PropertyDialogComposite {
       
    34 
       
    35 	/**
       
    36 	 * Each dialog has a different value label
       
    37 	 */
       
    38 	private Label valueLabel;
       
    39 
       
    40 	/**
       
    41 	 * Value field is mapped to trace text
       
    42 	 */
       
    43 	private Text valueField;
       
    44 
       
    45 	/**
       
    46 	 * Constructor
       
    47 	 * 
       
    48 	 * @param parent
       
    49 	 *            the parent composite
       
    50 	 * @param uiType
       
    51 	 *            the UI type
       
    52 	 * @param modifyListener
       
    53 	 *            text field modify listener
       
    54 	 */
       
    55 	PropertyDialogUIValue(Composite parent, int uiType,
       
    56 			ModifyListener modifyListener) {
       
    57 		super(parent);
       
    58 		create(uiType, modifyListener);
       
    59 	}
       
    60 
       
    61 	/**
       
    62 	 * Creates the value text field and associated label
       
    63 	 * 
       
    64 	 * @param uiType
       
    65 	 *            the UI type
       
    66 	 * @param modifyListener
       
    67 	 *            the text field modify listener
       
    68 	 */
       
    69 	private void create(int uiType, ModifyListener modifyListener) {
       
    70 		valueLabel = new Label(getParent(), SWT.NONE);
       
    71 		valueLabel.setText(getValueLabel(uiType));
       
    72 		valueField = new Text(getParent(), SWT.BORDER);
       
    73 		valueField.addModifyListener(modifyListener);
       
    74 		setFieldButtonLayoutData(valueField, null);
       
    75 	}
       
    76 
       
    77 	/**
       
    78 	 * Gets the label for value field
       
    79 	 * 
       
    80 	 * @param uiType
       
    81 	 *            the UI type
       
    82 	 * @return the label
       
    83 	 */
       
    84 	private String getValueLabel(int uiType) {
       
    85 		String value;
       
    86 		switch (uiType) {
       
    87 		case TraceObjectPropertyDialog.ADD_TRACE:
       
    88 			value = Messages.getString("PropertyDialogUI.AddTraceValueLabel"); //$NON-NLS-1$
       
    89 			break;
       
    90 		case TraceObjectPropertyDialog.EDIT_TRACE:
       
    91 			value = Messages.getString("PropertyDialogUI.EditTraceValueLabel"); //$NON-NLS-1$
       
    92 			break;
       
    93 		case TraceObjectPropertyDialog.INSTRUMENTER:
       
    94 			value = Messages.getString("PropertyDialogUI.TraceTextFormat"); //$NON-NLS-1$
       
    95 			break;
       
    96 		default:
       
    97 			value = ""; //$NON-NLS-1$
       
    98 			break;
       
    99 		}
       
   100 		return value;
       
   101 	}
       
   102 
       
   103 	/**
       
   104 	 * Gets the value field contents
       
   105 	 * 
       
   106 	 * @return the field contents
       
   107 	 */
       
   108 	String getValue() {
       
   109 		return valueField.getText();
       
   110 	}
       
   111 
       
   112 	/**
       
   113 	 * Sets the value field contents
       
   114 	 * 
       
   115 	 * @param value
       
   116 	 *            the new value
       
   117 	 */
       
   118 	void setValue(String value) {
       
   119 		valueField.setText(value);
       
   120 	}
       
   121 
       
   122 	/**
       
   123 	 * Enables / disables the value field and the tag button
       
   124 	 * 
       
   125 	 * @param flag
       
   126 	 *            new enabled state
       
   127 	 */
       
   128 	void setEnabled(boolean flag) {
       
   129 		valueField.setEnabled(flag);
       
   130 	}
       
   131 	
       
   132 	/**
       
   133 	 * Sets the label text
       
   134 	 * 
       
   135 	 * @param labelText
       
   136 	 *            the new label text
       
   137 	 */
       
   138 	void setLabel(String labelText) {
       
   139 		if (labelText != null) {
       
   140 			valueLabel.setText(labelText);
       
   141 		}
       
   142 	}
       
   143 	
       
   144 	/**
       
   145 	 * Get value label
       
   146 	 * 
       
   147 	 * @return the value label
       
   148 	 */
       
   149 	Label getValueLabel() {
       
   150 		return valueLabel;
       
   151 	}
       
   152 
       
   153 }