1 11 package org.eclipse.team.internal.ui.synchronize.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.jface.action.Action; 17 import org.eclipse.jface.operation.IRunnableWithProgress; 18 import org.eclipse.jface.util.IPropertyChangeListener; 19 import org.eclipse.jface.util.PropertyChangeEvent; 20 import org.eclipse.team.internal.ui.Utils; 21 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; 22 import org.eclipse.ui.PlatformUI; 23 24 27 public class PinParticipantAction extends Action implements IPropertyChangeListener { 28 29 private ISynchronizeParticipant participant; 30 31 public PinParticipantAction() { 32 super(); 33 Utils.initAction(this, "action.pinParticipant."); } 35 36 public void setParticipant(ISynchronizeParticipant participant) { 37 if (this.participant != null) { 38 this.participant.removePropertyChangeListener(this); 39 } 40 this.participant = participant; 41 setEnabled(participant != null); 42 if (participant != null) { 43 participant.addPropertyChangeListener(this); 44 } 45 updateState(); 46 } 47 48 private void updateState() { 49 setChecked(participant != null && participant.isPinned()); 50 } 51 52 public void run() { 53 if (participant != null) { 54 try { 55 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 56 public void run(IProgressMonitor monitor) 57 throws InvocationTargetException , InterruptedException { 58 participant.setPinned(!participant.isPinned()); 59 updateState(); 60 } 61 }); 62 } catch (InvocationTargetException e) { 63 Utils.handle(e); 64 } catch (InterruptedException e) { 65 } 67 } 68 } 69 70 73 public void propertyChange(PropertyChangeEvent event) { 74 if (event.getSource() == participant) { 75 updateState(); 76 } 77 } 78 79 public void dispose() { 80 if (participant != null) { 81 participant.removePropertyChangeListener(this); 82 } 83 } 84 } 85 | Popular Tags |