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.runs.RunsFilter.java

License:Apache License

@SuppressWarnings({ "rawtypes" })
public RunsFilter(String id, final DataGrid dataGrid, final PageParameters parameters) {

    super(id);//from   w  ww.ja va 2 s. co  m

    // filter fields
    searchByRun.setEscapeModelStrings(false);
    searchByRun.setOutputMarkupId(true);
    searchByProduct.setEscapeModelStrings(false);
    searchByProduct.setOutputMarkupId(true);
    searchByVersion.setEscapeModelStrings(false);
    searchByVersion.setOutputMarkupId(true);
    searchByBuild.setEscapeModelStrings(false);
    searchByBuild.setOutputMarkupId(true);
    searchByOs.setEscapeModelStrings(false);
    searchByOs.setOutputMarkupId(true);
    searchByUserNote.setOutputMarkupId(true);
    searchByUserNote.setEscapeModelStrings(false);
    searchByAfterDate.setOutputMarkupId(true);
    searchByBeforeDate.setOutputMarkupId(true);

    searchByAfterDate.add(DateValidator.maximum(new Date(), "dd.MM.yyyy"));

    add(searchByRun);
    add(searchByProduct);
    add(searchByVersion);
    add(searchByBuild);
    add(searchByOs);
    add(searchByUserNote);
    add(searchByAfterDate);
    add(searchByBeforeDate);

    // attach a Date Picker component
    searchByAfterDate.add(new TEDatePicker().setShowOnFieldClick(true).setAutoHide(true));
    searchByBeforeDate.add(new TEDatePicker().setShowOnFieldClick(true).setAutoHide(true));

    // search button
    AjaxButton searchButton = new AjaxButton("search_button") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            clearPageParameters(parameters);

            target.add(dataGrid);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {

            super.onError(target, form);
        }
    };
    add(searchButton);
    // search button is the button to trigger when user hit the enter key
    this.setDefaultButton(searchButton);

    // reset button
    add(new AjaxButton("reset_button") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            // reset the filter
            searchByRun.setModelObject("");
            searchByProduct.setModelObject("");
            searchByVersion.setModelObject("");
            searchByBuild.setModelObject("");
            searchByOs.setModelObject("");
            searchByUserNote.setModelObject("");
            searchByAfterDate.setModelObject(null);
            searchByBeforeDate.setModelObject(null);

            target.add(searchByRun);
            target.add(searchByProduct);
            target.add(searchByVersion);
            target.add(searchByBuild);
            target.add(searchByOs);
            target.add(searchByUserNote);
            target.add(searchByAfterDate);
            target.add(searchByBeforeDate);

            // automatically trigger a new search
            target.add(dataGrid);
        }
    });

    // copy URL button
    add(new AjaxButton("copy_url_button") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            String jsQuery = "window.prompt(\"Press 'Ctrl+C' to copy the following URL containing all Runs filter data\", window.location";
            if (StringUtils.isNullOrEmpty(urlParameters)) {
                jsQuery = jsQuery + ")";
            } else {
                jsQuery = jsQuery + "+'&" + urlParameters + "')";
            }
            target.appendJavaScript(jsQuery);
            target.add(dataGrid);
        }
    });

    setSearchValuesOnLoad(parameters);

}

From source file:com.axway.ats.testexplorer.pages.runsByTypeDashboard.home.Filter.java

License:Apache License

