~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/uistructures/StapSettingsDialog.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.uistructures;
 
13
 
 
14
import org.eclipse.jface.dialogs.Dialog;
 
15
import org.eclipse.linuxtools.internal.systemtap.ui.ide.Localization;
 
16
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants;
 
17
import org.eclipse.linuxtools.systemtap.ui.logging.LogManager;
 
18
import org.eclipse.swt.SWT;
 
19
import org.eclipse.swt.events.KeyEvent;
 
20
import org.eclipse.swt.events.KeyListener;
 
21
import org.eclipse.swt.graphics.Rectangle;
 
22
import org.eclipse.swt.layout.GridLayout;
 
23
import org.eclipse.swt.widgets.Button;
 
24
import org.eclipse.swt.widgets.Composite;
 
25
import org.eclipse.swt.widgets.Control;
 
26
import org.eclipse.swt.widgets.Shell;
 
27
import org.eclipse.swt.widgets.Text;
 
28
 
 
29
 
 
30
import org.eclipse.swt.widgets.Label;
 
31
 
 
32
 
 
33
/**
 
34
 * A dialog box displayed to prompt the user for additional arguments to pass to stap when the
 
35
 * user presses the Run with Options button.
 
36
 * @author Ryan Morse
 
37
 *
 
38
 */
 
