using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEditor.UIElements; using UnityEngine.UIElements; using Codice.Client.Common.Threading; using PlasticGui; using PlasticGui.WebApi; using PlasticGui.WebApi.Responses; using Unity.PlasticSCM.Editor.UI; using Unity.PlasticSCM.Editor.UI.UIElements; namespace Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome { internal class OrganizationPanel : VisualElement { internal OrganizationPanel( CloudEditionWelcomeWindow parentWindow, IPlasticWebRestApi restApi, string title, List organizations) { mParentWindow = parentWindow; mRestApi = restApi; InitializeLayoutAndStyles(); BuildComponents(title, organizations); EditorWindowFocus.OnApplicationActivated += OnEditorActivated; } internal void Dispose() { EditorWindowFocus.OnApplicationActivated -= OnEditorActivated; mParentWindow.CancelJoinOrganization(); if (mJoinSingleOrganizationButton != null) mJoinSingleOrganizationButton.clicked -= JoinOrganizationButton_clicked; if (mJoinMultipleOrganizationsButton != null) mJoinMultipleOrganizationsButton.clicked -= JoinOrganizationButton_clicked; if (mOpenUnityDashboardButton != null) mOpenUnityDashboardButton.clicked -= OpenUnityDashboardButton_clicked; } void OnEditorActivated() { if (!mReloadOrganizationsNeeded) return; mReloadOrganizationsNeeded = false; mProgressControls.ShowProgress(PlasticLocalization.Name.LoadingOrganizations.GetString()); OrganizationsResponse organizationResponse = null; IThreadWaiter waiter = ThreadWaiter.GetWaiter(); waiter.Execute( /*threadOperationDelegate*/ delegate { organizationResponse = mRestApi.GetCloudServers(); }, /*afterOperationDelegate*/ delegate { mProgressControls.HideProgress(); if (waiter.Exception != null) { mProgressControls.ShowError(PlasticLocalization.Name.UnexpectedError.GetString()); ExceptionsHandler.LogException(typeof(OrganizationPanel).Name, waiter.Exception); return; } if (organizationResponse.Error != null) { mReloadOrganizationsNeeded = true; mProgressControls.ShowError(organizationResponse.Error.Message); return; } ProcessOrganizations(organizationResponse.CloudServers); }); } void ProcessOrganizations(List organizations) { this.Query("noOrganization").Collapse(); this.Query("joinSingleOrganization").Collapse(); this.Query("joinMultipleOrganizations").Collapse(); if (organizations.Count == 0) { mReloadOrganizationsNeeded = true; BuildNoOrganizationSection(); mOpenUnityDashboardButton = this.Q