public Filter() {

    super("filter");

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

    try {/*from w  w w .  j av a2  s.  com*/

        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>(versionNames);

                    searchByVersion.getModel().setObject(selectedVersionNames);

                    searchByVersion.setChoices(versionNames);

                    target.add(searchByVersion);

                } catch (DatabaseAccessException e) {
                    error("Unable to get version names");
                    LOG.error(e);
                }

            }

        });

    } catch (DatabaseAccessException e) {
        error(e.getMessage());
        LOG.error(e);
    }

    versionNames = new ArrayList<String>(1);
    selectedVersionNames = new ArrayList<String>(1);

    searchByVersion = new ListMultipleChoice<String>("search_by_version",
            new ListModel<String>(selectedVersionNames), versionNames);

    searchByVersion.setEscapeModelStrings(false);
    searchByVersion.setOutputMarkupId(true);

    add(searchByProduct);
    add(searchByVersion);

    AjaxButton searchButton = new AjaxButton("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            List<String[]> productAndVersionNames = new ArrayList<String[]>(1);

            for (String versionName : selectedVersionNames) {
                productAndVersionNames.add(new String[] { selectedProductName, versionName });
            }

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

            try {
                new DashboardHomeUtils().callJavaScript(target, new DashboardHomeUtils().initJsonData(
                        productAndVersionNames, session.getDbReadConnection().getAllBuildTypes("AND 1=1")));
            } catch (DatabaseAccessException e) {
                error("Unable to get runs data");
                LOG.error("Unable to get runs data", e);
            }

        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {

            super.onError(target, form);
        }

    };
    add(searchButton);
    // search button is the button to trigger when user hit the enter key
    this.setDefaultButton(searchButton);

    add(new AjaxButton("clear") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            selectedProductName = null;

            selectedVersionNames = new ArrayList<String>(1);
            versionNames = new ArrayList<String>(1);

            searchByProduct.setModelObject(selectedProductName);

            searchByVersion.setModelObject(selectedVersionNames);
            searchByVersion.setChoices(new ListModel<String>(versionNames));

            target.add(searchByProduct);
            target.add(searchByVersion);

            target.appendJavaScript(";$('#container').empty();");

        }

    });

}

From source file:com.axway.ats.testexplorer.pages.testcase.attachments.AttachmentsPanel.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public AttachmentsPanel(String id, final String testcaseId, final PageParameters parameters) {
    super(id);/* w w  w  .j a  va  2 s  . c om*/

    form = new Form<Object>("form");
    buttonPanel = new WebMarkupContainer("buttonPanel");
    noButtonPanel = new WebMarkupContainer("noButtonPanel");
    fileContentContainer = new TextArea<String>("textFile", new Model<String>(""));
    imageContainer = new WebMarkupContainer("imageFile");
    fileContentInfo = new Label("fileContentInfo", new Model<String>(""));
    buttons = getAllAttachedFiles(testcaseId);

    form.add(fileContentContainer);
    form.add(imageContainer);
    form.add(fileContentInfo);
    form.add(buttonPanel);

    add(noButtonPanel);
    add(form);

    buttonPanel.setVisible(!(buttons == null));
    fileContentContainer.setVisible(false);
    imageContainer.setVisible(false);
    fileContentInfo.setVisible(false);
    noButtonPanel.setVisible(buttons == null);

    // if noButtonPanel is visible, do not show form and vice versa
    form.setVisible(!noButtonPanel.isVisible());

    noButtonPanel.add(new Label("description", noButtonPanelInfo));

    final ListView lv = new ListView("buttons", buttons) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem item) {

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }

            final String viewedFile = buttons.get(item.getIndex());

            final String name = getFileSimpleName(buttons.get(item.getIndex()));
            final Label buttonLabel = new Label("name", name);

            Label fileSize = new Label("fileSize", getFileSize(viewedFile));

            downloadFile = new DownloadLink("download", new File(" "), "");
            downloadFile.setModelObject(new File(viewedFile));
            downloadFile.setVisible(true);

            alink = new AjaxLink("alink", item.getModel()) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {

                    fileContentInfo.setVisible(true);
                    String fileContent = new String();
                    if (!isImage(viewedFile)) {
                        fileContentContainer.setVisible(true);
                        imageContainer.setVisible(false);
                        fileContent = getFileContent(viewedFile, name);
                        fileContentContainer.setModelObject(fileContent);
                    } else {

                        PageNavigation navigation = null;
                        try {
                            navigation = ((TestExplorerSession) Session.get()).getDbReadConnection()
                                    .getNavigationForTestcase(testcaseId, getTESession().getTimeOffset());
                        } catch (DatabaseAccessException e) {
                            LOG.error("Can't get runId, suiteId and dbname for testcase with id=" + testcaseId,
                                    e);
                        }

                        String runId = navigation.getRunId();
                        String suiteId = navigation.getSuiteId();
                        String dbname = TestExplorerUtils.extractPageParameter(parameters, "dbname");

                        fileContentInfo.setDefaultModelObject("Previewing '" + name + "' image");

                        final String url = "AttachmentsServlet?&runId=" + runId + "&suiteId=" + suiteId
                                + "&testcaseId=" + testcaseId + "&dbname=" + dbname + "&fileName=" + name;
                        imageContainer.add(new AttributeModifier("src", new Model<String>(url)));
                        imageContainer.setVisible(true);
                        fileContentContainer.setVisible(false);
                    }

                    // first setting all buttons with the same state
                    String reverseButtonsState = "var cusid_ele = document.getElementsByClassName('attachedButtons'); "
                            + "for (var i = 0; i < cusid_ele.length; ++i) { " + "var item = cusid_ele[i];  "
                            + "item.style.color= \"#000000\";" + "}";
                    // setting CSS style to the pressed button and its label
                    String pressClickedButton = "var span = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "span.style.backgroundPosition=\"left bottom\";"
                            + "span.style.padding=\"6px 0 4px 18px\";"
                            + "var button = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']/..\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "button.style.backgroundPosition=\"right bottom\";"
                            + "button.style.color=\"#000000\";" + "button.style.outline=\"medium none\";";

                    // I could not figure out how it works with wicket, so i did it with JS
                    target.appendJavaScript(reverseButtonsState);
                    target.appendJavaScript(pressClickedButton);

                    target.add(form);
                }
            };

            alink.add(buttonLabel);
            item.add(alink);
            item.add(downloadFile);
            item.add(fileSize);
        }
    };
    buttonPanel.add(lv);
}

