Example usage for org.apache.wicket.ajax AbstractAjaxTimerBehavior AbstractAjaxTimerBehavior

List of usage examples for org.apache.wicket.ajax AbstractAjaxTimerBehavior AbstractAjaxTimerBehavior

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AbstractAjaxTimerBehavior AbstractAjaxTimerBehavior.

Prototype

public AbstractAjaxTimerBehavior(final Duration updateInterval) 

Source Link

Document

Construct.

Usage

From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.components.CacheListPanel.java

License:Apache License

public CacheListPanel(final String id, final Behavior updater, final Component[] updateList) {
    super(id);//from  w  ww  . jav  a  2  s .c om

    final ModalWindow modal1;
    add(modal1 = new ModalWindow("modal1"));
    modal1.setInitialWidth(1000);
    //      modal1.setCookieName("modal-1");
    modal1.setPageCreator(new ModalWindow.PageCreator() {
        private static final long serialVersionUID = 1L;

        public Page createPage() {
            return new CacheDetailsPage(hostname);
        }
    });

    this.updateList = updateList;
    final WebMarkupContainer container = new WebMarkupContainer("listpanel");
    container.setOutputMarkupId(true);
    add(container);
    servers = createServerListView(updater, modal1);
    servers.setOutputMarkupId(true);
    container.setOutputMarkupId(true);
    container.add(servers);

    add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
        private static final long serialVersionUID = 1L;
        int serverCount = 0;

        @Override
        protected final void onTimer(final AjaxRequestTarget target) {
            //            target.add(getComponent());
            final int size = CacheState.getCacheStates().size();
            if (serverCount != size) {
                serverCount = size;
                servers.setList(getServerList());
                target.add(container);
                if (updateList != null) {
                    for (Component c : updateList) {
                        target.add(c);
                    }
                }
                //               target.add(graph);
            }
        }
    });
}

From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.components.DsListPanel.java

License:Apache License

public DsListPanel(final String id, final Behavior updater, final Component[] updateList) {
    super(id);/* ww w  . j ava  2s.c  o  m*/

    final ModalWindow modal1;
    add(modal1 = new ModalWindow("modal2"));
    modal1.setInitialWidth(1000);
    //      modal1.setCookieName("modal-1");
    modal1.setPageCreator(new ModalWindow.PageCreator() {
        private static final long serialVersionUID = 1L;

        public Page createPage() {
            return new DsDetailsPage(dsId);
        }
    });

    this.updateList = updateList;
    final WebMarkupContainer container = new WebMarkupContainer("listpanel");
    container.setOutputMarkupId(true);
    add(container);
    servers = createDsListView(updater, modal1);
    servers.setOutputMarkupId(true);
    container.setOutputMarkupId(true);
    container.add(servers);

    add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
        private static final long serialVersionUID = 1L;
        int serverCount = 0;

        @Override
        protected final void onTimer(final AjaxRequestTarget target) {
            final int size = DsState.getDsStates().size();
            if (serverCount != size) {
                serverCount = size;
                servers.setList(getDsList());
                target.add(container);
                if (updateList != null) {
                    for (Component c : updateList) {
                        target.add(c);
                    }
                }
            }
        }
    });
}

From source file:com.doculibre.constellio.wicket.pages.BaseConstellioPage.java

License:Open Source License

@SuppressWarnings("serial")
private void initComponents() {
    Component keepAliveComponent = new WebMarkupContainer("keepAlive");
    add(keepAliveComponent);/*from w  w w .  j  a  v a2 s. c o  m*/

    if (ConstellioSession.get().getUser() != null) {
        keepAliveComponent.add(new AbstractAjaxTimerBehavior(Duration.seconds(30)) {
            @Override
            protected void onTimer(AjaxRequestTarget target) {
                // Do nothing, will prevent page from expiring
            }
        });
    }
    initStyling();
}

From source file:com.doculibre.constellio.wicket.panels.admin.thesaurus.AddEditThesaurusPanel.java

License:Open Source License

