finished with images
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@71088 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eaacd1d5c8
commit
0a319f9b42
|
@ -1,7 +1,6 @@
|
|||
package org.gcube.portlets.user.reportgenerator.client.Presenter;
|
||||
|
||||
import org.gcube.portlets.user.reportgenerator.client.ReportConstants;
|
||||
import org.gcube.portlets.user.reportgenerator.client.dialog.ImageUploaderDialog;
|
||||
import org.gcube.portlets.user.reportgenerator.client.dialog.ImporterDialog;
|
||||
import org.gcube.portlets.user.workspace.lighttree.client.ItemType;
|
||||
import org.gcube.portlets.user.workspace.lighttree.client.event.PopupEvent;
|
||||
|
@ -95,17 +94,6 @@ public class CommonCommands {
|
|||
};
|
||||
|
||||
|
||||
insertImage = new Command() {
|
||||
public void execute() {
|
||||
int left = presenter.getHeader().getMainLayout().getAbsoluteLeft() + 50;
|
||||
int top = presenter.getHeader().getMainLayout().getAbsoluteTop() + 25;
|
||||
ImageUploaderDialog dlg = new ImageUploaderDialog(presenter);
|
||||
dlg.setAnimationEnabled(true);
|
||||
dlg.setPopupPosition(left, top);
|
||||
dlg.show();
|
||||
}
|
||||
};
|
||||
|
||||
pickColor = new Command() {
|
||||
public void execute() {
|
||||
int left = presenter.getHeader().getMainLayout().getAbsoluteLeft() + 600;
|
||||
|
|
|
@ -1,492 +0,0 @@
|
|||
package org.gcube.portlets.user.reportgenerator.client.components;
|
||||
|
||||
import org.gcube.portlets.user.reportgenerator.client.dialog.ImageUploaderDialog;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.ChangeListener;
|
||||
import com.google.gwt.user.client.ui.ChangeListenerCollection;
|
||||
import com.google.gwt.user.client.ui.ClickListener;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FileUpload;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.FormHandler;
|
||||
import com.google.gwt.user.client.ui.FormPanel;
|
||||
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;
|
||||
import com.google.gwt.user.client.ui.FormSubmitEvent;
|
||||
import com.google.gwt.user.client.ui.HasText;
|
||||
import com.google.gwt.user.client.ui.HasWordWrap;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.SourcesChangeEvents;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
* <code> FancyFileUpload </code> class is use to upload images from client in the UI
|
||||
*
|
||||
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
||||
* @version October 2008 (0.2)
|
||||
*/
|
||||
public class FancyFileUpload extends Composite implements HasText, HasWordWrap, SourcesChangeEvents{
|
||||
|
||||
/**
|
||||
* State definitions
|
||||
*/
|
||||
public final int EMPTY_STATE = 1;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int PENDING_STATE = 2;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int UPLOADING_STATE = 3;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int UPLOADED_STATE = 4;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int DELETED_STATE = 5;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int FAILED_STATE = 6;
|
||||
|
||||
/**
|
||||
* Initial State of the widget.
|
||||
*/
|
||||
private int widgetState = EMPTY_STATE;
|
||||
|
||||
/**
|
||||
* Default delay to check an empty FileUpload widget for
|
||||
* arrival of a filename.
|
||||
*
|
||||
*/
|
||||
private int searchUpdateDelay = 500;
|
||||
|
||||
/**
|
||||
* Default delay for pending state, when delay over the form is
|
||||
submitted.
|
||||
*/
|
||||
private int pendingUpdateDelay = 5000;
|
||||
|
||||
/**
|
||||
* the panel where this widget is in
|
||||
*/
|
||||
private ImageUploaderDialog theOwner;
|
||||
|
||||
|
||||
/**
|
||||
* OK message expected from file upload servlet to indicate successful
|
||||
upload.
|
||||
*/
|
||||
//private String retursOKMessage = "<pre>OK</pre>";
|
||||
|
||||
private FormPanel uploadForm = new FormPanel();
|
||||
private VerticalPanel mainPanel = new VerticalPanel();
|
||||
|
||||
/**
|
||||
* Internal timer for checking fileupload text for a value.
|
||||
*/
|
||||
private Timer t;
|
||||
|
||||
/**
|
||||
* Internal timer for checking if pending delay is over.
|
||||
*/
|
||||
private Timer p;
|
||||
|
||||
/**
|
||||
* Widget representing file to be uploaded.
|
||||
*/
|
||||
private UploadDisplay uploadItem;
|
||||
|
||||
/**
|
||||
* FileName to be uploaded
|
||||
*/
|
||||
String fileName = "";
|
||||
|
||||
|
||||
/**
|
||||
* Class used for the display of filename to be uploaded,
|
||||
* and handling the update of the display states.
|
||||
*
|
||||
*
|
||||
*/
|
||||
protected class UploadDisplay extends Composite{
|
||||
|
||||
/**
|
||||
* FileUpload Widget
|
||||
*/
|
||||
FileUpload uploadFileWidget = new FileUpload();
|
||||
|
||||
/**
|
||||
* Label to display after file widget is filled with a filename
|
||||
*/
|
||||
Label uploadFileName = new Label();
|
||||
|
||||
|
||||
/**
|
||||
* Panel to hold the widget
|
||||
*/
|
||||
FlowPanel mainPanel = new FlowPanel();
|
||||
|
||||
/**
|
||||
* Panel to hold pending, loading, loaded or failed state details.
|
||||
*/
|
||||
HorizontalPanel pendingPanel = new HorizontalPanel();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public UploadDisplay(){
|
||||
|
||||
mainPanel.add(uploadFileWidget);
|
||||
pendingPanel.add(uploadFileName);
|
||||
uploadFileName.setStyleName("HTMLObjectStyle-font");
|
||||
uploadFileName.setWordWrap(true);
|
||||
uploadFileWidget.setWidth("100%");
|
||||
|
||||
mainPanel.add(pendingPanel);
|
||||
pendingPanel.setVisible(false);
|
||||
initWidget(mainPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the widget into pending mode by altering style
|
||||
* of pending panel and displaying it. Hide the FileUpload
|
||||
* widget and finally set the state to Pending.
|
||||
*
|
||||
*/
|
||||
private void setPending(){
|
||||
uploadFileName.setText("Please wait, fetching image from your file system.. ");//uploadFileWidget.getFilename());
|
||||
uploadFileWidget.setVisible(false);
|
||||
pendingPanel.setVisible(true);
|
||||
pendingPanel.setStyleName("fancyfileupload-pending");
|
||||
widgetState = PENDING_STATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the widget into Loading mode by changing the style name
|
||||
* and updating the widget State to Uploading.
|
||||
*
|
||||
*/
|
||||
private void setLoading(){
|
||||
pendingPanel.setStyleName("fancyfileupload-loading");
|
||||
widgetState = UPLOADING_STATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the widget to Loaded mode by changing the style name
|
||||
* and updating the widget State to Loaded.
|
||||
*
|
||||
*/
|
||||
private void setLoaded(){
|
||||
pendingPanel.setStyleName("fancyfileupload-loaded");
|
||||
uploadFileName.setText("Image Successfully uploaded");
|
||||
widgetState = UPLOADED_STATE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the widget to Failed mode by changing the style name
|
||||
* and updating the widget State to Failed.
|
||||
* Additionally, hide the pending panel and display the FileUpload
|
||||
* widget.
|
||||
*
|
||||
*/
|
||||
private void setFailed(){
|
||||
widgetState = FAILED_STATE;
|
||||
uploadFileName.setText("Operation Failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the uploading of a file by changing state of display widget
|
||||
* and then calling form.submit() method.
|
||||
*
|
||||
*/
|
||||
private void uploadFiles(){
|
||||
fileName = uploadItem.uploadFileWidget.getFilename();
|
||||
|
||||
uploadItem.setLoading();
|
||||
uploadForm.submit();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put the widget into a Pending state, set the Pending delay timer
|
||||
* to call the upload file method when ran out.
|
||||
*
|
||||
*/
|
||||
private void pendingUpload(){
|
||||
// Fire an onChange event to anyone who is listening
|
||||
uploadItem.setPending();
|
||||
p = new Timer(){
|
||||
public void run() {
|
||||
uploadFiles();
|
||||
}
|
||||
};
|
||||
p.schedule(pendingUpdateDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if FileUpload Widget has a filename within it.
|
||||
* If so, cancel the timer that was set to call this method and then
|
||||
* call the pendingUpload() method.
|
||||
* If not, do nothing.
|
||||
*
|
||||
*/
|
||||
private void checkForFileName(){
|
||||
// GWT.log(uploadItem.uploadFileWidget.getFilename()+" :"+fileName,null);
|
||||
// if (!uploadItem.uploadFileWidget.getFilename().equals("")){
|
||||
// if (!uploadItem.uploadFileWidget.getFilename().equals(fileName)){
|
||||
// t.cancel();
|
||||
// pendingUpload();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets up a repeating schedule to call the
|
||||
checkforfilename
|
||||
* method to see if the FileUpload widget has any text in it.
|
||||
*
|
||||
*/
|
||||
private void startWaiting(){
|
||||
t = null;
|
||||
t = new Timer(){
|
||||
public void run() {
|
||||
checkForFileName();
|
||||
}
|
||||
};
|
||||
t.scheduleRepeating(searchUpdateDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner the caller
|
||||
* @param templateName .
|
||||
*/
|
||||
public FancyFileUpload(ImageUploaderDialog owner, String templateName){
|
||||
|
||||
this.theOwner = owner;
|
||||
// Set Form details
|
||||
// Set the action to call on submit
|
||||
|
||||
uploadForm.setAction(GWT.getModuleBaseURL() + "ImagesUploadServlet?currTemplateName=" + templateName);
|
||||
|
||||
|
||||
// Set the form encoding to multipart to indicate a file upload
|
||||
uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
|
||||
// Set the method to Post
|
||||
uploadForm.setMethod(FormPanel.METHOD_POST);
|
||||
uploadForm.setWidget(mainPanel);
|
||||
|
||||
// Create a new upload display widget
|
||||
uploadItem = new UploadDisplay();
|
||||
// Set the name of the upload file form element
|
||||
uploadItem.uploadFileWidget.setName("uploadFormElement");
|
||||
// Add the new widget to the panel.
|
||||
mainPanel.add(uploadItem);
|
||||
HorizontalPanel wrapper = new HorizontalPanel();
|
||||
wrapper.setSpacing(4);
|
||||
// Add a 'submit' button.
|
||||
wrapper.add(new Button("Submit", new ClickListener() {
|
||||
public void onClick(Widget sender) {
|
||||
String fName = uploadItem.uploadFileWidget.getFilename();
|
||||
|
||||
|
||||
int slashPosition = fName.lastIndexOf("/");
|
||||
|
||||
String fileNameToCheck = "" ;
|
||||
|
||||
if (slashPosition == -1) //it is windows
|
||||
slashPosition = fName.lastIndexOf("\\");
|
||||
|
||||
if (slashPosition != -1)
|
||||
fileNameToCheck = fName.substring(slashPosition+1, fName.length());
|
||||
|
||||
if (fName.equals("")) {
|
||||
Window.alert("The text box must not be empty");
|
||||
}
|
||||
else if (fileNameToCheck.indexOf(" ") > -1) {
|
||||
Window.alert("File name cannot contain empty spaces");
|
||||
|
||||
}
|
||||
else {
|
||||
t.cancel();
|
||||
pendingUpload();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Add a 'close' button.
|
||||
wrapper.add(new Button("Cancel", new ClickListener() {
|
||||
public void onClick(Widget sender) {
|
||||
theOwner.hide();
|
||||
}
|
||||
}));
|
||||
mainPanel.add(wrapper);
|
||||
|
||||
// Start the waiting for a name to appear in the file upload widget.
|
||||
startWaiting();
|
||||
// Initialise the widget.
|
||||
initWidget(uploadForm);
|
||||
|
||||
// Add an event handler to the form.
|
||||
uploadForm.addFormHandler(new FormHandler() {
|
||||
public void onSubmitComplete(FormSubmitCompleteEvent event) {
|
||||
// Fire an onChange Event
|
||||
fireChangeEvent();
|
||||
// Cancel all timers to be absolutely sure nothing is going on.
|
||||
t.cancel();
|
||||
p.cancel();
|
||||
// Ensure that the form encoding is set correctly.
|
||||
uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
|
||||
// Check the result to see if an OK message is returned from the server.
|
||||
|
||||
if(event.getResults().toString().contains("OK") || event.getResults().toString().startsWith("OK")) {
|
||||
uploadItem.setLoaded();
|
||||
String fName = uploadItem.uploadFileWidget.getFilename();
|
||||
|
||||
String nameToPass = "";
|
||||
if (fName.lastIndexOf("/") == -1) //windows
|
||||
nameToPass = fName.substring(fName.lastIndexOf("\\")+1);
|
||||
else
|
||||
nameToPass = fName.substring(fName.lastIndexOf("/")+1);
|
||||
|
||||
theOwner.insertImage(nameToPass);
|
||||
theOwner.hide();
|
||||
|
||||
} else {
|
||||
// If no, set the widget to failed state.
|
||||
uploadItem.setFailed();
|
||||
Window.alert("There were some errors during File Uploading processing,Please try again");
|
||||
}
|
||||
}
|
||||
|
||||
public void onSubmit(FormSubmitEvent event) {
|
||||
//No validation in this version.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a change event to anyone listening to us.
|
||||
*
|
||||
*/
|
||||
private void fireChangeEvent(){
|
||||
if (changeListeners != null)
|
||||
changeListeners.fireChange(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text from the widget - which in reality will be retrieving any
|
||||
* value set in the Label element of the display widget.
|
||||
* @return .
|
||||
*/
|
||||
public String getText() {
|
||||
return uploadItem.uploadFileName.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cannot set the text of a File Upload Widget, so raise an exception.
|
||||
* @param text .
|
||||
*/
|
||||
public void setText(String text) {
|
||||
throw new RuntimeException("Cannot set text of a FileUpload Widget");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the status of the upload widget.
|
||||
* @return Status of upload widget.
|
||||
*
|
||||
*/
|
||||
public int getUploadState(){
|
||||
return widgetState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the delay for checking for a filename to appear in the FileUpload widget
|
||||
* Might be useful if there are performance issues.
|
||||
* @param newDelay .
|
||||
*/
|
||||
public void setCheckForFileNameDelay(int newDelay){
|
||||
searchUpdateDelay = newDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the delay value indicating how long a file will remain in
|
||||
pending mode
|
||||
* prior to the upload action taking place.
|
||||
* @param newDelay .
|
||||
*/
|
||||
public void setPendingDelay(int newDelay){
|
||||
pendingUpdateDelay = newDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the delay value set for checking a file.
|
||||
* @return .
|
||||
*/
|
||||
public int getCheckForFileNameDelay(){
|
||||
return searchUpdateDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return value set for pending delay.
|
||||
* @return .
|
||||
*/
|
||||
public int getPendingDelay(){
|
||||
return pendingUpdateDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the label in the display widget is wordwrapped or not.
|
||||
* @return .
|
||||
*/
|
||||
public boolean getWordWrap() {
|
||||
return uploadItem.uploadFileName.getWordWrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the word wrap value of the label in the display widget.
|
||||
* @param wrap .
|
||||
*/
|
||||
public void setWordWrap(boolean wrap) {
|
||||
uploadItem.uploadFileName.setWordWrap(wrap);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private ChangeListenerCollection changeListeners;
|
||||
|
||||
/**
|
||||
* Add a change listener
|
||||
* @param listener ,
|
||||
*/
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
if (changeListeners == null)
|
||||
changeListeners = new ChangeListenerCollection();
|
||||
changeListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a change listener
|
||||
* @param listener .
|
||||
*/
|
||||
public void removeChangeListener(ChangeListener listener) {
|
||||
if (changeListeners != null)
|
||||
changeListeners.remove(listener);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
package org.gcube.portlets.user.reportgenerator.client.dialog;
|
||||
|
||||
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
||||
import org.gcube.portlets.user.reportgenerator.client.components.FancyFileUpload;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.ChangeListener;
|
||||
import com.google.gwt.user.client.ui.ClickListener;
|
||||
import com.google.gwt.user.client.ui.DialogBox;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.RadioButton;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
* <code> ImageUploaderDialog </code> class is the Dialog for uploading images
|
||||
*
|
||||
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
||||
* @version October 2008 (0.2)
|
||||
*/
|
||||
public class ImageUploaderDialog extends DialogBox {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private Presenter presenter;
|
||||
|
||||
|
||||
private String currTemplateName = "";
|
||||
|
||||
private HorizontalPanel topLabel = new HorizontalPanel();
|
||||
|
||||
private EventListener listener = new EventListener();
|
||||
private RadioButton local = new RadioButton("");
|
||||
private RadioButton web = new RadioButton("");
|
||||
|
||||
/**
|
||||
* the container panel
|
||||
*/
|
||||
private VerticalPanel mainLayout = new VerticalPanel();
|
||||
private VerticalPanel dialogPanel = new VerticalPanel();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates the dialog
|
||||
* @param presenter my controller
|
||||
*/
|
||||
public ImageUploaderDialog(Presenter presenter) {
|
||||
|
||||
|
||||
// Create a dialog box and set the caption text
|
||||
this.width = 400;
|
||||
this.height = 200;
|
||||
this.presenter = presenter;
|
||||
setText("Insert Image");
|
||||
|
||||
local.setHTML(" From this computer");
|
||||
topLabel.add(local);
|
||||
local.setChecked(true);
|
||||
|
||||
web.setHTML(" From the web (URL)");
|
||||
topLabel.add(web);
|
||||
web.addClickListener(listener);
|
||||
local.addClickListener(listener);
|
||||
|
||||
currTemplateName = presenter.getModel().getTemplateName();
|
||||
|
||||
|
||||
|
||||
dialogPanel.add(getFromLocalPanel());
|
||||
dialogPanel.setPixelSize(this.width, this.height);
|
||||
|
||||
mainLayout.add(topLabel);
|
||||
mainLayout.add(dialogPanel);
|
||||
setWidget(mainLayout);
|
||||
|
||||
}
|
||||
|
||||
private VerticalPanel getFromLocalPanel() {
|
||||
VerticalPanel toReturn = new VerticalPanel();
|
||||
FancyFileUpload uploader = new FancyFileUpload(this, currTemplateName);
|
||||
HTML theLabel = new HTML("<strong>Browse your computer for the image file to upload:</strong>");
|
||||
toReturn.add(theLabel);
|
||||
toReturn.add(uploader);
|
||||
toReturn.setSpacing(4);
|
||||
toReturn.setStyleName("uploadDialog");
|
||||
toReturn.setPixelSize(this.width, this.height);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private VerticalPanel getFromURLPanel() {
|
||||
VerticalPanel toReturn = new VerticalPanel();
|
||||
|
||||
toReturn.setSpacing(5);
|
||||
|
||||
HTML theLabel = new HTML("<strong>Enter image web address:</strong>");
|
||||
final TextBox urlTextbox = new TextBox();
|
||||
urlTextbox.setWidth("90%");
|
||||
|
||||
final HTML previewBox = new HTML("<div style=\"text-align:center;\"><font style=\"color: rgb(136, 136, 136);\"><br /> Image preview will be displayed here. <br><br> *Remember: Using others' images on the web without their permission may be bad manners, or worse, copyright infringement. <br><br></font></div>", true);
|
||||
previewBox.setStyleName("imagePreviewBox");
|
||||
|
||||
toReturn.add(theLabel);
|
||||
toReturn.add(urlTextbox);
|
||||
toReturn.add(previewBox);
|
||||
|
||||
urlTextbox.addChangeListener(new ChangeListener() {
|
||||
|
||||
public void onChange(Widget sender) {
|
||||
previewBox.setHTML("<img height=\"75\" width=\"120\" src=\"" + urlTextbox.getText()+ "\" >");
|
||||
previewBox.removeStyleName("imagePreviewBox");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
HorizontalPanel buttonsPanel = new HorizontalPanel();
|
||||
|
||||
|
||||
|
||||
buttonsPanel.add(new Button("Insert", new ClickListener() {
|
||||
public void onClick(Widget sender) {
|
||||
hide();
|
||||
presenter.getCurrentSelected().getExtendedFormatter().insertImage(urlTextbox.getText());
|
||||
presenter.getModel().storeInSession();
|
||||
}
|
||||
}));
|
||||
|
||||
buttonsPanel.add(new Button("Cancel", new ClickListener() {
|
||||
public void onClick(Widget sender) {
|
||||
hide();
|
||||
}
|
||||
}));
|
||||
|
||||
buttonsPanel.setSpacing(5);
|
||||
toReturn.add(buttonsPanel);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param imageName .
|
||||
*/
|
||||
public void insertImage(String imageName) {
|
||||
String imgURL = getImageURL(imageName, "CURRENT_OPEN");
|
||||
presenter.getCurrentSelected().getExtendedFormatter().insertImage(imgURL);
|
||||
presenter.getModel().storeInSession();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* use an inner EventListener class to avoid exposing event methods on the dialog class itself.
|
||||
*/
|
||||
|
||||
private class EventListener implements ClickListener {
|
||||
|
||||
public void onClick(Widget sender) {
|
||||
if (sender == web && web.isChecked()) {
|
||||
dialogPanel.clear();
|
||||
dialogPanel.add(getFromURLPanel());
|
||||
} else if (sender == local && local.isChecked()) {
|
||||
dialogPanel.clear();
|
||||
dialogPanel.add(getFromLocalPanel());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* return a URL which is lookable for on the web
|
||||
* @param imageName .
|
||||
* @param templateName .
|
||||
* @return .
|
||||
*/
|
||||
public String getImageURL(String imageName, String templateName) {
|
||||
String currentUser = presenter.getCurrentUser().getUsername();
|
||||
String currentScope = presenter.getCurrentScope();
|
||||
/**
|
||||
* Images will be stored under webapps/usersArea...
|
||||
* GWT.getModuleBaseURL() returns * e.g. http://dlib28.isti.cnr.it/templatecreator/html/
|
||||
* need to get just http://dlib28.isti.cnr.it/
|
||||
*/
|
||||
//remove "/html/" and get e.g. http://dlib28.isti.cnr.it/templatecreator
|
||||
String host = GWT.getModuleBaseURL().substring(0, GWT.getModuleBaseURL().length()-6);
|
||||
|
||||
//loog for last slash
|
||||
int lastSlash = host.lastIndexOf("/");
|
||||
|
||||
//get what i need : e.g. http://dlib28.isti.cnr.it/ or host = "http://localhost:8080/";
|
||||
host = host.substring(0, lastSlash +1 );
|
||||
//host = "http://localhost:8080/";
|
||||
|
||||
String imgURL = host + "usersArea/" + currentScope + "/templates/"
|
||||
+ currentUser + "/" + "CURRENT_OPEN" + "/images/" + imageName;
|
||||
|
||||
return imgURL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,21 +165,7 @@ public class TemplateComponent {
|
|||
switch (sc.getType()) {
|
||||
case DYNA_IMAGE:
|
||||
ClientImage dp = new ClientImage(sc, presenter, sc.getWidth(), sc.getHeight());
|
||||
this.content = dp;
|
||||
|
||||
// String possibelContent = ((String) sc.getPossibleContent());
|
||||
// if (possibelContent.startsWith("http")) {
|
||||
// dp = new ClientImage(presenter, width, height,possibelContent);
|
||||
//
|
||||
// dp.showImage(new Image(possibelContent));
|
||||
// }
|
||||
// else if (possibelContent.startsWith("/"))
|
||||
// dp = new DroppingArea(presenter, width, height, "");
|
||||
// else if (sc.getPossibleContent().equals(DEFAULT_IMAGE_PATH)) {
|
||||
// dp = new DroppingArea(presenter, width, height, "");
|
||||
// } else {
|
||||
// dp = new DroppingArea(presenter, width, height, possibelContent);
|
||||
// }
|
||||
this.content = dp;
|
||||
break;
|
||||
case HEADING_1:
|
||||
case HEADING_2:
|
||||
|
|
|
@ -64,6 +64,7 @@ public class ClientImage extends Composite {
|
|||
private String currentScope;
|
||||
|
||||
private final int DEFAULT_HEIGHT = 100;
|
||||
private final int DEFAULT_WIDTH = 700;
|
||||
|
||||
private TextBox titleTB = new TextBox();
|
||||
private TextBox descTB = new TextBox();
|
||||
|
@ -92,7 +93,7 @@ public class ClientImage extends Composite {
|
|||
mainPanel.add(attributesPanel);
|
||||
|
||||
mainPanel.setWidth((TemplateModel.TEMPLATE_WIDTH-95)+"px");
|
||||
imagePanel.setSize(width+"px", DEFAULT_HEIGHT+"px");
|
||||
imagePanel.setSize(DEFAULT_WIDTH+"px", DEFAULT_HEIGHT+"px");
|
||||
attributesPanel.setWidth((TemplateModel.TEMPLATE_WIDTH-95)+"px");
|
||||
|
||||
mainPanel.setStyleName("imageWrapperPanel");
|
||||
|
@ -139,7 +140,8 @@ public class ClientImage extends Composite {
|
|||
titleTB.setText("");
|
||||
descTB.setText("");
|
||||
sourceTB.setText("");
|
||||
showImage(new Image(TemplateComponent.DEFAULT_IMAGE_NAME), 300, 100);
|
||||
showImage(new Image(TemplateComponent.DEFAULT_IMAGE_NAME), DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
imagePanel.addStyleName("imageEmptyPanel");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
|
||||
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.Metadata;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
||||
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
||||
import org.gcube.portlets.user.reportgenerator.client.model.TemplateComponent;
|
||||
|
@ -54,8 +55,12 @@ public class SequenceWidget extends Composite {
|
|||
buttonPanel.add(buttonsWrapperPanel);
|
||||
}
|
||||
//if isNew and is not locked and is of type BODY then put fields to blank
|
||||
if (isNew && (!sComp.isLocked()) && (sComp.getType() == ComponentType.BODY || sComp.getType() == ComponentType.BODY_NOT_FORMATTED) ) {
|
||||
if (isNew && (!sComp.isLocked()) &&
|
||||
(sComp.getType() == ComponentType.BODY ||
|
||||
sComp.getType() == ComponentType.BODY_NOT_FORMATTED ||
|
||||
sComp.getType() == ComponentType.DYNA_IMAGE) ) {
|
||||
sComp.setPossibleContent("");
|
||||
sComp.setMetadata(new ArrayList<Metadata>());
|
||||
}
|
||||
add(new TemplateComponent(p.getModel(), sComp, p));
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
@ -44,6 +45,7 @@ import org.gcube.portlets.d4sreporting.common.shared.BasicSection;
|
|||
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.Model;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.Table;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.TableCell;
|
||||
import org.gcube.portlets.docxgenerator.DocxGenerator;
|
||||
|
@ -163,7 +165,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
_log.info("Initializing Servlet ReportServiceImpl...");
|
||||
store = new MyDerbyStore();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the current ASLSession
|
||||
* @return .
|
||||
|
@ -176,12 +178,12 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
this.getThreadLocalRequest().getSession().setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
|
||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec");
|
||||
}
|
||||
|
||||
|
||||
if (!withinPortal)
|
||||
_log.warn("\n\n****** Starting in Development MODE ******\n\n");
|
||||
|
||||
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Retrieve the user saved template names
|
||||
|
@ -875,14 +877,25 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
public void storeTemplateInSession(Model model) {
|
||||
ASLSession d4Session = getASLSession();
|
||||
d4Session.setAttribute(CURRENT_REPORT_INSTANCE, model);
|
||||
// Vector<SerialazableSection> sections = model.getSections();
|
||||
// for (SerialazableSection section : sections) {
|
||||
// for (SerializableComponent component : section.getComponents()) {
|
||||
// if (component.getType() == ComponentType.DYNA_IMAGE) {
|
||||
// Logger.debug("\n\n****FOUND DYNA IMAGE ID In Basket: " + component.getIdInBasket());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
System.out.println("SAVED");
|
||||
|
||||
Vector<BasicSection> sections = model.getSections();
|
||||
for (BasicSection section : sections) {
|
||||
for (BasicComponent component : section.getComponents()) {
|
||||
if (component.getType() == ComponentType.DYNA_IMAGE) {
|
||||
System.out.println("****FOUND DYNA IMAGE : " + component.getPossibleContent().toString());
|
||||
}
|
||||
if (component.getType() == ComponentType.REPEAT_SEQUENCE) {
|
||||
RepeatableSequence res = (RepeatableSequence) component.getPossibleContent();
|
||||
for (BasicComponent co : res.getGroupedComponents()) {
|
||||
if (co.getType() == ComponentType.DYNA_IMAGE) {
|
||||
System.out.println("****FOUND DYNA IMAGE In Sequence: " + component.getPossibleContent().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -891,39 +904,62 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
_log.debug("model == NULL " + (model == null));
|
||||
Vector<BasicSection> sections = model.getSections();
|
||||
for (BasicSection section : sections) {
|
||||
_log.debug("\n\n****section.getComponents() == NULL " + (section.getComponents() == null));
|
||||
for (BasicComponent component : section.getComponents()) {
|
||||
if (component.getType() == ComponentType.DYNA_IMAGE) {
|
||||
_log.debug("Found DP: " + component.getPossibleContent());
|
||||
|
||||
_log.debug("ID In Basket null?: " + (component.getIdInBasket() == null));
|
||||
|
||||
if (component.getIdInBasket() != null) {
|
||||
|
||||
String imageID = component.getIdInBasket();
|
||||
String imageNameFile = getRandom(12);
|
||||
String imageNameFile = UUID.randomUUID().toString();
|
||||
|
||||
String imageTargetDIR = myUtil.getTemplatePath(model.getTemplateName(), getVreName(), getUsername()) + "images" + File.separator;
|
||||
String imageTargetDIR =
|
||||
new StringBuilder(
|
||||
myUtil.getTemplatePath(model.getTemplateName(), getVreName(), getUsername()))
|
||||
.append("images").append(File.separator).toString();
|
||||
|
||||
imageNameFile = copyImageFromBasket(imageID, imageTargetDIR, imageNameFile);
|
||||
|
||||
component.setPossibleContent(getImageURL(imageNameFile, model.getTemplateName()));
|
||||
_log.trace("NEW setPossibleContent: " + component.getPossibleContent());
|
||||
}
|
||||
}
|
||||
if (component.getType() == ComponentType.REPEAT_SEQUENCE) {
|
||||
RepeatableSequence res = (RepeatableSequence) component.getPossibleContent();
|
||||
for (BasicComponent co : res.getGroupedComponents()) {
|
||||
_log.debug("Found DP IN SEQUENCE: " + component.getPossibleContent());
|
||||
if (co.getIdInBasket() != null) {
|
||||
String imageID = co.getIdInBasket();
|
||||
String imageNameFile = UUID.randomUUID().toString();
|
||||
|
||||
String imageTargetDIR =
|
||||
new StringBuilder(
|
||||
myUtil.getTemplatePath(model.getTemplateName(), getVreName(), getUsername()))
|
||||
.append("images").append(File.separator).toString();
|
||||
imageNameFile = copyImageFromBasket(imageID, imageTargetDIR, imageNameFile);
|
||||
|
||||
co.setPossibleContent(getImageURL(imageNameFile, model.getTemplateName()));
|
||||
_log.trace("NEW setPossibleContent in SEQUENCE: " + co.getPossibleContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param imageName
|
||||
* @param templateName
|
||||
* @return
|
||||
* @param imageName the generated image name
|
||||
* @param templateName the curr template name
|
||||
* @return the url to the image
|
||||
*/
|
||||
private String getImageURL(String imageName, String templateName) {
|
||||
String toReturn = currentHost + "usersArea/" + getVreName() + "/templates/" + getUsername() + "/CURRENT_OPEN/images/" + imageName;
|
||||
_log.info("getImageURL" + toReturn);
|
||||
return toReturn;
|
||||
StringBuilder sb = new StringBuilder("/usersArea/")
|
||||
.append( getVreName())
|
||||
.append("/templates/")
|
||||
.append(getUsername())
|
||||
.append("/CURRENT_OPEN/images/")
|
||||
.append(imageName);
|
||||
_log.info("getImageURL" + sb.toString());
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1036,20 +1072,6 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
else
|
||||
return "jpg";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* generate a random uid
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
private String getRandom(int length) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String myRandom = uuid.toString();
|
||||
return myRandom.substring(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a image from fromTemplate/images/imageNameFile to toTemplate/images/imageNameFile
|
||||
* @param fromTemplate the origin template
|
||||
|
@ -1064,7 +1086,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
|
||||
String imageNewFolder = myUtil.getTemplatePath(toTemplate, getVreName(), getUsername()) + "images" + File.separator;
|
||||
|
||||
_log.debug("Copying:\n" + imageFrom + "\nto: " + imageTarget);
|
||||
_log.debug("Copying:" + imageFrom + "\nto: " + imageTarget);
|
||||
|
||||
File from = new File(imageFrom);
|
||||
File to = new File(imageTarget);
|
||||
|
@ -1075,7 +1097,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
_log.error("Error While Copying: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
_log.debug("Copying Success\n");
|
||||
_log.debug("Copying Success");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue