KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > target > TargetEditor


1 /*******************************************************************************
2  * Copyright (c) 2005, 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 package org.eclipse.pde.internal.ui.editor.target;
12
13 import java.io.File JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.core.runtime.Platform;
19 import org.eclipse.jface.dialogs.IPageChangedListener;
20 import org.eclipse.jface.dialogs.PageChangedEvent;
21 import org.eclipse.osgi.service.datalocation.Location;
22 import org.eclipse.pde.internal.ui.IPDEUIConstants;
23 import org.eclipse.pde.internal.ui.PDEPlugin;
24 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
25 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
26 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
27 import org.eclipse.pde.internal.ui.editor.context.InputContext;
28 import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
29 import org.eclipse.ui.IEditorInput;
30 import org.eclipse.ui.IFileEditorInput;
31 import org.eclipse.ui.IStorageEditorInput;
32 import org.eclipse.ui.PartInitException;
33
34
35 public class TargetEditor extends PDEFormEditor {
36     
37     protected static String JavaDoc LAST_PATH;
38     
39     static {
40         Location installLoc = Platform.getInstallLocation();
41         if (installLoc == null) {
42             LAST_PATH = ""; //$NON-NLS-1$
43
}
44         URL JavaDoc url = installLoc.getURL();
45         LAST_PATH = new Path(url.getPath()).toOSString();
46     }
47
48     public TargetEditor() {
49         super();
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
54      */

55     protected String JavaDoc getEditorID() {
56         return IPDEUIConstants.TARGET_EDITOR_ID;
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#isSaveAsAllowed()
61      */

62     public boolean isSaveAsAllowed() {
63         return true;
64     }
65     
66     /* (non-Javadoc)
67      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getContextIDForSaveAs()
68      */

69     public String JavaDoc getContextIDForSaveAs() {
70         return TargetInputContext.CONTEXT_ID;
71     }
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createInputContextManager()
75      */

76     protected InputContextManager createInputContextManager() {
77         return new TargetInputContextManager(this);
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createResourceContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IFileEditorInput)
82      */

83     protected void createResourceContexts(InputContextManager manager, IFileEditorInput input) {
84         manager.putContext(input, new TargetInputContext(this, input, true));
85         manager.monitorFile(input.getFile());
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createSystemFileContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.pde.internal.ui.editor.SystemFileEditorInput)
90      */

91     protected void createSystemFileContexts(InputContextManager manager,
92             SystemFileEditorInput input) {
93         File JavaDoc file = (File JavaDoc) input.getAdapter(File JavaDoc.class);
94         if (file != null) {
95             String JavaDoc name = file.getName();
96             if (name.endsWith(".target")) { //$NON-NLS-1$
97
IEditorInput in = new SystemFileEditorInput(file);
98                 manager.putContext(in, new TargetInputContext(this, in, true));
99             }
100         }
101     }
102
103     /* (non-Javadoc)
104      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createStorageContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IStorageEditorInput)
105      */

106     protected void createStorageContexts(InputContextManager manager,
107             IStorageEditorInput input) {
108         if (input.getName().endsWith(".target")) { //$NON-NLS-1$
109
manager.putContext(input, new TargetInputContext(this, input, true));
110         }
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createContentOutline()
115      */

116     protected ISortableContentOutlinePage createContentOutline() {
117         return new TargetOutlinePage(this);
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
122      */

123     protected InputContext getInputContext(Object JavaDoc object) {
124         return fInputContextManager.findContext(TargetInputContext.CONTEXT_ID);
125     }
126
127     /* (non-Javadoc)
128      * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
129      */

130     protected void addEditorPages() {
131         try {
132             addPage(new OverviewPage(this));
133             addPage(new ContentPage(this));
134             addPage(new EnvironmentPage(this));
135             addPageChangedListener(new IPageChangedListener() {
136
137                 public void pageChanged(PageChangedEvent event) {
138                     Object JavaDoc o = event.getSelectedPage();
139                     if (o instanceof EnvironmentPage)
140                         ((EnvironmentPage)o).updateChoices();
141                 }
142                 
143             });
144         } catch (PartInitException e) {
145             PDEPlugin.log(e);
146         }
147     }
148     
149
150     /* (non-Javadoc)
151      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextAdded(org.eclipse.pde.internal.ui.editor.context.InputContext)
152      */

153     public void editorContextAdded(InputContext context) {
154     }
155
156     /* (non-Javadoc)
157      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextRemoved(org.eclipse.pde.internal.ui.editor.context.InputContext)
158      */

159     public void contextRemoved(InputContext context) {
160         close(false);
161     }
162
163     /* (non-Javadoc)
164      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileAdded(org.eclipse.core.resources.IFile)
165      */

166     public void monitoredFileAdded(IFile monitoredFile) {
167     }
168
169     /* (non-Javadoc)
170      * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileRemoved(org.eclipse.core.resources.IFile)
171      */

172     public boolean monitoredFileRemoved(IFile monitoredFile) {
173         return true;
174     }
175
176 }
Popular Tags