1 11 14 package org.eclipse.pde.internal.ui.editor.site; 15 import java.io.File ; 16 import java.util.Locale ; 17 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.jface.action.IMenuManager; 20 import org.eclipse.pde.internal.core.isite.ISiteObject; 21 import org.eclipse.pde.internal.ui.IPDEUIConstants; 22 import org.eclipse.pde.internal.ui.PDEPlugin; 23 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage; 24 import org.eclipse.pde.internal.ui.editor.MultiSourceEditor; 25 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 26 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 27 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput; 28 import org.eclipse.pde.internal.ui.editor.context.InputContext; 29 import org.eclipse.pde.internal.ui.editor.context.InputContextManager; 30 import org.eclipse.ui.IEditorInput; 31 import org.eclipse.ui.IFileEditorInput; 32 import org.eclipse.ui.IStorageEditorInput; 33 import org.eclipse.ui.PartInitException; 34 import org.eclipse.ui.part.FileEditorInput; 35 36 public class SiteEditor extends MultiSourceEditor { 37 38 41 protected String getEditorID() { 42 return IPDEUIConstants.SITE_EDITOR_ID; 43 } 44 45 protected void createResourceContexts(InputContextManager manager, 46 IFileEditorInput input) { 47 IFile file = input.getFile(); 48 IFile siteFile = null; 49 String name = file.getName().toLowerCase(Locale.ENGLISH); 50 if (name.equals("site.xml")) { siteFile = file; 52 if (siteFile.exists()) { 53 IEditorInput in = new FileEditorInput(siteFile); 54 manager.putContext(in, new SiteInputContext(this, in, file==siteFile)); 55 } 56 manager.monitorFile(siteFile); 57 } 58 } 59 60 protected InputContextManager createInputContextManager() { 61 SiteInputContextManager contextManager = new SiteInputContextManager(this); 62 contextManager.setUndoManager(new SiteUndoManager(this)); 63 return contextManager; 64 } 65 66 67 public void monitoredFileAdded(IFile file) { 68 } 69 70 public boolean monitoredFileRemoved(IFile file) { 71 return true; 75 } 76 public void editorContextAdded(InputContext context) { 77 addSourcePage(context.getId()); 78 } 79 public void contextRemoved(InputContext context) { 80 close(false); 81 } 82 83 protected void createSystemFileContexts(InputContextManager manager, 84 SystemFileEditorInput input) { 85 File file = (File ) input.getAdapter(File .class); 86 File siteFile = null; 87 88 String name = file.getName().toLowerCase(Locale.ENGLISH); 89 if (name.equals("site.xml")) { siteFile = file; 91 if (siteFile.exists()) { 92 IEditorInput in = new SystemFileEditorInput(siteFile); 93 manager.putContext(in, new SiteInputContext(this, in, 94 file == siteFile)); 95 } 96 } 97 } 98 99 protected void createStorageContexts(InputContextManager manager, 100 IStorageEditorInput input) { 101 String name = input.getName().toLowerCase(Locale.ENGLISH); 102 if (name.startsWith("site.xml")) { manager.putContext(input, new SiteInputContext(this, input, true)); 104 } 105 } 106 107 protected void contextMenuAboutToShow(IMenuManager manager) { 108 super.contextMenuAboutToShow(manager); 109 } 110 111 protected void addEditorPages() { 112 try { 113 addPage(new FeaturesPage(this)); 114 addPage(new ArchivePage(this)); 115 } catch (PartInitException e) { 116 PDEPlugin.logException(e); 117 } 118 addSourcePage(SiteInputContext.CONTEXT_ID); 119 } 120 121 122 protected String computeInitialPageId() { 123 return FeaturesPage.PAGE_ID; 124 } 125 126 129 protected PDESourcePage createSourcePage(PDEFormEditor editor, String title, String name, String contextId) { 130 return new SiteSourcePage(editor, title, name); 131 } 132 133 protected ISortableContentOutlinePage createContentOutline() { 134 return new SiteOutlinePage(this); 135 } 136 137 141 protected InputContext getInputContext(Object object) { 142 InputContext context = null; 143 if (object instanceof ISiteObject) { 144 context = fInputContextManager 145 .findContext(SiteInputContext.CONTEXT_ID); 146 } 147 return context; 148 } 149 150 } | Popular Tags |