List of usage examples for org.apache.wicket Component add
public Component add(final Behavior... behaviors)
From source file:com.servoy.j2db.server.headlessclient.dataui.SortableCellViewHeader.java
License:Open Source License
private void applyStyleChanges(Component c, final Properties changes) { StyleAppendingModifier headerStyles = new StyleAppendingModifier(new Model<String>() { @Override/*from w ww. j a v a 2 s. c om*/ public String getObject() { StringBuilder headerStyle = new StringBuilder(); Iterator<Entry<Object, Object>> headerStyleIte = changes.entrySet().iterator(); Entry<Object, Object> headerStyleEntry; while (headerStyleIte.hasNext()) { headerStyleEntry = headerStyleIte.next(); headerStyle.append(headerStyleEntry.getKey()).append(":").append(headerStyleEntry.getValue()) .append(";"); } return headerStyle.toString(); } }) { @Override public boolean isEnabled(Component c) { Iterator<IPersist> it2 = SortableCellViewHeader.this.cellview.getAllObjects(); while (it2.hasNext()) { IPersist element = it2.next(); if (SortableCellViewHeader.this.id .equals(ComponentFactory.getWebID(SortableCellViewHeader.this.form, element)) && SortableCellViewHeader.this.view.labelsFor .get(((ISupportName) element).getName()) != null) { return false; } } return true; } }; c.add(headerStyles); }
From source file:com.servoy.j2db.server.headlessclient.dataui.SortableCellViewHeader.java
License:Open Source License
private void applyInlineStyleString(Component c, final String inlineCSSSting) { StyleAppendingModifier headerStyles = new StyleAppendingModifier(new Model<String>() { @Override/*from w w w. ja v a 2 s . co m*/ public String getObject() { return inlineCSSSting; } }) { @Override public boolean isEnabled(Component c) { Iterator<IPersist> it2 = SortableCellViewHeader.this.cellview.getAllObjects(); while (it2.hasNext()) { IPersist element = it2.next(); if (SortableCellViewHeader.this.id .equals(ComponentFactory.getWebID(SortableCellViewHeader.this.form, element)) && SortableCellViewHeader.this.view.labelsFor .get(((ISupportName) element).getName()) != null) { return false; } } return true; } }; c.add(headerStyles); }
From source file:com.servoy.j2db.server.headlessclient.dataui.StartEditOnFocusGainedEventBehavior.java
License:Open Source License
/** * Add a focus gained behavior when it is not there yet. * /*from w w w. j a va2 s . c om*/ * @param component * @return added */ public static boolean addNewBehaviour(Component component) { List behaviors = component.getBehaviors(); if (behaviors != null) { for (Object behavior : behaviors) { if (StartEditOnFocusGainedEventBehavior.class.isAssignableFrom(behavior.getClass())) { return false; } } } component.add(new StartEditOnFocusGainedEventBehavior()); return true; }
From source file:com.servoy.j2db.server.headlessclient.dataui.TooltipAttributeModifier.java
License:Open Source License
@Override public void bind(final Component component) { super.bind(component); component.add(new SimpleAttributeModifier("onmouseout", "hidetip();") { @Override//from w w w.j av a 2 s . c om public boolean isEnabled(Component component) { String tooltip = getToolTipForComponent(component); if (tooltip == null) { return false; } return super.isEnabled(component); } }); }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebAnchoringHelper.java
License:Open Source License
public static Component getWrapperComponent(Component comp, IFormElement obj, int start, Dimension panelSize, boolean leftToRight, boolean isInListView) { MarkupContainer compWrapper = new WrapperContainer( ComponentFactory.getWebID(null, obj) + TemplateGenerator.WRAPPER_SUFFIX, comp); Point l = (obj).getLocation(); if (isInListView) { // substract left indicator l.x = Math.max(l.x - 3, 0); }/*from w ww. j a v a 2 s .co m*/ Dimension s = (obj).getSize(); int anchors = 0; if (obj instanceof ISupportAnchors) anchors = ((ISupportAnchors) obj).getAnchors(); int offsetWidth = s.width; int offsetHeight = s.height; if (comp instanceof ISupportWebBounds) { Rectangle b = ((ISupportWebBounds) comp).getWebBounds(); offsetWidth = b.width; offsetHeight = b.height; } final String styleToReturn = WebAnchoringHelper.computeWrapperDivStyle(l.y, l.x, offsetWidth, offsetHeight, s.width, s.height, anchors, start, start + panelSize.height, panelSize.width, leftToRight); // first the default compWrapper.add(new StyleAppendingModifier(new AbstractReadOnlyModel<String>() { @Override public String getObject() { return styleToReturn; } })); // then the style t hat can be set on the wrapped component compWrapper.add(StyleAttributeModifierModel.INSTANCE); // TODO: this needs to be done in a cleaner way. See what is the relation between // margin, padding and border when calculating the websize in ChangesRecorder vs. TemplateGenerator. // Looks like one of the three is not taken into account during calculations. For now decided to remove // the margin and leave the padding and border. comp.add(new StyleAppendingModifier(new AbstractReadOnlyModel<String>() { @Override public String getObject() { return "margin: 0px;"; //$NON-NLS-1$ } })); return compWrapper; }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.java
License:Open Source License
private void addClassToCellComponent(final Component c) { Model<String> componentClassModel = new Model<String>() { @Override//from w w w .jav a 2 s .com public String getObject() { return c.getId(); } }; c.add(new AttributeModifier("class", true, componentClassModel) //$NON-NLS-1$ { @Override protected String newValue(final String currentValue, String replacementValue) { String currentClass = currentValue == null ? "" : currentValue; //$NON-NLS-1$ String replacementClass = ""; //$NON-NLS-1$ if (replacementValue != null) { replacementClass = replacementValue; if (currentClass.equals(replacementClass)) return currentClass.trim(); // check if already added int replacementClassIdx = currentClass.indexOf(replacementClass); if ((replacementClassIdx != -1) && (replacementClassIdx == 0 || currentClass.charAt(replacementClassIdx - 1) == ' ') && (replacementClassIdx == currentClass.length() - replacementClass.length() || currentClass .charAt(replacementClassIdx + replacementClass.length()) == ' ')) { return currentClass.trim(); } } String result = replacementClass + " " + currentClass; //$NON-NLS-1$ return result.trim(); } }); }
From source file:com.servoy.j2db.server.headlessclient.TabIndexHelper.java
License:Open Source License
private static void setUpTabIndexAttributeModifierInternal(Component comp, int newTabIndex) { TabIndexAttributeModifier modifier = null; final Component component = comp; for (Object obeh : component.getBehaviors()) { IBehavior beh = (IBehavior) obeh; if (beh instanceof TabIndexAttributeModifier) { modifier = (TabIndexAttributeModifier) beh; break; }/*from w w w. ja v a2 s . c o m*/ } boolean componentChanged = true; boolean changeForClientSide = false; if (modifier == null) { if (newTabIndex != ISupportWebTabSeq.DEFAULT && isTabIndexSupported(component)) component.add(new TabIndexAttributeModifier(newTabIndex)); } else if (newTabIndex != ISupportWebTabSeq.DEFAULT) { if (newTabIndex != modifier.getTabIndex()) { modifier.setTabIndex(newTabIndex); if (!(component instanceof IProviderStylePropertyChanges) || !((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) { // if is already changed leave it to server side changeForClientSide = true; } } else { componentChanged = false; } } else { component.remove(modifier); } if (componentChanged) { MainPage page = component.findParent(MainPage.class); if (changeForClientSide) { if (page != null) { page.getPageContributor().addTabIndexChange(component.getMarkupId(), newTabIndex); } else { changeForClientSide = false; } } if (!changeForClientSide && component instanceof IProviderStylePropertyChanges) { IProviderStylePropertyChanges changeable = (IProviderStylePropertyChanges) component; changeable.getStylePropertyChanges().setChanged(); if (page != null) { page.getPageContributor().addTabIndexChange(component.getMarkupId(), ISupportWebTabSeq.DEFAULT); } } } }
From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java
License:Open Source License
/** * @see wicket.protocol.http.WebApplication#init() *///from w w w . ja va 2s . c o m @Override protected void init() { if (ApplicationServerRegistry.get() == null) return; // TODO this is a workaround to allow mobile test client that only starts Tomcat not to give exceptions (please remove if mobile test client initialises a full app. server in the future) getResourceSettings().setResourceWatcher(new ServoyModificationWatcher(Duration.seconds(5))); // getResourceSettings().setResourcePollFrequency(Duration.seconds(5)); getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true); getResourceSettings().setDefaultCacheDuration((int) Duration.days(365).seconds()); getMarkupSettings().setCompressWhitespace(true); getMarkupSettings().setMarkupCache(new ServoyMarkupCache(this)); // getMarkupSettings().setStripWicketTags(true); getResourceSettings().setResourceStreamLocator(new ServoyResourceStreamLocator(this)); getResourceSettings().setPackageResourceGuard(new ServoyPackageResourceGuard()); // getResourceSettings().setResourceFinder(createResourceFinder()); getResourceSettings().setThrowExceptionOnMissingResource(false); getApplicationSettings().setPageExpiredErrorPage(ServoyExpiredPage.class); getApplicationSettings().setClassResolver(new ServoyClassResolver()); getSessionSettings().setMaxPageMaps(15); // getRequestCycleSettings().setGatherExtendedBrowserInfo(true); getSecuritySettings().setCryptFactory(new CachingKeyInSessionSunJceCryptFactory()); Settings settings = Settings.getInstance(); getDebugSettings().setOutputComponentPath( Utils.getAsBoolean(settings.getProperty("servoy.webclient.debug.wicketpath", "false"))); //$NON-NLS-1$ //$NON-NLS-2$ if (Utils.getAsBoolean(settings.getProperty("servoy.webclient.nice.urls", "false"))) //$NON-NLS-1$ //$NON-NLS-2$ { mount(new HybridUrlCodingStrategy("/solutions", SolutionLoader.class)); //$NON-NLS-1$ mount(new HybridUrlCodingStrategy("/application", MainPage.class)); //$NON-NLS-1$ mount(new HybridUrlCodingStrategy("/ss", SolutionLoader.class) //$NON-NLS-1$ { /** * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget) */ @Override public boolean matches(IRequestTarget requestTarget) { return false; } }); } else { mountBookmarkablePage("/solutions", SolutionLoader.class); //$NON-NLS-1$ mount(new BookmarkablePageRequestTargetUrlCodingStrategy("/ss", SolutionLoader.class, null) //$NON-NLS-1$ { /** * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget) */ @Override public boolean matches(IRequestTarget requestTarget) { return false; } }); } long maxSize = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false); //$NON-NLS-1$ //$NON-NLS-2$ if (maxSize > 0) { getApplicationSettings().setDefaultMaximumUploadSize(Bytes.kilobytes(maxSize)); } getSharedResources().putClassAlias(IApplication.class, "application"); //$NON-NLS-1$ getSharedResources().putClassAlias(PageContributor.class, "pc"); //$NON-NLS-1$ getSharedResources().putClassAlias(MaskBehavior.class, "mask"); //$NON-NLS-1$ getSharedResources().putClassAlias(Application.class, "servoy"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.wicketstuff.calendar.markup.html.form.DatePicker.class, "datepicker"); //$NON-NLS-1$ getSharedResources().putClassAlias(YUILoader.class, "yui"); //$NON-NLS-1$ getSharedResources().putClassAlias(JQueryLoader.class, "jquery"); //$NON-NLS-1$ getSharedResources().putClassAlias(TinyMCELoader.class, "tinymce"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.markup.html.WicketEventReference.class, "wicketevent"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.ajax.WicketAjaxReference.class, "wicketajax"); //$NON-NLS-1$ getSharedResources().putClassAlias(MainPage.class, "servoyjs"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class, "modalwindow"); //$NON-NLS-1$ PackageResource.bind(this, IApplication.class, "images/open_project.gif"); //$NON-NLS-1$ PackageResource.bind(this, IApplication.class, "images/save.gif"); //$NON-NLS-1$ mountSharedResource("/formcss", "servoy/formcss"); //$NON-NLS-1$//$NON-NLS-2$ sharedMediaResource = new SharedMediaResource(); getSharedResources().add("media", sharedMediaResource); //$NON-NLS-1$ mount(new SharedResourceRequestTargetUrlCodingStrategy("mediafolder", "servoy/media") //$NON-NLS-1$ //$NON-NLS-2$ { @Override protected void appendParameters(AppendingStringBuffer url, Map<String, ?> parameters) { if (parameters != null && parameters.size() > 0) { Object solutionName = parameters.get("s"); //$NON-NLS-1$ if (solutionName != null) appendPathParameter(url, null, solutionName.toString()); Object resourceId = parameters.get("id"); //$NON-NLS-1$ if (resourceId != null) appendPathParameter(url, null, resourceId.toString()); StringBuilder queryParams = new StringBuilder(); for (Entry<?, ?> entry1 : parameters.entrySet()) { Object value = ((Entry<?, ?>) entry1).getValue(); if (value != null) { Object key = ((Entry<?, ?>) entry1).getKey(); if (!"s".equals(key) && !"id".equals(key)) //$NON-NLS-1$ //$NON-NLS-2$ { if (value instanceof String[]) { String[] values = (String[]) value; for (String value1 : values) { if (queryParams.length() > 0) queryParams.append("&"); //$NON-NLS-1$ queryParams.append(key).append("=").append(value1);//$NON-NLS-1$ } } else { if (queryParams.length() > 0) queryParams.append("&"); //$NON-NLS-1$ queryParams.append(key).append("=").append(value);//$NON-NLS-1$ } } } } if (queryParams.length() > 0) { url.append("?").append(queryParams);//$NON-NLS-1$ } } } @Override protected void appendPathParameter(AppendingStringBuffer url, String key, String value) { String escapedValue = value; String[] values = escapedValue.split("/");//$NON-NLS-1$ if (values.length > 1) { StringBuilder sb = new StringBuilder(escapedValue.length()); for (String str : values) { sb.append(urlEncodePathComponent(str)); sb.append('/'); } sb.setLength(sb.length() - 1); escapedValue = sb.toString(); } else { escapedValue = urlEncodePathComponent(escapedValue); } if (!Strings.isEmpty(escapedValue)) { if (!url.endsWith("/"))//$NON-NLS-1$ { url.append("/");//$NON-NLS-1$ } if (key != null) url.append(urlEncodePathComponent(key)).append("/");//$NON-NLS-1$ url.append(escapedValue); } } /* * (non-Javadoc) * * @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String, java.util.Map) */ @Override protected ValueMap decodeParameters(String urlFragment, Map<String, ?> urlParameters) { ValueMap map = new ValueMap(); final String[] pairs = urlFragment.split("/"); //$NON-NLS-1$ if (pairs.length > 1) { map.add("s", pairs[1]); //$NON-NLS-1$ StringBuffer sb = new StringBuffer(); for (int i = 2; i < pairs.length; i++) { sb.append(pairs[i]); sb.append("/"); //$NON-NLS-1$ } sb.setLength(sb.length() - 1); map.add("id", sb.toString()); //$NON-NLS-1$ } if (urlParameters != null) { map.putAll(urlParameters); } return map; } }); getSharedResources().add("resources", new ServeResources()); //$NON-NLS-1$ getSharedResources().add("formcss", new FormCssResource(this)); //$NON-NLS-1$ if (settings.getProperty("servoy.webclient.error.page", null) != null) //$NON-NLS-1$ { getApplicationSettings().setInternalErrorPage(ServoyErrorPage.class); } if (settings.getProperty("servoy.webclient.pageexpired.page", null) != null) //$NON-NLS-1$ { getApplicationSettings().setPageExpiredErrorPage(ServoyPageExpiredPage.class); } addPreComponentOnBeforeRenderListener(new IComponentOnBeforeRenderListener() { public void onBeforeRender(Component component) { if (component instanceof IServoyAwareBean) { IModel model = component.getInnermostModel(); WebForm webForm = component.findParent(WebForm.class); if (model instanceof RecordItemModel && webForm != null) { IRecord record = (IRecord) ((RecordItemModel) model).getObject(); FormScope fs = webForm.getController().getFormScope(); if (record != null && fs != null) { ((IServoyAwareBean) component).setSelectedRecord(new ServoyBeanState(record, fs)); } } } else { if (!component.isEnabled()) { boolean hasOnRender = (component instanceof IFieldComponent && ((IFieldComponent) component) .getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()) .getRenderEventExecutor().hasRenderCallback()); if (!hasOnRender) { // onrender may change the enable state return; } } Component targetComponent = null; boolean hasFocus = false, hasBlur = false; if (component instanceof IFieldComponent && ((IFieldComponent) component).getEventExecutor() != null) { targetComponent = component; if (component instanceof WebBaseSelectBox) { Component[] cs = ((WebBaseSelectBox) component).getFocusChildren(); if (cs != null && cs.length == 1) targetComponent = cs[0]; } if (component instanceof WebDataHtmlArea) hasFocus = true; // always install a focus handler when in a table view to detect change of selectedIndex and test for record validation if (((IFieldComponent) component).getEventExecutor().hasEnterCmds() || component.findParent(WebCellBasedView.class) != null || (((IFieldComponent) component) .getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component) .getScriptObject()).getRenderEventExecutor().hasRenderCallback())) { hasFocus = true; } // Always trigger event on focus lost: // 1) check for new selected index, record validation may have failed preventing a index changed // 2) prevent focus gained to be called when field validation failed // 3) general ondata change hasBlur = true; } else if (component instanceof WebBaseLabel) { targetComponent = component; hasFocus = true; } if (targetComponent != null) { MainPage mainPage = targetComponent.findParent(MainPage.class); if (mainPage.isUsingAjax()) { AbstractAjaxBehavior eventCallback = mainPage.getPageContributor().getEventCallback(); if (eventCallback != null) { String callback = eventCallback.getCallbackUrl().toString(); if (component instanceof WebDataRadioChoice || component instanceof WebDataCheckBoxChoice || component instanceof WebDataLookupField || component instanceof WebDataComboBox || component instanceof WebDataListBox || component instanceof WebDataHtmlArea) { // is updated via ServoyChoiceComponentUpdatingBehavior or ServoyFormComponentUpdatingBehavior, this is just for events callback += "&nopostdata=true"; } for (IBehavior behavior : targetComponent.getBehaviors()) { if (behavior instanceof EventCallbackModifier) { targetComponent.remove(behavior); } } if (hasFocus) { StringBuilder js = new StringBuilder(); js.append("eventCallback(this,'focus','").append(callback).append("',event)"); //$NON-NLS-1$ //$NON-NLS-2$ targetComponent.add(new EventCallbackModifier("onfocus", true, //$NON-NLS-1$ new Model<String>(js.toString()))); targetComponent.add(new EventCallbackModifier("onmousedown", true, //$NON-NLS-1$ new Model<String>("focusMousedownCallback(event)"))); //$NON-NLS-1$ } if (hasBlur) { boolean blockRequest = false; // if component has ondatachange, check for blockrequest if (component instanceof ISupportEventExecutor && ((ISupportEventExecutor) component).getEventExecutor() .hasChangeCmd()) { WebClientSession webClientSession = WebClientSession.get(); blockRequest = webClientSession != null && webClientSession.blockRequest(); } StringBuilder js = new StringBuilder(); js.append("postEventCallback(this,'blur','").append(callback) //$NON-NLS-1$ .append("',event," + blockRequest + ")"); //$NON-NLS-1$ targetComponent.add(new EventCallbackModifier("onblur", true, //$NON-NLS-1$ new Model<String>(js.toString()))); } } } } } } }); }
From source file:com.swordlord.gozer.components.wicket.report.GWReport.java
License:Open Source License
/** * Reloads the graph.//from w w w .j ava2s. co m */ private void reload() { // replace panel contents with loading icon Component loadingComponent = getLoadingComponent(LAZY_LOAD_COMPONENT_ID); this.replace(loadingComponent); // add ajax behaviour to install call back loadingComponent.add(new ReportAjaxBehavior(this)); setState((byte) 1); }
From source file:com.userweave.components.bar.BarPanel.java
License:Open Source License
public BarPanel(String id, int max, int value, String cssClassName) { super(id);// w w w .j a v a 2 s. c om int percentage = 100 * value / max; add(new Label("value", Integer.toString(value))); Component bar = new WebMarkupContainer("bar") .add(new SimpleAttributeModifier("style", "width: " + Integer.toString(percentage) + "%;")); if (cssClassName != null) { bar.add(new SimpleAttributeModifier("class", cssClassName)); } add(bar); }