KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > ui > synchronize > ParticipantPagePane


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
12 package org.eclipse.team.ui.synchronize;
13
14 import org.eclipse.compare.CompareViewerPane;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jface.action.ToolBarManager;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.internal.ui.*;
22 import org.eclipse.team.internal.ui.synchronize.*;
23 import org.eclipse.ui.PartInitException;
24 import org.eclipse.ui.part.IPageBookViewPage;
25
26 /**
27  * Stand alone presentation of a participant page within a view pane. This
28  * allows showing a participant page with it's toolbar in dialogs and embedded
29  * in views and editors.
30  *
31  * @since 3.1
32  */

33 public final class ParticipantPagePane {
34
35     private ISynchronizeParticipant participant;
36     private ISynchronizePageConfiguration pageConfiguration;
37     private Image titleImage;
38     private Shell shell;
39     private boolean isModal;
40     
41     // SWT controls
42
private CompareViewerPane fEditionPane;
43     private IPageBookViewPage fPage;
44     private DialogSynchronizePageSite site;
45     
46     /**
47      * Creates a part for the provided participant. The page configuration is used when creating the participant page and the resulting
48      * compare/merge panes will be configured with the provided compare configuration.
49      * <p>
50      * For example, clients can decide if the user can edit the compare panes by calling {@link org.eclipse.compare.CompareConfiguration#setLeftEditable(boolean)}
51      * or {@link org.eclipse.compare.CompareConfiguration#setRightEditable(boolean)}.
52      * </p>
53      * @param shell the parent shell for this part
54      * @param isModal to set the pane as modal or not
55      * @param pageConfiguration the configuration that will be provided to the participant prior to creating the page
56      * @param participant the participant whose page will be displayed in this part
57      */

58     public ParticipantPagePane(Shell shell, boolean isModal, ISynchronizePageConfiguration pageConfiguration, ISynchronizeParticipant participant) {
59         this.isModal = isModal;
60         this.shell = shell;
61         this.participant = participant;
62         this.pageConfiguration = pageConfiguration;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.team.ui.SaveablePartAdapter#dispose()
67      */

68     public void dispose() {
69         if(titleImage != null) {
70             titleImage.dispose();
71         }
72         if (fPage != null) {
73             fPage.dispose();
74         }
75         if (site != null)
76             site.dispose();
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.ui.IWorkbenchPart#getTitleImage()
81      */

82     public Image getTitleImage() {
83         if(titleImage == null) {
84             titleImage = participant.getImageDescriptor().createImage();
85         }
86         return titleImage;
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.IWorkbenchPart#getTitle()
91      */

92     public String JavaDoc getTitle() {
93         return Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, participant.getName());
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
98      */

99     public Control createPartControl(Composite parent) {
100         Composite top = new Composite(parent, SWT.NULL);
101         GridLayout layout = new GridLayout();
102         layout.marginHeight = 0;
103         layout.marginWidth = 0;
104         layout.verticalSpacing = 0;
105         top.setLayout(layout);
106         
107         shell = parent.getShell();
108         
109         fEditionPane = new CompareViewerPane(top, SWT.BORDER | SWT.FLAT);
110         fEditionPane.setText(TeamUIMessages.ParticipantPageSaveablePart_0); //
111

112         fEditionPane.setLayoutData(SWTUtils.createHVFillGridData());
113         
114         fPage = participant.createPage(pageConfiguration);
115         site = new DialogSynchronizePageSite(shell, isModal);
116         ((SynchronizePageConfiguration)pageConfiguration).setSite(site);
117         ToolBarManager tbm = CompareViewerPane.getToolBarManager(fEditionPane);
118         site.createActionBars(tbm);
119         try {
120             ((ISynchronizePage)fPage).init(pageConfiguration.getSite());
121         } catch (PartInitException e1) {
122            TeamUIPlugin.log(IStatus.ERROR, TeamUIMessages.ParticipantPagePane_0, e1);
123         }
124
125         fPage.createControl(fEditionPane);
126         fPage.setActionBars(site.getActionBars());
127         fEditionPane.setContent(fPage.getControl());
128         tbm.update(true);
129         
130         return top;
131     }
132     
133     /**
134      * Return the synchronize page configuration for this part
135      *
136      * @return Returns the pageConfiguration.
137      */

138     public ISynchronizePageConfiguration getPageConfiguration() {
139         return pageConfiguration;
140     }
141     
142     /**
143      * Return the Synchronize participant for this part
144      *
145      * @return Returns the participant.
146      */

147     public ISynchronizeParticipant getParticipant() {
148         return participant;
149     }
150 }
151
Popular Tags