KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > ChangeSetModelManager


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;
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 /**
24  * Manager for hierarchical models
25  */

26 public class ChangeSetModelManager extends HierarchicalModelManager implements IPropertyChangeListener {
27     
28     private static final String JavaDoc P_COMMIT_SET_ENABLED = TeamUIPlugin.ID + ".P_COMMIT_SET_ENABLED"; //$NON-NLS-1$
29

30     public static final String JavaDoc CHANGE_SET_GROUP = "ChangeSet"; //$NON-NLS-1$
31

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     /* (non-Javadoc)
105      * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager#dispose()
106      */

107     public void dispose() {
108         getConfiguration().removePropertyChangeListener(this);
109         super.dispose();
110     }
111     
112     /* (non-Javadoc)
113      * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager#createModelProvider(java.lang.String)
114      */

115     protected ISynchronizeModelProvider createModelProvider(String JavaDoc id) {
116         if (enabled) {
117             return new ChangeSetModelProvider(getConfiguration(), getSyncInfoSet(), id);
118         } else {
119             return super.createModelProvider(id);
120         }
121     }
122     
123     /* (non-Javadoc)
124      * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager#getSelectedProviderId()
125      */

126     protected String JavaDoc getSelectedProviderId() {
127         String JavaDoc id = super.getSelectedProviderId();
128         if (id.equals(ChangeSetModelProvider.ChangeSetModelProviderDescriptor.ID)) {
129             return ((ChangeSetModelProvider)getActiveModelProvider()).getSubproviderId();
130         } else {
131             return id;
132         }
133     }
134
135     /* (non-Javadoc)
136      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
137      */

138     public void propertyChange(PropertyChangeEvent event) {
139     }
140     
141     /* (non-Javadoc)
142      * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager#saveProviderSettings(java.lang.String)
143      */

144     protected void saveProviderSettings(String JavaDoc 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     /* (non-Javadoc)
153      * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
154      */

155     public void initialize(ISynchronizePageConfiguration configuration) {
156         // Load our setting before invoking super since the inherited
157
// initialize will create the provider
158
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     /*
168      * This method is public so it can be invoked from test cases
169      */

170     public void setCommitSetsEnabled(boolean enable) {
171         if (this.enabled != enable) {
172             this.enabled = enable;
173             setInput(getSelectedProviderId(), null);
174         }
175     }
176     
177     /* (non-Javadoc)
178      * This method is public so it can be invoked from test cases
179      */

180     public ISynchronizeModelProvider getActiveModelProvider() {
181         return super.getActiveModelProvider();
182     }
183 }
184
Popular Tags