Exemplo n.º 1
0
  public void setConnection(WbConnection aConnection) {
    shouldRetrieve = true;
    reset();

    this.dbConnection = aConnection;
    this.reader = TriggerReaderFactory.createReader(dbConnection);
    if (source != null) source.setDatabaseConnection(aConnection);
    if (compileAction != null) compileAction.setConnection(aConnection);
  }
Exemplo n.º 2
0
  public void reset() {
    if (!initialized) return;

    WbSwingUtilities.invoke(
        () -> {
          triggerList.reset();
          source.reset();
        });
  }
Exemplo n.º 3
0
 public void dispose() {
   reset();
   WbAction.dispose(dropAction, compileAction);
   if (source != null) source.dispose();
   if (findPanel != null) findPanel.dispose();
   if (triggerList != null) {
     triggerList.dispose();
   }
   Settings.getInstance().removePropertyChangeListener(this);
 }
Exemplo n.º 4
0
  protected void retrieveCurrentTrigger() {
    if (this.dbConnection == null || this.reader == null) return;
    int row = this.triggerList.getSelectedRow();
    if (!WbSwingUtilities.isConnectionIdle(this, this.dbConnection)) return;

    if (row < 0) return;

    final String triggerName =
        this.triggerList.getValueAsString(row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_NAME);
    final String tableName =
        this.triggerList.getValueAsString(
            row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_TABLE);
    final String comment =
        this.triggerList.getValueAsString(
            row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_COMMENT);

    Container parent = this.getParent();
    WbSwingUtilities.showWaitCursor(parent);

    try {
      if (dbConnection.getProfile().getUseSeparateConnectionPerTab()) {
        levelChanger.changeIsolationLevel(dbConnection);
      }
      dbConnection.setBusy(true);

      try {
        TableIdentifier tbl = null;
        if (tableName != null) {
          tbl = new TableIdentifier(tableName, dbConnection);
          if (tbl.getCatalog() == null) tbl.setCatalog(currentCatalog);
          if (tbl.getSchema() == null) tbl.setSchema(currentSchema);
        }

        DropType dropType =
            DbExplorerSettings.getDropTypeToGenerate(TriggerDefinition.TRIGGER_TYPE_NAME);

        String sql =
            reader.getTriggerSource(currentCatalog, currentSchema, triggerName, tbl, comment, true);
        Object obj = triggerList.getUserObject(row);

        boolean isReplace = SqlUtil.isReplaceDDL(sql, dbConnection, dropType);

        if (dropType != DropType.none
            && obj instanceof TriggerDefinition
            && sql != null
            && !isReplace) {
          TriggerDefinition trg = (TriggerDefinition) obj;
          String drop = trg.getDropStatement(dbConnection, dropType == DropType.cascaded);
          if (StringUtil.isNonBlank(drop)) {
            sql = drop + getDelimiterForDrop() + "\n\n" + sql;
          }
        }

        final String sourceSql = sql == null ? "" : sql;
        WbSwingUtilities.invoke(
            () -> {
              source.setText(sourceSql, triggerName, TRG_TYPE_NAME);
            });

      } catch (Throwable ex) {
        LogMgr.logError(
            "TriggerListPanel.retrieveTriggerSource() thread", "Could not read trigger source", ex);
        source.setPlainText(ExceptionUtil.getDisplay(ex));
      }
    } finally {
      WbSwingUtilities.showDefaultCursor(parent);
      levelChanger.restoreIsolationLevel(dbConnection);
      dbConnection.setBusy(false);
    }

    if (this.triggerList.getSelectedRowCount() == 1) {
      EventQueue.invokeLater(
          () -> {
            source.setCaretPosition(0, false);
            if (DbExplorerSettings.getSelectSourcePanelAfterRetrieve()) {
              source.requestFocusInWindow();
            }
          });
    }
  }
Exemplo n.º 5
0
 @Override
 public void propertyChange(PropertyChangeEvent evt) {
   if (source != null) {
     source.allowEditing(DbExplorerSettings.allowSourceEditing());
   }
 }
Exemplo n.º 6
0
  private void _initGui() {
    if (initialized) return;

    Reloadable sourceReload =
        () -> {
          if (dbConnection == null) return;
          if (dbConnection.isBusy()) return;
          retrieveCurrentTrigger();
        };

    this.source = new DbObjectSourcePanel(parentWindow, sourceReload);
    if (DbExplorerSettings.allowSourceEditing()) {
      source.allowEditing(true);
    }

    JPanel listPanel = new JPanel();
    this.triggerList = new WbTable(true, false, false);

    this.triggerList.setRendererSetup(RendererSetup.getBaseSetup());
    this.triggerList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    this.triggerList.setCellSelectionEnabled(false);
    this.triggerList.setColumnSelectionAllowed(false);
    this.triggerList.setRowSelectionAllowed(true);
    this.triggerList.getSelectionModel().addListSelectionListener(this);
    this.triggerList
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.triggerList.addTableModelListener(this);
    triggerList.setReadOnly(true);

    findPanel = new QuickFilterPanel(this.triggerList, false, "triggerlist");
    findPanel.setFilterOnType(DbExplorerSettings.getFilterDuringTyping());
    findPanel.setAlwaysUseContainsFilter(DbExplorerSettings.getUsePartialMatch());

    ReloadAction a = new ReloadAction(this);
    a.setUseLabelIconSize(true);
    this.findPanel.addToToolbar(a, true, false);
    a.getToolbarButton().setToolTipText(ResourceMgr.getString("TxtRefreshTriggerList"));
    listPanel.setLayout(new BorderLayout());
    listPanel.add((JPanel) findPanel, BorderLayout.NORTH);

    this.splitPane = new WbSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    this.splitPane.setOneTouchExpandable(true);
    this.splitPane.setDividerSize(6);
    WbScrollPane scroll = new WbScrollPane(this.triggerList);

    listPanel.add(scroll, BorderLayout.CENTER);

    infoLabel = new SummaryLabel("");
    listPanel.add(infoLabel, BorderLayout.SOUTH);

    this.splitPane.setLeftComponent(listPanel);
    this.splitPane.setRightComponent(source);
    this.splitPane.setDividerBorder(WbSwingUtilities.EMPTY_BORDER);
    this.setLayout(new BorderLayout());
    this.add(splitPane, BorderLayout.CENTER);

    WbTraversalPolicy pol = new WbTraversalPolicy();
    pol.setDefaultComponent((JPanel) findPanel);
    pol.addComponent((JPanel) findPanel);
    pol.addComponent(this.triggerList);
    this.setFocusTraversalPolicy(pol);
    this.reset();

    WbSelectionModel list = WbSelectionModel.Factory.createFacade(triggerList.getSelectionModel());
    this.dropAction = new DropDbObjectAction(this, list, this);
    triggerList.addPopupAction(dropAction, true);
    this.compileAction = new CompileDbObjectAction(this, list);
    triggerList.addPopupAction(compileAction, false);

    if (dbConnection != null) {
      setConnection(dbConnection);
    }
    this.splitPane.setDividerLocation(0.5d);

    initialized = true;

    restoreSettings();
    if (workspaceProperties != null) {
      readSettings(workspaceProperties, workspaceProperties.getFilterPrefix());
      workspaceProperties = null;
    }
    Settings.getInstance()
        .addPropertyChangeListener(this, DbExplorerSettings.PROP_ALLOW_SOURCE_EDITING);
  }