Skip to content

Commit

Permalink
Added test for TreeView
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert78 committed May 28, 2010
1 parent 2c24aa0 commit 63a4a4a
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 46 deletions.
13 changes: 1 addition & 12 deletions MP-II/Resources/GUITestPlugin/GUITestModel.cs
Expand Up @@ -24,20 +24,13 @@

using System;
using System.Collections.Generic;
using MediaPortal.Core;
using MediaPortal.Core.General;
using MediaPortal.Core.MediaManagement;
using MediaPortal.Core.Services.MediaManagement;
using MediaPortal.UI.Presentation.DataObjects;
using MediaPortal.UI.Presentation.Models;
using MediaPortal.UI.Presentation.Players;
using MediaPortal.UI.Presentation.Screens;
using MediaPortal.UI.Presentation.Workflow;

namespace Test.GUITestPlugin
{
/// <summary>
/// Model which holds the GUI state for the GUI test model.
/// Model which holds the GUI state for the GUI test state.
/// </summary>
public class GUITestModel : IWorkflowModel
{
Expand All @@ -50,10 +43,6 @@ public class GUITestModel : IWorkflowModel

#endregion

public GUITestModel()
{
}

#region IWorkflowModel implementation

public Guid ModelId
Expand Down
2 changes: 2 additions & 0 deletions MP-II/Resources/GUITestPlugin/GUITestPlugin.csproj
Expand Up @@ -52,6 +52,7 @@
<ItemGroup>
<Compile Include="GUITestModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TreeViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="plugin.xml" />
Expand All @@ -62,6 +63,7 @@
<Content Include="Skin\default\screens\test-opacitymask.xaml" />
<Content Include="Skin\default\screens\test-text-transforms.xaml" />
<Content Include="Skin\default\screens\test-transforms.xaml" />
<Content Include="Skin\default\screens\test-treeview.xaml" />
<Content Include="Skin\default\media\cherries.png" />
</ItemGroup>
<ItemGroup>
Expand Down
@@ -1,36 +1,50 @@
<DockPanel
<?xml version="1.0" encoding="utf-8"?>
<Include
xmlns="www.team-mediaportal.com/2008/mpf/directx"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
LastChildFill="True">
<Grid DockPanel.Dock="Center" Margin="30">
<Grid.Resources>
<Model x:Key="Model" Id="F4FC1599-F412-40d0-82BF-46FC352E93BE"/> <!-- GUI-Test-Model -->
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="50*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Style="{StaticResource ButtonStyle}" Content="Brushes/transforms test 1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-brushes-transforms1}"/>
<Button Grid.Column="0" Grid.Row="1" Style="{StaticResource ButtonStyle}" Content="Brushes/transforms test 2"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-brushes-transforms2}"/>
<Button Grid.Column="0" Grid.Row="2" Style="{StaticResource ButtonStyle}" Content="Opacity mask test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-opacitymask}"/>
<Button Grid.Column="0" Grid.Row="3" Style="{StaticResource ButtonStyle}" Content="Text elements/transforms test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-text-transforms}"/>
<Button Grid.Column="0" Grid.Row="4" Style="{StaticResource ButtonStyle}" Content="Transforms test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-transforms}"/>
</Grid>
</DockPanel>
Source="screens\master_menu.xaml"
>
<Include.Resources>

<!-- Header -->
<ResourceWrapper x:Key="Header_Text" Resource="GUI tests"/>

<!-- Contents -->
<ResourceWrapper x:Key="Contents_Element">
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Center" Margin="30">
<Grid.Resources>
<Model x:Key="Model" Id="F4FC1599-F412-40d0-82BF-46FC352E93BE"/> <!-- GUI-Test-Model -->
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="50*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Style="{StaticResource ButtonStyle}" Content="Brushes/transforms test 1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-brushes-transforms1}"/>
<Button Grid.Column="0" Grid.Row="1" Style="{StaticResource ButtonStyle}" Content="Brushes/transforms test 2"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-brushes-transforms2}"/>
<Button Grid.Column="0" Grid.Row="2" Style="{StaticResource ButtonStyle}" Content="Opacity mask test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-opacitymask}"/>
<Button Grid.Column="0" Grid.Row="3" Style="{StaticResource ButtonStyle}" Content="Text elements/transforms test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-text-transforms}"/>
<Button Grid.Column="0" Grid.Row="4" Style="{StaticResource ButtonStyle}" Content="Transforms test"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Command="{Command Source={Service ScreenManager},Path=ShowScreen,Parameters=test-transforms}"/>
</Grid>
</DockPanel>
</ResourceWrapper>

</Include.Resources>
</Include>
@@ -0,0 +1,33 @@
<Grid
xmlns="www.team-mediaportal.com/2008/mpf/directx"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Context="{Model Id=A6C3F942-105C-48cd-AEFF-059DA79773A9}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Content="TreeView test" Wrap="True"/>
<TreeView Grid.Row="1" Style="{ThemeResource DefaultSingleMarkableTreeViewStyle}"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ForceExpander="True"
ItemsSource="{Binding Path=Tree,Mode=OneTime}">
<TreeView.Resources>
<!-- Expander_Binding isn't necessary here - the TreeView won't synchronize its opening-state to the underlaying data model; it is static. We use a dummy. -->
<BindingWrapper x:Key="Expander_Binding"/>

<!-- Command not necessary here. We use a dummy. -->
<ResourceWrapper x:Key="Expander_Command"/>

