public Widget draw() { // show only part of title titleWidget.setText(Utils.getStrippedStringWithEllipsis(publication.getTitle())); // MAIN PANEL ScrollPanel sp = new ScrollPanel(); sp.addStyleName("perun-tableScrollPanel"); VerticalPanel vp = new VerticalPanel(); vp.addStyleName("perun-table"); sp.add(vp); // resize perun table to correct size on screen session.getUiElements().resizePerunTable(sp, 350, this); // content final FlexTable ft = new FlexTable(); ft.setStyleName("inputFormFlexTable"); if (publication.getLocked() == false) { ft.setHTML(1, 0, "Id / Origin:"); ft.setHTML(2, 0, "Title:"); ft.setHTML(3, 0, "Year:"); ft.setHTML(4, 0, "Category:"); ft.setHTML(5, 0, "Rank:"); ft.setHTML(6, 0, "ISBN / ISSN:"); ft.setHTML(7, 0, "DOI:"); ft.setHTML(8, 0, "Full cite:"); ft.setHTML(9, 0, "Created by:"); ft.setHTML(10, 0, "Created date:"); for (int i = 0; i < ft.getRowCount(); i++) { ft.getFlexCellFormatter().setStyleName(i, 0, "itemName"); } ft.getFlexCellFormatter().setWidth(1, 0, "100px"); final ListBoxWithObjects<Category> listbox = new ListBoxWithObjects<Category>(); // fill listbox JsonCallbackEvents events = new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { for (Category cat : JsonUtils.<Category>jsoAsList(jso)) { listbox.addItem(cat); // if right, selected if (publication.getCategoryId() == cat.getId()) { listbox.setSelected(cat, true); } } } }; FindAllCategories categories = new FindAllCategories(events); categories.retrieveData(); final TextBox rank = new TextBox(); rank.setWidth("30px"); rank.setMaxLength(4); rank.setText(String.valueOf(publication.getRank())); final TextBox title = new TextBox(); title.setMaxLength(1024); title.setText(publication.getTitle()); title.setWidth("500px"); final TextBox year = new TextBox(); year.setText(String.valueOf(publication.getYear())); year.setMaxLength(4); year.setWidth("30px"); final TextBox isbn = new TextBox(); isbn.setText(publication.getIsbn()); isbn.setMaxLength(32); final TextBox doi = new TextBox(); doi.setText(publication.getDoi()); doi.setMaxLength(256); final TextArea main = new TextArea(); main.setText(publication.getMain()); main.setSize("500px", "70px"); // set max length main.getElement().setAttribute("maxlength", "4000"); ft.setHTML( 1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + publication.getPublicationSystemName()); ft.setWidget(2, 1, title); ft.setWidget(3, 1, year); ft.setWidget(4, 1, listbox); if (session.isPerunAdmin()) { // only perunadmin can change rank ft.setWidget(5, 1, rank); } else { ft.setHTML(5, 1, "" + publication.getRank()); } ft.setWidget(6, 1, isbn); ft.setWidget(7, 1, doi); ft.setWidget(8, 1, main); ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy())); ft.setHTML( 10, 1, DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM) .format(new Date((long) publication.getCreatedDate()))); // update button final CustomButton change = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in publication details"); change.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { Publication pub = JsonUtils.clone(publication).cast(); if (!JsonUtils.checkParseInt(year.getText())) { JsonUtils.cantParseIntConfirm("YEAR", year.getText()); } else { pub.setYear(Integer.parseInt(year.getText())); } if (session.isPerunAdmin()) { pub.setRank(Double.parseDouble(rank.getText())); } pub.setCategoryId(listbox.getSelectedObject().getId()); pub.setTitle(title.getText()); pub.setMain(main.getText()); pub.setIsbn(isbn.getText()); pub.setDoi(doi.getText()); UpdatePublication upCall = new UpdatePublication( JsonCallbackEvents.disableButtonEvents( change, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { // refresh page content Publication p = jso.cast(); publication = p; draw(); } })); upCall.updatePublication(pub); } }); ft.setWidget(0, 0, change); } else { ft.getFlexCellFormatter().setColSpan(0, 0, 2); ft.setWidget( 0, 0, new HTML( new Image(SmallIcons.INSTANCE.lockIcon()) + " <strong>Publication is locked. Ask administrator to perform any changes for you at [email protected].</strong>")); ft.setHTML(1, 0, "Id / Origin:"); ft.setHTML(2, 0, "Title:"); ft.setHTML(3, 0, "Year:"); ft.setHTML(4, 0, "Category:"); ft.setHTML(5, 0, "Rank:"); ft.setHTML(6, 0, "ISBN / ISSN:"); ft.setHTML(7, 0, "DOI:"); ft.setHTML(8, 0, "Full cite:"); ft.setHTML(9, 0, "Created by:"); ft.setHTML(10, 0, "Created date:"); for (int i = 0; i < ft.getRowCount(); i++) { ft.getFlexCellFormatter().setStyleName(i, 0, "itemName"); } ft.getFlexCellFormatter().setWidth(1, 0, "100px"); ft.setHTML( 1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + publication.getPublicationSystemName()); ft.setHTML(2, 1, publication.getTitle()); ft.setHTML(3, 1, String.valueOf(publication.getYear())); ft.setHTML(4, 1, publication.getCategoryName()); ft.setHTML(5, 1, String.valueOf(publication.getRank()) + " (default is 0)"); ft.setHTML(6, 1, publication.getIsbn()); ft.setHTML(7, 1, publication.getDoi()); ft.setHTML(8, 1, publication.getMain()); ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy())); ft.setHTML( 10, 1, DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM) .format(new Date((long) publication.getCreatedDate()))); } // LOCK / UNLOCK button for PerunAdmin if (session.isPerunAdmin()) { final CustomButton lock; if (publication.getLocked()) { lock = new CustomButton( "Unlock", "Allow editing of publication details (for users).", SmallIcons.INSTANCE.lockOpenIcon()); ft.setWidget(0, 0, lock); ft.getFlexCellFormatter().setColSpan(0, 0, 1); ft.setWidget( 0, 1, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " Publication is locked.")); } else { lock = new CustomButton( "Lock", "Deny editing of publication details (for users).", SmallIcons.INSTANCE.lockIcon()); ft.setWidget(0, 1, lock); } lock.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { UpdatePublication upCall = new UpdatePublication( JsonCallbackEvents.disableButtonEvents( lock, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { // refresh page content Publication p = jso.cast(); publication = p; draw(); } })); Publication p = JsonUtils.clone(publication).cast(); p.setLocked(!publication.getLocked()); upCall.updatePublication(p); } }); } DisclosurePanel dp = new DisclosurePanel(); dp.setWidth("100%"); dp.setContent(ft); dp.setOpen(true); FlexTable detailsHeader = new FlexTable(); detailsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookIcon())); detailsHeader.setHTML(0, 1, "<h3>Details</h3>"); dp.setHeader(detailsHeader); vp.add(dp); vp.add(loadAuthorsSubTab()); vp.add(loadThanksSubTab()); this.contentWidget.setWidget(sp); return getWidget(); }
public Widget draw() { VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); final FindAllCategories callback = new FindAllCategories(); final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback); TabMenu menu = new TabMenu(); menu.addWidget( TabMenu.getPredefinedButton( ButtonType.ADD, "Add new category", new ClickHandler() { public void onClick(ClickEvent event) { session.getTabManager().addTabToCurrentTab(new CreateCategoryTabItem()); } })); final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, "Delete selected categories"); removeButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<Category> delete = callback.getTableSelectedList(); String text = "Following categories will be deleted"; UiElements.showDeleteConfirm( delete, text, new ClickHandler() { @Override public void onClick(ClickEvent event) { // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE for (int i = 0; i < delete.size(); i++) { if (i == delete.size() - 1) { DeleteCategory request = new DeleteCategory( JsonCallbackEvents.disableButtonEvents(removeButton, events)); request.deleteCategory(delete.get(i).getId()); } else { DeleteCategory request = new DeleteCategory( JsonCallbackEvents.disableButtonEvents(removeButton)); request.deleteCategory(delete.get(i).getId()); } } } }); } }); menu.addWidget(removeButton); final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in category ranks"); saveButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { final ArrayList<Category> list = callback.getTableSelectedList(); if (UiElements.cantSaveEmptyListDialogBox(list)) { // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE for (int i = 0; i < list.size(); i++) { if (i == list.size() - 1) { UpdateCategory request = new UpdateCategory( JsonCallbackEvents.disableButtonEvents(saveButton, events)); request.updateCategory(list.get(i)); } else { UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton)); request.updateCategory(list.get(i)); } } } } }); menu.addWidget(saveButton); vp.add(menu); vp.setCellHeight(menu, "30px"); CellTable<Category> table = callback.getTable(); removeButton.setEnabled(false); saveButton.setEnabled(false); JsonUtils.addTableManagedButton(callback, table, removeButton); JsonUtils.addTableManagedButton(callback, table, saveButton); table.addStyleName("perun-table"); ScrollPanel sp = new ScrollPanel(); sp.add(table); sp.addStyleName("perun-tableScrollPanel"); vp.add(sp); // resize perun table to correct size on screen session.getUiElements().resizeSmallTabPanel(sp, 350, this); this.contentWidget.setWidget(vp); return getWidget(); }