KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
12 package org.eclipse.team.internal.ui.synchronize;
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.jface.action.*;
16 import org.eclipse.jface.dialogs.IDialogSettings;
17 import org.eclipse.jface.viewers.*;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.team.internal.ui.Policy;
24 import org.eclipse.team.internal.ui.Utils;
25 import org.eclipse.team.internal.ui.synchronize.actions.DirectionFilterActionGroup;
26 import org.eclipse.team.ui.synchronize.*;
27 import org.eclipse.ui.IActionBars;
28 import org.eclipse.ui.IPageLayout;
29 import org.eclipse.ui.part.*;
30
31 /**
32  * Abstract synchronize page that populates the view using a sync info set
33  * that is possibly filtered by a working set and a mode incoming, outgoing,
34  * both or conflicting).
35  * <p>
36  * The particpant creating this page must set the particpant set property
37  * of the page configuration before the page is created. Subclasses
38  * should set the working set sync info set and output sync info set
39  * in the configuration. These sets are used by the page to display
40  * appropriate messages when the view is empty.
41  */

42 public abstract class SyncInfoSetSynchronizePage extends Page implements ISynchronizePage, IAdaptable {
43     
44     private ISynchronizePageConfiguration configuration;
45     private ISynchronizePageSite site;
46     
47     // Parent composite of this view. It is remembered so that we can dispose of its children when
48
// the viewer type is switched.
49
private Composite composite;
50     private ChangesSection changesSection;
51     private Viewer changesViewer;
52     private StructuredViewerAdvisor viewerAdvisor;
53     
54     /*
55      * Contribute actions for changing modes to the page.
56      */

57     class SyncInfoSetActions extends SynchronizePageActionGroup {
58         private DirectionFilterActionGroup modes;
59         public void initialize(ISynchronizePageConfiguration configuration) {
60             super.initialize(configuration);
61             if (isThreeWay()) {
62                 modes = new DirectionFilterActionGroup(configuration);
63             }
64         }
65         public void fillActionBars(IActionBars actionBars) {
66             super.fillActionBars(actionBars);
67             if (modes == null) return;
68             IToolBarManager manager = actionBars.getToolBarManager();
69             IContributionItem group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP);
70             if (manager != null && group != null) {
71                 modes.fillToolBar(group.getId(), manager);
72             }
73             IMenuManager viewMenu = actionBars.getMenuManager();
74             group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP);
75             if (viewMenu != null && group != null) {
76                 IContributionItem layoutGroup = findGroup(manager, ISynchronizePageConfiguration.LAYOUT_GROUP);
77                 if (layoutGroup != null) {
78                     // Put the modes in the layout group to save space
79
group = layoutGroup;
80                 }
81                 MenuManager modesItem = new MenuManager(Utils.getString("action.modes.label", Policy.getActionBundle())); //$NON-NLS-1$
82
viewMenu.appendToGroup(group.getId(), modesItem);
83                 modes.fillMenu(modesItem);
84             }
85         }
86         private boolean isThreeWay() {
87             return ISynchronizePageConfiguration.THREE_WAY.equals(configuration.getComparisonType());
88         }
89     }
90     
91     /**
92      * Create a new instance of the page
93      * @param configuration a synchronize page configuration
94      */

95     protected SyncInfoSetSynchronizePage(ISynchronizePageConfiguration configuration) {
96         this.configuration = configuration;
97         configuration.setPage(this);
98         configuration.addActionContribution(new SyncInfoSetActions());
99     }
100     
101     /* (non-Javadoc)
102      * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
103      */

104     public void createControl(Composite parent) {
105         composite = new Composite(parent, SWT.NONE);
106         //sc.setContent(composite);
107
GridLayout gridLayout= new GridLayout();
108         gridLayout.makeColumnsEqualWidth= false;
109         gridLayout.marginWidth= 0;
110         gridLayout.marginHeight = 0;
111         gridLayout.verticalSpacing = 0;
112         composite.setLayout(gridLayout);
113         GridData data = new GridData(GridData.FILL_BOTH);
114         data.grabExcessVerticalSpace = true;
115         composite.setLayoutData(data);
116         
117         // Create the changes section which, in turn, creates the changes viewer and its configuration
118
this.changesSection = new ChangesSection(composite, this, configuration);
119         this.changesViewer = createChangesViewer(changesSection.getComposite());
120         changesSection.setViewer(changesViewer);
121     }
122     
123     protected Viewer createChangesViewer(Composite parent) {
124         viewerAdvisor = new TreeViewerAdvisor(parent, configuration);
125         return viewerAdvisor.getViewer();
126     }
127     
128     public StructuredViewerAdvisor getViewerAdvisor() {
129         return viewerAdvisor;
130     }
131     
132     /* (non-Javadoc)
133      * @see org.eclipse.ui.part.IPage#getControl()
134      */

