Resizing and Reclaiming Dead Space Part 2

So, to follow up on my previous article I decided that there was even more that could be done to reclaiming dead space on MMS121.

Before we go too far, it’s worth pointing out that our MMS121 is modified to add Sorting Order 9, this adds some extra TextBoxes and labels down the bottom.

There are a lot of controls that are on the screen that are of no use or interest, hiding the unneeded controls doesn’t actually reclaim any space until we start moving controls around. So to that end.

Here’s what we have to work with.

And after some jscript magic, this is what we end up with.

There is still some space that can be reclaimed down the bottom but it creates some issues with our forklifts.

Now there was a lot of experimentation that went in to this. The hiding of the controls and the moving them was easy, not to mention resizing the ListView, maybe few hours of mucking around. The kicker was handling the ability to resize the Window and keep everything visible, stretched and sized properly – it’s wasn’t strictly needed for our purposes but I was curious.

The second issue was when the Sorting Order is changed or the user hits Refresh then it redraws the controls – all our added controls and changes effectively get reset see https://potatoit.wordpress.com/2010/12/23/where-did-my-control-go/ for some more detail.

We also manually change the visibility (yes, I know we don’t have to do it programmatically).

Other points of interest –

Controller.Host.HostTitle shows us the title of the Window.

Controller.RenderEngine.InquiryType is the current Sort Order

 