From source file:com.axway.ats.testexplorer.pages.testcase.statistics.charts.ChartsPanel.java

License:Apache License

private AjaxLink<?> getRefreshChartLink(final String diagramName) {

    AjaxLink refreshChartLink = new AjaxLink("refreshChart") {

        private static final long serialVersionUID = 1L;

        @Override//from  w  ww  .  j a  v a 2 s  .  c o m
        public void onClick(AjaxRequestTarget target) {

            List<DbStatisticDescription> dataToBeUpdated = diagramContent.get(diagramName);
            Set<Integer> sysStatisticTypeIds = new HashSet<Integer>();
            Set<Integer> sysMachineIds = new HashSet<Integer>();
            Set<Integer> usrStatisticTypeIds = new HashSet<Integer>();
            Set<Integer> usrMachineIds = new HashSet<Integer>();
            Set<Integer> testcaseIds = new HashSet<Integer>();
            StringBuilder actions = new StringBuilder();
            StringBuilder actionParents = new StringBuilder();
            Set<String> expectedActions = new HashSet<String>();

            // collect all the data from this diagram, so all statistics could be updated successfully
            for (DbStatisticDescription dbStatDescription : dataToBeUpdated) {
                testcaseIds.add(dbStatDescription.testcaseId);
                if (SQLServerDbReadAccess.MACHINE_NAME_FOR_ATS_AGENTS.equals(dbStatDescription.machineName)) {
                    usrStatisticTypeIds.add(dbStatDescription.statisticId);
                    usrMachineIds.add(dbStatDescription.machineId);
                } else if (dbStatDescription.machineId != 0) {
                    sysStatisticTypeIds.add(dbStatDescription.statisticId);
                    sysMachineIds.add(dbStatDescription.machineId);
                } else {
                    actions.append("'").append(dbStatDescription.name).append("'").append(",");
                    if (actionParents.indexOf(dbStatDescription.parentName) == -1) {
                        actionParents.append("'").append(dbStatDescription.parentName).append("',");
                    }
                    expectedActions.add(dbStatDescription.testcaseId + "->" + dbStatDescription.machineId + "->"
                            + dbStatDescription.parentName + "->" + dbStatDescription.name);
                }
            }

            loadActionStatisticsFromDatabase(testcaseIds, actions, actionParents, expectedActions);
            loadSystemStatisticsFromDatabase(sysStatisticTypeIds, sysMachineIds);
            loadUserStatisticsFromDatabase(usrStatisticTypeIds, usrMachineIds);

            refreshDiagramContent();

            target.add(chartsPanelContent);
        }
    };
    return refreshChartLink;
}

