Skip to content

Package: ViewMigrationResultDialog

ViewMigrationResultDialog

nameinstructionbranchcomplexitylinemethod
ViewMigrationResultDialog(Shell, Map, boolean)
M: 59 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
configureShell(Shell)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
create()
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createButtonsForButtonBar(Composite)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createDialogArea(Composite)
M: 131 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
isResizable()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2017 EclipseSource Muenchen GmbH and others.
3: *
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/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Edgar Mueller - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ide.internal.migration;
15:
16: import java.util.LinkedList;
17: import java.util.List;
18: import java.util.Map;
19:
20: import org.eclipse.emf.common.util.Diagnostic;
21: import org.eclipse.emf.ecp.internal.ui.validation.ValidationTreeViewerFactory;
22: import org.eclipse.emfforms.common.Optional;
23: import org.eclipse.jface.dialogs.IDialogConstants;
24: import org.eclipse.jface.dialogs.TitleAreaDialog;
25: import org.eclipse.jface.viewers.ArrayContentProvider;
26: import org.eclipse.jface.viewers.ListViewer;
27: import org.eclipse.jface.viewers.TreeViewer;
28: import org.eclipse.swt.SWT;
29: import org.eclipse.swt.layout.GridData;
30: import org.eclipse.swt.layout.GridLayout;
31: import org.eclipse.swt.widgets.Composite;
32: import org.eclipse.swt.widgets.Control;
33: import org.eclipse.swt.widgets.Label;
34: import org.eclipse.swt.widgets.Shell;
35:
36: /**
37: * Dialog that show the result of migration.
38: */
39: public class ViewMigrationResultDialog extends TitleAreaDialog {
40:
41:         private final List<Diagnostic> errors;
42:         private final List<String> unresolvedViews;
43:
44:         /**
45:          * Constructor.
46:          *
47:          * @param parentShell the parent shell
48:          * @param diagnostics the validation result of the migration
49:          * @param showWarnings whether migration warnings should be shown
50:          */
51:         public ViewMigrationResultDialog(Shell parentShell, Map<String, Optional<Diagnostic>> diagnostics,
52:                 boolean showWarnings) {
53:                 super(parentShell);
54:                 errors = new LinkedList<Diagnostic>();
55:                 unresolvedViews = new LinkedList<String>();
56:
57:•                if (showWarnings) {
58:•                        for (final Map.Entry<String, Optional<Diagnostic>> diagnostic : diagnostics.entrySet()) {
59:                                 final Optional<Diagnostic> diag = diagnostic.getValue();
60:•                                if (diag.isPresent() && diag.get().getSeverity() == Diagnostic.ERROR) {
61:                                         errors.add(diag.get());
62:•                                } else if (!diag.isPresent()) {
63:                                         unresolvedViews.add(diagnostic.getKey());
64:                                 }
65:                         }
66:                 }
67:         }
68:
69:         /**
70:          * {@inheritDoc}
71:          *
72:          * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
73:          */
74:         @Override
75:         protected void configureShell(Shell newShell) {
76:                 super.configureShell(newShell);
77:                 newShell.setText(Messages.ViewMigrationResultDialog_ShellTitle);
78:         }
79:
80:         /**
81:          * {@inheritDoc}
82:          *
83:          * @see org.eclipse.jface.dialogs.Dialog#isResizable()
84:          */
85:         @Override
86:         protected boolean isResizable() {
87:                 return true;
88:         }
89:
90:         /**
91:          * {@inheritDoc}
92:          *
93:          * @see org.eclipse.jface.dialogs.Dialog#create()
94:          */
95:         @Override
96:         public void create() {
97:                 super.create();
98:                 setTitle(Messages.ViewMigrationResultDialog_Title);
99:•                setMessage(errors.isEmpty() ? Messages.ViewMigrationResultDialog_MigrationSuccessMessage
100:                         : Messages.ViewMigrationResultDialog_MigrationFailureMessage);
101:         }
102:
103:         /**
104:          * {@inheritDoc}
105:          *
106:          * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite)
107:          */
108:         @Override
109:         protected Control createDialogArea(Composite parent) {
110:                 final Composite area = (Composite) super.createDialogArea(parent);
111:                 area.setLayout(new GridLayout(1, true));
112:
113:                 final Composite container = new Composite(area, SWT.NONE);
114:                 container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
115:                 final GridLayout layout = new GridLayout(1, false);
116:                 container.setLayout(layout);
117:
118:•                if (errors.isEmpty() && unresolvedViews.isEmpty()) {
119:                         final Label label = new Label(container, SWT.NONE);
120:                         label.setText(Messages.ViewMigrationResultDialog_MigrationSuccess);
121:                         label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
122:                 }
123:
124:•                if (!errors.isEmpty()) {
125:                         final TreeViewer diagnosticView = ValidationTreeViewerFactory.createValidationViewer(container);
126:                         diagnosticView.setInput(errors);
127:                         diagnosticView.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
128:                 }
129:
130:•                if (!unresolvedViews.isEmpty()) {
131:                         final Label label = new Label(container, SWT.NONE);
132:                         label.setText(Messages.ViewMigrationResultDialog_UnresolvedViews);
133:                         label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
134:                         final ListViewer listViewer = new ListViewer(container);
135:                         listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
136:                         listViewer.setContentProvider(new ArrayContentProvider());
137:                         listViewer.setInput(unresolvedViews);
138:                 }
139:
140:                 return parent;
141:         }
142:
143:         /**
144:          * {@inheritDoc}
145:          *
146:          * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
147:          */
148:         @Override
149:         protected void createButtonsForButtonBar(Composite parent) {
150:                 // create only OK button
151:                 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
152:         }
153: }