1 11 package org.eclipse.ui.internal.console; 12 13 import org.eclipse.jface.action.IMenuManager; 14 import org.eclipse.jface.action.IToolBarManager; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.ui.actions.ActionFactory; 19 import org.eclipse.ui.console.IConsoleConstants; 20 import org.eclipse.ui.console.IConsoleView; 21 import org.eclipse.ui.console.TextConsole; 22 import org.eclipse.ui.console.TextConsolePage; 23 import org.eclipse.ui.console.TextConsoleViewer; 24 25 31 public class IOConsolePage extends TextConsolePage { 32 33 private ScrollLockAction fScrollLockAction; 34 35 private boolean fReadOnly; 36 37 private IPropertyChangeListener fPropertyChangeListener; 38 39 public IOConsolePage(TextConsole console, IConsoleView view) { 40 super(console, view); 41 42 fPropertyChangeListener = new IPropertyChangeListener() { 43 public void propertyChange(PropertyChangeEvent event) { 44 String property = event.getProperty(); 45 if (property.equals(IConsoleConstants.P_CONSOLE_OUTPUT_COMPLETE)) { 46 setReadOnly(); 47 } 48 } 49 }; 50 console.addPropertyChangeListener(fPropertyChangeListener); 51 } 52 53 58 public void createControl(Composite parent) { 59 super.createControl(parent); 60 if (fReadOnly) { 61 IOConsoleViewer viewer = (IOConsoleViewer) getViewer(); 62 viewer.setReadOnly(); 63 } 64 } 65 66 72 protected TextConsoleViewer createViewer(Composite parent) { 73 return new IOConsoleViewer(parent, (TextConsole)getConsole()); 74 } 75 76 public void setAutoScroll(boolean scroll) { 77 IOConsoleViewer viewer = (IOConsoleViewer) getViewer(); 78 if (viewer != null) { 79 viewer.setAutoScroll(scroll); 80 fScrollLockAction.setChecked(!scroll); 81 } 82 } 83 84 87 public void setReadOnly() { 88 fReadOnly = true; 89 IOConsoleViewer viewer = (IOConsoleViewer) getViewer(); 90 if (viewer != null) { 91 viewer.setReadOnly(); 92 } 93 } 94 95 98 protected void createActions() { 99 super.createActions(); 100 fScrollLockAction = new ScrollLockAction(getConsoleView()); 101 setAutoScroll(!fScrollLockAction.isChecked()); 102 } 103 104 107 protected void contextMenuAboutToShow(IMenuManager menuManager) { 108 super.contextMenuAboutToShow(menuManager); 109 menuManager.add(fScrollLockAction); 110 IOConsoleViewer viewer = (IOConsoleViewer) getViewer(); 111 if (!viewer.isReadOnly()) { 112 menuManager.remove(ActionFactory.CUT.getId()); 113 menuManager.remove(ActionFactory.PASTE.getId()); 114 } 115 } 116 117 122 protected void configureToolBar(IToolBarManager mgr) { 123 super.configureToolBar(mgr); 124 mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fScrollLockAction); 125 } 126 127 132 public void dispose() { 133 if (fScrollLockAction != null) { 134 fScrollLockAction.dispose(); 135 fScrollLockAction = null; 136 } 137 getConsole().removePropertyChangeListener(fPropertyChangeListener); 138 super.dispose(); 139 } 140 141 } 142 | Popular Tags |