-
Notifications
You must be signed in to change notification settings - Fork 58
/
DebugPortSection.java
121 lines (109 loc) · 4.44 KB
/
DebugPortSection.java
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) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
*
******************************************************************************/
package org.jboss.ide.eclipse.as.rse.ui.editor;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
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.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.jboss.ide.eclipse.as.core.util.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.rse.core.RSEJbossLaunchConstants;
import org.jboss.ide.eclipse.as.ui.editor.PortSection;import org.jboss.ide.eclipse.as.ui.editor.ModuleRestartSection.SetOverrideHotcodeReplaceCommand;
import org.jboss.ide.eclipse.as.ui.editor.PortSection.IPortEditorExtension;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ServerProfileModel;
import org.jboss.ide.eclipse.as.wtp.ui.editor.ServerWorkingCopyPropertyButtonCommand;
import org.jboss.ide.eclipse.as.wtp.ui.editor.ServerWorkingCopyPropertyTextCommand;
public class DebugPortSection implements IPortEditorExtension {
private ServerAttributeHelper helper;
private PortSection section;
public DebugPortSection() {
// TODO Auto-generated constructor stub
}
@Override
public void setServerAttributeHelper(ServerAttributeHelper helper) {
this.helper = helper;
}
@Override
public void setSection(PortSection section) {
this.section = section;
}
@Override
public void createControl(Composite parent) {
String profile = ServerProfileModel.getProfile(helper.getOriginal());
if( profile.contains("rse")) {
final Button check = new Button(parent,SWT.CHECK);
check.setText("Launch remote debugger");
GridData gd = new GridData();
gd.horizontalSpan = 4;
check.setLayoutData(gd);
Label l2 = new Label(parent, SWT.NONE);
l2.setText("Debug Port");
final Text portText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).minSize(80, 10).grab(true, false).applyTo(portText);
portText.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
if( e.text == null || e.text.equals(""))
return;
try {
Integer i = Integer.parseInt(e.text);
if( i.intValue() == 0 ) {
// do not allow port 0
e.doit = false;
}
} catch( NumberFormatException nfe ) {
e.doit = false;
}
}
});
Boolean b = helper.getWorkingCopy().getAttribute(RSEJbossLaunchConstants.ATTACH_DEBUGGER, true);
check.setSelection(b.booleanValue());
check.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
ServerWorkingCopyPropertyButtonCommand command = new ServerWorkingCopyPropertyButtonCommand(
helper.getWorkingCopy(), "Enable debugging", check, check.getSelection(),
RSEJbossLaunchConstants.ATTACH_DEBUGGER, this);
section.execute(command);
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
String dbugPort = helper.getWorkingCopy().getAttribute(RSEJbossLaunchConstants.DEBUG_PORT, new Integer(RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT).toString());
portText.setText(dbugPort);
portText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
ServerWorkingCopyPropertyTextCommand command = new ServerWorkingCopyPropertyTextCommand(
helper.getWorkingCopy(), "Change Debug Port", portText, portText.getText(),
RSEJbossLaunchConstants.DEBUG_PORT, new Integer(RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT).toString(), this);
section.execute(command);
}
});
}
}
@Override
public String getValue() {
// irrelevant / unused
return null;
}
@Override
public void refresh() {
// unaffected by port offset
}
}