DockPanel Initialization

DockPanel Initialization

mwillia1
Enthusiast Enthusiast
458 Views
6 Replies
Message 1 of 7

DockPanel Initialization

mwillia1
Enthusiast
Enthusiast

What is the best way to initialize a DockPanel's control before a selection is made?  The selection changed event doesn't seem to fire if a login occurs and no selection is active.

 

Vault 2026 - C#

0 Likes
459 Views
6 Replies
Replies (6)
Message 2 of 7

Markus.Koechl
Autodesk
Autodesk

I suggest initializing the dock panel controls that require login on startup. You can review a coding sample here: Autodesk.TS.PlmDesktopExtensions/Autodesk.TS.VltPlmAddIn/VaultExplorerExtension.cs at master · koech...

I hope this helps.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 7

mwillia1
Enthusiast
Enthusiast

I meant Vault login.  Not an external login.  I would like to populate a DockPanel control with user information after the user logs into Vault possibly even before a selection is made to fire the SelectionChanged event.  This would require having access to an instance of the control in the OnLogon method.  So far the only way I have found to get the control passed in a DockPanel constructor is to scan Application.OpenForms for all controls until I find the one added to the DockPanel.  I just thought there might be a more official way to initialize a DockPanel's control w/o needing the context from the SelectionChanged event.

0 Likes
Message 4 of 7

Markus.Koechl
Autodesk
Autodesk

@mwillia1: I am sorry, I misunderstood, and hope that the following proven approach matches your objective: Let's say, your dockpanel has a grid control, which should be initialized with Vault UI theme support, context menu, and cached information retrieved from Vault server one time instead of on selection changed events.
I implemented this likewise:

- The dock panel is registered during startup (<UserControl> = myPanelGrid in later code snippets):

IEnumerable<DockPanel> IExplorerExtension.DockPanels()
        {
            List<DockPanel> dockPanels = new List<DockPanel>();

            DockPanel myPanel = new DockPanel(
                Guid.Parse("<GUID>"),
                "My Panel's DisplayName",
                typeof(<UserControl>));

            myPanel.SelectionChanged += myPanel_SelectionChanged;
            dockPanels.Add(myPanel);

            return dockPanels;
        }

 - The UserControl's constructor adds the theme support, context menu, and variables to preload data:

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="myPanelGrid"/> class.
        /// </summary>
        public myPanelGrid()
        {
            InitializeComponent();

            _dataGrid = gridControl1;

            _currentTheme = VaultmyPanel.mCurrentTheme.ToString();
            ApplyTheme(_currentTheme);
            UpdateTheme(_currentTheme);
        }

        #endregion

        #region Overrides

        /// <summary>
        /// Raises the <see cref="Control.Load"/> event.
        /// </summary>
        /// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            InitializeBarManager();
            InitializeContextMenu();
            SetupEventHandlers();
        }

        #endregion

Finally, the OnLogOn activates the theme and preloads data:

        void IExplorerExtension.OnLogOn(IApplication application)
        {
            VaultApplication = application;
            connection = application.Connection;

            // Load property definitions for both FILE and ITEM entity classes
            mFilePropDefs = connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId(EntityClassFile);
            mItemPropDefs = connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId(EntityClassItem);

            // do more stuff that myPanelGrid needs
//...

            // Register theme support
            mCurrentTheme = VDF.Forms.Library.CurrentTheme;
            VDF.Forms.Library.ThemeChanged += Library_ThemeChanged;
            myPanelGrid.UpdateTheme(VDF.Forms.Library.CurrentTheme.ToString());
        }

 Does this resonate with your objective?



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 5 of 7

mwillia1
Enthusiast
Enthusiast

That's what I'm trying to do but my question is where do you get the instance of myPanelGrid to use in the following line?

myPanelGrid.UpdateTheme(VDF.Forms.Library.CurrentTheme.ToString());

 

0 Likes
Message 6 of 7

mwillia1
Enthusiast
Enthusiast

Maybe this explains it better:  From what I can tell the DockPanel constructor will only use default constructor of a control so you have to get an instance of the control set up by the DockPanel to call some sort of Init function.

//Method 1
//private CustomControl _customControl;

public IEnumerable<DockPanel> DockPanels()
{
    var guid = new Guid("some guid");
    var dockPanel = new DockPanel(guid,
                                 "Title",
                                  typeof(CustomControl),
                                  true);
    //Method 1:
    //_customControl = ???

    return [dockPanel];
}

 

public void OnLogOn(IApplication application)
{
    //Method 1
    _customControl.Init(customArg);

    //Method 2
    //CustomControl customControl = ???
    customControl.Init(customArg);
}
0 Likes
Message 7 of 7

Markus.Koechl
Autodesk
Autodesk

For a full implementation sample, the SDK extended the HelloWorld sample extension with a DockPanel that loads a browser control. Did you have a look at it?
If I am not mistaken, the typeof(BrowserControl) expression passes the Type metadata to the DockPanel constructor, which likely handles instantiation internally (e.g., via Activator.CreateInstance) when the dock panel is initialized/loaded.
My sample and snippets before extend the constructor by overriding OnLoad(), e.g., to make the theme handler available before the user selection drives the content of the dock panel.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes