Workspace resources management finixed
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@130085 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b80ffda613
commit
d287bfb2be
|
@ -16,7 +16,7 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
public void onModuleLoad() {
|
||||
|
||||
// remove comment to the below line for testing the widget
|
||||
startExample();
|
||||
//startExample();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -326,7 +326,15 @@ public class CreateDatasetForm extends Composite{
|
|||
resourcesControlGroup.setVisible(true);
|
||||
addResourcesCheckBox.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
|
||||
resourcesTable = new ResourcesTable(bean.getResources());
|
||||
|
||||
|
||||
|
||||
// if there are not resources, for now just checked it ( and hide so that the step will be skipped) TODO
|
||||
if(bean.getResources() == null || bean.getResources().isEmpty()){
|
||||
|
||||
resourcesControlGroup.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
// try to retrieve the licenses
|
||||
setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true);
|
||||
ckanServices.getLicenses(new AsyncCallback<LicensesBean>() {
|
||||
|
|
|
@ -5,12 +5,14 @@ import java.util.List;
|
|||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.CellTable;
|
||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||
import com.google.gwt.cell.client.Cell.Context;
|
||||
import com.google.gwt.cell.client.CheckboxCell;
|
||||
import com.google.gwt.cell.client.EditTextCell;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.cell.client.FieldUpdater;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NativeEvent;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
|
@ -19,10 +21,13 @@ import com.google.gwt.event.dom.client.ClickHandler;
|
|||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.cellview.client.Column;
|
||||
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
|
||||
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
|
||||
import com.google.gwt.user.cellview.client.TextColumn;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.view.client.ListDataProvider;
|
||||
import com.google.gwt.view.client.ProvidesKey;
|
||||
import com.google.gwt.view.client.Range;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +40,7 @@ public class ResourcesTable extends Composite{
|
|||
protected ListDataProvider<ResourceBeanWrapper> dataProvider = new ListDataProvider<ResourceBeanWrapper>();
|
||||
|
||||
// the table that will be displayed
|
||||
private CellTable<ResourceBeanWrapper> table = new CellTable<ResourceBeanWrapper>();
|
||||
private CellTable<ResourceBeanWrapper> table;
|
||||
|
||||
// save original list
|
||||
private List<ResourceBeanWrapper> originalResources;
|
||||
|
@ -47,6 +52,20 @@ public class ResourcesTable extends Composite{
|
|||
private static final String SELECT_ALL_LABEL = "Select All";
|
||||
private static final String DESELECT_ALL_LABEL = "Deselect All";
|
||||
|
||||
// alert block
|
||||
private AlertBlock alert = new AlertBlock();
|
||||
|
||||
/*
|
||||
* The key provider that allows us to identify ResourceBeanWrapper even if a field
|
||||
* changes. We identify ResourceBeanWrapper by their unique ID.
|
||||
*/
|
||||
private static final ProvidesKey<ResourceBeanWrapper> KEY_PROVIDER = new ProvidesKey<ResourceBeanWrapper>() {
|
||||
@Override
|
||||
public Object getKey(ResourceBeanWrapper item) {
|
||||
return item.getId();
|
||||
}
|
||||
};
|
||||
|
||||
// maintain the selection status
|
||||
private boolean selectedAll = true;
|
||||
final Button selectAllButton = new Button(DESELECT_ALL_LABEL);
|
||||
|
@ -65,6 +84,10 @@ public class ResourcesTable extends Composite{
|
|||
// save original resources
|
||||
this.originalResources = resources;
|
||||
|
||||
// create table with key provider
|
||||
table = new CellTable<ResourceBeanWrapper>(KEY_PROVIDER);
|
||||
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
|
||||
|
||||
// add data to the provider
|
||||
dataProvider.setList(resources);
|
||||
dataProvider.addDataDisplay(table);
|
||||
|
@ -89,7 +112,9 @@ public class ResourcesTable extends Composite{
|
|||
|
||||
@Override
|
||||
public void onBrowserEvent(Context context, final Element parent, final ResourceBeanWrapper res, NativeEvent event) {
|
||||
event.preventDefault();
|
||||
super.onBrowserEvent(context, parent, res, event);
|
||||
|
||||
// set the value
|
||||
res.setToBeAdded(!res.isToBeAdded());
|
||||
}
|
||||
|
||||
|
@ -114,8 +139,9 @@ public class ResourcesTable extends Composite{
|
|||
};
|
||||
table.addColumn(chosenColumn, "Select");
|
||||
|
||||
// Add a text column to show the name (and make it sortable) TODO : make it editable
|
||||
Column<ResourceBeanWrapper, String> nameColumn = new Column<ResourceBeanWrapper, String>(new EditTextCell()) {
|
||||
// Add a text column to show the name (and make it sortable)
|
||||
final EditTextCell nameCell = new EditTextCell();
|
||||
Column<ResourceBeanWrapper, String> nameColumn = new Column<ResourceBeanWrapper, String>(nameCell) {
|
||||
|
||||
@Override
|
||||
public String getValue(ResourceBeanWrapper object) {
|
||||
|
@ -125,12 +151,33 @@ public class ResourcesTable extends Composite{
|
|||
@Override
|
||||
public void onBrowserEvent(Context context, Element elem,
|
||||
ResourceBeanWrapper object, NativeEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
//super.onBrowserEvent(context, elem, object, event);
|
||||
if(!readOnly){
|
||||
super.onBrowserEvent(context, elem, object, event);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Add a field updater to be notified when the user enters a new name for the resource.
|
||||
nameColumn.setFieldUpdater(new FieldUpdater<ResourceBeanWrapper, String>() {
|
||||
@Override
|
||||
public void update(int index, ResourceBeanWrapper object, String value) {
|
||||
if(value.isEmpty() || value.length() < 5){
|
||||
nameCell.clearViewData(KEY_PROVIDER.getKey(object));
|
||||
table.redraw();
|
||||
alert("Resource's name cannot be empty at should be at least of 5 characters", AlertType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// push the changes into the object
|
||||
object.setName(value);
|
||||
|
||||
// Redraw the table with the new data.
|
||||
table.redraw();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ListHandler<ResourceBeanWrapper> nameColHandler = new ListHandler<ResourceBeanWrapper>(dataProvider.getList());
|
||||
|
||||
nameColHandler.setComparator(nameColumn, new Comparator<ResourceBeanWrapper>() {
|
||||
|
@ -165,25 +212,25 @@ public class ResourcesTable extends Composite{
|
|||
@Override
|
||||
public void onBrowserEvent(Context context, Element elem,
|
||||
ResourceBeanWrapper object, NativeEvent event) {
|
||||
event.preventDefault();
|
||||
|
||||
if(!readOnly){
|
||||
super.onBrowserEvent(context, elem, object, event);
|
||||
|
||||
GWT.log("Element is " + elem);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Context context, ResourceBeanWrapper object,
|
||||
SafeHtmlBuilder sb) {
|
||||
// TODO Auto-generated method stub
|
||||
super.render(context, object, sb);
|
||||
GWT.log("Element is " + sb);
|
||||
}
|
||||
};
|
||||
|
||||
// Add a field updater to be notified when the user enters a new description.
|
||||
descColumn.setFieldUpdater(new FieldUpdater<ResourceBeanWrapper, String>() {
|
||||
@Override
|
||||
public void update(int index, ResourceBeanWrapper object, String value) {
|
||||
|
||||
// push the changes into the object
|
||||
object.setDescription(value);
|
||||
|
||||
// Redraw the table with the new data.
|
||||
table.redraw();
|
||||
}
|
||||
});
|
||||
|
||||
table.addColumn(descColumn, "Description (Editable)");
|
||||
|
||||
// sort by columnName
|
||||
|
@ -215,10 +262,15 @@ public class ResourcesTable extends Composite{
|
|||
|
||||
// add the table
|
||||
mainPanel.add(table);
|
||||
|
||||
// add the alert block
|
||||
mainPanel.add(alert);
|
||||
alert.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all resources
|
||||
* Check/Uncheck all resources according to value
|
||||
* @param boolean value
|
||||
*/
|
||||
public void checkAllResources(boolean value){
|
||||
|
||||
|
@ -241,8 +293,33 @@ public class ResourcesTable extends Composite{
|
|||
|
||||
selectAllButton.setEnabled(false);
|
||||
readOnly = true;
|
||||
|
||||
// redraw the table
|
||||
|
||||
// redraw the table (freezing it)
|
||||
table.redraw();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Alert the user
|
||||
*/
|
||||
private void alert(String msg, AlertType alertType){
|
||||
|
||||
alert.setText(msg);
|
||||
alert.setType(alertType);
|
||||
alert.setVisible(true);
|
||||
alert.setAnimation(true);
|
||||
|
||||
// hide anyway after a while
|
||||
Timer t = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
alert.setVisible(false);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
t.schedule(5000);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue