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

xdev.ui.DualListBoxSupport Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
package xdev.ui;

/*-
 * #%L
 * XDEV Component Suite
 * %%
 * Copyright (C) 2011 - 2021 XDEV Software
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */


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

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import xdev.ui.FormularComponent.ValueChangeListener;
import xdev.ui.ItemList.Entry;


/**
 * 
 * @author XDEV Software
 * 
 * @param 
 */
class DualListBoxSupport> extends
		FormularComponentSupport
{
	protected List	savedValue	= new ArrayList();
	
	
	protected DualListBoxSupport(L list)
	{
		super(list);
	}
	
	
	public boolean isMultiSelect()
	{
		return component.isMultipleSelectionsEnabled();
	}
	
	
	// public void setFormularValue(VirtualTable vt, int col, Object value)
	// {
	// list.deselectAll();
	//
	// if(value != null)
	// {
	// List values;
	// if(isMultiSelect() && value.getClass().isArray())
	// {
	// values = CollectionUtils.asList((Object[])value);
	// }
	// else
	// {
	// values = CollectionUtils.asList(value);
	// }
	// list.addToSelected(list.getIndicesOfData(values),false);
	// }
	// }
	
	public Object getFormularValue()
	{
		ItemList itemList = component.selectedItems;
		if(itemList.size() == 0)
		{
			return null;
		}
		else if(itemList.size() == 1 && !isMultiSelect())
		{
			return itemList.getData(0);
		}
		
		return itemList.getDataAsList().toArray();
	}
	
	
	public void saveState()
	{
		savedValue.clear();
		ItemList selected = component.selectedItems;
		int c = selected.size();
		for(int i = 0; i < c; i++)
		{
			savedValue.add(selected.get(i).clone());
		}
	}
	
	
	public void restoreState()
	{
		component.setSelectedEntries(savedValue,false);
	}
	
	
	public boolean hasStateChanged()
	{
		List selectedEntries = new ArrayList();
		ItemList selected = component.selectedItems;
		int c = selected.size();
		for(int i = 0; i < c; i++)
		{
			selectedEntries.add(selected.get(i));
		}
		
		return !savedValue.equals(selectedEntries);
	}
	
	
	public void addValueChangeListener(final ValueChangeListener l)
	{
		component.addListSelectionListener(new ListSelectionListener()
		{
			@Override
			public void valueChanged(ListSelectionEvent e)
			{
				l.valueChanged(e);
			}
		});
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy