Example usage for org.apache.wicket Component getDefaultModelObject

List of usage examples for org.apache.wicket Component getDefaultModelObject

Introduction

In this page you can find the example usage for org.apache.wicket Component getDefaultModelObject.

Prototype

public final Object getDefaultModelObject() 

Source Link

Document

Gets the backing model object.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.RecordItemModel.java

License:Open Source License

public void updateRenderedValue(Component comp) {
    lastRenderedValues.put(comp, comp.getDefaultModelObject());
}

From source file:hsa.awp.admingui.TestHomePage.java

License:Open Source License

@Test
public void testTimestamp() {
    login("sysadmin", "sysadmin");
    Date now = new Date();
    tester.startPage(HomePage.class);
    tester.assertComponent("timestamp", Label.class);
    Component timestampLabel = tester.getComponentFromLastRenderedPage("timestamp");
    String timestamp = (String) timestampLabel.getDefaultModelObject();
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    assertEquals(timestamp, dateFormat.format(now));
}

From source file:net.dontdrinkandroot.extensions.wicket.jqueryui.SortableBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {
    final StringValue oldPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("oldPosition");
    final StringValue newPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("newPosition");
    final StringValue outValue = this.getComponent().getRequest().getQueryParameters().getParameterValue("out");
    final StringValue componentPathValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("componentPath");

    final int oldPosition = oldPositionValue.toInt();
    final int newPosition = newPositionValue.toInt();
    final boolean out = outValue.toBoolean();
    final String droppedComponentPath = componentPathValue.toString("");
    final String boundComponentPath = this.getComponent().getPageRelativePath();

    if (boundComponentPath.equals(droppedComponentPath)) {

        /* The dropped component is one of our list items */
        if (out) {
            /* Item was dragged outside of the list, remove it */
            this.onRemove(target, oldPosition, newPosition);
        } else {//from  www.  j  a  va 2s.  com
            /* Item was dragged within the list, update position */
            this.onPositionChanged(target, oldPosition, newPosition);
        }
    } else {

        /* Retrieve the dropped component by its path and insert its model into the list */
        final Component droppedComponent = this.getComponent().getPage().get(droppedComponentPath);
        Object droppedComponentModelObject = null;
        if (droppedComponent != null) {
            droppedComponentModelObject = droppedComponent.getDefaultModelObject();
        }
        this.onInsert(target, droppedComponentModelObject, newPosition);
    }
}

From source file:net.dontdrinkandroot.wicket.behavior.jqueryui.SortableBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {

    final StringValue oldPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("oldPosition");
    final StringValue newPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("newPosition");
    final StringValue outValue = this.getComponent().getRequest().getQueryParameters().getParameterValue("out");
    final StringValue componentPathValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("componentPath");

    int oldPosition = oldPositionValue.toInt();
    int newPosition = newPositionValue.toInt();
    boolean out = outValue.toBoolean();
    String droppedComponentPath = componentPathValue.toString("");
    String boundComponentPath = this.getComponent().getPageRelativePath();

    if (boundComponentPath.equals(droppedComponentPath)) {

        /* The dropped component is one of our list items */
        if (out) {
            /* Item was dragged outside of the list, remove it */
            this.onRemove(target, oldPosition);
        } else {/*from  ww w  .j  av a 2 s. co m*/
            /* Item was dragged within the list, update position */
            this.onPositionChanged(target, oldPosition, newPosition);
        }

    } else {

        /* Retrieve the dropped component by its path and insert its model into the list */
        Component droppedComponent = this.getComponent().getPage().get(droppedComponentPath);
        Object droppedComponentModelObject = null;
        if (droppedComponent != null) {
            droppedComponentModelObject = droppedComponent.getDefaultModelObject();
        }
        this.onInsert(target, droppedComponentModelObject, newPosition);
    }
}

From source file:ontopoly.components.FieldInstanceAssociationBinaryPanel.java

License:Apache License