public AddEditThesaurusPanel(String id) {
    super(id, false);

    this.thesaurusModel = new EntityModel<Thesaurus>(new LoadableDetachableModel() {
        @Override/*ww w  . j a  v a  2s.  c  o  m*/
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            Thesaurus thesaurus = collection.getThesaurus();
            return thesaurus != null ? thesaurus : newThesaurus;
        }
    });

    Form form = getForm();
    form.setModel(new CompoundPropertyModel(thesaurusModel));

    final List<String> errorMessages = new ArrayList<String>();
    errorsModalWindow = new ModalWindow("errorsModal");
    errorsModalWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    skosFileField = new FileUploadField("skosFile");
    uploadButton = new Button("uploadButton") {
        @Override
        public void onSubmit() {
            errorMessages.clear();
            FileUpload upload = skosFileField.getFileUpload();
            if (upload != null) {
                try {
                    skosFile = upload.writeToTempFile();
                } catch (IOException e) {
                    throw new WicketRuntimeException(e);
                }
            }
            AddEditThesaurusPanel.this.add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
                @Override
                protected void onTimer(AjaxRequestTarget target) {
                    stop();
                    if (!importing && skosFile != null && skosFile.exists()) {
                        importing = true;
                        importCompleted = false;
                        progressInfo = new ProgressInfo();
                        progressPanel.start(target);
                        getForm().modelChanging();
                        new Thread() {
                            @Override
                            public void run() {
                                try {
                                    SkosServices skosServices = ConstellioSpringUtils.getSkosServices();
                                    FileInputStream is = new FileInputStream(skosFile);
                                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                                            AdminCollectionPanel.class);
                                    RecordCollection collection = collectionAdminPanel.getCollection();
                                    Thesaurus importedThesaurus = skosServices.importThesaurus(is, progressInfo,
                                            errorMessages);
                                    List<ImportThesaurusPlugin> importThesaurusPlugins = PluginFactory
                                            .getPlugins(ImportThesaurusPlugin.class);
                                    if (!importThesaurusPlugins.isEmpty()) {
                                        for (ImportThesaurusPlugin importThesaurusPlugin : importThesaurusPlugins) {
                                            is = new FileInputStream(skosFile);
                                            importThesaurusPlugin.afterUpload(is, importedThesaurus,
                                                    collection);
                                        }
                                    }
                                    FileUtils.deleteQuietly(skosFile);
                                    thesaurusModel.setObject(importedThesaurus);
                                    importing = false;
                                    importCompleted = true;
                                } catch (FileNotFoundException e) {
                                    throw new WicketRuntimeException(e);
                                }
                            }
                        }.start();

                    }
                }
            });
        }
    };
    uploadButton.setDefaultFormProcessing(false);

    progressInfo = new ProgressInfo();
    progressInfoModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            return progressInfo;
        }
    };
    progressPanel = new ProgressPanel("progressPanel", progressInfoModel) {
        @Override
        protected void onFinished(AjaxRequestTarget target) {
            //                while (!importCompleted) {
            //                    // Wait for the import to be completed
            //                    try {
            //                        Thread.sleep(500);
            //                    } catch (InterruptedException e) {
            //                        throw new WicketRuntimeException(e);
            //                    }
            //                }
            target.addComponent(rdfAbout);
            target.addComponent(dcTitle);
            target.addComponent(dcDescription);
            target.addComponent(dcDate);
            target.addComponent(dcCreator);

            if (!errorMessages.isEmpty()) {
                IModel errorMsgModel = new LoadableDetachableModel() {
                    @Override
                    protected Object load() {
                        StringBuffer sb = new StringBuffer();
                        for (String errorMsg : errorMessages) {
                            sb.append(errorMsg);
                            sb.append("\n");
                        }
                        return sb.toString();
                    }
                };
                MultiLineLabel multiLineLabel = new MultiLineLabel(errorsModalWindow.getContentId(),
                        errorMsgModel);
                multiLineLabel.add(new SimpleAttributeModifier("style", "text-align:left;"));
                errorsModalWindow.setContent(multiLineLabel);
                errorsModalWindow.show(target);
            }
        }
    };
    progressPanel.setVisible(false);

    deleteButton = new Button("deleteButton") {
        @Override
        public void onSubmit() {
            Thesaurus thesaurus = thesaurusModel.getObject();
            if (thesaurus.getId() != null) {
                SkosServices skosServices = ConstellioSpringUtils.getSkosServices();

                EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                if (!entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().begin();
                }

                skosServices.makeTransient(thesaurus);
                entityManager.getTransaction().commit();

                AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                        AdminCollectionPanel.class);
                RecordCollection collection = collectionAdminPanel.getCollection();
                collection.setThesaurus(null);
                AddEditThesaurusPanel.this.replaceWith(newReturnComponent(AddEditThesaurusPanel.this.getId()));
            }
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && thesaurusModel.getObject().getId() != null;
        }

        @Override
        protected String getOnClickScript() {
            String confirmMsg = getLocalizer().getString("confirmDelete", AddEditThesaurusPanel.this)
                    .replace("'", "\\'");
            return "if (confirm('" + confirmMsg + "')) { return true;} else { return false; }";
        }
    };
    deleteButton.setDefaultFormProcessing(false);

    rdfAbout = new Label("rdfAbout");
    rdfAbout.setOutputMarkupId(true);

    dcTitle = new Label("dcTitle");
    dcTitle.setOutputMarkupId(true);

    dcDescription = new Label("dcDescription");
    dcDescription.setOutputMarkupId(true);

    dcDate = new Label("dcDate");
    dcDate.setOutputMarkupId(true);

    dcCreator = new Label("dcCreator");
    dcCreator.setOutputMarkupId(true);

    form.add(skosFileField);
    form.add(uploadButton);
    form.add(progressPanel);
    form.add(errorsModalWindow);
    form.add(deleteButton);
    form.add(rdfAbout);
    form.add(dcTitle);
    form.add(dcDescription);
    form.add(dcDate);
    form.add(dcCreator);
}

