Пример #1
0
 private void setupFonts(
     Composite parent, final TreeTableComposite tree, final MergeTotalComposite total) {
   final IPropertyChangeListener preferenceListener =
       new IPropertyChangeListener() {
         @Override
         public void propertyChange(PropertyChangeEvent event) {
           if (event.getProperty().equals(MergeEditorPreferencePage.P_MERGE_EDITOR_FONT_SIZE)) {
             Font font = getMergeTreeFont();
             tree.getTree().setFont(font);
             total.getTable().setFont(font);
             editorComposite.layout(true);
             IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
             if (labelProvider instanceof MergeTreeLabelProvider) {
               ((MergeTreeLabelProvider) labelProvider).updateFonts();
             }
             treeViewer.refresh(true);
           }
         }
       };
   parent.addDisposeListener(
       new DisposeListener() {
         @Override
         public void widgetDisposed(DisposeEvent e) {
           MergePlugin.getDefault()
               .getPreferenceStore()
               .removePropertyChangeListener(preferenceListener);
         }
       });
   MergePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferenceListener);
   Font font = getMergeTreeFont();
   tree.getTree().setFont(font);
   total.getTable().setFont(font);
   total.layout(true);
 }
Пример #2
0
  /** This only works on linux */
  private void syncTreeTableScrollBars() {
    final ScrollBar treeBar = treeComposite.getTree().getHorizontalBar();
    final ScrollBar totalBar = totalComposite.getTable().getHorizontalBar();
    treeBar.setVisible(false);
    treeBar.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            scrollTable();
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            scrollTable();
          }

          private void scrollTable() {
            int selection = treeBar.getSelection();
            totalBar.setSelection(selection);
          }
        });
    totalBar.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            scrollTree();
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            scrollTree();
          }

          private void scrollTree() {
            int selection = totalBar.getSelection();
            treeBar.setSelection(selection);
          }
        });
  }
Пример #3
0
  @Override
  public void createPartControl(Composite parent) {
    IEditorInput input = getEditorInput();
    final TreeTableColumnConfiguration configuration =
        TableEditorUtils.getTableConfiguration(getId(), input);
    final PlanEditorModel model = PlanEditorModelRegistry.getPlanEditorModel(input);
    final EPlan plan = model.getEPlan();
    EnsembleSelectionProvider selectionProvider =
        (EnsembleSelectionProvider) getSelectionProvider();

    editorComposite = new EnsembleComposite(parent, SWT.NONE);
    // layout for the editor (arrangement and spacing between tree and table)
    GridLayout layout = new GridLayout(1, true);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    editorComposite.setLayout(layout);

    // setup tree
    treeComposite = buildTree(editorComposite, configuration);
    treeComposite.setData("name", "MergeEditor.treeComposite");
    treeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    treeViewer = new MergeTreeViewer(treeComposite, configuration, getSite());
    treeViewer.setContentProvider(new MergeTreeContentProvider());
    MergeTreeLabelProvider labelProvider = new MergeTreeLabelProvider();
    labelProvider.setRowHighlightDecorator(rowHighlightDecorator);
    treeViewer.setLabelProvider(labelProvider);
    treeViewer.setInput(plan);
    treeViewer.setEditorModel(model);
    treeViewer.expandToLevel(1);
    treeViewer.setAutoExpandLevel(1);
    selectionProvider.attachSelectionProvider(new TreeTableViewerSelectionListener(treeViewer));

    // setup table
    totalComposite = new MergeTotalComposite(editorComposite, configuration);
    totalComposite.setData("name", "MergeEditor.totalComposite");
    totalComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    totalViewer = new MergeTotalViewer(totalComposite);
    totalViewer.setInput(treeViewer);

    if (Platform.getOS().equals(Platform.OS_LINUX)) {
      syncTreeTableScrollBars();
    }

    IWorkbenchPage page = getSite().getPage();
    IEditorPart activeEditor = page.getActiveEditor();
    if ((activeEditor != null) && (activeEditor.getEditorInput() == input)) {
      treeViewer.setSelection(page.getSelection());
    }

    // make sure all the row/column sizes are correct given the current font
    setupFonts(editorComposite, treeComposite, totalComposite);

    MenuManager menuManager =
        WidgetUtils.createContextMenu(
            treeComposite.getTree(),
            new IMenuListener() {
              @Override
              public void menuAboutToShow(IMenuManager mgr) {
                fillContextMenu(mgr);
              }
            });
    // allow extensions to the context menu but not those based on the editor input
    getEditorSite().registerContextMenu(menuManager, getSelectionProvider(), false);
  }