Example usage for org.apache.wicket.markup.html.form TextArea TextArea

List of usage examples for org.apache.wicket.markup.html.form TextArea TextArea

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form TextArea TextArea.

Prototype

public TextArea(final String id, final IModel<T> model) 

Source Link

Usage

From source file:blg.bhdrkn.wicket.twitter.TwitterPage.java

License:Apache License

private void addTweetForm() {
    tweetForm = new Form<Void>("tweetForm");
    tweetArea = new TextArea<String>("tweetArea", new PropertyModel<String>(this, "tweetModel"));
    tweetArea.setOutputMarkupId(true);//from   w w  w.j av  a 2  s  .  c  om
    tweetForm.add(tweetArea);
    tweetForm.add(new AjaxButton("updateStatus") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                twitter = new TwitterFactory().getInstance();
                twitter.setOAuthConsumer(SocialMedia.TWITTER_CONSUMER_KEY, SocialMedia.TWITTER_CONSUMER_SECRET);
                twitter.setOAuthAccessToken(token);
                twitter.updateStatus(tweetModel);
                target.appendJavaScript("alert('Status Updated: " + tweetModel + "');");
                tweetModel = "";
                target.add(tweetArea);
            } catch (TwitterException e) {
                logger.error("Error While Updating the Status");
                e.printStackTrace();
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            logger.error("Error Before Updating the Status");
        }
    });
    add(tweetForm);
}

From source file:com.alfredmuponda.lostandfound.pages.LostReportForm.java

public LostReportForm() {
    itemTypes = Arrays.asList("Wallet", "National ID", "Drivers Licence", "Passport");
    lf_items = new ArrayList();
    contactInfo = new ContactInformation();
    item = new Item();

    Form form = new Form("form");
    add(new HeaderPanel("headerpanel"));
    add(form);//from w ww.ja  va  2  s  .c o  m

    firstNameField = new TextField("firstname", new PropertyModel(contactInfo, "firstName"));
    surnameField = new TextField("surname", new PropertyModel(contactInfo, "surname"));
    addressField = new TextField("address", new PropertyModel(contactInfo, "address"));
    phoneNumberField = new TextField("phonenumber", new PropertyModel(contactInfo, "phoneNumber"));
    emailAddressField = new EmailTextField("emailaddress", new PropertyModel(contactInfo, "emailAddress"));

    dateField = new TextField("date", new PropertyModel(item, "dateLorF"));
    itemTypeField = new DropDownChoice("itemtype", new PropertyModel(item, "itemType"), itemTypes);
    itemIDField = new TextField("itemid", new PropertyModel(item, "itemID"));
    locationField = new TextArea("location", new PropertyModel(item, "location"));
    descriptionField = new TextArea("description", new PropertyModel(item, "description"));

    //Add validators for user input
    firstNameField.setRequired(true);
    surnameField.setRequired(true);
    addressField.setRequired(true);
    phoneNumberField.setRequired(true).add(new PhoneNumberValidator());
    dateField.setRequired(true);
    itemTypeField.setRequired(true);
    itemIDField.add(new ItemNumberValidator(itemTypeField));
    locationField.setRequired(true);
    descriptionField.setRequired(true);
    emailAddressField.add(EmailAddressValidator.getInstance());

    form.add(new FeedbackPanel("feedback"));

    form.add(firstNameField);
    form.add(surnameField);
    form.add(addressField);
    form.add(phoneNumberField);
    form.add(emailAddressField);
    form.add(dateField);
    form.add(itemTypeField);
    form.add(itemIDField);
    form.add(locationField);
    form.add(descriptionField);

    form.add(new Button("submit") {
        @Override
        public void onSubmit() {
            getInfoInForm();
            //JDBC persistence
            /*
            uuid = UUID.randomUUID().toString();
            db = new ReadWriteDatabase(contactInfo, lf_items);
            db.addItemData(uuid);
            lf_items.clear(); 
             */

            //HIBERNATE persistance*
            persist();
            lf_items.clear();

            clear();
        }
    });
    form.add(new Button("addItem") {
        @Override
        public void onSubmit() {
            getInfoInForm();
            check();
            partialClear();
        }
    });
    form.add(new Link("clear") {
        @Override
        public void onClick() {
            clear();
        }
    });
    form.add(new Link("cancel") {
        @Override
        public void onClick() {
            setResponsePage(HomePage.class);
        }
    });
    form.add(new Link("policereport") {
        @Override
        public void onClick() {
            PoliceReport report = new PoliceReport();
            report.generatePoliceReport(uuid);
            setResponsePage(HomePage.class);
        }
    });
}

