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

at.spardat.xma.page.ControlSet Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2003, 2009 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

package at.spardat.xma.page;

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

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

/**
 * Container object used to hold the controls created for a dynamically added widget model.
 * It contains the control corresponding to the model and an optional label.
 * It may contain additional controls like a second label showing a currency etc.
 *
 * @author gub
 * @since 2.1.0
 * @see PageClient#createWidgetForModel(at.spardat.xma.mdl.IWModelClient, at.spardat.xma.mdl.NewModelEventParams)
*/
public class ControlSet {
	/** control which shall be attached to the model */
	Control control;
	/** label corresponding to control */
	Label label;
	/** additional widgets */
	List otherControls;

	/**
	 * Constructs a ControlSet and sets control and label
	 * @param control control which shall be attached to the model
	 * @param label label corresponding to the control
	 */
	public ControlSet(Control control,Label label) {
		this.control=control;
		this.label=label;
	}

	/**
	 * Returns the control which shall be attached to the model
	 */
	public Control getControl() {
		return control;
	}

	/**
	 * Returns the label corresponding to control
	 */
	public Label getLabel() {
		return label;
	}

	/**
	 * Returns all additional widgets added with {@link #addOtherControl(Control)}
	 */
	public List getOtherControls() {
		return otherControls;
	}

	/**
	 * Adds an additional widget created together with control.
	 * This my be a second label showing a currency or something similar.
	 */
	public void addOtherControl(Control control) {
		if(otherControls==null) otherControls=new ArrayList();
		otherControls.add(control);
	}

	/**
	 * Returns control, label and all other controls in an array.
	 */
	public Control[] toArray() {
		int size = 0;
		if(control!=null) size++;
		if(label!=null) size++;
		if(otherControls!=null) size+=otherControls.size();
		Control[] result = new Control[size];
		int i=0;
		if(control!=null) result[i++]=control;
		if(label!=null) result[i++]=label;
		if(otherControls!=null) {
			for(Iterator it=otherControls.iterator();it.hasNext();) {
				result[i++]=(Control) it.next();
			}
		}
		return result;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy