下面列出了怎么用com.vaadin.server.FontAwesome的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 创建删除按钮
* @return
*/
private Button createDeleteButton() {
Button deleteButton = new Button("删除",FontAwesome.CLOSE);
deleteButton.addStyleName(ValoTheme.BUTTON_DANGER);
deleteButton.addClickListener((Button.ClickListener) clickEvent -> {
//validate
Collection<Object> items = grid.getSelectedRows();
if(items.size() == 0){
Notification.show("请选中要删除的行!", Notification.Type.ERROR_MESSAGE);
return;
}
//batch delete
for (Object object : items) {
Item item = grid.getContainerDataSource().getItem(object);
if(item != null){
Long id = (Long) item.getItemProperty("序号").getValue();
zookeeperAppRepository.delete(id);
}
}
search();
});
return deleteButton;
}
/**
* 创建删除按钮
* @return
*/
private Button createDeleteButton() {
Button deleteButton = new Button("删除",FontAwesome.CLOSE);
deleteButton.addStyleName(ValoTheme.BUTTON_DANGER);
deleteButton.addClickListener((Button.ClickListener) clickEvent -> {
//validate
Collection<Object> items = grid.getSelectedRows();
if(items.size() == 0){
Notification.show("请选中要删除的行!", Notification.Type.ERROR_MESSAGE);
return;
}
//batch delete
for (Object object : items) {
Item item = grid.getContainerDataSource().getItem(object);
if (item != null) {
Long id = (Long) item.getItemProperty("序号").getValue();
zookeeperProviderRepository.delete(id);
}
}
search();
});
return deleteButton;
}
/**
* 创建删除按钮
* @return
*/
private Button createDeleteButton() {
Button deleteButton = new Button("删除",FontAwesome.CLOSE);
deleteButton.addStyleName(ValoTheme.BUTTON_DANGER);
deleteButton.addClickListener((Button.ClickListener) clickEvent -> {
//validate
Collection<Object> items = grid.getSelectedRows();
if(items.size() == 0){
Notification.show("请选中要删除的行!", Notification.Type.ERROR_MESSAGE);
return;
}
//batch delete
for (Object object : items) {
Item item = grid.getContainerDataSource().getItem(object);
if (item != null) {
Long id = (Long) item.getItemProperty("序号").getValue();
zookeeperConsumerRepository.delete(id);
}
}
search();
});
return deleteButton;
}
/**
* 创建删除按钮
* @return
*/
private Button createDeleteButton() {
Button deleteButton = new Button("删除",FontAwesome.CLOSE);
deleteButton.addStyleName(ValoTheme.BUTTON_DANGER);
deleteButton.addClickListener((Button.ClickListener) clickEvent -> {
//validate
Collection<Object> items = grid.getSelectedRows();
if(items.size() == 0){
Notification.show("请选中要删除的行!", Notification.Type.ERROR_MESSAGE);
return;
}
//batch delete
for (Object object : items) {
Item item = grid.getContainerDataSource().getItem(object);
if(item != null){
Long id = (Long) item.getItemProperty("序号").getValue();
zookeeperAppRepository.delete(id);
}
}
search();
});
return deleteButton;
}
/**
* Show confirmation window and if ok then only, force quit action.
*
* @param actionId
* as Id if the action needs to be forced.
*/
private void confirmAndForceQuitAction(final Long actionId) {
/* Display the confirmation */
final ConfirmationDialog confirmDialog = new ConfirmationDialog(
i18n.getMessage("caption.forcequit.action.confirmbox"),
i18n.getMessage("message.forcequit.action.confirm"), i18n.getMessage(UIMessageIdProvider.BUTTON_OK),
i18n.getMessage(UIMessageIdProvider.BUTTON_CANCEL), ok -> {
if (!ok) {
return;
}
final boolean cancelResult = forceQuitActiveAction(actionId);
if (cancelResult) {
populateAndUpdateTargetDetails(selectedTarget);
notification.displaySuccess(i18n.getMessage("message.forcequit.action.success"));
} else {
notification.displayValidationError(i18n.getMessage("message.forcequit.action.failed"));
}
}, FontAwesome.WARNING, UIComponentIdProvider.CONFIRMATION_POPUP_ID, null);
UI.getCurrent().addWindow(confirmDialog.getWindow());
confirmDialog.getWindow().bringToFront();
}
private HorizontalLayout saveConfigurationButtonsLayout() {
final HorizontalLayout hlayout = new HorizontalLayout();
hlayout.setSpacing(true);
saveConfigurationBtn = SPUIComponentProvider.getButton(UIComponentIdProvider.SYSTEM_CONFIGURATION_SAVE, "", "",
"", true, FontAwesome.SAVE, SPUIButtonStyleNoBorder.class);
saveConfigurationBtn.setEnabled(false);
saveConfigurationBtn.setDescription(i18n.getMessage("configuration.savebutton.tooltip"));
saveConfigurationBtn.addClickListener(event -> saveConfiguration());
hlayout.addComponent(saveConfigurationBtn);
undoConfigurationBtn = SPUIComponentProvider.getButton(UIComponentIdProvider.SYSTEM_CONFIGURATION_CANCEL, "",
"", "", true, FontAwesome.UNDO, SPUIButtonStyleNoBorder.class);
undoConfigurationBtn.setEnabled(false);
undoConfigurationBtn.setDescription(i18n.getMessage("configuration.cancellbutton.tooltip"));
undoConfigurationBtn.addClickListener(event -> undoConfiguration());
hlayout.addComponent(undoConfigurationBtn);
final Link linkToSystemConfigHelp = SPUIComponentProvider.getHelpLink(i18n,
uiProperties.getLinks().getDocumentation().getSystemConfigurationView());
hlayout.addComponent(linkToSystemConfigHelp);
return hlayout;
}
private HorizontalLayout createApprovalLayout() {
approveButtonsGroup = new OptionGroup();
approveButtonsGroup.setId(UIComponentIdProvider.ROLLOUT_APPROVAL_OPTIONGROUP_ID);
approveButtonsGroup.addStyleName(ValoTheme.OPTIONGROUP_SMALL);
approveButtonsGroup.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
approveButtonsGroup.addStyleName("custom-option-group");
approveButtonsGroup.addItems(Rollout.ApprovalDecision.APPROVED, Rollout.ApprovalDecision.DENIED);
approveButtonsGroup.setItemCaption(Rollout.ApprovalDecision.APPROVED, i18n.getMessage(APPROVAL_BUTTON_LABEL));
approveButtonsGroup.setItemIcon(Rollout.ApprovalDecision.APPROVED, FontAwesome.CHECK);
approveButtonsGroup.setItemCaption(Rollout.ApprovalDecision.DENIED, i18n.getMessage(DENY_BUTTON_LABEL));
approveButtonsGroup.setItemIcon(Rollout.ApprovalDecision.DENIED, FontAwesome.TIMES);
approvalRemarkField = createTextField("label.approval.remark",
UIComponentIdProvider.ROLLOUT_APPROVAL_REMARK_FIELD_ID, Rollout.APPROVAL_REMARK_MAX_SIZE);
approvalRemarkField.setWidth(100.0F, Unit.PERCENTAGE);
final HorizontalLayout layout = new HorizontalLayout(approveButtonsGroup, approvalRemarkField);
layout.setWidth(100.0F, Unit.PERCENTAGE);
layout.setExpandRatio(approvalRemarkField, 1.0F);
return layout;
}
private void addFilterTextField(final DistributionSetIdName distributionSetIdName) {
final Button filterLabelClose = SPUIComponentProvider.getButton("drop.filter.close", "", "", "", true,
FontAwesome.TIMES_CIRCLE, SPUIButtonStyleNoBorder.class);
filterLabelClose.addClickListener(clickEvent -> closeFilterByDistribution());
final Label filteredDistLabel = new Label();
filteredDistLabel.setStyleName(ValoTheme.LABEL_COLORED + " " + ValoTheme.LABEL_SMALL);
String name = HawkbitCommonUtil.getDistributionNameAndVersion(distributionSetIdName.getName(),
distributionSetIdName.getVersion());
if (name.length() > SPUITargetDefinitions.DISTRIBUTION_NAME_MAX_LENGTH_ALLOWED) {
name = new StringBuilder(name.substring(0, SPUITargetDefinitions.DISTRIBUTION_NAME_LENGTH_ON_FILTER))
.append("...").toString();
}
filteredDistLabel.setValue(name);
filteredDistLabel.setSizeUndefined();
getFilterDroppedInfo().removeAllComponents();
getFilterDroppedInfo().setSizeFull();
getFilterDroppedInfo().addComponent(filteredDistLabel);
getFilterDroppedInfo().addComponent(filterLabelClose);
getFilterDroppedInfo().setExpandRatio(filteredDistLabel, 1.0F);
eventBus.publish(this, TargetFilterEvent.FILTER_BY_DISTRIBUTION);
}
private Label getTargetPollTime(final Object itemId) {
final Label statusLabel = new Label();
statusLabel.addStyleName(ValoTheme.LABEL_SMALL);
statusLabel.setHeightUndefined();
statusLabel.setContentMode(ContentMode.HTML);
final String pollStatusToolTip = (String) getContainerDataSource().getItem(itemId)
.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP).getValue();
if (StringUtils.hasText(pollStatusToolTip)) {
statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml());
statusLabel.setDescription(pollStatusToolTip);
} else {
statusLabel.setValue(FontAwesome.CLOCK_O.getHtml());
statusLabel.setDescription(getI18n().getMessage(UIMessageIdProvider.TOOLTIP_IN_TIME));
}
return statusLabel;
}
private StatusFontIcon createTypeLabelMetadata(final Action action) {
if (ActionType.FORCED == action.getActionType() || ActionType.TIMEFORCED == action.getActionType()) {
return new StatusFontIcon(FontAwesome.BOLT, STATUS_ICON_FORCED,
i18n.getMessage(UIMessageIdProvider.CAPTION_ACTION_FORCED),
UIComponentIdProvider.ACTION_HISTORY_TABLE_TYPE_LABEL_ID);
}
if (ActionType.SOFT == action.getActionType()) {
return new StatusFontIcon(FontAwesome.STEP_FORWARD, STATUS_ICON_SOFT,
i18n.getMessage(UIMessageIdProvider.CAPTION_ACTION_SOFT),
UIComponentIdProvider.ACTION_HISTORY_TABLE_TYPE_LABEL_ID);
}
if (ActionType.DOWNLOAD_ONLY == action.getActionType()) {
return new StatusFontIcon(FontAwesome.DOWNLOAD, STATUS_ICON_DOWNLOAD_ONLY,
i18n.getMessage(UIMessageIdProvider.CAPTION_ACTION_DOWNLOAD_ONLY),
UIComponentIdProvider.ACTION_HISTORY_TABLE_TYPE_LABEL_ID);
}
return null;
}
@Override
public JsonValue encode(final String value) {
if (value == null) {
return super.encode(getNullRepresentation());
}
final String result;
switch (value) {
case STATUS_FINISHED:
result = "<div class=\"statusIconGreen\">" + FontAwesome.CHECK_CIRCLE.getHtml() + "</div>";
break;
case STATUS_FAILED:
result = "<div class=\"statusIconRed\">" + FontAwesome.EXCLAMATION_CIRCLE.getHtml() + "</div>";
break;
case STATUS_INPROGRESS:
result = "<div class=\"statusIconActive\"></div>";
break;
default:
throw new IllegalArgumentException("Argument " + value + " wasn't expected.");
}
return super.encode(result);
}
private Object addDeleteCell(final Object itemId) {
if (itemId instanceof TagIdName && noTagLabel.equals(((TagIdName) itemId).getName())) {
return null;
}
final Button deleteButton = SPUIComponentProvider.getButton("", "", "", "", true, FontAwesome.TRASH_O,
SPUIButtonStyleNoBorder.class);
if (itemId instanceof TagIdName) {
deleteButton.setId(UIComponentIdProvider.DELETE_TAG_ID + ((TagIdName) itemId).getName());
} else {
deleteButton.setId(UIComponentIdProvider.DELETE_TAG_ID + itemId.toString());
}
deleteButton.setDescription(i18n.getMessage(UIMessageIdProvider.TOOLTIP_DELETE));
deleteButton.addClickListener(this::addDeleteButtonClickListener);
return deleteButton;
}
/**
* 创建添加按钮
* @return
*/
private Button createAddButton() {
Button addButton = new Button("添加", FontAwesome.PLUS);
addButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
addButton.addClickListener((Button.ClickListener) clickEvent ->{
zookeeperConsumerAddUI.clearForm();
UI.getCurrent().addWindow(zookeeperConsumerAddUI);
});
return addButton;
}
/**
* 创建查询按钮
* @return
*/
private Button createSearchButton() {
searchButton = new Button("查询",FontAwesome.SEARCH);
searchButton.setStyleName(ValoTheme.BUTTON_PRIMARY);
searchButton.addClickListener((Button.ClickListener) clickEvent -> {
search();
});
return searchButton;
}
/**
* 创建添加按钮
* @return
*/
private Button createAddButton() {
Button addButton = new Button("添加",FontAwesome.PLUS);
addButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
addButton.addClickListener((Button.ClickListener) clickEvent ->{
zookeeperAppAddUI.clearForm();
UI.getCurrent().addWindow(zookeeperAppAddUI);
});
return addButton;
}
public void setIndicator(boolean read, Flag flag) {
MyTheme.MESSAGE_STYLES.forEach(indicatorButton::removeStyleName);
indicatorButton.setIcon(null);
if (flag == Flag.FLAG_STAR) {
indicatorButton.setIcon(FontAwesome.STAR);
if (!read) {
indicatorButton.addStyleName(MyTheme.INDICATOR_STAR_RED);
}
} else if (!read) {
indicatorButton.setIcon(FontAwesome.CIRCLE);
indicatorButton.addStyleName(MyTheme.INDICATOR_CIRCLE);
}
}
/**
* 创建添加按钮
* @return
*/
private Button createAddButton() {
Button addButton = new Button("添加", FontAwesome.PLUS);
addButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
addButton.addClickListener((Button.ClickListener) clickEvent ->{
zookeeperProviderAddUI.clearForm();
UI.getCurrent().addWindow(zookeeperProviderAddUI);
});
return addButton;
}
/**
* 创建保存按钮
* @return
*/
private Button createSaveButton() {
Button saveButton = new Button("保存", FontAwesome.CHECK);
saveButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
saveButton.addClickListener((Button.ClickListener) clickEvent -> {
String name = nameField.getValue();
if (StringUtils.isEmpty(name)) {
Notification.show("提供者名称不能为空!",Notification.Type.ERROR_MESSAGE);
return;
}
String ip = ipField.getValue();
if (StringUtils.isEmpty(ip)) {
Notification.show("IP不能为空!",Notification.Type.ERROR_MESSAGE);
return;
}
String port = portField.getValue();
if (StringUtils.isEmpty(port)) {
Notification.show("端口不能为空!",Notification.Type.ERROR_MESSAGE);
return;
}
//insert data
ZookeeperProvider provider = new ZookeeperProvider();
provider.setName(name);
provider.setIp(ip);
provider.setPort(Integer.parseInt(port));
zookeeperProviderRepository.save(provider);
isAddSuccess = true;
close();
});
return saveButton;
}
private static IndexedContainer getMetadataContainer() {
final IndexedContainer swcontactContainer = new IndexedContainer();
swcontactContainer.addContainerProperty(KEY, String.class, "");
swcontactContainer.addContainerProperty(VALUE, String.class, "");
swcontactContainer.addContainerProperty(DELETE_BUTTON, String.class, FontAwesome.TRASH_O.getHtml());
return swcontactContainer;
}
private Button createShowArtifactDetailsButton() {
artifactDetailsButton = SPUIComponentProvider.getButton(UIComponentIdProvider.UPLOAD_SW_MODULE_SHOW_ARTIFACT_DETAILS_BUTTON, "", "", null, false, FontAwesome.FILE_O,
SPUIButtonStyleNoBorder.class);
artifactDetailsButton.setDescription(getI18n().getMessage(UIMessageIdProvider.TOOLTIP_ARTIFACT_ICON));
artifactDetailsButton.addClickListener(event -> showArtifactDetailsWindow(getSelectedBaseEntity()));
return artifactDetailsButton;
}
/**
* 创建清理按钮
* @return
*/
private Button createClearButton() {
clearButton = new Button("清理", FontAwesome.TRASH);
clearButton.addStyleName(ValoTheme.BUTTON_DANGER);
clearButton.setDisableOnClick(true);
clearButton.addClickListener((Button.ClickListener) clickEvent -> {
Long consumerId = (Long) consumerBox.getValue();
if (consumerId == null) {
Notification.show("请选择消费者!", Notification.Type.ERROR_MESSAGE);
clearButton.setEnabled(true);
return;
}
ZookeeperConsumer consumer = zookeeperConsumerRepository.findOne(consumerId);
if (consumer == null) {
Notification.show("消费者获取失败!", Notification.Type.ERROR_MESSAGE);
clearButton.setEnabled(true);
return;
}
//clear app service
Response response = DubboSwitchTool.clearAppProvider(consumer.getIp() + ":" + consumer.getPort(), appField.getValue());
if (!response.isSuccess()) {
Notification.show(response.getMessage(), Notification.Type.ERROR_MESSAGE);
clearButton.setEnabled(true);
return;
}
updateZookeeperLastInfo(consumer);
clearButton.setEnabled(true);
isClearSuccess = true;
close();
});
return clearButton;
}
private Button createCloseButton() {
final Button button = SPUIComponentProvider.getButton(getCloseButtonId(), "",
i18n.getMessage(UIMessageIdProvider.TOOLTIP_CLOSE), null, false, FontAwesome.TIMES,
SPUIButtonStyleNoBorder.class);
button.addClickListener(this::onClose);
return button;
}
protected void createComponents() {
captionPrefix = new Label(getDefaultCaption());
captionPrefix.setImmediate(true);
captionPrefix.addStyleName(ValoTheme.LABEL_SMALL);
captionPrefix.addStyleName(ValoTheme.LABEL_BOLD);
captionPrefix.setSizeUndefined();
captionNameVersion = new Label();
captionNameVersion.setImmediate(true);
captionNameVersion.setId(getDetailsHeaderCaptionId());
captionNameVersion.setWidth("100%");
captionNameVersion.addStyleName(ValoTheme.LABEL_SMALL);
captionNameVersion.addStyleName("text-bold");
captionNameVersion.addStyleName("text-cut");
captionNameVersion.addStyleName("header-caption-right");
editButton = SPUIComponentProvider.getButton("", "", i18n.getMessage(UIMessageIdProvider.TOOLTIP_UPDATE), null,
false, FontAwesome.PENCIL_SQUARE_O, SPUIButtonStyleNoBorder.class);
editButton.setId(getEditButtonId());
editButton.addClickListener(this::onEdit);
editButton.setEnabled(false);
manageMetadataBtn = SPUIComponentProvider.getButton("", "",
i18n.getMessage(UIMessageIdProvider.TOOLTIP_METADATA_ICON), null, false, FontAwesome.LIST_ALT,
SPUIButtonStyleNoBorder.class);
manageMetadataBtn.setId(getMetadataButtonId());
manageMetadataBtn.setDescription(i18n.getMessage(UIMessageIdProvider.TOOLTIP_METADATA_ICON));
manageMetadataBtn.addClickListener(this::showMetadata);
manageMetadataBtn.setEnabled(false);
detailsTab = SPUIComponentProvider.getDetailsTabSheet();
detailsTab.setImmediate(true);
detailsTab.setWidth(98, Unit.PERCENTAGE);
detailsTab.setHeight(90, Unit.PERCENTAGE);
detailsTab.addStyleName(SPUIStyleDefinitions.DETAILS_LAYOUT_STYLE);
detailsTab.setId(getTabSheetId());
}
/**
* 创建查询按钮
* @return
*/
private Button createSearchButton() {
searchButton = new Button("查询",FontAwesome.SEARCH);
searchButton.setStyleName(ValoTheme.BUTTON_PRIMARY);
searchButton.addClickListener((Button.ClickListener) clickEvent -> {
search();
});
return searchButton;
}
private void closeSearchTextField() {
searchField.setValue("");
searchField.addStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
searchResetIcon.setDescription(i18n.getMessage(UIMessageIdProvider.TOOLTIP_SEARCH));
searchResetIcon.removeStyleName(SPUIDefinitions.FILTER_RESET_ICON);
searchResetIcon.toggleIcon(FontAwesome.SEARCH);
searchResetIcon.setData(Boolean.FALSE);
resetSearchText();
}
public MHorizontalLayout getInvoiceActions(Invoice invoice) {
final MHorizontalLayout actions = new MHorizontalLayout();
if (invoice.getInvoicer() != null) {
final MButton odtDownload = new DownloadButton(
out -> facade.writeAsOdt(invoice, out))
.setFileName(
"invoice_" + invoice.getInvoiceNumber() + ".odt")
.withIcon(FontAwesome.FILE_WORD_O)
.withStyleName(ValoTheme.BUTTON_ICON_ONLY);
final MButton pdfDownload = new DownloadButton(
out -> facade.writeAsPdf(invoice, out))
.setFileName(
"invoice_" + invoice.getInvoiceNumber() + ".pdf")
.withIcon(FontAwesome.FILE_PDF_O)
.withStyleName(ValoTheme.BUTTON_ICON_ONLY);
final MButton sendInvoice = new MButton()
.withIcon(FontAwesome.ENVELOPE_O)
.withStyleName(ValoTheme.BUTTON_ICON_ONLY)
.withListener(e -> sendInvoiceClicked(invoice));
actions.add(odtDownload, pdfDownload, sendInvoice);
}
final MButton deleteButton = new ConfirmButton(
FontAwesome.TRASH_O,
"Are you sure you want to delete this invoice",
e -> {
facade.remove(invoice);
listEntities();
}
).withStyleName(ValoTheme.BUTTON_ICON_ONLY);
actions.add(deleteButton);
return actions;
}
private static String prepareFilterButtonCaption(final String name, final String color) {
final StringBuilder caption = new StringBuilder();
caption.append("<span style=\"color: ").append(color).append(" !important;\">");
caption.append(FontAwesome.CIRCLE.getHtml());
caption.append("</span> ");
caption.append(name);
return caption.toString();
}
private void openSearchTextField() {
searchResetIcon.addStyleName(SPUIDefinitions.FILTER_RESET_ICON);
searchResetIcon.toggleIcon(FontAwesome.TIMES);
searchResetIcon.setData(Boolean.TRUE);
searchResetIcon.setDescription(i18n.getMessage(UIMessageIdProvider.TOOLTIP_RESET));
searchField.removeStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
searchField.focus();
}
private Button getArtifactDeleteButton(final Table table, final Object itemId) {
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
.getItemProperty(PROVIDED_FILE_NAME).getValue();
final Button deleteIcon = SPUIComponentProvider.getButton(
fileName + "-" + UIComponentIdProvider.UPLOAD_FILE_DELETE_ICON, "",
i18n.getMessage(UIMessageIdProvider.CAPTION_DISCARD), ValoTheme.BUTTON_TINY + " " + "blueicon",
true, FontAwesome.TRASH_O, SPUIButtonStyleNoBorder.class);
deleteIcon.setData(itemId);
deleteIcon.addClickListener(event -> confirmAndDeleteArtifact((Long) itemId, fileName));
return deleteIcon;
}
@Nullable
protected static Resource getIconNonCached(String iconName) {
Resource resource = null;
try {
resource = ((Resource) FontAwesome.class
.getDeclaredField(iconName)
.get(null));
} catch (IllegalAccessException | NoSuchFieldException e) {
log.warn("There is no icon with name {} in the FontAwesome icon set", iconName);
}
return resource;
}