/*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
package gr.grnet.pithos.web.client.commands;
import gr.grnet.pithos.web.client.FileUploadDialog;
-import gr.grnet.pithos.web.client.GSS;
-import gr.grnet.pithos.web.client.rest.GetCommand;
-import gr.grnet.pithos.web.client.rest.resource.FileResource;
-import gr.grnet.pithos.web.client.rest.resource.FolderResource;
-import gr.grnet.pithos.web.client.rest.resource.RestResource;
-import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.foldertree.Folder;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.DeferredCommand;
-import com.google.gwt.user.client.IncrementalCommand;
import com.google.gwt.user.client.ui.PopupPanel;
/**
public class UploadFileCommand implements Command {
private PopupPanel containerPanel;
- private List<FileResource> files;
- public UploadFileCommand(PopupPanel _containerPanel) {
+ private Pithos app;
+
+ /*
+ * The folder that is the target of the upload
+ */
+ private Folder folder;
+
+ public UploadFileCommand(Pithos _app, PopupPanel _containerPanel, Folder _folder) {
+ app = _app;
containerPanel = _containerPanel;
+ folder = _folder;
}
@Override
public void execute() {
if(containerPanel!=null)
containerPanel.hide();
- displayNewFile();
- }
-
- /**
- * Display the 'new file' dialog for uploading a new file to the system.
- */
- private void displayNewFile() {
- RestResource currentFolder = GSS.get().getTreeView().getSelection();
- if (currentFolder == null) {
- GSS.get().displayError("You have to select the parent folder first");
- return;
- }
- getFileList();
- DeferredCommand.addCommand(new IncrementalCommand() {
-
- @Override
- public boolean execute() {
- boolean res = canContinue();
- if (res) {
- FileUploadDialog dlg = GWT.create(FileUploadDialog.class);
- dlg.setFiles(files);
- dlg.center();
- return false;
- }
- return true;
- }
-
- });
+
+ FileUploadDialog dlg = app.getFileUploadDialog();
+ dlg.setFolder(folder);
+ dlg.center();
}
-
- private boolean canContinue() {
- if (files != null )
- return true;
- return false;
- }
-
- private void getFileList() {
- GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class,((RestResourceWrapper)GSS.get().getTreeView().getSelection()).getUri(), null){
-
- @Override
- public void onComplete() {
- files = getResult().getFiles();
- }
-
- @Override
- public void onError(Throwable t) {
- files = new ArrayList<FileResource>();
- }
-
- };
- DeferredCommand.addCommand(eg);
- }
-
}