FileDocCategorySizeDatePackage
UiTextAttributeNode.javaAPI DocAndroid 1.5 API6797Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.uimodel

UiTextAttributeNode

public class UiTextAttributeNode extends UiAbstractTextAttributeNode
Represents an XML attribute in that can be modified using a simple text field in the XML editor's user interface.

The XML attribute has no default value. When unset, the text field is blank. When updating the XML, if the field is empty, the attribute will be removed from the XML element.

See {@link UiAttributeNode} for more information.

Fields Summary
private org.eclipse.swt.widgets.Text
mText
Text field
private org.eclipse.ui.forms.IManagedForm
mManagedForm
The managed form, set only once createUiControl has been called.
Constructors Summary
public UiTextAttributeNode(com.android.ide.eclipse.editors.descriptors.AttributeDescriptor attributeDescriptor, UiElementNode uiParent)

        super(attributeDescriptor, uiParent);
    
Methods Summary
public voidcreateUiControl(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.IManagedForm managedForm)

        setManagedForm(managedForm);
        TextAttributeDescriptor desc = (TextAttributeDescriptor) getDescriptor();
        Text text = SectionHelper.createLabelAndText(parent, managedForm.getToolkit(),
                desc.getUiName(), getCurrentValue(),
                DescriptorsUtils.formatTooltip(desc.getTooltip()));

        setTextWidget(text);
    
protected org.eclipse.ui.forms.IManagedFormgetManagedForm()

return
The managed form, set only once createUiControl has been called.

        return mManagedForm;
    
public java.lang.String[]getPossibleValues(java.lang.String prefix)
No completion values for this UI attribute. {@inheritDoc}

        return null;
    
protected final org.eclipse.swt.widgets.TextgetTextWidget()
Returns the text widget.

        return mText;
    
public java.lang.StringgetTextWidgetValue()

        if (mText != null) {
            return mText.getText();
        }
        
        return null;
    
public booleanisValid()

        return mText != null;
    
protected voidonAddValidators(org.eclipse.swt.widgets.Text text)
Called after the text widget as been created.

Derived classes typically want to:

  • Create a new {@link ModifyListener} and attach it to the given {@link Text} widget.
  • In the modify listener, call getManagedForm().getMessageManager().addMessage() and getManagedForm().getMessageManager().removeMessage() as necessary.
  • Call removeMessage in a new text.addDisposeListener.
  • Call the validator once to setup the initial messages as needed.

    The base implementation does nothing.

    param
    text The {@link Text} widget to validate.

        
  • protected voidsetManagedForm(org.eclipse.ui.forms.IManagedForm managedForm)
    Sets the internal managed form. This is usually set by createUiControl.

             mManagedForm = managedForm;
        
    protected final voidsetTextWidget(org.eclipse.swt.widgets.Text textWidget)
    Sets the Text widget object, and prepares it to handle modification and synchronization with the XML node.

    param
    textWidget

            mText = textWidget;
     
            if (textWidget != null) {
                // Sets the with hint for the text field. Derived classes can always override it.
                // This helps the grid layout to resize correctly on smaller screen sizes.
                Object data = textWidget.getLayoutData();
                if (data == null) {
                } else if (data instanceof GridData) {
                    ((GridData)data).widthHint = AndroidEditor.TEXT_WIDTH_HINT;
                } else if (data instanceof TableWrapData) {
                    ((TableWrapData)data).maxWidth = 100;
                }
                
                mText.addModifyListener(new ModifyListener() {
                    /**
                     * Sent when the text is modified, whether by the user via manual
                     * input or programmatic input via setText().
                     * <p/>
                     * Simply mark the attribute as dirty if it really changed.
                     * The container SectionPart will collect these flag and manage them.
                     */
                    public void modifyText(ModifyEvent e) {
                        if (!isInInternalTextModification() &&
                                !isDirty() &&
                                mText != null &&
                                getCurrentValue() != null &&
                                !mText.getText().equals(getCurrentValue())) {
                            setDirty(true);
                        }
                    }            
                });
                
                // Remove self-reference when the widget is disposed
                mText.addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent e) {
                        mText = null;
                    }
                });
            }
            
            onAddValidators(mText);
        
    public voidsetTextWidgetValue(java.lang.String value)

            if (mText != null) {
                mText.setText(value);
            }