KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.eclipse.core.runtime.*;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.jface.dialogs.*;
26 import org.eclipse.jface.util.IPropertyChangeListener;
27 import org.eclipse.jface.util.PropertyChangeEvent;
28 import org.eclipse.jface.viewers.IBasicPropertyConstants;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Display;
31 import org.eclipse.team.core.TeamException;
32 import org.eclipse.team.internal.ui.*;
33 import org.eclipse.team.internal.ui.synchronize.actions.*;
34 import org.eclipse.team.ui.TeamUI;
35 import org.eclipse.team.ui.synchronize.*;
36 import org.eclipse.ui.*;
37 import org.eclipse.ui.actions.ActionFactory;
38 import org.eclipse.ui.part.*;
39 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
40
41 /**
42  * Implements a Synchronize View that contains multiple synchronize participants.
43  */

44 public class SynchronizeView extends PageBookView implements ISynchronizeView, ISynchronizeParticipantListener, IPropertyChangeListener, ISaveablesSource, ISaveablePart {
45     
46     /**
47      * Suggested maximum length of participant names when shown in certain menus and dialog.
48      */

49     public final static int MAX_NAME_LENGTH = 100;
50     
51     /**
52      * The participant being displayed, or <code>null</code> if none
53      */

54     private ISynchronizeParticipant activeParticipantRef = null;
55     
56     /**
57      * Map of participants to dummy participant parts (used to close pages)
58      */

59     private Map JavaDoc fParticipantToPart;
60     
61     /**
62      * Map of parts to participants
63      */

64     private Map JavaDoc fPartToParticipant;
65
66     /**
67      * Drop down action to switch between participants
68      */

69     private SynchronizePageDropDownAction fPageDropDown;
70     
71     /**
72      * Action to remove the selected participant
73      */

74     private PinParticipantAction fPinAction;
75     
76     /**
77      * Action to remove the currently shown participant
78      */

79     private RemoveSynchronizeParticipantAction fRemoveCurrentAction;
80     
81     /**
82      * Action to remove all non-pinned participants
83      */

84     private RemoveSynchronizeParticipantAction fRemoveAllAction;
85     
86     /**
87      * Preference key to save
88      */

89     private static final String JavaDoc KEY_LAST_ACTIVE_PARTICIPANT_ID = "lastactiveparticipant_id"; //$NON-NLS-1$
90
private static final String JavaDoc KEY_LAST_ACTIVE_PARTICIPANT_SECONDARY_ID = "lastactiveparticipant_sec_id"; //$NON-NLS-1$
91
private static final String JavaDoc KEY_SETTINGS_SECTION= "SynchronizeViewSettings"; //$NON-NLS-1$
92

93
94     /* (non-Javadoc)
95      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
96      */

97     public void propertyChange(PropertyChangeEvent event) {
98         Object JavaDoc source = event.getSource();
99         if (source instanceof ISynchronizeParticipant) {
100             if (event.getProperty().equals(IBasicPropertyConstants.P_TEXT)) {
101                 if (source.equals(getParticipant())) {
102                     updateTitle();
103                 }
104             } else if (event.getProperty().equals(ModelSynchronizeParticipant.PROP_DIRTY)) {
105                 Display.getDefault().asyncExec(new Runnable JavaDoc() {
106                     public void run() {
107                         firePropertyChange(PROP_DIRTY);
108                     }
109                 });
110             } else if (event.getProperty().equals(ModelSynchronizeParticipant.PROP_ACTIVE_SAVEABLE)) {
111                 Saveable oldSaveable = (Saveable)event.getOldValue();
112                 Saveable newSaveable = (Saveable)event.getNewValue();
113                 ISaveablesLifecycleListener listener = (ISaveablesLifecycleListener)getSite().getPage().getWorkbenchWindow()
114                     .getService(ISaveablesLifecycleListener.class);
115                 if (listener != null && oldSaveable != null)
116                     listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, new Saveable[] { oldSaveable }, false));
117                 if (listener != null && newSaveable != null)
118                     listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, new Saveable[] { oldSaveable }, false));
119             } else if (event.getProperty().equals(ISynchronizeParticipant.P_CONTENT)) {
120                 final IWorkbenchSiteProgressService ps = (IWorkbenchSiteProgressService)getSite().getAdapter(IWorkbenchSiteProgressService.class);
121                 if (ps != null)
122                     Display.getDefault().asyncExec(new Runnable JavaDoc() {
123                         public void run() {
124                             ps.warnOfContentChange();
125                         }
126                     });
127             }
128         }
129         if (source instanceof ISynchronizePageConfiguration) {
130             ISynchronizePageConfiguration configuration = (ISynchronizePageConfiguration) source;
131             if (event.getProperty().equals(ISynchronizePageConfiguration.P_PAGE_DESCRIPTION)) {
132                 if (configuration.getParticipant().equals(getParticipant())) {
133                     updateTitle();
134                 }
135             }
136         }
137     }
138     
139     /* (non-Javadoc)
140      * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
141      */

