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