I am building a project which downloads several PDF files from different URLs, merges them into a single one and downloads it.
I'm trying to use Vaadin's FileDownloader to achieve this:
final FileDownloader fileDownloader = new FileDownloader(new FileResource(resultResource.getFile()));
fileDownloader.extend(download);
The resultResource is the generated PDF which I want to download.
Now the problem is that it takes a short time to generate the PDF, so that sometimes the download happens before the new file is generated, resulting in it downloading the old file, or an empty one.
So what I've been trying to do is something like this:
download.addClickListener(e -> {
try {
// This creates the new PDF
pdfConverter.manipulatePdf(storeNumber.getValue());
fileDownloader.download();
} catch (...) {
...
}
});
But so far without any success. Is there any way to something like this? To disable the "automatic" download and trigger it manually?
There are two approaches you can try
First approach is to refactor your UI so, that PDF file is started to be generated when you enter the view, and once complete you enable the download button. You can have other indicators like progress bar if that is feasible.
In Vaadin 8.4+ you can also setup FileDownloader by extending EventTrigger (see pull request https://github.com/vaadin/framework/pull/10478 ) and API spec https://vaadin.com/download/release/8.4/8.4.2/docs/api/com/vaadin/server/EventTrigger.html That could be something to be exploited if the first way is not applicable for you.
Related
I need to create one more response filter during one test scenario. But now when I do this both filters work at the same time. How could I stop or override the previous one without stopping current browser instance?
Code example:
proxy.addResponseFilter((response, contents, messageInfo) -> {
if (messageInfo.getOriginalUrl().contains(keyWord)) {
contents.setTextContents(newResponse);
}
});
It's not currently possible to remove a javascript filter after you've added it, unfortunately. The new REST API that is currently in development will support this, though. There's an issue open to track this: https://github.com/lightbody/browsermob-proxy/issues/326
The GWT web app I'm building has a page where users can upload CSV files. The upload code uses the Moxieapps GWT Uploader, which mostly works great.
However, I've discovered a strange scenario, where navigating away from the page and back to it adds the upload button again. So the third time I visit the page, the upload section will look like this:
And the relevant part of the generated HTML viewed in an inspector shows that both the input and the div containing the "button" get added over and over (though there is only ever one dropzone):
I've gone over my code many times to see whether I was doing something that could be causing this, but haven't found anything. You don't actually manually add the button or the input; this is done automatically by the framework. The fileUploader gets initialised only once (this being GWT client code, I've debugged using the inspector as well as logging statements to the console to confirm this):
fileUploader.setButtonDisabled(true).setFileTypes("*.csv")
.setUploadURL(getBaseUrl() + "/fileUpload.upload")
.setButtonText("<span class=\"buttonText\">Select CSV file to upload</span>")
.setFileSizeLimit(FILE_SIZE_LIMIT)
.setButtonCursor(CustomUploader.Cursor.HAND)
.setButtonAction(CustomUploader.ButtonAction.SELECT_FILE)
.setUploadProgressHandler(new UploadProgressHandler() {...})
.setUploadSuccessHandler(...)
// etc. with other handlers
The method setButtonText() is called from a couple of other places, and the text changes as it should, but only on the last button (if there are several). Otherwise, there's nothing in my code that could possibly be adding the button as far as I can tell.
Has anyone else encountered this issue? Is there some property I need to set to prevent this? Could it be a bug in the moxieapps code?
After writing out my question, and adding "Could it be a bug in the moxieapps code?" at the end, I followed up on that suspicion, and it turns out that it is indeed a bug in the org.moxieapps.gwt.uploader.client.Uploader class.
The input and the "select file" button are added in the onLoad() method of that class without a check whether they may have been added already.
It looks like there hasn't been any active development on this framework for some time, so I thought it was time for a custom override version. I've tested this and it works:
package yourpackagename.client.override;
import java.util.Iterator;
import org.moxieapps.gwt.uploader.client.Uploader;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.WidgetCollection;
/**
* The sole reason this class exists is to fix a bug in the moxieapps uploader
* (org.moxieapps.gwt.uploader-1.1.0.jar) where it adds a new upload input and
* button each time its <code>onLoad()</code> method is called, i.e. every time
* you navigate away from the page and then back to it.
*/
public class CustomUploader extends Uploader {
#Override
protected void onLoad() {
boolean hasFileUploadAlready = false;
WidgetCollection children = getChildren();
for (Iterator<Widget> iterator = children.iterator(); iterator.hasNext();) {
Widget eachWidget = iterator.next();
if (eachWidget instanceof FileUpload) {
hasFileUploadAlready = true;
}
}
// Only call the super method if there isn't already a file upload input and button
if (!hasFileUploadAlready) {
super.onLoad();
}
}
}
Instead of referencing the org.moxieapps.gwt.uploader.client.Uploader, I've changed the references to point to my custom uploader class, which will now check for an existing FileUpload child widget, and simply skip the original onLoad() code if it finds such a widget.
Might be a bit of a crowbar approach, but it works (and in my case, changing the maven-managed JAR file is not very practical). Hopefully, this will be useful to anyone else coming across this problem.
I want to know which file (or even project is enough) is opened in eclipse editor? I know we can do this once we get IEditorPart from doSetInput method,
IFile file = ((IFileEditorInput) iEditorPart).getFile();
But I want the name of file without using IEditorPart, how can I do the same?
Checking which is the selected file in project explorer is not of much help because, user can select multiple files at once and open all simultaneously and I did not way to distinguish which file opened at what time.
Adding more info:
I have an editor specified for a particular type of file, now every time it opens, during intializing editor I have some operation to do based on project properties.
While initializing editor, I need the file handle (of the one which user opened/double clicked) or the corresponding project handle.
I have my editor something this way:
public class MyEditor extends TextEditor{
#Override
protected void initializeEditor() {
setSourceViewerConfiguration(new MySourceViewerConfiguration(
CDTUITools.getColorManager(), store,
"MyPartitions", this));
}
//other required methods
#Override
protected void doSetInput(IEditorInput input) throws CoreException {
if(input instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput) input).getFile();
}
}
}
as I have done in the doSetInput() method , I want the file handle(even project handle is sufficient). But the problem is in initializeEditor() function there is no reference to editorInput, hence I am unable to get the file handle.
In the source viewer configuration file, I set the code scanners and this needs some project specific information that will set the corresponding rules.
You never have the guarantee (even with IFileEditorInput) to know which files are "open" with editors.
There is even no definition of an "opened file" there are for example editors that show the contents of multiple files (like the Plug-In Manifest Editor from PDE). Other editors show only the contents of a URI (which maybe local)
Could you explain which problem you are trying to solve?
I have a news section where I can post some news.
-> Thumbnail , title and content
What I want:
The user should be able to upload an image file without leaving the page
-> progress bar
Send the file as a post request to my server.
Then I can get the image file from the post request, then I can resize/rename the image and upload it to amazon s3.
If I have to use a javascript library, I would prefere to use jquery.
This should looks something like this:
If I submit the news, I want to save the image path in my database. Now I would need a way to get the image name from my post method.
I've found some uploading solutions, but I have problems to understand how they are working.
http://blueimp.github.com/jQuery-File-Upload/
http://www.uploadify.com/
I only know get/post to retrieve information but they integrate somehow php files in the form.
for example:
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php'
// Put your options here
});
});
I am lacking information to do this on my own. What would you recommend me?
Ps: I am using Java with Play2
Uploadify is definitely the way to go.
All the steps for implementation are to be found here : http://www.uploadify.com/documentation/uploadify/implementing-uploadify/
You need to configure the path where your uploads go in the uploadify.php script.
As for amazon S3 here is an implementation : http://code.google.com/p/uploadify-amazon-s3/
I think onUploadSuccess method better fits than onSelect : http://www.uploadify.com/documentation/uploadify/onuploadsuccess/
You can do something like this from the documentation :
$(function() {
$("#file_upload").uploadify({
'swf' : '/uploadify/uploadify.swf',
'uploader' : '/uploadify/uploadify.php',
'onSelect' : function(file) {
alert('The file ' + file.name + ' was added to the queue.');
}
});
});
Where you can get the flename once it has been selected.
What you're asking for is a LOT really. But to get you started, have a look at this page (uses JQuery):
http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/
The above link is a nice upload utility that you can use for drag-and-drop pretty easily, but it can be used by manually selecting files as well. Well documented.
As for resizing, I've used this with great success (PHP): simpleImage
simpleImage is REALLY easy to use and plug into your website.
I am trying to render and export FusionCharts completely on the server. I am aware of solutions such as FCimg and FusionCharts .NET Solution. I have also implemented a Java solution that uses the Process class to run wkhtmltoimage.
However, I am trying to find a pure Java solution of doing this. I have an html file that includes FusionCharts JS Libraries and code to generate the fusion chart. I found JxBrowser that properly renders the chart but it requires X-Server for it to work on Linux. I also have tried Cobra/Lobo Browser but it does not fully support JavaScript. Are there any other ways to render and export fusion charts on the server or atleast render an html file that includes JavaScript completely in Java (and that does not require xserver)?
Thanks in advance for all the help!
Update: Solution that does not require xserver: WebRenderer. The Swing Edition is the only edition that supports HTML5 as of July 9th, 2012. You can use the swing edition to capture the image without a GUI.
I found a way that uses Eclipse's SWT Browser. However this cannot be run in an headless mode. You will have to use xserver to implement this. See this question.
Since this requires xserver and cannot be run in an headless mode, I would suggest using JxBrowser. It is a lot simpler and all you need is to generate an html file with all the fusion charts scripts. See #1, #2, #3
You have to create a template.html file that contains the header
(<html><head>), jquery.min.js, FusionCharts.js,
FusionCharts.HC.js, FusionCharts.HC.Charts.js. Make sure each of
these scripts are in their own script tags (<script type="text/javascript"> [js code] </script>)
Now add another JavaScript function with its own script tags containing the steps to render the chart. For example:
function load() { FusionCharts.setCurrentRenderer('javascript'); var chart = new FusionCharts("swf", 'chart0', "width", "height", "0", "1"); chart.setXMLData("XML DATA HERE"); chart.render("divNAMEHere"); }
Now you need to call the load() function onload, create a div to render the chart in, and end the html file. For example:
`
test
`
Create a new class that imports the eclipse swt browser libraries. Instantiate Display, Shell, and Browser (use this as a guideline to help understand what is happening: http://www.roseindia.net/tutorials/swt/swt-browser.shtml).
Set the text of the browser (browser.setText("htmlcode")) to the html code from template.html. The best way to do this would be to read the file using BufferedReader.
Lastly, the image takes some time to render. Now there is probably a better way to do this but if you want to just get it working, I set up a count and it captures the image after a certain number. This is what you need to add to the end:
int i = 0;
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
i++;
// System.out.println(i);
if(i==100)
{
GC source = new GC (shell);
Image image = new Image(display, browser.getClientArea());
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG);
}
}
}