Search in sources :

Example 1 with ERDEditorPart

use of org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart in project dbeaver by serge-rider.

the class ERDEditorPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof ERDEditorPart)) {
        return false;
    }
    ERDEditorPart erdEditor = (ERDEditorPart) receiver;
    switch(property) {
        case PROP_CAN_UNDO:
            return erdEditor.getCommandStack().canUndo();
        case PROP_CAN_REDO:
            return erdEditor.getCommandStack().canRedo();
        case PROP_EDITABLE:
            return !erdEditor.isReadOnly();
        case PROP_CAN_DELETE:
            DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) erdEditor);
            deleteAction.update();
            return deleteAction.isEnabled();
    }
    return false;
}
Also used : ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart) DeleteAction(org.eclipse.gef.ui.actions.DeleteAction)

Example 2 with ERDEditorPart

use of org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart in project dbeaver by serge-rider.

the class ERDHandlerPaste method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
    if (control != null) {
        ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
        if (editor != null && !editor.isReadOnly()) {
            final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (!CommonUtils.isEmpty(objects)) {
                try {
                    UIUtils.runInProgressService(monitor -> {
                        final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(monitor, editor.getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
                        if (!CommonUtils.isEmpty(erdEntities)) {
                            UIUtils.syncExec(() -> {
                                Command command = editor.getDiagramPart().createEntityAddCommand(erdEntities, new Point(10, 10));
                                editor.getCommandStack().execute(command);
                            });
                        }
                    });
                } catch (InvocationTargetException e) {
                    DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
                } catch (InterruptedException e) {
                // ignore
                }
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart) Command(org.eclipse.gef.commands.Command) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) DiagramCollectSettingsDefault(org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ERDEditorPart

use of org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart in project dbeaver by dbeaver.

the class ERDHandlerSelectAll method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
    if (control != null) {
        ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
        if (editor != null) {
            SelectAllAction selectAllAction = new SelectAllAction(editor);
            selectAllAction.run();
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart) SelectAllAction(org.eclipse.gef.ui.actions.SelectAllAction)

Example 4 with ERDEditorPart

use of org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart in project dbeaver by dbeaver.

the class FlyoutChangeLayoutAction method isChecked.

/**
 * @see org.eclipse.jface.action.IAction#isChecked()
 */
public boolean isChecked(IEditorPart editor) {
    if (editor instanceof ERDEditorPart) {
        ERDEditorPart schemaEditor = (ERDEditorPart) editor;
        EntityDiagram entityDiagram = schemaEditor.getDiagram();
        boolean checkTrue = entityDiagram.isLayoutManualDesired();
        return (!checkTrue);
    } else {
        return false;
    }
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)

Example 5 with ERDEditorPart

use of org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart in project dbeaver by dbeaver.

the class ERDHandlerPaste method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
    if (control != null) {
        ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
        if (editor != null && !editor.isReadOnly()) {
            final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (!CommonUtils.isEmpty(objects)) {
                try {
                    UIUtils.runInProgressService(monitor -> {
                        final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(monitor, editor.getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
                        if (!CommonUtils.isEmpty(erdEntities)) {
                            UIUtils.syncExec(() -> {
                                Command command = editor.getDiagramPart().createEntityAddCommand(erdEntities, new Point(10, 10));
                                editor.getCommandStack().execute(command);
                            });
                        }
                    });
                } catch (InvocationTargetException e) {
                    DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
                } catch (InterruptedException e) {
                // ignore
                }
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart) Command(org.eclipse.gef.commands.Command) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) DiagramCollectSettingsDefault(org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ERDEditorPart (org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)12 Control (org.eclipse.swt.widgets.Control)6 DeleteAction (org.eclipse.gef.ui.actions.DeleteAction)4 EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 SelectAllAction (org.eclipse.gef.ui.actions.SelectAllAction)2 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)2 DiagramCollectSettingsDefault (org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2