Fixed issue 33064: form widgets cant be added to workspace
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Thu, 02 Jun 2016 17:14:50 +0200
changeset 29574 3ea47b48a028
parent 29573 4c3b627a612c
child 29575 4cb4e1989316
Fixed issue 33064: form widgets cant be added to workspace

The problem was related with widgets that can be embedded
into a form. In some cases, these widgets should not be
placed into the workspace.

To resolve this problem in a generic way, it has been
implemented a flag (Available_in_workspace) in the widget
definition that determines when a widget is available to
be shown in the workspace.

Now, any widget that does not have selected the new flag,
will not appear in the list of widgets to place into the
workspace.
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java
--- a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java	Thu Jun 02 17:11:55 2016 +0200
+++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java	Thu Jun 02 17:14:50 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -182,8 +182,14 @@
 
   private void addAvailableWidgetClasses(JSONObject o, String roleId, boolean isAdminMode) {
     MyOpenbravoComponent component = weldUtils.getInstance(MyOpenbravoComponent.class);
+    List<String> availableClasses = null;
     try {
-      List<String> availableClasses = component.getAvailableWidgetClasses(roleId, isAdminMode);
+      final String strEventType = o.getString("eventType");
+      if (GET_AVAILABLE_WIDGET_CLASSES.equals(strEventType)) {
+        availableClasses = component.getAvailableWidgetClasses(roleId, isAdminMode, true);
+      } else {
+        availableClasses = component.getAvailableWidgetClasses(roleId, isAdminMode);
+      }
       o.put("availableWidgetClasses", availableClasses);
     } catch (Exception e) {
       log.error("Error retreiving widget classes", e);
--- a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java	Thu Jun 02 17:11:55 2016 +0200
+++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java	Thu Jun 02 17:14:50 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -96,6 +96,12 @@
 
   public List<String> getAvailableWidgetClasses(String roleId, boolean isAdminMode)
       throws Exception {
+    boolean shouldBeDisplayedInWorkspace = false;
+    return getAvailableWidgetClasses(roleId, isAdminMode, shouldBeDisplayedInWorkspace);
+  }
+
+  public List<String> getAvailableWidgetClasses(String roleId, boolean isAdminMode,
+      boolean shouldBeDisplayed) throws Exception {
     OBContext.setAdminMode();
     try {
       if (widgetClassDefinitions != null) {
@@ -105,8 +111,13 @@
       final List<JSONObject> definitions = new ArrayList<JSONObject>();
       final List<String> tmp = new ArrayList<String>();
       String classDef = "";
+      String strConditionQuery = WidgetClass.PROPERTY_SUPERCLASS + " is false";
+      if (shouldBeDisplayed) {
+        strConditionQuery += " and " + WidgetClass.PROPERTY_AVAILABLEINWORKSPACE + " is true";
+      }
+
       final OBQuery<WidgetClass> widgetClassesQry = OBDal.getInstance().createQuery(
-          WidgetClass.class, WidgetClass.PROPERTY_SUPERCLASS + " is false");
+          WidgetClass.class, strConditionQuery);
       for (WidgetClass widgetClass : widgetClassesQry.list()) {
         if (isAccessible(widgetClass, roleId)) {
           final WidgetProvider widgetProvider = myOBUtils.getWidgetProvider(widgetClass);