提交 1e9eef71 编写于 作者: S serge-rider

#1652 ERD palette/tools


Former-commit-id: 2efa6b6d
上级 ad3aee11
/*
* 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"));
......
/*
* 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();
}
}
}
/*
* 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();
}
}
}
/*
* 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)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册