1 11 package org.eclipse.team.internal.ui.synchronize.actions; 12 13 import org.eclipse.jface.action.*; 14 import org.eclipse.jface.wizard.IWizard; 15 import org.eclipse.jface.wizard.WizardDialog; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.swt.widgets.*; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ui.*; 20 import org.eclipse.team.internal.ui.synchronize.SynchronizeView; 21 import org.eclipse.team.internal.ui.wizards.GlobalSynchronizeWizard; 22 import org.eclipse.team.ui.TeamImages; 23 import org.eclipse.team.ui.TeamUI; 24 import org.eclipse.team.ui.synchronize.*; 25 26 public class SynchronizePageDropDownAction extends Action implements IMenuCreator, ISynchronizeParticipantListener { 27 28 private ISynchronizeView fView; 29 private Action synchronizeAction; 30 private MenuManager menuManager; 31 32 public SynchronizePageDropDownAction(ISynchronizeView view) { 33 fView= view; 34 Utils.initAction(this, "action.refreshSubscriber."); 36 synchronizeAction = new Action(TeamUIMessages.GlobalRefreshAction_4) { 37 public void run() { 38 IWizard wizard = new GlobalSynchronizeWizard(); 39 WizardDialog dialog = new WizardDialog(fView.getViewSite().getShell(), wizard); 40 dialog.open(); 41 } 42 }; 43 synchronizeAction.setImageDescriptor(TeamImages.getImageDescriptor(ITeamUIImages.IMG_SYNC_VIEW)); 44 synchronizeAction.setActionDefinitionId("org.eclipse.team.ui.synchronizeAll"); setMenuCreator(this); 46 TeamUI.getSynchronizeManager().addSynchronizeParticipantListener(this); 47 update(); 48 fView.getSite().getKeyBindingService().registerAction(synchronizeAction); 49 setActionDefinitionId("org.eclipse.team.ui.synchronizeLast"); fView.getSite().getKeyBindingService().registerAction(this); 51 } 52 53 56 public void dispose() { 57 if(menuManager != null) { 58 menuManager.dispose(); 59 menuManager = null; 60 } 61 TeamUI.getSynchronizeManager().removeSynchronizeParticipantListener(this); 62 } 63 64 67 public Menu getMenu(Menu parent) { 68 return null; 69 } 70 71 74 public Menu getMenu(Control parent) { 75 Menu fMenu = null; 76 if (menuManager == null) { 77 menuManager = new MenuManager(); 78 fMenu = menuManager.createContextMenu(parent); 79 final ISynchronizeParticipantReference[] participants = TeamUI.getSynchronizeManager().getSynchronizeParticipants(); 80 addParticipantsToMenu(participants); 81 if (participants.length > 0) 82 menuManager.add(new Separator()); 83 menuManager.add(synchronizeAction); 84 menuManager.update(true); 85 } else { 86 fMenu = menuManager.getMenu(); 87 } 88 return fMenu; 89 } 90 91 protected void addParticipantsToMenu(ISynchronizeParticipantReference[] refs) { 92 ISynchronizeParticipant current = fView.getParticipant(); 93 for (int i = 0; i < refs.length; i++) { 94 ISynchronizeParticipantReference page = refs[i]; 95 Action action = new ShowSynchronizeParticipantAction(fView, page); 96 try { 97 boolean isCurrent = page.getParticipant().equals(current); 98 action.setChecked(isCurrent); 99 } catch (TeamException e) { 100 continue; 101 } 102 menuManager.add(action); 103 } 104 } 105 106 109 public void run() { 110 ISynchronizeParticipant current = fView.getParticipant(); 111 if(current != null) { 112 current.run(fView); 113 } else { 114 synchronizeAction.run(); 115 } 116 update(); 117 } 118 119 122 public void participantsAdded(ISynchronizeParticipant[] consoles) { 123 Display display = TeamUIPlugin.getStandardDisplay(); 124 display.asyncExec(new Runnable () { 125 public void run() { 126 if(menuManager != null) { 127 menuManager.dispose(); 128 menuManager = null; 129 } 130 update(); 131 } 132 }); 133 } 134 135 138 public void participantsRemoved(ISynchronizeParticipant[] consoles) { 139 Display display = TeamUIPlugin.getStandardDisplay(); 140 display.asyncExec(new Runnable () { 141 public void run() { 142 if(menuManager != null) { 143 menuManager.dispose(); 144 menuManager = null; 145 } 146 update(); 147 } 148 }); 149 } 150 151 public void update() { 152 ISynchronizeParticipant current = fView.getParticipant(); 153 ISynchronizeParticipantReference[] refs = TeamUI.getSynchronizeManager().getSynchronizeParticipants(); 154 String text = null; 155 if(current != null && refs.length > 0) { 156 text = NLS.bind(TeamUIMessages.GlobalRefreshAction_5, new String [] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, current.getName()) }); 157 setToolTipText(text); 158 setText(text); 159 } else { 160 text = TeamUIMessages.GlobalRefreshAction_4; 161 setToolTipText(text); 162 setText(text); 163 } 164 } 165 } 166 | Popular Tags |