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