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

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

Introduction

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

Prototype

public Link(final String id) 

Source Link

Usage

From source file:almira.sample.web.AdminPage.java

License:Apache License

/**
 * Constructor./*from w  w w.j av a2s  . c  o m*/
 */
public AdminPage() {
    super();

    final Label counterLabel = new Label(COUNTER_LABEL_ID, "0");
    add(counterLabel);

    final Label feedbackLabel = new Label(FEEDBACK_LABEL_ID);
    add(feedbackLabel);

    add(new Link<String>("increment_counter_link") {
        @Override
        public void onClick() {
            final Session session = AdminPage.this.getSession();
            int counterValue = 0;
            synchronized (session) {
                AtomicInteger counter = (AtomicInteger) session.getAttribute(COUNTER_LABEL_ID);
                if (counter == null) {
                    counter = new AtomicInteger();
                }
                counterValue = counter.incrementAndGet();
                // trigger replication to other cluster nodes
                session.setAttribute(COUNTER_LABEL_ID, counter);
            }
            counterLabel.setDefaultModel(new Model<Integer>(counterValue));
            LOG.fine("*** Catapult counter value=" + counterValue + " ***");
            feedbackLabel.setDefaultModel(new Model<String>());
        }
    });

    add(new Link<String>("rebuild_index") {
        @Override
        public void onClick() {
            try {
                indexService.rebuildIndex();
                feedbackLabel.setDefaultModel(new Model<String>("Rebuilding index."));
            } catch (Exception e) {
                feedbackLabel.setDefaultModel(new Model<String>("Error rebuilding index!"));
                LOG.log(Level.SEVERE, "Error rebuilding", e);
            }
        }
    });
}

From source file:ar.edu.udc.cirtock.view.intranet.html.InsumoPage.java

License:Apache License

@SuppressWarnings("unchecked")
public InsumoPage() {
    cerrar = new Link<IndexPage>("cerrar") {
        /**/*from  w  ww  .j  a  v a 2 s  .  com*/
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(IndexPage.class);
        }
    };
    producto = new Link<ProductoPage>("producto") {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(ProductoPage.class);
        }
    };

    herramienta = new Link<HerramientaPage>("herramienta") {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(HerramientaPage.class);
        }
    };
    formBusqueda = new Form("form_busqueda");

    busquedaInput = new TextField<String>("busquedaInput", new Model<String>());
    formBusqueda.add(busquedaInput);

    formBusqueda.add(new Button("busquedaBoton") {

        @Override
        public void onSubmit() {
            String busqueda = busquedaInput.getModelObject();
            Connection conn;
            try {
                conn = CirtockConnection.getConection("cirtock", "cirtock", "cirtock");
                insumos = Consultas.obtenerInsumos(conn, null, busqueda, null);
                lista.setList(insumos);
            } catch (CirtockException e) {
                System.out.println(e.getMessage());
            }
        }
    });

    add(formBusqueda);

    add(cerrar);
    add(producto);
    add(herramienta);

    add(lista);

    add(new Link<FormularioInsumo>("nuevo") {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(FormularioInsumo.class);
        }
    });

}

From source file:at.ac.tuwien.ifs.tita.ui.BasePage.java

License:Apache License

/**
 * initialize the page.//from w  w  w. j av a 2s  .co  m
 */
