Search in sources :

Example 11 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project syncope by apache.

the class BinaryPDFPreviewer method preview.

@Override
public Component preview(final byte[] uploadedBytes) {
    firstPage = null;
    try (InputStream bais = new ByteArrayInputStream(uploadedBytes);
        PDDocument document = PDDocument.load(bais, MemoryUsageSetting.setupTempFileOnly())) {
        document.setResourceCache(new DefaultResourceCache() {

            @Override
            public void put(final COSObject indirect, final PDXObject xobject) throws IOException {
            }
        });
        if (document.isEncrypted()) {
            LOG.info("Document is encrypted, no preview is possible");
        } else {
            firstPage = new PDFRenderer(document).renderImageWithDPI(0, DPI, IMAGE_TYPE);
        }
    } catch (IOException e) {
        LOG.error("While generating thumbnail from first page", e);
    }
    Fragment fragment;
    if (firstPage == null) {
        fragment = new Fragment("preview", "noPreviewFragment", this);
    } else {
        fragment = new Fragment("preview", "previewFragment", this);
        fragment.add(new NonCachingImage("previewImage", new ThumbnailImageResource(firstPage)));
    }
    WebMarkupContainer previewContainer = new WebMarkupContainer("previewContainer");
    previewContainer.setOutputMarkupId(true);
    previewContainer.add(fragment);
    return this.addOrReplace(previewContainer);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NonCachingImage(org.apache.wicket.markup.html.image.NonCachingImage) IOException(java.io.IOException) Fragment(org.apache.wicket.markup.html.panel.Fragment) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) DefaultResourceCache(org.apache.pdfbox.pdmodel.DefaultResourceCache) ByteArrayInputStream(java.io.ByteArrayInputStream) COSObject(org.apache.pdfbox.cos.COSObject) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDFRenderer(org.apache.pdfbox.rendering.PDFRenderer) PDXObject(org.apache.pdfbox.pdmodel.graphics.PDXObject)

Example 12 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project syncope by apache.

the class AbstractMultiPanel method getPlusFragment.

private Fragment getPlusFragment(final IModel<List<INNER>> model, final String label) {
    final IndicatorAjaxSubmitLink plus = new IndicatorAjaxSubmitLink("add") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            // Add current component
            model.getObject().add(newModelObject());
            if (model.getObject().size() == 1) {
                form.addOrReplace(getDataFragment());
            }
            target.add(container);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            SyncopeConsoleSession.get().error(getString(Constants.OPERATION_ERROR));
            super.onError(target, form);
            ((BasePage) getPage()).getNotificationPanel().refresh(target);
        }
    };
    final Fragment fragment = new Fragment("panelPlus", "fragmentPlus", AbstractMultiPanel.this);
    fragment.addOrReplace(plus);
    fragment.setRenderBodyOnly(true);
    return fragment;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Form(org.apache.wicket.markup.html.form.Form) IndicatorAjaxSubmitLink(org.apache.syncope.client.console.wicket.ajax.markup.html.IndicatorAjaxSubmitLink) Fragment(org.apache.wicket.markup.html.panel.Fragment)

Example 13 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project openmeetings by apache.

the class RecordingExpiringTemplate method getSubjectFragment.

@Override
Fragment getSubjectFragment() {
    Fragment f = new Fragment(COMP_ID, "subject", this);
    Room room = roomDao.get(rec.getRoomId());
    f.add(new OmTextLabel("prefix", getString("template.recording.expiring.subj.prefix", locale)), new OmTextLabel("room", room == null ? null : getString("template.recording.expiring.subj.room", locale, room.getName())).setVisible(room != null));
    return f;
}
Also used : OmTextLabel(org.apache.openmeetings.service.mail.template.OmTextLabel) Fragment(org.apache.wicket.markup.html.panel.Fragment) Room(org.apache.openmeetings.db.entity.room.Room)

Example 14 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class TicketPage method createMergePanel.

/**
 * Adds a merge panel for the patchset to the markup container.  The panel
 * may just a message if the patchset can not be merged.
 *
 * @param c
 * @param user
 * @param repository
 */
