use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class SQLEditorHandlerOpenEditor method openEditor.
private static void openEditor(ExecutionEvent event) throws ExecutionException, CoreException, InterruptedException {
SQLNavigatorContext editorContext = getCurrentContext(event);
DBPProject project = editorContext.getProject();
checkProjectIsOpen(project);
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IFolder rootFolder = SQLEditorUtils.getScriptsFolder(project, true);
final List<SQLEditorUtils.ResourceInfo> scriptTree = SQLEditorUtils.findScriptTree(project, rootFolder, editorContext.getDataSourceContainer());
if (scriptTree.isEmpty()) {
// Create new script
final IFile newScript = SQLEditorUtils.createNewScript(project, rootFolder, editorContext);
openResource(newScript, editorContext);
} else {
// Show script chooser
ScriptSelectorPanel.showTree(workbenchWindow, editorContext, rootFolder, scriptTree);
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class AbstractNativeToolSettings method loadSettings.
public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) throws DBException {
if (dataSourceContainer == null && !CommonUtils.isEmpty(databaseObjects)) {
BASE_OBJECT baseObject = databaseObjects.get(0);
dataSourceContainer = baseObject instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) baseObject : baseObject.getDataSource().getContainer();
}
if (dataSourceContainer == null) {
String dsID = preferenceStore.getString("dataSource");
if (!CommonUtils.isEmpty(dsID)) {
String projectName = preferenceStore.getString("project");
DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
if (project == null) {
if (!CommonUtils.isEmpty(projectName)) {
log.error("Can't find project '" + projectName + "' for tool configuration");
}
project = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
}
dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsID);
if (dataSourceContainer == null) {
log.error("Can't find datasource '" + dsID + "' in project '" + project.getName() + "' for tool configuration");
}
}
}
if (preferenceStore instanceof DBPPreferenceMap && dataSourceContainer != null) {
List<String> databaseObjectList = ((DBPPreferenceMap) preferenceStore).getObject("databaseObjects");
if (!CommonUtils.isEmpty(databaseObjectList)) {
DBPProject finalProject = dataSourceContainer.getProject();
try {
runnableContext.run(true, true, monitor -> {
monitor.beginTask("Load database object list", databaseObjectList.size());
try {
for (String objectId : databaseObjectList) {
monitor.subTask("Load " + objectId);
try {
DBSObject object = DBUtils.findObjectById(monitor, finalProject, objectId);
if (object != null) {
databaseObjects.add((BASE_OBJECT) object);
dataSourceContainer = object instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) object : object.getDataSource().getContainer();
}
} catch (Throwable e) {
throw new DBException("Can't find database object '" + objectId + "' in project '" + finalProject.getName() + "' for task configuration", e);
}
monitor.worked(1);
}
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
});
} catch (InvocationTargetException e) {
throw new DBException("Error loading objects configuration", e.getTargetException());
} catch (InterruptedException e) {
// Ignore
}
}
}
extraCommandArgs = preferenceStore.getString(PROP_NAME_EXTRA_ARGS);
clientHomeName = preferenceStore.getString("clientHomeName");
if (preferenceStore instanceof DBPPreferenceMap) {
toolUserName = preferenceStore.getString("tool.user");
toolUserPassword = preferenceStore.getString("tool.password");
try {
final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
if (!CommonUtils.isEmpty(toolUserName))
toolUserName = encrypter.decrypt(toolUserName);
if (!CommonUtils.isEmpty(toolUserPassword))
toolUserPassword = encrypter.decrypt(toolUserPassword);
} catch (Exception e) {
throw new DBException("Error decrypting user credentials", e);
}
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class TaskHandlerCreate method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBPProject project = NavigatorUtils.getSelectedProject();
/*
CreateTaskConfigurationDialog dialog = new CreateTaskConfigurationDialog(
HandlerUtil.getActiveShell(event),
project
);
*/
TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event));
if (dialog.open() == IDialogConstants.OK_ID) {
DBTTaskManager taskManager = project.getTaskManager();
try {
/*
DBTTaskConfigurator configurator = dialog.getSelectedCategory().createConfigurator();
DBTTask task = taskManager.createTask(
dialog.getSelectedTaskType(),
dialog.getTaskName(),
dialog.getTaskDescription(),
dialog.getInitialProperties());
if (!configurator.createTaskConfigWizard(task)) {
taskManager.deleteTaskConfiguration(task);
}
*/
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Create task failed", "Error while creating new task", e);
}
}
return null;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DatabaseBrowserView method getNodeFromSecondaryId.
public static DBNNode getNodeFromSecondaryId(String id) throws DBException {
int divPos = id.indexOf('|');
if (divPos == -1) {
throw new DBException("Bad secondary ID: " + id);
}
String projectName = id.substring(0, divPos);
String nodePath = id.substring(divPos + 1).replace("~", ":");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (project == null) {
throw new DBException("Project '" + projectName + "' not found");
}
final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
DBNNode node = null;
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
if (projectMeta != null) {
navigatorModel.ensureProjectLoaded(projectMeta);
node = navigatorModel.getNodeByPath(new VoidProgressMonitor(), projectMeta, nodePath);
}
if (node == null) {
log.error("Node " + nodePath + " not found for browse view");
node = new DBNEmptyNode();
}
return node;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
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();
}
Aggregations