/* * Copyright 2010 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.gcube.portlets.admin.authportletmanager.client.pagelayout; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing; import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth; import com.google.gwt.core.shared.GWT; import com.google.gwt.view.client.HasData; import com.google.gwt.view.client.ListDataProvider; /** * The data source for contact information used in the sample. */ public class PolicyDataProvider { /** * The singleton instance of the database. */ private static PolicyDataProvider instance; /** * Get the singleton instance of the contact database. * * @return the singleton instance */ public static PolicyDataProvider get() { if (instance == null) { instance = new PolicyDataProvider(); } return instance; } /** * The provider that holds the list of contacts in the database. */ private ListDataProvider dataProvider = new ListDataProvider(); /** * The list string used for search */ private List initialSearch= new ArrayList();; /** * The list policy used for datagrid */ private List initialPolicies; /** * Construct a new PolicyDataProvider */ private PolicyDataProvider() { } /** * Add a display to the database. The current range of interest of the display * will be populated with data. * * @param display a {@Link HasData}. */ public void addDataDisplay(HasData display) { dataProvider.addDataDisplay(display); } public ListDataProvider getDataProvider() { return dataProvider; } /** * Load list policy provider * @param listResultPolicy */ public void loadPolicyProvider(List listResultPolicy) { initialPolicies = listResultPolicy; //load list policy from servlet List policies = dataProvider.getList(); policies.removeAll(policies); for (PolicyAuth policy : listResultPolicy){ policies.add(policy); } } /*** * Reset a provider */ public void resetPolicyProvider(){ List policies = dataProvider.getList(); policies.clear(); } /** * Refresh all displays. */ public void refreshDisplays() { dataProvider.refresh(); } /** * Method for remove policy from provider * @param idpolicy */ public void removePolicyProvider(Long idpolicy) { // TODO Auto-generated method stub List policies = dataProvider.getList(); for (int i=0; i policies = dataProvider.getList(); policies.add(policy); initialPolicies.add(policy); dataProvider.setList(policies); } /** * Used for research a string filter * @return */ public List getInitialSearch() { return initialSearch; } /** * Refresh list from a list search */ public void refreshlistFromSearch(String typeSearch){ List policies = new ArrayList(); Collections.copy(policies, initialPolicies); List toRemove = new ArrayList(policies.size()); for (int index=0; index initialSearch) { this.initialSearch = initialSearch; } /** * Used for add a string search * @param search */ public void setAddStringSearch(String search){ this.initialSearch.add(search); } /** * Used for remove string search * @param filter */ public void removeStringSearch(String filter) { // TODO Auto-generated method stub this.initialSearch.remove(filter); } /** * Used for remove all string search */ public void removeAllStringSearch() { // TODO Auto-generated method stub this.initialSearch.clear(); } /** * Used for insert a filter button * @param typefilter */ public void setFilterList(String typefilter) { // TODO Auto-generated method stub List policiesFilter = new ArrayList(); if (typefilter.isEmpty()){ Collections.copy(policiesFilter, initialPolicies); } else{ for (int index=0; index