]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/MultiPageResourceEditorPart.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / MultiPageResourceEditorPart.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.part.MultiPageEditorPart;
19 import org.simantics.db.Session;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public abstract class MultiPageResourceEditorPart extends MultiPageEditorPart implements IResourceEditorPart {
25
26     ResourceEditorSupport support;
27
28     @Override
29     public final void doSave(IProgressMonitor monitor) {
30     }
31
32     @Override
33     public final void doSaveAs() {
34     }
35
36     @Override
37     public final boolean isSaveAsAllowed() {
38         return false;
39     }
40
41     @Override
42     public IResourceEditorInput getResourceInput() {
43         return (IResourceEditorInput) getEditorInput();
44     }
45
46     @Override
47     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
48         if (!(input instanceof IResourceEditorInput))
49             throw new PartInitException("Invalid input: must be IResourceEditorInput");
50         super.init(site, input);
51         support = new ResourceEditorSupport(this);
52
53         // Set initial part name according to the name given by IEditorInput
54         setPartName(getEditorInput().getName());
55     }
56
57     @Override
58     public void dispose() {
59         support.dispose();
60         super.dispose();
61     }
62
63     @SuppressWarnings("rawtypes")
64     @Override
65     public Object getAdapter(Class adapter) {
66         if (adapter == Session.class && support != null)
67             return support.getSession();
68         return super.getAdapter(adapter);
69     }
70
71     protected Session getSession() {
72         return support.getSession();
73     }
74
75 }