Example usage for org.apache.wicket Component isVisible

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

Introduction

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

Prototype

public boolean isVisible() 

Source Link

Document

Gets whether this component and any children are visible.

Usage

From source file:com.gitblit.wicket.pages.RepositoriesPage.java

License:Apache License

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()) {
        String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit");
        String message = readMarkdown(messageSource, "login.mkd");
        Component repositoriesMessage = new Label("repositoriesMessage", message);
        add(repositoriesMessage.setEscapeModelStrings(false));
        add(new Label("repositoriesPanel"));
        return;/*  w  w  w.  j  a  v  a2 s  .c  o m*/
    }

    // Load the markdown welcome message
    String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit");
    String message = readMarkdown(messageSource, "welcome.mkd");
    Component repositoriesMessage = new Label("repositoriesMessage", message).setEscapeModelStrings(false)
            .setVisible(message.length() > 0);
    add(repositoriesMessage);

    // conditionally include personal repositories in this page
    List<RepositoryModel> repositories = getRepositories(params);
    if (!app().settings().getBoolean(Keys.web.includePersonalRepositories, true)) {
        Iterator<RepositoryModel> itr = repositories.iterator();
        while (itr.hasNext()) {
            RepositoryModel rm = itr.next();
            if (rm.isPersonalRepository()) {
                itr.remove();
            }
        }
    }

    RepositoriesPanel repositoriesPanel = new RepositoriesPanel("repositoriesPanel", showAdmin, true,
            repositories, true, getAccessRestrictions());
    // push the panel down if we are hiding the admin controls and the
    // welcome message
    if (!showAdmin && !repositoriesMessage.isVisible()) {
        WicketUtils.setCssStyle(repositoriesPanel, "padding-top:5px;");
    }
    add(repositoriesPanel);
}

From source file:com.googlecode.ounit.MainPage.java

License:Open Source License

