package org.openlca.app.devtools.ipc;

import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.openlca.app.M;
import org.openlca.app.db.Database;
import org.openlca.app.util.MsgBox;
import org.openlca.app.util.UI;

public class IpcDialog extends FormDialog {

	private Text portText;

	public static int show() {
		if (Database.get() == null) {
			MsgBox.error(M.NoDatabaseOpened, M.NeedOpenDatabase);
			return Window.CANCEL;
		}
		return new IpcDialog().open();
	}

	public IpcDialog() {
		super(UI.shell());
		setBlockOnOpen(true);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(M.StartIPCServer);
	}

	@Override
	protected void createFormContent(IManagedForm mForm) {
		FormToolkit tk = mForm.getToolkit();
		Composite body = UI.formBody(mForm.getForm(), tk);
		Composite comp = UI.formComposite(body, tk);
		UI.gridData(comp, true, false);
		portText = UI.formText(comp, tk, M.Port);
		portText.setText("8080");
	}

	@Override
	protected void okPressed() {
		String portStr = portText.getText();
		try {
			int port = Integer.parseInt(portStr);
			Database.startIpcOn(port);
			// TODO: need a UI for managing the server
			super.okPressed();
		} catch (Exception e) {
			MsgBox.error("Failed to start IPC server",
					e.getMessage());
		}
	}
}

@@ -72,16 +72,44 @@
 Window;%0A
+import org.eclipse.swt.SWT;%0A
 import o
@@ -792,20 +792,132 @@
 kOnOpen(
-true
+false);%0A%09%09setShellStyle(SWT.CLOSE%0A%09%09%09%09%7C SWT.MODELESS%0A%09%09%09%09%7C SWT.BORDER%0A%09%09%09%09%7C SWT.TITLE%0A%09%09%09%09%7C SWT.RESIZE%0A%09%09%09%09%7C SWT.MIN
 );%0A%09%7D%0A%0A%09
@@ -971,24 +971,24 @@
 newShell) %7B%0A
-
 %09%09super.conf
@@ -1009,16 +1009,17 @@
 Shell);%0A
+%0A
 %09%09newShe

make the IPC dialog modeless