39
public class StapSettingsDialog extends Dialog {
 
40
        public StapSettingsDialog(Shell parentShell) {
 
41
                super(parentShell);
 
42
                LogManager.logDebug("Start/End StapSettingsDialog: parentShell-" + parentShell, this);
 
43
                LogManager.logInfo("Initializing", this);
 
44
        }
 
45
        
 
46
        protected void configureShell(Shell shell) {
 
47
                super.configureShell(shell);
 
48
                LogManager.logDebug("Start configureShell: shell-" + shell, this);
 
49
                shell.setText(Localization.getString("StapSettingsDialog.StapOptions"));
 
50
                shell.setSize(new org.eclipse.swt.graphics.Point(640,170 + ((1+checkBox.length)>>1) + 50*((1+text.length)>>1)));
 
51
                LogManager.logDebug("End configureShell:", this);
 
52
        }
 
53
 
 
54
        protected Control createDialogArea(Composite parent) {
 
55
                LogManager.logDebug("Start createDialogArea: parent-" + parent, this);
 
56
                Composite comp = (Composite) super.createDialogArea(parent);
 
57
                
 
58
                //Check boxes
 
59
                GridLayout gridLayout = new GridLayout();
 
60
                gridLayout.numColumns = 2;
 
61
                cmpChkBoxes = new Composite(comp, SWT.NONE);
 
62
                cmpChkBoxes.setLayout(gridLayout);
 
63
                cmpChkBoxes.setBounds(new Rectangle(100,5,460,30*((1+checkBox.length)>>1)));
 
64
                
 
65
                int i;
 
66
                for(i=0; i<IDEPreferenceConstants.P_STAP.length - IDEPreferenceConstants.P_STAP_OPTS.length; i++) {
 
67
                        checkBox[i] = new Button(cmpChkBoxes, SWT.CHECK);
 
68
                        checkBox[i].setText(IDEPreferenceConstants.P_STAP[i][0] + IDEPreferenceConstants.P_STAP[i][1]);
 
69
                        checkBox[i].setBackground(cmpChkBoxes.getBackground());
 
70
                }
 
71
                
 
72
                //Labels and Text fields
 
73
                cmpTxtBoxes = new Composite(comp, SWT.NONE);
 
74
                cmpTxtBoxes.setBounds(new Rectangle(5,5+30*((1+checkBox.length)>>1),620,50*((1+text.length)>>1)));
 
75
 
 
76
                for(int j=0; j<IDEPreferenceConstants.P_STAP_OPTS.length; i++, j++) {
 
77
                        label[j] = new Label(cmpTxtBoxes, SWT.NONE);
 
78
                        label[j].setBounds(new Rectangle(320*(j/5),50*(j%5),300,17));
 
79
                        label[j].setText(IDEPreferenceConstants.P_STAP[i][0] + IDEPreferenceConstants.P_STAP[i][1]);
 
80
                        label[j].setBackground(cmpChkBoxes.getBackground());
 
81
                        text[j] = new Text(cmpTxtBoxes, SWT.BORDER);
 
82
                        text[j].setBounds(new Rectangle(320*(j/5),20+50*(j%5),300,27));
 
83
 
 
84
                        if("-v".equals(IDEPreferenceConstants.P_STAP[i][0])) {
 
85
                                text[j].addKeyListener(new KeyListener() {
 
86
                                        public void keyPressed(KeyEvent e) {
 
87
                                                if('v' != e.character) {
 
88
                                                        e.doit = false;
 
89
                                                }
 
90
                                        }
 
91
                                        
 
92
                                        public void keyReleased(KeyEvent e) {}
 
93
                                });
 
94
                        } else if("-p NUM".equals(IDEPreferenceConstants.P_STAP[i][0])) {
 
95
                                text[j].addKeyListener(new KeyListener() {
 
96
                                        public void keyPressed(KeyEvent e) {
 
97
                                                if(32 <= e.character && 126 >= e.character) {
 
98
                                                        if('1' > e.character || '5' < e.character)
 
99
                                                                e.doit = false;
 
100
                                                        else if(0 < text[1].getText().length())
 
101
                                                                e.doit = false;
 
102
                                                }
 
103
                                        }
 
104
                                        
 
105
                                        public void keyReleased(KeyEvent e) {}
 
106
                                });
 
107
                        } else if("-s NUM".equals(IDEPreferenceConstants.P_STAP[i][0])) {
 
108
                                text[j].addKeyListener(new KeyListener() {
 
109
                                        public void keyPressed(KeyEvent e) {
 
110
                                                if(32 <= e.character && 126 >= e.character) {
 
111
                                                        if(!Character.isDigit(e.character))
 
112
                                                                e.doit = false;
 
113
                                                }
 
114
                                        }
 
115
                                        
 
116
                                        public void keyReleased(KeyEvent e) {}
 
117
                                });
 
118
                        }
 
119
                }
 
120
                
 
121
                LogManager.logDebug("End createDialogArea: returnVal-" + comp, this);
 
122
                return comp;
 
123
        }
 
124
  
 
125
        protected void buttonPressed(int buttonID) {
 
126
                LogManager.logDebug("Start buttonPressed: buttonID-" + buttonID, this);
 
127
                if(0 == buttonID) {     //OK
 
128
                        cmdOpts = new boolean[checkBox.length];
 
129
                        cmdOptVals = new String[text.length];
 
130
                        
 
131
                        for(int i=0; i<cmdOpts.length; i++)
 
132
                                cmdOpts[i] = checkBox[i].getSelection();
 
133
                        
 
134
                        for(int i=0; i<cmdOptVals.length; i++)
 
135
                                cmdOptVals[i] = text[i].getText();
 
136
                }
 
137
                
 
138
                super.buttonPressed(buttonID);
 
139
                LogManager.logDebug("End buttonPressed:", this);
 
140
        }
 
141
        
 
142
        public boolean[] getStapOpts() {
 
143
                LogManager.logDebug("Start/End getStapOpts: returnVal-" + cmdOpts, this);
 
144
                return cmdOpts;
 
145
        }
 
146
        
 
147
        public String[] getStapOptVals() {
 
148
                LogManager.logDebug("Start/End getStapOptVals: returnVal-" + cmdOptVals, this);
 
149
                return cmdOptVals;
 
150
        }
 
151
        
 
152
        public void dispose() {
 
153
                LogManager.logInfo("Disposing", this);
 
154
                cmdOpts = null;
 
155
                cmdOptVals = null;
 
156
                cmpChkBoxes.dispose();
 
157
                cmpTxtBoxes.dispose();
 
158
                for(int i=0; i<checkBox.length; i++)
 
159
                        checkBox[i].dispose();
 
160
                checkBox = null;
 
161
                for(int i=0; i<label.length; i++) {
 
162
                        label[i].dispose();
 
163
                        text[i].dispose();
 
164
                }
 
165
                label = null;
 
166
                text = null;
 
167
        }
 
168
        
 
169
        //private static String[] tapsets = null;
 
170
        private static boolean[] cmdOpts = null;
 
171
        private static String[] cmdOptVals = null;
 
172
        
 
173
        private Composite cmpChkBoxes = null;
 
174
        private Composite cmpTxtBoxes = null;
 
175
        private Button checkBox[] = new Button[IDEPreferenceConstants.P_STAP.length - IDEPreferenceConstants.P_STAP_OPTS.length];
 
176
        private Label label[] = new Label[IDEPreferenceConstants.P_STAP_OPTS.length];
 
177
        private Text text[] = new Text[IDEPreferenceConstants.P_STAP_OPTS.length];
 
178
}
 
 
b'\\ No newline at end of file'