package org.orienteer.core.component.widget.oclass;

import com.google.inject.Inject;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.Form;
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.component.command.EditSchemaCommand;
import org.orienteer.core.component.command.SaveSchemaCommand;
import org.orienteer.core.component.meta.OClassMetaPanel;
import org.orienteer.core.component.structuretable.OrienteerStructureTable;
import org.orienteer.core.service.IOClassIntrospector;
import org.orienteer.core.widget.AbstractModeAwareWidget;
import org.orienteer.core.widget.Widget;

import ru.ydn.wicket.wicketorientdb.components.TransactionlessForm;

import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.impl.ODocument;

/**
 * Widget to show and modify {@link OClass} configuration
 */
@Widget(id="class-configuration", domain="class", tab="configuration", autoEnable=true)
public class OClassConfigurationWidget extends AbstractModeAwareWidget<OClass> {

	@Inject
	private IOClassIntrospector inspector;

	private OrienteerStructureTable<OClass, String> structureTable;
	
	public OClassConfigurationWidget(String id, IModel<OClass> model,
			IModel<ODocument> widgetDocumentModel) {
		super(id, model, widgetDocumentModel);
		Form<OClass> form = new TransactionlessForm<OClass>("form");
		structureTable  = new OrienteerStructureTable<OClass, String>("attributes", getModel(), OClassMetaPanel.OCLASS_ATTRS) {

			@Override
			protected Component getValueComponent(String id, final IModel<String> rowModel) {
				return new OClassMetaPanel<Object>(id, getModeModel(), OClassConfigurationWidget.this.getModel(), rowModel);
			}
			
		};
		structureTable.addCommand(new EditSchemaCommand<OClass>(structureTable, getModeModel()));
		structureTable.addCommand(new SaveSchemaCommand<OClass>(structureTable, getModeModel(), getModel()));
		
		form.add(structureTable);
		add(form);
	}

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

	@Override
	protected IModel<String> getTitleModel() {
		return new ResourceModel("class.configuration");
	}
	
	@Override
	protected String getWidgetStyleClass() {
		return "strict";
	}

}

@@ -245,24 +245,90 @@
 ourceModel;%0A
+import org.apache.wicket.request.mapper.parameter.PageParameters;%0A
 import org.o
@@ -407,16 +407,89 @@
 onType;%0A
+import org.orienteer.core.component.command.BookmarkablePageLinkCommand;%0A
 import o
@@ -660,24 +660,82 @@
 sMetaPanel;%0A
+import org.orienteer.core.component.property.DisplayMode;%0A
 import org.o
@@ -828,35 +828,211 @@
 ore.
-service.IOClassIntrospector
+component.widget.document.ODocumentPropertiesWidget;%0Aimport org.orienteer.core.service.IOClassIntrospector;%0Aimport org.orienteer.core.web.BrowseOClassPage;%0Aimport org.orienteer.core.web.schema.OClassPage
 ;%0Aim
@@ -2484,16 +2484,319 @@
 (form);%0A
+%09%09%0A%09%09addCommand(new BookmarkablePageLinkCommand%3COClass%3E(newCommandId(), %22class.browse%22, BrowseOClassPage.class) %7B%0A%09%09%09@Override%0A%09%09%09public PageParameters getPageParameters() %7B%0A%09%09%09%09return BrowseOClassPage.preparePageParameters(OClassConfigurationWidget.this.getModelObject(), DisplayMode.VIEW);%0A%09%09%09%7D%0A%09%09%7D);%0A
 %09%7D%0A%0A%09@Ov

Add action to jump to browsing of a OClass: fix #367