1 11 package org.eclipse.pde.internal.ui.editor.plugin.rows; 12 import org.eclipse.core.runtime.CoreException; 13 import org.eclipse.jface.text.ITextSelection; 14 import org.eclipse.jface.text.TextSelection; 15 import org.eclipse.pde.core.plugin.IPluginAttribute; 16 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 17 import org.eclipse.pde.internal.ui.PDEPlugin; 18 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 19 import org.eclipse.pde.internal.ui.editor.IContextPart; 20 import org.eclipse.pde.internal.ui.editor.text.PDETextHover; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.events.FocusAdapter; 23 import org.eclipse.swt.events.FocusEvent; 24 import org.eclipse.swt.events.ModifyEvent; 25 import org.eclipse.swt.events.ModifyListener; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Text; 29 import org.eclipse.ui.forms.widgets.FormToolkit; 30 31 public class TextAttributeRow extends ExtensionAttributeRow { 32 protected Text text; 33 36 public TextAttributeRow(IContextPart part, ISchemaAttribute att) { 37 super(part, att); 38 } 39 40 public TextAttributeRow(IContextPart part, IPluginAttribute att) { 41 super(part, att); 42 } 43 public void createContents(Composite parent, FormToolkit toolkit, int span) { 44 super.createContents(parent, toolkit, span); 45 createLabel(parent, toolkit); 46 text = toolkit.createText(parent, "", SWT.SINGLE); text.setLayoutData(createGridData(span)); 48 text.addModifyListener(new ModifyListener() { 49 public void modifyText(ModifyEvent e) { 50 if (!blockNotification) markDirty(); 51 PDETextHover.updateHover(fIC, getHoverContent(text)); 52 } 53 }); 54 text.setEditable(part.isEditable()); 55 PDETextHover.addHoverListenerToControl(fIC, text, this); 56 createUITextFocusListener(); 58 } 59 60 63 private void createUITextFocusListener() { 64 text.addFocusListener(new FocusAdapter() { 66 public void focusGained(FocusEvent e) { 67 ITextSelection selection = new TextSelection(1,1); 68 part.getPage().getPDEEditor().getContributor().updateSelectableActions(selection); 69 } 70 }); 71 } 72 73 protected GridData createGridData(int span) { 74 GridData gd = new GridData(span == 2 75 ? GridData.FILL_HORIZONTAL 76 : GridData.HORIZONTAL_ALIGN_FILL); 77 gd.widthHint = 20; 78 gd.horizontalSpan = span - 1; 79 gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT; 80 return gd; 81 } 82 87 protected void update() { 88 blockNotification = true; 89 text.setText(getValue()); 90 blockNotification = false; 91 } 92 public void commit() { 93 if (dirty && input!=null) { 94 String value = text.getText(); 95 try { 96 input.setAttribute(getName(), value); 97 dirty = false; 98 } catch (CoreException e) { 99 PDEPlugin.logException(e); 100 } 101 } 102 } 103 public void setFocus() { 104 text.setFocus(); 105 } 106 } 107 | Popular Tags |