]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CompositeViewerAdapter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / compositeViewer / CompositeViewerAdapter.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.structural.ui.compositeViewer;
13
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.structural.ui.modelBrowser.nodes.CompositeNode;
20 import org.simantics.ui.workbench.ResourceEditorInput;
21 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
22 import org.simantics.utils.ui.AdaptionUtils;
23
24 public class CompositeViewerAdapter extends AbstractResourceEditorAdapter {
25
26         public CompositeViewerAdapter() {
27                 super("Composite Viewer", null, 10);
28         }       
29
30         @Override
31         public boolean canHandle(ReadGraph g, Object input)
32                         throws DatabaseException {
33                 NodeContext context = AdaptionUtils.adaptToSingle(input, NodeContext.class);
34                 if(context != null) {
35                         Object obj = context.getConstant(BuiltinKeys.INPUT);
36                         if(obj instanceof CompositeNode) {
37                                 return true;
38                         }
39                 }
40                 return false;
41         }       
42         
43         @Override
44         public void openEditor(Resource r) throws Exception {
45                 String editorId = "org.simantics.structural.ui.compositeViewer";
46                 openEditorWithId(editorId, new ResourceEditorInput(editorId, r));
47         }
48         
49 }