示例#1
0
 private void duplicateCurrentSelection(KeyEvent e) {
   ISelection selection = treeViewer.getSelection();
   if (selection.isEmpty()) {
     return; // nothing to do
   }
   PlanStructureModifier modifier = getStructureModifier();
   PlanTransferable source = modifier.getTransferable(selection);
   PlanTransferable copy = (PlanTransferable) modifier.copy(source);
   IStructureLocation location =
       modifier.getInsertionLocation(copy, selection, InsertionSemantics.AFTER);
   AbstractOperation op = new PlanAddOperation(copy, modifier, location);
   op.setLabel("Duplicate element(s)");
   WidgetUtils.execute(op, getUndoContext(), e.widget, getSite());
 }
示例#2
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);
  }