Skip to content
Snippets Groups Projects
Commit 50c5d23a authored by buczekp's avatar buczekp
Browse files

[LMS-1504] links to materials in browsers in simple view mode;

fixed removing click listeners in simple view mode

SVN: 15750
parent a48c9048
No related branches found
No related tags found
No related merge requests found
Showing
with 151 additions and 51 deletions
......@@ -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();
}
}
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
......@@ -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);
}
......
/*
* 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;
}
}
}
......@@ -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;
}
}
......@@ -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,
......
......@@ -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);
}
......
......@@ -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>
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment