]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphFactoryStringModifier.java
Use Consumer interface instead of deprecated Callback interface
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / GraphFactoryStringModifier.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.browsing.ui.graph.impl;
13
14 import org.simantics.db.RequestProcessor;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.utils.ui.ErrorLogger;
20
21 /**
22  * Please implement:
23  * <ul>
24  * <li>{@link #createModifierInput(String)} - constructs an input for
25  * {@link org.simantics.db.layer0.adapter.Modifier#modify(WriteGraph, Object)}
26  * from the specified label given by the user.
27  * <li>{@link #doModify(WriteGraph, String)} - perform the requested
28  * modification into the graph.</li>
29  * </ul>
30  * 
31  * <p>
32  * See {@link AbstractStringModifier} for more information.
33  * </p>
34  * 
35  * @author Tuukka Lehtonen
36  * 
37  * @param <T> the input class of the used
38  *        {@link org.simantics.db.layer0.adapter.Modifier}
39  */
40 public class GraphFactoryStringModifier extends AbstractFactoryStringModifier {
41
42     /**
43      * @param context
44      * @param session
45      */
46     public GraphFactoryStringModifier(Resource subject, Resource predicate, Resource object, RequestProcessor processor) {
47         super(subject, predicate, object, processor);
48     }
49
50     @Override
51     public final void doModify(final String label) {
52         session.asyncRequest(new WriteRequest() {
53             @Override
54             public void perform(WriteGraph graph) throws DatabaseException {
55                 doModifyWithFactory(graph, label);
56             }
57         }, parameter -> {
58             if (parameter != null)
59                 ErrorLogger.defaultLogError(parameter);
60         });
61     }
62
63     public void doModifyWithFactory(WriteGraph graph, String label) throws DatabaseException {
64         if (getModifierFactory() != null)
65             getModifier().modify(graph, label);
66         else
67             doModify(graph, label);
68     }
69
70     public void doModify(WriteGraph graph, String label) throws DatabaseException {
71         getModifier().modify(graph, label);
72     }
73
74 };