]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramLoadQuery.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / query / DiagramLoadQuery.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.query;\r
13 \r
14 import org.eclipse.core.runtime.IProgressMonitor;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.common.ResourceArray;\r
18 import org.simantics.db.common.request.ResourceRead;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.diagram.adapter.IDiagramLoader;\r
21 import org.simantics.g2d.diagram.IDiagram;\r
22 import org.simantics.utils.datastructures.hints.IHintObservable;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class DiagramLoadQuery extends ResourceRead<IDiagram> {\r
28 \r
29     Resource         model;\r
30     Resource         runtime;\r
31     IProgressMonitor monitor;\r
32     ResourceArray    structuralPath;\r
33     IDiagramLoader   loader;\r
34     IHintObservable  initialHints;\r
35 \r
36     public DiagramLoadQuery(IProgressMonitor monitor, Resource model, Resource resource, Resource runtime, ResourceArray structuralPath, IDiagramLoader loader, IHintObservable initialHints) {\r
37         super(resource);\r
38 \r
39 //        if (runtime == null)\r
40 //            throw new IllegalArgumentException("null runtime diagram resource");\r
41 \r
42         this.model = model;\r
43         this.runtime = runtime;\r
44         this.monitor = monitor;\r
45         this.structuralPath = structuralPath != null ? structuralPath : ResourceArray.EMPTY;\r
46         this.loader = loader;\r
47         this.initialHints = initialHints;\r
48     }\r
49 \r
50     @Override\r
51     public IDiagram perform(ReadGraph graph) throws DatabaseException {\r
52         return loader.loadDiagram(monitor, graph, graph.getPossibleURI(model), resource, runtime, structuralPath, initialHints);\r
53     }\r
54 \r
55     @Override\r
56     public boolean equals(Object other) {\r
57         // Make sure that we always receive a new result\r
58         return this == other;\r
59     }\r
60 \r
61     @Override\r
62     public int hashCode() {\r
63         return super.hashCode() + 31 * getClass().hashCode();\r
64     }\r
65 \r
66 }\r