# HG changeset patch # User kazz # Date 1292822081 -32400 # Node ID bea1625524fe7c5201d15410db799fad23b8ee87 # Parent 58c0e5c876b8d594561318949125d834d8383c3f when you put and join to SessionManager, this plugin open a window for inputting address and port of SessionManager diff -r 58c0e5c876b8 -r bea1625524fe src/remoteeditor/action/RemoteEditorAction.java --- a/src/remoteeditor/action/RemoteEditorAction.java Sun Dec 19 23:01:45 2010 +0900 +++ b/src/remoteeditor/action/RemoteEditorAction.java Mon Dec 20 14:14:41 2010 +0900 @@ -3,7 +3,14 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbench; @@ -21,9 +28,28 @@ public class RemoteEditorAction implements IWorkbenchWindowActionDelegate { private IDocument document; - + private Shell shell; + private Text hostname; + private Text port; + private IAction action; + public RemoteEditorAction(){ - + Display display = Display.getDefault(); + this.shell = new Shell(display); + this.shell.setText("Connection To SessionManager"); + this.shell.setLayout(new FillLayout()); + this.hostname = new Text(shell, SWT.SINGLE|SWT.BORDER); + hostname.setText("localhost"); + this.port = new Text(shell, SWT.SINGLE|SWT.BORDER); + port.setText("8766"); + Button button = new Button(shell, SWT.NULL); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + connect(); + shell.dispose(); + } + }); + button.setText("connect"); } public void dispose() { @@ -34,8 +60,7 @@ } - public void run(IAction action) { - System.out.println(action.getId()); + public void connect() { if(action.getId().equals("EclipseRemoteEditor.action1")){ IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); @@ -47,16 +72,8 @@ // TextEditor 外部から IDocument を取得する方法 ITextEditor editor = (ITextEditor) editorPart; document = editor.getDocumentProvider().getDocument(editorinput); - REPEditor repEditor = new REPEditor(new REPTextImpl2(document, display), true); + REPEditor repEditor = new REPEditor(new REPTextImpl2(document, display), true, hostname.getText(), new Integer(port.getText())); repEditor.start(); - -// workbenchPage.closeEditor(editorPart, true); -// try { -// editorPart = workbenchPage.openEditor(editorinput, "remoteeditor.editors.RemoteEditor"); -// } catch (PartInitException e) { -// e.printStackTrace(); -// } - }else if(action.getId().equals("EclipseRemoteEditor.action2")){ IWorkbench workbench = PlatformUI.getWorkbench(); @@ -74,14 +91,15 @@ document = editor.getDocumentProvider().getDocument(editorinput); REPEditor repEditor = new REPEditor(new REPTextImpl2(document, display), false); repEditor.start(); - -// workbenchPage.closeEditor(editorPart, true); -// try { -// editorPart = workbenchPage.openEditor(editorinput, "remoteeditor.editors.RemoteEditor"); -// } catch (PartInitException e) { -// e.printStackTrace(); -// } } + + } + + public void run(IAction action) { + System.out.println(action.getId()); + this.action = action; + shell.pack(); + shell.open(); /* IWorkbench workbench = PlatformUI.getWorkbench(); //Display display = workbench.getDisplay(); diff -r 58c0e5c876b8 -r bea1625524fe src/remoteeditor/editors/REPEditor.java --- a/src/remoteeditor/editors/REPEditor.java Sun Dec 19 23:01:45 2010 +0900 +++ b/src/remoteeditor/editors/REPEditor.java Mon Dec 20 14:14:41 2010 +0900 @@ -31,6 +31,8 @@ private boolean master; private boolean syncEnable = true; private REPCommand quit = null; + private String hostname = "localhost"; + private int port = 8766; public REPEditor(REPText repText, boolean master){ this.repText = repText; @@ -43,7 +45,13 @@ repText.addTextListener(this); } - + + public REPEditor(REPText repText, boolean master, String hostname, int port) { + this(repText, master); + this.hostname = hostname; + this.port = port; + } + public void textDeleted(REPTextEvent event) { Logger.print(event.getText()); addUserInput(new REPCommand(REP.REPCMD_DELETE_USER, 0, 0, 0, event.getLineno(), event.getText())); @@ -80,7 +88,7 @@ return; } try { - InetSocketAddress semaIP = new InetSocketAddress("localhost", 8766); + InetSocketAddress semaIP = new InetSocketAddress(hostname, port); while (!channel.connect(semaIP)){ Logger.print("SeMa not listen to socket yet, wait"); }