From source file:com.axway.ats.testexplorer.pages.machines.MachinesPage.java

License:Apache License

public MachinesPage(PageParameters parameters) {

    super(parameters);

    machines = getMachines();/*  w w w .j av  a  2 s  .c  om*/

    Label noMachinesLabel = new Label("noMachinesLabel",
            "There are no machines in database '" + getTESession().getDbName() + "'");
    noMachinesLabel.setOutputMarkupId(true);
    Form<Object> machinesForm = getMachinesForm(noMachinesLabel);
    add(machinesForm);

    machineInfoDialog = new WebMarkupContainer("machineInfoDialog");
    machineInfoDialog.setVisible(false);
    machineInfoDialogTitle = new Label("machineInfoDialogTitle", "");
    machineInfoDialog.add(machineInfoDialogTitle);
    machineInfoText = new TextArea<String>("machineInformationText", new Model<String>(""));
    machineInfoDialog.add(machineInfoText);
    machineInfoDialog.add(getMachineInfoDialogSaveButton());
    machineInfoDialog.add(getMachineInfoDialogCancelButton());

    machineInfoDialogForm = new Form<Object>("machineInfoDialogForm");
    machineInfoDialogForm.setOutputMarkupId(true);
    machineInfoDialogForm.add(machineInfoDialog);

    add(machineInfoDialogForm);
}

From source file:com.axway.ats.testexplorer.pages.testcase.attachments.AttachmentsPanel.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public AttachmentsPanel(String id, final String testcaseId, final PageParameters parameters) {
    super(id);//w w  w  . ja  v a2  s.co  m

    form = new Form<Object>("form");
    buttonPanel = new WebMarkupContainer("buttonPanel");
    noButtonPanel = new WebMarkupContainer("noButtonPanel");
    fileContentContainer = new TextArea<String>("textFile", new Model<String>(""));
    imageContainer = new WebMarkupContainer("imageFile");
    fileContentInfo = new Label("fileContentInfo", new Model<String>(""));
    buttons = getAllAttachedFiles(testcaseId);

    form.add(fileContentContainer);
    form.add(imageContainer);
    form.add(fileContentInfo);
    form.add(buttonPanel);

    add(noButtonPanel);
    add(form);

    buttonPanel.setVisible(!(buttons == null));
    fileContentContainer.setVisible(false);
    imageContainer.setVisible(false);
    fileContentInfo.setVisible(false);
    noButtonPanel.setVisible(buttons == null);

    // if noButtonPanel is visible, do not show form and vice versa
    form.setVisible(!noButtonPanel.isVisible());

    noButtonPanel.add(new Label("description", noButtonPanelInfo));

    final ListView lv = new ListView("buttons", buttons) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem item) {

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }

            final String viewedFile = buttons.get(item.getIndex());

            final String name = getFileSimpleName(buttons.get(item.getIndex()));
            final Label buttonLabel = new Label("name", name);

            Label fileSize = new Label("fileSize", getFileSize(viewedFile));

            downloadFile = new DownloadLink("download", new File(" "), "");
            downloadFile.setModelObject(new File(viewedFile));
            downloadFile.setVisible(true);

            alink = new AjaxLink("alink", item.getModel()) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {

                    fileContentInfo.setVisible(true);
                    String fileContent = new String();
                    if (!isImage(viewedFile)) {
                        fileContentContainer.setVisible(true);
                        imageContainer.setVisible(false);
                        fileContent = getFileContent(viewedFile, name);
                        fileContentContainer.setModelObject(fileContent);
                    } else {

                        PageNavigation navigation = null;
                        try {
                            navigation = ((TestExplorerSession) Session.get()).getDbReadConnection()
                                    .getNavigationForTestcase(testcaseId, getTESession().getTimeOffset());
                        } catch (DatabaseAccessException e) {
                            LOG.error("Can't get runId, suiteId and dbname for testcase with id=" + testcaseId,
                                    e);
                        }

                        String runId = navigation.getRunId();
                        String suiteId = navigation.getSuiteId();
                        String dbname = TestExplorerUtils.extractPageParameter(parameters, "dbname");

                        fileContentInfo.setDefaultModelObject("Previewing '" + name + "' image");

                        final String url = "AttachmentsServlet?&runId=" + runId + "&suiteId=" + suiteId
                                + "&testcaseId=" + testcaseId + "&dbname=" + dbname + "&fileName=" + name;
                        imageContainer.add(new AttributeModifier("src", new Model<String>(url)));
                        imageContainer.setVisible(true);
                        fileContentContainer.setVisible(false);
                    }

                    // first setting all buttons with the same state
                    String reverseButtonsState = "var cusid_ele = document.getElementsByClassName('attachedButtons'); "
                            + "for (var i = 0; i < cusid_ele.length; ++i) { " + "var item = cusid_ele[i];  "
                            + "item.style.color= \"#000000\";" + "}";
                    // setting CSS style to the pressed button and its label
                    String pressClickedButton = "var span = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "span.style.backgroundPosition=\"left bottom\";"
                            + "span.style.padding=\"6px 0 4px 18px\";"
                            + "var button = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']/..\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "button.style.backgroundPosition=\"right bottom\";"
                            + "button.style.color=\"#000000\";" + "button.style.outline=\"medium none\";";

                    // I could not figure out how it works with wicket, so i did it with JS
                    target.appendJavaScript(reverseButtonsState);
                    target.appendJavaScript(pressClickedButton);

                    target.add(form);
                }
            };

            alink.add(buttonLabel);
            item.add(alink);
            item.add(downloadFile);
            item.add(fileSize);
        }
    };
    buttonPanel.add(lv);
}

