KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > ManifestEditor


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.plugin;
12 import java.io.File JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.util.Locale JavaDoc;
15 import java.util.zip.ZipFile JavaDoc;
16
17 import org.eclipse.core.resources.IContainer;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IFolder;
20 import org.eclipse.core.resources.IProject;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IStorage;
23 import org.eclipse.core.resources.ProjectScope;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.Path;
26 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.pde.core.IBaseModel;
29 import org.eclipse.pde.core.IIdentifiable;
30 import org.eclipse.pde.core.build.IBuild;
31 import org.eclipse.pde.core.build.IBuildEntry;
32 import org.eclipse.pde.core.build.IBuildModel;
33 import org.eclipse.pde.core.plugin.IFragmentModel;
34 import org.eclipse.pde.core.plugin.IPluginBase;
35 import org.eclipse.pde.core.plugin.IPluginExtension;
36 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
37 import org.eclipse.pde.core.plugin.IPluginModelBase;
38 import org.eclipse.pde.core.plugin.IPluginObject;
39 import org.eclipse.pde.core.plugin.ISharedPluginModel;
40 import org.eclipse.pde.core.plugin.PluginRegistry;
41 import org.eclipse.pde.internal.core.ICoreConstants;
42 import org.eclipse.pde.internal.core.PDECore;
43 import org.eclipse.pde.internal.core.TargetPlatformHelper;
44 import org.eclipse.pde.internal.core.build.IBuildObject;
45 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelProvider;
46 import org.eclipse.pde.internal.core.plugin.WorkspaceFragmentModel;
47 import org.eclipse.pde.internal.core.plugin.WorkspacePluginModel;
48 import org.eclipse.pde.internal.core.plugin.WorkspacePluginModelBase;
49 import org.eclipse.pde.internal.core.util.CoreUtility;
50 import org.eclipse.pde.internal.ui.IPDEUIConstants;
51 import org.eclipse.pde.internal.ui.IPreferenceConstants;
52 import org.eclipse.pde.internal.ui.PDEPlugin;
53 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
54 import org.eclipse.pde.internal.ui.editor.JarEntryEditorInput;
55 import org.eclipse.pde.internal.ui.editor.JarEntryFile;
56 import org.eclipse.pde.internal.ui.editor.MultiSourceEditor;
57 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
58 import org.eclipse.pde.internal.ui.editor.PDESourcePage;
59 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
60 import org.eclipse.pde.internal.ui.editor.build.BuildInputContext;
61 import org.eclipse.pde.internal.ui.editor.build.BuildPage;
62 import org.eclipse.pde.internal.ui.editor.build.BuildSourcePage;
63 import org.eclipse.pde.internal.ui.editor.context.InputContext;
64 import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
65 import org.eclipse.swt.widgets.Display;
66 import org.eclipse.ui.IEditorInput;
67 import org.eclipse.ui.IEditorPart;
68 import org.eclipse.ui.IFileEditorInput;
69 import org.eclipse.ui.IShowEditorInput;
70 import org.eclipse.ui.IStorageEditorInput;
71 import org.eclipse.ui.PartInitException;
72 import org.eclipse.ui.part.FileEditorInput;
73 import org.eclipse.ui.views.properties.IPropertySheetPage;
74 import org.osgi.service.prefs.BackingStoreException;
75
76 public class ManifestEditor extends MultiSourceEditor implements IShowEditorInput {
77     
78     private static int BUILD_INDEX = 5;
79     private static boolean SHOW_SOURCE;
80     private boolean fEquinox = true;
81     private boolean fShowExtensions = true;
82     private IEclipsePreferences fPrefs;
83
84     /* (non-Javadoc)
85      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
86      */

87     protected String JavaDoc getEditorID() {
88         return IPDEUIConstants.MANIFEST_EDITOR_ID;
89     }
90     
91     public static IEditorPart openPluginEditor(String JavaDoc id) {
92         return openPluginEditor(PluginRegistry.findModel(id));
93     }
94     
95     public static IEditorPart openPluginEditor(IPluginModelBase model) {
96         if (model == null) {
97             Display.getDefault().beep();
98             return null;
99         }
100         return openPluginEditor(model, false);
101     }
102     
103     public static IEditorPart openPluginEditor(IPluginModelBase model, boolean source) {
104         return open(model.getPluginBase(), source);
105     }
106     
107     public static IEditorPart open(Object JavaDoc object, boolean source) {
108         SHOW_SOURCE = source;
109         if (object instanceof IPluginObject) {
110             ISharedPluginModel model = ((IPluginObject)object).getModel();
111             if (model instanceof IBundlePluginModelProvider)
112                 model = ((IBundlePluginModelProvider)model).getBundlePluginModel();
113             if (model instanceof IPluginModelBase) {
114                 String JavaDoc filename = ((IPluginModelBase)model).isFragmentModel() ? "fragment.xml" : "plugin.xml"; //$NON-NLS-1$ //$NON-NLS-2$
115
if (!(object instanceof IPluginExtension) && !(object instanceof IPluginExtensionPoint)) {
116                     File JavaDoc file = new File JavaDoc(model.getInstallLocation());
117                     if (file.isFile()) {
118                         if (CoreUtility.jarContainsResource(file, "META-INF/MANIFEST.MF", false)) { //$NON-NLS-1$
119
filename = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
120
}
121                     } else if (new File JavaDoc(file, "META-INF/MANIFEST.MF").exists()) { //$NON-NLS-1$
122
filename = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
123
}
124                 }
125                 IResource resource = model.getUnderlyingResource();
126                 if (resource == null)
127                     return openExternalPlugin(new File JavaDoc(model.getInstallLocation()), filename);
128                 return openWorkspacePlugin(resource.getProject().getFile(filename));
129             }
130         }
131         return null;
132     }
133         
134     
135     private static IEditorPart openWorkspacePlugin(IFile pluginFile) {
136         return openEditor(new FileEditorInput(pluginFile));
137     }
138     
139     private static IEditorPart openExternalPlugin(File JavaDoc location, String JavaDoc filename) {
140         IEditorInput input = null;
141         if (location.isFile()) {
142             try {
143                 ZipFile JavaDoc zipFile = new ZipFile JavaDoc(location);
144                 if (zipFile.getEntry(filename) != null)
145                     input = new JarEntryEditorInput(new JarEntryFile(zipFile, filename));
146             } catch (IOException JavaDoc e) {
147             }
148         } else {
149             File JavaDoc file = new File JavaDoc(location, filename);
150             if (file.exists())
151                 input = new SystemFileEditorInput(file);
152         }
153         return openEditor(input);
154     }
155     
156     public static IEditorPart openEditor(IEditorInput input) {
157         if (input != null) {
158             try {
159                 return PDEPlugin.getActivePage().openEditor(
160                         input,
161                         IPDEUIConstants.MANIFEST_EDITOR_ID);
162             } catch (PartInitException e) {
163                 PDEPlugin.logException(e);
164             }
165         }
166         return null;
167     }
168
169     protected void createResourceContexts(InputContextManager manager, IFileEditorInput input) {
170         IFile file = input.getFile();
171         IContainer container = file.getParent();
172         
173         IFile manifestFile = null;
174         IFile buildFile = null;
175         IFile pluginFile = null;
176         boolean fragment = false;
177         
178         String JavaDoc name = file.getName().toLowerCase(Locale.ENGLISH);
179         if (name.equals("manifest.mf")) { //$NON-NLS-1$
180
if (container instanceof IFolder)
181                 container = container.getParent();
182             manifestFile = file;
183             buildFile = container.getFile(new Path("build.properties")); //$NON-NLS-1$
184
pluginFile = createPluginFile(container);
185         } else if (name.equals("plugin.xml") || name.equals("fragment.xml")) { //$NON-NLS-1$ //$NON-NLS-2$
186
pluginFile = file;
187             fragment = name.equals("fragment.xml"); //$NON-NLS-1$
188
buildFile = container.getFile(new Path("build.properties")); //$NON-NLS-1$
189
manifestFile = container.getFile(new Path("META-INF/MANIFEST.MF")); //$NON-NLS-1$
190
}
191         if (manifestFile.exists()) {
192             IEditorInput in = new FileEditorInput(manifestFile);
193             manager.putContext(in, new BundleInputContext(this, in, file == manifestFile));
194         }
195         if (pluginFile.exists()) {
196             FileEditorInput in = new FileEditorInput(pluginFile);
197             manager.putContext(in, new PluginInputContext(this, in, file == pluginFile, fragment));
198         }
199         if (buildFile.exists()) {
200             FileEditorInput in = new FileEditorInput(buildFile);
201             manager.putContext(in, new BuildInputContext(this, in, false));
202         }
203         manager.monitorFile(manifestFile);
204         manager.monitorFile(pluginFile); //$NON-NLS-1$
205
manager.monitorFile(buildFile);
206         
207         fPrefs = new ProjectScope(container.getProject()).getNode(PDECore.PLUGIN_ID);
208         if (fPrefs != null) {
209             fShowExtensions = fPrefs.getBoolean(ICoreConstants.EXTENSIONS_PROPERTY, true);
210             fEquinox = fPrefs.getBoolean(ICoreConstants.EQUINOX_PROPERTY, true);
211         }
212     }
213     
214     protected InputContextManager createInputContextManager() {
215         PluginInputContextManager manager = new PluginInputContextManager(this);
216         manager.setUndoManager(new PluginUndoManager(this));
217         return manager;
218     }
219     
220     public void monitoredFileAdded(IFile file) {
221         if (fInputContextManager == null)
222             return;
223         String JavaDoc name = file.getName();
224         if (name.equalsIgnoreCase("MANIFEST.MF")) { //$NON-NLS-1$
225
if (!fInputContextManager.hasContext(BundleInputContext.CONTEXT_ID)) {
226                 IEditorInput in = new FileEditorInput(file);
227                 fInputContextManager.putContext(in, new BundleInputContext(this, in, false));
228             }
229         }
230         else if (name.equalsIgnoreCase("plugin.xml")) { //$NON-NLS-1$
231
if (!fInputContextManager.hasContext(PluginInputContext.CONTEXT_ID)) {
232                 IEditorInput in = new FileEditorInput(file);
233                 fInputContextManager.putContext(in, new PluginInputContext(this, in, false, false));
234             }
235         }
236         else if (name.equalsIgnoreCase("fragment.xml")) { //$NON-NLS-1$
237
if (!fInputContextManager.hasContext(PluginInputContext.CONTEXT_ID)) {
238                 IEditorInput in = new FileEditorInput(file);
239                 fInputContextManager.putContext(in, new PluginInputContext(this, in, false, true));
240             }
241         }
242         else if (name.equalsIgnoreCase("build.properties")) { //$NON-NLS-1$
243
if (!fInputContextManager.hasContext(BuildInputContext.CONTEXT_ID)) {
244                 IEditorInput in = new FileEditorInput(file);
245                 fInputContextManager.putContext(in, new BuildInputContext(this, in, false));
246             }
247         }
248     }
249     
250     public void ensurePluginContextPresence() {
251         if (fInputContextManager.hasContext(PluginInputContext.CONTEXT_ID))
252             return;
253         IProject project = fInputContextManager.getCommonProject();
254         String JavaDoc name = (fInputContextManager.getAggregateModel() instanceof IFragmentModel)
255                         ? "fragment.xml" : "plugin.xml"; //$NON-NLS-1$ //$NON-NLS-2$
256
IFile file = project.getFile(name);
257         WorkspacePluginModelBase model;
258         if (name.equals("fragment.xml")) //$NON-NLS-1$
259
model = new WorkspaceFragmentModel(file, false);
260         else
261             model = new WorkspacePluginModel(file, false);
262         
263         IPluginBase pluginBase = model.getPluginBase(true);
264         try {
265             pluginBase.setSchemaVersion(TargetPlatformHelper.getTargetVersion() < 3.2 ? "3.0" : "3.2"); //$NON-NLS-1$ //$NON-NLS-2$
266
}
267         catch (CoreException e) {
268         }
269         model.save();
270         IEditorInput in = new FileEditorInput(file);
271         fInputContextManager.putContext(in, new PluginInputContext(this, in, false, false));
272
273         updateBuildProperties(name);
274     }
275     
276     private void updateBuildProperties(String JavaDoc filename) {
277         try {
278          InputContext context = fInputContextManager.findContext(BuildInputContext.CONTEXT_ID);
279          if (context != null) {
280                 IBuildModel buildModel = (IBuildModel)context.getModel();
281                 IBuild build = buildModel.getBuild();
282                 IBuildEntry entry = build.getEntry("bin.includes"); //$NON-NLS-1$
283
if (entry == null) {
284                     entry = buildModel.getFactory().createEntry("bin.includes"); //$NON-NLS-1$
285
build.add(entry);
286                 }
287                 if (!entry.contains(filename))
288                     entry.addToken(filename);
289             }
290          } catch (CoreException e) {
291          }
292      }
293
294     public boolean monitoredFileRemoved(IFile file) {
295         //TODO may need to check with the user if there
296
//are unsaved changes in the model for the
297
//file that just got removed under us.
298
return true;
299     }
300     public void editorContextAdded(InputContext context) {
301         addSourcePage(context.getId());
302         try {
303             if (context.getId().equals(BuildInputContext.CONTEXT_ID))
304                 addPage(BUILD_INDEX, new BuildPage(this));
305             else {
306                 updateFirstThreePages();
307             }
308         }
309         catch (PartInitException e) {
310             PDEPlugin.logException(e);
311         }
312     }
313     public void contextRemoved(InputContext context) {
314         close(true);
315     }
316     
317     private void updateFirstThreePages() {
318         try {
319             int index = getActivePage();
320             removePage(0);
321             removePage(0);
322             removePage(0);
323             addPage(0, new RuntimePage(this));
324             addPage(0, new DependenciesPage(this));
325             addPage(0, new OverviewPage(this));
326             setActivePage(index);
327         } catch (PartInitException e) {
328             PDEPlugin.logException(e);
329         }
330     }
331
332     protected void createSystemFileContexts(InputContextManager manager,
333             SystemFileEditorInput input) {
334         File JavaDoc file = (File JavaDoc) input.getAdapter(File JavaDoc.class);
335         File JavaDoc manifestFile = null;
336         File JavaDoc buildFile = null;
337         File JavaDoc pluginFile = null;
338         String JavaDoc name = file.getName().toLowerCase(Locale.ENGLISH);
339         if (name.equals("manifest.mf")) { //$NON-NLS-1$
340
manifestFile = file;
341             File JavaDoc dir = file.getParentFile().getParentFile();
342             buildFile = new File JavaDoc(dir, "build.properties"); //$NON-NLS-1$
343
pluginFile = createPluginFile(dir);
344         } else if (name.equals("build.properties")) { //$NON-NLS-1$
345
buildFile = file;
346             File JavaDoc dir = file.getParentFile();
347             pluginFile = createPluginFile(dir);
348             manifestFile = new File JavaDoc(dir, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
349
} else if (name.equals("plugin.xml") || name.equals("fragment.xml")) { //$NON-NLS-1$ //$NON-NLS-2$
350
pluginFile = file;
351             File JavaDoc dir = file.getParentFile();
352             buildFile = new File JavaDoc(dir, "build.properties"); //$NON-NLS-1$
353
manifestFile = new File JavaDoc(dir, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
354
}
355         if (manifestFile.exists()) {
356             IEditorInput in = new SystemFileEditorInput(manifestFile);
357             manager.putContext(in, new BundleInputContext(this, in,
358                     file == manifestFile));
359         }
360         if (pluginFile.exists()) {
361             SystemFileEditorInput in = new SystemFileEditorInput(pluginFile);
362             manager.putContext(in, new PluginInputContext(this, in,
363                     file == pluginFile, name.equals("fragment.xml"))); //$NON-NLS-1$
364
}
365         if (buildFile.exists()) {
366             SystemFileEditorInput in = new SystemFileEditorInput(buildFile);
367             manager.putContext(in, new BuildInputContext(this, in,
368                     file == buildFile));
369         }
370     }
371     private File JavaDoc createPluginFile(File JavaDoc dir) {
372         File JavaDoc pluginFile = new File JavaDoc(dir, "plugin.xml"); //$NON-NLS-1$
373
if (!pluginFile.exists())
374             pluginFile = new File JavaDoc(dir, "fragment.xml"); //$NON-NLS-1$
375
return pluginFile;
376     }
377     
378     private IFile createPluginFile(IContainer container) {
379         IFile pluginFile = container.getFile(new Path("plugin.xml")); //$NON-NLS-1$
380
if (!pluginFile.exists())
381             pluginFile = container.getFile(new Path("fragment.xml")); //$NON-NLS-1$
382
return pluginFile;
383     }
384     
385     protected void createStorageContexts(InputContextManager manager,
386             IStorageEditorInput input) {
387         if (input instanceof JarEntryEditorInput) {
388             createJarEntryContexts(manager, (JarEntryEditorInput)input);
389             return;
390         }
391         
392         String JavaDoc name = input.getName().toLowerCase(Locale.ENGLISH);
393         if (name.startsWith("manifest.mf")) { //$NON-NLS-1$
394
manager
395                     .putContext(input,
396                             new BundleInputContext(this, input, true));
397         } else if (name.startsWith("build.properties")) { //$NON-NLS-1$
398
manager.putContext(input, new BuildInputContext(this, input, true));
399         } else if (name.startsWith("plugin.xml")) { //$NON-NLS-1$
400
manager.putContext(input, new PluginInputContext(this, input, true,
401                     false));
402         } else if (name.startsWith("fragment.xml")) { //$NON-NLS-1$
403
manager.putContext(input, new PluginInputContext(this, input, true,
404                     true));
405         }
406     }
407     
408     protected void createJarEntryContexts(InputContextManager manager,
409             JarEntryEditorInput input) {
410         IStorage storage = input.getStorage();
411         ZipFile JavaDoc zip = (ZipFile JavaDoc)storage.getAdapter(ZipFile JavaDoc.class);
412         try {
413             if (zip == null)
414                 return;
415             
416             if (zip.getEntry("META-INF/MANIFEST.MF") != null) { //$NON-NLS-1$
417
input = new JarEntryEditorInput(new JarEntryFile(zip, "META-INF/MANIFEST.MF")); //$NON-NLS-1$
418
manager.putContext(input, new BundleInputContext(this, input, storage.getName().equals("MANIFEST.MF"))); //$NON-NLS-1$
419
}
420             
421             if (zip.getEntry("plugin.xml") != null) { //$NON-NLS-1$
422
input = new JarEntryEditorInput(new JarEntryFile(zip, "plugin.xml")); //$NON-NLS-1$
423
manager.putContext(input, new PluginInputContext(this, input, storage.getName().equals("plugin.xml"), false)); //$NON-NLS-1$
424
} else if (zip.getEntry("fragment.xml") != null) { //$NON-NLS-1$
425
input = new JarEntryEditorInput(new JarEntryFile(zip, "fragment.xml")); //$NON-NLS-1$
426
manager.putContext(input, new PluginInputContext(this, input, storage.getName().equals("fragment.xml"), true)); //$NON-NLS-1$
427
}
428             
429             if (zip.getEntry("build.properties") != null) { //$NON-NLS-1$
430
input = new JarEntryEditorInput(new JarEntryFile(zip, "build.properties")); //$NON-NLS-1$
431
manager.putContext(input, new BuildInputContext(this, input, storage.getName().equals("build.properties"))); //$NON-NLS-1$
432
}
433         } finally {
434             try {
435                 if (zip != null)
436                     zip.close();
437             } catch (IOException JavaDoc e) {
438             }
439         }
440     }
441     
442     protected void addEditorPages() {
443         try {
444             addPage(new OverviewPage(this));
445             addPage(new DependenciesPage(this));
446             addPage(new RuntimePage(this));
447             if (showExtensionTabs()) {
448                 addExtensionTabs();
449             }
450             if (fInputContextManager.hasContext(BuildInputContext.CONTEXT_ID))
451                 addPage(new BuildPage(this));
452         } catch (PartInitException e) {
453             PDEPlugin.logException(e);
454         }
455         addSourcePage(BundleInputContext.CONTEXT_ID);
456         addSourcePage(PluginInputContext.CONTEXT_ID);
457         addSourcePage(BuildInputContext.CONTEXT_ID);
458     }
459
460     /**
461      * @param pageID
462      * @return
463      */

464     private boolean isSourcePageID(String JavaDoc pageID) {
465         // Determine whether the page ID is a source page ID
466
if (pageID == null) {
467             return false;
468         } else if (pageID.equals(BuildInputContext.CONTEXT_ID)) {
469             // build.properites
470
return true;
471         } else if (pageID.equals(PluginInputContext.CONTEXT_ID)) {
472             // plugin.xml
473
return true;
474         } else if (pageID.equals(BundleInputContext.CONTEXT_ID)) {
475             // MANIFEST.MF
476
return true;
477         }
478         return false;
479     }
480     
481     /* (non-Javadoc)
482      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#computeInitialPageId()
483      */

484     protected String JavaDoc computeInitialPageId() {
485         // Used by plug-in search view to open query results, etc.
486
if (SHOW_SOURCE) {
487             SHOW_SOURCE = false;
488             return getPrimarySourceInputContextID();
489         }
490         // Retrieve the initial page
491
String JavaDoc firstPageId = super.computeInitialPageId();
492         // If none is defined, return the default
493
// If the initial page is a source page ID (e.g. build.properties,
494
// MANIFEST.MF, plugin.xml), then return the page ID belonging to the
495
// input context or file used to open this editor
496
if (firstPageId == null) {
497             return OverviewPage.PAGE_ID;
498         } else if (isSourcePageID(firstPageId)) {
499             return getPrimarySourceInputContextID();
500         }
501         
502         return firstPageId;
503     }
504     
505     /* (non-Javadoc)
506      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getPropertyEditorPageKey(org.eclipse.ui.IFileEditorInput)
507      */

508     protected String JavaDoc getPropertyEditorPageKey(IFileEditorInput input) {
509         // We are using the project itself to persist the editor page key property
510
// The value persists even after the editor is closed
511
// The project is used rather than the file in this case because the
512
// manifest editor has 3 input files and only one build.properties,
513
// one MANIFEST.MF and one plugin.xml should exist for each project.
514
// We also want the last editor page to be shared between the two
515
// input contexts. The build.properties file has its own editor.
516
IFile file = input.getFile();
517         IProject project = file.getProject();
518         // Ensure the project is defined
519
if (project == null) {
520             // Check the file for the key
521
return super.getPropertyEditorPageKey(input);
522         }
523         // Get the persistent editor page key from the project
524
try {
525             return project.getPersistentProperty(
526                     IPDEUIConstants.PROPERTY_MANIFEST_EDITOR_PAGE_KEY);
527         } catch (CoreException e) {
528             // Check the file for the key
529
return super.getPropertyEditorPageKey(input);
530         }
531     }
532     
533     /* (non-Javadoc)
534      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#setPropertyEditorPageKey(org.eclipse.ui.IFileEditorInput, java.lang.String)
535      */

536     protected void setPropertyEditorPageKey(IFileEditorInput input,
537             String JavaDoc pageId) {
538         // We are using the project itself to persist the editor page key property
539
// The value persists even after the editor is closed
540
// The project is used rather than the file in this case because the
541
// manifest editor has 3 input files and only one build.properties,
542
// one MANIFEST.MF and one plugin.xml should exist for each project.
543
// We also want the last editor page to be shared between the two
544
// input contexts. The build.properties file has its own editor.
545
IFile file = input.getFile();
546         IProject project = file.getProject();
547         // Ensure the project is defined
548
if (project == null) {
549             // Set the key on the file
550
super.setPropertyEditorPageKey(input, pageId);
551             return;
552         }
553         // Set the editor page ID as a persistent property on the project
554
try {
555             project.setPersistentProperty(
556                     IPDEUIConstants.PROPERTY_MANIFEST_EDITOR_PAGE_KEY,
557                     pageId);
558         } catch (CoreException e) {
559             // Set the key on the file
560
super.setPropertyEditorPageKey(input, pageId);
561             return;
562         }
563     }
564     
565     /**
566      * @return
567      */

568     private String JavaDoc getPrimarySourceInputContextID() {
569         // Get the input context used to open this editor
570
InputContext primary = fInputContextManager.getPrimaryContext();
571         // Ensure it is defined
572
if (primary == null) {
573             return null;
574         }
575         // Return its ID
576
return primary.getId();
577     }
578     
579     /* (non-Javadoc)
580      * @see org.eclipse.pde.internal.ui.neweditor.MultiSourceEditor#createXMLSourcePage(org.eclipse.pde.internal.ui.neweditor.PDEFormEditor, java.lang.String, java.lang.String)
581      */

582     protected PDESourcePage createSourcePage(PDEFormEditor editor, String JavaDoc title, String JavaDoc name, String JavaDoc contextId) {
583         if (contextId.equals(PluginInputContext.CONTEXT_ID))
584             return new ManifestSourcePage(editor, title, name);
585         if (contextId.equals(BuildInputContext.CONTEXT_ID))
586             return new BuildSourcePage(editor, title, name);
587         if (contextId.equals(BundleInputContext.CONTEXT_ID))
588             return new BundleSourcePage(editor, title, name);
589         return super.createSourcePage(editor, title, name, contextId);
590     }
591     
592     protected ISortableContentOutlinePage createContentOutline() {
593         return new ManifestOutlinePage(this);
594     }
595     
596     public Object JavaDoc getAdapter(Class JavaDoc key) {
597         //No property sheet needed - block super
598
if (key.equals(IPropertySheetPage.class)) {
599             return null;
600         }
601         return super.getAdapter(key);
602     }
603
604
605     public String JavaDoc getTitle() {
606         IPluginModelBase model = (IPluginModelBase)getAggregateModel();
607         if (model==null || !model.isValid())
608             return super.getTitle();
609         String JavaDoc text = getTitleText(model.getPluginBase());
610         if (text == null)
611             return super.getTitle();
612         return model.getResourceString(text);
613     }
614     
615     public String JavaDoc getTitleProperty() {
616         IPreferenceStore store = PDEPlugin.getDefault().getPreferenceStore();
617         String JavaDoc pref = store.getString(IPreferenceConstants.PROP_SHOW_OBJECTS);
618         if (pref!=null && pref.equals(IPreferenceConstants.VALUE_USE_NAMES))
619             return IPluginObject.P_NAME;
620         return IIdentifiable.P_ID;
621     }
622     
623     private String JavaDoc getTitleText(IPluginBase pluginBase) {
624         IPreferenceStore store = PDEPlugin.getDefault().getPreferenceStore();
625         String JavaDoc pref = store.getString(IPreferenceConstants.PROP_SHOW_OBJECTS);
626         if (pref!=null && pref.equals(IPreferenceConstants.VALUE_USE_NAMES))
627             return pluginBase.getName();
628         return pluginBase.getId();
629     }
630
631     /* (non-Javadoc)
632      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
633      */

634     protected InputContext getInputContext(Object JavaDoc object) {
635         InputContext context = null;
636         if (object instanceof IFile) {
637             String JavaDoc name = ((IFile)object).getName();
638             if (name.equals("plugin.xml") || name.equals("fragment.xml")) //$NON-NLS-1$ //$NON-NLS-2$
639
context = fInputContextManager.findContext(PluginInputContext.CONTEXT_ID);
640             else if (name.equals("MANIFEST.MF")) //$NON-NLS-1$
641
context = fInputContextManager.findContext(BundleInputContext.CONTEXT_ID);
642             else if (name.equals("build.properties")) //$NON-NLS-1$
643
context = fInputContextManager.findContext(BuildInputContext.CONTEXT_ID);
644         } else if (object instanceof IBuildObject) {
645             context = fInputContextManager.findContext(BuildInputContext.CONTEXT_ID);
646         } else if (object instanceof IPluginExtensionPoint || object instanceof IPluginExtension) {
647             context = fInputContextManager.findContext(PluginInputContext.CONTEXT_ID);
648         } else {
649             context = fInputContextManager.findContext(BundleInputContext.CONTEXT_ID);
650             if (context == null)
651                 context = fInputContextManager.findContext(PluginInputContext.CONTEXT_ID);
652         }
653         return context;
654     }
655     
656     /* (non-Javadoc)
657      * @see org.eclipse.ui.IShowEditorInput#showEditorInput(org.eclipse.ui.IEditorInput)
658      */

659     public void showEditorInput(IEditorInput editorInput) {
660         String JavaDoc name = editorInput.getName();
661         String JavaDoc id = getActivePageInstance().getId();
662         if (name.equals("build.properties")) { //$NON-NLS-1$
663
if (!BuildInputContext.CONTEXT_ID.equals(id))
664                 setActivePage(SHOW_SOURCE ? BuildInputContext.CONTEXT_ID : BuildPage.PAGE_ID);
665         } else if (name.equals("plugin.xml") || name.equals("fragment.xml")) { //$NON-NLS-1$ //$NON-NLS-2$
666
if (!PluginInputContext.CONTEXT_ID.equals(id)) {
667                 if (SHOW_SOURCE) {
668                     setActivePage(PluginInputContext.CONTEXT_ID);
669                 } else if (fInputContextManager.hasContext(BundleInputContext.CONTEXT_ID)) {
670                     setActivePage(ExtensionsPage.PAGE_ID);
671                 } else {
672                     setActivePage(OverviewPage.PAGE_ID);
673                 }
674             }
675         } else if (!BundleInputContext.CONTEXT_ID.equals(id)) {
676             setActivePage(SHOW_SOURCE ? BundleInputContext.CONTEXT_ID : OverviewPage.PAGE_ID);
677         }
678     }
679     
680     public boolean showExtensionTabs() {
681         if (fInputContextManager.hasContext(PluginInputContext.CONTEXT_ID))
682             return true;
683         IBaseModel model = getAggregateModel();
684         return fShowExtensions && model != null && model.isEditable();
685      }
686
687     public boolean isEquinox() {
688         return fEquinox;
689     }
690     
691     protected void addExtensionTabs() throws PartInitException {
692         addPage(3, new ExtensionPointsPage(this));
693         addPage(3, new ExtensionsPage(this));
694     }
695     
696     protected void setShowExtensions(boolean show) throws BackingStoreException {
697         if (fPrefs != null) {
698             fPrefs.putBoolean(ICoreConstants.EXTENSIONS_PROPERTY, show);
699             fPrefs.flush();
700         }
701         fShowExtensions = show;
702     }
703 }
704
Popular Tags