protected void onInitialize()

in openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java [67:165]


	protected void onInitialize() {
		super.onInitialize();

		SearchableDataProvider<IDataProviderEntity> sdp = new SearchableDataProvider<>(null) {
			private static final long serialVersionUID = 1L;

			private List<IDataProviderEntity> getConnections() {
				return Stream.concat(cm.stream()
						, streamProcessor.getStreams()
						.stream()
						.map(KStreamDto::new)
					).toList();
			}

			@Override
			public Iterator<? extends IDataProviderEntity> iterator(long first, long count) {
				List<IDataProviderEntity> l = getConnections();
				return l.subList((int)Math.max(0, first), (int)Math.min(first + count, l.size())).iterator();
			}

			@Override
			public long size() {
				return getConnections().size();
			}
		};
		final WebMarkupContainer container = new WebMarkupContainer("container");
		final WebMarkupContainer details = new WebMarkupContainer("details");
		SearchableDataView<IDataProviderEntity> dataView = new SearchableDataView<>("clientList", sdp) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(final Item<IDataProviderEntity> item) {
				if (item.getModelObject() instanceof KStreamDto kStream) {
					item.add(new Label("type", kStream.getType() + " " + kStream.getStreamType()));
					item.add(new Label("login", kStream.getUid()));
					item.add(new Label("since", getDateFormat().format(kStream.getConnectedSince())));
					item.add(new Label("scope", kStream.getRoomId()));
					item.add(new Label("server", ""));
					item.add(new Label("kick", ""));
				}
				if (item.getModelObject() instanceof Client c) {
					item.add(new Label("type", "html5"));
					item.add(new Label("login", c.getUser().getLogin()));
					item.add(new Label("since", getDateFormat().format(c.getConnectedSince())));
					item.add(new Label("scope", c.getRoom() == null ? "html5" : "" + c.getRoom().getId()));
					item.add(new Label("server", c.getServerId()));
					item.add(new BootstrapAjaxLink<String>("kick", null, Buttons.Type.Outline_Danger, new ResourceModel("603")) {
						private static final long serialVersionUID = 1L;
						{
							setSize(Buttons.Size.Small);
						}

						@Override
						public void onClick(AjaxRequestTarget target) {
							cm.invalidate(c.getUserId(), c.getSessionId());
							target.add(container, details.setVisible(false));
						}
					}.add(newOkCancelConfirm(this, getString("605"))));
				}

				item.add(AjaxEventBehavior.onEvent(EVT_CLICK, target -> {
					Field[] ff = (item.getModelObject() instanceof KStreamDto ? KStreamDto.class : Client.class).getDeclaredFields();
					RepeatingView lines = new RepeatingView("line");
					Object c = item.getModelObject();

					for (Field f : ff) {
						int mod = f.getModifiers();
						if (Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
							continue;
						}
						WebMarkupContainer line = new WebMarkupContainer(lines.newChildId());
						line.add(new Label("name", f.getName()));
						String val = "";
						try {
							f.setAccessible(true);
							val = "" + f.get(c);
						} catch (Exception e) {
							//noop
						}
						line.add(new Label("value", val));
						lines.add(line);
					}
					details.addOrReplace(lines);
					target.add(details.setVisible(true));
				}));

				item.add(AttributeModifier.append(ATTR_CLASS, ROW_CLASS));
			}
		};
		add(container.add(dataView).setOutputMarkupId(true), details.setVisible(false).setOutputMarkupPlaceholderTag(true));
		add(new PagedEntityListPanel("navigator", dataView) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onEvent(AjaxRequestTarget target) {
				target.add(container);
			}
		});
	}