From source file:com.axway.ats.testexplorer.pages.testcase.statistics.StatisticsPanel.java

License:Apache License

/**
 * @return ListView containing all diagrams
 *///from w w  w  . ja  v a 2 s  . c o m
private ListView<DbStatisticDescription> addChartGroupListView() {

    ListView<DbStatisticDescription> listViewChartGroup = new ListView<DbStatisticDescription>("chartGroupRows",
            listViewContent) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<DbStatisticDescription> item) {

            DbStatisticDescription statElement = listViewContent.get(item.getIndex());

            if (statElement.name.equals("HEADER")) { // add the header row for the diagram table
                item.add(AttributeModifier.replace("class", "chartGroupHeader"));
                Label removeIcon = new Label("removeIcon");
                removeIcon.add(AttributeModifier.append("style", ";display:none;"));
                item.add(removeIcon);
                item.add(addDiagramHeaderName("statName", "Name"));

                IModel<String> aliasModel = new Model<String>();
                aliasModel.setObject("Alias");
                TextField<String> alias = new TextField<String>("alias", aliasModel);
                alias.setOutputMarkupId(true);
                alias.add(AttributeModifier.append("style",
                        ";background-color:transparent;border:0px;pointer-events:none;text-align: center;font-family:\"Times New Roman\",Times,serif;"));
                alias.add(AttributeModifier.replace("class", "chartGroupHeader"));
                item.add(alias);
                item.add(addDiagramHeaderName("startDate", "Start Time"));
                item.add(addDiagramHeaderName("run", "Run"));
                item.add(addDiagramHeaderName("suite", "Suite"));
                item.add(addDiagramHeaderName("scenario", "Scenario"));
                item.add(addDiagramHeaderName("testcase", "Testcase"));

            } else if (statElement.unit == null) { // add diagram name row

                final AjaxButton deleteAllButton = new AjaxButton("removeIcon") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onSubmit(AjaxRequestTarget target, Form<?> form) {

                        String diagramName = listViewContent.get(item.getIndex()).name;
                        getTESession().getDiagramContainer().remove(diagramName);
                        updateDiagramTableContent();

                        target.add(statsForm);
                    }
                };
                deleteAllButton
                        .add(AttributeModifier.replace("class", "fixGroupTableColumn removeAllItemsIcon"));
                item.add(deleteAllButton);
                item.add(AttributeModifier.replace("class", "chartGroup"));

                item.add(new Label("statName", "").setEscapeModelStrings(false));
                Label alias = new Label("alias", "");
                // disable and change CSS of the input tag
                alias.add(AttributeModifier.append("style",
                        ";background-color:transparent;border:0px;pointer-events:none"));
                item.add(alias);
                item.add(new Label("startDate", statElement.name).setEscapeModelStrings(false));
                item.add(new Label("run", "").setEscapeModelStrings(false));
                item.add(new Label("suite", "").setEscapeModelStrings(false));
                item.add(new Label("scenario", "").setEscapeModelStrings(false));
                item.add(new Label("testcase", "").setEscapeModelStrings(false));

            } else { // add diagram content
                List<String> statNavigationTokens = getStatisticNavigation(statElement);
                final AjaxButton deleteButton = new AjaxButton("removeIcon") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onSubmit(AjaxRequestTarget target, Form<?> form) {

                        deleteSingleRowFromDiagramList(item);
                        updateDiagramTableContent();

                        target.add(statsForm);
                    }
                };
                item.add(deleteButton);
                item.add(new Label("statName", statElement.name).setEscapeModelStrings(false));
                IModel<String> aliasModel = null;
                DbStatisticDescription currentElement = listViewContent.get(item.getIndex());
                String currentElementKey = null;
                if (currentElement.getStatisticId() != 0 && currentElement.machineId != 0) {
                    currentElementKey = getDiagramName(item.getIndex()) + "_" + currentElement.testcaseStarttime
                            + "_" + currentElement.getStatisticId() + "_" + currentElement.machineId;
                } else {
                    currentElementKey = getDiagramName(item.getIndex()) + "_" + currentElement.testcaseStarttime
                            + "_" + currentElement.getName() + "_" + currentElement.getParentName();
                }
                // using diagramName+testcaseStartTime+statisticTypeId+machineId or testcaseStartTime+name+queueName for key
                IModel<String> alias = getTESession().getStatisticsAliasModels().get(currentElementKey);
                if (alias != null && alias.getObject() != null) {
                    aliasModel = alias;
                } else {
                    aliasModel = new Model<String>();
                }
                getTESession().getStatisticsAliasModels().put(currentElementKey, aliasModel);
                item.add(new TextField<String>("alias", aliasModel).setOutputMarkupId(true));
                item.add(new Label("startDate", statNavigationTokens.get(4)).setEscapeModelStrings(false));
                item.add(new Label("run", statNavigationTokens.get(0)).setEscapeModelStrings(false));
                item.add(new Label("suite", statNavigationTokens.get(1)).setEscapeModelStrings(false));
                item.add(new Label("scenario", statNavigationTokens.get(2)).setEscapeModelStrings(false));
                item.add(new Label("testcase", statNavigationTokens.get(3)).setEscapeModelStrings(false));
            }
        };
    };
    listViewChartGroup.setOutputMarkupId(true);

    return listViewChartGroup;
}

