Skip to main content
summaryrefslogtreecommitdiffstats
blob: e4411c80eb5d094223af23932386223006ca1e32 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * 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.ote.ui.test.manager.util;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * @author Roberto E. Escobar
 */
public class EnvVariableDialog extends MessageDialog {

   private Button cancelButton;
   private String dialogMessage;

   private Button okButton;

   private String selection;
   private boolean selectionOk;
   private StyledText textArea;

   public EnvVariableDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
         int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
      super(parentShell, dialogTitle, dialogTitleImage, null, dialogImageType, dialogButtonLabels, defaultIndex);
      this.dialogMessage = dialogMessage;
      this.selectionOk = false;
   }

   public String getSelection() {
      return selection;
   }

   public boolean isValid() {
      return selectionOk;
   }

   @Override
   protected Control createButtonBar(Composite parent) {
      Control c = super.createButtonBar(parent);
      okButton = getButton(0);
      cancelButton = getButton(1);

      okButton.addSelectionListener(new SelectionListener() {

         public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
         }

         public void widgetSelected(SelectionEvent e) {
            selectionOk = true;

         }
      });

      cancelButton.addSelectionListener(new SelectionListener() {

         public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
         }

         public void widgetSelected(SelectionEvent e) {
            selectionOk = false;
         }
      });
      return c;
   }

   @Override
   protected Control createCustomArea(Composite parent) {
      super.createCustomArea(parent);

      GridData gd = new GridData(SWT.FILL);
      // gd.minimumWidth = 200;
      gd.grabExcessHorizontalSpace = true;

      Composite addView = new Composite(parent, SWT.NONE);
      GridLayout gridLayout = new GridLayout();
      gridLayout.numColumns = 2;
      addView.setLayout(gridLayout);
      addView.setLayoutData(gd);

      (new Label(addView, SWT.NONE)).setText(dialogMessage);

      GridData gd1 = new GridData(SWT.FILL);
      gd1.minimumWidth = 200;
      gd1.grabExcessHorizontalSpace = true;

      textArea = new StyledText(addView, SWT.SINGLE | SWT.BORDER);
      textArea.setLayoutData(gd1);
      textArea.addModifyListener(new ModifyListener() {

         public void modifyText(ModifyEvent e) {
            selection = textArea.getText();
         }
      });

      return parent;
   }

}

Back to the top