use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.
the class CopyFilesCommand method performOperation.
/*
* (non-Javadoc)
*
* @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation()
*/
@Override
protected void performOperation() {
event.setMessage("Click");
EventBusUtil.EVENT_BUS.fireEvent(event);
if (this.getSolutionPath() != null && this.getFileNames() != null && this.getFileIds() != null) {
StringTokenizer pathTk = new StringTokenizer(this.getSolutionPath(), "\n");
StringTokenizer nameTk = new StringTokenizer(this.getFileNames(), "\n");
StringTokenizer idTk = new StringTokenizer(this.getFileIds(), "\n");
// Build Arrays since we cannot pass complex objects from the js bus
for (int i = 0; i < pathTk.countTokens(); i++) {
filesToCopy.add(new SolutionBrowserFile(idTk.tokenAt(i), nameTk.tokenAt(i), pathTk.tokenAt(i)));
}
performOperation(false);
} else {
performOperation(true);
}
}
use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.
the class CutFilesCommand method performOperation.
/*
* (non-Javadoc)
*
* @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation()
*/
@Override
protected void performOperation() {
event.setMessage("Click");
EventBusUtil.EVENT_BUS.fireEvent(event);
if (this.getSolutionPath() != null && this.getFileNames() != null && this.getFileIds() != null) {
StringTokenizer pathTk = new StringTokenizer(this.getSolutionPath(), "\n");
StringTokenizer nameTk = new StringTokenizer(this.getFileNames(), "\n");
StringTokenizer idTk = new StringTokenizer(this.getFileIds(), "\n");
// Build Arrays since we cannot pass complex objects from the js bus
for (int i = 0; i < pathTk.countTokens(); i++) {
filesToCut.add(new SolutionBrowserFile(idTk.tokenAt(i), nameTk.tokenAt(i), pathTk.tokenAt(i)));
}
performOperation(false);
} else {
performOperation(true);
}
}
use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.
the class DeleteFileCommand method performOperation.
protected void performOperation(boolean feedback) {
final SolutionFileActionEvent event = new SolutionFileActionEvent();
event.setAction(this.getClass().getName());
String temp = "";
String names = "";
// Convert to a comma delimted list for rest call
for (SolutionBrowserFile file : filesToDelete) {
// $NON-NLS-1$
temp += file.getId() + ",";
// $NON-NLS-1$
names += file.getName() + ",";
}
// remove trailing ","
temp = temp.substring(0, temp.length() - 1);
names = names.substring(0, names.length() - 1);
final String filesList = temp;
if (feedback) {
final HTML messageTextBox;
if (filesToDelete.size() > 1) {
messageTextBox = new HTML(Messages.getString("moveAllToTrashQuestionFile"));
} else {
messageTextBox = new HTML(Messages.getString("moveToTrashQuestionFile", names));
}
final PromptDialogBox fileMoveToTrashWarningDialogBox = new PromptDialogBox(Messages.getString("moveToTrash"), Messages.getString("yesMoveToTrash"), Messages.getString("no"), true, true);
fileMoveToTrashWarningDialogBox.setContent(messageTextBox);
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
fileMoveToTrashWarningDialogBox.hide();
}
public void okPressed() {
doDelete(filesList, event);
}
};
fileMoveToTrashWarningDialogBox.setCallback(callback);
fileMoveToTrashWarningDialogBox.center();
} else {
doDelete(filesList, event);
}
}
use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.
the class DeleteFileCommand method doDelete.
public void doDelete(String filesList, final SolutionFileActionEvent event) {
// $NON-NLS-1$
String deleteFilesURL = contextURL + "api/repo/files/delete";
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 // $NON-NLS-1$ //$NON-NLS-2$
MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotDeleteFile"), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotDeleteFile"));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == 200) {
event.setMessage("Success");
EventBusUtil.EVENT_BUS.fireEvent(event);
new RefreshRepositoryCommand().execute(false);
FileChooserDialog.setIsDirty(Boolean.TRUE);
setBrowseRepoDirty(Boolean.TRUE);
for (SolutionBrowserFile file : filesToDelete) {
if (file.getPath() != null) {
SolutionBrowserPanel.getInstance().removeRecent(file.getPath());
SolutionBrowserPanel.getInstance().removeFavorite(file.getPath());
}
}
} else {
event.setMessage(Messages.getString("couldNotDeleteFile"));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
});
} catch (RequestException e) {
MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotDeleteFile"), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotDeleteFile"));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.
the class PasteFilesCommand method performOperation.
/*
* (non-Javadoc)
*
* @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation(boolean)
*/
@Override
protected void performOperation(boolean feedback) {
final SolutionBrowserClipboard clipBoard = SolutionBrowserClipboard.getInstance();
@SuppressWarnings("unchecked") final List<SolutionBrowserFile> clipboardFileItems = clipBoard.getClipboardItems();
if (clipboardFileItems != null && clipboardFileItems.size() > 0 && getSolutionPath() != null) {
String getChildrenUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + "/tree?depth=1" + "&showHidden=" + // $NON-NLS-1$ //$NON-NLS-2$
SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles();
RequestBuilder childrenRequestBuilder = new RequestBuilder(RequestBuilder.GET, getChildrenUrl);
try {
childrenRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
childrenRequestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request getChildrenRequest, Throwable exception) {
Window.alert(exception.getLocalizedMessage());
event.setMessage(exception.getLocalizedMessage());
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(Request getChildrenRequest, Response getChildrenResponse) {
event.setMessage("Click");
EventBusUtil.EVENT_BUS.fireEvent(event);
boolean cutSameDir = false;
if (getChildrenResponse.getStatusCode() >= 200 && getChildrenResponse.getStatusCode() < 300) {
boolean promptForOptions = false;
Document children = XMLParser.parse(getChildrenResponse.getText());
NodeList childrenNameNodes = children.getElementsByTagName(NAME_NODE_TAG);
List<String> childNames = new ArrayList<String>();
for (int i = 0; i < childrenNameNodes.getLength(); i++) {
Node childNameNode = childrenNameNodes.item(i);
childNames.add(childNameNode.getFirstChild().getNodeValue());
}
for (SolutionBrowserFile file : clipboardFileItems) {
if (file.getPath() != null) {
String pasteFileParentPath = file.getPath();
// $NON-NLS-1$
String fileNameWithExt = pasteFileParentPath.substring(pasteFileParentPath.lastIndexOf("/") + 1, pasteFileParentPath.length());
// $NON-NLS-1$
pasteFileParentPath = pasteFileParentPath.substring(0, pasteFileParentPath.lastIndexOf("/"));
if (childNames.contains(fileNameWithExt) && !getSolutionPath().equals(pasteFileParentPath)) {
promptForOptions = true;
break;
} else if (childNames.contains(fileNameWithExt) && getSolutionPath().equals(pasteFileParentPath) && SolutionBrowserClipboard.getInstance().getClipboardAction() == SolutionBrowserClipboard.ClipboardAction.CUT) {
cutSameDir = true;
break;
}
}
}
if (promptForOptions) {
final OverwritePromptDialog overwriteDialog = new OverwritePromptDialog();
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
event.setMessage("Cancel");
EventBusUtil.EVENT_BUS.fireEvent(event);
overwriteDialog.hide();
}
public void okPressed() {
performSave(clipBoard, overwriteDialog.getOverwriteMode());
}
};
overwriteDialog.setCallback(callback);
overwriteDialog.center();
} else {
if (!cutSameDir) {
performSave(clipBoard, 2);
} else {
event.setMessage("Cancel");
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
} else {
Window.alert(getChildrenResponse.getText());
}
}
});
} catch (RequestException e) {
Window.alert(e.getLocalizedMessage());
}
}
}
Aggregations