/*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls
   * (org.eclipse.swt.widgets.Composite,
   * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
   */
  @Override
  public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);

    TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
    _composite = new PageBook(parent, SWT.NONE);
    factory.adapt(_composite);

    _blank = factory.createFlatFormComposite(_composite);
    _composite.showPage(_blank);
  }
  @Override
  protected void createControl(
      final Composite composite,
      final int style,
      final TabbedPropertySheetWidgetFactory widgetFactory) {
    mc = new MagicComposite(composite, SWT.INHERIT_DEFAULT);
    mc.setLayout(
        GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 0).create());
    checkBoxControl = new Button(mc, SWT.CHECK);
    if (widgetFactory != null) {
      widgetFactory.adapt(checkBoxControl, true, true);
    }
    checkBoxControl.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(false, true)
            .hint(SWT.DEFAULT, 30)
            .indent(16, 0)
            .align(SWT.BEGINNING, SWT.CENTER)
            .create());

    control = new Composite(mc, SWT.INHERIT_DEFAULT);
    if (widgetFactory != null) {
      widgetFactory.adapt(control);
    }
    control.addDisposeListener(disposeListener);
    control.setLayoutData(
        GridDataFactory.fillDefaults().grab(false, true).align(SWT.BEGINNING, SWT.CENTER).create());
    control.setLayout(
        GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).create());
    createTextControl(style, widgetFactory);

    createToolbar(style, widgetFactory);
    if ((style & SWT.BORDER) != 0) { // Not in a table
      createSwitchEditorControl(widgetFactory);
    }
    addDecorator(composite);
    mc.show(checkBoxControl);
    mc.hide(control);
  }
  @Override
  public void refresh() {
    PictogramElement pe = getSelectedPictogramElement();
    if (pe != null) {
      Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
      _interface = null;

      // the filter assured, that it is a Service or Reference
      if (bo == null) {
        _composite.showPage(_blank);
        _composite.redraw();
        return;
      }
      if (bo instanceof Contract) {
        Contract contract = (Contract) bo;
        _interface = contract.getInterface();
      }

      if (_interface != null) {
        if (_modelComposites.get(_interface) == null) {
          TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
          IInterfaceComposite composite =
              (IInterfaceComposite) InterfaceCompositeAdapter.adaptModelToComposite(_interface);
          if (composite != null) {
            ((AbstractSwitchyardComposite) composite).createContents(_composite, SWT.NONE);
            factory.adapt(((AbstractSwitchyardComposite) composite).getPanel());
            _modelComposites.put(_interface, composite);
          }
        }
        IInterfaceComposite composite = (IInterfaceComposite) _modelComposites.get(_interface);
        if (composite != null) {
          composite.setInterface(_interface);
          _composite.showPage(((AbstractSwitchyardComposite) composite).getPanel());
          Composite parent = _composite;
          // this is a hack to get it to refresh properly
          while (parent != null) {
            parent.layout(true, true);
            parent = parent.getParent();
          }
        } else {
          _composite.getParent().layout();
          _composite.showPage(_blank);
          _composite.layout(true, true);
        }
      } else {
        _composite.showPage(_blank);
        _composite.getParent().layout();
        _composite.layout(true, true);
      }
    }
  }