From source file:com.axway.ats.testexplorer.pages.testcase.statistics.StatisticsPanel.java

License:Apache License

/**
 * @return button that add new diagram to the table
 *///from  w  ww  .j  a  va  2  s .  co  m
private AjaxSubmitLink getAddDiagramButton() {

    AjaxSubmitLink addDiagramButton = new AjaxSubmitLink("addDiagramButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            // get the statistics, that should be added to the diagram
            List<DbStatisticDescription> selectedStatistics = getSelectedStatistics();
            if (selectedStatistics.size() > 0) {
                String diagramName = diagramNameModel.getObject();
                if (defaultDiagramName.equals(diagramName)) {
                    getTESession().setDiagramNameIndex(getTESession().getDiagramNameIndex() + 1);
                    defaultDiagramName = "Diagram" + getTESession().getDiagramNameIndex();
                }
                // check if there is already existing diagram with the same name and if do, we will add the new statistics to it
                Map<String, List<LinkedHashMap<String, List<DbStatisticDescription>>>> allDiagrams = getTESession()
                        .getDiagramContainer();
                if (allDiagrams.containsKey(diagramName)) {
                    List<LinkedHashMap<String, List<DbStatisticDescription>>> diagram = allDiagrams
                            .get(diagramName);
                    for (LinkedHashMap<String, List<DbStatisticDescription>> testcase : diagram) {
                        if (testcase.containsKey(testcaseId)) {
                            for (DbStatisticDescription stat : selectedStatistics) {
                                if (!testcase.get(testcaseId).contains(stat)) {
                                    testcase.get(testcaseId).add(stat);
                                }
                            }
                        } else {
                            testcase.put(testcaseId, selectedStatistics);
                            getTESession().getDiagramContainer().put(diagramName, diagram);
                        }
                    }
                } else {
                    LinkedHashMap<String, List<DbStatisticDescription>> newDiagram = new LinkedHashMap<String, List<DbStatisticDescription>>();
                    newDiagram.put(testcaseId, selectedStatistics);
                    List<LinkedHashMap<String, List<DbStatisticDescription>>> diagram = new ArrayList<LinkedHashMap<String, List<DbStatisticDescription>>>();
                    diagram.add(newDiagram);
                    getTESession().getDiagramContainer().put(diagramName, diagram);
                }
            }
            // update the content of the diagram table
            updateDiagramTableContent();

            diagramNameModel.setObject("Diagram" + getTESession().getDiagramNameIndex());

            // uncheck all selected statistics
            String uncheckCheckboxes = "checkboxes = document.getElementsByTagName('input');"
                    + "for(var i = 0; i < checkboxes.length; i++) {"
                    + "if(checkboxes[i].type.toLowerCase() == 'checkbox') {"
                    + "if(checkboxes[i].checked == true){" + "checkboxes[i].click();" + "}}}";
            target.appendJavaScript(uncheckCheckboxes);

            String scrollToTop = "$('html,body').scrollTop(0);";
            target.appendJavaScript(scrollToTop);

            target.add(statsForm);
            super.onSubmit(target, form);
        }
    };

    return addDiagramButton;
}

