List of usage examples for org.apache.wicket.ajax.attributes AjaxCallListener AjaxCallListener
AjaxCallListener
From source file:com.axway.ats.testexplorer.pages.model.ColumnsDialog.java
License:Apache License
@SuppressWarnings({ "rawtypes" }) public ColumnsDialog(String id, final DataGrid grid, List<TableColumn> columnDefinitions) { super(id);//from w ww.j a v a2 s . c o m setOutputMarkupId(true); this.dbColumnDefinitions = columnDefinitions; DataView<TableColumn> table = new DataView<TableColumn>("headers", new ListDataProvider<TableColumn>(dbColumnDefinitions), 100) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final Item<TableColumn> item) { final TableColumn column = item.getModelObject(); item.add(new CheckBox("visible", new PropertyModel<Boolean>(column, "visible"))); item.add(new Label("columnName", new PropertyModel<String>(column, "columnName"))); item.add(new AjaxEventBehavior("click") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { TableColumn tableColumn = (TableColumn) this.getComponent().getDefaultModelObject(); tableColumn.setVisible(!tableColumn.isVisible()); if (tableColumn.isVisible()) { item.add(AttributeModifier.replace("class", "selected")); } else { item.add(AttributeModifier.replace("class", "notSelected")); } grid.getColumnState().setColumnVisibility(tableColumn.getColumnId(), tableColumn.isVisible()); target.add(grid); target.add(this.getComponent()); open(target); } }); item.setOutputMarkupId(true); if (column.isVisible()) { item.add(AttributeModifier.replace("class", "selected")); } else { item.add(AttributeModifier.replace("class", "notSelected")); } } }; add(table); final Form<Void> columnDefinitionsForm = new Form<Void>("columnDefinitionsForm"); add(columnDefinitionsForm); AjaxSubmitLink saveButton = new AjaxSubmitLink("saveButton", columnDefinitionsForm) { private static final long serialVersionUID = 1L; @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("getTableColumnDefinitions(); "); attributes.getAjaxCallListeners().add(ajaxCallListener); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { String columnDefinitionsString = form.getRequest().getPostParameters() .getParameterValue("columnDefinitions").toString(); List<TableColumn> jsColDefinitions = asList(columnDefinitionsString); orderTableColumns(dbColumnDefinitions, jsColDefinitions); try { saveColumnDefinitionsToDb(jsColDefinitions); modifyDBColumnDefinitionList(jsColDefinitions); } catch (DatabaseAccessException dae) { throw new RuntimeException("Unable to save table Column definitions in db: " + ((TestExplorerSession) Session.get()).getDbName(), dae); } catch (SQLException sqle) { throw new RuntimeException("Unable to save table Column definitions in db: " + ((TestExplorerSession) Session.get()).getDbName(), sqle); } close(target); } }; add(AttributeModifier.append("class", "runsTableColDialogDivWrapper")); columnDefinitionsForm.add(saveButton); add(new Behavior() { private static final long serialVersionUID = 1L; @Override public void renderHead(Component component, IHeaderResponse response) { if (autoAddToHeader()) { String script = "jQuery.fn.center=function(){" + "this.css(\"position\",\"absolute\");" + "this.css(\"top\",(jQuery(window).height()-this.height())/2+jQuery(window).scrollTop()+\"px\");" + "this.css(\"left\",(jQuery(window).width()-this.width())/2+jQuery(window).scrollLeft()+\"px\");" + "return this};"; String css = "#settingsoverlay,.settingsoverlay,#settingsoverlay_high," + ".settingsoverlay_high{filter:Alpha(Opacity=40);" + "-moz-opacity:.4;opacity:.4;background-color:#444;display:none;position:absolute;" + "left:0;top:0;width:100%;height:100%;text-align:center;z-index:5000;}" + "#settingsoverlay_high,.settingsoverlay_high{z-index:6000;}" + "#settingsoverlaycontent,#settingsoverlaycontent_high{display:none;z-index:5500;" + "text-align:center;}.settingsoverlaycontent," + ".settingsoverlaycontent_high{display:none;z-index:5500;text-align:left;}" + "#settingsoverlaycontent_high,.settingsoverlaycontent_high{z-index:6500;}" + "#settingsoverlaycontent .modalborder," + "#settingsoverlaycontent_high .modalborder{padding:15px;width:300px;" + "border:1px solid #444;background-color:white;" + "-webkit-box-shadow:0 0 10px rgba(0,0,0,0.8);-moz-box-shadow:0 0 10px rgba(0,0,0,0.8);" + "box-shadow:0 0 10px rgba(0,0,0,0.8);" + "filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5,OffY=5,Color='gray');" + "-ms-filter:\"progid:DXImageTransform.Microsoft.dropshadow(OffX=5,OffY=5,Color='gray')\";}"; response.render(JavaScriptHeaderItem.forScript(script, null)); response.render(CssHeaderItem.forCSS(css, null)); if (isSupportIE6()) { response.render(JavaScriptHeaderItem .forReference(new PackageResourceReference(getClass(), "jquery.bgiframe.js"))); } } response.render(OnDomReadyHeaderItem.forScript(getJS())); } private String getJS() { StringBuilder sb = new StringBuilder(); sb.append("if (jQuery('#").append(getDivId()) .append("').length == 0) { jQuery(document.body).append('") .append(getDiv().replace("'", "\\'")).append("'); }"); return sb.toString(); } private String getDivId() { return getMarkupId() + "_ovl"; } private String getDiv() { if (isClickBkgToClose()) { return ("<div id=\"" + getDivId() + "\" class=\"settingsoverlayCD\" onclick=\"" + getCloseString() + "\"></div>"); } else { return ("<div id=\"" + getDivId() + "\" class=\"settingsoverlayCD\"></div>"); } } }); }
From source file:com.axway.ats.testexplorer.pages.model.PagingToolbar.java
License:Apache License
private void addColumnsDialog(final List<TableColumn> dbColumnDefinitions) { final MainDataGrid grid = getDataGrid(); Form<Object> form = new Form<Object>("columnsForm"); add(form);/*from w w w .j a v a 2 s.c o m*/ final ColumnsDialog dialog = new ColumnsDialog("modal", grid, dbColumnDefinitions); dialog.setClickBkgToClose(true); form.add(dialog); AjaxButton openChColumnsDialogButton = new AjaxButton("chColsButton", new Model<String>("Change columns")) { private static final long serialVersionUID = 1L; @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("getTableColumnDefinitions(); "); attributes.getAjaxCallListeners().add(ajaxCallListener); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // get column definitions from the JavaScript String columnDefinitionString = form.getRequest().getPostParameters() .getParameterValue("columnDefinitions").toString(); // as List List<TableColumn> jsColumnDefinitions = dialog.asList(columnDefinitionString); for (TableColumn colDefinition : dbColumnDefinitions) { if (jsColumnDefinitions.contains(colDefinition)) { // add column id jsColumnDefinitions.get(jsColumnDefinitions.indexOf(colDefinition)) .setColumnId(colDefinition.getColumnId()); } } //update column indexes according to the JavaScript result ColumnsState cs = grid.getColumnState(); int index; if (cs.getEntry("check") != null) { index = 1; } else { index = 0; } for (TableColumn col : jsColumnDefinitions) { cs.setColumnIndex(col.getColumnId(), index++); cs.setColumnWidth(col.getColumnId(), col.getInitialWidth()); } grid.setColumnState(cs); //reload grid target.add(grid); //open column selection dialog dialog.open(target); } }; form.add(openChColumnsDialogButton); }
From source file:com.axway.ats.testexplorer.pages.model.PagingToolbar.java
License:Apache License
private void addToolbarButtons(int supportedOperations) { final MainDataGrid grid = getDataGrid(); final IDataSource<?> dataSource = grid.getDataSource(); buttonsForm = new Form<Object>("toolbarButtonsForm"); buttonsForm.setOutputMarkupId(true); add(buttonsForm);//from w w w . j a v a2s .co m defaultMode = new WebMarkupContainer("defaultMode"); defaultMode.setVisible((supportedOperations & MainDataGrid.OPERATION_EDIT) > 0); editMode = new WebMarkupContainer("editMode"); editMode.setVisible(false); buttonsForm.add(defaultMode); buttonsForm.add(editMode); // add DELETE button for DEFAULT mode AjaxButton deleteButton = new AjaxButton("deleteButton") { private static final long serialVersionUID = 1L; // Add user confirmation dialog on the delete event @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); int selectedItems = grid.getSelectedItems().size(); if (selectedItems > 0) { ajaxCallListener.onPrecondition("return confirm('" + "Are you sure you want to delete the selected " + "item(s)?" + "');"); attributes.getAjaxCallListeners().add(ajaxCallListener); } } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // collect the objects to delete List<Object> objectsToDelete = new ArrayList<Object>(); for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { objectsToDelete.add(model.getObject()); } // delete deleteObjects(objectsToDelete); // the selected items were deleted, unselect them grid.resetSelectedItems(); target.add(grid); } }; deleteButton.setVisible((supportedOperations & MainDataGrid.OPERATION_DELETE) > 0); defaultMode.add(deleteButton); // add EDIT button for DEFAULT mode AjaxButton editButton = new AjaxButton("editButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (grid.getSelectedItems().size() > 0) { for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { grid.setItemEdit(model, true); } grid.switchToEditMode(); target.add(grid); } } }; editButton.setVisible((supportedOperations & MainDataGrid.OPERATION_EDIT) > 0); defaultMode.add(editButton); //add MESSAGE button for run and suite AjaxButton messageButton = new AjaxButton("messageButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { PageParameters parameters = new PageParameters(); // pass database name parameters.add("dbname", ((TestExplorerSession) Session.get()).getDbName()); String id = null; if (dataSource instanceof ScenariosDataSource) { id = ((ScenariosDataSource) dataSource).getSuiteId(); parameters.add("suiteId", id); setResponsePage(SuiteMessagePage.class, parameters); } else if (dataSource instanceof SuitesDataSource) { id = ((SuitesDataSource) dataSource).getRunId(); parameters.add("runId", id); setResponsePage(RunMessagePage.class, parameters); } } }; if (dataSource instanceof ScenariosDataSource) { messageButton.add(new Label("button_label", "Suite messages")); } else if (dataSource instanceof SuitesDataSource) { messageButton.add(new Label("button_label", "Run messages")); } messageButton.setVisible((supportedOperations & MainDataGrid.OPERATION_GET_LOG) > 0); defaultMode.add(messageButton); // add ADD TO COMPARE BASKET button for DEFAULT mode AjaxButton addToCompareButton = new AjaxButton("addToCompareButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { ((TestExplorerSession) Session.get()).getCompareContainer().addObject(model.getObject(), ((BasePage) getPage()).getCurrentPath()); } target.add(((BasePage) getPage()).getItemsCountLabel()); // unselect the items grid.resetSelectedItems(); target.add(grid); target.appendJavaScript( "$(\".arrowUpIndicator\").stop(true,true).removeAttr('style').show().effect(\"shake\",{times:2},300).fadeOut('slow');"); } }; addToCompareButton.setVisible((supportedOperations & MainDataGrid.OPERATION_ADD_TO_COMPARE) > 0); defaultMode.add(addToCompareButton); // add CREATE REPORT button for DEFAULT mode AjaxButton createReportButton = new AjaxButton("createReportButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { TestExplorerSession session = (TestExplorerSession) Session.get(); Collection<IModel<?>> selectedItems = grid.getSelectedItems(); if (selectedItems.isEmpty()) { error("Please select a test to create a report for"); return; } boolean workingWithScenarios = selectedItems.iterator().next().getObject() instanceof Scenario; String testcaseId = null; if (workingWithScenarios) { // get the ID of the first selected scenario int firstSuiteId = Integer.MAX_VALUE; String firstScenarioName = ""; for (IModel<?> model : selectedItems) { Object obj = model.getObject(); int thisSuiteId = Integer.parseInt(((Scenario) obj).suiteId); if (thisSuiteId < firstSuiteId) { firstSuiteId = thisSuiteId; firstScenarioName = ((Scenario) obj).name; } } try { // get the ID of the first testcase List<Testcase> testcases = session.getDbReadConnection().getTestcases(0, 1, "where suiteId=" + firstSuiteId, "testcaseId", true, ((TestExplorerSession) Session.get()).getTimeOffset()); if (testcases.size() < 1) { error("Could not find testcase(s) for scenario with name '" + firstScenarioName + "'and suite id " + firstSuiteId + "."); return; } testcaseId = testcases.get(0).testcaseId; } catch (DatabaseAccessException e) { error("Could not fetch testcase(s) for scenario with name '" + firstScenarioName + "'and suite id " + firstSuiteId + "."); return; } } else { testcaseId = ((Testcase) selectedItems.iterator().next().getObject()).testcaseId; } PageParameters parameters = new PageParameters(); parameters.add("testcaseId", testcaseId); setResponsePage(SelectTestcaseReportPage.class, parameters); } }; createReportButton.setVisible((supportedOperations & MainDataGrid.OPERATION_CREATE_REPORT) > 0); defaultMode.add(createReportButton); // add APPLY button for EDIT mode AjaxButton applyButton = new AjaxButton("applyButton", grid.getForm()) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { boolean hasError = false; for (IModel<?> model : (Collection<IModel<?>>) grid.getSelectedItems()) { if (updateObject(model.getObject())) { grid.setItemEdit(model, false); } else { hasError = true; } } if (!hasError) { grid.switchToDefaultMode(); } grid.resetSelectedItems(); target.add(grid); } }; applyButton.setVisible((supportedOperations & MainDataGrid.OPERATION_EDIT) > 0); editMode.add(applyButton); // add CANCEL button for DEFAULT mode AjaxButton cancelButton = new AjaxButton("cancelButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { grid.setItemEdit(model, false); } grid.switchToDefaultMode(); grid.resetSelectedItems(); target.add(grid); } }; cancelButton.setVisible((supportedOperations & MainDataGrid.OPERATION_EDIT) > 0); cancelButton.setDefaultFormProcessing(false); editMode.add(cancelButton); // add STATUS CHANGE buttons for DEFAULT mode AjaxButton statusChangePassButton = new AjaxButton("statusChangePassButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // collect the objects to change state to PASS List<Object> objectsToPass = new ArrayList<Object>(); for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { objectsToPass.add(model.getObject()); } changeTestcaseStatus(objectsToPass, 1); // unselect the selected items grid.resetSelectedItems(); target.add(grid); } }; statusChangePassButton.setVisible((supportedOperations & MainDataGrid.OPERATION_STATUS_CHANGE) > 0); defaultMode.add(statusChangePassButton); AjaxButton statusChangeFailButton = new AjaxButton("statusChangeFailButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // collect the objects to change state to FAIL List<Object> objectsToFail = new ArrayList<Object>(); for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { objectsToFail.add(model.getObject()); } changeTestcaseStatus(objectsToFail, 0); // unselect the selected items grid.resetSelectedItems(); target.add(grid); } }; statusChangeFailButton.setVisible((supportedOperations & MainDataGrid.OPERATION_STATUS_CHANGE) > 0); defaultMode.add(statusChangeFailButton); AjaxButton statusChangeSkipButton = new AjaxButton("statusChangeSkipButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // collect the objects to change state to SKIP List<Object> objectsToSkip = new ArrayList<Object>(); for (IModel<?> model : (Collection<IModel>) grid.getSelectedItems()) { objectsToSkip.add(model.getObject()); } changeTestcaseStatus(objectsToSkip, 2); // unselect the selected items grid.resetSelectedItems(); target.add(grid); } }; statusChangeSkipButton.setVisible((supportedOperations & MainDataGrid.OPERATION_STATUS_CHANGE) > 0); defaultMode.add(statusChangeSkipButton); }
From source file:com.evolveum.midpoint.web.component.util.AjaxCallListenerFactory.java
License:Apache License
/** * this listener will disable javascript event propagation from component to parent dom components * * @return {@link IAjaxCallListener}/*w ww . j a va 2s . c o m*/ */ public static IAjaxCallListener stopPropagation() { return new AjaxCallListener().onBefore("\nattrs.event.stopPropagation();"); }
From source file:com.gkrupa.samples.rebel.wicket.pages.panels.PanelOne.java
License:Apache License
@Override protected void onInitialize() { super.onInitialize(); final Form<Void> formOne = new Form<Void>("formOne"); final Label nameLbl = new Label("nameLbl", new PropertyModel<String>(getModel(), "fullName")); nameLbl.setOutputMarkupId(true);/*from w w w. ja v a 2 s .com*/ // final TextField<String> firstName = new TextField<String>("firstName", new PropertyModel<String>(getModel(), "firstName")); // firstName.add(new AjaxFormSubmitBehavior(formOne, "onkeyup") { // private static final long serialVersionUID = 1L; // @Override // protected void onSubmit(AjaxRequestTarget target) { // target.add(nameLbl); // getModelObject().setFirstName(firstName.getValue()); // } // // @Override // protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { // super.updateAjaxAttributes(attributes); // IAjaxCallListener listener = new AjaxCallListener() { // private static final long serialVersionUID = 1L; // // @Override // public CharSequence getAfterHandler(Component component) { // return "console.log('Hello World "+ getModelObject().getFullName() + "');"; // } // }; // attributes.getAjaxCallListeners().add(listener); // } // }); final TextField<String> lastName = new TextField<String>("lastName", new PropertyModel<String>(getModel(), "lastName")); lastName.add(new AjaxFormSubmitBehavior(formOne, "onkeyup") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { target.add(nameLbl); getModelObject().setLastName(lastName.getValue()); } }); final TextField<Integer> age = new TextField<Integer>("age", new PropertyModel<Integer>(getModel(), "age")); age.add(new AjaxFormSubmitBehavior(formOne, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { target.add(nameLbl); } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); IAjaxCallListener listener = new AjaxCallListener() { private static final long serialVersionUID = 1L; @Override public CharSequence getAfterHandler(Component component) { return "console.log('Hello World " + getModelObject().getFullName() + "');"; } }; attributes.getAjaxCallListeners().add(listener); } }); // formOne.add(firstName); formOne.add(lastName); formOne.add(age); formOne.add(nameLbl); add(formOne); }
From source file:com.googlecode.wicket.jquery.ui.widget.dialog.ButtonAjaxBehavior.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); if (this.button.isIndicating()) { AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onBefore(this.getBeforeStatement()); ajaxCallListener.onSuccess(this.getFinishStatement()); ajaxCallListener.onFailure(this.getFinishStatement()); attributes.getAjaxCallListeners().add(ajaxCallListener); }//from w w w . ja v a 2 s . co m }
From source file:com.romeikat.datamessie.core.base.ui.component.AjaxConfirmationLink.java
License:Open Source License
@Override protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); final AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("return confirm('" + text + "');"); attributes.getAjaxCallListeners().add(ajaxCallListener); }
From source file:com.wicketinaction.HandlebarsButton.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); // let Wicket.Ajax/jQuery know that the result is JSON so it will parse it for you attributes.setDataType("json"); // tell Wicket.Ajax to not try to process the Ajax response because it is not the normal <ajax-response> attributes.setWicketAjaxResponse(false); // register the onSuccess listener that will execute Handlebars logic AjaxCallListener listener = new AjaxCallListener() { @Override//www . ja v a 2s .c om public CharSequence getSuccessHandler(Component component) { // returns an instance of JsonFunction, so Wicket will render it as is return onSuccessFunction; } }; // the following handlers are not JsonFunction and they will be wrapped in JsonFunction by Wicket and the // appropriate parameters will be passed. // For the 'before' handler it looks like: function(attrs, jqXHR, settings){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');} listener.onBefore("Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');"); // For the 'complete' handler it looks like: function(attrs, jqXHR, textStatus){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler');} listener.onComplete( "Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler. Status: ' + textStatus);"); // change the return to 'false' and the Ajax call wont be executed at all. listener.onPrecondition("return true;"); attributes.getAjaxCallListeners().add(listener); }
From source file:cz.zcu.kiv.eegdatabase.wui.components.form.AjaxWizardButton.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("return confirm('" + message + "');"); attributes.getAjaxCallListeners().add(ajaxCallListener); }
From source file:cz.zcu.kiv.eegdatabase.wui.components.form.input.AjaxConfirmLink.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener ajaxCallListener = new AjaxCallListener(); ajaxCallListener.onPrecondition("return confirm('" + confirmMessage + "');"); attributes.getAjaxCallListeners().add(ajaxCallListener); }