From source file:com.axway.ats.testexplorer.pages.testcasesCopy.TestcasesCopyPage.java

License:Apache License

@Override
protected void addCopyDetailsComponents() {

    copyEntityTypes = ENTITY_TYPES.valueOf(copyEntitiesType);
    String[] copyEntitiesTokens = copyEntities.split("_");
    srcEntityIds = new int[copyEntitiesTokens.length];
    for (int i = 0; i < copyEntitiesTokens.length; i++) {
        srcEntityIds[i] = Integer.parseInt(copyEntitiesTokens[i]);
    }//from w  w  w.ja  v a  2  s .  c  o  m

    TextField<String> sourceHost = new TextField<String>("sourceHost", sourceHostModel);
    sourceHostModel.setObject(getTESession().getDbHost());
    form.add(sourceHost);

    TextField<String> sourceDbName = new TextField<String>("sourceDbName", sourceDbNameModel);
    sourceDbNameModel.setObject(getTESession().getDbName());
    form.add(sourceDbName);

    TextArea<String> sourceSelectionToCopy = new TextArea<String>("sourceSelectionToCopy",
            sourceSelectionToCopyModel);
    sourceSelectionToCopyModel.setObject(getCopySelectionInfo(copyEntityTypes));
    form.add(sourceSelectionToCopy);

    TextField<String> destinationRunId = new TextField<String>("destinationRunId", destinationRunIdModel);
    destinationRunIdModel.setObject("");
    form.add(destinationRunId);

    TextField<String> destinationHost = new TextField<String>("destinationHost", destinationHostModel);
    destinationHostModel.setObject(getTESession().getDbHost());
    form.add(destinationHost);

    TextField<String> destinationPort = new TextField<String>("destinationPort", destinationPortModel);
    destinationPortModel.setObject("");
    form.add(destinationPort);

    TextField<String> destinationDbName = new TextField<String>("destinationDbName", destinationDbNameModel);
    destinationDbNameModel.setObject(getTESession().getDbName());
    form.add(destinationDbName);

    RadioChoice<String> hostingType = new RadioChoice<String>("testcaseOverwriteOption",
            new PropertyModel<String>(this, "selectedEntityType"),
            Arrays.asList(TestcasesCopyUtility.OVERWRITE_TESTCASES_MSG_OVERWRITE,
                    TestcasesCopyUtility.OVERWRITE_TESTCASES_MSG_OVERWRITE_NOT_PASSED));
    form.add(hostingType);
}

