1 11 package org.eclipse.pde.internal.ui.editor.build; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.pde.core.build.IBuildModel; 15 import org.eclipse.pde.internal.core.build.IBuildObject; 16 import org.eclipse.pde.internal.ui.IPDEUIConstants; 17 import org.eclipse.pde.internal.ui.PDEPlugin; 18 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage; 19 import org.eclipse.pde.internal.ui.editor.MultiSourceEditor; 20 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 21 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 22 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 23 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput; 24 import org.eclipse.pde.internal.ui.editor.context.InputContext; 25 import org.eclipse.pde.internal.ui.editor.context.InputContextManager; 26 import org.eclipse.swt.SWTError; 27 import org.eclipse.swt.dnd.RTFTransfer; 28 import org.eclipse.swt.dnd.TextTransfer; 29 import org.eclipse.swt.dnd.Transfer; 30 import org.eclipse.swt.dnd.TransferData; 31 import org.eclipse.ui.IEditorInput; 32 import org.eclipse.ui.IFileEditorInput; 33 import org.eclipse.ui.IStorageEditorInput; 34 import org.eclipse.ui.PartInitException; 35 import org.eclipse.ui.part.FileEditorInput; 36 import org.eclipse.ui.views.properties.IPropertySheetPage; 37 38 public class BuildEditor extends MultiSourceEditor { 39 40 public BuildEditor() { 41 } 42 43 46 protected String getEditorID() { 47 return IPDEUIConstants.BUILD_EDITOR_ID; 48 } 49 50 protected void createResourceContexts(InputContextManager manager, 51 IFileEditorInput input) { 52 IFile file = input.getFile(); 53 54 manager.putContext(input, new BuildInputContext(this, input, true)); 55 manager.monitorFile(file); 56 } 57 58 protected InputContextManager createInputContextManager() { 59 BuildInputContextManager manager = new BuildInputContextManager(this); 60 manager.setUndoManager(new BuildUndoManager(this)); 61 return manager; 62 } 63 64 public void monitoredFileAdded(IFile file) { 65 String name = file.getName(); 66 if (name.equalsIgnoreCase("build.properties")) { if (!fInputContextManager.hasContext(BuildInputContext.CONTEXT_ID)) { 68 IEditorInput in = new FileEditorInput(file); 69 fInputContextManager.putContext(in, new BuildInputContext(this, in, false)); 70 } 71 } 72 } 73 74 public boolean monitoredFileRemoved(IFile file) { 75 return true; 79 } 80 public void editorContextAdded(InputContext context) { 81 addSourcePage(context.getId()); 82 } 83 public void contextRemoved(InputContext context) { 84 close(false); 85 } 86 87 protected void createSystemFileContexts(InputContextManager manager, 88 SystemFileEditorInput input) { 89 manager.putContext(input, new BuildInputContext(this, input, true)); 90 } 91 92 protected void createStorageContexts(InputContextManager manager, 93 IStorageEditorInput input) { 94 manager.putContext(input, new BuildInputContext(this, input, true)); 95 } 96 97 protected void addEditorPages() { 98 try { 99 if (getEditorInput() instanceof IFileEditorInput) 100 addPage(new BuildPage(this)); 101 } catch (PartInitException e) { 102 PDEPlugin.logException(e); 103 } 104 addSourcePage(BuildInputContext.CONTEXT_ID); 105 } 106 107 110 protected String computeInitialPageId() { 111 String firstPageId = super.computeInitialPageId(); 113 if (firstPageId == null) { 115 return BuildPage.PAGE_ID; 116 } 117 118 return firstPageId; 119 } 120 121 124 protected PDESourcePage createSourcePage(PDEFormEditor editor, String title, String name, String contextId) { 125 return new BuildSourcePage(editor, title, name); 126 } 127 128 protected ISortableContentOutlinePage createContentOutline() { 129 return new BuildOutlinePage(this); 130 } 131 132 protected IPropertySheetPage getPropertySheet(PDEFormPage page) { 133 return null; 134 } 135 136 public String getTitle() { 137 return super.getTitle(); 138 } 139 140 protected boolean isModelCorrect(Object model) { 141 return model != null ? ((IBuildModel) model).isValid() : false; 142 } 143 protected boolean hasKnownTypes() { 144 try { 145 TransferData[] types = getClipboard().getAvailableTypes(); 146 Transfer[] transfers = 147 new Transfer[] { TextTransfer.getInstance(), RTFTransfer.getInstance()}; 148 for (int i = 0; i < types.length; i++) { 149 for (int j = 0; j < transfers.length; j++) { 150 if (transfers[j].isSupportedType(types[i])) 151 return true; 152 } 153 } 154 } catch (SWTError e) { 155 } 156 return false; 157 } 158 159 public Object getAdapter(Class key) { 160 if (key.equals(IPropertySheetPage.class)) { 162 return null; 163 } 164 return super.getAdapter(key); 165 } 166 167 170 protected InputContext getInputContext(Object object) { 171 InputContext context = null; 172 if (object instanceof IBuildObject) { 173 context = fInputContextManager.findContext(BuildInputContext.CONTEXT_ID); 174 } 175 return context; 176 } 177 178 } 179 | Popular Tags |