Wednesday, February 25, 2009

XAF Usability: Limit SpinEdit values with XAF Rules

In this new XAF Usability post, we will show how you can limit max and min values dynamically when editing integer numeric properties with SpinEdit controls.

Say your project has a XAF entity called Customer with an integer property PaymentDay aimed to store the number of the day of the month that each Customer schedules payments to his providers. As days of month are known in advance, and limited in number, a range rule is defined at property level to set max and min values for such property.


Once written down, your source code might look like this:

public partial class Customer : BaseObject
{
[...]
private int _PaymentDay;
[DisplayName("Payment day")]
// Define a rule to set min and max value for the property
[RuleRange("Customer.PaymentDay.RR", "Save", 0, 31)]
public virtual int PaymentDay
{
get { return _PaymentDay; }
set { SetPropertyValue("PaymentDay", ref _PaymentDay, value); }
}
[...]
}

Ideally, XAF might set Max and Min properties according to the rule range when rendering that kind of property thru a SpinEditor. But the truth is that it won’t do it, so you will be the one who have to. You can do it by adding a new ViewController to Module.Win project of your Solutions. Such ViewController would target any DetailView in your application, checking for every IntegerPropertyEditor created. When a property editor of that kind is added to the DetailView, it will use Application ValidationModule’s RulesWithoutSerializer method to get the rule associated to the property corresponding to the PropertyEditor being created. If the type of Rule is RuleRange, then its Min and Max values are used to set IntegerPropertyEditor’s Min and Max properties, as shown in the following code:

public partial class CustomSpinRuleRange : ViewController
{
public CustomSpinRuleRange()
{
InitializeComponent();
RegisterActions(components);
// Target ViewController to any DetailView in your application
this.TargetViewType = ViewType.DetailView;
}

protected override void OnActivated()
{
// Suscribe LayoutManager’s ItemCreated event handler to be able to check for every item created in the DetailView
((DevExpress.ExpressApp.Win.Layout.WinLayoutManager)((View as DetailView).LayoutManager)).ItemCreated += new EventHandlerdevexpress.expressapp.win.layout.ItemCreatedEventArgs(CustomSpinRange_ItemCreated);
base.OnActivated();
}

void CustomSpinRange_ItemCreated(object sender, DevExpress.ExpressApp.Win.Layout.ItemCreatedEventArgs e)
{
// For every new item created in the DetailView, check if it’s an IntegerPropertyEditor
if (e.DetailViewItem != null && e.DetailViewItem is DevExpress.ExpressApp.Win.Editors.IntegerPropertyEditor)
{
DevExpress.ExpressApp.Win.Editors.IntegerPropertyEditor lIntegerPropertyEditor = (DevExpress.ExpressApp.Win.Editors.IntegerPropertyEditor)e.DetailViewItem;
if (lIntegerPropertyEditor != null)
{
//If a PropertyEditor is being created, check if has an associated RuleRangeAttribute
DevExpress.Persistent.Validation.RuleRangeAttribute lRuleRangeAttribute = ((DevExpress.ExpressApp.Editors.PropertyEditor)
(lIntegerPropertyEditor)).MemberInfo.FindAttribute();
if (lRuleRangeAttribute != null)
{
// If a RuleRangeAttribute is was found, get an instance of the Application’s ValidationModule
// to gain access to validation rules
ValidationModule lModule = (ValidationModule)Application.Modules.FindModule(typeof(ValidationModule));
if (lModule != null)
{
DevExpress.Persistent.Validation.IRule lIRule;
// Use ValidationModule’s RulesWithoutSerializer method to get the rule associated to
// the property corresponding to the PropertyEditor being created in a safely manner
if (lModule.RulesWithoutSerializer.TryGetValue(lRuleRangeAttribute.Name, out lIRule))
{
// Once the rule was gotten, set PropertyEditor’s Min and Max values to RuleRange’s ones
DevExpress.Persistent.Validation.RuleRange lRuleRange = lIRule as DevExpress.Persistent.Validation.RuleRange;
lIntegerPropertyEditor.Control.Properties.MinValue = Convert.ToInt32(lRuleRange.Properties.MinimumValue);
lIntegerPropertyEditor.Control.Properties.MaxValue = Convert.ToInt32(lRuleRange.Properties.MaximumValue);
}
}
}
}
}
}
}

When the application is run and users edit Payment day property, they are not allowed to spin value under 0 or above 31. On the other side, if they type a value out of the valid range, a validation exception will raise when Customer entity is saved as XAF checks rule “Customer.PaymentDay.RR” for “Save” context.

Monday, February 16, 2009

XAF Usability: Show Expand Button in Layout groups

Our second post on Usability in XAF will show you how to improve user experience while using complex layouts where Property Editors have been organized in Layout Groups.

