Fixed SCL Console Clear Console active-state when imports are erroneous
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / console / SCLScriptConsoleView.java
1 package org.simantics.scl.ui.console;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IToolBarManager;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.ui.part.ViewPart;
8 import org.simantics.scl.compiler.commands.SCLConsoleListener;
9 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
10
11 /**
12  * @author Tuukka Lehtonen
13  * @since 1.31.0
14  */
15 public class SCLScriptConsoleView extends ViewPart {
16
17     private SCLConsole console;
18
19     @Override
20     public void createPartControl(Composite parent) {
21         this.console = new SCLConsole(parent, SWT.NONE,
22                 AbstractCommandConsole.HIDE_INPUT | SCLConsole.EXCLUDE_CONTRIBUTED_LISTENERS);
23
24         IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
25         Action clearAction = ConsoleActions.createClearAction(console);
26         toolBarManager.add(clearAction);
27
28         console.addListener(new SCLConsoleListener() {
29             @Override
30             public void consoleIsNotEmptyAnymore() {
31                 clearAction.setEnabled(true);
32             }
33         });
34
35         toolBarManager.update(true);
36     }
37
38     @Override
39     public void setFocus() {
40         console.setFocus();
41     }
42
43     @Override
44     public void dispose() {
45         super.dispose();
46         console.dispose();
47     }
48
49     @SuppressWarnings("unchecked")
50     @Override
51     public <T> T getAdapter(Class<T> adapter) {
52         if (adapter == SCLReportingHandler.class)
53             return (T) console.getHandler();
54         return super.getAdapter(adapter);
55     }
56
57 }