001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Nov 1, 2005
014: * @author dmoran
015: */
016:
017: package org.pentaho.designstudio.controls;
018:
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Control;
021: import org.eclipse.swt.widgets.Text;
022:
023: /**
024: * An XMLAwareControl that is backed by a Text control. The XML aware control modifies the
025: * specified XML node to stay in sync with the text being displayed in the control.
026: *
027: * @author Doug Moran
028: *
029: */
030: public class XMLAwareTextField extends XMLAwareControl {
031: Text text;
032:
033: /**
034: * Create an XML aware text field.
035: * @param toolkit the toolkit to be used when creating the Text control.
036: * @param parent the parent of the Text control
037: * @param nodeName the name of the DOM node being modified by by this control
038: * @param controlLayoutData the layout data for the control
039: */
040: public XMLAwareTextField(Composite parent, String nodeName,
041: Object controlLayoutData) {
042: this (parent, nodeName, controlLayoutData, null);
043: }
044:
045: /**
046: * Create an XML aware text field.
047: * @param toolkit the toolkit to be used when creating the Text control.
048: * @param parent the parent of the Text control
049: * @param nodeName the name of the DOM node being modified by by this control
050: * @param controlLayoutData the layout data for the control
051: * @param labelLayoutData the layout data for the label
052: */
053: public XMLAwareTextField(Composite parent, String nodeName,
054: Object controlLayoutData, Object labelLayoutData) {
055: super (parent, nodeName, controlLayoutData, labelLayoutData);
056: }
057:
058: protected Control createControl(Composite parent, int style,
059: String labelStr, Object controlLayoutData,
060: Object labelLayoutData) {
061: createLabel(parent, labelLayoutData, labelStr);
062: text = WidgetFactory.createText(parent, ""); //$NON-NLS-1$
063: if (controlLayoutData != null) {
064: text.setLayoutData(controlLayoutData);
065: }
066: return (text);
067: }
068:
069: /* (non-Javadoc)
070: * @see org.pentaho.designstudio.controls.XMLAwareControl#getText()
071: */
072: public String getText() {
073: return ((text == null) ? "" : text.getText()); //$NON-NLS-1$
074: }
075:
076: /* (non-Javadoc)
077: * @see org.pentaho.designstudio.controls.XMLAwareControl#setText(java.lang.String)
078: */
079: protected void setText(String textStr) {
080: if (text != null) {
081: text.setText(textStr);
082: }
083: }
084:
085: /* (non-Javadoc)
086: * @see org.pentaho.designstudio.controls.XMLAwareControl#setEnabled(boolean)
087: */
088: protected void setEnabled(boolean enabled) {
089: text.setEnabled(enabled);
090: }
091:
092: /* (non-Javadoc)
093: * @see org.pentaho.designstudio.controls.XMLAwareControl#addModifyListener()
094: */
095: protected void addModifyListener() {
096: text.addModifyListener(this );
097: }
098:
099: /* (non-Javadoc)
100: * @see org.pentaho.designstudio.controls.XMLAwareControl#removeModifyListener()
101: */
102: protected void removeModifyListener() {
103: text.removeModifyListener(this );
104: }
105:
106: /* (non-Javadoc)
107: * @see org.pentaho.designstudio.controls.XMLAwareControl#getControl()
108: */
109: public Control getControl() {
110: return text;
111: }
112: }
|