Пример #1
0
  public void testAddScrollListener() {
    Scrollable textWidget = new Composite(WorkbenchUtil.getShell(), SWT.V_SCROLL);

    assertNotNull(textWidget.getVerticalBar());
    assertEquals(0, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    EditorUtil.addScrollListener(textWidget);
    assertEquals(1, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    // test when there is no vertical bar
    textWidget = new Composite(WorkbenchUtil.getShell(), SWT.NONE);
    assertNull(textWidget.getVerticalBar());

    assertEquals(0, textWidget.getListeners(SWT.MouseVerticalWheel).length);

    EditorUtil.addScrollListener(textWidget);
    assertEquals(1, textWidget.getListeners(SWT.MouseVerticalWheel).length);
  }
Пример #2
0
  @Override
  protected Composite createPageContainer(Composite parent) {
    this.editorParent = parent;
    Composite composite = super.createPageContainer(parent);

    EditorUtil.initializeScrollbars(getHeaderForm().getForm());

    // create left tool bar that replaces form heading label
    try {
      FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead();

      Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$
      field.setAccessible(true);

      TitleRegion titleRegion = (TitleRegion) field.get(heading);

      leftToolBarManager = new ToolBarManager(SWT.FLAT);
      leftToolBar = leftToolBarManager.createControl(titleRegion);
      leftToolBar.addControlListener(
          new ControlAdapter() {
            private boolean ignoreResizeEvents;

            @Override
            public void controlResized(ControlEvent e) {
              if (ignoreResizeEvents) {
                return;
              }
              ignoreResizeEvents = true;
              try {
                // the tool bar contents has changed, update state
                updateHeaderImage();
                updateHeaderLabel();
              } finally {
                ignoreResizeEvents = false;
              }
            }
          });

      // titleLabel = new Label(titleRegion, SWT.NONE);
      // need a viewer for copy support
      TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY);
      // Eclipse 3.3 needs a document, otherwise an NPE is thrown
      titleViewer.setDocument(new Document());

      titleLabel = titleViewer.getTextWidget();
      titleLabel.setForeground(heading.getForeground());
      titleLabel.setFont(heading.getFont());
      // XXX work-around problem that causes field to maintain selection when unfocused
      titleLabel.addFocusListener(
          new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
              titleLabel.setSelection(0);
            }
          });

      titleRegion.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              // do not create busyLabel to avoid recursion
              updateSizeAndLocations();
            }
          });

      IHandlerService handlerService =
          (IHandlerService) getSite().getService(IHandlerService.class);
      if (handlerService != null) {
        textSupport = new CommonTextSupport(handlerService);
        textSupport.install(titleViewer, false);
      }
    } catch (Exception e) {
      if (!toolBarFailureLogged) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to obtain busy label toolbar",
                e)); //$NON-NLS-1$
      }
      if (titleLabel != null) {
        titleLabel.dispose();
        titleLabel = null;
      }
      if (leftToolBar != null) {
        leftToolBar.dispose();
        leftToolBar = null;
      }
      if (leftToolBarManager != null) {
        leftToolBarManager.dispose();
        leftToolBarManager = null;
      }
    }

    updateHeader();

    return composite;
  }
