1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl;
14 import org.simantics.browsing.ui.common.ErrorLogger;
15 import org.simantics.browsing.ui.content.Labeler.Modifier;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.RequestProcessor;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.primitiverequest.PossibleAdapter;
21 import org.simantics.db.common.request.WriteRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.layer0.adapter.StringModifier;
24 import org.simantics.db.request.Read;
26 public class L0StringModifier implements Modifier {
28 final private RequestProcessor processor;
29 final private Resource resource;
31 public L0StringModifier(RequestProcessor processor, Resource resource) {
32 this.processor = processor;
33 this.resource = resource;
37 public String getValue() {
39 return processor.syncRequest(new PossibleAdapter<String>(resource, String.class));
40 } catch (DatabaseException e) {
41 ErrorLogger.defaultLogError(e);
47 public String isValid(final String label) {
49 return processor.syncRequest(new Read<String>() {
51 public String perform(ReadGraph graph) throws DatabaseException {
52 StringModifier modifier = graph.adapt(resource, StringModifier.class);
53 return modifier.isValid(label);
56 } catch (DatabaseException e) {
57 ErrorLogger.defaultLogError(e);
58 return e.getMessage();
63 public void modify(final String label) {
65 processor.syncRequest(new WriteRequest() {
67 public void perform(WriteGraph graph) throws DatabaseException {
68 StringModifier modifier = graph.adapt(resource, StringModifier.class);
69 modifier.modify(graph, label);
72 } catch (DatabaseException e) {
73 ErrorLogger.defaultLogError(e);