示例#1
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
 @Override
 public void onSuccess() {
   UIUtils.showMessageBox(
       getShell(),
       MySQLMessages.tools_db_export_wizard_title,
       NLS.bind(MySQLMessages.tools_db_export_wizard_message_export_completed, getObjectsName()),
       SWT.ICON_INFORMATION);
   UIUtils.launchProgram(outputFolder.getAbsolutePath());
 }
  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
    }
  }
示例#4
0
  @NotNull
  public static Text createOutputFolderChooser(
      final Composite parent, @Nullable String label, @Nullable ModifyListener changeListener) {
    UIUtils.createControlLabel(
        parent, label != null ? label : CoreMessages.data_transfer_wizard_output_label_directory);
    Composite chooserPlaceholder = UIUtils.createPlaceholder(parent, 2);
    chooserPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Text directoryText = new Text(chooserPlaceholder, SWT.BORDER);
    directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (changeListener != null) {
      directoryText.addModifyListener(changeListener);
    }

    final Runnable folderChooser =
        new Runnable() {
          @Override
          public void run() {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.NONE);
            dialog.setMessage(CoreMessages.data_transfer_wizard_output_dialog_directory_message);
            dialog.setText(CoreMessages.data_transfer_wizard_output_dialog_directory_text);
            String directory = directoryText.getText();
            if (!CommonUtils.isEmpty(directory)) {
              dialog.setFilterPath(directory);
            }
            directory = dialog.open();
            if (directory != null) {
              directoryText.setText(directory);
            }
          }
        };
    directoryText.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseUp(MouseEvent e) {
            folderChooser.run();
          }
        });

    Button openFolder = new Button(chooserPlaceholder, SWT.PUSH | SWT.FLAT);
    openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
    openFolder.setLayoutData(
        new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_CENTER));
    openFolder.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            folderChooser.run();
          }
        });
    return directoryText;
  }
  protected void createLinksPanel(Composite composite) {
    final DriverDescriptor driver = getWizard().getDriver();

    // UIUtils.createPlaceholder(composite, 1).setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite linksGroup = UIUtils.createPlaceholder(composite, 2);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.verticalIndent = 10;
    linksGroup.setLayoutData(gd);

    // Vendor site
    if (!CommonUtils.isEmpty(driver.getWebURL())) {
      Link link =
          UIUtils.createLink(
              linksGroup,
              "<a>Vendor's website</a>",
              new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                  RuntimeUtils.openWebBrowser(driver.getWebURL());
                }
              });
      link.setToolTipText(driver.getWebURL());
      link.setLayoutData(
          new GridData(
              GridData.FILL_HORIZONTAL
                  | GridData.VERTICAL_ALIGN_BEGINNING
                  | GridData.HORIZONTAL_ALIGN_BEGINNING));
    } else {
      UIUtils.createPlaceholder(linksGroup, 1)
          .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    Link link =
        UIUtils.createLink(
            linksGroup,
            "<a>Download configuration</a>",
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                UIUtils.showPreferencesFor(null, null, PrefPageDrivers.PAGE_ID);
              }
            });
    link.setLayoutData(
        new GridData(
            GridData.FILL_HORIZONTAL
                | GridData.VERTICAL_ALIGN_BEGINNING
                | GridData.HORIZONTAL_ALIGN_END));
  }
  @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;
  }
  public CompareObjectsWizard(List<DBNDatabaseNode> nodes) {
    this.settings = new CompareObjectsSettings(nodes);
    IDialogSettings section = UIUtils.getDialogSettings(RS_COMPARE_WIZARD_DIALOG_SETTINGS);
    setDialogSettings(section);

    settings.loadFrom(section);
  }
  private void renderReport(DBRProgressMonitor monitor, CompareReport report) {
    try {
      File reportFile;
      switch (settings.getOutputType()) {
        case BROWSER:
          reportFile = File.createTempFile("compare-report", ".html");
          break;
        default:
          {
            StringBuilder fileName = new StringBuilder("compare"); // "compare-report.html";
            for (DBNDatabaseNode node : report.getNodes()) {
              fileName.append("-").append(CommonUtils.escapeIdentifier(node.getName()));
            }
            fileName.append("-report.html");
            reportFile = new File(settings.getOutputFolder(), fileName.toString());
            break;
          }
      }

      reportFile.deleteOnExit();
      OutputStream outputStream = new FileOutputStream(reportFile);
      try {
        monitor.beginTask("Render report", report.getReportLines().size());
        CompareReportRenderer reportRenderer = new CompareReportRenderer();
        reportRenderer.renderReport(monitor, report, getSettings(), outputStream);
        monitor.done();
      } finally {
        ContentUtils.close(outputStream);
      }
      UIUtils.launchProgram(reportFile.getAbsolutePath());
    } catch (IOException e) {
      showError(e.getMessage());
      log.error(e);
    }
  }
 @Override
 public boolean performFinish() {
   try {
     RuntimeUtils.run(
         getContainer(),
         true,
         true,
         new DBRRunnableWithProgress() {
           @Override
           public void run(DBRProgressMonitor monitor)
               throws InvocationTargetException, InterruptedException {
             try {
               createProject(monitor);
             } catch (Exception e) {
               throw new InvocationTargetException(e);
             }
           }
         });
   } catch (InterruptedException ex) {
     return false;
   } catch (InvocationTargetException ex) {
     UIUtils.showErrorDialog(
         getShell(),
         CoreMessages.dialog_project_create_wizard_error_cannot_create,
         CoreMessages.dialog_project_create_wizard_error_cannot_create_message,
         ex.getTargetException());
     return false;
   }
   return true;
 }
