1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.modelBrowser.model;
\r
14 import java.io.File;
\r
15 import java.util.ArrayList;
\r
16 import java.util.Collection;
\r
18 import org.eclipse.core.runtime.IPath;
\r
19 import org.eclipse.core.runtime.Platform;
\r
20 import org.eclipse.jface.resource.ImageDescriptor;
\r
21 import org.simantics.browsing.ui.common.node.IModifiable;
\r
22 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
23 import org.simantics.browsing.ui.graph.impl.LabelModifier;
\r
24 import org.simantics.databoard.Bindings;
\r
25 import org.simantics.db.ReadGraph;
\r
26 import org.simantics.db.Resource;
\r
27 import org.simantics.db.Session;
\r
28 import org.simantics.db.exception.DatabaseException;
\r
29 import org.simantics.layer0.Layer0;
\r
30 import org.simantics.modeling.ui.Activator;
\r
31 import org.simantics.simulation.ontology.SimulationResource;
\r
34 public class Model extends Node implements IModifiable {
\r
36 final static boolean showFolders = true;
\r
38 Resource configuration;
\r
41 public Model(ReadGraph g, Resource resource) throws DatabaseException {
\r
43 this.configuration = g.getPossibleObject(resource, SimulationResource.getInstance(g).HasConfiguration);
\r
44 this.session = g.getSession();
\r
47 public File getModelDir() throws DatabaseException {
\r
48 IPath location = Platform.getLocation();
\r
49 File f = location.toFile();
\r
52 (String) session.syncRequest(
\r
53 org.simantics.db.common.request.Queries.getRelatedValue(resource, Layer0.URIs.HasName, Bindings.STRING));
\r
55 File modelDir = new File(f, modelName);
\r
60 public Collection<?> getChildren(ReadGraph g) throws DatabaseException {
\r
61 Collection<Object> ret = new ArrayList<Object>(3);
\r
62 if(configuration != null) {
\r
63 ret.add(new Decorator(g.adapt(configuration, INode.class)) {
\r
65 public String getLabel(ReadGraph g) {
\r
66 return "Configuration";
\r
70 ret.add(new Experiments(resource));
\r
71 ret.add(new States(resource));
\r
72 // ret.add(new Queries(g, resource));
\r
73 ret.add(new Charts(resource));
\r
74 ret.add(new Subscriptions(resource));
\r
75 ret.add(new Images(resource));
\r
76 // ret.add(new Spreadsheets(resource));
\r
77 ret.add(new RelationViews(resource));
\r
79 /*if(!showFolders) {
\r
80 ArrayList<Object> flatten = new ArrayList<Object>();
\r
82 flatten.addAll(n.getChildren(g));
\r
89 public ImageDescriptor getImage(ReadGraph g) {
\r
90 return Activator.MODEL_ICON;
\r
94 public boolean equals(Object obj) {
\r
99 if(!getClass().equals(obj.getClass()))
\r
101 Model other = (Model)obj;
\r
102 if(configuration == null) {
\r
103 return resource.equals(other.resource) && other.configuration == null;
\r
105 return resource.equals(other.resource)
\r
106 && configuration.equals(other.configuration);
\r
111 public int hashCode() {
\r
112 if(configuration == null) {
\r
113 return getClass().hashCode()*31 + resource.hashCode();
\r
115 return (getClass().hashCode()*31
\r
116 + configuration.hashCode())*31 + resource.hashCode();
\r
121 public Modifier getModifier(final Session session, String columnId) {
\r
122 return new LabelModifier(session, resource);
\r