package org.csstudio.opibuilder.adl2boy.translator;

import org.csstudio.opibuilder.model.AbstractContainerModel;
import org.csstudio.opibuilder.model.AbstractWidgetModel;
import org.csstudio.opibuilder.widgetActions.ActionsInput;
import org.csstudio.opibuilder.widgetActions.WritePVAction;
import org.csstudio.opibuilder.widgets.model.ActionButtonModel;
import org.csstudio.utility.adlparser.fileParser.ADLWidget;
import org.csstudio.utility.adlparser.fileParser.widgets.MessageButton;
import org.eclipse.swt.graphics.RGB;

public class MessageButton2Model extends AbstractADL2Model {
	ActionButtonModel buttonModel = new ActionButtonModel();

	public MessageButton2Model(ADLWidget adlWidget, RGB[] colorMap, AbstractContainerModel parentModel) {
		super(adlWidget, colorMap, parentModel);
		parentModel.addChild(buttonModel, true);
		MessageButton messageButtonWidget = new MessageButton(adlWidget);
		if (messageButtonWidget != null) {
			setADLObjectProps(messageButtonWidget, buttonModel);
			setADLControlProps(messageButtonWidget, buttonModel);
		}
		buttonModel.setPropertyValue(ActionButtonModel.PROP_TEXT, messageButtonWidget.getLabel());
		int actionIndex = 0;
		String press_msg = messageButtonWidget.getPress_msg();
		if ( (press_msg != null) && !(press_msg.equals(""))){
			ActionsInput ai = buttonModel.getActionsInput();
			WritePVAction wpvAction = new WritePVAction();
			wpvAction.setPropertyValue(WritePVAction.PROP_PVNAME, messageButtonWidget.getAdlControl().getChan());
			wpvAction.setPropertyValue(WritePVAction.PROP_VALUE, press_msg);
			ai.addAction(wpvAction);
			buttonModel.setPropertyValue(ActionButtonModel.PROP_ACTION_INDEX, actionIndex);
			actionIndex++;
		}
		String release_msg = messageButtonWidget.getRelease_msg();
		if ( (release_msg != null) && !(release_msg.equals(""))){
			buttonModel.setPropertyValue(ActionButtonModel.PROP_TOGGLE_BUTTON, true);
			ActionsInput ai = buttonModel.getActionsInput();
			WritePVAction wpvAction = new WritePVAction();
			wpvAction.setPropertyValue(WritePVAction.PROP_PVNAME, messageButtonWidget.getAdlControl().getChan());
			wpvAction.setPropertyValue(WritePVAction.PROP_VALUE, release_msg);
			ai.addAction(wpvAction);
			buttonModel.setPropertyValue(ActionButtonModel.PROP_RELEASED_ACTION_INDEX, actionIndex);
			actionIndex++;
		}
		//TODO Add Color mode to Menu2Model
	}

	@Override
	public	AbstractWidgetModel getWidgetModel() {
		return buttonModel;
	}

}

@@ -2309,43 +2309,542 @@
 %7D%0A%09%09
-//TODO Add C
+String color_mode = messageButtonWidget.getColor_mode();%0A%09%09if ( color_mode.equals(%22static%22) )%7B%0A%09%09%09buttonModel.setPropertyValue(ActionButtonModel.PROP_FORECOLOR_ALARMSENSITIVE, false);%0A%09%09%7D%0A%09%09else if (color_mode.equals(%22alarm%22) )%7B%0A%09%09%09buttonModel.setPropertyValue(ActionButtonModel.PROP_FORECOLOR_ALARMSENSITIVE, true);%0A%09%09%7D%0A%09%09else if (c
 olor
- 
+_
 mode
- to Menu2Model
+.equals(%22discrete%22) )%7B%0A%09%09%09buttonModel.setPropertyValue(ActionButtonModel.PROP_FORECOLOR_ALARMSENSITIVE, false);%0A%09%09%09//TODO MessageButton2Model Figure out what to do if colorMode is discrete%0A%09%09%7D
 %0A%09%7D%0A

Add code to handle static and alarm color modes.