Example usage for org.apache.wicket.ajax.form OnChangeAjaxBehavior OnChangeAjaxBehavior

List of usage examples for org.apache.wicket.ajax.form OnChangeAjaxBehavior OnChangeAjaxBehavior

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.form OnChangeAjaxBehavior OnChangeAjaxBehavior.

Prototype

public OnChangeAjaxBehavior() 

Source Link

Document

Constructor.

Usage

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.HeaderConfigUI.java

License:Apache License

/**
 * Create the DataType drop down. When the data type is changed, the offsets will be recalculated and updated.
 *///  w w  w.j ava2 s. c  om
private DropDownChoice<HeaderDataType> getDataTypeDropdown() {
    DropDownChoice<HeaderDataType> dropDown = new DropDownChoice<HeaderDataType>("dataType",
            HeaderDataType.getOptions(), new EnumChoiceRenderer<HeaderDataType>(this)) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (hasErrorMessage()) {
                String style = "background-color:#ffff00;";
                String oldStyle = tag.getAttribute("style");
                tag.put("style", style + oldStyle);
            }
        }
    };

    dropDown.setRequired(true);

    // When the data type is changed, the offsets are recalculated and displayed
    dropDown.add(new OnChangeAjaxBehavior() {
        @SuppressWarnings("unchecked")
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Recalculate and display the offsets
            updateOffsets(target);

            // Disable value field when DataType does not use a value.
            DropDownChoice<HeaderDataType> choice = (DropDownChoice<HeaderDataType>) getComponent();
            MarkupContainer parent = choice.getParent();
            HeaderDataType dataType = choice.getConvertedInput();
            target.add(
                    parent.get("rawValue").setEnabled(dataType.isHasValue()).setVisible(dataType.isHasValue()));
            target.add(parent.get("size").setEnabled(dataType.isArrayAllowed()));
        }
    });

    dropDown.add(new UniqueListItemValidator<HeaderDataType>(dropDown) {
        @Override
        public String getValue(IValidatable<HeaderDataType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("dataType.SpecialTypesValidator").setFilterList(HeaderDataType.getSpecialItemNames()));

    return dropDown;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private TextField<Integer> getSizeTextField() {

    TextField<Integer> textField = new FeedbackTextField<Integer>("size");

    textField.setRequired(true);/*w w  w .  j  a v  a  2  s.c o  m*/
    textField.add(new RangeValidator<Integer>(1, 1000));

    textField.setLabel(labelSize);

    textField.setOutputMarkupId(true);

    // When the size is changed, the offsets are recalculated and displayed
    textField.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateOffsets(target);
        }
    });

    return textField;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

/**
 * Create the DataType dropdown. When the datatype is changed, the offsets will be recalculated and updated.
 */// www.jav  a 2 s. c o m
