use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class EditAction method internalOpenEditor.
protected void internalOpenEditor(CollectionDatasource datasource, Entity existingItem, Datasource parentDs, Map<String, Object> params) {
LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner();
AbstractEditor window = frameOwner.openEditor(getWindowId(), existingItem, getOpenType(), params, parentDs);
if (editorCloseListener == null) {
window.addCloseListener(actionId -> {
// move focus to owner
if (target instanceof Component.Focusable) {
((Component.Focusable) target).focus();
}
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Entity editedItem = window.getItem();
if (editedItem != null) {
if (parentDs == null) {
editedItem = AppBeans.get(GuiActionSupport.class).reloadEntityIfNeeded(editedItem, datasource);
// noinspection unchecked
datasource.updateItem(editedItem);
}
afterCommit(editedItem);
if (afterCommitHandler != null) {
afterCommitHandler.handle(editedItem);
}
}
}
afterWindowClosed(window);
if (afterWindowClosedHandler != null) {
afterWindowClosedHandler.handle(window, actionId);
}
});
} else {
window.addCloseListener(editorCloseListener);
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class EditAction method actionPerform.
/**
* This method is invoked by the action owner component.
*
* @param component component invoking the action
*/
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
final Set selected = target.getSelected();
if (selected.size() == 1) {
Datasource parentDs = null;
final CollectionDatasource datasource = target.getDatasource();
if (datasource instanceof PropertyDatasource) {
MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
parentDs = datasource;
}
}
Map<String, Object> params = prepareWindowParams();
internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
} else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession();
boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
if (isBulkEditorPermitted) {
// if bulk editor integration enabled and permitted for user
Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner();
Window bulkEditor = frameOwner.openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
if (target instanceof Component.Focusable) {
((Component.Focusable) target).focus();
}
Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
if (afterEditorCloseHandler != null) {
afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
}
});
}
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class HasWindowManager method openFrame.
/**
* Load a frame registered in {@code screens.xml} and optionally show it inside a parent component of this
* frame. <br> It is recommended to use {@link Fragments} bean instead.
*
* @param parent if specified, all parent's sub components will be removed and the frame will be added
* @param windowAlias frame ID as defined in {@code screens.xml}
* @param params parameters to be passed into the frame's controller {@code init} method
* @return frame's controller instance
*/
@Deprecated
default Frame openFrame(@Nullable Component parent, String windowAlias, Map<String, Object> params) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
WindowInfo windowInfo = windowConfig.getWindowInfo(windowAlias);
Frame parentFrame;
if (this instanceof LegacyFrame) {
parentFrame = ((LegacyFrame) this).getWrappedFrame();
} else {
parentFrame = ((Frame) this);
}
return getWindowManager().openFrame(parentFrame, parent, windowInfo, params);
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class FilterDelegateImpl method fillTableActions.
/**
* Adds actions of 'Entities Set' functionality to Table component
*/
protected void fillTableActions() {
Table table;
if ((applyTo != null) && (Table.class.isAssignableFrom(applyTo.getClass()))) {
table = (Table) applyTo;
} else {
return;
}
ButtonsPanel buttons = table.getButtonsPanel();
if (buttons == null) {
// in lookup windows, there is no button panel
return;
}
com.haulmont.cuba.gui.components.Button addToSetBtn = (Button) buttons.getComponent("addToSetBtn");
com.haulmont.cuba.gui.components.Button addToCurSetBtn = (Button) buttons.getComponent("addToCurSetBtn");
com.haulmont.cuba.gui.components.Button removeFromCurSetBtn = (Button) buttons.getComponent("removeFromCurSetBtn");
Action addToSet = table.getAction("filter.addToSet");
Action addToCurrSet = table.getAction("filter.addToCurSet");
Action removeFromCurrSet = table.getAction("filter.removeFromCurSet");
if (addToSet != null)
table.removeAction(addToSet);
if (addToSetBtn != null)
addToSetBtn.setVisible(false);
if (addToCurrSet != null) {
table.removeAction(addToCurrSet);
}
if (addToCurSetBtn != null) {
addToCurSetBtn.setVisible(false);
}
if (removeFromCurrSet != null) {
table.removeAction(removeFromCurrSet);
}
if (removeFromCurSetBtn != null) {
removeFromCurSetBtn.setVisible(false);
}
if ((filterEntity != null) && (BooleanUtils.isTrue(filterEntity.getIsSet()))) {
addToSet = table.getAction("addToSet");
if (addToSet != null) {
addToSet.setVisible(false);
}
addToCurrSet = new AddToCurrSetAction();
if (addToCurSetBtn == null) {
addToCurSetBtn = uiComponents.create(Button.class);
addToCurSetBtn.setId("addToCurSetBtn");
addToCurSetBtn.setCaption(getMainMessage("filter.addToCurSet"));
buttons.add(addToCurSetBtn);
} else {
addToCurSetBtn.setVisible(true);
}
if (StringUtils.isEmpty(addToCurSetBtn.getIcon())) {
addToCurSetBtn.setIcon("icons/join-to-set.png");
}
addToCurSetBtn.setAction(addToCurrSet);
table.addAction(addToCurrSet);
removeFromCurrSet = new RemoveFromSetAction(table);
if (removeFromCurSetBtn == null) {
removeFromCurSetBtn = uiComponents.create(Button.class);
removeFromCurSetBtn.setId("removeFromCurSetBtn");
removeFromCurSetBtn.setCaption(getMainMessage("filter.removeFromCurSet"));
buttons.add(removeFromCurSetBtn);
} else {
removeFromCurSetBtn.setVisible(true);
}
if (StringUtils.isEmpty(removeFromCurSetBtn.getIcon())) {
removeFromCurSetBtn.setIcon("icons/delete-from-set.png");
}
removeFromCurSetBtn.setAction(removeFromCurrSet);
table.addAction(removeFromCurrSet);
} else if (filter.getFrame().getFrameOwner() instanceof LegacyFrame) {
addToSet = new AddToSetAction(table);
if (addToSetBtn == null) {
addToSetBtn = uiComponents.create(Button.class);
addToSetBtn.setId("addToSetBtn");
addToSetBtn.setCaption(getMainMessage("filter.addToSet"));
buttons.add(addToSetBtn);
} else {
addToSetBtn.setVisible(true);
}
if (StringUtils.isEmpty(addToSetBtn.getIcon())) {
addToSetBtn.setIcon("icons/insert-to-set.png");
}
addToSetBtn.setAction(addToSet);
table.addAction(addToSet);
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class FakeFilterSupport method createFakeFilter.
public Filter createFakeFilter() {
if (filter != null) {
return filter;
}
Filter fakeFilter = AppBeans.get(ComponentsFactory.NAME, ComponentsFactory.class).createComponent(Filter.class);
Dom4jTools dom4JTools = AppBeans.get(Dom4jTools.NAME);
((HasXmlDescriptor) fakeFilter).setXmlDescriptor(dom4JTools.readDocument("<filter/>").getRootElement());
CollectionDatasourceImpl fakeDatasource = new CollectionDatasourceImpl();
LegacyFrame legacyFrame = (LegacyFrame) this.frameOwner;
DsContextImpl fakeDsContext = new DsContextImpl(legacyFrame.getDsContext().getDataSupplier());
FrameContextImpl fakeFrameContext = new FrameContextImpl((Frame) legacyFrame);
fakeDsContext.setFrameContext(fakeFrameContext);
fakeDatasource.setDsContext(fakeDsContext);
// Attention: this query should match the logic in com.haulmont.reports.wizard.ReportingWizardBean.createJpqlDataSet()
fakeDatasource.setQuery("select queryEntity from " + metaClass.getName() + " queryEntity");
fakeDatasource.setMetaClass(metaClass);
fakeFilter.setDatasource(fakeDatasource);
fakeFilter.setFrame(UiControllerUtils.getFrame(frameOwner));
return fakeFilter;
}
Aggregations