use of com.haulmont.cuba.gui.components.actions.BaseAction in project cuba by cuba-platform.
the class ListEditorDelegateImpl method addClearBtn.
protected void addClearBtn() {
clearBtn = componentsFactory.createComponent(Button.class);
clearBtn.setIconFromSet(CubaIcon.PICKERFIELD_CLEAR);
clearBtn.setStyleName("c-listeditor-button");
clearBtn.setCaption("");
clearBtn.setAction(new BaseAction("clear").withCaption("Clear").withHandler(event -> actualField.setValue(null)));
layout.add(clearBtn);
}
use of com.haulmont.cuba.gui.components.actions.BaseAction in project cuba by cuba-platform.
the class AttributeEditor method initFieldGroup.
protected void initFieldGroup() {
attributeFieldGroup.addCustomField("defaultBoolean", new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
LookupField lookupField = factory.createComponent(LookupField.class);
Map<String, Object> options = new TreeMap<>();
options.put(datatypeFormatter.formatBoolean(true), true);
options.put(datatypeFormatter.formatBoolean(false), false);
lookupField.setOptionsMap(options);
lookupField.setDatasource(attributeDs, "defaultBoolean");
return lookupField;
}
});
attributeFieldGroup.addCustomField("dataType", new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
dataTypeField = factory.createComponent(LookupField.class);
Map<String, Object> options = new TreeMap<>();
PropertyType[] types = PropertyType.values();
for (PropertyType propertyType : types) {
options.put(getMessage(propertyType.toString()), propertyType);
}
dataTypeField.setWidth(fieldWidth);
dataTypeField.setNewOptionAllowed(false);
dataTypeField.setRequired(true);
dataTypeField.setRequiredMessage(getMessage("dataTypeRequired"));
dataTypeField.setOptionsMap(options);
dataTypeField.setCaption(getMessage("dataType"));
dataTypeField.setFrame(frame);
dataTypeField.setDatasource(datasource, propertyId);
return dataTypeField;
}
});
attributeFieldGroup.addCustomField("screen", new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
screenField = factory.createComponent(LookupField.class);
screenField.setId("screenField");
screenField.setCaption(getMessage("screen"));
screenField.setWidth(fieldWidth);
screenField.setRequired(true);
screenField.setRequiredMessage(getMessage("entityScreenRequired"));
screenField.setFrame(frame);
screenField.setDatasource(datasource, propertyId);
return screenField;
}
});
attributeFieldGroup.addCustomField("entityClass", new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
entityTypeField = factory.createComponent(LookupField.class);
entityTypeField.setId("entityClass");
entityTypeField.setCaption(getMessage("entityType"));
entityTypeField.setRequired(true);
entityTypeField.setRequiredMessage(getMessage("entityTypeRequired"));
entityTypeField.setWidth(fieldWidth);
entityTypeField.setFrame(frame);
Map<String, Object> options = new TreeMap<>();
MetaClass entityType = null;
for (MetaClass metaClass : metadataTools.getAllPersistentMetaClasses()) {
if (!metadataTools.isSystemLevel(metaClass)) {
if (metadata.getTools().hasCompositePrimaryKey(metaClass) && !HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) {
continue;
}
options.put(messageTools.getDetailedEntityCaption(metaClass), metaClass.getJavaClass().getName());
if (attribute != null && metaClass.getJavaClass().getName().equals(attribute.getEntityClass())) {
entityType = metaClass;
}
}
}
entityTypeField.setOptionsMap(options);
entityTypeField.setValue(entityType);
entityTypeField.setDatasource(datasource, propertyId);
return entityTypeField;
}
});
attributeFieldGroup.addCustomField("defaultEntityId", (datasource, propertyId) -> {
defaultEntityField = factory.createComponent(PickerField.class);
defaultEntityField.setCaption(messages.getMessage(CategoryAttribute.class, "CategoryAttribute.defaultEntityId"));
defaultEntityField.addValueChangeListener(e -> {
Entity entity = (Entity) e.getValue();
if (entity != null) {
attribute.setObjectDefaultEntityId(referenceToEntitySupport.getReferenceId(entity));
} else {
attribute.setObjectDefaultEntityId(null);
}
((AbstractDatasource) attributeDs).modified(attribute);
});
entityLookupAction = defaultEntityField.addLookupAction();
defaultEntityField.addClearAction();
return defaultEntityField;
});
attributeFieldGroup.addCustomField("enumeration", (datasource, propertyId) -> {
enumerationListEditor = factory.createComponent(ListEditor.class);
enumerationListEditor.setWidth("100%");
enumerationListEditor.setItemType(ListEditor.ItemType.STRING);
enumerationListEditor.setRequired(true);
enumerationListEditor.setRequiredMessage(getMessage("enumRequired"));
enumerationListEditor.addValueChangeListener(e -> {
List<String> value = (List<String>) e.getValue();
attribute.setEnumeration(Joiner.on(",").join(value));
});
if (localizedFrame != null) {
enumerationListEditor.setEditorWindowId("localizedEnumerationWindow");
enumerationListEditor.setEditorParamsSupplier(() -> ParamsMap.of("enumerationLocales", attribute.getEnumerationLocales()));
enumerationListEditor.addEditorCloseListener(closeEvent -> {
if (closeEvent.getActionId().equals(COMMIT_ACTION_ID)) {
LocalizedEnumerationWindow enumerationWindow = (LocalizedEnumerationWindow) closeEvent.getWindow();
attribute.setEnumerationLocales(enumerationWindow.getLocalizedValues());
}
});
}
return enumerationListEditor;
});
attributeFieldGroup.addCustomField("whereClause", (datasource, propertyId) -> {
whereField = factory.createComponent(SourceCodeEditor.class);
whereField.setDatasource(attributeDs, "whereClause");
whereField.setWidth("100%");
whereField.setHeight(themeConstants.get("cuba.gui.customConditionFrame.whereField.height"));
whereField.setSuggester((source, text, cursorPosition) -> requestHint(whereField, text, cursorPosition));
whereField.setHighlightActiveLine(false);
whereField.setShowGutter(false);
return whereField;
});
attributeFieldGroup.addCustomField("joinClause", (datasource, propertyId) -> {
joinField = factory.createComponent(SourceCodeEditor.class);
joinField.setDatasource(attributeDs, "joinClause");
joinField.setWidth("100%");
joinField.setHeight(themeConstants.get("cuba.gui.customConditionFrame.joinField.height"));
joinField.setSuggester((source, text, cursorPosition) -> requestHint(joinField, text, cursorPosition));
joinField.setHighlightActiveLine(false);
joinField.setShowGutter(false);
return joinField;
});
attributeFieldGroup.addCustomField("constraintWizard", (datasource, propertyId) -> {
HBoxLayout hbox = factory.createComponent(HBoxLayout.class);
hbox.setWidth("100%");
LinkButton linkButton = factory.createComponent(LinkButton.class);
linkButton.setAction(new BaseAction("constraintWizard").withHandler(event -> openConstraintWizard()));
linkButton.setCaption(getMessage("constraintWizard"));
linkButton.setAlignment(Alignment.MIDDLE_LEFT);
hbox.add(linkButton);
return hbox;
});
attributeDs.addItemPropertyChangeListener(e -> {
String property = e.getProperty();
CategoryAttribute attribute = getItem();
if ("dataType".equalsIgnoreCase(property) || "lookup".equalsIgnoreCase(property) || "defaultDateIsCurrent".equalsIgnoreCase(property) || "entityClass".equalsIgnoreCase(property)) {
setupVisibility();
}
if ("name".equalsIgnoreCase(property)) {
fillAttributeCode();
}
if ("screen".equalsIgnoreCase(property) || "joinClause".equals(property) || "whereClause".equals(property)) {
dynamicAttributesGuiTools.initEntityPickerField(defaultEntityField, attribute);
}
});
}
use of com.haulmont.cuba.gui.components.actions.BaseAction in project cuba by cuba-platform.
the class DesktopWindow method close.
@Override
public boolean close(final String actionId) {
if (!forceClose) {
if (!delegate.preClose(actionId))
return false;
}
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
if (!forceClose && isModified()) {
final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null;
if ((committable != null) && clientConfig.getUseSaveConfirmation()) {
windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.OK, Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(event -> {
committable.commitAndClose();
}), new BaseAction("discard").withIcon("icons/cancel.png").withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(event -> {
committable.close(actionId, true);
}), new DialogAction(Type.CANCEL).withIcon(null).withHandler(event -> {
doAfterClose = null;
}) });
} else {
windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("closeUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.YES).withHandler(event -> {
getWrapper().close(actionId, true);
}), new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
doAfterClose = null;
}) });
}
return false;
}
if (!clientConfig.getManualScreenSettingsSaving()) {
if (delegate.getWrapper() != null) {
delegate.getWrapper().saveSettings();
} else {
saveSettings();
}
}
delegate.disposeComponents();
windowManager.close(this);
boolean res = onClose(actionId);
if (res && doAfterClose != null) {
doAfterClose.run();
}
stopTimers();
userActionsLog.trace("Window {} was closed", getId());
return res;
}
use of com.haulmont.cuba.gui.components.actions.BaseAction in project cuba by cuba-platform.
the class WebWindowManager method checkModificationsAndCloseAll.
/**
* Check modifications and close all screens in all main windows.
*
* @param runIfOk a closure to run after all screens are closed
* @param runIfCancel a closure to run if there were modifications and a user canceled the operation
*/
public void checkModificationsAndCloseAll(final Runnable runIfOk, @Nullable final Runnable runIfCancel) {
boolean modified = false;
for (Window window : getOpenWindows()) {
if (!disableSavingScreenHistory) {
screenHistorySupport.saveScreenHistory(window, windowOpenMode.get(window).getOpenMode());
}
if (window instanceof WrappedWindow && ((WrappedWindow) window).getWrapper() != null) {
((WrappedWindow) window).getWrapper().saveSettings();
} else {
window.saveSettings();
}
if (window.getDsContext() != null && window.getDsContext().isModified()) {
modified = true;
}
}
disableSavingScreenHistory = true;
if (modified) {
showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesOnClose"), MessageType.WARNING, new Action[] { new BaseAction("closeApplication").withCaption(messages.getMainMessage("closeApplication")).withIcon(icons.get(CubaIcon.DIALOG_OK)).withHandler(event -> {
closeAllWindows();
runIfOk.run();
}), new DialogAction(Type.CANCEL, Status.PRIMARY).withHandler(event -> {
if (runIfCancel != null) {
runIfCancel.run();
}
}) });
} else {
closeAllWindows();
runIfOk.run();
}
}
use of com.haulmont.cuba.gui.components.actions.BaseAction in project cuba by cuba-platform.
the class CategoryBrowser method init.
@Override
public void init(Map<String, Object> params) {
categoryTable.addAction(new CreateAction());
categoryTable.addAction(new EditAction());
categoryTable.addAction(new RemoveAction(categoryTable));
categoryTable.addAction(new BaseAction("applyChanges").withCaption(getMessage("categoryTable.applyChanges")).withHandler(actionPerformedEvent -> {
dynamicAttributesCacheService.loadCache();
clientCacheManager.refreshCached(DynamicAttributesCacheStrategy.NAME);
permissionConfig.clearConfigCache();
showNotification(getMessage("notification.changesApplied"));
}));
categoryTable.removeGeneratedColumn("entityType");
categoryTable.addGeneratedColumn("entityType", entity -> {
Label dataTypeLabel = componentsFactory.createComponent(Label.class);
MetaClass meta = metadata.getSession().getClassNN(entity.getEntityType());
dataTypeLabel.setValue(messageTools.getEntityCaption(meta));
return dataTypeLabel;
});
}
Aggregations