Commit 2a38233
Changed files (17)
product
desktop.ui
bootstrappers
messages
presenters
views
product/desktop.ui/bootstrappers/Bootstrapper.cs
@@ -5,6 +5,7 @@ using Autofac;
using desktop.ui.eventing;
using desktop.ui.handlers;
using desktop.ui.handlers.orm;
+using desktop.ui.messages.@private;
using desktop.ui.presenters;
using desktop.ui.views;
using gorilla.infrastructure.container;
@@ -49,6 +50,7 @@ namespace desktop.ui.bootstrappers
{
builder.RegisterType<ComposeShell>().As<NeedStartup>();
builder.RegisterType<ConfigureMappings>().As<NeedStartup>();
+ builder.RegisterType<WireUpSubscribers>().As<NeedStartup>();
}
static void register_presentation_infrastructure(ContainerBuilder builder)
@@ -78,6 +80,7 @@ namespace desktop.ui.bootstrappers
builder.RegisterType<AddNewIncomeViewModel>();
builder.RegisterType<AddNewIncomeViewModel.AddIncomeCommand>();
+ builder.RegisterType<IfFamilyMemberIsSelected>().SingleInstance();
builder.RegisterType<TaxSummaryPresenter>();
product/desktop.ui/bootstrappers/WireUpSubscribers.cs
@@ -0,0 +1,15 @@
+using desktop.ui.eventing;
+using desktop.ui.presenters;
+using gorilla.infrastructure.container;
+
+namespace desktop.ui.bootstrappers
+{
+ public class WireUpSubscribers : NeedStartup
+ {
+ public void run()
+ {
+ var eventAggregator = Resolve.the<EventAggregator>();
+ eventAggregator.subscribe(Resolve.the<IfFamilyMemberIsSelected>());
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/AddIncomeCommandMessageHandler.cs
@@ -1,4 +1,5 @@
using System;
+using desktop.ui.messages.@private;
using desktop.ui.presenters;
namespace desktop.ui.handlers
product/desktop.ui/handlers/AddNewFamilyMemberHandler.cs
@@ -1,5 +1,6 @@
using desktop.ui.handlers.domain;
using desktop.ui.handlers.orm;
+using desktop.ui.messages.@private;
using desktop.ui.presenters;
namespace desktop.ui.handlers
product/desktop.ui/messages/private/AddIncomeCommandMessage.cs
@@ -0,0 +1,9 @@
+using desktop.ui.eventing;
+
+namespace desktop.ui.messages.@private
+{
+ public class AddIncomeCommandMessage : Event
+ {
+ public decimal amount { get; set; }
+ }
+}
\ No newline at end of file
product/desktop.ui/messages/private/FamilyMemberToAdd.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace desktop.ui.messages.@private
+{
+ public class FamilyMemberToAdd
+ {
+ public string first_name { get; set; }
+ public string last_name { get; set; }
+ public DateTime date_of_birth { get; set; }
+ }
+}
\ No newline at end of file
product/desktop.ui/presenters/AddFamilyMemberPresenter.cs
@@ -1,4 +1,5 @@
using System;
+using desktop.ui.messages.@private;
using gorilla.utility;
namespace desktop.ui.presenters
@@ -47,11 +48,4 @@ namespace desktop.ui.presenters
}
}
}
-
- public class FamilyMemberToAdd
- {
- public string first_name { get; set; }
- public string last_name { get; set; }
- public DateTime date_of_birth { get; set; }
- }
}
\ No newline at end of file
product/desktop.ui/presenters/AddNewIncomeViewModel.cs
@@ -1,5 +1,5 @@
using System;
-using desktop.ui.eventing;
+using desktop.ui.messages.@private;
namespace desktop.ui.presenters
{
@@ -14,7 +14,7 @@ namespace desktop.ui.presenters
public void present()
{
- Add = builder.build<AddIncomeCommand>(this);
+ Add = builder.build<AddIncomeCommand, IfFamilyMemberIsSelected>(this);
Cancel = builder.build<CancelCommand>(this);
}
@@ -39,9 +39,4 @@ namespace desktop.ui.presenters
}
}
}
-
- public class AddIncomeCommandMessage : Event
- {
- public decimal amount { get; set; }
- }
}
\ No newline at end of file
product/desktop.ui/presenters/IfFamilyMemberIsSelected.cs
@@ -0,0 +1,21 @@
+using desktop.ui.eventing;
+using desktop.ui.events;
+
+namespace desktop.ui.presenters
+{
+ public class IfFamilyMemberIsSelected : UISpecification<AddNewIncomeViewModel>,
+ EventSubscriber<SelectedFamilyMember>
+ {
+ public override bool is_satisfied_by(AddNewIncomeViewModel item)
+ {
+ return is_selected;
+ }
+
+ public void notify(SelectedFamilyMember message)
+ {
+ is_selected = message != null;
+ }
+
+ bool is_selected;
+ }
+}
\ No newline at end of file
product/desktop.ui/presenters/TaxSummaryPresenter.cs
@@ -2,12 +2,12 @@
using System.Collections.Generic;
using desktop.ui.eventing;
using desktop.ui.events;
+using desktop.ui.messages.@private;
using desktop.ui.model;
namespace desktop.ui.presenters
{
- public class TaxSummaryPresenter : Observable<TaxSummaryPresenter>, TabPresenter,
- EventSubscriber<AddIncomeCommandMessage>, EventSubscriber<SelectedFamilyMember>
+ public class TaxSummaryPresenter : Observable<TaxSummaryPresenter>, TabPresenter, EventSubscriber<AddIncomeCommandMessage>, EventSubscriber<SelectedFamilyMember>
{
UICommandBuilder builder;
product/desktop.ui/presenters/WpfCommandBuilder.cs
@@ -19,5 +19,15 @@ namespace desktop.ui.presenters
command.run(presenter);
});
}
+
+ public IObservableCommand build<Command, Specification>(Presenter presenter) where Command : UICommand where Specification : UISpecification
+ {
+ var command = container.get_a<Command>();
+ var specification = container.get_a<Specification>();
+ return new SimpleCommand(() =>
+ {
+ command.run(presenter);
+ }, () => specification.is_satisfied_by(presenter) );
+ }
}
}
\ No newline at end of file
product/desktop.ui/views/AddNewIncomeDialog.xaml
@@ -1,11 +1,15 @@
<Window x:Class="desktop.ui.views.AddNewIncomeDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Add Income">
+ Title="Add Income" Width="400" Height="100" WindowStartupLocation="CenterOwner">
<StackPanel>
- <Label>Income Amount:</Label>
+ <DockPanel>
+ <Label>Income Amount ($):</Label>
<TextBox Text="{Binding Path=amount}"></TextBox>
- <Button Command="{Binding Path=Add}">_Add</Button>
- <Button Command="{Binding Path=Cancel}">_Cancel</Button>
+ </DockPanel>
+ <DockPanel LastChildFill="False" HorizontalAlignment="Right">
+ <Button IsDefault="True" Command="{Binding Path=Add}">_Add</Button>
+ <Button IsCancel="True" Command="{Binding Path=Cancel}">_Cancel</Button>
+ </DockPanel>
</StackPanel>
</Window>
product/desktop.ui/desktop.ui.csproj
@@ -70,6 +70,7 @@
<Compile Include="bootstrappers\DefaultMapper.cs" />
<Compile Include="bootstrappers\NeedsShutdown.cs" />
<Compile Include="bootstrappers\NeedStartup.cs" />
+ <Compile Include="bootstrappers\WireUpSubscribers.cs" />
<Compile Include="CancelCommand.cs" />
<Compile Include="Dialog.cs" />
<Compile Include="DialogPresenter.cs" />
@@ -90,6 +91,8 @@
<Compile Include="handlers\PublishEventHandler.cs" />
<Compile Include="IObservableCommand.cs" />
<Compile Include="messages\private\AddedNewFamilyMember.cs" />
+ <Compile Include="messages\private\AddIncomeCommandMessage.cs" />
+ <Compile Include="messages\private\FamilyMemberToAdd.cs" />
<Compile Include="model\TaxesForIndividual.cs" />
<Compile Include="Observable.cs" />
<Compile Include="Presenter.cs" />
@@ -99,6 +102,7 @@
<Compile Include="presenters\DisplayCanadianTaxInformationViewModel.cs" />
<Compile Include="messages\private\FindAllFamily.cs" />
<Compile Include="model\PersonDetails.cs" />
+ <Compile Include="presenters\IfFamilyMemberIsSelected.cs" />
<Compile Include="presenters\SelectedFamilyMemberPresenter.cs" />
<Compile Include="presenters\TaxSummaryPresenter.cs" />
<Compile Include="ServiceBus.cs" />
@@ -112,6 +116,7 @@
<Compile Include="TabPresenter.cs" />
<Compile Include="UICommand.cs" />
<Compile Include="UICommandBuilder.cs" />
+ <Compile Include="UISpecification.cs" />
<Compile Include="View.cs" />
<Compile Include="views\AddFamilyMemberDialog.xaml.cs">
<DependentUpon>AddFamilyMemberDialog.xaml</DependentUpon>
product/desktop.ui/Observable.cs
@@ -14,21 +14,4 @@ namespace desktop.ui
properties.each(x => { PropertyChanged(this, new PropertyChangedEventArgs(x.pick_property().Name)); });
}
}
-
- public class ObservableProperty<T> : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged = (o, e) => { };
-
- public T Value
- {
- get { return value; }
- set
- {
- this.value = value;
- PropertyChanged(this, new PropertyChangedEventArgs("Value"));
- }
- }
-
- T value;
- }
}
\ No newline at end of file
product/desktop.ui/UICommand.cs
@@ -1,3 +1,5 @@
+using gorilla.utility;
+
namespace desktop.ui
{
public interface UICommand
@@ -5,13 +7,13 @@ namespace desktop.ui
void run<T>(T presenter) where T : Presenter;
}
- public abstract class UICommand<T> : UICommand where T : class, Presenter
+ public abstract class UICommand<TPresenter> : UICommand where TPresenter : Presenter
{
void UICommand.run<T1>(T1 presenter)
{
- run(presenter as T);
+ run(presenter.downcast_to<TPresenter>());
}
- public abstract void run(T presenter);
+ public abstract void run(TPresenter presenter);
}
}
\ No newline at end of file
product/desktop.ui/UICommandBuilder.cs
@@ -2,6 +2,7 @@ namespace desktop.ui
{
public interface UICommandBuilder
{
- IObservableCommand build<T>(Presenter presenter) where T : UICommand;
+ IObservableCommand build<Command>(Presenter presenter) where Command : UICommand;
+ IObservableCommand build<Command, Specification>(Presenter presenter) where Command : UICommand where Specification : UISpecification;
}
}
\ No newline at end of file
product/desktop.ui/UISpecification.cs
@@ -0,0 +1,20 @@
+using gorilla.utility;
+
+namespace desktop.ui
+{
+ public interface UISpecification
+ {
+ bool is_satisfied_by<T>(T presenter) where T : Presenter;
+ }
+
+ public abstract class UISpecification<TPresenter> : UISpecification, Specification<TPresenter>
+ where TPresenter : Presenter
+ {
+ bool UISpecification.is_satisfied_by<T>(T presenter)
+ {
+ return is_satisfied_by(presenter.downcast_to<TPresenter>());
+ }
+
+ public abstract bool is_satisfied_by(TPresenter presenter);
+ }
+}
\ No newline at end of file