From source file:com.axway.ats.testexplorer.pages.testcases.TestcasesPanel.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public TestcasesPanel(BasePage parentPage, String id, String suiteId, String scenarioId) {

    super(id);//from   www . j a  va  2s. c o  m

    // Add Testcases table
    List<TableColumn> columnDefinitions = getTableColumnDefinitions();
    List<IGridColumn> columns = new ArrayList<IGridColumn>();

    columns.add(new CheckBoxColumn("check"));
    for (final TableColumn cd : columnDefinitions) {

        AbstractColumn col;
        if ("Testcase".equals(cd.getColumnName())) {

            col = new TestcasesTestcaseLinkColumn(cd);
        } else if (cd.isEditable()) {

            col = new EditablePropertyColumn(cd.getColumnId(), new Model<String>(cd.getColumnName()),
                    cd.getPropertyExpression(), cd.getSortProperty()) {

                private static final long serialVersionUID = 1L;

                // Set cell tooltips
                @Override
                protected Object getProperty(Object object, String propertyExpression) {

                    Object value = PropertyResolver.getValue(propertyExpression, object);
                    if ("userNote".equals(propertyExpression) && value != null) {

                        value = "<span title=\"" + value + "\">" + value + "</span>";
                        setEscapeMarkup(false);
                    }
                    return value;
                }

                @Override
                protected boolean isClickToEdit() {

                    return false;
                }
            };
        } else {

            col = new PropertyColumn(cd.getColumnId(), new Model<String>(cd.getColumnName()),
                    cd.getPropertyExpression(), cd.getSortProperty()) {

                private static final long serialVersionUID = 1L;

                @Override
                public String getCellCssClass(IModel rowModel, int rowNum) {

                    if ("state".equals(getId())) {
                        return ((Testcase) rowModel.getObject()).state.toLowerCase() + "State";
                    } else if ("duration".equals(getId())) {
                        return "durationCell";
                    }
                    return null;
                }

                // Set column header class
                @Override
                public String getHeaderCssClass() {

                    return cd.getHeaderCssClass();
                }

                @Override
                protected Object getProperty(Object object, String propertyExpression) {

                    Testcase testcaseObject = (Testcase) object;
                    if ("dateStart".equals(propertyExpression) && testcaseObject.getDateStart() != null) {
                        setEscapeMarkup(false);
                        return "<span>" + testcaseObject.getDateStart() + "</span>";
                    } else if ("dateEnd".equals(propertyExpression) && testcaseObject.getDateEnd() != null) {
                        setEscapeMarkup(false);
                        return "<span>" + testcaseObject.getDateEnd() + "</span>";
                    } else if ("duration".equals(propertyExpression)) {
                        setEscapeMarkup(false);
                        return "<span>"
                                + testcaseObject.getDurationAsString(getTESession().getCurrentTimestamp())
                                + "</span>";
                    }

                    Object value = PropertyResolver.getValue(propertyExpression, object);
                    if ("description".equals(propertyExpression) && value != null) {

                        value = "<span title=\"" + value + "\">" + value + "</span>";
                        setEscapeMarkup(false);
                    }
                    return value;
                }

            };
        }

        // Set column initial width
        if (cd.getInitialWidth() >= 0) {
            col.setInitialSize(cd.getInitialWidth());
        }

        // set column tooltip
        col.setHeaderTooltipModel(cd.getTooltip());

        if ("User Note".equals(cd.getColumnName())) {
            col.setWrapText(true);
        }
        columns.add(col);
    }

    int supportedGridOperations = MainDataGrid.OPERATION_DELETE | MainDataGrid.OPERATION_EDIT
            | MainDataGrid.OPERATION_ADD_TO_COMPARE | MainDataGrid.OPERATION_CREATE_REPORT;
    if (parentPage.showTestcaseStatusChangeButtons) {
        supportedGridOperations |= MainDataGrid.OPERATION_STATUS_CHANGE;
    }

    final MainDataGrid grid = new MainDataGrid("testcasesTable", new TestcasesDataSource(suiteId, scenarioId),
            columns, columnDefinitions, "Testcases", supportedGridOperations);

    ((TestcasesDataSource) grid.getDataSource()).setDataGrid(grid);
    grid.setGridColumnsState(columnDefinitions);
    grid.setAllowSelectMultiple(true);
    grid.setSelectToEdit(false);
    grid.setClickRowToSelect(true);
    grid.setClickRowToDeselect(true);
    grid.setCleanSelectionOnPageChange(true);

    add(grid);

    parentPage.setMainGrid(grid);

    Form<Object> hiddenForm = new Form<Object>("hiddenForm");
    AjaxButton hiddenRefreshButton = new AjaxButton("hiddenRefreshButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            target.add(grid);
        }
    };
    hiddenForm.add(hiddenRefreshButton);
    add(hiddenForm);
}

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

