/** * @see org.eclipse.jface.action.IAction#run() * @since 5.0 */ @Override public void run() { final IWorkbenchWindow iww = VdbUiPlugin.singleton.getCurrentWorkbenchWindow(); // A) get the selected model and extract a "ConnectionProfileInfo" from it using the // ConnectionProfileInfoHandler // B) Use ConnectionProfileHandler.getConnectionProfile(connectionProfileInfo) to query the user // to // select a ConnectionProfile (or create new one) // C) Get the resulting ConnectionProfileInfo from the dialog and re-set the model's connection // info // via the ConnectionProfileInfoHandler ModelResource modelResource = null; if (!getSelection().isEmpty()) { IFile modelFile = (IFile) SelectionUtilities.getSelectedObjects(getSelection()).get(0); modelResource = ModelUtilities.getModelResource(modelFile); } try { ITeiidServer teiidServer = cachedServer; if (teiidServer == null) { if (DqpPlugin.getInstance().getServerManager().getDefaultServer() == null) { MessageDialog.openConfirm( iww.getShell(), getString("noServer.title"), // $NON-NLS-1$ getString("noServer.message")); // $NON-NLS-1$ return; } else if (DqpPlugin.getInstance().getServerManager().getDefaultServer().isConnected()) { teiidServer = DqpPlugin.getInstance().getServerManager().getDefaultServer(); } else { MessageDialog.openConfirm( iww.getShell(), getString("noServerConnection.title"), // $NON-NLS-1$ getString("noServerConnection.message")); // $NON-NLS-1$ return; } teiidServer.connect(); } Collection<ModelResource> relationalModels = getRelationalModelsWithConnections(); final CreateDataSourceWizard wizard = new CreateDataSourceWizard(teiidServer, relationalModels, modelResource); wizard.init(iww.getWorkbench(), new StructuredSelection()); final WizardDialog dialog = new WizardDialog(wizard.getShell(), wizard); final int rc = dialog.open(); if (rc == Window.OK) { // Need to check if the connection needs a password TeiidDataSourceInfo info = wizard.getTeiidDataSourceInfo(); Properties props = info.getProperties(); IConnectionInfoProvider provider = info.getConnectionInfoProvider(); boolean cancelledPassword = false; if (null != provider.getDataSourcePasswordPropertyKey() && props.get(provider.getDataSourcePasswordPropertyKey()) == null) { int result = new AbstractPasswordDialog( iww.getShell(), getString("passwordTitle"), null) { // $NON-NLS-1$ @SuppressWarnings("synthetic-access") @Override protected boolean isPasswordValid(final String password) { pwd = password; return true; } }.open(); if (result == Window.OK) { props.put(provider.getDataSourcePasswordPropertyKey(), this.pwd); } else { cancelledPassword = true; } } if (!cancelledPassword) { teiidServer.getOrCreateDataSource( info.getDisplayName(), info.getJndiName(), provider.getDataSourceType(), props); } } // createDataSource(modelFile); } catch (Exception e) { if (modelResource != null) { MessageDialog.openError( getShell(), getString("errorCreatingDataSourceForModel", modelResource.getItemName()), e.getMessage()); // $NON-NLS-1$ DqpUiConstants.UTIL.log( IStatus.ERROR, e, getString( "errorCreatingDataSourceForModel", modelResource.getItemName())); // $NON-NLS-1$ } else { MessageDialog.openError( getShell(), getString("errorCreatingDataSource"), e.getMessage()); // $NON-NLS-1$ DqpUiConstants.UTIL.log( IStatus.ERROR, e, getString("errorCreatingDataSource")); // $NON-NLS-1$ } } }