@Override public void selectionChanged(final IAction action, final ISelection selection) { fLaunch = null; if (selection instanceof IStructuredSelection) { final IStructuredSelection ss = (IStructuredSelection) selection; for (final Object o : ss.toArray()) { if (o instanceof ErlangDebugElement) { final ErlangDebugElement d = (ErlangDebugElement) o; fLaunch = d.getLaunch(); } else if (o instanceof ILaunch) { fLaunch = (ILaunch) o; } else if (o instanceof IProcess) { final IProcess p = (IProcess) o; fLaunch = p.getLaunch(); } } } }
/** * Computes and returns the current name of this console. * * @return a name for this console */ protected String computeName() { String label = null; final IProcess process = getProcess(); final ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration(); label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL); if (label == null) { if (config == null) { label = process.getLabel(); } else { // check if PRIVATE config if (DebugUITools.isPrivate(config)) { label = process.getLabel(); } else { String type = null; try { type = config.getType().getName(); } catch (final CoreException e) { } final StringBuffer buffer = new StringBuffer(); buffer.append("Remote shell connection to: "); buffer.append(config.getName()); if (type != null) { buffer.append(" ["); // $NON-NLS-1$ buffer.append(type); buffer.append("] "); // $NON-NLS-1$ } buffer.append(process.getLabel()); label = buffer.toString(); } } } if (process.isTerminated()) { return MessageFormat.format("<disconnected> {0}", (Object[]) new String[] {label}); } return label; }
/* * (non-Javadoc) * * @see org.eclipse.ui.part.IShowInSource#getShowInContext() */ public ShowInContext getShowInContext() { IProcess process = getProcess(); if (process == null) { return null; } IDebugTarget target = (IDebugTarget) process.getAdapter(IDebugTarget.class); ISelection selection = null; if (target == null) { selection = new TreeSelection( new TreePath( new Object[] { DebugPlugin.getDefault().getLaunchManager(), process.getLaunch(), process })); } else { selection = new TreeSelection( new TreePath( new Object[] { DebugPlugin.getDefault().getLaunchManager(), target.getLaunch(), target })); } return new ShowInContext(null, selection); }
public KarafRemoteConsole( final IProcess process, final KarafSshConnectionUrl connectionUrl, final KarafSshShellConnection.Credentials credentials, final IConsoleColorProvider colorProvider, final String name, final String encoding) { super( name, KARAF_REMOTE_CONSOLE_TYPE, KarafUIPluginActivator.getDefault() .getImageRegistry() .getDescriptor(KarafUIPluginActivator.LOGO_16X16_IMG), encoding, true); this.process = process; this.inputStream = getInputStream(); this.colorProvider = colorProvider; final Color color = this.colorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM); this.inputStream.setColor(color); final InputStream noAvailableInputStream = new FilterInputStream(inputStream) { @Override public int available() throws IOException { return 0; } }; setName(computeName()); final IOConsoleOutputStream outputStream = newOutputStream(); boolean remoteShellEnabled = false; try { final ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration(); remoteShellEnabled = configuration.getAttribute( KarafLaunchConfigurationConstants.KARAF_LAUNCH_START_REMOTE_CONSOLE, false); } catch (final CoreException e) { return; } if (remoteShellEnabled) { shellConnection = new KarafSshShellConnection( connectionUrl, credentials, noAvailableInputStream, outputStream, outputStream); final KarafRemoteShellConnectJob job = new KarafRemoteShellConnectJob(name, shellConnection); job.addJobChangeListener( new JobChangeAdapter() { @Override public void done(final IJobChangeEvent event) { if (!event.getResult().isOK()) { final Throwable t = event.getResult().getException(); writeTo( outputStream, "Unable to connect to SSH server: " + (t != null ? t.getLocalizedMessage() : "Unknown error")); } } }); DebugPlugin.getDefault() .addDebugEventListener( new IDebugEventSetListener() { @Override public void handleDebugEvents(final DebugEvent[] events) { for (final DebugEvent event : events) { if (process != null && process.equals(event.getSource()) && event.getKind() == DebugEvent.TERMINATE) { job.cancel(); } } } }); job.schedule(15 * 1000); } else { writeTo( outputStream, "The Karaf remote shell is disabled. Enable it in the launch configuration dialog."); } }
/** When a console page is initialized, */ public void init(IPageBookViewPage page, final IConsole console) { if (!(console instanceof ProcessConsole)) { return; } ProcessConsole processConsole = (ProcessConsole) console; IProcess process = processConsole.getProcess(); if (process == null) { return; } if (!PyCodeCompletionPreferencesPage.useCodeCompletion() || !PyCodeCompletionPreferencesPage.useCodeCompletionOnDebug()) { return; } String attribute = process.getAttribute(Constants.PYDEV_DEBUG_IPROCESS_ATTR); if (!Constants.PYDEV_DEBUG_IPROCESS_ATTR_TRUE.equals(attribute)) { // Only provide code-completion for pydev debug processes. return; } Control control = page.getControl(); if (page instanceof IOConsolePage) { // Note that completions on "all letters and '_'" are already activated just by installing // the content assist, but the completions on the default keybinding is not, so, we have to // call it ourselves here. control.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent e) { if (KeyBindingHelper.matchesContentAssistKeybinding(e)) { contentAssist.showPossibleCompletions(); } } public void keyReleased(KeyEvent e) {} }); IOConsolePage consolePage = (IOConsolePage) page; TextConsoleViewer viewer = consolePage.getViewer(); contentAssist = new PyContentAssistant() { public String showPossibleCompletions() { // Only show completions if we're in a suspended console. if (getCurrentSuspendedPyStackFrame(console) == null) { return null; } return super.showPossibleCompletions(); }; }; contentAssist.setInformationControlCreator( PyContentAssistant.createInformationControlCreator(viewer)); ILaunch launch = process.getLaunch(); IDebugTarget debugTarget = launch.getDebugTarget(); IInterpreterInfo projectInterpreter = null; if (debugTarget instanceof PyDebugTarget) { PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget; PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project); if (nature != null) { try { projectInterpreter = nature.getProjectInterpreter(); } catch (Throwable e1) { Log.log(e1); } } } contentAssist.install(new ScriptConsoleViewerWrapper(viewer, projectInterpreter)); PydevConsoleInterpreter interpreter = new PydevConsoleInterpreter(); interpreter.setConsoleCommunication(new GetCompletionsInDebug()); IContentAssistProcessor processor = new PydevConsoleCompletionProcessor(interpreter, contentAssist); contentAssist.setContentAssistProcessor(processor, IOConsolePartition.INPUT_PARTITION_TYPE); contentAssist.setContentAssistProcessor(processor, IOConsolePartition.OUTPUT_PARTITION_TYPE); contentAssist.enableAutoActivation(true); contentAssist.enableAutoInsert(false); contentAssist.setAutoActivationDelay(PyCodeCompletionPreferencesPage.getAutocompleteDelay()); } }