X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Fconsole%2FSCLConsoleView.java;h=bab62144b5e514ffbcdd6f6984b650e7875a4e76;hb=refs%2Fchanges%2F94%2F2594%2F1;hp=cb2181912e1464b5978298c6b7314e81bdff6e48;hpb=bc6a0b96888a031cb7f0d154b5e62150e7bab72b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsoleView.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsoleView.java index cb2181912..bab62144b 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsoleView.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsoleView.java @@ -10,6 +10,8 @@ import java.util.List; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.IPersistentPreferenceStore; @@ -20,28 +22,39 @@ import org.eclipse.swt.dnd.DropTargetAdapter; import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.FileTransfer; import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.commands.CommandSessionImportEntry; import org.simantics.scl.compiler.commands.SCLConsoleListener; +import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.compiler.testing.TestRunnable; import org.simantics.scl.osgi.internal.TestUtils; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; import org.simantics.scl.ui.Activator; import org.simantics.scl.ui.imports.internal.ManageImportsDialog; import org.simantics.scl.ui.tests.SCLTestsDialog; public class SCLConsoleView extends ViewPart { - public static final String PLUGIN_ID = "org.simantics.scl.ui"; - public static final String IMPORTS = "imports"; - public static final String SEPARATOR = ";"; - public static final String DISABLED_TAG = "[DISABLED]"; + public static final String PLUGIN_ID = "org.simantics.scl.ui"; //$NON-NLS-1$ + public static final String IMPORTS = "imports"; //$NON-NLS-1$ + public static final String REFRESH_AUTOMATICALLY = "refresh-automatically"; //$NON-NLS-1$ + public static final String SEPARATOR = ";"; //$NON-NLS-1$ + public static final String DISABLED_TAG = "[DISABLED]"; //$NON-NLS-1$ + IPersistentPreferenceStore store; SCLConsole console; + boolean refreshAutomatically = false; + MenuItem refreshAutomaticallyItem; private ArrayList readImportPreferences() { - IPersistentPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PLUGIN_ID); String importsString = store.getString(IMPORTS); String[] splitted = importsString.split(SEPARATOR); @@ -54,10 +67,10 @@ public class SCLConsoleView extends ViewPart { disabled = true; entryString = entryString.substring(DISABLED_TAG.length()); } - String[] parts = entryString.split("="); + String[] parts = entryString.split("="); //$NON-NLS-1$ CommandSessionImportEntry entry; if(parts.length == 1) - entry = new CommandSessionImportEntry(parts[0], "", true); + entry = new CommandSessionImportEntry(parts[0], "", true); //$NON-NLS-1$ else entry = new CommandSessionImportEntry(parts[1], parts[0], true); entry.disabled = disabled; @@ -80,13 +93,13 @@ public class SCLConsoleView extends ViewPart { b.append(DISABLED_TAG); if(!entry.localName.isEmpty()) { b.append(entry.localName); - b.append("="); + b.append("="); //$NON-NLS-1$ } b.append(entry.moduleName); } IPersistentPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PLUGIN_ID); - store.putValue(IMPORTS, b.toString()); + store.setValue(IMPORTS, b.toString()); } private ArrayList getCurrentImports() { @@ -118,8 +131,8 @@ public class SCLConsoleView extends ViewPart { try { // Bit of a haxx solution to get around a deadlock caused by simply // running the test with test.run() - console.execute("import \"Commands/Tests\""); - console.execute("runByName \"" + test.getName() + "\""); + console.execute("import \"Commands/Tests\""); //$NON-NLS-1$ + console.execute("runByName \"" + test.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ // test.run(); } catch (Exception e) { e.printStackTrace(); @@ -127,42 +140,50 @@ public class SCLConsoleView extends ViewPart { } } } + + private UpdateListener dependencyListener = new UpdateListener() { + @Override + public void notifyAboutUpdate() { + if(refreshAutomatically) + console.getSession().updateRuntimeEnvironment(true); + } + }; + private void setRefreshAutomatically(boolean refreshAutomatically, boolean refreshAlso) { + this.refreshAutomatically = refreshAutomatically; + if(refreshAutomaticallyItem != null) + refreshAutomaticallyItem.setSelection(refreshAutomatically); + + store.setValue(REFRESH_AUTOMATICALLY, refreshAutomatically); + + if(refreshAutomatically) { + console.getSession().setDependenciesListener(dependencyListener); + if(refreshAlso) + console.getSession().updateRuntimeEnvironment(true); + } + else { + console.getSession().setDependenciesListener(null); + dependencyListener.stopListening(); + } + } + @Override public void createPartControl(Composite parent) { + store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PLUGIN_ID); + store.setDefault(REFRESH_AUTOMATICALLY, true); + this.console = new SCLConsole(parent, SWT.NONE); - setCurrentImports(readImportPreferences()); - - addScriptDropSupport(console); IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager(); // Interrupt action - final Action interruptAction = new Action("Interrupt current command", - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/stop.png")) { - @Override - public void run() { - console.interruptCurrentCommands(); - } - }; - interruptAction.setDisabledImageDescriptor( - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/stop_disabled.png")); - interruptAction.setEnabled(false); + Action interruptAction = ConsoleActions.createInterruptAction(console); toolBarManager.add(interruptAction); // Clear console action - final Action clearAction = new Action("Clear console", - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/clear_console.png")) { - @Override - public void run() { - setEnabled(false); - console.clear(); - } - }; - clearAction.setDisabledImageDescriptor( - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/clear_console_disabled.png")); - clearAction.setEnabled(false); + Action clearAction = ConsoleActions.createClearAction(console); toolBarManager.add(clearAction); + console.addListener(new SCLConsoleListener() { @Override public void startedExecution() { @@ -179,27 +200,59 @@ public class SCLConsoleView extends ViewPart { }); // Refresh action - toolBarManager.add(new Action("Refresh modules", - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/arrow_refresh.png")) { + toolBarManager.add(new Action(Messages.SCLConsoleView_RefreshModules, IAction.AS_DROP_DOWN_MENU) { + { + setImageDescriptor(Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/arrow_refresh.png")); //$NON-NLS-1$ //$NON-NLS-2$ + setMenuCreator(new IMenuCreator() { + Menu menu; + @Override + public Menu getMenu(Menu parent) { + throw new UnsupportedOperationException(); + } + + @Override + public Menu getMenu(Control parent) { + if(menu == null) { + menu = new Menu(parent); + refreshAutomaticallyItem = new MenuItem(menu, SWT.CHECK); + refreshAutomaticallyItem.setText(Messages.SCLConsoleView_RefreshAutomatically); + refreshAutomaticallyItem.setSelection(refreshAutomatically); + refreshAutomaticallyItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setRefreshAutomatically(!refreshAutomatically, true); + } + }); + } + return menu; + } + + @Override + public void dispose() { + if(menu != null) + menu.dispose(); + } + }); + } @Override public void run() { console.getSession().getModuleRepository().getSourceRepository().checkUpdates(); console.getSession().updateRuntimeEnvironment(true); - console.appendOutput("refresh completed\n", console.greenColor, null); + console.appendOutput(Messages.SCLConsoleView_RefreshCompleted, console.greenColor, null); } }); - toolBarManager.add(new Action("Manage imports", - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/configure_imports.png")) { + toolBarManager.add(new Action(Messages.SCLConsoleView_ManageImports, + Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/configure_imports.png")) { //$NON-NLS-1$ //$NON-NLS-2$ @Override public void run() { manageImports(); } }); - + // Show action for running SCL tests if in development mode if (Platform.inDevelopmentMode()) { - toolBarManager.add(new Action("Run tests", - Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/run_tests.png")) { + toolBarManager.add(new Action(Messages.SCLConsoleView_RunTests, + Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/run_tests.png")) { //$NON-NLS-1$ //$NON-NLS-2$ @Override public void run() { sclTestDialog(); @@ -208,6 +261,12 @@ public class SCLConsoleView extends ViewPart { } toolBarManager.update(true); + + setRefreshAutomatically(store.getBoolean(REFRESH_AUTOMATICALLY), false); + // Do this after the actions and SCLConsoleListener are + // registered because it can cause output to the console. + setCurrentImports(readImportPreferences()); + addScriptDropSupport(console); } private class ScriptRunningDropTarget extends DropTargetAdapter { @@ -233,7 +292,7 @@ public class SCLConsoleView extends ViewPart { for (String file : files) { Path p = Paths.get(file).toAbsolutePath(); if (isScriptFile(p)) { - console.execute("runFromFile \"" + p.toString().replace('\\', '/') + "\""); + console.execute("runFromFile \"" + p.toString().replace('\\', '/') + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } } } @@ -263,4 +322,14 @@ public class SCLConsoleView extends ViewPart { console.dispose(); } + @SuppressWarnings("unchecked") + @Override + public T getAdapter(Class adapter) { + if (adapter == CommandSession.class) + return (T) console.getSession(); + if (adapter == SCLReportingHandler.class) + return (T) console.getHandler(); + return super.getAdapter(adapter); + } + }