예제 #1
0
 @Override
 public DBNNode getRootNode() {
   DBNProject projectNode =
       getModel()
           .getRoot()
           .getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject());
   return projectNode != null ? projectNode : getModel().getRoot();
 }
예제 #2
0
 @Override
 public String getName() {
   if (DBeaverCore.getGlobalPreferenceStore()
       .getBoolean(DBeaverPreferences.NAVIGATOR_EDITOR_FULL_NAME)) {
     return node.getNodeFullName();
   } else {
     return node.getName();
   }
 }
예제 #3
0
  @Override
  public IPersistableElement getPersistable() {
    if (getExecutionContext() == null
        || !DBeaverCore.getGlobalPreferenceStore()
            .getBoolean(DBeaverPreferences.UI_KEEP_DATABASE_EDITORS)) {
      return null;
    }

    return this;
  }
예제 #4
0
 private DBPPreferenceStore getPreferences() {
   DBPPreferenceStore store = null;
   DBPDataSource dataSource = editor.getDataSource();
   if (dataSource != null) {
     store = dataSource.getContainer().getPreferenceStore();
   }
   if (store == null) {
     store = DBeaverCore.getGlobalPreferenceStore();
   }
   return store;
 }
예제 #5
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
  public IAdaptable createElement(IMemento memento) {
    // Get the file name.
    String fileName = memento.getString(TAG_PATH);
    if (!CommonUtils.isEmpty(fileName)) {
      // Make sure that core is initialized
      DBeaverCore.getInstance();

      IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName));
      if (file != null) {
        return new ERDEditorInput(file);
      }
    }
    return null;
  }
예제 #7
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static void updateMainWindowTitle(IWorkbenchWindow window) {
   IProject activeProject = DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
   IProduct product = Platform.getProduct();
   String title = product == null ? "Unknown" : product.getName(); // $NON-NLS-1$
   if (activeProject != null) {
     title += " - " + activeProject.getName(); // $NON-NLS-1$
   }
   IWorkbenchPage activePage = window.getActivePage();
   if (activePage != null) {
     IEditorPart activeEditor = activePage.getActiveEditor();
     if (activeEditor != null) {
       title += " - [ " + activeEditor.getTitle() + " ]";
     }
   }
   window.getShell().setText(title);
 }
예제 #8
0
  private void createProject(DBRProgressMonitor monitor) throws DBException, CoreException {
    IWorkspace workspace = DBeaverCore.getInstance().getWorkspace();
    IProject project = workspace.getRoot().getProject(data.getName());
    if (project.exists()) {
      throw new DBException(
          NLS.bind(CoreMessages.dialog_project_create_wizard_error_already_exists, data.getName()));
    }
    project.create(monitor.getNestedMonitor());

    project.open(monitor.getNestedMonitor());

    if (!CommonUtils.isEmpty(data.getDescription())) {
      final IProjectDescription description = workspace.newProjectDescription(project.getName());
      description.setComment(data.getDescription());
      project.setDescription(description, monitor.getNestedMonitor());
    }
  }
예제 #9
0
  @Override
  public boolean performFinish() {
    objectsPage.saveState();

    final DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
    store.setValue("MySQL.export.outputFilePattern", this.outputFilePattern);
    store.setValue("MySQL.export.noCreateStatements", noCreateStatements);
    store.setValue("MySQL.export.addDropStatements", addDropStatements);
    store.setValue("MySQL.export.disableKeys", disableKeys);
    store.setValue("MySQL.export.extendedInserts", extendedInserts);
    store.setValue("MySQL.export.dumpEvents", dumpEvents);
    store.setValue("MySQL.export.comments", comments);
    store.setValue("MySQL.export.removeDefiner", removeDefiner);
    store.setValue("MySQL.export.binariesInHex", binariesInHex);
    store.setValue("MySQL.export.showViews", showViews);

    return super.performFinish();
  }
예제 #10
0
  public MySQLExportWizard(Collection<DBSObject> objects) {
    super(objects, MySQLMessages.tools_db_export_wizard_task_name);
    this.method = DumpMethod.NORMAL;
    this.outputFolder = new File(DialogUtils.getCurDialogFolder()); // $NON-NLS-1$ //$NON-NLS-2$

    final DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
    this.outputFilePattern = store.getString("MySQL.export.outputFilePattern");
    if (CommonUtils.isEmpty(this.outputFilePattern)) {
      this.outputFilePattern = "dump-${database}-${timestamp}.sql";
    }
    noCreateStatements =
        CommonUtils.getBoolean(store.getString("MySQL.export.noCreateStatements"), false);
    addDropStatements =
        CommonUtils.getBoolean(store.getString("MySQL.export.addDropStatements"), true);
    disableKeys = CommonUtils.getBoolean(store.getString("MySQL.export.disableKeys"), true);
    extendedInserts = CommonUtils.getBoolean(store.getString("MySQL.export.extendedInserts"), true);
    dumpEvents = CommonUtils.getBoolean(store.getString("MySQL.export.dumpEvents"), false);
    comments = CommonUtils.getBoolean(store.getString("MySQL.export.comments"), false);
    removeDefiner = CommonUtils.getBoolean(store.getString("MySQL.export.removeDefiner"), false);
    binariesInHex = CommonUtils.getBoolean(store.getString("MySQL.export.binariesInHex"), false);
    showViews = CommonUtils.getBoolean(store.getString("MySQL.export.showViews"), false);
  }
예제 #11
0
 private SQLCompletionProposal makeProposalsFromObject(
     DBRProgressMonitor monitor, DBSObject object) {
   DBNNode node =
       DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(monitor, object, false);
   return makeProposalsFromObject(object, node == null ? null : node.getNodeIconDefault());
 }
예제 #12
0
 @Override
 public void createControl(Composite parent) {
   source.loadState(DBeaverCore.getGlobalPreferenceStore());
   source.createControl(parent);
 }
예제 #13
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;
  }
예제 #14
0
 public ProjectExplorerView() {
   DBeaverCore.getInstance().getProjectRegistry().addProjectListener(this);
 }
예제 #15
0
 @Override
 public void dispose() {
   DBeaverCore.getInstance().getProjectRegistry().removeProjectListener(this);
   super.dispose();
 }
예제 #16
0
  @Override
  protected IStatus run(DBRProgressMonitor monitor) {
    RuntimeUtils.setThreadName("SQL script execution");
    statistics = new DBCStatistics();
    try {
      DBCExecutionContext context = getExecutionContext();
      DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
      DBCExecutionPurpose purpose =
          queries.size() > 1 ? DBCExecutionPurpose.USER_SCRIPT : DBCExecutionPurpose.USER;
      try (DBCSession session = context.openSession(monitor, purpose, "SQL Query")) {
        // Set transaction settings (only if autocommit is off)
        QMUtils.getDefaultHandler().handleScriptBegin(session);

        boolean oldAutoCommit = txnManager == null || txnManager.isAutoCommit();
        boolean newAutoCommit = (commitType == SQLScriptCommitType.AUTOCOMMIT);
        if (txnManager != null && !oldAutoCommit && newAutoCommit) {
          txnManager.setAutoCommit(monitor, true);
        }

        monitor.beginTask(this.getName(), queries.size());

        // Notify job start
        if (listener != null) {
          listener.onStartScript();
        }

        resultSetNumber = 0;
        for (int queryNum = 0; queryNum < queries.size(); ) {
          // Execute query
          SQLQuery query = queries.get(queryNum);

          fetchResultSetNumber = resultSetNumber;
          boolean runNext = executeSingleQuery(session, query, true);
          if (!runNext) {
            // Ask to continue
            if (lastError != null) {
              log.error(lastError);
            }
            boolean isQueue = queryNum < queries.size() - 1;
            ExecutionQueueErrorResponse response =
                ExecutionQueueErrorJob.showError(
                    isQueue ? "SQL script execution" : "SQL query execution", lastError, isQueue);

            boolean stopScript = false;
            switch (response) {
              case STOP:
                // just stop execution
                stopScript = true;
                break;
              case RETRY:
                // just make it again
                continue;
              case IGNORE:
                // Just do nothing
                break;
              case IGNORE_ALL:
                errorHandling = SQLScriptErrorHandling.IGNORE;
                break;
            }

            if (stopScript) {
              break;
            }
          }

          // Check monitor
          if (monitor.isCanceled()) {
            break;
          }
          monitor.worked(1);
          queryNum++;
        }
        showExecutionResult(session);
        monitor.done();

        // Commit data
        if (txnManager != null && !oldAutoCommit && commitType != SQLScriptCommitType.AUTOCOMMIT) {
          if (lastError == null || errorHandling == SQLScriptErrorHandling.STOP_COMMIT) {
            if (commitType != SQLScriptCommitType.NO_COMMIT) {
              monitor.beginTask("Commit data", 1);
              txnManager.commit(session);
              monitor.done();
            }
          } else {
            monitor.beginTask("Rollback data", 1);
            txnManager.rollback(session, null);
            monitor.done();
          }
        }

        // Restore transactions settings
        if (txnManager != null && !oldAutoCommit && newAutoCommit) {
          txnManager.setAutoCommit(monitor, false);
        }

        QMUtils.getDefaultHandler().handleScriptEnd(session);

        // Return success
        return new Status(Status.OK, DBeaverCore.getCorePluginID(), "SQL job completed");
      }
    } catch (Throwable ex) {
      return new Status(
          Status.ERROR,
          DBeaverCore.getCorePluginID(),
          "Error during SQL job execution: " + ex.getMessage());
    } finally {
      // Notify job end
      if (listener != null) {
        listener.onEndScript(statistics, lastError != null);
      }
    }
  }