Some More Improvements to Resizing and Reclaiming Dead Space

In a previous posting I mentioned that we had a modification around MMS121 so we could simplify panel down for staff who use our forklifts. (https://potatoit.wordpress.com/2010/12/23/resizing-and-reclaiming-dead-space-part-2/), it did however turn out that some of the assumptions that I made meant that the end result, though better than what it was previously, could easily be messed up by staff.

I also needed to refine some of the code so I could reduce the window down a little further without everything going south. So what I decided to do was take a look at the problem afresh – it’s been a wee while since I looked at the code and I was definitely in the situation of can’t see the forest for the trees.

So what I present below is the ‘feature’ complete πŸ˜‰ version that I am rolling out to my forklift users.

Instead of fudging everything and competing against the modification and getting horribly messed up when the ContainerPanel reaches its minimum size, we now check the size of the ContainerPanel Grid, this is the Grid upon which things like the Inquiry Type are attached.

Through some trial and error I found the minimum size that we get to before we get scroll bars (yes, I know, I should have just looked at the minimum size, but our modification seemed to be doing some odd things – or maybe it was the hour :-)). So, when we hit this magic height where the scrollbars appear, we change our resizing logic.

We also look at the information that Lawson provide in their jscript guide and some of our Row settings are now hardcoded.

Whenever the size of the ContainerPanel Grid changes we fire an event. This event will then resize our ListView and move the controls under that ListView based upon the new size offset against the ‘magic height’.

The code will also only apply when we are set to Inquiry Type 9 (this is our modified screen).

The raw code I am about to post won’t really work for anyone but us, but hopefully some of the functions and concepts will be useful.

This particular challenge has been rather good for me, its opened my eyes a little more and I hope illustrates and emphasises that this is a journey of discovery for me πŸ™‚ so what I do may make the poor developers at Lawson cringe but hey… πŸ™‚

Β 

// Name: MMS121
// Version: 1.00 2010-12-13
// Description: Resizes the ListView so it uses all of the 
//  windows real-estate
//
// Revision History:
//	1.00	2010-12-13	* Completed
//  1.006   2011-02-08  * adjusted so it better suits our needs
//                          - we now check for a specific height on the ContainerPanel which we use
//                            as an offset for the height of the ListView
//                          - the ListView is now offset correctly and aligned against the proper rows

import System;
import System.Text;
import System.Windows;
import System.Windows.Controls;
import System.Windows.Media;
import System.Windows.Media.Media3D;
import MForms;
import Mango.UI.Core;
import Mango.UI.Core.Util;
import Mango.UI.Services;
import Mango.Services;

package MForms.JScript
{
    class MMS121_006
    {
        var gController;
        var gContent;
        var gDebug;
        var grdLVParent : Grid;
        var glvListView : ListView;
        var gbtnPickButton : Button;
        var gcmbSortOption : ComboBox;

        // this is the Grid that is above the Combobox which selects our view
        var ggrdContainerPanel : Grid;

        // this is the magical height of the ContainerPanel when we end up with a verical scrollbar
        var gdblMagicHeight : double = 666.0;

        public function Init(element: Object, args: Object, controller : Object, debug : Object)
        {
            var ihHost : Mango.Services.IInstanceHost = controller.Host;
            var fweElement : System.Windows.FrameworkElement;
            var objWinData : Mango.Core.Persistance.WindowData;
       	
            // we will only work if we are against inquiry type 9
            if(String.Compare("9",controller.RenderEngine.InquiryType) == 0)
            {
                gController = controller;
                gDebug = debug;
	
                var content : Object = controller.RenderEngine.Content;
                gContent = content;
				
                var lcListControl : ListControl = controller.RenderEngine.ListControl;
	
                glvListView  = lcListControl.ListView;
				 
                grdLVParent = glvListView.Parent;
				
                gbtnPickButton = new Button();
                gbtnPickButton.Content = "PICK";
                Grid.SetColumnSpan(gbtnPickButton, 10);
                Grid.SetColumn(gbtnPickButton, 65);
                Grid.SetRow(gbtnPickButton, 2);
                content.Children.Add(gbtnPickButton);
	
                hideControls();
                moveControls();
                
				
                gbtnPickButton.add_Click(OnClick);
                gbtnPickButton.add_Unloaded(OnUnloaded);
				
                //grdLVParent.add_SizeChanged(OnGridSizeChanged);
                grdLVParent.add_Unloaded(OnGridUnloaded);
                goUp();
				
                if(null != gcmbSortOption)
                {
                    gcmbSortOption.add_SelectionChanged(onComboBoxSelectionChanged)
                }
                if(null != ggrdContainerPanel)
                {
                    ggrdContainerPanel.add_SizeChanged(OnContentGridSizeChanged);
                    LVResizeX(ggrdContainerPanel.ActualHeight);
                    moveModificationControls();
                }
            }
        }
		
        public function onComboBoxSelectionChanged(sender : Object, e : SelectionChangedEventArgs)
        {
            // MessageBox.Show(gcmbSortOption.SelectedIndex + Environment.NewLine + e.AddedItems[0]);
            // MessageBox.Show(gcmbSortOption.SelectedItem.ToString());
            if(7 == gcmbSortOption.SelectedIndex)
            {
                hideControls();
                moveControls();
                LVResizeX(ggrdContainerPanel.ActualHeight);
                moveModificationControls();
                //MessageBox.Show("xxxxxx");
            }
        }

        private function displayChildren(parent : Object, depth : int, debug : Object)
        {
            try
            {
                if(null != parent)
                {
                    // get the type of our object, we do this
                    // so we can check if the object inherits
                    // from a DependencyObject
                    var parentobjType : Type = parent.GetType();
                    if(parentobjType.IsSubclassOf(DependencyObject) == true)
                    {
                        for(var i=0; i = 1)
                                            {
                                                // recurse down
                                                displayChildren(current, depth+1, debug);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch(ex)
            {
                debug.WriteLine("!-! Exception: " + ex.Message + " " + ex.StackTrace);
            }
        }

        private function goUp()
        {
            var parent : Object = gContent;
            var lastParent : Object = gContent;
	
            // here we will loop UP the VisualTree seeking the top
            while(null != (parent = VisualTreeHelper.GetParent(parent)))
            {
                lastParent = parent;
	           
                var objType = lastParent.GetType();
                var objPropertyName = objType.GetProperty("Name");
                var strName : String = objPropertyName.GetValue(lastParent)
	           
                if(null != strName)
                {
                    if(String.Compare(strName,"ContainerPanel") == 0)
                    {
                        ggrdContainerPanel = lastParent;
                        //MessageBox.Show("ContainerPanel Type = " + objType);
                        for(var i : int = 0; i < lastParent.Children.Count; i++)
                        {
                            var con = displayChildren(lastParent);
                            if(null != con)
                            {
                                MessageBox.Show("xxFound!");
                            }
                            break;
                        }
                        break;
                    }
                }
            // PART_ContentPanel
            }
        }

        // retrieve the combined height of a specific set of rows
        // we do this so we can determine the height of the ListView
        // which is attached to specific rows
        private function getCombinedRowDefHeight(aiStartRow : int, aiEndRow : int)
		{
            var result : double = 0.0;
			var rdfRowDefinitionCollection : RowDefinitionCollection = grdLVParent.RowDefinitions;
			var iRowCount = rdfRowDefinitionCollection.Count;
			for(var i : int = aiStartRow; i = gdblMagicHeight)
            {
                glvListView.VerticalAlignment = VerticalAlignment.Stretch;
                glvListView.MinHeight = getCombinedRowDefHeight(3,20);
                setTopModificationControls(0.0);
            }
            else
            {
                glvListView.VerticalAlignment = VerticalAlignment.Top;
                glvListView.MinHeight = getCombinedRowDefHeight(3,20) + dblOffset;
                setTopModificationControls(dblOffset);
            }
            
            Grid.SetRow(glvListView, 3);
            Grid.SetRowSpan(glvListView, 18);
        }

        // We will use the interactive launching of the Normal Option
        private function listOptionNormal()
        {
            try
            {
                if(null != gController)
                {
                    gController.PressKey("F21");
                }
                else
                {
                    MessageBox.Show("Controller Class not initiated");
                }
            }
            catch(ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
            }
        }

        public function OnContentGridSizeChanged(sender : Object, e : SizeChangedEventArgs)
        {
            LVResizeX(e.NewSize.Height);
            moveModificationControls();
//             // some debugging information for us
//            var itno = ScriptUtil.FindChild(gContent, "WBITNO");
//            if(null != itno)
//            {
//                itno.Text = e.NewSize.Height.ToString();
//            }
        }

        public function OnGridUnloaded(sender : Object, e : RoutedEventArgs)
        {
            grdLVParent.remove_Unloaded(OnGridUnloaded);
            ggrdContainerPanel.remove_SizeChanged(OnContentGridSizeChanged);
        }

        public function OnClick(sender: Object, e: RoutedEventArgs) 
        {
            listOptionNormal();
        }

        public function OnUnloaded(sender: Object, e: RoutedEventArgs) 
        {
            gbtnPickButton.remove_Click(OnClick);
            gbtnPickButton.remove_Unloaded(OnUnloaded);
        }
    }
}

This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s