提交 dd16e850 编写于 作者: S Serge Rider

SQL presentatiomn commands state enablement

上级 47513449
......@@ -27,8 +27,8 @@ import org.eclipse.ui.contexts.IContextService;
import org.jkiss.dbeaver.model.runtime.features.DBRFeature;
import org.jkiss.dbeaver.model.runtime.features.DBRFeatureRegistry;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.DBeaverUIConstants;
import org.jkiss.dbeaver.ui.actions.DataSourcePropertyTester;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer;
import org.jkiss.dbeaver.ui.editors.entity.EntityEditor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
......@@ -198,7 +198,7 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
}
// Refresh auto-commit element state (#3315)
DataSourcePropertyTester.fireCommandRefresh(CoreCommands.CMD_TOGGLE_AUTOCOMMIT);
ActionUtils.fireCommandRefresh(CoreCommands.CMD_TOGGLE_AUTOCOMMIT);
}
finally {
contextService.deferUpdates(false);
......
......@@ -22,7 +22,6 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.dbeaver.runtime.sql.SQLControlCommandHandler;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorPresentation;
import org.jkiss.utils.CommonUtils;
......@@ -35,18 +34,12 @@ public class SQLPresentationDescriptor extends AbstractContextDescriptor {
public static final String EXTENSION_ID = "org.jkiss.dbeaver.sqlPresentation"; //$NON-NLS-1$
public enum ActivationType {
HIDDEN,
VISIBLE,
MAXIMIZED,
}
private final String id;
private final String label;
private final String description;
private final ObjectType implClass;
private final DBPImage icon;
private final ActivationType activationType;
private final SQLEditorPresentation.ActivationType activationType;
public SQLPresentationDescriptor(IConfigurationElement config)
{
......@@ -58,9 +51,9 @@ public class SQLPresentationDescriptor extends AbstractContextDescriptor {
this.icon = iconToImage(config.getAttribute(RegistryConstants.ATTR_ICON));
String activationStr = config.getAttribute("activation");
if (CommonUtils.isEmpty(activationStr)) {
this.activationType = ActivationType.HIDDEN;
this.activationType = SQLEditorPresentation.ActivationType.HIDDEN;
} else {
this.activationType = ActivationType.valueOf(activationStr.toUpperCase(Locale.ENGLISH));
this.activationType = SQLEditorPresentation.ActivationType.valueOf(activationStr.toUpperCase(Locale.ENGLISH));
}
}
......@@ -80,7 +73,7 @@ public class SQLPresentationDescriptor extends AbstractContextDescriptor {
return icon;
}
public ActivationType getActivationType() {
public SQLEditorPresentation.ActivationType getActivationType() {
return activationType;
}
......
......@@ -19,8 +19,6 @@ package org.jkiss.dbeaver.ui.actions;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
......@@ -99,20 +97,6 @@ public class DataSourcePropertyTester extends PropertyTester
ActionUtils.evaluatePropertyState(NAMESPACE + "." + propName);
}
public static void fireCommandRefresh(final String commandID)
{
// Update commands
final ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
UIUtils.asyncExec(new Runnable() {
@Override
public void run() {
commandService.refreshElements(commandID, null);
}
});
}
}
public static class QMService implements IPluginService {
private QMEventsHandler qmHandler;
......@@ -146,7 +130,7 @@ public class DataSourcePropertyTester extends PropertyTester
// Fire transactional mode change
DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_TRANSACTIONAL);
DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_TRANSACTION_ACTIVE);
DataSourcePropertyTester.fireCommandRefresh(CoreCommands.CMD_TOGGLE_AUTOCOMMIT);
ActionUtils.fireCommandRefresh(CoreCommands.CMD_TOGGLE_AUTOCOMMIT);
}
});
}
......
......@@ -36,7 +36,6 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
......@@ -142,7 +141,7 @@ public class SQLEditor extends SQLEditorBase implements
private static Image IMG_OUTPUT = DBeaverIcons.getImage(UIIcon.SQL_PAGE_OUTPUT);
private static Image IMG_OUTPUT_ALERT = DBeaverIcons.getImage(UIIcon.SQL_PAGE_OUTPUT_ALERT);
private static final String TOOLBAR_CONTRIBUTION_ID = "toolbar:org.jkiss.dbeaver.ui.editors.sql.toolbar.switch";
private static final String TOOLBAR_CONTRIBUTION_ID = "toolbar:org.jkiss.dbeaver.ui.editors.sql.toolbar.side";
private static final String TOOLBAR_GROUP_ADDITIONS = IWorkbenchActionConstants.MB_ADDITIONS;
public static final String VAR_CONNECTION_NAME = "connectionName";
......@@ -156,7 +155,6 @@ public class SQLEditor extends SQLEditorBase implements
private CustomSashForm resultsSash;
@Nullable
private CustomSashForm presentationSash;
private Control editorControl;
private CTabFolder resultTabs;
private SQLLogPanel logViewer;
......@@ -176,7 +174,7 @@ public class SQLEditor extends SQLEditorBase implements
private final List<SQLQuery> runningQueries = new ArrayList<>();
private QueryResultsContainer curResultsContainer;
private Image editorImage;
private ToolBarManager viewsToolBar;
private ToolBarManager sideToolBar;
private SQLPresentationDescriptor extraPresentationDescriptor;
private SQLEditorPresentation extraPresentation;
......@@ -355,7 +353,7 @@ public class SQLEditor extends SQLEditorBase implements
private class OutputLogWriter extends Writer {
@Override
public void write(@NotNull final char[] cbuf, final int off, final int len) throws IOException {
public void write(@NotNull final char[] cbuf, final int off, final int len) {
UIUtils.syncExec(() -> {
if (!outputViewer.isDisposed()) {
outputViewer.getOutputWriter().write(cbuf, off, len);
......@@ -496,42 +494,47 @@ public class SQLEditor extends SQLEditorBase implements
resultsSash.setSashWidth(5);
UIUtils.setHelp(resultsSash, IHelpContextIds.CTX_SQL_EDITOR);
SashForm editorSash = resultsSash;
Composite editorContainer;
Composite sqlEditorPanel = UIUtils.createPlaceholder(resultsSash, 2, 0);
createSideBar(sqlEditorPanel);
// divides SQL editor presentations
extraPresentationDescriptor = SQLPresentationRegistry.getInstance().getPresentation(this);
if (extraPresentationDescriptor != null) {
presentationSash = UIUtils.createPartDivider(
this,
resultsSash,
sqlEditorPanel,
((resultSetOrientation.getSashOrientation() == SWT.VERTICAL) ? SWT.HORIZONTAL : SWT.VERTICAL) | SWT.SMOOTH);
presentationSash.setSashWidth(5);
editorSash = presentationSash;
presentationSash.setLayoutData(new GridData(GridData.FILL_BOTH));
editorContainer = presentationSash;
} else {
editorContainer = sqlEditorPanel;
}
super.createPartControl(editorSash);
super.createPartControl(editorContainer);
getEditorControlWrapper().setLayoutData(new GridData(GridData.FILL_BOTH));
if (extraPresentationDescriptor != null) {
Composite pPlaceholder = new Composite(editorSash, SWT.NONE);
Composite pPlaceholder = new Composite(presentationSash, SWT.NONE);
pPlaceholder.setLayout(new FillLayout());
switch (extraPresentationDescriptor.getActivationType()) {
case HIDDEN:
editorSash.setMaximizedControl(editorSash.getChildren()[0]);
presentationSash.setMaximizedControl(presentationSash.getChildren()[0]);
break;
case MAXIMIZED:
case VISIBLE:
extraPresentation.createPresentation(pPlaceholder, this);
if (extraPresentationDescriptor.getActivationType() == SQLPresentationDescriptor.ActivationType.MAXIMIZED) {
if (editorSash.getChildren()[1] != null) {
editorSash.setMaximizedControl(pPlaceholder);
if (extraPresentationDescriptor.getActivationType() == SQLEditorPresentation.ActivationType.MAXIMIZED) {
if (presentationSash.getChildren()[1] != null) {
presentationSash.setMaximizedControl(pPlaceholder);
}
}
break;
}
}
editorControl = editorSash.getChildren()[0];
getSite().setSelectionProvider(new DynamicSelectionProvider());
createResultTabs();
......@@ -557,6 +560,29 @@ public class SQLEditor extends SQLEditorBase implements
UIUtils.asyncExec(this::onDataSourceChange);
}
private void createSideBar(Composite sqlEditorPanel) {
sideToolBar = new ToolBarManager(SWT.VERTICAL);
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_EXECUTE_STATEMENT));
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_EXECUTE_STATEMENT_NEW));
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_EXECUTE_SCRIPT));
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_EXECUTE_SCRIPT_NEW));
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_EXPLAIN_PLAN));
sideToolBar.add(new GroupMarker(TOOLBAR_GROUP_ADDITIONS));
sideToolBar.add(new Separator());
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_SHOW_OUTPUT, CommandContributionItem.STYLE_CHECK));
sideToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_SHOW_LOG, CommandContributionItem.STYLE_CHECK));
final IMenuService menuService = getSite().getService(IMenuService.class);
if (menuService != null) {
menuService.populateContributionManager(sideToolBar, TOOLBAR_CONTRIBUTION_ID);
}
sideToolBar.update(true);
ToolBar toolBar = sideToolBar.createControl(sqlEditorPanel);
GridData gd = new GridData(GridData.FILL_VERTICAL | GridData.VERTICAL_ALIGN_BEGINNING);
gd.verticalIndent = 5;
toolBar.setLayoutData(gd);
}
/**
* Sets focus in current editor.
* This function is called on drag-n-drop and some other operations
......@@ -619,23 +645,6 @@ public class SQLEditor extends SQLEditorBase implements
});
resultTabs.setSimple(true);
//resultTabs.setMRUVisible(true);
{
viewsToolBar = new ToolBarManager(SWT.HORIZONTAL | SWT.RIGHT | SWT.WRAP);
viewsToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_SHOW_OUTPUT, CommandContributionItem.STYLE_CHECK,
CoreMessages.sql_editor_resultset_tool_item_log, null, null, true));
viewsToolBar.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_SHOW_LOG, CommandContributionItem.STYLE_CHECK,
CoreMessages.sql_editor_resultset_tool_item_output, null, null, true));
viewsToolBar.add(new GroupMarker(TOOLBAR_GROUP_ADDITIONS));
final IMenuService menuService = getSite().getService(IMenuService.class);
if (menuService != null) {
menuService.populateContributionManager(viewsToolBar, TOOLBAR_CONTRIBUTION_ID);
}
viewsToolBar.update(true);
resultTabs.setTopRight(viewsToolBar.createControl(resultTabs));
}
resultTabs.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
......@@ -760,7 +769,7 @@ public class SQLEditor extends SQLEditorBase implements
private ToolItem getViewToolItem(String commandId) {
ToolItem viewItem = null;
for (ToolItem item : viewsToolBar.getControl().getItems()) {
for (ToolItem item : sideToolBar.getControl().getItems()) {
Object data = item.getData();
if (data instanceof CommandContributionItem) {
if (((CommandContributionItem) data).getCommand() != null && commandId.equals(((CommandContributionItem) data).getCommand().getId())) {
......@@ -797,9 +806,18 @@ public class SQLEditor extends SQLEditorBase implements
return resultsSash.getMaximizedControl() != null;
}
public boolean isExtraPresentationVisible() {
return extraPresentation != null &&
(presentationSash.getMaximizedControl() == null || presentationSash.getMaximizedControl() == getExtraPresentationControl());
public SQLEditorPresentation.ActivationType getExtraPresentationState() {
if (extraPresentation == null) {
return SQLEditorPresentation.ActivationType.HIDDEN;
}
Control maximizedControl = presentationSash.getMaximizedControl();
if (maximizedControl == getExtraPresentationControl()) {
return SQLEditorPresentation.ActivationType.MAXIMIZED;
} else if (maximizedControl == getEditorControlWrapper()) {
return SQLEditorPresentation.ActivationType.HIDDEN;
} else {
return SQLEditorPresentation.ActivationType.VISIBLE;
}
}
public void showExtraPresentation(boolean show, boolean maximize) {
......@@ -808,9 +826,9 @@ public class SQLEditor extends SQLEditorBase implements
}
if (!show) {
boolean epHasFocus = UIUtils.hasFocus(getExtraPresentationControl());
presentationSash.setMaximizedControl(editorControl);
presentationSash.setMaximizedControl(presentationSash.getChildren()[0]);
if (epHasFocus) {
editorControl.setFocus();
getEditorControlWrapper().setFocus();
}
} else {
if (extraPresentation == null) {
......@@ -868,7 +886,7 @@ public class SQLEditor extends SQLEditorBase implements
}
}
} else {
editorControl.setFocus();
getEditorControlWrapper().setFocus();
}
}
......@@ -903,7 +921,7 @@ public class SQLEditor extends SQLEditorBase implements
}
@Override
protected void doSetInput(IEditorInput editorInput) throws CoreException
protected void doSetInput(IEditorInput editorInput)
{
// Check for file existence
try {
......@@ -1350,7 +1368,7 @@ public class SQLEditor extends SQLEditorBase implements
reloadSyntaxRules();
if (getDataSourceContainer() == null) {
resultsSash.setMaximizedControl(editorControl);
resultsSash.setMaximizedControl(getEditorControlWrapper());
} else {
resultsSash.setMaximizedControl(null);
}
......@@ -2287,7 +2305,7 @@ public class SQLEditor extends SQLEditorBase implements
return;
}
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.MAXIMIZE_EDITOR_ON_SCRIPT_EXECUTE)) {
resultsSash.setMaximizedControl(editorControl);
resultsSash.setMaximizedControl(getEditorControlWrapper());
}
});
} finally {
......
......@@ -109,6 +109,7 @@ public abstract class SQLEditorBase extends BaseTextEditor implements IErrorVisu
private boolean hasVerticalRuler = true;
private SQLTemplatesPage templatesPage;
private IPropertyChangeListener themeListener;
private SQLEditorControl editorControl;
public SQLEditorBase()
{
......@@ -211,7 +212,8 @@ public abstract class SQLEditorBase extends BaseTextEditor implements IErrorVisu
{
setRangeIndicator(new DefaultRangeIndicator());
super.createPartControl(new SQLEditorControl(parent, this));
editorControl = new SQLEditorControl(parent, this);
super.createPartControl(editorControl);
ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
projectionSupport = new ProjectionSupport(
......@@ -271,6 +273,10 @@ public abstract class SQLEditorBase extends BaseTextEditor implements IErrorVisu
}
}
public SQLEditorControl getEditorControlWrapper() {
return editorControl;
}
@Override
public void updatePartControl(IEditorInput input)
{
......
......@@ -155,19 +155,7 @@ public class SQLEditorContributor extends TextEditorActionContributor
@Override
public void contributeToToolBar(IToolBarManager manager)
{
if (!isNestedEditor()) {
super.contributeToToolBar(manager);
if (manager.find(CoreCommands.CMD_EXECUTE_STATEMENT) == null) {
manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_EXECUTE_STATEMENT));
manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_EXECUTE_STATEMENT_NEW));
manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_EXECUTE_SCRIPT));
manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_EXECUTE_SCRIPT_NEW));
//manager.add(new Separator());
manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_EXPLAIN_PLAN));
//manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_ANALYSE_STATEMENT));
//manager.add(ActionUtils.makeCommandContribution(getPage().getWorkbenchWindow(), CoreCommands.CMD_VALIDATE_STATEMENT));
}
}
// Nothing here. All contributions moved to editor side bar
}
@Override
......
......@@ -22,4 +22,9 @@ public interface SQLEditorPresentation {
void createPresentation(Composite parent, SQLEditor editor);
enum ActivationType {
HIDDEN,
VISIBLE,
MAXIMIZED,
}
}
......@@ -313,4 +313,12 @@ public class ActionUtils
}
}
public static void fireCommandRefresh(final String commandID)
{
// Update commands
final ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
UIUtils.asyncExec(() -> commandService.refreshElements(commandID, null));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册