protected FieldInstanceAssociationBinaryPanel(String id, final FieldInstanceModel fieldInstanceModel,
        final FieldsViewModel fieldsViewModel, final boolean readonlyField, final boolean embedded,
        final boolean traversable) {
    super(id, fieldInstanceModel);

    FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance();
    FieldAssignment fieldAssignment = fieldInstance.getFieldAssignment();
    RoleField roleField = (RoleField) fieldAssignment.getFieldDefinition();
    this.roleFieldModel = new RoleFieldModel(roleField);

    add(new FieldDefinitionLabel("fieldLabel", new FieldDefinitionModel(roleField)));

    // set up container
    this.fieldValuesContainer = new WebMarkupContainer("fieldValuesContainer");
    fieldValuesContainer.setOutputMarkupId(true);
    add(fieldValuesContainer);/* w w  w.ja  v  a  2 s .  c  o  m*/

    // add feedback panel
    this.feedbackPanel = new FeedbackPanel("feedback", new AbstractFieldInstancePanelFeedbackMessageFilter());
    feedbackPanel.setOutputMarkupId(true);
    fieldValuesContainer.add(feedbackPanel);

    this.confirmDeletePanel = new ConfirmDeletePanel("confirm", fieldValuesContainer) {
        @Override
        protected void onDeleteTopic(AjaxRequestTarget target) {
            super.onDeleteTopic(target);
            FieldInstanceAssociationBinaryPanel.this.onUpdate(target);
        }
    };
    confirmDeletePanel.setOutputMarkupId(true);
    fieldValuesContainer.add(confirmDeletePanel);

    RoleField ofield = (RoleField) roleField.getFieldsForOtherRoles().iterator().next();
    this.ofieldModel = new RoleFieldModel(ofield);
    this.topicModel = new TopicModel<Topic>(fieldInstance.getInstance());

    InterfaceControl interfaceControl = ofield.getInterfaceControl();

    WebMarkupContainer fieldValuesList = new WebMarkupContainer("fieldValuesList");
    fieldValuesContainer.add(fieldValuesList);

    final String fieldDefinitionId = roleField.getId();

    EditMode editMode = roleField.getEditMode();

    final boolean ownedvalues = editMode.isOwnedValues();
    final boolean allowAdd = !(ownedvalues || editMode.isNewValuesOnly() || editMode.isNoEdit());
    final boolean allowCreate = !(editMode.isExistingValuesOnly() || editMode.isNoEdit());
    final boolean allowRemove = !editMode.isNoEdit();
    final boolean sortable = roleField.isSortable();

    // add field values component(s)
    // TODO: consider moving ordering logic into object model
    if (sortable) {
        // HACK: retrieving values ourselves so that we can get them ordered
        this.fieldValuesModel = new FieldValuesModel(fieldInstanceModel) {
            @Override
            protected List<RoleField.ValueIF> getValues(FieldInstance fieldInstance) {
                Topic instance = fieldInstance.getInstance();
                RoleField roleField = (RoleField) fieldInstance.getFieldAssignment().getFieldDefinition();
                return roleField.getOrderedValues(instance, ofieldModel.getRoleField());
            }
        };
    } else {
        Comparator<Object> comparator = new RoleFieldValueComparator(topicModel, ofieldModel);
        this.fieldValuesModel = new FieldValuesModel(fieldInstanceModel, comparator);
    }

    this.listView = new ListView<FieldValueModel>("fieldValues", fieldValuesModel) {
        @Override
        protected void onBeforeRender() {
            validateCardinality();
            super.onBeforeRender();
        }

        public void populateItem(final ListItem<FieldValueModel> item) {
            FieldValueModel fieldValueModel = item.getModelObject();

            // get topic
            Topic oplayer = null;
            if (fieldValueModel.isExistingValue()) {
                RoleField.ValueIF valueIf = (RoleField.ValueIF) fieldValueModel.getObject();
                RoleField ofield = ofieldModel.getRoleField();
                oplayer = valueIf.getPlayer(ofield, fieldInstanceModel.getFieldInstance().getInstance());
            }
            final String topicMapId = (oplayer == null ? null : oplayer.getTopicMap().getId());
            final String topicId = (oplayer == null ? null : oplayer.getId());

            // acquire lock for embedded topic
            final boolean isLockedByOther;
            if (embedded && fieldValueModel.isExistingValue()) {
                OntopolySession session = (OntopolySession) Session.get();
                String lockerId = session.getLockerId(getRequest());
                LockManager.Lock lock = session.lock(oplayer, lockerId);
                isLockedByOther = !lock.ownedBy(lockerId);
            } else {
                isLockedByOther = false;
            }
            final boolean readonly = readonlyField || isLockedByOther;

            boolean itemSortable = !readonly && sortable && fieldValueModel.isExistingValue();
            if (itemSortable) {
                item.add(new DroppableBehavior(fieldDefinitionId) {
                    @Override
                    protected MarkupContainer getDropContainer() {
                        return listView;
                    }

                    @Override
                    protected void onDrop(Component component, AjaxRequestTarget target) {
                        FieldValueModel fvm_dg = (FieldValueModel) component.getDefaultModelObject();
                        FieldValueModel fvm_do = (FieldValueModel) getComponent().getDefaultModelObject();
                        RoleField.ValueIF rfv_dg = (RoleField.ValueIF) fvm_dg.getFieldValue();
                        RoleField.ValueIF rfv_do = (RoleField.ValueIF) fvm_do.getFieldValue();

                        Topic topic = topicModel.getTopic();
                        RoleField rfield = roleFieldModel.getRoleField();
                        RoleField ofield = ofieldModel.getRoleField();
                        rfield.moveAfter(topic, ofield, rfv_dg, rfv_do);
                        getModel().detach(); // FIXME: better if we could just tweak model directly without detaching
                        listView.removeAll();
                        target.addComponent(fieldValuesContainer);
                    }
                });
                item.add(new DraggableBehavior(fieldDefinitionId));
            }

            item.setOutputMarkupId(true);
            WebMarkupContainer fieldIconContainer = new WebMarkupContainer("fieldIconContainer");
            fieldIconContainer
                    .add(new OntopolyImage("fieldIcon", "dnd.gif", new ResourceModel("icon.dnd.reorder")));
            fieldIconContainer.setVisible(itemSortable);
            item.add(fieldIconContainer);

            final WebMarkupContainer fieldValueButtons = new WebMarkupContainer("fieldValueButtons");
            fieldValueButtons.setOutputMarkupId(true);
            item.add(fieldValueButtons);

            FieldInstanceRemoveButton removeButton = new FieldInstanceRemoveButton("remove", "remove-value.gif",
                    fieldValueModel) {
                @Override
                public boolean isVisible() {
                    boolean visible = !readonly && fieldValueModel.isExistingValue() && allowRemove; // && !isValueProtected;
                    if (visible) {
                        // filter by player
                        AbstractOntopolyPage page = (AbstractOntopolyPage) getPage();
                        RoleField.ValueIF value = (RoleField.ValueIF) fieldValueModel.getObject();
                        Topic[] players = value.getPlayers();
                        for (int i = 0; i < players.length; i++) {
                            if (!page.filterTopic(players[i]))
                                return false;
                        }
                    }
                    return visible;
                }

                @Override
                public void onClick(AjaxRequestTarget target) {
                    // FIXME: could reuse some of these variable from above
                    FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance();
                    Object value = fieldValueModel.getObject();

                    Topic currentTopic = fieldInstance.getInstance();

                    RoleField currentField = (RoleField) fieldInstance.getFieldAssignment()
                            .getFieldDefinition();
                    RoleField selectedField = ofieldModel.getRoleField();

                    RoleField.ValueIF valueIf = (RoleField.ValueIF) value;
                    Topic selectedTopic = valueIf.getPlayer(selectedField, fieldInstance.getInstance());

                    // check with page to see if add is allowed
                    boolean changesMade = false;
                    AbstractOntopolyPage page = (AbstractOntopolyPage) getPage();
                    if (page.isRemoveAllowed(currentTopic, currentField, selectedTopic, selectedField)) {
                        if (ownedvalues) {

                            // don't remove system topics
                            if (!selectedTopic.isSystemTopic()) {
                                FieldInstanceAssociationBinaryPanel.this.confirmDeletePanel
                                        .setTopic(selectedTopic);
                                changesMade = true;
                            }
                        } else {
                            fieldInstance.removeValue(value, page.getListener());
                            changesMade = true;
                        }
                    }
                    // notify association panel so that it can update itself
                    if (changesMade)
                        FieldInstanceAssociationBinaryPanel.this.onUpdate(target);
                }
            };
            fieldValueButtons.add(removeButton);

            // embedded goto button
            OntopolyImageLink gotoButton = new OntopolyImageLink("goto", "goto.gif",
                    new ResourceModel("icon.goto.topic")) {
                @Override
                public boolean isVisible() {
                    FieldValueModel fieldValueModel = item.getModelObject();
                    return embedded && fieldValueModel.isExistingValue();
                }

                @Override
                public void onClick(AjaxRequestTarget target) {
                    // navigate to topic
                    PageParameters pageParameters = new PageParameters();
                    pageParameters.put("topicMapId", topicMapId);
                    pageParameters.put("topicId", topicId);
                    setResponsePage(getPage().getClass(), pageParameters);
                    setRedirect(true);
                }
            };
            fieldValueButtons.add(gotoButton);

            // embedded lock button
            OntopolyImageLink lockButton = new OntopolyImageLink("lock", "lock.gif",
                    new ResourceModel("icon.topic.locked")) {
                @Override
                public boolean isVisible() {
                    return embedded && isLockedByOther;
                }

                @Override
                public void onClick(AjaxRequestTarget target) {
                }
            };
            fieldValueButtons.add(lockButton);

            // binary
            // ISSUE: should not really pass in readonly-parameter here as it is only relevant if page is readonly
            FieldInstanceAssociationBinaryField binaryField = new FieldInstanceAssociationBinaryField(
                    "fieldValue", ofieldModel, fieldValueModel, fieldsViewModel, readonly, embedded,
                    traversable, allowAdd) {
                @Override
                protected void performNewSelection(FieldValueModel fieldValueModel, RoleField selectedField,
                        Topic selectedTopic) {
                    RoleField.ValueIF value = FieldInstanceAssociationBinaryPanel.this
                            .performNewSelection(selectedField, selectedTopic);
                    fieldValueModel.setExistingValue(value);
                }
            };
            if (binaryField.getUpdateableComponent() != null)
                binaryField.getUpdateableComponent().add(new FieldUpdatingBehaviour(true));
            item.add(binaryField);

            addNewFieldValueCssClass(item, fieldValuesModel, fieldValueModel);
        }
    };
    listView.setReuseItems(true);
    fieldValuesList.add(listView);

    // figure out which buttons to show
    this.fieldInstanceButtons = new WebMarkupContainer("fieldInstanceButtons");
    fieldInstanceButtons.setOutputMarkupId(true);
    add(fieldInstanceButtons);

    if (readonlyField || !allowAdd) {
        // unused components
        fieldInstanceButtons.add(new Label("add", new Model<String>("unused")).setVisible(false));
        fieldInstanceButtons.add(new Label("find", new Model<String>("unused")).setVisible(false));
        fieldInstanceButtons.add(new Label("findModal", new Model<String>("unused")).setVisible(false));

        // add/find button
    } else if (interfaceControl.isDropDownList() || interfaceControl.isAutoComplete()) {
        // "add" button
        OntopolyImageLink addButton = new OntopolyImageLink("add", "add.gif") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                boolean showExtraField = !fieldValuesModel.getShowExtraField();
                fieldValuesModel.setShowExtraField(showExtraField, true);
                listView.removeAll();
                updateDependentComponents(target);
            }

            @Override
            public boolean isVisible() {
                if (readonlyField)
                    return false;
                else
                    return fieldValuesModel.containsExisting();
            }

            @Override
            public String getImage() {
                return fieldValuesModel.getShowExtraField() ? "remove.gif" : "add.gif";
            }

            @Override
            public IModel<String> getTitleModel() {
                return new ResourceModel(
                        fieldValuesModel.getShowExtraField() ? "icon.remove.hide-field" : "icon.add.add-value");
            }
        };
        fieldInstanceButtons.add(addButton);

        // unused components
        fieldInstanceButtons.add(new Label("find", new Model<String>("unused")).setVisible(false));
        fieldInstanceButtons.add(new Label("findModal", new Model<String>("unused")).setVisible(false));

    } else if (interfaceControl.isSearchDialog() || interfaceControl.isBrowseDialog()) {

        // "search"/"browse" button
        final ModalWindow findModal = new ModalWindow("findModal");
        fieldInstanceButtons.add(findModal);

        int activeTab = (interfaceControl.isSearchDialog() ? ModalFindPage.ACTIVE_TAB_SEARCH
                : ModalFindPage.ACTIVE_TAB_BROWSE);

        findModal
                .setContent(new ModalFindPage<String>(findModal.getContentId(), fieldInstanceModel, activeTab) {
                    @Override
                    protected void onSelectionConfirmed(AjaxRequestTarget target, Collection<String> selected) {
                        FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance();
                        RoleField currentField = (RoleField) fieldInstance.getFieldAssignment()
                                .getFieldDefinition();
                        RoleField selectedField = (RoleField) currentField.getFieldsForOtherRoles().iterator()
                                .next();

                        // check with page to see if add is allowed
                        if (ObjectUtils.different(currentField, selectedField) ||
                        // if assoc type is symmetric currentField == selectedField,
                        // but we're still OK to go ahead, so checking for that
                        // (this is issue 457)
                        currentField.getAssociationType().isSymmetric()) {

                            Topic currentTopic = fieldInstance.getInstance();
                            TopicMap topicMap = currentTopic.getTopicMap();

                            boolean changesMade = false;
                            Iterator<String> iter = selected.iterator();
                            while (iter.hasNext()) {
                                String objectId = (String) iter.next();

                                AbstractOntopolyPage page = (AbstractOntopolyPage) getPage();
                                Topic selectedTopic = topicMap.getTopicById(objectId);

                                if (page.isAddAllowed(currentTopic, currentField, selectedTopic,
                                        selectedField)) {
                                    performNewSelection(selectedField, selectedTopic);
                                    changesMade = true;
                                }
                            }
                            // notify association panel so that it can update itself
                            if (changesMade)
                                FieldInstanceAssociationBinaryPanel.this.onUpdate(target);
                        }
                    }

                    @Override
                    protected void onCloseCancel(AjaxRequestTarget target) {
                        findModal.close(target);
                    }

                    @Override
                    protected void onCloseOk(AjaxRequestTarget target) {
                        findModal.close(target);
                    }
                });
        findModal.setTitle(new ResourceModel("ModalWindow.title.find.topic").getObject().toString());
        findModal.setCookieName("findModal");

        OntopolyImageLink findButton = new OntopolyImageLink("find", "search.gif",
                new ResourceModel("find.topic")) {
            @Override
            public void onClick(AjaxRequestTarget target) {
                findModal.show(target);
            }
        };
        fieldInstanceButtons.add(findButton);
        // unused components
        fieldInstanceButtons.add(new Label("add", new Model<String>("unused")).setVisible(false));
    } else {
        throw new RuntimeException("Unsupported interface control: " + interfaceControl);
    }

    // create button
    if (readonlyField || !allowCreate) {
        fieldInstanceButtons.add(new Label("create").setVisible(false));
    } else {

        CreateAction ca = roleField.getCreateAction();
        int createAction;
        if (embedded || ca.isNone())
            createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_NONE;
        else if (ca.isNavigate())
            createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_NAVIGATE;
        else
            createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_POPUP;

        FieldInstanceCreatePlayerPanel createPanel = new FieldInstanceCreatePlayerPanel("create",
                fieldInstanceModel, fieldsViewModel, new RoleFieldModel(ofield), this, createAction) {
            @Override
            protected void performNewSelection(RoleFieldModel ofieldModel, Topic selectedTopic) {
                FieldInstanceAssociationBinaryPanel.this.performNewSelection(ofieldModel.getRoleField(),
                        selectedTopic);
            }

        };
        createPanel.setOutputMarkupId(true);
        fieldInstanceButtons.add(createPanel);
    }
}

