Skip to main content
summaryrefslogtreecommitdiffstats
blob: 047b34bec832991bc4f4080736a7a6f12ec40fe8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.widgets.dialog;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

public class CheckBoxDialog extends MessageDialog {

   private Button checkButton;
   boolean fillVertically = false;
   private final String checkBoxMessage;

   //Have to save off the value so it is available after the dialog is closed since checkButton will get disposed.
   private boolean checked = false;

   public CheckBoxDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, String checkBoxMessage, int dialogImageType, int defaultIndex) {
      super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, new String[] {"OK", "Cancel"},
         defaultIndex);
      this.checkBoxMessage = checkBoxMessage;
      setBlockOnOpen(true);
   }

   public CheckBoxDialog(String dialogTitle, String dialogMessage, String checkBoxMessage) {
      this(Displays.getActiveShell(), dialogTitle, null, dialogMessage, checkBoxMessage, MessageDialog.QUESTION, 0);
   }

   @Override
   protected Control createCustomArea(Composite parent) {
      Composite composite = new Composite(parent, SWT.NONE);
      composite.setLayout(new GridLayout(2, false));
      composite.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

      checkButton = new Button(composite, SWT.CHECK);
      checkButton.setText(checkBoxMessage);
      checkButton.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            checked = checkButton.getSelection();
         }
      });

      return composite;
   }

   public boolean isChecked() {
      return checked;
   }
}

Back to the top