Example usage for org.apache.wicket.ajax.markup.html AjaxLink setVisible

List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink setVisible

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html AjaxLink setVisible.

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.hippoecm.frontend.editor.plugins.linkpicker.FacetSelectTemplatePlugin.java

License:Apache License

public FacetSelectTemplatePlugin(final IPluginContext context, IPluginConfig config) {
    super(context, config);

    Node node = getModelObject();
    try {/*  w  w w  .jav a  2s.com*/
        if (!node.hasProperty("hippo:docbase")) {
            node.setProperty("hippo:docbase", node.getSession().getRootNode().getUUID());
        }
        if (!node.hasProperty("hippo:facets")) {
            node.setProperty("hippo:facets", new String[0]);
        }
        if (!node.hasProperty("hippo:values")) {
            node.setProperty("hippo:values", new String[0]);
        }
        if (!node.hasProperty("hippo:modes")) {
            node.setProperty("hippo:modes", new String[0]);
        }
    } catch (ValueFormatException e) {
        log.error(e.getMessage());
    } catch (PathNotFoundException e) {
        log.error(e.getMessage());
    } catch (RepositoryException e) {
        log.error(e.getMessage());
    }

    final IModel<String> displayModel = new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            Node node = FacetSelectTemplatePlugin.this.getModelObject();
            try {
                if (node != null && node.hasProperty("hippo:docbase")) {
                    String docbaseUUID = node.getProperty("hippo:docbase").getString();
                    if (docbaseUUID == null || docbaseUUID.equals("") || docbaseUUID.startsWith("cafebabe-")) {
                        return EMPTY_LINK_TEXT;
                    }
                    return node.getSession().getNodeByUUID(docbaseUUID).getPath();
                }
            } catch (ValueFormatException e) {
                log.warn("Invalid value format for docbase " + e.getMessage());
                log.debug("Invalid value format for docbase ", e);
            } catch (PathNotFoundException e) {
                log.warn("Docbase not found " + e.getMessage());
                log.debug("Docbase not found ", e);
            } catch (RepositoryException e) {
                log.error("Invalid docbase" + e.getMessage(), e);
            }
            return EMPTY_LINK_TEXT;
        }
    };

    mode = IEditor.Mode.fromString(config.getString("mode"), IEditor.Mode.VIEW);
    try {
        IDataProvider<Integer> provider = new IDataProvider<Integer>() {
            private static final long serialVersionUID = 1L;

            @Override
            public Iterator<Integer> iterator(long first, long count) {
                return new Iterator<Integer>() {
                    int current = 0;

                    public boolean hasNext() {
                        try {
                            Node node = ((JcrNodeModel) FacetSelectTemplatePlugin.this.getDefaultModel())
                                    .getNode();
                            return current < node.getProperty("hippo:facets").getValues().length;
                        } catch (RepositoryException ex) {
                            return false;
                        }
                    }

                    public Integer next() {
                        if (hasNext()) {
                            return Integer.valueOf(current++);
                        } else {
                            throw new NoSuchElementException();
                        }
                    }

                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

            @Override
            public long size() {
                try {
                    Node node = ((JcrNodeModel) FacetSelectTemplatePlugin.this.getDefaultModel()).getNode();
                    return node.getProperty("hippo:facets").getValues().length;
                } catch (RepositoryException ex) {
                    return 0;
                }
            }

            @Override
            public IModel<Integer> model(Integer object) {
                return new Model<Integer>(object);
            }

            @Override
            public void detach() {
            }
        };
        if (IEditor.Mode.EDIT == mode) {
            final JcrPropertyValueModel<String> docbaseModel = new JcrPropertyValueModel<String>(
                    new JcrPropertyModel<String>(node.getProperty("hippo:docbase")));

            IDialogFactory dialogFactory = new IDialogFactory() {
                private static final long serialVersionUID = 1L;

                public AbstractDialog<String> createDialog() {
                    final IPluginConfig dialogConfig = LinkPickerDialogConfig
                            .fromPluginConfig(getPluginConfig(), docbaseModel);
                    return new LinkPickerDialog(context, dialogConfig, new IChainingModel<String>() {
                        private static final long serialVersionUID = 1L;

                        public String getObject() {
                            return docbaseModel.getObject();
                        }

                        public void setObject(String object) {
                            docbaseModel.setObject(object);
                            redraw();
                        }

                        public IModel<String> getChainedModel() {
                            return docbaseModel;
                        }

                        public void setChainedModel(IModel<?> model) {
                            throw new UnsupportedOperationException("Value model cannot be changed");
                        }

                        public void detach() {
                            docbaseModel.detach();
                        }
                    });
                }
            };

            add(new ClearableDialogLink("docbase", displayModel, dialogFactory, getDialogService()) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClear() {
                    Node node = ((JcrNodeModel) FacetSelectTemplatePlugin.this.getDefaultModel()).getNode();
                    try {
                        node.setProperty("hippo:docbase", node.getSession().getRootNode().getUUID());
                    } catch (RepositoryException e) {
                        log.error("Unable to reset docbase to rootnode uuid", e);
                    }
                    redraw();
                }

                @Override
                public boolean isClearVisible() {
                    // Checking for string literals ain't pretty. It's probably better to create a better display model.
                    return !EMPTY_LINK_TEXT.equals((String) displayModel.getObject());
                }
            });

            add(new DataView<Integer>("arguments", provider) {
                private static final long serialVersionUID = 1L;

                @Override
                public void populateItem(final Item<Integer> item) {
                    Node node = FacetSelectTemplatePlugin.this.getModelObject();
                    final int index = item.getModelObject().intValue();
                    try {
                        item.add(new TextFieldWidget("facet", new JcrPropertyValueModel<String>(index,
                                new JcrPropertyModel<String>(node.getProperty("hippo:facets")))));
                        item.add(new TextFieldWidget("mode", new JcrPropertyValueModel<String>(index,
                                new JcrPropertyModel<String>(node.getProperty("hippo:modes")))));
                        item.add(new TextFieldWidget("value", new JcrPropertyValueModel<String>(index,
                                new JcrPropertyModel<String>(node.getProperty("hippo:values")))));
                        AjaxLink<Void> removeButton;
                        item.add(removeButton = new AjaxLink<Void>("remove") {
                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                Node node = ((JcrNodeModel) FacetSelectTemplatePlugin.this.getDefaultModel())
                                        .getNode();
                                for (String property : new String[] { "hippo:facets", "hippo:modes",
                                        "hippo:values" }) {
                                    try {
                                        Value[] oldValues = node.getProperty(property).getValues();
                                        Value[] newValues = new Value[oldValues.length - 1];
                                        System.arraycopy(oldValues, 0, newValues, 0, index);
                                        System.arraycopy(oldValues, index + 1, newValues, 0,
                                                oldValues.length - index - 1);
                                        node.setProperty(property, newValues);
                                    } catch (RepositoryException ex) {
                                        log.error("cannot add new facet select line", ex);
                                    }
                                }
                                FacetSelectTemplatePlugin.this.redraw();
                            }
                        });
                        removeButton.setOutputMarkupId(true);
                    } catch (RepositoryException ex) {
                        log.error("cannot read facet select line", ex);
                    }
                }
            });
            AjaxLink<Void> addButton;
            add(addButton = new AjaxLink<Void>("add") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    Node node = ((JcrNodeModel) FacetSelectTemplatePlugin.this.getDefaultModel()).getNode();
                    for (String property : new String[] { "hippo:facets", "hippo:modes", "hippo:values" }) {
                        try {
                            Value[] oldValues = node.getProperty(property).getValues();
                            Value[] newValues = new Value[oldValues.length + 1];
                            System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
                            newValues[newValues.length - 1] = node.getSession().getValueFactory()
                                    .createValue("");
                            node.setProperty(property, newValues);
                        } catch (RepositoryException ex) {
                            log.error("cannot add new facet select line", ex);
                        }
                    }
                    FacetSelectTemplatePlugin.this.redraw();
                }
            });
            addButton.setOutputMarkupId(true);
        } else {
            add(new Label("docbase", displayModel));
            add(new DataView<Integer>("arguments", provider) {
                private static final long serialVersionUID = 1L;

                @Override
                public void populateItem(final Item<Integer> item) {
                    try {
                        Node node = FacetSelectTemplatePlugin.this.getModelObject();
                        int index = item.getModelObject().intValue();
                        item.add(new Label("facet",
                                node.getProperty("hippo:facets").getValues()[index].getString()));
                        item.add(new Label("mode",
                                node.getProperty("hippo:modes").getValues()[index].getString()));
                        item.add(new Label("value",
                                node.getProperty("hippo:values").getValues()[index].getString()));
                        Label removeButton;
                        item.add(removeButton = new Label("remove"));
                        removeButton.setVisible(false);
                    } catch (RepositoryException ex) {
                        log.error("cannot read facet select line", ex);
                    }
                }
            });
            Label addButton;
            add(addButton = new Label("add"));
            addButton.setVisible(false);
        }
    } catch (PathNotFoundException ex) {
        log.error("failed to read existing facet select", ex);
    } catch (ValueFormatException ex) {
        log.error("failed to read existing facet select", ex);
    } catch (RepositoryException ex) {
        log.error("failed to read existing facet select", ex);
    }

    setOutputMarkupId(true);
}

