Controller.cs :  » Game » SokoSolve-Sokoban » SokoSolve » UI » Section » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » UI » Section » Controller.cs
using System;
using System.Collections.Generic;
using System.Text;
using SokoSolve.Common.Math;
using SokoSolve.Core.UI;

namespace SokoSolve.UI.Section{
    /// <summary>
    /// Allow execution 'working' status for controller, commands and other mini transaction-like code.
    /// </summary>
  public enum ExecutionStatus
  {
    None,
    Waiting,
    Working,
    Complete,
        AwaitingCallback,
        Incomplete,
    Error
  }

    /// <summary>
    /// The controller for a specific domain class has a list of possible commands and the current selection (context)
    /// </summary>
    /// <typeparam name="T">Domain Object</typeparam>
  public abstract class Controller<T>
  {
    /// <summary>
    /// Abstract constructor
    /// </summary>
    protected Controller()
    {
        logger = new ContextLogger();
      commands = new List<Command<T>>();
       
      statusText = "Startup...";
      status = ExecutionStatus.Waiting;
    }

        /// <summary>
        /// Provide icons for the commands
        /// </summary>
        public IconBinder IconBinder
        {
            get { return iconBinder; }
        }

        /// <summary>
        /// List of all commands (not editable)
        /// </summary>
    public IEnumerable<Command<T>> Commands
    {
      get { return commands; }
    }

        /// <summary>
        /// Current selection
        /// </summary>
        public List<T> Selection
        {
            get { return selection; }
        }

        /// <summary>
        /// Is there a selection
        /// </summary>
        public bool HasSelection
        {
            get { return selection != null && selection.Count > 0; }
        }

        /// <summary>
        /// Current Status Text
        /// </summary>
    public string StatusText
    {
      get { return statusText; }
    }

    /// <summary>
    /// Current Status
    /// </summary>
        public ExecutionStatus Status
    {
      get { return status; }
    }

        /// <summary>
        /// Allows intellegent internal context aware logging
        /// </summary>
      public ContextLogger Logger
      {
          get { return logger; }
      }

        /// <summary>
        /// Set the status
        /// </summary>
        /// <param name="newStatus"></param>
        /// <param name="text"></param>
      public virtual void SetStatus(ExecutionStatus newStatus, string text)
    {
      this.statusText = text;
      this.status = newStatus;
          Logger.Add(this, "Status: {0} - {1}.", newStatus, text);
    }

        /// <summary>
        /// Overloaded
        /// </summary>
        /// <param name="newStatus"></param>
        /// <param name="stringFormat"></param>
        /// <param name="parm"></param>
    public void SetStatus(ExecutionStatus newStatus, string stringFormat, params  object[] parm)
    {
        SetStatus(newStatus, string.Format(stringFormat, parm));
    }

        /// <summary>
        /// Update the UI, informs the commands and allows them to bind to the UI.
        /// </summary>
        /// <param name="context"></param>
    public abstract void UpdateUI(string context);


        /// <summary>
        /// Overload for <see cref="UpdateSelection"/>
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool UpdateSelectionSingle(T item)
        {
            List<T> helper = new List<T>(1);
            helper.Add(item);
            return UpdateSelection(helper);
        }

        /// <summary>
        /// Change the current selection
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
    public virtual bool UpdateSelection(List<T> newSelection)
    {
      List<T> oldSelection = this.selection;

      bool updated = false;
      if (oldSelection == null || oldSelection.Count == 0)
      {
        if (newSelection != null && newSelection.Count > 0) updated = true;
      }

      if (oldSelection != null && newSelection != null)
      {
        updated = !(oldSelection.Equals(newSelection));
      }

      this.selection = newSelection;

        Logger.Add(this, "UpdateSelection {0} - {1}", updated, newSelection);

      return updated;
    }

    /// <summary>
    /// Handle an error
    /// </summary>
    /// <param name="ex">Exception</param>
    /// <returns>false will rethrow</returns>
    public bool HandelException(Exception ex)
    {
      return false;
    }

        /// <summary>
        /// Perform a command via a URI
        /// </summary>
        /// <param name="appURI"></param>
        /// <returns></returns>
        public virtual bool PerformCommandURI(Uri appURI)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Register a new command for this controller
        /// </summary>
        /// <param name="newCommand"></param>
        protected void Register(Command<T> newCommand)
        {
            commands.Add(newCommand);
        }

        protected List<Command<T>> commands;
        private string statusText;
        private ExecutionStatus status;
        private List<T> selection;
        private ContextLogger logger;
        private IconBinder iconBinder = new IconBinder(new StaticImage(ResourceController.Singleton.GetInstance("Default.Tiles"), new VectorInt(16, 16)));

  }

  

  

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.