Search in sources :

Example 6 with Item

use of org.apache.wicket.markup.repeater.Item in project gitblit by gitblit.

the class UserPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        authenticationError("Please login");
        return;
    }
    String userName = WicketUtils.getUsername(params);
    if (StringUtils.isEmpty(userName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    UserModel user = app().users().getUserModel(userName);
    if (user == null) {
        // construct a temporary user model
        user = new UserModel(userName);
    }
    add(new UserTitlePanel("userTitlePanel", user, user.username));
    UserModel sessionUser = GitBlitWebSession.get().getUser();
    boolean isMyProfile = sessionUser != null && sessionUser.equals(user);
    if (isMyProfile) {
        addPreferences(user);
        if (app().services().isServingSSH()) {
            // show the SSH key management tab
            addSshKeys(user);
        } else {
            // SSH daemon is disabled, hide keys tab
            add(new Label("sshKeysLink").setVisible(false));
            add(new Label("sshKeysTab").setVisible(false));
        }
    } else {
        // visiting user
        add(new Label("preferencesLink").setVisible(false));
        add(new Label("preferencesTab").setVisible(false));
        add(new Label("sshKeysLink").setVisible(false));
        add(new Label("sshKeysTab").setVisible(false));
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    final ListDataProvider<RepositoryModel> dp = new ListDataProvider<RepositoryModel>(repositories);
    DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repositoryList", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RepositoryModel> item) {
            final RepositoryModel entry = item.getModelObject();
            ProjectRepositoryPanel row = new ProjectRepositoryPanel("repository", getLocalizer(), this, showAdmin, entry, getAccessRestrictions());
            item.add(row);
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) UserTitlePanel(com.gitblit.wicket.panels.UserTitlePanel) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectRepositoryPanel(com.gitblit.wicket.panels.ProjectRepositoryPanel)

Example 7 with Item

use of org.apache.wicket.markup.repeater.Item in project gitblit by gitblit.

the class SshKeysPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    setOutputMarkupId(true);
    final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
    final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
    final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SshKey> item) {
            final SshKey key = item.getModelObject();
            item.add(new Label("comment", key.getComment()));
            item.add(new Label("fingerprint", key.getFingerprint()));
            item.add(new Label("permission", key.getPermission().toString()));
            item.add(new Label("algorithm", key.getAlgorithm()));
            AjaxLink<Void> delete = new AjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (app().keys().removeKey(user.username, key)) {
                        // reset the keys list
                        keys.clear();
                        keys.addAll(app().keys().getKeys(user.username));
                        // update the panel
                        target.addComponent(SshKeysPanel.this);
                    }
                }
            };
            if (!canWriteKeys) {
                delete.setVisibilityAllowed(false);
            }
            item.add(delete);
        }
    };
    add(keysView);
    Form<Void> addKeyForm = new Form<Void>("addKeyForm");
    final IModel<String> keyData = Model.of("");
    addKeyForm.add(new TextAreaOption("addKeyData", getString("gb.key"), null, "span5", keyData));
    final IModel<AccessPermission> keyPermission = Model.of(AccessPermission.PUSH);
    addKeyForm.add(new ChoiceOption<AccessPermission>("addKeyPermission", getString("gb.permission"), getString("gb.sshKeyPermissionDescription"), keyPermission, Arrays.asList(AccessPermission.SSHPERMISSIONS)));
    final IModel<String> keyComment = Model.of("");
    addKeyForm.add(new TextOption("addKeyComment", getString("gb.comment"), getString("gb.sshKeyCommentDescription"), "span5", keyComment));
    addKeyForm.add(new AjaxButton("addKeyButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            UserModel user = GitBlitWebSession.get().getUser();
            String data = keyData.getObject();
            if (StringUtils.isEmpty(data)) {
                // do not submit empty key
                return;
            }
            SshKey key = new SshKey(data);
            try {
                key.getPublicKey();
            } catch (Exception e) {
                // failed to parse the key
                return;
            }
            AccessPermission permission = keyPermission.getObject();
            key.setPermission(permission);
            String comment = keyComment.getObject();
            if (!StringUtils.isEmpty(comment)) {
                key.setComment(comment);
            }
            if (app().keys().addKey(user.username, key)) {
                // reset add key fields
                keyData.setObject("");
                keyPermission.setObject(AccessPermission.PUSH);
                keyComment.setObject("");
                // reset the keys list
                keys.clear();
                keys.addAll(app().keys().getKeys(user.username));
                // update the panel
                target.addComponent(SshKeysPanel.this);
            }
        }
    });
    if (!canWriteKeys) {
        addKeyForm.setVisibilityAllowed(false);
    }
    add(addKeyForm);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) UserModel(com.gitblit.models.UserModel) Item(org.apache.wicket.markup.repeater.Item) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AccessPermission(com.gitblit.Constants.AccessPermission) SshKey(com.gitblit.transport.ssh.SshKey) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DataView(org.apache.wicket.markup.repeater.data.DataView)

