1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.viewers.ISelectionChangedListener; 15 import org.eclipse.jface.viewers.SelectionChangedEvent; 16 import org.eclipse.swt.events.DisposeEvent; 17 import org.eclipse.swt.events.DisposeListener; 18 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 19 import org.eclipse.ui.*; 20 21 25 public class ActionDelegateWrapper extends Action implements ISelectionChangedListener { 26 27 private IActionDelegate delegate; 28 29 public ActionDelegateWrapper(IActionDelegate delegate, ISynchronizePageConfiguration configuration) { 30 this.delegate = delegate; 31 IWorkbenchPart part = configuration.getSite().getPart(); 32 if(part != null) { 33 if (delegate instanceof IObjectActionDelegate) { 34 ((IObjectActionDelegate)delegate).setActivePart(this, part); 35 } 36 if (part instanceof IViewPart 37 && delegate instanceof IViewActionDelegate) { 38 ((IViewActionDelegate)delegate).init((IViewPart)part); 39 } 40 if (part instanceof IEditorPart 41 && delegate instanceof IViewActionDelegate) { 42 ((IEditorActionDelegate)delegate).setActiveEditor(this, (IEditorPart)part); 43 } 44 } 45 initialize(configuration); 46 } 47 48 public ActionDelegateWrapper(IActionDelegate delegate, ISynchronizePageConfiguration configuration, String id) { 49 this(delegate, configuration); 50 setId(id); 51 setActionDefinitionId(id); 52 } 53 54 60 protected void initialize(final ISynchronizePageConfiguration configuration) { 61 configuration.getSite().getSelectionProvider().addSelectionChangedListener(this); 62 configuration.getPage().getViewer().getControl().addDisposeListener(new DisposeListener() { 63 public void widgetDisposed(DisposeEvent e) { 64 configuration.getSite().getSelectionProvider().removeSelectionChangedListener(ActionDelegateWrapper.this); 65 } 66 }); 67 } 68 69 72 public void selectionChanged(SelectionChangedEvent event) { 73 getDelegate().selectionChanged(this, event.getSelection()); 74 } 75 76 79 public void run() { 80 getDelegate().run(this); 81 } 82 83 87 public IActionDelegate getDelegate() { 88 return delegate; 89 } 90 91 } 92 | Popular Tags |