use of org.pentaho.di.ui.core.database.dialog.DatabaseDialog in project pentaho-kettle by pentaho.
the class BaseStepDialog method showDbDialogUnlessCancelledOrValid.
@VisibleForTesting
String showDbDialogUnlessCancelledOrValid(DatabaseMeta changing, DatabaseMeta origin) {
changing.shareVariablesWith(transMeta);
DatabaseDialog cid = getDatabaseDialog(shell);
cid.setDatabaseMeta(changing);
cid.setModalDialog(true);
String name = null;
boolean repeat = true;
while (repeat) {
name = cid.open();
if (name == null) {
// Cancel was pressed
repeat = false;
} else {
name = name.trim();
DatabaseMeta same = transMeta.findDatabase(name);
if (same == null || same == origin) {
// OK was pressed and input is valid
repeat = false;
} else {
showDbExistsDialog(changing);
}
}
}
return name;
}
use of org.pentaho.di.ui.core.database.dialog.DatabaseDialog in project pentaho-kettle by pentaho.
the class JobEntryDialog_ConnectionLine_Test method test_showDbDialogUnlessCancelledOrValid_ShownOnce.
private void test_showDbDialogUnlessCancelledOrValid_ShownOnce(String inputName, String expectedResult) throws Exception {
DatabaseDialog databaseDialog = mock(DatabaseDialog.class);
when(databaseDialog.open()).thenReturn(inputName);
JobMeta jobMeta = new JobMeta();
DatabaseMeta db = createDefaultDatabase();
jobMeta.addDatabase(db);
JobEntryDialog dialog = mock(JobEntryDialog.class);
dialog.databaseDialog = databaseDialog;
dialog.jobMeta = jobMeta;
when(dialog.showDbDialogUnlessCancelledOrValid(anyDbMeta(), anyDbMeta())).thenCallRealMethod();
String result = dialog.showDbDialogUnlessCancelledOrValid((DatabaseMeta) db.clone(), db);
assertEquals(expectedResult, result);
// database dialog should be shown only once
verify(databaseDialog, times(1)).open();
}
use of org.pentaho.di.ui.core.database.dialog.DatabaseDialog in project pentaho-kettle by pentaho.
the class BaseStepDialog_ConnectionLine_Test method showDbDialog_LoopsUntilUniqueValueIsInput.
@Test
public void showDbDialog_LoopsUntilUniqueValueIsInput() throws Exception {
DatabaseMeta db1 = createDefaultDatabase();
DatabaseMeta db2 = createDefaultDatabase();
db2.setName(INPUT_NAME);
TransMeta transMeta = new TransMeta();
transMeta.addDatabase(db1);
transMeta.addDatabase(db2);
final String expectedResult = INPUT_NAME + "2";
DatabaseDialog databaseDialog = mock(DatabaseDialog.class);
when(databaseDialog.open()).thenReturn(INPUT_NAME).thenReturn(INPUT_NAME + " ").thenReturn(INPUT_NAME.toUpperCase()).thenReturn(expectedResult);
BaseStepDialog dialog = mock(BaseStepDialog.class);
dialog.databaseDialog = databaseDialog;
dialog.transMeta = transMeta;
when(dialog.showDbDialogUnlessCancelledOrValid(anyDbMeta(), anyDbMeta())).thenCallRealMethod();
when(dialog.getDatabaseDialog(any(Shell.class))).thenCallRealMethod();
// try to rename db1 ("qwerty")
String result = dialog.showDbDialogUnlessCancelledOrValid((DatabaseMeta) db1.clone(), db1);
assertEquals(expectedResult, result);
// database dialog should be shown four times
verify(databaseDialog, times(4)).open();
// and the error message should be shown three times
verify(dialog, times(3)).showDbExistsDialog(anyDbMeta());
}
use of org.pentaho.di.ui.core.database.dialog.DatabaseDialog in project pentaho-kettle by pentaho.
the class MonetDBBulkLoaderDialog method addConnectionLine.
public ComboVar addConnectionLine(Composite parent, Control previous, int middle, int margin, final Class<? extends DatabaseInterface> databaseType, final TransMeta transMeta) {
final ComboVar wConnection;
final FormData fdlConnection, fdbConnection, fdeConnection, fdConnection;
wConnection = new ComboVar(transMeta, parent, SWT.BORDER);
props.setLook(wConnection);
addDatabases(wConnection, null);
//
// Database connection (Label)
//
Label wlConnection = new Label(parent, SWT.LEFT);
wlConnection.setText(BaseMessages.getString(PKG, "MonetDBBulkLoaderDialog.Connection.Label"));
props.setLook(wlConnection);
//
// New (Button)
//
Button wbnConnection = new Button(parent, SWT.RIGHT);
wbnConnection.setText(BaseMessages.getString(PKG, "MonetDBBulkLoaderDialog.NewConnectionButton.Label"));
wbnConnection.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DatabaseMeta databaseMeta = new DatabaseMeta();
databaseMeta.shareVariablesWith(transMeta);
DatabaseDialog cid = getDatabaseDialog(shell);
cid.setDatabaseMeta(databaseMeta);
cid.setModalDialog(true);
if (cid.open() != null) {
transMeta.addDatabase(databaseMeta);
wConnection.removeAll();
addDatabases(wConnection, databaseType);
selectDatabase(wConnection, databaseMeta.getName());
}
}
});
//
// Edit (Button)
//
Button wbeConnection = new Button(parent, SWT.RIGHT);
wbeConnection.setText(BaseMessages.getString(PKG, "BaseStepDialog.EditConnectionButton.Label"));
wbeConnection.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta != null) {
databaseMeta.shareVariablesWith(transMeta);
DatabaseDialog cid = getDatabaseDialog(shell);
cid.setDatabaseMeta(databaseMeta);
cid.setModalDialog(true);
if (cid.open() != null) {
wConnection.removeAll();
addDatabases(wConnection, null);
selectDatabase(wConnection, databaseMeta.getName());
}
}
}
});
//
// Database connection (Label layout)
//
fdlConnection = new FormData();
// attaches to the left of the bounding container
fdlConnection.left = new FormAttachment(0, margin);
if (previous != null) {
fdlConnection.top = new FormAttachment(previous, margin + 10);
} else {
fdlConnection.top = new FormAttachment(0, 0);
}
wlConnection.setLayoutData(fdlConnection);
//
// New (Button layout)
//
fdbConnection = new FormData();
fdbConnection.right = new FormAttachment(100, -margin);
if (previous != null) {
fdbConnection.top = new FormAttachment(previous, margin);
} else {
fdbConnection.top = new FormAttachment(0, 0);
}
wbnConnection.setLayoutData(fdbConnection);
//
// Edit (Button layout)
//
fdeConnection = new FormData();
fdeConnection.right = new FormAttachment(wbnConnection, -margin);
if (previous != null) {
fdeConnection.top = new FormAttachment(previous, margin);
} else {
fdeConnection.top = new FormAttachment(0, 0);
}
wbeConnection.setLayoutData(fdeConnection);
//
// Connection (Combo Box layout)
//
// The right side of the Combo Box is attached to the Edit button
// The left side of the Combo Box is attached to the side of the database connection label
// Effectively, it resizes the combo box between the two components.
fdConnection = new FormData();
// fdConnection.height = fieldHeight;
fdConnection.left = new FormAttachment(middle, margin);
fdConnection.right = new FormAttachment(wbeConnection, -margin);
if (previous != null) {
fdConnection.top = new FormAttachment(previous, margin + 10);
} else {
fdConnection.top = new FormAttachment(wlConnection, margin);
}
wConnection.setLayoutData(fdConnection);
return wConnection;
}
use of org.pentaho.di.ui.core.database.dialog.DatabaseDialog in project pentaho-kettle by pentaho.
the class DatabaseConfigurationImportRuleComposite method editDatabase.
protected void editDatabase() {
DatabaseMeta editMeta;
if (databaseMeta == null) {
editMeta = new DatabaseMeta();
} else {
editMeta = (DatabaseMeta) databaseMeta.clone();
}
DatabaseDialog databaseDialog = new DatabaseDialog(composite.getShell(), editMeta);
if (databaseDialog.open() != null) {
databaseMeta = editMeta;
setCompositeData(rule);
}
}
Aggregations