This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new f3d5ebdcef projects and environment fixes for hop web. fixes #6395
(#6400)
f3d5ebdcef is described below
commit f3d5ebdcefe9fbedc22dc1c9fb0f9e69c575307b
Author: Bart Maertens <[email protected]>
AuthorDate: Fri Jan 16 10:35:41 2026 +0000
projects and environment fixes for hop web. fixes #6395 (#6400)
* projects and environment fixes for hop web. fixes #6395
* add some extra margin to the project buttons
---------
Co-authored-by: Hans Van Akelyen <[email protected]>
---
.../apache/hop/projects/gui/ProjectsGuiPlugin.java | 84 +++++++++++++++++-----
.../apache/hop/ui/core/gui/GuiToolbarWidgets.java | 30 +++++++-
2 files changed, 94 insertions(+), 20 deletions(-)
diff --git
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
index afb70be66b..1d4ff72835 100644
---
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
+++
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
@@ -419,7 +419,9 @@ public class ProjectsGuiPlugin {
image = "ui/images/edit.svg")
public void editProject() {
HopGui hopGui = HopGui.getInstance();
- String projectName = getProjectToolItem().getText();
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String projectName =
+
hopGui.getStatusToolbarWidgets().getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT);
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
ProjectConfig projectConfig = config.findProjectConfig(projectName);
@@ -516,8 +518,10 @@ public class ProjectsGuiPlugin {
menuWidgets.createMenuWidgets(ID_CONTEXT_MENU_PROJECT, shell, menu);
// Enable menus if a project is active.
- //
- boolean enabled = !"".equals(getProjectToolItem().getText());
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String projectText =
+
HopGui.getInstance().getStatusToolbarWidgets().getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT);
+ boolean enabled = !"".equals(projectText);
menuWidgets.enableMenuItem(ID_CONTEXT_MENU_PROJECT_EDIT, enabled);
menuWidgets.enableMenuItem(ID_CONTEXT_MENU_PROJECT_DELETE, enabled);
@@ -564,16 +568,25 @@ public class ProjectsGuiPlugin {
menuWidgets.createMenuWidgets(ID_CONTEXT_MENU_ENVIRONMENT, shell, menu);
// Enable menus if an environment is active.
- //
- boolean enabled = !"".equals(getEnvironmentToolItem().getText());
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String environmentText =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_ENVIRONMENT);
+ boolean enabled = !"".equals(environmentText);
menuWidgets.enableMenuItem(ID_CONTEXT_MENU_ENVIRONMENT_EDIT, enabled);
menuWidgets.enableMenuItem(ID_CONTEXT_MENU_ENVIRONMENT_DUPLICATE, enabled);
menuWidgets.enableMenuItem(ID_CONTEXT_MENU_ENVIRONMENT_DELETE, enabled);
new MenuItem(menu, SWT.SEPARATOR);
- String currentProjectName = getProjectToolItem().getText();
- String currentEnvironmentName = getEnvironmentToolItem().getText();
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String currentProjectName =
+
HopGui.getInstance().getStatusToolbarWidgets().getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT);
+ String currentEnvironmentName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_ENVIRONMENT);
// Display list of environments
//
@@ -583,12 +596,17 @@ public class ProjectsGuiPlugin {
// Exclude environment linked to another project
LifecycleEnvironment environment = config.findEnvironment(name);
- if (Utils.isEmpty(environment.getProjectName())
- || currentProjectName.equals(environment.getProjectName())) {
+ if (environment != null
+ && (Utils.isEmpty(environment.getProjectName())
+ || currentProjectName.equals(environment.getProjectName()))) {
+ // Create a final copy of the name variable for the lambda closure
+ // This is critical for RAP/web compatibility - each menu item needs
its own copy
+ final String environmentName = name;
MenuItem item = new MenuItem(menu, SWT.NONE);
- item.setText(name);
- item.addListener(SWT.Selection, e -> selectEnvironment(name));
- if (currentEnvironmentName.equals(name)) {
+ item.setText(environmentName);
+ // Match projects exactly - use addListener with lambda (projects work
this way)
+ item.addListener(SWT.Selection, e ->
selectEnvironment(environmentName));
+ if (currentEnvironmentName.equals(environmentName)) {
item.setImage(GuiResource.getInstance().getImageCheck());
}
}
@@ -862,7 +880,9 @@ public class ProjectsGuiPlugin {
toolTip = "i18n::HopGui.Toolbar.Project.Delete.Tooltip",
image = "ui/images/delete.svg")
public void deleteProject() {
- String projectName = getProjectToolItem().getText();
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String projectName =
+
HopGui.getInstance().getStatusToolbarWidgets().getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT);
if (StringUtils.isEmpty(projectName)) {
return;
}
@@ -953,7 +973,12 @@ public class ProjectsGuiPlugin {
image = "ui/images/edit.svg")
public void editEnvironment() {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
- LifecycleEnvironment environment =
config.findEnvironment(getEnvironmentToolItem().getText());
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String environmentName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_ENVIRONMENT);
+ LifecycleEnvironment environment = config.findEnvironment(environmentName);
if (environment != null) {
this.editEnvironment(environment);
}
@@ -1002,7 +1027,11 @@ public class ProjectsGuiPlugin {
}
String projectName = environment.getProjectName();
if (StringUtils.isEmpty(projectName)) {
- projectName = getProjectToolItem().getText();
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ projectName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT);
}
ProjectConfig projectConfig = config.findProjectConfig(projectName);
if (projectConfig == null) {
@@ -1035,7 +1064,11 @@ public class ProjectsGuiPlugin {
HopGui hopGui = HopGui.getInstance();
try {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
- String projectName = getProjectToolItem().getText(); // The default is
the active project
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String projectName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT); // The default is
the active project
LifecycleEnvironment environment =
new LifecycleEnvironment(null, "", projectName, new ArrayList<>());
@@ -1073,7 +1106,12 @@ public class ProjectsGuiPlugin {
image = "ui/images/duplicate.svg")
public void duplicateEnvironment() {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
- LifecycleEnvironment environment =
config.findEnvironment(getEnvironmentToolItem().getText());
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String environmentName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_ENVIRONMENT);
+ LifecycleEnvironment environment = config.findEnvironment(environmentName);
if (environment == null) {
return;
}
@@ -1092,7 +1130,11 @@ public class ProjectsGuiPlugin {
image = "ui/images/delete.svg")
public void deleteEnvironment() {
HopGui hopGui = HopGui.getInstance();
- String environmentName = getEnvironmentToolItem().getText();
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String environmentName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_ENVIRONMENT);
if (StringUtils.isEmpty(environmentName)) {
return;
}
@@ -1117,7 +1159,11 @@ public class ProjectsGuiPlugin {
int answer = box.open();
if ((answer & SWT.YES) != 0) {
try {
- String projectName = getProjectToolItem().getText(); // The default is
the active project
+ // Use getToolbarItemText() for RAP compatibility (text is stored in
Label, not ToolItem)
+ String projectName =
+ HopGui.getInstance()
+ .getStatusToolbarWidgets()
+ .getToolbarItemText(ID_TOOLBAR_ITEM_PROJECT); // The default
is the active project
ProjectConfig projectConfig = config.findProjectConfig(projectName);
Project project = projectConfig.loadProject(hopGui.getVariables());
diff --git a/ui/src/main/java/org/apache/hop/ui/core/gui/GuiToolbarWidgets.java
b/ui/src/main/java/org/apache/hop/ui/core/gui/GuiToolbarWidgets.java
index 91b4bb24f4..f63ea58ce0 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/gui/GuiToolbarWidgets.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/gui/GuiToolbarWidgets.java
@@ -547,7 +547,9 @@ public class GuiToolbarWidgets extends BaseGuiWidgets {
Composite composite = (Composite) widgetsMap.get(id);
if (composite != null && !composite.isDisposed()) {
composite.pack();
- toolItem.setWidth(composite.getSize().x);
+ // Add extra margin to the right for spacing between toolbar items
+ int extraMargin = !Utils.isEmpty(textToSet) ? 10 : 0;
+ toolItem.setWidth(composite.getSize().x + extraMargin);
// Force layout update
ToolBar toolbar = toolItem.getParent();
@@ -562,6 +564,32 @@ public class GuiToolbarWidgets extends BaseGuiWidgets {
}
}
+ /**
+ * Get text from a toolbar item. Handles both SWT (desktop) and RWT (web)
environments. In SWT,
+ * gets text directly from the ToolItem. In RWT, gets text from the separate
text Label.
+ *
+ * @param id The ID of the toolbar item
+ * @return The text on the toolbar item, or empty string if not found
+ */
+ public String getToolbarItemText(String id) {
+ ToolItem toolItem = toolItemMap.get(id);
+ if (toolItem == null || toolItem.isDisposed()) {
+ return "";
+ }
+
+ if (EnvironmentUtils.getInstance().isWeb()) {
+ // In web/RWT, get text from the separate text label
+ Label textLabel = textLabelMap.get(id);
+ if (textLabel != null && !textLabel.isDisposed()) {
+ return Const.NVL(textLabel.getText(), "");
+ }
+ return "";
+ } else {
+ // In SWT, get text directly from the ToolItem
+ return Const.NVL(toolItem.getText(), "");
+ }
+ }
+
public void refreshComboItemList(String id) {
GuiToolbarItem item = guiToolBarMap.get(id);
if (item != null) {