List of usage examples for org.apache.wicket.markup.html.list LoopItem getId
@Override
public String getId()
From source file:com.servoy.j2db.server.headlessclient.dataui.WebTabPanel.java
License:Open Source License
public WebTabPanel(IApplication application, final RuntimeTabPanel scriptable, String name, int orient, boolean oneTab) { super(name);//from w w w . j a v a2s . co m this.application = application; this.orient = orient; final boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$ setOutputMarkupPlaceholderTag(true); if (orient != TabPanel.SPLIT_HORIZONTAL && orient != TabPanel.SPLIT_VERTICAL) add(new Label("webform", new Model<String>("")));//temporary add, in case the tab panel does not contain any tabs //$NON-NLS-1$ //$NON-NLS-2$ // TODO check ignore orient and oneTab?? IModel<Integer> tabsModel = new AbstractReadOnlyModel<Integer>() { private static final long serialVersionUID = 1L; @Override public Integer getObject() { return Integer.valueOf(allTabs.size()); } }; if (orient != TabPanel.HIDE && orient != TabPanel.SPLIT_HORIZONTAL && orient != TabPanel.SPLIT_VERTICAL && !(orient == TabPanel.DEFAULT_ORIENTATION && oneTab)) { add(new Loop("tablinks", tabsModel) //$NON-NLS-1$ { private static final long serialVersionUID = 1L; private String focusedItem; @Override protected void populateItem(final LoopItem item) { final WebTabHolder holder = allTabs.get(item.getIteration()); MarkupContainer link = null; link = new ServoySubmitLink("tablink", useAJAX) //$NON-NLS-1$ { private static final long serialVersionUID = 1L; /** * @see wicket.ajax.markup.html.AjaxFallbackLink#onClick(wicket.ajax.AjaxRequestTarget) */ @Override public void onClick(AjaxRequestTarget target) { Page page = findPage(); if (page != null) { setActiveTabPanel(holder.getPanel()); if (target != null) { relinkAtTabPanel(WebTabPanel.this); focusedItem = item.getId(); WebEventExecutor.generateResponse(target, page); } } } private void relinkAtForm(WebForm form) { form.visitChildren(WebTabPanel.class, new IVisitor<WebTabPanel>() { public Object component(WebTabPanel wtp) { relinkAtTabPanel(wtp); return IVisitor.CONTINUE_TRAVERSAL; } }); } private void relinkAtTabPanel(WebTabPanel wtp) { wtp.relinkFormIfNeeded(); wtp.visitChildren(WebForm.class, new IVisitor<WebForm>() { public Object component(WebForm form) { relinkAtForm(form); return IVisitor.CONTINUE_TRAVERSAL; } }); } @Override protected void disableLink(final ComponentTag tag) { // if the tag is an anchor proper if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") //$NON-NLS-1$//$NON-NLS-2$ || tag.getName().equalsIgnoreCase("area")) //$NON-NLS-1$ { // Remove any href from the old link tag.remove("href"); //$NON-NLS-1$ tag.remove("onclick"); //$NON-NLS-1$ } } }; if (item.getId().equals(focusedItem)) { IRequestTarget currentRequestTarget = RequestCycle.get().getRequestTarget(); if (currentRequestTarget instanceof AjaxRequestTarget) { ((AjaxRequestTarget) currentRequestTarget).focusComponent(link); } focusedItem = null; } if (holder.getTooltip() != null) { link.setMetaData(TooltipAttributeModifier.TOOLTIP_METADATA, holder.getTooltip()); } TabIndexHelper.setUpTabIndexAttributeModifier(link, tabSequenceIndex); link.add(TooltipAttributeModifier.INSTANCE); if (item.getIteration() == 0) link.add(new AttributeModifier("firsttab", true, new Model<Boolean>(Boolean.TRUE))); //$NON-NLS-1$ link.setEnabled(holder.isEnabled() && WebTabPanel.this.isEnabled()); String text = holder.getText(); if (holder.getDisplayedMnemonic() > 0) { final String mnemonic = Character.toString((char) holder.getDisplayedMnemonic()); link.add(new SimpleAttributeModifier("accesskey", mnemonic)); //$NON-NLS-1$ if (text != null && text.contains(mnemonic) && !HtmlUtils.hasUsefulHtmlContent(text)) { StringBuffer sbBodyText = new StringBuffer(text); int mnemonicIdx = sbBodyText.indexOf(mnemonic); if (mnemonicIdx != -1) { sbBodyText.insert(mnemonicIdx + 1, "</u>"); //$NON-NLS-1$ sbBodyText.insert(mnemonicIdx, "<u>"); //$NON-NLS-1$ text = sbBodyText.toString(); } } } ServoyTabIcon tabIcon = new ServoyTabIcon("icon", holder, scriptable); //$NON-NLS-1$ link.add(tabIcon); Label label = new Label("linktext", new Model<String>(text)); //$NON-NLS-1$ label.setEscapeModelStrings(false); link.add(label); item.add(link); IModel<String> selectedOrDisabledClass = new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (!holder.isEnabled() || !WebTabPanel.this.isEnabled()) { if (currentForm == holder.getPanel()) { return "disabled_selected_tab"; //$NON-NLS-1$ } return "disabled_tab"; //$NON-NLS-1$ } else { if (currentForm == holder.getPanel()) { return "selected_tab"; //$NON-NLS-1$ } return "deselected_tab"; //$NON-NLS-1$ } } }; item.add(new AttributeModifier("class", true, selectedOrDisabledClass)); //$NON-NLS-1$ label.add(new StyleAppendingModifier(new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { String style = "white-space: nowrap;"; //$NON-NLS-1$ if (foreground != null) { style += " color:" + PersistHelper.createColorString(foreground); //$NON-NLS-1$ } if (holder.getIcon() != null) { style += "; padding-left: 3px"; //$NON-NLS-1$ } return style; } })); } }); // All tab panels get their tabs rearranged after they make it to the browser. // On Chrome & Safari the tab rearrangement produces an ugly flicker effect, because // initially the tabs are not visible and then they are made visible. By // sending the tab as invisible and turning it to visible only after the tabs // are arranged, this jumping/flickering effect is gone. However a small delay can now be // noticed in Chrome & Safari, which should also be eliminated somehow. // The tab panel is set to visible in function "rearrageTabsInTabPanel" from "servoy.js". add(new StyleAppendingModifier(new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return "visibility: hidden;overflow:hidden"; //$NON-NLS-1$ } })); add(new AbstractServoyDefaultAjaxBehavior() { @Override protected void respond(AjaxRequestTarget target) { } @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); boolean dontRearrangeHere = false; if (!(getRequestCycle().getRequestTarget() instanceof AjaxRequestTarget) && Utils.getAsBoolean(((MainPage) getPage()).getController().getApplication() .getRuntimeProperties().get("enableAnchors"))) //$NON-NLS-1$ { Component parentForm = getParent(); while ((parentForm != null) && !(parentForm instanceof WebForm)) parentForm = parentForm.getParent(); if (parentForm != null) { int anch = ((WebForm) parentForm).getAnchors(WebTabPanel.this.getMarkupId()); if (anch != 0 && anch != IAnchorConstants.DEFAULT) dontRearrangeHere = true; } } if (!dontRearrangeHere) { String jsCall = "rearrageTabsInTabPanel('" + WebTabPanel.this.getMarkupId() + "');"; //$NON-NLS-1$ //$NON-NLS-2$ // Safari and Konqueror have some problems with the "domready" event, so for those // browsers we'll use the "load" event. Otherwise use "domready", it reduces the flicker // effect when rearranging the tabs. ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties(); if (clp.isBrowserKonqueror() || clp.isBrowserSafari()) response.renderOnLoadJavascript(jsCall); else response.renderOnDomReadyJavascript(jsCall); } } @Override public boolean isEnabled(Component component) { return WebClientSession.get().useAjax(); } }); } add(StyleAttributeModifierModel.INSTANCE); add(TooltipAttributeModifier.INSTANCE); this.scriptable = scriptable; ((ChangesRecorder) scriptable.getChangesRecorder()).setDefaultBorderAndPadding(null, TemplateGenerator.DEFAULT_LABEL_PADDING); }