Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 04d8dd4b6fa3ed709e7ac187219eacba1ed2489e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************************
 * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.ui.part;

import java.io.File;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PanningSelectionToolEntry;
import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.diagram.ui.business.api.view.SiriusGMFHelper;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.ui.business.api.session.SessionEditorInput;
import org.eclipse.sirius.ui.tools.api.views.modelexplorerview.IModelExplorerView;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.ui.part.IShowInTargetList;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.views.properties.IPropertySheetPage;

/**
 * @not-generated
 */
public class SiriusDiagramEditor extends DiagramDocumentEditor implements IGotoMarker, IAdaptable {

    /**
     * @was-generated
     */
    public static final String CONTEXT_ID = "org.eclipse.sirius.diagram.ui.diagramContext"; //$NON-NLS-1$

    /**
     * @not-generated
     */
    public SiriusDiagramEditor() {
        super(true);
    }

    /**
     * @was-generated
     */
    @Override
    protected String getContextID() {
        return CONTEXT_ID;
    }

    private PaletteRoot previousPalette = null;

    /**
     * @not-generated
     */
    @Override
    protected PaletteRoot createPaletteRoot(final PaletteRoot existingPaletteRoot) {
        if (previousPalette == null) {
            previousPalette = super.createPaletteRoot(existingPaletteRoot);
            if (previousPalette.getDefaultEntry() instanceof PanningSelectionToolEntry) {
                // Replace the GMF SelectionToolEx by the specific Sirius one to correctly handle tooltip on decoration
                // and the travesability of this last.
                previousPalette.getDefaultEntry().setToolClass(org.eclipse.sirius.diagram.ui.tools.internal.palette.SiriusSelectionToolEx.class);
            }
        }
        return previousPalette;
    }

    /**
     * @was-generated
     */
    @Override
    protected PreferencesHint getPreferencesHint() {
        return DiagramUIPlugin.DIAGRAM_PREFERENCES_HINT;
    }

    /**
     * @was-generated
     */
    @Override
    public String getContributorId() {
        return DiagramUIPlugin.ID;
    }

    /**
     * @was-generated
     */
    @Override
    public Object getAdapter(Class type) {

        if (type == IShowInTargetList.class) {
            return new IShowInTargetList() {
                @Override
                public String[] getShowInTargetIds() {
                    return new String[] { ProjectExplorer.VIEW_ID, IModelExplorerView.ID };
                }
            };
        }
        if (type == IPropertySheetPage.class) {
            IPropertySheetPage contributedPage = SiriusEditPlugin.getPlugin().getPropertySheetPage(this, getContributorId());
            if (contributedPage != null) {
                return contributedPage;
            }
        }
        if (type == AdapterFactory.class) {
            return DiagramUIPlugin.getPlugin().getItemProvidersAdapterFactory();
        }
        return super.getAdapter(type);
    }

    /**
     * @was-generated
     */
    @Override
    public TransactionalEditingDomain getEditingDomain() {
        final IDocument document = getEditorInput() != null ? getDocumentProvider().getDocument(getEditorInput()) : null;
        if (document instanceof IDiagramDocument) {
            return ((IDiagramDocument) document).getEditingDomain();
        }
        return super.getEditingDomain();
    }

    /**
     * @was-generated
     */
    @Override
    public void gotoMarker(final IMarker marker) {
        MarkerNavigationService.getInstance().gotoMarker(this, marker);
    }

    /**
     * Overridden to not have superclass calls "ViewUtil.getIdStr(getDiagram())"
     * which cast InMemoryResourceImpl in XMLResource.
     */
    /**
     * Returns the workspace viewer <code>PreferenceStore</code>
     * 
     * @return the workspace viewer <code>PreferenceStore</code>
     */
    @Override
    public PreferenceStore getWorkspaceViewerPreferenceStore() {
        if (workspaceViewerPreferenceStore != null) {
            return workspaceViewerPreferenceStore;
        } else {
            // Try to load it
            IPath path = DiagramUIPlugin.getPlugin().getStateLocation();
            String viewId = SiriusGMFHelper.getViewId(getDiagram());

            String fileName = path.toString() + "/" + viewId;//$NON-NLS-1$
            java.io.File file = new File(fileName);
            workspaceViewerPreferenceStore = new PreferenceStore(fileName);
            if (file.exists()) {
                // Load it
                try {
                    workspaceViewerPreferenceStore.load();
                } catch (Exception e) {
                    // Create the default
                    addDefaultPreferences();
                }
            } else {
                // Create it
                addDefaultPreferences();
            }
            return workspaceViewerPreferenceStore;
        }
    }

    /**
     * @not-generated Disable "Save As" for Sirius diagrams.
     */
    @Override
    public boolean isSaveAsAllowed() {
        return false;
    }

    /**
     * @not-generated Disable "Save As" for Sirius diagrams.
     */
    @Override
    public void doSaveAs() {
        // Do nothing.
    }

    /**
     * @not-generated Disable "Save As" for Sirius diagrams.
     */
    @Override
    protected void performSaveAs(final IProgressMonitor progressMonitor) {
        // Do nothing.
    }

    /**
     * @was-generated
     */
    @Override
    public ShowInContext getShowInContext() {
        return new ShowInContext(getEditorInput(), getNavigatorSelection());
    }

    /**
     * @was-generated NOT
     */
    private ISelection getNavigatorSelection() {
        if (getEditorInput() instanceof SessionEditorInput) {
            SessionEditorInput sessionEditorInput = (SessionEditorInput) getEditorInput();
            Session session = sessionEditorInput.getSession(false);
            if (session != null) {
                Resource sessionResource = session.getSessionResource();
                if (sessionResource != null && sessionResource.getURI().isPlatformResource()) {
                    final IFile file = WorkspaceSynchronizer.getFile(sessionResource);
                    if (file != null) {
                        return new StructuredSelection(file);
                    }
                }
            }
        }
        return StructuredSelection.EMPTY;
    }
}

Back to the top