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
}
}
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;
}
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();
}
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;
}
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));
}
Aggregations