Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setInitialHeight

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setInitialHeight

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setInitialHeight.

Prototype

public ModalWindow setInitialHeight(final int initialHeight) 

Source Link

Document

Sets the initial height of the window.

Usage

From source file:org.syncope.console.pages.ReportModalPage.java

License:Apache License

private void setupExecutions() {
    final WebMarkupContainer executions = new WebMarkupContainer("executions");
    executions.setOutputMarkupId(true);//ww  w.jav  a 2  s  .c  o m
    form.add(executions);

    final ModalWindow reportExecMessageWin = new ModalWindow("reportExecMessageWin");
    reportExecMessageWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    reportExecMessageWin.setCookieName("report-exec-message-win-modal");
    add(reportExecMessageWin);

    final ModalWindow reportExecExportWin = new ModalWindow("reportExecExportWin");
    reportExecExportWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    reportExecExportWin.setCookieName("report-exec-export-win-modal");
    reportExecExportWin.setInitialHeight(EXEC_EXPORT_WIN_HEIGHT);
    reportExecExportWin.setInitialWidth(EXEC_EXPORT_WIN_WIDTH);
    reportExecExportWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            AjaxExportDownloadBehavior behavior = new AjaxExportDownloadBehavior(
                    ReportModalPage.this.exportFormat, ReportModalPage.this.exportExecId);
            executions.add(behavior);
            behavior.initiate(target);
        }
    });
    add(reportExecExportWin);

    final List<IColumn> columns = new ArrayList<IColumn>();
    columns.add(new PropertyColumn(new ResourceModel("id"), "id", "id"));
    columns.add(new DatePropertyColumn(new ResourceModel("startDate"), "startDate", "startDate"));
    columns.add(new DatePropertyColumn(new ResourceModel("endDate"), "endDate", "endDate"));
    columns.add(new PropertyColumn(new ResourceModel("status"), "status", "status"));
    columns.add(new AbstractColumn<ReportExecTO>(new ResourceModel("actions", "")) {

        private static final long serialVersionUID = 2054811145491901166L;

        @Override
        public String getCssClass() {
            return "action";
        }

        @Override
        public void populateItem(final Item<ICellPopulator<ReportExecTO>> cellItem, final String componentId,
                final IModel<ReportExecTO> model) {

            final ReportExecTO taskExecutionTO = model.getObject();

            final ActionLinksPanel panel = new ActionLinksPanel(componentId, model);

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    reportExecMessageWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            return new ExecMessageModalPage(model.getObject().getMessage());
                        }
                    });
                    reportExecMessageWin.show(target);
                }
            }, ActionLink.ActionType.EDIT, "Reports", "read",
                    StringUtils.hasText(model.getObject().getMessage()));

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    reportExecExportWin.setPageCreator(new ModalWindow.PageCreator() {

                        private static final long serialVersionUID = -7834632442532690940L;

                        @Override
                        public Page createPage() {
                            ReportModalPage.this.exportExecId = model.getObject().getId();
                            return new ReportExecResultDownloadModalPage(reportExecExportWin,
                                    ReportModalPage.this.getPageReference());
                        }
                    });
                    reportExecExportWin.show(target);
                }
            }, ActionLink.ActionType.EXPORT, "Reports", "read",
                    ReportExecStatus.SUCCESS.name().equals(model.getObject().getStatus()));

            panel.add(new ActionLink() {

                private static final long serialVersionUID = -3722207913631435501L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    try {
                        restClient.deleteExecution(taskExecutionTO.getId());

                        reportTO.removeExecution(taskExecutionTO);

                        info(getString("operation_succeded"));
                    } catch (SyncopeClientCompositeErrorException scce) {
                        error(scce.getMessage());
                    }

                    target.add(feedbackPanel);
                    target.add(executions);
                }
            }, ActionLink.ActionType.DELETE, "Reports", "delete");

            cellItem.add(panel);
        }
    });

    final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("executionsTable", columns,
            new ReportExecutionsProvider(reportTO), 10);
    executions.add(table);
}

From source file:org.syncope.console.pages.Users.java

License:Apache License

