Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contributor / viewpoint / ContextInputOutputViewpointContributorImpl.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.browsing.ui.graph.impl.contributor.viewpoint;
13
14 import java.util.Collection;
15
16 import org.simantics.browsing.ui.NodeContext;
17 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
18 import org.simantics.browsing.ui.Tester;
19 import org.simantics.browsing.ui.BuiltinKeys.ViewpointContributionKey;
20 import org.simantics.browsing.ui.content.Contributor;
21 import org.simantics.browsing.ui.content.ViewpointContribution;
22 import org.simantics.browsing.ui.content.ViewpointContributionFactory;
23 import org.simantics.browsing.ui.graph.impl.contribution.ViewpointContributionImpl;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.exception.DatabaseException;
26
27 abstract public class ContextInputOutputViewpointContributorImpl implements Contributor<ViewpointContributionFactory> {
28
29     abstract public Collection<NodeContext> getContribution(ReadGraph graph, NodeContext context) throws DatabaseException;
30
31     final private Class<?> clazz;
32
33         public String getViewpointId() {
34                 return "Standard";
35         }
36         
37     @Override
38     public Tester getNodeContextTester() {
39         return null;
40     }
41
42     public ContextInputOutputViewpointContributorImpl() {
43         clazz = Object.class;
44     }
45
46     public ContextInputOutputViewpointContributorImpl(Class<?> clazz) {
47         this.clazz = clazz;
48     }
49
50     @Override
51     public ViewpointContributionFactory getFactory() {
52
53         return new ViewpointContributionFactory() {
54
55             @Override
56             public String getViewpointId() {
57                 return ContextInputOutputViewpointContributorImpl.this.getViewpointId();
58             }
59
60             @Override
61             public ViewpointContribution create(final PrimitiveQueryUpdater updater, NodeContext context, final ViewpointContributionKey key) {
62
63                 return new ViewpointContributionImpl(updater, context, key) {
64
65                     @Override
66                     public Collection<NodeContext> children(ReadGraph graph, NodeContext context) throws DatabaseException {
67
68                         return ContextInputOutputViewpointContributorImpl.this.getContribution(graph, context);
69
70                     }
71
72                     @Override
73                     public Tester getNodeContextTester() {
74                         return ContextInputOutputViewpointContributorImpl.this.getNodeContextTester();
75                     }
76
77                     @Override
78                     public Class<?> getInputClass() {
79                         return ContextInputOutputViewpointContributorImpl.this.getInputClass();
80                     }
81
82                 };
83
84             }
85
86         };
87
88     }
89
90     @Override
91     public Class<?> getInputClass() {
92         return clazz;
93     }
94
95 }