256: Workspace explorer

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

Enhancements on save panel

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@117079 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-08 10:34:54 +00:00
parent 047a65e6d8
commit bd1cb4a5aa
3 changed files with 313 additions and 6 deletions

View File

@ -22,7 +22,6 @@ import com.github.gwtbootstrap.client.ui.event.HideEvent;
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.ClickHandler;
@ -150,11 +149,7 @@ public class WorkspaceExplorerSaveDialog extends Modal implements HasWorskpaceEx
Item itemB = controller.getBreadcrumbs().getLastParent();
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){
if(itemB.getPath().equals(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)){
Window.alert("Destination folder "+WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH+" is not valid!");
return;
}

View File

@ -0,0 +1,302 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.save;
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.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.notification.WorkspaceExplorerSaveNotification.HasWorskpaceExplorerSaveNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.base.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* The Class WorkspaceExplorerSavePanel.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 7, 2015
*/
public class WorkspaceExplorerSavePanel extends ScrollPanel implements HasWorskpaceExplorerSaveNotificationListener {
private Button saveButton;
@SuppressWarnings("unused")
private boolean isSave = false;
private WorkspaceExplorerSavePanel INSTANCE = this;
private WorkspaceExplorerController controller = new WorkspaceExplorerController();
private List<WorskpaceExplorerSaveNotificationListener> listeners = new ArrayList<WorskpaceExplorerSaveNotificationListener>();
private TextBox fileNameTextBox = new TextBox();
private VerticalPanel mainVP = new VerticalPanel();
private HorizontalPanel footerHP = new HorizontalPanel();
/**
* Instantiates a new workspace explorer save panel.
*
* @param fileName the file name
*/
public WorkspaceExplorerSavePanel(String fileName) {
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initPanel(fileName);
}
/**
* Instantiates a new workspace explorer save panel.
*
* @param fileName the file name
* @param showOnlyFolders the show only folders
*/
public WorkspaceExplorerSavePanel(String fileName, boolean showOnlyFolders) {
if (showOnlyFolders) {
ItemType[] itemsType = new ItemType[2];
itemsType[0] = ItemType.ROOT;
itemsType[1] = ItemType.FOLDER;
setSelectableTypes(itemsType);
setShowableTypes(itemsType);
}
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initPanel(fileName);
}
/**
* Instantiates a new workspace explorer save panel.
*
* @param fileName the file name
* @param showableTypes the showable types
*/
public WorkspaceExplorerSavePanel(String fileName, List<ItemType> showableTypes) {
if (showableTypes != null) {
ItemType[] itemsType = new ItemType[showableTypes.size()];
itemsType = showableTypes.toArray(itemsType);
setShowableTypes(showableTypes.toArray(itemsType));
}
WorkspaceExplorerController.eventBus.fireEvent(new LoadRootEvent());
initPanel(fileName);
}
/**
* Inits the dialog.
*
* @param fileName the file name
*/
private void initPanel(String fileName) {
saveButton = new Button(WorkspaceExplorerConstants.SAVE);
saveButton.setType(ButtonType.PRIMARY);
setWidth(WorkspaceExplorerConstants.WIDHT_DIALOG+"px");
addStyleName("savePanel");
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
isSave = false;
Item item = controller.getWsExplorer().getItemSelected();
if (item != null && item.isFolder()) {
//GO INTO FOLDER
WorkspaceExplorerController.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent(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;
}
Item itemB = controller.getBreadcrumbs().getLastParent();
if (itemB != null) {
if(itemB.getPath().equals(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)){
Window.alert("Destination folder "+WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH+" is not valid!");
return;
}
notifySaving(itemB, getFileName());
isSave = true;
}else
Window.alert("Parent item is null!!");
}
}
});
fileNameTextBox.setAlignment(TextAlignment.LEFT);
fileNameTextBox.getElement().getStyle().setMarginRight(10.0, Unit.PX);
setFileName(fileName);
footerHP.add(fileNameTextBox);
footerHP.add(saveButton);
footerHP.addStyleName("footerHP");
mainVP.add(controller.getWorkspaceExplorerPanel());
mainVP.add(footerHP);
add(mainVP);
addHandlers();
}
/**
* Adds the handlers.
*/
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());
}
});
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand () {
public void execute () {
fileNameTextBox.selectAll();
fileNameTextBox.setFocus(true);
}
});
}
/**
* Sets the file name.
*
* @param txt the txt
*/
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();
}
/**
* Notify parent selected.
*
* @param parent the parent
* @param fileName the file name
*/
private void notifySaving(Item parent, String fileName) {
for (WorskpaceExplorerSaveNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onSaving(parent, fileName);
}
}
/**
* Notify aborted.
*/
private void notifyAborted() {
for (WorskpaceExplorerSaveNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onAborted();
}
}
/**
* Notify failed.
*
* @param t
* the t
*/
@SuppressWarnings("unused")
private void notifyFailed(Throwable t) {
for (WorskpaceExplorerSaveNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onFailed(t);
}
}
/**
* 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);
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerSaveNotification.HasWorskpaceExplorerSaveNotificationListener#addWorkspaceExplorerSaveNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener)
*/
@Override
public void addWorkspaceExplorerSaveNotificationListener(WorskpaceExplorerSaveNotificationListener handler) {
if(handler!=null)
listeners.add(handler);
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerSaveNotification.HasWorskpaceExplorerSaveNotificationListener#removeWorkspaceExplorerSaveNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener)
*/
@Override
public void removeWorkspaceExplorerSaveNotificationListener(WorskpaceExplorerSaveNotificationListener handler) {
if(handler!=null){
if(listeners.contains(handler))
listeners.remove(handler);
}
}
}

View File

@ -28,4 +28,14 @@
.fileNameTextBox{
vertical-align: top !important;
margin-right: 10px;
}
.footerHP{
margin-top: 20px !important;
float: right;
}
.savePanel{
border: 1px solid;
padding-left: 15px;
}