@SuppressWarnings("unchecked")
protected void initLogoutLink() {
    // not a secure link because everyone can logoff.
    Link logoff = new Link("logoff") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            TitaSession titaSession = TitaSession.getSession();
            if (titaSession.logoff(getLogoffContext())) {
                try {
                    TiTAUser user = userService.getUserByUsername(TitaSession.getSession().getUsername());
                    List<ActiveTaskId> activeTasks = timerCoordinator.getActiveTasks(user.getId());

                    for (ActiveTaskId at : activeTasks) {
                        Effort e = timerCoordinator.stopIssueTimer(user.getId(), at);
                        ITaskTrackable task = taskService.getIssueTrackerTaskById(at.getIssueId(),
                                at.getIssueTProjetId(), at.getIssueTrackerId());

                        effortService.saveIssueTrackerTaskEfforts(e, at.getIssueId(), at.getIssueTProjetId(),
                                task.getDescription(), user, at.getTitaProjectId());

                    }

                    // ActiveTaskEffort ate =
                    // timerCoordinator.findTiTATaskForUser(user.getId());
                    // if (ate != null && panel != null) {
                    // Effort e =
                    // timerCoordinator.stopTiTATimer(user.getId());
                    // effortService.saveEffortForTiTATask(e,
                    // panel.getGeneralTimer().getDescription(), user,
                    // panel.getProject());
                    // }

                    timerCoordinator.unregisterUser(user.getId());
                    activeTasks = timerCoordinator.getActiveTasks(user.getId());

                } catch (Exception e) {
                    error("couldn't log out - user didn't exist in database");
                }
                setResponsePage(Application.get().getHomePage());
                titaSession.invalidate();
            } else {
                error("A problem occured during the logoff process, please " + "try again or contact support");
            }
        }
    };
    add(logoff);
}

From source file:au.org.emii.geoserver.extensions.filters.LayerFilterForm.java

License:Open Source License

private Link cancelLink() {
    return new Link("cancel") {

        @Override//from w w  w.  j  av  a2  s. com
        public void onClick() {
            throw new org.apache.wicket.RestartResponseException(LayerPage.class);
        }
    };
}

From source file:au.org.theark.core.web.component.tabbedPanel.DynamicTabbedPanel.java

License:Open Source License

/**
 * Factory method for links used to switch between tabs.
 * /* www.ja  v a 2 s. c  o  m*/
 * The created component is attached to the following markup. Label component with id: title will be added for you by the tabbed panel.
 * 
 * <pre>
 * &lt;a href=&quot;#&quot; wicket:id=&quot;link&quot;&gt;&lt;span wicket:id=&quot;title&quot;&gt;[[tab title]]&lt;/span&gt;&lt;/a&gt;
 * </pre>
 * 
 * Example implementation:
 * 
 * <pre>
 * protected WebMarkupContainer newLink(String linkId, final int index) {
 *    return new Link(linkId) {
 *       private static final long   serialVersionUID   = 1L;
 * 
 *       public void onClick() {
 *          setSelectedTab(index);
 *       }
 *    };
 * }
 * </pre>
 * 
 * @param linkId
 *           component id with which the link should be created
 * @param index
 *           index of the tab that should be activated when this link is clicked. See {@link #setSelectedTab(int)}.
 * @return created link component
 */
protected WebMarkupContainer newLink(final String linkId, final int index) {
    return new Link<Void>(linkId) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setSelectedTab(index);
        }
    };
}

From source file:au.org.theark.lims.web.component.biospecimenupload.SearchResultListPanel.java

License:Open Source License

protected Link<Upload> buildDownloadLink(final Upload upload) {
    Link<Upload> link = new Link<Upload>(Constants.DOWNLOAD_FILE) {

        private static final long serialVersionUID = 1L;

        @Override/*  w  ww . j av a2 s  . c om*/
        public void onClick() {

            Payload payload = iArkCommonService.getPayloadForUpload(upload);
            byte[] data = payload.getPayload();
            getRequestCycle().scheduleRequestHandlerAfterCurrent(
                    new ByteDataResourceRequestHandler("text/plain", data, upload.getFilename()));

        };
    };

    Label nameLinkLabel = new Label("downloadFileLbl", "Download File");
    link.add(nameLinkLabel);
    return link;
}

From source file:au.org.theark.lims.web.component.biospecimenupload.SearchResultListPanel.java

License:Open Source License

