Search in sources :

Example 6 with DBNResource

use of org.jkiss.dbeaver.model.navigator.DBNResource in project dbeaver by serge-rider.

the class NavigatorHandlerAssociateScript method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    List<IFile> scripts = new ArrayList<>();
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
            final DBNNode node = RuntimeUtils.getObjectAdapter(iter.next(), DBNNode.class);
            if (node instanceof DBNResource) {
                IResource resource = ((DBNResource) node).getResource();
                if (resource instanceof IFile) {
                    scripts.add((IFile) resource);
                }
            }
        }
    }
    if (!scripts.isEmpty()) {
        DBPDataSourceContainer dataSourceDescriptor = SelectDataSourceDialog.selectDataSource(activeShell, scripts.get(0).getProject());
        if (dataSourceDescriptor != null) {
            for (IFile script : scripts) {
                EditorUtils.setFileDataSource(script, dataSourceDescriptor, true);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 7 with DBNResource

use of org.jkiss.dbeaver.model.navigator.DBNResource 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 8 with DBNResource

use of org.jkiss.dbeaver.model.navigator.DBNResource in project dbeaver by serge-rider.

the class NavigatorHandlerCreateFolder method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNResource)) {
            return null;
        }
        Shell activeShell = HandlerUtil.getActiveShell(event);
        String folderName = EnterNameDialog.chooseName(activeShell, CoreMessages.actions_navigator_create_folder_folder_name);
        if (!CommonUtils.isEmpty(folderName)) {
            try {
                ((DBNResource) element).createNewFolder(folderName);
            } catch (DBException e) {
                UIUtils.showErrorDialog(activeShell, CoreMessages.actions_navigator_create_folder_error_title, NLS.bind(CoreMessages.actions_navigator_create_folder_error_message, folderName), e);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with DBNResource

use of org.jkiss.dbeaver.model.navigator.DBNResource in project dbeaver by serge-rider.

the class AbstractResourceHandler method openResource.

@Override
public void openResource(@NotNull IResource resource) throws CoreException, DBException {
    if (resource instanceof IFolder) {
        DBNResource node = DBeaverCore.getInstance().getNavigatorModel().getNodeByResource(resource);
        if (node != null) {
            NodeEditorInput nodeInput = new NodeEditorInput(node);
            DBeaverUI.getActiveWorkbenchWindow().getActivePage().openEditor(nodeInput, FolderEditor.class.getName());
        }
    }
//throw new DBException("Resource open is not implemented");
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) NodeEditorInput(org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput) FolderEditor(org.jkiss.dbeaver.ui.editors.entity.FolderEditor) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with DBNResource

use of org.jkiss.dbeaver.model.navigator.DBNResource in project dbeaver by serge-rider.

the class DefaultResourceHandlerImpl method makeNavigatorNode.

@NotNull
@Override
public DBNResource makeNavigatorNode(@NotNull DBNNode parentNode, @NotNull IResource resource) throws CoreException, DBException {
    DBNResource node = super.makeNavigatorNode(parentNode, resource);
    ProgramInfo program = ProgramInfo.getProgram(resource);
    if (program != null && program.getImage() != null) {
        node.setResourceImage(program.getImage());
    }
    return node;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) ProgramInfo(org.jkiss.dbeaver.ui.ProgramInfo) NotNull(org.jkiss.code.NotNull)

Aggregations

DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)12 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 ISelection (org.eclipse.jface.viewers.ISelection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IFile (org.eclipse.core.resources.IFile)3 IFolder (org.eclipse.core.resources.IFolder)3 IResource (org.eclipse.core.resources.IResource)3 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)3 ArrayList (java.util.ArrayList)2 IContainer (org.eclipse.core.resources.IContainer)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Shell (org.eclipse.swt.widgets.Shell)2 Text (org.eclipse.swt.widgets.Text)2