public class CompositionModel {
	private String id;
	private String compositionPath;

	private PropertyChangeSupport changes;

	public CompositionModel() {
		changes = new PropertyChangeSupport(this);
		id = "" + UUID.randomUUID();
	}

	public String getID() {
		return this.id;
	}

	public void setID(String id) {
		this.id = id;
	}

	public void setCompositionPath(String path) {
		changes.firePropertyChange(Constants.COMPOSITION_MODEL_PATH, this.compositionPath, this.compositionPath = path);
	}

	public String getCompositionPath() {
		return this.compositionPath;
	}
	
	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}
} public class LaunchConfigurationModel {

	private PropertyChangeSupport changes;

	private String appPath;
	private String platform;
	private String id;
	private String clientController;

	private String appName;
	private String appPort;
	private boolean running;
	private String name;
	private String flagBackend;
	private String flagApp;

	public LaunchConfigurationModel() {
		changes = new PropertyChangeSupport(this);
	}

	public void setRunning(boolean newRunning) {
		changes.firePropertyChange(Constants.APP_RUNNING_MODEL, running, this.running = newRunning);
	}

	public boolean getRunning() {
		return this.running;
	}

	public String getName(){
		return this.name;
	}
	
	public void setName(String name){
		changes.firePropertyChange(Constants.LaunchName, this.name, this.name = name);
	}
	
	public String getPlatform() {
		return this.platform;
	}
	
	public String getFlagBackend() {
		return this.flagBackend;
	}

	public void setFlagBackend(String flagBackend){
		changes.firePropertyChange(Constants.FLAG_BACKEND, this.flagBackend, this.flagBackend = flagBackend);
	}

	public void setPlatform(String platform) {
		changes.firePropertyChange(Constants.PLATFORM_MODEL, this.platform, this.platform = platform);
	}

	public String getAppPort() {
		return this.appPort;
	}

	public void setAppPort(String appPort) {
		changes.firePropertyChange(Constants.PORT_MODEL, this.appPort, this.appPort = appPort);
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String name) {
		changes.firePropertyChange(Constants.APP_NAME_MODEL, this.appName, this.appName = name);
	}

	public void setID(String id) {
		changes.firePropertyChange(Constants.ID_MODEL, this.id, this.id = id);
	}

	public String getID() {
		return this.id;
	}

	public String getAppPath() {
		return appPath;
	}

	public void setAppPath(String appPath) {
		changes.firePropertyChange(Constants.APP_PATH_MODEL, this.appPath, this.appPath = appPath);
	}

	public String getClientController() {
		if (clientController == null)
			clientController = "";
		return clientController;
	}

	public void setClientController(String clientController) {
		changes.firePropertyChange(Constants.CLIENT_CONTROLLER_MODEL, this.clientController,
				this.clientController = clientController);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LaunchConfigurationModel other = (LaunchConfigurationModel) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		// TODO: parse to xml format here
		return "Configuration [id=" + id + ", for App =" + appPath + "]";
	}

	public LaunchConfigurationModel copy() {
		// TODO: add all setter
		return new LaunchConfigurationModel();
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}

	public String getFlagApp() {
		return flagApp;
	}

	public void setFlagApp(String flagApp) {
		changes.firePropertyChange(Constants.FLAG_APP, this.flagApp,
				this.flagApp = flagApp);
	}

} public class ShimModel {
	private String id;
	private String shim;

	private String port;

	private PropertyChangeSupport changes;

	public ShimModel() {
		changes = new PropertyChangeSupport(this);
		id = "" + UUID.randomUUID();
	}

	public String getID() {
		return this.id;
	}

	public void setID(String id) {
		this.id = id;
	}

	public void setPort(String port) {
		changes.firePropertyChange(Constants.SHIM_PORT, this.port, this.port = port);
	}

	public String getPort() {
		return this.port;
	}

	public void setShim(String shim) {
		changes.firePropertyChange(Constants.COMPOSITION_MODEL_PATH, this.shim, this.shim = shim);
	}

	public String getShim() {
		return this.shim;
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}
} public class SshProfileModel {

	private String host;
	private String port;
	private String sshIdFile;
	private String username;
	private String profileName;
	private String secondPort;
	private String secondHost;
	private String secondUsername;

	private String odl;
	private String engine;
	private String core;
	private String topology;
	private String tools;
	private String appFolder;
	private String composite;

	private String appSource;
	private String appTarget;
	private String minConfigSource;
	private String minConfigTarget;

	private String id;

	private PropertyChangeSupport changes;

	public SshProfileModel() {
		changes = new PropertyChangeSupport(this);
		this.id = "" + UUID.randomUUID();
	}

	public boolean getIsDoubleTunnel() {
		return (!getSecondHost().equals("") && !getSecondPort().equals("") && !getSecondUsername().equals(""));
	}

	public String getID() {
		return this.id;
	}

	public void setSecondUsername(String username) {
		this.changes.firePropertyChange(Constants.SECOND_USERNAME, this.secondUsername, this.secondUsername = username);
	}

	public String getSecondUsername() {
		return this.secondUsername;
	}

	public void setSecondHost(String host) {
		this.changes.firePropertyChange(Constants.SECOND_HOST, this.secondHost, this.secondHost = host);
	}

	public String getSecondHost() {
		return this.secondHost;
	}

	public void setSecondPort(String port) {
		this.changes.firePropertyChange(Constants.SECOND_PORT, this.secondPort, this.secondPort = port);
	}

	public String getSecondPort() {
		return this.secondPort;
	}

	public void setHost(String host) {
		this.changes.firePropertyChange(Constants.HOST_MODEL, this.host, this.host = host);
	}

	public void setPort(String port) {
		this.changes.firePropertyChange(Constants.SSH_PORT_MODEL, this.port, this.port = port);
	}

	public void setSshIdFile(String sshIdFile) {
		this.changes.firePropertyChange(Constants.SSH_ID_FILE_MODEL, this.sshIdFile, this.sshIdFile = sshIdFile);
	}

	public void setUsername(String username) {
		this.changes.firePropertyChange(Constants.USERNAME_MODEL, this.username, this.username = username);
	}

	public void setProfileName(String profileName) {
		this.changes.firePropertyChange(Constants.PROFILE_NAME_MODEL, this.profileName, this.profileName = profileName);
	}

	public String getOdl() {
		return odl;
	}

	public void setOdl(String odl) {
		this.changes.firePropertyChange(Constants.ODL_SHIM, this.odl, this.odl = odl);
	}

	public String getEngine() {
		return engine;
	}

	public void setEngine(String engine) {
		this.changes.firePropertyChange(Constants.ENGINE, this.engine, this.engine = engine);
	}

	public String getCore() {
		return core;
	}

	public void setCore(String core) {
		this.changes.firePropertyChange(Constants.CORE, this.core, this.core = core);
	}

	public String getTopology() {
		return topology;
	}

	public void setTopology(String topology) {
		this.changes.firePropertyChange(Constants.TOPOLOGY, this.topology, this.topology = topology);
	}

	public String getTools() {
		return tools;
	}

	public void setTools(String tools) {
		this.changes.firePropertyChange(Constants.TOOLS, this.tools, this.tools = tools);
	}

	public String getAppFolder() {
		return appFolder;
	}

	public void setAppFolder(String appFolder) {
		this.changes.firePropertyChange(Constants.APP_FOLDER, this.appFolder, this.appFolder = appFolder);
	}

	public String getComposite() {
		return composite;
	}

	public void setComposite(String composite) {
		this.changes.firePropertyChange(Constants.COMPOSITE_FILE, this.composite, this.composite = composite);
	}

	public String getHost() {
		return this.host;
	}

	public String getPort() {
		return this.port;
	}

	public String getSshIdFile() {

		return this.sshIdFile;
	}

	public String getUsername() {
		return this.username;
	}

	public String getProfileName() {
		return this.profileName;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SshProfileModel other = (SshProfileModel) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		// TODO: parse to xml format here
		return "Configuration [id=" + id + ", for App =" + "" + "]";
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}

	public String getAppSource() {
		return appSource;
	}

	public void setAppSource(String appSource) {
		this.changes.firePropertyChange(Constants.APP_SOURCE, this.appSource, this.appSource = appSource);
	}

	public String getAppTarget() {
		return appTarget;
	}

	public void setAppTarget(String appTarget) {
		this.changes.firePropertyChange(Constants.APP_TARGET, this.appTarget, this.appTarget = appTarget);
	}

	public String getMinConfigSource() {
		return minConfigSource;
	}

	public void setMinConfigSource(String minConfigSource) {
		this.changes.firePropertyChange(Constants.MIN_CONFIG_SOURCE, this.minConfigSource,
				this.minConfigSource = minConfigSource);
	}

	public String getMinConfigTarget() {
		return minConfigTarget;
	}

	public void setMinConfigTarget(String minConfigTarget) {
		this.changes.firePropertyChange(Constants.MIN_CONFIG_TARGET, this.minConfigTarget,
				this.minConfigTarget = minConfigTarget);
	}

} public class TopologyModel {
	private String id;
	private String topologyPath;

	private PropertyChangeSupport changes;

	public TopologyModel() {
		changes = new PropertyChangeSupport(this);
		id = "" + UUID.randomUUID();
	}

	public String getID() {
		return this.id;
	}

	public void setID(String id) {
		this.id = id;
	}

	public void setTopologyPath(String path) {
		changes.firePropertyChange(Constants.TOPOLOGY_MODEL_PATH, this.topologyPath, this.topologyPath = path);
	}

	public String getTopologyPath() {
		return this.topologyPath;
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}
} public class UiStatusModel {

	private Boolean vagrantRunning;
	private Boolean mininetRunning;
	private Boolean debuggerRunning;
	private Boolean sshRunning;
	private Boolean serverControllerRunning;
	private Boolean coreRunning;

	private int sshComboSelectionIndex;
	private int launchTableIndex;
	private int compositionSelectionIndex;

	private String serverControllerSelection;
	private CompositionModel compositionModel;
	private TopologyModel topologyModel;
	private ShimModel shimModel;



	private WritableList profileWritableList;
	private WritableList modelWritableList;
	private WritableList compositionWritableList;
	

	// list corresponding to doc
	private ArrayList<LaunchConfigurationModel> modelList;
	// list corresponding to doc
	private ArrayList<SshProfileModel> profileList;

	// private ArrayList<CompositionModel> compositionList;

	private PropertyChangeSupport changes;

	public UiStatusModel() {
		this.changes = new PropertyChangeSupport(this);
		this.modelList = new ArrayList<LaunchConfigurationModel>();
		this.profileList = new ArrayList<SshProfileModel>();
		this.topologyModel = new TopologyModel();
		this.compositionModel = new CompositionModel();
		this.shimModel = new ShimModel();

		this.setMininetRunning(new Boolean(false));
		this.setServerControllerRunning(new Boolean(false));
		this.setSshRunning(new Boolean(false));
		this.setVagrantRunning(new Boolean(false));
		this.setCoreRunning(false);
		this.setDebuggerRunning(false);
	}

	// public CompositionModel getCompositionAtSelectedIndex() {
	// return this.compositionList.get(this.compositionSelectionIndex);
	// }
	//
	// public void addCompositionToList(CompositionModel m) {
	// compositionWritableList.add(m);
	// }

	public void setCompositionSelectionIndex(int index) {
		changes.firePropertyChange(Constants.COMPOSITION_SELECTION_INDEX, this.compositionSelectionIndex,
				this.compositionSelectionIndex = index);
	}

	public int getCompositionSelectionIndex() {
		return this.compositionSelectionIndex;
	}

	public void setCoreRunning(boolean running) {
		changes.firePropertyChange(Constants.CORE_RUNNING_MODEL, this.coreRunning, this.coreRunning = running);
	}

	public boolean getCoreRunning() {
		return this.coreRunning;
	}

	public void setWritableCompositionList(WritableList input) {
		this.compositionWritableList = input;
	}

	public WritableList getWritableCompositionList() {
		return this.compositionWritableList;
	}

	// public void setCompositionList(ArrayList<CompositionModel> compoList) {
	// this.compositionList = compoList;
	// }
	//
	// public ArrayList<CompositionModel> getCompositionList() {
	// return this.compositionList;
	// }

	public void setWritableModelList(WritableList input) {
		this.modelWritableList = input;
	}

	public WritableList getWritableModelList() {
		return this.modelWritableList;
	}

	public void setWritableProfileList(WritableList input) {
		this.profileWritableList = input;
	}

	public WritableList getWritableProfileList() {
		return this.profileWritableList;
	}

	public int getLaunchTableIndex() {
		return this.launchTableIndex;
	}

	public void setServerControllerSelection(String serverControllerSelection) {
		changes.firePropertyChange(Constants.SERVER_CONTROLLER_SELECTION, this.serverControllerSelection,
				this.serverControllerSelection = serverControllerSelection);
	}

	public String getServerControllerSelection() {
		return this.serverControllerSelection;
	}

	public void setLaunchTableIndex(int launchTableIndex) {
		changes.firePropertyChange(Constants.LAUNCH_TABLE_INDEX, this.launchTableIndex,
				this.launchTableIndex = launchTableIndex);
	}

	public Boolean getVagrantRunning() {
		return vagrantRunning;
	}

	public int getSshComboSelectionIndex() {
		return this.sshComboSelectionIndex;
	}

	public void setSshComboSelectionIndex(int sshComboSelectionIndex) {
		changes.firePropertyChange(Constants.SSH_COMBO_SELECTION_INDEX, this.sshComboSelectionIndex,
				this.sshComboSelectionIndex = sshComboSelectionIndex);
	}

	public void setVagrantRunning(Boolean vagrantRunning) {
		changes.firePropertyChange(Constants.VAGRANT_RUNNING_MODEL, this.vagrantRunning,
				this.vagrantRunning = vagrantRunning);
	}

	public Boolean getMininetRunning() {
		return mininetRunning;
	}

	public void setMininetRunning(Boolean mininetRunning) {
		changes.firePropertyChange(Constants.MININET_RUNNING_MODEL, this.mininetRunning,
				this.mininetRunning = mininetRunning);
	}

	public Boolean getSshRunning() {
		return sshRunning;
	}

	public void setSshRunning(Boolean sshRunning) {
		changes.firePropertyChange(Constants.SSH_RUNNING_MODEL, this.sshRunning, this.sshRunning = sshRunning);
	}

	public Boolean getServerControllerRunning() {
		return serverControllerRunning;
	}

	public void setServerControllerRunning(Boolean serverControllerRunning) {
		changes.firePropertyChange(Constants.SERVER_CONTROLLER_RUNNING_MODEL, this.serverControllerRunning,
				this.serverControllerRunning = serverControllerRunning);
	}

	public Boolean getDebuggerRunning() {
		return debuggerRunning;
	}

	public void setDebuggerRunning(Boolean debuggerRunning) {
		changes.firePropertyChange(Constants.DEBUGGER_RUNNING_MODEL, this.debuggerRunning,
				this.debuggerRunning = debuggerRunning);
	}

	public void setCompositionModel(CompositionModel model) {
		changes.firePropertyChange(Constants.COMPOSITION_MODEL_PATH, this.compositionModel,
				this.compositionModel = model);
	}

	public void setTopologyModel(TopologyModel model) {
		changes.firePropertyChange(Constants.TOPOLOGY_MODEL_PATH, this.topologyModel, this.topologyModel = model);
	}
	
	public void setShimModel(ShimModel model) {
		changes.firePropertyChange(Constants.SERVER_CONTROLLER_SELECTION, this.shimModel, this.shimModel = model);
	}
	

	public TopologyModel getTopologyModel() {
		return this.topologyModel;
	}

	public void addEntryToModelList(LaunchConfigurationModel model) {
		if (this.modelWritableList != null) {
			this.modelWritableList.add(model);
		} else {
			this.modelList.add(model);
		}
	}

	public void addEntryToSSHList(SshProfileModel model) {
		if (this.profileWritableList != null) {
			this.profileWritableList.add(model);
		} else {
			this.profileList.add(model);
		}

	}

	public void removeEntryFromModelList(LaunchConfigurationModel model) {

		if (this.modelWritableList != null) {
			this.modelWritableList.remove(model);
		} else {
			this.modelList.remove(model);
		}
	}

	public void removeEntryFromSSHList(SshProfileModel model) {

		if (this.profileWritableList != null) {
			this.profileWritableList.remove(model);
		} else {
			this.profileList.remove(model);
		}
	}

	public void removeEntryFromSSHList() {

		if (this.profileWritableList != null) {
			this.profileWritableList.remove(sshComboSelectionIndex);
		} else {
			this.profileList.remove(sshComboSelectionIndex);
		}
	}

	public void removeEntryFromModelList() {

		if (this.modelWritableList != null) {
			this.modelWritableList.remove(launchTableIndex);
		} else {
			this.modelList.remove(launchTableIndex);
		}
	}

	public void setModelList(ArrayList<LaunchConfigurationModel> modelList) {
		this.modelList = modelList;
	}

	public void setProfileList(ArrayList<SshProfileModel> profileList) {
		this.profileList = profileList;
	}

	public ArrayList<LaunchConfigurationModel> getModelList() {
		return this.modelList;
	}

	public ArrayList<SshProfileModel> getProfileList() {
		return this.profileList;
	}

	public LaunchConfigurationModel getModelAtIndex(int index) {
		return this.modelList.get(index);
	}

	public LaunchConfigurationModel getModelAtIndex() {
		return this.modelList.get(this.launchTableIndex);
	}

	public SshProfileModel getSshModelAtIndex(int index) {
		return this.profileList.get(index);
	}

	public SshProfileModel getSshModelAtIndex() {
		return this.profileList.get(this.sshComboSelectionIndex);
	}

	public CompositionModel getCompositionModel() {
		return compositionModel;
	}
	
	public ShimModel getShimModel() {
		return shimModel;
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changes.addPropertyChangeListener(l);
	}

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		changes.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changes.removePropertyChangeListener(l);
	}
	

} public class Constants {
	// Launch Configuration Model Constants
	public static final String APP_PATH_MODEL = "appPath";
	public static final String CLIENT_CONTROLLER_MODEL = "clientController";
	public static final String TOPOLOGY_MODEL = "topology";
	public static final String ID_MODEL = "id";
	public static final String PLATFORM_MODEL = "platform";
	public static final String PORT_MODEL = "appPort";
	public static final String APP_NAME_MODEL = "appName";
	public static final String APP_RUNNING_MODEL = "running";
	public static final String LaunchName = "name";
	public static final String FLAG_BACKEND = "flagBackend";
	public static final String FLAG_APP = "flagApp";

	// UI Status Model Constants
	public static final String VAGRANT_RUNNING_MODEL = "vagrantRunning";
	public static final String MININET_RUNNING_MODEL = "mininetRunning";
	public static final String CORE_RUNNING_MODEL = "coreRunning";
	public static final String SSH_RUNNING_MODEL = "sshRunning";
	public static final String SERVER_CONTROLLER_RUNNING_MODEL = "serverControllerRunning";
	public static final String DEBUGGER_RUNNING_MODEL = "debuggerRunning";
	public static final String SSH_COMBO_SELECTION_INDEX = "sshComboSelectionIndex";
	public static final String LAUNCH_TABLE_INDEX = "launchTableIndex";
	public static final String SERVER_CONTROLLER_SELECTION = "serverControllerSelection";
	public static final String COMPOSITION_SELECTION_INDEX = "compositionSelectionIndex";

	public static final String TOPOLOGY_MODEL_PATH = "topologyPath";
	public static final String COMPOSITION = "compositionPath";
	public static final String COMPOSITION_PATH = "compositionPath";
	public static final String ELEMENT_TOPOLOGY_PATH = "topologyPath";

	public static final String COMPOSITION_MODEL_PATH = "compositionPath";
	public static final String SERVER_COMBO_TEXT = "shim";
	
	public static final String SHIM_PORT = "port";

	// SSH Profile Model Constants
	public static final String HOST_MODEL = "host";
	public static final String SSH_PORT_MODEL = "port";
	public static final String SSH_ID_FILE_MODEL = "sshIdFile";
	public static final String USERNAME_MODEL = "username";
	public static final String PROFILE_NAME_MODEL = "profileName";
	public static final String SECOND_PORT = "secondPort";
	public static final String SECOND_USERNAME = "secondUsername";
	public static final String SECOND_HOST = "secondHost";
	
	public static final String APP_FOLDER = "appFolder";
	public static final String COMPOSITE_FILE = "compositeFile";
	public static final String ODL_SHIM = "odlShim";
	public static final String ENGINE = "engine";
	public static final String CORE = "core";
	public static final String VAGRANT_BOX = "vagrantBox";
	public static final String TOOLS = "tools";
	public static final String TOPOLOGY = "topology";
	public static final String APP_SOURCE = "appSource";
	public static final String APP_TARGET = "appTarget";
	public static final String MIN_CONFIG_SOURCE = "minConfigSource";
	public static final String MIN_CONFIG_TARGET = "minConfigTarget";


	// UI Constants
	public static final String LABEL_RUNNING = "running";
	public static final String LABEL_OFFLINE = "offline";

} public class RunningBoolInverter extends Converter{

	public RunningBoolInverter(Object fromType, Object toType) {
		super(fromType, toType);
		// TODO Auto-generated constructor stub
	}

	@Override
	public Object convert(Object fromObject) {
		
		if (fromObject instanceof Boolean) {
			return !(Boolean)fromObject;
		}
		
		return null;
	}

} public class RunningBoolToStringConverter extends Converter {

	public RunningBoolToStringConverter() {
		super(Boolean.class, String.class);
	}

	@Override
	public Object convert(Object fromObject) {
		if (fromObject instanceof Boolean) {
			Boolean bool = (Boolean) fromObject;

			if (bool) {
				return Constants.LABEL_RUNNING;
			} else {
				return Constants.LABEL_OFFLINE;
			}

		}
		return Constants.LABEL_OFFLINE;

	}

} public class RunningStringToBoolConverter extends Converter {

	public RunningStringToBoolConverter() {
		super(null, null);
	}

	@Override
	public Object convert(Object fromObject) {
		if (fromObject instanceof String) {
			String string = (String) fromObject;

			if (string.equalsIgnoreCase(Constants.LABEL_RUNNING)) {
				return new Boolean(true);
			} else if (string.equalsIgnoreCase(Constants.LABEL_OFFLINE)) {
				return new Boolean(false);
			}

		}
		return new Boolean(false);

	}

} public class WbConfigurationEditor extends EditorPart implements IJobChangeListener {

	public static final String ID = "workbenchconfigurationeditor.editors.WbConfigurationEditor"; //$NON-NLS-1$
	private WbConfigurationEditor instanceWb = this;
	private WorkbenchConfigurationEditorEngine engine;

	private IFile file;

	private boolean isDirty;

	private ConfigurationShell tempShell;
	private LaunchConfigurationModel tmpModel;
	private ControllerManager controllerManager;

	public WbConfigurationEditor() {
		try {
			ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		this.isDirty = false;
		IFileEditorInput fileInput = (IFileEditorInput) input;
		file = fileInput.getFile();
		setSite(site);
		setInput(input);

		setPartName(file.getName());

	}

	public IFile getFile() {
		return this.file;
	}

	/**
	 * Create contents of the editor part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		createLayout(parent);
		engine = new WorkbenchConfigurationEditorEngine(this);
		controllerManager = new ControllerManager(engine.getStatusModel(), getFile());
		addButtonListener();
		if (sshProfileCombo.getSelectionIndex() != -1) {
			// lblSShStatus.setText("Status: waiting");
			checkSwitch();

			SshProfileModel model = engine.getStatusModel().getSshModelAtIndex();

			if (model != null) {
				controllerManager.startSSH(engine.getStatusModel().getModelList(), instanceWb, model);
			}
		}

	}

	public void addTopoButtonListener() {

		this.btnLoadTopo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.initTopo();
			}
		});

		this.btnBrowse_topo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String path = null;

				IFile selectedFile = null;
				ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(container.getShell(),
						new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
				dialog.setTitle("Tree Selection");
				dialog.setMessage("Select the elements from the tree:");
				dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
				if (dialog.open() == ElementTreeSelectionDialog.OK) {
					Object[] result = dialog.getResult();
					if (result.length == 1) {
						if (result[0] instanceof IFile) {

							selectedFile = (IFile) result[0];

							path = selectedFile.getFullPath().toString();
							path = "platform:/resource".concat(path);
							TopologyModel m = new TopologyModel();
							m.setTopologyPath(path);

							engine.getStatusModel().getTopologyModel().setTopologyPath(path);

							setIsDirty(true);
						} else {
							showMessage("Please select a Topology.");
						}

					}
				}
			}
		});
	}

	private void addCoreButtonListener() {
		this.startCoreBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.startCore();
			}
		});

		this.stopCoreBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.stopCore();
			}
		});

		this.browseCompositionBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String path = null;

				IFile selectedFile = null;
				ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(container.getShell(),
						new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
				dialog.setTitle("Tree Selection");
				dialog.setMessage("Select the elements from the tree:");
				dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
				if (dialog.open() == ElementTreeSelectionDialog.OK) {
					Object[] result = dialog.getResult();
					if (result.length == 1) {
						if (result[0] instanceof IFile) {

							selectedFile = (IFile) result[0];

							path = selectedFile.getFullPath().toString();
							path = "platform:/resource".concat(path);
							CompositionModel m = new CompositionModel();
							m.setCompositionPath(path);
							engine.getStatusModel().getCompositionModel().setCompositionPath(path);

							setIsDirty(true);
						} else {
							showMessage("Please select a Composition.");
						}

					}
				}
			}
		});

		this.loadCompositionBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.loadComposition();
			}
		});
	}

	private void addMininetButtonListener() {
		btnMininetOn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.startMininet();
			}
		});

		btnMininetOff.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.stopMininet();
			}
		});
	}

	private void addVagrantButtonListener() {

		btnInitVagrantFile.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				controllerManager.createVagrantFile();
			}
		});

		btnVagrantUp.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.startVagrant(instanceWb);
				checkSwitch();
			}
		});

		btnReattach.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (table.getSelectionCount() > 0)
					controllerManager.reattachStarter();
			}
		});

		btnVagrantHalt.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				engine.getStatusModel().setVagrantRunning(false);
				controllerManager.haltVagrant();
				checkSwitch();
			}
		});
	}

	private void startApp() {
		if ((engine.getStatusModel().getSshRunning() || engine.getStatusModel().getVagrantRunning())) {
			if (table.getSelectionCount() > 0) {
				controllerManager.startApp();
			} else {
				showMessage("Make sure vagrant is running or a ssh connection is established.");
			}
		}
	}

	private void addTestButtonListener() {
		btnRemoveTest.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (table.getSelectionCount() > 0) {
					engine.getStatusModel().removeEntryFromModelList();
					setIsDirty(true);
				} else {
					showMessage("Select a test to remove from the table.");
				}
			}
		});

		btnStopTest.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				if (table.getSelectionCount() > 0) {
					controllerManager.stopStarter();
				}
			}
		});

		startBTN.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				startApp();
			}
		});

		btnAddTest.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				tempShell = new ConfigurationShell(container.getDisplay());
				tempShell.openShell(null);

				tmpModel = tempShell.getModel();
				if (tmpModel != null) {
					boolean complete = true;
					if (tmpModel.getPlatform().equals("") || tmpModel.getAppPath().equals(""))
						complete = false;

					if (complete) {

						engine.getStatusModel().addEntryToModelList(tmpModel);
						setIsDirty(true);
					}
				}

			}

		});

		btnEditTest.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				if (table.getSelectionCount() > 0) {
					LaunchConfigurationModel model = engine.getStatusModel().getModelAtIndex();
					tempShell = new ConfigurationShell(container.getDisplay());
					tempShell.openShell(model);

					model = tempShell.getModel();
					if (model != null) {
						boolean complete = true;
						if (model.getPlatform().equals("") || model.getAppPath().equals(""))
							complete = false;

						if (complete) {

							setIsDirty(true);
						}

					}

				}
			}
		});

		tableViewer.addDoubleClickListener(new IDoubleClickListener() {

			@Override
			public void doubleClick(DoubleClickEvent event) {
				startApp();
			}

		});

		btnProvision_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MessageBox messageBox = new MessageBox(container.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
				messageBox.setMessage("Do you really want to use provision, it will take a long time?");
				messageBox.setText("Provision ");
				int response = messageBox.open();
				if (response == SWT.YES)
					controllerManager.reprovision();
			}
		});
		btnProvision_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MessageBox messageBox = new MessageBox(container.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
				messageBox.setMessage("Do you really want to use provision, it will take a long time?");
				messageBox.setText("Provision ");
				int response = messageBox.open();
				if (response == SWT.YES)
					controllerManager.reprovision();
			}
		});
	}

	private void addSshButtonListener() {

		btnCopyApps.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.copyApps();
			}
		});

		tabFolder.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				checkSwitch();

				if (noSwitch) {
					tabFolder.setSelection(currentPageIndex);
				} else {
					int newIndex = tabFolder.indexOf((TabItem) e.item);
					tabFolder.setSelection(newIndex);
					currentPageIndex = newIndex;
					engine.getStatusModel().setSshRunning(false);
					engine.getStatusModel().setVagrantRunning(false);
				}
			}
		});

		btnStopAll.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.stopSSH();
				checkSwitch();
			}
		});

		btnReloadSSH.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				// controllerManager.stopSSH();
				if (engine.getStatusModel().getSshRunning()) {
					controllerManager.recreateAll();

				} else {
					if (sshProfileCombo.getSelectionIndex() != -1) {
						lblSShStatus.setText("Status: waiting");

						SshProfileModel model = engine.getStatusModel().getSshModelAtIndex();

						if (model != null) {
							controllerManager.startSSH(engine.getStatusModel().getModelList(), instanceWb, model);
						}
					} else {
						showMessage("Please select / create a ssh Profile.");
					}
					checkSwitch();
				}
			}
		});

		btnCreateProfile.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SShShell sshShell = new SShShell(container.getDisplay());
				sshShell.openShell(null);
				SshProfileModel result = sshShell.getResult();
				if (result != null) {

					engine.getStatusModel().addEntryToSSHList(result);

					sshProfileCombo.select(engine.getStatusModel().getProfileList().indexOf(result));
					engine.getStatusModel()
							.setSshComboSelectionIndex(engine.getStatusModel().getProfileList().indexOf(result));

					setIsDirty(true);
				}

			}
		});

		btnEditProfile.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (sshProfileCombo.getSelectionIndex() != -1) {

					SshProfileModel profile = engine.getStatusModel().getSshModelAtIndex();

					if (profile != null) {
						SShShell sshShell = new SShShell(container.getDisplay());
						sshShell.openShell(profile);

						setIsDirty(true);

						if (sshShell.deleteEntry()) {
							engine.getStatusModel().removeEntryFromSSHList(profile);
							sshProfileCombo.clearSelection();
							sshProfileCombo.deselectAll();
						}

					}

				} else {
					showMessage("Please select a profile to edit");
				}
			}
		});
	}

	private void addServerControllerButtonListener() {
		startServerController.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				String selection = engine.getStatusModel().getServerControllerSelection();
				if (!engine.getStatusModel().getServerControllerRunning() && !selection.equals("")) {
					// Create starter for selected server controller
					controllerManager.startServerController(selection,
							engine.getStatusModel().getShimModel().getPort());

					engine.getStatusModel().setServerControllerRunning(true);
				}
			}
		});

		btnStopServerController.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (engine.getStatusModel().getServerControllerRunning()) {
					// Stop starter
					controllerManager.stopServerController();
					engine.getStatusModel().setServerControllerRunning(false);
					selectServerCombo.setEnabled(true);
				}
			}
		});

		btnImportTopology.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.importTopology();
			}
		});

	}

	public void addButtonListener() {
		addMininetButtonListener();
		addVagrantButtonListener();
		addTestButtonListener();
		addSshButtonListener();
		addServerControllerButtonListener();
		addCoreButtonListener();
		addTopoButtonListener();

	}

	private boolean noSwitch = false;

	private void checkSwitch() {

		boolean allControllerStopped = true;
		if (engine.getStatusModel().getCoreRunning() || engine.getStatusModel().getMininetRunning()
				|| engine.getStatusModel().getDebuggerRunning()
				|| engine.getStatusModel().getServerControllerRunning()) {
			allControllerStopped = false;
		} else {
			for (int i = 0; i < engine.getStatusModel().getModelList().size(); i++) {
				if (engine.getStatusModel().getModelAtIndex(i).getRunning()) {
					allControllerStopped = false;
				}
			}

		}
		if (allControllerStopped) {
			noSwitch = false;
			tabFolder.setEnabled(true);
			for (Control c : tabFolder.getTabList()) {
				c.setEnabled(true);

			}
		} else {
			noSwitch = true;
		}
	}

	private int currentPageIndex;

	private void showMessage(String msg) {
		MessageDialog.openInformation(container.getShell(), "NetIDE Workbench View", msg);
	}

	public void createLayout(Composite parent) {

		container = new Composite(parent, SWT.NONE);
		container.setLayout(new FillLayout());

		final ScrolledComposite sc2 = new ScrolledComposite(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc2.setExpandHorizontal(true);
		sc2.setExpandVertical(true);

		final Composite startAppComposite = new Composite(sc2, SWT.BORDER);

		sc2.setContent(startAppComposite);

		GridData gd_startAppComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_startAppComposite.widthHint = 888;
		startAppComposite.setLayoutData(gd_startAppComposite);
		startAppComposite.setLayout(new GridLayout(1, false));

		tabFolder = new TabFolder(startAppComposite, SWT.BORDER);
		GridData gd_tabFolder = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_tabFolder.widthHint = 515;
		tabFolder.setLayoutData(gd_tabFolder);

		sshTabItem = new TabItem(tabFolder, SWT.NONE);
		sshTabItem.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
			}
		});
		sshTabItem.setText("SSH");

		sshComposite = new Composite(tabFolder, SWT.NONE);
		sshTabItem.setControl(sshComposite);
		sshComposite.setLayout(new GridLayout(1, false));

		composite_1 = new Composite(sshComposite, SWT.NONE);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		composite_1.setLayout(new GridLayout(5, false));

		lblSShStatus = new Label(composite_1, SWT.NONE);
		GridData gd_lblSShStatus = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_lblSShStatus.widthHint = 96;
		lblSShStatus.setLayoutData(gd_lblSShStatus);
		lblSShStatus.setText("Status: Offline");

		btnReloadSSH = new Button(composite_1, SWT.NONE);
		btnReloadSSH.setText("Reload");

		btnStopAll = new Button(composite_1, SWT.NONE);

		btnStopAll.setText("Stop All");

		btnProvision_1 = new Button(composite_1, SWT.NONE);
		btnProvision_1.setText("Provision");

		btnCopyApps = new Button(composite_1, SWT.NONE);

		btnCopyApps.setText("Copy Apps ");
		new Label(composite_1, SWT.NONE);
		new Label(composite_1, SWT.NONE);
		new Label(composite_1, SWT.NONE);
		new Label(composite_1, SWT.NONE);

		btnCopyTopology = new Button(composite_1, SWT.NONE);
		btnCopyTopology.setText("Copy Topology");

		btnCopyTopology.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.copyTopology();
			}
		});
		composite = new Composite(sshComposite, SWT.NONE);
		GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_composite.widthHint = 400;
		composite.setLayoutData(gd_composite);
		composite.setLayout(new GridLayout(4, false));

		sshProfileCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
		sshProfileCombo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (sshProfileCombo.getSelectionIndex() != -1) {
					lblSShStatus.setText("Status: waiting");

					SshProfileModel model = engine.getStatusModel().getSshModelAtIndex();

					if (model != null) {
						controllerManager.startSSH(engine.getStatusModel().getModelList(), instanceWb, model);
					}
					checkSwitch();
				}

			}

		});

		GridData gd_sshProfileCombo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_sshProfileCombo.widthHint = 161;
		sshProfileCombo.setLayoutData(gd_sshProfileCombo);
		sshComboViewer = new ComboViewer(sshProfileCombo);

		btnCreateProfile = new Button(composite, SWT.NONE);

		btnCreateProfile.setText("Create Profile");

		btnEditProfile = new Button(composite, SWT.NONE);

		btnEditProfile.setBounds(0, 0, 94, 28);
		btnEditProfile.setText("Edit Profile");
		new Label(composite, SWT.NONE);

		vagrantTabItem = new TabItem(tabFolder, SWT.NONE);
		vagrantTabItem.setText("Vagrant");

		Composite vagrantButtons = new Composite(tabFolder, SWT.NONE);
		vagrantTabItem.setControl(vagrantButtons);
		vagrantButtons.setLayout(new GridLayout(4, false));

		btnInitVagrantFile = new Button(vagrantButtons, SWT.NONE);

		btnInitVagrantFile.setText("Init Vagrant File");
		new Label(vagrantButtons, SWT.NONE);
		new Label(vagrantButtons, SWT.NONE);
		new Label(vagrantButtons, SWT.NONE);

		vagrantStatusLabel = new Label(vagrantButtons, SWT.NONE);
		vagrantStatusLabel.setText("Status: Offline");

		btnVagrantUp = new Button(vagrantButtons, SWT.NONE);

		btnVagrantUp.setText("Up");

		btnVagrantHalt = new Button(vagrantButtons, SWT.NONE);
		btnVagrantHalt.setText("Halt");

		btnProvision_2 = new Button(vagrantButtons, SWT.NONE);
		btnProvision_2.setText("Provision");

		currentPageIndex = tabFolder.getSelectionIndex();

		composite_2 = new Composite(startAppComposite, SWT.NONE);

		GridData gd_composite_2 = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
		gd_composite_2.widthHint = 624;
		gd_composite_2.heightHint = 290;
		composite_2.setLayoutData(gd_composite_2);
		composite_2.setLayout(new GridLayout(2, false));

		composite_3 = new Composite(composite_2, SWT.NONE);
		GridData gd_composite_3 = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_composite_3.widthHint = 300;
		gd_composite_3.heightHint = 155;
		composite_3.setLayoutData(gd_composite_3);
		composite_3.setLayout(new GridLayout(1, false));

		grpCore = new Group(composite_3, SWT.BORDER);

		grpCore.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		grpCore.setText("Core");
		grpCore.setLayout(new GridLayout(5, false));

		lblCoreStatus = new Label(grpCore, SWT.NONE);
		GridData gd_lblCoreStatus = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_lblCoreStatus.widthHint = 97;
		lblCoreStatus.setLayoutData(gd_lblCoreStatus);
		lblCoreStatus.setText("Status : Offline");

		startCoreBtn = new Button(grpCore, SWT.NONE);
		startCoreBtn.setText("On");

		stopCoreBtn = new Button(grpCore, SWT.NONE);
		stopCoreBtn.setText("Off");

		btnReattachCore = new Button(grpCore, SWT.NONE);
		btnReattachCore.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.reattachCore();
			}
		});
		btnReattachCore.setText("Reattach");
		new Label(grpCore, SWT.NONE);

		grpCompositionLoader = new Group(composite_3, SWT.NONE);
		grpCompositionLoader.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		grpCompositionLoader.setText("Composition Loader");
		grpCompositionLoader.setLayout(new GridLayout(3, false));
		new Label(grpCompositionLoader, SWT.NONE);
		new Label(grpCompositionLoader, SWT.NONE);
		new Label(grpCompositionLoader, SWT.NONE);

		textCompositionPath = new Text(grpCompositionLoader, SWT.BORDER);

		textCompositionPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textCompositionPath.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				setIsDirty(true);
			}

		});

		browseCompositionBtn = new Button(grpCompositionLoader, SWT.NONE);
		browseCompositionBtn.setText("Browse");

		loadCompositionBtn = new Button(grpCompositionLoader, SWT.NONE);
		loadCompositionBtn.setText("Load");

		composite_4 = new Composite(composite_2, SWT.NONE);
		composite_4.setLayout(new GridLayout(1, false));
		GridData gd_composite_4 = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_composite_4.widthHint = 321;
		composite_4.setLayoutData(gd_composite_4);

		grpServerController = new Group(composite_4, SWT.NONE);
		grpServerController.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		grpServerController.setLayout(new GridLayout(5, false));
		grpServerController.setText("Shim");

		lblServerControllerStatus = new Label(grpServerController, SWT.NONE);
		GridData gd_lblServerControllerStatus = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_lblServerControllerStatus.widthHint = 56;
		lblServerControllerStatus.setLayoutData(gd_lblServerControllerStatus);
		lblServerControllerStatus.setText(Constants.LABEL_OFFLINE);

		selectServerCombo = new Combo(grpServerController, SWT.BORDER | SWT.READ_ONLY);
		selectServerCombo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setIsDirty(true);
			}
		});
		GridData gd_selectServerCombo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_selectServerCombo.widthHint = 123;
		selectServerCombo.setLayoutData(gd_selectServerCombo);
		selectServerCombo.add(NetIDE.CONTROLLER_POX);
		selectServerCombo.add(NetIDE.CONTROLLER_ODL);
		selectServerCombo.add(NetIDE.CONTROLLER_RYU);
		selectServerCombo.add(NetIDE.CONTROLLER_RYU_REST);

		serverComboViewer = new ComboViewer(selectServerCombo);

		startServerController = new Button(grpServerController, SWT.BORDER);

		startServerController.setText("On");

		btnStopServerController = new Button(grpServerController, SWT.NONE);
		btnStopServerController.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

		btnStopServerController.setText("Off");

		btnReattachServer = new Button(grpServerController, SWT.NONE);
		btnReattachServer.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.reattachServerController();
			}
		});
		btnReattachServer.setText("Reattach");

		lblPort = new Label(grpServerController, SWT.NONE);
		lblPort.setText("Port");

		shimPortText = new Text(grpServerController, SWT.BORDER);
		GridData gd_text_shim_port = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
		gd_text_shim_port.widthHint = 32;
		shimPortText.setLayoutData(gd_text_shim_port);
		shimPortText.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				setIsDirty(true);
			}

		});

		btnImportTopology = new Button(grpServerController, SWT.NONE);
		btnImportTopology.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));

		btnImportTopology.setText("Import Topology");

		grpMininet = new Group(composite_4, SWT.NONE);
		grpMininet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		grpMininet.setText("Mininet");
		grpMininet.setLayout(new GridLayout(4, false));

		mininetStatusLable = new Label(grpMininet, SWT.NONE);
		GridData gd_mininetStatusLable = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_mininetStatusLable.widthHint = 99;
		mininetStatusLable.setLayoutData(gd_mininetStatusLable);
		mininetStatusLable.setText("Status: Offline");

		btnMininetOn = new Button(grpMininet, SWT.NONE);
		btnMininetOn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));

		btnMininetOn.setText("On");

		btnMininetOff = new Button(grpMininet, SWT.NONE);

		btnMininetOff.setText("Off");

		btnReattachMininet = new Button(grpMininet, SWT.NONE);
		btnReattachMininet.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.reattachMininet();
			}
		});
		btnReattachMininet.setText("Reattach");

		grpDebugger = new Group(composite_2, SWT.NONE);
		GridData gd_grpDebugger = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2);
		gd_grpDebugger.heightHint = 112;
		grpDebugger.setLayoutData(gd_grpDebugger);
		grpDebugger.setText("Debugger");
		grpDebugger.setLayout(new GridLayout(4, false));

		lblDebuggerStatus = new Label(grpDebugger, SWT.NONE);
		GridData gd_lblDebuggerStatus = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_lblDebuggerStatus.widthHint = 99;
		lblDebuggerStatus.setLayoutData(gd_lblDebuggerStatus);
		lblDebuggerStatus.setText("Status: Offline");

		btnDebuggerOn = new Button(grpDebugger, SWT.NONE);
		btnDebuggerOn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.startDebugger();
			}
		});
		btnDebuggerOn.setText("On");

		btnDebuggerOff = new Button(grpDebugger, SWT.NONE);
		btnDebuggerOff.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.stopDebugger();
			}
		});
		btnDebuggerOff.setText("Off");

		btnDebuggerReattach = new Button(grpDebugger, SWT.NONE);
		btnDebuggerReattach.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controllerManager.reattachDebugger();
			}
		});
		btnDebuggerReattach.setText("Reattach");

		btnToolView = new Button(grpDebugger, SWT.NONE);
		btnToolView.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.showView("eu.netide.toolpanel.views.Toolpanel");
					if (view instanceof ToolPanel) {
						ToolPanel toolPanel = (ToolPanel) view;
						toolPanel.setBackend(controllerManager.getBackend());
						toolPanel.setFile(file);
						String toolpath = null;
						// if
						// (engine.getStatusModel().getSshModelAtIndex().getTools())
						toolPanel.setSshModel(engine.getStatusModel()
								.getSshModelAtIndex(engine.getStatusModel().getSshComboSelectionIndex()).getTools());
					}
				} catch (PartInitException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnToolView.setText("Show Runtime Tools");
		new Label(grpDebugger, SWT.NONE);
		new Label(grpDebugger, SWT.NONE);
		new Label(grpDebugger, SWT.NONE);

		btnShowReplayView = new Button(grpDebugger, SWT.NONE);
		btnShowReplayView.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.showView("eu.netide.toolpanel.views.ReplayPanel");
					if (view instanceof ReplayPanel) {
						ReplayPanel replayPanel = (ReplayPanel) view;
						replayPanel.setFile(file);
						String toolpath = null;
						// if
						// (engine.getStatusModel().getSshModelAtIndex().getTools())
					}
				} catch (PartInitException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnShowReplayView.setText("Show Replay View");
		new Label(grpDebugger, SWT.NONE);
		new Label(grpDebugger, SWT.NONE);
		new Label(grpDebugger, SWT.NONE);

		grpTopology = new Group(composite_2, SWT.NONE);
		grpTopology.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		grpTopology.setText("Topology ");
		grpTopology.setLayout(new GridLayout(3, false));

		topo_text = new Text(grpTopology, SWT.BORDER);
		topo_text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		topo_text.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				setIsDirty(true);
			}

		});

		btnBrowse_topo = new Button(grpTopology, SWT.NONE);
		btnBrowse_topo.setText("Browse");

		btnLoadTopo = new Button(grpTopology, SWT.NONE);
		btnLoadTopo.setText("Generate");
		new Label(composite_2, SWT.NONE);

		grpConfigurationOverview = new Group(startAppComposite, SWT.NONE);
		grpConfigurationOverview.setLayout(new GridLayout(2, false));
		grpConfigurationOverview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		grpConfigurationOverview.setText("Apps");

		tableViewer = new TableViewer(grpConfigurationOverview,
				SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

		table = tableViewer.getTable();
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

		TableColumn tc0 = new TableColumn(table, SWT.CENTER);
		TableColumn tc1 = new TableColumn(table, SWT.CENTER);
		TableColumn tc2 = new TableColumn(table, SWT.CENTER);
		TableColumn tc3 = new TableColumn(table, SWT.CENTER);
		TableColumn tc4 = new TableColumn(table, SWT.CENTER);
		TableColumn tc5 = new TableColumn(table, SWT.CENTER);
		TableColumn tc6 = new TableColumn(table, SWT.CENTER);
		TableColumn tc7 = new TableColumn(table, SWT.CENTER);

		tc0.setText("Name");
		tc1.setText("App Name");
		tc2.setText("Active");
		tc3.setText("Platform");
		tc4.setText("Client");
		tc5.setText("Port");
		tc6.setText("Flag Backend");
		tc7.setText("Flag App");
		tc0.setWidth(100);
		tc1.setWidth(120);
		tc2.setWidth(80);
		tc3.setWidth(100);
		tc4.setWidth(100);
		tc5.setWidth(100);
		tc6.setWidth(120);
		tc7.setWidth(100);

		table.setHeaderVisible(true);
		table.setLinesVisible(true);

		Composite buttonComposite = new Composite(grpConfigurationOverview, SWT.NONE);
		buttonComposite.setLayout(new GridLayout(1, false));

		startBTN = new Button(buttonComposite, SWT.NONE);
		startBTN.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));

		startBTN.setText("Start");

		btnStopTest = new Button(buttonComposite, SWT.NONE);
		btnStopTest.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		btnStopTest.setText("Stop");

		btnReload = new Button(buttonComposite, SWT.NONE);
		btnReload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		btnReload.setText("Reload");

		btnReattach = new Button(buttonComposite, SWT.NONE);
		btnReattach.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		btnReattach.setText("Reattach");

		testButtons = new Composite(grpConfigurationOverview, SWT.NONE);
		testButtons.setLayout(new GridLayout(3, false));

		btnAddTest = new Button(testButtons, SWT.NONE);
		btnAddTest.setText("Add");

		btnRemoveTest = new Button(testButtons, SWT.NONE);
		btnRemoveTest.setText("Remove");

		btnEditTest = new Button(testButtons, SWT.NONE);
		btnEditTest.setText("Edit");
		new Label(grpConfigurationOverview, SWT.NONE);

		sc2.addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent e) {
				sc2.setMinSize(startAppComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
			}
		});

	}

	@Override
	public void setFocus() {
		// Set the focus
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// do saving
		engine.saveAllChanges();
		setIsDirty(false);

	}

	@Override
	public void doSaveAs() {
		// Do the Save As operation
	}

	@Override
	public boolean isDirty() {
		return this.isDirty;
	}

	private void setIsDirty(boolean dirty) {
		if (dirty != this.isDirty) {
			this.isDirty = dirty;
			this.firePropertyChange(PROP_DIRTY);
		}
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	@Override
	public void aboutToRun(IJobChangeEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void awake(IJobChangeEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void done(IJobChangeEvent event) {
		if (event.getJob().getName().equals("VagrantManager")) {
			Display.getDefault().syncExec(new Runnable() {
				public void run() {
					engine.getStatusModel().setVagrantRunning(true);
				}
			});
		} else if (event.getJob().getName().equals("SshManager")) {
			Display.getDefault().syncExec(new Runnable() {

				public void run() {
					engine.getStatusModel().setSshRunning(true);
				}

			});
		}

	}

	@Override
	public void running(IJobChangeEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void scheduled(IJobChangeEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void sleeping(IJobChangeEvent event) {
		// TODO Auto-generated method stub

	}

	private Composite testButtons;
	private Label lblServerControllerStatus;
	private Button btnStopServerController;
	private Button btnVagrantUp;
	private Button btnMininetOff;
	private Label vagrantStatusLabel;
	private Label mininetStatusLable;
	private Composite sshComposite;
	private Button startBTN;
	private Button btnVagrantHalt;
	private Button btnReload;
	private Button btnReattach;
	private Button btnAddTest;
	private Button btnRemoveTest;
	private Button btnStopTest;
	private Button btnEditProfile;
	private Combo selectServerCombo;
	private Button startServerController;
	private Button btnMininetOn;
	private Button btnReloadSSH;
	private Composite container;
	private Table table;
	private Label lblSShStatus;
	private TabFolder tabFolder;
	private TabItem vagrantTabItem;
	private TabItem sshTabItem;
	private Button btnCreateProfile;
	private Composite composite;
	private Combo sshProfileCombo;
	private Button btnEditTest;
	private Composite composite_1;
	private Button btnProvision_1;
	private Button btnProvision_2;
	private TableViewer tableViewer;
	private ComboViewer sshComboViewer;
	private ComboViewer serverComboViewer;
	private Button browseCompositionBtn;
	private Button loadCompositionBtn;
	private Label lblCoreStatus;
	private Button startCoreBtn;
	private Button stopCoreBtn;
	private Group grpMininet;
	private Group grpCore;
	private Group grpServerController;
	private Composite composite_2;
	private Composite composite_3;
	private Composite composite_4;
	private Group grpCompositionLoader;
	private Group grpConfigurationOverview;
	private Button btnInitVagrantFile;
	private Button btnCopyApps;
	private Button btnImportTopology;
	private Text textCompositionPath;
	private Button btnReattachCore;
	private Button btnReattachServer;
	private Button btnReattachMininet;
	private Group grpDebugger;
	private Button btnDebuggerReattach;
	private Button btnDebuggerOn;
	private Button btnDebuggerOff;
	private Label lblDebuggerStatus;
	private Group grpTopology;
	private Text topo_text;
	private Button btnBrowse_topo;
	private Button btnLoadTopo;
	private Button btnCopyTopology;
	private Button btnStopAll;
	private Button btnToolView;
	private Text shimPortText;
	private Label lblPort;
	private Button btnShowReplayView;

	public Label getCoreStatusLabel() {
		return this.lblCoreStatus;
	}

	public Label getServerControllerLabel() {
		return this.lblServerControllerStatus;
	}

	public Label getSSHStautsLabel() {
		return this.lblSShStatus;
	}

	public Label getVagrantStatusLabel() {
		return vagrantStatusLabel;
	}

	public Label getMininetStatusLable() {
		return mininetStatusLable;
	}

	public TableViewer getTableViewer() {
		return this.tableViewer;
	}

	public ComboViewer getSshComboViewer() {
		return this.sshComboViewer;
	}

	public ComboViewer getServerComboViewer() {
		return this.serverComboViewer;
	}

	public Button getSshReloadButton() {
		return this.btnReloadSSH;
	}

	public Button getBtnVagrantUp() {
		return btnVagrantUp;
	}

	public Button getBtnMininetOff() {
		return btnMininetOff;
	}

	public Button getBtnVagrantHalt() {
		return btnVagrantHalt;
	}

	public Button getBtnMininetOn() {
		return btnMininetOn;
	}

	public Button getStartCoreBtn() {
		return startCoreBtn;
	}

	public Button getStopCoreBtn() {
		return stopCoreBtn;
	}

	public Button getBtnProvision_1() {
		return btnProvision_1;
	}

	public Button getBtnCopyApps() {
		return btnCopyApps;
	}

	public Button getBtnProvision_2() {
		return btnProvision_2;
	}

	public Button getBtnStopServerController() {
		return btnStopServerController;
	}

	public Button getStartServerController() {
		return startServerController;
	}

	public Button getBtnImportTopology() {
		return btnImportTopology;
	}

	public Text getTextCompositionPath() {
		return textCompositionPath;
	}

	public Button getBtnReattachCore() {
		return btnReattachCore;
	}

	public Button getBtnReattachServer() {
		return btnReattachServer;
	}

	public Button getBtnReattachMininet() {
		return btnReattachMininet;
	}

	public Button getBtnDebuggerOn() {
		return btnDebuggerOn;
	}

	public Button getBtnDebuggerOff() {
		return btnDebuggerOff;
	}

	public Button getBtnDebuggerReattach() {
		return btnDebuggerReattach;
	}

	public Button getTopologySSHButton() {
		return btnCopyTopology;
	}

	public Label getLblDebuggerStatus() {
		return lblDebuggerStatus;
	}

	public Text getTopologyText() {
		return this.topo_text;
	}

	public TabFolder getTabFolder() {
		return tabFolder;
	}

	public Combo getSelectServerCombo() {
		return selectServerCombo;
	}

	public Text getShimPortText() {
		return this.shimPortText;
	}
}
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ViewerSupport;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.w3c.dom.Document;
import eu.netide.workbenchconfigurationeditor.model.CompositionModel;
import eu.netide.workbenchconfigurationeditor.model.LaunchConfigurationModel;
import eu.netide.workbenchconfigurationeditor.model.ShimModel;
import eu.netide.workbenchconfigurationeditor.model.SshProfileModel;
import eu.netide.workbenchconfigurationeditor.model.TopologyModel;
import eu.netide.workbenchconfigurationeditor.model.UiStatusModel;
import eu.netide.workbenchconfigurationeditor.util.Constants;
import eu.netide.workbenchconfigurationeditor.util.RunningBoolInverter;
import eu.netide.workbenchconfigurationeditor.util.RunningBoolToStringConverter;
import eu.netide.workbenchconfigurationeditor.util.RunningStringToBoolConverter;
import eu.netide.workbenchconfigurationeditor.view.WbConfigurationEditor;
package eu.netide.workbenchconfigurationeditor.controller;




public class WorkbenchConfigurationEditorEngine {

	private WbConfigurationEditor editor;
	// input object from editor
	private IFile inputFile;
	// xml representation of input file
	private Document doc;
	// representation of the ui status
	private UiStatusModel statusModel;