From source file:com.cubeia.games.poker.admin.wicket.pages.tournaments.configuration.TournamentConfigurationPanel.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
public TournamentConfigurationPanel(String id, Form<?> form,
        PropertyModel<TournamentConfiguration> propertyModel, boolean sitAndGo) {
    super(id, propertyModel);
    this.model = propertyModel;
    add(new RequiredTextField<String>("name", new PropertyModel(model, "name")));
    add(new RequiredTextField<Integer>("seatsPerTable", new PropertyModel(model, "seatsPerTable")));
    DropDownChoice<TimingProfile> timing = new DropDownChoice<TimingProfile>("timingType", model("timingType"),
            adminDAO.getTimingProfiles(), renderer("name"));
    timing.setRequired(true);//from w w  w .  j  a  v a  2 s  . c  o  m
    add(timing);
    TextField<Integer> minPlayers = new TextField<Integer>("minPlayers",
            new PropertyModel(model, "minPlayers"));
    minPlayers.add(RangeValidator.minimum(2));
    add(minPlayers);
    TextField<Integer> maxPlayers = new TextField<Integer>("maxPlayers",
            new PropertyModel(model, "maxPlayers"));
    maxPlayers.add(RangeValidator.minimum(2));
    add(maxPlayers);
    add(new RequiredTextField<BigDecimal>("buyIn", new PropertyModel(model, "buyIn")));
    add(new RequiredTextField<BigDecimal>("fee", new PropertyModel(model, "fee")));
    add(new RequiredTextField<BigDecimal>("guaranteedPrizePool",
            new PropertyModel(model, "guaranteedPrizePool")));
    add(new CheckBox("payoutAsBonus", new PropertyModel(model, "payOutAsBonus")));
    add(new RequiredTextField<BigDecimal>("startingChips", new PropertyModel(model, "startingChips")));
    DropDownChoice<BetStrategyType> strategy = new DropDownChoice<BetStrategyType>("betStrategy",
            new PropertyModel(model, "betStrategy"), asList(BetStrategyType.values()), renderer("name"));
    strategy.setRequired(true);
    add(strategy);

    DropDownChoice<PokerVariant> variant = new DropDownChoice<PokerVariant>("variant",
            new PropertyModel(model, "variant"), asList(PokerVariant.values()), renderer("name"));
    variant.setRequired(true);
    add(variant);
    form.add(new TournamentPlayersValidator(minPlayers, maxPlayers));

    final List<OperatorDTO> operators = networkClient.getOperators();

    add(new ListMultipleChoice<Long>("operatorIds", model("operatorIds"), getOperatorIds(operators),
            new IChoiceRenderer<Long>() {

                @Override
                public Object getDisplayValue(Long id) {
                    return getOperatorName(operators, id);
                }

                @Override
                public String getIdValue(Long object, int index) {
                    return object.toString();
                }
            }));
    TextField<String> userRule = new TextField<String>("userRuleExpression",
            new PropertyModel(model, "userRuleExpression"));
    add(userRule);

    DropDownChoice<String> currency = new DropDownChoice<String>("currency", model("currency"),
            networkClient.getCurrencies(), new ChoiceRenderer<String>());
    currency.setRequired(true);
    add(currency);
    DropDownChoice<BlindsStructure> blindsStructure = new DropDownChoice<BlindsStructure>("blindsStructure",
            model("blindsStructure"), adminDAO.getBlindsStructures(), renderer("name"));
    blindsStructure.setRequired(true);
    add(blindsStructure);
    DropDownChoice<PayoutStructure> payoutStructure = new DropDownChoice<PayoutStructure>("payoutStructure",
            model("payoutStructure"), adminDAO.getPayoutStructures(), renderer("name"));
    payoutStructure.setRequired(true);
    add(payoutStructure);

    if (sitAndGo) {
        maxPlayers.setVisible(false);
    }

    TextArea<String> description = new TextArea<String>("description", new PropertyModel(model, "description"));
    description.add(StringValidator.maximumLength(1000));
    add(description);
}

From source file:com.doculibre.constellio.wicket.pages.SQLPage.java

