2015-07-28 16:37:00 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.wsexplorer.client.select;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerController;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadRootEvent;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.HasWorskpaceExplorerSelectNotificationListener;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
|
|
|
|
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.ModalFooter;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class WorkspaceExplorerSelectPanel.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Jul 28, 2015
|
|
|
|
*/
|
|
|
|
public class WorkspaceExplorerSelectPanel extends ScrollPanel implements HasWorskpaceExplorerSelectNotificationListener{
|
|
|
|
|
|
|
|
private Button selectButton;
|
|
|
|
private WorkspaceExplorerSelectPanel INSTANCE = this;
|
|
|
|
private boolean isSelect = false;
|
|
|
|
private String captionTxt;
|
|
|
|
private ModalFooter footer = new ModalFooter();
|
|
|
|
private Alert alertConfirm;
|
|
|
|
private WorkspaceExplorerController controller = new WorkspaceExplorerController();
|
|
|
|
private List<WorskpaceExplorerSelectNotificationListener> listeners = new ArrayList<WorskpaceExplorerSelectNotificationListener>();
|
|
|
|
private VerticalPanel mainVP = new VerticalPanel();
|
|
|
|
private HorizontalPanel footerHP = new HorizontalPanel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new workspace explorer select panel.
|
|
|
|
*
|
2015-07-28 16:49:10 +02:00
|
|
|
* @param captionTxt the tool-tip of the panel
|
2015-07-28 16:37:00 +02:00
|
|
|
*/
|
|
|
|
public WorkspaceExplorerSelectPanel(String captionTxt) {
|
|
|
|
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
|
2015-07-28 16:49:10 +02:00
|
|
|
initPanel(captionTxt);
|
2015-07-28 16:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new workspace explorer select panel.
|
|
|
|
*
|
|
|
|
* @param captionTxt the caption txt
|
|
|
|
* @param showOnlyFolders the show only folders
|
|
|
|
*/
|
|
|
|
public WorkspaceExplorerSelectPanel(String captionTxt, boolean showOnlyFolders) {
|
|
|
|
|
|
|
|
if(showOnlyFolders){
|
|
|
|
ItemType[] itemsType = new ItemType[1];
|
|
|
|
itemsType[0] = ItemType.FOLDER;
|
|
|
|
setSelectableTypes(itemsType);
|
|
|
|
setShowableTypes(itemsType);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
|
2015-07-28 16:49:10 +02:00
|
|
|
initPanel(captionTxt);
|
2015-07-28 16:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new workspace explorer select panel.
|
|
|
|
*
|
|
|
|
* @param captionTxt the caption txt
|
|
|
|
* @param selectableTypes the selectable types
|
|
|
|
* @param showableTypes the showable types
|
|
|
|
*/
|
|
|
|
public WorkspaceExplorerSelectPanel(String captionTxt, List<ItemType> selectableTypes, List<ItemType> showableTypes) {
|
|
|
|
if(selectableTypes!=null){
|
|
|
|
ItemType[] itemsType = new ItemType[selectableTypes.size()];
|
|
|
|
itemsType = selectableTypes.toArray(itemsType);
|
|
|
|
setSelectableTypes(selectableTypes.toArray(itemsType));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(showableTypes!=null){
|
|
|
|
ItemType[] itemsType = new ItemType[showableTypes.size()];
|
|
|
|
itemsType = showableTypes.toArray(itemsType);
|
|
|
|
setShowableTypes(showableTypes.toArray(itemsType));
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
|
2015-07-28 16:49:10 +02:00
|
|
|
initPanel(captionTxt);
|
2015-07-28 16:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the dialog.
|
|
|
|
*
|
|
|
|
* @param captionTxt the caption txt
|
|
|
|
*/
|
2015-07-28 16:49:10 +02:00
|
|
|
private void initPanel(String captionTxt) {
|
2015-07-28 16:37:00 +02:00
|
|
|
this.captionTxt = (captionTxt==null || captionTxt.isEmpty())?WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION:captionTxt;
|
|
|
|
setTitle(this.captionTxt);
|
|
|
|
selectButton = new Button(WorkspaceExplorerConstants.SELECT);
|
|
|
|
selectButton.setType(ButtonType.PRIMARY);
|
|
|
|
setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG+"px");
|
|
|
|
|
|
|
|
add(controller.getWorkspaceExplorerPanel());
|
|
|
|
selectButton.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
isSelect = false;
|
|
|
|
Item item = controller.getWsExplorer().getItemSelected();
|
|
|
|
if(item!=null){
|
|
|
|
isSelect = true;
|
|
|
|
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);
|
|
|
|
mainVP.add(controller.getWorkspaceExplorerPanel());
|
|
|
|
mainVP.add(footer);
|
|
|
|
|
|
|
|
add(mainVP);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the alert confirm.
|
|
|
|
*
|
|
|
|
* @param html the html
|
|
|
|
* @param show the show
|
|
|
|
* @param item the item
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param selected the selected
|
|
|
|
*/
|
|
|
|
private void notifySelectedItem(Item selected){
|
|
|
|
|
|
|
|
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
|
|
|
|
worskpaceExplorerNotificationListener.onSelectedItem(selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify aborted.
|
|
|
|
*/
|
|
|
|
private void notifyAborted(){
|
|
|
|
|
|
|
|
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
|
|
|
|
worskpaceExplorerNotificationListener.onAborted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify failed.
|
|
|
|
*
|
|
|
|
* @param t the t
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void notifyFailed(Throwable t){
|
|
|
|
|
|
|
|
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
|
|
|
|
worskpaceExplorerNotificationListener.onFailed(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the caption txt.
|
|
|
|
*
|
|
|
|
* @return the captionTxt
|
|
|
|
*/
|
|
|
|
public String getCaptionTxt() {
|
|
|
|
return captionTxt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is valid hide.
|
|
|
|
*
|
|
|
|
* @return the isValidHide
|
|
|
|
*/
|
|
|
|
public boolean isValidHide() {
|
|
|
|
return isSelect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#addWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void addWorkspaceExplorerSelectNotificationListener(WorskpaceExplorerSelectNotificationListener handler) {
|
|
|
|
if(handler!=null)
|
|
|
|
listeners.add(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#removeWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void removeWorkspaceExplorerSelectNotificationListener(WorskpaceExplorerSelectNotificationListener handler) {
|
|
|
|
if(handler!=null){
|
|
|
|
if(listeners.contains(handler))
|
|
|
|
listeners.remove(handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set which items are selectable.
|
|
|
|
* @param selectableTypes the selectableTypes to set
|
|
|
|
*/
|
|
|
|
private void setSelectableTypes(ItemType ... selectableTypes) {
|
|
|
|
controller.setSelectableTypes(selectableTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selectable types.
|
|
|
|
*
|
|
|
|
* @return the selectable types
|
|
|
|
*/
|
|
|
|
public List<ItemType> getSelectableTypes() {
|
|
|
|
return controller.getSelectableTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the showable items.
|
|
|
|
* @return the showableTypes
|
|
|
|
*/
|
|
|
|
public List<ItemType> getShowableTypes() {
|
|
|
|
return controller.getShowableTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the showable items. The folders items are show as default.
|
|
|
|
* @param showableTypes the showableTypes to set
|
|
|
|
*/
|
|
|
|
private void setShowableTypes(ItemType ... showableTypes) {
|
|
|
|
controller.setShowableTypes(showableTypes);
|
|
|
|
}
|
|
|
|
}
|