List of usage examples for org.apache.wicket Component findParent
public final <Z> Z findParent(final Class<Z> c)
From source file:org.hippoecm.frontend.plugins.cms.browse.tree.FolderTreePlugin.java
License:Apache License
private CmsJcrTree initializeTree(final IPluginContext context, final IPluginConfig config, final String startingPath) { rootModel = new JcrNodeModel(startingPath); DocumentListFilter folderTreeConfig = new DocumentListFilter(config); final boolean workflowEnabled = getPluginConfig().getAsBoolean("workflow.enabled", true); this.rootNode = new FolderTreeNode(rootModel, folderTreeConfig); treeModel = new JcrTreeModel(rootNode); context.registerService(treeModel, IObserver.class.getName()); final CmsJcrTree cmsJcrTree = new CmsJcrTree("tree", treeModel, newTreeNodeTranslator(config), newTreeNodeIconProvider(context, config)) { private static final long serialVersionUID = 1L; @Override/*from w ww . ja v a 2s .co m*/ protected MarkupContainer newContextContent(MarkupContainer parent, String id, final TreeNode node) { IPluginConfig workflowConfig = config.getPluginConfig("module.workflow"); if (workflowConfig != null && (node instanceof IJcrTreeNode)) { ContextWorkflowManagerPlugin content = new ContextWorkflowManagerPlugin(context, workflowConfig); content.bind(FolderTreePlugin.this, id); IModel<Node> nodeModel = ((IJcrTreeNode) node).getNodeModel(); content.setModel(nodeModel); return content; } return new EmptyPanel(id); } @Override protected MarkupContainer newContextLink(final MarkupContainer parent, String id, final TreeNode node, final MarkupContainer content) { if (getPluginConfig().getBoolean("contextmenu.rightclick.enabled")) { parent.add(new RightClickBehavior(content, parent) { private static final long serialVersionUID = 1L; @Override protected void respond(AjaxRequestTarget target) { updateTree(target); getContextmenu().setVisible(true); target.add(getComponentToUpdate()); IContextMenuManager menuManager = findParent(IContextMenuManager.class); if (menuManager != null) { menuManager.showContextMenu(this); final IRequestParameters requestParameters = RequestCycle.get().getRequest() .getRequestParameters(); StringValue x = requestParameters.getParameterValue(MOUSE_X_PARAM); StringValue y = requestParameters.getParameterValue(MOUSE_Y_PARAM); if (x != null && y != null) { target.appendJavaScript("Hippo.ContextMenu.renderAtPosition('" + content.getMarkupId() + "', " + x + ", " + y + ");"); } else { target.appendJavaScript( "Hippo.ContextMenu.renderInTree('" + content.getMarkupId() + "');"); } } } }); } MarkupContainer container = super.newContextLink(parent, id, node, content); if (!workflowEnabled) { container.setEnabled(false); } return container; } @Override protected void onContextLinkClicked(MarkupContainer content, AjaxRequestTarget target) { target.appendJavaScript("Hippo.ContextMenu.renderInTree('" + content.getMarkupId() + "');"); } @Override protected void onNodeLinkClicked(AjaxRequestTarget target, TreeNode clickedNode) { if (clickedNode instanceof IJcrTreeNode) { IJcrTreeNode treeNodeModel = (IJcrTreeNode) clickedNode; FolderTreePlugin.this.setDefaultModel(treeNodeModel.getNodeModel()); ITreeState state = getTreeState(); if (state.isNodeExpanded(clickedNode)) { // super has already switched selection. if (!state.isNodeSelected(clickedNode)) { state.collapseNode(clickedNode); } } else { state.expandNode(clickedNode); } } updateTree(target); } @Override protected void onJunctionLinkClicked(AjaxRequestTarget target, TreeNode node) { updateTree(target); } @Override public void onTargetRespond(final AjaxRequestTarget target, boolean dirty) { if (dirty) { target.appendJavaScript(treeHelperBehavior.getRenderString()); } } @Override protected void addComponent(final AjaxRequestTarget target, final Component component) { if (component.findParent(Page.class) != null) { super.addComponent(target, component); } } }; cmsJcrTree.add(treeHelperBehavior = new WicketTreeHelperBehavior(new WicketTreeHelperSettings(config)) { private static final long serialVersionUID = 1L; @Override protected String getWicketId() { return tree.getMarkupId(); } }); cmsJcrTree.setRootLess(config.getBoolean("rootless")); return cmsJcrTree; }
From source file:org.hippoecm.frontend.plugins.yui.layout.UnitBehavior.java
License:Apache License
@Override public void bind(final Component component) { super.bind(component); // re-render complete wireframe during the render phase AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { target.addListener(new IListener() { public void onBeforeRespond(Map map, AjaxRequestTarget target) { if (target.getPage() != component.findParent(Page.class)) { return; }/*from ww w.j a v a2s . c o m*/ IWireframe wireframe = WireframeUtils.getParentWireframe(component); if (wireframe != null) { wireframe.render(target); } else { log.warn("Unable to find parent wireframe-behavior"); } } public void onAfterRespond(Map map, AjaxRequestTarget.IJavaScriptResponse response) { } }); } }
From source file:org.hippoecm.frontend.util.WebApplicationHelper.java
License:Apache License
public static boolean isPartOfPage(final Component component) { return component.findParent(Page.class) != null; }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.behavior.QuestionCategorySelectionBehavior.java
License:Open Source License
@Override public void onComponentTag(Component component, ComponentTag tag) { super.onRendered(component); // behavior can be attached to the QuestionCategoryImageSelectorPanel or any of its children IQuestionCategorySelectionStateHolder selector; if (IQuestionCategorySelectionStateHolder.class.isInstance(component)) { selector = (IQuestionCategorySelectionStateHolder) component; } else {/* ww w. j av a 2 s . c o m*/ selector = component.findParent(IQuestionCategorySelectionStateHolder.class); } // synchronize the state if (selector != null && selector.updateState()) { String cssClass = SELECTED_CSS_CLASS; if (tag.getAttributes().containsKey("class")) { cssClass += " " + tag.getAttributes().getString("class"); } tag.getAttributes().put("class", cssClass); log.debug("{}", tag); } }
From source file:ro.nextreports.server.web.dashboard.WidgetPopupMenuModel.java
License:Apache License
private void changeSettings(FeedbackPanel feedbackPanel, Component component, Widget widget, WidgetRuntimeModel runtimeModel, AjaxRequestTarget target) { final WidgetPanel widgetPanel = component.findParent(WidgetPanel.class); int oldRefreshTime = widget.getRefreshTime(); Map<String, String> widgetSettings = null; try {/* w ww . j a va2 s .c o m*/ String dashboardId = getDashboardId(widget.getId()); String owner = dashboardService.getDashboardOwner(dashboardId); String user = ServerUtil.getUsername(); boolean isDashboardLink = !owner.equals(user); if (component.findParent(DashboardPanel.class) == null) { errorRefresh(); target.add(feedbackPanel); return; } else { ModalWindow.closeCurrent(target); } boolean hasWrite = securityService.hasPermissionsById(user, PermissionUtil.getWrite(), dashboardId); if (isDashboardLink && !hasWrite) { // if dashboard is not owned by user (was shared to him) // save parameters values under usersData node if user has only read permission QueryRuntime newQueryRuntime = ChartUtil .updateQueryRuntime(ObjectCloner.silenceDeepCopy(widget.getQueryRuntime()), runtimeModel); widgetSettings = ChartUtil.getSettingsFromModel(runtimeModel); String parentPath = WidgetUtil.getUserWidgetParametersPath(user); String path = parentPath + "/" + widget.getId(); if (storageService.entityExists(path)) { UserWidgetParameters wp = (UserWidgetParameters) storageService.getEntity(path); oldRefreshTime = Integer.parseInt(wp.getSettings().get(ChartWidget.REFRESH_TIME)); wp.setQueryRuntime(newQueryRuntime); wp.setSettings(widgetSettings); storageService.modifyEntity(wp); } else { UserWidgetParameters wp = new UserWidgetParameters(widget.getId(), path); wp.setQueryRuntime(newQueryRuntime); wp.setSettings(widgetSettings); storageService.createFolders(parentPath); storageService.addEntity(wp); } dashboardService.resetCache(widget.getId()); } else { ChartUtil.updateWidget(widget, runtimeModel); dashboardService.modifyWidget(dashboardId, widget); } } catch (NotFoundException e) { // never happening throw new RuntimeException(e); } catch (DuplicationException e) { throw new RuntimeException(e); } int refreshTime = widget.getRefreshTime(); if (widgetSettings != null) { refreshTime = Integer.parseInt(widgetSettings.get(ChartWidget.REFRESH_TIME)); } if (oldRefreshTime != refreshTime) { for (Behavior behavior : widgetPanel.getBehaviors()) { if (behavior instanceof AjaxSelfUpdatingTimerBehavior) { ((AjaxSelfUpdatingTimerBehavior) behavior).stop(target); // do not remove the behavior : after changing , the event is called one more time // on the client so it has to be present ... } } if (refreshTime > 0) { widgetPanel.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(refreshTime))); } } if ((widget instanceof DrillDownWidget) || (widget instanceof PivotWidget)) { widgetPanel.refresh(target); } else { //target.add(widgetPanel); // ChartRendererPanel uses container.replace("chart") // we should add widgetView again instead of a simple target.add(widgetPanel), otherwise we will see two refreshes widgetPanel.refresh(target); } }
From source file:ro.nextreports.server.web.dashboard.WidgetPopupMenuModel.java
License:Apache License
private void resetSettings(FeedbackPanel feedbackPanel, Component component, Widget widget, AjaxRequestTarget target) {// www. j a v a 2 s. c o m // on reset settings we must delete UserWidgetParameters if any try { UserWidgetParameters wp = dashboardService.getUserWidgetParameters(widget.getId()); if (wp != null) { storageService.removeEntityById(wp.getId()); dashboardService.resetCache(widget.getId()); final WidgetPanel widgetPanel = component.findParent(WidgetPanel.class); ModalWindow.closeCurrent(target); //target.add(widgetPanel); // ChartRendererPanel uses container.replace("chart") // we should add widgetView again instead of a simple target.add(widgetPanel), otherwise we will see two refreshes widgetPanel.refresh(target); return; } } catch (NotFoundException ex) { // should not happen Log.error(ex.getMessage(), ex); } if ((widget instanceof DrillDownWidget) && (((DrillDownWidget) widget).getEntity() instanceof Chart)) { final WidgetPanel widgetPanel = component.findParent(WidgetPanel.class); ChartUtil.updateWidget(widget, ChartUtil.getRuntimeModel(storageService.getSettings(), (EntityWidget) widget, reportService, dataSourceService, false)); try { if (component.findParent(DashboardPanel.class) == null) { errorRefresh(); target.add(feedbackPanel); return; } else { ModalWindow.closeCurrent(target); } dashboardService.modifyWidget(getDashboardId(widget.getId()), widget); } catch (NotFoundException e) { // never happening } widgetPanel.refresh(target); } else if (widget instanceof ChartWidget) { final WidgetPanel widgetPanel = component.findParent(WidgetPanel.class); if (component.findParent(DashboardPanel.class) == null) { errorRefresh(); target.add(feedbackPanel); return; } else { ModalWindow.closeCurrent(target); } ChartUtil.updateWidget(widget, ChartUtil.getDefaultRuntimeModel(storageService.getSettings(), (ChartWidget) widget, reportService, dataSourceService)); try { dashboardService.modifyWidget(getDashboardId(widget.getId()), widget); } catch (NotFoundException e) { // never happening } //target.add(widgetPanel); // ChartRendererPanel uses container.replace("chart") // we should add widgetView again instead of a simple target.add(widgetPanel), otherwise we will see two refreshes widgetPanel.refresh(target); } }
From source file:ro.nextreports.server.web.dashboard.WidgetPopupMenuModel.java
License:Apache License
private AjaxLink createMoveLink(final IModel<Widget> model) { AjaxLink<Void> moveLink = new AjaxLink<Void>(MenuPanel.LINK_ID) { @Override// www .jav a 2 s . c om public void onClick(AjaxRequestTarget target) { final Widget widget = model.getObject(); ModalWindow dialog = findParent(BasePage.class).getDialog(); dialog.setTitle(new StringResourceModel("WidgetPopupMenu.copyMoveWidget", null).getString()); dialog.setInitialWidth(300); dialog.setUseInitialHeight(false); final Component component = this; dialog.setContent(new SelectDashboardPanel(dialog.getContentId()) { private static final long serialVersionUID = 1L; @Override public void onAction(String toDashboardId, boolean move, AjaxRequestTarget target) { try { int column = dashboardService.getWidgetColumn(widget.getId()); if (move) { dashboardService.moveWidget(DashboardUtil.getSelectedDashboardId(), toDashboardId, widget.getId()); DashboardColumnPanel columnPanel = component.findParent(DashboardPanel.class) .getColumnPanel(column); target.add(component.findParent(DashboardColumnPanel.class)); target.add(columnPanel); } else { dashboardService.copyWidget(DashboardUtil.getSelectedDashboardId(), toDashboardId, widget.getId()); } } catch (NotFoundException e) { e.printStackTrace(); // should never happen } finally { ModalWindow.closeCurrent(target); } } @Override public void onCancel(AjaxRequestTarget target) { ModalWindow.closeCurrent(target); } }); dialog.show(target); } @Override public boolean isVisible() { return hasWritePermission(model.getObject()); } }; return moveLink; }
From source file:sf.wicklet.gwt.server.ajax.impl.AbstractGwtAjaxResponse.java
License:Apache License
/** * Detaches the page if at least one of its components was updated. * * @param requestCycle/*ww w.j a v a2s . c o m*/ * the current request cycle */ void detach(final IRequestCycle requestCycle) { final Iterator<Component> iterator = markupIdToComponent.values().iterator(); while (iterator.hasNext()) { final Component component = iterator.next(); final Page parentPage = component.findParent(Page.class); if (parentPage != null) { parentPage.detach(); break; } } }
From source file:sf.wicklet.gwt.server.ajax.impl.GwtAjaxWickletResponse.java
License:Apache License
@Override protected void writeComponent(final Response response, final String markupId, final Component component, final String encoding) { if (component.getRenderBodyOnly() == true) { throw new IllegalStateException( "Ajax render cannot be called on component that has setRenderBodyOnly enabled. Component: " + component.toString()); }//from w ww.j a va 2s. co m component.setOutputMarkupId(true); // substitute our encoding response for the real one so we can capture // component's markup in a manner safe for transport inside CDATA block encodingBodyResponse.reset(); RequestCycle.get().setResponse(encodingBodyResponse); // Initialize temporary variables final Page page = component.findParent(Page.class); if (page == null) { // dont throw an exception but just ignore this component, somehow // it got removed from the page. AbstractGwtAjaxResponse.LOG.debug("component: " + component + " with markupid: " + markupId + " not rendered because it was already removed from page"); return; } page.startComponentRender(component); try { component.prepareForRender(); // render any associated headers of the component writeHeaderContribution(response, component); } catch (final RuntimeException e) { try { component.afterRender(); } catch (final RuntimeException e2) { // ignore this one could be a result off. } // Restore original response RequestCycle.get().setResponse(response); encodingBodyResponse.reset(); throw e; } try { component.render(); } catch (final RuntimeException e) { RequestCycle.get().setResponse(response); encodingBodyResponse.reset(); throw e; } page.endComponentRender(component); // Restore original response RequestCycle.get().setResponse(response); response.write("<component id=\""); response.write(markupId); response.write("\" "); // if (encodingBodyResponse.isContentsEncoded()) { // response.write(" encoding=\""); // response.write(getEncodingName()); // response.write("\" "); // } response.write(" encoding=\"escaped-xml\" >"); response.write(XmlUtil.escXml(encodingBodyResponse.getContents())); response.write("</component>"); encodingBodyResponse.reset(); }