License:Open Source License

public SQLPage() {
    super();//w w w.ja va  2s  .  c o  m
    ConstellioSession session = ConstellioSession.get();
    ConstellioUser user = session.getUser();
    boolean redirect;
    if (user == null) {
        redirect = true;
    } else if (user.isAdmin()) {
        redirect = false;
    } else {
        redirect = true;
        RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
        for (RecordCollection collection : collectionServices.list()) {
            if (user.hasCollaborationPermission(collection) || user.hasAdminPermission(collection)) {
                redirect = false;
                break;
            }
        }
    }
    if (redirect) {
        setResponsePage(getApplication().getHomePage());
    } else {
        form = new Form("form");
        feedbackPanel = new FeedbackPanel("feedback");
        textArea = new TextArea("query", queryModel);
        submitButton = new Button("submitButton") {
            @Override
            public void onSubmit() {
                String sql = (String) queryModel.getObject();
                if (StringUtils.isNotBlank(sql)) {
                    EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                    if (!entityManager.getTransaction().isActive()) {
                        entityManager.getTransaction().begin();
                    }
                    Query sqlQuery = entityManager.createNativeQuery(sql);
                    try {
                        int rowCount = sqlQuery.executeUpdate();
                        entityManager.getTransaction().commit();
                        info(rowCount + " " + getLocalizer().getString("affectedRows", this));
                    } catch (Exception e) {
                        String stack = ExceptionUtils.getFullStackTrace(e);
                        error(stack);
                    }
                }
            }
        };

        add(form);
        form.add(feedbackPanel);
        form.add(textArea);
        form.add(submitButton);
    }
}

From source file:com.doculibre.constellio.wicket.panels.admin.collection.AddEditCollectionPanel.java

License:Open Source License

public AddEditCollectionPanel(String id, RecordCollection collection) {
    super(id, false);
    this.collectionModel = new ReloadableEntityModel<RecordCollection>(collection);
    edit = collection.getId() != null;//w  ww.j a  v  a 2 s . com

    final Form form = getForm();
    form.setModel(new CompoundPropertyModel(collectionModel));
    form.add(new SetFocusBehavior(form));

    TextField nameField = new RequiredTextField("name");
    form.add(nameField);
    nameField.setEnabled(collection.getId() == null);
    nameField.setOutputMarkupId(true);
    nameField.add(new StringValidator.MaximumLengthValidator(50));
    nameField.add(new PatternValidator(ConstellioNameUtils.NAME_PATTERN));
    nameField.add(new DuplicateItemValidator() {
        @Override
        protected boolean isDuplicate(Object value) {
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            return collectionServices.get((String) value) != null;
        }
    });

    TextField openSearchURL = new TextField("openSearchURL");
    form.add(openSearchURL);

    final WebMarkupContainer titleContainer = new WebMarkupContainer("titleContainer");
    form.add(titleContainer);
    titleContainer.setOutputMarkupId(true);

    MultiLocaleComponentHolder titleHolder = new MultiLocaleComponentHolder("title", collectionModel,
            new PropertyModel(collectionModel, "locales")) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField titleLocaleField = new RequiredTextField("titleField", componentModel);
            item.add(titleLocaleField);
            titleLocaleField.setOutputMarkupId(true);
            titleLocaleField.add(new StringValidator.MaximumLengthValidator(255));
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    return collectionModel.getObject().getLocales().size() > 1;
                }
            });
        }
    };
    titleContainer.add(titleHolder);

    final WebMarkupContainer descriptionContainer = new WebMarkupContainer("descriptionContainer");
    form.add(descriptionContainer);
    descriptionContainer.setOutputMarkupId(true);

    MultiLocaleComponentHolder descriptionHolder = new MultiLocaleComponentHolder("description",
            collectionModel, new PropertyModel(collectionModel, "locales")) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextArea descriptionLocaleField = new TextArea("descriptionLocale", componentModel);
            item.add(descriptionLocaleField);
            descriptionLocaleField.setOutputMarkupId(true);
            item.add(descriptionLocaleField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    return collectionModel.getObject().getLocales().size() > 1;
                }
            });
        }
    };
    descriptionContainer.add(descriptionHolder);

    List<Locale> supportedLocales = ConstellioSpringUtils.getSupportedLocales();
    if (collection.getId() == null) {
        collection.setLocales(new HashSet<Locale>(supportedLocales));
    }

    CheckGroup localesCheckGroup = new CheckGroup("localesCheckGroup",
            new PropertyModel(collectionModel, "locales"));
    form.add(localesCheckGroup);
    localesCheckGroup.setOutputMarkupId(true);
    localesCheckGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(titleContainer);
            target.addComponent(descriptionContainer);
        }
    });

    final Map<Locale, Check> localeChecks = new HashMap<Locale, Check>();
    localesCheckGroup.add(new ListView("locales", supportedLocales) {
        @Override
        protected void populateItem(ListItem item) {
            final Locale locale = (Locale) item.getModelObject();
            Check localeCheck = localeChecks.get(locale);
            if (localeCheck == null) {
                localeCheck = new Check("localeCheck", new Model(locale));
                localeChecks.put(locale, localeCheck);
            }
            item.add(localeCheck);
            item.add(new LocaleNameLabel("localeName", locale));
        }
    });

    CheckBox publicCollectionCheck = new CheckBox("publicCollection");
    form.add(publicCollectionCheck);
}

