use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class UiControllerPropertyInjector method findDatasource.
@Nullable
protected Datasource findDatasource(String datasourceId) {
Datasource datasource = null;
if (sourceScreen instanceof LegacyFrame) {
((LegacyFrame) sourceScreen).getDsContext().get(datasourceId);
}
FrameOwner frameOwner = this.frameOwner instanceof ScreenFragment ? ((ScreenFragment) this.frameOwner).getHostController() : this.frameOwner;
if (frameOwner instanceof LegacyFrame) {
datasource = ((LegacyFrame) frameOwner).getDsContext().get(datasourceId);
}
return datasource;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class UiControllerPropertyInjector method findComponent.
@Nullable
protected Component findComponent(String componentId) {
Component component = null;
Window window = null;
if (sourceScreen != null) {
window = sourceScreen.getWindow();
} else if (frameOwner instanceof ScreenFragment) {
FrameOwner host = ((ScreenFragment) frameOwner).getHostController();
if (host instanceof Screen) {
window = ((Screen) host).getWindow();
}
} else if (frameOwner instanceof Screen) {
window = ((Screen) frameOwner).getWindow();
}
if (window != null) {
component = window.getComponent(componentId);
}
return component;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class WebSuggestionPickerField method showSuggestions.
protected void showSuggestions(List<V> suggestions, boolean userOriginated) {
FrameOwner frameOwner = getFrame().getFrameOwner();
Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
Screen lastDialog = null;
for (Screen dialogScreen : dialogScreens) {
lastDialog = dialogScreen;
}
if (frameOwner instanceof ScreenFragment) {
frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
}
if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
getComponent().showSuggestions(suggestions, userOriginated);
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class DeclarativeAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (StringUtils.isEmpty(methodName)) {
return;
}
FrameOwner controller = frame.getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
Method method;
try {
method = controller.getClass().getMethod(methodName, Component.class);
} catch (NoSuchMethodException e) {
try {
method = controller.getClass().getMethod(methodName);
} catch (NoSuchMethodException e1) {
throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
}
}
try {
if (method.getParameterCount() == 1) {
method.invoke(controller, component);
} else {
method.invoke(controller);
}
} catch (Exception e) {
throw new RuntimeException("Exception on action handling", e);
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class DeclarativeFieldGenerator method generateField.
@Override
public Component generateField(Datasource datasource, String propertyId) {
Frame frame = fieldGroup.getFrame();
if (frame == null) {
throw new IllegalStateException("Table should be attached to frame");
}
FrameOwner controller = frame.getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
Class<? extends FrameOwner> cCls = controller.getClass();
Method exactMethod = getAccessibleMethod(cCls, methodName, Datasource.class, String.class);
if (exactMethod != null) {
checkGeneratorMethodResultType(exactMethod, frame);
try {
return (Component) exactMethod.invoke(controller, datasource, propertyId);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
}
}
Method dsMethod = getAccessibleMethod(cCls, methodName, Datasource.class);
if (dsMethod != null) {
checkGeneratorMethodResultType(dsMethod, frame);
try {
return (Component) dsMethod.invoke(controller, datasource);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
}
}
Method parameterLessMethod = getAccessibleMethod(cCls, methodName);
if (parameterLessMethod != null) {
checkGeneratorMethodResultType(parameterLessMethod, frame);
try {
return (Component) parameterLessMethod.invoke(controller);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
}
}
String fieldGroupId = fieldGroup.getId() == null ? "" : fieldGroup.getId();
throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, fieldGroupId));
}
Aggregations