Example usage for org.apache.wicket AttributeModifier replace

List of usage examples for org.apache.wicket AttributeModifier replace

Introduction

In this page you can find the example usage for org.apache.wicket AttributeModifier replace.

Prototype

public static AttributeModifier replace(String attributeName, Serializable value) 

Source Link

Document

Creates a attribute modifier that replaces the current value with the given value.

Usage

From source file:ch.difty.scipamato.common.web.component.table.column.LinkIconPanel.java

License:Apache License

private Label makeImage(String id) {
    Label image = new Label(id, "");
    image.add(AttributeModifier.replace("class", getDefaultModel()));
    if (titleModel != null) {
        image.add(AttributeModifier.replace("title", titleModel));
    }/*from w w  w . j a v  a  2s. com*/
    return image;
}

From source file:com.apachecon.memories.ApproveGallery.java

License:Apache License

@Override
protected void enrich(WebMarkupContainer secondContainer, UserFile file, int page) {
    secondContainer.add(new ImageLink("imageLink", file));

    final EmptyPanel decorator = new EmptyPanel("decorator");
    decorator.setOutputMarkupId(true);/*from ww  w. j  a v  a 2s.co  m*/

    if (!file.isNew()) {
        // decorate files only if they come from approved/declined directory
        decorator.add(AttributeModifier.append("class", file.isApproved() ? "approved" : "declined"));
    }
    secondContainer.add(decorator);

    secondContainer.add(new ApproveLink("approve", file) {
        private static final long serialVersionUID = 1L;

        protected void update(AjaxRequestTarget target) {
            decorator.add(AttributeModifier.replace("class", "approved"));
            target.add(decorator);
        }
    });
    secondContainer.add(new DeclineLink("decline", file) {
        private static final long serialVersionUID = 1L;

        protected void update(AjaxRequestTarget target) {
            decorator.add(AttributeModifier.replace("class", "declined"));
            target.add(decorator);
        }
    });
}

From source file:com.axway.ats.testexplorer.pages.machines.MachinesPage.java

License:Apache License

private Form<Object> getMachinesForm(final Label noMachinesLabel) {

    final Form<Object> machinesForm = new Form<Object>("machinesForm");
    machinesForm.setOutputMarkupId(true);

    machineModels = new HashMap<Integer, IModel<String>>();

    ListView<Machine> machinesTable = new ListView<Machine>("machine", machines) {

        private static final long serialVersionUID = 1L;

        @Override/* ww  w . j  a v  a 2  s  .c  o m*/
        protected void populateItem(final ListItem<Machine> item) {

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }
            IModel<String> aliasModel = new Model<String>(item.getModelObject().alias);
            machineModels.put(item.getModelObject().machineId, aliasModel);
            item.add(new TextField<String>("machineAlias", aliasModel));

            item.add(new Label("machineName", item.getModelObject().name).setEscapeModelStrings(false));

            final Machine machine = item.getModelObject();
            item.add(new AjaxButton("machineInfo") {

                private static final long serialVersionUID = 1L;

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

                    if (machine.alias == null || machine.alias.trim().length() == 0) {
                        machineInfoDialogTitle.setDefaultModelObject(machine.name);
                    } else {
                        machineInfoDialogTitle.setDefaultModelObject(machine.alias + " (" + machine.name + ")");
                    }

                    machineInfoDialog.setVisible(true);
                    machineForEdit = machine;
                    machineInfoText.setModelObject(getMachineInformation(machine));

                    target.add(machineInfoDialogForm);
                }
            });
        }
    };
    machinesForm.add(machinesTable);

    AjaxButton saveMachineAliasesButton = new AjaxButton("saveMachineAliasesButton") {

        private static final long serialVersionUID = 1L;

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

            if (!form.isSubmitted()) {
                return;
            }

            for (Machine machine : machines) {

                String newMachineAlias = machineModels.get(machine.machineId).getObject();
                if (newMachineAlias != null) {
                    newMachineAlias = newMachineAlias.trim();
                }
                if ((newMachineAlias == null && machine.alias != null)
                        || (newMachineAlias != null && !newMachineAlias.equals(machine.alias))) {

                    machine.alias = newMachineAlias;
                    try {
                        getTESession().getDbWriteConnection().updateMachineAlias(machine);
                    } catch (DatabaseAccessException e) {
                        LOG.error("Can't update alias of machine '" + machine.name + "'", e);
                        target.appendJavaScript(
                                "alert('There was an error while updating the machine aliases!');");
                        return;
                    }
                }
            }
            target.appendJavaScript("alert('The machine aliases were successfully updated.');");
        }
    };

    boolean hasMachines = machines.size() > 0;

    machinesTable.setVisible(hasMachines);
    saveMachineAliasesButton.setVisible(hasMachines);
    noMachinesLabel.setVisible(!hasMachines);

    machinesForm.add(saveMachineAliasesButton);
    machinesForm.add(noMachinesLabel);

    return machinesForm;
}

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  va  2s  .co 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.MainDataGrid.java

