Search in sources :

Example 1 with SelectionProviderAdapter

use of org.eclipse.mylyn.commons.ui.SelectionProviderAdapter in project linuxtools by eclipse.

the class OSIOWorkitemLinkAttributeEditor method createControl.

@Override
public void createControl(Composite parent, FormToolkit toolkit) {
    initialize();
    selectionProvider = new SelectionProviderAdapter();
    actionGroup = new CommentActionGroup();
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            // get comment and add reply action as first item in the menu
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                ReplyToCommentAction replyAction = new ReplyToCommentAction(currentViewer);
                manager.add(replyAction);
            }
            actionGroup.setContext(new ActionContext(selectionProvider.getSelection()));
            actionGroup.fillContextMenu(manager);
            if (currentViewer != null && currentViewer.getEditor() instanceof RichTextAttributeEditor) {
                RichTextAttributeEditor editor = (RichTextAttributeEditor) currentViewer.getEditor();
                if (editor.getViewSourceAction().isEnabled()) {
                    // $NON-NLS-1$
                    manager.add(new Separator("planning"));
                    manager.add(editor.getViewSourceAction());
                }
            }
        }
    });
    getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, selectionProvider, false);
    commentMenu = menuManager.createContextMenu(parent);
    section = createSection(parent, toolkit, hasIncoming);
    // $NON-NLS-1$ //$NON-NLS-2$
    section.setText(section.getText() + " (" + commentAttributes.size() + ")");
    if (commentAttributes.isEmpty()) {
        section.setEnabled(false);
    } else {
        if (hasIncoming) {
            expandSection(toolkit, section);
        } else {
            section.addExpansionListener(new ExpansionAdapter() {

                @Override
                public void expansionStateChanged(ExpansionEvent event) {
                    if (section.getClient() == null) {
                        try {
                            expandAllInProgress = true;
                            getTaskEditorPage().setReflow(false);
                            expandSection(toolkit, section);
                        } finally {
                            expandAllInProgress = false;
                            getTaskEditorPage().setReflow(true);
                        }
                        reflow();
                    }
                }
            });
        }
    }
    setSection(toolkit, section);
}
Also used : RichTextAttributeEditor(org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor) SelectionProviderAdapter(org.eclipse.mylyn.commons.ui.SelectionProviderAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) CommentActionGroup(org.eclipse.mylyn.internal.tasks.ui.actions.CommentActionGroup) ActionContext(org.eclipse.ui.actions.ActionContext) IMenuListener(org.eclipse.jface.action.IMenuListener) AbstractReplyToCommentAction(org.eclipse.mylyn.internal.tasks.ui.editors.AbstractReplyToCommentAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ISelection(org.eclipse.jface.viewers.ISelection) IMenuManager(org.eclipse.jface.action.IMenuManager) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) Separator(org.eclipse.jface.action.Separator)

Aggregations

IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionProviderAdapter (org.eclipse.mylyn.commons.ui.SelectionProviderAdapter)1 CommentActionGroup (org.eclipse.mylyn.internal.tasks.ui.actions.CommentActionGroup)1 AbstractReplyToCommentAction (org.eclipse.mylyn.internal.tasks.ui.editors.AbstractReplyToCommentAction)1 RichTextAttributeEditor (org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor)1 ActionContext (org.eclipse.ui.actions.ActionContext)1 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)1 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)1