From source file:org.apache.openmeetings.web.common.tree.FileTreePanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();
    final AddFolderDialog addFolder = new AddFolderDialog("addFolder", Application.getString(712)) {
        private static final long serialVersionUID = 1L;

        @Override/*from  w w  w. j  a v  a  2  s.  com*/
        protected void onSubmit(AjaxRequestTarget target) {
            createFolder(target, getModelObject());
        }
    };
    add(addFolder);
    Droppable<FileItem> trashToolbar = new Droppable<FileItem>("trash-toolbar") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onConfigure(JQueryBehavior behavior) {
            super.onConfigure(behavior);
            behavior.setOption("hoverClass", Options.asString("ui-state-hover trash-toolbar-hover"));
            behavior.setOption("accept", Options.asString(".recorditem, .fileitem"));
        }

        @Override
        public JQueryBehavior newWidgetBehavior(String selector) {
            return new DroppableBehavior(selector, this) {
                private static final long serialVersionUID = 1L;

                @Override
                protected JQueryAjaxBehavior newOnDropAjaxBehavior(IJQueryAjaxAware source) {
                    return new OnDropAjaxBehavior(source) {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public CharSequence getCallbackFunctionBody(CallbackParameter... parameters) {
                            String dialogId = UUID.randomUUID().toString();

                            String statement = "var $drop = $(this);";
                            statement += "$('body').append('<div id=" + dialogId + ">" + getString("713")
                                    + "</div>');";
                            statement += "$( '#" + dialogId + "' ).dialog({ title: '" + getString("80")
                                    + "', dialogClass: 'no-close', buttons: [";
                            statement += "    { text: '" + getString("54")
                                    + "', click: function() { $drop.append(ui.draggable); $(this).dialog('close'); "
                                    + super.getCallbackFunctionBody(parameters) + " } },";
                            statement += "    { text: '" + getString("25")
                                    + "', click: function() { $( this ).dialog('close'); } } ";
                            statement += "],";
                            statement += "close: function(event, ui) { $(this).dialog('destroy').remove(); }";
                            statement += "});";

                            return statement;
                        }
                    };
                }
            };
        }

        @Override
        public void onDrop(AjaxRequestTarget target, Component component) {
            Object o = component.getDefaultModelObject();
            if (o instanceof FileItem) {
                delete((FileItem) o, target);
            }
        }
    };
    add(trashToolbar);
    trashToolbar.add(getUpload("upload"));
    trashToolbar.add(new WebMarkupContainer("create").add(new AjaxEventBehavior("click") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            addFolder.open(target);
        }
    }));
    trashToolbar.add(new WebMarkupContainer("refresh").add(new AjaxEventBehavior("click") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            update(target);
        }
    }));
    trashToolbar.add(new ConfirmableAjaxBorder("trash", getString("80"), getString("713")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            FileItem f = selected.getObject();
            if (f != null && f.getId() != null) {
                super.onEvent(target);
            }
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            delete(selected.getObject(), target);
        }
    });

    add(trees.add(tree).setOutputMarkupId(true));
    updateSizes();
    add(sizes.add(new Label("homeSize", homeSize), new Label("publicSize", publicSize))
            .setOutputMarkupId(true));
    add(errorsDialog);
}

