KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
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 /**
25  * Action that toggles pinned state of a participant
26  */

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."); //$NON-NLS-1$
34
}
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 JavaDoc, InterruptedException JavaDoc {
58                         participant.setPinned(!participant.isPinned());
59                         updateState();
60                     }
61                 });
62             } catch (InvocationTargetException JavaDoc e) {
63                 Utils.handle(e);
64             } catch (InterruptedException JavaDoc e) {
65                 // Cancelled. Just ignore
66
}
67         }
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
72      */

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