From source file:org.hippoecm.frontend.plugins.console.editor.PropertiesEditor.java

License:Apache License

@Override
protected void populateItem(Item item) {
    JcrPropertyModel model = (JcrPropertyModel) item.getModel();

    try {//ww w .j av a2s. co m
        final AjaxLink deleteLink = deleteLink("delete", model);
        item.add(deleteLink);
        deleteLink.setVisible(!model.getProperty().getDefinition().isProtected());

        JcrName propName = new JcrName(model.getProperty().getName());
        item.add(new Label("namespace", namespacePrefix));
        item.add(new Label("name", propName.getName()));

        item.add(new Label("type", PropertyType.nameFromValue(model.getProperty().getType())));

        WebMarkupContainer valuesContainer = new WebMarkupContainer("values-container");
        valuesContainer.setOutputMarkupId(true);
        item.add(valuesContainer);

        PropertyValueEditor editor = createPropertyValueEditor("values", model);
        valuesContainer.add(editor);

        final AjaxLink addLink = addLink("add", model, valuesContainer, editor);
        addLink.add(TitleAttribute.set(getString("property.value.add")));
        item.add(addLink);

        PropertyDefinition definition = model.getProperty().getDefinition();
        addLink.setVisible(definition.isMultiple() && !definition.isProtected());
    } catch (RepositoryException e) {
        log.error(e.getMessage());
    }
}