From source file:org.apache.openmeetings.web.common.tree.FolderPanel.java

License:Apache License

public FolderPanel(String id, final IModel<? extends FileItem> model, final FileTreePanel treePanel) {
    super(id, model);
    FileItem r = model.getObject();/*from   w  w  w . j  a  va2 s  .  c  o  m*/
    drop = r.getType() == Type.Folder ? new Droppable<FileItem>("drop", Model.of(r)) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onConfigure(JQueryBehavior behavior) {
            super.onConfigure(behavior);
            behavior.setOption("hoverClass", Options.asString("ui-state-hover"));
            behavior.setOption("accept", Options
                    .asString(getDefaultModelObject() instanceof Recording ? ".recorditem" : ".fileitem"));
        }

        @Override
        public void onDrop(AjaxRequestTarget target, Component component) {
            Object o = component.getDefaultModelObject();
            if (o instanceof FileItem) {
                FileItem p = (FileItem) drop.getDefaultModelObject();
                FileItem f = (FileItem) o;
                Long pid = p.getId();
                //FIXME parent should not be moved to child !!!!!!!
                if (pid != null && pid.equals(f.getId())) {
                    return;
                }
                f.setParentId(pid);
                f.setOwnerId(p.getOwnerId());
                f.setRoomId(p.getRoomId());
                if (f instanceof Recording) {
                    Recording r = (Recording) f;
                    r.setGroupId(((Recording) p).getGroupId());
                    getBean(RecordingDao.class).update(r);
                } else {
                    getBean(FileExplorerItemDao.class).update((FileExplorerItem) f);
                }
                treePanel.updateNode(target, p);
                treePanel.updateNode(target, f);
            }
            target.add(treePanel.trees);
        }
    } : new WebMarkupContainer("drop");
    if (r.getId() == null) {
        drag = new WebMarkupContainer("drag");
    } else {
        drag = new Draggable<FileItem>("drag", Model.of(r)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onConfigure(JQueryBehavior behavior) {
                super.onConfigure(behavior);
                behavior.setOption("revert", "treeRevert");
                behavior.setOption("cursor", Options.asString("move"));
                behavior.setOption("helper", "'clone'");
            }
        }.setContainment(treePanel.getContainment());
        drag.add(AttributeAppender.append("class", r instanceof Recording ? "recorditem" : "fileitem"));
    }
    drag.add(r.getId() == null ? new Label("name", r.getName())
            : new AjaxEditableLabel<String>("name", Model.of(model.getObject().getName())) {
                private static final long serialVersionUID = 1L;

                @Override
                protected String getLabelAjaxEvent() {
                    return "dblClick";
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target) {
                    super.onSubmit(target);
                    FileItem fi = model.getObject();
                    fi.setName(getEditor().getModelObject());
                    if (fi instanceof Recording) {
                        getBean(RecordingDao.class).update((Recording) fi);
                    } else {
                        getBean(FileExplorerItemDao.class).update((FileExplorerItem) fi);
                    }
                }

                @Override
                public void onEdit(AjaxRequestTarget target) {
                    super.onEdit(target);
                }
            });
    add(drop.add(drag).setOutputMarkupId(true));
}

