use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.
the class MonitorDialog method createDialogArea.
/**
*/
protected Control createDialogArea(Composite parent) {
// create a composite with standard margins and spacing
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 2;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setFont(parent.getFont());
// WorkbenchHelp.setHelp(composite, ContextIds.TERMINATE_SERVER_DIALOG);
Label label = new Label(composite, SWT.WRAP);
label.setText(NLS.bind(Messages.dialogMonitorAddDescription, new String[] { server.getName() }));
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
data.horizontalSpan = 2;
data.widthHint = 275;
label.setLayoutData(data);
table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
data.heightHint = 100;
data.horizontalSpan = 2;
table.setLayoutData(data);
table.setLinesVisible(true);
tableViewer = new TableViewer(table);
TableLayout tableLayout = new TableLayout();
table.setLayout(tableLayout);
table.setHeaderVisible(true);
tableLayout.addColumnData(new ColumnWeightData(12, 120, true));
TableColumn col = new TableColumn(table, SWT.NONE);
col.setText(Messages.dialogMonitorColumnType);
tableLayout.addColumnData(new ColumnWeightData(4, 40, true));
col = new TableColumn(table, SWT.NONE);
col.setText(Messages.dialogMonitorColumnPort);
tableViewer.setContentProvider(new PortContentProvider(server));
tableViewer.setLabelProvider(new PortLabelProvider(server));
tableViewer.setInput(AbstractTreeContentProvider.ROOT);
tableViewer.setSorter(new ViewerSorter() {
public int compare(Viewer viewer, Object e1, Object e2) {
ServerPort port1 = (ServerPort) e1;
ServerPort port2 = (ServerPort) e2;
if (port1.getPort() == port2.getPort())
return 0;
else if (port1.getPort() > port2.getPort())
return 1;
else
return -1;
}
});
label = new Label(composite, SWT.NONE);
label.setText(Messages.dialogMonitorMonitorPort);
final Text portText = new Text(composite, SWT.BORDER);
data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 150;
portText.setLayoutData(data);
if (monitorPort >= 0)
portText.setText(monitorPort + "");
portText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
try {
monitorPort = Integer.parseInt(portText.getText());
if (ok != null)
ok.setEnabled(true);
} catch (Exception ex) {
monitorPort = -1;
if (ok != null)
ok.setEnabled(false);
}
portChanged = true;
}
});
label = new Label(composite, SWT.NONE);
label.setText(Messages.dialogMonitorContentType);
final Combo combo = new Combo(composite, SWT.READ_ONLY);
data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 150;
combo.setLayoutData(data);
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int size = combo.getItemCount();
int sel = combo.getSelectionIndex();
if (sel == size - 1)
contentTypes = portContentTypes;
else
contentTypes = new String[] { portContentTypes[sel] };
}
});
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
port = (ServerPort) getSelection(tableViewer.getSelection());
if (port == null)
return;
if (!portChanged) {
portText.setText((port.getPort() + 1) + "");
portChanged = false;
}
portContentTypes = port.getContentTypes();
String[] s = null;
String all = Messages.dialogMonitorContentTypeAll;
if (portContentTypes == null || portContentTypes.length == 1) {
s = new String[] { all };
} else {
int size = portContentTypes.length;
s = new String[size + 1];
for (int i = 0; i < size; i++) {
s[i] = MonitorLabelProvider.getContentTypeString(portContentTypes[i]);
}
s[size] = all;
}
combo.setItems(s);
combo.setText(all);
}
});
Dialog.applyDialogFont(composite);
if (port != null) {
portChanged = true;
String[] ct = contentTypes;
tableViewer.setSelection(new StructuredSelection(port));
if (ct != null && ct.length > 0)
combo.setText(MonitorLabelProvider.getContentTypeString(ct[0]));
} else if (tableViewer != null) {
try {
Object obj = tableViewer.getElementAt(0);
if (obj != null)
tableViewer.setSelection(new StructuredSelection(obj));
} catch (Exception e) {
// ignore
}
}
portChanged = false;
return composite;
}
use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.
the class AbstractTomcatServerTestCase method createServer.
public IServer createServer() throws Exception {
IServerType st = ServerCore.findServerType(getServerTypeId());
IRuntime runtime = createRuntime();
IServerWorkingCopy wc = st.createServer(null, null, runtime, null);
ServerPort[] ports = wc.getServerPorts(null);
TomcatServer tomcatServer = (TomcatServer) wc.getAdapter(TomcatServer.class);
ITomcatConfigurationWorkingCopy configuration = (ITomcatConfigurationWorkingCopy) tomcatServer.getServerConfiguration();
// if no ports from the server, use the configuration
if (ports == null || ports.length == 0) {
List portsList = configuration.getServerPorts();
if (portsList != null && portsList.size() > 0) {
ports = (ServerPort[]) portsList.toArray(new ServerPort[portsList.size()]);
}
}
if (ports != null) {
int size = ports.length;
for (int i = 0; i < size; i++) {
configuration.modifyServerPort(ports[i].getId(), 22100 + i);
}
}
return wc.save(true, null);
}
use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.
the class GenericServerBehaviour method setupLaunch.
/**
* Setup for starting the server. Checks all ports available
* and sets server state and mode.
*
* @param launch ILaunch
* @param launchMode String
* @param monitor IProgressMonitor
*/
protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
if (// $NON-NLS-1$ //$NON-NLS-2$
"true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false")))
return;
String host = getServer().getHost();
ServerPort[] ports = getServer().getServerPorts(null);
ServerPort sp = null;
if (SocketUtil.isLocalhost(host)) {
for (int i = 0; i < ports.length; i++) {
sp = ports[i];
if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, NLS.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(sp.getPort()), sp.getName()), null));
}
}
setServerState(IServer.STATE_STARTING);
setMode(launchMode);
}
use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.
the class ExternalServerBehaviour method setupLaunch.
/**
* Override to set status to unknown if the port was in use and to reset the status if the state was
* unknown and an exception was not thrown. Will want to change logic once external generic server pings
* server process to determine state instead of maintaining handle to process.
*/
protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
int state = getServer().getServerState();
try {
super.setupLaunch(launch, launchMode, monitor);
} catch (CoreException ce) {
ServerPort portInUse = portInUse();
if (portInUse != null) {
// $NON-NLS-1$//$NON-NLS-2$
Trace.trace(Trace.WARNING, "Port " + portInUse.getPort() + " is currently in use");
Status status = new Status(IStatus.WARNING, CorePlugin.PLUGIN_ID, IStatus.OK, NLS.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(portInUse.getPort()), portInUse.getName()), null);
setServerStatus(status);
setServerState(IServer.STATE_UNKNOWN);
}
throw ce;
}
resetStatus(state);
}
use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.
the class ExternalServerBehaviour method portInUse.
private ServerPort portInUse() {
ServerPort[] ports = getServer().getServerPorts(null);
ServerPort sp;
for (int i = 0; i < ports.length; i++) {
sp = ports[i];
if (SocketUtil.isPortInUse(sp.getPort(), 5)) {
return sp;
}
}
return null;
}
Aggregations