use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kura by eclipse.
the class FileUploadDialog method onRender.
@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setLayout(new FormLayout());
setBodyBorder(false);
setModal(true);
setButtons("");
setScrollMode(Scroll.AUTO);
setHideOnButtonClick(false);
setSize(400, 125);
m_formPanel = new FormPanel();
m_formPanel.setFrame(false);
m_formPanel.setHeaderVisible(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setAction(m_url);
m_formPanel.setEncoding(Encoding.MULTIPART);
m_formPanel.setMethod(Method.POST);
m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
m_formPanel.setLabelWidth(50);
m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent be) {
String htmlResponse = be.getResultHtml();
if (htmlResponse == null || htmlResponse.isEmpty()) {
MessageBox.info(MSGS.information(), MSGS.fileUploadSuccess(), null);
} else {
String errMsg = htmlResponse;
int startIdx = htmlResponse.indexOf("<pre>");
int endIndex = htmlResponse.indexOf("</pre>");
if (startIdx != -1 && endIndex != -1) {
errMsg = htmlResponse.substring(startIdx + 5, endIndex);
}
MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
}
hide();
}
});
m_fileUploadField = new FileUploadField();
m_fileUploadField.setAllowBlank(false);
m_fileUploadField.setName("uploadedFile");
m_fileUploadField.setFieldLabel(MSGS.fileLabel());
m_formPanel.add(m_fileUploadField);
if (m_hiddenFields != null) {
for (HiddenField<?> hf : m_hiddenFields) {
m_formPanel.add(hf);
}
}
//
// xsrfToken Hidden field
//
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
xsrfTokenField = new HiddenField<String>();
xsrfTokenField.setId("xsrfToken");
xsrfTokenField.setName("xsrfToken");
xsrfTokenField.setValue("");
m_formPanel.add(xsrfTokenField);
//
add(m_formPanel);
}
use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kura by eclipse.
the class CommandTab method onRender.
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FitLayout());
setId("device-command");
FormData formData = new FormData("100%");
//
// Command Form
//
m_formPanel = new FormPanel();
m_formPanel.setFrame(true);
m_formPanel.setHeaderVisible(false);
m_formPanel.setBorders(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setAction(SERVLET_URL);
m_formPanel.setEncoding(Encoding.MULTIPART);
m_formPanel.setMethod(Method.POST);
m_formPanel.setButtonAlign(HorizontalAlignment.RIGHT);
m_buttonBar = m_formPanel.getButtonBar();
initButtonBar();
m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent be) {
String htmlResult = be.getResultHtml();
if (htmlResult.startsWith("HTTP ERROR")) {
MessageBox.info(MSGS.information(), MSGS.fileUploadFailure() + "\n" + htmlResult, null);
m_commandInput.unmask();
} else {
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtDeviceService.executeCommand(token, m_commandField.getValue(), m_passwordField.getValue(), new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught.getLocalizedMessage().equals(GwtKuraErrorCode.SERVICE_NOT_ENABLED.toString())) {
Info.display(MSGS.error(), MSGS.commandServiceNotEnabled());
} else if (caught.getLocalizedMessage().equals(GwtKuraErrorCode.ILLEGAL_ARGUMENT.toString())) {
Info.display(MSGS.error(), MSGS.commandPasswordNotCorrect());
} else {
Info.display(MSGS.error(), caught.getLocalizedMessage());
}
// FailureHandler.handle(caught);
m_commandInput.unmask();
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
}
public void onSuccess(String result) {
m_result.clear();
m_result.setValue(result);
m_commandInput.unmask();
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
}
});
}
});
}
}
});
//
// Command Output
//
m_commandOutput = new LayoutContainer();
m_commandOutput.setBorders(false);
m_commandOutput.setWidth("99.5%");
m_commandOutput.setLayout(new FitLayout());
m_result = new TextArea();
m_result.setBorders(false);
m_result.setReadOnly(true);
m_result.setEmptyText(MSGS.deviceCommandNoOutput());
m_commandOutput.add(m_result);
//
// Input and Upload
//
m_commandField = new TextField<String>();
m_commandField.setName("command");
m_commandField.setAllowBlank(false);
m_commandField.setFieldLabel(MSGS.deviceCommandExecute());
m_formPanel.add(m_commandField, formData);
m_passwordField = new TextField<String>();
m_passwordField.setName("password");
m_passwordField.setPassword(true);
m_passwordField.setAllowBlank(true);
m_passwordField.setFieldLabel(MSGS.deviceCommandPassword());
m_formPanel.add(m_passwordField, formData);
m_fileUploadField = new FileUploadField();
m_fileUploadField.setAllowBlank(true);
m_fileUploadField.setName("file");
m_fileUploadField.setFieldLabel("File");
m_formPanel.add(m_fileUploadField, formData);
//
// xsrfToken Hidden field
//
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
xsrfTokenField = new HiddenField<String>();
xsrfTokenField.setId("xsrfToken");
xsrfTokenField.setName("xsrfToken");
xsrfTokenField.setValue("");
m_formPanel.add(xsrfTokenField);
//
m_commandInput = m_formPanel;
// Main Panel
ContentPanel deviceCommandPanel = new ContentPanel();
deviceCommandPanel.setBorders(false);
deviceCommandPanel.setBodyBorder(false);
deviceCommandPanel.setHeaderVisible(false);
deviceCommandPanel.setScrollMode(Scroll.AUTO);
deviceCommandPanel.setLayout(new FitLayout());
deviceCommandPanel.setTopComponent(m_commandInput);
deviceCommandPanel.add(m_commandOutput);
add(deviceCommandPanel);
}
use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kura by eclipse.
the class PackageInstallDialog method onRender.
@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setLayout(new FitLayout());
setBodyBorder(false);
setModal(true);
setButtons("");
setScrollMode(Scroll.AUTO);
setHideOnButtonClick(false);
setSize(400, 175);
m_tabsPanel = new TabPanel();
m_tabsPanel.setPlain(true);
m_tabsPanel.setBorders(false);
//
// File upload tab
m_formPanelFile = new FormPanel();
m_formPanelFile.setFrame(false);
m_formPanelFile.setHeaderVisible(false);
m_formPanelFile.setBodyBorder(false);
m_formPanelFile.setAction(m_actionUrl + "/upload");
m_formPanelFile.setEncoding(Encoding.MULTIPART);
m_formPanelFile.setMethod(Method.POST);
m_formPanelFile.setButtonAlign(HorizontalAlignment.CENTER);
m_formPanelFile.setStyleAttribute("padding-right", "0px");
m_formPanelFile.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent be) {
String htmlResponse = be.getResultHtml();
if (htmlResponse == null || htmlResponse.isEmpty()) {
MessageBox.info(MSGS.information(), MSGS.fileUploadSuccess(), null);
} else {
MessageBox.info(MSGS.information(), MSGS.fileUploadFailure(), null);
}
hide();
}
});
FieldSet fileFieldSet = new FieldSet();
fileFieldSet.setBorders(false);
fileFieldSet.setStyleAttribute("padding", "0px");
FormLayout fileFormLayout = new FormLayout();
fileFormLayout.setLabelWidth(Constants.LABEL_WIDTH_FORM_SMALL);
fileFieldSet.setLayout(fileFormLayout);
m_fileUploadField = new FileUploadField();
m_fileUploadField.setAllowBlank(false);
m_fileUploadField.setName("uploadedFile");
m_fileUploadField.setFieldLabel(MSGS.fileLabel());
if (m_hiddenFields != null) {
for (HiddenField<?> hf : m_hiddenFields) {
fileFieldSet.add(hf);
}
}
FormData fileFormData = new FormData("-20");
fileFormData.setMargins(new Margins(0, 0, 0, 0));
fileFieldSet.add(m_fileUploadField, fileFormData);
m_formPanelFile.add(fileFieldSet, fileFormData);
m_tabFile = new TabItem(MSGS.fileLabel());
m_tabFile.setBorders(true);
m_tabFile.setLayout(new FormLayout());
m_tabFile.add(m_formPanelFile);
m_tabsPanel.add(m_tabFile);
//
// xsrfToken Hidden field
//
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenFieldFile.setValue(token.getToken());
xsrfTokenFieldUrl.setValue(token.getToken());
}
});
xsrfTokenFieldFile = new HiddenField<String>();
xsrfTokenFieldFile.setId("xsrfToken");
xsrfTokenFieldFile.setName("xsrfToken");
xsrfTokenFieldFile.setValue("");
m_formPanelFile.add(xsrfTokenFieldFile);
//
//
// Download URL tab
m_formPanelUrl = new FormPanel();
m_formPanelUrl.setFrame(false);
m_formPanelUrl.setHeaderVisible(false);
m_formPanelUrl.setBodyBorder(false);
m_formPanelUrl.setAction(m_actionUrl + "/url");
m_formPanelUrl.setMethod(Method.POST);
m_formPanelUrl.setStyleAttribute("padding-right", "0px");
m_formPanelUrl.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent be) {
String htmlResponse = be.getResultHtml();
if (htmlResponse == null || htmlResponse.isEmpty()) {
MessageBox.info(MSGS.information(), MSGS.fileDownloadSuccess(), null);
} else {
String errMsg = htmlResponse;
int startIdx = htmlResponse.indexOf("<pre>");
int endIndex = htmlResponse.indexOf("</pre>");
if (startIdx != -1 && endIndex != -1) {
errMsg = htmlResponse.substring(startIdx + 5, endIndex);
}
MessageBox.alert(MSGS.error(), MSGS.fileDownloadFailure() + ": " + errMsg, null);
}
hide();
}
});
FieldSet urlFieldSet = new FieldSet();
urlFieldSet.setBorders(false);
urlFieldSet.setStyleAttribute("padding", "0px");
FormLayout urlFormLayout = new FormLayout();
urlFormLayout.setLabelWidth(Constants.LABEL_WIDTH_FORM_SMALL);
urlFieldSet.setLayout(urlFormLayout);
m_textFieldUrl = new TextField<String>();
m_textFieldUrl.setAllowBlank(false);
m_textFieldUrl.setName("packageUrl");
m_textFieldUrl.setFieldLabel(MSGS.urlLabel());
FormData urlFormData = new FormData("-20");
urlFormData.setMargins(new Margins(0, 0, 0, 0));
urlFieldSet.add(m_textFieldUrl, urlFormData);
if (m_hiddenFields != null) {
for (HiddenField<?> hf : m_hiddenFields) {
urlFieldSet.add(hf);
}
}
m_formPanelUrl.add(urlFieldSet, urlFormData);
//
// xsrfToken Hidden field
//
xsrfTokenFieldUrl = new HiddenField<String>();
xsrfTokenFieldUrl.setId("xsrfToken");
xsrfTokenFieldUrl.setName("xsrfToken");
xsrfTokenFieldUrl.setValue("");
m_formPanelUrl.add(xsrfTokenFieldUrl);
//
m_tabUrl = new TabItem(MSGS.urlLabel());
m_tabUrl.setBorders(true);
m_tabUrl.setLayout(new FormLayout());
m_tabUrl.add(m_formPanelUrl);
m_tabsPanel.add(m_tabUrl);
add(m_tabsPanel);
}
use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kapua by eclipse.
the class DeviceTabCommand method initCommandInput.
private void initCommandInput() {
FormData formData = new FormData("-20");
FormLayout layout = new FormLayout();
layout.setLabelWidth(Constants.LABEL_WIDTH_FORM);
FieldSet fieldSet = new FieldSet();
fieldSet.setBorders(false);
fieldSet.setLayout(layout);
fieldSet.setStyleAttribute("margin", "0px");
fieldSet.setStyleAttribute("padding", "0px");
m_formPanel = new FormPanel();
m_formPanel.setFrame(true);
m_formPanel.setHeaderVisible(false);
m_formPanel.setBorders(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setAction(SERVLET_URL);
m_formPanel.setEncoding(Encoding.MULTIPART);
m_formPanel.setMethod(Method.POST);
m_formPanel.add(fieldSet);
m_formPanel.addListener(Events.Render, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
NodeList<com.google.gwt.dom.client.Element> nl = m_formPanel.getElement().getElementsByTagName("form");
if (nl.getLength() > 0) {
com.google.gwt.dom.client.Element elemForm = nl.getItem(0);
elemForm.setAttribute("autocomplete", "off");
}
}
});
m_formPanel.setButtonAlign(HorizontalAlignment.RIGHT);
m_buttonBar = m_formPanel.getButtonBar();
initButtonBar();
m_formPanel.addListener(Events.BeforeSubmit, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if (!m_selectedDevice.isOnline()) {
MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
m_commandInput.unmask();
}
});
be.setCancelled(true);
}
}
});
m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
@Override
public void handleEvent(FormEvent be) {
String htmlResult = be.getResultHtml();
//
if (!htmlResult.startsWith("<pre")) {
int errorMessageStartIndex = htmlResult.indexOf("<pre");
errorMessageStartIndex = htmlResult.indexOf(">", errorMessageStartIndex) + 1;
int errorMessageEndIndex = htmlResult.indexOf("</pre>");
String errorMessage = htmlResult.substring(errorMessageStartIndex, errorMessageEndIndex);
MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ":<br/>" + errorMessage, null);
m_commandInput.unmask();
} else {
int outputMessageStartIndex = htmlResult.indexOf("<pre");
outputMessageStartIndex = htmlResult.indexOf(">", outputMessageStartIndex) + 1;
int outputMessageEndIndex = htmlResult.indexOf("</pre>");
String output = htmlResult.substring(outputMessageStartIndex, outputMessageEndIndex);
m_result.setValue(KapuaSafeHtmlUtils.htmlUnescape(output));
m_commandInput.unmask();
}
}
});
m_accountField = new HiddenField<String>();
m_accountField.setName("scopeIdString");
fieldSet.add(m_accountField);
m_deviceIdField = new HiddenField<String>();
m_deviceIdField.setName("deviceIdString");
fieldSet.add(m_deviceIdField);
m_timeoutField = new HiddenField<Integer>();
m_timeoutField.setName("timeout");
fieldSet.add(m_timeoutField);
//
// xsrfToken Hidden field
//
xsrfTokenField = new HiddenField<String>();
xsrfTokenField.setId("xsrfToken");
xsrfTokenField.setName("xsrfToken");
xsrfTokenField.setValue("");
fieldSet.add(xsrfTokenField);
m_commandField = new TextField<String>();
m_commandField.setName("command");
m_commandField.setAllowBlank(false);
m_commandField.setFieldLabel("* " + MSGS.deviceCommandExecute());
m_commandField.setLayoutData(layout);
fieldSet.add(m_commandField, formData);
m_fileUploadField = new FileUploadField();
m_fileUploadField.setAllowBlank(true);
m_fileUploadField.setName("file");
m_fileUploadField.setLayoutData(layout);
m_fileUploadField.setFieldLabel(MSGS.deviceCommandFile());
fieldSet.add(m_fileUploadField, formData);
m_passwordField = new TextField<String>();
m_passwordField.setName("password");
m_passwordField.setFieldLabel(MSGS.deviceCommandPassword());
m_passwordField.setToolTip(MSGS.deviceCommandPasswordTooltip());
m_passwordField.setPassword(true);
m_passwordField.setLayoutData(layout);
fieldSet.add(m_passwordField, formData);
m_commandInput = m_formPanel;
m_commandInput.mask(MSGS.deviceNoDeviceSelected());
}
use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kapua by eclipse.
the class FileUploadDialog method onRender.
@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setLayout(new FormLayout());
setBodyBorder(false);
// setButtonAlign(HorizontalAlignment.CENTER); // Must be called beforehand
setModal(true);
setButtons("");
setAutoWidth(true);
setScrollMode(Scroll.AUTO);
setHideOnButtonClick(false);
m_formPanel = new FormPanel();
m_formPanel.setFrame(false);
m_formPanel.setHeaderVisible(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setAction(m_url);
m_formPanel.setEncoding(Encoding.MULTIPART);
m_formPanel.setMethod(Method.POST);
m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
@Override
public void handleEvent(FormEvent be) {
String htmlResponse = be.getResultHtml();
if (htmlResponse == null || htmlResponse.isEmpty()) {
MessageBox.info(MSGS.information(), MSGS.fileUploadSuccess(), null);
} else {
String errMsg = htmlResponse;
int startIdx = htmlResponse.indexOf("<pre>");
int endIndex = htmlResponse.indexOf("</pre>");
if (startIdx != -1 && endIndex != -1) {
errMsg = htmlResponse.substring(startIdx + 5, endIndex);
}
MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
}
hide();
}
});
m_fileUploadField = new FileUploadField();
m_fileUploadField.setAllowBlank(false);
m_fileUploadField.setName("uploadedFile");
m_fileUploadField.setFieldLabel("File");
m_formPanel.add(m_fileUploadField);
if (m_hiddenFields != null) {
for (HiddenField<?> hf : m_hiddenFields) {
m_formPanel.add(hf);
}
}
//
// xsrfToken Hidden field
//
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
xsrfTokenField = new HiddenField<String>();
xsrfTokenField.setId("xsrfToken");
xsrfTokenField.setName("xsrfToken");
xsrfTokenField.setValue("");
m_formPanel.add(xsrfTokenField);
//
add(m_formPanel);
}
Aggregations