]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/model/SubscriptionNode.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser2 / model / SubscriptionNode.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser2.model;
13
14 import java.util.List;
15
16 import org.eclipse.jface.viewers.ISelection;
17 import org.simantics.Simantics;
18 import org.simantics.browsing.ui.common.node.IDeletable;
19 import org.simantics.browsing.ui.common.node.IDropTargetNode;
20 import org.simantics.db.Resource;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.variable.VariableReference;
23 import org.simantics.modeling.PropertyVariables;
24 import org.simantics.modeling.subscription.AddSubscriptionItems;
25 import org.simantics.modeling.utils.VariableReferences;
26 import org.simantics.structural.ui.modelBrowser.nodes.AbstractNode;
27 import org.simantics.utils.ui.ErrorLogger;
28 import org.simantics.utils.ui.ISelectionUtils;
29
30 /**
31  * @author Tuukka Lehtonen
32  */
33 public class SubscriptionNode extends AbstractNode implements IDeletable, IDropTargetNode {
34
35     public SubscriptionNode(Resource resource) {
36         super(resource);
37     }
38
39     @Override
40     public void drop(Object data) {
41         if (!(data instanceof ISelection))
42             return;
43         final List<PropertyVariables> vars = ISelectionUtils.filterSelection((ISelection) data, PropertyVariables.class);
44         if (!vars.isEmpty()) {
45             List<VariableReference> references;
46             try {
47                 references = Simantics.getSession().syncRequest(VariableReferences.toReferences(vars));
48                 addSubscriptions(references);
49             } catch (DatabaseException e) {
50                 ErrorLogger.defaultLogError(e);
51             }
52         } else {
53             final List<VariableReference> references = ISelectionUtils.filterSelection((ISelection) data, VariableReference.class);
54             if (!references.isEmpty()) {
55                 addSubscriptions(references);
56             }
57         }
58     }
59
60     private void addSubscriptions(List<VariableReference> references) {
61         Simantics.getSession().asyncRequest(new AddSubscriptionItems(resource, references), e -> {
62             if (e != null)
63                 ErrorLogger.defaultLogError(e);
64         });
65     }
66
67 }