135     public Control getControl() {
136         return composite;
137     }
138     
139     /* (non-Javadoc)
140      * @see org.eclipse.ui.part.IPage#setFocus()
141      */

142     public void setFocus() {
143         changesSection.setFocus();
144     }
145     
146     /* (non-Javadoc)
147      * @see org.eclipse.team.ui.synchronize.ISynchronizePage#init(org.eclipse.team.ui.synchronize.ISynchronizePageSite)
148      */

149     public void init(ISynchronizePageSite site) {
150         this.site = site;
151         IDialogSettings settings = getSettings();
152         if (settings != null) {
153             try {
154                 int mode = settings.getInt(ISynchronizePageConfiguration.P_MODE);
155                 if (mode != 0) {
156                     configuration.setMode(mode);
157                 }
158             } catch (NumberFormatException JavaDoc e) {
159                 // The mode settings does not exist.
160
// Leave the mode as is (assuming the
161
// participant initialized it to an
162
// appropriate value
163
}
164         }
165     }
166     
167     /* (non-Javadoc)
168      * @see org.eclipse.ui.part.IPage#setActionBars(org.eclipse.ui.IActionBars)
169      */

170     public void setActionBars(IActionBars actionBars) {
171         // Delegate menu creation to the advisor
172
viewerAdvisor.setActionBars(actionBars);
173     }
174     
175     /* (non-Javadoc)
176      * @see org.eclipse.ui.part.Page#dispose()
177      */

178     public void dispose() {
179         changesSection.dispose();
180         composite.dispose();
181         super.dispose();
182     }
183     
184     /* (non-Javadoc)
185      * @see org.eclipse.team.ui.synchronize.ISynchronizePage#getViewer()
186      */

187     public Viewer getViewer() {
188         return changesViewer;
189     }
190     
191     /* (non-Javadoc)
192      * @see org.eclipse.team.ui.synchronize.ISynchronizePage#aboutToChangeProperty(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, java.lang.String, java.lang.Object)
193      */

194     public boolean aboutToChangeProperty(
195             ISynchronizePageConfiguration configuration, String JavaDoc key,
196             Object JavaDoc newValue) {
197         if (key.equals(ISynchronizePageConfiguration.P_MODE)) {
198             return (internalSetMode(configuration.getMode(), ((Integer JavaDoc)newValue).intValue()));
199         }
200         return true;
201     }
202
203     private boolean internalSetMode(int oldMode, int mode) {
204         if(oldMode == mode) return false;
205         updateMode(mode);
206         IDialogSettings settings = getSettings();
207         if (settings != null) {
208             settings.put(ISynchronizePageConfiguration.P_MODE, mode);
209         }
210         return true;
211     }
212
213     /*
214      * This method enables "Show In" support for this view
215      *
216      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
217      */

218     public Object JavaDoc getAdapter(Class JavaDoc key) {
219         if (key.equals(ISelectionProvider.class))
220             return changesViewer;
221         if (key == IShowInSource.class) {
222             return new IShowInSource() {
223                 public ShowInContext getShowInContext() {
224                     StructuredViewer v = (StructuredViewer)changesViewer;
225                     if (v == null) return null;
226                     ISelection s = v.getSelection();
227                     if (s instanceof IStructuredSelection) {
228                         Object JavaDoc[] resources = Utils.getResources(((IStructuredSelection)s).toArray());
229                         return new ShowInContext(null, new StructuredSelection(resources));
230                     }
231                     return null;
232                 }
233             };
234         }
235         if (key == IShowInTargetList.class) {
236             return new IShowInTargetList() {
237                 public String JavaDoc[] getShowInTargetIds() {
238                     return new String JavaDoc[] { IPageLayout.ID_RES_NAV };
239                 }
240
241             };
242         }
243         return null;
244     }
245     
246     /**
247      * Return the page site that was assigned to this page.
248      * @return the page site that was assigned to this page
249      */

250     public ISynchronizePageSite getSynchronizePageSite() {
251         return site;
252     }
253     
254     /**
255      * Return the synchronize page configuration that was used to create
256      * this page.
257      * @return Returns the configuration.
258      */

259     public ISynchronizePageConfiguration getConfiguration() {
260         return configuration;
261     }
262
263     /**
264      * Return the settings for the page from the configuration
265      * os <code>null</code> if settings can not be persisted
266      * for the page
267      * @return the persisted page settings
268      */

269     protected IDialogSettings getSettings() {
270         return configuration.getSite().getPageSettings();
271     }
272
273     /**
274      * Callback from the changes section that indicates that the
275      * user has chosen to reset the view contents after an error
276      * has occurred
277      */

278     public abstract void reset();
279     
280     /**
281      * Change the mode to the given mode. This method is invoked
282      * when the mode in the configuration is changed by a client.
283      * @param mode the mode to be used
284      */

285     protected abstract void updateMode(int mode);
286 }
287
Popular Tags