1 11 package org.eclipse.team.internal.ui.synchronize.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.jface.resource.CompositeImageDescriptor; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 import org.eclipse.swt.graphics.ImageData; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.team.core.TeamException; 21 import org.eclipse.team.internal.ui.TeamUIPlugin; 22 import org.eclipse.team.internal.ui.Utils; 23 import org.eclipse.team.internal.ui.synchronize.SubscriberRefreshSchedule; 24 import org.eclipse.team.internal.ui.synchronize.SynchronizeView; 25 import org.eclipse.team.ui.synchronize.*; 26 27 public class ShowSynchronizeParticipantAction extends Action implements IPropertyChangeListener { 28 29 private ISynchronizeParticipantReference fPage; 30 private ISynchronizeView fView; 31 32 public void run() { 33 try { 34 if (!fPage.equals(fView.getParticipant())) { 35 fView.display(fPage.getParticipant()); 36 } 37 } catch (TeamException e) { 38 Utils.handle(e); 39 } 40 } 41 42 49 public ShowSynchronizeParticipantAction(ISynchronizeView view, ISynchronizeParticipantReference ref) { 50 super(Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, ref.getDisplayName()), IAction.AS_RADIO_BUTTON); 51 fPage = ref; 52 fView = view; 53 setImageDescriptor( new ParticipantOverlay( ref)); 54 55 try { 56 fPage.getParticipant().addPropertyChangeListener( this); 57 } catch( TeamException e) { 58 Utils.handle(e); 59 } 60 } 61 62 public void propertyChange( PropertyChangeEvent event) { 63 String property = event.getProperty(); 64 if( AbstractSynchronizeParticipant.P_PINNED.equals( property) || 65 AbstractSynchronizeParticipant.P_SCHEDULED.equals(property)) { 66 setImageDescriptor(new ParticipantOverlay( fPage)); 67 } 68 } 69 70 71 private static final class ParticipantOverlay extends CompositeImageDescriptor { 72 73 private ImageData pinnedData = TeamUIPlugin.getImageDescriptor("ovr/pinned_ovr.gif").getImageData(); private ImageData scheduledData = TeamUIPlugin.getImageDescriptor("ovr/waiting_ovr.gif").getImageData(); private ImageData imageData; 76 private ISynchronizeParticipant participant; 77 78 private ParticipantOverlay(ISynchronizeParticipantReference ref) { 79 try { 80 this.participant = ref.getParticipant(); 81 this.imageData = ref.getDescriptor().getImageDescriptor().getImageData(); 82 } catch (TeamException ex) { 83 TeamUIPlugin.log(ex); 84 } 85 } 86 87 protected void drawCompositeImage(int width, int height) { 88 drawImage(this.imageData, 0, 0); 89 if (this.participant.isPinned()) { 90 drawImage(pinnedData, this.imageData.width - pinnedData.width, 0); 91 } 92 if (this.participant instanceof SubscriberParticipant) { 93 SubscriberParticipant participant = ( SubscriberParticipant) this.participant; 94 SubscriberRefreshSchedule schedule = participant.getRefreshSchedule(); 95 if(schedule!=null && schedule.isEnabled()) { 96 drawImage(scheduledData, 0, 0); 97 } 98 } else { 99 SubscriberRefreshSchedule schedule = (SubscriberRefreshSchedule)Utils.getAdapter(participant, SubscriberRefreshSchedule.class); 100 if(schedule!=null && schedule.isEnabled()) { 101 drawImage(scheduledData, 0, 0); 102 } 103 } 104 } 105 106 protected Point getSize() { 107 return new Point(this.imageData.width, this.imageData.height); 108 } 109 } 110 } 111 112 | Popular Tags |