From source file:org.apache.openmeetings.web.room.RoomPanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();
    //let's refresh user in client
    cm.update(getClient().updateUser(userDao));
    Component accessDenied = new WebMarkupContainer(ACCESS_DENIED_ID).setVisible(false);

    room.add(AttributeModifier.append(ATTR_CLASS, r.getType().name()));
    room.add(menu = new RoomMenuPanel("menu", this));
    room.add(AttributeModifier.append("data-room-id", r.getId()));
    if (interview) {
        room.add(new WebMarkupContainer("wb-area").add(wb));
    } else {/*from  www .ja  v a2  s . c  om*/
        Droppable<BaseFileItem> wbArea = new Droppable<BaseFileItem>("wb-area") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onConfigure(JQueryBehavior behavior) {
                super.onConfigure(behavior);
                behavior.setOption("hoverClass", Options.asString("ui-state-hover"));
                behavior.setOption("accept", Options.asString(".recorditem, .fileitem, .readonlyitem"));
            }

            @Override
            public void onDrop(AjaxRequestTarget target, Component component) {
                Object o = component.getDefaultModelObject();
                if (wb.isVisible() && o instanceof BaseFileItem) {
                    BaseFileItem f = (BaseFileItem) o;
                    if (sidebar.getFilesPanel().isSelected(f)) {
                        for (Entry<String, BaseFileItem> e : sidebar.getFilesPanel().getSelected().entrySet()) {
                            wb.sendFileToWb(e.getValue(), false);
                        }
                    } else {
                        wb.sendFileToWb(f, false);
                    }
                }
            }
        };
        room.add(wbArea.add(wb));
    }
    room.add(roomEnter);
    room.add(sidebar = new RoomSidebar("sidebar", this));
    add(roomClosed = new RedirectMessageDialog("room-closed", "1098", r.isClosed(), r.getRedirectURL()));
    if (r.isClosed()) {
        room.setVisible(false);
    } else if (cm.listByRoom(r.getId()).size() >= r.getCapacity()) {
        accessDenied = new ExpiredMessageDialog(ACCESS_DENIED_ID, getString("99"), menu);
        room.setVisible(false);
    } else if (r.getId().equals(WebSession.get().getRoomId())) {
        // secureHash/invitationHash, already checked
    } else {
        boolean allowed = false;
        String deniedMessage = null;
        if (r.isAppointment()) {
            Appointment a = apptDao.getByRoom(r.getId());
            if (a != null && !a.isDeleted()) {
                boolean isOwner = a.getOwner().getId().equals(getUserId());
                allowed = isOwner;
                log.debug("appointed room, isOwner ? {}", isOwner);
                if (!allowed) {
                    for (MeetingMember mm : a.getMeetingMembers()) {
                        if (getUserId().equals(mm.getUser().getId())) {
                            allowed = true;
                            break;
                        }
                    }
                }
                if (allowed) {
                    Calendar c = WebSession.getCalendar();
                    if (isOwner || c.getTime().after(a.getStart()) && c.getTime().before(a.getEnd())) {
                        eventDetail = new EventDetailDialog(EVENT_DETAILS_ID, a);
                    } else {
                        allowed = false;
                        deniedMessage = String.format("%s %s - %s", getString("error.hash.period"),
                                getDateFormat().format(a.getStart()), getDateFormat().format(a.getEnd()));
                    }
                }
            }
        } else {
            allowed = r.getIspublic() || (r.getOwnerId() != null && r.getOwnerId().equals(getUserId()));
            log.debug("public ? " + r.getIspublic() + ", ownedId ? " + r.getOwnerId() + " " + allowed);
            if (!allowed) {
                User u = getClient().getUser();
                for (RoomGroup ro : r.getGroups()) {
                    for (GroupUser ou : u.getGroupUsers()) {
                        if (ro.getGroup().getId().equals(ou.getGroup().getId())) {
                            allowed = true;
                            break;
                        }
                    }
                    if (allowed) {
                        break;
                    }
                }
            }
        }
        if (!allowed) {
            if (deniedMessage == null) {
                deniedMessage = getString("1599");
            }
            accessDenied = new ExpiredMessageDialog(ACCESS_DENIED_ID, deniedMessage, menu);
            room.setVisible(false);
        }
    }
    waitForModerator = new MessageDialog("wait-for-moderator", getString("204"), getString("696"),
            DialogButtons.OK, DialogIcon.LIGHT) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
            // no-op
        }
    };
    waitApplyModeration = new MessageDialog("wait-apply-moderation", getString("204"),
            getString(r.isModerated() ? "641" : "498"), DialogButtons.OK, DialogIcon.LIGHT) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
            // no-op
        }
    };
    add(room, accessDenied, eventDetail, waitForModerator, waitApplyModeration);
    if (r.isWaitForRecording()) {
        add(new MessageDialog("wait-for-recording", getString("1316"), getString("1315"), DialogButtons.OK,
                DialogIcon.LIGHT) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onConfigure(JQueryBehavior behavior) {
                super.onConfigure(behavior);
                behavior.setOption("autoOpen", true);
                behavior.setOption("resizable", false);
            }

            @Override
            public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
                //no-op
            }
        });
    } else {
        add(new WebMarkupContainer("wait-for-recording").setVisible(false));
    }
    if (room.isVisible()) {
        add(new NicknameDialog("nickname", this));
        add(download);
        add(new BaseWebSocketBehavior("media"));
    } else {
        add(new WebMarkupContainer("nickname").setVisible(false));
    }
    add(clientKicked = new MessageDialog("client-kicked", getString("797"), getString("606"), DialogButtons.OK,
            DialogIcon.ERROR) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
            menu.exit(handler);
        }
    });
}

