]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceFormEditor.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / ResourceFormEditor.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.ui.workbench;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IEditorSite;
17 import org.eclipse.ui.PartInitException;
18 import org.eclipse.ui.forms.editor.FormEditor;
19 import org.simantics.Simantics;
20 import org.simantics.db.Session;
21 import org.simantics.db.management.ISessionContext;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public abstract class ResourceFormEditor extends FormEditor implements IResourceEditorPart {
27
28     ResourceEditorSupport support;
29     boolean               disposed = false;
30
31     @Override
32     public final void doSave(IProgressMonitor monitor) {
33     }
34
35     @Override
36     public final void doSaveAs() {
37     }
38
39     @Override
40     public final boolean isSaveAsAllowed() {
41         return false;
42     }
43
44     @Override
45     public IResourceEditorInput getResourceInput() {
46         return (IResourceEditorInput) getEditorInput();
47     }
48
49     @Override
50     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
51         if (!(input instanceof IResourceEditorInput))
52             throw new PartInitException("Invalid input: must be IResourceEditorInput");
53         super.init(site, input);
54         support = new ResourceEditorSupport(this);
55
56         // Set initial part name according to the name given by IEditorInput
57         setPartName(getEditorInput().getName());
58
59         Session session = Simantics.peekSession();
60         if (session != null) {
61             session.asyncRequest(
62                     new TitleRequest(site.getId(), getResourceInput()),
63                     new TitleUpdater(site.getShell().getDisplay(), this::setPartName, () -> disposed));
64         }
65     }
66
67     @Override
68     public void dispose() {
69         disposed = true;
70         support.dispose();
71         super.dispose();
72     }
73
74     protected ISessionContext getSessionContext() {
75         return support.getSessionContext();
76     }
77
78     protected Session getSession() {
79         return support.getSession();
80     }
81
82 }