1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.workbench;
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;
24 * @author Tuukka Lehtonen
26 public abstract class SharedHeaderResourceFormEditor extends SharedHeaderFormEditor implements IResourceEditorPart {
28 protected boolean disposed = false;
29 protected ResourceEditorSupport support;
32 * Override to define your own input resource editor input validator that
33 * the view uses by default in {@link #init(IEditorSite, IEditorInput)}.
37 protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
42 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
43 init(site, input, getInputValidator());
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);
52 support = new ResourceEditorSupport(this, inputValidator);
54 // Set initial part name according to the name given by IEditorInput
55 setPartName(getEditorInput().getName());
57 Session session = Simantics.peekSession();
58 if (session != null) {
60 new TitleRequest(site.getId(), getResourceInput()),
61 new TitleUpdater(site.getShell().getDisplay(), this::setPartName, () -> disposed));
66 public void dispose() {
73 public void doSave(IProgressMonitor monitor) {
77 public final void doSaveAs() {
81 public final boolean isSaveAsAllowed() {
86 public IResourceEditorInput getResourceInput() {
87 return (IResourceEditorInput) getEditorInput();
90 protected Session getSession() {
91 return support.getSession();