From source file:org.hippoecm.frontend.plugins.console.editor.PropertyValueEditor.java

License:Apache License

@Override
protected void populateItem(Item item) {
    try {//from  www  . jav a2 s. com
        final JcrPropertyValueModel valueModel = (JcrPropertyValueModel) item.getModel();
        Component valueEditor = createValueEditor(valueModel);

        item.add(valueEditor);

        final AjaxLink removeLink = new AjaxLink("remove") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                try {
                    Property prop = propertyModel.getProperty();
                    Value[] values = prop.getValues();
                    values = (Value[]) ArrayUtils.remove(values, valueModel.getIndex());
                    prop.getParent().setProperty(prop.getName(), values, prop.getType());
                } catch (RepositoryException e) {
                    log.error(e.getMessage());
                }

                NodeEditor editor = findParent(NodeEditor.class);
                if (editor != null) {
                    target.add(editor);
                }
            }
        };

        removeLink.add(TitleAttribute.set(getString("property.value.remove")));

        PropertyDefinition definition = propertyModel.getProperty().getDefinition();
        removeLink.setVisible(definition.isMultiple() && !definition.isProtected());

        item.add(removeLink);

        if (focusOnLastItem && item.getIndex() == getItemCount() - 1) {
            focusOnLastItem = false;

            AjaxRequestTarget ajax = RequestCycle.get().find(AjaxRequestTarget.class);
            if (ajax != null && valueEditor instanceof AjaxUpdatingWidget) {
                ajax.focusComponent(((AjaxUpdatingWidget) valueEditor).getFocusComponent());
            }
        }
    } catch (RepositoryException e) {
        log.error(e.getMessage());
        item.add(new Label("value", e.getClass().getName() + ":" + e.getMessage()));
        item.add(new Label("remove", ""));
    }
}

From source file:org.hippoecm.frontend.plugins.standardworkflow.FolderShortcutPlugin.java

License:Apache License

