Build an AJAX-Enabled CMS with Visual WebGUI: Adding Menu Components (II)

Build an AJAX-Enabled CMS with Visual WebGUI: Adding Menu Components (II)

One of the basic components of any application is the menu system. It allows users to navigate across the application and launch the modules. Menu components should be customizable both on look and feel and functionality, and user should be able to develop and integrate them easily into application.The MiniCMS system begun in the first article in this series needs to have flexible menu components.

In the previous article, I designed and implemented the functionality of two elements of the menu system, as required by the MVC pattern: components handling the Model (menu configuration data) and the Controller, and also defined the interfaces to be implemented by the View part — actual menu control for user interace. Now I will create few implementations for the View part of the menu system — the actual components visible to the end user, which implements the functionality of the menu in the application.

Thanks to the modular approach of the menu system, we can create various menu View components, which, as long as you implement the same interface, can be integrated with the menu controller.

In the previous article I defined the two interfaces that define the View part of the menus: IWTMenu and IWTMenuItem. In this part I will create a few implementations for the menu’s View part, and design a small application empowering the menu components.

Implementing the WTTreeMenu component

The WTTreeMenu creates a menu that resembles the behavior of a tree menu. It extends the TreeView control, and implements the IWTMenu interface. The class diagram for the menu is shown in Figure 1.

Figure 1: Class diagrams for WTTreeMenu and WTTreeMenuItem.

We need to implement two components: the menu component WTTreeMenu and WTTreeMenu Item. Table 1 shows the public members of WTTreeMenu. Basically, the public interface of the menu just implements the interface IWTMenu.

Table 1: Public members of WTTreeMenu control.

Table 2 shows the public members of WTTreeMenuItem, which implements the properties defined in the IWTMenuItem interface.

Table 2: Public members of WTTreeMenuItem component.

The constructor is defined below. In the constructor I register the event handler for NodeMouseClick event, which is what we need to detect menu item selection.

