}
public Widget asWidget()
{
final TabPanel tabs = new TabPanel();
tabs.setStyleName("default-tabpanel");
// -------
VerticalPanel layout = new VerticalPanel();
layout.setStyleName("window-content");
// Create a FormPanel and point it at a service.
final FormPanel form = new FormPanel();
String url = Console.getBootstrapContext().getProperty(BootstrapContext.DEPLOYMENT_API);
form.setAction(url);
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
panel.getElement().setAttribute("style", "width:100%");
form.setWidget(panel);
// Create a FileUpload widget.
final FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);
final HTML errorMessages = new HTML("Please chose a file!");
errorMessages.setStyleName("error-panel");
errorMessages.setVisible(false);
panel.add(errorMessages);
// Add a 'submit' button.
ClickHandler cancelHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
window.hide();
}
};
ClickHandler submitHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
errorMessages.setVisible(false);
// verify form
String filename = upload.getFilename();
if(tabs.getTabBar().getSelectedTab()==1)
{
// unmanaged content
if(unmanagedForm.validate().hasErrors())
{
return;
}
else
{
wizard.onCreateUnmanaged(unmanagedForm.getUpdatedEntity());
}
}
else if(filename!=null && !filename.equals(""))
{
loading = Feedback.loading(
Console.CONSTANTS.common_label_plaseWait(),
Console.CONSTANTS.common_label_requestProcessed(),
new Feedback.LoadingCallback() {
@Override
public void onCancel() {
}
});
form.submit();
}
else
{
errorMessages.setVisible(true);
}
}
};
DialogueOptions options = new DialogueOptions(
Console.CONSTANTS.common_label_next(), submitHandler,
Console.CONSTANTS.common_label_cancel(), cancelHandler);
// Add an event handler to the form.
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
@Override
public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) {
getLoading().hide();
String html = event.getResults();
// Step 1: upload content, retrieve hash value
try {
String json = html;
try {
if(!GWT.isScript()) // TODO: Formpanel weirdness
json = html.substring(html.indexOf(">")+1, html.lastIndexOf("<"));
} catch (StringIndexOutOfBoundsException e) {
// if I get this exception it means I shouldn't strip out the html
// this issue still needs more research
Log.debug("Failed to strip out HTML. This should be preferred?");
}
JSONObject response = JSONParser.parseLenient(json).isObject();
JSONObject result = response.get("result").isObject();
String hash= result.get("BYTES_VALUE").isString().stringValue();
// step2: assign name and group
wizard.onUploadComplete(upload.getFilename(), hash);
} catch (Exception e) {
Log.error(Console.CONSTANTS.common_error_failedToDecode() + ": " + html, e);
}
// Option 2: Unmanaged content
}
});
String stepText = "<h3>" + Console.CONSTANTS.common_label_step() + "1/2: " +
Console.CONSTANTS.common_label_deploymentSelection() + "</h3>";
layout.add(new HTML(stepText));
HTML description = new HTML();
description.setHTML(Console.CONSTANTS.common_label_chooseFile());
description.getElement().setAttribute("style", "padding-bottom:15px;");
layout.add(description);
layout.add(form);
// Unmanaged form
VerticalPanel unmanagedPanel = new VerticalPanel();
unmanagedPanel.setStyleName("window-content");
String unmanagedText = "<h3>" + Console.CONSTANTS.common_label_step() + "1/1: Specify Deployment</h3>";
unmanagedPanel.add(new HTML(unmanagedText));
unmanagedForm = new Form<DeploymentRecord>(DeploymentRecord.class);
TextAreaItem path = new TextAreaItem("path", "Path");
TextBoxItem relativeTo= new TextBoxItem("relativeTo", "Relative To", false);
TextBoxItem name = new TextBoxItem("name", "Name");
TextBoxItem runtimeName = new TextBoxItem("runtimeName", "Runtime Name");
CheckBoxItem archive = new CheckBoxItem("archive", "Is Archive?");
archive.setValue(true);
unmanagedForm.setFields(path, relativeTo, archive, name, runtimeName);
unmanagedPanel.add(unmanagedForm.asWidget());
// Composite view
tabs.add(layout, "Managed");
tabs.add(unmanagedPanel, "Unmanaged");
tabs.selectTab(0);
return new WindowContentBuilder(tabs, options).build();
}