public Users(final PageParameters parameters) {
    super(parameters);

    // Modal window for editing user attributes
    final ModalWindow editModalWin = new ModalWindow("editModal");
    editModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    editModalWin.setInitialHeight(EDIT_MODAL_WIN_HEIGHT);
    editModalWin.setInitialWidth(EDIT_MODAL_WIN_WIDTH);
    editModalWin.setCookieName("edit-modal");
    add(editModalWin);/* w w  w  .j  ava  2 s. c om*/

    final ResultSetPanel searchResult = new ResultSetPanel("searchResult", true, null, getPageReference());
    add(searchResult);

    final ResultSetPanel listResult = new ResultSetPanel("listResult", false, null, getPageReference());
    add(listResult);

    // create new user
    final AjaxLink createLink = new IndicatingAjaxLink("createLink") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            editModalWin.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = -7834632442532690940L;

                @Override
                public Page createPage() {
                    return new EditUserModalPage(Users.this.getPageReference(), editModalWin, new UserTO());
                }
            });

            editModalWin.show(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(createLink, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Users", "create"));
    add(createLink);

    setWindowClosedReloadCallback(editModalWin);

    final Form searchForm = new Form("searchForm");
    add(searchForm);

    final UserSearchPanel searchPanel = new UserSearchPanel("searchPanel");
    searchForm.add(searchPanel);

    searchForm.add(new IndicatingAjaxButton("search", new ResourceModel("search")) {

        private static final long serialVersionUID = -958724007591692537L;

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

            final NodeCond searchCond = searchPanel.buildSearchCond();
            LOG.debug("Node condition " + searchCond);

            doSearch(target, searchCond, searchResult);

            Session.get().getFeedbackMessages().clear();
            target.add(searchPanel.getSearchFeedback());
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {

            target.add(searchPanel.getSearchFeedback());
        }
    });
}

From source file:org.ujorm.hotels.gui.booking.BookingEditor.java

License:Apache License

/** Create the editor dialog */
public static BookingEditor create(String componentId, int width, int height) {
    IModel<Booking> model = Model.of(new Booking());
    final ModalWindow modalWindow = new ModalWindow(componentId, model);
    modalWindow.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

    final BookingEditor result = new BookingEditor(modalWindow, model);
    modalWindow.setInitialWidth(width);//from   w w  w  . j av  a  2 s. c om
    modalWindow.setInitialHeight(height);
    modalWindow.setTitle(new LocalizedModel("dialog.booking.title"));
    //modalWindow.setCookieName("modal-dialog");

    return result;
}

From source file:org.ujorm.hotels.gui.customer.CustomerEditor.java

License:Apache License

/** Create the editor dialog */
public static CustomerEditor create(String componentId, int width, int height) {
    IModel<Customer> model = Model.of(new Customer());
    final ModalWindow modalWindow = new ModalWindow(componentId, model);
    modalWindow.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

    final CustomerEditor result = new CustomerEditor(modalWindow, model);
    modalWindow.setInitialWidth(width);/*from   w  w  w  .  jav  a  2  s  . co m*/
    modalWindow.setInitialHeight(height);
    modalWindow.setTitle(new LocalizedModel("dialog.edit.title"));
    //modalWindow.setCookieName("modal-dialog");

    return result;
}

From source file:org.ujorm.hotels.gui.customer.LoginDialog.java

License:Apache License

/** Create the editor dialog */
public static LoginDialog create(String componentId, int width, int height) {
    IModel<Customer> model = Model.of(new Customer());
    final ModalWindow modalWindow = new ModalWindow(componentId, model);
    modalWindow.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

    final LoginDialog result = new LoginDialog(modalWindow, model);
    modalWindow.setInitialWidth(width);/*from  w  ww  . ja v a2s.  c o  m*/
    modalWindow.setInitialHeight(height);
    modalWindow.setTitle(new LocalizedModel("dialog.login.title"));
    //modalWindow.setCookieName("modal-dialog");

    return result;
}

From source file:org.ujorm.hotels.gui.hotel.HotelEditor.java

License:Apache License

/** Create the editor dialog */
public static HotelEditor create(String componentId, int width, int height) {
    IModel<Hotel> model = Model.of(new Hotel());
    final ModalWindow modalWindow = new ModalWindow(componentId, model);
    modalWindow.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

    final HotelEditor result = new HotelEditor(modalWindow, model);
    modalWindow.setInitialWidth(width);/*  w w  w . j av  a 2s. c o  m*/
    modalWindow.setInitialHeight(height);
    modalWindow.setTitle(new LocalizedModel("dialog.edit.title"));
    //modalWindow.setCookieName("modal-dialog");

    return result;
}

From source file:org.ujorm.wicket.component.dialog.domestic.MessageDialogPane.java

License:Apache License

/** Create the default message dialog */
public static MessageDialogPane create(String componentId, int width, int height) {
    IModel<String> model = Model.of("");
    final ModalWindow modalWindow = new ModalWindow(componentId, model);
    modalWindow.setCssClassName(ModalWindow.CSS_CLASS_BLUE);

    final MessageDialogPane result = new MessageDialogPane(modalWindow, model);
    modalWindow.setInitialWidth(width);/*from  w  w w  .  j  a  v a 2 s.  c o  m*/
    modalWindow.setInitialHeight(height);
    //modalWindow.setCookieName("modal-dialog");

    return result;
}

From source file:ro.nextreports.server.web.dashboard.DashboardPanel.java

License:Apache License

private void addToolbar() {

    toolbarContainer = new WebMarkupContainer("toolbar");
    add(toolbarContainer);/*from  w ww  .j  av a  2s.c  o  m*/

    IModel<String> toggleImageModel = new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            String imagePath = "images/left-gray.png";
            Map<String, String> preferences = NextServerSession.get().getPreferences();
            boolean isHidden = !PreferencesHelper.getBoolean("dashboard.navigationToggle", preferences);
            if (isHidden) {
                imagePath = "images/right-gray.png";
            }

            return imagePath;
        }

    };
    final ContextImage toggle = new ContextImage("toggle", toggleImageModel);
    toggle.add(new WiQueryAjaxEventBehavior(MouseEvent.CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            Map<String, String> preferences = NextServerSession.get().getPreferences();
            boolean toogle = false;
            if (preferences.containsKey("dashboard.navigationToggle")) {
                toogle = Boolean.parseBoolean(preferences.get("dashboard.navigationToggle"));
                toogle = !toogle;
            }

            preferences.put("dashboard.navigationToggle", String.valueOf(toogle));
            NextServerSession.get().setPreferences(preferences);

            DashboardBrowserPanel browserPanel = findParent(DashboardBrowserPanel.class);
            target.add(browserPanel.getDashboardNavigationPanel());
            target.add(toggle);
            target.add(DashboardPanel.this);
        }

        public JsStatement statement() {
            return null;
        }

    });
    IModel<String> toggleTooltipModel = new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            String tooltip = getString("DashboardPanel.hide");
            Map<String, String> preferences = NextServerSession.get().getPreferences();
            boolean isHidden = !PreferencesHelper.getBoolean("dashboard.navigationToggle", preferences);
            if (isHidden) {
                tooltip = getString("DashboardPanel.show");
            }

            return tooltip;
        }

    };
    toggle.add(new AttributeModifier("title", toggleTooltipModel));
    toolbarContainer.add(toggle);

    //      add(new AjaxLink<Void>("addDashboard") {
    //
    //         private static final long serialVersionUID = 1L;
    //
    //         @Override
    //         public void onClick(AjaxRequestTarget target) {
    //                ModalWindow dialog = findParent(BasePage.class).getDialog();
    //                dialog.setTitle("Add dashboard");
    //                dialog.setInitialWidth(350);
    //                dialog.setUseInitialHeight(false);
    //                
    //                final AddDashboardPanel addDashboardPanel = new AddDashboardPanel(dialog.getContentId()) {
    //
    //               private static final long serialVersionUID = 1L;
    //
    //               @Override
    //                    public void onAdd(AjaxRequestTarget target) {
    //                        ModalWindow.closeCurrent(target);
    //                        String id;
    //                        String title = getTitle();                        
    //                        Dashboard dashboard = new DefaultDashboard(title, getColumnCount());
    //                        id = dashboardService.addOrModifyDashboard(dashboard);
    //
    //                        SectionContext sectionContext = NextServerSession.get().getSectionContext(DashboardSection.ID);
    //                        sectionContext.getData().put(SectionContextConstants.SELECTED_DASHBOARD_ID, id);
    //                        
    //                        target.add(DashboardPanel.this.findParent(DashboardBrowserPanel.class));
    //                    }
    //
    //                    @Override
    //                    public void onCancel(AjaxRequestTarget target) {
    //                        ModalWindow.closeCurrent(target);
    //                    }
    //
    //                };
    //                dialog.setContent(addDashboardPanel);
    //                dialog.show(target);
    //         }
    //         
    //      });

    AjaxLink<Void> refreshLink = new AjaxLink<Void>("refresh") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.add(DashboardPanel.this);
        }

    };
    toolbarContainer.add(refreshLink);

    AjaxLink<Void> addWidgetLink = new AjaxLink<Void>("addWidget") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("DashboardPanel.add"));
            dialog.setInitialWidth(350);
            dialog.setUseInitialHeight(false);

            AddWidgetPanel addWidgetPanel = new AddWidgetPanel() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onOk(AjaxRequestTarget target) {
                    if (getEntity() == null) {
                        error(getString("DashboardPanel.select"));
                        target.add(getFeedbackPanel());
                        return;
                    }

                    ModalWindow.closeCurrent(target);

                    Widget widget = null;
                    //!important: first we test for pivot and then for drill-downable
                    if (isPivot()) {
                        PivotWidget pivotWidget = (PivotWidget) widgetFactory
                                .createWidget(new PivotWidgetDescriptor());
                        pivotWidget.setEntity(getEntity());
                        widget = pivotWidget;
                    } else if (isDrillDownable()) {
                        DrillDownWidget drillWidget = (DrillDownWidget) widgetFactory
                                .createWidget(new DrillDownWidgetDescriptor());
                        drillWidget.setEntity(getEntity());
                        widget = drillWidget;
                    } else if (isChart()) {
                        ChartWidget chartWidget = (ChartWidget) widgetFactory
                                .createWidget(new ChartWidgetDescriptor());
                        chartWidget.setEntity(getEntity());
                        widget = chartWidget;
                    } else if (isTable()) {
                        TableWidget tableWidget = (TableWidget) widgetFactory
                                .createWidget(new TableWidgetDescriptor());
                        tableWidget.setEntity(getEntity());
                        widget = tableWidget;
                    } else if (isAlarm()) {
                        AlarmWidget alarmWidget = (AlarmWidget) widgetFactory
                                .createWidget(new AlarmWidgetDescriptor());
                        alarmWidget.setEntity(getEntity());
                        widget = alarmWidget;
                    } else if (isIndicator()) {
                        IndicatorWidget indicatorWidget = (IndicatorWidget) widgetFactory
                                .createWidget(new IndicatorWidgetDescriptor());
                        indicatorWidget.setEntity(getEntity());
                        widget = indicatorWidget;
                    } else if (isDisplay()) {
                        DisplayWidget displayWidget = (DisplayWidget) widgetFactory
                                .createWidget(new DisplayWidgetDescriptor());
                        displayWidget.setEntity(getEntity());
                        widget = displayWidget;
                    }
                    widget.setTitle(getUniqueWidgetTitle(widget.getTitle()));
                    widget.afterCreate(storageService);
                    Dashboard dashboard = getDashboard();
                    try {
                        dashboardService.addWidget(dashboard.getId(), widget);
                    } catch (NotFoundException e) {
                        // never happening
                        throw new RuntimeException(e);
                    }

                    // TODO
                    /*
                    target.add(getLeftColumnPanel());
                    // @todo
                    // if we do not refresh right panel we have a strange bug :                       
                    // move a W widget from left to right, add a widget (to left), move W from right to left (will look like the added widget) 
                    target.add(getRightColumnPanel());
                    */
                    /*
                    for (int i = 0; i < getDashboard().getColumnCount(); i++) {
                       System.out.println(">>> " + i);
                       System.out.println(getColumnPanel(i));
                       target.add(getColumnPanel(i));
                    }
                    */

                    // globalSettingsLink may be disabled
                    //                       target.add(globalSettingsLink);         

                    // need to to do detach (otherwise after we add a widget to current dashboard, added widget does not appear)!
                    // see also DashboardColumnModel
                    DashboardPanel.this.getModel().detach();
                    target.add(DashboardPanel.this);
                }

            };
            dialog.setContent(new FormPanel<Void>(dialog.getContentId(), addWidgetPanel, true) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onConfigure() {
                    super.onConfigure();
                    setOkButtonValue(getString("add"));
                }

            });
            dialog.show(target);
        }

        @Override
        public boolean isVisible() {
            return hasWritePermission();
        }

    };
    toolbarContainer.add(addWidgetLink);

    globalSettingsLink = new AjaxLink<Void>("globalSettings") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("DashboardPanel.global"));

            final WidgetRuntimeModel runtimeModel = ChartUtil.getGlobalRuntimeModel(
                    storageService.getSettings(), getDashboard().getId(), reportService, dataSourceService,
                    dashboardService);
            Entity entity = null;
            if (runtimeModel.getParameters().size() > 0) {
                entity = ((EntityWidget) getDashboard().getWidgets().get(0)).getEntity();
            }
            if (getDashboard().getWidgets().size() > 0) {
                final ParameterRuntimePanel paramRuntimePanel = new GeneralWidgetRuntimePanel(
                        "chartRuntimePanel", entity, runtimeModel, true);

                boolean isDynamic = false;
                if (paramRuntimePanel instanceof DynamicParameterRuntimePanel) {
                    if (((DynamicParameterRuntimePanel) paramRuntimePanel).hasDynamicParameter()) {
                        isDynamic = true;
                    }
                }

                if (paramRuntimePanel.hasPalette()) {
                    if (isDynamic) {
                        dialog.setInitialWidth(720);
                    } else {
                        dialog.setInitialWidth(685);
                    }
                } else {
                    if (isDynamic) {
                        dialog.setInitialWidth(445);
                    } else {
                        dialog.setInitialWidth(435);
                    }
                }
                dialog.setUseInitialHeight(false);
                dialog.setContent(new WidgetSettingsPanel(dialog.getContentId(), paramRuntimePanel) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onChange(AjaxRequestTarget target) {
                        changeGlobalSettings(runtimeModel, target);
                    }

                    @Override
                    public void onCancel(AjaxRequestTarget target) {
                        ModalWindow.closeCurrent(target);
                    }

                    @Override
                    public void onReset(AjaxRequestTarget target) {
                        // resetSettings(widget, target);
                    }

                });
            } else {
                dialog.setContent(new Label(dialog.getContentId(), getString("DashboardPanel.empty")));
                dialog.setInitialWidth(300);
                dialog.setInitialHeight(40);
            }
            dialog.show(target);
        }

        @Override
        public boolean isVisible() {
            return hasWritePermission()
                    && (DashboardUtil.getDashboard(DashboardUtil.getSelectedDashboardId(), dashboardService)
                            .getWidgets().size() > 0);
        }

    };
    globalSettingsLink.setOutputMarkupId(true);
    globalSettingsLink.setOutputMarkupPlaceholderTag(true);
    toolbarContainer.add(globalSettingsLink);

    toolbarContainer.add(new AjaxLink<Void>("pdf") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavaScript(getPdfJavascriptCall());
        }

        // a landscape pdf with the entire visible part of dashboard
        private String getPdfJavascriptCall() {
            StringBuilder sb = new StringBuilder();
            sb.append("var doc = new jsPDF('l', 'mm');");
            //sb.append("var list = $('li[id^=\"widget\"]');");
            //sb.append("pdfSettings.position = 1;");
            sb.append("var list = $('div[class=\"dashboardCapture\"]');");
            sb.append("var pdfSettings = new Object();");
            sb.append("pdfSettings.doc = doc;");
            sb.append("pdfSettings.elements = list;");
            sb.append("pdfSettings.title = \"" + getDashboard().getTitle() + "\";");
            sb.append("pdfSettings.showFooter = true;");
            sb.append("pdfSettings.footerText = \"Generated by NextReports "
                    + new SimpleDateFormat().format(new Date()) + "\";");
            sb.append("capturePdf(pdfSettings);");
            return sb.toString();
        }

    });

}

