@Override public void setItems(FormItem... items) { for (FormItem nextFormItem : items) { nextFormItem.setWrapTitle(false); nextFormItem.setWidth(300); // wider than default if (nextFormItem instanceof TextItem) { nextFormItem.addKeyPressHandler(this); } else if (nextFormItem instanceof SelectItem) { nextFormItem.addChangedHandler(this); } else if (nextFormItem instanceof EnhancedSearchBarItem) { // searchBarItem = (SearchBarItem) nextFormItem; // searchBarItem.getSearchBar().addKeyPressHandler(this); String name = searchBarItem.getName(); searchBarItem.setName(name + "_hidden"); hiddenItem = new HiddenItem(name); // hiddenItem.setValue(searchBarItem.getSearchBar().getValue()); } } if (hiddenItem != null) { FormItem[] tmpItems = new FormItem[items.length + 1]; System.arraycopy(items, 0, tmpItems, 0, items.length); tmpItems[items.length] = hiddenItem; items = tmpItems; } super.setItems(items); }
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(); }
public TagInputDialog(String locatorId) { super(locatorId); setIsModal(true); setShowHeader(false); setShowEdges(false); setEdgeSize(10); setWidth(200); setHeight(30); setShowToolbar(false); setDismissOnEscape(true); setDismissOnOutsideClick(true); Map<String, Integer> bodyDefaults = new HashMap<String, Integer>(2); bodyDefaults.put("layoutLeftMargin", 5); bodyDefaults.put("membersMargin", 10); setBodyDefaults(bodyDefaults); final LocatableDynamicForm form = new LocatableDynamicForm(extendLocatorId("tagInputForm")); addItem(form); tagInputItem = new ComboBoxItem("tag"); tagInputItem.setShowTitle(false); tagInputItem.setHideEmptyPickList(true); tagInputItem.setValueField("tag"); tagInputItem.setDisplayField("tag"); tagInputItem.setType("comboBox"); tagInputItem.setTextMatchStyle(TextMatchStyle.SUBSTRING); tagInputItem.setTooltip(MSG.view_tags_tooltip_3()); tagInputItem.addKeyPressHandler( new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if ((event.getCharacterValue() != null) && (event.getCharacterValue() == KeyCodes.KEY_ENTER)) { // String tag = form.getValueAsString("tag"); String tag = tagInputItem.getEnteredValue(); if (tag != null) { Tag newTag = new Tag(tag); tags.add(newTag); TagEditorView.this.save(); TagInputDialog.this.hide(); } } } }); form.setFields(tagInputItem); }
private DynamicForm buildEditForm() { editForm = new LocatableDynamicForm(extendLocatorId("Editor")); editForm.setMargin(5); editForm.setAutoWidth(); editForm.setNumCols(canEditName() ? 12 : 10); TextItem nameItem = null; if (dashboardContainer.supportsDashboardNameEdit()) { nameItem = new TextItem("name", MSG.common_title_dashboard_name()); nameItem.setValue(storedDashboard.getName()); nameItem.setLength(200); nameItem.setWrapTitle(false); nameItem.addBlurHandler( new BlurHandler() { public void onBlur(BlurEvent blurEvent) { FormItem nameItem = blurEvent.getItem(); String name = (String) nameItem.getValue(); String trimmedName = (name == null) ? "" : name.trim(); if (dashboardContainer.isValidDashboardName(trimmedName)) { storedDashboard.setName(trimmedName); save(); dashboardContainer.updateDashboardNames(); } else { // TODO: i18n Message message = new Message( "There is already a dashboard named '" + trimmedName + "'. Please specify a name that is not already in use.", Message.Severity.Error, EnumSet.of(Message.Option.Transient)); CoreGUI.getMessageCenter().notify(message); nameItem.setValue(storedDashboard.getName()); } } }); } final StaticTextItem numColItem = new StaticTextItem(); numColItem.setTitle(MSG.common_title_columns()); numColItem.setValue(storedDashboard.getColumns()); ButtonItem addColumn = new ButtonItem("addColumn", MSG.common_title_add_column()); addColumn.setAutoFit(true); addColumn.setStartRow(false); addColumn.setEndRow(false); final ButtonItem removeColumn = new ButtonItem("removeColumn", MSG.common_title_remove_column()); removeColumn.setAutoFit(true); removeColumn.setStartRow(false); removeColumn.setEndRow(false); removeColumn.setDisabled(storedDashboard.getColumns() == 1); addColumn.addClickHandler( new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { portalLayout.addMember(new PortalColumn()); numColItem.setValue(storedDashboard.getColumns() + 1); storedDashboard.setColumns(storedDashboard.getColumns() + 1); removeColumn.setDisabled(storedDashboard.getColumns() == 1); save(); } }); removeColumn.addClickHandler( new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { Canvas[] columns = portalLayout.getMembers(); int numColumns = columns.length; if (numColumns > 0) { PortalColumn lastColumn = (PortalColumn) columns[numColumns - 1]; for (Canvas portletWindow : lastColumn.getMembers()) { storedDashboard.removePortlet(((PortletWindow) portletWindow).getStoredPortlet()); } portalLayout.removeMember(lastColumn); numColItem.setValue(numColumns - 1); storedDashboard.setColumns(storedDashboard.getColumns() - 1); removeColumn.setDisabled(storedDashboard.getColumns() == 1); save(); } } }); // build the menu of valid portlets for this context, sorted by portlet name final Menu addPortletMenu = new LocatableMenu(editForm.extendLocatorId("PortletMenu")); LinkedHashMap<String, String> valueMap; switch (context.getType()) { case SubsystemView: valueMap = PortletFactory.getGlobalPortletMenuMap(); break; case ResourceGroup: valueMap = processPortletNameMapForGroup(this.groupComposite); // In addition to the group-specific portlets, make the global portlets available valueMap.putAll(PortletFactory.getGlobalPortletMenuMap()); break; case Resource: valueMap = processPortletNameMapForResource(this.resourceComposite); // In addition to the resource-specific portlets, make the global portlets available valueMap.putAll(PortletFactory.getGlobalPortletMenuMap()); break; default: throw new IllegalStateException("Unsupported context [" + context + "]"); } for (Iterator<String> i = valueMap.keySet().iterator(); i.hasNext(); ) { String portletKey = i.next(); String portletName = valueMap.get(portletKey); MenuItem menuItem = new MenuItem(portletName); menuItem.setAttribute("portletKey", portletKey); addPortletMenu.addItem(menuItem); } addPortlet = new LocatableIMenuButton( editForm.extendLocatorId("AddPortlet"), MSG.common_title_add_portlet(), addPortletMenu); addPortlet.setIcon("[skin]/images/actions/add.png"); addPortlet.setAutoFit(true); addPortletMenu.addItemClickHandler( new ItemClickHandler() { public void onItemClick(ItemClickEvent itemClickEvent) { String key = itemClickEvent.getItem().getAttribute("portletKey"); String name = itemClickEvent.getItem().getTitle(); addPortlet(key, name); } }); CanvasItem addCanvas = new CanvasItem(); addCanvas.setShowTitle(false); addCanvas.setCanvas(addPortlet); addCanvas.setStartRow(false); addCanvas.setEndRow(false); ColorButtonItem picker = new ColorButtonItem("colorButton", MSG.common_title_background()); picker.setStartRow(false); picker.setEndRow(false); picker.setCurrentColor( storedDashboard.getConfiguration().getSimpleValue(Dashboard.CFG_BACKGROUND, "white")); picker.setColorSelectedHandler( new ColorSelectedHandler() { @Override public void onColorSelected(ColorSelectedEvent event) { String selectedColor = event.getColor(); if (selectedColor != null) { setBackgroundColor(selectedColor); storedDashboard .getConfiguration() .put(new PropertySimple(Dashboard.CFG_BACKGROUND, selectedColor)); save(); } } }); // refresh interval LocatableMenu refreshMenu = new LocatableMenu("AutoRefreshMenu"); refreshMenu.setShowShadow(true); refreshMenu.setShadowDepth(10); refreshMenu.setAutoWidth(); refreshMenu.setHeight(15); ClickHandler menuClick = new ClickHandler() { @Override public void onClick(MenuItemClickEvent event) { String selection = event.getItem().getTitle(); refreshInterval = 0; if (selection != null) { if (selection.equals(STOP)) { refreshInterval = STOP_VALUE; } else if (selection.equals(REFRESH1)) { refreshInterval = REFRESH1_VALUE; } else if (selection.equals(REFRESH5)) { refreshInterval = REFRESH5_VALUE; } else if (selection.equals(REFRESH10)) { refreshInterval = REFRESH10_VALUE; } else { // unable to locate value disable refresh refreshInterval = STOP_VALUE; // } UserSessionManager.getUserPreferences() .setPageRefreshInterval(refreshInterval, new UpdatePortletRefreshCallback()); } } }; String[] refreshIntervals = {STOP, REFRESH1, REFRESH5, REFRESH10}; Integer[] refreshValues = {STOP_VALUE, REFRESH1_VALUE, REFRESH5_VALUE, REFRESH10_VALUE}; refreshMenuMappings = new HashMap<Integer, String>(); refreshMenuItems = new MenuItem[refreshIntervals.length]; int retrievedRefreshInterval = REFRESH1_VALUE; if (null != UserSessionManager.getUserPreferences()) { retrievedRefreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval(); } for (int i = 0; i < refreshIntervals.length; i++) { MenuItem item = new MenuItem(refreshIntervals[i], ""); item.addClickHandler(menuClick); refreshMenuMappings.put(refreshValues[i], refreshIntervals[i]); if (retrievedRefreshInterval == refreshValues[i]) { item.setIcon(ImageManager.getAvailabilityIcon(true)); } refreshMenuItems[i] = item; } refreshMenu.setItems(refreshMenuItems); refreshMenuButton = new LocatableIMenuButton( "AutoRefreshButton", MSG.common_title_change_refresh_time(), refreshMenu); refreshMenu.setAutoHeight(); refreshMenuButton.getMenu().setItems(refreshMenuItems); refreshMenuButton.setWidth(140); refreshMenuButton.setShowTitle(true); refreshMenuButton.setTop(0); refreshMenuButton.setIconOrientation("left"); CanvasItem refreshCanvas = new CanvasItem(); refreshCanvas.setShowTitle(false); refreshCanvas.setCanvas(refreshMenuButton); refreshCanvas.setStartRow(false); refreshCanvas.setEndRow(false); if (null != nameItem) { editForm.setItems( nameItem, addCanvas, numColItem, addColumn, removeColumn, picker, refreshCanvas); } else { editForm.setItems(addCanvas, numColItem, addColumn, removeColumn, picker, refreshCanvas); } updateRefreshMenu(); this.refreshMenuButton.markForRedraw(); markForRedraw(); // attempt to initialize editForm.markForRedraw(); markForRedraw(); return editForm; }