コード例 #1
0
  private void createTableControl(Composite parent) {
    createLabel(
        parent,
        Messages.UsedInRelationshipsSection_0,
        ITabbedLayoutConstants.STANDARD_LABEL_WIDTH,
        SWT.NONE);

    // Table
    Composite tableComp = createTableComposite(parent, SWT.NONE);
    fTableLayout = (UpdatingTableColumnLayout) tableComp.getLayout();
    fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION);

    // Column
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    fTableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));

    // On Mac shows alternate table row colours
    fTableViewer.getTable().setLinesVisible(true);

    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);

    fTableViewer.setContentProvider(
        new IStructuredContentProvider() {
          public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}

          public void dispose() {}

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

    fTableViewer.setLabelProvider(
        new LabelProvider() {
          @Override
          public String getText(Object element) {
            IBasicRelationship relationship = (IBasicRelationship) element;
            String name = ZentaLabelProvider.INSTANCE.getLabel(relationship) + " ("; // $NON-NLS-1$
            name += ZentaLabelProvider.INSTANCE.getLabel(relationship.getSource());
            name += " - "; // $NON-NLS-1$
            name += ZentaLabelProvider.INSTANCE.getLabel(relationship.getTarget());
            name += ")"; // $NON-NLS-1$
            return name;
          }

          @Override
          public Image getImage(Object element) {
            return ZentaLabelProvider.INSTANCE.getImage(element);
          }
        });

    fTableViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            if (isAlive()) {
              Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
              if (o instanceof IZentaElement) {
                IBasicRelationship relation = (IBasicRelationship) o;
                ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
                if (view != null) {
                  view.getViewer().setSelection(new StructuredSelection(relation), true);
                }
              }
            }
          }
        });

    fTableViewer.setSorter(new ViewerSorter());
  }
コード例 #2
0
 protected void refreshControls() {
   fTableViewer.setInput(fZentaElement);
   fTableLayout.doRelayout();
 }