1 11 12 package org.eclipse.pde.internal.ui.editor.plugin.rows; 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.jface.text.IInformationControl; 16 import org.eclipse.pde.core.plugin.IPluginAttribute; 17 import org.eclipse.pde.core.plugin.IPluginElement; 18 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 19 import org.eclipse.pde.internal.ui.editor.IContextPart; 20 import org.eclipse.pde.internal.ui.editor.text.PDETextHover; 21 import org.eclipse.pde.internal.ui.editor.text.IControlHoverContentProvider; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.swt.widgets.Text; 27 import org.eclipse.ui.forms.IFormColors; 28 import org.eclipse.ui.forms.widgets.FormToolkit; 29 import org.eclipse.ui.forms.widgets.Hyperlink; 30 31 public abstract class ExtensionAttributeRow implements IControlHoverContentProvider { 32 protected IContextPart part; 33 protected Object att; 34 protected IPluginElement input; 35 protected boolean blockNotification; 36 protected boolean dirty; 37 protected IInformationControl fIC; 38 39 public ExtensionAttributeRow(IContextPart part, ISchemaAttribute att) { 40 this.part = part; 41 this.att = att; 42 } 43 44 public ExtensionAttributeRow(IContextPart part, IPluginAttribute att) { 45 this.part = part; 46 this.att = att; 47 } 48 49 public ISchemaAttribute getAttribute() { 50 return (att instanceof ISchemaAttribute) ? (ISchemaAttribute)att:null; 51 } 52 53 public String getName() { 54 if (att instanceof ISchemaAttribute) 55 return ((ISchemaAttribute)att).getName(); 56 57 return ((IPluginAttribute)att).getName(); 58 } 59 60 protected int getUse() { 61 if (att instanceof ISchemaAttribute) 62 return ((ISchemaAttribute)att).getUse(); 63 return ISchemaAttribute.OPTIONAL; 64 } 65 66 protected String getDescription() { 67 if (att instanceof ISchemaAttribute) 68 return ((ISchemaAttribute)att).getDescription(); 69 return ""; } 71 72 protected String getValue() { 73 String value= ""; if (input!=null) { 75 IPluginAttribute patt = input.getAttribute(getName()); 76 if (patt!=null) 77 value = patt.getValue(); 78 } 79 return value; 80 } 81 protected String getPropertyLabel() { 82 String label=getName(); 83 if (getUse()==ISchemaAttribute.REQUIRED) 84 label+= "*:"; else 86 label+=":"; return label; 88 } 89 protected void createLabel(Composite parent, FormToolkit toolkit) { 90 Label label = toolkit.createLabel(parent, getPropertyLabel(), SWT.NULL); 91 label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); 92 PDETextHover.addHoverListenerToControl(fIC, label, this); 93 } 94 95 98 protected void createTextHover(Control control) { 99 fIC = PDETextHover.getInformationControlCreator().createInformationControl(control.getShell()); 100 fIC.setSizeConstraints(300, 600); 101 } 102 103 public String getHoverContent(Control c) { 104 if (c instanceof Label || c instanceof Hyperlink) 105 return getDescription(); 106 if (c instanceof Text) { 107 String text = ((Text)c).getText(); 108 ISchemaAttribute sAtt = getAttribute(); 109 String translated = null; 110 if (input != null && sAtt != null && sAtt.isTranslatable() && text.startsWith("%")) translated = input.getResourceString(text); 112 if (!text.equals(translated)) 113 return translated; 114 } 115 return null; 116 } 117 118 123 public void createContents(Composite parent, FormToolkit toolkit, int span) { 124 createTextHover(parent); 125 } 126 127 protected abstract void update(); 128 public abstract void commit(); 129 130 public abstract void setFocus(); 131 132 public boolean isDirty() { 133 return dirty; 134 } 135 136 protected void markDirty() { 137 dirty=true; 138 part.fireSaveNeeded(); 139 } 140 141 public void dispose() { 142 if (fIC != null) 143 fIC.dispose(); 144 } 145 146 public void setInput(IPluginElement input) { 147 this.input = input; 148 update(); 149 } 150 protected IProject getProject() { 151 return part.getPage().getPDEEditor().getCommonProject(); 152 } 153 } 154 | Popular Tags |