From source file:com.doculibre.constellio.wicket.panels.admin.featuredLink.AddEditFeaturedLinkPanel.java

License:Open Source License

public AddEditFeaturedLinkPanel(String id, FeaturedLink featuredLink) {
    super(id, false);
    this.featuredLinkModel = new ReloadableEntityModel<FeaturedLink>(featuredLink);

    Form form = getForm();//w  ww  . j  a v a  2 s .  com
    form.setModel(new CompoundPropertyModel(featuredLinkModel));

    IModel localesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return collection.getLocales();
        }
    };
    MultiLocaleComponentHolder titleHolder = new MultiLocaleComponentHolder("linkTitle", "title",
            featuredLinkModel, localesModel) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField titleLocaleField = new RequiredTextField("titleLocale", componentModel);
            titleLocaleField.add(new StringValidator.MaximumLengthValidator(50));
            item.add(titleLocaleField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                            AdminCollectionPanel.class);
                    RecordCollection collection = collectionAdminPanel.getCollection();
                    return collection.getLocales().size() > 1;
                }
            });
        }
    };
    form.add(titleHolder);

    MultiLocaleComponentHolder descriptionHolder = new MultiLocaleComponentHolder("description",
            featuredLinkModel, localesModel) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextArea descriptionLocaleField = new TextArea("descriptionLocale", componentModel);
            //            descriptionLocaleField.add(new StringValidator.MaximumLengthValidator(50));
            item.add(descriptionLocaleField);

            TinyMCESettings tinyMCESettings = new TinyMCESettings(TinyMCESettings.Theme.advanced);
            tinyMCESettings.setToolbarLocation(TinyMCESettings.Location.top);
            descriptionLocaleField.add(new TinyMceBehavior(tinyMCESettings));

            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                            AdminCollectionPanel.class);
                    RecordCollection collection = collectionAdminPanel.getCollection();
                    return collection.getLocales().size() > 1;
                }
            });
        }
    };
    form.add(descriptionHolder);

    IModel keywordsModel = new Model() {
        @Override
        public Object getObject() {
            FeaturedLink featuredLink = featuredLinkModel.getObject();
            StringBuffer keywordsSB = new StringBuffer();
            for (Iterator<String> it = featuredLink.getKeywords().iterator(); it.hasNext();) {
                String keyword = it.next();
                keywordsSB.append(keyword);
                if (it.hasNext()) {
                    keywordsSB.append("\n");
                }
            }
            return keywordsSB.toString();
        }

        @Override
        public void setObject(Serializable object) {
            String keywordsText = (String) object;
            FeaturedLink featuredLink = featuredLinkModel.getObject();
            featuredLink.getKeywords().clear();
            if (keywordsText != null) {
                AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                        AdminCollectionPanel.class);
                RecordCollection collection = collectionAdminPanel.getCollection();

                StringTokenizer st = new StringTokenizer(keywordsText, "\n");
                while (st.hasMoreTokens()) {
                    String keyword = StringUtils.trim(st.nextToken());
                    String keywordAnalyzed = AnalyzerUtils.analyze(keyword, collection);
                    featuredLink.getKeywords().add(keyword);
                    featuredLink.getKeywordsAnalyzed().add(keywordAnalyzed);
                }
            }
        }
    };
    form.add(new TextArea("keywords", keywordsModel));
}

