List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink add
public MarkupContainer add(final Component... children)
From source file:org.obiba.onyx.wicket.wizard.WizardForm.java
License:Open Source License
private AjaxLink createCancel() { AjaxLink link = new AjaxLink("cancelLink") { private static final long serialVersionUID = 0L; @Override/* w w w . ja va2 s . c om*/ public void onClick(AjaxRequestTarget target) { onCancelClick(target); } }; link.add(new AttributeModifier("value", true, getLabelModel("Cancel"))); return link; }
From source file:org.onehippo.cms7.autoexport.plugin.AutoExportPlugin.java
License:Apache License
public AutoExportPlugin(IPluginContext context, IPluginConfig config) { super(context, config); // set up label component final Label label = new Label("link-text", new Model<String>() { private static final long serialVersionUID = 1L; private final String unavailable = new StringResourceModel("unavailable", AutoExportPlugin.this, null) .getObject();// www . j a va 2 s . c o m private final String on = new StringResourceModel("on", AutoExportPlugin.this, null).getObject(); private final String off = new StringResourceModel("off", AutoExportPlugin.this, null).getObject(); @Override public String getObject() { if (!isExportAvailable()) { return unavailable; } return isExportEnabled() ? on : off; } }); label.setOutputMarkupId(true); add(AttributeModifier.append("class", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (!isExportAvailable()) { return "auto-export-state-unavailable"; } return isExportEnabled() ? "auto-export-state-enabled" : "auto-export-state-disabled"; } })); add(AttributeModifier.append("class", "auto-export-dev-extension")); AjaxLink<Void> link = new AjaxLink<Void>("link") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { setExportEnabled(!isExportEnabled()); target.add(label); //target.add(icon); } }; link.add(label); link.setEnabled(isExportAvailable()); link.setVisible(isLinkVisible()); add(link); if (isExportAvailable()) { // redraw plugin when config has changed try { Node node = getJcrSession().getNode(CONFIG_NODE_PATH); Property enabled = node.getProperty(CONFIG_ENABLED_PROPERTY_NAME); enabledModel = new JcrPropertyModel(enabled); context.registerService(new Observer<IObservable>(enabledModel) { @Override public void onEvent(final Iterator events) { redraw(); } }, IObserver.class.getName()); } catch (PathNotFoundException e) { log.warn("No such item: " + CONFIG_NODE_PATH + "/" + CONFIG_ENABLED_PROPERTY_NAME); } catch (RepositoryException e) { log.error("An error occurred starting observation", e); } } }
From source file:org.onehippo.cms7.reports.ReportsPerspective.java
License:Apache License
public ReportsPerspective(IPluginContext context, IPluginConfig config) { super(context, config, "reports"); setOutputMarkupId(true);//from w w w. j a v a2s . co m refreshGroup = new WebMarkupContainer("refresh-group"); refreshGroup .add(new Label("latest-refresh-label", new StringResourceModel("last-refresh-label", this, null))); lastRefreshDateLabel = new DateLabel("latest-refresh-date", new PatternDateConverter("HH:mm", false)); lastRefreshDateLabel.setOutputMarkupId(true); refreshGroup.add(lastRefreshDateLabel); AjaxLink<String> refreshLink = new AjaxLink<String>("refresh-link") { @Override public void onClick(final AjaxRequestTarget target) { try { Session session = UserSession.get().getJcrSession(); session.save(); session.refresh(false); lastRefreshDateLabel.setDefaultModel(Model.of(new Date())); target.add(lastRefreshDateLabel); } catch (RepositoryException repositoryException) { log.error("Error refreshing jcr session.", repositoryException); } target.appendJavaScript( "if (typeof Hippo.Reports.RefreshObservableInstance !== 'undefined') { Hippo.Reports.RefreshObservableInstance.fireEvent('refresh'); }"); } }; refreshLink.add(new Label("refresh-link-label", new StringResourceModel("refresh-link-text", this, null))); refreshGroup.add(refreshLink); add(refreshGroup); }
From source file:org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin.java
License:Apache License
public DefaultDocumentCommentingFieldPlugin(IPluginContext context, IPluginConfig config) { super(context, config); setOutputMarkupId(true);// ww w.java2s .c o m documentModel = (JcrNodeModel) getModel(); commentingContext = new CommentingContext(context, config, documentModel); String commentPersistenceManagerClazz = config.getString("comment.persistence.manager", null); if (StringUtils.isNotBlank(commentPersistenceManagerClazz)) { try { commentPersistenceManager = (CommentPersistenceManager) Class .forName(commentPersistenceManagerClazz).newInstance(); } catch (Exception e) { log.error("Cannot create custom comment persistence manager.", e); } } if (commentPersistenceManager == null) { commentPersistenceManager = new DefaultJcrCommentPersistenceManager(); } queryLimit = config.getAsLong("comment.query.limit", 100); editableByAuthorOnly = config.getAsBoolean("comment.editable.author.only", false); deletableByAuthorOnly = config.getAsBoolean("comment.deletable.author.only", false); add(new Label("doc-commenting-caption", getCaptionModel())); MarkupContainer commentsContainer = new WebMarkupContainer("doc-comments-container"); addDialogAction = new DialogAction( createDialogFactory(new CommentItem(), new SerializableCallable<Object>() { @Override public Object call() throws Exception { refreshCommentItems(); return refreshDocumentEditorWithSelectedCompounds(); } }), getDialogService()); AjaxLink addLink = new AjaxLink("add") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { addDialogAction.execute(); } }; final Image addImage = new Image("add-image") { private static final long serialVersionUID = 1L; }; addImage.setImageResourceReference(ADD_ICON_REF, null); addLink.add(addImage); addLink.setVisible(canCreateCommentItem(UserSession.get().getJcrSession())); commentsContainer.add(addLink); refreshCommentItems(); commentsContainer.add(createRefreshingView()); add(commentsContainer); }
From source file:org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin.java
License:Apache License
private RefreshingView<? extends Serializable> createRefreshingView() { return new RefreshingView<Serializable>("view") { private static final long serialVersionUID = 1L; private IDataProvider<CommentItem> dataProvider = new SimpleListDataProvider<CommentItem>( currentCommentItems);//from www. j a v a 2s.co m @Override protected Iterator getItemModels() { final Iterator<? extends CommentItem> baseIt = dataProvider.iterator(0, currentCommentItems.size()); return new Iterator<IModel<CommentItem>>() { public boolean hasNext() { return baseIt.hasNext(); } public IModel<CommentItem> next() { return dataProvider.model(baseIt.next()); } public void remove() { baseIt.remove(); } }; } @Override protected void populateItem(Item item) { final CommentItem comment = (CommentItem) item.getModelObject(); final Session userJcrSession = UserSession.get().getJcrSession(); final Label commentHeadLabel = new Label("docitem-head-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentHeadText(getCommentingContext(), comment); } }); commentHeadLabel.setEscapeModelStrings(false); item.add(commentHeadLabel); final String headTooltip = getCommentPersistenceManager() .getCommentHeadTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(headTooltip)) { commentHeadLabel.add(new AttributeModifier("title", new Model<String>(headTooltip))); } final Label commentBodyLabel = new Label("docitem-body-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentBodyText(getCommentingContext(), comment); } }); commentBodyLabel.setEscapeModelStrings(false); item.add(commentBodyLabel); final String bodyTooltip = getCommentPersistenceManager() .getCommentBodyTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(bodyTooltip)) { commentBodyLabel.add(new AttributeModifier("title", new Model<String>(bodyTooltip))); } if (item.getIndex() == currentCommentItems.size() - 1) { item.add(new AttributeAppender("class", new Model("last"), " ")); } final DialogAction editDialogAction = new DialogAction( createDialogFactory(comment, new SerializableCallable<Object>() { @Override public Object call() throws Exception { refreshCommentItems(); return refreshDocumentEditorWithSelectedCompounds(); } }), getDialogService()); AjaxLink editLink = new AjaxLink("edit") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { editDialogAction.execute(); } }; final Image editImage = new Image("edit-image") { private static final long serialVersionUID = 1L; }; editImage.setImageResourceReference(EDIT_ICON_REF, null); editLink.add(editImage); editLink.setVisible(isEditableCommentItem(userJcrSession, comment)); item.add(editLink); AjaxLink deleteLink = new AjaxLink("delete") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { try { final ConfirmDialog confirmDlg = new ConfirmDialog( new StringResourceModel("confirm.delete.comment.title", this, null, "Confirmation"), new StringResourceModel("confirm.delete.comment.message", this, null, "Are you sure to delete the item?")) { @Override public void invokeWorkflow() throws Exception { getCommentPersistenceManager().deleteCommentItem(getCommentingContext(), comment); currentCommentItems.remove(comment); refreshDocumentEditorWithSelectedCompounds(); } }; getDialogService().show(confirmDlg); } catch (CommentingException e) { log.error("Failed to delete comment.", e); } } }; final Image deleteImage = new Image("delete-image") { private static final long serialVersionUID = 1L; }; deleteImage.setImageResourceReference(DELETE_ICON_REF, null); deleteLink.add(deleteImage); deleteLink.setVisible(isDeletableCommentItem(userJcrSession, comment)); item.add(deleteLink); } }; }
From source file:org.onehippo.taxonomy.plugin.TaxonomyEditorPlugin.java
License:Apache License
/** * Constructor which adds all the UI components. * The UI components include taxonomy tree, toolbar, and detail form container. * The detail form container holds all the category detail fields such as name, description and synonyms. * * @param context//from w ww. j av a2 s .c o m * @param config */ public TaxonomyEditorPlugin(final IPluginContext context, final IPluginConfig config) { super(context, config); final boolean editing = "edit".equals(config.getString("mode")); useUrlKeyEncoding = config.getAsBoolean("keys.urlencode", false); taxonomy = newTaxonomy(getModel(), editing); availableLanguageSelections = getAvailableLanguageSelections(); currentLanguageSelection = new LanguageSelection(getLocale(), getLocale()); synonymModel = new IModel<String[]>() { private static final long serialVersionUID = 1L; public String[] getObject() { EditableCategoryInfo info = taxonomy.getCategoryByKey(key) .getInfo(currentLanguageSelection.getLanguageCode()); return info.getSynonyms(); } public void setObject(String[] object) { EditableCategoryInfo info = taxonomy.getCategoryByKey(key) .getInfo(currentLanguageSelection.getLanguageCode()); try { info.setSynonyms(object); } catch (TaxonomyException e) { redraw(); } } public void detach() { } }; final IModel<Taxonomy> taxonomyModel = new Model<Taxonomy>(taxonomy); String currentLanguageCode = currentLanguageSelection.getLanguageCode(); tree = new TaxonomyTree("tree", new TaxonomyTreeModel(taxonomyModel, currentLanguageCode), currentLanguageCode) { private static final long serialVersionUID = 1L; @Override public boolean isEnabled() { return editing; } @Override protected void onNodeLinkClicked(AjaxRequestTarget target, TreeNode node) { if (node instanceof CategoryNode) { key = ((CategoryNode) node).getCategory().getKey(); path = ((CategoryNode) node).getCategory().getPath(); } else { key = null; path = null; } redraw(); super.onNodeLinkClicked(target, node); } }; tree.setOutputMarkupId(true); add(tree); if (editing) { TreeNode rootNode = (TreeNode) tree.getModelObject().getRoot(); tree.getTreeState().selectNode(rootNode, true); } holder = new WebMarkupContainer("container-holder"); holder.setOutputMarkupId(true); toolbarHolder = new WebMarkupContainer("toolbar-container-holder"); toolbarHolder.setOutputMarkupId(true); AjaxLink<Void> addCategory = new AjaxLink<Void>("add-category") { private static final long serialVersionUID = 1L; @Override public boolean isEnabled() { return editing; } @Override public void onClick(AjaxRequestTarget target) { IDialogService dialogService = getDialogService(); dialogService.show(new NewCategoryDialog(taxonomyModel, path) { private static final long serialVersionUID = 1L; @Override public boolean useKeyUrlEncoding() { return useUrlKeyEncoding; } @Override public StringCodec getNodeNameCodec() { final ISettingsService settingsService = getPluginContext() .getService(ISettingsService.SERVICE_ID, ISettingsService.class); final StringCodecFactory stringCodecFactory = settingsService.getStringCodecFactory(); final StringCodec stringCodec = stringCodecFactory.getStringCodec("encoding.node"); if (stringCodec == null) { return new StringCodecFactory.UriEncoding(); } return stringCodec; } @Override protected void onOk() { EditableCategory category = taxonomy.getCategoryByKey(key); TreeNode node; if (category != null) { node = new CategoryNode(new CategoryModel(taxonomyModel, key), currentLanguageSelection.getLanguageCode()); } else { node = new TaxonomyNode(taxonomyModel, currentLanguageSelection.getLanguageCode()); } try { String newKey = getKey(); if (category != null) { category.addCategory(newKey, getName(), currentLanguageSelection.getLanguageCode()); } else { taxonomy.addCategory(newKey, getName(), currentLanguageSelection.getLanguageCode()); } TreeNode child = new CategoryNode(new CategoryModel(taxonomyModel, newKey), currentLanguageSelection.getLanguageCode()); tree.getTreeState().selectNode(child, true); key = newKey; } catch (TaxonomyException e) { error(e.getMessage()); } tree.getTreeState().expandNode(node); tree.markNodeChildrenDirty(node); redraw(); } }); } }; addCategory.add(new Image("add-category-icon", new ResourceReference(TaxonomyEditorPlugin.class, "res/new-category-16.png"))); if (!editing) { addCategory.add(new AttributeAppender("class", new Model<String>("disabled"), " ")); } toolbarHolder.add(addCategory); // <HCT> AjaxLink<Void> removeCategory = new AjaxLink<Void>("remove-category") { private static final long serialVersionUID = 5538299138211283825L; @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) { private static final long serialVersionUID = -7927968187160354605L; @Override public CharSequence preDecorateScript(final CharSequence script) { return "if (confirm('" + getString("confirmDelete") + "'))" + "{" + script + "}"; } }; } @Override public boolean isEnabled() { return editing; } @Override public void onClick(final AjaxRequestTarget target) { EditableCategory category = taxonomy.getCategoryByKey(key); if (category != null) { CategoryNode node = (CategoryNode) tree.getTreeState().getSelectedNodes().iterator().next(); TreeNode parent = node.getParent(); try { category.remove(); key = null; tree.getTreeState().collapseNode(parent); tree.getTreeState().expandNode(parent); redraw(); } catch (TaxonomyException e) { LOG.error("Could not remove category {} [{}]", new Object[] { category.getName(), category.getPath(), e }); } } } }; removeCategory.add(new Image("remove-category-icon", new ResourceReference(TaxonomyEditorPlugin.class, "res/remove-category-16.png"))); if (!editing) { addCategory.add(new AttributeAppender("class", new Model<String>("disabled"), " ")); } toolbarHolder.add(removeCategory); // </HCT> container = new Form("container") { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return taxonomy.getCategoryByKey(key) != null; } }; ChoiceRenderer<LanguageSelection> choiceRenderer = new ChoiceRenderer<LanguageSelection>("displayName", "languageCode"); DropDownChoice<LanguageSelection> languageSelectionChoice = new DropDownChoice<LanguageSelection>( "language", new PropertyModel<LanguageSelection>(this, "currentLanguageSelection"), availableLanguageSelections, choiceRenderer); languageSelectionChoice.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = -151291731388673682L; @Override protected void onUpdate(AjaxRequestTarget target) { redraw(); } }); languageSelectionChoice.setOutputMarkupId(true); languageSelectionChoice.setEnabled(!CollectionUtils.isEmpty(availableLanguageSelections)); container.add(languageSelectionChoice); // show key value key: final Label label = new Label("widgetKey", new KeyModel()); container.add(label); if (editing) { MarkupContainer name = new Fragment("name", "fragmentname", this); FormComponent<String> nameField = new TextField<String>("widget", new NameModel()); nameField.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { tree.markNodeDirty(getSelectedNode()); } }); name.add(nameField); container.add(name); container.add(new TextAreaWidget("description", new DescriptionModel())); } else { container.add(new Label("name", new NameModel())); TextField<String> myKey = new TextField<String>("key"); myKey.setVisible(false); container.add(myKey); container.add(new MultiLineLabel("description", new DescriptionModel())); } container.add(new RefreshingView<String>("view") { private static final long serialVersionUID = 1L; @Override protected Iterator<IModel<String>> getItemModels() { return getSynonymList().iterator(); } @Override protected void populateItem(final Item<String> item) { item.add(new AjaxLink("up") { private static final long serialVersionUID = 1L; @Override public boolean isEnabled() { return item.getIndex() > 0; } @Override public boolean isVisible() { return editing; } @Override public void onClick(AjaxRequestTarget target) { String[] synonyms = synonymModel.getObject(); int index = item.getIndex(); String tmp = synonyms[index]; synonyms[index] = synonyms[index - 1]; synonyms[index - 1] = tmp; synonymModel.setObject(synonyms); target.addComponent(holder); } }); item.add(new AjaxLink("down") { private static final long serialVersionUID = 1L; @Override public boolean isEnabled() { String[] synonyms = synonymModel.getObject(); return item.getIndex() < synonyms.length - 1; } @Override public boolean isVisible() { return editing; } @Override public void onClick(AjaxRequestTarget target) { String[] synonyms = synonymModel.getObject(); int index = item.getIndex(); String tmp = synonyms[index]; synonyms[index] = synonyms[index + 1]; synonyms[index + 1] = tmp; synonymModel.setObject(synonyms); target.addComponent(holder); } }); item.add(new AjaxLink("remove") { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return editing; } @Override public void onClick(AjaxRequestTarget target) { String[] synonyms = synonymModel.getObject(); String[] syns = new String[synonyms.length - 1]; System.arraycopy(synonyms, 0, syns, 0, item.getIndex()); System.arraycopy(synonyms, item.getIndex() + 1, syns, item.getIndex(), synonyms.length - item.getIndex() - 1); synonymModel.setObject(syns); target.addComponent(holder); } }); if (editing) { TextFieldWidget input = new TextFieldWidget("synonym", item.getModel()); FormComponent fc = (FormComponent) input.get("widget"); fc.add(new MinimumLengthValidator(1)); item.add(input); } else { item.add(new Label("synonym", item.getModel())); } } }); container.add(new AjaxLink("add") { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return editing; } @Override public void onClick(AjaxRequestTarget target) { String[] synonyms = synonymModel.getObject(); String[] newSyns = new String[synonyms.length + 1]; System.arraycopy(synonyms, 0, newSyns, 0, synonyms.length); newSyns[synonyms.length] = ""; synonymModel.setObject(newSyns); target.addComponent(holder); } }); holder.add(container); add(toolbarHolder); add(holder); add(CSSPackageResource.getHeaderContribution(TaxonomyEditorPlugin.class, "res/style.css")); }
From source file:org.onexus.ui.api.progressbar.columns.LogLink.java
License:Apache License
public LogLink(String id) { super(id);/*ww w. jav a 2 s . c o m*/ AjaxLink<String> link = new AjaxLink<String>("link") { @Override public void onClick(AjaxRequestTarget target) { LogLink.this.onClick(target); } }; link.add(new Label("label", "<i class=\"icon-eye-open\"></i>").setEscapeModelStrings(false)); add(link); }
From source file:org.onexus.ui.workspace.internal.viewers.wizards.WizardViewer.java
License:Apache License
public WizardViewer(String id, IModel<? extends Resource> model) { super(id);/*w ww . j a v a 2 s. c o m*/ this.resourceModel = model; add(new ListView<IWizardCreator>("wizardList", new WizardCreatorsModel()) { @Override protected void populateItem(final ListItem<IWizardCreator> item) { AjaxLink<String> link = new AjaxLink<String>("link") { @Override public void onClick(AjaxRequestTarget target) { IWizardCreator wizard = item.getModelObject(); wizardContainer.addOrReplace(wizard.getPanel("wizard", resourceModel)); target.add(wizardContainer); } }; IWizardCreator wizard = item.getModelObject(); String label = wizard.getLabel(); String title = wizard.getTitle(); String description = wizard.getDescription(); link.add(new Label("label", label)); item.add(link); item.add(new Label("title", title)); if (description != null) { item.add(new HelpMark("description", title, description)); } else { item.add(new EmptyPanel("description")); } } }); wizardContainer = new WebMarkupContainer("wizardContainer") { @Override public boolean isVisible() { Component wizard = get("wizard"); if (wizard == null || !wizard.isVisible()) { return false; } return true; } }; wizardContainer.setOutputMarkupPlaceholderTag(true); wizardContainer.add(new EmptyPanel("wizard").setVisible(false)); add(wizardContainer); }
From source file:org.onexus.website.api.pages.search.boxes.DisambiguationPanel.java
License:Apache License
public DisambiguationPanel(String id, Set<String> notFoundValues) { super(id);// w ww.j av a 2 s. c om add(new Label("message", "Unknown entries: ")); RepeatingView links = new RepeatingView("links"); WebMarkupContainer item = new WebMarkupContainer(links.newChildId()); WebMarkupContainer comma = new WebMarkupContainer("comma"); item.add(comma); comma.setVisible(false); AjaxLink<String> link = new AjaxLink<String>("link") { @Override public void onClick(AjaxRequestTarget target) { } }; link.add(new Label("label", Strings.join(", ", new ArrayList<String>(notFoundValues)))); item.add(link); links.add(item); add(links); }
From source file:org.onexus.website.api.pages.search.boxes.DisambiguationPanel.java
License:Apache License
private void addLink(RepeatingView links, IEntity entity, boolean showComma) { WebMarkupContainer item = new WebMarkupContainer(links.newChildId()); WebMarkupContainer comma = new WebMarkupContainer("comma"); item.add(comma);// w w w.j a v a 2s . c o m comma.setVisible(showComma); AjaxLink<String> link = new AjaxLink<String>("link", new Model(entity.getId())) { @Override public void onClick(AjaxRequestTarget target) { onSelection(target, getModelObject()); } }; link.add(new Label("label", getEntityLabel(entity))); item.add(link); links.add(item); }