use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class WindowCreationHelper method applyCompositeComponentPermission.
private static void applyCompositeComponentPermission(Window window, String screenId, Integer permissionValue, String componentId) {
final Matcher matcher = INNER_COMPONENT_PATTERN.matcher(componentId);
if (matcher.find()) {
final String customComponentId = matcher.group(1);
final String subComponentId = matcher.group(2);
final Component compositeComponent = window.getComponent(customComponentId);
if (compositeComponent != null) {
if (compositeComponent instanceof Component.UiPermissionAware) {
Component.UiPermissionAware uiPermissionAwareComponent = (Component.UiPermissionAware) compositeComponent;
UiPermissionValue uiPermissionValue = UiPermissionValue.fromId(permissionValue);
UiPermissionDescriptor permissionDescriptor;
if (subComponentId.contains("<")) {
final Matcher actionMatcher = COMPONENT_ACTION_PATTERN.matcher(subComponentId);
if (actionMatcher.find()) {
final String actionHolderComponentId = actionMatcher.group(1);
final String actionId = actionMatcher.group(2);
permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, actionHolderComponentId, actionId);
} else {
log.warn(String.format("Incorrect permission definition for component %s in window %s", subComponentId, screenId));
return;
}
} else {
permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, subComponentId);
}
uiPermissionAwareComponent.applyPermission(permissionDescriptor);
}
} else {
log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
}
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class LinkColumnHelper method initColumn.
public static void initColumn(Table table, final String propertyName, final Handler handler) {
final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {
@Override
public Component generateCell(final Entity entity) {
// //process properties like building.house.room
String[] props = propertyName.split("\\.");
Instance nestedEntity = entity;
for (int i = 0; i < props.length - 1; i++) {
nestedEntity = nestedEntity.getValue(props[i]);
if (nestedEntity == null) {
break;
}
}
final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
if (value != null) {
Button button = componentsFactory.createComponent(Button.class);
button.setStyleName("link");
button.setAction(new AbstractAction("open") {
@Override
public void actionPerform(Component component) {
handler.onClick(entity);
}
@Override
public String getCaption() {
String str;
Datatype datatype = Datatypes.get(value.getClass());
if (datatype != null) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
str = datatype.format(value, sessionSource.getLocale());
} else {
str = value.toString();
}
return str;
}
});
button.setStyleName("link");
return button;
}
return null;
}
});
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class SessionAttributeEditor method init.
@Override
public void init(Map<String, Object> params) {
datasource = getDsContext().get("attribute");
FieldGroup fields = (FieldGroup) getComponent("fields");
FieldGroup.FieldConfig field = fields.getField("datatype");
fields.addCustomField(field, new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
LookupField lookup = AppConfig.getFactory().createComponent(LookupField.class);
lookup.setDatasource(datasource, propertyId);
lookup.setRequiredMessage(getMessage("datatypeMsg"));
lookup.setRequired(true);
lookup.setPageLength(15);
Map<String, Object> options = new TreeMap<>();
String mainMessagePack = AppConfig.getMessagesPack();
for (String datatypeId : Datatypes.getIds()) {
options.put(messages.getMessage(mainMessagePack, "Datatype." + datatypeId), datatypeId);
}
lookup.setOptionsMap(options);
return lookup;
}
});
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DesktopPopupButton method showPopup.
protected void showPopup() {
popup.removeAll();
for (final Action action : actionList) {
if (action.isVisible()) {
final JMenuItem menuItem = new JMenuItem(action.getCaption());
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
action.actionPerform((Component) action.getOwner());
}
});
menuItem.setEnabled(action.isEnabled());
menuItem.setName(action.getId());
initAction(action, menuItem);
popup.add(menuItem);
}
}
int popupHeight = popup.getComponentCount() * 25;
Point pt = new Point();
SwingUtilities.convertPointToScreen(pt, impl);
int y;
if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
y = impl.getHeight();
} else {
y = -popupHeight;
}
// do not show ugly empty popup
if (popup.getComponentCount() > 0) {
popup.show(impl, 0, y);
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DesktopScrollBoxLayout method updateEnabled.
@Override
public void updateEnabled() {
super.updateEnabled();
boolean resultEnabled = isEnabledWithParent();
for (Component component : components) {
if (component instanceof DesktopAbstractComponent) {
((DesktopAbstractComponent) component).setParentEnabled(resultEnabled);
}
}
}
Aggregations