Skip to content

Commit

Permalink
NPE is thrown from Filter inside of frame on new window initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaurite committed Apr 2, 2019
1 parent 25dbc0d commit 704a507
Showing 1 changed file with 51 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.haulmont.cuba.gui.components.Action.Status;
import com.haulmont.cuba.gui.components.Component.Alignment;
import com.haulmont.cuba.gui.components.DialogAction.Type;
import com.haulmont.cuba.gui.components.Frame.MessageType;
import com.haulmont.cuba.gui.components.KeyCombination.Key;
import com.haulmont.cuba.gui.components.actions.BaseAction;
import com.haulmont.cuba.gui.components.actions.ItemTrackingAction;
Expand Down Expand Up @@ -103,8 +102,6 @@ public class FilterDelegateImpl implements FilterDelegate {
@Inject
protected Messages messages;
@Inject
protected WindowManagerProvider windowManagerProvider;
@Inject
protected Metadata metadata;
@Inject
protected WindowConfig windowConfig;
Expand Down Expand Up @@ -137,7 +134,6 @@ public class FilterDelegateImpl implements FilterDelegate {
protected FtsFilterHelper ftsFilterHelper;
protected AddConditionHelper addConditionHelper;
protected ThemeConstants theme;
protected WindowManager windowManager;

protected Filter filter;
protected FilterEntity adHocFilter;
Expand Down Expand Up @@ -233,7 +229,6 @@ public void setScreenBuilders(ScreenBuilders screenBuilders) {
@PostConstruct
public void init() {
theme = themeConstantsManager.getConstants();
windowManager = windowManagerProvider.get();
if (beanLocator.containsBean(FtsFilterHelper.NAME)) {
ftsFilterHelper = beanLocator.get(FtsFilterHelper.class);
}
Expand Down Expand Up @@ -516,9 +511,10 @@ public void loadFiltersAndApplyDefault() {
setFilterEntity(defaultFilter);
} catch (Exception e) {
log.error("Exception on loading default filter '{}'", defaultFilter.getName(), e);
windowManager.showNotification(
messages.formatMainMessage("filter.errorLoadingDefaultFilter", defaultFilter.getName()),
Frame.NotificationType.ERROR);
getNotifications().create(Notifications.NotificationType.ERROR)
.withCaption(messages.formatMainMessage("filter.errorLoadingDefaultFilter"))
.withDescription(defaultFilter.getName())
.show();
defaultFilter = adHocFilter;
setFilterEntity(adHocFilter);
}
Expand Down Expand Up @@ -573,8 +569,9 @@ public void setFilterEntity(FilterEntity filterEntity) {
if (!suitableCondition(condition)) {
String message = String.format(getMainMessage("filter.inappropriate.filter"),
filterEntity.getName(), adapter.getMetaClass().getName());

windowManager.showNotification(message, Frame.NotificationType.HUMANIZED);
getNotifications().create(Notifications.NotificationType.HUMANIZED)
.withCaption(message)
.show();
setFilterEntity(adHocFilter);
break;
}
Expand Down Expand Up @@ -1180,7 +1177,7 @@ protected void addShowMoreFilterEntitiesAction(PopupButton popupButton) {
@Override
public void actionPerform(Component component) {
WindowInfo windowInfo = windowConfig.getWindowInfo("filterSelect");
FilterSelectWindow window = (FilterSelectWindow) windowManager.openWindow(windowInfo,
FilterSelectWindow window = (FilterSelectWindow) getWindowManager().openWindow(windowInfo,
OpenType.DIALOG,
ParamsMap.of("filterEntities", filterEntities));

Expand Down Expand Up @@ -1299,21 +1296,19 @@ protected void removeAppliedFilter() {
adapter.unpinAllQuery();
this.layout.remove(appliedFiltersLayout);
} else {
windowManager.showOptionDialog(
messages.getMainMessage("removeApplied.title"),
messages.getMainMessage("removeApplied.message"),
MessageType.WARNING,
new Action[]{
new DialogAction(Type.YES).withHandler(event -> {
getDialogs().createOptionDialog(Dialogs.MessageType.WARNING)
.withCaption(messages.getMainMessage("removeApplied.title"))
.withMessage(messages.getMainMessage("removeApplied.message"))
.withActions(new DialogAction(Type.YES).withHandler(event -> {
for (AppliedFilterHolder holder : appliedFilters) {
appliedFiltersLayout.remove(holder.layout);
FilterDelegateImpl.this.layout.remove(appliedFiltersLayout);
}
appliedFilters.clear();
adapter.unpinAllQuery();
}),
new DialogAction(Type.NO, Status.PRIMARY)
});
new DialogAction(Type.NO, Status.PRIMARY))
.show();
}
}
}
Expand Down Expand Up @@ -1544,8 +1539,9 @@ public boolean apply(Filter.FilterOptions options) {
boolean haveCorrectCondition = hasCorrectCondition();
if (!haveCorrectCondition) {
if (!options.isNotifyInvalidConditions()) {
windowManager.showNotification(messages.getMainMessage("filter.emptyConditions"),
Frame.NotificationType.HUMANIZED);
getNotifications().create(Notifications.NotificationType.HUMANIZED)
.withCaption(messages.getMainMessage("filter.emptyConditions"))
.show();
}
return false;
}
Expand All @@ -1562,8 +1558,9 @@ public boolean apply(Filter.FilterOptions options) {
boolean haveRequiredConditions = haveFilledRequiredConditions();
if (!haveRequiredConditions) {
if (!options.isNotifyInvalidConditions()) {
windowManager.showNotification(messages.getMainMessage("filter.emptyRequiredConditions"),
Frame.NotificationType.HUMANIZED);
getNotifications().create(Notifications.NotificationType.HUMANIZED)
.withCaption(messages.getMainMessage("filter.emptyRequiredConditions"))
.show();
}
return false;
}
Expand Down Expand Up @@ -1635,7 +1632,9 @@ protected void applyFts() {

String searchTerm = ftsSearchCriteriaField.getValue();
if (Strings.isNullOrEmpty(searchTerm) && clientConfig.getGenericFilterChecking()) {
windowManager.showNotification(getMainMessage("filter.fillSearchCondition"), Frame.NotificationType.TRAY);
getNotifications().create(Notifications.NotificationType.TRAY)
.withCaption(getMainMessage("filter.fillSearchCondition"))
.show();
return;
}

Expand Down Expand Up @@ -2203,7 +2202,7 @@ protected void updateWindowCaption() {
initialWindowCaption = window.getCaption();
}

windowManager.setWindowCaption(window, initialWindowCaption, filterTitle);
getWindowManager().setWindowCaption(window, initialWindowCaption, filterTitle);

String newCaption = Strings.isNullOrEmpty(filterTitle) ? caption : caption + ": " + filterTitle;
captionChangedListener.accept(newCaption);
Expand Down Expand Up @@ -2284,7 +2283,7 @@ public void actionPerform(Component component) {
if (!getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) {
params.put("filterName", filterEntity.getName());
}
final SaveFilterWindow window = (SaveFilterWindow) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
final SaveFilterWindow window = (SaveFilterWindow) getWindowManager().openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
String filterName = window.getFilterName();
Expand Down Expand Up @@ -2346,7 +2345,7 @@ public void actionPerform(Component component) {
.collect(Collectors.toList())
);

final SaveFilterWindow window = (SaveFilterWindow) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
final SaveFilterWindow window = (SaveFilterWindow) getWindowManager().openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
String filterName = window.getFilterName();
Expand Down Expand Up @@ -2397,7 +2396,7 @@ public void actionPerform(Component component) {
params.put("filter", filter);
params.put("conditions", conditions);

FilterEditor window = (FilterEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
FilterEditor window = (FilterEditor) getWindowManager().openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
conditions = window.getConditions();
Expand Down Expand Up @@ -2466,19 +2465,17 @@ public RemoveAction() {
@Override
public void actionPerform(Component component) {
if (filterEntity == adHocFilter) return;
windowManager.showOptionDialog(
getMainMessage("filter.removeDialogTitle"),
getMainMessage("filter.removeDialogMessage"),
MessageType.CONFIRMATION,
new Action[]{
new DialogAction(Type.YES).withHandler(event -> {
getDialogs().createOptionDialog(Dialogs.MessageType.CONFIRMATION)
.withCaption(getMainMessage("filter.removeDialogTitle"))
.withMessage(getMainMessage("filter.removeDialogMessage"))
.withActions(new DialogAction(Type.YES).withHandler(event -> {
removeFilterEntity();
settingsBtn.focus();
}),
new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
settingsBtn.focus();
})
});
}))
.show();
}

@Override
Expand Down Expand Up @@ -2530,6 +2527,23 @@ protected void removeFilterEntity() {
updateWindowCaption();
}

@Nullable
protected WindowManager getWindowManager() {
Window window = ComponentsHelper.getWindow(filter);
if (window != null) {
return window.getWindowManager();
}
return null;
}

protected Notifications getNotifications() {
return ComponentsHelper.getScreenContext(filter).getNotifications();
}

protected Dialogs getDialogs() {
return ComponentsHelper.getScreenContext(filter).getDialogs();
}

protected class PinAppliedAction extends AbstractAction {

public PinAppliedAction() {
Expand Down Expand Up @@ -2659,7 +2673,7 @@ public void actionPerform(Component component) {
removeFilterEntity();

Window window = ComponentsHelper.getWindow(filter);
windowManager.close(window);
window.getWindowManager().close(window);
} else {
String filterXml = filterEntity.getXml();
filterEntity.setXml(UserSetHelper.removeEntities(filterXml, selected));
Expand Down

0 comments on commit 704a507

Please sign in to comment.