From source file:com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails.java

License:Apache License

@Override
protected void onConfigure() {
    super.onConfigure();
    if (saveOnConfigure) {
        saveOnConfigure = false;/*from w ww . j ava  2 s . c  om*/
        add(new AbstractAjaxTimerBehavior(Duration.milliseconds(100)) {
            @Override
            protected void onTimer(AjaxRequestTarget target) {
                stop(target);
                savePerformed(target);
            }
        });
    }
}

From source file:com.genericconf.bbbgateway.web.pages.HomePage.java

License:Apache License

public HomePage(final PageParameters parameters) {
    IModel<? extends List<? extends Meeting>> model = new LoadableDetachableModel<List<? extends Meeting>>() {
        private static final long serialVersionUID = 1L;

        @Override// w ww  .j a v a2s. com
        protected List<? extends Meeting> load() {
            return new ArrayList<Meeting>(meetingService.getMeetings());
        }
    };

    final WebMarkupContainer joinContainer = new WebMarkupContainer("joinContainer");
    joinContainer.setOutputMarkupPlaceholderTag(true).setVisible(false);
    add(joinContainer);

    final WebMarkupContainer placeholder = new WebMarkupContainer("tablePlaceholder");
    placeholder.add(new AbstractAjaxTimerBehavior(
            Duration.seconds(TimerSettings.INSTANCE.getSecondsBetweenHomePagePolls())) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            target.addComponent(placeholder);
            target.appendJavascript("initializeTableStuff();");
        }

    });
    final PropertyListView<Meeting> meetingList = new PropertyListView<Meeting>("meetings", model) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Meeting> item) {
            item.add(new Label("name"));
            item.add(new DateTimeLabel("startTime"));
            item.add(new Label("attendeesInMeeting"));
            item.add(new Label("attendeesWaiting"));
            item.add(new AjaxLink<Void>("join") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    JoinMeetingFormPanel panel = new JoinMeetingFormPanel(joinContainer.getId(),
                            item.getModel());
                    joinContainer.replaceWith(panel);
                    target.addComponent(panel);

                    panel.add(new SimpleAttributeModifier("style", "display: none;"));
                    panel.onAjaxRequest(target);

                    StringBuffer js = new StringBuffer().append("$('#").append(panel.getMarkupId())
                            .append("').dialog({ modal: true, title: 'Join Meeting' });");
                    target.appendJavascript(js.toString());
                }
            });
        }

    };
    meetingList.setOutputMarkupId(true);
    add(placeholder.setOutputMarkupId(true));
    placeholder.add(meetingList);
}

From source file:com.genericconf.bbbgateway.web.pages.ManageMeeting.java

License:Apache License

