/** * ************************************************************************* Create the dialog * area contents. * * @param parent The base composite of the dialog * @return The resulting contents * ************************************************************************ */ protected Control createDialogArea(Composite parent) { // Main composite of the dialog area ----------------------------------- Composite top = new Composite(parent, SWT.NONE); top.setLayoutData(new GridData(GridData.FILL_BOTH)); top.setLayout(new GridLayout(1, true)); IConfigurationManager cfg = (IConfigurationManager) ServiceManager.get(IConfigurationManager.class); Font codeFont = cfg.getFont(FontKey.MASTERC); Color bcolor = cfg.getGuiColor(GuiColorKey.CONSOLE_BG); Color wcolor = cfg.getGuiColor(GuiColorKey.CONSOLE_FG); // Create the console display m_display = new Text(top, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); m_display.setFont(codeFont); m_display.setBackground(bcolor); m_display.setForeground(wcolor); GridData ddata = new GridData(GridData.FILL_BOTH); ddata.minimumHeight = 200; m_display.setLayoutData(ddata); m_display.setText(""); m_display.setEditable(false); // Create the input field m_prompt = new PromptField(top, ""); m_prompt.getContents().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); m_prompt.getContents().addKeyListener(this); m_prompt.getContents().setFocus(); return parent; }
/** * ************************************************************************* Callback for key * release event. Used for command processing. * * @param e Key release event * ************************************************************************ */ public void keyReleased(KeyEvent e) { // Check if the key code corresponds to one of the two enter keys. if (e.keyCode == 13 || e.keyCode == 16777296) { // Obtain the contents of the input field String cmdString = m_prompt.getValue(); try { // Add the text to the display, reset the prompt, and // send the command string to the shell manager if (!s_smgr.haveShell()) { addDisplayMessage("No shell plugin available."); return; } addDisplayMessage(m_prompt.getPrompt() + PromptField.PROMPT_SYMBOL + cmdString); s_smgr.shellInput(cmdString); } catch (CommandFailed ex) { // If the console manager raises an error show it on the // display addDisplayMessage("ERROR (" + m_prompt.getPrompt() + "): " + ex.getLocalizedMessage()); } m_prompt.reset(); } }