private DropDownChoice<BinaryDataType> getDataTypeDropdown() {
    DropDownChoice<BinaryDataType> dropDown = new DropDownChoice<BinaryDataType>("dataType",
            BinaryDataType.getOptions(), new EnumChoiceRenderer<BinaryDataType>(this)) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (hasErrorMessage()) {
                String style = "background-color:#ffff00;";
                String oldStyle = tag.getAttribute("style");
                tag.put("style", style + oldStyle);
            }
        }
    };

    dropDown.setRequired(true);

    // When the datatype is changed, the offsets are recalculated and displayed
    dropDown.add(new OnChangeAjaxBehavior() {
        @SuppressWarnings("unchecked")
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Recalculate and display the offsets
            updateOffsets(target);

            // Disable input fields when DataType is a special type.
            // Current state is determined by the enabled state of TextField("id")
            DropDownChoice<BinaryDataType> choice = (DropDownChoice<BinaryDataType>) getComponent();
            MarkupContainer parent = choice.getParent();
            Component idTextField = parent.get("id");
            BinaryDataType dataType = choice.getConvertedInput();
            if (dataType.isSpecial() && idTextField.isEnabled()) {
                // DataType changed to special type
                // Store current values
                ((TextField<Integer>) idTextField).getRawInput();
                idTextField.replaceWith(getSpecialIdTextField().setEnabled(false));
                target.add(parent.get("id"));
                target.add(parent.get("alias").setVisible(false));
            } else if (!idTextField.isEnabled()) {
                idTextField.replaceWith(getIdTextField());
                target.add(parent.get("id").setEnabled(true));
                target.add(parent.get("alias").setVisible(true));
            }
            target.add(parent.get("size").setEnabled(dataType.isArrayAllowed()));
            target.add(parent.get("tagLengthType").setEnabled(dataType.supportsVariableLength()));
            if (!dataType.supportsVariableLength()) {
                EditorListItem<TagConfig> listItem = getComponent().findParent(EditorListItem.class);
                if (listItem != null) {
                    listItem.getModelObject().setTagLengthType(TagLengthType.FIXED_LENGTH);
                }
            }
        }
    });

    dropDown.add(new UniqueListItemValidator<BinaryDataType>(dropDown) {
        @Override
        public String getValue(IValidatable<BinaryDataType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("dataType.SpecialTypesValidator")
            .setFilterList(new String[] { BinaryDataType.MessageAge.name() }));

    return dropDown;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.WritebackConfigUI.java

License:Apache License

private CheckBox getEnabledCheckBox() {
    CheckBox checkbox = new CheckBox("enabled");

    checkbox.add(new OnChangeAjaxBehavior() {
        @Override/*from  w w w . ja v a2 s  .  c o m*/
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();

            if (value) {
                settingsTable.setEnabled(true);
            } else {
                settingsTable.setEnabled(false);
            }
            target.add(settingsTable);
        }
    });

    return checkbox;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.WritebackConfigUI.java

License:Apache License

private CheckBox getUsePrefixCheckBox() {
    CheckBox checkbox = new CheckBox("usePrefix");

    checkbox.add(new OnChangeAjaxBehavior() {
        @Override//ww w  . j a va  2s.c  o  m
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();

            Component prefixTextField = getComponent().getParent().get("prefix");
            if (value && !prefixTextField.isEnabled()) {
                prefixTextField.setEnabled(true);
            } else {
                prefixTextField.setEnabled(false);
            }
            target.add(prefixTextField);
        }
    });

    return checkbox;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.WritebackConfigUI.java

License:Apache License

private CheckBox getSendInitialValueCheckBox() {
    CheckBox checkbox = new CheckBox("sendInitialValue");

    // When the datatype is changed, the offsets are recalculated and
    // displayed/*ww  w  .  j  a  v a2 s. c o  m*/
    checkbox.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();

            Component initialValueTextField = getComponent().getParent().get("initialValue");
            Component initialIdTextField = getComponent().getParent().get("initialId");

            if (value && !initialValueTextField.isEnabled()) {
                initialValueTextField.setEnabled(true);
                initialIdTextField.setEnabled(true);
            } else {
                initialValueTextField.setEnabled(false);
                initialIdTextField.setEnabled(false);
            }
            target.add(initialValueTextField);
            target.add(initialIdTextField);
        }
    });

    return checkbox;
}

From source file:com.doculibre.constellio.wicket.panels.admin.facets.AddEditFacetPanel.java

License:Open Source License

public AddEditFacetPanel(String id, CollectionFacet facet) {
    super(id, true);
    this.facetModel = new ReloadableEntityModel<CollectionFacet>(facet);
    this.indexFieldOptionsModel = new AdminCollectionIndexFieldsModel(this);

    this.indexFieldRenderer = new ChoiceRenderer() {
        @Override/*from w w  w. j a v  a  2  s  .  c  o m*/
        public Object getDisplayValue(Object object) {
            IndexField indexField = (IndexField) object;
            return indexField.getName();
        }
    };

    Form form = getForm();
    form.setModel(new CompoundPropertyModel(facetModel));

    final WebMarkupContainer contextFieldsContainer = new WebMarkupContainer("contextFields");
    form.add(contextFieldsContainer);
    contextFieldsContainer.setOutputMarkupId(true);

    IModel localesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return collection.getLocales();
        }
    };
    MultiLocaleComponentHolder nameHolder = new MultiLocaleComponentHolder("name", facetModel, localesModel) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField nameField = new RequiredTextField("nameLocale", componentModel);
            item.add(nameField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                            AdminCollectionPanel.class);
                    RecordCollection collection = collectionAdminPanel.getCollection();
                    return collection.getLocales().size() > 1;
                }
            });
        }
    };
    form.add(nameHolder);

    IChoiceRenderer facetTypeRenderer = new ChoiceRenderer() {
        @Override
        public Object getDisplayValue(Object object) {
            String key = "facetType." + object;
            return getLocalizer().getString(key, AddEditFacetPanel.this);
        }
    };
    DropDownChoice facetType = new DropDownChoice("facetType", Arrays.asList(CollectionFacet.FACET_TYPES),
            facetTypeRenderer);
    form.add(facetType);
    facetType.setOutputMarkupId(true);
    facetType.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(contextFieldsContainer);
        }
    });

    CheckBox hideEmptyValues = new CheckBox("hideEmptyValues");
    CheckBox sortable = new CheckBox("sortable");
    CheckBox multiValued = new CheckBox("multiValued");
    form.add(hideEmptyValues);
    form.add(sortable);
    form.add(multiValued);

    //FIXME Bug when changing the type of an existing facet
    facetType.setEnabled(facet.getId() == null);

    addFieldFacetFields(contextFieldsContainer);
    addQueryFacetFields(contextFieldsContainer);
    addClusterFacetFields(contextFieldsContainer);
    addCloudKeywordFields(contextFieldsContainer);
}