When entities have a large number of properties or one or more of its properties require large Property Editors, layout design for such entities soon become uncomfortable to read, navigate and edit by users. XAF's provides two solutions for this situation: tabs and layout item groups.

While tabs allow developers to arrange a larger number of controls on a form, they have two main drawbacks. First, if more than one tab is used vertical space consumed is that of the taller tab. Second, they are somewhat old-fashion looking. You can overcome all this using layout item groups. But once at runtime, you should realize that XAF’s item groups have fixed vertical size and that they don’t provide any user interface to collapse nor expand them.


That’s because item groups’ ExpandButtonVisible property is set to true by default, so it’s hidden for every group you create. You can switch it to true by means of a ViewController targeted to ViewType.DetailView as shown in the following code:


public partial class CustomDetailViewGroupBehaviour : ViewController
{
public CustomDetailViewGroupBehaviour()
{
InitializeComponent();
RegisterActions(components);
// Target ViewController to any DetailView in your application
TargetViewType = ViewType.DetailView;
}

protected override void OnActivated()
{
base.OnActivated();
// Suscribe LayoutManager’s ItemCreated event handler to be able to check for every item created in the DetailView
((WinLayoutManager)((View as DetailView).LayoutManager)).ItemCreated += new EventHandler(CustomDetailViewGroupBehaviour_ItemCreated);
}

protected override void OnDeactivating()
{
// Unsuscribe LayoutManager’s ItemCreated event handler
((WinLayoutManager)((View as DetailView).LayoutManager)).ItemCreated -= new EventHandler(CustomDetailViewGroupBehaviour_ItemCreated); base.OnDeactivating();
}

void CustomDetailViewGroupBehaviour_ItemCreated(object sender, ItemCreatedEventArgs e)
{
// For every new item created in the DetailView, check if it’s a layout item group
if (e.Item is LayoutControlGroup)
{
LayoutControlGroup lLayoutControlGroup = (LayoutControlGroup)e.Item;

//If a group is being created, check if ExpandButtonVisible needs to be visible
//(i.e. only for non-nested groups with text located on top)

if (((lLayoutControlGroup.TextLocation == DevExpress.Utils.Locations.Default
lLayoutControlGroup.TextLocation == DevExpress.Utils.Locations.Top))
&& !(lLayoutControlGroup.Parent != null))
lLayoutControlGroup.ExpandButtonVisible = true;
}
}
}

On the other hand, you can check for specific groups too, by checking its Text property replacing previous If block with the following code:

if (lLayoutControlGroup.Text.StartsWith("ContactDetails"))

And that’s what you get when you run your application with the new ViewController in place:

Expanded groups:


Contact groups collapsed:

Monday, January 19, 2009

Launching Freelander’s Blog...

Today we’re launching Freelander Solution Developer’s blog. Actually we struggled with what would be the first post. How would we start this blog? And then realized it’s just like walking into a room full of people you’ve never met - we’ll introduce ourselves to you. It seems like the polite thing to do, right?

First, the company: we are Freelander Solutions Developer – an innovative company that is marketing and developing software and services based on XAF, the award winning eXpressApplication Framework from DevExpress.

That’s it. If you want to read more about the company, take a look at our new website, also launched today. That will tell you everything you need to know about the company, what we do, detail all our products and services, and so on.

This space isn’t about our company. This space is about software development with XAF and people working on it with whom we are willing to share knowledge and expertise, whether they are freelance or part of small or large development teams. Back in 2006 we chose to use XAF as our main development tool. After all that months, we feel the need to create a forum for dialogue around XAF, its development techniques and how it changes the way we create applications.

We will be posting tech articles on XAF in a timely basis to keep you in touch with our last achievements in Windows and web applications, as well as tips and tricks on using DevExpress’ tools. Even though we are a spanish company, all post will be published in english, which we adopted as the official language for this blog to ease your experience as a member and our work as publishers.

So bookmark this blog, email to a friend/colleague or add our RSS feed, and stay tunned for news about development with XAF. And of course, we’d like getting your feedback on this blog — and what you want to see discussed (and showcased) in the future.

Until next time…


Freelander development team

Poniendo en marcha el Blog de Freelander…

Hoy ponemos en marcha el blog de Freelander Solutions Developer. ¿Cómo empezar este blog? En un principio, fue difícil decidir cómo sería este primer post.Y entonces nos dimos cuenta de que es como entrar en una habitación llena de gente a la que nunca antes has visto – bien pues vamos a presentarnos. Parace ser la mejor manera de hacerlo, ¿no?

En primer lugar, la empresa: somos Freelander Solutions Developer – una innovadora empresa que es comercializa y desarrolla software y servicios basados en XAF, el premiado eXpressApplication Framework de DevExpress.

Si deseas saber más acerca de nosotros, puedes visitar nuestro nuevo sitio web, que también se ha puesto en marcha hoy. Allí encontrarás todo lo que necesitas saber acerca de la empresa, lo que hacemos, detalles de nuestros productos y servicios, etc.

Este espacio no está dedicado a nuestra empresa. Este espacio trata sobre desarrollo de software con XAF y sobre las personas que trabajan en ello, con las que queremos compartir conocimientos y experiencia, ya sean freelance o parte de equipos de desarrollo grandes o pequeños. En el año 2006 decidimos utilizar XAF como nuestra principal herramienta de desarrollo. Después de todos estos meses, sentimos la necesidad de crear un foro para el diálogo sobre XAF, sus técnicas de desarrollo y cómo ha cambiado la manera en la que creamos aplicaciones.

Publicaremos artículos técnicos sobre XAF de forma periódica para mantenerte en contacto con nuestros progresos en aplicaciones Windows y web, así como trucos en el uso de las herramientas de DevExpress. Aunque somos una empresa situada en España, publicaremos todos los artículos en inglés, lengua que hemos adoptado como oficial para este blog con el objetivo de facilitar tu experiencia como lector y nuestro trabajo como editores.

Así que añade este blog a tus favoritos, envíalo por correo a un amigo/colega o añade nuestro feed RSS, y mantente informado con noticias acerca de desarrollo en XAF. Y, por supuesto, nos encantaría contar con tu participación y tus opiniones acerca de este blog — y sobre los temas que crees que deberían tratarse en el futuro.

Hasta muy pronto…

Equipo de desarrollo de Freelander

Freelander, in the Technology special issue of 'La Vanguardia'

Spanish newspaper La Vanguardia includes today in its special issue about Technology an interview with Sebastià Prat, CEO of Freelander Solutions Developer, who presents latests news on company’s main businesses and development strategy.

click image to enlarge

Freelander, en el monográfico especial de Tecnología de 'La Vanguardia'

El periódico La Vanguardia publica hoy en su Monográfico Especial de Tecnología una entrevista a Sebastià Prat, Gerente de Freelander Solutions Developer, quien presenta las novedades acerca de las líneas de negocio y la estrategia de desarrollo de nuestra empresa.

clik en la imagen para ampliar

XAF articles: the Usability series

When applied to human-computer interaction and computer science, Wikipedia defines usability as


elegance and clarity with which the interaction with a computer program or a web site is designed

Whether your applications are Windows-based o web-based, XAF does a noticeable amount of usability management for you. However, there are some enhancements you can apply to the User Interface that can make the difference, improving user experience and giving a unique touch to your applications.

Our first XAF articles will be focused on usability and will show how you can bring your users applications with a richer user interface with only a little effort. All of them have been used in our products with great results.

The series begins with

XAF Usability: Highlight focused items in DetailViews

and goes on with

XAF Usability: Show Expand Button in Layout groups

and

XAF Usability: Limit Spin values with XAF rules

XAF Usability: Highlight focused items in DetailViews

We all agree that DevExpress’ skins are very cool, but you can get even a cooler user interface as well as an enhanced usability for you Windows Forms Applications with a small but effective piece of code that will let you highlight and change background color for every focused item in a DetailView.

OptionsView.HighlightFocusedItem property allows you to get or set whether focused layout items are highlighted according to the current skin. If the HighlightFocusedItem option is set to true, the layout item containing the focused control is painted according to the current skin.

At the same time, you can use Appearance.ControlFocused.BackColor property to override skin’s backcolor and set the one that suits your needs, giving your users a constant visual clue of where keyboard entry is going to, whatever the focused layout item is.

To achieve it, add a new ViewController with its target type set to ViewType.DetailView. Then, in OnActivated event, get the actual DetailView and set OptionsView.HighlightFocusedItem and Appearance.ControlFocused.BackColor properties for the DetailView’s LayoutControl.

public partial class HighlightFocusedItemController : ViewController
{
public HighlightFocusedItemController()
{
InitializeComponent();
RegisterActions(components);
TargetViewType = ViewType.DetailView;
}

protected override void OnActivated()
{
base.OnActivated();

DetailView lDet = View as DetailView;
if (lDet != null)
{
((LayoutControl)(((WinLayoutManager)(lDet.LayoutManager)).Container)).OptionsView.HighlightFocusedItem = true;
((LayoutControl)(((WinLayoutManager)(lDet.LayoutManager)).Container)).Appearance.ControlFocused.BackColor = System.Drawing.Color.FromArgb(255, 201, 84);
}
}

protected override void OnDeactivating()
{
base.OnDeactivating();
}
}

Run your application, open any DetailView and see how it looks like. Here you have the screenshots.

Focused item before adding the ViewController


Focused item after adding the ViewController


Keep in mind that OptionsView.HighlightFocusedItem is in effect when a skinning paint scheme is applied and the OptionsView.AllowItemSkining property is set to true.