package org.csstudio.opibuilder.widgets.model;

import org.csstudio.opibuilder.model.AbstractContainerModel;
import org.csstudio.opibuilder.properties.BooleanProperty;
import org.csstudio.opibuilder.properties.WidgetPropertyCategory;

/**The model for grouping container widget.
 * @author Xihui Chen
 *
 */
public class GroupingContainerModel extends AbstractContainerModel {

	/**
	 * The ID of this widget model.
	 */
	public static final String ID = "org.csstudio.opibuilder.widgets.groupingContainer"; //$NON-NLS-1$	
	
	/**True if the background color is transparent. */
	public static final String PROP_TRANSPARENT = "transparent";	
	
	/** True if children widgets are not selectable.*/
	public static final String PROP_LOCK_CHILDREN = "lock_children";
	/**
	 * True if scrollbar is visible when children widgets are out of range. 
	 */
	public static final String PROP_SHOW_SCROLLBAR = "show_scrollbar";

	
	public GroupingContainerModel() {
		setSize(200, 200);
		//setBorderStyle(BorderStyle.GROUP_BOX);
	}
	
	@Override
	protected void configureProperties() {
		addProperty(new BooleanProperty(PROP_TRANSPARENT, "Transparent Background",
				WidgetPropertyCategory.Display, false));
		addProperty(new BooleanProperty(PROP_LOCK_CHILDREN, "Lock Children",
				WidgetPropertyCategory.Behavior, false));
		addProperty(new BooleanProperty(PROP_SHOW_SCROLLBAR, "Show Scrollbar",
				WidgetPropertyCategory.Behavior, true));
	}

	@Override
	public String getTypeID() {
		return ID;
	}

	
	/**
	 * Returns, if this widget should have a transparent background.
	 * @return boolean
	 * 				True, if it should have a transparent background, false otherwise
	 */
	public boolean isTransparent() {
		return (Boolean) getProperty(PROP_TRANSPARENT).getPropertyValue();
	}
	
	/**
	* @return boolean
	* 				True, if the children should be locked, false otherwise
	*/
	public boolean isLocked() {
		return (Boolean) getProperty(PROP_LOCK_CHILDREN).getPropertyValue();
	}
	
	/**
	* @return boolean
	* 				True, if scrollbar should be shown when necessary, false otherwise.
	*/
	public boolean isShowScrollbar() {
		return (Boolean) getProperty(PROP_SHOW_SCROLLBAR).getPropertyValue();
	}
	
}

@@ -102,16 +102,74 @@
 rModel;%0A
+import org.csstudio.opibuilder.model.AbstractWidgetModel;%0A
 import o
@@ -284,16 +284,58 @@
 ategory;
+%0Aimport org.eclipse.draw2d.geometry.Point;
 %0A%0A/**The
@@ -2272,11 +2272,983 @@
 ();%0A%09%7D%0A%09
+%0A%0A%09@Override%0A%09public void flipVertically() %7B%0A%09%09int centerY = getHeight()/2;%0A%09%09for(AbstractWidgetModel abstractWidgetModel : getChildren())%7B%0A%09%09%09abstractWidgetModel.flipVertically(centerY);%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09public void flipHorizontally() %7B%0A%09%09int centerX = getWidth()/2;%0A%09%09for(AbstractWidgetModel abstractWidgetModel : getChildren())%7B%0A%09%09%09abstractWidgetModel.flipHorizontally(centerX);%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09public void rotate90(boolean clockwise) %7B%0A%09%09Point center = new Point(getWidth()/2, getHeight()/2);%0A%09%09for(AbstractWidgetModel abstractWidgetModel : getChildren())%7B%0A%09%09%09abstractWidgetModel.rotate90(clockwise, center);%0A%09%09%7D%0A%09%09Point oldLoc = getLocation();%0A%09%09super.rotate90(clockwise);%0A%09%09Point newLoc = getLocation();%0A%09%09%0A%09%09int dx = newLoc.x - oldLoc.x;%0A%09%09int dy = newLoc.y - oldLoc.y;%0A%09%09//move back%0A%09%09for(AbstractWidgetModel abstractWidgetModel : getChildren())%7B%0A%09%09%09abstractWidgetModel.setLocation(%0A%09%09%09%09%09abstractWidgetModel.getLocation().translate(-dx, -dy));%0A%09%09%7D%0A%09%09%0A%09%7D%0A%09
 %0A%7D%0A

support orientation operation on Group Container