Example usage for org.apache.wicket.ajax AjaxRequestTarget add

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget add.

Prototype

void add(Component... components);

Source Link

Document

Adds components to the list of components to be rendered.

Usage

From source file:com.axway.ats.testexplorer.pages.testcasesByGroups.TestcasesByGroupFilter.java

License:Apache License

private DropDownChoice<String> createSearchByProductComponent() {

    TestExplorerSession session = (TestExplorerSession) Session.get();

    try {/*from   w ww  .  j a  v  a 2  s  . c  o  m*/
        productNames = (ArrayList<String>) session.getDbReadConnection().getAllProductNames("WHERE 1=1");

        selectedProductName = null;

        searchByProduct = new DropDownChoice<String>("search_by_product",
                new PropertyModel<String>(this, "selectedProductName"), productNames);
        searchByProduct.setNullValid(false);
        searchByProduct.setEscapeModelStrings(false);
        searchByProduct.setOutputMarkupId(true);
        searchByProduct.add(new OnChangeAjaxBehavior() {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {

                TestExplorerSession session = (TestExplorerSession) Session.get();
                try {
                    versionNames = session.getDbReadConnection()
                            .getAllVersionNames("WHERE productName = '" + selectedProductName + "'");

                    selectedVersionNames = new ArrayList<String>(1);
                    searchByVersion.getModel().setObject(selectedVersionNames);

                    searchByVersion.setChoices(versionNames);
                    target.add(searchByVersion);

                    groupNames = new ArrayList<String>(1);
                    selectedGroupNames = new ArrayList<String>(1);
                    searchByAllGroups.getModel().setObject(selectedGroupNames);
                    searchByAllGroups.setChoices(groupNames);
                    target.add(searchByAllGroups);
                } catch (DatabaseAccessException e) {
                    error("Unable to get version names");
                }
            }
        });
    } catch (DatabaseAccessException e) {
        error(e.getMessage());
    }
    return searchByProduct;
}

From source file:com.axway.ats.testexplorer.TestExplorerApplication.java

License:Apache License

@Override
protected void init() {

    Locale.setDefault(Locale.US);

    getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class);
    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    // show internal error page rather than default developer page
    //TODO: use this line in PRODUCTION mode, by default in development mode is used ExceptionSettings.SHOW_EXCEPTION_PAGE
    //        getExceptionSettings().setUnexpectedExceptionDisplay( ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE );

    mountPage("/runs", RunsPage.class);
    mountPage("/suites", SuitesPage.class);
    mountPage("/scenarios", ScenariosPage.class);
    mountPage("/testcases", TestcasesPage.class);
    mountPage("/testcase", TestcasePage.class);

    mountPage("/charts", ChartsBasePage.class);

    mountPage("/compare", ComparePage.class);
    mountPage("/compareStatistics", CompareTestcaseSystemStatisticsPage.class);

    mountPage("/runMessages", RunMessagePage.class);
    mountPage("/suiteMessages", SuiteMessagePage.class);

    mountPage("/machines", MachinesPage.class);
    mountPage("/runCopy", RunCopyPage.class);
    mountPage("/testcasesCopy", TestcasesCopyPage.class);

    mountPage("/reportSelect", SelectTestcaseReportPage.class);

    mountPage("/pageExpired", PageExpiredErrorPage.class);
    mountPage("/error", InternalErrorPage.class);

    mountPage("/dashboardhome", RunsByTypeDashboardHomePage.class);
    mountPage("/dashboardrun", RunsByTypeDashboardRunPage.class);
    mountPage("/dashboardsuite", RunsByTypeDashboardSuitePage.class);

    mountPage("/groups", TestcasesByGroupsPage.class);

    try {/*ww  w. j  a v a2 s .c  o m*/
        configProperties = new Properties();
        configProperties.load(this.getClass().getClassLoader().getResourceAsStream("ats.config.properties"));
    } catch (IOException e) {
        LOG.error("Can't load config.properties file", e);
    }

    getAjaxRequestTargetListeners().add(new AjaxRequestTarget.IListener() {

        @Override
        public void onBeforeRespond(Map<String, Component> map, final AjaxRequestTarget target) {

            // if( !Session.get().getFeedbackMessages().isEmpty() ) {

            target.getPage().visitChildren(IFeedback.class, new IVisitor<Component, Void>() {
                public void component(final Component component, final IVisit<Void> visit) {

                    if (component.getOutputMarkupId()) {
                        target.appendJavaScript(
                                "$('#" + component.getMarkupId() + "').effect('bounce', { times:5 }, 200);");
                        target.add(component);
                        //visit.stop();
                    }
                    visit.dontGoDeeper();
                }
            });
        }

        @Override
        public void onAfterRespond(Map<String, Component> map, IJavaScriptResponse response) {

            // Do nothing.
        }

        @Override
        public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior,
                AjaxRequestAttributes attributes) {

            // TODO Auto-generated method stub

        }
    });

    // load any available Test Explorer plugins
    TestExplorerPluginsRepo.getInstance();
}

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

License:Apache License

private CheckBox getUseHandshakeCheckBox() {
    CheckBox checkbox = new CheckBox("useHandshake");

    checkbox.add(new OnChangeAjaxBehavior() {
        @Override//from   ww  w  .  j  a v  a  2 s .c  om
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();
            target.add(getComponent().getParent().get("handshakeMsg").setEnabled(value));
        }
    });

    return checkbox;
}

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.
 *///from  ww w.j a v  a2 s . c  o m
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.HeaderConfigUI.java

License:Apache License

/**
 * Update the offsets displayed in the list editor
 * @param target/*w  w w.jav  a 2s. c  o  m*/
 *       The RequestTarget used for updating.
 */
private void updateOffsets(AjaxRequestTarget target) {
    recalcOffsets();

    // Update the offsets
    List<Label> labels = editor.getComponentsById("offset", Label.class);
    for (Label lab : labels) {
        target.add(lab);
    }
}

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

License:Apache License

private DropDownChoice<Integer> getCurrentMessageIdDropdown() {

    IChoiceRenderer<Integer> messageConfigRender = new IChoiceRenderer<Integer>() {
        @Override/*w  ww.  j av a 2  s. c  om*/
        public Object getDisplayValue(Integer object) {
            return String.format("%d - %s", object, getConfig().getMessageConfig(object).getMessageAlias());
        }

        @Override
        public String getIdValue(Integer object, int index) {
            return object.toString();
        }
    };

    IModel<List<Integer>> messageListModel = new LoadableDetachableModel<List<Integer>>() {
        @Override
        protected List<Integer> load() {
            List<MessageConfig> messages = getConfig().getMessageList();
            List<Integer> list = new ArrayList<Integer>(messages.size());
            for (MessageConfig messageConfig : messages) {
                list.add(messageConfig.getMessageId());
            }
            return list;
        }
    };

    DropDownChoice<Integer> dropDown = new DropDownChoice<Integer>("currentMessage",
            new PropertyModel<Integer>(this, "currentMessageId"), messageListModel, messageConfigRender);

    dropDown.add(new AjaxFormSubmitBehavior("onchange") {

        @Override
        protected void onSubmit(final AjaxRequestTarget target) {

            // Reset feedback messages
            target.addChildren(getPage(), FeedbackPanel.class);

            // Change the current message
            currentMessage = getConfig().getMessageConfig(currentMessageId);
            currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize());

            // Refresh the form
            updateForm(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target) {
            // Add the drop down to revert the changed selection
            target.add(getComponent());

            handleError(target);
        };
    });

    dropDown.add(new AjaxIndicatorAppender());
    dropDown.setOutputMarkupId(true);

    return dropDown;
}

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

License:Apache License

private TextField<Integer> getMessageIdTextField() {

    TextField<Integer> textField = new FeedbackTextField<Integer>("messageId");
    textField.setRequired(true);/*  ww  w.j  a  v  a  2  s  . com*/

    CompoundValidator<Integer> validator = new CompoundValidator<Integer>();
    validator.add(new RangeValidator<Integer>(0, 65535));
    validator.add(new UniqueMessageIdValidator());
    textField.add(validator);
    textField.setOutputMarkupId(true);

    textField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // The id is the key for the message map, so we have to replace it here
            getConfig().messages.remove(currentMessageId);
            getConfig().addMessageConfig(currentMessage);
            currentMessageId = currentMessage.getMessageId();
            target.add(currentMessageIdDropdown);

            // Clear feedback messages
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }
    });

    return textField;
}

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

License:Apache License

private TextField<String> getMessageAliasTextField() {

    TextField<String> textField = new FeedbackTextField<String>("messageAlias");
    textField.setRequired(true);// ww  w .  j a va  2 s . c o  m

    CompoundValidator<String> validator = new CompoundValidator<String>();

    validator.add(new PatternValidator("[A-Za-z0-9_]+"));
    validator.add(StringValidator.lengthBetween(1, 32));
    validator.add(new UniqueMessageAliasValidator());
    textField.add(validator);

    textField.setLabel(labelAlias); // Use the same label as the items
    textField.setOutputMarkupId(true);

    textField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(currentMessageIdDropdown);
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }
    });

    return textField;
}

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

License:Apache License

private DropDownChoice<TagLengthType> getTagLengthTypeDropDown() {
    DropDownChoice<TagLengthType> dropDown = new DropDownChoice<TagLengthType>("tagLengthType",
            TagLengthType.getOptions(), new EnumChoiceRenderer<TagLengthType>(this)) {
        @Override/*from w w  w  .  j  ava  2  s.  c o m*/
        public boolean isVisible() {
            return currentMessage.isVariableLength();
        }
    };

    dropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(feedback);
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            target.add(feedback);
        }
    });

    dropDown.setOutputMarkupId(true);
    dropDown.setOutputMarkupPlaceholderTag(true);

    dropDown.add(new UniqueListItemValidator<TagLengthType>(dropDown) {
        @Override
        public String getValue(IValidatable<TagLengthType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("tagLengthType.OnlyOnePackedBasedValidator")
            .setFilterList(new String[] { TagLengthType.PACKET_BASED.name() }));

    return dropDown;
}

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.
 *///from w w  w.j  ava  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;
}