protected Component createMergePanel(UserModel user, RepositoryModel repository) {
    Patchset patchset = ticket.getCurrentPatchset();
    if (patchset == null) {
        // no patchset to merge
        return new Label("mergePanel");
    }
    boolean allowMerge;
    if (repository.requireApproval) {
        // repository requires approval
        allowMerge = ticket.isOpen() && ticket.isApproved(patchset);
    } else {
        // vetoes are binding
        allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
    }
    MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo, repository.mergeType);
    if (allowMerge) {
        if (MergeStatus.MERGEABLE == mergeStatus) {
            // patchset can be cleanly merged to integration branch OR has already been merged
            Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
            if (user.canPush(repository)) {
                // user can merge locally
                SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        // ensure the patchset is still current AND not vetoed
                        Patchset patchset = ticket.getCurrentPatchset();
                        final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
                        if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
                            // patchset is current, check for recent veto
                            if (!refreshedTicket.isVetoed(patchset)) {
                                // patchset is not vetoed
                                // execute the merge using the ticket service
                                app().tickets().exec(new Runnable() {

                                    @Override
                                    public void run() {
                                        PatchsetReceivePack rp = new PatchsetReceivePack(app().gitblit(), getRepository(), getRepositoryModel(), GitBlitWebSession.get().getUser());
                                        MergeStatus result = rp.merge(refreshedTicket);
                                        if (MergeStatus.MERGED == result) {
                                            // notify participants and watchers
                                            rp.sendAll();
                                        } else {
                                            // merge failure
                                            String msg = MessageFormat.format("Failed to merge ticket {0,number,0}: {1}", ticket.number, result.name());
                                            logger().error(msg);
                                            GitBlitWebSession.get().cacheErrorMessage(msg);
                                        }
                                    }
                                });
                            } else {
                                // vetoed patchset
                                String msg = MessageFormat.format("Can not merge ticket {0,number,0}, patchset {1,number,0} has been vetoed!", ticket.number, patchset.number);
                                GitBlitWebSession.get().cacheErrorMessage(msg);
                                logger().error(msg);
                            }
                        } else {
                            // not current patchset
                            String msg = MessageFormat.format("Can not merge ticket {0,number,0}, the patchset has been updated!", ticket.number);
                            GitBlitWebSession.get().cacheErrorMessage(msg);
                            logger().error(msg);
                        }
                        redirectTo(TicketsPage.class, getPageParameters());
                    }
                };
                mergePanel.add(mergeButton);
                Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetMergeableMore");
                mergePanel.add(instructions);
            } else {
                mergePanel.add(new Label("mergeButton").setVisible(false));
                mergePanel.add(new Label("mergeMore").setVisible(false));
            }
            return mergePanel;
        } else if (MergeStatus.ALREADY_MERGED == mergeStatus) {
            // patchset already merged
            Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
            return mergePanel;
        } else if (MergeStatus.MISSING_INTEGRATION_BRANCH == mergeStatus) {
            // target/integration branch is missing
            Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.missingIntegrationBranchMore"), ticket.mergeTo)));
            return mergePanel;
        } else {
            // patchset can not be cleanly merged
            Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            if (user.canPush(repository)) {
                // user can merge locally
                Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetNotMergeableMore");
                mergePanel.add(instructions);
            } else {
                mergePanel.add(new Label("mergeMore").setVisible(false));
            }
            return mergePanel;
        }
    } else {
        // merge not allowed
        if (MergeStatus.ALREADY_MERGED == mergeStatus) {
            // patchset already merged
            Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
            return mergePanel;
        } else if (ticket.isVetoed(patchset)) {
            // patchset has been vetoed
            Fragment mergePanel = new Fragment("mergePanel", "vetoedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            return mergePanel;
        } else if (repository.requireApproval) {
            // patchset has been not been approved for merge
            Fragment mergePanel = new Fragment("mergePanel", "notApprovedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotApproved"), ticket.mergeTo)));
            mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.patchsetNotApprovedMore"), ticket.mergeTo)));
            return mergePanel;
        } else {
            // other case
            return new Label("mergePanel");
        }
    }
}
Also used : PatchsetReceivePack(com.gitblit.git.PatchsetReceivePack) Label(org.apache.wicket.markup.html.basic.Label) TicketLabel(com.gitblit.tickets.TicketLabel) Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SimpleAjaxLink(com.gitblit.wicket.panels.SimpleAjaxLink) MergeStatus(com.gitblit.utils.JGitUtils.MergeStatus) ShockWaveComponent(com.gitblit.wicket.panels.ShockWaveComponent) Component(org.apache.wicket.Component)

Example 15 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class TicketsPage method milestoneList.