public class WTTreeMenu : TreeView, IWTMenu { ?// Constructor ?public WTTreeMenu() : base() { ???this.NodeMouseClick +=  ???????new TreeNodeMouseClickEventHandler(MenuItemMouseClick); ?// ...}

The methods implementing the IWTMenu interface are simple, and are mainly warppers around private methods. InitMenu method just calls the FillTree private method, then set the initial status of the menu based on ExpandMode property.

public void InitMenu(List menuDefinition){ ?Nodes.Clear(); ?FillTree(Nodes, menuDefinition); ?if (m_expandMode == WTTreeExpandMode.MenuMode) ???CollapseAll(); ?else if (m_expandMode == WTTreeExpandMode.TreeMode) ???ExpandAll();}

The main workhorse here is FillTree. It is developed as recursive method, processing any object from the current level and calling recursive for sub-levels. For each entry in menuDef list, a new WTTreeMenuItem is created, attached to the currect Nodes collection, then if the current menu definition objects has child sub-menus, a recursive call is made to generate the menu entries for submenus. When the menu item was added to the menu, it fires MenuItemAdded event, which allow application to bind custom handler to perform additional processing on the menuitem. For example, the application might want to set the menu item with specific properties to customize its look. Through the binding between menu component and menu controller presented in previous article, the event fires back to controller, which is where the custom event handler should be bind to.

private void FillTree( ?TreeNodeCollection treeNodeCollection,  ?List menuDef){ ?// for each menu entry definition ?foreach (IWTMenuEntryDefinition menuEntryDef in menuDef){ ???// create the menu item object ???WTTreeMenuItem menuItem = new WTTreeMenuItem(menuEntryDef); ???// set various properties as TreeNode (the default font) ???TreeNode node = menuItem as TreeNode; ???if (node != null) ?????node.NodeFont = new System.Drawing.Font(this.Font.Name, this.Font.Size); ???// and add it to menu ???treeNodeCollection.Add(menuItem); ???// fire event on menu item adding ??? ???OnMenuItemAdded(menuItem); ???// if menu has child items, create the sub-memu ???if (menuEntryDef.HasChildMenus) ?????FillTree(menuItem.Nodes, menuEntryDef.ChildMenus); ?}}

When a menu item is selected, MenuItemSelected event is fired and the controller is notified, and it gets the reference to the menu item through WTMenuEventArgs parameter. The controller loads the corresponding module, which is linked back to the menu item through LinkedModule property. If user starts another module (by selecting another menu item) and leave some modules open, they became inactive. If later user selects again the menu entry for a module already loaded, the controller just activate the corresponding module.

When user closes a module, it must be detached from the corresponding menu item. This is accomplished through method DetachModule. It receives the reference to module to be detached, finds the associated menu item and un-link them. DetachModule scans the nodes collection of the tree menu recursively, to find associated menu item.

public bool DetachModule(IWTModule module){ ?return DetachModule(Nodes, module);}private bool DetachModule(TreeNodeCollection nodes, IWTModule module){ ?bool nodeFound = false; ?// for each menu item on current level ?foreach (TreeNode tn in nodes){ ???WTTreeMenuItem menuItem = tn as WTTreeMenuItem; ???if (menuItem != null) { ?????// if we found the linked module, detach it  ?????// and select parent menu item as active menu  ?????if (menuItem.LinkedModule == module) { ???????menuItem.LinkedModule = null; ???????SelectedNode = tn.Parent; ???????nodeFound = true; ???????break; ?????} ?????// if not found but currect menu item has sub-menus ?????// search in sub-menus ?????else if (tn.HasNodes) { ???????nodeFound = DetachModule(tn.Nodes, module); ???????if (nodeFound) ?????????break; ?????} ???} ?} ?return nodeFound;}

The actual functionality as menu is accomplished by intercepting NodeMouseClick event of TreeView, handled by MenuItemMouseClick method. When node click is detected, the menus react depending on ExpandMode property, then fire MenuItemClick event.

private void MenuItemMouseClick(object sender, TreeNodeMouseClickEventArgs e){ ?if (m_expandMode == WTTreeExpandMode.MenuMode){ ???CollapseAll(); ???ExpandBranch(e.Node); ?} ?IWTMenuItem menuItem = e.Node as IWTMenuItem; ?OnMenuItemClick(menuItem);}

If ExpandMode is MenuMode, only current menu branch should be expanded, and this all other tree branches must be collapsed.

private void ExpandBranch(TreeNode currentNode){ ?ExpandBranch(currentNode.Parent); ?if (currentNode.HasNodes) ???currentNode.Expand();}

Because the menu is actually a Treeview, you can customize it. In Figures 2, 3, and 4 you can see WTTreeMenu look based on various settings:

    * Figure 2: Menu with ExpandMode = TreeMode and show Plus/Minus signs (for nodes with sub-items

    * Figure 3: Menu with ExpandMode = MenuMode and show Plus/Minus signs (for nodes with sub-items

    * Figure 4: Menu with ExpandMode = TreeMode and hide Plus/Minus signs.

Figure 2: Menu with ExpandMode = TreeMode and show Plus/Minus signs (for nodes with sub-items

Figure 3: Menu with ExpandMode = MenuMode and show Plus/Minus signs (for nodes with sub-items

Figure 4: Menu with ExpandMode = TreeMode and hide Plus/Minus signs.

The WTTreeMenuItem class is derived from TreeNode. Its code contains just the properties defined by the interface IWTMenuItem. Figure 5 shows the sample application included in the download file, using WTTreeMenu.

Figure 5: Sample application using WTTreeMenu component.

WTIconPanelMenu Menu Component

The IconPanel component allows you to develop interfaces that feature Windows Control-Panel like behavior. It displays a list of icons arranged from left to righ and top to bottom. It partly ressembles the functionality of ListView control in LargeIcons mode, but with the advantage that the icons are not limited to 32 x 32 pixels, but can be at any size.

Using the IconPanel and IconPanelItem controls I implemented WTIconPanelMenu. At a certain moment, the menu shows the items on a certain level, and a first item, Back which allow to return to upper level.

In Figure 6, the right panel is shown a WTIconPanelMenu, created from the menu definition for Security tree menu. If users click in the right panel on Security icon, the IconPanel menu will show next menu level, as in Figure 7. Using the Back button, the user can return to the upper level.

Figure 6: Sample application using WTIconPanelMenu in right panel. By clicking on Security icon, the WTIconPanelMenu will show the submenu.

Figure 7: Sample application using WTIconPanelMenu in right panel, shown submenu ofSecurity menu item. By clicking on Back icon, the WTIconPanelMenu will reload the meni items on the first level.

devx-admin

devx-admin

Share the Post:
Apple Tech

Apple’s Search Engine Disruptor Brewing?

As the fourth quarter of 2023 kicks off, the technology sphere is abuzz with assorted news and advancements. Global stocks exhibit mixed results, whereas cryptocurrency

Revolutionary Job Market

AI is Reshaping the Tech Job Market

The tech industry is facing significant layoffs in 2023, with over 224,503 workers in the U.S losing their jobs. However, experts maintain that job security

Foreign Relations

US-China Trade War: Who’s Winning?

The August 2023 visit of Gina Raimondo, the U.S. Secretary of Commerce, to China demonstrated the progress being made in dialogue between the two nations.

Pandemic Recovery

Conquering Pandemic Supply Chain Struggles

The worldwide coronavirus pandemic has underscored supply chain challenges that resulted in billions of dollars in losses for automakers in 2021. Consequently, several firms are

Game Changer

How ChatGPT is Changing the Game

The AI-powered tool ChatGPT has taken the computing world by storm, receiving high praise from experts like Brex design lead, Pietro Schirano. Developed by OpenAI,

Apple Tech

Apple’s Search Engine Disruptor Brewing?

As the fourth quarter of 2023 kicks off, the technology sphere is abuzz with assorted news and advancements. Global stocks exhibit mixed results, whereas cryptocurrency tokens have seen a substantial

GlobalFoundries Titan

GlobalFoundries: Semiconductor Industry Titan

GlobalFoundries, a company that might not be a household name but has managed to make enormous strides in its relatively short 14-year history. As the third-largest semiconductor foundry in the

Revolutionary Job Market

AI is Reshaping the Tech Job Market

The tech industry is facing significant layoffs in 2023, with over 224,503 workers in the U.S losing their jobs. However, experts maintain that job security in the sector remains strong.

Foreign Relations

US-China Trade War: Who’s Winning?

The August 2023 visit of Gina Raimondo, the U.S. Secretary of Commerce, to China demonstrated the progress being made in dialogue between the two nations. However, the United States’ stance

Pandemic Recovery

Conquering Pandemic Supply Chain Struggles

The worldwide coronavirus pandemic has underscored supply chain challenges that resulted in billions of dollars in losses for automakers in 2021. Consequently, several firms are now contemplating constructing domestic manufacturing

Game Changer

How ChatGPT is Changing the Game

The AI-powered tool ChatGPT has taken the computing world by storm, receiving high praise from experts like Brex design lead, Pietro Schirano. Developed by OpenAI, ChatGPT is known for its

Future of Cybersecurity

Cybersecurity Battles: Lapsus$ Era Unfolds

In 2023, the cybersecurity field faces significant challenges due to the continuous transformation of threats and the increasing abilities of hackers. A prime example of this is the group of

Apple's AI Future

Inside Apple’s AI Expansion Plans

Rather than following the widespread pattern of job cuts in the tech sector, Apple’s CEO Tim Cook disclosed plans to increase the company’s UK workforce. The main area of focus

AI Finance

AI Stocks to Watch

As investor interest in artificial intelligence (AI) grows, many companies are highlighting their AI product plans. However, discovering AI stocks that already generate revenue from generative AI, such as OpenAI,

Web App Security

Web Application Supply Chain Security

Today’s web applications depend on a wide array of third-party components and open-source tools to function effectively. This reliance on external resources poses significant security risks, as malicious actors can

Thrilling Battle

Thrilling Battle: Germany Versus Huawei

The German interior ministry has put forward suggestions that would oblige telecommunications operators to decrease their reliance on equipment manufactured by Chinese firms Huawei and ZTE. This development comes after

iPhone 15 Unveiling

The iPhone 15’s Secrets and Surprises

As we dive into the most frequently asked questions and intriguing features, let us reiterate that the iPhone 15 brings substantial advancements in technology and design compared to its predecessors.

Chip Overcoming

iPhone 15 Pro Max: Overcoming Chip Setbacks

Apple recently faced a significant challenge in the development of a key component for its latest iPhone series, the iPhone 15 Pro Max, which was unveiled just a week ago.

Performance Camera

iPhone 15: Performance, Camera, Battery

Apple’s highly anticipated iPhone 15 has finally hit the market, sending ripples of excitement across the tech industry. For those considering upgrading to this new model, three essential features come

Battery Breakthrough

Electric Vehicle Battery Breakthrough

The prices of lithium-ion batteries have seen a considerable reduction, with the cost per kilowatt-hour dipping under $100 for the first occasion in two years, as reported by energy analytics

Economy Act Soars

Virginia’s Clean Economy Act Soars Ahead

Virginia has made significant strides towards achieving its short-term carbon-free objectives as outlined in the Clean Economy Act of 2020. Currently, about 44,000 megawatts (MW) of wind, solar, and energy

Renewable Storage Innovation

Innovative Energy Storage Solutions

The Department of Energy recently revealed a significant investment of $325 million in advanced battery technologies to store excess renewable energy produced by solar and wind sources. This funding will

Renesas Tech Revolution

Revolutionizing India’s Tech Sector with Renesas

Tushar Sharma, a semiconductor engineer at Renesas Electronics, met with Indian Prime Minister Narendra Modi to discuss the company’s support for India’s “Make in India” initiative. This initiative focuses on

Development Project

Thrilling East Windsor Mixed-Use Development

Real estate developer James Cormier, in collaboration with a partnership, has purchased 137 acres of land in Connecticut for $1.15 million with the intention of constructing residential and commercial buildings.

USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies in the USA. Through a

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its