package org.orienteer.devutils.component.widget;

import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;
import org.orienteer.core.component.FAIcon;
import org.orienteer.core.component.FAIconType;
import org.orienteer.core.widget.AbstractWidget;
import org.orienteer.core.widget.Widget;

import com.orientechnologies.orient.core.record.impl.ODocument;

import ru.ydn.wicket.wicketconsole.WicketConsolePanel;

/**
 * Widget to show wicket-console on tools dashboard page
 */
@Widget(id="wicket-console", domain="tools", tab = "console", autoEnable=true)
public class WicketConsoleWidget extends AbstractWidget<Void> {

	public WicketConsoleWidget(String id, IModel<Void> model, IModel<ODocument> widgetDocumentModel) {
		super(id, model, widgetDocumentModel);
		add(new WicketConsolePanel("console"));
	}

	@Override
	protected FAIcon newIcon(String id) {
		return new FAIcon(id, FAIconType.terminal);
	}

	@Override
	protected IModel<String> getDefaultTitleModel() {
		return new ResourceModel("widget.wicketconsole");
	}

}

@@ -39,24 +39,47 @@
 nt.widget;%0A%0A
+import java.util.Map;%0A%0A
 import org.a
@@ -101,24 +101,24 @@
 del.IModel;%0A
-
 import org.a
@@ -330,24 +330,343 @@
 et.Widget;%0A%0A
+import com.orientechnologies.orient.core.command.script.OScriptDocumentDatabaseWrapper;%0Aimport com.orientechnologies.orient.core.command.script.OScriptOrientWrapper;%0Aimport com.orientechnologies.orient.core.db.document.ODatabaseDocument;%0Aimport com.orientechnologies.orient.core.metadata.function.OFunctionUtilWrapper;%0A
 import com.o
@@ -714,24 +714,75 @@
 ODocument;%0A%0A
+import ru.ydn.wicket.wicketconsole.IScriptContext;%0A
 import ru.yd
@@ -1175,16 +1175,16 @@
 Model);%0A
-
 %09%09add(ne
@@ -1213,16 +1213,416 @@
 console%22
+,new IScriptContext() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public Map%3CString, Object%3E getBindings() %7B%0A%09%09%09%09Map%3CString, Object%3E bindings = new HashMap%3CString, Object%3E();%0A%09%09%09%09ODatabaseDocument db = getDatabase();%0A%09%09%09%09bindings.put(%22db%22, new OScriptDocumentDatabaseWrapper(db));%0A%09%09%09%09bindings.put(%22orient%22, new OScriptOrientWrapper(db));%0A%09%09%09%09bindings.put(%22util%22, new OFunctionUtilWrapper());%0A%09%09%09%09return bindings;%0A%09%09%09%7D%0A%09%09%7D
 ));%0A%09%7D%0A%0A

add orienteer context for console scripts