]> gerrit.simantics Code Review - simantics/platform.git/blob - modelBrowser/model/Image.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / modelBrowser / model / Image.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.modelBrowser.model;
13
14 import java.util.Collection;
15 import java.util.Collections;
16
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.simantics.browsing.ui.common.node.IDeletable;
20 import org.simantics.browsing.ui.common.node.IModifiable;
21 import org.simantics.browsing.ui.content.Labeler.Modifier;
22 import org.simantics.browsing.ui.graph.impl.LabelerUtil;
23 import org.simantics.databoard.Bindings;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.Session;
27 import org.simantics.db.WriteGraph;
28 import org.simantics.db.common.primitiverequest.RelatedValue;
29 import org.simantics.db.common.request.WriteRequest;
30 import org.simantics.db.exception.DatabaseException;
31 import org.simantics.layer0.Layer0;
32 import org.simantics.modeling.ui.Activator;
33
34 /**
35  * 
36  * @author J-P Laine
37  *
38  * @Deprecated Use org.simantics.image instead
39  */
40 @Deprecated
41 public class Image extends Node implements IAdaptable, IDeletable, IModifiable {
42
43     public Image(Resource image) {
44         super(image);
45     }
46
47     @Override
48     public String getLabel(ReadGraph g) throws DatabaseException {
49         String name = LabelerUtil.safeStringRepresentation(g, resource);
50         return name;
51     }
52
53     @Override
54     public Collection<?> getChildren(ReadGraph g) {
55         return Collections.emptyList();
56     }
57
58     @Override
59     public ImageDescriptor getImage(ReadGraph g) {
60         return Activator.IMAGE_ICON;
61     }
62
63     @Override
64     public Modifier getModifier(final Session session, String columnId) {
65         return new Modifier() {
66
67             @Override
68             public String getValue() {
69                 // TODO: rename the workspace directory containing the data
70                 try {
71                         Layer0 b = Layer0.getInstance(session);
72                     return session.syncRequest(new RelatedValue<String>(resource, b.HasName, Bindings.STRING));
73                 } catch (DatabaseException e) {
74                     e.printStackTrace();
75                     return "";
76                 }
77             }
78
79             @Override
80             public String isValid(String label) {
81                 return null;
82             }
83
84             @Override
85             public void modify(final String label) {
86                 session.asyncRequest(new WriteRequest() {
87
88                     @Override
89                     public void perform(WriteGraph g) throws DatabaseException {
90                         Layer0 b = Layer0.getInstance(g);
91                         g.claimLiteral(resource, b.HasName, label);
92                     }
93
94                 });
95             }
96
97         };
98     }
99 }