public MainPage(PageParameters parameters) {
    super(parameters);
    log.debug("MainPage()");

    if (getOunitSession() == null)
        throw new RuntimeException("No model attached to the page");

    if (!getOunitSession().isPrepared()) {
        throw new RuntimeException("Main page requires a prepared session");
    }/*ww w . j  a v  a2 s  . c o  m*/

    WebMarkupContainer quizPanel = new WebMarkupContainer("questiondiv");
    mainForm.add(quizPanel);
    quizPanel
            .add(new QuizStateAttributeModifier(getOunitModel(), "class", "ou-question", "ou-closed-question"));

    final Component description = new HtmlFile("description");
    quizPanel.add(description);
    quizPanel.add(new AnchorLink("descriptionlink", description));

    final Component results = new HtmlFile("resultsFile");
    quizPanel.add(results);
    quizPanel.add(new WebMarkupContainer("resultscaption") {
        private static final long serialVersionUID = 1L;

        protected void onConfigure() {
            super.onConfigure();
            results.configure();
            setVisible(results.isVisible());
        };
    }.add(new AnchorLink("resultslink", results)));

    /*
     * Generate TextAreas first, because we need editor objects as anchors
     * for the links
     */
    ListView<ProjectTreeNode> lv = new ListView<ProjectTreeNode>("editors") {
        private static final long serialVersionUID = 1L;

        protected void populateItem(ListItem<ProjectTreeNode> item) {
            ProjectTreeNode node = item.getModelObject();
            node.setEditor(item);
            TextArea<ProjectTreeNode> ta = new TextArea<ProjectTreeNode>("editorarea",
                    new PropertyModel<ProjectTreeNode>(node, "fileContents"));
            ta.add(AttributeModifier.replace("title", node.getName()));
            ta.add(new QuizStateAttributeModifier(getOunitModel(), "readonly", null, "readonly"));
            item.add(ta);
            item.setOutputMarkupId(true);
        }
    };
    quizPanel.add(lv);
    lv.setReuseItems(true);
    /* Force ListView to populate itself RIGHT NOW so state-less forms can work */
    // FIXME: This is an internal function. Maybe implement some hack like this
    //        http://osdir.com/ml/users-wicket.apache.org/2009-02/msg00925.html
    lv.internalPrepareForRender(false);

    /*
     * Populate tab header links
     */
    quizPanel.add(new ListView<ProjectTreeNode>("editorcaptions") {
        private static final long serialVersionUID = 1L;

        protected void populateItem(ListItem<ProjectTreeNode> item) {
            ProjectTreeNode node = item.getModelObject();
            item.add(new AnchorLink("editorlink", node.getEditor(), node.getName()));
        }
    }.setReuseItems(true));

    final Component tree = new ExplorerTreePanel("tree");
    quizPanel.add(tree);
    quizPanel.add(new WebMarkupContainer("treecaption") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            tree.configure();
            setVisible(tree.isVisible());
        }
    });

    // FIXME: We shouldn't access it directly. Should use model or something
    quizPanel.add(new QuestionDownloadLink("download"));

    mainForm.add(new Button("compile") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(!getOunitSession().isClosed());
        }

        @Override
        public void onSubmit() {
            // FIXME: This is a hack that should go away as soon as sessions
            //        start working properly
            redirected = true;
            setResponsePage(MainPage.class);

            OunitSession sess = getOunitSession();

            // Check if student is out of attempts
            int attempt = sess.getAttempt();
            int maxAttempts = sess.getMaxAttempts();
            if (maxAttempts > 0) {
                if (attempt >= maxAttempts)
                    sess.setClosed(true);
                /*
                 * Skip build if out of attempts. This is a sanity check, it
                 * shouldn't happen under normal circumstances
                 */
                if (attempt > maxAttempts)
                    return;
            }
            sess.setAttempt(attempt + 1);

            boolean buildSuccessful = sess.build();

            int marks = sess.getMarks();
            if (marks == sess.getMaxMarks()) {
                // Max marks, grade NOW!
                sess.setClosed(true);
            }

            if (!buildSuccessful && !sess.isClosed()) {
                // Successful build, ask if student wants a partial grade         
                setResponsePage(ConfirmPage.class);
            }
        }
    });
    mainForm.add(new Label("attempt"));
    mainForm.add(new Label("maxAttempts") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            if (getOunitSession().isClosed()) {
                setVisible(false);
            } else {
                setVisible(getOunitSession().getMaxAttempts() > 0);
            }
        }
    });
}

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

License:Open Source License

private void updateHeader(Component columnHeader, Component columnIdentifier) {
    columnHeader.setVisible(columnIdentifier.isVisible());
    columnHeader.setEnabled(isEnabled());
    if (columnHeader instanceof MarkupContainer)
        enableChildrenInContainer((MarkupContainer) columnHeader, isEnabled());
}

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

License:Open Source License

private ArrayList<Component> getVisibleColummIdentifierComponents() {
    ArrayList<Component> colummIdentifierComponents = new ArrayList<Component>();
    Iterator<Component> columnComponentsIte = elementToColumnIdentifierComponent.values().iterator();
    Component c;
    while (columnComponentsIte.hasNext()) {
        c = columnComponentsIte.next();/*from   w  w  w.  java  2 s .  c  o  m*/
        if (c.isVisible())
            colummIdentifierComponents.add(c);
    }
    return colummIdentifierComponents;
}

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

License:Open Source License

/**
 * Distributes an amount of horizontal free space to some or the columns of the table.
 *
 * Can be called in two situations:/* www .  j a  v  a  2s . co  m*/
 *
 * 1. When the browser windows is resized.
 *
 * In this case the positive/negative extra space gets distributed to those columns that are
 * anchored left + right.
 *
 * 2. When a column is resized
 *
 * In this case the positive/negative extra space gets distributed to all other columns,
 * regardless of their anchoring.
 *
 * In both scenarios the extra space is distributed proportionally to the sizes of the
 * involved columns.
 */
