Search in sources :

Example 96 with IResource

use of org.eclipse.core.resources.IResource in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateCopy method pasteResource.

private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
    final IResource resource = resourceNode.getResource();
    final IResource targetResource = toFolder.getResource();
    assert resource != null;
    assert targetResource != null;
    final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    copyResource(monitor, resource, targetFolder);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 97 with IResource

use of org.eclipse.core.resources.IResource 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 98 with IResource

use of org.eclipse.core.resources.IResource in project dbeaver by serge-rider.

the class ScriptsExportWizard method exportScripts.

public void exportScripts(DBRProgressMonitor monitor, final ScriptsExportData exportData) throws IOException, CoreException, InterruptedException {
    Collection<IResource> scripts = exportData.getScripts();
    int totalFiles = 0;
    for (IResource res : scripts) {
        if (res instanceof IFolder) {
            totalFiles += countFiles((IFolder) res);
        } else {
            totalFiles++;
        }
    }
    monitor.beginTask("Export scripts", totalFiles);
    for (IResource res : scripts) {
        if (res instanceof IFolder) {
            exportFolder(monitor, (IFolder) res, exportData);
        } else {
            exportScript(monitor, (IFile) res, exportData);
        }
    }
    monitor.done();
}
Also used : IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 99 with IResource

use of org.eclipse.core.resources.IResource in project dbeaver by serge-rider.

the class ScriptsExportWizard method makeExternalFile.

private File makeExternalFile(IResource folder, File outputFolder) {
    List<IResource> path = new ArrayList<>();
    for (IResource f = folder; f.getParent() instanceof IFolder; f = f.getParent()) {
        path.add(0, f);
    }
    File fsDir = outputFolder;
    for (IResource pathItem : path) {
        fsDir = new File(fsDir, pathItem.getName());
    }
    return fsDir;
}
Also used : ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with IResource

use of org.eclipse.core.resources.IResource in project dbeaver by serge-rider.

the class ScriptsExportWizardPage method getExportData.

public ScriptsExportData getExportData() {
    Set<IResource> result = new LinkedHashSet<>();
    // Add folders
    for (DBNResource resourceNode : selectedResources) {
        final IResource resource = resourceNode.getResource();
        if (resource instanceof IFolder) {
            addResourceToSet(result, resource);
        }
    }
    // Add files
    for (DBNResource resourceNode : selectedResources) {
        final IResource resource = resourceNode.getResource();
        addResourceToSet(result, resource);
    }
    final String outputDir = directoryText.getText();
    DBeaverCore.getGlobalPreferenceStore().setValue(PREF_SCRIPTS_EXPORT_OUT_DIR, outputDir);
    return new ScriptsExportData(result, overwriteCheck.getSelection(), new File(outputDir));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IResource (org.eclipse.core.resources.IResource)377 CoreException (org.eclipse.core.runtime.CoreException)98 IFile (org.eclipse.core.resources.IFile)83 IPath (org.eclipse.core.runtime.IPath)80 IProject (org.eclipse.core.resources.IProject)79 ArrayList (java.util.ArrayList)61 IFolder (org.eclipse.core.resources.IFolder)54 IContainer (org.eclipse.core.resources.IContainer)44 IStatus (org.eclipse.core.runtime.IStatus)34 IOException (java.io.IOException)33 IJavaElement (org.eclipse.jdt.core.IJavaElement)29 Status (org.eclipse.core.runtime.Status)26 File (java.io.File)25 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)25 IJavaProject (org.eclipse.jdt.core.IJavaProject)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 List (java.util.List)21 IResourceDelta (org.eclipse.core.resources.IResourceDelta)21 HashSet (java.util.HashSet)18 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18