Search in sources :

Example 1 with DatabaseConnectionDialog

use of org.pentaho.ui.database.DatabaseConnectionDialog in project pentaho-kettle by pentaho.

the class DatabaseDialogHarness method showDialog.

private void showDialog() {
    XulDomContainer container = null;
    try {
        DatabaseConnectionDialog dcDialog = new DatabaseConnectionDialog();
        container = dcDialog.getSwtInstance(new Shell(SWT.NONE));
        if (database != null) {
            container.getEventHandler("dataHandler").setData(database);
        }
    } catch (XulException e) {
        e.printStackTrace();
    }
    XulRoot root = (XulRoot) container.getDocumentRoot().getRootElement();
    if (root instanceof XulDialog) {
        ((XulDialog) root).show();
    }
    if (root instanceof XulWindow) {
        ((XulWindow) root).open();
    }
    try {
        database = (DatabaseMeta) container.getEventHandler("dataHandler").getData();
    } catch (Exception e) {
        e.printStackTrace();
    }
    String message = DatabaseDialogHarness.setMessage(database);
    Shell shell = new Shell(SWT.DIALOG_TRIM);
    shell.setLayout(new RowLayout());
    Label label = new Label(shell, SWT.NONE);
    label.setText(message);
    Button button = new Button(shell, SWT.NONE);
    button.setText("Edit Database ...");
    button.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            try {
                showDialog();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!shell.getDisplay().readAndDispatch()) {
            shell.getDisplay().sleep();
        }
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DatabaseConnectionDialog(org.pentaho.ui.database.DatabaseConnectionDialog) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) XulRoot(org.pentaho.ui.xul.containers.XulRoot) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) XulDialog(org.pentaho.ui.xul.containers.XulDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XulWindow(org.pentaho.ui.xul.containers.XulWindow)

Example 2 with DatabaseConnectionDialog

use of org.pentaho.ui.database.DatabaseConnectionDialog in project pentaho-kettle by pentaho.

the class XulDatabaseDialog method createDialog.

@SuppressWarnings("deprecation")
private void createDialog() {
    XulDomContainer container = null;
    try {
        databaseDialogInstance = new DatabaseConnectionDialog();
        if (((Shell) this.parentShell).getText().contains("Metadata Editor")) {
            databaseDialogInstance.registerClass(EXTENDED_WIDGET_ID, PMD_WIDGET_CLASSNAME);
            databaseDialogInstance.registerClass(EXTENDED_MENULIST_WIDGET_ID, PMD_MENULIST_WIDGET_CLASSNAME);
        } else {
            databaseDialogInstance.registerClass(EXTENDED_WIDGET_ID, EXTENDED_WIDGET_CLASSNAME);
            databaseDialogInstance.registerClass(EXTENDED_MENULIST_WIDGET_ID, EXTENDED_MENULIST_WIDGET_CLASSNAME);
        }
        /*
       * Attention: onload: loadConnectionData() is called here the first time, see below for second time
       */
        container = databaseDialogInstance.getSwtInstance(new KettleXulLoader(), parentShell);
        container.addEventHandler(EVENT_ID, DataOverrideHandler.class.getName());
        SpoonPluginManager.getInstance().applyPluginsForContainer("connection_dialog", container);
        dataHandler = (DataOverrideHandler) container.getEventHandler(EVENT_ID);
        if (databaseMeta != null) {
            dataHandler.setData(databaseMeta);
        }
        dataHandler.setDatabases(databases);
        dataHandler.getControls();
    } catch (XulException e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.HandleXul"), e);
        return;
    }
    try {
        // Inject the button panel that contains the "Feature List" and "Explore" buttons
        XulComponent boxElement = container.getDocumentRoot().getElementById(FRAGMENT_ID);
        XulComponent parentElement = boxElement.getParent();
        ResourceBundle res = null;
        try {
            res = GlobalMessages.getBundle(MESSAGES);
        } catch (MissingResourceException e) {
            log.logError(BaseMessages.getString(PKG, "XulDatabaseDialog.Error.ResourcesNotFound.Title"), e.getMessage(), e);
        }
        XulDomContainer fragmentContainer = null;
        String pkg = getClass().getPackage().getName().replace('.', '/');
        // to check for it here.
        if (res != null) {
            fragmentContainer = container.loadFragment(pkg.concat(DIALOG_FRAGMENT_FILE), res);
        } else {
            fragmentContainer = container.loadFragment(pkg.concat(DIALOG_FRAGMENT_FILE));
        }
        XulComponent newBox = fragmentContainer.getDocumentRoot().getFirstChild();
        parentElement.replaceChild(boxElement, newBox);
    } catch (Exception e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.HandleXul"), e);
        return;
    }
    try {
        xulDialogComponent = (XulDialog) container.getDocumentRoot().getRootElement();
        parentShell.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent arg0) {
                xulDialogComponent.hide();
            }
        });
    } catch (Exception e) {
        new ErrorDialog(parentShell, BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Title"), BaseMessages.getString(PKG, "XulDatabaseDialog.Error.Dialog"), e);
        return;
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MissingResourceException(java.util.MissingResourceException) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseConnectionDialog(org.pentaho.ui.database.DatabaseConnectionDialog) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) XulException(org.pentaho.ui.xul.XulException) MissingResourceException(java.util.MissingResourceException) XulException(org.pentaho.ui.xul.XulException) ResourceBundle(java.util.ResourceBundle) XulComponent(org.pentaho.ui.xul.XulComponent)

Aggregations

DatabaseConnectionDialog (org.pentaho.ui.database.DatabaseConnectionDialog)2 XulDomContainer (org.pentaho.ui.xul.XulDomContainer)2 XulException (org.pentaho.ui.xul.XulException)2 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Label (org.eclipse.swt.widgets.Label)1 Shell (org.eclipse.swt.widgets.Shell)1 KettleException (org.pentaho.di.core.exception.KettleException)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 KettleXulLoader (org.pentaho.di.ui.xul.KettleXulLoader)1 XulComponent (org.pentaho.ui.xul.XulComponent)1 XulDialog (org.pentaho.ui.xul.containers.XulDialog)1 XulRoot (org.pentaho.ui.xul.containers.XulRoot)1 XulWindow (org.pentaho.ui.xul.containers.XulWindow)1