License:Apache License

private void init(List<TableColumn> columnDefinitions, String whatIsShowing, int supportedOperations) {

    // prevent from automatically checking checkboxes (cached) from the browser, on page Reload
    getForm().add(AttributeModifier.replace("autocomplete", "off"));

    setRowsPerPage(((TestExplorerSession) Session.get()).getRowsPerPage());

    topToolbar = new PagingToolbar(this, columnDefinitions, whatIsShowing, supportedOperations);
    addTopToolbar(topToolbar);/* ww  w.  j  a v a  2 s . co  m*/

    bottomToolbar = new PagingToolbar(this, columnDefinitions, whatIsShowing, supportedOperations);
    addBottomToolbar(bottomToolbar);

    addBottomToolbar(new NoRecordsToolbar(this));
}

From source file:com.axway.ats.testexplorer.pages.reports.compare.ComparePage.java

License:Apache License

private Form<Object> getItemsToCompareForm(final Label noRunsLabel, final Label noTestcasesLabel) {

    final Form<Object> itemsToCompareForm = new Form<Object>("itemsToCompareForm");
    itemsToCompareForm.setOutputMarkupId(true);

    IModel<? extends List<Run>> runsListModel = new LoadableDetachableModel<List<Run>>() {
        private static final long serialVersionUID = 1L;

        protected List<Run> load() {

            return getTESession().getCompareContainer().getRunsList();
        }//www. ja v a 2 s  .c  om
    };
    final ListView<Run> runsToCompare = new ListView<Run>("runsToCompare", runsListModel) {
        private static final long serialVersionUID = 1L;

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

            final ListView<Run> runsToCompareComponent = this;

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }
            Map<Run, Model<Boolean>> runs = getTESession().getCompareContainer().getRuns();
            item.add(new CheckBox("checkbox", runs.get(item.getModelObject())));
            item.add(new Label("runName", item.getModelObject().runName).setEscapeModelStrings(false));
            item.add(new Label("version", item.getModelObject().versionName).setEscapeModelStrings(false));
            item.add(new Label("build", item.getModelObject().buildName).setEscapeModelStrings(false));
            item.add(new Label("startDate", item.getModelObject().getDateStart()).setEscapeModelStrings(false));
            item.add(new Label("endDate", item.getModelObject().getDateEnd()).setEscapeModelStrings(false));
            item.add(new AjaxButton("removeIcon") {

                private static final long serialVersionUID = 1L;

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

                    CompareContainer compareContainer = getTESession().getCompareContainer();
                    compareContainer.removeObject(item.getModelObject());
                    runsToCompareComponent.setModelObject(compareContainer.getRunsList());

                    noRunsLabel.setVisible(compareContainer.getRuns().size() == 0);

                    target.add(noRunsLabel);
                    target.add(itemsToCompareForm);
                }
            });
        }
    };
    itemsToCompareForm.add(runsToCompare);

    AjaxButton removeAllRunsButton = new AjaxButton("removeAllRuns") {

        private static final long serialVersionUID = 1L;

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

            CompareContainer compareContainer = getTESession().getCompareContainer();
            compareContainer.getRuns().clear();
            runsToCompare.setModelObject(compareContainer.getRunsList());
            noRunsLabel.setVisible(true);

            target.add(noRunsLabel);
            target.add(itemsToCompareForm);
        }
    };
    itemsToCompareForm.add(removeAllRunsButton);

    IModel<? extends List<Testcase>> testcasesListModel = new LoadableDetachableModel<List<Testcase>>() {
        private static final long serialVersionUID = 1L;

        protected List<Testcase> load() {

            return getTESession().getCompareContainer().getTestcasesList();
        }
    };
    final TestcaseListView<Testcase> testcasesToCompare = new TestcaseListView<Testcase>("testcasesToCompare",
            testcasesListModel) {

        private static final long serialVersionUID = 1L;

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

            final ListView<Testcase> testcasesToCompareComponent = this;

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }
            Map<Testcase, Model<Boolean>> testcases = getTESession().getCompareContainer().getTestcases();
            item.add(new CheckBox("checkbox", testcases.get(item.getModelObject())));
            item.add(new Label("runName", item.getModelObject().runName).setEscapeModelStrings(false));
            item.add(new Label("suiteName", item.getModelObject().suiteName).setEscapeModelStrings(false));
            item.add(
                    new Label("scenarioName", item.getModelObject().scenarioName).setEscapeModelStrings(false));
            item.add(new Label("testcaseName", item.getModelObject().name).setEscapeModelStrings(false));
            item.add(new Label("dateStart", item.getModelObject().getDateStart()).setEscapeModelStrings(false));
            item.add(new TextField<String>("testcaseAlias",
                    new PropertyModel<String>(item.getModelObject(), "alias")));

            item.add(moveLinkUp("moveUpLink", item));
            item.add(new AjaxButton("removeIcon") {

                private static final long serialVersionUID = 1L;

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

                    CompareContainer compareContainer = getTESession().getCompareContainer();
                    compareContainer.removeObject(item.getModelObject());
                    testcasesToCompareComponent.setModelObject(compareContainer.getTestcasesList());

                    noTestcasesLabel.setVisible(compareContainer.getTestcases().size() == 0);

                    target.add(noTestcasesLabel);
                    target.add(itemsToCompareForm);
                }
            });
        }
    };
    itemsToCompareForm.add(testcasesToCompare);

    AjaxButton removeAllTestcasesButton = new AjaxButton("removeAllTestcases") {

        private static final long serialVersionUID = 1L;

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

            CompareContainer compareContainer = getTESession().getCompareContainer();
            compareContainer.getTestcases().clear();
            testcasesToCompare.setModelObject(compareContainer.getTestcasesList());
            noTestcasesLabel.setVisible(true);

            target.add(noTestcasesLabel);
            target.add(itemsToCompareForm);
        }
    };
    itemsToCompareForm.add(removeAllTestcasesButton);

    // Standard Runs Compare buttons
    itemsToCompareForm.add(getStandardRunsCompareButtons());

    // Custom Runs Compare buttons
    itemsToCompareForm.add(getCustomRunsCompareButtons());

    // Standard Testcases Compare buttons
    itemsToCompareForm.add(getStandardTestcasesCompareButtons());

    // Custom Testcases Compare buttons
    itemsToCompareForm.add(getCustomTestcasesCompareButtons());

    noRunsLabel.setVisible(getTESession().getCompareContainer().getRuns().size() == 0);
    itemsToCompareForm.add(noRunsLabel);
    noTestcasesLabel.setVisible(getTESession().getCompareContainer().getTestcases().size() == 0);
    itemsToCompareForm.add(noTestcasesLabel);

    return itemsToCompareForm;
}

