UiListAttributeNodepublic class UiListAttributeNode extends UiAbstractTextAttributeNode Represents an XML attribute which has possible built-in values, and can be modified by
an editable Combo box.
See {@link UiTextAttributeNode} for more information. |
Fields Summary |
---|
protected org.eclipse.swt.widgets.Combo | mCombo |
Methods Summary |
---|
public final void | createUiControl(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.IManagedForm managedForm)
FormToolkit toolkit = managedForm.getToolkit();
TextAttributeDescriptor desc = (TextAttributeDescriptor) getDescriptor();
Label label = toolkit.createLabel(parent, desc.getUiName());
label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
SectionHelper.addControlTooltip(label, DescriptorsUtils.formatTooltip(desc.getTooltip()));
int style = SWT.DROP_DOWN;
mCombo = new Combo(parent, style);
TableWrapData twd = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE);
twd.maxWidth = 100;
mCombo.setLayoutData(twd);
fillCombo();
setTextWidgetValue(getCurrentValue());
mCombo.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() &&
mCombo != null &&
getCurrentValue() != null &&
!mCombo.getText().equals(getCurrentValue())) {
setDirty(true);
}
}
});
// Remove self-reference when the widget is disposed
mCombo.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
mCombo = null;
}
});
| protected void | fillCombo()
String[] values = getPossibleValues(null);
if (values == null) {
AdtPlugin.log(IStatus.ERROR,
"FrameworkResourceManager did not provide values yet for %1$s",
getDescriptor().getXmlLocalName());
} else {
for (String value : values) {
mCombo.add(value);
}
}
| public java.lang.String[] | getPossibleValues(java.lang.String prefix)Get the list values, either from the initial values set in the attribute
or by querying the framework resource parser.
{@inheritDoc}
AttributeDescriptor descriptor = getDescriptor();
UiElementNode uiParent = getUiParent();
String attr_name = descriptor.getXmlLocalName();
String element_name = uiParent.getDescriptor().getXmlName();
// FrameworkResourceManager expects a specific prefix for the attribute.
String nsPrefix = "";
if (SdkConstants.NS_RESOURCES.equals(descriptor.getNamespaceUri())) {
nsPrefix = "android:"; //$NON-NLS-1$
} else if (XmlnsAttributeDescriptor.XMLNS_URI.equals(descriptor.getNamespaceUri())) {
nsPrefix = "xmlns:"; //$NON-NLS-1$
}
attr_name = nsPrefix + attr_name;
String[] values = null;
if (descriptor instanceof ListAttributeDescriptor &&
((ListAttributeDescriptor) descriptor).getValues() != null) {
// Get enum values from the descriptor
values = ((ListAttributeDescriptor) descriptor).getValues();
}
if (values == null) {
// or from the AndroidTargetData
UiElementNode uiNode = getUiParent();
AndroidEditor editor = uiNode.getEditor();
AndroidTargetData data = editor.getTargetData();
if (data != null) {
// get the great-grand-parent descriptor.
// the parent should always exist.
UiElementNode grandParentNode = uiParent.getUiParent();
String greatGrandParentNodeName = null;
if (grandParentNode != null) {
UiElementNode greatGrandParentNode = grandParentNode.getUiParent();
if (greatGrandParentNode != null) {
greatGrandParentNodeName =
greatGrandParentNode.getDescriptor().getXmlName();
}
}
values = data.getAttributeValues(element_name, attr_name, greatGrandParentNodeName);
}
}
return values;
| public java.lang.String | getTextWidgetValue()
if (mCombo != null) {
return mCombo.getText();
}
return null;
| public final boolean | isValid()
return mCombo != null;
| public void | setTextWidgetValue(java.lang.String value)
if (mCombo != null) {
mCombo.setText(value);
}
|
|