Skip to content

Package: DiffDialogHelper

DiffDialogHelper

nameinstructionbranchcomplexitylinemethod
getControlLabel(VControl, DiffMergeModelContext)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
showDialog(DiffMergeModelContext, VControl, String)
M: 92 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
showDialog(DiffMergeModelContext, int)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.diffmerge.swt;
15:
16: import org.eclipse.emf.ecp.diffmerge.spi.context.ControlPair;
17: import org.eclipse.emf.ecp.diffmerge.spi.context.DiffMergeModelContext;
18: import org.eclipse.emf.ecp.view.spi.model.VControl;
19: import org.eclipse.emfforms.spi.core.services.label.NoLabelFoundException;
20: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
21: import org.eclipse.swt.SWT;
22: import org.eclipse.swt.graphics.Rectangle;
23: import org.eclipse.swt.layout.FillLayout;
24: import org.eclipse.swt.widgets.Shell;
25:
26: /**
27: * The Diff Dialog helper provides methods to open a Diff Dialog.
28: *
29: * @author Eugen Neufeld
30: *
31: */
32: public final class DiffDialogHelper {
33:         private DiffDialogHelper() {
34:         }
35:
36:         /**
37:          * This opens a dialog displaying the differences of the elements of the {@link DiffMergeModelContext} based on the
38:          * index of the difference. If the index is not valid, less then 0 or greater equals the number of differences, then
39:          * an {@link IllegalArgumentException} is thrown.
40:          *
41:          * @param diffModelContext the {@link DiffMergeModelContext} containing the data
42:          * @param diffIndex the index of the difference
43:          * @throws IllegalArgumentException if the index is invalid
44:          */
45:         public static void showDialog(DiffMergeModelContext diffModelContext, int diffIndex)
46:                 throws IllegalArgumentException {
47:                 final VControl control = diffModelContext.getControl(diffIndex);
48:                 final String label = getControlLabel(control, diffModelContext);
49:                 showDialog(diffModelContext, control, label);
50:         }
51:
52:         /**
53:          * Opens a dialog displaying the differences of the elements of the {@link DiffMergeModelContext} based on the
54:          * provided {@link VControl}.
55:          *
56:          * @param diffModelContext the {@link DiffMergeModelContext} containing the data
57:          * @param vControl the {@link VControl} having the differences
58:          * @param featureLabel the feature text to use in the title of the dialog
59:          * @throws IllegalArgumentException if the controls doesn't have a difference
60:          */
61:         public static void showDialog(DiffMergeModelContext diffModelContext, VControl vControl, String featureLabel)
62:                 throws IllegalArgumentException {
63:                 final ControlPair pairWithDiff = diffModelContext.getPairWithDiff(vControl);
64:•                if (pairWithDiff == null) {
65:                         return;
66:                 }
67:                 final DiffDialog dialog = new DiffDialog(diffModelContext, featureLabel, pairWithDiff.getLeftControl(),
68:                         pairWithDiff.getRightControl(), vControl);
69:
70:                 final Shell shell = new Shell(SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.MAX | SWT.RESIZE);
71:                 final int index = diffModelContext.getIndexOf(vControl);
72:•                if (index == -1) {
73:                         throw new IllegalArgumentException("This VControl doesn't has a difference."); //$NON-NLS-1$
74:                 }
75:                 shell
76:                         .setText(String.format(
77:                                 LocalizationServiceHelper.getString(DiffDialogHelper.class, MessageKeys.DiffDialog_title),
78:                                 featureLabel, index + 1, diffModelContext.getTotalNumberOfDiffs()));
79:                 shell.setLayout(new FillLayout());
80:                 final Rectangle clientArea = shell.getDisplay().getBounds();
81:                 shell.setSize(clientArea.width / 2, 500);
82:                 dialog.create(shell);
83:                 shell.setLocation(clientArea.width / 4, clientArea.height / 4);
84:                 shell.open();
85:         }
86:
87:         private static String getControlLabel(VControl control, DiffMergeModelContext diffModelContext) {
88:                 try {
89:                         return (String) Activator.getInstance().getEMFFormsLabelProvider()
90:                                 .getDisplayName(control.getDomainModelReference(), diffModelContext.getDomainModel()).getValue();
91:                 } catch (final NoLabelFoundException e) {
92:                         return e.getMessage();
93:                 }
94:         }
95: }