]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/AbstractEditorAdapter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / editor / AbstractEditorAdapter.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.editor;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.PartInitException;
17 import org.eclipse.ui.WorkbenchException;
18 import org.simantics.utils.ui.ErrorLogger;
19 import org.simantics.utils.ui.workbench.WorkbenchUtils;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public abstract class AbstractEditorAdapter implements EditorAdapter, Prioritized {
25
26     protected String          name;
27
28     protected ImageDescriptor icon;
29
30     protected int             priority;
31
32     public AbstractEditorAdapter(String name) {
33         this(name, null, 0);
34     }
35
36     public AbstractEditorAdapter(String name, ImageDescriptor icon) {
37         this(name, icon, 0);
38     }
39
40     public AbstractEditorAdapter(String name, ImageDescriptor icon, int priority) {
41         this.name = name;
42         this.icon = icon;
43         this.priority = priority;
44     }
45
46     public String getName() {
47         return name;
48     }
49
50     public ImageDescriptor getIcon() {
51         return icon;
52     }
53
54     @Override
55     public int getPriority() {
56         return priority;
57     }
58
59     @Override
60     public void setPriority(int priority) {
61         this.priority = priority;
62     }
63
64     protected void setIcon(ImageDescriptor icon) {
65         this.icon = icon;
66     }
67
68     protected void openEditorWithId(String editorId, IEditorInput input) throws PartInitException {
69         WorkbenchUtils.openEditor(editorId, input);
70     }
71
72     protected void openEditorWithIdInPerspective(String editorId, IEditorInput input, String perspectiveId)
73     throws WorkbenchException {
74         try {
75             WorkbenchUtils.showPerspective(perspectiveId);
76         } catch (WorkbenchException e) {
77             ErrorLogger.getDefault().logError("Could not open perspective with ID'" + perspectiveId + "'.", e);
78         }
79
80         openEditorWithId(editorId, input);
81     }
82
83 }