1 /*******************************************************************************
2 * Copyright (C) 2018, Luís Copetti <lhcopetti@gmail.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.branch
;
13 import java
.util
.EnumMap
;
14 import java
.util
.LinkedHashMap
;
16 import java
.util
.Map
.Entry
;
18 import org
.eclipse
.egit
.core
.RepositoryUtil
;
19 import org
.eclipse
.egit
.ui
.internal
.LabelColumnComparator
;
20 import org
.eclipse
.egit
.ui
.internal
.UIText
;
21 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
22 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
23 import org
.eclipse
.jface
.layout
.GridDataFactory
;
24 import org
.eclipse
.jface
.layout
.TableColumnLayout
;
25 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
26 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
27 import org
.eclipse
.jface
.viewers
.ColumnWeightData
;
28 import org
.eclipse
.jface
.viewers
.TableViewer
;
29 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
30 import org
.eclipse
.jgit
.api
.CheckoutResult
;
31 import org
.eclipse
.jgit
.api
.CheckoutResult
.Status
;
32 import org
.eclipse
.jgit
.lib
.Repository
;
33 import org
.eclipse
.swt
.SWT
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Control
;
37 import org
.eclipse
.swt
.widgets
.Shell
;
38 import org
.eclipse
.swt
.widgets
.Table
;
39 import org
.eclipse
.swt
.widgets
.TableColumn
;
40 import org
.eclipse
.ui
.ISharedImages
;
41 import org
.eclipse
.ui
.PlatformUI
;
44 * Presents the result of a checkout operation for multiple repositories
47 public class MultiBranchOperationResultDialog
extends TitleAreaDialog
{
49 private final Map
<Repository
, CheckoutResult
> results
= new LinkedHashMap
<>();
51 private TableViewer tv
;
53 private EnumMap
<CheckoutResult
.Status
, String
> resultMessages
;
59 protected MultiBranchOperationResultDialog(Shell parentShell
,
60 Map
<Repository
, CheckoutResult
> results
) {
63 getShellStyle() & ~SWT
.APPLICATION_MODAL
| SWT
.SHELL_TRIM
);
64 setBlockOnOpen(false);
65 this.results
.putAll(results
);
67 this.initializeResultMessages();
71 protected Control
createDialogArea(Composite parent
) {
72 Composite main
= new Composite(parent
, SWT
.NONE
);
73 tv
= new TableViewer(main
, SWT
.MULTI
| SWT
.FULL_SELECTION
| SWT
.BORDER
);
74 tv
.setContentProvider(ArrayContentProvider
.getInstance());
75 TableColumnLayout layout
= new TableColumnLayout();
76 main
.setLayout(layout
);
78 Table table
= tv
.getTable();
79 TableViewerColumn tc
= new TableViewerColumn(tv
, SWT
.NONE
);
80 TableColumn col
= tc
.getColumn();
81 tc
.setLabelProvider(new ColumnLabelProvider() {
83 public String
getText(Object element
) {
84 @SuppressWarnings("unchecked")
85 Entry
<Repository
, CheckoutResult
> item
= (Entry
<Repository
, CheckoutResult
>) element
;
86 return RepositoryUtil
.INSTANCE
.getRepositoryName(item
.getKey());
90 UIText
.MultiBranchOperationResultDialog_RepositoryColumnHeader
);
91 layout
.setColumnData(col
, new ColumnWeightData(200, 200));
92 createComparator(col
, 0);
95 tc
= new TableViewerColumn(tv
, SWT
.NONE
);
97 tc
.setLabelProvider(new ColumnLabelProvider() {
100 public Image
getImage(Object element
) {
101 @SuppressWarnings("unchecked")
102 Entry
<Repository
, CheckoutResult
> item
= (Entry
<Repository
, CheckoutResult
>) element
;
104 if (item
.getValue().getStatus() == Status
.OK
) {
107 return PlatformUI
.getWorkbench().getSharedImages()
108 .getImage(ISharedImages
.IMG_ELCL_STOP
);
112 public String
getText(Object element
) {
113 @SuppressWarnings("unchecked")
114 Entry
<Repository
, CheckoutResult
> item
= (Entry
<Repository
, CheckoutResult
>) element
;
116 CheckoutResult
.Status status
= item
.getValue().getStatus();
117 return getMessageForStatus(status
);
121 UIText
.MultiBranchOperationResultDialog_CheckoutStatusColumnHeader
);
122 layout
.setColumnData(col
, new ColumnWeightData(200, 450));
123 createComparator(col
, 1);
125 table
.setHeaderVisible(true);
126 table
.setLinesVisible(true);
127 tv
.setInput(results
.entrySet());
129 int linesToShow
= Math
.min(Math
.max(results
.size(), 5), 15);
130 int height
= table
.getItemHeight() * linesToShow
;
132 GridDataFactory
.fillDefaults().grab(true, true)
133 .minSize(SWT
.DEFAULT
, height
).applyTo(main
);
135 setTitle(UIText
.MultiBranchOperationResultDialog_DialogTitle
);
137 UIText
.MultiBranchOperationResultDialog_DialogErrorMessage
);
142 protected void createButtonsForButtonBar(Composite parent
) {
143 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
,
148 protected void configureShell(Shell newShell
) {
149 super.configureShell(newShell
);
150 newShell
.setText(UIText
.MultiBranchOperationResultDialog_WindowTitle
);
153 private LabelColumnComparator
createComparator(TableColumn column
,
155 return new LabelColumnComparator(this.tv
, column
, columnIndex
);
158 private void initializeResultMessages() {
159 this.resultMessages
= new EnumMap
<>(CheckoutResult
.Status
.class);
161 this.resultMessages
.put(Status
.OK
,
162 UIText
.MultiBranchOperationResultDialog_CheckoutResultOK
);
163 this.resultMessages
.put(Status
.CONFLICTS
,
164 UIText
.MultiBranchOperationResultDialog_CheckoutResultConflicts
);
165 this.resultMessages
.put(Status
.NOT_TRIED
,
166 UIText
.MultiBranchOperationResultDialog_CheckoutResultNotTried
);
167 this.resultMessages
.put(Status
.NONDELETED
,
168 UIText
.MultiBranchOperationResultDialog_CheckoutResultNonDeleted
);
169 this.resultMessages
.put(Status
.ERROR
,
170 UIText
.MultiBranchOperationResultDialog_CheckoutResultError
);
173 private String
getMessageForStatus(CheckoutResult
.Status status
) {
174 return this.resultMessages
.getOrDefault(status
, ""); //$NON-NLS-1$