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:io.ucoin.ucoinj.web.pages.admin.ToolsPage.java

License:Open Source License

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

    IModel<ToolsPage> model = new CompoundPropertyModel<ToolsPage>(this);

    isIndexingLastBlocksRunning = false;

    // Progression panel
    progressionModel = new WicketProgressionModel(getSession().getId());
    progressionPanel = new ProgressionPanel("progress", progressionModel) {
        private static final long serialVersionUID = 1L;

        @Override/*from   w  w  w.j  a v a 2 s.c om*/
        protected void onConfigure() {
            super.onConfigure();
            setVisibilityAllowed(isIndexingLastBlocksRunning);
        }

        @Override
        public void onComplete(AjaxRequestTarget target) {
            ToolsPage.this.onIndexLastBlocksComplete(target);
        }
    };
    progressionPanel.setOutputMarkupId(true);
    progressionPanel.setOutputMarkupPlaceholderTag(true);
    add(progressionPanel);

    Form<ToolsPage> form = new Form<ToolsPage>("form", model);
    form.setOutputMarkupId(true);
    add(form);

    AjaxButton startIndexLastBlocksButton = new AjaxButton("startIndexLastBlocksButton", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onAfterSubmit(target, form);
            startIndexLastBlocks(target);
        }
    };
    form.add(startIndexLastBlocksButton);

    // auto refresh
    selfUpdatingTimer = new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
        @Override
        protected void onTimer(AjaxRequestTarget target) {
            //String message = new StringResourceModel("tools.refreshLastUpdateDate.done", ToolsPage.this, new Model<ToolsPage>(ToolsPage.this)).getString();
            stop(target);

            //info(message);
            target.add(ToolsPage.this);
        }
    };
    selfUpdatingTimer.stop(null);
    add(selfUpdatingTimer);
}

From source file:name.martingeisse.webeco.SimulatorPage.java

License:Open Source License

/**
 * Constructor.//from   www . ja v  a 2s  .  c  o m
 */
public SimulatorPage() {

    final GuiMessageHub guiMessageHub = Simulator.getGuiMessageHub();

    final CharacterDisplayPanel characterDisplayPanel = new CharacterDisplayPanel("characterDisplayPanel",
            guiMessageHub.getCharacterDisplayQueue());
    add(characterDisplayPanel);

    final QueueTextFeeder feeder = new QueueTextFeeder("text", guiMessageHub.getTerminalOutputQueue());
    add(feeder);

    add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
        @Override
        protected void onTimer(final AjaxRequestTarget target) {
            characterDisplayPanel.feed(target);
            feeder.feed(target);
        }
    });

    final Form<Void> inputForm = new Form<Void>("inputForm");
    add(inputForm);

    final TextField<String> inputLineTextField = new TextField<String>("text",
            new PropertyModel<String>(this, "inputLine"));
    inputLineTextField.setOutputMarkupId(true);
    inputForm.add(inputLineTextField);

    inputForm.add(new AjaxButton("submit", inputForm) {
        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            inputLine = (inputLine == null) ? "" : inputLine;
            guiMessageHub.getTerminalInputQueue().add(inputLine + "\r\n");
            notifyTerminalInputAvailable();
            inputLine = null;
            target.add(inputLineTextField);
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
        }
    });

    final WebMarkupContainer backspaceButton = new WebMarkupContainer("backspaceButton");
    add(backspaceButton);
    backspaceButton.add(new AjaxEventBehavior("onclick") {
        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            guiMessageHub.getTerminalInputQueue().add("\b");
            notifyTerminalInputAvailable();
        }
    });

    add(new AjaxLink<Void>("resetLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            guiMessageHub.getActions().add(new ISimulatorAction() {
                @Override
                public void execute(SimulationModel model) {
                    model.getCpu().reset();
                }
            });
        }
    });

}

From source file:ontopoly.components.LockPanel.java

License:Apache License

