/******************************************************************************* * Copyright (c) 2015 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Semantum Oy - initial API and implementation *******************************************************************************/ package org.simantics.browsing.ui.model.queries; import java.util.Collections; import org.simantics.browsing.ui.BuiltinKeys; import org.simantics.browsing.ui.NodeContext; import org.simantics.browsing.ui.model.actions.ActionBrowseContext; import org.simantics.browsing.ui.model.browsecontexts.ActionBrowseContextRequest; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.request.Queries; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Remover; import org.simantics.project.ontology.ProjectResource; /** * @author Tuukka Lehtonen * @since 1.18.1 */ public class IsNodeContextRemovable extends UnaryRead { public IsNodeContextRemovable(NodeContext context) { super(context); } @Override public Boolean perform(ReadGraph graph) throws DatabaseException { boolean result = false; try { ActionBrowseContext defaultContext = graph.syncRequest( new ActionBrowseContextRequest(Collections.singleton(ProjectResource.getInstance(graph).ProjectActionContext)), TransientCacheAsyncListener.instance()); ActionBrowseContext browseContext = ActionBrowseContext.get(graph, parameter, defaultContext); if (browseContext != null && !browseContext.canRemove(graph, parameter)) return false; result = true; } catch (DatabaseException e) { return false; } Object input = parameter.getConstant(BuiltinKeys.INPUT); if (result && input instanceof Resource) { Remover remover = graph.syncRequest(Queries.adapt((Resource) input, Remover.class, true)); if (remover != null) return remover.canRemove(graph, null) == null; } return result; } }