|
| 1 | +package org.nodeclipse.debug.launch; |
| 2 | + |
| 3 | +import org.eclipse.core.runtime.CoreException; |
| 4 | +import org.eclipse.debug.core.ILaunchConfiguration; |
| 5 | +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
| 6 | +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
| 7 | +import org.eclipse.debug.ui.StringVariableSelectionDialog; |
| 8 | +import org.eclipse.swt.SWT; |
| 9 | +import org.eclipse.swt.events.ModifyEvent; |
| 10 | +import org.eclipse.swt.events.ModifyListener; |
| 11 | +import org.eclipse.swt.events.SelectionAdapter; |
| 12 | +import org.eclipse.swt.events.SelectionEvent; |
| 13 | +import org.eclipse.swt.events.TraverseEvent; |
| 14 | +import org.eclipse.swt.events.TraverseListener; |
| 15 | +import org.eclipse.swt.graphics.Font; |
| 16 | +import org.eclipse.swt.layout.GridData; |
| 17 | +import org.eclipse.swt.layout.GridLayout; |
| 18 | +import org.eclipse.swt.widgets.Button; |
| 19 | +import org.eclipse.swt.widgets.Composite; |
| 20 | +import org.eclipse.swt.widgets.Group; |
| 21 | +import org.eclipse.swt.widgets.Label; |
| 22 | +import org.eclipse.swt.widgets.Text; |
| 23 | +import org.nodeclipse.debug.util.Constants; |
| 24 | + |
| 25 | +public class NodeArgumentsTab extends AbstractLaunchConfigurationTab { |
| 26 | + protected Label fPrgmArgumentsLabel; |
| 27 | + protected Text fPrgmArgumentsText; |
| 28 | + |
| 29 | + // Node arguments widgets |
| 30 | + protected Label fNodeArgumentsLabel; |
| 31 | + protected Text fNodeArgumentsText; |
| 32 | + |
| 33 | + @Override |
| 34 | + public void createControl(Composite parent) { |
| 35 | + Font font = parent.getFont(); |
| 36 | + Composite comp = new Composite(parent, SWT.NONE); |
| 37 | + GridLayout layout = new GridLayout(1, true); |
| 38 | + comp.setLayout(layout); |
| 39 | + comp.setFont(font); |
| 40 | + |
| 41 | + GridData gd = new GridData(GridData.FILL_BOTH); |
| 42 | + comp.setLayoutData(gd); |
| 43 | + setControl(comp); |
| 44 | + //setHelpContextId(); |
| 45 | + |
| 46 | + Group group = new Group(comp, SWT.NONE); |
| 47 | + group.setFont(font); |
| 48 | + layout = new GridLayout(); |
| 49 | + group.setLayout(layout); |
| 50 | + group.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 51 | + |
| 52 | + group.setText("Program Arguments"); |
| 53 | + |
| 54 | + fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); |
| 55 | + fPrgmArgumentsText.addTraverseListener(new TraverseListener() { |
| 56 | + public void keyTraversed(TraverseEvent e) { |
| 57 | + switch (e.detail) { |
| 58 | + case SWT.TRAVERSE_ESCAPE: |
| 59 | + case SWT.TRAVERSE_PAGE_NEXT: |
| 60 | + case SWT.TRAVERSE_PAGE_PREVIOUS: |
| 61 | + e.doit = true; |
| 62 | + break; |
| 63 | + case SWT.TRAVERSE_RETURN: |
| 64 | + case SWT.TRAVERSE_TAB_NEXT: |
| 65 | + case SWT.TRAVERSE_TAB_PREVIOUS: |
| 66 | + if ((fPrgmArgumentsText.getStyle() & SWT.SINGLE) != 0) { |
| 67 | + e.doit = true; |
| 68 | + } else { |
| 69 | + if (!fPrgmArgumentsText.isEnabled() || (e.stateMask & SWT.MODIFIER_MASK) != 0) { |
| 70 | + e.doit = true; |
| 71 | + } |
| 72 | + } |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | + gd = new GridData(GridData.FILL_BOTH); |
| 78 | + gd.heightHint = 40; |
| 79 | + gd.widthHint = 100; |
| 80 | + fPrgmArgumentsText.setLayoutData(gd); |
| 81 | + fPrgmArgumentsText.setFont(font); |
| 82 | + fPrgmArgumentsText.addModifyListener(new ModifyListener() { |
| 83 | + public void modifyText(ModifyEvent evt) { |
| 84 | + scheduleUpdateJob(); |
| 85 | + } |
| 86 | + }); |
| 87 | + //ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText()); |
| 88 | + |
| 89 | + String buttonLabel = "Variables..."; |
| 90 | + Button pgrmArgVariableButton = createPushButton(group, buttonLabel, null); |
| 91 | + pgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 92 | + pgrmArgVariableButton.addSelectionListener(new SelectionAdapter() { |
| 93 | + public void widgetSelected(SelectionEvent e) { |
| 94 | + StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); |
| 95 | + dialog.open(); |
| 96 | + String variable = dialog.getVariableExpression(); |
| 97 | + if (variable != null) { |
| 98 | + fPrgmArgumentsText.insert(variable); |
| 99 | + } |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + Group groupNode = new Group(comp, SWT.NONE); |
| 104 | + groupNode.setFont(font); |
| 105 | + groupNode.setLayout(new GridLayout()); |
| 106 | + groupNode.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 107 | + |
| 108 | + groupNode.setText("Node Arguments"); |
| 109 | + |
| 110 | + fNodeArgumentsText = new Text(groupNode, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); |
| 111 | + fNodeArgumentsText.addTraverseListener(new TraverseListener() { |
| 112 | + public void keyTraversed(TraverseEvent e) { |
| 113 | + switch (e.detail) { |
| 114 | + case SWT.TRAVERSE_ESCAPE: |
| 115 | + case SWT.TRAVERSE_PAGE_NEXT: |
| 116 | + case SWT.TRAVERSE_PAGE_PREVIOUS: |
| 117 | + e.doit = true; |
| 118 | + break; |
| 119 | + case SWT.TRAVERSE_RETURN: |
| 120 | + case SWT.TRAVERSE_TAB_NEXT: |
| 121 | + case SWT.TRAVERSE_TAB_PREVIOUS: |
| 122 | + if ((fPrgmArgumentsText.getStyle() & SWT.SINGLE) != 0) { |
| 123 | + e.doit = true; |
| 124 | + } else { |
| 125 | + if (!fPrgmArgumentsText.isEnabled() || (e.stateMask & SWT.MODIFIER_MASK) != 0) { |
| 126 | + e.doit = true; |
| 127 | + } |
| 128 | + } |
| 129 | + break; |
| 130 | + } |
| 131 | + } |
| 132 | + }); |
| 133 | + GridData gd2 = new GridData(GridData.FILL_BOTH); |
| 134 | + gd2.heightHint = 40; |
| 135 | + gd2.widthHint = 100; |
| 136 | + fNodeArgumentsText.setLayoutData(gd2); |
| 137 | + fNodeArgumentsText.setFont(font); |
| 138 | + fNodeArgumentsText.addModifyListener(new ModifyListener() { |
| 139 | + public void modifyText(ModifyEvent evt) { |
| 140 | + scheduleUpdateJob(); |
| 141 | + } |
| 142 | + }); |
| 143 | + //ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText()); |
| 144 | + |
| 145 | + String buttonLabel2 = "Variables..."; |
| 146 | + Button pgrmArgVariableButton2 = createPushButton(groupNode, buttonLabel2, null); |
| 147 | + pgrmArgVariableButton2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 148 | + pgrmArgVariableButton2.addSelectionListener(new SelectionAdapter() { |
| 149 | + public void widgetSelected(SelectionEvent e) { |
| 150 | + StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); |
| 151 | + dialog.open(); |
| 152 | + String variable = dialog.getVariableExpression(); |
| 153 | + if (variable != null) { |
| 154 | + fNodeArgumentsText.insert(variable); |
| 155 | + } |
| 156 | + } |
| 157 | + }); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
| 162 | + } |
| 163 | + |
| 164 | + @Override |
| 165 | + public void initializeFrom(ILaunchConfiguration configuration) { |
| 166 | + try { |
| 167 | + fPrgmArgumentsText.setText((String)configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, "")); |
| 168 | + fNodeArgumentsText.setText((String)configuration.getAttribute(Constants.ATTR_NODE_ARGUMENTS, "")); |
| 169 | + } catch (CoreException e) { |
| 170 | + e.printStackTrace(); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 176 | + configuration.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, getAttributeValueFrom(fPrgmArgumentsText)); |
| 177 | + configuration.setAttribute(Constants.ATTR_NODE_ARGUMENTS, getAttributeValueFrom(fNodeArgumentsText)); |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public String getName() { |
| 182 | + return "Arguments"; |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * Returns the string in the text widget, or <code>null</code> if empty. |
| 187 | + * |
| 188 | + * @return text or <code>null</code> |
| 189 | + */ |
| 190 | + protected String getAttributeValueFrom(Text text) { |
| 191 | + String content = text.getText().trim(); |
| 192 | + if (content.length() > 0) { |
| 193 | + return content; |
| 194 | + } |
| 195 | + return null; |
| 196 | + } |
| 197 | +} |
0 commit comments