public void rebuild() { // destroy all of the portlets and recreate from scratch portalLayout.removeFromParent(); portalLayout.destroy(); portalLayout = null; buildPortlets(); }
protected void addPortlet(String portletKey, String portletName) { DashboardPortlet storedPortlet = new DashboardPortlet(portletName, portletKey, 250); storedDashboard.addPortlet(storedPortlet); String locatorId = getPortletLocatorId(portalLayout, storedPortlet); final PortletWindow newPortletWindow = new PortletWindow(locatorId, this, storedPortlet, context); newPortletWindow.setTitle(portletName); newPortletWindow.setHeight(350); newPortletWindow.setVisible(false); portletWindows.add(newPortletWindow); portalLayout.addPortletWindow(newPortletWindow, storedPortlet.getColumn()); PortalColumn portalColumn = portalLayout.getPortalColumn(storedPortlet.getColumn()); // also insert a blank spacer element, which will trigger the built-in // animateMembers layout animation final LayoutSpacer placeHolder = new LayoutSpacer(); // placeHolder.setRect(newPortlet.getRect()); portalColumn.addMember(placeHolder); // add to top // create an outline around the clicked button final Canvas outline = new Canvas(); outline.setLeft(editForm.getAbsoluteLeft() + addPortlet.getLeft()); outline.setTop(editForm.getAbsoluteTop()); outline.setWidth(addPortlet.getWidth()); outline.setHeight(addPortlet.getHeight()); outline.setBorder("2px solid 8289A6"); outline.draw(); outline.bringToFront(); outline.animateRect( newPortletWindow.getPageLeft(), newPortletWindow.getPageTop(), newPortletWindow.getVisibleWidth(), newPortletWindow.getViewportHeight(), new AnimationCallback() { public void execute(boolean earlyFinish) { // callback at end of animation - destroy placeholder and outline; show the new portlet placeHolder.destroy(); outline.destroy(); newPortletWindow.show(); } }, 750); save(); }
/** * LocatorIds need to be repeatable and non-duplicated. The natural key for a portlet is the Id * but the Id is not a good locatorId as it may change (it's a sequence generated id) on * subsequent test runs. A portlet has an internal identifier (portletKey) and a name, but the * key-name tuple is not guaranteed to be unique as multiple instances of the same portlet type * may be present on the same, or across multiple dashboards. There is one tuple that is * guaranteed unique and useful for a repeatable locator Id: DashBoard-Position. This means that * the on a single dashboard each portlet has a unique column-columnIndex pair. Although portlets * can move, and the positions can change at runtime, it's still valid for a locatorId because it * is unique and repeatable for test purposes. We also add the portletKey for an easier visual * cue. The portalLayout's locatorId already incorporates the dashboardName, so we need only * extend it with the positioning information. * * @param portalLayout * @param dashboardPortlet * @return The locatorId for the portlet. Form PortleyKey_DashboardId_Column_ColumnIndex */ private String getPortletLocatorId(PortalLayout portalLayout, DashboardPortlet dashboardPortlet) { StringBuilder locatorId = new StringBuilder(dashboardPortlet.getPortletKey()); locatorId.append("_"); locatorId.append(dashboardPortlet.getColumn()); locatorId.append("_"); locatorId.append(dashboardPortlet.getIndex()); return portalLayout.extendLocatorId(locatorId.toString()); }
public void buildPortlets() { this.setBackgroundColor( storedDashboard.getConfiguration().getSimpleValue(Dashboard.CFG_BACKGROUND, "white")); portalLayout = new PortalLayout( extendLocatorId("PortalLayout"), this, storedDashboard.getColumns(), storedDashboard.getColumnWidths()); portalLayout.setOverflow(Overflow.AUTO); portalLayout.setWidth100(); portalLayout.setHeight100(); loadPortletWindows(); addMember(portalLayout); }
private void loadPortletWindows() { for (int i = 0; i < storedDashboard.getColumns(); i++) { for (DashboardPortlet storedPortlet : storedDashboard.getPortlets(i)) { String locatorId = getPortletLocatorId(portalLayout, storedPortlet); PortletWindow portletWindow = new PortletWindow(locatorId, this, storedPortlet, context); portletWindow.setTitle(storedPortlet.getName()); portletWindow.setHeight(storedPortlet.getHeight()); portletWindow.setVisible(true); portletWindows.add(portletWindow); portalLayout.addPortletWindow(portletWindow, i); } } }
public String[] updatePortalColumnWidths() { int numColumns = storedDashboard.getColumns(); int totalPixelWidth = 0; int[] columnPixelWidths = new int[numColumns]; for (int i = 0; i < numColumns; ++i) { PortalColumn col = portalLayout.getPortalColumn(i); totalPixelWidth += col.getWidth(); columnPixelWidths[i] = col.getWidth(); } String[] columnWidths = new String[numColumns]; columnWidths[numColumns - 1] = "*"; for (int i = 0; i < numColumns - 1; ++i) { columnWidths[i] = String.valueOf(((int) columnPixelWidths[i] * 100 / totalPixelWidth)) + "%"; } storedDashboard.setColumnWidths(columnWidths); return columnWidths; }
public void resize() { portalLayout.resize(); }