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 model for testing data binding #218

Merged
merged 1 commit into from
Mar 4, 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
6 changes: 3 additions & 3 deletions Wreck/Controller/AbstractController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class AbstractController : IController

private static readonly StatisticsCollector STATS = StatisticsCollector.Instance;

private FileSystemInfo startPath;
protected FileSystemInfo startPath;

private readonly WreckService service;

Expand Down Expand Up @@ -59,7 +59,7 @@ public virtual void Error()
Console.Error.WriteLine(startPath + " is invalid.");
}

public void Start(string startPath)
public virtual void Start(string startPath)
{
if(Directory.Exists(startPath))
this.startPath = new DirectoryInfo(startPath);
Expand All @@ -75,7 +75,7 @@ public void Start(string startPath)
}
}

public void Stop()
public virtual void Stop()
{
LOG.Info("Stopping and cleaning up...");
try
Expand Down
62 changes: 52 additions & 10 deletions WreckGui/Controller/GuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

using Java.Beans;
using Javax.Swing;
using log4net;
using Wreck.Entity;
using Wreck.IO;
using Wreck.IO.Reader;
using Wreck.IO.Task;
using Wreck.IO.Writer;
using Wreck.Model;
using Wreck.Resources;
using Wreck.Time;
using Wreck.Util.Logging;
using WreckGui.View;

Expand Down Expand Up @@ -54,14 +56,54 @@ public GuiWorker Worker
set { worker = value; }
}

/*
public override void Start(string startPath)
{
try
{
this.startPath = TimestampFormatter.IsValidPath(startPath);
Init();
View.GetMain().Show();
}
catch(Exception e)
{
LOG.ErrorFormat("Invalid path: {0}", e.Message);
Application.Exit();
}
}

public override void Stop()
{
LOG.Info("Stopping and cleaning up...");
try
{
if(WriterFactory.IsInitialized())
{
LOG.Info("Closing writers...");
WriterFactory.Instance.Dispose();
}

if(ReaderFactory.IsInitialized()) {
LOG.Info("Closing readers...");
ReaderFactory.Instance.Dispose();
}
}
catch (Exception e)
{
LOG.Error(e.StackTrace);
}
}
*/

private void Init()
{
string title = startPath.FullName + " - " + R.Strings.AppTitle;

}

public override void Error()
{
MessageBox.Show(
StartPath + " is invalid.",
"Invalid path",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
View.GetMain().Error(StartPath.FullName);
}

private void PrefillPaths()
Expand Down Expand Up @@ -108,7 +150,7 @@ public override void Run(CorrectionMode mode, FileSystemInfo fsi)

// FIXME: To check GUI control checkbox and textbox
DateTime customDateTime = DateTime.Now;

ITask task = Service.Run(fsi, mode, sources, corrections, customDateTime);

PropertyChangeListener propertyChangeListener = new ProgressPropertyChangeListener(this);
Expand Down Expand Up @@ -145,13 +187,13 @@ public void PropertyChange(PropertyChangeEvent evt)
else if (R.Strings.PropertyProgress.Equals(evt.PropertyName))
{
int progress = (int)evt.NewValue;
LOG.InfoFormat("Progress: {0}% MessageLoop: {1}", progress, Application.MessageLoop);
LOG.InfoFormat("Progress: {0}%", progress);
controller.View.GetMain().SetProgress(progress);
}
else if (R.Strings.PropertyVisits.Equals(evt.PropertyName))
{
FileVisit visit = (FileVisit) evt.NewValue;
LOG.InfoFormat("Progress: {0}% - Visit: {1} MessageLoop: {2}", visit.Progress, visit.File.Name, Application.MessageLoop);
LOG.InfoFormat("Progress: {0}% - Visit: {1}", visit.Progress, visit.File.Name);
controller.View.GetMain().SetProgress(visit.Progress);
controller.View.GetMain().SetAction(visit);
}
Expand Down
10 changes: 10 additions & 0 deletions WreckGui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,15 @@ public void Done()
rootNode.ExpandAll();
toolStripProgressBar.Visible = false;
}

public void Error(string startPath)
{
MessageBox.Show(
startPath + " is invalid.",
"Invalid path",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
}
}
}
33 changes: 26 additions & 7 deletions WreckGui/Model/GuiModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System;
using System.Collections.Generic;
using Java.Beans;
using Javax.Swing;
using Wreck.Entity;
Expand All @@ -17,14 +18,10 @@ public class GuiModel : IModel

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 IDictionary<SourceEnum, Boolean> sourceModel;
private DateTime customDateTimeModel;

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

// private readonly DefaultButtonModel backupModel;
// private readonly DefaultButtonModel restoreModel;
Expand All @@ -48,13 +45,35 @@ public GuiModel()
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.tableModel = new SampleTableModel<FileBean>(typeof(FileBean));

this.sourceModel = new Dictionary<SourceEnum, Boolean>();
this.customDateTimeModel = new DateTime();
this.correctionModel = new Dictionary<CorrectionEnum, Boolean>();

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

this.scanningProgressModel = new DefaultBoundedRangeModel();
}

public IDictionary<SourceEnum, bool> SourceModel
{
get { return sourceModel; }
set { sourceModel = value; }
}

public DateTime CustomDateTimeModel
{
get { return customDateTimeModel; }
set { customDateTimeModel = value; }
}

public IDictionary<CorrectionEnum, bool> CorrectionModel
{
get { return correctionModel; }
set { correctionModel = value; }
}

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