1 11 package org.eclipse.pde.internal.ui.editor.site; 12 import org.eclipse.core.runtime.CoreException; 13 import org.eclipse.pde.core.IModelChangedEvent; 14 import org.eclipse.pde.internal.core.isite.ISite; 15 import org.eclipse.pde.internal.core.isite.ISiteModel; 16 import org.eclipse.pde.internal.ui.PDEPlugin; 17 import org.eclipse.pde.internal.ui.PDEUIMessages; 18 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 19 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 20 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 21 import org.eclipse.pde.internal.ui.editor.PDESection; 22 import org.eclipse.pde.internal.ui.parts.FormEntry; 23 import org.eclipse.swt.dnd.Clipboard; 24 import org.eclipse.swt.dnd.RTFTransfer; 25 import org.eclipse.swt.dnd.TextTransfer; 26 import org.eclipse.swt.dnd.Transfer; 27 import org.eclipse.swt.dnd.TransferData; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.ui.forms.widgets.ExpandableComposite; 31 import org.eclipse.ui.forms.widgets.FormToolkit; 32 import org.eclipse.ui.forms.widgets.Section; 33 34 37 public class MirrorsSection extends PDESection { 38 private FormEntry fMirrorsURLEntry; 39 public MirrorsSection(PDEFormPage page, Composite parent) { 40 super(page, parent, Section.DESCRIPTION | ExpandableComposite.TWISTIE); 41 getSection() 42 .setText( 43 PDEUIMessages.SiteEditor_MirrorsSection_header); 44 getSection() 45 .setDescription( 46 PDEUIMessages.SiteEditor_MirrorsSection_desc); 47 createClient(getSection(), page.getManagedForm().getToolkit()); 48 } 49 public void commit(boolean onSave) { 50 fMirrorsURLEntry.commit(); 51 super.commit(onSave); 52 } 53 public void createClient(Section section, FormToolkit toolkit) { 54 55 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 56 Composite container = toolkit.createComposite(section); 57 container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); 58 GridData data = new GridData(GridData.FILL_HORIZONTAL); 59 container.setLayoutData(data); 60 61 data = new GridData(GridData.FILL_HORIZONTAL); 62 data.widthHint = 200; 63 section.setLayoutData(data); 64 65 66 fMirrorsURLEntry = new FormEntry(container, toolkit, PDEUIMessages.SiteEditor_MirrorsSection_urlLabel, 67 null, false); 68 fMirrorsURLEntry.setFormEntryListener(new FormEntryAdapter(this) { 69 public void textValueChanged(FormEntry text) { 70 setMirrorsURL(text.getValue()); 71 } 72 }); 73 fMirrorsURLEntry.setEditable(isEditable()); 74 75 toolkit.paintBordersFor(container); 76 section.setClient(container); 77 initialize(); 78 } 79 private void setMirrorsURL(String text) { 80 ISiteModel model = (ISiteModel) getPage().getModel(); 81 ISite site = model.getSite(); 82 try { 83 site.setMirrorsURL(text); 84 } catch (CoreException e) { 85 PDEPlugin.logException(e); 86 } 87 } 88 public void dispose() { 89 ISiteModel model = (ISiteModel) getPage().getModel(); 90 if (model!=null) 91 model.removeModelChangedListener(this); 92 super.dispose(); 93 } 94 public void initialize() { 95 ISiteModel model = (ISiteModel) getPage().getModel(); 96 refresh(); 97 model.addModelChangedListener(this); 98 } 99 public void modelChanged(IModelChangedEvent e) { 100 markStale(); 101 } 102 public void setFocus() { 103 if (fMirrorsURLEntry != null) 104 fMirrorsURLEntry.getText().setFocus(); 105 } 106 private void setIfDefined(FormEntry formText, String value) { 107 if (value != null) { 108 formText.setValue(value, true); 109 } 110 } 111 public void refresh() { 112 ISiteModel model = (ISiteModel) getPage().getModel(); 113 ISite site = model.getSite(); 114 setIfDefined(fMirrorsURLEntry, site.getMirrorsURL()); 115 super.refresh(); 116 } 117 public void cancelEdit() { 118 fMirrorsURLEntry.cancelEdit(); 119 super.cancelEdit(); 120 } 121 124 public boolean canPaste(Clipboard clipboard) { 125 TransferData[] types = clipboard.getAvailableTypes(); 126 Transfer[] transfers = new Transfer[]{TextTransfer.getInstance(), 127 RTFTransfer.getInstance()}; 128 for (int i = 0; i < types.length; i++) { 129 for (int j = 0; j < transfers.length; j++) { 130 if (transfers[j].isSupportedType(types[i])) 131 return true; 132 } 133 } 134 return false; 135 } 136 } 137 | Popular Tags |