Exemplo n.º 1
0
  @Override
  protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);

    final Text nameText =
        UIUtils.createLabelText(propsGroup, "Name", attribute.getName()); // $NON-NLS-2$
    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
              ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
          }
        });

    UIUtils.createControlLabel(propsGroup, "Properties")
        .setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(
        new ViewerFilter() {
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
          }
        });

    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute);
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
      if (prop instanceof ObjectPropertyDescriptor) {
        if (((ObjectPropertyDescriptor) prop).isEditPossible()
            && !prop.getId().equals(DBConstants.PROP_ID_NAME)) {
          continue;
        }
      }
      pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);

    return propsGroup;
  }
Exemplo n.º 2
0
  @Override
  public void createControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumHeight = 200;
    composite.setLayoutData(gd);

    {
      Group certGroup =
          UIUtils.createControlGroup(composite, "Certificates", 2, GridData.FILL_HORIZONTAL, -1);
      UIUtils.createControlLabel(certGroup, "CA certificate");
      gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.minimumWidth = 130;
      clientCAText =
          new TextWithOpenFile(
              certGroup, "CA Certificate", new String[] {"*.*", "*.crt", "*.cert", "*.pem", "*"});
      clientCAText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      UIUtils.createControlLabel(certGroup, "SSL certificate");
      gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.minimumWidth = 130;
      clientCertText =
          new TextWithOpenFile(
              certGroup, "SSL Certificate", new String[] {"*.*", "*.cert", "*.pem", "*"});
      clientCertText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      UIUtils.createControlLabel(certGroup, "SSL certificate key");
      gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.minimumWidth = 130;
      clientKeyText =
          new TextWithOpenFile(
              certGroup, "SSL Certificate", new String[] {"*.*", "*.cert", "*.pem", "*"});
      clientKeyText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      cipherSuitesText = UIUtils.createLabelText(certGroup, "Cipher suites (optional)", "");
      cipherSuitesText.setToolTipText(
          "Overrides the cipher suites enabled for use on the underlying SSL sockets.\nThis may be required when using external JSSE providers or to specify cipher suites compatible with both MySQL server and used JVM.");
    }

    {
      Group advGroup =
          UIUtils.createControlGroup(composite, "Advanced", 2, GridData.FILL_HORIZONTAL, -1);
      requireSSQL =
          UIUtils.createLabelCheckbox(
              advGroup, "Require SSL", "Require server support of SSL connection.", false);
      veryServerCert =
          UIUtils.createLabelCheckbox(
              advGroup,
              "Verify server certificate",
              "Should the driver verify the server's certificate?\nWhen using this feature, the explicit certificate parameters should be specified, rather than system properties.",
              true);
      allowPublicKeyRetrieval =
          UIUtils.createLabelCheckbox(
              advGroup,
              "Allow public key retrieval",
              "Allows special handshake roundtrip to get server RSA public key directly from server.",
              false);
    }
    //        debugSSL = UIUtils.createLabelCheckbox(composite, "Debug SSL", "Prints debug
    // information in standard output.", false);
  }
  @Override
  protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1, 5);

    {
      typeTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
      typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
      UIUtils.createTableColumn(typeTable, SWT.LEFT, "Name");
      UIUtils.createTableColumn(typeTable, SWT.LEFT, "Description");
      typeTable.setHeaderVisible(true);
      typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
      typeTable.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              showSelectedType(getSelectedType());
            }
          });

      Composite tableGroup = UIUtils.createPlaceholder(composite, 2, 5);
      tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      Button newButton = new Button(tableGroup, SWT.PUSH);
      newButton.setText("New");
      newButton.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              String name;
              for (int i = 1; ; i++) {
                name = "Type" + i;
                boolean hasName = false;
                for (DBPConnectionType type : changedInfo.keySet()) {
                  if (type.getName().equals(name)) {
                    hasName = true;
                    break;
                  }
                }
                if (!hasName) {
                  break;
                }
              }
              DBPConnectionType newType =
                  new DBPConnectionType(
                      SecurityUtils.generateUniqueId(),
                      name,
                      "255,255,255",
                      "New type",
                      true,
                      false);
              addTypeToTable(newType, newType);
              typeTable.select(typeTable.getItemCount() - 1);
              typeTable.showSelection();
              showSelectedType(newType);
            }
          });

      deleteButton = new Button(tableGroup, SWT.PUSH);
      deleteButton.setText("Delete");
      deleteButton.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              DBPConnectionType connectionType = getSelectedType();
              if (!UIUtils.confirmAction(
                  deleteButton.getShell(),
                  "Delete connection type",
                  "Are you sure you want to delete connection type '"
                      + connectionType.getName()
                      + "'?\n"
                      + "All connections of this type will be reset to default type ("
                      + DBPConnectionType.DEFAULT_TYPE.getName()
                      + ")")) {
                return;
              }
              changedInfo.remove(connectionType);
              int index = typeTable.getSelectionIndex();
              typeTable.remove(index);
              if (index > 0) index--;
              typeTable.select(index);
              showSelectedType(getSelectedType());
            }
          });
    }

    {
      Group groupSettings =
          UIUtils.createControlGroup(
              composite, "Settings", 2, GridData.VERTICAL_ALIGN_BEGINNING, 300);
      groupSettings.setLayoutData(new GridData(GridData.FILL_BOTH));

      typeName = UIUtils.createLabelText(groupSettings, "Name", null);
      typeName.addModifyListener(
          new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
              getSelectedType().setName(typeName.getText());
              updateTableInfo();
            }
          });
      typeDescription = UIUtils.createLabelText(groupSettings, "Description", null);
      typeDescription.addModifyListener(
          new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
              getSelectedType().setDescription(typeDescription.getText());
              updateTableInfo();
            }
          });

      {
        UIUtils.createControlLabel(groupSettings, "Color");
        Composite colorGroup = UIUtils.createPlaceholder(groupSettings, 2, 5);
        colorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        colorPicker = new CImageCombo(colorGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
        colorPicker.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        colorPicker.addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                getSelectedType()
                    .setColor(
                        StringConverter.asString(
                            colorPicker
                                .getItem(colorPicker.getSelectionIndex())
                                .getBackground()
                                .getRGB()));
                updateTableInfo();
              }
            });
        Button pickerButton = new Button(colorGroup, SWT.PUSH);
        pickerButton.setText("...");
        pickerButton.addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                DBPConnectionType connectionType = getSelectedType();
                ColorDialog colorDialog = new ColorDialog(parent.getShell());
                colorDialog.setRGB(StringConverter.asRGB(connectionType.getColor()));
                RGB rgb = colorDialog.open();
                if (rgb != null) {
                  Color color = null;
                  int count = colorPicker.getItemCount();
                  for (int i = 0; i < count; i++) {
                    TableItem item = colorPicker.getItem(i);
                    if (item.getBackground() != null && item.getBackground().getRGB().equals(rgb)) {
                      color = item.getBackground();
                      break;
                    }
                  }
                  if (color == null) {
                    color = new Color(colorPicker.getDisplay(), rgb);
                    colorPicker.add(null, COLOR_TEXT, color, color);
                  }
                  colorPicker.select(color);
                  getSelectedType().setColor(StringConverter.asString(color.getRGB()));
                  updateTableInfo();
                }
              }
            });
      }

      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.horizontalSpan = 2;

      autocommitCheck = UIUtils.createCheckbox(groupSettings, "Auto-commit by default", false);
      autocommitCheck.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              getSelectedType().setAutocommit(autocommitCheck.getSelection());
            }
          });
      autocommitCheck.setLayoutData(gd);
      confirmCheck = UIUtils.createCheckbox(groupSettings, "Confirm SQL execution", false);
      confirmCheck.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              getSelectedType().setConfirmExecute(confirmCheck.getSelection());
            }
          });
      confirmCheck.setLayoutData(gd);
    }

    performDefaults();

    return composite;
  }