package org.openlca.app.devtools;

import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.openlca.app.M;
import org.openlca.app.db.Database;
import org.openlca.app.rcp.images.Icon;
import org.openlca.app.util.Actions;
import org.openlca.app.util.Editors;
import org.openlca.app.util.Info;

public class Toolbar extends EditorActionBarContributor {

	@Override
	public void contributeToToolBar(IToolBarManager manager) {
		manager.add(Actions.create("Run", Icon.RUN.descriptor(),
				() -> {
					if (Database.get() == null) {
						Info.showBox(M.NoDatabaseOpened, M.NeedOpenDatabase);
						return;
					}
					FormEditor editor = Editors.getActive();
					if (!(editor instanceof IScriptEditor))
						return;
					IScriptEditor scriptEditor = (IScriptEditor) editor;
					scriptEditor.evalContent();
				}));
	}
}

@@ -183,70 +183,8 @@
 or;%0A
-import org.openlca.app.M;%0Aimport org.openlca.app.db.Database;%0A
 impo
@@ -219,16 +219,16 @@
 s.Icon;%0A
+
 import o
@@ -296,42 +296,8 @@
 ors;
-%0Aimport org.openlca.app.util.Info;
 %0A%0Apu
@@ -486,21 +486,17 @@
 r(),
-%0A%09%09%09%09
+ 
 () -%3E %7B%0A
 %09%09%09%09
@@ -495,126 +495,8 @@
 %3E %7B%0A
-%09%09%09%09%09if (Database.get() == null) %7B%0A%09%09%09%09%09%09Info.showBox(M.NoDatabaseOpened, M.NeedOpenDatabase);%0A%09%09%09%09%09%09return;%0A%09%09%09%09%09%7D%0A%09%09
 %09%09%09F
@@ -535,18 +535,16 @@
 tive();%0A
-%09%09
 %09%09%09if (!
@@ -586,18 +586,16 @@
 %09%09%09%09
-%09%09
 return;%0A
 %09%09%09%09
@@ -590,18 +590,16 @@
 return;%0A
-%09%09
 %09%09%09IScri
@@ -649,18 +649,16 @@
 tor;%0A%09%09%09
-%09%09
 scriptEd
@@ -677,18 +677,16 @@
 tent();%0A
-%09%09
 %09%09%7D));%0A%09

fix issue #23: Allow to execute Python scripts without an open database