256: Workspace explorer

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

Enhancements on save dialogs

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@117057 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-07 16:18:14 +00:00
parent 9d026759d1
commit 047a65e6d8
7 changed files with 150 additions and 69 deletions

View File

@ -3,23 +3,23 @@ package org.gcube.portlets.widgets.wsexplorer.client;
/** /**
* The Class WorkspaceExplorerConstants. * The Class WorkspaceExplorerConstants.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 30, 2015
* Jun 30, 2015
*/ */
public class WorkspaceExplorerConstants { public class WorkspaceExplorerConstants {
public static final String SPECIAL_FOLDERS_LABEL = "MySpecialFolders"; public static final String SPECIAL_FOLDERS_LABEL = "MySpecialFolders";
public static final String VRE_FOLDERS_LABEL = "My VRE Folders"; public static final String VRE_FOLDERS_LABEL = "My VRE Folders";
public static final String WORKSPACE_EXPLORER_CAPTION = "Workspace Explorer"; public static final String WORKSPACE_EXPLORER_CAPTION = "Workspace Explorer";
public static final String HOME_LABEL = "Home"; public static final String HOME_LABEL = "Home";
public static final String WORKSPACE_MY_SPECIAL_FOLDERS_PATH = "/Workspace/MySpecialFolders";
//DIALOGS
// DIALOGS
public static final String SAVE = "Save"; public static final String SAVE = "Save";
public static final String MAX_HEIGHT_DIALOG = "500px"; public static final String MAX_HEIGHT_DIALOG = "500px";
public static final int WIDHT_DIALOG = 720; public static final int WIDHT_DIALOG = 720;
public static final String SELECT = "Select"; public static final String SELECT = "Select";
} }

View File

