📄 portletbeangrid.java
字号:
the current row position. If so reduce the row to include at the end of the column, avoiding "hole" creation. */ if (targetPortlet.getPortletRow() >= getRowCount(targetPortlet.getPortletColumn() - 1) ) { targetPortlet.setPortletRow(getRowCount(targetPortlet.getPortletColumn() - 1)); } targetPortlet.setPortletColumn(targetPortlet.getPortletColumn() - 1); } } /** * Move the specified portlet one column to the right, creating a new column * if the portlet is already at the rightmost position before the move. * @param portletID identifier of the portlet to be moved * @throws JahiaException if the portlet corresponding to the identifier * cannot be found */ public void movePortletRight(int portletID) throws JahiaException { JahiaConsole.println("PortletBeanGrid.movePortletRight", "Moving portlet " + Integer.toString(portletID) + " to the right..."); PortletBean targetPortlet = findPortlet(portletID); int oldRow = targetPortlet.getPortletRow(); int oldColumn = targetPortlet.getPortletColumn(); if (oldColumn == getColumnCount()-1) { columnCount++; /* Let's move all the portlets in the current column up one row */ JahiaConsole.println("PortletBeanGrid.movePortletRight", "Deleting from column " + Integer.toString(oldColumn) + ", moving " + Integer.toString(getRowCount(oldColumn)) + " portlets up..."); for (int i = oldRow+1; i <= getRowCount(oldColumn); i++) { PortletBean curPortlet = getPosPortlet(i, oldColumn); if (curPortlet != null) { curPortlet.setPortletRow(i-1); } } } else { /* Let's move all the portlets in the current column up one row */ JahiaConsole.println("PortletBeanGrid.movePortletRight", "Deleting from column " + Integer.toString(oldColumn) + ", moving " + Integer.toString(getRowCount(oldColumn)) + " portlets up..."); for (int i = oldRow+1; i <= getRowCount(oldColumn); i++) { PortletBean curPortlet = getPosPortlet(i, oldColumn); if (curPortlet != null) { curPortlet.setPortletRow(i-1); } } /* Let's move all the portlets in the new column down to insert the portlet */ JahiaConsole.println("PortletBeanGrid.movePortletRight", "Making space in column " + Integer.toString(oldColumn+1) + ", moving " + Integer.toString(getRowCount(oldColumn+1)) + "portlets down..."); for (int i = getRowCount(oldColumn + 1) - 1; i >= targetPortlet.getPortletRow(); i--) { PortletBean curPortlet = getPosPortlet(i, oldColumn + 1); if (curPortlet != null) { curPortlet.setPortletRow(i+1); } } } /* Let's check if we are inserting in a column that is smaller than the current row position. If so reduce the row to include at the end of the column, avoiding "hole" creation. */ if (targetPortlet.getPortletRow() >= getRowCount(oldColumn + 1) ) { targetPortlet.setPortletRow(getRowCount(oldColumn + 1)); } targetPortlet.setPortletColumn(oldColumn + 1); } /** * Retrieves the column count present in the grid. This is obtained by going * through all the portlets and keeping the maximal value. * Note : this might mean that some columns do not contain portlets. * @returns an integer that represents the maximal column value in the grid * @todo investigate how this behaves when column "holes" are present */ public int getColumnCount() { Enumeration portletBeanEnum = this.elements(); while (portletBeanEnum.hasMoreElements()) { PortletBean portlet = (PortletBean) portletBeanEnum.nextElement(); if (portlet.getPortletColumn() + 1 > columnCount) { columnCount = portlet.getPortletColumn() + 1; } } return columnCount; } /** * Retrieves the column count in the specified row. * @param rowID the identifier (0-based) of the row in which we want to count * the columns. * @returns an integer representing the number of columns in the specified * row */ public int getColumnCount (int rowID) throws JahiaException { int resultColumnCount = 0; Enumeration portletBeanEnum = this.elements(); while (portletBeanEnum.hasMoreElements()) { PortletBean portlet = (PortletBean) portletBeanEnum.nextElement(); if (portlet.getPortletRow() == rowID) { if (portlet.getPortletColumn() + 1 > resultColumnCount) { resultColumnCount = portlet.getPortletColumn() + 1; } } } return resultColumnCount; } /** * Retrieves the row count present in the grid. This is obtained by going * through all the portlets and keeping the maximal value. * Note : this might mean that some rows do not contain portlets. * @returns an integer that represents the maximal row value in the grid * @todo investigate how this behaves when row "holes" are present in the * grid */ public int getRowCount() { Enumeration portletBeanEnum = this.elements(); while (portletBeanEnum.hasMoreElements()) { PortletBean portlet = (PortletBean) portletBeanEnum.nextElement(); if (portlet.getPortletRow() + 1 > rowCount) { rowCount = portlet.getPortletRow() + 1; } } return rowCount; } /** * Retrieves the row count present in the grid at the specified column. * @param columnID the identifier (0-based) of the column we want to get the * row count of. * @returns an integer that represents the maximal row value in the specified * column */ public int getRowCount(int columnID) throws JahiaException { int resultRowCount = 0; Enumeration portletBeanEnum = this.elements(); while (portletBeanEnum.hasMoreElements()) { PortletBean portlet = (PortletBean) portletBeanEnum.nextElement(); if (portlet.getPortletColumn() == columnID) { if (portlet.getPortletRow() + 1 > resultRowCount) { resultRowCount = portlet.getPortletRow() + 1; } } } return resultRowCount; } /** * Insert a new portlet into the set. What is done here is position checking * to make sure the new portlet does not overlap or conflict with an existing * portlet. * WARNING : this method modifies the position of the portlet bean object !! * @param portlet PortletBean object to insert in the grid. This object will * also be modified so that the correct position is reflected in the portlet * @returns true on success, false on failure (failure is not defined for the * moment) */ public boolean add(PortletBean portlet) { // let's do position checking. Enumeration portletBeanEnum = this.elements(); while (portletBeanEnum.hasMoreElements()) { PortletBean curPortlet = (PortletBean) portletBeanEnum.nextElement(); if ((curPortlet.getPortletRow() == portlet.getPortletRow()) && (curPortlet.getPortletColumn() == portlet.getPortletColumn())) { // we have found a conflict, let's resolve it. int maxRow = getRowCount(); portlet.setPortletRow(maxRow); portlet.setPortletColumn(0); JahiaConsole.println("PortletBeanGrid.add", "Conflict found, modifying new portlet position to row=" + maxRow + " column=0"); } } return super.add(portlet); } /** * Displays the grid on the jahia console by inserting the portlet ID into * each cell. */ public void debugDisplayGrid() { String separatorLine = new String(); for (int j=0; j < this.getColumnCount(); j++) { separatorLine = separatorLine + "+-----"; } StringBuffer curLine; String idStr; for (int i=0; i < this.getRowCount(); i++) { curLine = new StringBuffer(); curLine = new StringBuffer(); for (int j=0; j < this.getColumnCount(); j++) { PortletBean curPortlet = this.getPosPortlet(i, j); curLine.append("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -