KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > actions > ShowSynchronizeParticipantAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /**
43      * Constructs an action to display the given synchronize participant in the
44      * synchronize view.
45      *
46      * @param view the synchronize view in which the given page is contained
47      * @param ref the participant to show
48      */

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 JavaDoc 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(); //$NON-NLS-1$
74
private ImageData scheduledData = TeamUIPlugin.getImageDescriptor("ovr/waiting_ovr.gif").getImageData(); //$NON-NLS-1$
75
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