List of usage examples for org.apache.wicket.markup.html.list ListView ListView
public ListView(final String id, final List<T> list)
From source file:gr.abiss.calipso.wicket.AssetViewPanel.java
License:Open Source License
public void init(IBreadCrumbModel breadCrumbModel, final Asset asset) { //logger.debug("Loaded asset: "+asset); add(new IconPanel("assetIcon", new PropertyModel(asset.getAssetType(), "id"), "assetTypes")); add(new Label("assetType", localize(asset.getAssetType().getNameTranslationResourceKey()))); add(new Label("inventoryCode", asset.getInventoryCode())); add(new Link("printToPdf") { public void onClick() { // TODO: pickup template from TB if it exists for this asset type getRequestCycle().scheduleRequestHandlerAfterCurrent(new PdfRequestTarget( PdfUtils.getPdf(getCalipso(), asset, AssetViewPanel.this), asset.getInventoryCode())); }// w w w. j av a 2 s .c om }); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); if (asset.getSupportStartDate() != null) { add(new Label("supportStartDate", dateFormat.format(asset.getSupportStartDate()))); } else { add(new Label("supportStartDate", "")); } if (asset.getSupportEndDate() != null) { add(new Label("supportEndDate", dateFormat.format(asset.getSupportStartDate()))); } else { add(new Label("supportEndDate", "")); } // TODO: this is insane but otherwise we cannot retrieve values from // the map using the keys obtained from it! equals/hashCode looks ok, need to investigate // see also AssetFormPagePanel#updateCustomAttributeValue @SuppressWarnings("serial") ListView listView = new ListView("attributeValuesList", KeyValuePair.fromMap(asset.getCustomAttributes())) { final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt"); @SuppressWarnings("unchecked") @Override protected void populateItem(ListItem listItem) { if (listItem.getIndex() % 2 == 1) { listItem.add(sam); } KeyValuePair entry = (KeyValuePair) listItem.getModelObject(); AssetTypeCustomAttribute customAttr = (AssetTypeCustomAttribute) entry.getKey(); String sValue = (String) entry.getValue(); Label customAttributeLabel = new Label("customAttribute", localize(customAttr.getNameTranslationResourceKey())); listItem.add(customAttributeLabel); String value = new String(localize("asset.customAttributeNoValue")); if (sValue != null && !sValue.isEmpty()) { value = sValue; } // this works for all componentViewLinks if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_SELECT) || customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_OPTIONS_TREE)) { Label customAttributeValueLabel; if (customAttr.getLookupValue() != null) { customAttributeValueLabel = (Label) new Label("customAttributeValue", customAttr.getLookupValue().getValue()); } else { customAttributeValueLabel = new Label("customAttributeValue"); } listItem.add(customAttributeValueLabel); } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_USER)) { UserViewLink userViewLink = new UserViewLink("customAttributeValue", getBreadCrumbModel(), customAttr.getUserValue()); listItem.add(userViewLink); } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_ORGANIZATION)) { // this works for all componentViewLinks OrganizationViewLink organizationViewLink = new OrganizationViewLink("customAttributeValue", getBreadCrumbModel(), customAttr.getOrganizationValue()); listItem.add(organizationViewLink); } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_ASSET)) { // this works for all componentViewLinks AssetViewLink assetViewLink = new AssetViewLink("customAttributeValue", getBreadCrumbModel(), customAttr.getAssetValue()); listItem.add(assetViewLink); } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_COUNTRY)) { Country country = customAttr.getCountryValue(); Label customAttributeValueLabel = (Label) new Label("customAttributeValue", country != null ? localize(country) : "").setEscapeModelStrings(false); listItem.add(customAttributeValueLabel); } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_TABULAR)) { Label customAttributeValueLabel = (Label) new Label("customAttributeValue", MultipleValuesTextField.toHtmlSafeTable(value)).setEscapeModelStrings(false); listItem.add(customAttributeValueLabel); } else { Label customAttributeValueLabel = (Label) new Label("customAttributeValue", value) .setEscapeModelStrings(false); listItem.add(customAttributeValueLabel); } // }// populateItem }; add(listView); }
From source file:gr.abiss.calipso.wicket.components.formfields.MultipleValuesTextField.java
License:Open Source License
/** * Read the hidden field value, i.e. the input thus far, then render it * appropriately in a table/*from w w w .ja v a 2s . c o m*/ * @param form */ @SuppressWarnings({ "unchecked", "serial" }) private void paintSubValuesTable(final Form form) { // show existing values table String currentValue = valuesField.getModelObject(); final List<String> originalValueRows = MultipleValuesTextField.getValueRows(currentValue); // record the line count, used for validation linesCount = originalValueRows.size(); if (!originalLinesCountSet) { originalLinesCount = linesCount; originalLinesCountSet = true; } // mark as empty if (linesCount == 0) { clearInput(); } final SimpleAttributeModifier cssTextAlignRight = new SimpleAttributeModifier("class", "left"); final FieldSummaryHelper helper = new FieldSummaryHelper(fieldConfig); form.addOrReplace(new ListView("row", originalValueRows) { @Override protected void populateItem(ListItem rowItem) { int rowIndex = rowItem.getIndex(); if (rowToEditIndex == rowIndex) { editableFragment = new EditableFragment("rowContent", getSubFieldConfigs(MultipleValuesTextField.this.fieldConfig), form, helper); rowItem.add(editableFragment.setRenderBodyOnly(true)); } else { rowItem.add(new ReadOnlyFragment("rowContent", "readOnlyFragment", form, originalValueRows, cssTextAlignRight, helper, rowItem).setRenderBodyOnly(true)); } } }); if (rowToEditIndex == -1) { // logger.info("adding editable fragment as heading"); editableFragment = new EditableFragment("editableRow", getSubFieldConfigs(MultipleValuesTextField.this.fieldConfig), form, helper); form.addOrReplace(editableFragment); } else { form.addOrReplace(new EmptyPanel("editableRow").setRenderBodyOnly(true)); } form.addOrReplace(new ListView<FieldConfig>("summary", fieldConfig != null ? fieldConfig.getSubFieldConfigs() : new ArrayList<FieldConfig>(0)) { @Override protected void populateItem(ListItem<FieldConfig> cellItem) { int fieldConfigIndex = cellItem.getIndex(); FieldConfig subConfig = fieldConfig.getSubFieldConfigs().get(fieldConfigIndex); String summary = helper.getCalculatedSummary(subConfig); if (StringUtils.isNotBlank(helper.getSummary(subConfig))) { summary = getLocalizer().getString(helper.getSummary(subConfig), MultipleValuesTextField.this) + ": " + summary; } cellItem.add(new Label("cellValue", summary)); if (subConfig.isNumberType()) { cellItem.add(cssTextAlignRight); } } }); }
From source file:gr.abiss.calipso.wicket.ConfigListPanel.java
License:Open Source License
public ConfigListPanel(String id, final IBreadCrumbModel breadCrumbModel, final String selectedParam) { super(id, breadCrumbModel); this.selectedParam = selectedParam; final Map<String, String> configMap = getCalipso().loadAllConfig(); List<String> params = new ArrayList(Config.getParams()); final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt"); add(new ListView("configs", params) { protected void populateItem(ListItem listItem) { final String param = (String) listItem.getModelObject(); final String value = configMap.get(param); if (param.equals(ConfigListPanel.this.selectedParam)) { listItem.add(new SimpleAttributeModifier("class", "selected")); } else if (listItem.getIndex() % 2 == 1) { listItem.add(sam);//from w w w . j a v a 2 s . com } listItem.add(new Label("param", param)); listItem.add(new Label("value", value)); listItem.add(new BreadCrumbLink("link", breadCrumbModel) { protected IBreadCrumbParticipant getParticipant(String componentId) { return new ConfigFormPanel(componentId, breadCrumbModel, param, value); } }); listItem.add(new Label("description", localize("config." + param))); } }); final CalipsoPropertiesEditor cpr = new CalipsoPropertiesEditor(); add(new ListView("configs_", new ArrayList(cpr.getParams())) { protected void populateItem(ListItem listItem) { final String param = (String) listItem.getModelObject(); final String value = cpr.getValue(param); if (param.equals(ConfigListPanel.this.selectedParam)) { listItem.add(new SimpleAttributeModifier("class", "selected")); } else if (listItem.getIndex() % 2 == 1) { listItem.add(sam); } listItem.add(new Label("param_", param)); listItem.add(new Label("value_", value)); listItem.add(new BreadCrumbLink("link_", breadCrumbModel) { private static final long serialVersionUID = 1L; protected IBreadCrumbParticipant getParticipant(String componentId) { return new ConfigFormPanel(componentId, breadCrumbModel, param, value, cpr); } }); listItem.add(new Label("description_", localize("config." + param))); } }); }
From source file:gr.abiss.calipso.wicket.customattrs.CustomAttributeOptionsPanel.java
License:Open Source License
@SuppressWarnings("unchecked") private void addComponents(CustomAttribute customAttribute, List<Language> languages, final Map<String, String> textAreaOptions) { // default value TextField<String> textField = new TextField<String>("defaultOption", new PropertyModel(customAttribute, "defaultStringValue")); textField.setLabel(new ResourceModel("space_field_form.defaultOption")); add(textField);/*from ww w. ja va 2 s . c om*/ add(new SimpleFormComponentLabel("defaultOptionLabel", textField)); // TODO: switch this to tabs per language // List optionTranslationTabs = new ArrayList(); // get the field's custom attribute or create one if needed add(new ListView("optionTranslations", languages) { @Override protected void populateItem(ListItem listItem) { // logger.debug("Building option translations for : "+fieldInternalName); Language language = (Language) listItem.getModelObject(); TextArea optionsTextArea = new TextArea("optionTranslationsList", new PropertyModel(textAreaOptions, "[" + language.getId() + "]")); //logger.info("optionsTextArea 1 model: "+optionsTextArea.getModel()+", object: "+ optionsTextArea.getModelObject()); optionsTextArea.setType(String.class); // name translations are required. optionsTextArea.setRequired(true); optionsTextArea.add(new ErrorHighlighter()); listItem.add(optionsTextArea); /* optionsTextArea = (TextArea) CustomAttributeOptionsPanel.this.model.bind( optionsTextArea, new StringBuffer("textAreaOptions[") .append(language.getId()).append("]") .toString()); */ //logger.info("optionsTextArea 2 model: "+optionsTextArea.getModel()+", object: "+ optionsTextArea.getModelObject()); // form label for name optionsTextArea.setLabel(new ResourceModel("language." + language.getId())); listItem.add(new SimpleFormComponentLabel("languageLabel", optionsTextArea)); } }.setReuseItems(true)); }
From source file:gr.abiss.calipso.wicket.CustomFieldsFormPanel.java
License:Open Source License
@SuppressWarnings("serial") private void addComponents(final CompoundPropertyModel model, final Metadata metadata, final List<Field> fields, final Map<String, FileUploadField> fileUploadFields) { //final AbstractItem item = (AbstractItem) model.getObject(); List<FieldGroup> fieldGroupsList = metadata.getFieldGroups(); @SuppressWarnings("unchecked") ListView fieldGroups = new ListView("fieldGroups", fieldGroupsList) { @Override// w w w . j av a 2 s .co m protected void populateItem(ListItem listItem) { FieldGroup fieldGroup = (FieldGroup) listItem.getModelObject(); listItem.add(new Label("fieldGroupLabel", fieldGroup.getName())); List<Field> groupFields = fieldGroup.getFields(); List<Field> editableGroupFields = new LinkedList<Field>(); if (CollectionUtils.isNotEmpty(groupFields)) { for (Field field : groupFields) { // is editable? if (fields.contains(field)) { editableGroupFields.add(field); } } } ListView listView = new ListView("fields", editableGroupFields) { @Override @SuppressWarnings("deprecation") protected void populateItem(ListItem listItem) { boolean preloadExistingValue = true; final Field field = (Field) listItem.getModelObject(); // preload custom attribute if (field.getCustomAttribute() == null) { field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(), field.getName().getText())); } // preload value? if (preloadExistingValue) { AbstractItem history = (AbstractItem) model.getObject(); history.setValue(field.getName(), item.getValue(field.getName())); } // return the value for the field (see abstract item getCustomValue method) Object fieldLastCustomValue = null; String i18nedFieldLabelResourceKey = item.getSpace() .getPropertyTranslationResourceKey(field.getName().getText()); if (item != null && !editMode) { if (field.getName().isFile()) { Set<Attachment> tmpAttachments = item.getAttachments(); if (tmpAttachments != null && tmpAttachments.size() > 0) { for (Attachment attachment : tmpAttachments) { if (field.getLabel() .equals(AttachmentUtils.getBaseName(attachment.getFileName()))) { fieldLastCustomValue = attachment.getFileName(); break; } } } } else { fieldLastCustomValue = item.getValue(field.getName()); } } // Decide whether the field is mandatory boolean valueRequired = false; //logger.info("fieldLastCustomValue for field " + field.getLabel() +": "+fieldLastCustomValue); if (field.getMask() == State.MASK_MANDATORY || (field.getMask() == State.MASK_MANDATORY_IF_EMPTY && (fieldLastCustomValue == null || StringUtils.isBlank(fieldLastCustomValue.toString())))) { valueRequired = true; // value required } // go over custom fields WebMarkupContainer labelContainer = new WebMarkupContainer("labelContainer"); listItem.add(labelContainer); SimpleFormComponentLabel label = null; if (field.getName().isDropDownType()) { String autoValue; final Map<String, String> options = field.getOptions(); if (field.getFieldType().equals(Field.FIELD_TYPE_DROPDOWN_HIERARCHICAL)) { Fragment f = new Fragment("field", "treeField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); ItemFieldCustomAttribute customAttribute = field.getCustomAttribute(); // if(customAttribute == null){ // customAttribute = getCalipso().loadCustomAttribute(getCurrentSpace(), field.getName().getText()); // field.setCustomAttribute(customAttribute); // } // preload existing value if (field.getCustomAttribute() != null && customAttribute.getLookupValue() == null && item.getCustomValue(field) != null) { logger.info("preloading custom attribute for field: " + field.getLabel()); customAttribute.setLookupValue(getCalipso().loadCustomAttributeLookupValue( NumberUtils.createLong(item.getCustomValue(field).toString()))); customAttribute.setAllowedLookupValues( getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute)); } else { logger.info( "SKIPPED preloading custom attribute for field: " + field.getLabel()); customAttribute.setAllowedLookupValues( getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute)); } TreeChoice choice = new TreeChoice("field", new PropertyModel<CustomAttributeLookupValue>(field, "customAttribute.lookupValue"), customAttribute.getAllowedLookupValues(), customAttribute); // TODO: temp, make configurable in space field form for 1520 int attrId = customAttribute.getId().intValue(); choice.setVisibleMenuLinks( attrId == 3 || attrId == 4 || attrId == 16 || attrId == 17); //choice.setType(Long.class); choice.setRequired(valueRequired); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); //border.add(new ErrorHighlighter(choice)); border.add(choice); //choice.setModel(model.bind(field.getName().getText())); //border.add(model.bind(choice, field.getName().getText())); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); } // get the type of component that will render the choices else if (field.getFieldType().equals(Field.FIELD_TYPE_AUTOSUGGEST)) { renderAutoSuggest(model, listItem, field, i18nedFieldLabelResourceKey, valueRequired, options); } else { // normal drop down label = renderDropDown(model, listItem, field, i18nedFieldLabelResourceKey, valueRequired, options); } } else if (field.getName().equals(Field.Name.ASSIGNABLE_SPACES)) { Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); List assignableSpaces = loadAssignableSpaces(field); final Map options = new LinkedHashMap(); // Replace value from space id to space description for // reasons of appearance. for (int i = 0; i < assignableSpaces.size(); i++) { Space space = (Space) assignableSpaces.get(i); if (!space.equals(getCurrentSpace())) { options.put(space.getId(), localize(space.getNameTranslationResourceKey())); } // if } // for final List keys = new ArrayList(options.keySet()); AssignableSpacesDropDownChoice choice = new AssignableSpacesDropDownChoice("field", keys, new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { return o; }; @Override public String getIdValue(Object o, int i) { return o.toString(); }; }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); choice.add(new Behavior() { @Override public void renderHead(Component component, IHeaderResponse response) { response.renderJavaScript(new JavaScripts().setAssignableSpacesId.asString(), "setAssignableSpacesId"); } }); choice.add(new AjaxFormComponentUpdatingBehavior("onChange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (statusChoice != null && !statusChoice.getDefaultModelObjectAsString().equals("") && !statusChoice.getDefaultModelObjectAsString().equals("-1")) { // if // (statusChoice.getValue().equals(String.valueOf(State.MOVE_TO_OTHER_SPACE))){ // assignedToChoice.setChoices(getAssignableSpaceUsers()); // assignedToChoice.setNullValid(false); // assignedToChoice.setVisible(true); // }//if } // if target.appendJavaScript("assignableSpacesId=" + "'" + assignableSpacesDropDownChoice.getMarkupId() + "';"); // This can happen at the creation of a new item // where makes no sense to be moved to other space if (assignedToChoice != null) { target.addComponent(assignedToChoice); } }// onUpdate @Override protected void onError(AjaxRequestTarget arg0, RuntimeException arg1) { // Do nothing. // It happens only if the choice be set to NULL by // the user. // The exception occurs because the model binds to // space id that is from (primitive) type // long and its value can not be set to NULL. } }); choice.setOutputMarkupId(true); assignableSpacesDropDownChoice = choice; if (itemViewFormPanel != null) { itemViewFormPanel.getItemViewForm() .setAssignableSpacesDropDownChoice(assignableSpacesDropDownChoice); } // if WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(choice)); // Set field name explicitly to avoid runtime error //border.add(model.bind(choice, field.getName() + ".id")); choice.setModel(model.bind(field.getName() + ".id")); border.add(choice); listItem.add(f.setRenderBodyOnly(true)); border.setVisible(!CustomFieldsFormPanel.this.editMode); label = new SimpleFormComponentLabel("label", choice); } else if (field.getName().getType() == 6) { // date picker Fragment fragment = new Fragment("field", "dateFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); if (item.getId() == 0 && item.getValue(field.getName()) == null && field.getDefaultValueExpression() != null && field.getDefaultValueExpression().equalsIgnoreCase("now")) { item.setValue(field.getName(), new Date()); } DateField calendar = new DateField("field", preloadExistingValue ? new PropertyModel(model.getObject(), field.getName().getText()) : new PropertyModel(model, field.getName().getText())) { @Override protected String getDateFormat() { // TODO Auto-generated method stub return metadata.getDateFormats().get(Metadata.DATE_FORMAT_SHORT); } }; calendar.setRequired(valueRequired); // i8n calendar.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); fragment.add(calendar); listItem.add(fragment.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", calendar); } // TODO: Creating new space item - users custom field else if (field.getName().isOrganization()) { // is organization // Get users list Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); Organization organization = (Organization) item.getValue(field.getName()); // logger.debug("Item organization field has value: "+organization); final List<Organization> allOrganizationsList = getCalipso().findAllOrganizations(); DropDownChoice organizationChoice = new DropDownChoice("field", allOrganizationsList, new IChoiceRenderer() { // user's choice renderer // display value user's name @Override public Object getDisplayValue(Object object) { return ((Organization) object).getName(); } @Override public String getIdValue(Object object, int index) { // id value user's id return index + ""; } }); organizationChoice.add(new ErrorHighlighter()); organizationChoice.setRequired(valueRequired); // i18n organizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(organizationChoice, field.getName().getText())); organizationChoice.setModel(model.bind(field.getName().getText())); f.add(organizationChoice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", organizationChoice); } else if (field.getName().isFile()) { // File addFileInputField(model, fileUploadFields, listItem, field, i18nedFieldLabelResourceKey, valueRequired); } // TODO: Creating new space item - organizations custom field else if (field.getName().isUser()) { // is user Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); // find organization id from field's options String strOrgId = field.getOptions().get("organizationId"); Long orgId = Long.valueOf(strOrgId); // load organization from database Organization selectedOrg = getCalipso().loadOrganization(orgId); // TODO: load all users from organization // add new list of selected organizations List<Organization> selectedOrganization = new ArrayList<Organization>(); // add selected organization selectedOrganization.add(selectedOrg); final List<User> usersFromOrganization = getCalipso() .findUsersInOrganizations(selectedOrganization); // TODO: dropdown of all organization DropDownChoice usersFromOrganizationChoice = new DropDownChoice("field", usersFromOrganization, new UserChoiceRenderer()); usersFromOrganizationChoice.setNullValid(false); usersFromOrganizationChoice.setRequired(valueRequired); // i18n usersFromOrganizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(usersFromOrganizationChoice, field.getName().getText())); usersFromOrganizationChoice.setModel(model.bind(field.getName().getText())); f.add(usersFromOrganizationChoice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", usersFromOrganizationChoice); } else if (field.getName().isCountry()) { // organization fragment holds a dropDown of countries final List<Country> allCountriesList = getCalipso().findAllCountries(); Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); listItem.add(f.setRenderBodyOnly(true)); DropDownChoice countryChoice = getCountriesDropDown("field", allCountriesList); countryChoice.add(new ErrorHighlighter()); countryChoice.setRequired(valueRequired); // i18n countryChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(countryChoice, field.getName().getText())); countryChoice.setModel(model.bind(field.getName().getText())); f.add(countryChoice); label = new SimpleFormComponentLabel("label", countryChoice); } else { if (logger.isDebugEnabled()) logger.debug("model.getObject(): " + model.getObject()); if (logger.isDebugEnabled()) logger.debug( "model.getObject().getClass(): " + model.getObject().getClass().getName()); if (logger.isDebugEnabled()) logger.debug("field.getName().getText(): " + field.getName().getText()); //if(logger.isDebugEnabled()) logger.debug("((Item)model.getObject()).getCusStr01(): "+((Item)model.getObject()).getCusStr01()); FormComponent textField; Fragment f; if (field.isMultivalue()) { f = new Fragment("field", "multipleValuesTextField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); if (logger.isDebugEnabled()) logger.debug("model.getObject(): " + model.getObject()); if (logger.isDebugEnabled()) logger.debug("field.getName().getText(): " + field.getName().getText()); textField = preloadExistingValue ? new MultipleValuesTextField("field", new PropertyModel(model.getObject(), field.getName().getText()), field.getXmlConfig()) : new MultipleValuesTextField("field", field.getXmlConfig()); } else if (field.getLineCount() == 1) { f = new Fragment("field", "textField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); textField = preloadExistingValue ? new TextField("field", new PropertyModel(model.getObject(), field.getName().getText())) : new TextField("field"); } else { f = new Fragment("field", "textareaField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); textField = preloadExistingValue ? new TextArea("field", new PropertyModel(model.getObject(), field.getName().getText())) { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("rows", field.getLineCount().toString()); } } : new TextArea("field") { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("rows", field.getLineCount().toString()); } }; } // any validations for this field? ValidationExpression validationExpression = getCalipso() .loadValidationExpression(field.getValidationExpressionId()); if (validationExpression != null) { textField.add(new ValidationExpressionValidator(validationExpression)); } // TODO: do we need these two? if (field.getName().getType() == 4) { textField.setType(Double.class); } else if (field.getName().isDecimalNumber()) { textField.add(new PositiveNumberValidator()); } textField.add(new ErrorHighlighter()); textField.setRequired(valueRequired); // i18n textField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); if (preloadExistingValue) { f.add(textField); } else { //f.add(model.bind(textField, field.getName().getText())); textField.setModel(model.bind(field.getName().getText())); f.add(textField); } // f.add(textField); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", textField); // styles FieldUtils.appendFieldStyles(field.getXmlConfig(), textField); } // add label labelContainer.add(label != null ? label : new Label("label", "")); if (field.getCustomAttribute() != null && StringUtils.isBlank(field.getCustomAttribute().getHtmlDescription())) { labelContainer.add(new SimpleAttributeModifier("class", "labelContainer")); } // mandatory? // mark as mandatory in the UI? labelContainer .add(new Label("star", valueRequired ? "* " : " ").setEscapeModelStrings(false)); } private SimpleFormComponentLabel renderAutoSuggest(final IModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final Map<String, String> options) { SimpleFormComponentLabel label = null; Fragment f = new Fragment("field", "autoCompleteFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); final List<String> autoKeys = new ArrayList<String>( options != null ? new ArrayList<String>(options.keySet()) : new ArrayList<String>()); // the autocomplet textField // TODO: fix to render values instead of integer AbstractAutoCompleteRenderer autoRenderer = new AbstractAutoCompleteRenderer() { @Override protected String getTextValue(Object object) { // TODO Auto-generated method stub return object.toString(); } @Override protected void renderChoice(Object object, Response response, String criteria) { response.write(object.toString()); } }; autoTextField = new AutoCompleteTextField("field", new PropertyModel(field, "customAttribute.lookupValue")) { // TODO: the list @Override protected Iterator<String> getChoices(String input) { if (Strings.isEmpty(input)) { List<String> emptyList = Collections.emptyList(); return emptyList.iterator(); } List<String> searchResults = new ArrayList<String>(); for (String s : options.values()) { if (s.startsWith(input)) { searchResults.add(s); } } return searchResults.iterator(); } }; autoTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { // TODO Auto-generated method stub List<String> searchResults = new ArrayList<String>(); for (String s : options.values()) { if (s.startsWith((String) autoTextField.getModelObject())) { searchResults.add(s); } } target.addComponent(autoTextField); } }); // i18n autoTextField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); String componentValue = (String) ((autoTextField != null && autoTextField.getModelObject() != null) ? autoTextField.getModelObject() : null); autoTextField.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(autoTextField)); autoTextField.setModel(new PropertyModel(model.getObject(), field.getName().getText())); //border.add(model.bind(autoTextField, field.getName().getText())); border.add(autoTextField); if (logger.isDebugEnabled() && autoTextField != null && autoTextField.getDefaultModelObjectAsString() != null) { if (logger.isDebugEnabled()) logger.debug( "Auto complete value is :" + autoTextField.getDefaultModelObjectAsString()); } listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", autoTextField); return label; // ------------------------- } private SimpleFormComponentLabel addFileInputField(final CompoundPropertyModel model, final Map<String, FileUploadField> fileUploadFields, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired) { SimpleFormComponentLabel label = null; Fragment f = new Fragment("field", "fileField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); FileUploadField fileField = new FileUploadField("field"); fileUploadFields.put(field.getLabel(), fileField); fileField.add(new ErrorHighlighter()); fileField.setRequired(valueRequired); // i18n fileField.setLabel(new ResourceModel( StringUtils.isNotBlank(i18nedFieldLabelResourceKey) ? i18nedFieldLabelResourceKey : Field.FIELD_TYPE_SIMPLE_ATTACHEMENT));//field.getName().getText().equalsIgnoreCase(Field.FIELD_TYPE_SIMPLE_ATTACHEMENT) ? Field.FIELD_TYPE_SIMPLE_ATTACHEMENT : i18nedFieldLabelResourceKey)); //f.add(model.bind(fileField, field.getName().getText())); fileField.setModel(new Model()); // List<FileUpload> fileUploads = new LinkedList<FileUpload>(); f.add(fileField); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", fileField); return label; } /** * @param model * @param listItem * @param field * @param i18nedFieldLabelResourceKey * @param valueRequired * @param options */ private SimpleFormComponentLabel renderDropDown(final IModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final Map<String, String> options) { SimpleFormComponentLabel label = null; /* final List<CustomAttributeLookupValue> lookupValues = getCalipso().findLookupValuesByCustomAttribute(field.getCustomAttribute()); TreeChoice choice = new TreeChoice("field", new PropertyModel(field, "customAttribute.lookupValue"), lookupValues); choice.setType(CustomAttributeLookupValue.class); //choice.setType(Long.class); choice.setRequired(valueRequired); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); //border.add(new ErrorHighlighter(choice)); border.add(choice); */ // drop down list final Fragment fragment = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); if (field.getCustomAttribute() == null) { field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(), field.getName().getText())); } // add HTML description through velocity logger.info("field name:" + field.getName() + ", custom atribute: " + field.getCustomAttribute()); addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute() != null ? field.getCustomAttribute().getHtmlDescription() : "", null, true); final List<CustomAttributeLookupValue> lookupValues = getCalipso() .findActiveLookupValuesByCustomAttribute(field.getCustomAttribute()); // preselect previous user choice from DB if available Object preselected = item.getValue(field.getName()); if (preselected != null) { String sPreselectedId = preselected.toString(); if (CollectionUtils.isNotEmpty(lookupValues)) { for (CustomAttributeLookupValue value : lookupValues) { if ((value.getId() + "").equals(sPreselectedId)) { field.getCustomAttribute().setLookupValue(value); break; } } } } // else set using the default string value instead, if any // TODO: move this into a LookupValueDropDownChoice class else { String defaultStringValue = field.getCustomAttribute() != null ? field.getCustomAttribute().getDefaultStringValue() : null; if (defaultStringValue != null && CollectionUtils.isNotEmpty(lookupValues)) { for (CustomAttributeLookupValue value : lookupValues) { if (value.getValue().equals(defaultStringValue)) { field.getCustomAttribute().setLookupValue(value); break; } } } } DropDownChoice choice = new DropDownChoice("field", new PropertyModel(field, "customAttribute.lookupValue"), lookupValues, new IChoiceRenderer<CustomAttributeLookupValue>() { @Override public Object getDisplayValue(CustomAttributeLookupValue o) { return fragment.getString(o.getNameTranslationResourceKey()); } @Override public String getIdValue(CustomAttributeLookupValue o, int index) { return String.valueOf(index); } }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); fragment.add(border); border.add(new ErrorHighlighter(choice)); //border.add(model.bind(choice, field.getName().getText())); border.add(choice); listItem.add(fragment.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); return label; } /** * @param model * @param listItem * @param field * @param i18nedFieldLabelResourceKey * @param valueRequired * @param options */ private SimpleFormComponentLabel renderPeriodPartDropDown(final CompoundPropertyModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final List<Date> options) { SimpleFormComponentLabel label = null; // drop down list Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); DropDownChoice choice = new DropDownChoice("field", options, new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { return DateUtils.format((Date) o); }; @Override public String getIdValue(Object o, int i) { return String.valueOf(i); }; }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(choice)); //border.add(model.bind(choice, field.getName().getText())); choice.setModel(model.bind(field.getName().getText())); border.add(choice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); return label; } }; if (editableGroupFields.isEmpty()) { listItem.setVisible(false); } listView.setReuseItems(true); listItem.add(listView.setRenderBodyOnly(true)); } }; add(fieldGroups.setReuseItems(true)); // }
From source file:gr.abiss.calipso.wicket.DashboardPanel.java
License:Open Source License
/** * /*from w w w. jav a 2 s. c o m*/ * @param id * @param breadCrumbModel * @param isSingleSpace */ @SuppressWarnings({ "unchecked", "serial" }) public DashboardPanel(String id, IBreadCrumbModel breadCrumbModel, final boolean isSingleSpace) { super(id, breadCrumbModel); if (!isSingleSpace) { setCurrentSpace(null); } final User user = getPrincipal(); // current space??? List<UserSpaceRole> nonGlobalSpaceRoles = new ArrayList<UserSpaceRole>(user.getSpaceRolesNoGlobal()); logger.info("nonGlobalSpaceRoles: " + nonGlobalSpaceRoles); WebMarkupContainer table = new WebMarkupContainer("table"); WebMarkupContainer message = new WebMarkupContainer("message"); // if only one space exist for the user, and user has roles in this space if (isSingleSpace && nonGlobalSpaceRoles.size() > 0) { UserSpaceRole singleUSR = null; // if only one space exist then the first space is the the current space final Space singleSpace = getCurrentSpace();//spaceRoles.get(0).getSpaceRole().getSpace(); //setCurrentSpace(singleSpace); // try to obtain a non-Guest role for user for (UserSpaceRole u : nonGlobalSpaceRoles) { u.getSpaceRole().getSpace(); if (u.getSpaceRole().getSpace().equals(singleSpace)) { singleUSR = u; break; } } /* MOVED this to CalipsoServiceImpl for login // if no match was found for a non-guest role but space is open to guests, // add the Guest role to the user if(singleUSR == null && singleSpace.isGuestAllowed()){ for(SpaceRole spaceRole: singleSpace.getSpaceRoles()){ if(spaceRole.getRoleType().getType().equals(Type.GUEST)){ singleUSR = new UserSpaceRole(user, spaceRole); break; } } if(logger.isDebugEnabled()){ logger.debug("Found no Roles for the user in this space but Guest is allowed, added role: "+singleUSR); } } */ nonGlobalSpaceRoles = new ArrayList(); nonGlobalSpaceRoles.add(singleUSR); if (singleUSR.isAbleToCreateNewItem()) { add(new BreadCrumbLink("new", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { return new ItemFormPanel(componentId, getBreadCrumbModel()); } }); } else { add(new WebMarkupContainer("new").setVisible(false)); } if (singleSpace.isAssetEnabled()) { SpaceAssetAdminLink spaceAssetAdminLink = new SpaceAssetAdminLink("asset", getBreadCrumbModel()) { @Override public void onLinkActivate() { }//onLinkActivate }; spaceAssetAdminLink.setVisible(user.isGlobalAdmin() || user.isSpaceAdmin(singleSpace)); add(spaceAssetAdminLink); } else { add(new WebMarkupContainer("asset").setVisible(false)); } add(new BreadCrumbLink("search", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { return new ItemSearchFormPanel(componentId, getBreadCrumbModel()); } }); String spaceName = localize(getCurrentSpace().getNameTranslationResourceKey()); //add overview title for single space add(new Label("dashboardTitle", localize("dashboard.title.overview", spaceName)) .setRenderBodyOnly(true)); //remove space name title if single space table.add(new WebMarkupContainer("spaceTitle").setVisible(false)); //add help message table.add(new Label("DashboardPanelHelp", localize("DashboardPanel.SingleSpace.help", spaceName)) .setRenderBodyOnly(true)); } // many spaces else { setCurrentSpace(null); //add overview title for dashboard spaces add(new Label("dashboardTitle", localize("dashboard.title.mySpaces")).setRenderBodyOnly(true)); //add space title for dashboard spaces table.add(new Label("spaceTitle", localize("dashboard.space"))); //add help message table.add(new Label("DashboardPanelHelp", localize("DashboardPanel.help"))); // hide add(new WebMarkupContainer("new").setVisible(false)); add(new WebMarkupContainer("asset").setVisible(false)); add(new WebMarkupContainer("search").setVisible(false)); } add(table); add(message); // TODO: this should actually present totals for public spaces. if (nonGlobalSpaceRoles.size() > 0) { // if many spaces there is no current space // check loggedBy,assignedTo,Unassigned counts final CountsHolder countsHolder = getCalipso().loadCountsForUser(user); WebMarkupContainer hideLogged = new WebMarkupContainer("hideLogged"); WebMarkupContainer hideAssigned = new WebMarkupContainer("hideAssigned"); WebMarkupContainer hideUnassigned = new WebMarkupContainer("hideUnassigned"); if (user.getId() == 0) { hideLogged.setVisible(false); hideAssigned.setVisible(false); hideUnassigned.setVisible(false); } table.add(hideLogged); table.add(hideAssigned); table.add(hideUnassigned); TreeSet<UserSpaceRole> sortedBySpaceCode = new TreeSet<UserSpaceRole>(new UserSpaceRoleComparator()); sortedBySpaceCode.addAll(nonGlobalSpaceRoles); List<UserSpaceRole> sortedBySpaceCodeList = new ArrayList<UserSpaceRole>(sortedBySpaceCode.size()); sortedBySpaceCodeList.addAll(sortedBySpaceCode); table.add(new ListView<UserSpaceRole>("dashboardRows", sortedBySpaceCodeList) { @Override protected void populateItem(final ListItem listItem) { UserSpaceRole userSpaceRole = (UserSpaceRole) listItem.getModelObject(); // TODO: this should happen onclick //logger.info("populateItem, userSpaceRole.getSpaceRole().getSpace(): "+userSpaceRole.getSpaceRole().getSpace()); Counts counts = countsHolder.getCounts().get(userSpaceRole.getSpaceRole().getSpace().getId()); if (counts == null) { counts = new Counts(false); // this can happen if fresh space } boolean isOddLine; if (listItem.getIndex() % 2 == 1) { isOddLine = true; } else { isOddLine = false; } MarkupContainer dashboardRow; //if single space, render expanded row if ((isSingleSpace && getCurrentSpace() != null) || isRowExpanded(userSpaceRole)) { if (!counts.isDetailed()) { counts = getCalipso().loadCountsForUserSpace(user, userSpaceRole.getSpaceRole().getSpace()); } dashboardRow = new DashboardRowExpandedPanel("dashboardRow", getBreadCrumbModel(), userSpaceRole, counts, isSingleSpace).setOddLine(isOddLine); } else { dashboardRow = new DashboardRowPanel("dashboardRow", getBreadCrumbModel(), userSpaceRole, counts, isSingleSpace).setOddLine(isOddLine); } listItem.add(dashboardRow); } }); // SimpleAttributeModifier colSpan = new SimpleAttributeModifier("colspan", user.isAdminForAllSpaces()?"3":"2"); SimpleAttributeModifier colSpan = new SimpleAttributeModifier("colspan", "3"); Label hAction = new Label("hAction", localize("dashboard.action")); hAction.add(colSpan); table.add(hAction); // TODO panelize totals row and reduce redundant code WebMarkupContainer total = new WebMarkupContainer("total"); total.add(new Label("allSpaces", localize("item_search_form.allSpaces")).setRenderBodyOnly(true) .setVisible(!user.isAnonymous())); if (nonGlobalSpaceRoles.size() > 1) { Label hTotal = new Label("hTotal"); hTotal.add(colSpan); total.add(hTotal); total.add(new BreadCrumbLink("search", getBreadCrumbModel()) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { return new ItemSearchFormPanel(componentId, getBreadCrumbModel()); } }.setVisible(!user.isAnonymous())); if (user.getId() > 0) { total.add(new BreadCrumbLink("loggedByMe", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(user, DashboardPanel.this); itemSearch.setLoggedBy(user); setCurrentItemSearch(itemSearch); return new ItemListPanel(componentId, getBreadCrumbModel()); } }.add(new Label("loggedByMe", new PropertyModel(countsHolder, "totalLoggedByMe")))); total.add(new BreadCrumbLink("assignedToMe", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(user, DashboardPanel.this); itemSearch.setAssignedTo(user); setCurrentItemSearch(itemSearch); return new ItemListPanel(componentId, getBreadCrumbModel()); } }.add(new Label("assignedToMe", new PropertyModel(countsHolder, "totalAssignedToMe")))); total.add(new BreadCrumbLink("unassigned", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(user, DashboardPanel.this); itemSearch.setUnassigned(); setCurrentItemSearch(itemSearch); return new ItemListPanel(componentId, getBreadCrumbModel()); } }.add(new Label("unassigned", new PropertyModel(countsHolder, "totalUnassigned")))); } else { total.add(new WebMarkupContainer("loggedByMe").setVisible(false)); total.add(new WebMarkupContainer("assignedToMe").setVisible(false)); total.add(new WebMarkupContainer("unassigned").setVisible(false)); } total.add(new BreadCrumbLink("total", breadCrumbModel) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(user, DashboardPanel.this); setCurrentItemSearch(itemSearch); return new ItemListPanel(componentId, getBreadCrumbModel()); } }.add(new Label("total", new PropertyModel(countsHolder, "totalTotal"))) .setVisible(!user.isAnonymous())); } else { total.setVisible(false); } table.add(total/*.setVisible(!user.isAnonymous())*/); message.setVisible(false); } else { table.setVisible(false); } }
From source file:gr.abiss.calipso.wicket.DashboardRowExpandedPanel.java
License:Open Source License
public DashboardRowExpandedPanel(String id, IBreadCrumbModel breadCrumbModel, final UserSpaceRole userSpaceRole, final Counts counts, final boolean isSingleSpace) { super(id, breadCrumbModel); setOutputMarkupId(true);//from ww w .jav a 2s . c o m setCurrentSpace(userSpaceRole.getSpaceRole().getSpace()); final Space space = getCurrentSpace(); refreshParentMenu(breadCrumbModel); final User user = userSpaceRole.getUser(); final Map<Integer, String> states = new TreeMap(space.getMetadata().getStatesMap()); states.remove(State.NEW); int rowspan = states.size() + 1; // add one totals row also int totalUnassignedItems = getCalipso().loadCountUnassignedItemsForSpace(space); if (totalUnassignedItems > 0) { rowspan++; //for unassiged items } final SimpleAttributeModifier sam = new SimpleAttributeModifier("rowspan", rowspan + ""); final SimpleAttributeModifier altClass = new SimpleAttributeModifier("class", "alt"); List<Integer> stateKeys = new ArrayList<Integer>(states.keySet()); add(new ListView("rows", stateKeys) { protected void populateItem(ListItem listItem) { if (listItem.getIndex() % 2 == 1) { listItem.add(altClass); } if (listItem.getIndex() == 0) { // rowspan output only for first row BreadCrumbLink spaceLink = new BreadCrumbLink("spaceName", getBreadCrumbModel()) { @Override protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); } }; spaceLink.add(new Label("spaceName", localize(space.getNameTranslationResourceKey()))); spaceLink.add(sam); //if in single space, don't render name if (isSingleSpace) { spaceLink.setVisible(false); } listItem.add(spaceLink); WebMarkupContainer newColumn = new WebMarkupContainer("new"); newColumn.add(sam); listItem.add(newColumn); if (userSpaceRole.isAbleToCreateNewItem()) { newColumn.add(new BreadCrumbLink("new", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { return new ItemFormPanel(componentId, getBreadCrumbModel()); } }); } else { newColumn.add(new WebMarkupContainer("new").setVisible(false)); } //TODO: For future use WebMarkupContainer slaColumn = new WebMarkupContainer("sla"); slaColumn.add(sam); slaColumn.add(new Link("sla") { public void onClick() { setResponsePage(SLAsPage.class); } }); listItem.add(slaColumn.setVisible(false)); //Asset WebMarkupContainer assetColumn = new WebMarkupContainer("asset"); assetColumn.add(sam); listItem.add(assetColumn); if (space.isAssetEnabled() && (user.isGlobalAdmin() || user.isSpaceAdmin(space))) { assetColumn.add(new BreadCrumbLink("asset", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { return new AssetSpacePanel(componentId, getBreadCrumbModel()); } }.setVisible(user.isGlobalAdmin() || user.isSpaceAdmin(space))); } else { assetColumn.add(new WebMarkupContainer("asset").setVisible(false)); } listItem.add(new BreadCrumbLink("search", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { return new ItemSearchFormPanel(componentId, getBreadCrumbModel()); } }.add(sam)); WebMarkupContainer link = new WebMarkupContainer("link"); link.add(sam); listItem.add(link); //if in single space, don't render expand/contract link if (isSingleSpace) { link.add(new WebMarkupContainer("link").setVisible(false)); } else { link.add(new IndicatingAjaxLink("link") { public void onClick(AjaxRequestTarget target) { //mark contracted in DashboardPanel IBreadCrumbParticipant activePanel = getBreadCrumbModel().getActive(); if (activePanel instanceof DashboardPanel) { ((DashboardPanel) activePanel).unmarkRowExpanded(userSpaceRole); } DashboardRowPanel dashboardRow = new DashboardRowPanel("dashboardRow", getBreadCrumbModel(), userSpaceRole, counts, isSingleSpace) .setOddLine(isOddLine); DashboardRowExpandedPanel.this.replaceWith(dashboardRow); target.addComponent(dashboardRow); } }); } } else { listItem.add(new WebMarkupContainer("spaceName").add(new WebMarkupContainer("spaceName")) .setVisible(false)); listItem.add(new WebMarkupContainer("new").setVisible(false)); listItem.add(new WebMarkupContainer("sla").setVisible(false)); listItem.add(new WebMarkupContainer("asset").setVisible(false)); listItem.add(new WebMarkupContainer("search").setVisible(false)); listItem.add( new WebMarkupContainer("link").add(new WebMarkupContainer("link")).setVisible(false)); } final Integer i = (Integer) listItem.getModelObject(); listItem.add(new Label("status", states.get(i))); if (user.getId() > 0) { WebMarkupContainer loggedByMeContainer; WebMarkupContainer assignedToMeContainer; WebMarkupContainer unassignedContainer; if (isSingleSpace) {//if a space is selected loggedByMeContainer = new IndicatingAjaxLink("loggedByMe") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setLoggedBy(user); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel() .getActive(); singleSpacePanel.refreshItemListPanel(target); } }; assignedToMeContainer = new IndicatingAjaxLink("assignedToMe") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setAssignedTo(user); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel() .getActive(); singleSpacePanel.refreshItemListPanel(target); } }; unassignedContainer = new IndicatingAjaxLink("unassigned") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setUnassigned(); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel() .getActive(); singleSpacePanel.refreshItemListPanel(target); } }; } else {//if no space is selected. i.e. for dashboard loggedByMeContainer = new BreadCrumbLink("loggedByMe", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setLoggedBy(user); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); //return new ItemListPanel(componentId, getBreadCrumbModel()); } }; assignedToMeContainer = new BreadCrumbLink("assignedToMe", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setAssignedTo(user); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); } }; unassignedContainer = new BreadCrumbLink("unassigned", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setUnassigned(); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); } }; } //get numbers for loggedByMe and assignedToMe Long total = counts.getTotalForState(i); //add the numbers loggedByMeContainer .add(new DashboardNumbers("loggedByMeNumbers", counts.getLoggedByMeForState(i), total)); assignedToMeContainer.add( new DashboardNumbers("assignedToMeNumbers", counts.getAssignedToMeForState(i), total)); unassignedContainer .add(new DashboardNumbers("unassignedNumbers", counts.getUnassignedForState(i), total)); //add the containers listItem.add(loggedByMeContainer); listItem.add(assignedToMeContainer); listItem.add(unassignedContainer); } else { listItem.add(new WebMarkupContainer("loggedByMe").setVisible(false)); listItem.add(new WebMarkupContainer("assignedToMe").setVisible(false)); listItem.add(new WebMarkupContainer("unassigned").setVisible(false)); } WebMarkupContainer totalContainer; if (isSingleSpace) {//if a space is selected totalContainer = new IndicatingAjaxLink("total") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel().getActive(); singleSpacePanel.refreshItemListPanel(target); } }; } else {//if no space is selected. i.e. for dashboard totalContainer = new BreadCrumbLink("total", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setStatus(i); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); //return new ItemListPanel(componentId, getBreadCrumbModel()); } }; } Long total = counts.getTotalForState(i); totalContainer.add(new Label("total", total == null ? "" : total.toString())); listItem.add(totalContainer); } }); // sub totals ========================================================== if (user.getId() > 0) { WebMarkupContainer loggedByMeTotalContainer; WebMarkupContainer assignedToMeTotalContainer; WebMarkupContainer unassignedTotalContainer; if (isSingleSpace) {//if a space is selected loggedByMeTotalContainer = new IndicatingAjaxLink("loggedByMeTotal") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setLoggedBy(user); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel().getActive(); singleSpacePanel.refreshItemListPanel(target); } }; assignedToMeTotalContainer = new IndicatingAjaxLink("assignedToMeTotal") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setAssignedTo(user); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel().getActive(); singleSpacePanel.refreshItemListPanel(target); } }; unassignedTotalContainer = new IndicatingAjaxLink("unassignedTotal") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setUnassigned(); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel().getActive(); singleSpacePanel.refreshItemListPanel(target); } }; } else {//if no space is selected. i.e. for dashboard loggedByMeTotalContainer = new BreadCrumbLink("loggedByMeTotal", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setLoggedBy(user); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); //return new ItemListPanel(componentId, getBreadCrumbModel()); } }; assignedToMeTotalContainer = new BreadCrumbLink("assignedToMeTotal", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setAssignedTo(user); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); //return new ItemListPanel(componentId, getBreadCrumbModel()); } }; unassignedTotalContainer = new BreadCrumbLink("unassignedTotal", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); itemSearch.setUnassigned(); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); } }; } //get total Long total = new Long(counts.getTotal()); //add the numbers loggedByMeTotalContainer .add(new DashboardNumbers("loggedByMeNumbers", new Long(counts.getLoggedByMe()), total)); assignedToMeTotalContainer .add(new DashboardNumbers("assignedToMeNumbers", new Long(counts.getAssignedToMe()), total)); unassignedTotalContainer .add(new DashboardNumbers("unassignedNumbers", new Long(counts.getUnassigned()), total)); //add the containers add(loggedByMeTotalContainer); add(assignedToMeTotalContainer); add(unassignedTotalContainer); } else { add(new WebMarkupContainer("loggedByMeTotal").setVisible(false)); add(new WebMarkupContainer("assignedToMeTotal").setVisible(false)); add(new WebMarkupContainer("unassignedTotal").setVisible(false)); } WebMarkupContainer totalTotalContainer; if (isSingleSpace) {//if a space is selected totalTotalContainer = new IndicatingAjaxLink("totalTotal") { public void onClick(AjaxRequestTarget target) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); setCurrentItemSearch(itemSearch); SingleSpacePanel singleSpacePanel = (SingleSpacePanel) getBreadCrumbModel().getActive(); singleSpacePanel.refreshItemListPanel(target); } }; } else {//if no space is selected. i.e. for dashboard totalTotalContainer = new BreadCrumbLink("totalTotal", getBreadCrumbModel()) { protected IBreadCrumbParticipant getParticipant(String componentId) { ItemSearch itemSearch = new ItemSearch(space, getPrincipal(), this, DashboardRowExpandedPanel.this.getCalipso()); setCurrentItemSearch(itemSearch); return new SingleSpacePanel(componentId, getBreadCrumbModel(), itemSearch); //return new ItemListPanel(componentId, getBreadCrumbModel()); } }; } totalTotalContainer.add(new Label("total", new PropertyModel(counts, "total"))); add(totalTotalContainer); }
From source file:gr.abiss.calipso.wicket.helpMenu.HelpMenuPanel.java
License:Open Source License
private void init() { final Space space = getCurrentSpace(); final boolean hasBreadCrumbModel = getBreadCrumbModel() != null; if (space == null) { WebMarkupContainer empty = new WebMarkupContainer("availableAssetTypesListMenu"); add(new EmptyPanel("assetTypesHeadingLabel").setRenderBodyOnly(true).setVisible(false)); empty.setVisible(false);/*from w ww .j ava2 s. c o m*/ add(empty.setRenderBodyOnly(true)); add(new Label("spaceCreateLink").setVisible(false)); WebMarkupContainer spaceLink = new WebMarkupContainer("spaceLink"); spaceLink.setVisible(true); add(spaceLink); } else { if (getCalipso().isAllowedToCreateNewItem(getPrincipal(), space)) { // link to create current space if (hasBreadCrumbModel) { BreadCrumbLink spaceCreateLink = new BreadCrumbLink("spaceCreateLink", getBreadCrumbModel()) { private static final long serialVersionUID = 1L; @Override protected IBreadCrumbParticipant getParticipant(String id) { List<IBreadCrumbParticipant> breadCrumbList = getBreadCrumbModel() .allBreadCrumbParticipants(); int siz = breadCrumbList.size(); if (breadCrumbList.get(siz - 1).equals(getBreadCrumbModel().getActive())) { breadCrumbList.remove(siz - 1); } return new ItemFormPanel(id, getBreadCrumbModel()); } }; add(spaceCreateLink); } else { Link spaceCreateLink = new Link("spaceCreateLink") { private static final long serialVersionUID = 1L; @Override public void onClick() { setResponsePage(ItemFormPage.class); } }; add(spaceCreateLink); } } else { add(new Label("spaceCreateLink").setVisible(false)); } if (hasBreadCrumbModel) { BreadCrumbLink spaceLink = new BreadCrumbLink("spaceLink", getBreadCrumbModel()) { private static final long serialVersionUID = 1L; @Override protected IBreadCrumbParticipant getParticipant(String id) { List<IBreadCrumbParticipant> breadCrumbList = getBreadCrumbModel() .allBreadCrumbParticipants(); int siz = breadCrumbList.size(); if (breadCrumbList.get(siz - 1).equals(getBreadCrumbModel().getActive())) { breadCrumbList.remove(siz - 1); } ItemSearch itemSearch = new ItemSearch(getCurrentSpace(), getPrincipal(), this, HelpMenuPanel.this.getCalipso()); SingleSpacePanel singleSpacePanel = new SingleSpacePanel(id, getBreadCrumbModel(), itemSearch); return singleSpacePanel; } }; add(spaceLink.setRenderBodyOnly(getPrincipal().isAnonymous())); spaceLink.add(new Label("spaceNameLabel", localize(space.getNameTranslationResourceKey()))); } else { Link spaceLink = new Link("spaceLink") { private static final long serialVersionUID = 1L; @Override public void onClick() { setResponsePage(SpacePage.class); } }; add(spaceLink.setRenderBodyOnly(getPrincipal().isAnonymous())); spaceLink.add(new Label("spaceNameLabel", localize(space.getNameTranslationResourceKey()))); } List<AssetType> visibleAssetTypes = getCalipso().findAllAssetTypesForSpace(space); boolean showAssets = CollectionUtils.isNotEmpty(visibleAssetTypes) && !getPrincipal().isAnonymous(); RenderedClazzListView availableAssetTypesListMenu = new RenderedClazzListView( "availableAssetTypesListMenu", visibleAssetTypes); availableAssetTypesListMenu.setRenderBodyOnly(false); add(new Label("assetTypesHeadingLabel", localize("asset.assetTypes")).setVisible(showAssets)); add(availableAssetTypesListMenu.setVisible(showAssets)); // render message if no asset types exist // if(CollectionUtils.isEmpty(visibleAssetTypes) || getPrincipal().isAnonymous()){ // availableAssetTypesListMenu.setVisible(false); // add(new Label("noAssetTypes", localize("asset.no.assetTypes.exist")).setVisible(!getPrincipal().isAnonymous())); // } // else{ // add(new Label("noAssetTypes", "").setVisible(false)); // } } // searches don't depend on spaces List<SavedSearch> visibleReports = new ArrayList<SavedSearch>( getCalipso().findVisibleSearches(getPrincipal())); add(new Label("reports", localize("reports"))); if (CollectionUtils.isNotEmpty(visibleReports)) { add(new ListView("visibleSearchListView", visibleReports) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem listItem) { final SavedSearch savedSearch = (SavedSearch) listItem.getModelObject(); if (getBreadCrumbModel() != null && space != null) { BreadCrumbLink savedSearchBreadCrumbLink = new BreadCrumbLink("visbleSearchItem", getBreadCrumbModel()) { private static final long serialVersionUID = 1L; @Override protected IBreadCrumbParticipant getParticipant(String id) { //create PageParameters and ItemSearch classes PageParameters params = new PageParameters(savedSearch.getQueryString(), ","); ItemSearch itemSearch = null; try { itemSearch = ItemUtils.getItemSearch(getPrincipal(), params, this, HelpMenuPanel.this.getCalipso()); } catch (CalipsoSecurityException e) { e.printStackTrace(); } setCurrentItemSearch(itemSearch); BreadCrumbUtils.removePreviousBreadCrumbPanel(getBreadCrumbModel()); return new ItemListPanel(id, getBreadCrumbModel(), savedSearch.getName()); } }; listItem.add(savedSearchBreadCrumbLink); savedSearchBreadCrumbLink.add(new Label("visbleSearchItemLabel", savedSearch.getName())); } else { listItem.add(new EmptyPanel("visbleSearchItem").setVisible(false)); } } }); add(new Label("noReports", "").setVisible(false)); } // if there are no visible reports else { add(new EmptyPanel("visibleSearchListView").setVisible(false)); add(new Label("noReports", localize("reports.none.available"))); } }
From source file:gr.abiss.calipso.wicket.HistoryEntry.java
License:Open Source License
@SuppressWarnings("unchecked") public HistoryEntry(String id, IBreadCrumbModel breadCrumbModel, final History history, final List<Field> editable) { super(id, breadCrumbModel); // logged By/*w w w . j av a 2 s. c o m*/ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ User loggedBy = history.getLoggedBy(); add(loggedBy != null ? new UserIconPanel("loggedByIcon", getBreadCrumbModel(), loggedBy, true) : new EmptyPanel("loggedByIcon")); add(loggedBy != null ? new UserViewLink("loggedBy", getBreadCrumbModel(), loggedBy) : new EmptyPanel("loggedBy")); // date formats Metadata metadata = getCalipso().getCachedMetadataForSpace(getCurrentSpace()); final SimpleDateFormat longDateTimeFormat = metadata.getDateFormat(Metadata.DATETIME_FORMAT_LONG); final SimpleDateFormat shortDateFormat = metadata.getDateFormat(Metadata.DATE_FORMAT_SHORT); // Changed status // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ add(new Label("status", localize("item_view.changedStatus", history.getStatusValue())) .setVisible(!history.getStatusValue().equals(""))); // AssignedTo // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WebMarkupContainer assignedToContainer = new WebMarkupContainer("assignedToContainer"); add(assignedToContainer); if (history.getAssignedTo() != null) { assignedToContainer .add(new UserViewLink("assignedToLink", getBreadCrumbModel(), history.getAssignedTo())); } else { assignedToContainer.setVisible(false); } // Comment // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WebMarkupContainer comment = new WebMarkupContainer("comment"); add(comment); // TODO: fix the issue of Colections that history returns and the HTML if (history.getAttachments() != null && history.getAttachments().size() > 0) { this.renderSighslideDirScript(); comment.add(new ListView("attachmentThumbs", new ArrayList<Attachment>(history.getAttachments())) { @Override protected void populateItem(ListItem attachmentItem) { Attachment tmp = (Attachment) attachmentItem.getModelObject(); attachmentItem.add(new AttachmentLinkPanel("attachment", tmp, false)); } }); } else { comment.add(new EmptyPanel("attachmentThumbs").setVisible(false)); } // do not escape HTML // comment.add(new Label("comment", // ItemUtils.fixWhiteSpace(h.getComment())).setEscapeModelStrings(false)); comment.add(new Label("commentLabel", history.getHtmlComment()).setEscapeModelStrings(false)); add(new Label("timeStamp", longDateTimeFormat.format(history.getTimeStamp()))); if (editable != null) { add(new ListView("fields", editable) { protected void populateItem(ListItem listItem) { Field field = (Field) listItem.getModelObject(); //logger.info("field: "+field); //logger.info("field.fieldName: "+field.getName()); //logger.info("field.isDropDownType: "+field.isDropDownType()); //logger.info("field.getFieldType: "+field.getFieldType()); //logger.info("field.getName.getType: "+field.getName().getType()); Serializable fieldValue = (Serializable) (field.isDropDownType() ? history.getValue(field.getName()) : history.getCustomValue(field)); // TODO: i118n // check if attachment was uploaded and get it from the history if (field.getName().isFile()) { fieldValue = ""; Set<Attachment> attachments = history.getAttachments(); if (attachments != null && attachments.size() > 0) { for (Attachment attachment : attachments) { if (attachment.getFileName().startsWith(field.getLabel())) { displayed = attachment; fieldValue = field.getLabel(); break; } } } } // if empty, dont render any change info if (fieldValue == null || fieldValue.equals("")) { listItem.add(new WebMarkupContainer("field").setVisible(false)); listItem.add(new EmptyPanel("fileLink")).setVisible(false); } else if (field.isDropDownType()) { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), localize("CustomAttributeLookupValue." + fieldValue + ".name")))); listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // if file, render file specific text else if (field.getName().isFile()) { AttachmentDownLoadableLinkPanel fileLink = new AttachmentDownLoadableLinkPanel("fileLink", displayed); listItem.add(new Label("field", localize("item_view.changedCustomFile", field.getLabel()))); listItem.add(fileLink); } // if file, render country specific text else if (field.getName().isCountry()) { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), localize("country." + fieldValue)))); listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // if file, render user specific text else if (field.getName().isUser()) { //if is user render link if (getBreadCrumbModel() != null) { listItem.add(new UserViewLink("field", getBreadCrumbModel(), (User) fieldValue)); } else { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), ((User) fieldValue).getDisplayValue()))); } listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // if file, render user specific text else if (field.getName().isOrganization()) { if (getBreadCrumbModel() != null) { listItem.add(new OrganizationViewLink("field", getBreadCrumbModel(), (Organization) fieldValue)); } else { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), ((Organization) fieldValue).getName()))); } listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // if date else if (field.isDateType()) { listItem.add( new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), shortDateFormat.format((Date) history.getValue(field.getName()))))); listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // if tabular else if (field.isMultivalue()) { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), MultipleValuesTextField.toHtmlSafeLines(fieldValue.toString())))); listItem.add(new EmptyPanel("fileLink").setVisible(false)); } // else render generic change info text else { listItem.add(new Label("field", localize("item_view.changedCustomAttribute", field.getLabel(), fieldValue.toString()))); listItem.add(new EmptyPanel("fileLink").setVisible(false)); } } }); } else { add(new WebMarkupContainer("fields").setVisible(false)); } // Common Fields Access getPrincipal().setRoleSpaceStdFieldList(getCalipso().findSpaceFieldsForUser(getPrincipal())); Map<StdField.Field, StdFieldMask> fieldMaskMap = getPrincipal().getStdFieldsForSpace(getCurrentSpace()); // Due To // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (fieldMaskMap.get(StdField.Field.DUE_TO) != null && !fieldMaskMap.get(StdField.Field.DUE_TO).getMask().equals(StdFieldMask.Mask.HIDDEN) && history.getDueTo() != null) { IModel value = new Model(DateUtils.format(history.getDueTo())); add(new Label("dueTo", localize("item_view.changedCustomAttribute", localize("field.dueTo"), value))); } // if else { add(new WebMarkupContainer("dueTo").setVisible(false)); } // else // Actual Effort // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (fieldMaskMap.get(StdField.Field.ACTUAL_EFFORT) != null && !fieldMaskMap.get(StdField.Field.ACTUAL_EFFORT).getMask().equals(StdFieldMask.Mask.HIDDEN) && history.getActualEffort() != null) { IModel value = new Model(ItemUtils.formatEffort(history.getActualEffort() * 60, localize("item_list.days"), localize("item_list.hours"), localize("item_list.minutes"))); add(new Label("actualEffort", localize("item_view.changedCustomAttribute", localize("field.actualEffort"), value))); } // if else { add(new WebMarkupContainer("actualEffort").setVisible(false)); } // else }
From source file:gr.abiss.calipso.wicket.ItemList.java
License:Open Source License
private void addPagination() { WebMarkupContainer pagination = new WebMarkupContainer("pagination"); if (pageCount > 1) { IndicatingAjaxLink prevOn = new IndicatingAjaxLink("prevOn") { public void onClick(AjaxRequestTarget target) { itemSearch.setCurrentPage(currentPage - 1); setCurrentItemSearch(itemSearch); // TODO avoid next line, refresh pagination only ItemList itemList = new ItemList(ItemList.this.getId(), getBreadCrumbModel()); ItemList.this.replaceWith(itemList); target.addComponent(itemList); }// w w w . jav a 2s .c o m }; prevOn.add(new Label("prevOn", "<<")); Label prevOff = new Label("prevOff", "<<"); if (currentPage == 0) { prevOn.setVisible(false); } else { prevOff.setVisible(false); } pagination.add(prevOn); pagination.add(prevOff); List<Integer> pageNumbers = new ArrayList<Integer>(pageCount); for (int i = 0; i < pageCount; i++) { pageNumbers.add(new Integer(i)); } ListView pages = new ListView("pages", pageNumbers) { protected void populateItem(ListItem listItem) { final Integer i = (Integer) listItem.getModelObject(); String pageNumber = i + 1 + ""; IndicatingAjaxLink pageOn = new IndicatingAjaxLink("pageOn") { public void onClick(AjaxRequestTarget target) { itemSearch.setCurrentPage(i); setCurrentItemSearch(itemSearch); // TODO avoid next line, refresh pagination only ItemList itemList = new ItemList(ItemList.this.getId(), getBreadCrumbModel()); ItemList.this.replaceWith(itemList); target.addComponent(itemList); } }; pageOn.add(new Label("pageOn", pageNumber)); Label pageOff = new Label("pageOff", pageNumber); if (i == currentPage) { pageOn.setVisible(false); } else { pageOff.setVisible(false); } listItem.add(pageOn); listItem.add(pageOff); } }; pagination.add(pages); IndicatingAjaxLink nextOn = new IndicatingAjaxLink("nextOn") { public void onClick(AjaxRequestTarget target) { itemSearch.setCurrentPage(currentPage + 1); setCurrentItemSearch(itemSearch); // TODO avoid next line, refresh pagination only ItemList itemList = new ItemList(ItemList.this.getId(), getBreadCrumbModel()); ItemList.this.replaceWith(itemList); target.addComponent(itemList); } }; nextOn.add(new Label("nextOn", ">>")); Label nextOff = new Label("nextOff", ">>"); if (currentPage == pageCount - 1) { nextOn.setVisible(false); } else { nextOff.setVisible(false); } pagination.add(nextOn); pagination.add(nextOff); } else { // if pageCount == 1 pagination.setVisible(false); } add(pagination); }