]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/SharedHeaderResourceFormEditor.java
Modified OpenWith for further customization.
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / SharedHeaderResourceFormEditor.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.SharedHeaderFormEditor;
19 import org.simantics.Simantics;
20 import org.simantics.db.Session;
21 import org.simantics.db.common.request.ParametrizedRead;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public abstract class SharedHeaderResourceFormEditor extends SharedHeaderFormEditor implements IResourceEditorPart {
27
28     protected boolean               disposed = false;
29     protected ResourceEditorSupport support;
30
31     /**
32      * Override to define your own input resource editor input validator that
33      * the view uses by default in {@link #init(IEditorSite, IEditorInput)}.
34      * 
35      * @return
36      */
37     protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
38         return null;
39     }
40
41     @Override
42     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
43         init(site, input, getInputValidator());
44     }
45
46     protected void init(IEditorSite site, IEditorInput input,
47             ParametrizedRead<IResourceEditorInput, Boolean> inputValidator) throws PartInitException {
48         if (!(input instanceof IResourceEditorInput))
49             throw new PartInitException("Invalid input: must be IResourceEditorInput");
50         super.init(site, input);
51
52         support = new ResourceEditorSupport(this, inputValidator);
53
54         // Set initial part name according to the name given by IEditorInput
55         setPartName(getEditorInput().getName());
56
57         Session session = Simantics.peekSession();
58         if (session != null) {
59             session.asyncRequest(
60                     new TitleRequest(site.getId(), getResourceInput()),
61                     new TitleUpdater(site.getShell().getDisplay(), this::setPartName, () -> disposed));
62         }
63     }
64
65     @Override
66     public void dispose() {
67         disposed = true;
68         support.dispose();
69         super.dispose();
70     }
71
72     @Override
73     public void doSave(IProgressMonitor monitor) {
74     }
75
76     @Override
77     public final void doSaveAs() {
78     }
79
80     @Override
81     public final boolean isSaveAsAllowed() {
82         return false;
83     }
84
85     @Override
86     public IResourceEditorInput getResourceInput() {
87         return (IResourceEditorInput) getEditorInput();
88     }
89
90     protected Session getSession() {
91         return support.getSession();
92     }
93
94 }