public void handleEvent(Event event) {
   Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
   String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
   if (element instanceof MMenuItem) {
     MMenuItem itemModel = (MMenuItem) element;
     if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
       Object obj = itemModel.getParent();
       if (!(obj instanceof MMenu)) {
         return;
       }
       MenuManager parent = getManager((MMenu) obj);
       if (itemModel.isToBeRendered()) {
         if (parent != null) {
           modelProcessSwitch(parent, itemModel);
         }
       } else {
         IContributionItem ici = getContribution(itemModel);
         clearModelToContribution(itemModel, ici);
         if (ici != null && parent != null) {
           parent.remove(ici);
         }
         if (ici != null) {
           ici.dispose();
         }
       }
     }
   }
   if (UIEvents.UIElement.VISIBLE.equals(attName)) {
     if (element instanceof MMenu) {
       MMenu menuModel = (MMenu) element;
       MenuManager manager = getManager(menuModel);
       if (manager == null) {
         return;
       }
       manager.setVisible(menuModel.isVisible());
       if (manager.getParent() != null) {
         manager.getParent().markDirty();
       }
     } else if (element instanceof MMenuElement) {
       MMenuElement itemModel = (MMenuElement) element;
       Object obj = getContribution(itemModel);
       if (!(obj instanceof ContributionItem)) {
         return;
       }
       ContributionItem item = (ContributionItem) obj;
       item.setVisible(itemModel.isVisible());
       if (item.getParent() != null) {
         item.getParent().markDirty();
       }
     }
   }
 }
 @Override
 public void dispose() {
   if (this.widget != null) {
     this.widget.dispose();
     this.widget = null;
   }
   disposeOldImages();
   super.dispose();
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jface.action.ContributionItem#setParent(org.eclipse.jface
  * .action.IContributionManager)
  */
 public void setParent(IContributionManager parent) {
   if (getParent() instanceof IMenuManager) {
     IMenuManager menuMgr = (IMenuManager) getParent();
     menuMgr.removeMenuListener(menuListener);
   }
   if (parent instanceof IMenuManager) {
     IMenuManager menuMgr = (IMenuManager) parent;
     menuMgr.addMenuListener(menuListener);
   }
   super.setParent(parent);
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.ContributionItem#dispose()
  */
 public void dispose() {
   if (elementRef != null) {
     commandService.unregisterElement(elementRef);
     elementRef = null;
   }
   if (commandListener != null) {
     command.getCommand().removeCommandListener(commandListener);
     commandListener = null;
   }
   command = null;
   commandService = null;
   disposeOldImages();
   super.dispose();
 }