1 11 package org.eclipse.pde.internal.ui.editor.build; 12 import org.eclipse.jface.preference.IPreferenceStore; 13 import org.eclipse.jface.text.ITextSelection; 14 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; 15 import org.eclipse.jface.util.PropertyChangeEvent; 16 import org.eclipse.jface.viewers.ILabelProvider; 17 import org.eclipse.jface.viewers.ITreeContentProvider; 18 import org.eclipse.jface.viewers.LabelProvider; 19 import org.eclipse.pde.core.build.IBuild; 20 import org.eclipse.pde.core.build.IBuildEntry; 21 import org.eclipse.pde.core.build.IBuildModel; 22 import org.eclipse.pde.internal.core.text.IDocumentKey; 23 import org.eclipse.pde.internal.core.text.IDocumentRange; 24 import org.eclipse.pde.internal.core.text.build.BuildEntry; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEPluginImages; 27 import org.eclipse.pde.internal.ui.editor.KeyValueSourcePage; 28 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 29 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 30 import org.eclipse.swt.graphics.Image; 31 32 public class BuildSourcePage extends KeyValueSourcePage { 33 class BuildOutlineContentProvider extends DefaultContentProvider 34 implements 35 ITreeContentProvider { 36 public Object [] getChildren(Object parent) { 37 return new Object [0]; 38 } 39 public boolean hasChildren(Object parent) { 40 return false; 41 } 42 public Object getParent(Object child) { 43 if (child instanceof IBuildEntry) 44 return ((IBuildEntry) child).getModel(); 45 return null; 46 } 47 public Object [] getElements(Object parent) { 48 if (parent instanceof IBuildModel) { 49 IBuildModel model = (IBuildModel) parent; 50 IBuild build = model.getBuild(); 51 return build.getBuildEntries(); 52 } 53 return new Object [0]; 54 } 55 } 56 class BuildLabelProvider extends LabelProvider { 57 public String getText(Object obj) { 58 if (obj instanceof IBuildEntry) { 59 return ((IBuildEntry) obj).getName(); 60 } 61 return super.getText(obj); 62 } 63 public Image getImage(Object obj) { 64 if (obj instanceof IBuildEntry) 65 return PDEPlugin.getDefault().getLabelProvider().get( 66 PDEPluginImages.DESC_BUILD_VAR_OBJ); 67 return null; 68 } 69 } 70 71 public BuildSourcePage(PDEFormEditor editor, String id, String title) { 72 super(editor, id, title); 73 } 74 75 public void setPreferenceStore(IPreferenceStore store) { 76 super.setPreferenceStore(store); 77 } 78 79 public ILabelProvider createOutlineLabelProvider() { 80 return new BuildLabelProvider(); 81 } 82 83 public ITreeContentProvider createOutlineContentProvider() { 84 return new BuildOutlineContentProvider(); 85 } 86 protected IDocumentRange getRangeElement(ITextSelection selection) { 87 if (selection.isEmpty()) 88 return null; 89 IBuildModel model = (IBuildModel) getInputContext().getModel(); 90 return findBuildNode(model.getBuild().getBuildEntries(), selection.getOffset()); 91 } 92 93 private BuildEntry findBuildNode(IBuildEntry[] nodes, int offset) { 94 for (int i = 0; i < nodes.length; i++) { 95 BuildEntry node = (BuildEntry) nodes[i]; 96 if (offset >= node.getOffset() 97 && offset < node.getOffset() + node.getLength()) { 98 return node; 99 } 100 } 101 return null; 102 } 103 104 protected String [] collectContextMenuPreferencePages() { 105 String [] ids= super.collectContextMenuPreferencePages(); 106 String [] more= new String [ids.length + 1]; 107 more[0]= "org.eclipse.jdt.ui.preferences.PropertiesFileEditorPreferencePage"; System.arraycopy(ids, 0, more, 1, ids.length); 109 return more; 110 } 111 112 protected boolean affectsTextPresentation(PropertyChangeEvent event) { 113 return ((BuildSourceViewerConfiguration)getSourceViewerConfiguration()).affectsTextPresentation(event) || super.affectsTextPresentation(event); 114 } 115 116 public IDocumentRange getRangeElement(int offset, boolean searchChildren) { 117 IBuildModel model = (IBuildModel) getInputContext().getModel(); 118 IBuildEntry[] buildEntries = model.getBuild().getBuildEntries(); 119 120 for (int i = 0; i < buildEntries.length; i++) { 121 IDocumentKey key = (IDocumentKey) buildEntries[i]; 122 if (offset >= key.getOffset() && offset < key.getOffset() + key.getLength()) 123 return key; 124 } 125 return null; 126 } 127 128 public Object getAdapter(Class adapter) { 129 if (IHyperlinkDetector[].class.equals(adapter)) 130 return new IHyperlinkDetector[] { new BuildHyperlinkDetector(this) }; 131 return super.getAdapter(adapter); 132 } 133 134 137 public void updateSelection(Object object) { 138 if (object instanceof IDocumentKey) { 139 setHighlightRange((IDocumentKey)object); 140 } else { 141 resetHighlightRange(); 142 } 143 } 144 145 } 146 | Popular Tags |