use of org.pentaho.mantle.client.events.SolutionFolderActionEvent in project pentaho-platform by pentaho.
the class NewFolderCommand method performOperation.
protected void performOperation(boolean feedback) {
final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
event.setAction(this.getClass().getName());
final TextBox folderNameTextBox = new TextBox();
folderNameTextBox.setTabIndex(1);
folderNameTextBox.setVisibleLength(40);
VerticalPanel vp = new VerticalPanel();
// $NON-NLS-1$
vp.add(new Label(Messages.getString("newFolderName")));
vp.add(folderNameTextBox);
final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), Messages.getString("ok"), Messages.getString("cancel"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
vp);
newFolderDialog.setFocusWidget(folderNameTextBox);
folderNameTextBox.setFocus(true);
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
newFolderDialog.hide();
}
public void okPressed() {
if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
event.setMessage(Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
return;
}
solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment(folderNameTextBox.getText());
// $NON-NLS-1$
String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId(solutionPath);
RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);
try {
createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
createDirRequestBuilder.sendRequest("", new RequestCallback() {
@Override
public void onError(Request createFolderRequest, Throwable exception) {
MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
if (createFolderResponse.getStatusCode() == 200) {
NewFolderCommand.this.callback.onHandle(solutionPath);
new RefreshRepositoryCommand().execute(false);
event.setMessage("Success");
FileChooserDialog.setIsDirty(Boolean.TRUE);
setBrowseRepoDirty(Boolean.TRUE);
EventBusUtil.EVENT_BUS.fireEvent(event);
} else {
event.setMessage(StringUtils.isEmpty(createFolderResponse.getText()) || Messages.getString(createFolderResponse.getText()) == null ? // $NON-NLS-1$
Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(), folderNameTextBox.getText()));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
});
} catch (RequestException e) {
Window.alert(e.getLocalizedMessage());
event.setMessage(e.getLocalizedMessage());
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
};
newFolderDialog.setCallback(callback);
newFolderDialog.center();
}
use of org.pentaho.mantle.client.events.SolutionFolderActionEvent in project pentaho-platform by pentaho.
the class DeleteFolderCommand method performOperation.
protected void performOperation(boolean feedback) {
final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
event.setAction(this.getClass().getName());
final String filesList = repositoryFile.getId();
final String folderName = repositoryFile.getTitle() == null ? repositoryFile.getName() : repositoryFile.getTitle();
final HTML messageTextBox = new HTML(Messages.getString("moveToTrashQuestionFolder", escapeHtmlEntities(folderName)));
final PromptDialogBox folderDeleteWarningDialogBox = new PromptDialogBox(Messages.getString("moveToTrash"), Messages.getString("yesMoveToTrash"), Messages.getString("no"), true, true);
folderDeleteWarningDialogBox.setContent(messageTextBox);
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
folderDeleteWarningDialogBox.hide();
}
public void okPressed() {
// $NON-NLS-1$
String deleteFilesURL = contextURL + "api/repo/files/delete";
RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
// $NON-NLS-1$//$NON-NLS-2$
deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
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("couldNotDeleteFolder"), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotDeleteFolder"));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == 200) {
new RefreshRepositoryCommand().execute(false);
event.setMessage("Success");
FileChooserDialog.setIsDirty(Boolean.TRUE);
setBrowseRepoDirty(Boolean.TRUE);
EventBusUtil.EVENT_BUS.fireEvent(event);
} else {
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("couldNotDeleteFolder"), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotDeleteFolder"));
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("couldNotDeleteFolder"), false, false, true);
dialogBox.center();
event.setMessage(Messages.getString("couldNotDeleteFolder"));
EventBusUtil.EVENT_BUS.fireEvent(event);
}
}
};
folderDeleteWarningDialogBox.setCallback(callback);
folderDeleteWarningDialogBox.center();
}
Aggregations