示例#10
0
    @Override
    public void run() {
      visualizer.completeLoading(innerResult);

      if (innerError != null) {
        log.debug(innerError);
        UIUtils.showErrorDialog(null, getName(), null, innerError);
      }
    }
  private void showSelectedType(DBPConnectionType connectionType) {
    colorPicker.select(UIUtils.getConnectionTypeColor(connectionType));
    typeName.setText(connectionType.getName());
    typeDescription.setText(connectionType.getDescription());
    autocommitCheck.setSelection(connectionType.isAutocommit());
    confirmCheck.setSelection(connectionType.isConfirmExecute());

    deleteButton.setEnabled(!connectionType.isPredefined());
  }
示例#12
0
 private void showResult(final long time, final boolean hasErrors) {
   UIUtils.showMessageBox(
       null,
       "Data transfer",
       "Data transfer completed "
           + (hasErrors ? "with errors " : "")
           + "("
           + RuntimeUtils.formatExecutionTime(time)
           + ")",
       hasErrors ? SWT.ICON_ERROR : SWT.ICON_INFORMATION);
 }
示例#13
0
  @Override
  public boolean performAction() {
    try {
      source.saveState(DBeaverCore.getGlobalPreferenceStore());

      NewSearchUI.runQueryInBackground(createQueryAdapter(source.createQuery()));
    } catch (Exception e) {
      UIUtils.showErrorDialog(getControl().getShell(), "Search", "Can't perform search", e);
      return false;
    }
    return true;
  }
  @Override
  protected Control createDialogArea(Composite parent) {
    IValueController valueController = getValueController();
    Object value = valueController.getValue();

    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    Composite panel = UIUtils.createPlaceholder(dialogGroup, 3);
    panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    int style = SWT.BORDER;
    if (valueController.isReadOnly()) {
      style |= SWT.READ_ONLY;
    }

    UIUtils.createControlLabel(panel, "Time")
        .setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    DBDDataFormatter formatter =
        helper.getFormatter(valueController, valueController.getValueType());
    timeEditor = new CustomTimeEditor(panel, style, formatter);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    timeEditor.getControl().setLayoutData(gd);

    primeEditorValue(value);

    Button button = UIUtils.createPushButton(panel, "Set Current", null);
    button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    button.setEnabled(!valueController.isReadOnly());
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            primeEditorValue(new Date());
          }
        });

    return dialogGroup;
  }
 private void updateTableInfo() {
   DBPConnectionType connectionType = getSelectedType();
   for (TableItem item : typeTable.getItems()) {
     if (item.getData() == connectionType) {
       item.setText(0, connectionType.getName());
       item.setText(1, connectionType.getDescription());
       Color connectionColor = UIUtils.getConnectionTypeColor(connectionType);
       item.setBackground(0, connectionColor);
       item.setBackground(1, connectionColor);
       break;
     }
   }
 }
 private void addTypeToTable(DBPConnectionType source, DBPConnectionType connectionType) {
   changedInfo.put(connectionType, source);
   TableItem item = new TableItem(typeTable, SWT.LEFT);
   item.setText(0, connectionType.getName());
   item.setText(1, CommonUtils.toString(connectionType.getDescription()));
   if (connectionType.getColor() != null) {
     Color connectionColor = UIUtils.getConnectionTypeColor(connectionType);
     item.setBackground(0, connectionColor);
     item.setBackground(1, connectionColor);
     colorPicker.add(null, COLOR_TEXT, connectionColor, connectionColor);
   }
   item.setData(connectionType);
 }
