From 50c5d23a3a3902c1d312ae32783d2803922f3b35 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Tue, 4 May 2010 11:37:41 +0000 Subject: [PATCH] [LMS-1504] links to materials in browsers in simple view mode; fixed removing click listeners in simple view mode SVN: 15750 --- .../client/application/CommonViewContext.java | 27 ++++++- .../locator/MaterialLocatorResolver.java | 34 +-------- .../renderer/AbstractPropertyColRenderer.java | 2 + .../renderer/MaterialPropertyColRenderer.java | 75 +++++++++++++++++++ .../application/renderer/LinkRenderer.java | 9 ++- .../ui/PropertyValueRenderers.java | 3 +- .../ui/columns/framework/LinkExtractor.java | 43 ++++++++--- .../listener/OpenEntityDetailsTabHelper.java | 9 +++ 8 files changed, 151 insertions(+), 51 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MaterialPropertyColRenderer.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/CommonViewContext.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/CommonViewContext.java index 5003ca75720..2ca8733a07d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/CommonViewContext.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/CommonViewContext.java @@ -37,6 +37,27 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; */ public final class CommonViewContext implements IViewContext<ICommonClientServiceAsync> { + + /** + * Holds static state of client that should be accessible from everywhere on the client. + * + * @author Piotr Buczek + */ + public final static class ClientStaticState + { + private static boolean simpleMode; + + public static void init(final boolean isSimpleMode) + { + simpleMode = isSimpleMode; + } + + public static boolean isSimpleMode() + { + return simpleMode; + } + } + private static final String TECHNOLOGY_NAME = "common"; private final ICommonClientServiceAsync service; @@ -57,8 +78,6 @@ public final class CommonViewContext implements IViewContext<ICommonClientServic private final IProfilingTable profilingTable; - private final boolean simpleMode; - CommonViewContext(final ICommonClientServiceAsync service, final IGenericImageBundle imageBundle, final IPageController pageController, boolean isLoggingEnabled, boolean isSimpleMode) @@ -66,12 +85,12 @@ public final class CommonViewContext implements IViewContext<ICommonClientServic this.service = service; this.imageBundle = imageBundle; this.pageController = pageController; - this.simpleMode = isSimpleMode; this.profilingTable = ProfilingTable.create(isLoggingEnabled); messageProvider = new CompositeMessageProvider(); messageProvider.add(new DictonaryBasedMessageProvider(TECHNOLOGY_NAME)); viewModel = new GenericViewModel(); locatorHandlerRegistry = new ViewLocatorResolverRegistry(); + ClientStaticState.init(isSimpleMode); } final void setClientPluginFactoryProvider( @@ -215,7 +234,7 @@ public final class CommonViewContext implements IViewContext<ICommonClientServic public boolean isSimpleMode() { - return simpleMode; + return ClientStaticState.isSimpleMode(); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/MaterialLocatorResolver.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/MaterialLocatorResolver.java index 69ade201f8b..abaa31bbbfa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/MaterialLocatorResolver.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/MaterialLocatorResolver.java @@ -1,11 +1,9 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.locator; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabAction; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabHelper; import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; -import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; @@ -19,9 +17,9 @@ public class MaterialLocatorResolver extends AbstractViewLocatorResolver { private final IViewContext<ICommonClientServiceAsync> viewContext; - private final static String CODE_PARAMETER_KEY = "code"; + public final static String CODE_PARAMETER_KEY = "code"; - protected final static String TYPE_PARAMETER_KEY = "type"; + public final static String TYPE_PARAMETER_KEY = "type"; public MaterialLocatorResolver(IViewContext<ICommonClientServiceAsync> viewContext) { @@ -62,31 +60,7 @@ public class MaterialLocatorResolver extends AbstractViewLocatorResolver protected void openInitialMaterialViewer(MaterialIdentifier identifier) throws UserFailureException { - viewContext.getService().getMaterialInformationHolder(identifier, - new OpenEntityDetailsTabCallback(viewContext)); - } - - private static class OpenEntityDetailsTabCallback extends - AbstractAsyncCallback<IEntityInformationHolder> - { - - private OpenEntityDetailsTabCallback(final IViewContext<?> viewContext) - { - super(viewContext); - } - - // - // AbstractAsyncCallback - // - - /** - * Opens the tab with <var>result</var> entity details. - */ - @Override - protected final void process(final IEntityInformationHolder result) - { - new OpenEntityDetailsTabAction(result, viewContext).execute(); - } + OpenEntityDetailsTabHelper.open(viewContext, identifier); } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java index 7147548925d..19aba91fc27 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java @@ -55,6 +55,8 @@ public abstract class AbstractPropertyColRenderer<T extends IEntityPropertiesHol return new VocabularyPropertyColRenderer<S>(colDef); case TIMESTAMP: return new TimestampPropertyColRenderer<S>(colDef); + case MATERIAL: + return new MaterialPropertyColRenderer<S>(colDef); default: return new DefaultPropertyColRenderer<S>(colDef); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MaterialPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MaterialPropertyColRenderer.java new file mode 100644 index 00000000000..1179bd1d1f8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MaterialPropertyColRenderer.java @@ -0,0 +1,75 @@ +/* + * 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.model.renderer; + +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.InlineHTML; +import com.google.gwt.user.client.ui.Widget; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.CommonViewContext.ClientStaticState; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.LinkRenderer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.EntityPropertyColDef; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.LinkExtractor; +import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; + +/** + * An {@link AbstractPropertyColRenderer} which renders value preserving newlines. + * + * @author Piotr Buczek + */ +class MaterialPropertyColRenderer<T extends IEntityPropertiesHolder> extends + AbstractPropertyColRenderer<T> +{ + + public MaterialPropertyColRenderer(EntityPropertyColDef<T> colDef) + { + super(colDef); + } + + @Override + protected String renderValue(GridRowModel<T> entity) + { + String value = colDef.getValue(entity); + final MaterialIdentifier identifier = MaterialIdentifier.tryParseIdentifier(value); + // FIXME Can't create ClickHandler because we don't have access to viewContext here. + // Material will be rendered as link only in simple mode + if (identifier != null && ClientStaticState.isSimpleMode()) + { + // final ClickHandler listener = new ClickHandler() { + // + // public void onClick(ClickEvent event) + // { + // OpenEntityDetailsTabHelper.open(viewContext, identifier); + // } + // } + String href = LinkExtractor.tryExtract(identifier); + final Widget link = + LinkRenderer.getLinkWidget(identifier.getCode(), null, false, + href != null ? ("#" + href) : null); + + FlowPanel panel = new FlowPanel(); + panel.add(link); + panel.add(new InlineHTML(" [" + identifier.getTypeCode() + "]")); + return panel.toString(); + } else + { + return value; + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/LinkRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/LinkRenderer.java index 6c5a82d0722..d9b3009b047 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/LinkRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/LinkRenderer.java @@ -27,6 +27,7 @@ import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Hyperlink; import com.google.gwt.user.client.ui.Widget; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.CommonViewContext.ClientStaticState; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel; /** @@ -132,8 +133,9 @@ public class LinkRenderer /** * @return {@link Hyperlink} GWT widget that is displayed as a link with given <var>text</var> - * and a <var>listener</var> registered on the click event. The link display style is - * based on <var>invalidate</var> (default style is for false). + * and if simple mode is not active a <var>listener</var> registered on the click event. + * The link display style is based on <var>invalidate</var> (default style is for + * false). */ public static Widget getLinkWidget(final String text, final ClickHandler listener, boolean invalidate, String href) @@ -141,7 +143,7 @@ public class LinkRenderer Anchor link = new Anchor(); link.setText(text); link.setStyleName(LINK_STYLE); - if (listener != null) + if (listener != null && ClientStaticState.isSimpleMode() == false) { link.addClickHandler(listener); } @@ -155,5 +157,4 @@ public class LinkRenderer } return link; } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java index 257cf69f6d6..40c01c7b3e2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java @@ -423,8 +423,7 @@ public final class PropertyValueRenderers final String displayText = getDisplayText(entity); final boolean invalidate = getInvalidate(entity); final ClickHandler listener = - viewContext.isSimpleMode() ? null : new OpenEntityDetailsTabClickListener( - entity, viewContext); + new OpenEntityDetailsTabClickListener(entity, viewContext); String href = LinkExtractor.tryExtract(entity); final Widget link = LinkRenderer.getLinkWidget(displayText, listener, invalidate, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/LinkExtractor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/LinkExtractor.java index 883fce71c51..a035901670d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/LinkExtractor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/LinkExtractor.java @@ -16,11 +16,14 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.MaterialLocatorResolver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.ProjectLocatorResolver; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; import ch.systemsx.cisd.openbis.generic.shared.basic.URLMethodWithParameters; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; /** @@ -31,6 +34,18 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; public class LinkExtractor { + public static String tryExtract(IEntityInformationHolderWithIdentifier e) + { + if (e == null) + { + return null; + } + URLMethodWithParameters url = new URLMethodWithParameters(""); + url.addParameter(PermlinkUtilities.ENTITY_KIND_PARAMETER_KEY, e.getEntityKind().name()); + url.addParameter(PermlinkUtilities.PERM_ID_PARAMETER_KEY, e.getPermId()); + return print(url); + } + public static final String tryExtract(Project p) { if (p == null) @@ -45,28 +60,34 @@ public class LinkExtractor return print(url); } - public static final String tryExtract(Material m) + public static final String tryExtract(Material material) { - if (m == null) + if (material == null) { return null; } - URLMethodWithParameters url = new URLMethodWithParameters(""); - url.addParameter(PermlinkUtilities.ENTITY_KIND_PARAMETER_KEY, m.getEntityKind().name()); - url.addParameter("code", m.getCode()); - url.addParameter("type", m.getMaterialType().getCode()); - return print(url); + return tryCreateMaterialLink(material.getCode(), material.getMaterialType().getCode()); } - public static String tryExtract(IEntityInformationHolderWithIdentifier e) + public static final String tryExtract(MaterialIdentifier identifier) { - if (e == null) + if (identifier == null) + { + return null; + } + return tryCreateMaterialLink(identifier.getCode(), identifier.getTypeCode()); + } + + private static final String tryCreateMaterialLink(String materialCode, String materialTypeCode) + { + if (materialCode == null || materialTypeCode == null) { return null; } URLMethodWithParameters url = new URLMethodWithParameters(""); - url.addParameter(PermlinkUtilities.ENTITY_KIND_PARAMETER_KEY, e.getEntityKind().name()); - url.addParameter(PermlinkUtilities.PERM_ID_PARAMETER_KEY, e.getPermId()); + url.addParameter(PermlinkUtilities.ENTITY_KIND_PARAMETER_KEY, EntityKind.MATERIAL.name()); + url.addParameter(MaterialLocatorResolver.CODE_PARAMETER_KEY, materialCode); + url.addParameter(MaterialLocatorResolver.TYPE_PARAMETER_KEY, materialTypeCode); return print(url); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/listener/OpenEntityDetailsTabHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/listener/OpenEntityDetailsTabHelper.java index dc644bc6062..cf56e07a468 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/listener/OpenEntityDetailsTabHelper.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/listener/OpenEntityDetailsTabHelper.java @@ -29,9 +29,11 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpP import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageDomain; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractViewer; +import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; /** @@ -48,6 +50,13 @@ public class OpenEntityDetailsTabHelper } + public static void open(IViewContext<?> viewContext, MaterialIdentifier identifier) + throws UserFailureException + { + viewContext.getCommonService().getMaterialInformationHolder(identifier, + new OpenEntityDetailsTabCallback(viewContext)); + } + private static class OpenEntityDetailsTabCallback extends AbstractAsyncCallback<IEntityInformationHolder> { -- GitLab