package ru.ydn.wicket.wicketorientdb.utils;

import java.util.List;

import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;

import ru.ydn.wicket.wicketorientdb.OrientDbWebSession;
import ru.ydn.wicket.wicketorientdb.model.OClassNamingModel;

import com.orientechnologies.orient.core.metadata.schema.OClass;

/**
 * {@link IChoiceRenderer} for {@link OClass}es
 */
public class OClassChoiceRenderer implements IChoiceRenderer<OClass> {
	
	public static final OClassChoiceRenderer INSTANCE = new OClassChoiceRenderer();

	private static final long serialVersionUID = 1L;

	@Override
	public Object getDisplayValue(OClass object) {
		return new OClassNamingModel(object).getObject();
	}

	@Override
	public String getIdValue(OClass object, int index) {
		return object.getName();
	}

	@Override
	public OClass getObject(String id,
			IModel<? extends List<? extends OClass>> choicesModel) {
		OClass ret = OrientDbWebSession.get().getDatabase().getMetadata().getSchema().getClass(id);
		List<? extends OClass> choices = choicesModel.getObject();
		return choices!=null && choices.contains(ret) ? ret : null;
	}
}

@@ -556,61 +556,278 @@
 rer(
-);%0A%0A%09private static final long serialVersionUID = 1L;
+true);%0A%09public static final OClassChoiceRenderer INSTANCE_NO_LOCALIZATION = new OClassChoiceRenderer(false);%0A%0A%09private static final long serialVersionUID = 1L;%0A%09%0A%09private boolean localize;%0A%09%0A%09public OClassChoiceRenderer(boolean localize) %7B%0A%09%09this.localize = localize;%0A%09%7D
 %0A%0A%09@
@@ -892,16 +892,25 @@
 %09return 
+localize?
 new OCla
@@ -942,16 +942,33 @@
 Object()
+:object.getName()
 ;%0A%09%7D%0A%0A%09@

Allow to avoid translation of classname