示例#17
0
 private boolean fillStatementParameters(final List<SQLQueryParameter> parameters) {
   final RunnableWithResult<Boolean> binder =
       new RunnableWithResult<Boolean>() {
         @Override
         public void run() {
           SQLQueryParameterBindDialog dialog =
               new SQLQueryParameterBindDialog(partSite, getExecutionContext(), parameters);
           result = (dialog.open() == IDialogConstants.OK_ID);
         }
       };
   UIUtils.runInUI(partSite.getShell(), binder);
   Boolean result = binder.getResult();
   return result != null && result;
 }
  @Override
  public boolean performFinish() {
    // Save settings
    getSettings().saveTo(getDialogSettings());
    showError(null);

    // Compare
    final CompareObjectsExecutor executor = new CompareObjectsExecutor(settings);
    try {
      DBeaverUI.run(
          getContainer(),
          true,
          true,
          new DBRRunnableWithProgress() {
            @Override
            public void run(DBRProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              try {
                CompareReport report = generateReport(monitor, executor);

                renderReport(monitor, report);
              } catch (DBException e) {
                throw new InvocationTargetException(e);
              }
            }
          });
      UIUtils.showMessageBox(
          getShell(), "Objects compare", "Objects compare finished", SWT.ICON_INFORMATION);
    } catch (InvocationTargetException e) {
      if (executor.getInitializeError() != null) {
        showError(executor.getInitializeError().getMessage());
      } else {
        log.error(e.getTargetException());
        showError(e.getTargetException().getMessage());
      }
      return false;
    } catch (InterruptedException e) {
      showError("Compare interrupted");
      return false;
    } finally {
      executor.dispose();
    }

    // Done
    return true;
  }
  @Override
  public void createPartControl(Composite parent) {
    super.createPartControl(parent);
    final TreeViewer viewer = getNavigatorViewer();
    assert viewer != null;
    viewer.getTree().setHeaderVisible(true);
    createColumns(viewer);
    UIUtils.setHelp(parent, IHelpContextIds.CTX_PROJECT_EXPLORER);

    viewer.addFilter(
        new ViewerFilter() {
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return !(element instanceof DBNProjectDatabases);
          }
        });
    updateTitle();
  }
示例#20
0
  private IStatus run(DBRProgressMonitor monitor, boolean lazy) {
    monitor = visualizer.overwriteMonitor(monitor);

    LoadingUIJob<RESULT> updateUIJob = new LoadingUIJob<>(this, monitor);
    updateUIJob.schedule();
    this.loadingService.setProgressMonitor(monitor);
    Throwable error = null;
    RESULT result = null;
    try {
      result = this.loadingService.evaluate();
    } catch (InvocationTargetException e) {
      //            log.error(e.getTargetException());
      error = e.getTargetException();
    } catch (InterruptedException e) {
      return new Status(Status.CANCEL, DBeaverCore.PLUGIN_ID, "Loading interrupted");
    } finally {
      UIUtils.runInUI(null, new LoadFinisher(result, error));
    }
    return Status.OK_STATUS;
  }
示例#21
0
 public static void runInUI(IRunnableContext context, final DBRRunnableWithProgress runnable) {
   try {
     PlatformUI.getWorkbench()
         .getProgressService()
         .runInUI(
             context,
             new IRunnableWithProgress() {
               @Override
               public void run(IProgressMonitor monitor)
                   throws InvocationTargetException, InterruptedException {
                 runnable.run(RuntimeUtils.makeMonitor(monitor));
               }
             },
             DBeaverActivator.getWorkspace().getRoot());
   } catch (InvocationTargetException e) {
     UIUtils.showErrorDialog(null, null, null, e.getTargetException());
   } catch (InterruptedException e) {
     // do nothing
   }
 }
示例#22
0
 @Override
 public DBAAuthInfo promptUserCredentials(String prompt, String userName, String userPassword) {
   // Ask user
   final Shell shell = DBeaverUI.getActiveWorkbenchShell();
   final BaseAuthDialog authDialog = new BaseAuthDialog(shell, prompt);
   authDialog.setUserName(userName);
   authDialog.setUserPassword(userPassword);
   final RunnableWithResult<Boolean> binder =
       new RunnableWithResult<Boolean>() {
         @Override
         public void run() {
           result = (authDialog.open() == IDialogConstants.OK_ID);
         }
       };
   UIUtils.runInUI(shell, binder);
   if (binder.getResult() != null && binder.getResult()) {
     return authDialog.getAuthInfo();
   } else {
     return null;
   }
 }
示例#23
0
 @Override
 public void updateElement(UIElement element, Map parameters) {
   List<OracleSourceObject> objects = new ArrayList<>();
   IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
   if (partSite != null) {
     final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
     if (selectionProvider != null) {
       ISelection selection = selectionProvider.getSelection();
       if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
         for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
           final Object item = iter.next();
           final OracleSourceObject sourceObject =
               RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
           if (sourceObject != null) {
             objects.add(sourceObject);
           }
         }
       }
     }
     if (objects.isEmpty()) {
       final IWorkbenchPart activePart = partSite.getPart();
       final OracleSourceObject sourceObject =
           RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
       if (sourceObject != null) {
         objects.add(sourceObject);
       }
     }
   }
   if (!objects.isEmpty()) {
     if (objects.size() > 1) {
       element.setText("Compile " + objects.size() + " objects");
     } else {
       final OracleSourceObject sourceObject = objects.get(0);
       String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
       element.setText("Compile " + objectType /* + " '" + sourceObject.getName() + "'"*/);
     }
   }
 }
 private void createLink(IWorkbenchWindow workbenchWindow, IFolder folder, String fsFolder) {
   final File externalFolder = new File(fsFolder);
   try {
     final IFolder linkedFolder = folder.getFolder(externalFolder.getName());
     workbenchWindow.run(
         true,
         true,
         new IRunnableWithProgress() {
           @Override
           public void run(IProgressMonitor monitor)
               throws InvocationTargetException, InterruptedException {
             try {
               linkedFolder.createLink(externalFolder.toURI(), IResource.NONE, monitor);
             } catch (CoreException e) {
               throw new InvocationTargetException(e);
             }
           }
         });
   } catch (InvocationTargetException e) {
     UIUtils.showErrorDialog(workbenchWindow.getShell(), "Create link", "Can't create link", e);
   } catch (InterruptedException e) {
     // skip
   }
 }
  @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;
  }
示例#27
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<OracleSourceObject> objects = getSelectedObjects(event);
    if (!objects.isEmpty()) {
      final Shell activeShell = HandlerUtil.getActiveShell(event);
      if (objects.size() == 1) {
        final OracleSourceObject unit = objects.get(0);

        DBCSourceHost sourceHost = null;
        final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
        if (activePart != null) {
          sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
          if (sourceHost == null) {
            sourceHost = activePart.getAdapter(DBCSourceHost.class);
          }
        }
        if (sourceHost != null && sourceHost.getSourceObject() != unit) {
          sourceHost = null;
        }

        final DBCCompileLog compileLog =
            sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
        compileLog.clearLog();
        Throwable error = null;
        try {
          DBeaverUI.runInProgressService(
              new DBRRunnableWithProgress() {
                @Override
                public void run(DBRProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    compileUnit(monitor, compileLog, unit);
                  } catch (DBCException e) {
                    throw new InvocationTargetException(e);
                  }
                }
              });
          if (compileLog.getError() != null) {
            error = compileLog.getError();
          }
        } catch (InvocationTargetException e) {
          error = e.getTargetException();
        } catch (InterruptedException e) {
          return null;
        }
        if (error != null) {
          UIUtils.showErrorDialog(activeShell, "Unexpected compilation error", null, error);
        } else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
          // Show compile errors
          int line = -1, position = -1;
          StringBuilder fullMessage = new StringBuilder();
          for (DBCCompileError oce : compileLog.getErrorStack()) {
            fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
            if (line < 0) {
              line = oce.getLine();
              position = oce.getPosition();
            }
          }

          // If compiled object is currently open in editor - try to position on error line
          if (sourceHost != null
              && sourceHost.getSourceObject() == unit
              && line > 0
              && position > 0) {
            sourceHost.positionSource(line, position);
            activePart.getSite().getPage().activate(activePart);
          }

          String errorTitle = unit.getName() + " compilation failed";
          if (sourceHost != null) {
            sourceHost.setCompileInfo(errorTitle, true);
            sourceHost.showCompileLog();
          }
          UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
        } else {
          String message = unit.getName() + " compiled successfully";
          if (sourceHost != null) {
            sourceHost.setCompileInfo(message, true);
          }
          UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
        }
      } else {
        OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
        dialog.open();
      }
    }
    return null;
  }
 @Override
 public IStatus runInUIThread(DBRProgressMonitor monitor) {
   UIUtils.showErrorDialog(
       getDisplay().getActiveShell(), "Data export error", error.getMessage(), error);
   return Status.OK_STATUS;
 }
示例#29
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Color background = JFaceColors.getBannerBackground(parent.getDisplay());
    // Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
    parent.setBackground(background);

    Composite group = new Composite(parent, SWT.NONE);
    group.setBackground(background);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 20;
    layout.marginWidth = 20;
    group.setLayout(layout);

    GridData gd;

    IProduct product = Platform.getProduct();
    String productVersion = DBeaverCore.getVersion().toString();

    Label titleLabel = new Label(group, SWT.NONE);
    titleLabel.setBackground(background);
    titleLabel.setFont(TITLE_FONT);
    titleLabel.setText(product.getProperty(PRODUCT_PROP_SUB_TITLE));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    titleLabel.setLayoutData(gd);
    titleLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDoubleClick(MouseEvent e) {
            BusyIndicator.showWhile(
                getShell().getDisplay(),
                new Runnable() {
                  @Override
                  public void run() {
                    // Do not create InstallationDialog directly
                    // but execute "org.eclipse.ui.help.installationDialog" command
                    IWorkbenchWindow workbenchWindow =
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    IHandlerService service = workbenchWindow.getService(IHandlerService.class);
                    if (service != null) {
                      try {
                        service.executeCommand(
                            "org.eclipse.ui.help.installationDialog", null); // $NON-NLS-1$
                      } catch (Exception e1) {
                        // just ignore error
                      }
                    }
                  }
                });
          }
        });

    Label imageLabel = new Label(group, SWT.NONE);
    imageLabel.setBackground(background);

    gd = new GridData();
    gd.verticalAlignment = GridData.BEGINNING;
    gd.horizontalAlignment = GridData.CENTER;
    gd.grabExcessHorizontalSpace = true;
    imageLabel.setLayoutData(gd);
    imageLabel.setImage(ABOUT_IMAGE);

    Label versionLabel = new Label(group, SWT.NONE);
    versionLabel.setBackground(background);
    versionLabel.setText(CoreMessages.dialog_about_label_version + productVersion);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    versionLabel.setLayoutData(gd);

    Label authorLabel = new Label(group, SWT.NONE);
    authorLabel.setBackground(background);
    authorLabel.setText(product.getProperty(PRODUCT_PROP_COPYRIGHT));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    authorLabel.setLayoutData(gd);

    Link siteLink =
        UIUtils.createLink(
            group,
            UIUtils.makeAnchor(product.getProperty(PRODUCT_PROP_WEBSITE)),
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                UIUtils.launchProgram(e.text);
              }
            });
    siteLink.setBackground(background);
    gd = new GridData();
    gd.horizontalAlignment = GridData.CENTER;
    siteLink.setLayoutData(gd);

    Link emailLink =
        UIUtils.createLink(
            group,
            UIUtils.makeAnchor(product.getProperty(PRODUCT_PROP_EMAIL)),
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                UIUtils.launchProgram("mailto:" + e.text); // $NON-NLS-1$
              }
            });
    emailLink.setBackground(background);
    gd = new GridData();
    gd.horizontalAlignment = GridData.CENTER;
    emailLink.setLayoutData(gd);

    return parent;
  }
示例#30
0
 @Override
 public void showError(@NotNull String title, @Nullable String message) {
   UIUtils.showErrorDialog(null, title, message);
 }