private void distributeExtraSpace(int delta, int totalWidthToStretch, IPersist dontTouchThis,
        boolean onlyAnchoredColumns) {
    if (totalWidthToStretch == 0)
        return;

    int consumedDelta = 0;
    IRuntimeComponent lastStretched = null;
    for (IPersist element : elementToColumnIdentifierComponent.keySet()) {
        boolean distributeToThisColumn = true;
        if (dontTouchThis != null && element.equals(dontTouchThis))
            distributeToThisColumn = false;
        if (distributeToThisColumn && onlyAnchoredColumns) {
            if (element instanceof ISupportAnchors) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                if (((anchors & IAnchorConstants.EAST) == 0) || ((anchors & IAnchorConstants.WEST) == 0))
                    distributeToThisColumn = false;
            } else
                distributeToThisColumn = false;
        }

        if (distributeToThisColumn) {
            Component c = elementToColumnIdentifierComponent.get(element);
            if (c instanceof IScriptableProvider
                    && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent
                    && c.isVisible()) {
                IRuntimeComponent ic = (IRuntimeComponent) ((IScriptableProvider) c).getScriptObject();
                int thisDelta = delta * ic.getWidth() / totalWidthToStretch;
                consumedDelta += thisDelta;
                int newWidth = ic.getWidth() + thisDelta;

                int height = ic.getHeight();
                Iterator<Component> alreadyAddedComponents = cellToElement.keySet().iterator();
                if (alreadyAddedComponents.hasNext()) {
                    Component firstAddedComponent = alreadyAddedComponents.next();
                    if ((firstAddedComponent instanceof IComponent))
                        height = ((IComponent) firstAddedComponent).getSize().height;
                }
                ic.setSize(newWidth, height);

                lastStretched = ic;
            }
        }
    }
    // we can have some leftover due to rounding errors, just put it into the last stretched column.
    if ((delta - consumedDelta != 0) && (lastStretched != null)) {
        lastStretched.setSize(lastStretched.getWidth() + delta - consumedDelta, lastStretched.getHeight());
    }

    updateXLocationForColumns(getOrderedHeaders());
}

From source file:com.servoy.j2db.server.headlessclient.MainPage.java

License:Open Source License

@Override
protected void onAfterRender() {
    super.onAfterRender();

    mainFormSwitched = false;//from   w ww . j  av  a  2s.c om
    if (storeMinVersion) {
        minimumVersionNumber = getCurrentVersionNumber();
        storeMinVersion = false;
    }
    // make sure that all IProviderStylePropertyChanges are set to rendered on a full page render.
    visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {
        @SuppressWarnings("nls")
        public Object component(Component component) {
            if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) {
                if (Debug.tracing()) {
                    if (component.isVisible()) {
                        Debug.trace("Component " + component
                                + " is changed but is not rendered, deleted from template?");
                    } else {
                        Debug.trace("Component " + component
                                + " is changed but is not rendered because it is not visible");
                    }
                }
                ((IProviderStylePropertyChanges) component).getStylePropertyChanges().setRendered();
            }
            return component.isVisible() ? IVisitor.CONTINUE_TRAVERSAL
                    : IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        }
    });
}

From source file:de.javakaffee.kryoserializers.wicket.WicketTest.java

License:Apache License

@Test(enabled = true)
public void testFeedbackPanel() throws Exception {
    final FeedbackPanel markupContainer = new FeedbackPanel("foo");
    //markupContainer.info( "foo" );
    final Component child = markupContainer.get(0);
    child.isVisible();
    final byte[] serialized = serialize(_kryo, markupContainer);
    final MarkupContainer deserialized = deserialize(_kryo, serialized, markupContainer.getClass());

    final Component deserializedChild = deserialized.get(0);
    deserializedChild.isVisible();//ww w . j av  a  2  s.  co  m

    KryoTest.assertDeepEquals(deserialized, markupContainer);
}

