Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ComobBox with a Treeview for selection of Apsim version. #9549

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 66 additions & 17 deletions ApsimNG/Presenters/RunOnCloudPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using APSIM.Shared.Utilities;
using ApsimNG.Cloud;
using Gtk;
using Models.Core;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -54,8 +54,16 @@ public sealed class RunOnCloudPresenter : IPresenter
/// <summary>The version label.</summary>
private LabelView versionLabel;

/// <summary>The version combobox.</summary>
private DropDownView versionCombobox;
/// <summary>The Treeview for selection of an Apsim version.</summary>
private Gtk.TreeView versionTreeview;

/// <summary>
/// Frame around the version list
/// </summary>
private Gtk.Frame versionFrame;

// ListStore for the TreeView
private ListStore listmodel = new ListStore(typeof(string));

/// <summary>The submit button.</summary>
private ButtonView submitButton;
Expand Down Expand Up @@ -99,7 +107,16 @@ public void Attach(object model, object viewBase, ExplorerPresenter parentPresen
directoryEdit = view.GetControl<EditView>("directoryEdit");
browseButton = view.GetControl<ButtonView>("browseButton");
versionLabel = view.GetControl<LabelView>("versionLabel");
versionCombobox = view.GetControl<DropDownView>("versionCombobox");
versionFrame = view.GetGladeObject<Gtk.Frame>("versionFrame");
versionTreeview = view.GetGladeObject<Gtk.TreeView>("versionTreeview");
versionTreeview.Model = listmodel;
CellRendererText textRender = new Gtk.CellRendererText();
textRender.Editable = false;

TreeViewColumn column0 = new TreeViewColumn("Version", textRender, "text", 0);
versionTreeview.AppendColumn(column0);

column0.Sizing = TreeViewColumnSizing.Autosize;
submitButton = view.GetControl<ButtonView>("submitButton");
statusLabel = view.GetControl<LabelView>("statusLabel");
lowPriorityCheckBox = view.GetControl<CheckBoxView>("lowPriorityCheckBox");
Expand All @@ -121,14 +138,29 @@ public void Attach(object model, object viewBase, ExplorerPresenter parentPresen
SetupWidgets();

if (!string.IsNullOrEmpty(ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMVersion))
versionCombobox.SelectedValue = ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMVersion;
{
string targetVersion = ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMVersion;
TreeIter iter;
if (listmodel.GetIterFirst(out iter))
{
do
{
if ((string)listmodel.GetValue(iter, 0) == targetVersion)
{
versionTreeview.SetCursor(listmodel.GetPath(iter), null, false);
break;
}
}
while (listmodel.IterNext(ref iter));
}
}
else if (!string.IsNullOrEmpty(ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMDirectory))
directoryEdit.Text = ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMDirectory;
else if (!string.IsNullOrEmpty(ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMZipFile))
directoryEdit.Text = ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMZipFile;
lowPriorityCheckBox.Checked = ApsimNG.Cloud.Azure.AzureSettings.Default.LowPriority;

apsimTypeToRunCombobox.Changed += OnVersionComboboxChanged;
apsimTypeToRunCombobox.Changed += OnApsimTypeToRunComboboxChanged;
browseButton.Clicked += OnBrowseButtonClicked;
submitButton.Clicked += OnSubmitJobClicked;
}
Expand All @@ -142,24 +174,39 @@ public void Detach()
ApsimNG.Cloud.Azure.AzureSettings.Default.LowPriority = lowPriorityCheckBox.Checked;

if (apsimTypeToRunCombobox.SelectedValue == "A released version")
ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMVersion = versionCombobox.SelectedValue;
ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMVersion = GetSelectedVersion();
else if (apsimTypeToRunCombobox.SelectedValue == "A directory")
ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMDirectory = directoryEdit.Text;
else
ApsimNG.Cloud.Azure.AzureSettings.Default.APSIMZipFile = directoryEdit.Text;
ApsimNG.Cloud.Azure.AzureSettings.Default.Save();
cancellation.Dispose();
apsimTypeToRunCombobox.Changed -= OnVersionComboboxChanged;
apsimTypeToRunCombobox.Changed -= OnApsimTypeToRunComboboxChanged;
browseButton.Clicked -= OnBrowseButtonClicked;
submitButton.Clicked -= OnSubmitJobClicked;
}

/// <summary>User has changed the selection in the version combobox.</summary>
private void OnVersionComboboxChanged(object sender, EventArgs e)
private void OnApsimTypeToRunComboboxChanged(object sender, EventArgs e)
{
SetupWidgets();
}

private string GetSelectedVersion()
{
TreePath selPath;
TreeViewColumn selCol;
versionTreeview.GetCursor(out selPath, out selCol);
if (selPath == null)
return null;
else
{
TreeIter iter;
listmodel.GetIter(out iter, selPath);
return (string)listmodel.GetValue(iter, 0);
}
}

/// <summary>User has clicked the browse button.</summary>
private void OnBrowseButtonClicked(object sender, EventArgs e)
{
Expand Down Expand Up @@ -210,15 +257,15 @@ public void CancelJobSubmission(object sender, EventArgs args)
private void SetupWidgets()
{
versionLabel.Visible = apsimTypeToRunCombobox.SelectedValue == "A released version";
versionCombobox.Visible = versionLabel.Visible;
versionFrame.Visible = versionLabel.Visible;
directoryLabel.Visible = !versionLabel.Visible;
directoryEdit.Visible = !versionLabel.Visible;
browseButton.Visible = !versionLabel.Visible;

if (versionLabel.Visible)
{
// Populate the version drop down.
if (versionCombobox.Values.Length == 0)
if (listmodel.IterNChildren() == 0)
{
presenter.MainPresenter.ShowWaitCursor(true);
try
Expand All @@ -231,15 +278,16 @@ private void SetupWidgets()
name = name.Remove(50);
return name;
});
versionCombobox.Values = upgradeNames.ToArray();
foreach (string upgradeName in upgradeNames)
listmodel.AppendValues(upgradeName);
}
finally
{
presenter.MainPresenter.ShowWaitCursor(false);
}
}
}

if (apsimTypeToRunCombobox.SelectedValue == "A directory")
directoryLabel.Text = "Directory:";
else
Expand All @@ -250,16 +298,17 @@ private void SetupWidgets()
private async Task SubmitJob(object sender, EventArgs args)
{
string path;
string version;
if (versionCombobox.SelectedValue == null)

string version = GetSelectedVersion();

if (version == null)
{
path = directoryEdit.Text;
version = Path.GetFileName(directoryEdit.Text);
}
else
{
path = await DownloadReleasedVersion();
version = versionCombobox.SelectedValue;
if (path == null)
return;
}
Expand Down Expand Up @@ -336,7 +385,7 @@ private async Task<string> DownloadReleasedVersion()
{
var apsimReleasesPath = Path.Combine(Path.GetTempPath(), "ApsimReleases");
Directory.CreateDirectory(apsimReleasesPath);
var versionNumber = versionCombobox.SelectedValue;
var versionNumber = GetSelectedVersion();
StringUtilities.SplitOffAfterDelimiter(ref versionNumber, " ");
var apsimReleaseDirectory = Path.Combine(apsimReleasesPath, versionNumber);
if (!Directory.Exists(apsimReleaseDirectory))
Expand Down
41 changes: 30 additions & 11 deletions ApsimNG/Resources/Glade/RunOnCloudView.glade
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,36 @@
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="versionCombobox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="versionFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="height-request">200</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkTreeView" id="versionTreeview">
<property name="visible">True</property>
<property name="headers-visible">False</property>
<property name="can-focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
Expand Down