1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 import org.eclipse.jface.viewers.StructuredSelection; 13 import org.eclipse.osgi.util.NLS; 14 import org.eclipse.pde.internal.core.ischema.ISchemaObject; 15 import org.eclipse.pde.internal.core.schema.SchemaElementReference; 16 import org.eclipse.pde.internal.ui.PDEUIMessages; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.events.SelectionAdapter; 19 import org.eclipse.swt.events.SelectionEvent; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Label; 23 import org.eclipse.ui.forms.IFormColors; 24 import org.eclipse.ui.forms.events.HyperlinkAdapter; 25 import org.eclipse.ui.forms.events.HyperlinkEvent; 26 import org.eclipse.ui.forms.widgets.FormToolkit; 27 import org.eclipse.ui.forms.widgets.Hyperlink; 28 29 public class SchemaElementReferenceDetails extends AbstractSchemaDetails { 30 31 private SchemaElementReference fElement; 32 private Hyperlink fReferenceLink; 33 private Label fRefLabel; 34 35 public SchemaElementReferenceDetails(ElementSection section) { 36 super(section, true); 37 } 38 39 public void createDetails(Composite parent) { 40 FormToolkit toolkit = getManagedForm().getToolkit(); 41 42 createMinOccurComp(parent, toolkit); 43 createMaxOccurComp(parent, toolkit); 44 45 fRefLabel = toolkit.createLabel(parent, PDEUIMessages.SchemaElementReferenceDetails_reference); 46 fRefLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); 47 fReferenceLink = toolkit.createHyperlink(parent, new String (), SWT.NONE); 48 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 49 gd.horizontalSpan = 2; 50 fReferenceLink.setLayoutData(gd); 51 52 setText(PDEUIMessages.SchemaElementReferenceDetails_title); 53 } 54 55 public void updateFields(ISchemaObject object) { 56 if (!(object instanceof SchemaElementReference)) 57 return; 58 fElement = (SchemaElementReference)object; 59 60 setDecription(NLS.bind(PDEUIMessages.SchemaElementReferenceDetails_description, fElement.getName())); 61 fReferenceLink.setText(fElement.getName()); 62 updateMinOccur(fElement.getMinOccurs()); 63 updateMaxOccur(fElement.getMaxOccurs()); 64 boolean editable = isEditableElement(); 65 fRefLabel.setEnabled(editable); 66 fReferenceLink.setEnabled(editable); 67 enableMinMax(editable); 68 } 69 70 public void hookListeners() { 71 hookMinOccur(new SelectionAdapter() { 72 public void widgetSelected(SelectionEvent e) { 73 if (blockListeners()) 74 return; 75 fElement.setMinOccurs(getMinOccur()); 76 } 77 }); 78 hookMaxOccur(new SelectionAdapter() { 79 public void widgetSelected(SelectionEvent e) { 80 if (blockListeners()) 81 return; 82 fElement.setMaxOccurs(getMaxOccur()); 83 } 84 }); 85 fReferenceLink.addHyperlinkListener(new HyperlinkAdapter() { 86 public void linkActivated(HyperlinkEvent e) { 87 if (blockListeners()) 88 return; 89 fireMasterSelection(new StructuredSelection(fElement.getReferencedObject())); 90 } 91 }); 92 } 93 94 97 public void commit(boolean onSave) { 98 super.commit(onSave); 99 } 102 } 103 | Popular Tags |