public FolderShortcutPlugin(final IPluginContext context, final IPluginConfig config) {
    super(context, config);

    AjaxLink link = new AjaxLink("link") {
        private static final long serialVersionUID = 1L;

        @Override//from   w  w w  .  ja v  a  2 s .com
        public void onClick(AjaxRequestTarget target) {
            IDialogService dialogService = getDialogService();
            JcrNodeModel model = (JcrNodeModel) FolderShortcutPlugin.this.getDefaultModel();
            Node node = model != null ? model.getNode() : null;
            dialogService.show(
                    new FolderShortcutPlugin.AddRootFolderDialog(context, config, node, defaultDropLocation));
        }
    };
    add(link);

    String path = config.getString("option.location");
    if (path != null && !path.equals("")) {
        defaultDropLocation = path;
    }

    if (!defaultDropLocation.equals("")) {
        try {
            Session jcrSession = UserSession.get().getJcrSession();
            while (defaultDropLocation.startsWith(SLASH)) {
                defaultDropLocation = defaultDropLocation.substring(1);
            }
            if (!jcrSession.getRootNode().hasNode(defaultDropLocation)) {
                defaultDropLocation = null;
            } else {
                link.setVisible(jcrSession.hasPermission(SLASH + defaultDropLocation, Session.ACTION_ADD_NODE));
            }
        } catch (PathNotFoundException ex) {
            log.warn("No default drop location present");
            defaultDropLocation = null; // force adding empty panel
        } catch (RepositoryException ex) {
            log.warn("Error while accessing default drop location");
            defaultDropLocation = null; // force adding empty panel
        }
    }

    if (defaultDropLocation == null) {
        link.setVisible(false);
    }
}

From source file:org.obiba.onyx.jade.core.wicket.workstation.ActionsPanel.java

License:Open Source License

public ActionsPanel(String id, IModel<InstrumentMeasurementType> model) {
    super(id, model);
    setOutputMarkupId(true);//from   www  . java  2s .  c  o m

    InstrumentMeasurementType instrumentMeasurementType = (InstrumentMeasurementType) model.getObject();

    experimentalConditionDialogHelperPanel = new ExperimentalConditionDialogHelperPanel(
            "experimentalConditionDialogHelperPanel",
            new Model<Instrument>(instrumentMeasurementType.getInstrument()),
            new Model<Instrument>(instrumentMeasurementType.getInstrument()));
    add(experimentalConditionDialogHelperPanel);

    editInstrumentWindow = createEditInstrumentWindow("editInstrumentWindow");
    add(editInstrumentWindow);

    deleteInstrumentConfirmationWindow = createDeleteInstrumentConfirmationDialogWindow(
            "deleteConfirmationDialog");
    add(deleteInstrumentConfirmationWindow);

    RepeatingView repeating = new RepeatingView("link");
    add(repeating);
    SeparatorMarkupComponentBorder border = new SeparatorMarkupComponentBorder();

    for (LinkInfo linkInfo : getListOfLinkInfo(instrumentMeasurementType.getInstrument())) {
        AjaxLink<LinkInfo> link = new AjaxLink<LinkInfo>(repeating.newChildId(),
                new Model<LinkInfo>(linkInfo)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                getModelObject().onClick(target);
            }

        };
        link.add(new Label("action", new StringResourceModel(linkInfo.name, null)).setRenderBodyOnly(true));
        link.setComponentBorder(border);
        link.setVisible(linkInfo.isVisible());
        repeating.add(link);
    }

}

From source file:org.obiba.onyx.jade.core.wicket.workstation.WorkstationLogPanel.java

License:Open Source License

