Search in sources :

Example 1 with DatabaseDialog

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;
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DatabaseDialog

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();
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 3 with DatabaseDialog

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());
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransMeta(org.pentaho.di.trans.TransMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog) Test(org.junit.Test)

Example 4 with DatabaseDialog

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;
}
Also used : FormData(org.eclipse.swt.layout.FormData) ComboVar(org.pentaho.di.ui.core.widget.ComboVar) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) FormAttachment(org.eclipse.swt.layout.FormAttachment) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 5 with DatabaseDialog

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);
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)11 DatabaseDialog (org.pentaho.di.ui.core.database.dialog.DatabaseDialog)11 Shell (org.eclipse.swt.widgets.Shell)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 KettleException (org.pentaho.di.core.exception.KettleException)2 JobMeta (org.pentaho.di.job.JobMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Button (org.eclipse.swt.widgets.Button)1 Label (org.eclipse.swt.widgets.Label)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 ComboVar (org.pentaho.di.ui.core.widget.ComboVar)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1