#region Disclaimer / License
// Copyright (C) 2010, Jackie Ng
// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core.WinForms;
using ICSharpCode.Core;
using Maestro.Shared.UI;
namespace Maestro.Base
{
///
/// The base class of all view content. Provides the default implementation of
///
[ToolboxItem(false)]
public partial class ViewContentBase : UserControl, IViewContent
{
///
/// Initializes a new instance of the class.
///
public ViewContentBase()
{
InitializeComponent();
}
private string _title;
///
/// The title of the view
///
public string Title
{
get
{
return _title;
}
set
{
if (_title != value)
{
_title = value;
var handler = this.TitleChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
}
///
/// Fires when the title has been changed
///
public event EventHandler TitleChanged;
///
/// Detrmines if this view can be closed by the user, note that this does not affect the method
/// in any way. All view content can still be programmatically closed if they inherit from and
/// does not override the default implementation of
///
public virtual bool AllowUserClose
{
get { return true; }
}
///
/// Closes the view. This raises the event
///
public virtual void Close()
{
CancelEventArgs ce = new CancelEventArgs(false);
var ceHandler = this.ViewContentClosing;
if (ceHandler != null)
ceHandler(this, ce);
if (ce.Cancel)
return;
var handler = this.ViewContentClosed;
if (handler != null)
handler(this, EventArgs.Empty);
}
///
/// Fired when the view has been closed internally
///
public event CancelEventHandler ViewContentClosing;
///
/// Displays an exception message
///
/// The exception object
public void ShowError(Exception ex)
{
ErrorDialog.Show(ex);
}
///
/// Displays an error message
///
/// The message
public void ShowError(string message)
{
MessageService.ShowError(message);
}
///
/// Displays an alert message
///
/// The title of this message
/// The message
public void ShowMessage(string title, string message)
{
MessageService.ShowMessage(message, title);
}
///
/// Make a request for confirmation
///
/// The title of the confirmation message
/// The message
///
/// true if confirmed, false otherwise
///
public bool Confirm(string title, string message)
{
return MessageService.AskQuestion(message, title);
}
///
/// Make a request for confirmation
///
/// The title of the confirmation message
/// The message template
/// The template values
///
/// true if confirmed, false otherwise
///
public bool ConfirmFormatted(string title, string format, params string[] args)
{
return MessageService.AskQuestion(string.Format(format, args), title);
}
///
/// The underlying control
///
public Control ContentControl
{
get { return this; }
}
private string _description;
///
/// The view's description, this is the ToolTip content
///
public string Description
{
get
{
return _description;
}
set
{
if (_description != value)
{
_description = value;
var handler = this.DescriptionChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
}
///
/// Raised when the description has changed
///
public event EventHandler DescriptionChanged;
///
/// Makes this content active
///
public void Activate()
{
var handler = this.ViewContentActivating;
if (handler != null)
handler(this, EventArgs.Empty);
}
///
/// Fired when the view is going to hide
///
public event EventHandler ViewContentHiding;
///
/// Fired when the view, which was hidden is now being shown
///
public event EventHandler ViewContentShowing;
///
/// Fired when the view is activating
///
public event EventHandler ViewContentActivating;
///
/// Conceals the control from the user.
///
///
///
///
///
///
///
void IViewContent.Hide()
{
var handler = this.ViewContentHiding;
if (handler != null)
handler(this, EventArgs.Empty);
}
///
/// Indicates whether this view is attached to a workbench
///
public bool IsAttached
{
get;
internal set;
}
///
/// Indicates the default region this view content will be put in
///
public virtual ViewRegion DefaultRegion
{
get { return ViewRegion.Document; }
}
///
/// Fired when the view has been closed internally
///
public event EventHandler ViewContentClosed;
}
}