1 11 package org.eclipse.pde.internal.ui.editor.plugin.rows; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.jdt.core.search.IJavaSearchConstants; 16 import org.eclipse.jdt.ui.IJavaElementSearchConstants; 17 import org.eclipse.pde.core.IBaseModel; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 21 import org.eclipse.pde.internal.ui.editor.IContextPart; 22 import org.eclipse.pde.internal.ui.editor.contentassist.TypeFieldAssistDisposer; 23 import org.eclipse.pde.internal.ui.editor.plugin.JavaAttributeValue; 24 import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI; 25 import org.eclipse.pde.internal.ui.util.TextUtil; 26 import org.eclipse.swt.custom.BusyIndicator; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.ui.forms.widgets.FormToolkit; 29 30 public class ClassAttributeRow extends ButtonAttributeRow { 31 32 private TypeFieldAssistDisposer fTypeFieldAssistDisposer; 33 34 public ClassAttributeRow(IContextPart part, ISchemaAttribute att) { 35 super(part, att); 36 } 37 protected boolean isReferenceModel() { 38 return !part.getPage().getModel().isEditable(); 39 } 40 45 protected void openReference() { 46 String name = TextUtil.trimNonAlphaChars(text.getText()).replace('$', '.'); 47 name = PDEJavaHelperUI.createClass( 48 name, getProject(), 49 createJavaAttributeValue(name), true); 50 if (name != null) 51 text.setText(name); 52 } 53 54 59 public void createContents(Composite parent, FormToolkit toolkit, int span) { 60 super.createContents(parent, toolkit, span); 61 62 if (part.isEditable()) { 63 fTypeFieldAssistDisposer = 64 PDEJavaHelperUI.addTypeFieldAssistToText(text, 65 getProject(), 66 IJavaSearchConstants.CLASS_AND_INTERFACE); 67 } 68 } 69 70 75 protected void browse() { 76 BusyIndicator.showWhile(text.getDisplay(), new Runnable () { 77 public void run() { 78 doOpenSelectionDialog(); 79 } 80 }); 81 } 82 private JavaAttributeValue createJavaAttributeValue(String name) { 83 IProject project = part.getPage().getPDEEditor().getCommonProject(); 84 IPluginModelBase model = (IPluginModelBase) part.getPage().getModel(); 85 return new JavaAttributeValue(project, model, getAttribute(), name); 86 } 87 private void doOpenSelectionDialog() { 88 IResource resource = getPluginBase().getModel().getUnderlyingResource(); 89 String type = PDEJavaHelperUI.selectType( 90 resource, 91 IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, 92 text.getText()); 93 if (type != null) 94 text.setText(type); 95 96 } 97 private IPluginBase getPluginBase() { 98 IBaseModel model = part.getPage().getPDEEditor().getAggregateModel(); 99 return ((IPluginModelBase) model).getPluginBase(); 100 } 101 102 105 public void dispose() { 106 super.dispose(); 107 if (fTypeFieldAssistDisposer != null) { 108 fTypeFieldAssistDisposer.dispose(); 109 } 110 } 111 } 112 | Popular Tags |