License:Apache License

public TestcasesByGroupFilter(String id) {

    super(id);// ww  w .  j  a va 2 s  . co  m

    searchByProduct = createSearchByProductComponent();
    searchByVersion = createSearchByVersionComponent();
    searchByAllGroups = createSearchByAllGroupsComponent();
    searchByGroupContains = new TextField<String>("search_by_group_contains", new Model<String>(""));
    searchByGroupContains.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            if (StringUtils.isNullOrEmpty(searchByGroupContains.getModel().getObject())) {
                TestExplorerSession session = (TestExplorerSession) Session.get();
                try {
                    groupNames = session.getDbReadConnection().getAllGroupNames(selectedProductName,
                            selectedVersionNames);
                } catch (DatabaseAccessException e) {
                    LOG.error("Unable to get all group names", e);
                    error("Unable to get all group names");
                }
            } else {
                groupNames = new ArrayList<String>();
            }

            selectedGroupNames = groupNames;
            searchByAllGroups.getModel().setObject(selectedGroupNames);
            searchByAllGroups.setChoices(groupNames);
            target.add(searchByAllGroups);
        }
    });

    searchByAfterDate.setOutputMarkupId(true);
    searchByAfterDate.add(DateValidator.maximum(new Date(), "dd.MM.yyyy"));

    searchByBeforeDate.setOutputMarkupId(true);

    searchByGroupContains.setEscapeModelStrings(false);
    searchByGroupContains.setOutputMarkupId(true);

    add(searchByProduct);
    add(searchByVersion);
    add(searchByAllGroups);
    add(searchByAfterDate);
    add(searchByBeforeDate);
    add(searchByGroupContains);

    searchByAfterDate.add(new DatePicker().setShowOnFieldClick(true).setAutoHide(true));
    searchByBeforeDate.add(new DatePicker().setShowOnFieldClick(true).setAutoHide(true));

    AjaxButton searchButton = new AjaxButton("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (StringUtils.isNullOrEmpty(selectedProductName) && selectedVersionNames.size() == 0
                    && selectedGroupNames.size() == 0
                    && StringUtils.isNullOrEmpty(searchByGroupContains.getModel().getObject())
                    && StringUtils.isNullOrEmpty(searchByAfterDate.getInput())
                    && StringUtils.isNullOrEmpty(searchByBeforeDate.getInput())) {
                return;
            }

            TestExplorerSession session = (TestExplorerSession) Session.get();
            TestcaseInfoPerGroupStorage perGroupStorage = null;
            try {
                perGroupStorage = session.getDbReadConnection().getTestcaseInfoPerGroupStorage(
                        selectedProductName, selectedVersionNames, selectedGroupNames,
                        searchByAfterDate.getValue(), searchByBeforeDate.getValue(),
                        searchByGroupContains.getModel().getObject());
            } catch (DatabaseAccessException e) {
                LOG.error("Unable to get Testcases and groups data", e);
                error("Unable to get Testcases and groups data");
            }

            if (perGroupStorage != null) {
                String treemapData = perGroupStorage.generateTreemapData();

                String testcasesIdsMap = perGroupStorage.generateTestcasesIdsMap();

                String script = ";setHiddenValue(\"groups\");drawTreemap(" + treemapData + ","
                        + TestcaseInfoPerGroupStorage.TREEMAP_OPTIONS
                        + ");$('.filterHeader').click();populateFilterDataPanel(" + getFilterData()
                        + ");setTestcasesIdsMap(" + testcasesIdsMap + ");";

                target.appendJavaScript(script);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {

            super.onError(target, form);
        }

    };
    add(searchButton);
    // search button is the button to trigger when user hit the enter key
    this.setDefaultButton(searchButton);

    add(new AjaxButton("clear") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            selectedProductName = null;

            selectedVersionNames = new ArrayList<String>(1);
            versionNames = new ArrayList<String>(1);

            selectedGroupNames = new ArrayList<String>(1);
            groupNames = new ArrayList<String>(1);

            searchByProduct.getModel().setObject(selectedProductName);

            searchByVersion.getModel().setObject(selectedVersionNames);
            searchByVersion.setChoices(new ListModel<String>(versionNames));

            searchByAllGroups.getModel().setObject(selectedGroupNames);
            searchByAllGroups.setChoices(new ListModel<String>(groupNames));

            searchByAfterDate.getModel().setObject(null);
            searchByAfterDate.clearInput();

            searchByBeforeDate.clearInput();
            searchByBeforeDate.getModel().setObject(null);

            searchByGroupContains.getModel().setObject(null);

            target.add(searchByProduct);
            target.add(searchByVersion);
            target.add(searchByAllGroups);
            target.add(searchByAfterDate);
            target.add(searchByBeforeDate);
            target.add(searchByGroupContains);

            target.appendJavaScript(
                    ";$('#chart_div').empty();populateFilterDataPanel(" + getFilterData() + ");");
        }
    });
}

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

