181 lines
6.0 KiB
Java
181 lines
6.0 KiB
Java
package org.gcube.portlets.user.reportgenerator.client.dialog;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.SerializableModel;
|
|
import org.gcube.portlets.user.reportgenerator.client.ReportConstants;
|
|
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
|
import org.gcube.portlets.user.workspace.lighttree.client.Item;
|
|
import org.gcube.portlets.user.workspace.lighttree.client.ItemType;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Button;
|
|
import com.google.gwt.user.client.ui.CheckBox;
|
|
import com.google.gwt.user.client.ui.ClickListener;
|
|
import com.google.gwt.user.client.ui.DialogBox;
|
|
import com.google.gwt.user.client.ui.Grid;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.Image;
|
|
import com.google.gwt.user.client.ui.ListBox;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
/**
|
|
* <code> ImporterDialog </code> class is is the Dialog for importing template or report sections
|
|
*
|
|
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
|
* @version October 2009 (1.4)
|
|
*/
|
|
public class ImporterDialog extends DialogBox {
|
|
|
|
/**
|
|
* this layout panel
|
|
*/
|
|
private VerticalPanel dialogPanel = new VerticalPanel();
|
|
Image loading = new Image(ReportConstants.LOADING_BAR);
|
|
|
|
VerticalPanel toReplace = new VerticalPanel();
|
|
SerializableModel toimportFrom = null;
|
|
ListBox listbox = new ListBox();
|
|
|
|
ListBox listboxCurr = new ListBox();
|
|
CheckBox lastSection = new CheckBox();
|
|
|
|
Presenter presenter;
|
|
|
|
/**
|
|
*
|
|
* @param item the item to import
|
|
* @param presenter the c
|
|
*/
|
|
public ImporterDialog(Item item, final Presenter presenter) {
|
|
this.presenter = presenter;
|
|
|
|
dialogPanel.setSpacing(4);
|
|
setText("Import from Template or Report");
|
|
toReplace.setWidth("100%");
|
|
|
|
HTML templateNameLabel = new HTML("Importing Template, please hold ...");
|
|
toReplace.add(templateNameLabel);
|
|
toReplace.add(loading);
|
|
|
|
|
|
HorizontalPanel buttonsPanel = new HorizontalPanel();
|
|
HorizontalPanel buttonsContainer = new HorizontalPanel();
|
|
|
|
// Add a cancel button at the bottom of the dialog
|
|
Button cancelButton = new Button("Close",new ClickListener() {
|
|
public void onClick(Widget sender) { hide(); }
|
|
});
|
|
|
|
Button applyButton = new Button("Import",new ClickListener() {
|
|
public void onClick(Widget sender) {
|
|
boolean result = false;
|
|
if (lastSection.isChecked())
|
|
result = Window.confirm("You are about to import section " + (listbox.getSelectedIndex()+1) + " as last section in the current document");
|
|
else
|
|
result = Window.confirm("You are about to import section " + (listbox.getSelectedIndex()+1) + " before section " + (listboxCurr.getSelectedIndex()+1) + " of the current document");
|
|
|
|
if (result)
|
|
presenter.importSection(toimportFrom, listbox.getSelectedIndex()+1, listboxCurr.getSelectedIndex()+1, lastSection.isChecked());
|
|
hide();
|
|
}
|
|
});
|
|
|
|
buttonsPanel.setWidth("100%");
|
|
buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
|
|
buttonsContainer.setSpacing(10);
|
|
buttonsContainer.add(applyButton);
|
|
buttonsContainer.add(cancelButton);
|
|
buttonsPanel.add(buttonsContainer);
|
|
|
|
dialogPanel.add(toReplace);
|
|
|
|
|
|
dialogPanel.add(buttonsPanel);
|
|
dialogPanel.setPixelSize(350, 275);
|
|
setWidget(dialogPanel);
|
|
|
|
|
|
AsyncCallback<SerializableModel> callback = new AsyncCallback<SerializableModel>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
Window.alert("Could not Import template, please try again later: " + caught.getMessage());
|
|
}
|
|
public void onSuccess(SerializableModel toLoad) {
|
|
importFinished(toLoad);
|
|
}
|
|
};
|
|
|
|
//then is not deployed mode
|
|
if (item == null) {
|
|
presenter.getModel().getModelService().readModel("", "", true, true, callback);
|
|
}
|
|
else {
|
|
boolean isTemplate = (item.getType() == ItemType.REPORT_TEMPLATE) ? true : false;
|
|
//will asyncrously return a SerializableModel instance read from disk
|
|
presenter.getModel().getModelService().readModel(item.getName(), item.getId(), isTemplate, true, callback);
|
|
}
|
|
}
|
|
|
|
|
|
private void importFinished(SerializableModel toLoad) {
|
|
HTML label = new HTML("Importing Complete...");
|
|
|
|
Grid grid = new Grid(4, 2);
|
|
grid.setWidget(0, 0, new HTML("<b>Name: </b>"));
|
|
grid.setWidget(0, 1, new HTML(toLoad.getTemplateName()));
|
|
grid.setWidget(1, 0, new HTML("<b>Author: </b>"));
|
|
grid.setWidget(1, 1, new HTML(toLoad.getAuthor()));
|
|
grid.setWidget(2, 0, new HTML("<b>Last Edit: </b>"));
|
|
grid.setWidget(2, 1, new HTML(""+toLoad.getLastEdit()));
|
|
grid.setWidget(3, 0, new HTML("<b>Total Sections: </b>"));
|
|
grid.setWidget(3, 1, new HTML(""+toLoad.getTotalPages()));
|
|
|
|
toReplace.clear();
|
|
toReplace.add(label);
|
|
toReplace.add(grid);
|
|
toReplace.add(new HTML("<hr color=\"#DDDDDD\" height=\"1px\" width=\"100%\" />"));
|
|
|
|
|
|
for (int i = 1; i <= toLoad.getTotalPages(); i++) {
|
|
listbox.addItem("Section " + i, ""+(i-1));
|
|
}
|
|
Grid grid2 = new Grid(1, 2);
|
|
grid2.setWidget(0, 0, new HTML("<b>Choose the section to import: </b> "));
|
|
grid2.setWidget(0, 1, listbox);
|
|
grid2.setCellPadding(5);
|
|
|
|
|
|
for (int i = 1; i <= presenter.getModel().getTotalPages(); i++) {
|
|
listboxCurr.addItem("Section " + i, ""+(i-1));
|
|
}
|
|
|
|
|
|
lastSection.addClickListener(new ClickListener() {
|
|
|
|
public void onClick(Widget sender) {
|
|
CheckBox cb = (CheckBox) sender;
|
|
listboxCurr.setEnabled(! cb.isChecked());
|
|
}
|
|
|
|
});
|
|
|
|
Grid grid3 = new Grid(2, 2);
|
|
grid3.setWidget(0, 0, new HTML("<b>Import Section before: </b> "));
|
|
grid3.setWidget(0, 1, listboxCurr);
|
|
grid3.setWidget(1, 0, new HTML("<b>As last section: </b> "));
|
|
grid3.setWidget(1, 1, lastSection);
|
|
grid3.setCellPadding(5);
|
|
|
|
toReplace.add(grid2);
|
|
toReplace.add(new HTML("<hr color=\"#DDDDDD\" height=\"1px\" width=\"100%\" />"));
|
|
toReplace.add(grid3);
|
|
toimportFrom = toLoad;
|
|
|
|
}
|
|
}
|
|
|
|
|