package org.orienteer.core.component.property;

import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.orienteer.core.component.IExportable;
import org.orienteer.core.component.ODocumentPageLink;

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

/**
 * {@link Panel} to view a link to a document
 */
public class LinkViewPanel extends AbstractLinkViewPanel<ODocument> implements IExportable<String> {

	private static final long serialVersionUID = 1L;
	
	private IModel<?> titleModel;

	public LinkViewPanel(
			String id,
			IModel<ODocument> valueModel) {
		this(id, valueModel, null);
	}
	
	public LinkViewPanel(
			String id,
			IModel<ODocument> valueModel, IModel<?> titleModel) {
		super(id, valueModel);
		this.titleModel = titleModel;
	}
	
	@Override
	protected AbstractLink newLink(String id)
	{
		ODocumentPageLink link = new ODocumentPageLink(id, getModel());
		if(titleModel!=null) link.setBody(titleModel);
		else link.setDocumentNameAsBody(true);
		return link;
	}
	
	@Override
	public void detachModels() {
		super.detachModels();
		if(titleModel!=null) titleModel.detach();
	}

	@Override
	public IModel<String> getExportableDataModel() {
		return (IModel<String>) link.getBody();
	}

}

@@ -289,16 +289,68 @@
 ageLink;
+%0Aimport org.orienteer.core.model.ODocumentNameModel;
 %0A%0Aimport
@@ -619,22 +619,22 @@
 ortable%3C
-String
+Object
 %3E %7B%0A%0A%09pr
@@ -1349,22 +1349,17 @@
  IModel%3C
-String
+?
 %3E getExp
@@ -1381,16 +1381,31 @@
 l() %7B%0A%09%09
+if(link!=null) 
 return (
@@ -1432,18 +1432,115 @@
 .getBody();%0A
+%09%09else if(titleModel!=null) return titleModel;%0A%09%09else return new ODocumentNameModel(getModel());%0A
 %09%7D%0A%0A%7D%0A

Fix NPE in export if table contain LinkViewPanel