public WorkstationLogPanel(String id) {
    super(id);/*from w  w w  .  ja va  2 s  .  c om*/

    experimentalConditionDialogHelperPanel = new ExperimentalConditionDialogHelperPanel(
            "experimentalConditionDialogHelperPanel", null, null);
    add(experimentalConditionDialogHelperPanel);

    final List<ExperimentalConditionLog> experimentalConditionLogs = getExperimentalConditionLogs();
    if (experimentalConditionLogs.size() >= 1)
        selectedExperimentalConditionLog = experimentalConditionLogs.get(0);

    final DropDownChoice<ExperimentalConditionLog> workstationLogChoice = new DropDownChoice<ExperimentalConditionLog>(
            "workstationLogChoice",
            new PropertyModel<ExperimentalConditionLog>(this, "selectedExperimentalConditionLog"),
            getExperimentalConditionLogs(), new ChoiceRenderer<ExperimentalConditionLog>() {
                private static final long serialVersionUID = 1L;

                @Override
                public Object getDisplayValue(ExperimentalConditionLog object) {
                    String name = object.getName() + "Log";
                    return new SpringStringResourceModel(name, name).getString();
                }

                @Override
                public String getIdValue(ExperimentalConditionLog object, int index) {
                    return object.getName();
                }

            });

    workstationLogChoice.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ExperimentalConditionHistoryPanel newExperimentalConditionHistoryPanel = getExperimentalConditionHistoryPanel();
            experimentalConditionHistoryPanel.replaceWith(newExperimentalConditionHistoryPanel);
            experimentalConditionHistoryPanel = newExperimentalConditionHistoryPanel;
            if (experimentalConditionLogs.size() == 0)
                experimentalConditionHistoryPanel.setVisible(false);
            target.addComponent(experimentalConditionHistoryPanel);
            workstationLogChoice.updateModel();
        }

    });
    add(workstationLogChoice);

    AjaxLink addWorkstationLogButton = new AjaxLink("addWorkstationLogButton") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            experimentalConditionDialogHelperPanel.setExperimentalConditionLog(selectedExperimentalConditionLog,
                    null);

            experimentalConditionDialogHelperPanel.getExperimentalConditionDialog()
                    .setWindowClosedCallback(new WindowClosedCallback() {
                        private static final long serialVersionUID = 1L;

                        public void onClose(AjaxRequestTarget target, Status status) {
                            ExperimentalConditionHistoryPanel newExperimentalConditionHistoryPanel = getExperimentalConditionHistoryPanel();
                            experimentalConditionHistoryPanel.replaceWith(newExperimentalConditionHistoryPanel);
                            experimentalConditionHistoryPanel = newExperimentalConditionHistoryPanel;
                            if (experimentalConditionLogs.size() == 0)
                                experimentalConditionHistoryPanel.setVisible(false);
                            target.addComponent(experimentalConditionHistoryPanel);
                        }

                    });
            SpringStringResourceModel experimentalConditionNameResource = new SpringStringResourceModel(
                    selectedExperimentalConditionLog.getName(), selectedExperimentalConditionLog.getName());
            String experimentalConditionName = experimentalConditionNameResource.getString();
            experimentalConditionDialogHelperPanel.getExperimentalConditionDialog()
                    .setTitle(new StringResourceModel("ExperimentalConditionDialogTitle",
                            WorkstationLogPanel.this, new Model<ValueMap>(
                                    new ValueMap("experimentalConditionName=" + experimentalConditionName))));
            experimentalConditionDialogHelperPanel.getExperimentalConditionDialog().show(target);
        }

    };
    add(addWorkstationLogButton);
    if (experimentalConditionLogs.size() == 0)
        addWorkstationLogButton.setVisible(false);

    experimentalConditionHistoryPanel = getExperimentalConditionHistoryPanel();
    add(experimentalConditionHistoryPanel);
    if (experimentalConditionLogs.size() == 0)
        experimentalConditionHistoryPanel.setVisible(false);

}

From source file:org.obiba.onyx.quartz.editor.widget.sortable.SortableList.java

License:Open Source License