From source file:ro.nextreports.server.web.report.RunHistoryPanel.java

License:Apache License

protected List<IColumn<RunReportHistory, String>> createHistoryTableColumns() {
    List<IColumn<RunReportHistory, String>> columns = new ArrayList<IColumn<RunReportHistory, String>>();

    columns.add(new AbstractColumn<RunReportHistory, String>(
            new Model<String>(getString("ActionContributor.EditParameters.parameterSelect"))) {

        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            try {
                if (securityService.hasPermissionsById(ServerUtil.getUsername(), PermissionUtil.getDelete(),
                        rowModel.getObject().getId())) {
                    item.add(new CheckBoxPanel(componentId, rowModel, item));
                } else {
                    item.add(new Label(componentId));
                }/* w  w w  .  j  a v a2  s .co  m*/
                item.add(new AttributeModifier("width", "30px"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public Component getHeader(String s) {
            return new CheckBoxHeaderPanel(s);
        }

    });

    columns.add(new PropertyColumn<RunReportHistory, String>(new Model<String>(getString("Report")), "path",
            "path") {

        @Override
        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            String path = rowModel.getObject().getPath();
            String relativePath = path.substring(StorageConstants.REPORTS_ROOT.length(),
                    path.indexOf("/runHistory"));
            String name = StorageUtil.getName(relativePath);
            Label label = new Label(componentId, name);
            label.add(new SimpleTooltipBehavior(relativePath));
            item.add(label);
        }

    });

    columns.add(new AbstractColumn<RunReportHistory, String>(
            new Model<String>(getString("ActionContributor.DataSource.url"))) {

        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                final IModel<RunReportHistory> rowModel) {
            String url = rowModel.getObject().getUrl();
            if ((url == null) || url.equals("")) {
                item.add(new Label(componentId));
                return;
            } else if (url.equals(ReportConstants.ETL_FORMAT)) {
                item.add(new Label(componentId, Model.of(url)));
                return;
            }

            // dynamic url
            String fileName = url.substring(url.lastIndexOf("/") + 1);
            String dynamicUrl = reportService.getReportURL(fileName);
            item.add(new SimpleLink(componentId, dynamicUrl, getString("view"), true));
        }

    });

    columns.add(new PropertyColumn<RunReportHistory, String>(
            new Model<String>(getString("DashboardNavigationPanel.owner")), "runnerId", "runnerId") {

        @Override
        protected IModel<?> createLabelModel(IModel<RunReportHistory> rowModel) {
            try {
                // TODO optimization (getNameByUUID - no entity creation)
                Entity entity = storageService.getEntityById(rowModel.getObject().getRunnerId());
                String owner;
                if (entity instanceof User) {
                    owner = entity.getName();
                } else {
                    //SchedulerJob
                    owner = entity.getCreatedBy();
                }
                return new Model<String>(owner);
            } catch (NotFoundException ex) {
                // if user or scheduler was deleted
                return new Model<String>();
            }
        }

    });
    columns.add(new PropertyColumn<RunReportHistory, String>(
            new Model<String>(getString("ActionContributor.RunHistory.type")), "runnerType", "runnerType") {
        @Override
        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            item.add(new Label(componentId,
                    getString("MonitorPanel.runnerType." + rowModel.getObject().getRunnerType())));
        }
    });
    columns.add(new DateColumn<RunReportHistory>(new Model<String>(getString("startDate")), "startDate",
            "startDate"));
    columns.add(new PropertyColumn<RunReportHistory, String>(new Model<String>(getString("duration")),
            "duration", "duration") {

        @Override
        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            super.populateItem(item, componentId, rowModel);
            item.add(new AttributeModifier("width", "70px"));
        }

        @Override
        protected IModel<?> createLabelModel(IModel<RunReportHistory> rowModel) {
            int runTime = rowModel.getObject().getDuration();
            String text = "";
            if (runTime >= 0) {
                DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss").withZone(DateTimeZone.UTC);
                text = formatter.print(runTime * 1000);
            }

            return new Model<String>(text);
        }

    });
    columns.add(
            new DateColumn<RunReportHistory>(new Model<String>(getString("endDate")), "endDate", "endDate"));

    columns.add(new ImageLinkPropertyColumn<RunReportHistory>(new Model<String>(getString("Query"))) {

        @Override
        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            super.populateItem(item, componentId, rowModel);
            item.add(new AttributeModifier("width", "50px"));
            item.add(new SimpleTooltipBehavior(getString("Query")));
        }

        @Override
        public void onImageClick(RunReportHistory runHistory, AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("Query"));
            dialog.setInitialWidth(600);
            dialog.setInitialHeight(400);
            dialog.setContent(new RunHistoryQueryPanel(dialog.getContentId(), runHistory));
            dialog.show(target);
        }

        @Override
        public String getLinkImageName() {
            return "sql.png";
        }

    });

    columns.add(new BooleanImageLinkPropertyColumn<RunReportHistory>(new Model<String>(getString("success")),
            "success", "success") {

        @Override
        public void populateItem(Item<ICellPopulator<RunReportHistory>> item, String componentId,
                IModel<RunReportHistory> rowModel) {
            super.populateItem(item, componentId, rowModel);
            item.add(new AttributeModifier("width", "50px"));
            item.add(new SimpleTooltipBehavior(getString("details")));
        }

        @Override
        public void onImageClick(RunReportHistory runHistory, AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("details"));
            dialog.setInitialWidth(350);
            dialog.setInitialHeight(200);
            dialog.setContent(new RunHistoryDetailPanel(dialog.getContentId(), runHistory));
            dialog.show(target);
        }

    });

    return columns;
}