From source file:com.axway.ats.testexplorer.pages.reports.compare.CompareRunsPage.java

License:Apache License

private ListView<List<TestcasesTableCell>> getTestcasesTable(
        List<List<TestcasesTableCell>> testcasesTableModel) {

    ListView<List<TestcasesTableCell>> statisticDetailsTable = new ListView<List<TestcasesTableCell>>(
            "runsDetailsRows", testcasesTableModel) {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww w  . j ava  2s .  c  o  m*/
        protected void populateItem(ListItem<List<TestcasesTableCell>> item) {

            // table TR
            List<TestcasesTableCell> tdObjects = item.getModelObject();
            final int columnsCount = tdObjects.size();

            if (item.getIndex() == 0) {
                item.add(AttributeModifier.append("class", "runName"));
            } else if (item.getIndex() == 1) {
                item.add(AttributeModifier.append("class", "runDuration"));
            } else if (item.getIndex() == 2) {
                item.add(AttributeModifier.append("class", "testStateFilter"));
            } else if (item.getIndex() == 3 || item.getIndex() == 4) {
                // this is the Apply Filter Button row, we will use colspan, so we need only one column
                tdObjects = item.getModelObject().subList(0, 1);
            } else if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.append("class", "oddRow"));
            } else {
                item.add(AttributeModifier.append("class", "evenRow"));
            }

            item.add(new ListView<TestcasesTableCell>("runsDetailsColumns", tdObjects) {

                private static final long serialVersionUID = 1L;

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

                    // table TD
                    if (item.getIndex() == 0) {
                        item.add(AttributeModifier.append("class", "compareTest_firstCell"));
                    }
                    TestcasesTableCell cell = item.getModelObject();
                    if (cell.isFilter) {

                        item.add(new CheckBox("showOnlyTestsPresentInAllRuns").setVisible(false));
                        item.add(new Label("label", "").setVisible(false));
                        item.add(getTestStateChoices(cell.labelText));

                    } else if (cell.isShowOnlyTestsPresentInAllRunsCheckbox) {

                        item.add(AttributeModifier.replace("class", "compareTest_checkboxCell"));
                        item.add(AttributeModifier.replace("colspan", columnsCount));

                        item.add(new CheckBox("showOnlyTestsPresentInAllRuns",
                                showOnlyTestsPresentInAllRunsModel).setOutputMarkupId(true)
                                        .setMarkupId("showOnlyTestsPresentInAllRuns"));
                        item.add(new Label("label",
                                "<label for=\"showOnlyTestsPresentInAllRuns\">Show only tests present in all runs</label>")
                                        .setEscapeModelStrings(false));
                        item.add(getTestStateChoices(null).setVisible(false));
                    } else if (cell.isFilterButton) {

                        item.add(AttributeModifier.replace("class", "compareTest_applyFilterButtonCell"));
                        item.add(AttributeModifier.replace("colspan", columnsCount));

                        item.add(new CheckBox("showOnlyTestsPresentInAllRuns").setVisible(false));
                        Label label = new Label("label",
                                "<a href=\"#\" class=\"button applyFilterButton\" onclick=\"document.getElementById('applyFilterButton').click();\"><span>Apply Filter</span></a>");
                        label.setEscapeModelStrings(false);
                        item.add(label);
                        item.add(getTestStateChoices(null).setVisible(false));
                    } else {

                        if (cell.cssClass != null) {
                            item.add(AttributeModifier.append("class", cell.cssClass));
                        }
                        item.add(new CheckBox("showOnlyTestsPresentInAllRuns").setVisible(false));
                        Label label = null;
                        if (cell.url != null) {
                            label = new Label("label", "<a href=\"" + cell.url + "\" target=\"_blank\">"
                                    + cell.labelText + "</a>");
                        } else {
                            label = new Label("label", cell.labelText);
                        }
                        label.setEscapeModelStrings(false);
                        item.add(label);
                        item.add(getTestStateChoices(null).setVisible(false));
                    }
                }
            });
        }
    };

    statisticDetailsTable.setOutputMarkupId(true);
    return statisticDetailsTable;
}

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);//from   w ww. ja v  a 2  s  . c o  m

    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.loadqueues.LoadQueuesPanel.java

License:Apache License

public LoadQueuesPanel(String id, final String testcaseId) {

    super(id);/*from  w ww  .j  ava  2s. c  o  m*/

    List<ComplexLoadQueue> loadQueues = getLoadQueues(testcaseId);
    ListView<ComplexLoadQueue> loadQueuesContainer = new ListView<ComplexLoadQueue>("loadQueuesContainer",
            loadQueues) {
        private static final long serialVersionUID = 1L;

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

            final ComplexLoadQueue loadQueue = item.getModelObject();

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }
            item.add(new Label("name", loadQueue.getName()));
            item.add(new Label("threadingPattern", loadQueue.getThreadingPattern())
                    .setEscapeModelStrings(false));

            item.add(new Label("state", loadQueue.getState())
                    .add(AttributeModifier.replace("class", loadQueue.getState().toLowerCase() + "State")));

            item.add(new Label("dateStart", loadQueue.getDateStart()));
            item.add(new Label("dateEnd", loadQueue.getDateEnd()));
            item.add(new Label("duration", String.valueOf(loadQueue.getDuration())));

            item.add(new ListView<ComplexAction>("checkpoint_summary_info", loadQueue.getCheckpointsSummary()) {
                private static final long serialVersionUID = 1L;

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

                    if (item.getIndex() % 2 != 0) {
                        item.add(AttributeModifier.replace("class", "oddRow"));
                    }
                    final ComplexAction checkpointSummary = item.getModelObject();
                    item.add(new Label("name", checkpointSummary.getName()));

                    item.add(new Label("numTotal", String.valueOf(checkpointSummary.getNumTotal())));
                    item.add(new Label("numRunning", String.valueOf(checkpointSummary.getNumRunning())));
                    item.add(new Label("numPassed", String.valueOf(checkpointSummary.getNumPassed())));
                    item.add(new Label("numFailed", String.valueOf(checkpointSummary.getNumFailed())));

                    item.add(new Label("minResponseTime", checkpointSummary.getMinResponseTime()));
                    item.add(new Label("avgResponseTime", checkpointSummary.getAvgResponseTime()));
                    item.add(new Label("maxResponseTime", checkpointSummary.getMaxResponseTime()));

                    String transferRateUnit = checkpointSummary.getTransferRateUnit();
                    if (StringUtils.isNullOrEmpty(transferRateUnit)) {
                        // this action does not transfer data
                        item.add(new Label("minTransferRate", ""));
                        item.add(new Label("avgTransferRate", ""));
                        item.add(new Label("maxTransferRate", ""));
                        item.add(new Label("transferRateUnit", ""));
                    } else {
                        // this action transfers data
                        item.add(new Label("minTransferRate", checkpointSummary.getMinTransferRate()));
                        item.add(new Label("avgTransferRate", checkpointSummary.getAvgTransferRate()));
                        item.add(new Label("maxTransferRate", checkpointSummary.getMaxTransferRate()));
                        item.add(new Label("transferRateUnit", transferRateUnit));
                    }
                }
            });
        }
    };
    loadQueuesContainer.setVisible(!loadQueues.isEmpty());

    WebMarkupContainer noLoadQueuesContainer = new WebMarkupContainer("noLoadQueuesContainer");
    noLoadQueuesContainer.setVisible(loadQueues.isEmpty());

    add(loadQueuesContainer);
    add(noLoadQueuesContainer);
}

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

