private Properties getModelConnectionProperties(ModelResource mr) { try { if (ModelIdentifier.isRelationalSourceModel(mr)) { IConnectionInfoProvider provider = null; try { provider = getProvider(mr); } catch (Exception e) { // If provider throws exception its OK because some models may not have connection info. } if (provider != null) { Properties properties = provider.getProfileProperties(mr); // ConnectionProperties(mr); Properties p2 = provider.getConnectionProperties(mr); String translatorName = provider.getTranslatorName(mr); for (Object key : p2.keySet()) { properties.put(key, p2.get(key)); } if (translatorName != null) { properties.put(getString("translatorKey"), translatorName); // $NON-NLS-1$ } if (properties != null && !properties.isEmpty()) { return properties; } } } } catch (CoreException e) { DatatoolsUiConstants.UTIL.log(e); } return null; }
private Collection<ModelResource> getRelationalModelsWithConnections() { Collection<ModelResource> result = new ArrayList<ModelResource>(); try { ModelResource[] mrs = ModelWorkspaceManager.getModelWorkspaceManager().getModelWorkspace().getModelResources(); for (ModelResource mr : mrs) { if (ModelIdentifier.isRelationalSourceModel(mr)) { IConnectionInfoProvider provider = null; try { provider = getProvider(mr); } catch (Exception e) { // If provider throws exception its OK because some models may not have connection info. } if (provider != null) { Properties properties = provider.getConnectionProperties(mr); if (properties != null && !properties.isEmpty()) { result.add(mr); } } } } } catch (CoreException e) { DqpUiConstants.UTIL.log(e); } return result; }
/** * @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$ } } }