示例#1
0
  @Override
  protected Control createDialogArea(Composite parent) {
    updateTitle();
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
    final ScrolledComposite scrolledComposite =
        new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setBackground(composite.getBackground());
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);

    final Composite content = new Composite(scrolledComposite, SWT.NONE);
    content.setBackground(composite.getBackground());
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(content);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(content);

    try {
      if (view == null) {
        ECPSWTViewRenderer.INSTANCE.render(content, selection);
      } else {
        ECPSWTViewRenderer.INSTANCE.render(content, selection, view);
      }
    } catch (final ECPRendererException ex) {
      Activator.log(ex);
    }

    scrolledComposite.setContent(content);
    final Point point = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    content.setSize(point);
    scrolledComposite.setMinSize(point);

    objectChangeAdapter =
        new AdapterImpl() {

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
           */
          @Override
          public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            updateTitle();
          }
        };
    selection.eAdapters().add(objectChangeAdapter);

    return composite;
  }
    @Override
    public void selectionChanged(SelectionChangedEvent event) {

      final Object treeSelected = ((IStructuredSelection) event.getSelection()).getFirstElement();
      final Object selected =
          treeSelected == null ? treeSelected : manipulateSelection(treeSelected);
      if (selected instanceof EObject) {
        try {
          if (childComposite != null) {
            childComposite.dispose();
            cleanCustomOnSelectionChange();
          }
          childComposite = createComposite();

          final Object root =
              manipulateSelection(
                  ((RootObject) ((TreeViewer) event.getSource()).getInput()).getRoot());

          final VElement viewModel = getViewModelContext().getViewModel();
          final VViewModelProperties properties =
              ViewModelPropertiesHelper.getInhertitedPropertiesOrEmpty(viewModel);
          properties.addNonInheritableProperty(DETAIL_KEY, true);

          final boolean rootSelected = selected.equals(root);

          if (rootSelected) {
            properties.addNonInheritableProperty(ROOT_KEY, true);
          }
          VView view = null;
          if (rootSelected) {
            view = getVElement().getDetailView();
          }
          if (view == null || view.getChildren().isEmpty()) {
            view = ViewProviderHelper.getView((EObject) selected, properties);
          }

          final ReferenceService referenceService =
              getViewModelContext().getService(ReferenceService.class);
          final ViewModelContext childContext =
              getViewModelContext()
                  .getChildContext(
                      (EObject) selected,
                      getVElement(),
                      view,
                      new TreeMasterDetailReferenceService(referenceService));

          manipulateViewContext(childContext);
          ECPSWTViewRenderer.INSTANCE.render(childComposite, childContext);

          relayoutDetail();
        } catch (final ECPRendererException e) {
          Activator.getDefault()
              .getReportService()
              .report(
                  new StatusReport(
                      new Status(
                          IStatus.ERROR,
                          Activator.getDefault().getBundle().getSymbolicName(),
                          e.getMessage(),
                          e)));
        }
      }
    }