This can probably be slimmed down even more as some of the code is probably redundant as I continue to refine.
 

 

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
   {
           var gController;
           var gContent;
           var gDebug;
           var grdLVParent : Grid;
           var glvListView : ListView;
           var gbtnPickButton : Button;
           var gcmbSortOption : ComboBox;

       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;

           if(null != ihHost)
           {
               //MessageBox.Show(ihHost.HostTitle);
           }
           
           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;
                
                //ListObjects();
                
                gbtnPickButton = new Button();
                gbtnPickButton.Content = "PICK";
                Grid.SetColumnSpan(gbtnPickButton, 10);
                Grid.SetColumn(gbtnPickButton, 65);
                Grid.SetRow(gbtnPickButton, 2);
                content.Children.Add(gbtnPickButton);
    
                hideControls();
                moveControls();
                LVResize();
                
                gbtnPickButton.add_Click(OnClick);
                gbtnPickButton.add_Unloaded(OnUnloaded);
                
                grdLVParent.add_SizeChanged(OnGridSizeChanged);
                grdLVParent.add_Unloaded(OnGridUnloaded);
                goUp();
                }
        }
        
      

     private function findComboBox(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 < VisualTreeHelper.GetChildrenCount(parent);i++)
                        {
                            // retrieve the child object
                            var current : Object = VisualTreeHelper.GetChild(parent,i);
                            if(null != current)
                            {
                                // here we shall deterine the type of the new object
                                var objType = current.GetType();
                                
                                if(null != objType)
                                {
                                    // we're looking for the Name property, because
                                    // this is what I am interested in
                                    var objPropertyName = objType.GetProperty("Name");
                                    if(null != objPropertyName)
                                    {
                                        var strName = objPropertyName.GetValue(current);
                                        if(null != strName)
                                        {
                                            if(0 == String.Compare(strName,"WWQTTP"))
                                            {
                                                gcmbSortOption = current;
                                                //MessageBox.Show("Found!");
                                                //return (current);
                                                break;
                                            }
                                            
                                            // does the current object have any children?
                                            if(VisualTreeHelper.GetChildrenCount(current) >= 1)
                                            {
                                                // recurse down
                                                findComboBox(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)
                   {
                       for(var i : int = 0; i < lastParent.Children.Count; i++)
                       {
                           var con = findComboBox(lastParent);
                           if(null != con)
                           {
                               MessageBox.Show("xxFound!");
                           }
                           break;
                       }
                       
                       break;
                   }
               }
               // PART_ContentPanel
           }
        }



        
        private function hideControl(astrName : String)
        {
            var objControl = ScriptUtil.FindChild(gContent, astrName);
            if(null != objControl)
            {
                var objType = objControl.GetType();
                var objPropertyVisible = objType.GetProperty("Visibility");
                if(null != objPropertyVisible)
                {
                    objPropertyVisible.SetValue(objControl,Visibility.Collapsed);
                }
            }
        }

        private function hideControls()
        {
            hideControl("X__7714");        // "Auto alloc" button
            hideControl("X__7715");        // "Deallocate" button
            hideControl("X__7716");        // "Display Soft Allocation" button
            hideControl("XT_0168");        // "Apply" button
            hideControl("WUN0215");        // Basic U/M
            hideControl("WNOAA15");        // Over Alloc Mtd
            hideControl("WRO1915");        // Ref Order Cat
            hideControl("WRI0315");        // 'Delivery    no.:'

            hideControl("WSTA115");        //'Status    bal    ID:'
            hideControl("MWWHLO");        // 'WSN'
            hideControl("MMUNMS");        //
            hideControl("M3RIDI");        //
            hideControl("M9RIDI");
            hideControl("M9RIDI");
            hideControl("WBNOAA");
            hideControl("WWORCA");
            hideControl("WWH0115");
            hideControl("LBL_L20T2");
            hideControl("WOR0515");
            hideControl("WXORQT");
            hideControl("WPQ0515");
            hideControl("WXPQTT");
            hideControl("WLSTAS");
        }

        private function moveControl(astrName : String, aiColumn : int, aiRow : int)
        {
            var objControl = ScriptUtil.FindChild(gContent, astrName);
            if(null != objControl)
            {
                if(-1 != aiColumn)
                {
                    Grid.SetColumn(objControl, aiColumn);
                }
                if(-1 != aiRow)
                {
                    Grid.SetRow(objControl, aiRow);
                }
                
            }
        }

        private function moveControls()
        {
            moveControl("WIT0115", -1, 0);
            moveControl("MMITNO", -1, 0);
            moveControl("LBL_L32T3", -1, 0);
            moveControl("MM12103", -1, 1);
            moveControl("MM12103", -1, 1);
            moveControl("M3RIDN", -1, 1);
            moveControl("M3RIDL", -1, 1);
            moveControl("M3RIDX", -1, 1);
            
            moveControl("MM12105", -1, 2);
            moveControl("WXSQTY", -1, 2);
            
            moveControl("WAL0315", -1, 2);
            moveControl("WXALQT", 52, 2);
            moveControl("M9ALQT", 52, 2);
            
            glvListView.VerticalAlignment = VerticalAlignment.Stretch;
            var rdfRowDefinitionCollection : RowDefinitionCollection = grdLVParent.RowDefinitions;
            var iRowCount = rdfRowDefinitionCollection.Count;
            
            // make sure taht the margin is set to 0
            var mgMargin : Thickness = new Thickness(0,70,0,50);
            glvListView.Margin = mgMargin;
            glvListView.Height = double.NaN;

            Grid.SetRow(glvListView,3);
            // set the listview so it spans all of the rows
            //Grid.SetRowSpan(glvListView, iRowCount);
            moveControl("List", -1, 0);
        }

        public function LVResize()
        {
            glvListView.VerticalAlignment = VerticalAlignment.Stretch;
            var rdfRowDefinitionCollection : RowDefinitionCollection = grdLVParent.RowDefinitions;
            var iRowCount = rdfRowDefinitionCollection.Count;
            
            // make sure taht the margin is set to 0
            var mgMargin : Thickness = new Thickness(0,70,0,70);
            glvListView.Margin = mgMargin;
            glvListView.Height = double.NaN;
            glvListView.MinHeight = 200;
            Grid.SetRow(glvListView,3);
            // set the listview so it spans all of the rows
            Grid.SetRowSpan(glvListView, iRowCount-5);
            //changeMinimumHeight();
            moveControl("List", -1, 0);
        }

        private function changeMinimumHeight()
        {
            var rdfRowDefinitionCollection : RowDefinitionCollection = grdLVParent.RowDefinitions;
            var iRowCount = rdfRowDefinitionCollection.Count;
            for(var i : int = 0; i < iRowCount; i++)
            {
                rdfRowDefinitionCollection[i].MinHeight = 0;
            }
        }

        
        // 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 OnGridSizeChanged(sender : Object, e : SizeChangedEventArgs)
        {
            LVResize();
        }
        
        public function OnGridUnloaded(sender : Object, e : RoutedEventArgs)
        {
            grdLVParent.remove_Unloaded(OnGridUnloaded);
            grdLVParent.remove_SizeChanged(OnGridSizeChanged);
        }

        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, How Far is Too Far?, M3 / MoveX. Bookmark the permalink.

1 Response to Resizing and Reclaiming Dead Space Part 2

  1. Pingback: Some More Improvements to Resizing and Reclaiming Dead Space | Potato IT

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 )

Facebook photo

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

Connecting to %s