]> gerrit.simantics Code Review - simantics/platform.git/blob
3c5d4af6367b5138ef5b8a32feb5a6e398187a00
[simantics/platform.git] /
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.modeling.ui.diagramEditor;
13
14 import java.util.Collections;
15 import java.util.Set;
16
17 import org.simantics.db.common.request.ParametrizedRead;
18 import org.simantics.db.layer0.request.combinations.Combinators;
19 import org.simantics.diagram.participant.PointerInteractor2;
20 import org.simantics.g2d.canvas.ICanvasContext;
21 import org.simantics.g2d.diagram.DiagramHints;
22 import org.simantics.g2d.diagram.IDiagram;
23 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
24 import org.simantics.g2d.layers.ILayer;
25 import org.simantics.g2d.layers.ILayers;
26 import org.simantics.g2d.layers.ILayersEditor;
27 import org.simantics.modeling.ui.diagramEditor.handlers.StructuralBrowsingHandler;
28 import org.simantics.ui.workbench.IResourceEditorInput;
29 import org.simantics.ui.workbench.editor.input.InputValidationCombinators;
30
31 /**
32  * @author Tuukka Lehtonen
33  */
34 public class PlainDiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer {
35
36     ParametrizedRead<IResourceEditorInput, Boolean> INPUT_VALIDATOR =
37         Combinators.compose(
38                         InputValidationCombinators.hasURI(),
39                 InputValidationCombinators.extractInputResource()
40         );
41
42     protected String getPopupId() {
43         return "#PlainDiagramViewerPopup";
44     }
45     
46     public ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
47         return INPUT_VALIDATOR;
48     }
49
50     @Override
51     protected PointerInteractor getPointerInteractor() {
52         return new PointerInteractor2(true, true, true, false, false, false, synchronizer.getElementClassProvider());
53     }
54     
55     protected void addStructureParticipants(ICanvasContext ctx) {
56         ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, getResourceInput2()));
57         addWorkbenchSelectionProvider(ctx);
58
59         ctx.add(
60                 new TerminalInformer(
61                         c,
62                         resourceManager,
63                         getEditorSite().getActionBars().getStatusLineManager(),
64                         new DefaultTerminalNamingStrategy()
65                         )
66                 );
67     }
68
69     @Override
70     protected void beforeSetDiagram(IDiagram diagram) {
71         setupLayers(diagram);
72     }
73
74     protected void setupLayers(IDiagram diagram) {
75         diagram.setHint(DiagramHints.KEY_LAYERS, new ILayers() {
76
77             @Override
78             public boolean isActive(ILayer layer) {
79                 return true;
80             }
81
82             @Override
83             public Set<ILayer> getVisibleLayers() {
84                 return Collections.emptySet();
85             }
86
87             @Override
88             public Set<ILayer> getLayers() {
89                 return Collections.emptySet();
90             }
91
92             @Override
93             public boolean getIgnoreVisibilitySettings() {
94                 return true;
95             }
96
97             @Override
98             public boolean getIgnoreFocusSettings() {
99                 return true;
100             }
101
102         });
103
104         // Disable roles (layers) by default in symbol editor to show everything.
105         ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
106         if (le != null) {
107             le.setIgnoreFocusSettings(true);
108             le.setIgnoreVisibilitySettings(true);
109         }
110     }
111
112     @Override
113     protected EditorState getSavedEditorState(ICanvasContext ctx) {
114         return DiagramEditorStates.toEditorState(ctx, true, true, false);
115     }
116
117 }