public ManageMeeting(PageParameters params) {
    final String meetingID = params.getString("0");
    String check = params.getString("1");
    boolean okay = createCheck(meetingID).equals(check);
    logger.info("meeting ID: " + meetingID + "; check: " + check + "; okay: " + okay);
    if (!okay) {/* www .  j  a  v a2  s.co m*/
        getSession().error("You are not authorized to manage that meeting");
        throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
    }
    IModel<Meeting> model = new LoadableDetachableModel<Meeting>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected Meeting load() {
            final Meeting mtg = meetingService.findByMeetingID(meetingID);
            if (mtg == null) {
                getSession().error("That meeting no longer exists");
                throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
            }
            return mtg;
        }
    };
    setDefaultModel(new CompoundPropertyModel<Meeting>(model));

    add(new Label("name"));
    add(new Label("meetingID"));
    add(new Label("attendeePassword"));
    add(new Label("moderatorPassword"));
    add(maxAtts = new Label("maximumAttendees"));
    maxAtts.setOutputMarkupId(true);
    attendeeList = new AttendeeAndWaitingListPanel("attendeeList", getModel());
    add(attendeeList.setAllowAdminControls(true));

    checked = new DateTimeLabel("checkedTime", new AlwaysReturnCurrentDateModel());
    add(checked.setOutputMarkupId(true));

    final Form<Void> bulkAllowForm = new Form<Void>("bulkAllowForm");
    add(bulkAllowForm.setOutputMarkupId(true));
    final Model<Integer> howMany = new Model<Integer>(0);
    bulkAllowForm.add(new TextField<Integer>("howMany", howMany, Integer.class));
    bulkAllowForm.add(new AjaxButton("submit") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (howMany.getObject() <= 0) {
                target.appendJavascript("alert('must be a positive number');");
            } else {
                final Meeting meeting = ManageMeeting.this.getModel().getObject();
                meeting.increaseMaximumAttendees(howMany.getObject());
                meetingService.bulkAllowAttendees(meeting);
                ManageMeeting.this.onPageAjaxRequest(target);
            }
        }
    });

    add(new AbstractAjaxTimerBehavior(
            Duration.seconds(TimerSettings.INSTANCE.getSecondsBetweenManageMeetingPagePolls())) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            ManageMeeting.this.onPageAjaxRequest(target);
        }
    });
}

From source file:com.genericconf.bbbgateway.web.pages.WaitingRoom.java

License:Apache License

public WaitingRoom(PageParameters params) {
    final String meetingID = params.getString("0");
    final String attName = params.getString("1");
    if (StringUtils.isEmpty(meetingID) || StringUtils.isEmpty(attName)) {
        throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
    }/*from  w ww .j  a  v a 2 s  . c o m*/
    meeting = new LoadableDetachableModel<Meeting>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected Meeting load() {
            return meetingService.findByMeetingID(meetingID);
        }
    };
    attendee = new LoadableDetachableModel<Attendee>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected Attendee load() {
            return meeting.getObject().getAttendeeByName(attName);
        }
    };

    add(new Label("name", new PropertyModel<String>(meeting, "name")));
    add(new Label("meetingID", new PropertyModel<String>(meeting, "meetingID")));

    add(new Label("attName", new PropertyModel<String>(attendee, "name")));
    add(new Label("attRole", new PropertyModel<String>(attendee, "role")));

    final AttendeeAndWaitingListPanel attendeeList = new AttendeeAndWaitingListPanel("attendeeList", meeting);
    add(attendeeList);

    final DateTimeLabel checked = new DateTimeLabel("checkedTime", new AlwaysReturnCurrentDateModel());
    add(checked.setOutputMarkupId(true));

    final WebMarkupContainer joinDialog = new WebMarkupContainer("joinDialog");
    add(joinDialog.setOutputMarkupId(true));

    add(new AbstractAjaxTimerBehavior(
            Duration.seconds(TimerSettings.INSTANCE.getSecondsBeforeFirstWaitingRoomPagePoll())) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            target.addComponent(checked);
            setUpdateInterval(Duration.seconds(TimerSettings.INSTANCE.getSecondsBetweenWaitingRoomPagePolls()));
            attendeeList.onAjaxRequest(target);
            final Attendee att = attendee.getObject();
            att.pinged();
            if (att.isAllowedToJoin()) {
                stop();

                final JoinMeetingLinkPanel panel = new JoinMeetingLinkPanel(joinDialog.getId(), meeting,
                        attendee);
                joinDialog.replaceWith(panel);
                target.addComponent(panel);

                StringBuffer js = new StringBuffer().append("$('#").append(panel.getMarkupId())
                        .append("').dialog({ modal: true, title: 'Join Meeting' });");
                target.appendJavascript(js.toString());
            }
        }
    });
}

From source file:com.modusoperandi.dragonfly.widgets.table.TableWidgetPage.java

License:Open Source License

/**
 * Instantiates a new table widget page.
 *///from w  w w  .  ja  va2  s. c  o m
public TableWidgetPage() {

    // /////////////////////////////
    // Elasticsearch
    getEsClient();
    sortOrder = "Asc";

    // /////////////////////////////
    // UI
    setVersioned(false);

    final Form<?> queryForm = new Form<>("queryForm");
    add(queryForm);

    // ////////////////////////////
    // Index Name
    populateIndices();

    selectIndex = new DropDownChoice<>("dataSetName", new PropertyModel<String>(this, "indexName"), indexList);
    selectIndex.add(new AjaxFormComponentUpdatingBehavior("focus") {

        private static final long serialVersionUID = 2981822623630720652L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

            if (populateIndices()) {
                target.add(selectIndex);
            }
        }
    });
    selectIndex.add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 2981822623630720652L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

            resetFacets();

            target.add(selectFacetField);
            target.add(selectFacetValue);
            target.appendJavaScript(jqgridUpdateJs());
            target.appendJavaScript(jqgridPopulatedJs());
        }
    });
    queryForm.add(selectIndex);

    // ////////////////////////////
    // Filter
    final TextField<String> filterField = new TextField<>("filter", new PropertyModel<String>(this, "filter"));
    filterField.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 2981822623630720652L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

            target.appendJavaScript(jqgridUpdateJs());
            target.appendJavaScript(jqgridPopulatedJs());
        }
    });

    queryForm.add(filterField);

    // ////////////////////////////
    // Facet
    selectFacetField = new DropDownChoice<>("facetField", new PropertyModel<String>(this, "facetField"),
            fieldList);

    selectFacetField.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 2981822623630720652L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

            populateFacet(esMakeQuery());

            target.add(selectFacetValue);
            target.appendJavaScript(jqgridUpdateJs());
            target.appendJavaScript(jqgridPopulatedJs());
        }
    });
    queryForm.add(selectFacetField);

    selectFacetValue = new DropDownChoice<>("facetValue", new PropertyModel<String>(this, "facetValue"),
            valueList);

    selectFacetValue.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 2981822623630720652L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

            target.appendJavaScript(jqgridUpdateJs());
            target.appendJavaScript(jqgridPopulatedJs());
        }
    });
    queryForm.add(selectFacetValue);

    // //////////////////////////////
    // Table
    populateTableBehavior = new TablePopulateAjaxBehavior();
    add(populateTableBehavior);

    // //////////////////////////////
    // Updates
    add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {

        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.ajax.AbstractAjaxTimerBehavior#onTimer(org.apache.wicket.ajax.AjaxRequestTarget)
         */
        @Override
        protected void onTimer(final AjaxRequestTarget target) {

            if (indexName != null) {
                final IndicesExistsResponse exists = getEsClient().admin().indices()
                        .exists(new IndicesExistsRequest(indexName)).actionGet();

                if (exists.isExists()) {
                    final CountResponse response = getEsClient().prepareCount(indexName).execute().actionGet();

                    if (response.getCount() != lastCount) {

                        System.out
                                .println(Long.toString(lastCount) + " : " + Long.toString(response.getCount()));

                        lastCount = response.getCount();

                        target.appendJavaScript(jqgridUpdateJs());
                        target.appendJavaScript(jqgridPopulatedJs());
                    }
                }
            }
        }
    });
}

From source file:com.mycompany.AjaxCanNotRollLinkPanel.java

License:Apache License

/**
 * NNbNCxg<br>//from  w  w w .ja v a2s. c o  m
 *
 * NgpsC^?[oJA???<br>
 * NNbN???Override?superL?<br>
 * gp?F<br>
 * <code>
 *  new AjaxCanNotRollLinkPanel(?`) {
 *      @Override
 *      protected void onClickEvent(AjaxRequestTarget target) {
 *          super.onClickEvent(target);
 *          NbN??L?q
 *      }
 *  });
 * </code>
 * @param target Override?gp~
 */
protected void onClickEvent(AjaxRequestTarget target) {
    update.setEnabled(false);
    updateLabel.setVisible(false);
    indicator.setVisible(true);
    this.add(new AbstractAjaxTimerBehavior(waitTime) {
        @Override
        protected void onTimer(AjaxRequestTarget target) {
            update.setEnabled(true);
            updateLabel.setVisible(true);
            indicator.setVisible(false);
            this.stop();
            target.add(this.getComponent());
        }
    });
    target.add(targetComponent);
}