Search in sources :

Example 1 with IClipboardSource

use of org.jkiss.dbeaver.ui.IClipboardSource in project dbeaver by serge-rider.

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
        ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with IClipboardSource

use of org.jkiss.dbeaver.ui.IClipboardSource in project dbeaver by dbeaver.

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
        ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 3 with IClipboardSource

use of org.jkiss.dbeaver.ui.IClipboardSource in project dbeaver by serge-rider.

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
    // ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 4 with IClipboardSource

use of org.jkiss.dbeaver.ui.IClipboardSource in project dbeaver by dbeaver.

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
    // ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)4 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)4 ClipboardData (org.jkiss.dbeaver.ui.ClipboardData)4 IClipboardSource (org.jkiss.dbeaver.ui.IClipboardSource)4