diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/ERDEditorPart.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/ERDEditorPart.java index f6651903909d13bd46359c434f6bce3afe8bc265..a3e07a725cc3eef99af0210a0eb0f204ef012fc0 100644 --- a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/ERDEditorPart.java +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/ERDEditorPart.java @@ -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. @@ -162,6 +162,7 @@ public abstract class ERDEditorPart extends GraphicalEditorWithFlyoutPalette @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { + rootPart = new ScalableFreeformRootEditPart(); editDomain = new DefaultEditDomain(this); setEditDomain(editDomain); @@ -397,7 +398,6 @@ public abstract class ERDEditorPart extends GraphicalEditorWithFlyoutPalette // configure the viewer viewer.getControl().setBackground(UIUtils.getColorRegistry().get(ERDConstants.COLOR_ERD_DIAGRAM_BACKGROUND)); - rootPart = new ScalableFreeformRootEditPart(); viewer.setRootEditPart(rootPart); viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)); @@ -589,9 +589,6 @@ public abstract class ERDEditorPart extends GraphicalEditorWithFlyoutPalette // use selection tool as default entry paletteRoot.setDefaultEntry(selectionTool); - // the marquee selection tool - controls.add(new MarqueeToolEntry()); - if (!isReadOnly()) { // separator PaletteSeparator separator = new PaletteSeparator("tools"); @@ -622,6 +619,46 @@ public abstract class ERDEditorPart extends GraphicalEditorWithFlyoutPalette } } +/* + { + //PaletteDrawer controls = new PaletteDrawer("Diagram", ERDActivator.getImageDescriptor("icons/erd.png")); + PaletteToolbar controls = new PaletteToolbar("Diagram"); + paletteRoot.add(controls); + + controls.add(new ActionToolEntry(new ZoomInAction(rootPart.getZoomManager()))); + controls.add(new ActionToolEntry(new ZoomOutAction(rootPart.getZoomManager()))); + + controls.add(new ActionToolEntry(new DiagramLayoutAction(ERDEditorPart.this))); + controls.add(new ActionToolEntry(new DiagramToggleGridAction())); + controls.add(new ActionToolEntry(new DiagramRefreshAction(ERDEditorPart.this))); + controls.add(new PaletteSeparator()); + { + controls.add(new CommandToolEntry( + IWorkbenchCommandConstants.FILE_SAVE_AS, + ERDMessages.erd_editor_control_action_save_external_format, + UIIcon.PICTURE_SAVE)); + controls.add(new CommandToolEntry( + IWorkbenchCommandConstants.FILE_PRINT, + ERDMessages.erd_editor_control_action_print_diagram, + UIIcon.PRINT)); + } + { + Action configAction = new Action(ERDMessages.erd_editor_control_action_configuration) { + @Override + public void run() + { + UIUtils.showPreferencesFor( + getSite().getShell(), + ERDEditorPart.this, + ERDPreferencePage.PAGE_ID); + } + }; + configAction.setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.CONFIGURATION)); + controls.add(new ActionToolEntry(configAction)); + } + } +*/ + /* PaletteDrawer drawer = new PaletteDrawer("New Component", ERDActivator.getImageDescriptor("icons/connection.gif")); diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/ActionToolEntry.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/ActionToolEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..d1f1ea94eb903e60654ef0905b2e1d5fef8473a3 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/ActionToolEntry.java @@ -0,0 +1,55 @@ +/* + * 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.ext.erd.editor.tools; + +import org.eclipse.gef.Tool; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gef.tools.AbstractTool; +import org.eclipse.gef.tools.SelectionTool; +import org.eclipse.jface.action.IAction; + +public class ActionToolEntry extends ToolEntry { + + private final IAction action; + + public ActionToolEntry(IAction action) { + super(action.getText().replace("&", ""), action.getDescription(), action.getImageDescriptor(), action.getImageDescriptor()); + this.action = action; + + this.setUserModificationPermission(PaletteEntry.PERMISSION_NO_MODIFICATION); + } + + public Tool createTool() { + return new ActionTool(); + } + + public class ActionTool extends SelectionTool { + + @Override + protected String getCommandName() { + return action.getId(); + } + + @Override + public void activate() { + action.run(); + super.activate(); + } + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/CommandToolEntry.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/CommandToolEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..705ff208d491de219c32992caa390039d1b648c6 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/editor/tools/CommandToolEntry.java @@ -0,0 +1,64 @@ +/* + * 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.ext.erd.editor.tools; + +import org.eclipse.gef.Tool; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gef.tools.AbstractTool; +import org.eclipse.gef.tools.SelectionTool; +import org.eclipse.ui.menus.CommandContributionItem; +import org.jkiss.dbeaver.model.DBIcon; +import org.jkiss.dbeaver.model.DBPImage; +import org.jkiss.dbeaver.ui.ActionUtils; +import org.jkiss.dbeaver.ui.DBeaverIcons; +import org.jkiss.dbeaver.ui.UIUtils; + +public class CommandToolEntry extends ToolEntry { + + private final String commandId; + + public CommandToolEntry(String commandId, String label, DBPImage image) { + super( + label, + ActionUtils.findCommandDescription(commandId, UIUtils.getActiveWorkbenchWindow(), false), + DBeaverIcons.getImageDescriptor(image), + null); + this.commandId = commandId; + + this.setUserModificationPermission(PaletteEntry.PERMISSION_NO_MODIFICATION); + } + + public Tool createTool() { + return new ActionTool(); + } + + public class ActionTool extends SelectionTool { + + @Override + protected String getCommandName() { + return commandId; + } + + @Override + public void activate() { + ActionUtils.runCommand(commandId, UIUtils.getActiveWorkbenchWindow()); + super.activate(); + } + } + +} diff --git a/plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/ActionUtils.java b/plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/ActionUtils.java index fe1965f736a5b9474e24e08e7b2a465ede57155b..dbf4310936c159fe8e68bcb86b64d5e3efb936fe 100644 --- a/plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/ActionUtils.java +++ b/plugins/org.jkiss.dbeaver.ui/src/org/jkiss/dbeaver/ui/ActionUtils.java @@ -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. @@ -31,7 +31,9 @@ import org.eclipse.jface.bindings.TriggerSequence; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.graphics.Image; import org.eclipse.ui.*; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.keys.IBindingService; @@ -165,6 +167,16 @@ public class ActionUtils return "???"; } + @Nullable + public static ImageDescriptor findCommandImage(String commandId) + { + ICommandImageService commandService = PlatformUI.getWorkbench().getService(ICommandImageService.class); + if (commandService != null) { + return commandService.getImageDescriptor(commandId); + } + return null; + } + @Nullable public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {