summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Lepp <jlepp@arcresources.com>2010-10-15 11:09:49 -0600
committerJason Lepp <jlepp@arcresources.com>2010-10-15 11:09:49 -0600
commiteca7f7df8d6c50f8a89ef6afbeec96b70bff5725 (patch)
treec5b988eeda5e8c1b65bcd36fe7f38a6244889fa0
parent364848a914c844fe2e29d83922f8f1001d14c14b (diff)
Begin adding presenter for TodoItems
-rw-r--r--README1
-rwxr-xr-xsrc/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj7
-rwxr-xr-xsrc/MVPtoMVVM.mvp/MainWindow.xaml8
-rwxr-xr-xsrc/MVPtoMVVM.mvp/MainWindow.xaml.cs27
-rwxr-xr-xsrc/MVPtoMVVM.mvp/MvpWindow.xaml3
-rwxr-xr-xsrc/MVPtoMVVM.mvp/MvpWindow.xaml.cs10
-rwxr-xr-xsrc/MVPtoMVVM.mvp/TodoItemView.xaml11
-rwxr-xr-xsrc/MVPtoMVVM.mvp/TodoItemView.xaml.cs43
-rwxr-xr-xsrc/MVPtoMVVM/IMvpView.cs10
-rwxr-xr-xsrc/MVPtoMVVM/MVPtoMVVM.csproj10
-rwxr-xr-xsrc/MVPtoMVVM/mappers/ITodoItemPresenterMapper.cs12
-rwxr-xr-xsrc/MVPtoMVVM/mappers/TodoItemPresenterMapper.cs25
-rwxr-xr-xsrc/MVPtoMVVM/presenters/IMvpPresenter.cs3
-rwxr-xr-xsrc/MVPtoMVVM/presenters/ITodoItemPresenter.cs11
-rwxr-xr-xsrc/MVPtoMVVM/presenters/MvpPresenter.cs9
-rwxr-xr-xsrc/MVPtoMVVM/presenters/TodoItemPresenter.cs30
-rwxr-xr-xsrc/MVPtoMVVM/repositories/IRepository.cs12
-rwxr-xr-xsrc/MVPtoMVVM/repositories/TodoItemRepository.cs11
-rwxr-xr-xsrc/MVPtoMVVM/views/IMvpView.cs10
-rwxr-xr-xsrc/MVPtoMVVM/views/ITodoItemView.cs10
20 files changed, 192 insertions, 71 deletions
diff --git a/README b/README
deleted file mode 100644
index e1de3f9..0000000
--- a/README
+++ /dev/null
@@ -1 +0,0 @@
-Test commit
diff --git a/src/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj b/src/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj
index 013702a..f82749d 100755
--- a/src/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj
+++ b/src/MVPtoMVVM.mvp/MVPtoMVVM.mvp.csproj
@@ -59,6 +59,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Compile Include="TodoItemView.xaml.cs">
+ <DependentUpon>TodoItemView.xaml</DependentUpon>
+ </Compile>
<Page Include="MvpWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -72,6 +75,10 @@
<DependentUpon>MvpWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
+ <Page Include="TodoItemView.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
diff --git a/src/MVPtoMVVM.mvp/MainWindow.xaml b/src/MVPtoMVVM.mvp/MainWindow.xaml
deleted file mode 100755
index 01760b5..0000000
--- a/src/MVPtoMVVM.mvp/MainWindow.xaml
+++ /dev/null
@@ -1,8 +0,0 @@
-<Window x:Class="MVPtoMVVM.mvp.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
-
- </Grid>
-</Window>
diff --git a/src/MVPtoMVVM.mvp/MainWindow.xaml.cs b/src/MVPtoMVVM.mvp/MainWindow.xaml.cs
deleted file mode 100755
index 987ac7a..0000000
--- a/src/MVPtoMVVM.mvp/MainWindow.xaml.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace MVPtoMVVM.mvp
-{
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/src/MVPtoMVVM.mvp/MvpWindow.xaml b/src/MVPtoMVVM.mvp/MvpWindow.xaml
index 873db7d..ffc17f7 100755
--- a/src/MVPtoMVVM.mvp/MvpWindow.xaml
+++ b/src/MVPtoMVVM.mvp/MvpWindow.xaml
@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
- <DataGrid AutoGenerateColumns="True" Name="todoItemsGrid">
- </DataGrid>
+ <ListView Name="todoItemsList"></ListView>
</StackPanel>
</Window>
diff --git a/src/MVPtoMVVM.mvp/MvpWindow.xaml.cs b/src/MVPtoMVVM.mvp/MvpWindow.xaml.cs
index 2ebe158..364488f 100755
--- a/src/MVPtoMVVM.mvp/MvpWindow.xaml.cs
+++ b/src/MVPtoMVVM.mvp/MvpWindow.xaml.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
-using System.Diagnostics;
-using MVPtoMVVM.domain;
+using System.Linq;
using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
using StructureMap;
namespace MVPtoMVVM.mvp
@@ -13,14 +13,14 @@ namespace MVPtoMVVM.mvp
public MvpWindow()
{
InitializeComponent();
- Debug.Write(ObjectFactory.WhatDoIHave());
presenter = ObjectFactory.GetInstance<IMvpPresenter>();
presenter.SetView(this);
}
- public void SetTodoItems(IEnumerable<TodoItem> items)
+ public void SetTodoItems(IEnumerable<ITodoItemPresenter> presenters)
{
- todoItemsGrid.ItemsSource = items;
+ todoItemsList.ItemsSource = presenters.Select(x => new TodoItemView(x));
}
+
}
}
diff --git a/src/MVPtoMVVM.mvp/TodoItemView.xaml b/src/MVPtoMVVM.mvp/TodoItemView.xaml
new file mode 100755
index 0000000..9cc8b6d
--- /dev/null
+++ b/src/MVPtoMVVM.mvp/TodoItemView.xaml
@@ -0,0 +1,11 @@
+<UserControl x:Class="MVPtoMVVM.mvp.TodoItemView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ mc:Ignorable="d">
+ <StackPanel Orientation="Horizontal">
+ <TextBox Name="description" Width="200"/>
+ <DatePicker Name="dueDate" />
+ </StackPanel>
+</UserControl>
diff --git a/src/MVPtoMVVM.mvp/TodoItemView.xaml.cs b/src/MVPtoMVVM.mvp/TodoItemView.xaml.cs
new file mode 100755
index 0000000..89ef811
--- /dev/null
+++ b/src/MVPtoMVVM.mvp/TodoItemView.xaml.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.mvp
+{
+ /// <summary>
+ /// Interaction logic for TodoItemView.xaml
+ /// </summary>
+ public partial class TodoItemView : ITodoItemView
+ {
+ public TodoItemView(ITodoItemPresenter presenter)
+ {
+ InitializeComponent();
+ presenter.SetView(this);
+ }
+
+ public string Description
+ {
+ get { return description.Text; }
+ set { description.Text = value; }
+ }
+
+ public DateTime DueDate
+ {
+ get { return dueDate.SelectedDate.Value; }
+ set { dueDate.SelectedDate = value; }
+ }
+ }
+}
diff --git a/src/MVPtoMVVM/IMvpView.cs b/src/MVPtoMVVM/IMvpView.cs
deleted file mode 100755
index 9b99bee..0000000
--- a/src/MVPtoMVVM/IMvpView.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-using MVPtoMVVM.domain;
-
-namespace MVPtoMVVM
-{
- public interface IMvpView
- {
- void SetTodoItems(IEnumerable<TodoItem> items);
- }
-} \ No newline at end of file
diff --git a/src/MVPtoMVVM/MVPtoMVVM.csproj b/src/MVPtoMVVM/MVPtoMVVM.csproj
index b4fb83b..88cf63e 100755
--- a/src/MVPtoMVVM/MVPtoMVVM.csproj
+++ b/src/MVPtoMVVM/MVPtoMVVM.csproj
@@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="StructureMap">
+ <HintPath>..\..\lib\StructureMap\StructureMap.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -43,12 +46,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="domain\TodoItem.cs" />
- <Compile Include="IMvpView.cs" />
+ <Compile Include="mappers\ITodoItemPresenterMapper.cs" />
+ <Compile Include="mappers\TodoItemPresenterMapper.cs" />
+ <Compile Include="presenters\ITodoItemPresenter.cs" />
+ <Compile Include="presenters\TodoItemPresenter.cs" />
+ <Compile Include="views\IMvpView.cs" />
<Compile Include="presenters\IMvpPresenter.cs" />
<Compile Include="presenters\MvpPresenter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="repositories\ITodoItemRepository.cs" />
<Compile Include="repositories\TodoItemRepository.cs" />
+ <Compile Include="views\ITodoItemView.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/src/MVPtoMVVM/mappers/ITodoItemPresenterMapper.cs b/src/MVPtoMVVM/mappers/ITodoItemPresenterMapper.cs
new file mode 100755
index 0000000..e1d7147
--- /dev/null
+++ b/src/MVPtoMVVM/mappers/ITodoItemPresenterMapper.cs
@@ -0,0 +1,12 @@
+using System.Collections.Generic;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.mappers
+{
+ public interface ITodoItemPresenterMapper
+ {
+ IEnumerable<ITodoItemPresenter> MapAll(IEnumerable<TodoItem> items);
+ }
+} \ No newline at end of file
diff --git a/src/MVPtoMVVM/mappers/TodoItemPresenterMapper.cs b/src/MVPtoMVVM/mappers/TodoItemPresenterMapper.cs
new file mode 100755
index 0000000..5b650fc
--- /dev/null
+++ b/src/MVPtoMVVM/mappers/TodoItemPresenterMapper.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.presenters;
+using MVPtoMVVM.views;
+using StructureMap;
+
+namespace MVPtoMVVM.mappers
+{
+ public class TodoItemPresenterMapper : ITodoItemPresenterMapper
+ {
+ private ITodoItemPresenter MapFrom(TodoItem item)
+ {
+ var presenter = ObjectFactory.GetInstance<ITodoItemPresenter>();
+ presenter.SetItem(item);
+ return presenter;
+ }
+
+ public IEnumerable<ITodoItemPresenter> MapAll(IEnumerable<TodoItem> items)
+ {
+ return items.Select(todoItem => MapFrom(todoItem));
+ }
+ }
+} \ No newline at end of file
diff --git a/src/MVPtoMVVM/presenters/IMvpPresenter.cs b/src/MVPtoMVVM/presenters/IMvpPresenter.cs
index 7cac253..ccc2003 100755
--- a/src/MVPtoMVVM/presenters/IMvpPresenter.cs
+++ b/src/MVPtoMVVM/presenters/IMvpPresenter.cs
@@ -1,8 +1,9 @@
+using MVPtoMVVM.views;
+
namespace MVPtoMVVM.presenters
{
public interface IMvpPresenter
{
void SetView(IMvpView view);
-
}
} \ No newline at end of file
diff --git a/src/MVPtoMVVM/presenters/ITodoItemPresenter.cs b/src/MVPtoMVVM/presenters/ITodoItemPresenter.cs
new file mode 100755
index 0000000..f4f127b
--- /dev/null
+++ b/src/MVPtoMVVM/presenters/ITodoItemPresenter.cs
@@ -0,0 +1,11 @@
+using MVPtoMVVM.domain;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.presenters
+{
+ public interface ITodoItemPresenter
+ {
+ void SetView(ITodoItemView view);
+ void SetItem(TodoItem item);
+ }
+} \ No newline at end of file
diff --git a/src/MVPtoMVVM/presenters/MvpPresenter.cs b/src/MVPtoMVVM/presenters/MvpPresenter.cs
index a36beef..13a9bb5 100755
--- a/src/MVPtoMVVM/presenters/MvpPresenter.cs
+++ b/src/MVPtoMVVM/presenters/MvpPresenter.cs
@@ -1,5 +1,8 @@
using System;
+using System.Linq;
+using MVPtoMVVM.mappers;
using MVPtoMVVM.repositories;
+using MVPtoMVVM.views;
namespace MVPtoMVVM.presenters
{
@@ -7,10 +10,12 @@ namespace MVPtoMVVM.presenters
{
private IMvpView view;
private ITodoItemRepository itemRepository;
+ private ITodoItemPresenterMapper presenterMapper;
- public MvpPresenter(ITodoItemRepository itemRepository)
+ public MvpPresenter(ITodoItemRepository itemRepository, ITodoItemPresenterMapper presenterMapper)
{
this.itemRepository = itemRepository;
+ this.presenterMapper = presenterMapper;
}
public void SetView(IMvpView view)
@@ -21,7 +26,7 @@ namespace MVPtoMVVM.presenters
private void InitializeView()
{
- view.SetTodoItems(itemRepository.GetAll());
+ view.SetTodoItems(presenterMapper.MapAll(itemRepository.GetAll()));
}
}
} \ No newline at end of file
diff --git a/src/MVPtoMVVM/presenters/TodoItemPresenter.cs b/src/MVPtoMVVM/presenters/TodoItemPresenter.cs
new file mode 100755
index 0000000..fe50830
--- /dev/null
+++ b/src/MVPtoMVVM/presenters/TodoItemPresenter.cs
@@ -0,0 +1,30 @@
+using System;
+using MVPtoMVVM.domain;
+using MVPtoMVVM.views;
+
+namespace MVPtoMVVM.presenters
+{
+ public class TodoItemPresenter : ITodoItemPresenter
+ {
+ private ITodoItemView view;
+ private TodoItem item;
+
+ public void SetView(ITodoItemView view)
+ {
+ this.view = view;
+ InitializeView();
+ }
+
+ public void SetItem(TodoItem item)
+ {
+ this.item = item;
+ }
+
+ private void InitializeView()
+ {
+ view.Description = item.Description;
+ view.DueDate = item.DueDate;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/MVPtoMVVM/repositories/IRepository.cs b/src/MVPtoMVVM/repositories/IRepository.cs
deleted file mode 100755
index 3593a02..0000000
--- a/src/MVPtoMVVM/repositories/IRepository.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System.Collections.Generic;
-using MVPtoMVVM.domain;
-
-namespace MVPtoMVVM.repositories
-{
- public interface ITodoItemRepository
- {
- void Add(TodoItem item);
- TodoItem Get(string description);
- IEnumerable<TodoItem> GetAll();
- }
-} \ No newline at end of file
diff --git a/src/MVPtoMVVM/repositories/TodoItemRepository.cs b/src/MVPtoMVVM/repositories/TodoItemRepository.cs
index 9a81f73..6029ad4 100755
--- a/src/MVPtoMVVM/repositories/TodoItemRepository.cs
+++ b/src/MVPtoMVVM/repositories/TodoItemRepository.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using MVPtoMVVM.domain;
using System.Linq;
@@ -6,7 +7,13 @@ namespace MVPtoMVVM.repositories
{
public class TodoItemRepository : ITodoItemRepository
{
- private List<TodoItem> items = new List<TodoItem>();
+ private List<TodoItem> items;
+
+ public TodoItemRepository()
+ {
+ items = new List<TodoItem>();
+ items.Add(new TodoItem {Description = "First One", DueDate = DateTime.Today});
+ }
public void Add(TodoItem item)
{
diff --git a/src/MVPtoMVVM/views/IMvpView.cs b/src/MVPtoMVVM/views/IMvpView.cs
new file mode 100755
index 0000000..321df66
--- /dev/null
+++ b/src/MVPtoMVVM/views/IMvpView.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using MVPtoMVVM.presenters;
+
+namespace MVPtoMVVM.views
+{
+ public interface IMvpView
+ {
+ void SetTodoItems(IEnumerable<ITodoItemPresenter> presenters);
+ }
+} \ No newline at end of file
diff --git a/src/MVPtoMVVM/views/ITodoItemView.cs b/src/MVPtoMVVM/views/ITodoItemView.cs
new file mode 100755
index 0000000..7c2c48f
--- /dev/null
+++ b/src/MVPtoMVVM/views/ITodoItemView.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace MVPtoMVVM.views
+{
+ public interface ITodoItemView
+ {
+ string Description { get; set; }
+ DateTime DueDate { get; set; }
+ }
+} \ No newline at end of file