From source file:org.apache.syncope.fit.console.BulkActionITCase.java

License:Apache License

private void userStatusBulkAction(final int index, final String resourceName) {
    // suspend //from w  w  w .j ava 2s  . c o  m
    TESTER.clickLink("body:realmsLI:realms");
    TESTER.clickLink("body:content:body:container:content:tabbedPanel:tabs-container:tabs:1:link");

    Component component = findComponentByProp("username",
            CONTAINER + ":searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable", "rossini");
    assertNotNull(component);

    TESTER.clickLink(component.getPageRelativePath() + ":cells:6:cell:panelEnable:enableLink");

    TESTER.assertComponent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "firstLevelContainer:first:container:content:searchContainer:resultTable:tablePanel:groupForm:"
            + "checkgroup:dataTable", WebMarkupContainer.class);

    component = findComponentByProp("resourceName",
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:firstLevelContainer:first:container:"
                    + "content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
            resourceName);

    component = TESTER
            .getComponentFromLastRenderedPage(component.getPageRelativePath() + ":cells:1:cell:check");
    assertEquals(Status.ACTIVE, StatusBean.class.cast(component.getDefaultModelObject()).getStatus());
    assertEquals(resourceName, StatusBean.class.cast(component.getDefaultModelObject()).getResourceName());

    FormTester formTester = TESTER
            .newFormTester(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:firstLevelContainer:"
                    + "first:container:content:searchContainer:resultTable:tablePanel:groupForm");
    assertNotNull(formTester);

    formTester.select("checkgroup", index);

    TESTER.executeAjaxEvent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "firstLevelContainer:first:container:content:searchContainer:resultTable:tablePanel:bulkActionLink",
            Constants.ON_CLICK);

    TESTER.assertComponent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "secondLevelContainer:second:container", WebMarkupContainer.class);

    TESTER.executeAjaxEvent(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:"
                    + "status:secondLevelContainer:second:container:actions:panelSuspend:suspendLink",
            Constants.ON_CLICK);

    TESTER.assertInfoMessages("Operation executed successfully");
    TESTER.cleanupFeedbackMessages();

    TESTER.assertLabel(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
                    + "secondLevelContainer:second:container:selectedObjects:body:rows:1:cells:3:cell",
            "SUCCESS");

    TESTER.executeAjaxEvent(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:secondLevelContainer:back",
            Constants.ON_CLICK);

    component = findComponentByProp("resourceName",
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:firstLevelContainer:first:container:"
                    + "content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
            resourceName);

    component = TESTER
            .getComponentFromLastRenderedPage(component.getPageRelativePath() + ":cells:1:cell:check");
    assertEquals(Status.SUSPENDED, StatusBean.class.cast(component.getDefaultModelObject()).getStatus());
    assertEquals(resourceName, StatusBean.class.cast(component.getDefaultModelObject()).getResourceName());

    // re-activate
    TESTER.clickLink("body:realmsLI:realms");
    TESTER.clickLink("body:content:body:container:content:tabbedPanel:tabs-container:tabs:1:link");

    component = findComponentByProp("username",
            CONTAINER + ":searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable", "rossini");
    assertNotNull(component);

    TESTER.clickLink(component.getPageRelativePath() + ":cells:6:cell:panelEnable:enableLink");

    TESTER.assertComponent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "firstLevelContainer:first:container:content:searchContainer:resultTable:tablePanel:groupForm:"
            + "checkgroup:dataTable", WebMarkupContainer.class);

    formTester = TESTER
            .newFormTester(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:firstLevelContainer:"
                    + "first:container:content:searchContainer:resultTable:tablePanel:groupForm");
    assertNotNull(formTester);

    formTester.select("checkgroup", index);

    TESTER.executeAjaxEvent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "firstLevelContainer:first:container:content:searchContainer:resultTable:tablePanel:bulkActionLink",
            Constants.ON_CLICK);

    TESTER.assertComponent(TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
            + "secondLevelContainer:second:container", WebMarkupContainer.class);

    TESTER.executeAjaxEvent(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:"
                    + "status:secondLevelContainer:second:container:actions:panelReactivate:reactivateLink",
            Constants.ON_CLICK);

    TESTER.assertInfoMessages("Operation executed successfully");
    TESTER.cleanupFeedbackMessages();

    TESTER.assertLabel(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:"
                    + "secondLevelContainer:second:container:selectedObjects:body:rows:1:cells:3:cell",
            "SUCCESS");

    TESTER.executeAjaxEvent(
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:secondLevelContainer:back",
            Constants.ON_CLICK);

    component = findComponentByProp("resourceName",
            TAB_PANEL + "outerObjectsRepeater:1:outer:form:content:status:firstLevelContainer:first:container:"
                    + "content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable",
            resourceName);

    component = TESTER
            .getComponentFromLastRenderedPage(component.getPageRelativePath() + ":cells:1:cell:check");
    assertEquals(Status.ACTIVE, StatusBean.class.cast(component.getDefaultModelObject()).getStatus());
    assertEquals(resourceName, StatusBean.class.cast(component.getDefaultModelObject()).getResourceName());

    TESTER.executeAjaxEvent(TAB_PANEL + "outerObjectsRepeater:1:outer:dialog:footer:buttons:0:button",
            Constants.ON_CLICK);
}

From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java

License:Open Source License

protected void onContextMenu(Component item, AjaxRequestTarget target) {
    ActionableItemTreeNode node = (ActionableItemTreeNode) item.getDefaultModelObject();

    // check at least one action is enabled
    Set<ItemAction> actions = node.getUserObject().getContextMenuActions();
    for (ItemAction action : actions) {
        if (action.isEnabled()) {
            showContextMenu(item, node, target);
            return;
        }// w ww  . jav  a 2 s.c om
    }
}