All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.personify.iam.frontend.wicket.panel.common.MapPanel Maven / Gradle / Ivy

There is a newer version: 1.5.2.RELEASE
Show newest version
package be.personify.iam.frontend.wicket.panel.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.Model;

import be.personify.util.KeyValue;

public class MapPanel extends Panel {

	private static final String OBFUSCATED_PASS = "******************";

	private static final String PASSWORD = "password";

	private static final String VALUE = "value";

	private static final String KEY = "key";

	private static final long serialVersionUID = 3718617781557193878L;

	private static final Logger logger = LogManager.getLogger(MapPanel.class);

	public MapPanel(String id, Map map) {
		super(id);
		logger.debug("new MapPanel {}", id);
		add(getDataView("dataView", map));
		Injector.get().inject(this);
	}

	public DataView getDataView(String name, Map map) {

		List keyValueList = new ArrayList();
		for (String key : map.keySet()) {
			keyValueList.add(new KeyValue(key, map.get(key)));
		}

		DataView view = new DataView(name, new ListDataProvider(keyValueList)) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(Item item) {
				item.add(new Label(KEY, new Model(item.getModelObject().getKey())));
				if ( item.getModelObject().getKey().equalsIgnoreCase(PASSWORD)) {
					item.add(new Label(VALUE, new Model(OBFUSCATED_PASS)));
				}
				else {
					item.add(new Label(VALUE, new Model(item.getModelObject().getValue())));
				}
			}
		};

		view.setItemsPerPage(10);
		return view;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy