256: Workspace explorer

Task-Url: https://support.d4science.org/issues/256

Refactor
Updated Explorer

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@115741 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-01 09:15:53 +00:00
parent 3f81a37a43
commit f5933696b7
2 changed files with 92 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.load;
package org.gcube.portlets.widgets.wsexplorer.client.select;
import java.util.ArrayList;
import java.util.List;
@ -14,12 +14,15 @@ import org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplor
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.ModalFooter;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.event.HideEvent;
import com.github.gwtbootstrap.client.ui.event.HideHandler;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@ -30,17 +33,18 @@ import com.google.gwt.event.dom.client.ClickHandler;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 30, 2015
*/
public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceExplorerNotificationListener{
public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpaceExplorerNotificationListener{
public static final String SELECT = "Select";
public static final String MAX_HEIGHT_DIALOG = "500px";
public static final int WIDHT_DIALOG = 720;
private Button selectButton;
private WorkspaceExplorerLoadDialog INSTANCE = this;
private WorkspaceExplorerSelectDialog INSTANCE = this;
private boolean isSelect = false;
private String captionTxt;
private ModalFooter footer = new ModalFooter();
private Alert alertConfirm;
private WorkspaceExplorerController controller = new WorkspaceExplorerController();
private List<WorskpaceExplorerNotificationListener> listeners = new ArrayList<WorskpaceExplorerNotificationListener>();
@ -51,7 +55,7 @@ public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceEx
* @param captionTxt the caption txt
* You can implement {@link WorskpaceExplorerNotificationListener} to receive events
*/
public WorkspaceExplorerLoadDialog(String captionTxt) {
public WorkspaceExplorerSelectDialog(String captionTxt) {
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initDialog(captionTxt);
}
@ -62,7 +66,7 @@ public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceEx
* @param captionTxt the caption txt
* @param showOnlyFolders the show only folders
*/
public WorkspaceExplorerLoadDialog(String captionTxt, boolean showOnlyFolders) {
public WorkspaceExplorerSelectDialog(String captionTxt, boolean showOnlyFolders) {
if(showOnlyFolders){
ItemType[] itemsType = new ItemType[2];
@ -85,7 +89,7 @@ public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceEx
*
* You can implement {@link WorskpaceExplorerNotificationListener} to receive events
*/
public WorkspaceExplorerLoadDialog(String captionTxt, List<ItemType> selectableTypes, List<ItemType> showableTypes) {
public WorkspaceExplorerSelectDialog(String captionTxt, List<ItemType> selectableTypes, List<ItemType> showableTypes) {
if(selectableTypes!=null){
ItemType[] itemsType = new ItemType[selectableTypes.size()];
itemsType = selectableTypes.toArray(itemsType);
@ -139,13 +143,66 @@ public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceEx
isSelect = true;
INSTANCE.hide();
notifySelectedItem(item);
}else if(!controller.getWsExplorer().itemIsSelectable()){ //IGNORING ITEMS NOT SELECTABLE, USING BREADCRUMBS
Item itemB = controller.getBreadcrumbs().getLastParent();
if(itemB!=null){
setAlertConfirm("Selecting \""+itemB.getName()+"\", confirm?", true, itemB);
}
}
}
});
setAlertConfirm("", false, null);
footer.add(selectButton);
add(footer);
}
/**
* Sets the alert confirm.
*
* @param html the html
* @param bool the bool
*/
private void setAlertConfirm(String html, boolean show, final Item item){
try{
footer.remove(alertConfirm);
}catch(Exception e){
//silent
}
alertConfirm = new Alert();
alertConfirm.setText(html);
alertConfirm.setVisible(show);
alertConfirm.setClose(true);
alertConfirm.setType(AlertType.INFO);
Button yes = new Button("Yes");
yes.setType(ButtonType.LINK);
yes.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if(item!=null){
isSelect = true;
INSTANCE.hide();
notifySelectedItem(item);
}
}
});
Button no = new Button("No");
no.setType(ButtonType.LINK);
no.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
alertConfirm.close();
}
});
alertConfirm.add(yes);
alertConfirm.add(no);
footer.insert(alertConfirm,0);
}
/**
* Notify selected item.
*

View File

@ -69,6 +69,12 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Sets the alert.
*
* @param html the html
* @param type the type
*/
public void setAlert(String html, AlertType type){
explorerPanel.clear();
alert.setHTML(html);
@ -238,6 +244,23 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Item is selectable.
*
* @return true, if successful
*/
public boolean itemIsSelectable(){
Item item = itTables.getSelectedItem();
if (item!=null){
boolean selectable = selectableTypes.contains(item.getType());
return (selectable)?true:false;
}
return false;
}
/**
* Gets the selectable types.
*
* @return the selectableTypes
*/
@Override
@ -246,6 +269,8 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Sets the selectable types.
*
* @param selectableTypes the selectableTypes to set
*/
@Override
@ -255,6 +280,8 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Gets the showable types.
*
* @return the showableTypes
*/
@Override
@ -263,6 +290,8 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Sets the showable types.
*
* @param showableTypes the showableTypes to set
*/
@Override