Skip to content

Commit

Permalink
SQL editor listener model
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Jul 14, 2018
1 parent 0c1b19b commit 64a49c8
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -191,6 +191,8 @@ public class SQLEditor extends SQLEditorBase implements
private Map<SQLPresentationPanelDescriptor, SQLEditorPresentationPanel> extraPresentationPanels = new HashMap<>();
private SQLEditorPresentationPanel extraPresentationCurrentPanel;

private final List<SQLEditorListener> listeners = new ArrayList<>();

public SQLEditor()
{
super();
Expand Down Expand Up @@ -357,6 +359,18 @@ private void releaseContainer() {
}
}

public void addListener(SQLEditorListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
}

public void removeListener(SQLEditorListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
}

private class OutputLogWriter extends Writer {
@Override
public void write(@NotNull final char[] cbuf, final int off, final int len) {
Expand Down Expand Up @@ -1181,6 +1195,13 @@ public void setFocus()

public void explainQueryPlan()
{
// Notify listeners
synchronized (listeners) {
for (SQLEditorListener listener : listeners) {
listener.beforeQueryPlanExplain();
}
}

final SQLScriptElement scriptElement = extractActiveQuery();
if (scriptElement == null) {
setStatus(CoreMessages.editors_sql_status_empty_query_string, DBPMessageType.ERROR);
Expand Down Expand Up @@ -1269,6 +1290,14 @@ public void processSQL(boolean newTab, boolean script, SQLQueryTransformer trans
setStatus(CoreMessages.editors_sql_status_cant_obtain_document, DBPMessageType.ERROR);
return;
}

// Notify listeners
synchronized (listeners) {
for (SQLEditorListener listener : listeners) {
listener.beforeQueryExecute(script, newTab);
}
}

List<SQLScriptElement> elements;
if (script) {
// Execute all SQL statements consequently
Expand Down Expand Up @@ -1554,6 +1583,10 @@ public void beforeDisconnect()
@Override
public void dispose()
{
if (extraPresentation != null) {
extraPresentation.dispose();
extraPresentation = null;
}
// Release ds container
releaseContainer();
closeAllJobs();
Expand Down
@@ -0,0 +1,40 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql;

import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.sql.SQLQuery;

/**
* SQLEditorListener
*
* @author Serge Rider
*/
public interface SQLEditorListener
{
void onConnect(DBPDataSourceContainer container);

void onDisconnect(DBPDataSourceContainer container);

void beforeQueryExecute(boolean script, boolean newTabs);

void afterQueryExecute(boolean script, boolean newTabs);

void onQueryChange(SQLQuery oldQuery, SQLQuery newQuery);

void beforeQueryPlanExplain();
}
@@ -0,0 +1,56 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql;

import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.sql.SQLQuery;

/**
* SQLEditorListenerDefault
*/
public class SQLEditorListenerDefault implements SQLEditorListener
{
@Override
public void onConnect(DBPDataSourceContainer container) {

}

@Override
public void onDisconnect(DBPDataSourceContainer container) {

}

@Override
public void beforeQueryExecute(boolean script, boolean newTabs) {

}

@Override
public void afterQueryExecute(boolean script, boolean newTabs) {

}

@Override
public void onQueryChange(SQLQuery oldQuery, SQLQuery newQuery) {

}

@Override
public void beforeQueryPlanExplain() {

}
}
Expand Up @@ -22,6 +22,8 @@ public interface SQLEditorPresentation {

void createPresentation(Composite parent, SQLEditor editor);

void dispose();

enum ActivationType {
HIDDEN,
VISIBLE,
Expand Down

0 comments on commit 64a49c8

Please sign in to comment.