List of usage examples for org.apache.wicket.request.handler.resource ResourceStreamRequestHandler setCacheDuration
public ResourceStreamRequestHandler setCacheDuration(Duration cacheDuration)
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private void addComponents() { // Select the first message for initial display if (getConfig().messages.isEmpty()) { // No messages configured. Create a new message with id=1. getConfig().addMessageConfig(new MessageConfig(1)); }/*from www .j av a2s.c o m*/ currentMessage = getConfig().getMessageList().get(0); currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize()); currentMessageId = currentMessage.getMessageId(); // ******************************************************************************************* // *** Form for XML import final FileUploadField uploadField = new FileUploadField("upload-field", new ListModel<FileUpload>()); Form<?> uploadForm = new Form<Object>("upload-form") { @Override protected void onSubmit() { try { FileUpload upload = uploadField.getFileUpload(); if (upload != null) { handleOnUpload(upload.getInputStream()); } else { warn(new StringResourceModel("warn.noFileToUpload", this, null).getString()); } } catch (Exception e) { this.error(new StringResourceModel("import.error", this, null).getString() + " Exception: " + e.toString()); } } }; uploadForm.add(uploadField); SubmitLink importLink = new SubmitLink("import-link"); uploadForm.add(importLink); add(uploadForm); // ******************************************************************************************* // *** The message configuration currentMessageModel = new PropertyModel<MessageConfig>(this, "currentMessage"); editForm = new Form<MessageConfig>("edit-form", new CompoundPropertyModel<MessageConfig>(currentMessageModel)) { @Override protected void onError() { // Validation error - reset the message dropdown to the original value // Clear input causes the component to reload the model currentMessageIdDropdown.clearInput(); super.onError(); } }; editForm.add(new MessageFormValidator()); WebMarkupContainer tableContainer = new WebMarkupContainer("table-container"); messageIdTypeDropDown = getMessageIdTypeDropdown(); tableContainer.add(messageIdTypeDropDown); currentMessageIdDropdown = getCurrentMessageIdDropdown(); tableContainer.add(currentMessageIdDropdown); Button buttonNew = new Button("new"); buttonNew.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleNew(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonNew); Button buttonCopy = new Button("copy"); buttonCopy.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleCopy(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonCopy); Button deleteButton = new Button("delete"); deleteButton.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { handleDelete(target); } }); tableContainer.add(deleteButton); messageTypeDropdown = getMessageTypeDropdown(); tableContainer.add(messageTypeDropdown); tableContainer.add(getQueueModeDropdown()); tableContainer.add(new CheckBox("usePersistance").setOutputMarkupId(true)); WebMarkupContainer listEditorContainer = new WebMarkupContainer("list-editor"); messageIdTextField = getMessageIdTextField(); listEditorContainer.add(messageIdTextField); messageAliasTextField = getMessageAliasTextField(); listEditorContainer.add(messageAliasTextField); // Create the list editor editor = new ListEditor<TagConfig>("tags", new PropertyModel<List<TagConfig>>(currentMessageModel, "tags")) { @Override protected void onPopulateItem(EditorListItem<TagConfig> item) { item.setModel(new CompoundPropertyModel<TagConfig>(item.getModelObject())); BinaryDataType dataType = item.getModelObject().getDataType(); boolean enable = dataType.isSpecial() ? false : true; // Offset is displayed only for information item.add(new Label("offset").setOutputMarkupId(true)); if (enable) { item.add(getIdTextField()); } else { // The static TextField has no validation. Validation would fail for special tags. item.add(getSpecialIdTextField().setEnabled(false)); } item.add(getAliasTextField().setVisible(enable)); item.add(getSizeTextField().setEnabled(dataType.isArrayAllowed())); item.add(getTagLengthTypeDropDown().setEnabled(dataType.supportsVariableLength())); item.add(getDataTypeDropdown()); // Create the edit links to be used in the list editor item.add(getInsertLink()); item.add(getDeleteLink()); item.add(getMoveUpLink().setVisible(item.getIndex() > 0)); item.add(getMoveDownLink().setVisible(item.getIndex() < getList().size() - 1)); } }; listEditorContainer.add(editor); Label noItemsLabel = new Label("no-items-label", new StringResourceModel("noitems", this, null)) { @Override public boolean isVisible() { return editor.getList().size() == 0; } }; listEditorContainer.add(noItemsLabel); listEditorContainer.add(new EditorSubmitLink("add-row-link") { @Override public void onSubmit() { editor.addItem(new TagConfig()); // Adjust the visibility of the edit links updateListEditor(editor); } }); listEditorContainer.setOutputMarkupId(true); tableContainer.add(listEditorContainer); editForm.add(tableContainer); // XML export SubmitLink exportLink = new SubmitLink("export-link", editForm) { @Override public void onSubmit() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); handler.setCacheDuration(Duration.NONE); getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); } private String getFileName() { return String.format("MsgConfig_%s.xml", currentMessageModel.getObject().getMessageId()); } private IResourceStream getResourceStream() { String config = currentMessageModel.getObject().toXMLString(); return new StringResourceStream(config, "text/xml"); } }; editForm.add(exportLink); uploadForm.add(editForm); }
From source file:org.cast.cwm.ThemeDirectoryRequestMapper.java
License:Open Source License
@Override public IRequestHandler mapRequest(Request request) { String path = request.getUrl().getPath(); for (String prefix : prefixes) { if (path.startsWith(prefix)) { IResourceStream stream = getResourceStream(themeDirectory + "/" + path); if (stream == null) return null; ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(stream); if (cacheDuration != null) handler.setCacheDuration(cacheDuration); return handler; }/*w ww. j av a2 s. co m*/ } return null; }
From source file:org.cast.isi.mapper.CustomThemeDirectoryRequestMapper.java
License:Open Source License
private IRequestHandler getResourceStreamRequestHandler(IResourceStream stream) { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(stream); if (cacheDuration != null) handler.setCacheDuration(cacheDuration); return handler; }