use of org.jkiss.dbeaver.model.app.DBPWorkspace in project dbeaver by dbeaver.
the class ProjectImportWizard method importProject.
private IProject importProject(DBRProgressMonitor monitor, Element projectElement, ZipFile zipFile, Map<String, String> driverMap) throws DBException, CoreException, IOException {
String projectName = projectElement.getAttribute(ExportConstants.ATTR_NAME);
String projectDescription = projectElement.getAttribute(ExportConstants.ATTR_DESCRIPTION);
String targetProjectName = data.getTargetProjectName(projectName);
if (targetProjectName == null) {
return null;
}
IWorkspace eclipseWorkspace = DBWorkbench.getPlatform().getWorkspace().getEclipseWorkspace();
IProject project = eclipseWorkspace.getRoot().getProject(targetProjectName);
if (project.exists()) {
throw new DBException("Project '" + targetProjectName + "' already exists");
}
final IProjectDescription description = eclipseWorkspace.newProjectDescription(project.getName());
if (!CommonUtils.isEmpty(projectDescription)) {
description.setComment(projectDescription);
}
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
project.create(description, 0, RuntimeUtils.getNestedMonitor(monitor));
try {
monitor.beginTask(CoreMessages.dialog_project_import_wizard_monitor_import_projects, zipFile.size());
monitor.subTask("Import project properties");
// Open project
project.open(RuntimeUtils.getNestedMonitor(monitor));
monitor.worked(1);
// Set project properties
loadResourceProperties(monitor, project, projectElement);
monitor.worked(1);
// Load resources
importChildResources(monitor, project, projectElement, // $NON-NLS-1$ //$NON-NLS-2$
ExportConstants.DIR_PROJECTS + "/" + projectName + "/", zipFile);
// Update driver references in datasources
updateDriverReferences(monitor, project, driverMap);
monitor.done();
} catch (Exception e) {
// Cleanup project which was partially imported
try {
project.delete(true, true, RuntimeUtils.getNestedMonitor(monitor));
} catch (CoreException e1) {
log.error(e1);
}
throw new DBException("Error importing project resources", e);
}
return project;
}
use of org.jkiss.dbeaver.model.app.DBPWorkspace in project dbeaver by serge-rider.
the class ProjectImportWizard method importProject.
private IProject importProject(DBRProgressMonitor monitor, Element projectElement, ZipFile zipFile, Map<String, String> driverMap) throws DBException, CoreException, IOException {
String projectName = projectElement.getAttribute(ExportConstants.ATTR_NAME);
String projectDescription = projectElement.getAttribute(ExportConstants.ATTR_DESCRIPTION);
String targetProjectName = data.getTargetProjectName(projectName);
if (targetProjectName == null) {
return null;
}
IWorkspace eclipseWorkspace = DBWorkbench.getPlatform().getWorkspace().getEclipseWorkspace();
IProject project = eclipseWorkspace.getRoot().getProject(targetProjectName);
if (project.exists()) {
throw new DBException("Project '" + targetProjectName + "' already exists");
}
final IProjectDescription description = eclipseWorkspace.newProjectDescription(project.getName());
if (!CommonUtils.isEmpty(projectDescription)) {
description.setComment(projectDescription);
}
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
project.create(description, 0, RuntimeUtils.getNestedMonitor(monitor));
try {
monitor.beginTask(CoreMessages.dialog_project_import_wizard_monitor_import_projects, zipFile.size());
monitor.subTask("Import project properties");
// Open project
project.open(RuntimeUtils.getNestedMonitor(monitor));
monitor.worked(1);
// Set project properties
loadResourceProperties(monitor, project, projectElement);
monitor.worked(1);
// Load resources
importChildResources(monitor, project, projectElement, // $NON-NLS-1$ //$NON-NLS-2$
ExportConstants.DIR_PROJECTS + "/" + projectName + "/", zipFile);
// Update driver references in datasources
updateDriverReferences(monitor, project, driverMap);
monitor.done();
} catch (Exception e) {
// Cleanup project which was partially imported
try {
project.delete(true, true, RuntimeUtils.getNestedMonitor(monitor));
} catch (CoreException e1) {
log.error(e1);
}
throw new DBException("Error importing project resources", e);
}
return project;
}
use of org.jkiss.dbeaver.model.app.DBPWorkspace in project dbeaver by serge-rider.
the class PrefPageProjectResourceSettings method performDefaults.
@Override
protected void performDefaults() {
resourceTable.removeAll();
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
for (DBPResourceHandlerDescriptor descriptor : workspace.getResourceHandlerDescriptors()) {
if (!descriptor.isManagable()) {
continue;
}
TableItem item = new TableItem(resourceTable, SWT.NONE);
item.setData(descriptor);
final DBPImage icon = descriptor.getIcon();
if (icon != null) {
item.setImage(DBeaverIcons.getImage(icon));
}
item.setText(0, descriptor.getName());
DBPProject projectMeta = getProjectMeta();
String defaultRoot = projectMeta == null ? null : descriptor.getDefaultRoot(projectMeta);
if (defaultRoot != null) {
item.setText(1, defaultRoot);
}
}
UIUtils.packColumns(resourceTable, true);
super.performDefaults();
}
use of org.jkiss.dbeaver.model.app.DBPWorkspace in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateNew method fillCreateMenuItems.
// If site is null then we need only item count. BAD CODE.
public static List<IContributionItem> fillCreateMenuItems(@Nullable IWorkbenchPartSite site, DBNNode node) {
List<IContributionItem> createActions = new ArrayList<>();
if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases) {
IContributionItem item = makeCreateContributionItem(site, DBPDataSourceContainer.class.getName(), ModelMessages.model_navigator_Connection, UIIcon.SQL_NEW_CONNECTION, false);
createActions.add(item);
}
if (node instanceof DBNDatabaseNode) {
addDatabaseNodeCreateItems(site, createActions, (DBNDatabaseNode) node);
}
if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases || node instanceof DBNDataSource) {
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_LOCAL_FOLDER));
} else if (node instanceof DBNResource) {
final DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
IResource resource = ((DBNResource) node).getResource();
if (resource instanceof IProject) {
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_PROJECT));
}
DBPResourceHandler handler = workspace.getResourceHandler(resource);
if (handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 0) {
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FILE));
}
if (handler != null && (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0) {
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FOLDER));
}
if (resource instanceof IContainer) {
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FILE_LINK));
createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FOLDER_LINK));
}
}
if (site != null) {
if (!createActions.isEmpty() && !(createActions.get(createActions.size() - 1) instanceof Separator)) {
createActions.add(new Separator());
}
createActions.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.FILE_NEW, "Other ...", null));
}
return createActions;
}
use of org.jkiss.dbeaver.model.app.DBPWorkspace in project dbeaver by serge-rider.
the class ResourcePropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof IResource)) {
return false;
}
IResource resource = (IResource) receiver;
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
DBPResourceHandler handler = workspace.getResourceHandler(resource);
if (handler == null) {
return false;
}
switch(property) {
case PROP_CAN_OPEN:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_OPEN) != 0;
case PROP_CAN_DELETE:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_DELETE) != 0;
case PROP_CAN_CREATE_FILE:
return handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 0;
case PROP_CAN_CREATE_FOLDER:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0;
case PROP_CAN_CREATE_LINK:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0 && !resource.isLinked(IResource.CHECK_ANCESTORS);
case PROP_CAN_SET_ACTIVE:
{
DBPProject activeProject = workspace.getActiveProject();
return resource instanceof IProject && (activeProject == null || resource != activeProject.getEclipseProject());
}
case PROP_TYPE:
final DBPResourceHandler resourceHandler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
}
return false;
}
Aggregations