From source file:ro.nextreports.server.web.schedule.TemplatePanel.java

License:Apache License

private void init() {

    validator = createValidator();//w w w. j  a  v  a 2s .c  om

    add(new Label("templateLabel", getString("ActionContributor.Run.template.name")));

    ChoiceRenderer<ReportRuntimeTemplate> nameRenderer = new ChoiceRenderer<ReportRuntimeTemplate>("name") {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(ReportRuntimeTemplate template) {
            if (template == null) {
                return getString("nullValid");
            }
            return template.getName();
        }

    };

    final DropDownChoice<ReportRuntimeTemplate> templateChoice = new DropDownChoice<ReportRuntimeTemplate>(
            "template", new PropertyModel<ReportRuntimeTemplate>(this, "template"),
            new LoadableDetachableModel<List<ReportRuntimeTemplate>>() {

                @Override
                protected List<ReportRuntimeTemplate> load() {
                    List<ReportRuntimeTemplate> templates = new ArrayList<ReportRuntimeTemplate>();
                    try {
                        templates = reportService.getReportTemplatesById(report.getId());
                    } catch (Exception e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        error(e.getMessage());
                    }
                    return templates;
                }
            }, nameRenderer);

    templateChoice.setNullValid(true);

    templateChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            if (template != null) {
                new ChangeValuesTemplateEvent(templateChoice, report, template.getReportRuntime(),
                        template.getShortcutType(), target).fire();
                runtimeModel.setShortcutType(template.getShortcutType());
                target.add(shortcutChoice);

                // when a template is changed then the shortcut is changed
                ShortcutType shortcutType = runtimeModel.getShortcutType();
                new ChangeShortcutTemplateEvent(shortcutChoice, shortcutType, target).fire();

                timeType = TimeShortcutType.getTypeName(runtimeModel.getShortcutType().getTimeType());
                boolean visible = (runtimeModel.getShortcutType().getType() == -1);
                shortcutLastContainer.setVisible(visible);
                target.add(shortcutLastContainer);
            } else {
                runtimeModel.setShortcutType(ShortcutType.NONE);
                shortcutLastContainer.setVisible(false);
                target.add(shortcutChoice);
                target.add(shortcutLastContainer);
            }
        }
    });
    add(templateChoice);

    final TextField<String> nameField = new TextField<String>("name",
            new PropertyModel<String>(this, "runtimeModel.templateName"));
    nameField.setRequired(false);
    nameField.setEnabled(false);
    nameField.setOutputMarkupId(true);
    nameField.setLabel(Model.of(getString("ActionContributor.Run.template.info")));
    add(nameField);

    add(new Label("saveTemplateLabel", getString("ActionContributor.Run.template.save")));
    final CheckBox saveTemplate = new CheckBox("saveTemplate",
            new PropertyModel<Boolean>(this, "runtimeModel.saveTemplate"));
    saveTemplate.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            boolean save = runtimeModel.isSaveTemplate();
            nameField.setEnabled(save);
            nameField.setRequired(save);
            if (save) {
                nameField.add(validator);
            } else {
                nameField.remove(validator);
            }
            target.add(nameField);
        }
    });
    add(saveTemplate);

    WebMarkupContainer shortcutContainer = new WebMarkupContainer("shortcutContainer");
    boolean visible = ReportUtil.hasIntervalParameters(storageService.getSettings(), report);
    shortcutContainer.setVisible(visible);
    add(shortcutContainer);

    shortcutContainer.add(new Label("withShortcut", getString("ActionContributor.Run.template.interval")));

    ChoiceRenderer<ShortcutType> shortcutRenderer = new ChoiceRenderer<ShortcutType>("name") {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(ShortcutType shortcut) {
            return getString(
                    "ActionContributor.Run.template.interval." + ShortcutType.getName(shortcut.getType()));
        }

    };
    shortcutChoice = new DropDownChoice<ShortcutType>("shortcutType",
            new PropertyModel<ShortcutType>(this, "runtimeModel.shortcutType"), ShortcutType.getTypes(),
            shortcutRenderer);
    shortcutChoice.setNullValid(false);
    shortcutChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            ShortcutType shortcutType = runtimeModel.getShortcutType();
            new ChangeShortcutTemplateEvent(shortcutChoice, shortcutType, target).fire();
            boolean visible = (runtimeModel.getShortcutType().getType() == -1);
            shortcutLastContainer.setVisible(visible);
            target.add(shortcutLastContainer);
        }
    });
    shortcutChoice.setOutputMarkupId(true);
    shortcutContainer.add(shortcutChoice);

    shortcutLastContainer = new WebMarkupContainer("shortcutLastContainer");
    shortcutLastContainer.setVisible(false);
    shortcutLastContainer.setOutputMarkupPlaceholderTag(true);
    shortcutContainer.add(shortcutLastContainer);

    timeUnitsField = new TextField<Integer>("timeUnits",
            new PropertyModel<Integer>(this, "runtimeModel.shortcutType.timeUnits"));
    timeUnitsField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            new ChangeShortcutTemplateEvent(shortcutChoice, runtimeModel.getShortcutType(), target).fire();
        }
    });
    timeUnitsField.setRequired(false);
    shortcutLastContainer.add(timeUnitsField);

    ChoiceRenderer<String> timeTypeRenderer = new ChoiceRenderer<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(String type) {
            return getString(type.toLowerCase());
        }

    };
    timeTypeChoice = new DropDownChoice<String>("timeType", new PropertyModel<String>(this, "timeType"),
            TimeShortcutType.getTypeNames(), timeTypeRenderer);
    timeTypeChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            runtimeModel.getShortcutType().setTimeType(TimeShortcutType.getTypeUnit(timeType));
            new ChangeShortcutTemplateEvent(shortcutChoice, runtimeModel.getShortcutType(), target).fire();
        }
    });
    shortcutLastContainer.add(timeTypeChoice);

    if (runtimeModel.getShortcutType().getType() == -1) {
        shortcutLastContainer.setVisible(true);
    }

    add(new AjaxLink<Void>("removeTemplate") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("ActionContributor.Run.template.remove"));
            dialog.setInitialWidth(350);
            dialog.setInitialHeight(200);
            dialog.setResizable(true);

            final ManageTemplatesPanel panel = new ManageTemplatesPanel(dialog.getContentId(), report) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onDelete(AjaxRequestTarget target, List<ReportRuntimeTemplate> selected) {
                    ModalWindow.closeCurrent(target);
                    if (selected.size() == 0) {
                        return;
                    }
                    List<String> ids = new ArrayList<String>();
                    for (ReportRuntimeTemplate rt : selected) {
                        ids.add(rt.getId());
                    }
                    try {
                        storageService.removeEntitiesById(ids);
                    } catch (NotFoundException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        error(e.getMessage());
                    }
                    template = null;
                    target.add(templateChoice);
                }

                @Override
                public void onCancel(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                }

            };
            dialog.setContent(panel);
            dialog.show(target);
        }

    });
}