1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 import org.eclipse.team.internal.ui.*; 18 import org.eclipse.team.internal.ui.TeamUIPlugin; 19 import org.eclipse.team.ui.synchronize.*; 20 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 21 import org.eclipse.team.ui.synchronize.SynchronizePageActionGroup; 22 23 26 public class ChangeSetModelManager extends HierarchicalModelManager implements IPropertyChangeListener { 27 28 private static final String P_COMMIT_SET_ENABLED = TeamUIPlugin.ID + ".P_COMMIT_SET_ENABLED"; 30 public static final String CHANGE_SET_GROUP = "ChangeSet"; 32 boolean enabled = false; 33 34 private class ToggleCommitSetAction extends Action { 35 public ToggleCommitSetAction() { 36 super(TeamUIMessages.ChangeLogModelManager_0, TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_CHANGE_SET)); 37 setToolTipText(TeamUIMessages.ChangeLogModelManager_0); 38 update(); 39 } 40 public void run() { 41 setCommitSetsEnabled(!enabled); 42 update(); 43 } 44 private void update() { 45 setChecked(enabled); 46 } 47 } 48 49 private ToggleCommitSetAction toggleCommitSetAction; 50 51 private class CommitSetActionContribution extends SynchronizePageActionGroup { 52 53 public void initialize(ISynchronizePageConfiguration configuration) { 54 super.initialize(configuration); 55 56 toggleCommitSetAction = new ToggleCommitSetAction(); 57 appendToGroup( 58 ISynchronizePageConfiguration.P_TOOLBAR_MENU, 59 CHANGE_SET_GROUP, 60 toggleCommitSetAction); 61 updateEnablement(); 62 } 63 } 64 65 public ChangeSetModelManager(ISynchronizePageConfiguration configuration) { 66 super(configuration); 67 configuration.addPropertyChangeListener(this); 68 configuration.addMenuGroup(ISynchronizePageConfiguration.P_TOOLBAR_MENU, CHANGE_SET_GROUP); 69 configuration.addActionContribution(new CommitSetActionContribution()); 70 ChangeSetCapability changeSetCapability = getChangeSetCapability(configuration); 71 if (changeSetCapability != null && changeSetCapability.supportsActiveChangeSets()) { 72 configuration.addLabelDecorator(new ChangeSetLabelDecorator(configuration)); 73 } 74 configuration.addPropertyChangeListener(new IPropertyChangeListener() { 75 public void propertyChange(PropertyChangeEvent event) { 76 if (event.getProperty().equals(ISynchronizePageConfiguration.P_MODE)) { 77 updateEnablement(); 78 } 79 } 80 81 }); 82 } 83 84 private ChangeSetCapability getChangeSetCapability(ISynchronizePageConfiguration configuration) { 85 ISynchronizeParticipant participant = configuration.getParticipant(); 86 if (participant instanceof IChangeSetProvider) { 87 IChangeSetProvider provider = (IChangeSetProvider) participant; 88 return provider.getChangeSetCapability(); 89 } 90 return null; 91 } 92 93 private void updateEnablement() { 94 if (toggleCommitSetAction != null) { 95 ISynchronizePageConfiguration configuration = getConfiguration(); 96 ChangeSetCapability changeSetCapability = getChangeSetCapability(configuration); 97 boolean enabled = changeSetCapability != null && (changeSetCapability.enableActiveChangeSetsFor(configuration) 98 || changeSetCapability.enableCheckedInChangeSetsFor(configuration)); 99 toggleCommitSetAction.setEnabled(enabled); 100 } 101 102 } 103 104 107 public void dispose() { 108 getConfiguration().removePropertyChangeListener(this); 109 super.dispose(); 110 } 111 112 115 protected ISynchronizeModelProvider createModelProvider(String id) { 116 if (enabled) { 117 return new ChangeSetModelProvider(getConfiguration(), getSyncInfoSet(), id); 118 } else { 119 return super.createModelProvider(id); 120 } 121 } 122 123 126 protected String getSelectedProviderId() { 127 String id = super.getSelectedProviderId(); 128 if (id.equals(ChangeSetModelProvider.ChangeSetModelProviderDescriptor.ID)) { 129 return ((ChangeSetModelProvider)getActiveModelProvider()).getSubproviderId(); 130 } else { 131 return id; 132 } 133 } 134 135 138 public void propertyChange(PropertyChangeEvent event) { 139 } 140 141 144 protected void saveProviderSettings(String id) { 145 super.saveProviderSettings(id); 146 IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); 147 if(pageSettings != null) { 148 pageSettings.put(P_COMMIT_SET_ENABLED, enabled); 149 } 150 } 151 152 155 public void initialize(ISynchronizePageConfiguration configuration) { 156 IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); 159 ChangeSetCapability changeSetCapability = getChangeSetCapability(getConfiguration()); 160 enabled = changeSetCapability != null && changeSetCapability.enableChangeSetsByDefault(); 161 if(pageSettings != null && pageSettings.get(P_COMMIT_SET_ENABLED) != null) { 162 enabled = pageSettings.getBoolean(P_COMMIT_SET_ENABLED); 163 } 164 super.initialize(configuration); 165 } 166 167 170 public void setCommitSetsEnabled(boolean enable) { 171 if (this.enabled != enable) { 172 this.enabled = enable; 173 setInput(getSelectedProviderId(), null); 174 } 175 } 176 177 180 public ISynchronizeModelProvider getActiveModelProvider() { 181 return super.getActiveModelProvider(); 182 } 183 } 184 | Popular Tags |