UiFlagAttributeNodepublic class UiFlagAttributeNode extends UiTextAttributeNode Represents an XML attribute that is defined by a set of flag values,
i.e. enum names separated by pipe (|) characters.
Note: in Android resources, a "flag" is a list of fixed values where one or
more values can be selected using an "or", e.g. "align='left|top'".
By contrast, an "enum" is a list of fixed values of which only one can be
selected at a given time, e.g. "gravity='right'".
This class handles the "flag" case.
The "enum" case is done using {@link UiListAttributeNode}. |
Methods Summary |
---|
public void | createUiControl(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.IManagedForm managedForm)
setManagedForm(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()));
Composite composite = toolkit.createComposite(parent);
composite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
GridLayout gl = new GridLayout(2, false);
gl.marginHeight = gl.marginWidth = 0;
composite.setLayout(gl);
// Fixes missing text borders under GTK... also requires adding a 1-pixel margin
// for the text field below
toolkit.paintBordersFor(composite);
final Text text = toolkit.createText(composite, getCurrentValue());
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalIndent = 1; // Needed by the fixed composite borders under GTK
text.setLayoutData(gd);
final Button selectButton = toolkit.createButton(composite, "Select...", SWT.PUSH);
setTextWidget(text);
selectButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
String currentText = getTextWidgetValue();
String result = showDialog(selectButton.getShell(), currentText);
if (result != null) {
setTextWidgetValue(result);
}
}
});
| public java.lang.String[] | getPossibleValues(java.lang.String prefix)Get the flag names, either from the initial names set in the attribute
or by querying the framework resource parser.
{@inheritDoc}
String attr_name = getDescriptor().getXmlLocalName();
String element_name = getUiParent().getDescriptor().getXmlName();
String[] values = null;
if (getDescriptor() instanceof FlagAttributeDescriptor &&
((FlagAttributeDescriptor) getDescriptor()).getNames() != null) {
// Get enum values from the descriptor
values = ((FlagAttributeDescriptor) getDescriptor()).getNames();
}
if (values == null) {
// or from the AndroidTargetData
UiElementNode uiNode = getUiParent();
AndroidEditor editor = uiNode.getEditor();
AndroidTargetData data = editor.getTargetData();
if (data != null) {
values = data.getAttributeValues(element_name, attr_name);
}
}
return values;
| public java.lang.String | showDialog(org.eclipse.swt.widgets.Shell shell, java.lang.String currentValue)Shows a dialog letting the user choose a set of enum, and returns a string
containing the result.
FlagSelectionDialog dlg = new FlagSelectionDialog(
shell, currentValue.trim().split("\\s*\\|\\s*")); //$NON-NLS-1$
dlg.open();
Object[] result = dlg.getResult();
if (result != null) {
StringBuilder buf = new StringBuilder();
for (Object name : result) {
if (name instanceof String) {
if (buf.length() > 0) {
buf.append("|"); //$NON-NLS-1$
}
buf.append(name);
}
}
return buf.toString();
}
return null;
|
|