private void createEmbeddedDatabase() {
    String paramCreate =
        CommonUtils.toString(
            site.getDriver().getDriverParameter(GenericConstants.PARAM_CREATE_URL_PARAM));

    DataSourceDescriptor dataSource = (DataSourceDescriptor) site.getActiveDataSource();
    final DataSourceDescriptor testDataSource =
        new DataSourceDescriptor(
            site.getDataSourceRegistry(),
            dataSource.getId(),
            dataSource.getDriver(),
            new DBPConnectionConfiguration(dataSource.getConnectionConfiguration()));

    saveSettings(testDataSource);
    DBPConnectionConfiguration cfg = testDataSource.getConnectionConfiguration();
    cfg.setUrl(cfg.getUrl() + paramCreate);
    String databaseName = cfg.getDatabaseName();
    testDataSource.setName(databaseName);

    if (!UIUtils.confirmAction(
        getShell(),
        "Create Database",
        "Are you sure you want to create database '" + databaseName + "'?")) {
      testDataSource.dispose();
      return;
    }

    try {
      site.getRunnableContext()
          .run(
              true,
              true,
              new DBRRunnableWithProgress() {
                @Override
                public void run(DBRProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    createEmbeddedDatabase(monitor, testDataSource);
                  } catch (DBException e1) {
                    throw new InvocationTargetException(e1);
                  }
                }
              });
      MessageDialog.openInformation(
          getShell(), "Database Create", "Database '" + databaseName + "' created!");
    } catch (InvocationTargetException e1) {
      UIUtils.showErrorDialog(
          getShell(), "Create database", "Error creating database", e1.getTargetException());
    } catch (InterruptedException e1) {
      // Just ignore
    }
  }
Example #2
0
 public static Color getConnectionColor(DBPConnectionConfiguration connectionInfo) {
   String rgbString = connectionInfo.getConnectionColor();
   if (CommonUtils.isEmpty(rgbString)) {
     rgbString = connectionInfo.getConnectionType().getColor();
   }
   if (CommonUtils.isEmpty(rgbString)) {
     return null;
   }
   Color connectionColor =
       DBeaverUI.getSharedTextColors().getColor(StringConverter.asRGB(rgbString));
   if (connectionColor.getBlue() == 255
       && connectionColor.getRed() == 255
       && connectionColor.getGreen() == 255) {
     // For white color return just null to avoid explicit color set.
     // It is important for dark themes
     return null;
   }
   return connectionColor;
 }
  @Override
  public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    final Set<String> properties =
        metaURL == null ? Collections.<String>emptySet() : metaURL.getAvailableProperties();

    if (hostText != null && properties.contains(DriverDescriptor.PROP_HOST)) {
      connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null && properties.contains(DriverDescriptor.PROP_PORT)) {
      connectionInfo.setHostPort(portText.getText().trim());
    }
    if (serverText != null && properties.contains(DriverDescriptor.PROP_SERVER)) {
      connectionInfo.setServerName(serverText.getText().trim());
    }
    if (dbText != null && properties.contains(DriverDescriptor.PROP_DATABASE)) {
      connectionInfo.setDatabaseName(dbText.getText().trim());
    }
    if (pathText != null
        && (properties.contains(DriverDescriptor.PROP_FOLDER)
            || properties.contains(DriverDescriptor.PROP_FILE))) {
      connectionInfo.setDatabaseName(pathText.getText().trim());
    }
    if (userNameText != null) {
      connectionInfo.setUserName(userNameText.getText().trim());
    }
    if (passwordText != null) {
      connectionInfo.setUserPassword(passwordText.getText());
    }
    super.saveSettings(dataSource);
    if (isCustom) {
      if (urlText != null) {
        connectionInfo.setUrl(urlText.getText().trim());
      }
    } else {
      if (urlText != null && connectionInfo.getUrl() != null) {
        urlText.setText(connectionInfo.getUrl());
      }
    }
  }
  @Override
  public void loadSettings() {
    super.loadSettings();

    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo =
        site.getActiveDataSource().getConnectionConfiguration();
    this.parseSampleURL(site.getDriver());
    if (!isCustom) {
      if (hostText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
          hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
        } else {
          hostText.setText("localhost"); // $NON-NLS-1$
        }
      }
      if (portText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
          portText.setText(String.valueOf(connectionInfo.getHostPort()));
        } else if (site.getDriver().getDefaultPort() != null) {
          portText.setText(site.getDriver().getDefaultPort());
        } else {
          portText.setText(""); // $NON-NLS-1$
        }
      }
      if (serverText != null) {
        serverText.setText(CommonUtils.notEmpty(connectionInfo.getServerName()));
      }
      if (dbText != null) {
        dbText.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
      }
      if (pathText != null) {
        pathText.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
      }
    } else {
      hostText.setText(""); // $NON-NLS-1$
      portText.setText(""); // $NON-NLS-1$
      serverText.setText(""); // $NON-NLS-1$
      dbText.setText(""); // $NON-NLS-1$
      pathText.setText(""); // $NON-NLS-1$
    }
    if (userNameText != null) {
      userNameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (passwordText != null) {
      passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }

    if (urlText != null) {
      if (connectionInfo.getUrl() != null) {
        urlText.setText(CommonUtils.notEmpty(connectionInfo.getUrl()));
      } else {
        urlText.setText(""); // $NON-NLS-1$
      }
    }

    activated = true;
  }