@ -26,21 +26,14 @@ public class WorkspaceExplorerSaveNotification {
* @see WorskpaceExplorerSaveNotificationEvent * @see WorskpaceExplorerSaveNotificationEvent
*/ */
public interface WorskpaceExplorerSaveNotificationListener { public interface WorskpaceExplorerSaveNotificationListener {
/** /**
* On parent selected. * On saving.
* *
* @param parent the parent * @param parent the parent
* @param fileName the file name
*/ */
void onParentSelected(Item parent); void onSaving(Item parent,String fileName);
/**
* On folder item name.
*
* @param itemName the item name
*/
void onFolderItemName(String itemName);
/** /**
* On aborted. * On aborted.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 B

After

Width:  |  Height:  |  Size: 245 B

View File

@ -5,6 +5,8 @@ import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerController; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerController;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadRootEvent; import org.gcube.portlets.widgets.wsexplorer.client.event.LoadRootEvent;
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.HasWorskpaceExplorerSaveNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.HasWorskpaceExplorerSaveNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener;
@ -14,11 +16,18 @@ import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal; import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.ModalFooter; import com.github.gwtbootstrap.client.ui.ModalFooter;
import com.github.gwtbootstrap.client.ui.base.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.event.HideEvent; import com.github.gwtbootstrap.client.ui.event.HideEvent;
import com.github.gwtbootstrap.client.ui.event.HideHandler; import com.github.gwtbootstrap.client.ui.event.HideHandler;
import com.github.gwtbootstrap.client.ui.event.ShownEvent;
import com.github.gwtbootstrap.client.ui.event.ShownHandler;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;
/** /**
@ -27,35 +36,38 @@ import com.google.gwt.event.dom.client.ClickHandler;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 7, 2015 * Jul 7, 2015
*/ */
public class WorkspaceExplorerSaveDialog extends Modal implements public class WorkspaceExplorerSaveDialog extends Modal implements HasWorskpaceExplorerSaveNotificationListener {
HasWorskpaceExplorerSaveNotificationListener {
private Button saveButton; private Button saveButton;
private boolean isSave = false;
private WorkspaceExplorerSaveDialog INSTANCE = this; private WorkspaceExplorerSaveDialog INSTANCE = this;
private boolean isSelect = false;
private String captionTxt; private String captionTxt;
private ModalFooter footer = new ModalFooter(); private ModalFooter footer = new ModalFooter();
private WorkspaceExplorerController controller = new WorkspaceExplorerController(); private WorkspaceExplorerController controller = new WorkspaceExplorerController();
private List<WorskpaceExplorerSaveNotificationListener> listeners = new ArrayList<WorskpaceExplorerSaveNotificationListener>(); private List<WorskpaceExplorerSaveNotificationListener> listeners = new ArrayList<WorskpaceExplorerSaveNotificationListener>();
private TextBox fileNameTextBox = new TextBox();
/** /**
* Instantiates a new workspace explorer save dialog. * Instantiates a new workspace explorer save dialog.
* *
* @param captionTxt the caption txt * @param captionTxt the caption txt
* @param fileName the file name
*/ */
public WorkspaceExplorerSaveDialog(String captionTxt) { public WorkspaceExplorerSaveDialog(String captionTxt, String fileName) {
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent()); WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initDialog(captionTxt); initDialog(captionTxt, fileName);
} }
/** /**
* Instantiates a new workspace explorer save dialog. * Instantiates a new workspace explorer save dialog.
* *
* @param captionTxt the caption txt * @param captionTxt the caption txt
* @param fileName the file name
* @param showOnlyFolders the show only folders * @param showOnlyFolders the show only folders
*/ */
public WorkspaceExplorerSaveDialog(String captionTxt, public WorkspaceExplorerSaveDialog(String captionTxt, String fileName, boolean showOnlyFolders) {
boolean showOnlyFolders) {
if (showOnlyFolders) { if (showOnlyFolders) {
ItemType[] itemsType = new ItemType[2]; ItemType[] itemsType = new ItemType[2];
@ -66,23 +78,18 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
} }
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent()); WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initDialog(captionTxt); initDialog(captionTxt, fileName);
} }
/** /**
* Instantiates a new workspace explorer save dialog. * Instantiates a new workspace explorer save dialog.
* *
* @param captionTxt the caption txt * @param captionTxt the caption txt
* @param selectableTypes the selectable types * @param fileName the file name
* @param showableTypes the showable types * @param showableTypes the showable types
*/ */
public WorkspaceExplorerSaveDialog(String captionTxt, public WorkspaceExplorerSaveDialog(String captionTxt, String fileName, List<ItemType> showableTypes) {
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) { if (showableTypes != null) {
ItemType[] itemsType = new ItemType[showableTypes.size()]; ItemType[] itemsType = new ItemType[showableTypes.size()];
@ -91,32 +98,32 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
} }
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent()); WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initDialog(captionTxt); initDialog(captionTxt, fileName);
} }
/** /**
* Inits the dialog. * Inits the dialog.
* *
* @param captionTxt * @param captionTxt the caption txt
* the caption txt * @param fileName the file name
*/ */
private void initDialog(String captionTxt) { private void initDialog(String captionTxt, String fileName) {
this.captionTxt = (captionTxt == null || captionTxt.isEmpty()) ? WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION this.captionTxt = (captionTxt == null || captionTxt.isEmpty()) ? WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION: captionTxt;
: captionTxt;
setAnimation(false); setAnimation(false);
setCloseVisible(true); setCloseVisible(true);
hide(false);
setTitle(this.captionTxt); setTitle(this.captionTxt);
saveButton = new Button(WorkspaceExplorerConstants.SAVE); saveButton = new Button(WorkspaceExplorerConstants.SAVE);
saveButton.setType(ButtonType.PRIMARY); saveButton.setType(ButtonType.PRIMARY);
setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG); setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG);
setMaxHeigth(WorkspaceExplorerConstants.MAX_HEIGHT_DIALOG); setMaxHeigth(WorkspaceExplorerConstants.MAX_HEIGHT_DIALOG);
hide(false);
addHideHandler(new HideHandler() { addHideHandler(new HideHandler() {
@Override @Override
public void onHide(HideEvent hideEvent) { public void onHide(HideEvent hideEvent) {
if (!isSelect) if (!isSave)
notifyAborted(); notifyAborted();
} }
}); });
@ -126,23 +133,107 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
isSelect = false; isSave = false;
Item item = controller.getWsExplorer().getItemSelected(); Item item = controller.getWsExplorer().getItemSelected();
if (item != null) { if (item != null && item.isFolder()) {
isSelect = true; //GO INTO FOLDER
INSTANCE.hide(); WorkspaceExplorerController.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent(item));
notifyParentSelected(item); } else {
//VALIDATING FILE NAME
String fileName = getFileName();
if(fileName==null || fileName.isEmpty()){
Window.alert("You must insert a valid file name!! It cannot be empty!!");
fileNameTextBox.setFocus(true);
return;
}
} else if (!controller.getWsExplorer().itemIsSelectable()) {
// IGNORING ITEMS NOT SELECTABLE, USING BREADCRUMBS
Item itemB = controller.getBreadcrumbs().getLastParent(); Item itemB = controller.getBreadcrumbs().getLastParent();
if (itemB != null) { if (itemB != null) {
} GWT.log(itemB.getPath());
GWT.log(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH);
boolean compare = itemB.getPath().compareTo(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)==0;
GWT.log(compare+"");
if(itemB.getPath().compareTo(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)==0){
Window.alert("Destination folder "+WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH+" is not valid!");
return;
}
INSTANCE.hide();
notifySaving(itemB, getFileName());
isSave = true;
}else
Window.alert("Parent item is null!!");
} }
} }
}); });
fileNameTextBox.addStyleName("fileNameTextBox");
fileNameTextBox.setAlignment(TextAlignment.LEFT);
setFileName(fileName);
footer.add(fileNameTextBox);
footer.add(saveButton); footer.add(saveButton);
add(footer); add(footer);
addHandlers();
}
/**
*
*/
private void addHandlers() {
WorkspaceExplorerController.eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() {
@Override
public void onClick(final ClickItemEvent clickItemEvent) {
Item item = clickItemEvent.getItem();
if(item!=null && !item.isFolder())
setFileName("New_"+item.getName());
}
});
addShownHandler(new ShownHandler() {
@Override
public void onShown(ShownEvent shownEvent) {
// fileNameTextBox.setCursorPos(fileNameTextBox.getText().length());
fileNameTextBox.selectAll();
fileNameTextBox.setFocus(true);
}
});
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand () {
public void execute () {
fileNameTextBox.selectAll();
fileNameTextBox.setFocus(true);
}
});
}
/**
* Sets the file name.
*
* @param txt the txt
* @param select the select
*/
private void setFileName(final String txt){
if(txt==null)
return;
fileNameTextBox.setValue(txt);
}
/**
* Gets the file name.
*
* @return the file name
*/
private String getFileName(){
return fileNameTextBox.getValue();
} }
/** /**
@ -150,10 +241,10 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
* *
* @param selected the selected * @param selected the selected
*/ */
private void notifyParentSelected(Item selected) { private void notifySaving(Item parent, String fileName) {
for (WorskpaceExplorerSaveNotificationListener worskpaceExplorerNotificationListener : listeners) { for (WorskpaceExplorerSaveNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onParentSelected(selected); worskpaceExplorerNotificationListener.onSaving(parent, fileName);
} }
} }
@ -196,7 +287,7 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
* @return the isValidHide * @return the isValidHide
*/ */
public boolean isValidHide() { public boolean isValidHide() {
return isSelect; return isSave;
} }
/* /*
@ -207,7 +298,7 @@ public class WorkspaceExplorerSaveDialog extends Modal implements
@Override @Override
public void show() { public void show() {
super.show(); super.show();
isSelect = false; isSave = false;
} }
/** /**

View File

@ -111,14 +111,13 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace
this.captionTxt = (captionTxt==null || captionTxt.isEmpty())?WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION:captionTxt; this.captionTxt = (captionTxt==null || captionTxt.isEmpty())?WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION:captionTxt;
setAnimation(false); setAnimation(false);
setCloseVisible(true); setCloseVisible(true);
hide(false);
setTitle(this.captionTxt); setTitle(this.captionTxt);
selectButton = new Button(WorkspaceExplorerConstants.SELECT); selectButton = new Button(WorkspaceExplorerConstants.SELECT);
selectButton.setType(ButtonType.PRIMARY); selectButton.setType(ButtonType.PRIMARY);
setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG); setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG);
setMaxHeigth(WorkspaceExplorerConstants.MAX_HEIGHT_DIALOG); setMaxHeigth(WorkspaceExplorerConstants.MAX_HEIGHT_DIALOG);
hide(false);
addHideHandler(new HideHandler() { addHideHandler(new HideHandler() {
@Override @Override

View File

@ -23,4 +23,9 @@
margin-top: 10px; margin-top: 10px;
margin-bottom: 0 !important; margin-bottom: 0 !important;
padding: 2px !important; padding: 2px !important;
}
.fileNameTextBox{
vertical-align: top !important;
margin-right: 10px;
} }

View File

@ -236,19 +236,12 @@ public class Item implements IsSerializable {
public void setSpecialFolder(boolean isSpecialFolder) { public void setSpecialFolder(boolean isSpecialFolder) {
this.isSpecialFolder = isSpecialFolder; this.isSpecialFolder = isSpecialFolder;
} }
/** /**
* Return this item path. * @return the path
*
* @return the item path.
*/ */
// Modified in date 26/06/2012 by Francesco Mangiacrapa
public String getPath() { public String getPath() {
System.out.println("getting path for " + name); return path;
if (parent == null)
return "/";
return parent.getPath() + name + "/";
} }
/** /**