public LockPanel(String id, IModel<? extends Topic> topicModel, boolean shouldAcquireLock) {
    super(id, topicModel);

    // acquire lock unless read-only page
    if (!shouldAcquireLock)
        acquireLock();/*from  w  ww.j  ava 2  s.co  m*/

    WebMarkupContainer container = new WebMarkupContainer("lockPanelContainer") {
        @Override
        public boolean isVisible() {
            return lockedByOther;
        }
    };
    container.setOutputMarkupId(true);

    container.add(new Label("lockMessage", lockedByOther ? new ResourceModel("lockPanel.message") : null));

    container.add(new Label("lockedByLabel", new ResourceModel("lockPanel.lockedByLabel")));
    container.add(new Label("lockedByValue", lockedBy));
    container.add(new Label("lockedAtLabel", new ResourceModel("lockPanel.lockedAtLabel")));
    container.add(new Label("lockedAtValue", lockedAt));

    final AbstractAjaxTimerBehavior timerBehavior = new AbstractAjaxTimerBehavior(
            Duration.minutes(LockManager.DEFAULT_LOCK_REACQUIRE_TIMESPAN_MINUTES)) {
        @Override
        protected void onTimer(AjaxRequestTarget target) {
            boolean hadlock = !lockedByOther;
            //! System.out.println("Attempting to " + (hadlock ? "re" : "") + "acquire lock on " + (AbstractTopic)getModelObject());
            boolean gotlock = acquireLock();
            //! System.out.println("Got lock: " + hadlock + " " + gotlock);
            if ((hadlock && !gotlock)) {
                stop();
                onLockLost(target, (Topic) getDefaultModelObject());
            } else if (!hadlock && gotlock) {
                onLockWon(target, (Topic) getDefaultModelObject());
            }
        }
    };
    Button unlockButton = new Button("unlockButton");
    unlockButton.add(new AjaxFormComponentUpdatingBehavior("onclick") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            LockManager lockManager = OntopolyContext.getLockManager();
            Topic topic = (Topic) getDefaultModelObject();
            lockManager.forcedUnlock(lockKey);
            timerBehavior.stop();
            onLockWon(target, topic);
        }
    });
    container.add(unlockButton);
    add(container);

    // add timer behaviour only if page was locked by us
    if (!lockedByOther) {
        // have page (re)acquire the lock just before it times out
        add(timerBehavior);
    }
}

From source file:org.apache.jetspeed.portlets.rpad.RemotePortletAppDeployer.java

License:Apache License

@SuppressWarnings("unchecked")
public RemotePortletAppDeployer() {
    deployer = new JetspeedPortletDeployer();
    Form form = new Form("form");
    repositories = getRepositoryManager().getRepositories();
    form.add(new DropDownChoice("repositorySelection", new PropertyModel(this, "selectedRepository"),
            repositories, new ChoiceRenderer("name", "name")));

    Button selectButton = new Button("selectButton") {

        private static final long serialVersionUID = 1L;

        public void onSubmit() {

        }//from  w  w  w . j av a 2 s  . c  om
    };

    form.add(selectButton);
    add(form);

    IModel getRepo = new LoadableDetachableModel() {

        protected Object load() {
            return getRepo();
        }
    };

    final PageableListView listview = new PageableListView("repositories", getRepo, 10) {

        private static final long serialVersionUID = 1L;

        // This method is called for each 'entry' in the list.
        @Override
        protected void populateItem(final ListItem item) {
            final PortletApplication application = (PortletApplication) item.getModelObject();
            item.add(new Label("groupId", application.getGroupId()));
            item.add(new Label("artifactId", application.getArtifactId()));
            item.add(new Label("name", application.getName()));
            item.add(new Label("version", application.getVersion()));
            item.add(new Label("type", application.getPackaging()));
            Link actionLink = new Link("action", item.getModel()) {

                public void onClick() {
                    PortletApplication portletApplication = (PortletApplication) getModelObject();
                    deployer.deploy(portletApplication, getServiceLocator().getDeploymentManager());
                }
            };
            actionLink.setVisibilityAllowed(true);
            actionLink.setOutputMarkupId(true);
            if (deployer.getStatus() == PortletDeployer.DEPLOYING) {
                actionLink.setVisible(false);
            }
            item.add(actionLink);
        }
    };
    listview.setOutputMarkupId(true);
    final WebMarkupContainer tableGroup = new WebMarkupContainer("tableGroup");
    tableGroup.setOutputMarkupId(true);
    //tableGroup.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)));
    tableGroup.add(new PagingNavigator("navigator", listview));
    tableGroup.add(listview);
    final MultiLineLabel statusLabel = new MultiLineLabel("status", new PropertyModel(this, "message"));
    statusLabel.setOutputMarkupId(true);
    final Label tickerLabel = new Label("ticker", new PropertyModel(this, "ticker"));
    tickerLabel.setOutputMarkupId(true);
    add(new AbstractAjaxTimerBehavior(Duration.seconds(3)) {
        protected void onTimer(AjaxRequestTarget target) {
            setMessage(deployer.getMessage());
            target.addComponent(tickerLabel);
            target.addComponent(statusLabel);
            target.addComponent(tableGroup);
        }
    });
    add(statusLabel);
    add(tickerLabel);
    add(tableGroup);

}

From source file:org.apache.openmeetings.web.pages.MainPage.java

License:Apache License

public MainPage() {
    super();//w  ww  . j  av a 2  s  .c  om
    getHeader().setVisible(false);
    add(main, inviteUser = new InviteUserToRoomDialog("invite-to-room"));
    //load preselected content
    add(areaBehavior = new AbstractAjaxTimerBehavior(Duration.ONE_SECOND) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            OmUrlFragment area = WebSession.get().getArea();
            main.updateContents(area == null ? OmUrlFragment.get() : area, target);
            stop(target);
            WebSession.get().setArea(null);
        }
    });
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            inviteUser.open(target, getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(JavaScriptHeaderItem
                    .forScript(getNamedFunction("inviteUser", this, explicit(PARAM_USER_ID)), "inviteUser")));
        }
    });
}

From source file:org.apache.openmeetings.web.room.SwfPanel.java

License:Apache License

public SwfPanel(String id, PageParameters pp) {
    super(id);//from   ww  w . j av a 2 s.c  o m
    //OK let's find the room
    try {
        StringValue room = pp.get(WICKET_ROOM_ID);
        if (!room.isEmpty()) {
            roomId = room.toLongObject();
        }
    } catch (Exception e) {
        //no-op
    }
    PageParameters spp = new PageParameters(pp);
    if (roomId != null) {
        spp.mergeWith(new PageParameters().add(WICKET_ROOM_ID, roomId));
    }
    add(new Label("init", getInitFunction(spp)).setEscapeModelStrings(false));
    add(new AbstractAjaxTimerBehavior(Duration.minutes(5)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            getBean(SessiondataDao.class).check(WebSession.getSid()); //keep SID alive
        }
    });
    RoomInvitationForm rif = new RoomInvitationForm("form", roomId);
    add(invite = new InvitationDialog("invite", rif));
    rif.setDialog(invite);
    add(createPoll = new CreatePollDialog("createPoll", roomId));
    add(vote = new VoteDialog("vote", roomId));
    add(pollResults = new PollResultsDialog("pollResults", roomId));
    add(startSharing = new StartSharingEventBehavior(roomId));
    if (roomId != null && roomId.longValue() > 0) {
        add(new AbstractDefaultAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void respond(AjaxRequestTarget target) {
                invite.updateModel(target);
                invite.open(target);
            }

            @Override
            public void renderHead(Component component, IHeaderResponse response) {
                super.renderHead(component, response);
                response.render(new PriorityHeaderItem(JavaScriptHeaderItem
                        .forScript(getNamedFunction("openInvitation", this), "openInvitation")));
            }
        });
        add(new AbstractDefaultAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void respond(AjaxRequestTarget target) {
                String publicSid = getPublicSid();
                Client c = getClient(publicSid);
                if (c != null && c.getIsMod()) {
                    createPoll.updateModel(target, publicSid);
                    createPoll.open(target);
                }
            }

            @Override
            public void renderHead(Component component, IHeaderResponse response) {
                super.renderHead(component, response);
                response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript(
                        getNamedFunction("createPoll", this, explicit(PARAM_PUBLIC_SID)), "createPoll")));
            }
        });
        add(new AbstractDefaultAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void respond(AjaxRequestTarget target) {
                Client c = getClient(getPublicSid());
                if (c != null) {
                    pollResults.updateModel(target, c.getIsMod());
                    pollResults.open(target);
                }
            }

            @Override
            public void renderHead(Component component, IHeaderResponse response) {
                super.renderHead(component, response);
                response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript(
                        getNamedFunction("pollResults", this, explicit(PARAM_PUBLIC_SID)), "pollResults")));
            }
        });
        add(new AbstractDefaultAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void respond(AjaxRequestTarget target) {
                if (getBean(PollDao.class).hasPoll(roomId)
                        && !getBean(PollDao.class).hasVoted(roomId, getUserId())
                        && getClient(getPublicSid()) != null) {
                    vote.updateModel(target);
                    vote.open(target);
                }
            }

            @Override
            public void renderHead(Component component, IHeaderResponse response) {
                super.renderHead(component, response);
                response.render(new PriorityHeaderItem(JavaScriptHeaderItem
                        .forScript(getNamedFunction("vote", this, explicit(PARAM_PUBLIC_SID)), "vote")));
            }
        });
        add(new AbstractDefaultAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void respond(AjaxRequestTarget target) {
                startSharing.respond(target);
            }

            @Override
            public void renderHead(Component component, IHeaderResponse response) {
                super.renderHead(component, response);
                response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript(
                        getNamedFunction("startSharing", this, explicit(PARAM_PUBLIC_SID)), "startSharing")));
            }
        });
    }
}

From source file:org.apache.syncope.client.console.panels.RuntimePanel.java

License:Apache License

public void startPolling(final int seconds) {
    AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(seconds)) {

        private static final long serialVersionUID = 1L;

        @Override/*w  ww .j a  v  a2  s  . c  o  m*/
        protected void onTimer(AjaxRequestTarget target) {
            target.add(refresh());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getExtraParameters().put("pollingTimeout", "true");
        }

    };

    panel.setTimer(timer);

}

From source file:org.apache.syncope.client.console.topology.Topology.java

License:Apache License

public Topology() {
    modal = new BaseModal<>("resource-modal");
    body.add(modal.size(Modal.Size.Large));
    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override//from   ww w. j  ava 2  s.c  o m
        public void onClose(final AjaxRequestTarget target) {
            modal.show(false);
        }
    });

    body.add(new TopologyWebSocketBehavior());

    togglePanel = new TopologyTogglePanel("toggle", getPageReference());
    body.add(togglePanel);

    // -----------------------------------------
    // Add Zoom panel
    // -----------------------------------------
    final ActionLinksPanel.Builder<Serializable> zoomActionPanel = ActionLinksPanel.builder();
    zoomActionPanel.setDisableIndicator(true);

    zoomActionPanel.add(new ActionLink<Serializable>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
            target.appendJavaScript("zoomIn($('#drawing')[0]);");
        }
    }, ActionLink.ActionType.ZOOM_IN, StandardEntitlement.RESOURCE_LIST).add(new ActionLink<Serializable>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
            target.appendJavaScript("zoomOut($('#drawing')[0]);");
        }
    }, ActionLink.ActionType.ZOOM_OUT, StandardEntitlement.RESOURCE_LIST);

    body.add(zoomActionPanel.build("zoom"));
    // -----------------------------------------

    // -----------------------------------------
    // Add Syncope (root topologynode)
    // -----------------------------------------
    final TopologyNode syncopeTopologyNode = new TopologyNode(ROOT_NAME, ROOT_NAME, TopologyNode.Kind.SYNCOPE);
    syncopeTopologyNode.setX(origX);
    syncopeTopologyNode.setY(origY);

    final URI uri = WebClient.client(BaseRestClient.getSyncopeService()).getBaseURI();
    syncopeTopologyNode.setHost(uri.getHost());
    syncopeTopologyNode.setPort(uri.getPort());

    body.add(topologyNodePanel("syncope", syncopeTopologyNode));

    final Map<Serializable, Map<Serializable, TopologyNode>> connections = new HashMap<>();
    final Map<Serializable, TopologyNode> syncopeConnections = new HashMap<>();
    connections.put(syncopeTopologyNode.getKey(), syncopeConnections);

    // required to retrieve parent positions
    final Map<String, TopologyNode> servers = new HashMap<>();
    final Map<String, TopologyNode> connectors = new HashMap<>();
    // -----------------------------------------

    // -----------------------------------------
    // Add Connector Servers
    // -----------------------------------------
    final ListView<URI> connectorServers = new ListView<URI>("connectorServers",
            csModel.getObject().getLeft()) {

        private static final long serialVersionUID = 6978621871488360380L;

        private final int size = csModel.getObject().getLeft().size() + 1;

        @Override
        protected void populateItem(final ListItem<URI> item) {
            int kx = size >= 4 ? 800 : (200 * size);

            int x = (int) Math.round(origX + kx * Math.cos(Math.PI + Math.PI * (item.getIndex() + 1) / size));
            int y = (int) Math.round(origY + 100 * Math.sin(Math.PI + Math.PI * (item.getIndex() + 1) / size));

            final URI location = item.getModelObject();
            final String url = location.toASCIIString();

            final TopologyNode topologynode = new TopologyNode(url, url, TopologyNode.Kind.CONNECTOR_SERVER);

            topologynode.setHost(location.getHost());
            topologynode.setPort(location.getPort());
            topologynode.setX(x);
            topologynode.setY(y);

            servers.put(String.class.cast(topologynode.getKey()), topologynode);

            item.add(topologyNodePanel("cs", topologynode));

            syncopeConnections.put(url, topologynode);
            connections.put(url, new HashMap<Serializable, TopologyNode>());
        }
    };

    connectorServers.setOutputMarkupId(true);
    body.add(connectorServers);
    // -----------------------------------------

    // -----------------------------------------
    // Add File Paths
    // -----------------------------------------
    final ListView<URI> filePaths = new ListView<URI>("filePaths", csModel.getObject().getRight()) {

        private static final long serialVersionUID = 6978621871488360380L;

        private final int size = csModel.getObject().getRight().size() + 1;

        @Override
        protected void populateItem(final ListItem<URI> item) {
            int kx = size >= 4 ? 800 : (200 * size);

            int x = (int) Math.round(origX + kx * Math.cos(Math.PI * (item.getIndex() + 1) / size));
            int y = (int) Math.round(origY + 100 * Math.sin(Math.PI * (item.getIndex() + 1) / size));

            final URI location = item.getModelObject();
            final String url = location.toASCIIString();

            final TopologyNode topologynode = new TopologyNode(url, url, TopologyNode.Kind.FS_PATH);

            topologynode.setHost(location.getHost());
            topologynode.setPort(location.getPort());
            topologynode.setX(x);
            topologynode.setY(y);

            servers.put(String.class.cast(topologynode.getKey()), topologynode);

            item.add(topologyNodePanel("fp", topologynode));

            syncopeConnections.put(url, topologynode);
            connections.put(url, new HashMap<Serializable, TopologyNode>());
        }
    };

    filePaths.setOutputMarkupId(true);
    body.add(filePaths);
    // -----------------------------------------

    // -----------------------------------------
    // Add Connector Intances
    // -----------------------------------------
    final List<List<ConnInstanceTO>> allConns = new ArrayList<>(connModel.getObject().values());

    final ListView<List<ConnInstanceTO>> conns = new ListView<List<ConnInstanceTO>>("conns", allConns) {

        private static final long serialVersionUID = 697862187148836036L;

        @Override
        protected void populateItem(final ListItem<List<ConnInstanceTO>> item) {

            final int size = item.getModelObject().size() + 1;

            final ListView<ConnInstanceTO> conns = new ListView<ConnInstanceTO>("conns",
                    item.getModelObject()) {

                private static final long serialVersionUID = 6978621871488360381L;

                @Override
                protected void populateItem(final ListItem<ConnInstanceTO> item) {
                    final ConnInstanceTO conn = item.getModelObject();

                    final TopologyNode topologynode = new TopologyNode(conn.getKey(), conn.getDisplayName(),
                            TopologyNode.Kind.CONNECTOR);

                    // Define the parent note
                    final TopologyNode parent = servers.get(conn.getLocation());

                    // Set the position
                    int kx = size >= 6 ? 800 : (130 * size);

                    final double hpos;
                    if (conn.getLocation().startsWith(CONNECTOR_SERVER_LOCATION_PREFIX)) {
                        hpos = Math.PI;
                    } else {
                        hpos = 0.0;
                    }

                    int x = (int) Math.round((parent == null ? origX : parent.getX())
                            + kx * Math.cos(hpos + Math.PI * (item.getIndex() + 1) / size));
                    int y = (int) Math.round((parent == null ? origY : parent.getY())
                            + 100 * Math.sin(hpos + Math.PI * (item.getIndex() + 1) / size));

                    topologynode.setConnectionDisplayName(conn.getBundleName());
                    topologynode.setX(x);
                    topologynode.setY(y);

                    connectors.put(String.class.cast(topologynode.getKey()), topologynode);
                    item.add(topologyNodePanel("conn", topologynode));

                    // Update connections
                    final Map<Serializable, TopologyNode> remoteConnections;

                    if (connections.containsKey(conn.getLocation())) {
                        remoteConnections = connections.get(conn.getLocation());
                    } else {
                        remoteConnections = new HashMap<>();
                        connections.put(conn.getLocation(), remoteConnections);
                    }
                    remoteConnections.put(conn.getKey(), topologynode);
                }
            };

            conns.setOutputMarkupId(true);
            item.add(conns);
        }
    };

    conns.setOutputMarkupId(true);
    body.add(conns);
    // -----------------------------------------

    // -----------------------------------------
    // Add Resources
    // -----------------------------------------
    final List<String> connToBeProcessed = new ArrayList<>();
    for (ResourceTO resourceTO : resModel.getObject()) {
        final TopologyNode topologynode = new TopologyNode(resourceTO.getKey(), resourceTO.getKey(),
                TopologyNode.Kind.RESOURCE);

        final Map<Serializable, TopologyNode> remoteConnections;

        if (connections.containsKey(resourceTO.getConnector())) {
            remoteConnections = connections.get(resourceTO.getConnector());
        } else {
            remoteConnections = new HashMap<>();
            connections.put(resourceTO.getConnector(), remoteConnections);
        }

        remoteConnections.put(topologynode.getKey(), topologynode);

        if (!connToBeProcessed.contains(resourceTO.getConnector())) {
            connToBeProcessed.add(resourceTO.getConnector());
        }
    }

    final ListView<String> resources = new ListView<String>("resources", connToBeProcessed) {

        private static final long serialVersionUID = 697862187148836038L;

        @Override
        protected void populateItem(final ListItem<String> item) {
            final String connectorKey = item.getModelObject();

            final ListView<TopologyNode> innerListView = new ListView<TopologyNode>("resources",
                    new ArrayList<>(connections.get(connectorKey).values())) {

                private static final long serialVersionUID = 1L;

                private final int size = getModelObject().size() + 1;

                @Override
                protected void populateItem(final ListItem<TopologyNode> item) {
                    final TopologyNode topologynode = item.getModelObject();
                    final TopologyNode parent = connectors.get(connectorKey);

                    // Set position
                    int kx = size >= 16 ? 800 : (48 * size);
                    int ky = size < 4 ? 100 : size < 6 ? 350 : 750;

                    final double hpos;
                    if (parent == null || parent.getY() < syncopeTopologyNode.getY()) {
                        hpos = Math.PI;
                    } else {
                        hpos = 0.0;
                    }

                    int x = (int) Math.round((parent == null ? origX : parent.getX())
                            + kx * Math.cos(hpos + Math.PI * (item.getIndex() + 1) / size));
                    int y = (int) Math.round((parent == null ? origY : parent.getY())
                            + ky * Math.sin(hpos + Math.PI * (item.getIndex() + 1) / size));

                    topologynode.setX(x);
                    topologynode.setY(y);

                    item.add(topologyNodePanel("res", topologynode));
                }
            };

            innerListView.setOutputMarkupId(true);
            item.add(innerListView);
        }
    };

    resources.setOutputMarkupId(true);
    body.add(resources);
    // -----------------------------------------

    // -----------------------------------------
    // Create connections
    // -----------------------------------------
    final WebMarkupContainer jsPlace = new WebMarkupContainerNoVeil("jsPlace");
    jsPlace.setOutputMarkupId(true);
    body.add(jsPlace);

    jsPlace.add(new Behavior() {

        private static final long serialVersionUID = 2661717818979056044L;

        @Override
        public void renderHead(final Component component, final IHeaderResponse response) {
            final StringBuilder jsPlumbConf = new StringBuilder();
            jsPlumbConf.append(String.format(Locale.US, "activate(%.2f);", 0.68f));

            for (String str : createConnections(connections)) {
                jsPlumbConf.append(str);
            }

            response.render(OnDomReadyHeaderItem.forScript(jsPlumbConf.toString()));
        }
    });

    jsPlace.add(new AbstractAjaxTimerBehavior(Duration.seconds(2)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(final AjaxRequestTarget target) {
            target.appendJavaScript("checkConnection()");

            if (getUpdateInterval().seconds() < 5.0) {
                setUpdateInterval(Duration.seconds(5));
            } else if (getUpdateInterval().seconds() < 10.0) {
                setUpdateInterval(Duration.seconds(10));
            } else if (getUpdateInterval().seconds() < 15.0) {
                setUpdateInterval(Duration.seconds(15));
            } else if (getUpdateInterval().seconds() < 20.0) {
                setUpdateInterval(Duration.seconds(20));
            } else if (getUpdateInterval().seconds() < 30.0) {
                setUpdateInterval(Duration.seconds(30));
            } else if (getUpdateInterval().seconds() < 60.0) {
                setUpdateInterval(Duration.seconds(60));
            }
        }
    });
    // -----------------------------------------

    newlyCreatedContainer = new WebMarkupContainer("newlyCreatedContainer");
    newlyCreatedContainer.setOutputMarkupId(true);
    body.add(newlyCreatedContainer);

    newlyCreated = new ListView<TopologyNode>("newlyCreated", new ArrayList<TopologyNode>()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<TopologyNode> item) {
            item.add(topologyNodePanel("el", item.getModelObject()));
        }
    };
    newlyCreated.setOutputMarkupId(true);
    newlyCreated.setReuseItems(true);

    newlyCreatedContainer.add(newlyCreated);
}