142     public void partClosed(IWorkbenchPart part) {
143         super.partClosed(part);
144     }
145
146     /* (non-Javadoc)
147      * @see org.eclipse.team.ui.sync.ISynchronizeView#getParticipant()
148      */

149     public ISynchronizeParticipant getParticipant() {
150         return activeParticipantRef;
151     }
152     
153     /* (non-Javadoc)
154      * @see org.eclipse.ui.part.PageBookView#showPageRec(org.eclipse.ui.part.PageBookView.PageRec)
155      */

156     protected void showPageRec(PageRec pageRec) {
157         super.showPageRec(pageRec);
158         activeParticipantRef = (ISynchronizeParticipant)fPartToParticipant.get(pageRec.part);
159         updateActionEnablements();
160         updateTitle();
161     }
162
163     /*
164      * Updates the view title based on the active participant
165      */

166     protected void updateTitle() {
167         ISynchronizeParticipant participant = getParticipant();
168         if (participant == null) {
169             setContentDescription(""); //$NON-NLS-1$
170
} else {
171             SynchronizeViewWorkbenchPart part = (SynchronizeViewWorkbenchPart)fParticipantToPart.get(participant);
172             ISynchronizePageConfiguration configuration = part.getConfiguration();
173             String JavaDoc description = (String JavaDoc)configuration.getProperty(ISynchronizePageConfiguration.P_PAGE_DESCRIPTION);
174             if (description == null)
175                 description = part.getParticipant().getName();
176             // TODO: Get the description from the configuration
177
// TODO: listen to the configuration for description changes
178
setContentDescription(Utils.shortenText(MAX_NAME_LENGTH, description));
179         }
180     }
181     
182     /* (non-Javadoc)
183      * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.part.PageBookView.PageRec)
184      */

185     protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
186         IPage page = pageRecord.page;
187         page.dispose();
188         pageRecord.dispose();
189         SynchronizeViewWorkbenchPart syncPart = (SynchronizeViewWorkbenchPart) part;
190         ISynchronizeParticipant participant = syncPart.getParticipant();
191         clearCrossReferenceCache(part, participant);
192     }
193
194     private void clearCrossReferenceCache(IWorkbenchPart part, ISynchronizeParticipant participant) {
195         participant.removePropertyChangeListener(this);
196         if (part == null)
197             return;
198         ISynchronizePageConfiguration configuration = ((SynchronizeViewWorkbenchPart)part).getConfiguration();
199         if (configuration != null)
200             configuration.removePropertyChangeListener(this);
201         fPartToParticipant.remove(part);
202         fParticipantToPart.remove(participant);
203     }
204
205     /* (non-Javadoc)
206      * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart)
207      */

208     protected PageRec doCreatePage(IWorkbenchPart dummyPart) {
209         SynchronizeViewWorkbenchPart part = (SynchronizeViewWorkbenchPart)dummyPart;
210         ISynchronizeParticipant participant = part.getParticipant();
211         participant.addPropertyChangeListener(this);
212         ISynchronizePageConfiguration configuration = participant.createPageConfiguration();
213         part.setConfiguration(configuration);
214         configuration.addPropertyChangeListener(this);
215         IPageBookViewPage page = participant.createPage(configuration);
216         if(page != null) {
217             initPage(page);
218             initPage(configuration, page);
219             page.createControl(getPageBook());
220             PageRec rec = new PageRec(dummyPart, page);
221             return rec;
222         }
223         return null;
224     }
225
226     /* (non-Javadoc)
227      * @see org.eclipse.ui.part.PageBookView#initPage(org.eclipse.ui.part.IPageBookViewPage)
228      */

