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();
}
}
}
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;
}
}
Aggregations