From source file:dk.teachus.frontend.components.calendar.CalendarPanel.java

License:Apache License

public CalendarPanel(String id, IModel<DateMidnight> weekDateModel) {
    super(id, weekDateModel);

    /*//w  w w  .  j av  a2  s .c  om
     * Navigation
     */
    Link<DateMidnight> previousWeekLink = new Link<DateMidnight>("previousWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(getModelObject().minusWeeks(1));
        }
    };
    previousWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.previousWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(previousWeekLink);
    Link<DateMidnight> thisWeekLink = new Link<DateMidnight>("thisWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(new DateMidnight());
        }
    };
    thisWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.thisWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(thisWeekLink);
    Link<DateMidnight> nextWeekLink = new Link<DateMidnight>("nextWeek", weekDateModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setModelObject(getModelObject().plusWeeks(1));
        }
    };
    nextWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.nextWeek"))); //$NON-NLS-1$ //$NON-NLS-2$
    add(nextWeekLink);

    /*
     * Calendar
     */
    IModel<List<DateMidnight>> daysModel = new LoadableDetachableModel<List<DateMidnight>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<DateMidnight> load() {
            DateMidnight thisMonday = CalendarPanel.this.getModelObject()
                    .withDayOfWeek(DateTimeConstants.MONDAY);
            List<DateMidnight> days = new ArrayList<DateMidnight>();
            for (int i = 0; i < 7; i++) {
                days.add(thisMonday);
                thisMonday = thisMonday.plusDays(1);
            }
            return days;
        }
    };

    final IModel<List<LocalTime>> timesModel = new LoadableDetachableModel<List<LocalTime>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<LocalTime> load() {
            int minutesDivider = 30;
            LocalTime localTime = getCalendarStartTime();
            final List<LocalTime> times = new ArrayList<LocalTime>();
            for (int i = 0; i < calculateNumberOfCalendarHours() * (60 / minutesDivider); i++) {
                times.add(localTime);
                localTime = localTime.plusMinutes(minutesDivider);
            }

            return times;
        }
    };

    // Headers
    add(new ListView<DateMidnight>("headers", daysModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<DateMidnight> item) {
            item.add(new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return HEADER_FORMAT.withLocale(TeachUsSession.get().getLocale())
                            .print(item.getModelObject());
                }
            }).setRenderBodyOnly(true));
        }
    });

    // Body
    // Times
    add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<LocalTime> item) {
            Label label = new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    if (item.getModelObject().getMinuteOfHour() == 0) {
                        return TIME_FORMAT.withLocale(TeachUsSession.get().getLocale())
                                .print(item.getModelObject());
                    } else {
                        return null;
                    }
                }
            });
            item.add(label);

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

                @Override
                public String getObject() {
                    if (item.getModelObject().getMinuteOfHour() == 0) {
                        return "timehour"; //$NON-NLS-1$
                    } else {
                        return null;
                    }
                }
            };
            item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$
        }
    });

    // Days
    add(new ListView<DateMidnight>("days", daysModel) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<DateMidnight> dayItem) {
            // Times
            dayItem.add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(final ListItem<LocalTime> item) {
                    IModel<String> appendModel = new AbstractReadOnlyModel<String>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            if (item.getModelObject().getMinuteOfHour() == 0) {
                                return "daytimehour"; //$NON-NLS-1$
                            } else {
                                return null;
                            }
                        }
                    };
                    item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$
                }
            });

            /*
             * Entries
             */
            dayItem.add(new ListView<TimeSlot<T>>("timeSlots", getTimeSlotModel(dayItem.getModelObject())) { //$NON-NLS-1$
                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(final ListItem<TimeSlot<T>> timeSlotItem) {
                    timeSlotItem.setOutputMarkupId(true);

                    final LocalTime startTime = timeSlotItem.getModelObject().getStartTime();
                    final LocalTime endTime = timeSlotItem.getModelObject().getEndTime();
                    int dividerPixelHeight = 25;
                    double minutesPerDivider = calculateNumberOfCalendarHours() * 60
                            / timesModel.getObject().size();

                    // Calculate top/y (start time)
                    double minutesStart = startTime.getHourOfDay() * 60 + startTime.getMinuteOfHour();
                    minutesStart -= getCalendarStartTime().getHourOfDay() * 60
                            + getCalendarStartTime().getMinuteOfHour();
                    double pixelStart = minutesStart / minutesPerDivider;
                    long top = Math.round(pixelStart * dividerPixelHeight) - 1;

                    // Calculate height (end time)
                    final double minutesEnd = (endTime.getHourOfDay() * 60 + endTime.getMinuteOfHour())
                            - minutesStart - getCalendarStartTime().getHourOfDay() * 60
                            + getCalendarStartTime().getMinuteOfHour();
                    double pixelEnd = minutesEnd / minutesPerDivider;
                    long height = Math.round(pixelEnd * dividerPixelHeight) - 1;

                    timeSlotItem.add(AttributeModifier.replace("style", //$NON-NLS-1$
                            "left: 0; top: " + top + "px; height: " + height + "px;")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

                    // Time slot content
                    IModel<List<String>> timeSlotContentModel = new LoadableDetachableModel<List<String>>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected List<String> load() {
                            return getTimeSlotContent(dayItem.getModelObject(), timeSlotItem.getModelObject(),
                                    timeSlotItem);
                        }
                    };

                    timeSlotItem.add(new ListView<String>("timeSlotContent", timeSlotContentModel) {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void populateItem(ListItem<String> item) {
                            item.add(new Label("content", item.getModel()));
                            item.add(AttributeModifier.replace("title", item.getModel()));
                        }
                    });

                    // Details
                    final Component dayTimeLessonDetails = createTimeSlotDetailsComponent(
                            "dayTimeLessonDetails", timeSlotItem.getModelObject());
                    dayTimeLessonDetails.setOutputMarkupId(true);
                    timeSlotItem.add(dayTimeLessonDetails);
                    timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            if (dayTimeLessonDetails.isVisible()) {
                                return "popover-external";
                            }
                            return null;
                        }
                    }));
                    timeSlotItem.add(
                            AttributeModifier.replace("data-content-id", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
                                private static final long serialVersionUID = 1L;

                                @Override
                                public String getObject() {
                                    if (dayTimeLessonDetails.isVisible()) {
                                        return "#" + dayTimeLessonDetails.getMarkupId(); //$NON-NLS-1$
                                    } else {
                                        return null;
                                    }
                                }
                            }));
                }
            });
        }
    });
}

From source file:gr.interamerican.wicket.factories.LinkFactory.java

License:Open Source License

/**
 * Creates an AjaxLink that togles on/of the visibility of a component.
 * //from www  .j  av a 2s . c  o  m
 * The Component must have <code>outputMarkUpPlaceholderId = true</code>.
 * 
 * @param componentName
 *        Name of the panel who's visibility is toggled on/off.
 * @param <T>
 *        Type of link model object.          
 *        
 * @param container - O container that contains the component and the link.
 * 
 * @return Returns the link.  
 */

public static <T> AjaxLink<T> createTogleVisibleLink(final String componentName,
        final MarkupContainer container) {
    AjaxLink<T> refreshLink = new AjaxLink<T>(componentName + "Link") { //$NON-NLS-1$

        /**
         * serialize.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Component component = container.get(componentName);
            boolean newVisibility = !component.isVisible();
            component.setVisible(newVisibility);
            target.add(component);
        }
    };
    return refreshLink;

}

From source file:jp.go.nict.langrid.management.web.view.page.language.component.form.panel.AbstractLanguagePathPanel.java

License:Open Source License

public void switchVisible() {
    for (Component c : switchVisibleList) {
        c.setVisible(!c.isVisible());
    }
}