License:Apache License

private ListMultipleChoice<String> createSearchByVersionComponent() {

    versionNames = new ArrayList<String>(1);
    selectedVersionNames = new ArrayList<String>(1);

    searchByVersion = new ListMultipleChoice<String>("search_by_version",
            new ListModel<String>(selectedVersionNames), versionNames);
    searchByVersion.setEscapeModelStrings(false);
    searchByVersion.setOutputMarkupId(true);
    searchByVersion.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override//from w  w  w. jav  a  2  s . co  m
        protected void onUpdate(AjaxRequestTarget target) {

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

                groupNames = session.getDbReadConnection().getAllGroupNames(selectedProductName,
                        selectedVersionNames);

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

    return searchByVersion;
}

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

License:Apache License

private ListMultipleChoice<String> createSearchByAllGroupsComponent() {

    groupNames = new ArrayList<String>(1);
    selectedGroupNames = new ArrayList<String>(1);

    searchByAllGroups = new ListMultipleChoice<String>("search_by_all_groups",
            new ListModel<String>(selectedGroupNames), groupNames);

    searchByAllGroups.setEscapeModelStrings(false);
    searchByAllGroups.setOutputMarkupId(true);
    searchByAllGroups.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override//w  ww . ja  va 2s.  c  o m
        protected void onUpdate(AjaxRequestTarget target) {

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

                groupNames = session.getDbReadConnection().getAllGroupNames(selectedProductName,
                        selectedVersionNames);

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

            searchByGroupContains.setModelObject(null);
            target.add(searchByGroupContains);
        }
    });

    return searchByAllGroups;
}