예제 #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
  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();
  }