1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 SAP AG and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License 2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-2.0/
8 * SPDX-License-Identifier: EPL-2.0
11 * Mathias Kinzler (SAP AG) - initial implementation
12 * Markus Keller <markus_keller@ch.ibm.com> - Show the repository name in the title of the Pull Result dialog
13 *******************************************************************************/
14 package org
.eclipse
.egit
.ui
.internal
.pull
;
16 import org
.eclipse
.egit
.ui
.Activator
;
17 import org
.eclipse
.egit
.ui
.UIUtils
;
18 import org
.eclipse
.egit
.ui
.internal
.UIText
;
19 import org
.eclipse
.egit
.ui
.internal
.fetch
.FetchResultDialog
;
20 import org
.eclipse
.egit
.ui
.internal
.merge
.MergeResultDialog
;
21 import org
.eclipse
.egit
.ui
.internal
.rebase
.RebaseResultDialog
;
22 import org
.eclipse
.jface
.dialogs
.Dialog
;
23 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
24 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
25 import org
.eclipse
.jface
.layout
.GridDataFactory
;
26 import org
.eclipse
.jface
.layout
.GridLayoutFactory
;
27 import org
.eclipse
.jgit
.api
.MergeResult
;
28 import org
.eclipse
.jgit
.api
.MergeResult
.MergeStatus
;
29 import org
.eclipse
.jgit
.api
.PullResult
;
30 import org
.eclipse
.jgit
.api
.RebaseResult
;
31 import org
.eclipse
.jgit
.api
.RebaseResult
.Status
;
32 import org
.eclipse
.jgit
.lib
.Repository
;
33 import org
.eclipse
.jgit
.transport
.FetchResult
;
34 import org
.eclipse
.osgi
.util
.NLS
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.graphics
.Point
;
37 import org
.eclipse
.swt
.layout
.GridData
;
38 import org
.eclipse
.swt
.widgets
.Button
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Control
;
41 import org
.eclipse
.swt
.widgets
.Group
;
42 import org
.eclipse
.swt
.widgets
.Label
;
43 import org
.eclipse
.swt
.widgets
.Shell
;
46 * Display the result of a pull.
48 * Simply combines fetch and merge result dialogs into one dialog.
50 public class PullResultDialog
extends Dialog
{
51 private final Repository repo
;
53 private final PullResult result
;
55 private boolean persistSize
;
62 public PullResultDialog(Shell shell
, Repository repo
, PullResult result
) {
64 setShellStyle(getShellStyle() & ~SWT
.APPLICATION_MODAL
| SWT
.SHELL_TRIM
);
65 setBlockOnOpen(false);
68 persistSize
= hasFetchResults() || hasMergeResults();
71 private boolean hasFetchResults() {
72 final FetchResult fetchResult
= result
.getFetchResult();
73 return fetchResult
!= null
74 && !fetchResult
.getTrackingRefUpdates().isEmpty();
77 private boolean hasMergeResults() {
78 final MergeResult mergeResult
= result
.getMergeResult();
79 return mergeResult
!= null
80 && mergeResult
.getMergeStatus() != MergeStatus
.ALREADY_UP_TO_DATE
;
83 private boolean hasRebaseResults() {
84 final RebaseResult rebaseResult
= result
.getRebaseResult();
85 return rebaseResult
!= null
86 && rebaseResult
.getStatus() != Status
.UP_TO_DATE
;
90 protected Control
createDialogArea(Composite parent
) {
91 Composite main
= new Composite(parent
, SWT
.NONE
);
92 GridLayoutFactory
.swtDefaults().applyTo(main
);
93 GridDataFactory
.fillDefaults().indent(0, 0).grab(true, true).applyTo(
95 Group fetchResultGroup
= new Group(main
, SWT
.SHADOW_ETCHED_IN
);
97 .setText(UIText
.PullResultDialog_FetchResultGroupHeader
);
98 GridLayoutFactory
.fillDefaults().applyTo(fetchResultGroup
);
99 GridDataFactory
.fillDefaults().grab(true, true).applyTo(
101 FetchResult fRes
= result
.getFetchResult();
102 if (hasFetchResults()) {
103 GridLayoutFactory
.fillDefaults().applyTo(fetchResultGroup
);
104 FetchResultDialog dlg
= new FetchResultDialog(getParentShell(),
105 repo
, fRes
, result
.getFetchedFrom());
106 Control fresult
= dlg
.createFetchResultTable(fetchResultGroup
);
107 Object layoutData
= fresult
.getLayoutData();
108 if (layoutData
instanceof GridData
)
109 GridDataFactory
.createFrom((GridData
) layoutData
)
110 .hint(SWT
.DEFAULT
, 130).applyTo(fresult
);
113 GridLayoutFactory
.swtDefaults().applyTo(fetchResultGroup
);
114 Label noResult
= new Label(fetchResultGroup
, SWT
.NONE
);
115 if (result
.getFetchedFrom().equals(".")) //$NON-NLS-1$
117 .setText(UIText
.PullResultDialog_NothingToFetchFromLocal
);
119 noResult
.setText(NLS
.bind(
120 UIText
.FetchResultDialog_labelEmptyResult
, result
124 Group mergeResultGroup
= new Group(main
, SWT
.SHADOW_ETCHED_IN
);
126 .setText(UIText
.PullResultDialog_MergeResultGroupHeader
);
127 if (hasMergeResults()) {
128 GridDataFactory
.fillDefaults().grab(true, true).applyTo(
130 GridLayoutFactory
.fillDefaults().applyTo(mergeResultGroup
);
131 MergeResultDialog dlg
= new MergeResultDialog(getParentShell(),
132 repo
, result
.getMergeResult());
133 dlg
.createDialogArea(mergeResultGroup
);
134 } else if (hasRebaseResults()) {
135 RebaseResultDialog
.createFailedOrConflictsParts(mergeResultGroup
,
136 result
.getRebaseResult());
137 GridDataFactory
.fillDefaults().grab(true, false).applyTo(
140 GridDataFactory
.fillDefaults().grab(true, false).applyTo(
142 GridLayoutFactory
.swtDefaults().applyTo(mergeResultGroup
);
143 Label noResult
= new Label(mergeResultGroup
, SWT
.NONE
);
145 .setText(UIText
.PullResultDialog_MergeAlreadyUpToDateMessage
);
151 protected void createButtonsForButtonBar(Composite parent
) {
152 Button okayButton
= createButton(parent
, IDialogConstants
.OK_ID
,
153 IDialogConstants
.CLOSE_LABEL
,
155 okayButton
.setFocus();
159 protected void configureShell(Shell newShell
) {
160 super.configureShell(newShell
);
161 newShell
.setText(NLS
.bind(
162 UIText
.PullResultDialog_DialogTitle
,
163 Activator
.getDefault().getRepositoryUtil()
164 .getRepositoryName(repo
)));
168 protected IDialogSettings
getDialogBoundsSettings() {
169 return UIUtils
.getDialogBoundSettings(getClass());
173 protected int getDialogBoundsStrategy() {
174 int strategy
= DIALOG_PERSISTLOCATION
;
176 strategy
|= DIALOG_PERSISTSIZE
;
181 protected Point
getInitialSize() {
183 // For "small" dialogs with label-only results, use the default
184 // height and the persisted width
185 Point size
= super.getInitialSize();
186 size
.x
= getPersistedSize().x
;
189 return super.getInitialSize();
192 private Point
getPersistedSize() {
193 boolean oldPersistSize
= persistSize
;
194 // This affects getDialogBoundsStrategy
197 Point persistedSize
= super.getInitialSize();
198 return persistedSize
;
200 persistSize
= oldPersistSize
;