KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > console > IOConsolePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
26  * A page for an IOConsole
27  *
28  * @since 3.1
29  *
30  */

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 JavaDoc property = event.getProperty();
45                 if (property.equals(IConsoleConstants.P_CONSOLE_OUTPUT_COMPLETE)) {
46                     setReadOnly();
47                 }
48             }
49         };
50         console.addPropertyChangeListener(fPropertyChangeListener);
51     }
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
57      */

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     /*
67      * (non-Javadoc)
68      *
69      * @see org.eclipse.ui.console.TextConsolePage#createViewer(org.eclipse.swt.widgets.Composite,
70      * org.eclipse.ui.console.TextConsole)
71      */

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     /**
85      * Informs the viewer that it's text widget should not be editable.
86      */

87     public void setReadOnly() {
88         fReadOnly = true;
89         IOConsoleViewer viewer = (IOConsoleViewer) getViewer();
90         if (viewer != null) {
91             viewer.setReadOnly();
92         }
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.ui.console.TextConsolePage#createActions()
97      */

98     protected void createActions() {
99         super.createActions();
100         fScrollLockAction = new ScrollLockAction(getConsoleView());
101         setAutoScroll(!fScrollLockAction.isChecked());
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.ui.console.TextConsolePage#contextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
106      */

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     /*
118      * (non-Javadoc)
119      *
120      * @see org.eclipse.ui.console.TextConsolePage#configureToolBar(org.eclipse.jface.action.IToolBarManager)
121      */

122     protected void configureToolBar(IToolBarManager mgr) {
123         super.configureToolBar(mgr);
124         mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fScrollLockAction);
125     }
126
127     /*
128      * (non-Javadoc)
129      *
130      * @see org.eclipse.ui.part.IPage#dispose()
131      */

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