/** * retrieve or create a ConsoleIO with the given UId * the name is used only if the console is created * @param name * @return */ public EclipseConsoleIO getConsoleIO(String uid, String name){ EclipseConsoleIO consoleIo=consoleIOMap.get(uid); if(consoleIo == null){ // create the eclipse console IOConsole ioConsole = new IOConsole(name, null); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ ioConsole }); // ConsolePlugin.getDefault().getConsoleManager().showConsoleView(ioConsole); // ioConsole.activate(); // console will be displayed on first use // create the IO with this console consoleIo = new EclipseConsoleIO(ioConsole); consoleIOMap.put(uid, consoleIo); } return consoleIo; }
public IOConsole getConsole() { if (console == null) { // create console IOConsole newConsole = new IOConsole("leJOS EV3", null, getImageDescriptor("icons/ev3.jpg"), LeJOSEV3Plugin.CONSOLE_CHARSET, false); // add to console manager ConsolePlugin cplugin = ConsolePlugin.getDefault(); IConsoleManager conMan = cplugin.getConsoleManager(); try { consoleWriter = new PrintWriter(new OutputStreamWriter(newConsole.newOutputStream(), CONSOLE_CHARSET), true); consoleReader = new BufferedReader(new InputStreamReader(newConsole.getInputStream(), CONSOLE_CHARSET)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } conMan.addConsoles(new IConsole[] { newConsole }); this.console = newConsole; } return console; }
private void addRef(IOConsole console) { synchronized (referencesLock) { //We'll clear the current references and add the new one if it's not there already. int size = weakrefs.size(); for (int i = 0; i < size; i++) { WeakReference<IOConsole> ref = weakrefs.get(i); Object object = ref.get(); if (object == console) { return; //already there (nothing to add). } if (object == null) { weakrefs.remove(i); i--; size--; } } //Add the new reference. weakrefs.add(new WeakReference<IOConsole>(console)); } }
private ArrayList<IOConsole> getCurrentRefs() { int size = weakrefs.size(); ArrayList<IOConsole> currentRefs = new ArrayList<IOConsole>(size); for (int i = 0; i < size; i++) { WeakReference<IOConsole> ref = weakrefs.get(i); IOConsole object = ref.get(); if (object == null) { weakrefs.remove(i); i--; size--; } else { currentRefs.add(object); } } return currentRefs; }
@SuppressWarnings("restriction") private void processIOConsole(IOConsole ioConsole) { IDocument document = ioConsole.getDocument(); try { Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); Arrays.sort(positions, new Comparator<Position>() { @Override public int compare(Position o1, Position o2) { return Integer.compare(o1.getOffset(), o2.getOffset()); } }); if (positions.length > 0) { Position p = positions[positions.length - 1]; if (p instanceof ConsoleHyperlinkPosition) { ConsoleHyperlinkPosition consoleHyperlinkPosition = (ConsoleHyperlinkPosition) p; IHyperlink hyperLink = consoleHyperlinkPosition.getHyperLink(); hyperLink.linkActivated(); } } } catch (BadPositionCategoryException e) { Log.log(e); } }
public void openConsole() { IOConsole console = getConsole(); IConsole[] existing = consoleManager.getConsoles(); boolean exists = false; for (int i = 0; i < existing.length; i++) { if (console == existing[i]) { exists = true; } } if (!exists) { consoleManager.addConsoles(new IConsole[] { console }); } // console.clearConsole(); consoleManager.showConsoleView(console); }
private CloudSdkDebugTarget(ILaunch launch, LocalAppEngineServerBehaviour serverBehaviour, IOConsole console) { super(null); this.launch = launch; this.serverBehaviour = serverBehaviour; server = serverBehaviour.getServer(); this.console = console; }
/** * Build the Eclipse console handler * * @param currentConsole * the current eclipse process console * */ public EclipseConsoleHandler(IConsole console) { super(); if (console instanceof IOConsole) { this.console = (IOConsole) console; this.console.activate(); } else { throw new TurnusRuntimeException("Invalid console passed as parameter"); } }
protected void showConsole() { IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); IConsole[] consoles = consoleManager.getConsoles(); for (IConsole iConsole : consoles) { if (TYPE.equals(iConsole.getType())) { if (iConsole instanceof IOConsole) { ((IOConsole) iConsole).activate(); consoleManager.showConsoleView(iConsole); } } } }
/** * Creates and configures a Creel engine using plugin preferences and * folders. * * @param project * The project * @param folders * Map of artifact types to folders * @return A Creel engine * @throws CoreException * In case of an Eclipse error */ public static Engine createEngine( IProject project, Map<Artifact.Type, IContainer> folders ) throws CoreException { IPreferenceStore preferences = Plugin.instance.getPreferenceStore(); Engine engine = new Engine(); IOConsole console = EclipseUtil.getConsole( "Creel" ); IOConsoleOutputStream stream = console.newOutputStream(); if( !preferences.getBoolean( PreferencesPage.QUIET ) ) ( (EventHandlers) engine.getEventHandler() ).add( new ConsoleEventHandler( stream, false, false ) ); engine.setVerbosity( preferences.getInt( PreferencesPage.VERBOSITY ) ); engine.getDirectories().set( toDirectories( folders ) ); return engine; }
public void consume(InputStream outputStream) { IOConsole messageConsole = getMessageConsole(consoleName); messageConsole.activate(); MessageConsoleWriter messageConsoleWriter = new MessageConsoleWriter(messageConsole, outputStream, isStdErr); new Thread(messageConsoleWriter).start(); }
public static IOConsole findConsole() { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); for (int i = 0; i < existing.length; i++) { if (KARAF_CONSOLE.equals(existing[i].getName())) return (IOConsole) existing[i]; } // no console found, so create a new one IOConsole myConsole = new IOConsole(KARAF_CONSOLE, null); conMan.addConsoles(new IConsole[] { myConsole }); return myConsole; }
public static void clearConsole() { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); for (int i = 0; i < existing.length; i++) { if (KARAF_CONSOLE.equals(existing[i].getName())) { ((IOConsole) existing[i]).destroy(); conMan.removeConsoles(new IConsole[] { existing[i] }); } } }
@Override protected void append(LoggingEvent logEvent) { final String message = logEvent.getRenderedMessage(); final Level level = logEvent.getLevel(); final String streamId = getStreamId(level); final Display display = Display.getDefault(); final Thread thread = display.getThread(); Thread _currentThread = Thread.currentThread(); final boolean uiThread = Objects.equal(thread, _currentThread); final Runnable _function = new Runnable() { @Override public void run() { try { final IOConsole console = AntlrConsoleFactory.getConsole(); final IOConsoleOutputStream stream = console .newOutputStream(); final ConsoleColorProvider colorProvider = new ConsoleColorProvider(); final Color color = colorProvider.getColor(streamId); stream.setColor(color); stream.setActivateOnWrite(true); stream.write((message + "\n")); stream.close(); } catch (Throwable ex) { ex.printStackTrace(); } } }; final Runnable printTask = _function; if (uiThread) { printTask.run(); } else { display.syncExec(printTask); } }
@Override public void preferenceChange(PreferenceChangeEvent event) { String key = event.getKey(); if ("org.eclipse.debug.ui.consoleBackground".equals(key) || "org.eclipse.debug.ui.outColor".equals(key) || "org.eclipse.debug.ui.errorColor".equals(key)) { synchronized (referencesLock) { ArrayList<IOConsole> currentRefs = getCurrentRefs(); for (IOConsole console : currentRefs) { updateConsole(console); } } } }
@Override public void run(IAction action) { for (IConsoleView c : ScriptConsole.iterConsoles()) { IConsole console = c.getConsole(); if (console instanceof IOConsole) { IOConsole ioConsole = (IOConsole) console; processIOConsole(ioConsole); break; } } }
protected void addProcessConsole(IOConsole c) { // What we'd like to do is not put in the input stream the contents we received // in the console UNLESS we're waiting for input (but unfortunately, it seems there's // no API for that). // // This means that if the user writes something (to do an evaluation) and later // does a raw_input('say something:\n'), the raw_input will get the contents that // the user wrote for the evaluation and not the contents it'd write now. // As we now have a separate input console, this shouldn't be so troublesome, as // we control things better when the user writes to the PromptOverlay console, but // if he writes to the other console, things may misbehave. }
private IOConsole findOrCreateConsole(String name) { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); for (int i = 0; i < existing.length; i++) if (name.equals(existing[i].getName())) return (IOConsole) existing[i]; IOConsole console = new IOConsole(name, null); conMan.addConsoles(new IConsole[] { console }); return console; }
public IOConsole getConsole() { if (console == null) createConsole(); return console; }
public InputStream getInputStream() { IOConsole messageConsole = getMessageConsole(consoleName); messageConsole.activate(); return messageConsole.getInputStream(); }
private MessageConsoleWriter(IOConsole messageConsole, InputStream from, boolean isStdErr) { this.messageConsole = messageConsole; this.from = from; this.isStdErr = isStdErr; }
@Override public void openConsole() { IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); final IOConsole console = getConsole(); manager.showConsoleView(console); }
private static void initializeSystemContext(ClassLoader cl, File ev3Home) throws LeJOSEV3Exception { LeJOSEV3Plugin p = LeJOSEV3Plugin.getDefault(); IOConsole con = p.getConsole(); Writer consw = p.getConsoleWriter(); InputStream cins = con.getInputStream(); InputStreamReader cinsr; try { cinsr = new InputStreamReader(cins, LeJOSEV3Plugin.CONSOLE_CHARSET); } catch (UnsupportedEncodingException e1) { throw new RuntimeException(e1); } try { Class<?> c = cl.loadClass("lejos.pc.comm.SystemContext"); Method m; m = c.getDeclaredMethod("setEV3Home", String.class); m.invoke(null, ev3Home.getAbsolutePath()); m = c.getDeclaredMethod("setOut", Writer.class); m.invoke(null, consw); m = c.getDeclaredMethod("setErr", Writer.class); m.invoke(null, consw); m = c.getDeclaredMethod("setIn", Reader.class); m.invoke(null, cinsr); } catch (Exception e) { Throwable t = e; if (t instanceof InvocationTargetException) t = ((InvocationTargetException)t).getTargetException(); throw new LeJOSEV3Exception("unanble to initialize system context", t); } }
@Override public void run() { IOConsole console = findOrCreateConsole(M.FormulaInterpreter); ConsoleJob job = new ConsoleJob(console); job.schedule(); }
public ConsoleJob(IOConsole console) { super(M.FormulaInterpreter); this.console = console; }
/** * In this method we'll make sure a console will have its colors properly updated. * * @param console This is the console to keep updated. * * The console should have a getAttribute("themeConsoleStreamToColor") which returns a Map<IOConsoleOutputStream, String> * where the values may be: * * "console.output" or "console.error" */ public void keepConsoleColorsSynched(IOConsole console) { updateConsole(console); addRef(console); }