229     protected void initPage(ISynchronizePageConfiguration configuration, IPageBookViewPage page) {
230         // A page site does not provide everything the page may need
231
// Also provide the synchronize page site if the page is a synchronize view page
232
((SynchronizePageConfiguration)configuration).setSite(new WorkbenchPartSynchronizePageSite(this, page.getSite(), getDialogSettings(configuration.getParticipant())));
233         if (page instanceof ISynchronizePage) {
234             try {
235                 ((ISynchronizePage)page).init(configuration.getSite());
236             } catch (PartInitException e) {
237                 TeamUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
238             }
239         }
240         page.getSite().getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), fPageDropDown);
241         page.getSite().getActionBars().updateActionBars();
242     }
243
244     /* (non-Javadoc)
245      * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart)
246      */

247     protected boolean isImportant(IWorkbenchPart part) {
248         return part instanceof SynchronizeViewWorkbenchPart;
249     }
250
251     /* (non-Javadoc)
252      * @see org.eclipse.ui.IWorkbenchPart#dispose()
253      */

254     public void dispose() {
255         super.dispose();
256         TeamUI.getSynchronizeManager().removeSynchronizeParticipantListener(this);
257         // Pin action is hooked up to listeners, must call dispose to un-register.
258
fPinAction.dispose();
259         // Remember the last active participant
260
if(activeParticipantRef != null) {
261             rememberCurrentParticipant();
262         }
263         fParticipantToPart = null;
264         fPartToParticipant = null;
265     }
266
267     /**
268      *
269      */

270     private void rememberCurrentParticipant() {
271         IDialogSettings section = getDialogSettings();
272         section.put(KEY_LAST_ACTIVE_PARTICIPANT_ID, activeParticipantRef.getId());
273         section.put(KEY_LAST_ACTIVE_PARTICIPANT_SECONDARY_ID, activeParticipantRef.getSecondaryId());
274     }
275
276     /* (non-Javadoc)
277      * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
278      */

279     protected IPage createDefaultPage(PageBook book) {
280         Page page = new MessagePage();
281         page.createControl(getPageBook());
282         initPage(page);
283         return page;
284     }
285
286     /* (non-Javadoc)
287      * @see org.eclipse.team.ui.sync.ISynchronizeParticipantListener#participantsAdded(org.eclipse.team.ui.sync.ISynchronizeParticipant[])
288      */

289     public void participantsAdded(final ISynchronizeParticipant[] participants) {
290         for (int i = 0; i < participants.length; i++) {
291             ISynchronizeParticipant participant = participants[i];
292             if (isAvailable() && select(TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()))) {
293                 SynchronizeViewWorkbenchPart part = new SynchronizeViewWorkbenchPart(participant, getSite());
294                 fParticipantToPart.put(participant, part);
295                 fPartToParticipant.put(part, participant);
296             }
297         }
298         Display.getDefault().asyncExec(new Runnable JavaDoc() {
299             public void run() {
300                 firePropertyChange(PROP_DIRTY);
301             }
302         });
303     }
304
305     /* (non-Javadoc)
306      * @see org.eclipse.team.ui.sync.ISynchronizeParticipantListener#participantsRemoved(org.eclipse.team.ui.sync.ISynchronizeParticipant[])
307      */