Пример #3
0
  void createSubSectionContents(
      final ChangeDetail changeDetail,
      final PatchSetDetail patchSetDetail,
      PatchSetPublishDetail publishDetail,
      Section subSection) {
    Composite composite = toolkit.createComposite(subSection);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    subSection.setClient(composite);

    Label authorLabel = new Label(composite, SWT.NONE);
    authorLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    authorLabel.setText("Author");

    Text authorText = new Text(composite, SWT.READ_ONLY);
    authorText.setText(GerritUtil.getUserLabel(patchSetDetail.getInfo().getAuthor()));

    Label committerLabel = new Label(composite, SWT.NONE);
    committerLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    committerLabel.setText("Committer");

    Text committerText = new Text(composite, SWT.READ_ONLY);
    committerText.setText(GerritUtil.getUserLabel(patchSetDetail.getInfo().getCommitter()));

    Label commitLabel = new Label(composite, SWT.NONE);
    commitLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    commitLabel.setText("Commit");

    Hyperlink commitLink = new Hyperlink(composite, SWT.READ_ONLY);
    commitLink.setText(patchSetDetail.getPatchSet().getRevision().get());
    commitLink.addHyperlinkListener(
        new HyperlinkAdapter() {
          @Override
          public void linkActivated(HyperlinkEvent event) {
            GerritToGitMapping mapping = getRepository(changeDetail);
            if (mapping != null) {
              final FetchPatchSetJob job =
                  new FetchPatchSetJob(
                      "Opening Commit Viewer",
                      mapping.getRepository(),
                      mapping.getRemote(),
                      patchSetDetail.getPatchSet());
              job.schedule();
              job.addJobChangeListener(
                  new JobChangeAdapter() {
                    @Override
                    public void done(IJobChangeEvent event) {
                      Display.getDefault()
                          .asyncExec(
                              new Runnable() {
                                @Override
                                public void run() {
                                  CommitEditor.openQuiet(job.getCommit());
                                }
                              });
                    }
                  });
            }
          }
        });

    Label refLabel = new Label(composite, SWT.NONE);
    refLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    refLabel.setText("Ref");

    Text refText = new Text(composite, SWT.READ_ONLY);
    refText.setText(patchSetDetail.getPatchSet().getRefName());

    final TableViewer viewer =
        new TableViewer(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
    GridDataFactory.fillDefaults()
        .span(2, 1)
        .grab(true, true)
        .hint(500, SWT.DEFAULT)
        .applyTo(viewer.getControl());
    viewer.setContentProvider(
        new IStructuredContentProvider() {
          private EContentAdapter modelAdapter;

          public void dispose() {
            // ignore
          }

          public Object[] getElements(Object inputElement) {
            return getReviewItems(inputElement).toArray();
          }

          private List<IReviewItem> getReviewItems(Object inputElement) {
            if (inputElement instanceof IReviewItemSet) {
              return ((IReviewItemSet) inputElement).getItems();
            }
            return Collections.emptyList();
          }

          public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
            if (modelAdapter != null) {
              for (IReviewItem item : getReviewItems(oldInput)) {
                ((EObject) item).eAdapters().remove(modelAdapter);
              }
              addedDrafts = 0;
            }

            if (newInput instanceof IReviewItemSet) {
              // monitors any new topics that are added
              modelAdapter =
                  new EContentAdapter() {
                    @Override
                    public void notifyChanged(Notification notification) {
                      super.notifyChanged(notification);
                      if (notification.getFeatureID(IReviewItem.class)
                              == ReviewsPackage.REVIEW_ITEM__TOPICS
                          && notification.getEventType() == Notification.ADD) {
                        viewer.refresh();
                        addedDrafts++;
                      }
                    }
                  };
              for (Object item : getReviewItems(newInput)) {
                ((EObject) item).eAdapters().add(modelAdapter);
              }
            }
          }
        });
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new ReviewItemLabelProvider()));
    viewer.addOpenListener(
        new IOpenListener() {
          public void open(OpenEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IFileItem item = (IFileItem) selection.getFirstElement();
            if (item != null) {
              doOpen((IReviewItemSet) viewer.getInput(), item);
            }
          }
        });

    IReviewItemSet itemSet =
        GerritUtil.createInput(changeDetail, new GerritPatchSetContent(patchSetDetail), cache);
    viewer.setInput(itemSet);

    Composite actionComposite =
        createActions(changeDetail, patchSetDetail, publishDetail, composite);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(actionComposite);

    subSectionExpanded(changeDetail, patchSetDetail, subSection, viewer);
    EditorUtil.addScrollListener(viewer.getTable());

    getTaskEditorPage().reflow();
  }