License:Apache License

/**
* @return statistic details component with all Min, Avg and Max values
*///ww  w.java  2  s . c o m
private Component getStatisticsDetailsComponent() {

    List<List<StatisticsTableCell>> rows = new ArrayList<List<StatisticsTableCell>>();
    List<StatisticsTableCell> columns = new ArrayList<StatisticsTableCell>();

    // add title
    columns.add(new StatisticsTableCell(
            "<img class=\"arrowUD\" src=\"images/up.png\"> System statistic details", false));

    // add machine value columns
    List<MachineDescription> mergedMachineDescriptions = getMergedMachineDescriptions();
    columns.add(new StatisticsTableCell(true, getMachineAliasModel("Values")));
    rows.add(columns);

    rows.addAll(systemStatisticsPanel.generateStatisticDetailRows(mergedMachineDescriptions, diagramContent));
    rows.addAll(userStatisticsPanel.generateStatisticDetailRows(mergedMachineDescriptions, diagramContent));
    rows.addAll(actionStatisticsPanel.generateStatisticDetailRows(mergedMachineDescriptions, diagramContent));

    ListView<List<StatisticsTableCell>> statisticDetailsTable = new ListView<List<StatisticsTableCell>>(
            "statDetailsRows", rows) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<List<StatisticsTableCell>> item) {

            // table TR
            if (item.getIndex() == 0) {
                item.add(AttributeModifier.replace("class", "statDetailsHeaderRow"));
                item.add(AttributeModifier.replace("onclick",
                        "showOrHideTableRows('statDetailsTable',1,false);"));
            } else if (item.getIndex() > 1 && item.getModelObject().get(0).labelText.contains("statUnit")) {
                item.add(AttributeModifier.replace("class", "statDetailsStatNameRow"));
            }
            item.add(new ListView<StatisticsTableCell>("statDetailsColumns", item.getModelObject()) {

                private static final long serialVersionUID = 1L;

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

                    // table TD
                    if (item.getIndex() > 0) { // skip the first column
                        item.add(AttributeModifier.replace("class", "statDetailsCenCol"));
                    }
                    StatisticsTableCell cell = item.getModelObject();
                    Label label = null;
                    if (cell.isInputText) {
                        label = new Label("label", cell.getMachineLabelModel());
                        if (cell.getMachineLabelModel() != null) {
                            rememberMachineAliasLabel(label);
                        }
                    } else {
                        label = new Label("label", cell.labelText);
                    }
                    label.setEscapeModelStrings(false);
                    item.add(label);
                }
            });
        }
    };

    return statisticDetailsTable;
}