Example 8 with Item

use of org.apache.wicket.markup.repeater.Item in project midpoint by Evolveum.

the class AbstractRoleMemberPanel method createMembersColumns.

protected List<IColumn<SelectableBean<ObjectType>, String>> createMembersColumns() {
    List<IColumn<SelectableBean<ObjectType>, String>> columns = new ArrayList<>();
    IColumn<SelectableBean<ObjectType>, String> column = new AbstractExportableColumn<SelectableBean<ObjectType>, String>(createStringResource("TreeTablePanel.fullName.displayName")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ObjectType>>> cellItem, String componentId, IModel<SelectableBean<ObjectType>> rowModel) {
            SelectableBean<ObjectType> bean = rowModel.getObject();
            ObjectType object = bean.getValue();
            cellItem.add(new Label(componentId, getMemberObjectDisplayName(object)));
        }

        @Override
        public IModel<String> getDataModel(IModel<SelectableBean<ObjectType>> rowModel) {
            return Model.of(getMemberObjectDisplayName(rowModel.getObject().getValue()));
        }
    };
    columns.add(column);
    column = new AbstractExportableColumn<SelectableBean<ObjectType>, String>(createStringResource("TreeTablePanel.identifier.description")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ObjectType>>> cellItem, String componentId, IModel<SelectableBean<ObjectType>> rowModel) {
            SelectableBean<ObjectType> bean = rowModel.getObject();
            ObjectType object = bean.getValue();
            cellItem.add(new Label(componentId, getMemberObjectIdentifier(object)));
        }

        @Override
        public IModel<String> getDataModel(IModel<SelectableBean<ObjectType>> rowModel) {
            return Model.of(getMemberObjectIdentifier(rowModel.getObject().getValue()));
        }
    };
    columns.add(column);
    return columns;
}
Also used : IModel(org.apache.wicket.model.IModel) AbstractExportableColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.export.AbstractExportableColumn) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Item(org.apache.wicket.markup.repeater.Item) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean)

Example 9 with Item

use of org.apache.wicket.markup.repeater.Item in project midpoint by Evolveum.

the class SynchronizationStep method initLayout.

private void initLayout() {
    final ListDataProvider<ObjectSynchronizationType> syncProvider = new ListDataProvider<>(this, new PropertyModel<List<ObjectSynchronizationType>>(syncDtoModel, ResourceSynchronizationDto.F_OBJECT_SYNCRONIZATION_LIST));
    //first row - object sync list
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_TABLE_ROWS);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    //second row - ObjectSynchronizationType editor
    WebMarkupContainer objectSyncEditor = new WebMarkupContainer(ID_OBJECT_SYNC_EDITOR);
    objectSyncEditor.setOutputMarkupId(true);
    objectSyncEditor.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return isAnySelected();
        }
    });
    add(objectSyncEditor);
    //third row - container for more specific editors
    WebMarkupContainer thirdRowContainer = new WebMarkupContainer(ID_THIRD_ROW_CONTAINER);
    thirdRowContainer.setOutputMarkupId(true);
    add(thirdRowContainer);
    DataView<ObjectSynchronizationType> syncDataView = new DataView<ObjectSynchronizationType>(ID_OBJECT_SYNC_ROW, syncProvider, UserProfileStorage.DEFAULT_PAGING_SIZE) {

        @Override
        protected void populateItem(Item<ObjectSynchronizationType> item) {
            final ObjectSynchronizationType syncObject = item.getModelObject();
            AjaxSubmitLink link = new AjaxSubmitLink(ID_OBJECT_SYNC_LINK) {

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    editSyncObjectPerformed(target, syncObject);
                }
            };
            item.add(link);
            Label label = new Label(ID_OBJECT_SYNC_LABEL, createObjectSyncTypeDisplayModel(syncObject));
            label.setOutputMarkupId(true);
            link.add(label);
            AjaxLink delete = new AjaxLink(ID_OBJECT_SYNC_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteSyncObjectPerformed(target, syncObject);
                }
            };
            parentPage.addEditingVisibleBehavior(delete);
            link.add(delete);
            item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    if (isSelected(syncObject)) {
                        return "success";
                    }
                    return null;
                }
            }));
        }
    };
    tableBody.add(syncDataView);
    NavigatorPanel navigator = new NavigatorPanel(ID_PAGING, syncDataView, true);
    navigator.setOutputMarkupId(true);
    navigator.setOutputMarkupPlaceholderTag(true);
    add(navigator);
    AjaxLink add = new AjaxLink(ID_OBJECT_SYNC_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addSyncObjectPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(add);
    add(add);
    initObjectSyncEditor(objectSyncEditor);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DataView(org.apache.wicket.markup.repeater.data.DataView) ListItem(org.apache.wicket.markup.html.list.ListItem) Item(org.apache.wicket.markup.repeater.Item) NavigatorPanel(com.evolveum.midpoint.web.component.data.paging.NavigatorPanel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 10 with Item

use of org.apache.wicket.markup.repeater.Item in project midpoint by Evolveum.

the class SchemaListPanel method initLayout.

protected void initLayout() {
    final ObjectClassDataProvider dataProvider = new ObjectClassDataProvider(allClasses);
    TextField objectClass = new TextField<>(ID_OBJECT_CLASS, new Model<>());
    objectClass.setOutputMarkupId(true);
    objectClass.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateSearchPerformed(target, dataProvider);
        }
    });
    add(objectClass);
    AjaxButton clearSearch = new AjaxButton(ID_CLEAR_SEARCH) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            clearSearchPerformed(target, dataProvider);
        }
    };
    add(clearSearch);
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_TABLE_BODY);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    DataView<ObjectClassDto> objectClassDataView = new DataView<ObjectClassDto>(ID_OBJECT_CLASS_LIST, dataProvider, UserProfileStorage.DEFAULT_PAGING_SIZE) {

        @Override
        protected void populateItem(final Item<ObjectClassDto> item) {
            AjaxLink link = new AjaxLink(ID_CLASS_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    objectClassClickPerformed(target, item.getModelObject());
                }
            };
            item.add(link);
            Label label = new Label(ID_LABEL, new PropertyModel<>(item.getModel(), ObjectClassDto.F_DISPLAY_NAME));
            link.add(label);
            item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return item.getModelObject().isSelected() ? "success" : null;
                }
            }));
        }
    };
    tableBody.add(objectClassDataView);
    NavigatorPanel objectClassNavigator = new NavigatorPanel(ID_NAVIGATOR, objectClassDataView, true);
    objectClassNavigator.setOutputMarkupId(true);
    objectClassNavigator.setOutputMarkupPlaceholderTag(true);
    add(objectClassNavigator);
    WebMarkupContainer objectClassInfoContainer = new WebMarkupContainer(ID_OBJECT_CLASS_INFO_CONTAINER);
    objectClassInfoContainer.setOutputMarkupId(true);
    add(objectClassInfoContainer);
    WebMarkupContainer objectClassInfoColumn = new WebMarkupContainer(ID_OBJECT_CLASS_INFO_COLUMN);
    objectClassInfoColumn.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getSelectedObjectClass() != null;
        }
    });
    objectClassInfoContainer.add(objectClassInfoColumn);
    initDetailsPanel(objectClassInfoColumn);
    ListDataProvider<AttributeDto> attributeProvider = new ListDataProvider<>(this, attributeModel, true);
    attributeProvider.setSort(AttributeDto.F_DISPLAY_ORDER, SortOrder.ASCENDING);
    BoxedTablePanel<AttributeDto> attributeTable = new BoxedTablePanel<>(ID_ATTRIBUTE_TABLE, attributeProvider, initColumns());
    attributeTable.setOutputMarkupId(true);
    attributeTable.setItemsPerPage(UserProfileStorage.DEFAULT_PAGING_SIZE);
    attributeTable.setShowPaging(true);
    objectClassInfoColumn.add(attributeTable);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) ObjectClassDataProvider(com.evolveum.midpoint.web.component.wizard.resource.dto.ObjectClassDataProvider) ObjectClassDto(com.evolveum.midpoint.web.component.wizard.resource.dto.ObjectClassDto) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AttributeDto(com.evolveum.midpoint.web.component.wizard.resource.dto.AttributeDto) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) NavigatorPanel(com.evolveum.midpoint.web.component.data.paging.NavigatorPanel) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel)

Aggregations

Item (org.apache.wicket.markup.repeater.Item)30 Label (org.apache.wicket.markup.html.basic.Label)23 DataView (org.apache.wicket.markup.repeater.data.DataView)15 IModel (org.apache.wicket.model.IModel)15 ArrayList (java.util.ArrayList)13 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)11 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)11 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)9 Model (org.apache.wicket.model.Model)7 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 PropertyColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn)6 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)5 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)5 ListItem (org.apache.wicket.markup.html.list.ListItem)5 Fragment (org.apache.wicket.markup.html.panel.Fragment)5 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)4 UserModel (com.gitblit.models.UserModel)4 Component (org.apache.wicket.Component)4 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)4