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.modeling.ui.modelBrowser.model;
15 import java.util.ArrayList;
16 import java.util.Collection;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.simantics.browsing.ui.common.node.IModifiable;
22 import org.simantics.browsing.ui.content.Labeler.Modifier;
23 import org.simantics.browsing.ui.graph.impl.LabelModifier;
24 import org.simantics.databoard.Bindings;
25 import org.simantics.db.ReadGraph;
26 import org.simantics.db.Resource;
27 import org.simantics.db.Session;
28 import org.simantics.db.exception.DatabaseException;
29 import org.simantics.layer0.Layer0;
30 import org.simantics.modeling.ui.Activator;
31 import org.simantics.simulation.ontology.SimulationResource;
34 public class Model extends Node implements IModifiable {
36 final static boolean showFolders = true;
38 Resource configuration;
41 public Model(ReadGraph g, Resource resource) throws DatabaseException {
43 this.configuration = g.getPossibleObject(resource, SimulationResource.getInstance(g).HasConfiguration);
44 this.session = g.getSession();
47 public File getModelDir() throws DatabaseException {
48 IPath location = Platform.getLocation();
49 File f = location.toFile();
52 (String) session.syncRequest(
53 org.simantics.db.common.request.Queries.getRelatedValue(resource, Layer0.URIs.HasName, Bindings.STRING));
55 File modelDir = new File(f, modelName);
60 public Collection<?> getChildren(ReadGraph g) throws DatabaseException {
61 Collection<Object> ret = new ArrayList<Object>(3);
62 if(configuration != null) {
63 ret.add(new Decorator(g.adapt(configuration, INode.class)) {
65 public String getLabel(ReadGraph g) {
66 return "Configuration";
70 ret.add(new Experiments(resource));
71 ret.add(new States(resource));
72 // ret.add(new Queries(g, resource));
73 ret.add(new Charts(resource));
74 ret.add(new Subscriptions(resource));
75 ret.add(new Images(resource));
76 // ret.add(new Spreadsheets(resource));
77 ret.add(new RelationViews(resource));
80 ArrayList<Object> flatten = new ArrayList<Object>();
82 flatten.addAll(n.getChildren(g));
89 public ImageDescriptor getImage(ReadGraph g) {
90 return Activator.MODEL_ICON;
94 public boolean equals(Object obj) {
99 if(!getClass().equals(obj.getClass()))
101 Model other = (Model)obj;
102 if(configuration == null) {
103 return resource.equals(other.resource) && other.configuration == null;
105 return resource.equals(other.resource)
106 && configuration.equals(other.configuration);
111 public int hashCode() {
112 if(configuration == null) {
113 return getClass().hashCode()*31 + resource.hashCode();
115 return (getClass().hashCode()*31
116 + configuration.hashCode())*31 + resource.hashCode();
121 public Modifier getModifier(final Session session, String columnId) {
122 return new LabelModifier(session, resource);