Package org.gatein.mop.api.workspace.ui

Examples of org.gatein.mop.api.workspace.ui.UIComponent


        return new PageContext(new PageData(dstPage));
    }

    private void copy(Page srcPage, Page dstPage, UIContainer src, UIContainer dst) {
        for (UIComponent srcChild : src.getComponents()) {
            UIComponent dstChild = dst.add(srcChild.getObjectType(), srcChild.getObjectId());

            //
            if (srcChild.isAdapted(Described.class)) {
                Described srcDescribed = srcChild.adapt(Described.class);
                Described dstDescribed = dstChild.adapt(Described.class);
                dstDescribed.setName(srcDescribed.getName());
                dstDescribed.setDescription(srcDescribed.getDescription());
            }

            //
            if (srcChild.isAdapted(ProtectedResource.class)) {
                ProtectedResource srcPR = srcChild.adapt(ProtectedResource.class);
                ProtectedResource dstPR = dstChild.adapt(ProtectedResource.class);
                dstPR.setAccessPermissions(srcPR.getAccessPermissions());
                dstPR.setEditPermission(srcPR.getEditPermission());
            }

            //
            Attributes srcAttrs = srcChild.getAttributes();
            Attributes dstAttrs = dstChild.getAttributes();
            for (String key : srcAttrs.getKeys()) {
                Object value = srcAttrs.getObject(key);
                dstAttrs.setObject(key, value);
            }
View Full Code Here


      private void copy(org.gatein.mop.api.workspace.Page srcPage, org.gatein.mop.api.workspace.Page dstPage,
         UIContainer src, UIContainer dst)
      {
         for (UIComponent srcChild : src.getComponents())
         {
            UIComponent dstChild = dst.add(srcChild.getObjectType(), srcChild.getObjectId());

            //
            if (srcChild.isAdapted(Described.class))
            {
               Described srcDescribed = srcChild.adapt(Described.class);
               Described dstDescribed = dstChild.adapt(Described.class);
               dstDescribed.setName(srcDescribed.getName());
               dstDescribed.setDescription(srcDescribed.getDescription());
            }

            //
            if (srcChild.isAdapted(ProtectedResource.class))
            {
               ProtectedResource srcPR = srcChild.adapt(ProtectedResource.class);
               ProtectedResource dstPR = dstChild.adapt(ProtectedResource.class);
               dstPR.setAccessPermissions(srcPR.getAccessPermissions());
               dstPR.setEditPermission(srcPR.getEditPermission());
            }

            //
            Attributes srcAttrs = srcChild.getAttributes();
            Attributes dstAttrs = dstChild.getAttributes();
            for (String key : srcAttrs.getKeys())
            {
               Object value = srcAttrs.getObject(key);
               dstAttrs.setObject(key, value);
            }
View Full Code Here

               }
            }
         }

         //
         UIComponent dstChild;
         if (srcChildId != null)
         {
            dstChild = session.findObjectById(ObjectType.COMPONENT, srcChildId);
            if (dstChild == null)
            {
               throw new StaleModelException("Could not find supposed present child with id " + srcChildId);
            }

            // julien : this can fail due to a bug in chromattic not implementing equals method properly
            // and is replaced with the foreach below
            /*
                    if (!dst.contains(dstChild)) {
                      throw new IllegalArgumentException("Attempt for updating a ui component " + session.pathOf(dstChild) +
                        "that is not present in the target ui container " + session.pathOf(dst));
                    }
            */
            boolean found = false;
            for (UIComponent child : dst.getComponents())
            {
               if (child.getObjectId().equals(srcChildId))
               {
                  found = true;
                  break;
               }
            }

            //
            if (!found)
            {
               if (hierarchyRelationships.containsKey(srcChildId))
               {
                  String srcId = hierarchyRelationships.get(srcChildId);

                  // It's a move operation, so we move the node first
                  dst.getComponents().add(dstChild);

                  //
                  changes.add(new ModelChange.Move(srcId, dst.getObjectId(), srcChildId));
               }
               else
               {
                     throw new IllegalArgumentException("Attempt for updating a ui component " + session.pathOf(dstChild)
                     + " that is not present in the target ui container " + session.pathOf(dst));
               }
            }

            //
            changes.add(new ModelChange.Update(srcChild));
         }
         else
         {
            String name = srcChild.getStorageName();
            if (name == null)
            {
               // We manufacture one name
               name = UUID.randomUUID().toString();
            }
            if (srcChild instanceof ContainerData)
            {
               dstChild = dst.add(ObjectType.CONTAINER, name);
            }
            else if (srcChild instanceof ApplicationData)
            {
               dstChild = dst.add(ObjectType.WINDOW, name);
            }
            else if (srcChild instanceof BodyData)
            {
               dstChild = dst.add(ObjectType.BODY, name);
            }
            else
            {
               throw new StaleModelException("Was not expecting child " + srcChild);
            }
            changes.add(new ModelChange.Create(dst.getObjectId(), srcChild));
         }

         //
         save(srcChild, dstChild, changes, hierarchyRelationships);

         //
         String dstChildId = dstChild.getObjectId();
         modelObjectMap.put(dstChildId, srcChild);
         orders.add(dstChildId);
      }

      // Take care of move operation that could be seen as a remove otherwise
      for (UIComponent dstChild : dst.getComponents())
      {
         String dstChildId = dstChild.getObjectId();
         if (!modelObjectMap.containsKey(dstChildId))
         {
            String parentId = hierarchyRelationships.get(dstChildId);
            if (parentId != null)
            {
               // Get the new parent
               UIContainer parent = session.findObjectById(ObjectType.CONTAINER, parentId);

               // Perform the move
               parent.getComponents().add(dstChild);

               //
               changes.add(new ModelChange.Move(dst.getObjectId(), parentId, dstChildId));

               // julien : we do not need to create an update operation
               // as later the update operation will be created when the object
               // will be processed
            }
         }
      }

      // Delete removed children
      for (Iterator<UIComponent> i = dst.getComponents().iterator(); i.hasNext();)
      {
         UIComponent dstChild = i.next();
         String dstChildId = dstChild.getObjectId();
         if (!modelObjectMap.containsKey(dstChildId))
         {
            i.remove();
            changes.add(new ModelChange.Destroy(dstChildId));
         }
View Full Code Here

TOP

Related Classes of org.gatein.mop.api.workspace.ui.UIComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.