From 8022b3d8600d52a358953eea2b020c3496e70e5a Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Tue, 1 Mar 2011 21:50:02 +0000 Subject: [PATCH] minor: show last opened tab on startup SVN: 20187 --- .../client/web/client/application/Client.java | 16 +++++++- .../framework/ComponentProvider.java | 3 +- .../application/framework/DefaultTabItem.java | 36 ++++++++++------ .../application/framework/ITabItem.java | 2 +- .../framework/LastHistoryTokenUpdater.java | 41 +++++++++++++++++++ .../application/framework/MainTabPanel.java | 7 ++-- .../locator/HomeLocatorResolver.java | 3 +- .../ui/attachment/AttachmentBrowser.java | 3 +- .../application/ui/script/ScriptGrid.java | 27 +++++++----- .../shared/basic/dto/DisplaySettings.java | 13 ++++++ .../application/ClientPluginFactory.java | 13 +++--- 11 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/LastHistoryTokenUpdater.java 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 e96180c2805..4173d0c4f32 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 @@ -29,6 +29,7 @@ import com.google.gwt.user.client.History; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.ServiceDefTarget; +import ch.systemsx.cisd.common.shared.basic.utils.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.IClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientService; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; @@ -56,6 +57,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ApplicationInfo; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.ViewMode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; /** * The {@link EntryPoint} implementation. @@ -314,11 +316,23 @@ public class Client implements EntryPoint, ValueChangeHandler<String> // also for the second user. viewContext.initDisplaySettingsManager(); dispatcher.dispatch(AppEvents.INIT); - afterInitAction.execute(); + if (viewContext.isSimpleMode() == false) { GWTUtils.setConfirmExitMessage(); } + + DisplaySettings displaySettings = + viewContext.getModel().getSessionContext().getDisplaySettings(); + String lastHistoryOrNull = displaySettings.getLastHistoryTokenOrNull(); + if (viewContext.isSimpleMode() == false && StringUtils.isBlank(History.getToken()) + && StringUtils.isBlank(lastHistoryOrNull) == false) + { + History.newItem(lastHistoryOrNull); + } else + { + afterInitAction.execute(); + } } } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java index 5f89276d4bc..3b95f6ccf24 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java @@ -104,7 +104,8 @@ public final class ComponentProvider private ITabItem createSimpleTab(String title, Component component, boolean isCloseConfirmationNeeded) { - return DefaultTabItem.createUnaware(title, component, isCloseConfirmationNeeded); + return DefaultTabItem.createUnaware(title, component, isCloseConfirmationNeeded, + viewContext); } public AbstractTabItemFactory getSampleBrowser(final String initialGroupOrNull, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/DefaultTabItem.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/DefaultTabItem.java index 69a08eb683e..b78e92ed8a2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/DefaultTabItem.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/DefaultTabItem.java @@ -42,14 +42,17 @@ public class DefaultTabItem implements ITabItem private final LastModificationStateUpdater lastModificationStateUpdaterOrNull; + private final LastHistoryTokenUpdater historyTokenUpdater; + /** * Creates a tab with the specified {@link Component}. The tab is unaware of database * modifications and will not be automatically refreshed if changes occur. */ public static ITabItem createUnaware(final String title, final Component component, - boolean isCloseConfirmationNeeded) + boolean isCloseConfirmationNeeded, IViewContext<?> viewContext) { - return new DefaultTabItem(title, component, null, null, isCloseConfirmationNeeded); + return new DefaultTabItem(viewContext, title, component, null, null, + isCloseConfirmationNeeded); } /** @@ -57,10 +60,11 @@ public class DefaultTabItem implements ITabItem * modifications and will not be automatically refreshed if changes occur. */ public static ITabItem createUnaware(final ContentPanel component, - boolean isCloseConfirmationNeeded) + boolean isCloseConfirmationNeeded, IViewContext<?> viewContext) { String title = getTabTitle(component); - return new DefaultTabItem(title, component, null, null, isCloseConfirmationNeeded); + return new DefaultTabItem(viewContext, title, component, null, null, + isCloseConfirmationNeeded); } private static String getTabTitle(ContentPanel contentPanel) @@ -77,7 +81,7 @@ public class DefaultTabItem implements ITabItem final DatabaseModificationAwareComponent component, IViewContext<?> viewContext, boolean isCloseConfirmationNeeded) { - return create(title, component.get(), viewContext, component, null, + return create(viewContext, title, component.get(), component, null, isCloseConfirmationNeeded); } @@ -86,18 +90,18 @@ public class DefaultTabItem implements ITabItem { boolean isCloseConfirmationNeeded = false; IDelegatedAction disposer = createDisposer(component); - return create(title, component.getComponent(), viewContext, component, disposer, + return create(viewContext, title, component.getComponent(), component, disposer, isCloseConfirmationNeeded); } - private static DefaultTabItem create(final String title, final Component component, - IViewContext<?> viewContext, IDatabaseModificationObserver modificationObserver, + private static DefaultTabItem create(IViewContext<?> viewContext, final String title, + final Component component, IDatabaseModificationObserver modificationObserver, IDelegatedAction disposerActionOrNull, boolean isCloseConfirmationNeeded) { - LastModificationStateUpdater updater = + LastModificationStateUpdater stateUpdater = new LastModificationStateUpdater(viewContext, modificationObserver); - return new DefaultTabItem(title, component, updater, disposerActionOrNull, - isCloseConfirmationNeeded); + return new DefaultTabItem(viewContext, title, component, stateUpdater, + disposerActionOrNull, isCloseConfirmationNeeded); } private static IDelegatedAction createDisposer(final IDisposableComponent disposableComponent) @@ -111,12 +115,14 @@ public class DefaultTabItem implements ITabItem }; } - private DefaultTabItem(final String initialTitle, final Component component, + private DefaultTabItem(IViewContext<?> viewContext, final String initialTitle, + final Component component, LastModificationStateUpdater lastModificationStateUpdaterOrNull, IDelegatedAction disposerActionOrNull, boolean isCloseConfirmationNeeded) { assert initialTitle != null : "Unspecified title."; assert component != null : "Unspecified component."; + this.historyTokenUpdater = new LastHistoryTokenUpdater(viewContext); this.titleUpdater = new TabTitleUpdater(initialTitle); this.component = component; this.lastModificationStateUpdaterOrNull = lastModificationStateUpdaterOrNull; @@ -145,8 +151,12 @@ public class DefaultTabItem implements ITabItem return isCloseConfirmationNeeded; } - public void onActivate() + public void onActivate(String linkOrNull) { + if (linkOrNull != null) + { + historyTokenUpdater.update(linkOrNull); + } if (lastModificationStateUpdaterOrNull != null) { lastModificationStateUpdaterOrNull.update(); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ITabItem.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ITabItem.java index e3d8cc65875..da8c8e94f9d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ITabItem.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ITabItem.java @@ -37,7 +37,7 @@ public interface ITabItem extends IClosableItem * Usually refreshes the tab if it was detected that relevant database objects have changed. * </p> */ - public void onActivate(); + public void onActivate(String linkOrNull); /** * Returns true if the confirmation dialog should be displayed before closing the tab. diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/LastHistoryTokenUpdater.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/LastHistoryTokenUpdater.java new file mode 100644 index 00000000000..60aa1457af8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/LastHistoryTokenUpdater.java @@ -0,0 +1,41 @@ +/* + * Copyright 2009 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.framework; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; + +/** + * @author Piotr Buczek + */ +class LastHistoryTokenUpdater +{ + private final IViewContext<?> viewContext; + + public LastHistoryTokenUpdater(IViewContext<?> viewContext) + { + this.viewContext = viewContext; + } + + public void update(String historyToken) + { + DisplaySettings displaySettings = + viewContext.getModel().getSessionContext().getDisplaySettings(); + displaySettings.setLastHistoryTokenOrNull(historyToken); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java index 548cbeee52a..f411353bdb3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java @@ -85,9 +85,8 @@ public class MainTabPanel extends TabPanel implements IMainPanel { final Component mainComponent = WelcomePanelHelper.createWelcomePanel(viewContext, PREFIX); final MainTabItem intro = - new MainTabItem( - DefaultTabItem.createUnaware(BLANK_TAB_TITLE, mainComponent, false), - mainComponent.getId(), null, null); + new MainTabItem(DefaultTabItem.createUnaware(BLANK_TAB_TITLE, mainComponent, false, + viewContext), mainComponent.getId(), null, null); intro.setClosable(false); return intro; } @@ -319,7 +318,7 @@ public class MainTabPanel extends TabPanel implements IMainPanel { if (be.getType().equals(Events.Select)) { - tabItem.onActivate(); + tabItem.onActivate(linkOrNull); } } }; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/HomeLocatorResolver.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/HomeLocatorResolver.java index e2e95646315..b5317301edb 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/HomeLocatorResolver.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/HomeLocatorResolver.java @@ -41,7 +41,8 @@ public class HomeLocatorResolver extends AbstractViewLocatorResolver public ITabItem create() { return DefaultTabItem.createUnaware(getTabTitle(), WelcomePanelHelper - .createWelcomePanel(viewContext, MainPagePanel.PREFIX), false); + .createWelcomePanel(viewContext, MainPagePanel.PREFIX), false, + viewContext); } @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java index 013773d8c63..fcc20ea1f3b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java @@ -389,7 +389,8 @@ public class AttachmentBrowser extends AbstractSimpleBrowserGrid<AttachmentVersi public ITabItem create() { final Component component = helper.createVersionsPanel(versions); - return DefaultTabItem.createUnaware(getTabTitle(), component, false); + return DefaultTabItem.createUnaware(getTabTitle(), component, false, + viewContext); } @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptGrid.java index 6e1edb7b7a8..b1a18918ca4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptGrid.java @@ -118,10 +118,12 @@ public class ScriptGrid extends TypedTableGrid<Script> addButton(addScriptButton); Button editButton = - createSelectedItemButton(viewContext.getMessage(Dict.BUTTON_EDIT), + createSelectedItemButton( + viewContext.getMessage(Dict.BUTTON_EDIT), new ISelectedEntityInvoker<BaseEntityModel<TableModelRowWithObject<Script>>>() { - public void invoke(BaseEntityModel<TableModelRowWithObject<Script>> selectedItem, + public void invoke( + BaseEntityModel<TableModelRowWithObject<Script>> selectedItem, boolean keyPressed) { openEditor(selectedItem, keyPressed); @@ -135,7 +137,8 @@ public class ScriptGrid extends TypedTableGrid<Script> new AbstractCreateDialogListener() { @Override - protected Dialog createDialog(List<TableModelRowWithObject<Script>> scripts, + protected Dialog createDialog( + List<TableModelRowWithObject<Script>> scripts, IBrowserGridActionInvoker invoker) { return new ScriptListDeletionConfirmationDialog(viewContext, @@ -153,11 +156,12 @@ public class ScriptGrid extends TypedTableGrid<Script> { return columnID.toLowerCase(); } - + @Override protected ColumnDefsAndConfigs<TableModelRowWithObject<Script>> createColumnsDefinition() { - ColumnDefsAndConfigs<TableModelRowWithObject<Script>> schema = super.createColumnsDefinition(); + ColumnDefsAndConfigs<TableModelRowWithObject<Script>> schema = + super.createColumnsDefinition(); schema.setGridCellRendererFor(ScriptColDefKind.DESCRIPTION.id(), createMultilineStringCellRenderer()); schema.setGridCellRendererFor(ScriptColDefKind.SCRIPT.id(), @@ -178,7 +182,8 @@ public class ScriptGrid extends TypedTableGrid<Script> } @Override - protected void prepareExportEntities(TableExportCriteria<TableModelRowWithObject<Script>> exportCriteria, + protected void prepareExportEntities( + TableExportCriteria<TableModelRowWithObject<Script>> exportCriteria, AbstractAsyncCallback<String> callback) { viewContext.getService().prepareExportScripts(exportCriteria, callback); @@ -198,7 +203,8 @@ public class ScriptGrid extends TypedTableGrid<Script> DatabaseModificationKind.edit(ObjectKind.SCRIPT) }; } - private void openEditor(BaseEntityModel<TableModelRowWithObject<Script>> selectedItem, boolean keyPressed) + private void openEditor(BaseEntityModel<TableModelRowWithObject<Script>> selectedItem, + boolean keyPressed) { final Script script = selectedItem.getBaseObject().getObjectOrNull(); final TechId scriptId = TechId.create(script); @@ -208,7 +214,8 @@ public class ScriptGrid extends TypedTableGrid<Script> public ITabItem create() { Component component = ScriptEditForm.create(viewContext, scriptId); - return DefaultTabItem.createUnaware(getTabTitle(), component, true); + return DefaultTabItem + .createUnaware(getTabTitle(), component, true, viewContext); } @Override @@ -249,8 +256,8 @@ public class ScriptGrid extends TypedTableGrid<Script> private final AbstractAsyncCallback<Void> callback; public ScriptListDeletionConfirmationDialog( - IViewContext<ICommonClientServiceAsync> viewContext, List<TableModelRowWithObject<Script>> data, - AbstractAsyncCallback<Void> callback) + IViewContext<ICommonClientServiceAsync> viewContext, + List<TableModelRowWithObject<Script>> data, AbstractAsyncCallback<Void> callback) { super(viewContext, data); this.viewContext = viewContext; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DisplaySettings.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DisplaySettings.java index 517e900d9f8..63058789163 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DisplaySettings.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DisplaySettings.java @@ -58,6 +58,8 @@ public class DisplaySettings implements ISerializable // For new users with clean display settings the debugging mode is disabled private boolean debugging = false; + private String lastHistoryTokenOrNull; + private RealNumberFormatingParameters realNumberFormatingParameters = new RealNumberFormatingParameters(); @@ -222,4 +224,15 @@ public class DisplaySettings implements ISerializable { debugging = isDebugging; } + + public String getLastHistoryTokenOrNull() + { + return lastHistoryTokenOrNull; + } + + public void setLastHistoryTokenOrNull(String lastHistoryOrNull) + { + this.lastHistoryTokenOrNull = lastHistoryOrNull; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/demo/client/web/client/application/ClientPluginFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/demo/client/web/client/application/ClientPluginFactory.java index 4cefd5b4958..531124afe84 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/demo/client/web/client/application/ClientPluginFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/demo/client/web/client/application/ClientPluginFactory.java @@ -126,7 +126,8 @@ public final class ClientPluginFactory extends AbstractClientPluginFactory<DemoV { final DemoSampleViewer sampleViewer = new DemoSampleViewer(getViewContext(), sampleId); - return DefaultTabItem.createUnaware(getTabTitle(), sampleViewer, false); + return DefaultTabItem.createUnaware(getTabTitle(), sampleViewer, false, + getViewContext()); } @Override @@ -181,7 +182,7 @@ public final class ClientPluginFactory extends AbstractClientPluginFactory<DemoV @Override public ITabItem create() { - return createDummyTab(getTabTitle()); + return createDummyTab(getTabTitle(), getViewContext()); } @Override @@ -212,7 +213,7 @@ public final class ClientPluginFactory extends AbstractClientPluginFactory<DemoV } - private final static class ExperimentClientPlugin extends + private final class ExperimentClientPlugin extends ClientPluginAdapter<ExperimentType, IIdAndCodeHolder> { @@ -229,7 +230,7 @@ public final class ClientPluginFactory extends AbstractClientPluginFactory<DemoV @Override public ITabItem create() { - return createDummyTab(getTabTitle()); + return createDummyTab(getTabTitle(), getViewContext()); } @Override @@ -260,10 +261,10 @@ public final class ClientPluginFactory extends AbstractClientPluginFactory<DemoV } } - private static ITabItem createDummyTab(final String identifier) + private static ITabItem createDummyTab(final String identifier, IViewContext<?> viewContext) { Component component = new DummyComponent(); - return DefaultTabItem.createUnaware(identifier, component, false); + return DefaultTabItem.createUnaware(identifier, component, false, viewContext); } @Override -- GitLab