protected DataView<TicketMilestone> milestoneList(String wicketId, List<TicketMilestone> milestones, final boolean acceptingUpdates) {
    ListDataProvider<TicketMilestone> milestonesDp = new ListDataProvider<TicketMilestone>(milestones);
    DataView<TicketMilestone> milestonesList = new DataView<TicketMilestone>(wicketId, milestonesDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<TicketMilestone> item) {
            Fragment entryPanel = new Fragment("entryPanel", "milestoneListFragment", this);
            item.add(entryPanel);
            final TicketMilestone tm = item.getModelObject();
            String[] states;
            if (tm.isOpen()) {
                states = TicketsUI.openStatii;
            } else {
                states = TicketsUI.closedStatii;
            }
            PageParameters params = queryParameters(null, tm.name, states, null, null, true, 1);
            entryPanel.add(new LinkPanel("milestoneName", null, tm.name, TicketsPage.class, params).setRenderBodyOnly(true));
            String css;
            String status = tm.status.name();
            switch(tm.status) {
                case Open:
                    if (tm.isOverdue()) {
                        css = "aui-lozenge aui-lozenge-subtle aui-lozenge-error";
                        status = "overdue";
                    } else {
                        css = "aui-lozenge aui-lozenge-subtle";
                    }
                    break;
                default:
                    css = "aui-lozenge";
                    break;
            }
            Label stateLabel = new Label("milestoneState", status);
            WicketUtils.setCssClass(stateLabel, css);
            entryPanel.add(stateLabel);
            if (tm.due == null) {
                entryPanel.add(new Label("milestoneDue", getString("gb.notSpecified")));
            } else {
                entryPanel.add(WicketUtils.createDatestampLabel("milestoneDue", tm.due, getTimeZone(), getTimeUtils()));
            }
            if (acceptingUpdates) {
                entryPanel.add(new LinkPanel("editMilestone", null, getString("gb.edit"), EditMilestonePage.class, WicketUtils.newObjectParameter(repositoryName, tm.name)));
            } else {
                entryPanel.add(new Label("editMilestone").setVisible(false));
            }
            if (tm.isOpen()) {
                // re-load milestone with query results
                TicketMilestone m = app().tickets().getMilestone(getRepositoryModel(), tm.name);
                Fragment milestonePanel = new Fragment("milestonePanel", "openMilestoneFragment", this);
                Label label = new Label("progress");
                WicketUtils.setCssStyle(label, "width:" + m.getProgress() + "%;");
                milestonePanel.add(label);
                milestonePanel.add(new LinkPanel("openTickets", null, MessageFormat.format(getString("gb.nOpenTickets"), m.getOpenTickets()), TicketsPage.class, queryParameters(null, tm.name, TicketsUI.openStatii, null, null, true, 1)));
                milestonePanel.add(new LinkPanel("closedTickets", null, MessageFormat.format(getString("gb.nClosedTickets"), m.getClosedTickets()), TicketsPage.class, queryParameters(null, tm.name, TicketsUI.closedStatii, null, null, true, 1)));
                milestonePanel.add(new Label("totalTickets", MessageFormat.format(getString("gb.nTotalTickets"), m.getTotalTickets())));
                entryPanel.add(milestonePanel);
            } else {
                entryPanel.add(new Label("milestonePanel").setVisible(false));
            }
        }
    };
    return milestonesList;
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) TicketLabel(com.gitblit.tickets.TicketLabel) Label(org.apache.wicket.markup.html.basic.Label) PageParameters(org.apache.wicket.PageParameters) Fragment(org.apache.wicket.markup.html.panel.Fragment) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) TicketMilestone(com.gitblit.tickets.TicketMilestone)

Aggregations

Fragment (org.apache.wicket.markup.html.panel.Fragment)51 Label (org.apache.wicket.markup.html.basic.Label)20 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 ArrayList (java.util.ArrayList)9 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 Component (org.apache.wicket.Component)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 RepositoryModel (com.gitblit.models.RepositoryModel)5 UserModel (com.gitblit.models.UserModel)5 Item (org.apache.wicket.markup.repeater.Item)5 DataView (org.apache.wicket.markup.repeater.data.DataView)5 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)5 ResourceModel (org.apache.wicket.model.ResourceModel)4 TicketLabel (com.gitblit.tickets.TicketLabel)3 List (java.util.List)3 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)3 IndicatingAjaxLink (org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)3 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)3 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)2 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)2