Skip to content

Commit

Permalink
View and Edit components for BINARY. Issue #131 and #41
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomYdn committed Mar 16, 2015
1 parent 24dcf00 commit c663c92
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wicket:panel>
<input wicket:id="data" type="file">
</wicket:panel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.orienteer.components.properties;

import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.model.IModel;

public class BinaryEditPanel extends FormComponentPanel<byte[]> {

private FileUploadField fileUploadField;

public BinaryEditPanel(String id, IModel<byte[]> model) {
super(id, model);
fileUploadField = new FileUploadField("data");
add(fileUploadField);
}

@Override
protected void convertInput() {
FileUpload fileUpload = fileUploadField.getFileUpload();
if(fileUpload!=null)
{
setConvertedInput(fileUpload.getBytes());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wicket:panel>
<a href="#" wicket:id="data"><wicket:message key="download.link">Data</wicket:message></a>
</wicket:panel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.orienteer.components.properties;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.AbstractResource.ResourceResponse;
import org.apache.wicket.request.resource.IResource.Attributes;
import org.orienteer.services.IOClassIntrospector;

import com.google.inject.Inject;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.record.impl.ODocument;

public class BinaryViewPanel<V> extends GenericPanel<V> {

private IModel<ODocument> documentModel;
private IModel<OProperty> propertyModel;
private IModel<V> valueModel;

@Inject
private IOClassIntrospector oClassIntrospector;

@SuppressWarnings("unchecked")
public BinaryViewPanel(String id, IModel<ODocument> docModel, IModel<OProperty> propModel, IModel<V> valueModel) {
super(id, valueModel);
this.documentModel = docModel;
this.propertyModel = propModel;
add(new ResourceLink<byte[]>("data", new AbstractResource() {

@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
ResourceResponse resourceResponse = new ResourceResponse();
resourceResponse.setContentType("application/octet-stream");
String filename = oClassIntrospector.getDocumentName(documentModel.getObject());
filename += "."+propertyModel.getObject().getName()+".bin";
resourceResponse.setFileName(filename);
resourceResponse.setWriteCallback(new WriteCallback()
{
@Override
public void writeData(Attributes attributes) throws IOException
{
OutputStream outputStream = attributes.getResponse().getOutputStream();
outputStream.write((byte[])BinaryViewPanel.this.getModelObject());
}
});
return resourceResponse;
}
}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.orienteer.components.properties.BinaryEditPanel;
import org.orienteer.components.properties.BinaryViewPanel;
import org.orienteer.components.properties.BooleanViewPanel;
import org.orienteer.components.properties.DisplayMode;
import org.orienteer.components.properties.EmbeddedCollectionEditPanel;
Expand Down Expand Up @@ -70,6 +72,8 @@ public <V> Component createComponent(String id, DisplayMode mode,
case EMBEDDEDLIST:
case EMBEDDEDSET:
return new EmbeddedCollectionViewPanel<Object, Collection<Object>>(id, documentModel, propertyModel);
case BINARY:
return new BinaryViewPanel(id, documentModel, propertyModel, valueModel);
default:
return new Label(id, valueModel);
}
Expand All @@ -94,6 +98,8 @@ else if(DisplayMode.EDIT.equals(mode))
return new EmbeddedCollectionEditPanel<Object, List<Object>>(id, documentModel, propertyModel, ArrayList.class);
case EMBEDDEDSET:
return new EmbeddedCollectionEditPanel<Object, Set<Object>>(id, documentModel, propertyModel, HashSet.class);
case BINARY:
return new BinaryEditPanel(id, (IModel<byte[]>)valueModel);
default:
TextField<V> ret = new TextField<V>(id, valueModel);
Class<?> javaOType = oType.getDefaultJavaType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ menu.userProfile=User Profile
menu.login=Login
menu.logout=Logout

download.link=Data

menu.list.class=Classes
menu.list.role=Roles
menu.list.user=Users
Expand Down

0 comments on commit c663c92

Please sign in to comment.