From source file:com.doculibre.constellio.wicket.panels.admin.resultPanels.AddEditResultClassPanel.java

License:Open Source License

public AddEditResultClassPanel(String id, ConnectorInstance connector) {
    super(id, true);
    this.connectorModel = new ReloadableEntityModel<ConnectorInstance>(connector);

    String defaultConnectorTypeClass = connector.getConnectorType().getSearchResultPanelClassName();

    IModel customClassModel = new Model();

    final IModel choice = new Model();
    if (connector.getSearchResultPanelClassName() != null) {
        choice.setObject(CUSTOM_CLASS);/* ww  w .j  a  v a 2s .  co  m*/
        customClassModel.setObject(connector.getSearchResultPanelClassName());
    } else if (defaultConnectorTypeClass != null) {
        choice.setObject(DEFAULT_CONNECTOR_TYPE_CLASS);
    } else {
        choice.setObject(DEFAULT_CLASS);
    }

    List<String> choices = new ArrayList<String>();
    String defaultClass = DefaultSearchResultPanel.class.getCanonicalName();
    if (defaultConnectorTypeClass != null) {
        defaultClass = defaultConnectorTypeClass;
        choices.add(DEFAULT_CONNECTOR_TYPE_CLASS);
    } else {
        choices.add(DEFAULT_CLASS);
    }
    choices.add(CUSTOM_CLASS);

    final Form form = getForm();

    // Remplacer les composantes directement par ajax cre des problmes
    // Remplacer le panel au complet cre un autre problme avec firefox
    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);

    this.customClassTextField = new TextField("customClass", customClassModel) {
        @Override
        public boolean isVisible() {
            boolean visible = CUSTOM_CLASS.equals((String) choice.getObject());
            return visible;
        }
    };

    this.defaultClassLabel = new Label("defaultClass", defaultClass) {
        @Override
        public boolean isVisible() {
            return !CUSTOM_CLASS.equals((String) choice.getObject());
        }
    };

    this.defaultOrCustomDropDown = new DropDownChoice("defaultClassRadio", choice, choices,
            new StringResourceChoiceRenderer(this));
    this.defaultOrCustomDropDown.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(container);
        }
    });

    form.add(defaultOrCustomDropDown);
    form.add(container);
    container.add(customClassTextField);
    container.add(defaultClassLabel);
}

From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteItemDefinitionPanel.java

License:Apache License

private void initLayout(final IModel<ItemDefinition<?>> model) {
    final Model<String> itemDefinitionAsStringModel = new Model<>(null);
    AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT,
            itemDefinitionAsStringModel, String.class, createAutoCompleteSettings()) {

        private static final long serialVersionUID = 1L;

        @Override/*from   w  w  w  .  j  a v a 2s.c  om*/
        protected Iterator<String> getChoices(String input) {
            List<String> defsAsString = new ArrayList<>();
            for (ItemDefinition<?> def : listChoices(input).values()) {
                defsAsString.add(def.getName().getLocalPart());
            }
            return defsAsString.iterator();

        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            itemDefinitionAsStringModel.setObject(null);
        }

    };

    input.add(new OnChangeAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String newValue = itemDefinitionAsStringModel.getObject();
            if (StringUtils.isNotBlank(newValue)) {
                ItemDefinition<?> def = listChoices("").get(newValue);
                if (def != null) {
                    model.setObject(def);
                }
            }
        }
    });

    add(input);
}

From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel.java

License:Apache License

private void initLayout(final IModel<QName> model) {
    setOutputMarkupId(true);//from   www . j  ava  2 s  .c o m

    AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
    final IModel<String> stringModel = new Model<String>() {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            model.setObject(convertToQname(object));
        }

    };

    // The inner autocomplete field is always String. Non-string auto-complete fields are problematic
    final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel,
            String.class, autoCompleteSettings) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return getIterator(input);
        }

    };
    input.add(new OnChangeAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String inputString = stringModel.getObject();
            if (StringUtils.isBlank(inputString)) {
                QName modelObject = model.getObject();
                if (modelObject != null) {
                    model.setObject(null);
                    AutoCompleteQNamePanel.this.onChange(target);
                }
            } else {
                QName inputQName = convertToQname(stringModel.getObject());
                if (inputQName == null) {
                    // We have some input, but it does not match any QName. Just do nothing.
                } else {
                    QName modelObject = model.getObject();
                    if (inputQName.equals(modelObject)) {
                        model.setObject(inputQName);
                        AutoCompleteQNamePanel.this.onChange(target);
                    }
                }
            }
        }
    });
    add(input);
}