Search in sources :

Example 1 with UIBox

use of org.terasology.nui.widgets.UIBox in project Terasology by MovingBlocks.

the class ObjectLayoutBuilder method populateNullLayout.

private void populateNullLayout(Binding<T> binding, ColumnLayout layout, UILabel nameWidget) {
    // TODO: Translate
    if (MODIFY_LABEL.equals(nameWidget.getText())) {
        nameWidget.setText(NULL_LABEL);
    }
    List<Constructor<T>> constructors = Arrays.stream(type.getRawType().getConstructors()).map(constructor -> (Constructor<T>) constructor).collect(Collectors.toList());
    if (constructors.isEmpty()) {
        // TODO: Translate
        UIBox box = buildErrorWidget("No accessible constructors found");
        layout.addWidget(box);
        return;
    }
    ColumnLayout parameterLayout = createDefaultLayout();
    UIButton createInstanceButton = new UIButton();
    // TODO: Translate
    createInstanceButton.setText("Create Instance");
    UIDropdownScrollable<Constructor<T>> constructorSelection = new UIDropdownScrollable<>();
    Binding<Constructor<T>> selectedConstructor = new NotifyingBinding<Constructor<T>>(constructors.get(0)) {

        @Override
        protected void onSet() {
            populateConstructorParameters(binding, parameterLayout, createInstanceButton, this);
        }
    };
    constructorSelection.setOptions(constructors);
    constructorSelection.bindSelection(selectedConstructor);
    constructorSelection.setOptionRenderer(new StringTextRenderer<Constructor<T>>() {

        @Override
        public String getString(Constructor<T> value) {
            return ReflectionUtil.resolvedMethodToString(type.getType(), value, true);
        }
    });
    // TODO: Translate
    constructorSelection.setTooltip("Select the constructor to use to create the new object");
    layout.addWidget(constructorSelection);
    layout.addWidget(parameterLayout);
    layout.addWidget(createInstanceButton);
}
Also used : Arrays(java.util.Arrays) Defaults(com.google.common.base.Defaults) LoggerFactory(org.slf4j.LoggerFactory) TypeWidgetLibrary(org.terasology.nui.widgets.types.TypeWidgetLibrary) TypeInfo(org.terasology.reflection.TypeInfo) ExpandableLayoutBuilder(org.terasology.nui.widgets.types.builtin.util.ExpandableLayoutBuilder) FieldsWidgetBuilder(org.terasology.nui.widgets.types.builtin.util.FieldsWidgetBuilder) WidgetUtil(org.terasology.nui.WidgetUtil) Constructor(java.lang.reflect.Constructor) UIBox(org.terasology.nui.widgets.UIBox) NotifyingBinding(org.terasology.nui.databinding.NotifyingBinding) DefaultBinding(org.terasology.nui.databinding.DefaultBinding) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) Parameter(java.lang.reflect.Parameter) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) ReflectionUtil(org.terasology.engine.utilities.ReflectionUtil) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) UIWidget(org.terasology.nui.UIWidget) List(java.util.List) UIButton(org.terasology.nui.widgets.UIButton) LABEL_WIDGET_ID(org.terasology.nui.widgets.types.TypeWidgetFactory.LABEL_WIDGET_ID) Optional(java.util.Optional) Constructor(java.lang.reflect.Constructor) UIBox(org.terasology.nui.widgets.UIBox) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIButton(org.terasology.nui.widgets.UIButton) NotifyingBinding(org.terasology.nui.databinding.NotifyingBinding)

Aggregations

Defaults (com.google.common.base.Defaults)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Parameter (java.lang.reflect.Parameter)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ReflectionUtil (org.terasology.engine.utilities.ReflectionUtil)1 UIWidget (org.terasology.nui.UIWidget)1 WidgetUtil (org.terasology.nui.WidgetUtil)1 Binding (org.terasology.nui.databinding.Binding)1 DefaultBinding (org.terasology.nui.databinding.DefaultBinding)1 NotifyingBinding (org.terasology.nui.databinding.NotifyingBinding)1 StringTextRenderer (org.terasology.nui.itemRendering.StringTextRenderer)1 ColumnLayout (org.terasology.nui.layouts.ColumnLayout)1 UIBox (org.terasology.nui.widgets.UIBox)1 UIButton (org.terasology.nui.widgets.UIButton)1