rowcolumncontrolleraction.java

来自「jetspeed源代码」· Java 代码 · 共 636 行 · 第 1/2 页

JAVA
636
字号
                logger.error("Unable to load action controls.EndCustomize ",e);
            }
        }
    }

    /** Remove a pane from the current set
     *  This method expects the following parameters
     * - paneid: the id a the pane to modify within the current profile
     * - position: the position of the component to delete
     */
    public void doDelete(RunData data, Context context) throws Exception
    {
      JetspeedRunData jdata = (JetspeedRunData)data;
      PortletSet customizedSet = (PortletSet)jdata.getCustomized();
      int position = data.getParameters().getInt("position",-1);
      Profile profile = jdata.getCustomizedProfile();

      // ADDED for WML
      //boolean isWML = (profile.getMediaType().equalsIgnoreCase("wml"));


        if (customizedSet == null) return;

        if (position > -1)
        {
            Portlets set = profile.getDocument()
                                  .getPortletsById(customizedSet.getID());
            if (set != null)
            {
                // first try explicit portlets position
                for(int i=0; i < set.getPortletsCount(); i++)
                {
                    Portlets p = set.getPortlets(i);
                    Layout layout = p.getLayout();
//
//                    if (layout == null)
//                    {
//                      Layout nl = new Layout ();
//                      nl.setPosition (String.valueOf(i));
//
//                    }
                    if ((layout!=null) && (layout.getPosition() != -1))
                    {

                        int lpos = (int)layout.getPosition();
                        if (lpos==position)
                        {
                            set.removePortlets(i);

                            updateLayoutPositions(set);

                            // MODIFIED: Save changes for wml profiles
                            //if (isWML)
                            //  doSave(data, null);

                            return;
                        }
                    }
                }

                // try explicit entry position
                for(int i=0; i < set.getEntryCount(); i++)
                {
                    Entry p = set.getEntry(i);
                    Layout layout = p.getLayout();

                    if ((layout!=null) && (layout.getPosition() != -1))
                    {
                        int lpos = (int)layout.getPosition();

                        if (lpos==position)
                        {
                            set.removeEntry(i);

                            // MODIFIED: Save changes for wml profiles
                            //if (isWML)
                            //  doSave(data, null);
                            return;
                        }
                    }
                }

                //else use implicit position
                if (position < set.getPortletsCount())
                {
                    set.removePortlets(position);

                    // MODIFIED: Save changes for wml profiles
                    //if (isWML)
                    //  doSave(data, null);
                    return;
                }

                if (position < set.getEntryCount())
                {
                    set.removeEntry(position);

                    // MODIFIED: Save changes for wml profiles
                    //if (isWML)
                    //  doSave(data, null);
                    return;
                }
            }
        }


    }

    /**
     * Updates the layout position based on physical order within the resorted portlet list. Assures that 
     * layout position is always consecutive and within bounds.
     * 
     * @param set
     */
    private void updateLayoutPositions(Portlets set)
    {
        // Load the panes into a list
        List list = new ArrayList();
        for(int i = 0; i < set.getPortletsCount(); i++)
        {
            Portlets pane = set.getPortlets(i);
            list.add(pane);
        }

        // Sort list using the current layout position
        Collections.sort(list, 
                         new Comparator()
                         {
                             public int compare(Object pane1, Object pane2)
                             {
                                 Long pos1 = new Long(((Portlets) pane1).getLayout().getPosition());
                                 Long pos2 = new Long(((Portlets) pane2).getLayout().getPosition());
                                 return pos1.compareTo(pos2);
                             }
                         });

        // Update the layout position based on the physical order within the sorted list
        int position = 0;
        for (Iterator iter = list.iterator(); iter.hasNext();)
        {
            Portlets pane = (Portlets) iter.next();
            Layout layout = pane.getLayout();
            layout.setPosition(position++);
        }
    }

    /** Move a component up within the pane
     *  This method expects the following parameters
     * - paneid: the id a the pane to modify within the current profile
     * - position: move the component which occupies this position
     */
    public void doUp(RunData data, Context context) throws Exception
    {
        doMove(data,context,true);
    }

    /** Move a component down within the pane
     *  This method expects the following parameters
     * - paneid: the id a the pane to modify within the current profile
     * - position: move the component which occupies this position
     */
    public void doDown(RunData data, Context context) throws Exception
    {
        doMove(data,context,false);
    }

    /** Move a component within the pane
     *  This method expects the following parameters
     * - paneid: the id a the pane to modify within the current profile
     * - position: move the component which occupies this position
     * The moveUp boolean determines the direction of the move
     */
    public void doMove(RunData data, Context context, boolean moveUp) throws Exception
    {
        JetspeedRunData jdata = (JetspeedRunData)data;
        PortletSet customizedSet = (PortletSet)jdata.getCustomized();
        int position = data.getParameters().getInt("position",-1);
        Profile profile = jdata.getCustomizedProfile();

        // ADDED for WML
        //boolean isWML = (profile.getMediaType().equalsIgnoreCase("wml"));


        if (customizedSet == null) return;

        if (position > -1)
        {
            int target = -1;

            Portlets set = profile.getDocument()
                                  .getPortletsById(customizedSet.getID());
            Layout targetLayout = null;
            Layout baseLayout = null;

            if (set != null)
            {
                // check if we can possibly move as requested and calculate
                // target position
                if ( moveUp )
                {
                    if ( (position >= set.getPortletsCount())
                         && (position >= set.getEntryCount()) ) return;
                    target = position + 1;
                }
                else
                {
                    if (position ==0) return;
                    target = position - 1;
                }

                // first find objects at explicit portlets position
                for(int i=0; i < set.getPortletsCount(); i++)
                {
                    if ((targetLayout!=null) && (baseLayout!=null)) break;

                    Portlets p = set.getPortlets(i);
                    Layout layout = p.getLayout();
                    if ((layout!=null)&&(layout.getPosition()!=-1))
                    {
                        int lpos = (int)layout.getPosition();
                        if ((baseLayout == null) && (lpos==position))
                        {
                            baseLayout = layout;
                        }

                        if ((targetLayout == null) && (lpos==target))
                        {
                            targetLayout = layout;
                        }
                    }
                }

                // try explicit entry position
                for(int i=0; i < set.getEntryCount(); i++)
                {
                    if ((targetLayout!=null) && (baseLayout!=null)) break;

                    Entry p = set.getEntry(i);
                    Layout layout = p.getLayout();
                    if ((layout!=null)&&(layout.getPosition()!=-1))
                    {
                        int lpos = (int)layout.getPosition();
                        if ((baseLayout == null) && (lpos==position))
                        {
                            baseLayout = layout;
                        }

                        if ((targetLayout == null) && (lpos==target))
                        {
                            targetLayout = layout;
                        }
                    }
                }

                //else use implicit position
                if (baseLayout == null)
                {
                    if (position < set.getPortletsCount())
                    {
                        Portlets p = set.getPortlets(position);
                        if (p.getLayout()==null)
                        {
                            p.setLayout(new PsmlLayout());
                        }
                        baseLayout=p.getLayout();
                    }

                    if (position < set.getEntryCount())
                    {
                        Entry p = set.getEntry(position);
                        if (p.getLayout()==null)
                        {
                            p.setLayout(new PsmlLayout());
                        }
                        baseLayout=p.getLayout();
                    }
                }

                if (targetLayout == null)
                {
                    if (target < set.getPortletsCount())
                    {
                        Portlets p = set.getPortlets(target);
                        if (p.getLayout()==null)
                        {
                            p.setLayout(new PsmlLayout());
                        }
                        targetLayout=p.getLayout();
                    }

                    if (target < set.getEntryCount())
                    {
                        Entry p = set.getEntry(target);
                        if (p.getLayout()==null)
                        {
                            p.setLayout(new PsmlLayout());
                        }
                        targetLayout=p.getLayout();
                    }
                }

                //we should now have found both baseLayout and targetLayout, swap
                //their positions using explicit positioning

                if ((baseLayout == null) || (targetLayout == null)) return;

                baseLayout.setPosition(target);
                targetLayout.setPosition(position);
            }
        }


    // MODIFIED: Save changes for wml profiles
    //if (isWML)
    //  doSave(data, null);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?