protected Link<Upload> buildDownloadReportLink(final Upload upload) {
    Link<Upload> link = new Link<Upload>(Constants.UPLOADVO_UPLOAD_UPLOAD_REPORT) {

        private static final long serialVersionUID = 1L;

        @Override/*from   w  w w. ja va  2s.  co m*/
        public void onClick() {
            byte[] data = upload.getUploadReport();
            getRequestCycle().scheduleRequestHandlerAfterCurrent(new ByteDataResourceRequestHandler(
                    "text/plain", data, "uploadReport" + upload.getId() + ".txt"));
        };
    };

    Label nameLinkLabel = new Label("downloadReportLbl", "Download Report");
    link.add(nameLinkLabel);
    return link;
}

From source file:au.org.theark.lims.web.component.bioupload.SearchResultListPanel.java

License:Open Source License

protected Link<Upload> buildDownloadLink(final Upload upload) {
    Link<Upload> link = new Link<Upload>(au.org.theark.lims.web.Constants.DOWNLOAD_FILE) {

        private static final long serialVersionUID = 1L;

        @Override//  w  w  w .  j ava  2s . c o  m
        public void onClick() {
            Payload payload = iArkCommonService.getPayloadForUpload(upload);
            byte[] data = payload.getPayload();
            getRequestCycle().scheduleRequestHandlerAfterCurrent(
                    new ByteDataResourceRequestHandler("text/plain", data, upload.getFilename()));

        };
    };

    Label nameLinkLabel = new Label("downloadFileLbl", "Download File");
    link.add(nameLinkLabel);
    return link;
}

From source file:au.org.theark.lims.web.component.bioupload.SearchResultListPanel.java

License:Open Source License

protected Link<Upload> buildDownloadReportLink(final Upload upload) {
    Link<Upload> link = new Link<Upload>(au.org.theark.lims.web.Constants.UPLOADVO_UPLOAD_UPLOAD_REPORT) {

        private static final long serialVersionUID = 1L;

        @Override/*  ww  w  . j ava  2 s.co  m*/
        public void onClick() {
            byte[] data = upload.getUploadReport();
            log.warn("buildDownloadReportLink onclick get blob");
            getRequestCycle().scheduleRequestHandlerAfterCurrent(new ByteDataResourceRequestHandler(
                    "text/plain", data, "uploadReport" + upload.getId() + ".txt"));
        };
    };

    Label nameLinkLabel = new Label("downloadReportLbl", "Download Report");
    link.add(nameLinkLabel);
    return link;
}

From source file:au.org.theark.lims.web.component.inventory.panel.box.display.GridBoxPanel.java

License:Open Source License

/**
 * Return a download link for the gridBox contents as an Excel Worksheet 
 * @param invCellList//  w  ww .j  a  v  a  2s.c  om
 * @return
 */
protected Link<String> buildXLSDownloadLink(final List<InvCell> invCellList) {
    Link<String> link = new Link<String>("downloadGridBoxDataLink") {

        private static final long serialVersionUID = 1L;

        public void onClick() {
            byte[] data = createWorkBookAsByteArray(invCellList);
            if (data != null) {
                InputStream inputStream = new ByteArrayInputStream(data);
                OutputStream outputStream;
                try {
                    final String tempDir = System.getProperty("java.io.tmpdir");
                    final java.io.File file = new File(tempDir, limsVo.getInvBox().getName() + ".xls");
                    final String fileName = limsVo.getInvBox().getName() + ".xls";
                    outputStream = new FileOutputStream(file);
                    IOUtils.copy(inputStream, outputStream);

                    IResourceStream resourceStream = new FileResourceStream(
                            new org.apache.wicket.util.file.File(file));
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(
                            new ResourceStreamRequestHandler(resourceStream) {
                                @Override
                                public void respond(IRequestCycle requestCycle) {
                                    super.respond(requestCycle);
                                    Files.remove(file);
                                }
                            }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT));
                } catch (FileNotFoundException e) {
                    log.error(e.getMessage());
                } catch (IOException e) {
                    log.error(e.getMessage());
                }
            }
        }
    };

    return link;
}