<BindingWrapper x:Key="IsChecked_Binding" Binding="{Binding Path=Selected,Mode=TwoWay}"/>

<!-- Checker_Command isn't necessary here - the selection state will be propagated via the IsChecked_Binding.
We use a dummy. -->
<ResourceWrapper x:Key="Checker_Command"/>
</TreeView.Resources>
</TreeView>
</Grid>
Expand Up @@ -8,5 +8,12 @@
SourceState="7F702D9C-F2DD-42da-9ED8-0BA92F07787F"
TargetState="F660C2CA-A340-4694-A7F4-9E68AB9721C4"
DisplayTitle="GUI-Test"/>
<PushNavigationTransition Id="D0DB2310-E55D-4cdf-BCF7-6D8181318FAA"
Name="GUI-Test->TreeView"
DisplayCategory="controls"
SortOrder="TreeView"
SourceState="F660C2CA-A340-4694-A7F4-9E68AB9721C4"
TargetState="9233F320-F0D3-4511-84F0-4575CC9F6A55"
DisplayTitle="TreeView"/>
</MenuActions>
</Workflow>
Expand Up @@ -5,5 +5,9 @@
Name="GuiTestMain" MainScreen="gui-test-main"
DisplayLabel="GUI-Test"
WorkflowModel="F4FC1599-F412-40d0-82BF-46FC352E93BE"/> <!-- Workflow model = GUITestModel -->
<WorkflowState Id="9233F320-F0D3-4511-84F0-4575CC9F6A55"
Name="TreeViewTest" MainScreen="test-treeview"
DisplayLabel="TreeView"
WorkflowModel="A6C3F942-105C-48cd-AEFF-059DA79773A9"/> <!-- Workflow model = TreeViewModel -->
</States>
</Workflow>
135 changes: 135 additions & 0 deletions MP-II/Resources/GUITestPlugin/TreeViewModel.cs
@@ -0,0 +1,135 @@
#region Copyright (C) 2007-2008 Team MediaPortal

/*
Copyright (C) 2007-2008 Team MediaPortal
http://www.team-mediaportal.com
This file is part of MediaPortal II
MediaPortal II is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MediaPortal II is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaPortal II. If not, see <http://www.gnu.org/licenses/>.
*/

#endregion

using System;
using System.Collections.Generic;
using MediaPortal.UI.Presentation.DataObjects;
using MediaPortal.UI.Presentation.Models;
using MediaPortal.UI.Presentation.Workflow;

namespace Test.GUITestPlugin
{
/// <summary>
/// Model which holds the GUI state for the TreeView state.
/// </summary>
public class TreeViewModel : IWorkflowModel
{
public const string MODEL_ID_STR = "A6C3F942-105C-48cd-AEFF-059DA79773A9";

#region Protected fields

protected ItemsList _tree = null;

#endregion

protected void CreateChildren(TreeItem item, int level, int maxLevel)
{
if (level > maxLevel)
return;
TreeItem childItem = new TreeItem("Name", "First item, level " + level);
CreateChildren(childItem, level + 1, maxLevel);
item.SubItems.Add(childItem);
childItem = new TreeItem("Name", "Second item, level " + level);
CreateChildren(childItem, level + 1, maxLevel);
item.SubItems.Add(childItem);
childItem = new TreeItem("Name", "Third item, level " + level);
CreateChildren(childItem, level + 1, maxLevel);
item.SubItems.Add(childItem);
}

protected void InitializeTree()
{
_tree = new ItemsList();
TreeItem item = new TreeItem("Name", "First item");
CreateChildren(item, 2, 3);
_tree.Add(item);
item = new TreeItem("Name", "Second item");
CreateChildren(item, 2, 4);
_tree.Add(item);
item = new TreeItem("Name", "Third item");
CreateChildren(item, 2, 5);
_tree.Add(item);
}

protected void DisposeTree()
{
_tree = null;
}

#region Public properties

public ItemsList Tree
{
get { return _tree; }
}

#endregion

#region IWorkflowModel implementation

public Guid ModelId
{
get { return new Guid(MODEL_ID_STR); }
}

public bool CanEnterState(NavigationContext oldContext, NavigationContext newContext)
{
return true;
}

public void EnterModelContext(NavigationContext oldContext, NavigationContext newContext)
{
InitializeTree();
}

public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
{
DisposeTree();
}

public void ChangeModelContext(NavigationContext oldContext, NavigationContext newContext, bool push)
{
// We could initialize some data here when changing the media navigation state
}

public void Deactivate(NavigationContext oldContext, NavigationContext newContext)
{
}

public void ReActivate(NavigationContext oldContext, NavigationContext newContext)
{
}

public void UpdateMenuActions(NavigationContext context, IDictionary<Guid, WorkflowAction> actions)
{
}

public ScreenUpdateMode UpdateScreen(NavigationContext context, ref string screen)
{
return ScreenUpdateMode.AutoWorkflowManager;
}

#endregion
}
}
1 change: 1 addition & 0 deletions MP-II/Resources/GUITestPlugin/plugin.xml
Expand Up @@ -13,6 +13,7 @@

<Register Location="/Models">
<Model Id="F4FC1599-F412-40d0-82BF-46FC352E93BE" ClassName="Test.GUITestPlugin.GUITestModel"/>
<Model Id="A6C3F942-105C-48cd-AEFF-059DA79773A9" ClassName="Test.GUITestPlugin.TreeViewModel"/>
</Register>

<Register Location="/Resources/Skin">
Expand Down

0 comments on commit 63a4a4a

Please sign in to comment.