package org.camunda.bpm.modeler.ui.property.tabs.builder;

import org.camunda.bpm.modeler.ui.property.tabs.binding.BooleanButtonBinding;
import org.camunda.bpm.modeler.ui.property.tabs.util.PropertyUtil;
import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.Bpmn2Package;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.graphiti.ui.platform.GFPropertySection;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

/**
 * 
 * @author kristin.polenz
 *
 */
public class IsForCompensationPropertiesBuilder extends AbstractPropertiesBuilder<BaseElement> {

	private static final EStructuralFeature IS_FOR_COMPENSATION_FEATURE = Bpmn2Package.eINSTANCE.getActivity_IsForCompensation();
	
	public IsForCompensationPropertiesBuilder(Composite parent, GFPropertySection section, BaseElement bo) {
		super(parent, section, bo);
	}

	@Override
	public void create() {
		
		final Button checkbox = PropertyUtil.createUnboundCheckbox(section, parent, "For Compensation");
		
		new IsForCompensationFlagButtonBinding(bo, IS_FOR_COMPENSATION_FEATURE, checkbox).establish();
	}

	private class IsForCompensationFlagButtonBinding extends BooleanButtonBinding {

		public IsForCompensationFlagButtonBinding(EObject model, EStructuralFeature feature, Button control) {
			super(model, feature, control);
		}
		
		@Override
		public Boolean getModelValue() {
			return (Boolean) bo.eGet(IS_FOR_COMPENSATION_FEATURE);
		}

		@Override
		public void setModelValue(final Boolean value) {
			TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(bo);
			editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
			
				@Override
				protected void doExecute() {
					if (!value) {
						bo.eUnset(IS_FOR_COMPENSATION_FEATURE);
					} else {
						bo.eSet(IS_FOR_COMPENSATION_FEATURE, value);
					}
				}
			});
		}
	}
}

@@ -56,86 +56,8 @@
 r;%0A%0A
-import org.camunda.bpm.modeler.ui.property.tabs.binding.BooleanButtonBinding;%0A
 impo
@@ -200,46 +200,8 @@
 ge;%0A
-import org.eclipse.emf.ecore.EObject;%0A
 impo
@@ -249,181 +249,8 @@
 re;%0A
-import org.eclipse.emf.transaction.RecordingCommand;%0Aimport org.eclipse.emf.transaction.TransactionalEditingDomain;%0Aimport org.eclipse.emf.transaction.util.TransactionUtil;%0A
 impo
@@ -308,47 +308,8 @@
 on;%0A
-import org.eclipse.swt.widgets.Button;%0A
 impo
@@ -799,32 +799,8 @@
 %09%0A%09%09
-final Button checkbox = 
 Prop
@@ -818,15 +818,8 @@
 eate
-Unbound
 Chec
@@ -862,888 +862,49 @@
 ion%22
-);%0A%09%09%0A%09%09new IsForCompensationFlagButtonBinding(bo, IS_FOR_COMPENSATION_FEATURE, checkbox).establish();%0A%09%7D%0A%0A%09private class IsForCompensationFlagButtonBinding extends BooleanButtonBinding %7B%0A%0A%09%09public IsForCompensationFlagButtonBinding(EObject model, EStructuralFeature feature, Button control) %7B%0A%09%09%09super(model, feature, control);%0A%09%09%7D%0A%09%09%0A%09%09@Override%0A%09%09public Boolean getModelValue() %7B%0A%09%09%09return (Boolean) bo.eGet(IS_FOR_COMPENSATION_FEATURE);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void setModelValue(final Boolean value) %7B%0A%09%09%09TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(bo);%0A%09%09%09editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) %7B%0A%09%09%09%0A%09%09%09%09@Override%0A%09%09%09%09protected void doExecute() %7B%0A%09%09%09%09%09if (!value) %7B%0A%09%09%09%09%09%09bo.eUnset(IS_FOR_COMPENSATION_FEATURE);%0A%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09bo.eSet(IS_FOR_COMPENSATION_FEATURE, value);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D%0A%09%7D
+, IS_FOR_COMPENSATION_FEATURE, bo);%0A%09%09%0A%09%7D%0A
 %0A%7D%0A

Remove inner class