From source file:org.artifactory.webapp.wicket.page.home.news.ArtifactoryUpdatesPanel.java

License:Open Source License

private void scheduleMessageFetch() {
    add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
        @Override//from w w w .  j a  va2s.co  m
        protected IAjaxCallDecorator getAjaxCallDecorator() {
            return new NoAjaxIndicatorDecorator();
        }

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            stop();
            final Message message = artifactoryUpdatesService.getCachedMessage();
            if (message != null && message != ArtifactoryUpdatesService.PROCESSING_MESSAGE) {
                setupMessage(message);
                target.add(ArtifactoryUpdatesPanel.this);
            }
        }
    });
}

From source file:org.artifactory.webapp.wicket.page.logs.SystemLogsViewPanel.java

License:Open Source License

/**
 * Main constructor// w w w .j  a  v a  2  s .c  om
 *
 * @param id The verbal ID of the panel
 */
public SystemLogsViewPanel(String id) {
    super(id);
    addLogComboBox();
    addSystemLogsSize();
    addSystemLogsLink();
    addSystemLogsContent();
    addLastUpdate();

    // add the timer behavior to the page and make it update both components
    add(new AbstractAjaxTimerBehavior(Duration.seconds(ConstantValues.logsViewRefreshRateSecs.getInt())) {
        @Override
        protected void onTimer(AjaxRequestTarget target) {
            updateComponents(target, (!systemLogFile.exists()));
        }
    });
}