2
|
1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
2 |
// Use of this source code is governed by a BSD-style license that can be
|
|
3 |
// found in the LICENSE file.
|
|
4 |
|
|
5 |
package org.chromium.debug.ui.launcher;
|
|
6 |
|
|
7 |
import org.chromium.debug.core.ChromiumDebugPlugin;
|
|
8 |
import org.eclipse.core.runtime.CoreException;
|
|
9 |
import org.eclipse.debug.core.ILaunchConfiguration;
|
|
10 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
|
11 |
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
|
|
12 |
import org.eclipse.debug.ui.DebugUITools;
|
|
13 |
import org.eclipse.debug.ui.IDebugUIConstants;
|
|
14 |
import org.eclipse.jface.preference.BooleanFieldEditor;
|
|
15 |
import org.eclipse.jface.preference.FieldEditor;
|
|
16 |
import org.eclipse.jface.preference.IntegerFieldEditor;
|
|
17 |
import org.eclipse.jface.preference.PreferenceStore;
|
|
18 |
import org.eclipse.jface.util.IPropertyChangeListener;
|
|
19 |
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
20 |
import org.eclipse.swt.SWT;
|
|
21 |
import org.eclipse.swt.graphics.Image;
|
|
22 |
import org.eclipse.swt.layout.GridData;
|
|
23 |
import org.eclipse.swt.layout.GridLayout;
|
|
24 |
import org.eclipse.swt.widgets.Composite;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* The "Remote" tab for the Chromium JavaScript launch tab group.
|
|
28 |
*/
|
|
29 |
public class ChromiumRemoteTab extends AbstractLaunchConfigurationTab {
|
|
30 |
|
|
31 |
private static final String PORT_FIELD_NAME = "port_field"; //$NON-NLS-1$
|
|
32 |
private static final String ADD_NETWORK_CONSOLE_FIELD_NAME =
|
|
33 |
"add_network_console_field"; //$NON-NLS-1$
|
|
34 |
|
|
35 |
// However, recommended range is [1024, 32767].
|
|
36 |
private static final int minimumPortValue = 0;
|
|
37 |
private static final int maximumPortValue = 65535;
|
|
38 |
|
|
39 |
private IntegerFieldEditor debugPort;
|
|
40 |
private BooleanFieldEditor addNetworkConsole;
|
|
41 |
private final PreferenceStore store = new PreferenceStore();
|
|
42 |
|
|
43 |
public void createControl(Composite parent) {
|
|
44 |
Composite composite = createDefaultComposite(parent);
|
|
45 |
|
|
46 |
IPropertyChangeListener modifyListener = new IPropertyChangeListener() {
|
|
47 |
public void propertyChange(PropertyChangeEvent event) {
|
|
48 |
updateLaunchConfigurationDialog();
|
|
49 |
}
|
|
50 |
};
|
|
51 |
|
|
52 |
Composite propertiesComp = createInnerComposite(composite, 2);
|
|
53 |
// Port text field
|
|
54 |
debugPort = new IntegerFieldEditor(PORT_FIELD_NAME, Messages.ChromiumRemoteTab_PortLabel,
|
|
55 |
propertiesComp);
|
|
56 |
debugPort.setPropertyChangeListener(modifyListener);
|
|
57 |
debugPort.setPreferenceStore(store);
|
|
58 |
|
|
59 |
addNetworkConsole = new BooleanFieldEditor(ADD_NETWORK_CONSOLE_FIELD_NAME,
|
|
60 |
Messages.ChromiumRemoteTab_ShowDebuggerNetworkCommunication,
|
|
61 |
propertiesComp);
|
|
62 |
addNetworkConsole.setPreferenceStore(store);
|
|
63 |
addNetworkConsole.setPropertyChangeListener(modifyListener);
|
|
64 |
}
|
|
65 |
|
|
66 |
public String getName() {
|
|
67 |
return Messages.ChromiumRemoteTab_RemoteTabName;
|
|
68 |
}
|
|
69 |
|
|
70 |
public void initializeFrom(ILaunchConfiguration config) {
|
|
71 |
int debugPortDefault = PluginVariablesUtil.getValueAsInt(PluginVariablesUtil.DEFAULT_PORT);
|
|
72 |
|
|
73 |
try {
|
|
74 |
store.setDefault(PORT_FIELD_NAME, config.getAttribute(LaunchTypeBase.CHROMIUM_DEBUG_PORT,
|
|
75 |
debugPortDefault));
|
|
76 |
store.setDefault(ADD_NETWORK_CONSOLE_FIELD_NAME, config.getAttribute(
|
|
77 |
LaunchTypeBase.ADD_NETWORK_CONSOLE, false));
|
|
78 |
} catch (CoreException e) {
|
|
79 |
ChromiumDebugPlugin.log(new Exception("Unexpected storage problem", e)); //$NON-NLS-1$
|
|
80 |
store.setDefault(PORT_FIELD_NAME, debugPortDefault);
|
|
81 |
store.setDefault(ADD_NETWORK_CONSOLE_FIELD_NAME, false);
|
|
82 |
}
|
|
83 |
|
|
84 |
debugPort.loadDefault();
|
|
85 |
addNetworkConsole.loadDefault();
|
|
86 |
}
|
|
87 |
|
|
88 |
public void performApply(ILaunchConfigurationWorkingCopy config) {
|
|
89 |
storeEditor(debugPort, "-1"); //$NON-NLS-1$
|
|
90 |
storeEditor(addNetworkConsole, ""); //$NON-NLS-1$
|
|
91 |
|
|
92 |
config.setAttribute(LaunchTypeBase.CHROMIUM_DEBUG_PORT, store.getInt(PORT_FIELD_NAME));
|
|
93 |
config.setAttribute(LaunchTypeBase.ADD_NETWORK_CONSOLE,
|
|
94 |
store.getBoolean(ADD_NETWORK_CONSOLE_FIELD_NAME));
|
|
95 |
}
|
|
96 |
|
|
97 |
@Override
|
|
98 |
public boolean isValid(ILaunchConfiguration config) {
|
|
99 |
try {
|
|
100 |
int port = config.getAttribute(LaunchTypeBase.CHROMIUM_DEBUG_PORT, -1);
|
|
101 |
if (port < minimumPortValue || port > maximumPortValue) {
|
|
102 |
setErrorMessage(Messages.ChromiumRemoteTab_InvalidPortNumberError);
|
|
103 |
return false;
|
|
104 |
}
|
|
105 |
} catch (CoreException e) {
|
|
106 |
ChromiumDebugPlugin.log(new Exception("Unexpected storage problem", e)); //$NON-NLS-1$
|
|
107 |
}
|
|
108 |
|
|
109 |
setErrorMessage(null);
|
|
110 |
return true;
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
|
|
115 |
int port = PluginVariablesUtil.getValueAsInt(PluginVariablesUtil.DEFAULT_PORT);
|
|
116 |
config.setAttribute(LaunchTypeBase.CHROMIUM_DEBUG_PORT, port);
|
|
117 |
}
|
|
118 |
|
|
119 |
@Override
|
|
120 |
public Image getImage() {
|
|
121 |
return DebugUITools.getImage(IDebugUIConstants.IMG_LCL_DISCONNECT);
|
|
122 |
}
|
|
123 |
|
|
124 |
private Composite createDefaultComposite(Composite parent) {
|
|
125 |
Composite composite = new Composite(parent, SWT.NULL);
|
|
126 |
setControl(composite);
|
|
127 |
|
|
128 |
GridLayout layout = new GridLayout();
|
|
129 |
layout.numColumns = 1;
|
|
130 |
composite.setLayout(layout);
|
|
131 |
|
|
132 |
GridData data = new GridData();
|
|
133 |
data.verticalAlignment = GridData.FILL;
|
|
134 |
data.horizontalAlignment = GridData.FILL;
|
|
135 |
composite.setLayoutData(data);
|
|
136 |
|
|
137 |
return composite;
|
|
138 |
}
|
|
139 |
|
|
140 |
private Composite createInnerComposite(Composite parent, int numColumns) {
|
|
141 |
Composite composite = new Composite(parent, SWT.NONE);
|
|
142 |
composite.setLayout(new GridLayout(numColumns, false));
|
|
143 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
144 |
composite.setLayoutData(gd);
|
|
145 |
return composite;
|
|
146 |
}
|
|
147 |
|
|
148 |
private static void storeEditor(FieldEditor editor, String errorValue) {
|
|
149 |
if (editor.isValid()) {
|
|
150 |
editor.store();
|
|
151 |
} else {
|
|
152 |
editor.getPreferenceStore().setValue(editor.getPreferenceName(), errorValue);
|
|
153 |
}
|
|
154 |
}
|
|
155 |
}
|