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); }
@Override protected DeleteOperation getDeleteOperation( IStructureModifier modifier, ISelection selection, Event event) { if (treeComposite == null) { return null; } ITransferable transferable = modifier.getTransferable(selection); return new MergePlanDeleteOperation( transferable, modifier, getSelectionProvider(), treeComposite.getTree()); }
/** * Build the Tree widget for the editor to contain ActivityGroups and Activities. * * @param parent * @param configuration * @return */ private TreeTableComposite buildTree( Composite parent, TreeTableColumnConfiguration configuration) { TreeTableComposite treeComposite = new TreeTableComposite(parent, configuration, true); treeComposite.setLayout(new FillLayout()); treeComposite .getTree() .addKeyListener( new KeyListener() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.INSERT) { duplicateCurrentSelection(e); } } @Override public void keyReleased(KeyEvent e) { // nothing } }); return treeComposite; }
/** 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); } }); }
@Override public void dispose() { if (treeViewer != null) { EnsembleSelectionProvider selectionProvider = (EnsembleSelectionProvider) getSelectionProvider(); if (selectionProvider != null) { selectionProvider.detachSelectionProvider(treeViewer); } treeViewer = null; } /* if (mergeTreeFont != null) { mergeTreeFont.dispose(); }*/ if (treeComposite != null) { treeComposite.dispose(); } if (editorComposite != null) { editorComposite.dispose(); } totalViewer = null; super.dispose(); }
@Override public void setFocus() { treeComposite.setFocus(); }
@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); }