@Override protected boolean doLazyInit() { try { mainController = (MainController) this.getXulDomContainer().getEventHandler("mainController"); } catch (XulException e) { return false; } try { setRepReadOnly(this.repository.getRepositoryMeta().getRepositoryCapabilities().isReadOnly()); // Load the SWT Shell from the explorer dialog shell = ((SwtDialog) document.getElementById("repository-explorer-dialog")).getShell(); bf = new DefaultBindingFactory(); bf.setDocument(this.getXulDomContainer().getDocumentRoot()); if (bf != null) { createBindings(); } enableButtons(true, false, false); return true; } catch (Exception e) { if (mainController == null || !mainController.handleLostRepository(e)) { return false; } } return false; }
private void createBindings() { refreshConnectionList(); connectionsTable = (XulTree) document.getElementById("connections-table"); // Bind the connection table to a list of connections bf.setBindingType(Binding.Type.ONE_WAY); // CHECKSTYLE:LineLength:OFF try { bf.createBinding(dbConnectionList, "children", connectionsTable, "elements") .fireSourceChanged(); (bindButtonNew = bf.createBinding(this, "repReadOnly", "connections-new", "disabled")) .fireSourceChanged(); (bindButtonEdit = bf.createBinding(this, "repReadOnly", "connections-edit", "disabled")) .fireSourceChanged(); (bindButtonRemove = bf.createBinding(this, "repReadOnly", "connections-remove", "disabled")) .fireSourceChanged(); if (repository != null) { bf.createBinding(connectionsTable, "selectedItems", this, "selectedConnections"); } } catch (Exception ex) { if (mainController == null || !mainController.handleLostRepository(ex)) { // convert to runtime exception so it bubbles up through the UI throw new RuntimeException(ex); } } }
public void removeConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if (connections != null && !connections.isEmpty()) { for (Object obj : connections) { if (obj != null && obj instanceof UIDatabaseConnection) { UIDatabaseConnection connection = (UIDatabaseConnection) obj; DatabaseMeta databaseMeta = connection.getDatabaseMeta(); // Make sure this connection already exists and store its id for updating ObjectId idDatabase = repository.getDatabaseID(databaseMeta.getName()); if (idDatabase == null) { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Delete.DoesNotExists.Message", databaseMeta.getName())); mb.setText( BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title")); mb.open(); } else { repository.deleteDatabaseMeta(databaseMeta.getName()); } } } } else { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message")); mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title")); mb.open(); } } catch (KettleException e) { if (mainController == null || !mainController.handleLostRepository(e)) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Remove.UnexpectedError.Message"), e); } } finally { refreshConnectionList(); } }
public void createConnection() { try { DatabaseMeta databaseMeta = new DatabaseMeta(); databaseMeta.initializeVariablesFrom(null); getDatabaseDialog().setDatabaseMeta(databaseMeta); String dbName = getDatabaseDialog().open(); if (dbName != null) { dbName = dbName.trim(); if (!dbName.isEmpty()) { // See if this user connection exists... ObjectId idDatabase = repository.getDatabaseID(dbName); if (idDatabase == null) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.CreatingDatabase", getDatabaseDialog().getDatabaseMeta().getName())); repository.save( getDatabaseDialog().getDatabaseMeta(), Const.VERSION_COMMENT_INITIAL_VERSION, null); } else { showAlreadyExistsMessage(); } } } // We should be able to tell the difference between a cancel and an empty database name // // else { // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); // mb.setMessage(BaseMessages.getString(PKG, // "RepositoryExplorerDialog.Connection.Edit.MissingName.Message")); // mb.setText(BaseMessages.getString(PKG, // "RepositoryExplorerDialog.Connection.Edit.MissingName.Title")); // mb.open(); // } } catch (KettleException e) { if (mainController == null || !mainController.handleLostRepository(e)) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Message"), e); } } finally { refreshConnectionList(); } }
public void setRepReadOnly(boolean isRepReadOnly) { try { if (this.isRepReadOnly != isRepReadOnly) { this.isRepReadOnly = isRepReadOnly; if (initialized) { bindButtonNew.fireSourceChanged(); bindButtonEdit.fireSourceChanged(); bindButtonRemove.fireSourceChanged(); } } } catch (Exception e) { if (mainController == null || !mainController.handleLostRepository(e)) { // convert to runtime exception so it bubbles up through the UI throw new RuntimeException(e); } } }
public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if (connections != null && !connections.isEmpty()) { // Grab the first item in the list & send it to the database dialog DatabaseMeta databaseMeta = ((UIDatabaseConnection) connections.toArray()[0]).getDatabaseMeta(); // Make sure this connection already exists and store its id for updating ObjectId idDatabase = repository.getDatabaseID(databaseMeta.getName()); if (idDatabase == null) { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message")); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title")); mb.open(); } else { getDatabaseDialog().setDatabaseMeta(databaseMeta); String dbName = getDatabaseDialog().open(); if (dbName != null) { dbName = dbName.trim(); if (!dbName.isEmpty()) { ObjectId idRenamed = repository.getDatabaseID(dbName); if (idRenamed == null || idRenamed.equals(idDatabase)) { // renaming to non-existing name or updating the current repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName())); repository.save(databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null); } else { // trying to rename to an existing name - show error dialog showAlreadyExistsMessage(); } } } // We should be able to tell the difference between a cancel and an empty database name // // else { // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); // mb.setMessage(BaseMessages.getString(PKG, // "RepositoryExplorerDialog.Connection.Edit.MissingName.Message")); // mb.setText(BaseMessages.getString(PKG, // "RepositoryExplorerDialog.Connection.Edit.MissingName.Title")); // mb.open(); // } } } else { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message")); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title")); mb.open(); } } catch (KettleException e) { if (mainController == null || !mainController.handleLostRepository(e)) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message"), e); } } finally { refreshConnectionList(); } }