308     public void participantsRemoved(final ISynchronizeParticipant[] participants) {
309         if (isAvailable()) {
310             Runnable JavaDoc r = new Runnable JavaDoc() {
311                 public void run() {
312                     for (int i = 0; i < participants.length; i++) {
313                         ISynchronizeParticipant participant = participants[i];
314                         if (isAvailable()) {
315                             SynchronizeViewWorkbenchPart part = (SynchronizeViewWorkbenchPart)fParticipantToPart.get(participant);
316                             if (part != null) {
317                                 partClosed(part);
318                                 clearCrossReferenceCache(part, participant);
319                             }
320                             // Remove any settings created for the participant
321
removeDialogSettings(participant);
322                             if (getParticipant() == null) {
323                                 ISynchronizeParticipantReference[] available = TeamUI.getSynchronizeManager().getSynchronizeParticipants();
324                                 if (available.length > 0) {
325                                     ISynchronizeParticipant p;
326                                     try {
327                                         p = available[available.length - 1].getParticipant();
328                                     } catch (TeamException e) {
329                                         return;
330                                     }
331                                     display(p);
332                                 }
333                             }
334                         }
335                     }
336                     firePropertyChange(PROP_DIRTY);
337                 }
338             };
339             asyncExec(r);
340         }
341     }
342
343     /**
344      * Constructs a synchronize view
345      */

346     public SynchronizeView() {
347         super();
348         fParticipantToPart = new HashMap JavaDoc();
349         fPartToParticipant = new HashMap JavaDoc();
350         updateTitle();
351     }
352     
353     /**
354      * Create the default actions for the view. These will be shown regardless of the
355      * participant being displayed.
356      */

357     protected void createActions() {
358         fPageDropDown = new SynchronizePageDropDownAction(this);
359         fPinAction = new PinParticipantAction();
360         fRemoveCurrentAction = new RemoveSynchronizeParticipantAction(this, false);
361         fRemoveAllAction = new RemoveSynchronizeParticipantAction(this, true);
362         updateActionEnablements();
363     }
364
365     private void updateActionEnablements() {
366         if (fPinAction != null) {
367             fPinAction.setParticipant(activeParticipantRef);
368         }
369         if (fRemoveAllAction != null) {
370             fRemoveAllAction.setEnabled(getParticipant() != null);
371         }
372         if (fRemoveCurrentAction != null) {
373             fRemoveCurrentAction.setEnabled(getParticipant() != null);
374         }
375     }
376
377     /**
378      * Add the actions to the toolbar
379      *
380      * @param bars the action bars
381      */

382     protected void configureToolBar(IActionBars bars) {
383         IToolBarManager mgr = bars.getToolBarManager();
384         mgr.add(fPageDropDown);
385         mgr.add(fPinAction);
386         IMenuManager menu = bars.getMenuManager();
387         menu.add(fPinAction);
388         menu.add(fRemoveCurrentAction);
389         menu.add(fRemoveAllAction);
390     }
391
392     /* (non-Javadoc)
393      * @see org.eclipse.team.ui.synchronize.ISynchronizeView#display(org.eclipse.team.ui.synchronize.ISynchronizeParticipant)
394      */

395     public void display(ISynchronizeParticipant participant) {
396         SynchronizeViewWorkbenchPart part = (SynchronizeViewWorkbenchPart)fParticipantToPart.get(participant);
397         if (part != null) {
398             partActivated(part);
399             fPageDropDown.update();
400             rememberCurrentParticipant();
401         }
402     }
403     
404     /* (non-Javadoc)
405      * @see org.eclipse.ui.part.PageBookView#getBootstrapPart()
406      */

407     protected IWorkbenchPart getBootstrapPart() {
408         return null;
409     }
410     
411     /**
412      * Registers the given runnable with the display
413      * associated with this view's control, if any.
414      * @param runnable a runnable
415      */

416     public void asyncExec(Runnable JavaDoc runnable) {
417         if (isAvailable()) {
418             getPageBook().getDisplay().asyncExec(runnable);
419         }
420     }
421     
422     /**
423      * Creates this view's underlying viewer and actions.
424      * Hooks a pop-up menu to the underlying viewer's control,
425      * as well as a key listener. When the delete key is pressed,
426      * the <code>REMOVE_ACTION</code> is invoked. Hooks help to
427      * this view. Subclasses must implement the following methods
428      * which are called in the following order when a view is
429      * created:<ul>
430      * <li><code>createViewer(Composite)</code> - the context
431      * menu is hooked to the viewer's control.</li>
432      * <li><code>createActions()</code></li>
433      * <li><code>configureToolBar(IToolBarManager)</code></li>
434      * <li><code>getHelpContextId()</code></li>
435      * </ul>
436      * @see IWorkbenchPart#createPartControl(Composite)
437      */

438     public void createPartControl(Composite parent) {
439         super.createPartControl(parent);
440         createActions();
441         configureToolBar(getViewSite().getActionBars());
442         updateForExistingParticipants();
443         getViewSite().getActionBars().updateActionBars();
444         updateTitle();
445         
446         IWorkbenchSiteProgressService progress = (IWorkbenchSiteProgressService)getSite().getAdapter(IWorkbenchSiteProgressService.class);
447         if(progress != null) {
448             progress.showBusyForFamily(ISynchronizeManager.FAMILY_SYNCHRONIZE_OPERATION);
449         }
450         
451         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.SYNC_VIEW);
452     }
453     
454     /**
455      * Initialize for existing participants
456      */

457     private void updateForExistingParticipants() {
458         ISynchronizeManager manager = TeamUI.getSynchronizeManager();
459         List JavaDoc participants = Arrays.asList(getParticipants());
460         boolean errorOccurred = false;
461         for (int i = 0; i < participants.size(); i++) {
462             try {
463                 ISynchronizeParticipantReference ref = (ISynchronizeParticipantReference)participants.get(i);
464                 participantsAdded(new ISynchronizeParticipant[] {ref.getParticipant()});
465             } catch (TeamException e) {
466                 errorOccurred = true;
467                 continue;
468             }
469             
470         }
471         if (errorOccurred) {
472             participants = Arrays.asList(getParticipants());
473         }
474         try {
475             // decide which participant to show on startup
476
if (participants.size() > 0) {
477                 ISynchronizeParticipantReference participantToSelect = (ISynchronizeParticipantReference)participants.get(0);
478                 IDialogSettings section = getDialogSettings();
479                 String JavaDoc selectedParticipantId = section.get(KEY_LAST_ACTIVE_PARTICIPANT_ID);
480                 String JavaDoc selectedParticipantSecId = section.get(KEY_LAST_ACTIVE_PARTICIPANT_SECONDARY_ID);
481                 if(selectedParticipantId != null) {
482                     ISynchronizeParticipantReference selectedParticipant = manager.get(selectedParticipantId, selectedParticipantSecId);
483                     if(selectedParticipant != null) {
484                         participantToSelect = selectedParticipant;
485                     }
486                 }
487                 display(participantToSelect.getParticipant());
488             }
489             
490             // add as a listener to update when new participants are added
491
manager.addSynchronizeParticipantListener(this);
492         } catch (TeamException e) {
493             Utils.handle(e);
494         }
495     }
496     
497     private ISynchronizeParticipantReference[] getParticipants() {
498         ISynchronizeManager manager = TeamUI.getSynchronizeManager();
499         // create pages
500
List JavaDoc participants = new ArrayList JavaDoc();
501         ISynchronizeParticipantReference[] refs = manager.getSynchronizeParticipants();
502         for (int i = 0; i < refs.length; i++) {
503             ISynchronizeParticipantReference ref =refs[i];
504             if(select(ref)) {
505                 participants.add(ref);
506             }
507         }
508         return (ISynchronizeParticipantReference[]) participants.toArray(new ISynchronizeParticipantReference[participants.size()]);
509     }
510     
511     private boolean isAvailable() {
512         return getPageBook() != null && !getPageBook().isDisposed();
513     }
514     
515     /*
516      * Method used by test cases to access the page for a participant
517      */

518     public IPage getPage(ISynchronizeParticipant participant) {
519         IWorkbenchPart part = (IWorkbenchPart)fParticipantToPart.get(participant);
520         if (part == null) return null;
521         try {
522             return getPageRec(part).page;
523         } catch (NullPointerException JavaDoc e) {
524             // The PageRec class is not visible so we can't do a null check
525
// before accessing the page.
526
return null;
527         }
528     }
529     
530     protected boolean select(ISynchronizeParticipantReference ref) {
531         return true;
532     }
533     
534     /*
535      * Return the dialog settings for the view
536      */

