List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel
AbstractReadOnlyModel
From source file:eu.uqasar.web.pages.qmodel.QModelImportPage.java
License:Apache License
public QModelImportPage(PageParameters parameters) { super(parameters); logger.info("QModelImportPage::QModelImportPage start"); final Form<?> form = new Form<Void>("form") { /**//from ww w . java 2 s. c o m * */ private static final long serialVersionUID = 4949407424211758709L; @Override protected void onSubmit() { logger.info("QModelImportPage::onSubmit starts"); errorMessage = ""; try { FileUpload upload = file.getFileUpload(); if (upload == null) { errorMessage = "qmodel.empty.file.error"; logger.info("QModelImportPage::onSubmit no file uploaded"); } else { logger.info("QModelImportPage::onSubmit some file uploaded"); if (upload.getSize() > Bytes.kilobytes(MAX_SIZE).bytes()) { errorMessage = "qmodel.max.file.error"; logger.info("QModelImportPage::onSubmit MAX_SIZE size" + upload.getSize()); } else { logger.info("QModelImportPage::onSubmit file name " + upload.getClientFileName() + " File-Size: " + Bytes.bytes(upload.getSize()).toString() + "content-type " + upload.getContentType()); user = UQasar.getSession().getLoggedInUser(); if (user.getCompany() != null) { company = companyService.getById(user.getCompany().getId()); } if (upload.getContentType() != null && upload.getContentType().equals(XML_CONTENT)) { //parsing qm = parse(upload, true); } else if (upload.getContentType() != null && (upload.getContentType().equals(JSON_CONTENT) || upload.getContentType().equals(OCT_CONTENT))) { //json candidate qm = parse(upload, false); } else { //file not valid errorMessage = "qmodel.type.file.error"; } } } if (qm != null) { qm.setUpdateDate(DateTime.now().toDate()); if (qm.getCompanyId() != 0) { qm.setCompany(companyService.getById(qm.getCompanyId())); } else { if (company != null) { qm.setCompany(company); qm.setCompanyId(company.getId()); } } qm = (QModel) qmodelService.create(qm); } } catch (uQasarException ex) { if (ex.getMessage().contains("nodeKey")) { errorMessage = "qmodel.key.unique"; } } catch (JsonProcessingException ex) { logger.info("JsonProcessingException----------------------------------------"); if (ex.getMessage().contains("expecting comma to separate ARRAY entries")) { errorMessage = "qmodel.json.parse.error"; } else if (ex.getMessage().contains("Unexpected character")) { errorMessage = "qmodel.json.char.error"; } else if (ex.getMessage().contains("Can not construct instance")) { errorMessage = "qmodel.json.enum.error"; } else { logger.info("JsonProcessingException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } } catch (JAXBException ex) { logger.info("JAXBException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } catch (Exception ex) { logger.info("IOException----------------------------"); errorMessage = "qmodel.import.importError"; } finally { PageParameters parameters = new PageParameters(); if (null != errorMessage && !errorMessage.equals("")) { logger.info("Attaching error message"); parameters.add(QModelImportPage.LEVEL_PARAM, FeedbackMessage.ERROR); parameters.add(QModelImportPage.MESSAGE_PARAM, getLocalizer().getString(errorMessage, this)); setResponsePage(QModelImportPage.class, parameters); } else { logger.info("qmodel successfully created: redirection"); //qmodel successfully created: redirection parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.SUCCESS); parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("treenode.imported.message", this)); parameters.add("qmodel-key", qm.getNodeKey()); parameters.add("name", qm.getName()); setResponsePage(QModelViewPage.class, parameters); } } } }; // create the file upload field file = new FileUploadField("file"); form.addOrReplace(file); form.add(new Label("max", new AbstractReadOnlyModel<String>() { /** * */ private static final long serialVersionUID = 3532428309651830468L; @Override public String getObject() { return (Bytes.kilobytes(MAX_SIZE)).toString(); } })); // add progress bar form.add(new UploadProgressBar("progress", form, file)); ServletContext context = ((WebApplication) getApplication()).getServletContext(); // Download xml example File filexml = new File(context.getRealPath("/assets/files/qmodel.xml")); DownloadLink xmlLink = new DownloadLink("xmlLink", filexml); form.add(xmlLink); // Download json example File filejson = new File(context.getRealPath("/assets/files/qmodel.json")); DownloadLink jsonLink = new DownloadLink("jsonLink", filejson); form.add(jsonLink); add(form); logger.info("QModelImportPage::QModelImportPage ends"); }
From source file:eu.uqasar.web.pages.tree.metric.panels.MetricEditPanel.java
License:Apache License
public MetricEditPanel(String id, final IModel<Metric> model, boolean isNew) { super(id, model); MetricSource metricSource = null;//from w w w.j a v a 2 s.c om List<String> metricTypesUsed = null; System.out.println(model.getObject().getProject().getAdapterSettings().toString()); // Iterate the adapter settings for the project for (AdapterSettings settings : model.getObject().getProject().getAdapterSettings()) { metricSource = settings.getMetricSource(); if (metricSource.equals(MetricSource.IssueTracker)) { metricTypesUsed = UQasarUtil.getJiraMetricNames(); } else if (metricSource.equals(MetricSource.StaticAnalysis)) { metricTypesUsed = UQasarUtil.getSonarMetricNames(); setAdapterProjectName(settings.getAdapterProject()); } else if (metricSource.equals(MetricSource.TestingFramework)) { metricTypesUsed = UQasarUtil.getTestLinkMetricNames(); setPlanName(settings.getAdapterProject()); } else if (metricSource.equals(MetricSource.CubeAnalysis)) { metricTypesUsed = UQasarUtil.getCubesMetricNames(); } else if (metricSource.equals(MetricSource.ContinuousIntegration)) { metricTypesUsed = UQasarUtil.getJenkinsMetricNames(); } else { metricTypesUsed = new ArrayList<>(); } metricsMap.put(metricSource, metricTypesUsed); } // Add the option for manual data metricsMap.put(MetricSource.Manual, null); // Metric source choices IModel<List<? extends MetricSource>> metricSourceChoices = new AbstractReadOnlyModel<List<? extends MetricSource>>() { private static final long serialVersionUID = 2610709400336511400L; @Override public List<MetricSource> getObject() { logger.info(metricsMap.keySet()); return new ArrayList<>(metricsMap.keySet()); } }; // Metric type choices IModel<List<? extends String>> metricTypeChoices = new AbstractReadOnlyModel<List<? extends String>>() { private static final long serialVersionUID = 785545686808048810L; @Override public List<String> getObject() { List<String> metricTypes = metricsMap.get(model.getObject().getMetricSource()); if (metricTypes == null) { metricTypes = Collections.emptyList(); } return metricTypes; } }; form = new Form<Metric>("form", model) { private static final long serialVersionUID = 6993544095735400633L; @Override protected void onSubmit() { // If manual metrics source // if (getModelObject().getMetricSource().equals(MetricSource.Manual)) { // float value = 0; // if (valueField.getValue() != null) // value = Float.valueOf(valueField.getValue()); // getModelObject().setValue(value); // } Metric met = model.getObject(); // Update the tree on save UQasarUtil.updateTreeWithParticularNode(getModelObject().getProject(), met); // Set last updated getModelObject().setLastUpdated(new Date()); //If "create copy" check is selected if (chkCreateCopy.getModelObject()) { Metric metric = new Metric(met); (met.getParent()).addChild(metric); TreeNode parent = treeNodeService.update(met.getParent()); Iterator children = parent.getChildren().iterator(); boolean found = false; TreeNode qmn = null; while (children.hasNext() && !found) { qmn = (TreeNode) children.next(); if (qmn.equals(metric)) { found = true; } } // Update the tree on save UQasarUtil.updateTreeWithParticularNode(getModelObject().getProject(), met); PageParameters params = new PageParameters(); params.add("id", qmn.getId()); params.add("isNew", true); setResponsePage(MetricEditPage.class, params); } else { PageParameters parameters = BasePage.appendSuccessMessage( MetricViewPage.forMetric(getModelObject()), new StringResourceModel("treenode.saved.message", this, getModel())); setResponsePage(MetricViewPage.class, parameters); } } }; form.add(new TextField<>("name", new PropertyModel<>(model, "name")) .add(new AttributeAppender("maxlength", 255))); form.add(new DropDownChoice<>("purpose", new PropertyModel<Purpose>(model, "indicatorPurpose"), Arrays.asList(Purpose.values()))); form.add(new DropDownChoice<>("lcStage", new PropertyModel<LifeCycleStage>(model, "lifeCycleStage"), Arrays.asList(LifeCycleStage.values()))); form.add(new TextField<>("unit", new PropertyModel<>(model, "unit"))); final DropDownChoice<MetricSource> metricSources = new DropDownChoice<>("metricSources", new PropertyModel<MetricSource>(model, "metricSource"), metricSourceChoices); form.add(metricSources); final DropDownChoice<String> metricTypes = new DropDownChoice<>("metricTypes", new PropertyModel<String>(model, "metricType"), metricTypeChoices); metricTypes.setOutputMarkupId(true); form.add(metricTypes); // Metric value valueField = new TextField<>("metricValue", new PropertyModel<>(model, "value")); switchValueField(metricSources.getModelObject()); valueField.setOutputMarkupId(true); form.add(valueField).add(new AttributeAppender("maxlength", 255)); metricSources.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -8410045826567595007L; @Override protected void onUpdate(AjaxRequestTarget target) { target.add(metricTypes); target.add(valueField); switchValueField(metricSources.getModelObject()); } }); metricTypes.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 8702053900619896141L; @Override protected void onUpdate(AjaxRequestTarget target) { target.add(metricTypes); target.add(valueField); } }); // Threshold indicator form.add(new ThresholdEditor<>("thresholdEditor", model)); form.add(new TextField<>("targetValue", new PropertyModel<>(model, "targetValue"))); form.add(new TextField<>("weight", new PropertyModel<>(model, "weight"))); // Weight indicator shows data of weight consumed and available form.add(new WeightIndicator<>("totalWeight", model)); form.add(description = new TextArea<>("description", new PropertyModel<String>(model, "description"))); description.add(tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get())); form.add(new AjaxCheckBox("toggle.richtext", richEnabledModel) { private static final long serialVersionUID = 6814340728713542784L; @Override protected void onUpdate(AjaxRequestTarget target) { if (getModelObject()) { description.add(tinyMceBehavior); } else { description.remove(tinyMceBehavior); tinyMceBehavior = new TinyMceBehavior(DefaultTinyMCESettings.get()); } target.add(MetricEditPanel.this); } }); if (isNew) { Button cancel = new Button("cancel") { private static final long serialVersionUID = 1892636210626847636L; public void onSubmit() { QualityIndicator parent = treeNodeService .getQualityIndicator(model.getObject().getParent().getId()); treeNodeService.removeTreeNode(model.getObject().getId()); setResponsePage(QualityIndicatorViewPage.class, QualityIndicatorViewPage.forQualityIndicator(parent)); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); } else { form.add(new BootstrapBookmarkablePageLink<>("cancel", MetricViewPage.class, MetricViewPage.forMetric(model.getObject()), de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons.Type.Default) .setLabel(new StringResourceModel("button.cancel", this, null))); } //Create additional metric with predefined values chkCreateCopy = new CheckBox("checkboxCopy", Model.of(Boolean.FALSE)); form.add(chkCreateCopy); form.add(new Label("checkboxCopyLabel", new StringResourceModel("label.metric.checkboxCopy", this, null))); form.add(new Button("save", new StringResourceModel("button.save", this, null))); add(form); setOutputMarkupId(true); }
From source file:eu.uqasar.web.pages.tree.projects.ProjectImportPage.java
License:Apache License
public ProjectImportPage(PageParameters parameters) { super(parameters); upload = new FileUploadField("file"); final Form<?> form = new Form<Void>("form") { private static final long serialVersionUID = -8541751079487127243L; @Override/*from ww w. java 2 s .c om*/ protected void onSubmit() { Project p = null; try { FileUpload file = upload.getFileUpload(); if (file == null) { logger.info("File upload failed"); error = true; } else { if (file.getSize() > Bytes.kilobytes(MAX_SIZE).bytes()) { logger.info("File is too big"); error = true; } else { String content = file.getContentType(); if (content != null) { logger.info("Parser called"); p = parseProject(file, content); p = (Project) treeNodeService.create(p); // set company to qmodel user = UQasar.getSession().getLoggedInUser(); if (user != null && user.getCompany() != null) { p.setCompany(user.getCompany()); } } else { logger.info("Upload file is invalid"); error = true; } } } } catch (uQasarException ex) { if (ex.getMessage().contains("nodeKey")) { error = true; logger.info("duplicated nodeKey"); errorMessage = "import.key.unique"; } } catch (Exception ex) { error = true; logger.error(ex.getMessage(), ex); } finally { PageParameters parameters = new PageParameters(); if (error) { parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.ERROR); if (errorMessage != null && errorMessage.contains("key")) { parameters.add(QModelImportPage.MESSAGE_PARAM, getLocalizer().getString(errorMessage, this)); } else { parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("import.importError", this)); } setResponsePage(ProjectImportPage.class, parameters); } else { parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.SUCCESS); parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("import.importMessage", this)); // TODO what if p == null? parameters.add("project-key", p != null ? p.getNodeKey() : "?"); setResponsePage(ProjectViewPage.class, parameters); } } } }; form.add(upload); form.setMaxSize(Bytes.kilobytes(MAX_SIZE)); form.add(new Label("max", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 3532428309651830468L; @Override public String getObject() { return form.getMaxSize().toString(); } })); form.add(new UploadProgressBar("progress", form, upload)); form.add(new Button("uploadButton", new StringResourceModel("upload.button", this, null))); add(form); }
From source file:fiftyfive.wicket.model.CountMessageModel.java
License:Apache License
/** * Constructs a CountMessageModel that will choose the appropriate * localized string from a properties file. * /* w ww . j a va 2 s . c o m*/ * @param messageKey The key that will be consulted in the properties file. * The key will have ".zero", ".one" or ".many" appended * to it depending on the value of the {@code count}. * @param component The Wicket component that will be used for finding * the properties file. Usually this is the page or panel * where you plan to use the model. * @param count The number that will be used in the message. This will * be used to substitute any <code>${count}</code> expressions * in the message. */ public CountMessageModel(String messageKey, Component component, IModel<? extends Number> count) { super(); Args.notNull(messageKey, "messageKey"); Args.notNull(component, "component"); Args.notNull(count, "count"); this.component = component; this.countModel = count; this.stringModel = new StringResourceModel(messageKey + "${resourceSuffix}", component, new AbstractReadOnlyModel<CountMessageModel>() { public CountMessageModel getObject() { return CountMessageModel.this; } }); }
From source file:gr.abiss.calipso.wicket.yui.YuiCalendar.java
License:Open Source License
public YuiCalendar(String id, IModel model, boolean required) { super(id, null); add(new Behavior() { public void renderHead(Component component, IHeaderResponse response) { response.renderJavaScriptReference("resources/yui/yahoo/yahoo-min.js", "yui-yahoo"); response.renderJavaScriptReference("resources/yui/event/event-min.js", "yui-event"); response.renderJavaScriptReference("resources/yui/dom/dom-min.js", "yui-dom"); response.renderJavaScriptReference("resources/yui/calendar/calendar-min.js", "yui-calendar"); response.renderJavaScriptReference("resources/yui/calendar/calendar-utils.js", "yui-calendar-utils"); response.renderCSSReference("resources/yui/container/assets/calendar.css"); }//from w w w. j a va 2 s.c o m }); dateField = new TextField("field", model, Date.class) { @Override public IConverter getConverter(Class clazz) { return new AbstractConverter() { // private DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); private DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); public Object convertToObject(String s, Locale locale) { if (s == null || s.trim().length() == 0) { value = null; dateValue = null; return null; } try { value = s; dateValue = df.parse(s); return dateValue; } catch (Exception e) { value = null; throw new ConversionException(e); } } protected Class getTargetType() { return Date.class; } @Override public String convertToString(Object o, Locale locale) { Date d = (Date) o; return df.format(d); } }; } @Override public IModel getLabel() { return YuiCalendar.this.getLabel(); } }; dateField.setOutputMarkupId(true); dateField.setRequired(required); dateField.add(new ErrorHighlighter()); add(dateField); final WebMarkupContainer button = new WebMarkupContainer("button"); button.setOutputMarkupId(true); button.add(new AttributeModifier("onclick", true, new AbstractReadOnlyModel() { public Object getObject() { String js = "showCalendar(" + getCalendarId() + ", '" + getInputId() + "');"; logger.info("YuiCalendar button onclick js: " + js); return js; } })); add(button); container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); add(container); }
From source file:info.jtrac.wicket.ExcelImportColumnPage.java
License:Apache License
public ExcelImportColumnPage(final ExcelImportPage previous, final int index) { add(new FeedbackPanel("feedback")); space = previous.getSpace();/* www. j a v a 2 s . c o m*/ excelFile = previous.getExcelFile(); this.index = index; column = excelFile.getColumns().get(index).getClone(); columnCells = excelFile.getColumnCellsCloned(index); final Map<Name, String> labelsMap = BasePage.getLocalizedLabels(this); Form form = new Form("form"); add(form); DropDownChoice columnChoice = new DropDownChoice("column"); columnChoice.setChoices(new AbstractReadOnlyModel() { @Override public Object getObject() { // avoid lazy init problem Space s = getJtrac().loadSpace(space.getId()); List<ColumnHeading> list = ColumnHeading.getColumnHeadings(s); list.remove(new ColumnHeading(Name.ID)); list.remove(new ColumnHeading(Name.SPACE)); return list; } }); columnChoice.setChoiceRenderer(new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { ColumnHeading ch = (ColumnHeading) o; if (ch.isField()) { return ch.getLabel(); } return labelsMap.get(ch.getName()); } @Override public String getIdValue(Object o, int i) { ColumnHeading ch = (ColumnHeading) o; return ch.getNameText(); } }); columnChoice.setModel(new PropertyModel(column, "columnHeading")); columnChoice.setNullValid(true); form.add(columnChoice); Button previewButton = new Button("preview") { @Override public void onSubmit() { if (column.getColumnHeading() == null) { return; } } }; form.add(previewButton); form.add(new Link("cancel") { @Override public void onClick() { setResponsePage(previous); } }); final WebMarkupContainer columnCellsContainer = new WebMarkupContainer("columnCells") { @Override public boolean isVisible() { return column.getColumnHeading() != null; } }; form.add(columnCellsContainer); final WebMarkupContainer distinctCellsContainer = new WebMarkupContainer("distinctCells") { @Override public boolean isVisible() { ColumnHeading ch = column.getColumnHeading(); return ch != null && ch.isDropDownType(); } }; columnCellsContainer.add(new Label("header", new PropertyModel(column, "label"))); columnCellsContainer.add(new ReadOnlyRefreshingView<Cell>("rows") { @Override public List<Cell> getObjectList() { return columnCells; } @Override protected void populateItem(Item item) { if (item.getIndex() % 2 == 1) { item.add(CLASS_ALT); } item.add(new Label("index", item.getIndex() + 1 + "")); Cell cell = (Cell) item.getModelObject(); Label label = new Label("cell", new PropertyModel(cell, "valueAsString")); label.setEscapeModelStrings(false); if (!cell.isValid(column.getColumnHeading())) { label.add(CLASS_ERROR_BACK); } item.add(label); if (mappedDisplayValues != null && distinctCellsContainer.isVisible() && cell.getKey() != null) { String mapped = mappedDisplayValues.get(cell.getKey()); item.add(new Label("mapped", mapped)); } else { item.add(new WebMarkupContainer("mapped")); } } }); form.add(distinctCellsContainer); distinctCellsContainer.add(new DistinctCellsView("rows")); Button updateButton = new Button("update") { @Override public void onSubmit() { if (distinctCellsContainer.isVisible()) { for (Cell cell : columnCells) { IModel model = mappedKeys.get(cell.getValueAsString()); Object o = model.getObject(); cell.setKey(o); } } } @Override public boolean isVisible() { return distinctCellsContainer.isVisible(); } }; form.add(updateButton); Button submitButton = new Button("submit") { @Override public void onSubmit() { ColumnHeading ch = column.getColumnHeading(); for (Cell cell : columnCells) { if (!cell.isValid(ch)) { error(localize("excel_view.error.invalidValue")); return; } } if (ch.isField()) { column.setLabel(ch.getLabel()); } else { column.setLabel(labelsMap.get(column.getColumnHeading().getName())); } excelFile.getColumns().set(index, column); if (distinctCellsContainer.isVisible()) { for (Cell cell : columnCells) { cell.setValue(mappedDisplayValues.get(cell.getKey())); } excelFile.setColumnCells(index, columnCells); } setResponsePage(previous); } @Override public boolean isVisible() { return columnCellsContainer.isVisible(); } }; form.add(submitButton); }
From source file:info.jtrac.wicket.ExcelImportPage.java
License:Apache License
public ExcelImportPage() { add(new FeedbackPanel("feedback")); final FileUploadField fileUploadField = new FileUploadField("file"); Form uploadForm = new Form("uploadForm") { @Override//from w ww.ja v a 2s . c o m public void onSubmit() { if (fileUploadField.getFileUpload() == null) { return; } InputStream is = null; try { is = fileUploadField.getFileUpload().getInputStream(); excelFile = new ExcelFile(is); } catch (Exception e) { error(localize("excel_upload.error.invalidFile")); return; } } @Override public boolean isVisible() { return excelFile == null; } }; add(uploadForm); uploadForm.add(fileUploadField); Form form = new Form("form") { @Override public void onSubmit() { if (action == 0) { error(localize("excel_view.error.noActionSelected")); return; } switch (action) { case 1: // delete if (!excelFile.isColumnSelected() && !excelFile.isRowSelected()) { error(localize("excel_view.error.noColumnOrRowSelected")); return; } excelFile.deleteSelectedRowsAndColumns(); break; case 2: // convert to date if (!excelFile.isColumnSelected()) { error(localize("excel_view.error.noColumnSelected")); return; } excelFile.convertSelectedColumnsToDate(); break; case 3: // concatenate if (excelFile.getSelectedColumns().size() < 2) { error(localize("excel_view.error.atLeastTwoColumns")); return; } excelFile.concatenateSelectedColumns(); break; case 4: // extract summary into new column if (!excelFile.isColumnSelected()) { error(localize("excel_view.error.noColumnSelected")); return; } excelFile.extractSummaryFromSelectedColumn(); break; case 5: // duplicate column if (!excelFile.isColumnSelected()) { error(localize("excel_view.error.noColumnSelected")); return; } excelFile.duplicateSelectedColumn(); break; case 6: // map column if (space == null) { error(localize("excel_view.error.noSpaceSelected")); return; } if (!excelFile.isColumnSelected()) { error(localize("excel_view.error.noColumnSelected")); return; } int colIndex = excelFile.getSelectedColumns().get(0); setResponsePage(new ExcelImportColumnPage(ExcelImportPage.this, colIndex)); break; case 7: // edit row if (!excelFile.isRowSelected()) { error(localize("excel_view.error.noRowSelected")); return; } int rowIndex = excelFile.getSelectedRows().get(0); setResponsePage(new ExcelImportRowPage(ExcelImportPage.this, rowIndex)); break; case 8: // import ! if (space == null) { error(localize("excel_view.error.noSpaceSelected")); return; } Map<Name, String> labelsMap = BasePage.getLocalizedLabels(ExcelImportPage.this); ColumnHeading duplicate = excelFile.getDuplicatedColumnHeadings(); if (duplicate != null) { error(localize("excel_view.error.duplicateMapping", labelsMap.get(duplicate.getName()))); return; } List<ColumnHeading> unMapped = excelFile.getUnMappedColumnHeadings(); if (unMapped.size() > 0) { for (ColumnHeading ch : unMapped) { error(localize("excel_view.error.notMapped", labelsMap.get(ch.getName()))); } return; } List<info.jtrac.domain.Item> items = excelFile.getAsItems(space); getJtrac().storeItems(items); info(localize("excel_view.importSuccess")); setResponsePage(new ExcelImportPage()); } action = 0; excelFile.clearSelected(); } @Override public boolean isVisible() { return excelFile != null; } }; add(form); form.add(new Label("selectedSpace", new AbstractReadOnlyModel() { @Override public Object getObject() { if (space == null) { return localize("excel_view.noSpaceSelected"); } return space.getName() + " [" + space.getPrefixCode() + "]"; } })); form.add(new Link("selectSpace") { @Override public void onClick() { setResponsePage(new ExcelImportSpacePage(ExcelImportPage.this)); } }); final Map<Integer, String> map = new LinkedHashMap<Integer, String>(); map.put(0, "excel_view.selectActionToPerform"); map.put(1, "excel_view.deleteSelected"); map.put(2, "excel_view.convertToDate"); map.put(3, "excel_view.concatenateFields"); map.put(4, "excel_view.extractFirstEighty"); map.put(5, "excel_view.duplicateColumn"); map.put(6, "excel_view.mapToField"); map.put(7, "excel_view.editRow"); map.put(8, "excel_view.import"); DropDownChoice actionChoice = new DropDownChoice("action", new ArrayList<Integer>(map.keySet())); actionChoice.setModel(new PropertyModel(this, "action")); actionChoice.setChoiceRenderer(new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { int i = (Integer) o; return localize(map.get(i)); } @Override public String getIdValue(Object o, int i) { return i + ""; } }); form.add(actionChoice); CheckGroup colsCheckGroup = new CheckGroup("colsCheckGroup", new PropertyModel(this, "excelFile.selectedColumns")); form.add(colsCheckGroup); colsCheckGroup.add(new ColumnCheckboxes("checks")); form.add(new ColumnHeadings("headings")); CheckGroup rowsCheckGroup = new CheckGroup("rowsCheckGroup", new PropertyModel(this, "excelFile.selectedRows")); form.add(rowsCheckGroup); rowsCheckGroup.add(new RowsListView("rows")); }
From source file:info.jtrac.wicket.IndividualHeadPanel.java
License:Apache License
/** * Constructor.//from w ww . j a v a 2 s . co m */ public IndividualHeadPanel() { super("individual"); final Map<String, String> configMap = getJtrac().loadAllConfig(); Image img = new Image("icon"); img.add(new AttributeModifier("src", true, new AbstractReadOnlyModel() { private static final long serialVersionUID = 1L; @Override public final Object getObject() { // based on some condition return the image source String url = configMap.get("jtrac.header.picture"); if (StringUtils.isBlank(url)) { String urlbase = StringUtils.defaultString(configMap.get("jtrac.url.base"), RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot()); return urlbase + "/resources/jtrac-logo.gif"; } else return url; } })); add(img); String message = configMap.get("jtrac.header.text"); if ((message == null) || ("".equals(message))) add(new Label("message", "JTrac - Open Source Issue Tracking System")); else if ((message != null) && ("no".equals(message))) add(new Label("message", "")); else add(new Label("message", message)); }
From source file:info.jtrac.wicket.ReadOnlyRefreshingView.java
License:Apache License
@Override protected Iterator<IModel> getItemModels() { List<T> list = getObjectList(); List<IModel> models = new ArrayList<IModel>(list.size()); for (final T o : list) { models.add(new AbstractReadOnlyModel() { public Object getObject() { return o; }//from w ww. j a va 2 s . c om }); } return models.iterator(); }
From source file:info.jtrac.wicket.yui.YuiCalendar.java
License:Apache License
public YuiCalendar(String id, IModel model, boolean required) { super(id, null); add(HeaderContributor.forJavaScript("resources/yui/yahoo/yahoo-min.js")); add(HeaderContributor.forJavaScript("resources/yui/event/event-min.js")); add(HeaderContributor.forJavaScript("resources/yui/dom/dom-min.js")); add(HeaderContributor.forJavaScript("resources/yui/calendar/calendar-min.js")); add(HeaderContributor.forJavaScript("resources/yui/calendar/calendar-utils.js")); add(HeaderContributor.forCss("resources/yui/calendar/assets/calendar.css")); dateField = new TextField("field", model, Date.class) { @Override// w w w . j ava 2 s . c o m public IConverter getConverter(@SuppressWarnings("rawtypes") Class clazz) { return new AbstractConverter() { private DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); @Override public Object convertToObject(String s, Locale locale) { if (s == null || s.trim().length() == 0) { return null; } try { return df.parse(s); } catch (Exception e) { throw new ConversionException(e); } } @Override protected Class<Date> getTargetType() { return Date.class; } @Override public String convertToString(Object o, Locale locale) { Date d = (Date) o; return df.format(d); } }; } @Override public IModel getLabel() { return YuiCalendar.this.getLabel(); } }; dateField.setOutputMarkupId(true); dateField.setRequired(required); dateField.add(new ErrorHighlighter()); add(dateField); final WebMarkupContainer button = new WebMarkupContainer("button"); button.setOutputMarkupId(true); button.add(new AttributeModifier("onclick", true, new AbstractReadOnlyModel() { @Override public Object getObject() { return "showCalendar(" + getCalendarId() + ", '" + getInputId() + "');"; } })); add(button); container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); add(container); }