use of org.pentaho.ui.xul.components.XulPromptBox in project pentaho-kettle by pentaho.
the class BrowseControllerTest method shouldNotCreateFolderOnCloseCreationDialog.
/*
* Test for {@link BrowseController#createFolder()}.
*
* Given an opened folder creation dialog with the non-empty folder name field.
*
* When this prompt dialog is just simply closed by pressing 'x' button, then folder should not be created.
*/
@Test
public void shouldNotCreateFolderOnCloseCreationDialog() throws Exception {
XulPromptBox prompt = new XulPromptBoxMock(XulDialogCallback.Status.CANCEL);
when(document.createElement(PROMPTBOX)).thenReturn(prompt);
controller.createFolder();
assertTrue(directoryMap.isEmpty());
verify(selectedFolder, never()).createFolder(anyString());
verify(directoryBinding, never()).fireSourceChanged();
verify(selectedItemsBinding, never()).fireSourceChanged();
}
use of org.pentaho.ui.xul.components.XulPromptBox in project pentaho-kettle by pentaho.
the class XulDatabaseExplorerController method preview.
public void preview(boolean askLimit) {
if (model.getTable() == null) {
return;
}
try {
PromptCallback theCallback = new PromptCallback();
@SuppressWarnings("unused") boolean execute = true;
int limit = 100;
if (askLimit) {
XulPromptBox thePromptBox = (XulPromptBox) this.document.createElement("promptbox");
thePromptBox.setModalParent(this.dbExplorerDialog.getShell());
thePromptBox.setTitle("Enter Max Rows");
thePromptBox.setMessage("Max Rows:");
thePromptBox.addDialogCallback(theCallback);
thePromptBox.open();
execute = theCallback.getLimit() != -1;
limit = theCallback.getLimit();
}
// if (execute) {
// XulPreviewRowsDialog thePreviewRowsDialog = new XulPreviewRowsDialog(this.shell, SWT.NONE,
// this.model.getDatabaseMeta(), this.model.getTable(), theCallback.getLimit());
// thePreviewRowsDialog.open();
// }
GetPreviewTableProgressDialog pd = new GetPreviewTableProgressDialog(this.dbExplorerDialog.getShell(), this.model.getDatabaseMeta(), model.getSchema(), model.getTable(), limit);
List<Object[]> rows = pd.open();
if (rows != null) {
if (rows.size() > 0) {
PreviewRowsDialog prd = new PreviewRowsDialog(this.dbExplorerDialog.getShell(), this.model.getDatabaseMeta(), SWT.None, this.model.getTable(), pd.getRowMeta(), rows);
prd.open();
} else {
MessageBox mb = new MessageBox(this.dbExplorerDialog.getShell(), SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoRows.Message"));
mb.setText(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoRows.Title"));
mb.open();
}
}
} catch (Exception e) {
LogChannel.GENERAL.logError("Error previewing rows", e);
}
}
use of org.pentaho.ui.xul.components.XulPromptBox in project pentaho-kettle by pentaho.
the class RepositoryLockController method lockContent.
public void lockContent() throws Exception {
List<UIRepositoryObject> selectedRepoObjects = browseController.getSelectedFileItems();
if (selectedRepoObjects.size() > 0 && selectedRepoObjects.get(0) instanceof UIRepositoryContent) {
final UIRepositoryContent contentToLock = (UIRepositoryContent) selectedRepoObjects.get(0);
if (((ILockObject) contentToLock).isLocked()) {
// Unlock the item
((ILockObject) contentToLock).unlock();
browseController.getSelectedItemsBinding().fireSourceChanged();
} else {
// Lock the item
XulPromptBox lockNotePrompt = promptLockMessage(document, messages, null);
lockNotePrompt.addDialogCallback(new XulDialogCallback<String>() {
public void onClose(XulComponent component, Status status, String value) {
if (!status.equals(Status.CANCEL)) {
try {
((ILockObject) contentToLock).lock(value);
browseController.getSelectedItemsBinding().fireSourceChanged();
} catch (Exception e) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
} else {
// $NON-NLS-1$
XulMenuitem lockMenuItem = (XulMenuitem) document.getElementById("lock-context-lock");
lockMenuItem.setSelected(false);
// $NON-NLS-1$
lockMenuItem = (XulMenuitem) document.getElementById("file-context-lock");
lockMenuItem.setSelected(false);
}
}
public void onError(XulComponent component, Throwable err) {
throw new RuntimeException(err);
}
});
lockNotePrompt.open();
}
}
}
use of org.pentaho.ui.xul.components.XulPromptBox in project pentaho-kettle by pentaho.
the class BrowseController method createFolder.
public void createFolder() throws Exception {
try {
Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems();
if (directories == null || directories.size() == 0) {
return;
}
UIRepositoryDirectory selectedFolder = directories.iterator().next();
// First, ask for a name for the folder
XulPromptBox prompt = promptForName(null);
prompt.addDialogCallback(new XulDialogCallback<String>() {
public void onClose(XulComponent component, Status status, String value) {
if (status == Status.ACCEPT) {
newName = value;
} else {
newName = null;
}
}
public void onError(XulComponent component, Throwable err) {
throw new RuntimeException(err);
}
});
prompt.open();
if (newName != null) {
if (selectedFolder == null) {
selectedFolder = repositoryDirectory;
}
// Do an explicit check here to see if the folder already exists in the ui
// This is to prevent a double message being sent in case the folder does
// not exist in the ui but does exist in the repo (PDI-5202)
boolean folderExistsInUI = selectedFolder.contains(newName);
if (folderExistsInUI) {
throw new Exception(BaseMessages.getString(PKG, "BrowserController.DirAlreadyExistsInUI", newName));
}
// PDI-5202
String newNameInRepo = selectedFolder.checkDirNameExistsInRepo(newName);
if (newNameInRepo != null) {
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Warning"));
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "BrowserController.DirAlreadyExistsInRepository", newNameInRepo));
messageBox.open();
newName = newNameInRepo;
}
UIRepositoryDirectory newDir = selectedFolder.createFolder(newName);
dirMap.put(newDir.getObjectId(), newDir);
directoryBinding.fireSourceChanged();
selectedItemsBinding.fireSourceChanged();
this.folderTree.setSelectedItems(Collections.singletonList(selectedFolder));
}
newName = null;
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
confirm(BaseMessages.getString(PKG, "Dialog.Error"), e.getLocalizedMessage());
}
}
}
use of org.pentaho.ui.xul.components.XulPromptBox in project pentaho-kettle by pentaho.
the class BrowseController method renameRepositoryObject.
protected void renameRepositoryObject(final UIRepositoryObject object) throws XulException {
XulPromptBox prompt = promptForName(object);
prompt.addDialogCallback(new XulDialogCallback<String>() {
public void onClose(XulComponent component, Status status, String value) {
if (status == Status.ACCEPT) {
try {
object.setName(value);
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
throw new RuntimeException(e);
}
}
}
}
public void onError(XulComponent component, Throwable err) {
throw new RuntimeException(err);
}
});
prompt.open();
}
Aggregations