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

be.personify.iam.frontend.wicket.panel.common.ResourcesPanel 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.Arrays;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.model.IModel;
import org.springframework.hateoas.EntityModel;

import be.personify.iam.frontend.wicket.model.common.ResourcesModel;
import be.personify.iam.frontend.wicket.util.wicket.CustomPagingNavigator;

public abstract class ResourcesPanel extends Panel {

	private static final long serialVersionUID = 361376636341741911L;
	
	private static final Logger logger = LogManager.getLogger(ResourcesPanel.class);
	
	public static final long defaultItemsPerPage = 10;
	
	
	
	protected SearchPanel searchPanel;
	private Component resultComponent;
	
	public static final String COMP_NAME_SEARCHPANEL = "searchPanel";
	public static final String COMP_NAME_DATAVIEW_HEADER = "dataViewHeader";
	public static final String COMP_NAME_DATAVIEW = "dataView";
	public static final String COMP_NAME_DETAIL_LINK = "detail";
	public static final String COMP_NAME_EDIT_LINK = "edit";
	public static final String COMP_NAME_DELETE_LINK = "delete";
	private static final String COMP_NAME_NAVIGATOR = "navigator";
	private static final String COMP_NAME_SEARCH_RESULT = "searchResult";
	
	private MarkupContainer searchResult = new WebMarkupContainer(COMP_NAME_SEARCH_RESULT);
	
	private boolean showHeader = true;
	private boolean searchPanelVisible = true;
	private List componentFilters = null;
	
	public static final String SALT_KEY = "h";

	
	public ResourcesPanel(String id) {
		super(id);
	}
	
	public ResourcesPanel(String id, boolean searchPanelVisible, boolean showHeader, String... componentFilters) {
		super(id);
		logger.debug("constructor with id {} searchPanelVisible {} showHeader {} componentFilters {} called", id, searchPanelVisible, showHeader, componentFilters);
		this.searchPanelVisible = searchPanelVisible;
		this.componentFilters = Arrays.asList(componentFilters);
		this.showHeader = showHeader;
	}

	public ResourcesPanel(String id, ResourcesModel> model) {
		super(id, model);
	}
	
	public void setCustomModel(IModel model ) {
		setDefaultModel(model);
	}
	
	public void setCustomModel(ResourcesModel> model ) {
		setDefaultModel(model);
	}

	@Override
	protected void onInitialize() {
		super.onInitialize();
		searchPanel = composeSearchPanel();
		add(searchPanel);
		
		searchResult = new WebMarkupContainer(COMP_NAME_SEARCH_RESULT);
		searchResult.setOutputMarkupId(true);
		
		MarkupContainer panelHeading = new WebMarkupContainer("panel-heading");
		logger.debug("onInitialize() showHeader {}", showHeader);
		panelHeading.setVisible(showHeader);
		searchResult.add(panelHeading);
		
		searchResult.add(getDataViewHeader());
		resultComponent = getDataView();
		searchResult.add(resultComponent);
		searchResult.add(composeNavigator());
		searchResult.setVisible(resultComponent.isVisible());
		add(searchResult);
	}
	
	private Component composeNavigator() {
		Component component = new CustomPagingNavigator(COMP_NAME_NAVIGATOR, (DataView)resultComponent);
		return component;
	}
	
	
	protected void refreshDataView(AjaxRequestTarget target) {
		

		resultComponent = getDataView();
		
		//searchResult.addOrReplace(getDataViewHeader());
		searchResult.addOrReplace(resultComponent);
		searchResult.addOrReplace(new CustomPagingNavigator(COMP_NAME_NAVIGATOR, (DataView)resultComponent));
		
		target.add(searchResult);
	}
	 
	
	public ResourcesModel> getCustomModel() {
		return (ResourcesModel>)getDefaultModel();
	}

	public abstract DataView> getDataView();
	public abstract DataView getDataViewHeader();
	public abstract SearchPanel composeSearchPanel();
	
	public String getPanelName() {
		return this.getClass().getName();
	}
	
	public Component getViewComponent() {
		return resultComponent;
	}

	public boolean isSearchPanelVisible() {
		return searchPanelVisible;
	}

	public void setSearchPanelVisible(boolean searchPanelVisible) {
		this.searchPanelVisible = searchPanelVisible;
	}

	public List getComponentFilters() {
		return componentFilters;
	}

	public void setComponentFilters(List componentFilters) {
		this.componentFilters = componentFilters;
	}

	
	
	public boolean haveToShowComponent( String name ) {
    	if ( getComponentFilters() != null && !getComponentFilters().isEmpty() ) {
    		return !getComponentFilters().contains(name);
    	}
    	return true;
    }
	
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy