KickJava   Java API By Example, From Geeks To Geeks.

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


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.viewers.Viewer;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.team.internal.ui.TeamUIPlugin;
21 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
22 import org.eclipse.ui.forms.HyperlinkGroup;
23 import org.eclipse.ui.forms.widgets.FormToolkit;
24 import org.eclipse.ui.part.PageBook;
25
26 /**
27  * Section shown in a participant page to show the changes for this participant. This
28  * includes a diff viewer for browsing the changes.
29  *
30  * @since 3.2
31  */

32 public class ChangesSection extends Composite {
33
34     private AbstractSynchronizePage page;
35     private ISynchronizePageConfiguration configuration;
36     private FormToolkit forms;
37     
38     /**
39      * Page book either shows the diff tree viewer if there are changes or
40      * shows a message to the user if there are no changes that would be
41      * shown in the tree.
42      */

43     private PageBook changesSectionContainer;
44     
45     /**
46      * Diff tree viewer that shows synchronization changes. This is created
47      * by the participant.
48      */

49     private Viewer changesViewer;
50
51     /**
52      * Create a changes section on the following page.
53      *
54      * @param parent the parent control
55      * @param page the page showing this section
56      */

57     public ChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) {
58         super(parent, SWT.NONE);
59         this.page = page;
60         this.configuration = configuration;
61         
62         GridLayout layout = new GridLayout();
63         layout.marginHeight = 0;
64         layout.marginWidth = 0;
65         setLayout(layout);
66         GridData data = new GridData(GridData.FILL_BOTH);
67         data.grabExcessVerticalSpace = true;
68         setLayoutData(data);
69         
70         forms = new FormToolkit(parent.getDisplay());
71         forms.setBackground(getBackgroundColor());
72         HyperlinkGroup group = forms.getHyperlinkGroup();
73         group.setBackground(getBackgroundColor());
74         
75         changesSectionContainer = new PageBook(this, SWT.NONE);
76         data = new GridData(GridData.FILL_BOTH);
77         data.grabExcessHorizontalSpace = true;
78         data.grabExcessVerticalSpace = true;
79         changesSectionContainer.setLayoutData(data);
80     }
81     
82     protected Color getBackgroundColor() {
83         return getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
84     }
85     
86     public PageBook getContainer() {
87         return changesSectionContainer;
88     }
89
90     protected ISynchronizePageConfiguration getConfiguration() {
91         return configuration;
92     }
93
94     protected FormToolkit getForms() {
95         return forms;
96     }
97
98     protected AbstractSynchronizePage getPage() {
99         return page;
100     }
101     
102     /* (non-Javadoc)
103      * @see org.eclipse.swt.widgets.Widget#dispose()
104      */

105     public void dispose() {
106         super.dispose();
107         forms.dispose();
108     }
109     
110     public void setViewer(Viewer viewer) {
111         this.changesViewer = viewer;
112         initializeChangesViewer();
113     }
114
115     protected void initializeChangesViewer() {
116         TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
117             public void run() {
118                 Control control = ChangesSection.this.getChangesViewer().getControl();
119                 if (!getContainer().isDisposed() && !control.isDisposed()) {
120                     getContainer().showPage(control);
121                 }
122             }
123         });
124     }
125
126     public Viewer getChangesViewer() {
127         return changesViewer;
128     }
129     
130     protected boolean isThreeWay() {
131         return ISynchronizePageConfiguration.THREE_WAY.equals(getConfiguration().getComparisonType());
132     }
133 }
134
Popular Tags