diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java index 805cb2fff3011bf9a5077b991af6f3ecc3729d5c..20f38d8bb616e792be6a3b0044f715469ff6f82f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java @@ -32,15 +32,31 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.exception.InvalidSessi */ public abstract class AbstractAsyncCallback<T> implements AsyncCallback<T> { + private static final ICallbackListener DUMMY_LISTENER = new ICallbackListener() + { + public void onFailureOf(AsyncCallback<Object> callback, Throwable throwable) + { + } + + public void startOnSuccessOf(AsyncCallback<Object> callback, Object result) + { + } + + public void finishOnSuccessOf(AsyncCallback<Object> callback, Object result) + { + } + }; + private static final String PREFIX = "exception_"; - private static ICallbackListener callbackListener = DummyCallbackListener.DUMMY_LISTENER; + + private static ICallbackListener callbackListener = DUMMY_LISTENER; /** * Sets the global callback listener. Note: THIS METHOD SHOULD ONLY BE USED IN TEST CODE. */ - public static void setCallbackListener(ICallbackListener listenerOrNull) + static void setCallbackListener(ICallbackListener listenerOrNull) { - callbackListener = listenerOrNull == null ? DummyCallbackListener.DUMMY_LISTENER : listenerOrNull; + callbackListener = listenerOrNull == null ? DUMMY_LISTENER : listenerOrNull; } protected final GenericViewContext viewContext; @@ -53,9 +69,15 @@ public abstract class AbstractAsyncCallback<T> implements AsyncCallback<T> this.viewContext = viewContext; } + @SuppressWarnings("unchecked") + private AsyncCallback<Object> getThis() + { + return (AsyncCallback<Object>) this; + } + public void onFailure(Throwable caught) { - callbackListener.onFailureOf(this, caught); + callbackListener.onFailureOf(getThis(), caught); System.out.println(caught); final String msg; if (caught instanceof InvocationException) @@ -88,9 +110,9 @@ public abstract class AbstractAsyncCallback<T> implements AsyncCallback<T> public final void onSuccess(T result) { - callbackListener.startOnSuccessOf(this, result); + callbackListener.startOnSuccessOf(getThis(), result); process(result); - callbackListener.finishOnSuccessOf(this, result); + callbackListener.finishOnSuccessOf(getThis(), result); } /** diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java index 406b5ec2b75725bdd068ed9db949292fbf4ab5b2..88d57b0b37d579293a6424bbb97ed003da29bf29 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java @@ -16,15 +16,12 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application; -import com.extjs.gxt.ui.client.widget.Component; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.ServiceDefTarget; -import com.google.gwt.user.client.ui.RootPanel; import ch.systemsx.cisd.openbis.generic.client.web.client.IGenericClientService; import ch.systemsx.cisd.openbis.generic.client.web.client.IGenericClientServiceAsync; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.LoginPage; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.DictonaryBasedMessageProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ApplicationInfo; @@ -36,8 +33,8 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext; */ public class Client implements EntryPoint { - GenericViewContext viewContext; - AbstractAsyncCallback<SessionContext> loginCallback; + private GenericViewContext viewContext; + private AbstractAsyncCallback<SessionContext> loginCallback; public void onModuleLoad() { @@ -45,7 +42,7 @@ public class Client implements EntryPoint { viewContext = createViewContext(); } - loginCallback = loginCallback(); + loginCallback = new SessionContextCallback(viewContext); final IGenericClientServiceAsync service = viewContext.getService(); service.getApplicationInfo(new AbstractAsyncCallback<ApplicationInfo>(viewContext) { @@ -76,27 +73,4 @@ public class Client implements EntryPoint return new GenericViewContext(service, messageProvider, imageBundle, pageController); } - private AbstractAsyncCallback<SessionContext> loginCallback() - { - return new AbstractAsyncCallback<SessionContext>(viewContext) - { - @Override - public void process(SessionContext sessionContext) - { - RootPanel rootPanel = RootPanel.get(); - rootPanel.clear(); - Component widget; - if (sessionContext == null) - { - widget = new LoginPage(viewContext); - } else - { - viewContext.getModel().setSessionContext(sessionContext); - widget = new Application(viewContext); - } - rootPanel.add(widget); - } - }; - } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/DummyCallbackListener.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/DummyCallbackListener.java deleted file mode 100644 index 117d127313cfe615ded78495d196334f88f5c0d2..0000000000000000000000000000000000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/DummyCallbackListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.generic.client.web.client.application; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -/** - * Dummy implementation of a callback listener which does nothing. - * - * @author Franz-Josef Elmer - */ -class DummyCallbackListener implements ICallbackListener -{ - /** The one and only one instance of this class. */ - static final ICallbackListener DUMMY_LISTENER = new DummyCallbackListener(); - - private DummyCallbackListener() - { - } - - public <T> void onFailureOf(AsyncCallback<T> callback, Throwable throwable) - { - } - - public <T> void startOnSuccessOf(AsyncCallback<T> callback, T result) - { - } - - public <T> void finishOnSuccessOf(AsyncCallback<T> callback, T result) - { - } - -} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ICallbackListener.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ICallbackListener.java index 2488a5a69925a12738af2f327e11f8725ecb0422..1bf1f6b3a2f7ddf751cce934d480aadeab4bbeb8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ICallbackListener.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ICallbackListener.java @@ -23,26 +23,26 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * * @author Franz-Josef Elmer */ -public interface ICallbackListener +interface ICallbackListener { /** * Handles invocations of {@link AsyncCallback#onFailure(Throwable)} of the specified * callback object with the specified throwable. This method will be invoked before * the callback object is actually handling the failure. */ - public <T> void onFailureOf(AsyncCallback<T> callback, Throwable throwable); + public void onFailureOf(AsyncCallback<Object> callback, Throwable throwable); /** * Handles invocations of {@link AsyncCallback#onSuccess(Object)} of the specified * callback object with the specified result object. This method will be invoked before * the callback object is actually processing the result object. */ - public <T> void startOnSuccessOf(AsyncCallback<T> callback, T result); + public void startOnSuccessOf(AsyncCallback<Object> callback, Object result); /** * Handles invocations of {@link AsyncCallback#onSuccess(Object)} of the specified * callback object with the specified result object. This method will be invoked after * the callback object is actually processing the result object. */ - public <T> void finishOnSuccessOf(AsyncCallback<T> callback, T result); + public void finishOnSuccessOf(AsyncCallback<Object> callback, Object result); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SessionContextCallback.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SessionContextCallback.java new file mode 100644 index 0000000000000000000000000000000000000000..624ebccf7a97c259fa741fe23da7189624b8dc6a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SessionContextCallback.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application; + +import com.extjs.gxt.ui.client.widget.Component; +import com.google.gwt.user.client.ui.RootPanel; + +import ch.systemsx.cisd.openbis.generic.client.web.client.IGenericClientService; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.LoginPage; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext; + +/** + * Callback class which handles return value + * {@link IGenericClientService#tryToGetCurrentSessionContext()}. + * + * @author Franz-Josef Elmer + */ +public final class SessionContextCallback extends AbstractAsyncCallback<SessionContext> +{ + SessionContextCallback(GenericViewContext viewContext) + { + super(viewContext); + } + + @Override + public void process(SessionContext sessionContext) + { + RootPanel rootPanel = RootPanel.get(); + rootPanel.clear(); + Component widget; + if (sessionContext == null) + { + widget = new LoginPage(viewContext); + } else + { + viewContext.getModel().setSessionContext(sessionContext); + widget = new Application(viewContext); + } + rootPanel.add(widget); + } +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/LoginWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/LoginWidget.java index 4a08bf66b60168b8b58ab6f533a0afb98cdf7064..fd8085448245b0693388dc60f34309b98324f2bd 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/LoginWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/LoginWidget.java @@ -36,6 +36,10 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext; public class LoginWidget extends VerticalPanel { private static final String PREFIX = "login_"; + + static final String USER_FIELD_ID = PREFIX + "user"; + static final String PASSWORD_FIELD_ID = PREFIX + "password"; + static final String BUTTON_ID = PREFIX + "button"; private final TextField<String> userField; private final TextField<String> passwordField; @@ -55,16 +59,16 @@ public class LoginWidget extends VerticalPanel userField.setSelectOnFocus(true); userField.setAllowBlank(false); userField.setValidateOnBlur(true); - userField.setId(PREFIX + "user"); + userField.setId(USER_FIELD_ID); formPanel.add(userField); passwordField = new TextField<String>(); passwordField.setPassword(true); passwordField.setAllowBlank(false); passwordField.setFieldLabel(viewContext.getMessage(PREFIX + "passwordLabel")); - passwordField.setId(PREFIX + "password"); + passwordField.setId(PASSWORD_FIELD_ID); formPanel.add(passwordField); Button button = new Button(viewContext.getMessage(PREFIX + "buttonLabel")); - button.setId(PREFIX + "button"); + button.setId(BUTTON_ID); button.addSelectionListener(new SelectionListener<ComponentEvent>() { @Override