use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.
the class RestoreFileCommand method execute.
/*
* (non-Javadoc)
*
* @see com.google.gwt.user.client.Command#execute()
*/
@Override
public void execute() {
final SolutionFileActionEvent event = new SolutionFileActionEvent();
event.setAction(this.getClass().getName());
String temp = "";
if (repositoryFiles != null) {
for (RepositoryFile repoFile : repositoryFiles) {
// $NON-NLS-1$
temp += repoFile.getId() + ",";
}
}
// Add file names from js
temp = temp + fileList;
// remove trailing ","
temp = temp.substring(0, temp.length() - 1);
final String filesList = temp;
// $NON-NLS-1$
String deleteFilesURL = contextURL + "api/repo/files/restore";
RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
// $NON-NLS-1$//$NON-NLS-2$
deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
deleteFilesRequestBuilder.sendRequest(filesList, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotRestoreItem", type), false, false, true);
dialogBox.center();
event.setMessage("cannotRestore");
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(final Request request, final Response response) {
if (response.getStatusCode() == Response.SC_OK) {
new RefreshRepositoryCommand().execute(false);
event.setMessage("Success");
EventBusUtil.EVENT_BUS.fireEvent(event);
} else if (response.getStatusCode() == Response.SC_CONFLICT || response.getStatusCode() == Response.SC_NOT_ACCEPTABLE) {
final int restoreResponseStatusCode = response.getStatusCode();
final String userHomeDirUrl = GWT.getHostPageBaseURL() + "api/session/userWorkspaceDir";
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, userHomeDirUrl);
try {
// Get user home folder string
builder.sendRequest("", new RequestCallback() {
@Override
public void onResponseReceived(final Request request, final Response response) {
if (response.getStatusCode() == 200) {
// API returns /user/home_folder/workspace
String userHomeFolderPath = response.getText().replaceAll("/workspace", "");
performRestoreToHomeFolder(filesList, restoreResponseStatusCode, userHomeFolderPath, event);
}
}
@Override
public void onError(Request request, Throwable exception) {
showErrorDialogBox(event);
}
});
} catch (RequestException e) {
showErrorDialogBox(event);
}
} else {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotRestoreItem", type), false, false, true, Messages.getString("close"));
dialogBox.center();
event.setMessage("Success");
FileChooserDialog.setIsDirty(Boolean.TRUE);
setBrowseRepoDirty(Boolean.TRUE);
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
});
} catch (RequestException e) {
showErrorDialogBox(event);
}
}
use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.
the class ShareFileCommand method execute.
public void execute() {
final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
if (this.getSolutionPath() != null) {
selectedList = new ArrayList<RepositoryFile>();
sbp.getFile(this.getSolutionPath(), new SolutionFileHandler() {
@Override
public void handle(RepositoryFile repositoryFile) {
selectedList.add(repositoryFile);
performOperation();
}
});
} else {
selectedList = sbp.getFilesListPanel().getRepositoryFiles();
performOperation();
}
}
use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.
the class ImportFileCommand method performOperation.
protected void performOperation() {
if (this.getSolutionPath() != null) {
SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
sbp.getFile(this.getSolutionPath(), new SolutionFileHandler() {
@Override
public void handle(RepositoryFile repositoryFile) {
ImportFileCommand.this.repositoryFile = repositoryFile;
performOperation(true);
}
});
} else {
performOperation(true);
}
}
use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.
the class FilesListPanel method selectPreviousItem.
public void selectPreviousItem(List<FileItem> currentItems) {
if (currentItems == null || currentItems.size() < 1) {
return;
}
FileItem currentItem = currentItems.get(0);
RepositoryFile currentRepositoryFile = currentItem.getRepositoryFile();
int myIndex = -1;
for (int i = 0; i < getFileCount(); i++) {
FileItem fileItem = getFileItem(i);
if (fileItem == currentItem) {
myIndex = i;
}
}
if (myIndex > 0 && myIndex < getFileCount()) {
if (currentRepositoryFile.isHidden()) {
// $NON-NLS-1$
currentItem.setStyleName("hiddenFileLabel");
} else {
// $NON-NLS-1$
currentItem.setStyleName("fileLabel");
}
FileItem previousItem = getFileItem(myIndex - 1);
RepositoryFile previousCurrentRepositoryFile = previousItem.getRepositoryFile();
if (previousCurrentRepositoryFile.isHidden()) {
// $NON-NLS-1$
previousItem.setStyleName("hiddenFileLabelSelected");
} else {
// $NON-NLS-1$
previousItem.setStyleName("fileLabelSelected");
}
List<FileItem> fileItems = new ArrayList<FileItem>();
fileItems.add(previousItem);
setSelectedFileItems(fileItems);
previousItem.fireFileSelectionEvent();
}
}
use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.
the class RepositoryFileTreeManager method fetchRepositoryFileTree.
public void fetchRepositoryFileTree(final AsyncCallback<RepositoryFileTree> callback, Integer depth, String filter, Boolean showHidden) {
// notify listeners that we are about to talk to the server (in case there's anything they want to do
// such as busy cursor or tree loading indicators)
beforeFetchRepositoryFileTree();
RequestBuilder builder = null;
// $NON-NLS-1$
String url = GWT.getHostPageBaseURL() + "api/repo/files/:/tree?";
if (depth == null) {
depth = -1;
}
if (filter == null) {
// $NON-NLS-1$
filter = "*";
}
if (showHidden == null) {
showHidden = Boolean.FALSE;
}
url = url + "depth=" + depth + "&filter=" + filter + "&showHidden=" + showHidden + "&ts=" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
System.currentTimeMillis();
builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("Accept", "application/json");
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
RequestCallback innerCallback = new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.toString());
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_OK) {
String json = response.getText();
System.out.println(json);
final JsonToRepositoryFileTreeConverter converter = new JsonToRepositoryFileTreeConverter(response.getText());
fileTree = converter.getTree();
String deletedFilesUrl = GWT.getHostPageBaseURL() + "api/repo/files/deleted?ts=" + System.currentTimeMillis();
RequestBuilder deletedFilesRequestBuilder = new RequestBuilder(RequestBuilder.GET, deletedFilesUrl);
deletedFilesRequestBuilder.setHeader("Accept", "application/json");
deletedFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
deletedFilesRequestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
fireRepositoryFileTreeFetched();
Window.alert(exception.toString());
}
public void onResponseReceived(Request delRequest, Response delResponse) {
if (delResponse.getStatusCode() == Response.SC_OK) {
try {
trashItems = JsonToRepositoryFileTreeConverter.getTrashFiles(delResponse.getText());
} catch (Throwable t) {
// apparently this happens when you have no trash
}
fireRepositoryFileTreeFetched();
} else {
fireRepositoryFileTreeFetched();
}
}
});
} catch (Exception e) {
fireRepositoryFileTreeFetched();
}
if (callback != null) {
callback.onSuccess(fileTree);
}
} else {
fileTree = new RepositoryFileTree();
RepositoryFile errorFile = new RepositoryFile();
errorFile.setFolder(true);
errorFile.setName("!ERROR!");
fileTree.setFile(errorFile);
}
}
};
try {
builder.sendRequest(null, innerCallback);
} catch (RequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations