1 /*******************************************************************************
2 * Copyright (c) 2015 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.model.queries;
14 import java.util.Collections;
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.NodeContext;
18 import org.simantics.browsing.ui.model.actions.ActionBrowseContext;
19 import org.simantics.browsing.ui.model.browsecontexts.ActionBrowseContextRequest;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
23 import org.simantics.db.common.request.Queries;
24 import org.simantics.db.common.request.UnaryRead;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.db.layer0.adapter.Remover;
27 import org.simantics.project.ontology.ProjectResource;
30 * @author Tuukka Lehtonen
33 public class IsNodeContextRemovable extends UnaryRead<NodeContext, Boolean> {
35 public IsNodeContextRemovable(NodeContext context) {
40 public Boolean perform(ReadGraph graph) throws DatabaseException {
41 boolean result = false;
43 ActionBrowseContext defaultContext = graph.syncRequest(
44 new ActionBrowseContextRequest(Collections.singleton(ProjectResource.getInstance(graph).ProjectActionContext)),
45 TransientCacheAsyncListener.<ActionBrowseContext>instance());
46 ActionBrowseContext browseContext = ActionBrowseContext.get(graph, parameter, defaultContext);
47 if (browseContext != null && !browseContext.canRemove(graph, parameter))
50 } catch (DatabaseException e) {
54 Object input = parameter.getConstant(BuiltinKeys.INPUT);
55 if (result && input instanceof Resource) {
56 Remover remover = graph.syncRequest(Queries.adapt((Resource) input, Remover.class, true));
58 return remover.canRemove(graph, null) == null;