Example usage for org.apache.wicket.markup.html.link Link getParent

List of usage examples for org.apache.wicket.markup.html.link Link getParent

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.link Link getParent.

Prototype

@Override
public final MarkupContainer getParent() 

Source Link

Document

Gets any parent container, or null if there is none.

Usage

From source file:org.geoserver.backuprestore.web.BackupRestorePage.java

License:Open Source License

void initComponents(final IModel<T> model) {
    add(new Label("id", new PropertyModel(model, "id")));
    add(new Label("clazz", new Model(
            this.clazz.getSimpleName().substring(0, this.clazz.getSimpleName().indexOf("Execution")))));

    BackupRestoreExecutionsProvider provider = new BackupRestoreExecutionsProvider(getType()) {
        @Override//from  w  w w. j  a v  a 2 s .  c o  m
        protected List<Property<AbstractExecutionAdapter>> getProperties() {
            return Arrays.asList(ID, STATE, STARTED, PROGRESS, ARCHIVEFILE, OPTIONS);
        }

        @Override
        protected List<T> getItems() {
            return Collections.singletonList(model.getObject());
        }
    };

    final BackupRestoreExecutionsTable headerTable = new BackupRestoreExecutionsTable("header", provider,
            getType());

    headerTable.setOutputMarkupId(true);
    headerTable.setFilterable(false);
    headerTable.setPageable(false);
    add(headerTable);

    final T bkp = model.getObject();
    boolean selectable = bkp.getStatus() != BatchStatus.COMPLETED;

    add(new Icon("icon", COMPRESS_ICON));
    add(new Label("title", new DataTitleModel(bkp))
            .add(new AttributeModifier("title", new DataTitleModel(bkp, false))));

    @SuppressWarnings("rawtypes")
    Form<?> form = new Form("form");
    add(form);

    try {
        if (params != null && params.getNamedKeys().contains(DETAILS_LEVEL)) {
            if (params.get(DETAILS_LEVEL).toInt() > 0) {
                expand = params.get(DETAILS_LEVEL).toInt();
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error parsing the 'details level' parameter: ",
                params.get(DETAILS_LEVEL).toString());
    }

    form.add(new SubmitLink("refresh") {
        @Override
        public void onSubmit() {
            setResponsePage(BackupRestorePage.class, new PageParameters().add("id", params.get("id").toLong())
                    .add("clazz", getType().getSimpleName()).add(DETAILS_LEVEL, expand));
        }
    });

    NumberTextField<Integer> expand = new NumberTextField<Integer>("expand",
            new PropertyModel<Integer>(this, "expand"));
    expand.add(RangeValidator.minimum(0));
    form.add(expand);

    TextArea<String> details = new TextArea<String>("details", new BKErrorDetailsModel(bkp));
    details.setOutputMarkupId(true);
    details.setMarkupId("details");
    add(details);

    String location = bkp.getArchiveFile().path();
    if (location == null) {
        location = getGeoServerApplication().getGeoServer().getLogging().getLocation();
    }
    backupFile = new File(location);
    if (!backupFile.isAbsolute()) {
        // locate the geoserver.log file
        GeoServerDataDirectory dd = getGeoServerApplication().getBeanOfType(GeoServerDataDirectory.class);
        backupFile = dd.get(Paths.convert(backupFile.getPath())).file();
    }

    if (!backupFile.exists()) {
        error("Could not find the Backup Archive file: " + backupFile.getAbsolutePath());
    }

    /***
     * DOWNLOAD LINK
     */
    final Link<Object> downLoadLink = new Link<Object>("download") {

        @Override
        public void onClick() {
            IResourceStream stream = new FileResourceStream(backupFile) {
                public String getContentType() {
                    return "application/zip";
                }
            };
            ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(stream,
                    backupFile.getName());
            handler.setContentDisposition(ContentDisposition.ATTACHMENT);

            RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
        }
    };
    add(downLoadLink);

    /***
     * PAUSE LINK
     */
    final AjaxLink pauseLink = new AjaxLink("pause") {

        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(AttributeModifier.replace("class", "disabled"));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            AbstractExecutionAdapter bkp = model.getObject();
            if (bkp.getStatus() == BatchStatus.STOPPED) {
                setLinkEnabled((AjaxLink) downLoadLink.getParent().get("pause"), false, target);
            } else {
                try {
                    backupFacade().stopExecution(bkp.getId());

                    setResponsePage(BackupRestoreDataPage.class);
                } catch (NoSuchJobExecutionException | JobExecutionNotRunningException e) {
                    LOGGER.log(Level.WARNING, "", e);
                    getSession().error(e);
                    setResponsePage(BackupRestoreDataPage.class);
                }
            }
        }

    };
    pauseLink.setEnabled(doSelectReady(bkp) && bkp.getStatus() != BatchStatus.STOPPED);
    add(pauseLink);

    /***
     * RESUME LINK
     */
    final AjaxLink resumeLink = new AjaxLink("resume") {

        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(AttributeModifier.replace("class", "disabled"));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            AbstractExecutionAdapter bkp = model.getObject();
            if (bkp.getStatus() != BatchStatus.STOPPED) {
                setLinkEnabled((AjaxLink) downLoadLink.getParent().get("pause"), false, target);
            } else {
                try {
                    Long id = backupFacade().restartExecution(bkp.getId());

                    PageParameters pp = new PageParameters();
                    pp.add("id", id);
                    if (bkp instanceof BackupExecutionAdapter) {
                        pp.add("clazz", BackupExecutionAdapter.class.getSimpleName());
                    } else if (bkp instanceof RestoreExecutionAdapter) {
                        pp.add("clazz", RestoreExecutionAdapter.class.getSimpleName());
                    }

                    setResponsePage(BackupRestorePage.class, pp);
                } catch (NoSuchJobExecutionException | JobInstanceAlreadyCompleteException | NoSuchJobException
                        | JobRestartException | JobParametersInvalidException e) {
                    LOGGER.log(Level.WARNING, "", e);
                    getSession().error(e);
                    setResponsePage(BackupRestoreDataPage.class);
                }
            }
        }

    };
    resumeLink.setEnabled(bkp.getStatus() == BatchStatus.STOPPED);
    add(resumeLink);

    /***
     * ABANDON LINK
     */
    final AjaxLink cancelLink = new AjaxLink("cancel") {

        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(AttributeModifier.replace("class", "disabled"));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            AbstractExecutionAdapter bkp = model.getObject();
            if (!doSelectReady(bkp)) {
                setLinkEnabled((AjaxLink) downLoadLink.getParent().get("cancel"), false, target);
            } else {
                try {
                    backupFacade().abandonExecution(bkp.getId());

                    PageParameters pp = new PageParameters();
                    pp.add("id", bkp.getId());
                    if (bkp instanceof BackupExecutionAdapter) {
                        pp.add("clazz", BackupExecutionAdapter.class.getSimpleName());
                    } else if (bkp instanceof RestoreExecutionAdapter) {
                        pp.add("clazz", RestoreExecutionAdapter.class.getSimpleName());
                    }

                    setResponsePage(BackupRestorePage.class, pp);
                } catch (NoSuchJobExecutionException | JobExecutionAlreadyRunningException e) {
                    error(e);
                    LOGGER.log(Level.WARNING, "", e);
                }
            }
        }

    };
    cancelLink.setEnabled(doSelectReady(bkp));
    add(cancelLink);

    /***
     * DONE LINK
     */
    final AjaxLink doneLink = new AjaxLink("done") {

        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(AttributeModifier.replace("class", "disabled"));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            setResponsePage(BackupRestoreDataPage.class);
            return;
        }

    };
    add(doneLink);

    /**
     * FINALIZE
     */
    add(dialog = new GeoServerDialog("dialog"));
}

From source file:org.onexus.website.api.Website.java

License:Apache License

public Website(PageParameters pageParameters) {
    super(new WebsiteModel(pageParameters));

    if (!Authorization.authorize(getConfig())) {
        if (WebsiteSession.get().isSignedIn()) {
            setResponsePage(NotAuthorizedPage.class);
        } else {//from  w  w w .  ja  va2 s .  c  om
            WebsiteApplication.get().restartResponseAtSignInPage();
        }
    }

    LoginContext ctx = LoginContext.get();
    try {

        LoginContext.set(LoginContext.SERVICE_CONTEXT, null);

        add(new DefaultTheme());

        final WebsiteStatus status = getStatus();
        final WebsiteConfig config = getConfig();

        ORI parentUri = config.getORI().getParent();
        add(new CustomCssBehavior(parentUri, config.getCss()));

        // Init currentPage
        VisiblePredicate visiblePredicate = new VisiblePredicate(getConfig().getORI(), Collections.EMPTY_LIST);
        if (status.getCurrentPage() == null || config.getPage(status.getCurrentPage()) == null
                || !visiblePredicate.evaluate(config.getPage(status.getCurrentPage()))) {
            List<PageConfig> visiblePages = getPageConfigList();
            if (!visiblePages.isEmpty()) {
                String currentPage = visiblePages.get(0).getId();
                status.setCurrentPage(currentPage);
            }
        }

        add(new Label("windowTitle", config.getTitle()));

        add(new EmptyPanel("progressbar"));
        //TODO add(new ProgressBar("progressbar", false));

        String header = config.getHeader();

        Label headerLabel = new Label("header", new HtmlDataResourceModel(parentUri, header));
        headerLabel.setVisible(header != null && !header.isEmpty());
        headerLabel.setEscapeModelStrings(false);
        add(headerLabel);

        WebMarkupContainer menuSection = new WebMarkupContainer("menuSection");
        menuSection.add(
                new ListView<PageConfig>("menu", new PropertyModel<List<PageConfig>>(this, "pageConfigList")) {

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

                        PageConfig pageConfig = item.getModelObject();

                        PageParameters parameters = new PageParameters();
                        parameters.add(PARAMETER_CURRENT_PAGE, pageConfig.getId());

                        Link<String> link = new BookmarkablePageLink<String>("link", Website.class, parameters);
                        link.add(new Label("name", pageConfig.getLabel()));

                        String currentPage = status.getCurrentPage();

                        item.add(link);

                        if (currentPage.equals(pageConfig.getId())) {
                            link.getParent().add(new AttributeModifier("class", "active"));
                        }

                    }
                });

        if (pageParameters.get("embed").toBoolean(false)) {
            menuSection.setVisible(false);
        } else {
            menuSection.setVisible(true);
        }

        // Login section
        Panel login = new LoginPanel("login");
        menuSection.add(login);
        if (config.getLogin() == null || !config.getLogin()) {
            login.setVisible(false);
        }

        // Projects section
        menuSection.add(new ConnectionsPanel("connections", config.getConnections()));

        add(menuSection);

        String currentPage = status.getCurrentPage();

        add(pageManager.create("page", new PageModel(currentPage, (IModel<WebsiteStatus>) getDefaultModel())));

        String bottom = config.getBottom();
        Label bottomLabel = new Label("bottom", new HtmlDataResourceModel(parentUri, bottom));
        bottomLabel.setVisible(bottom != null && !bottom.isEmpty());
        bottomLabel.setEscapeModelStrings(false);
        add(bottomLabel);

    } finally {
        LoginContext.set(ctx, null);
    }

}