@SuppressWarnings("unchecked")
public SortableList(String id, IModel<? extends List<? extends T>> model, final boolean hideEditButton) {
    super(id, model);

    add(CSSPackageResource.getHeaderContribution(SortableList.class, "SortableList.css"));

    ListView<T> listView = new ListView<T>("listView", model) {

        @Override//from   ww  w  .  j  av a  2 s.c  o m
        protected void populateItem(ListItem<T> item) {
            item.setOutputMarkupId(true);
            final T t = item.getModelObject();

            item.add(getItemTitle("item", t));

            Image editImg = new Image("editImg", Images.EDIT);
            editImg.add(new AttributeModifier("title", true, new ResourceModel("Edit")));
            AjaxLink<Void> editAjaxLink = new AjaxLink<Void>("editItem") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    editItem(t, target);
                }
            };
            editAjaxLink.setVisible(!hideEditButton);
            item.add(editAjaxLink.add(editImg));

            Image deleteImg = new Image("deleteImg", Images.DELETE);
            deleteImg.add(new AttributeModifier("title", true, new ResourceModel("Delete")));
            item.add(new AjaxLink<Void>("deleteItem") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteItem(t, target);
                }
            }.add(deleteImg));

            itemByMarkupId.put(item.getMarkupId(), t);
        }
    };

    listContainer = new WebMarkupContainer("listContainer") {
        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();

            final IModel<Map<String, Object>> variablesModel = new AbstractReadOnlyModel<Map<String, Object>>() {
                private Map<String, Object> variables;

                @Override
                public Map<String, Object> getObject() {
                    if (variables == null) {
                        this.variables = new MiniMap<String, Object>(2);
                        variables.put("listMarkupId", listContainer.getMarkupId());
                        variables.put("callbackUrl", toArrayBehavior.getCallbackUrl());
                    }
                    return variables;
                }
            };
            PackagedTextTemplate jsTemplate = new PackagedTextTemplate(SortableList.class, "SortableList.js");
            final Label jsScript = new Label("sortableJs",
                    new JavaScriptTemplate(jsTemplate).asString(variablesModel.getObject()));
            jsScript.setEscapeModelStrings(false);
            listContainer.addOrReplace(jsScript);
        }
    };
    listContainer.add(toArrayBehavior = new ToArrayBehavior());
    listContainer.setOutputMarkupId(true);
    listContainer.add(listView);
    add(listContainer);

    listContainer.add(new AbstractBehavior() {
        @Override
        public void renderHead(IHeaderResponse response) {
            response.renderOnLoadJavascript("Wicket.Sortable.create" + listContainer.getMarkupId() + "('"
                    + listContainer.getMarkupId() + "')");
        }
    });

    add(new ListView<Button>("buttons",
            getButtons() == null ? Collections.EMPTY_LIST : Arrays.asList(getButtons())) {
        @Override
        protected void populateItem(ListItem<Button> item) {
            item.add(new ButtonFragment("button", item.getModel()));
        }
    });
    listContainer.addOrReplace(new WebMarkupContainer("sortableJs"));
}

From source file:org.obiba.onyx.webapp.stage.panel.ViewCommentsActionPanel.java

License:Open Source License

public ViewCommentsActionPanel(String id) {
    super(id);// w ww  .java  2  s.  co  m

    AjaxLink viewLogs = new AjaxLink("viewLogs") {

        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            ViewCommentsActionPanel.this.onViewLogs(target);
        }
    };
    viewLogs.add(new ContextImage("viewLogsImg", new Model("icons/loupe_button.png")));
    add(viewLogs);
    viewLogs.setVisible(logEntryExists());

    AjaxLink viewComments = new AjaxLink("viewComments") {

        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            ViewCommentsActionPanel.this.onViewComments(target);
        }
    };
    viewComments.add(new ContextImage("viewCommentsImg", new Model("icons/note.png")));
    add(viewComments);
    viewComments.setVisible(commentEntryExists());

}

From source file:org.obiba.onyx.wicket.wizard.WizardForm.java

License:Open Source License

public WizardForm(String id, IModel model) {
    super(id, model);

    setOutputMarkupId(true);//from  w w  w  .ja  v a2  s  .  c  o m

    IBehavior buttonStyleBehavior = new AttributeAppender("class", new Model("ui-corner-all"), " ");

    // finish button
    AjaxButton finish = createFinish();
    finish.add(buttonStyleBehavior);
    finish.setVisible(false);
    finish.setOutputMarkupId(true);
    finish.setOutputMarkupPlaceholderTag(true);
    add(finish);

    // previous button
    AjaxLink link = createPrevious();
    link.setVisible(false);
    link.setOutputMarkupId(true);
    link.setOutputMarkupPlaceholderTag(true);
    link.add(buttonStyleBehavior);
    add(link);

    // next button
    AjaxButton button = createNext();
    button.setOutputMarkupId(true);
    button.setOutputMarkupPlaceholderTag(true);
    button.add(buttonStyleBehavior);
    add(button);

    // cancel button
    AjaxLink cancelLink = createCancel();
    cancelLink.add(buttonStyleBehavior);
    add(cancelLink);

    add(new LanguageStyleBehavior());
}

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();/*from   w w w . ja v a2  s  . c om*/
        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);
        }
    }
}