/*******************************************************************************
 * Copyright (c) 2016, 2017 Artal Technologies and others.
 * 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:
 *     Aurelien Didier (Artal Technologies) - initial API and implementation
 *******************************************************************************/
/**
 * Generated with Acceleo
 */
package org.polarsys.time4sys.ui.views.grm.parts.impl;

// Start of user code for imports
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.eef.runtime.EEFRuntimePlugin;
import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart;
import org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy;
import org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider;
import org.eclipse.emf.eef.runtime.ui.parts.PartComposer;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.BindingCompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionStep;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.ButtonsModeEnum;
import org.eclipse.emf.eef.runtime.ui.widgets.EMFComboViewer;
import org.eclipse.emf.eef.runtime.ui.widgets.EObjectFlatComboViewer;
import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable;
import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener;
import org.eclipse.emf.eef.runtime.ui.widgets.SWTUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.TabElementTreeSelectionDialog;
import org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableContentProvider;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.polarsys.time4sys.ui.views.grm.parts.GeneralPropertiesEditionPart;
import org.polarsys.time4sys.ui.views.grm.parts.GrmViewsRepository;
import org.polarsys.time4sys.ui.views.grm.providers.GrmMessages;

// End of user code

/**
 * 
 * 
 */
public class GeneralPropertiesEditionPartImpl extends CompositePropertiesEditionPart
		implements ISWTPropertiesEditionPart, GeneralPropertiesEditionPart {

	protected Text name;
	protected Button isPeriodic;
	protected Text value;
	protected Text elementSize;
	protected Text resMult;
	protected Text msgSize;
	protected Text packetSize;
	protected Text event;
	protected Text speedFactor;
	protected Button isProtected;
	protected Button isActive;
	protected Text otherProtocol;
	protected EMFComboViewer protocol;
	protected EMFComboViewer transmMode;
	protected EObjectFlatComboViewer start;
	protected EObjectFlatComboViewer set;
	protected EObjectFlatComboViewer get;
	protected EObjectFlatComboViewer reset;
	protected EObjectFlatComboViewer pause;
	protected EObjectFlatComboViewer scheduler;
	protected EObjectFlatComboViewer type;
	protected EObjectFlatComboViewer host;
	protected EObjectFlatComboViewer dependentScheduler;
	protected EObjectFlatComboViewer mainScheduler;
	protected EObjectFlatComboViewer sourcePort;
	protected EObjectFlatComboViewer targetPort;
	protected ReferencesTable usedBy;
	protected List<ViewerFilter> usedByBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> usedByFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable usedResource;
	protected List<ViewerFilter> usedResourceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> usedResourceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable processingUnits;
	protected List<ViewerFilter> processingUnitsBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> processingUnitsFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable workload;
	protected List<ViewerFilter> workloadBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> workloadFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable brokedResource;
	protected List<ViewerFilter> brokedResourceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> brokedResourceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable managedResource;
	protected List<ViewerFilter> managedResourceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> managedResourceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable schedulableResource;
	protected List<ViewerFilter> schedulableResourceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> schedulableResourceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable virtualProcessingUnit;
	protected List<ViewerFilter> virtualProcessingUnitBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> virtualProcessingUnitFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable protectParams;
	protected List<ViewerFilter> protectParamsBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> protectParamsFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable schedParams;
	protected List<ViewerFilter> schedParamsBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> schedParamsFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable requiredAmount;
	protected List<ViewerFilter> requiredAmountBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> requiredAmountFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable ownedElement;
	protected List<ViewerFilter> ownedElementBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> ownedElementFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable ownedPort;
	protected List<ViewerFilter> ownedPortBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> ownedPortFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable ownedConnector;
	protected List<ViewerFilter> ownedConnectorBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> ownedConnectorFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable ownedResource;
	protected List<ViewerFilter> ownedResourceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> ownedResourceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable ownedService;
	protected List<ViewerFilter> ownedServiceBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> ownedServiceFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable usage;
	protected List<ViewerFilter> usageBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> usageFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable accCtrlPolicy;
	protected List<ViewerFilter> accCtrlPolicyBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> accCtrlPolicyFilters = new ArrayList<ViewerFilter>();
	protected ReferencesTable resCtrlPolicy;
	protected List<ViewerFilter> resCtrlPolicyBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> resCtrlPolicyFilters = new ArrayList<ViewerFilter>();

	/**
	 * Default constructor
	 * 
	 * @param editionComponent
	 *            the {@link IPropertiesEditionComponent} that manage this part
	 * 
	 */
	public GeneralPropertiesEditionPartImpl(IPropertiesEditionComponent editionComponent) {
		super(editionComponent);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
	 *      createFigure(org.eclipse.swt.widgets.Composite)
	 * 
	 */
	public Composite createFigure(final Composite parent) {
		view = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		view.setLayout(layout);
		createControls(view);
		return view;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
	 *      createControls(org.eclipse.swt.widgets.Composite)
	 * 
	 */
	public void createControls(Composite view) {
		CompositionSequence generalStep = new BindingCompositionSequence(propertiesEditionComponent);
		CompositionStep propertiesStep = generalStep.addStep(GrmViewsRepository.General.Properties.class);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.name);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.isPeriodic);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.value);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.elementSize);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.resMult);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.msgSize);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.packetSize);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.event);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.speedFactor);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.isProtected);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.isActive);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.otherProtocol);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.protocol);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.transmMode);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.start);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.set);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.get);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.reset);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.pause);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.scheduler);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.type);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.host);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.dependentScheduler);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.mainScheduler);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.sourcePort);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.targetPort);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.usedBy);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.usedResource);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.processingUnits);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.workload);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.brokedResource);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.managedResource);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.schedulableResource);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.virtualProcessingUnit);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.protectParams);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.schedParams);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.requiredAmount);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.ownedElement);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.ownedPort);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.ownedConnector);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.ownedResource);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.ownedService);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.usage);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.accCtrlPolicy);
		propertiesStep.addStep(GrmViewsRepository.General.Properties.resCtrlPolicy);

		composer = new PartComposer(generalStep) {

			@Override
			public Composite addToPart(Composite parent, Object key) {
				if (key == GrmViewsRepository.General.Properties.class) {
					return createPropertiesGroup(parent);
				}
				if (key == GrmViewsRepository.General.Properties.name) {
					return createNameText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.isPeriodic) {
					return createIsPeriodicCheckbox(parent);
				}
				if (key == GrmViewsRepository.General.Properties.value) {
					return createValueText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.elementSize) {
					return createElementSizeText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.resMult) {
					return createResMultText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.msgSize) {
					return createMsgSizeText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.packetSize) {
					return createPacketSizeText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.event) {
					return createEventText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.speedFactor) {
					return createSpeedFactorText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.isProtected) {
					return createIsProtectedCheckbox(parent);
				}
				if (key == GrmViewsRepository.General.Properties.isActive) {
					return createIsActiveCheckbox(parent);
				}
				if (key == GrmViewsRepository.General.Properties.otherProtocol) {
					return createOtherProtocolText(parent);
				}
				if (key == GrmViewsRepository.General.Properties.protocol) {
					return createProtocolEMFComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.transmMode) {
					return createTransmModeEMFComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.start) {
					return createStartFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.set) {
					return createSetFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.get) {
					return createGetFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.reset) {
					return createResetFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.pause) {
					return createPauseFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.scheduler) {
					return createSchedulerFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties.type) {
					return createTypeFlatComboViewer(parent);
				}
				if (key == GrmViewsRepository.General.Properties