Skip to content

Commit

Permalink
dbeaver/pro#3336 RCP model refactoring. Remove VFS from base model (#…
Browse files Browse the repository at this point in the history
…2913)

* dbeaver/pro#3336 RCP model refactoring. Remove VFS from base model

* dbeaver/pro#3336 Simplify DBNNodeWithResource

* dbeaver/pro#3336 Web node info fix

* dbeaver/pro#3336 Code style

* dbeaver/pro#3336 Fix node project get
  • Loading branch information
serge-rider authored Sep 19, 2024
1 parent 46309e9 commit 90acaaf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.DBPObject;
Expand All @@ -37,7 +36,6 @@
import java.util.List;

public class DBNResourceManagerProject extends DBNAbstractResourceManagerNode {
private static final Log log = Log.getLog(DBNResourceManagerProject.class);

private final RMProject project;

Expand Down Expand Up @@ -123,29 +121,29 @@ public DBNNode refreshNode(DBRProgressMonitor monitor, Object source) throws DBE
return this;
}

@Override
public String toString() {
return getNodeDisplayName();
}


@NotNull
@Override
public DBPProject getOwnerProject() {
List<? extends DBPProject> globalProjects = getModel().getModelProjects();
if (globalProjects == null) {
return null;
}
for (DBPProject modelProject : globalProjects) {
if (CommonUtils.equalObjects(modelProject.getId(), project.getId())) {
return modelProject;
if (globalProjects != null) {
for (DBPProject modelProject : globalProjects) {
if (CommonUtils.equalObjects(modelProject.getId(), project.getId())) {
return modelProject;
}
}
}
return null;
throw new IllegalStateException("Project '" + project.getId() + "' not found in workspace");
}

@Nullable
@Override
public DBPObject getObjectDetails(@NotNull DBRProgressMonitor monitor, @NotNull SMSessionContext sessionContext, @NotNull Object dataSource) throws DBException {
return project;
}

@Override
public String toString() {
return getNodeDisplayName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public DBPObject getObjectDetails(@NotNull DBRProgressMonitor monitor, @NotNull
return resource;
}

@NotNull
@Override
public DBPProject getOwnerProject() {
return getParentNode().getOwnerProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.cloudbeaver.WebProjectImpl;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPAdaptable;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.app.DBPWorkspace;
Expand Down Expand Up @@ -132,6 +134,11 @@ public void dispose() {
clearProjects();
}

@Override
public DBPImage getResourceIcon(DBPAdaptable resourceAdapter) {
return null;
}

public void setActiveProject(DBPProject activeProject) {
this.activeProject = (WebProjectImpl) activeProject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ public String getPlainName() { // for renaming node

@Property
public String getProjectId() {
DBPProject ownerProject = node.getOwnerProject();
DBPProject ownerProject = node.getOwnerProjectOrNull();
return ownerProject == null ? null : ownerProject.getId();
}

@Property
@Deprecated
public String getFullName() {
String nodeName;
if (node instanceof DBNDatabaseNode && !(node instanceof DBNDataSource)) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (node instanceof DBNDatabaseNode dbNode && !(node instanceof DBNDataSource)) {
DBSObject object = dbNode.getObject();
nodeName = DBUtils.getObjectFullName(object, DBPEvaluationContext.UI);
} else if (node instanceof DBNDataSource) {
DBPDataSourceContainer object = ((DBNDataSource) node).getDataSourceContainer();
} else if (node instanceof DBNDataSource dataSource) {
DBPDataSourceContainer object = dataSource.getDataSourceContainer();
nodeName = object.getName();
} else {
nodeName = node.getNodeTargetName();
Expand Down Expand Up @@ -235,7 +235,7 @@ public String[] getFeatures() {
if (objectManager != null && objectManager.canDeleteObject(object)) {
features.add(NODE_FEATURE_CAN_DELETE);
}
if (objectManager instanceof DBEObjectRenamer && ((DBEObjectRenamer) objectManager).canRenameObject(object)) {
if (objectManager instanceof DBEObjectRenamer renamer && renamer.canRenameObject(object)) {
if (!object.getDataSource().getContainer().getNavigatorSettings().isShowOnlyEntities()) {
features.add(NODE_FEATURE_CAN_RENAME);
}
Expand Down Expand Up @@ -282,9 +282,10 @@ private boolean isDistributedSpecialFolderNode() {

@Property
public WebPropertyInfo[] getNodeDetails() throws DBWebException {
if (node instanceof DBPObjectWithDetails) {
if (node instanceof DBPObjectWithDetails objectWithDetails) {
try {
DBPObject objectDetails = ((DBPObjectWithDetails) node).getObjectDetails(session.getProgressMonitor(), session.getSessionContext(), node);
DBPObject objectDetails = objectWithDetails.getObjectDetails(
session.getProgressMonitor(), session.getSessionContext(), node);
if (objectDetails != null) {
return WebServiceUtils.getObjectProperties(session, objectDetails);
}
Expand All @@ -301,8 +302,8 @@ public WebPropertyInfo[] getNodeDetails() throws DBWebException {

@Property
public WebDatabaseObjectInfo getObject() {
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (node instanceof DBNDatabaseNode dbNode) {
DBSObject object = dbNode.getObject();
return object == null ? null : new WebDatabaseObjectInfo(session, object);
}
return null;
Expand All @@ -320,10 +321,10 @@ public String getObjectId() {

@Property
public DBSObjectFilter getFilter() throws DBWebException {
if (!(node instanceof DBNDatabaseNode)) {
if (!(node instanceof DBNDatabaseNode dbNode)) {
throw new DBWebException("Invalid navigator node type: " + node.getClass().getName());
}
DBSObjectFilter filter = ((DBNDatabaseNode) node).getNodeFilter(((DBNDatabaseNode) node).getItemsMeta(), true);
DBSObjectFilter filter = dbNode.getNodeFilter(dbNode.getItemsMeta(), true);
return filter == null || filter.isEmpty() || !filter.isEnabled() ? null : filter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ public boolean setNavigatorNodeFilter(
filter.setExclude(exclude);
}
filter.setEnabled(true);
((DBNDatabaseNode) node).setNodeFilter(
((DBNDatabaseNode) node).getItemsMeta(), filter, true);
if (hasNodeEditPermission(webSession, node, ((WebProjectImpl) node.getOwnerProject()).getRmProject())) {
// Save settings
((DBNDatabaseNode) node).getDataSourceContainer().persistConfiguration();
if (node instanceof DBNDatabaseNode dbNode) {
dbNode.setNodeFilter(dbNode.getItemsMeta(), filter, true);
if (hasNodeEditPermission(webSession, node, ((WebProjectImpl) node.getOwnerProject()).getRmProject())) {
// Save settings
dbNode.getDataSourceContainer().persistConfiguration();
}
}
} catch (DBException e) {
if (e instanceof DBWebException) {
Expand All @@ -255,14 +256,14 @@ public boolean refreshNavigatorNode(
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
if (node instanceof DBNDataSource) {
if (node instanceof DBNDataSource dbnDataSource) {
// Do not refresh entire tree - just clear child nodes
// Otherwise refresh may fail if navigator settings were changed.
DBPDataSource dataSource = ((DBNDataSource) node).getDataSource();
if (dataSource instanceof DBPRefreshableObject) {
((DBPRefreshableObject) dataSource).refreshObject(monitor);
DBPDataSource dataSource = dbnDataSource.getDataSource();
if (dataSource instanceof DBPRefreshableObject refreshableObject) {
refreshableObject.refreshObject(monitor);
}
((DBNDataSource) node).cleanupNode();
dbnDataSource.cleanupNode();
} else if (node instanceof DBNLocalFolder) {
// Refresh can't be applied to the local folder node
return true;
Expand Down Expand Up @@ -425,7 +426,7 @@ private String renameConnectionFolder(@NotNull WebSession session, DBNNode node,
List<String> siblings = Arrays.stream(
((DBNLocalFolder) node).getLogicalParent().getChildren(session.getProgressMonitor()))
.filter(n -> n instanceof DBNLocalFolder)
.map(DBNNode::getName).collect(Collectors.toList());
.map(DBNNode::getName).toList();
if (siblings.contains(newName)) {
throw new DBWebException("Name " + newName + " is unavailable or invalid");
}
Expand Down
Loading

0 comments on commit 90acaaf

Please sign in to comment.