1 11 package org.eclipse.pde.internal.ui.editor.target; 12 13 import java.io.File ; 14 import java.net.URL ; 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 LAST_PATH; 38 39 static { 40 Location installLoc = Platform.getInstallLocation(); 41 if (installLoc == null) { 42 LAST_PATH = ""; } 44 URL url = installLoc.getURL(); 45 LAST_PATH = new Path(url.getPath()).toOSString(); 46 } 47 48 public TargetEditor() { 49 super(); 50 } 51 52 55 protected String getEditorID() { 56 return IPDEUIConstants.TARGET_EDITOR_ID; 57 } 58 59 62 public boolean isSaveAsAllowed() { 63 return true; 64 } 65 66 69 public String getContextIDForSaveAs() { 70 return TargetInputContext.CONTEXT_ID; 71 } 72 73 76 protected InputContextManager createInputContextManager() { 77 return new TargetInputContextManager(this); 78 } 79 80 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 91 protected void createSystemFileContexts(InputContextManager manager, 92 SystemFileEditorInput input) { 93 File file = (File ) input.getAdapter(File .class); 94 if (file != null) { 95 String name = file.getName(); 96 if (name.endsWith(".target")) { IEditorInput in = new SystemFileEditorInput(file); 98 manager.putContext(in, new TargetInputContext(this, in, true)); 99 } 100 } 101 } 102 103 106 protected void createStorageContexts(InputContextManager manager, 107 IStorageEditorInput input) { 108 if (input.getName().endsWith(".target")) { manager.putContext(input, new TargetInputContext(this, input, true)); 110 } 111 } 112 113 116 protected ISortableContentOutlinePage createContentOutline() { 117 return new TargetOutlinePage(this); 118 } 119 120 123 protected InputContext getInputContext(Object object) { 124 return fInputContextManager.findContext(TargetInputContext.CONTEXT_ID); 125 } 126 127 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 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 153 public void editorContextAdded(InputContext context) { 154 } 155 156 159 public void contextRemoved(InputContext context) { 160 close(false); 161 } 162 163 166 public void monitoredFileAdded(IFile monitoredFile) { 167 } 168 169 172 public boolean monitoredFileRemoved(IFile monitoredFile) { 173 return true; 174 } 175 176 } | Popular Tags |