From source file:com.doculibre.constellio.wicket.panels.admin.stats.CollectionStatsPanel.java

License:Open Source License

public CollectionStatsPanel(String id, final String collectionName) {
    super(id);/*w ww . j  ava2 s.c  om*/

    endDate = new Date();
    startDate = DateUtils.addMonths(endDate, -1);

    Form form = new Form("form") {
        @Override
        protected void onSubmit() {
            statsPanel.replaceWith(statsPanel = new CollectionStatsReportPanel(statsPanel.getId(),
                    collectionName, statsType, startDate, endDate, rows, includeFederatedCollections));
        }
    };
    add(form);

    IModel queryExcludeRegexpsModel = new Model() {
        @Override
        public Object getObject() {
            String result;
            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = adminCollectionPanel.getCollection();
            CollectionStatsFilter statsFilter = collection.getStatsFilter();
            if (statsFilter != null) {
                StringBuffer sb = new StringBuffer();
                Set<String> existingRegexps = statsFilter.getQueryExcludeRegexps();
                for (String existingRegexp : existingRegexps) {
                    sb.append(existingRegexp);
                    sb.append("\n");
                }
                result = sb.toString();
            } else {
                result = null;
            }
            return result;
        }

        @Override
        public void setObject(Object object) {
            String queryExcludeRegexpsStr = (String) object;
            String[] newRegexpsArray = StringUtils.split(queryExcludeRegexpsStr, "\n");
            List<String> newRegexps = new ArrayList<String>();
            for (String newRegexp : newRegexpsArray) {
                newRegexps.add(newRegexp.trim());
            }

            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = adminCollectionPanel.getCollection();
            CollectionStatsFilter statsFilter = collection.getStatsFilter();
            if (statsFilter == null) {
                statsFilter = new CollectionStatsFilter();
                statsFilter.setRecordCollection(collection);
                collection.setStatsFilter(statsFilter);
            }

            Set<String> existingRegexps = statsFilter.getQueryExcludeRegexps();
            if (!CollectionUtils.isEqualCollection(existingRegexps, newRegexps)) {
                RecordCollectionServices collectionServices = ConstellioSpringUtils
                        .getRecordCollectionServices();
                EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                if (!entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().begin();
                }
                existingRegexps.clear();
                existingRegexps.addAll(newRegexps);
                collectionServices.makePersistent(collection, false);

                entityManager.getTransaction().commit();
            }
        }
    };

    form.add(new TextArea("queryExcludeRegexps", queryExcludeRegexpsModel));
    form.add(new DateTextField("startDate", new PropertyModel(this, "startDate"), "yyyy-MM-dd")
            .add(new DatePicker()));
    form.add(new DateTextField("endDate", new PropertyModel(this, "endDate"), "yyyy-MM-dd")
            .add(new DatePicker()));
    form.add(new TextField("rows", new PropertyModel(this, "rows"), Integer.class));
    form.add(new CheckBox("includeFederatedCollections",
            new PropertyModel(this, "includeFederatedCollections")) {
        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            if (visible) {
                AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                        AdminCollectionPanel.class);
                RecordCollection collection = adminCollectionPanel.getCollection();
                visible = collection.isFederationOwner();
            }
            return visible ? visible : false;
        }
    });

    form.add(new DropDownChoice("statsType", new PropertyModel(this, "statsType"), StatsConstants.ALL_STATS,
            new StringResourceChoiceRenderer("statsType", this)));

    form.add(new Label("title", new PropertyModel(this, "statsType")));
    statsPanel = new AjaxLazyLoadPanel("statsPanel") {
        @Override
        public Component getLazyLoadComponent(String markupId) {
            return new CollectionStatsReportPanel(markupId, collectionName, statsType, startDate, endDate, rows,
                    includeFederatedCollections);
        }
    };
    form.add(statsPanel);
}