Search in sources :

Example 1 with DiagramCollectSettingsDefault

use of org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault in project dbeaver by serge-rider.

the class NodeDropTargetListener method createTargetRequest.

@Override
protected Request createTargetRequest() {
    CreateRequest request = new CreateRequest();
    request.setFactory(new CreationFactory() {

        @Override
        public Object getNewObject() {
            Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (objects == null) {
                return null;
            }
            DBRRunnableWithResult<List<ERDEntity>> collector = new DBRRunnableWithResult<List<ERDEntity>>() {

                @Override
                public void run(DBRProgressMonitor monitor) {
                    result = DiagramObjectCollector.generateEntityList(monitor, ((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
                }
            };
            try {
                UIUtils.runInProgressService(collector);
            } catch (InvocationTargetException e) {
                DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
            } catch (InterruptedException e) {
            // ignore
            }
            return collector.getResult();
        }

        @Override
        public Object getObjectType() {
            return RequestConstants.REQ_CREATE;
        }
    });
    request.setLocation(getDropLocation());
    return request;
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) CreationFactory(org.eclipse.gef.requests.CreationFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) DiagramCollectSettingsDefault(org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault) Collection(java.util.Collection) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 2 with DiagramCollectSettingsDefault

use of org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault 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 DiagramCollectSettingsDefault

use of org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault 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)

Example 4 with DiagramCollectSettingsDefault

use of org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault in project dbeaver by dbeaver.

the class NodeDropTargetListener method createTargetRequest.

@Override
protected Request createTargetRequest() {
    CreateRequest request = new CreateRequest();
    request.setFactory(new CreationFactory() {

        @Override
        public Object getNewObject() {
            Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (objects == null) {
                return null;
            }
            DBRRunnableWithResult<List<ERDEntity>> collector = new DBRRunnableWithResult<List<ERDEntity>>() {

                @Override
                public void run(DBRProgressMonitor monitor) {
                    result = DiagramObjectCollector.generateEntityList(monitor, ((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects, new DiagramCollectSettingsDefault(), true);
                }
            };
            try {
                UIUtils.runInProgressService(collector);
            } catch (InvocationTargetException e) {
                DBWorkbench.getPlatformUI().showError("Entity collect error", "Error during diagram entities collect", e);
            } catch (InterruptedException e) {
            // ignore
            }
            return collector.getResult();
        }

        @Override
        public Object getObjectType() {
            return RequestConstants.REQ_CREATE;
        }
    });
    request.setLocation(getDropLocation());
    return request;
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) CreationFactory(org.eclipse.gef.requests.CreationFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) DiagramCollectSettingsDefault(org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault) Collection(java.util.Collection) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)4 DiagramCollectSettingsDefault (org.jkiss.dbeaver.erd.ui.model.DiagramCollectSettingsDefault)4 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)4 Collection (java.util.Collection)2 List (java.util.List)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 CreateRequest (org.eclipse.gef.requests.CreateRequest)2 CreationFactory (org.eclipse.gef.requests.CreationFactory)2 Control (org.eclipse.swt.widgets.Control)2 ERDEditorPart (org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithResult (org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult)2