public Object createWidget(final MUIElement element, Object parent) {
    if (!(element instanceof MPart) || !(parent instanceof Composite)) return null;

    Widget parentWidget = (Widget) parent;
    Widget newWidget = null;
    final MPart part = (MPart) element;

    final Composite newComposite =
        new Composite((Composite) parentWidget, SWT.NONE) {

          /**
           * Field to determine whether we are currently in the midst of granting focus to the part.
           */
          private boolean beingFocused = false;

          /*
           * (non-Javadoc)
           *
           * @see org.eclipse.swt.widgets.Composite#setFocus()
           */
          @Override
          public boolean setFocus() {
            if (!beingFocused) {
              try {
                // we are currently asking the part to take focus
                beingFocused = true;

                // delegate an attempt to set the focus here to the
                // part's implementation (if there is one)
                Object object = part.getObject();
                if (object != null) {
                  IPresentationEngine pe = part.getContext().get(IPresentationEngine.class);
                  pe.focusGui(part);
                  return true;
                }
                return super.setFocus();
              } finally {
                // we are done, unset our flag
                beingFocused = false;
              }
            }

            if (logger != null) {
              String id = part.getElementId();
              if (id == null) {
                logger.warn(
                    new IllegalStateException(),
                    "Blocked recursive attempt to activate part " //$NON-NLS-1$
                        + id);
              } else {
                logger.warn(
                    new IllegalStateException(),
                    "Blocked recursive attempt to activate part"); //$NON-NLS-1$
              }
            }

            // already being focused, likely some strange recursive call,
            // just return
            return true;
          }
        };

    newComposite.setLayout(new FillLayout(SWT.VERTICAL));

    newWidget = newComposite;
    bindWidget(element, newWidget);

    // Create a context for this part
    IEclipseContext localContext = part.getContext();
    localContext.set(Composite.class.getName(), newComposite);

    IContributionFactory contributionFactory =
        (IContributionFactory) localContext.get(IContributionFactory.class.getName());
    Object newPart = contributionFactory.create(part.getContributionURI(), localContext);
    part.setObject(newPart);

    return newWidget;
  }