use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class PrefPageProjectResourceSettings method performOk.
@Override
public boolean performOk() {
java.util.List<IResource> refreshedResources = new ArrayList<>();
// Save roots
DBPProject projectMeta = getProjectMeta();
if (projectMeta != null) {
for (TableItem item : resourceTable.getItems()) {
DBPResourceHandlerDescriptor descriptor = (DBPResourceHandlerDescriptor) item.getData();
String rootPath = item.getText(1);
if (!CommonUtils.equalObjects(descriptor.getDefaultRoot(projectMeta), rootPath)) {
IResource oldResource = project.findMember(descriptor.getDefaultRoot(projectMeta));
if (oldResource != null) {
refreshedResources.add(oldResource);
}
IResource newResource = project.findMember(rootPath);
if (newResource != null) {
refreshedResources.add(newResource);
}
descriptor.setDefaultRoot(projectMeta, rootPath);
}
}
if (!refreshedResources.isEmpty()) {
for (IResource resource : refreshedResources) {
DBNUtils.refreshNavigatorResource(resource, this);
}
}
}
return super.performOk();
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class QueryLogViewer method openSelectionInEditor.
private void openSelectionInEditor() {
DBPDataSourceContainer dsContainer = null;
StringBuilder sql = new StringBuilder();
TableItem[] items = logTable.getSelection();
for (TableItem item : items) {
QMMetaEvent event = (QMMetaEvent) item.getData();
QMMObject object = event.getObject();
if (object instanceof QMMStatementExecuteInfo) {
QMMStatementExecuteInfo stmtExec = (QMMStatementExecuteInfo) object;
if (dsContainer == null) {
QMMSessionInfo session = stmtExec.getStatement().getSession();
DBPProject project = session.getProject();
String containerId = session.getContainerId();
if (project != null) {
dsContainer = project.getDataSourceRegistry().getDataSource(containerId);
} else {
dsContainer = DBUtils.findDataSource(containerId);
}
}
String queryString = stmtExec.getQueryString();
if (!CommonUtils.isEmptyTrimmed(queryString)) {
if (sql.length() > 0) {
// $NON-NLS-1$
sql.append("\n");
}
queryString = queryString.trim();
sql.append(queryString);
if (!queryString.endsWith(SQLConstants.DEFAULT_STATEMENT_DELIMITER)) {
// $NON-NLS-1$
sql.append(SQLConstants.DEFAULT_STATEMENT_DELIMITER).append("\n");
}
}
}
}
if (sql.length() > 0) {
SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(dsContainer), // $NON-NLS-1$
"QueryManager", sql.toString());
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
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 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;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by serge-rider.
the class NavigatorActiveProjectContributor method createMenu.
private void createMenu(final Menu menu) {
final DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
for (final DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
MenuItem txnItem = new MenuItem(menu, SWT.RADIO);
txnItem.setText(project.getName());
txnItem.setSelection(project == activeProject);
txnItem.setData(project);
txnItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
NavigatorHandlerProjectSetActive.setActiveProject(project);
}
});
}
}
Aggregations