KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > SimpleCSEditor


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple;
13
14 import java.io.File JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.pde.internal.ui.IPDEUIConstants;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
21 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
22 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
23 import org.eclipse.pde.internal.ui.editor.context.InputContext;
24 import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
25 import org.eclipse.ui.IEditorInput;
26 import org.eclipse.ui.IFileEditorInput;
27 import org.eclipse.ui.IStorageEditorInput;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.forms.editor.IFormPage;
30
31 /**
32  * SimpleCheatSheetEditor
33  *
34  */

35 public class SimpleCSEditor extends PDEFormEditor {
36
37     /**
38      *
39      */

40     public SimpleCSEditor() {
41         super();
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
46      */

47     protected String JavaDoc getEditorID() {
48         return IPDEUIConstants.SIMPLE_CHEAT_SHEET_EDITOR_ID;
49     }
50     
51     /* (non-Javadoc)
52      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#isSaveAsAllowed()
53      */

54     public boolean isSaveAsAllowed() {
55         return true;
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getContextIDForSaveAs()
60      */

61     public String JavaDoc getContextIDForSaveAs() {
62         return SimpleCSInputContext.CONTEXT_ID;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#addEditorPages()
67      */

68     protected void addEditorPages() {
69         try {
70             addPage(new SimpleCSPage(this));
71         } catch (PartInitException e) {
72             PDEPlugin.logException(e);
73         }
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createContentOutline()
78      */

79     protected ISortableContentOutlinePage createContentOutline() {
80         return new SimpleCSFormOutlinePage(this);
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createInputContextManager()
85      */

86     protected InputContextManager createInputContextManager() {
87         return new SimpleCSInputContextManager(this);
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createResourceContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IFileEditorInput)
92      */

93     protected void createResourceContexts(InputContextManager contexts,
94             IFileEditorInput input) {
95         contexts.putContext(input, new SimpleCSInputContext(this, input, true));
96         contexts.monitorFile(input.getFile());
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createStorageContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IStorageEditorInput)
101      */

102     protected void createStorageContexts(InputContextManager contexts,
103             IStorageEditorInput input) {
104         contexts.putContext(input, new SimpleCSInputContext(this, input, true));
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createSystemFileContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.pde.internal.ui.editor.SystemFileEditorInput)
109      */

110     protected void createSystemFileContexts(InputContextManager contexts,
111             SystemFileEditorInput input) {
112         File JavaDoc file = (File JavaDoc) input.getAdapter(File JavaDoc.class);
113         if (file != null) {
114             IEditorInput in = new SystemFileEditorInput(file);
115             contexts.putContext(in, new SimpleCSInputContext(this, in, true));
116         }
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#editorContextAdded(org.eclipse.pde.internal.ui.editor.context.InputContext)
121      */

122     public void editorContextAdded(InputContext context) {
123         // NO-OP
124
}
125
126     /* (non-Javadoc)
127      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
128      */

129     protected InputContext getInputContext(Object JavaDoc object) {
130         return fInputContextManager.findContext(SimpleCSInputContext.CONTEXT_ID);
131     }
132
133     /* (non-Javadoc)
134      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextRemoved(org.eclipse.pde.internal.ui.editor.context.InputContext)
135      */

136     public void contextRemoved(InputContext context) {
137         close(false);
138     }
139
140     /* (non-Javadoc)
141      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileAdded(org.eclipse.core.resources.IFile)
142      */

143     public void monitoredFileAdded(IFile monitoredFile) {
144         // NO-OP
145
}
146
147     /* (non-Javadoc)
148      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileRemoved(org.eclipse.core.resources.IFile)
149      */

150     public boolean monitoredFileRemoved(IFile monitoredFile) {
151         return true;
152     }
153
154     /* (non-Javadoc)
155      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getSelection()
156      */

157     public ISelection getSelection() {
158         // Override the parent getSelection because it doesn't work.
159
// The selection provider operates at the form level and does not
160
// track selections made in the master tree view.
161
// The selection is required to synchronize the master tree view with
162
// the outline view
163
IFormPage formPage = getActivePageInstance();
164         if ((formPage != null) &&
165                 (formPage instanceof SimpleCSPage)) {
166             // Synchronizes the selection made in the master tree view with the
167
// selection in the outline view when the link with editor button
168
// is toggled on
169
return ((SimpleCSPage)formPage).getSelection();
170         }
171         return super.getSelection();
172     }
173     
174 }
175
Popular Tags