537     private IDialogSettings getDialogSettings() {
538         IDialogSettings workbenchSettings = TeamUIPlugin.getPlugin().getDialogSettings();
539         IDialogSettings syncViewSettings = workbenchSettings.getSection(KEY_SETTINGS_SECTION);
540         if (syncViewSettings == null) {
541             syncViewSettings = workbenchSettings.addNewSection(KEY_SETTINGS_SECTION);
542         }
543         return syncViewSettings;
544     }
545     
546     private String JavaDoc getSettingsKey(ISynchronizeParticipant participant) {
547         String JavaDoc id = participant.getId();
548         String JavaDoc secondaryId = participant.getSecondaryId();
549         return secondaryId == null ? id : id + '.' + secondaryId;
550     }
551     
552     private IDialogSettings getDialogSettings(ISynchronizeParticipant participant) {
553         String JavaDoc key = getSettingsKey(participant);
554         IDialogSettings viewsSettings = getDialogSettings();
555         IDialogSettings settings = viewsSettings.getSection(key);
556         if (settings == null) {
557             settings = viewsSettings.addNewSection(key);
558         }
559         return settings;
560     }
561     
562     private void removeDialogSettings(ISynchronizeParticipant participant) {
563         String JavaDoc key = getSettingsKey(participant);
564         IDialogSettings settings = getDialogSettings();
565         if (settings.getSection(key) != null) {
566             // There isn't an explicit remove so just make sure
567
// That the old settings are forgotten
568
getDialogSettings().addSection(new DialogSettings(key));
569         }
570     }
571     
572     /* (non-Javadoc)
573      * @see org.eclipse.ui.ISaveablesSource#getSaveables()
574      */

575     public Saveable[] getSaveables() {
576         Set JavaDoc result = new HashSet JavaDoc();
577         for (Iterator JavaDoc iter = fPartToParticipant.keySet().iterator(); iter.hasNext();) {
578             SynchronizeViewWorkbenchPart part = (SynchronizeViewWorkbenchPart) iter.next();
579             Saveable saveable = getSaveable(part.getParticipant());
580             if (saveable != null) {
581                 result.add(saveable);
582             }
583         }
584         return (Saveable[]) result.toArray(new Saveable[result.size()]);
585     }
586
587     private Saveable getSaveable(ISynchronizeParticipant participant) {
588         if (participant instanceof ModelSynchronizeParticipant) {
589             ModelSynchronizeParticipant msp = (ModelSynchronizeParticipant) participant;
590             return msp.getActiveSaveable();
591         }
592         return null;
593     }
594
595     /* (non-Javadoc)
596      * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables()
597      */

598     public Saveable[] getActiveSaveables() {
599         ISynchronizeParticipant participant = getParticipant();
600         Saveable s = getSaveable(participant);
601         if (s != null)
602             return new Saveable[] { s };
603         return new Saveable[0];
604     }
605
606     /* (non-Javadoc)
607      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
608      */

609     public void doSave(IProgressMonitor monitor) {
610         Saveable[] saveables = getSaveables();
611         if (saveables.length == 0)
612             return;
613         monitor.beginTask(null, 100* saveables.length);
614         for (int i = 0; i < saveables.length; i++) {
615             Saveable saveable = saveables[i];
616             try {
617                 saveable.doSave(Policy.subMonitorFor(monitor, 100));
618             } catch (CoreException e) {
619                 ErrorDialog.openError(getSite().getShell(), null, e.getMessage(), e.getStatus());
620             }
621             Policy.checkCanceled(monitor);
622         }
623         monitor.done();
624         firePropertyChange(PROP_DIRTY);
625     }
626
627     /* (non-Javadoc)
628      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
629      */

630     public void doSaveAs() {
631         // Not allowed
632
}
633
634     /* (non-Javadoc)
635      * @see org.eclipse.ui.ISaveablePart#isDirty()
636      */

637     public boolean isDirty() {
638         Saveable[] saveables = getSaveables();
639         for (int i = 0; i < saveables.length; i++) {
640             Saveable saveable = saveables[i];
641             if (saveable.isDirty())
642                 return true;
643         }
644         return false;
645     }
646
647     /* (non-Javadoc)
648      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
649      */

650     public boolean isSaveAsAllowed() {
651         return false;
652     }
653
654     /* (non-Javadoc)
655      * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
656      */

657     public boolean isSaveOnCloseNeeded() {
658         return true;
659     }
660 }
661
Popular Tags