mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-08 03:52:18 +00:00
bug3529 Adjusted ComponentContext to accept a Component as root
component with settings
This commit is contained in:
1 parent
1a2961f15b
commit
7ab14d599e
14 files changed
+144
-136
No files matched your search
+9
-8
@@ -2,25 +2,26 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
import com.sap.sse.gwt.client.shared.components.Component;
|
||||
import com.sap.sse.gwt.client.shared.components.ComponentLifecycle;
|
||||
|
||||
public abstract class AbstractComponentContext<PL extends PerspectiveLifecycle<PS>, PS extends Settings> {
|
||||
public abstract class AbstractComponentContext<L extends ComponentLifecycle<S, ?>, S extends Settings> {
|
||||
|
||||
protected final PL rootPerspectiveLifecycle;
|
||||
protected final L rootLifecycle;
|
||||
|
||||
public AbstractComponentContext(PL rootPerspectiveLifecycle) {
|
||||
this.rootPerspectiveLifecycle = rootPerspectiveLifecycle;
|
||||
public AbstractComponentContext(L rootLifecycle) {
|
||||
this.rootLifecycle = rootLifecycle;
|
||||
}
|
||||
|
||||
public void makeSettingsDefault(Component<? extends Settings> component, Settings newDefaultSettings) {
|
||||
throw new UnsupportedOperationException("Make Default action is unsupported for this type of ComponentContext");
|
||||
}
|
||||
|
||||
public PL getRootPerspectiveLifecycle() {
|
||||
return rootPerspectiveLifecycle;
|
||||
public L getRootLifecycle() {
|
||||
return rootLifecycle;
|
||||
}
|
||||
|
||||
public PerspectiveCompositeSettings<PS> getDefaultSettingsForRootPerspective() {
|
||||
return rootPerspectiveLifecycle.createDefaultSettings();
|
||||
public S getDefaultSettings() {
|
||||
return rootLifecycle.createDefaultSettings();
|
||||
}
|
||||
|
||||
public boolean hasMakeCustomDefaultSettingsSupport(Component<?> component) {
|
||||
|
||||
+42
-29
@@ -8,36 +8,37 @@ import com.sap.sse.common.settings.Settings;
|
||||
import com.sap.sse.common.settings.generic.GenericSerializableSettings;
|
||||
import com.sap.sse.common.settings.generic.SettingsMap;
|
||||
import com.sap.sse.gwt.client.shared.components.Component;
|
||||
import com.sap.sse.gwt.client.shared.components.ComponentLifecycle;
|
||||
|
||||
public abstract class AbstractComponentContextWithSettingsStorage<PL extends PerspectiveLifecycle<PS>, PS extends Settings> extends AbstractComponentContext<PL, PS> {
|
||||
public abstract class AbstractComponentContextWithSettingsStorage<L extends ComponentLifecycle<S, ?>, S extends Settings> extends AbstractComponentContext<L, S> {
|
||||
|
||||
private final SettingsStorageManager<PS> settingsStorageManager;
|
||||
private final SettingsStorageManager<S> settingsStorageManager;
|
||||
|
||||
/**
|
||||
* Current default settings for the whole settings tree.
|
||||
*/
|
||||
private PerspectiveCompositeSettings<PS> currentDefaultSettings = null;
|
||||
private S currentDefaultSettings = null;
|
||||
|
||||
public AbstractComponentContextWithSettingsStorage(PL rootPerspectiveLifecycle, SettingsStorageManager<PS> settingsStorageManager) {
|
||||
super(rootPerspectiveLifecycle);
|
||||
public AbstractComponentContextWithSettingsStorage(L rootLifecycle, SettingsStorageManager<S> settingsStorageManager) {
|
||||
super(rootLifecycle);
|
||||
this.settingsStorageManager = settingsStorageManager;
|
||||
}
|
||||
|
||||
public void initDefaultSettings(final DefaultSettingsLoadedCallback<PS> asyncCallback) {
|
||||
public void initDefaultSettings(final DefaultSettingsLoadedCallback<S> asyncCallback) {
|
||||
if(currentDefaultSettings != null) {
|
||||
throw new IllegalStateException("Settings have been already initialized. You may only call this method once.");
|
||||
}
|
||||
PerspectiveCompositeSettings<PS> systemDefaultSettings = rootPerspectiveLifecycle.createDefaultSettings();
|
||||
settingsStorageManager.retrieveDefaultSettings(systemDefaultSettings, new DefaultSettingsLoadedCallback<PS>() {
|
||||
S systemDefaultSettings = rootLifecycle.createDefaultSettings();
|
||||
settingsStorageManager.retrieveDefaultSettings(systemDefaultSettings, new DefaultSettingsLoadedCallback<S>() {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable caught, PerspectiveCompositeSettings<PS> fallbackDefaultSettings) {
|
||||
public void onError(Throwable caught, S fallbackDefaultSettings) {
|
||||
asyncCallback.onError(caught, fallbackDefaultSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PerspectiveCompositeSettings<PS> result) {
|
||||
currentDefaultSettings = rootPerspectiveLifecycle.cloneSettings(result);
|
||||
public void onSuccess(S result) {
|
||||
currentDefaultSettings = rootLifecycle.cloneSettings(result);
|
||||
asyncCallback.onSuccess(result);
|
||||
}
|
||||
});
|
||||
@@ -48,36 +49,48 @@ public abstract class AbstractComponentContextWithSettingsStorage<PL extends Per
|
||||
public void makeSettingsDefault(Component<? extends Settings> component, Settings newDefaultSettings) {
|
||||
Perspective<? extends Settings> parentPerspective = component.getComponentTreeNodeInfo().getParentPerspective();
|
||||
|
||||
final PerspectiveCompositeSettings<PS> newRootPerspectiveSettings;
|
||||
final S newRootSettings;
|
||||
if(parentPerspective == null) {
|
||||
//root perspective is updating its perspective own settings
|
||||
Perspective<PS> rootPerspective = (Perspective<PS>) component;
|
||||
newRootPerspectiveSettings = (PerspectiveCompositeSettings<PS>)newDefaultSettings;
|
||||
rootPerspective.getPerspectiveLifecycleWithAllSettings().setAllSettings(newRootPerspectiveSettings);
|
||||
if(component instanceof Perspective) {
|
||||
//root perspective is updating its perspective own settings
|
||||
Perspective<? extends Settings> rootPerspective = (Perspective<? extends Settings>) component;
|
||||
setPerspectiveSettingsHelper(rootPerspective, newDefaultSettings);
|
||||
newRootSettings = (S) newDefaultSettings;
|
||||
} else {
|
||||
//root is a single component
|
||||
newRootSettings = (S) newDefaultSettings;
|
||||
}
|
||||
} else {
|
||||
newRootPerspectiveSettings = (PerspectiveCompositeSettings<PS>) updatePerspectiveLifecycleWithAllSettings(parentPerspective, component, newDefaultSettings);
|
||||
// propagate updated settings to parent and get root settings
|
||||
newRootSettings = (S) propagateSettingsToRootPerspective(parentPerspective, component, newDefaultSettings);
|
||||
}
|
||||
this.currentDefaultSettings = rootPerspectiveLifecycle.cloneSettings(newRootPerspectiveSettings);
|
||||
storeNewDefaultSettings(newRootPerspectiveSettings);
|
||||
this.currentDefaultSettings = rootLifecycle.cloneSettings(newRootSettings);
|
||||
storeNewDefaultSettings(newRootSettings);
|
||||
}
|
||||
|
||||
private void storeNewDefaultSettings(PerspectiveCompositeSettings<PS> newRootPerspectiveSettings) {
|
||||
PerspectiveCompositeSettings<PS> globalSettings = extractGlobalSettings(newRootPerspectiveSettings);
|
||||
private static<PS extends Settings> void setPerspectiveSettingsHelper(Perspective<PS> perspective, Settings newPerspectiveSettings) {
|
||||
@SuppressWarnings("unchecked")
|
||||
PerspectiveCompositeSettings<PS> newRootSettings = (PerspectiveCompositeSettings<PS>)newPerspectiveSettings;
|
||||
perspective.getPerspectiveLifecycleWithAllSettings().setAllSettings(newRootSettings);
|
||||
}
|
||||
|
||||
private void storeNewDefaultSettings(S newRootSettings) {
|
||||
S globalSettings = extractGlobalSettings(newRootSettings);
|
||||
if(globalSettings != null) {
|
||||
settingsStorageManager.storeGlobalSettings(globalSettings);
|
||||
}
|
||||
PerspectiveCompositeSettings<PS> contextSpecificSettings = extractContextSpecificSettings(newRootPerspectiveSettings);
|
||||
S contextSpecificSettings = extractContextSpecificSettings(newRootSettings);
|
||||
if(contextSpecificSettings != null) {
|
||||
settingsStorageManager.storeContextSpecificSettings(contextSpecificSettings);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PerspectiveCompositeSettings<PS> extractContextSpecificSettings(PerspectiveCompositeSettings<PS> newRootPerspectiveSettings);
|
||||
protected abstract S extractContextSpecificSettings(S newRootSettings);
|
||||
|
||||
protected abstract PerspectiveCompositeSettings<PS> extractGlobalSettings(
|
||||
PerspectiveCompositeSettings<PS> newRootPerspectiveSettings);
|
||||
protected abstract S extractGlobalSettings(
|
||||
S newRootSettings);
|
||||
|
||||
private<T extends Settings> PerspectiveCompositeSettings<?> updatePerspectiveLifecycleWithAllSettings(Perspective<T> perspective, Component<? extends Settings> replaceComponent, Settings replaceComponentNewDefaultSettings) {
|
||||
private<T extends Settings> PerspectiveCompositeSettings<?> propagateSettingsToRootPerspective(Perspective<T> perspective, Component<? extends Settings> replaceComponent, Settings replaceComponentNewDefaultSettings) {
|
||||
PerspectiveLifecycleWithAllSettings<?,T> perspectiveLifecycleWithAllSettings = perspective.getPerspectiveLifecycleWithAllSettings();
|
||||
Map<String, Settings> originalSettingsPerComponent = perspectiveLifecycleWithAllSettings.getComponentSettings().getSettingsPerComponentId();
|
||||
Map<String, Settings> newSettingsPerComponent = new HashMap<>();
|
||||
@@ -96,7 +109,7 @@ public abstract class AbstractComponentContextWithSettingsStorage<PL extends Per
|
||||
|
||||
Perspective<? extends Settings> parentPerspective = perspective.getComponentTreeNodeInfo().getParentPerspective();
|
||||
if(parentPerspective != null) {
|
||||
return updatePerspectiveLifecycleWithAllSettings(parentPerspective, perspective, allSettings);
|
||||
return propagateSettingsToRootPerspective(parentPerspective, perspective, allSettings);
|
||||
} else {
|
||||
return allSettings;
|
||||
}
|
||||
@@ -107,11 +120,11 @@ public abstract class AbstractComponentContextWithSettingsStorage<PL extends Per
|
||||
}
|
||||
|
||||
@Override
|
||||
public PerspectiveCompositeSettings<PS> getDefaultSettingsForRootPerspective() {
|
||||
public S getDefaultSettings() {
|
||||
if(currentDefaultSettings == null) {
|
||||
throw new IllegalStateException("Settings have not been initialized yet.");
|
||||
}
|
||||
return rootPerspectiveLifecycle.cloneSettings(currentDefaultSettings);
|
||||
return rootLifecycle.cloneSettings(currentDefaultSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public abstract class AbstractPerspectiveComposite<PL extends PerspectiveLifecyc
|
||||
return perspectiveLifecycle.getPerspectiveOwnSettingsDialogComponent(perspectiveSettings);
|
||||
}
|
||||
|
||||
public AbstractPerspectiveComposite(AbstractComponentContext<PL, PS> componentContext, PerspectiveLifecycleWithAllSettings<PL, PS> perspectiveLifecycleWithAllSettings) {
|
||||
public AbstractPerspectiveComposite(AbstractComponentContext<PL, PerspectiveCompositeSettings<PS>> componentContext, PerspectiveLifecycleWithAllSettings<PL, PS> perspectiveLifecycleWithAllSettings) {
|
||||
this.perspectiveLifecycle = perspectiveLifecycleWithAllSettings.getPerspectiveLifecycle();
|
||||
this.perspectiveOwnSettings = perspectiveLifecycleWithAllSettings.getPerspectiveSettings();
|
||||
this.perspectiveLifecycleWithAllSettings = perspectiveLifecycleWithAllSettings;
|
||||
|
||||
+6
-6
@@ -3,12 +3,12 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
|
||||
public class AsyncCallbackWithSettingsRetrievementJoiner<T, PS extends Settings> extends CallbacksJoinerHelper<T, PerspectiveCompositeSettings<PS>> implements AsyncCallback<T> {
|
||||
public class AsyncCallbackWithSettingsRetrievementJoiner<T, S extends Settings> extends CallbacksJoinerHelper<T, S> implements AsyncCallback<T> {
|
||||
|
||||
private final AsyncCallback<T> wrappedCallback;
|
||||
private final AbstractComponentContextWithSettingsStorage<?, PS> context;
|
||||
private final AbstractComponentContextWithSettingsStorage<?, S> context;
|
||||
|
||||
public AsyncCallbackWithSettingsRetrievementJoiner(AbstractComponentContextWithSettingsStorage<?, PS> context, AsyncCallback<T> callbackToWrap) {
|
||||
public AsyncCallbackWithSettingsRetrievementJoiner(AbstractComponentContextWithSettingsStorage<?, S> context, AsyncCallback<T> callbackToWrap) {
|
||||
this.wrappedCallback = callbackToWrap;
|
||||
this.context = context;
|
||||
}
|
||||
@@ -37,16 +37,16 @@ public class AsyncCallbackWithSettingsRetrievementJoiner<T, PS extends Settings>
|
||||
|
||||
public void startSettingsRetrievementAndJoinAsyncCallback() {
|
||||
|
||||
context.initDefaultSettings(new DefaultSettingsLoadedCallback<PS>() {
|
||||
context.initDefaultSettings(new DefaultSettingsLoadedCallback<S>() {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable caught, PerspectiveCompositeSettings<PS> fallbackDefaultSettings) {
|
||||
public void onError(Throwable caught, S fallbackDefaultSettings) {
|
||||
receiveSecondCallbackResult(fallbackDefaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PerspectiveCompositeSettings<PS> defaultSettings) {
|
||||
public void onSuccess(S defaultSettings) {
|
||||
receiveSecondCallbackResult(defaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,18 +2,19 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
import com.sap.sse.gwt.client.shared.components.ComponentLifecycle;
|
||||
|
||||
public class ComponentContextInitialisationUtils {
|
||||
|
||||
private ComponentContextInitialisationUtils() {}
|
||||
|
||||
public static<T, PS extends Settings> AsyncCallbackWithSettingsRetrievementJoiner<T, PS> createSettingsRetrievementWithAsyncCallbackJoiner(
|
||||
AbstractComponentContextWithSettingsStorage<? extends PerspectiveLifecycle<PS>, PS> componentContext, AsyncCallback<T> callbackToWrap) {
|
||||
public static<T, S extends Settings> AsyncCallbackWithSettingsRetrievementJoiner<T, S> wrapAsyncCallbak(
|
||||
AbstractComponentContextWithSettingsStorage<? extends ComponentLifecycle<S, ?>, S> componentContext, AsyncCallback<T> callbackToWrap) {
|
||||
return new AsyncCallbackWithSettingsRetrievementJoiner<>(componentContext, callbackToWrap);
|
||||
}
|
||||
|
||||
public static<PS1 extends Settings, PS2 extends Settings> void initTwoComponentContexts(AbstractComponentContextWithSettingsStorage<?, PS1> context1, AbstractComponentContextWithSettingsStorage<?, PS2> context2, final IOnDefaultSettingsLoaded onDefaultSettingsLoaded) {
|
||||
TwoParallelSettingsRetrievementJoiner<PS1, PS2> joiner = new TwoParallelSettingsRetrievementJoiner<PS1, PS2>(context1, context2) {
|
||||
public static<S1 extends Settings, S2 extends Settings> void initTwoComponentContexts(AbstractComponentContextWithSettingsStorage<?, S1> context1, AbstractComponentContextWithSettingsStorage<?, S2> context2, final IOnDefaultSettingsLoaded onDefaultSettingsLoaded) {
|
||||
TwoParallelSettingsRetrievementJoiner<S1, S2> joiner = new TwoParallelSettingsRetrievementJoiner<S1, S2>(context1, context2) {
|
||||
@Override
|
||||
public void onAllDefaultSettingsLoaded() {
|
||||
onDefaultSettingsLoaded.onLoaded();
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
|
||||
public interface DefaultSettingsLoadedCallback<PS extends Settings> {
|
||||
void onError(Throwable caught, PerspectiveCompositeSettings<PS> fallbackDefaultSettings);
|
||||
void onSuccess(PerspectiveCompositeSettings<PS> defaultSettings);
|
||||
public interface DefaultSettingsLoadedCallback<S extends Settings> {
|
||||
void onError(Throwable caught, S fallbackDefaultSettings);
|
||||
void onSuccess(S defaultSettings);
|
||||
}
|
||||
+5
-5
@@ -2,14 +2,14 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
|
||||
public interface SettingsStorageManager<PS extends Settings> {
|
||||
public interface SettingsStorageManager<S extends Settings> {
|
||||
|
||||
void retrieveDefaultSettings(PerspectiveCompositeSettings<PS> defaultSettings,
|
||||
DefaultSettingsLoadedCallback<PS> asyncCallback);
|
||||
void retrieveDefaultSettings(S defaultSettings,
|
||||
DefaultSettingsLoadedCallback<S> asyncCallback);
|
||||
|
||||
void storeGlobalSettings(PerspectiveCompositeSettings<PS> globalSettings);
|
||||
void storeGlobalSettings(S globalSettings);
|
||||
|
||||
void storeContextSpecificSettings(PerspectiveCompositeSettings<PS> contextSpecificSettings);
|
||||
void storeContextSpecificSettings(S contextSpecificSettings);
|
||||
|
||||
Throwable getLastError();
|
||||
|
||||
|
||||
+10
-10
@@ -2,12 +2,12 @@ package com.sap.sse.gwt.client.shared.perspective;
|
||||
|
||||
import com.sap.sse.common.settings.Settings;
|
||||
|
||||
public abstract class TwoParallelSettingsRetrievementJoiner<PS1 extends Settings, PS2 extends Settings> extends CallbacksJoinerHelper<PerspectiveCompositeSettings<PS1>, PerspectiveCompositeSettings<PS2>> {
|
||||
public abstract class TwoParallelSettingsRetrievementJoiner<S1 extends Settings, S2 extends Settings> extends CallbacksJoinerHelper<S1, S2> {
|
||||
|
||||
private final AbstractComponentContextWithSettingsStorage<?, PS1> context1;
|
||||
private final AbstractComponentContextWithSettingsStorage<?, PS2> context2;
|
||||
private final AbstractComponentContextWithSettingsStorage<?, S1> context1;
|
||||
private final AbstractComponentContextWithSettingsStorage<?, S2> context2;
|
||||
|
||||
public TwoParallelSettingsRetrievementJoiner(AbstractComponentContextWithSettingsStorage<?, PS1> context1, AbstractComponentContextWithSettingsStorage<?, PS2> context2) {
|
||||
public TwoParallelSettingsRetrievementJoiner(AbstractComponentContextWithSettingsStorage<?, S1> context1, AbstractComponentContextWithSettingsStorage<?, S2> context2) {
|
||||
this.context1 = context1;
|
||||
this.context2 = context2;
|
||||
}
|
||||
@@ -20,31 +20,31 @@ public abstract class TwoParallelSettingsRetrievementJoiner<PS1 extends Settings
|
||||
|
||||
public void startSettingsRetrievementAndJoinAsyncCallback() {
|
||||
|
||||
context1.initDefaultSettings(new DefaultSettingsLoadedCallback<PS1>() {
|
||||
context1.initDefaultSettings(new DefaultSettingsLoadedCallback<S1>() {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable caught, PerspectiveCompositeSettings<PS1> fallbackDefaultSettings) {
|
||||
public void onError(Throwable caught, S1 fallbackDefaultSettings) {
|
||||
receiveFirstCallbackResult(fallbackDefaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PerspectiveCompositeSettings<PS1> defaultSettings) {
|
||||
public void onSuccess(S1 defaultSettings) {
|
||||
receiveFirstCallbackResult(defaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
});
|
||||
|
||||
context2.initDefaultSettings(new DefaultSettingsLoadedCallback<PS2>() {
|
||||
context2.initDefaultSettings(new DefaultSettingsLoadedCallback<S2>() {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable caught, PerspectiveCompositeSettings<PS2> fallbackDefaultSettings) {
|
||||
public void onError(Throwable caught, S2 fallbackDefaultSettings) {
|
||||
receiveSecondCallbackResult(fallbackDefaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PerspectiveCompositeSettings<PS2> defaultSettings) {
|
||||
public void onSuccess(S2 defaultSettings) {
|
||||
receiveSecondCallbackResult(defaultSettings);
|
||||
processIfFinished();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user