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

Add Gui model #153

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion WreckGui/Controller/GuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Wreck.IO.Task;
using Wreck.Resources;
using Wreck.Util.Logging;
using WreckGui.Model;
using Wreck.Model;

namespace Wreck.Controller
{
Expand Down
53 changes: 52 additions & 1 deletion WreckGui/Model/GuiModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@

using System;
using Wreck.Entity;

namespace WreckGui.Model
namespace Wreck.Model
{
/// <summary>
/// Description of GuiModel.
/// </summary>
public class GuiModel
{
// private static readonly Pattern DIGITS = Pattern.compile("^[0-9]+$");

private readonly SampleTableModel<FileBean> tableModel;
// private readonly ButtonModel metadataModel;
// private readonly IDictionary<SourceEnum, ButtonModel> sourceModel;
// private readonly Document dateTimeDocument;
// private readonly SpinnerNumberModel customDateTimeYearModel;
// private readonly SpinnerNumberModel customDateTimeMonthModel;
// private readonly SpinnerNumberModel customDateTimeDayModel;
// private readonly SpinnerDateModel customDateTimeModel;

// private readonly IDictionary<CorrectionEnum, ButtonModel> correctionModel;

// private readonly DefaultButtonModel backupModel;
// private readonly DefaultButtonModel restoreModel;
// private readonly DefaultButtonModel verifyModel;

private readonly SampleTableModel<FileStatisticsBean> fileStatisticsTableModel;
private readonly SampleTableModel<MetadataStatisticsBean> metadataStatisticsTableModel;
private readonly SampleTableModel<ExtensionStatisticsBean> extensionStatisticsTableModel;

// private readonly DefaultListModel<AboutBean> aboutModel;

// private readonly BoundedRangeModel scanningProgressModel;

public GuiModel()
{
this.tableModel = new SampleTableModel<FileBean>(typeof(FileBean));

this.fileStatisticsTableModel = new SampleTableModel<FileStatisticsBean>(typeof(FileStatisticsBean));
this.metadataStatisticsTableModel = new SampleTableModel<MetadataStatisticsBean>(typeof(MetadataStatisticsBean));
this.extensionStatisticsTableModel = new SampleTableModel<ExtensionStatisticsBean>(typeof(ExtensionStatisticsBean));
}

public SampleTableModel<FileBean> TableModel
{
get { return tableModel; }
}

public SampleTableModel<FileStatisticsBean> FileStatisticsTableModel
{
get { return fileStatisticsTableModel; }
}

public SampleTableModel<MetadataStatisticsBean> MetadataStatisticsTableModel
{
get { return metadataStatisticsTableModel; }
}

public SampleTableModel<ExtensionStatisticsBean> ExtensionStatisticsTableModel
{
get { return extensionStatisticsTableModel; }
}
}
}
139 changes: 139 additions & 0 deletions WreckGui/Model/SampleTableModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

using System;
using System.Collections.Generic;
using System.Security;

using log4net;

namespace Wreck.Model
{
/// <summary>
/// Description of SampleTableModel.
/// </summary>
public class SampleTableModel<T>
{
private static readonly ILog LOG = LogManager.GetLogger(typeof(SampleTableModel<T>));

private IList<string> columns = new List<string>();
private IList<T> data = new List<T>();

private readonly Type type;

public SampleTableModel(Type type) : base()
{
this.type = type;
}

public Type Type
{
get { return this.type; }
}

public string[] Header
{
get
{
string[] header = new string[columns.Count];
for(int i = 0; i < columns.Count; i++)
{
header[i] = columns[i].ToUpper();
}

return header;
}
}

public IList<T> Data
{
get { return data; }
}

public int RowCount
{
get { return Data.Count; }
}

public int ColumnCount
{
get { return columns.Count; }
}

public object GetValueAt(int rowIndex, int columnIndex)
{
T bean = Data[rowIndex];
string column = columns[columnIndex];
object val = null;
try
{
// column.SetAccessible(true);
// val = column[bean];
}
catch (ArgumentException e)
{
LOG.Error(e.ToString());
}
catch (AccessViolationException e)
{
LOG.Error(e.ToString());
}
catch (SecurityException e)
{
LOG.Error(e.ToString());
}
return val;
}

public string ColumnName(int column)
{
string n = columns[column];
return n.Substring(0, 1).ToUpper() + n.Substring(1);
}

public Type ColumnClass(int columnIndex)
{

Type clazz = null;

string field;
try
{
field = columns[columnIndex];

if((field != null))
clazz = field.GetType();

if(clazz.IsPrimitive)
{
clazz = clazz.ReflectedType;
}
// LOG.DebugFormat("Column class: {0} -> {1}", columnIndex, clazz);
}
catch (SecurityException e)
{
LOG.Error(e.ToString());
}

return clazz;
}

public void AddRow(T row)
{
data.Add(row);
// this.FireTableRowsInserted(data.Count-1, data.Count-1);
}

public void RemoveRow(int row)
{
data.RemoveAt(row);
// this.FireTableRowsDeleted(row, row);
}

public void Clear() {
if(data.Count > 0)
{
data.Clear();
// this.FireTableRowsDeleted(0, this.RowCount-1);
}
}
}
}
1 change: 1 addition & 0 deletions WreckGui/WreckGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Model\GuiModel.cs" />
<Compile Include="Model\SampleTableModel.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
Expand Down