Skip to content

Package: DialogToggleInteraction

DialogToggleInteraction

nameinstructionbranchcomplexitylinemethod
DialogToggleInteraction()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
askQuestion(String, String, String)
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getAnswerCode(int)
M: 10 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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: * Stefan Dirix - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.emf2web.exporter;
15:
16: import org.eclipse.jface.dialogs.IDialogConstants;
17: import org.eclipse.jface.dialogs.MessageDialogWithToggle;
18: import org.eclipse.swt.SWT;
19: import org.eclipse.swt.widgets.Display;
20: import org.eclipse.swt.widgets.Shell;
21:
22: /**
23: * @author Stefan Dirix
24: *
25: */
26: public class DialogToggleInteraction implements UserInteraction {
27:
28:         private boolean askAgain;
29:         private int lastAnswer;
30:
31:         /**
32:          * Constructor.
33:          */
34:         public DialogToggleInteraction() {
35:                 askAgain = true;
36:                 lastAnswer = SWT.NO;
37:         }
38:
39:         @Override
40:         public int askQuestion(String title, String question, String toggleQuestion) {
41:•                if (!askAgain) {
42:                         return lastAnswer;
43:                 }
44:
45:                 final Shell shell = Display.getDefault().getActiveShell();
46:                 final MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell, title,
47:                         question,
48:                         toggleQuestion, false, null, null);
49:•                if (dialog.getToggleState()) {
50:                         askAgain = false;
51:                 }
52:                 lastAnswer = getAnswerCode(dialog.getReturnCode());
53:                 return lastAnswer;
54:         }
55:
56:         private int getAnswerCode(int dialogCode) {
57:•                switch (dialogCode) {
58:                 case IDialogConstants.YES_ID:
59:                         return YES;
60:                 case IDialogConstants.NO_ID:
61:                         return NO;
62:                 case IDialogConstants.CANCEL_ID:
63:                         return CANCEL;
64:                 default:
65:                         return NO;
66:                 }
67:         }
68:
69: }