1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.pde.core.IModelChangedEvent; 17 import org.eclipse.pde.internal.core.ifeature.IFeatureChild; 18 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 19 import org.eclipse.pde.internal.ui.PDEPlugin; 20 import org.eclipse.pde.internal.ui.PDEUIMessages; 21 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 22 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 23 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 24 import org.eclipse.pde.internal.ui.editor.PDESection; 25 import org.eclipse.pde.internal.ui.parts.FormEntry; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Button; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.ui.forms.IFormPart; 34 import org.eclipse.ui.forms.IManagedForm; 35 import org.eclipse.ui.forms.IPartSelectionListener; 36 import org.eclipse.ui.forms.widgets.FormToolkit; 37 import org.eclipse.ui.forms.widgets.Section; 38 import org.eclipse.ui.forms.widgets.TableWrapData; 39 40 public class IncludedFeaturesDetailsSection extends PDESection implements 41 IFormPart, IPartSelectionListener { 42 protected IFeatureChild fInput; 43 44 private FormEntry fNameText; 45 46 private FormEntry fVersionText; 47 48 private Button fOptionalButton; 49 50 private Button fSearchRootButton; 51 52 private Button fSearchSelfButton; 53 54 private Button fSearchBothButton; 55 56 private boolean fBlockNotification; 57 58 public IncludedFeaturesDetailsSection(PDEFormPage page, Composite parent) { 59 this(page, parent, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_title, 60 PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_desc, SWT.NULL); 61 } 62 63 public IncludedFeaturesDetailsSection(PDEFormPage page, Composite parent, 64 String title, String desc, int toggleStyle) { 65 super(page, parent, Section.DESCRIPTION | toggleStyle); 66 getSection().setText(title); 67 getSection().setDescription(desc); 68 createClient(getSection(), page.getManagedForm().getToolkit()); 69 } 70 71 public void cancelEdit() { 72 fNameText.cancelEdit(); 73 fVersionText.cancelEdit(); 74 super.cancelEdit(); 75 } 76 77 public void commit(boolean onSave) { 78 fNameText.commit(); 79 fVersionText.commit(); 80 super.commit(onSave); 81 } 82 83 public void createClient(Section section, FormToolkit toolkit) { 84 85 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 86 GridData data = new GridData(GridData.FILL_HORIZONTAL 87 | GridData.VERTICAL_ALIGN_BEGINNING); 88 section.setLayoutData(data); 89 90 Composite container = toolkit.createComposite(section); 91 container.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 2)); 92 93 fNameText = new FormEntry(container, toolkit, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_featureLabel, null, false); 94 fNameText.setFormEntryListener(new FormEntryAdapter(this) { 95 public void textValueChanged(FormEntry text) { 96 if (fInput != null) 97 try { 98 fInput.setName(text.getValue()); 99 } catch (CoreException e) { 100 PDEPlugin.logException(e); 101 } 102 } 103 }); 104 fNameText.setEditable(isEditable()); 105 106 fVersionText = new FormEntry(container, toolkit, PDEUIMessages.FeatureEditor_SpecSection_version, null, false); 107 fVersionText.setFormEntryListener(new FormEntryAdapter(this) { 108 public void textValueChanged(FormEntry text) { 109 if (fInput != null) 110 try { 111 fInput.setVersion(text.getValue()); 112 } catch (CoreException e) { 113 PDEPlugin.logException(e); 114 } 115 } 116 }); 117 fVersionText.setEditable(isEditable()); 118 119 fOptionalButton = toolkit.createButton(container, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_optional, SWT.CHECK); 120 121 TableWrapData gd = new TableWrapData(TableWrapData.FILL); 122 gd.colspan = 2; 123 fOptionalButton.setLayoutData(gd); 124 fOptionalButton.addSelectionListener(new SelectionAdapter() { 125 public void widgetSelected(SelectionEvent e) { 126 if (!fBlockNotification) { 127 try { 128 fInput.setOptional(fOptionalButton.getSelection()); 129 } catch (CoreException ce) { 130 } 131 } 132 } 133 }); 134 Label fSearchLocationDescLabel = toolkit.createLabel(container, 135 PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_searchLocation, SWT.WRAP); 136 gd = new TableWrapData(TableWrapData.FILL); 137 gd.colspan = 2; 138 fSearchLocationDescLabel.setLayoutData(gd); 139 140 fSearchRootButton = toolkit.createButton(container, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_root, SWT.RADIO); 141 fSearchRootButton.setSelection(true); 142 gd = new TableWrapData(TableWrapData.FILL); 143 gd.colspan = 2; 144 gd.indent = 5; 145 fSearchRootButton.setLayoutData(gd); 146 fSearchRootButton.addSelectionListener(new SelectionAdapter() { 147 public void widgetSelected(SelectionEvent e) { 148 if (!fBlockNotification) { 149 try { 150 if (fSearchRootButton.getSelection()) 151 fInput.setSearchLocation(IFeatureChild.ROOT); 152 } catch (CoreException ce) { 153 } 154 } 155 } 156 }); 157 158 fSearchSelfButton = toolkit.createButton(container, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_self, SWT.RADIO); 159 fSearchSelfButton.setSelection(true); 160 gd = new TableWrapData(TableWrapData.FILL); 161 gd.colspan = 2; 162 gd.indent = 5; 163 fSearchSelfButton.setLayoutData(gd); 164 fSearchSelfButton.addSelectionListener(new SelectionAdapter() { 165 public void widgetSelected(SelectionEvent e) { 166 if (!fBlockNotification) { 167 try { 168 if (fSearchSelfButton.getSelection()) 169 fInput.setSearchLocation(IFeatureChild.SELF); 170 } catch (CoreException ce) { 171 } 172 } 173 } 174 }); 175 176 fSearchBothButton = toolkit.createButton(container, PDEUIMessages.SiteEditor_IncludedFeaturesDetailsSection_both, SWT.RADIO); 177 fSearchBothButton.setSelection(true); 178 gd = new TableWrapData(TableWrapData.FILL); 179 gd.colspan = 2; 180 gd.indent = 5; 181 fSearchBothButton.setLayoutData(gd); 182 fSearchBothButton.addSelectionListener(new SelectionAdapter() { 183 public void widgetSelected(SelectionEvent e) { 184 if (!fBlockNotification) { 185 try { 186 if (fSearchBothButton.getSelection()) 187 fInput.setSearchLocation(IFeatureChild.BOTH); 188 } catch (CoreException ce) { 189 } 190 } 191 } 192 }); 193 194 toolkit.paintBordersFor(container); 195 section.setClient(container); 196 } 197 198 public void dispose() { 199 IFeatureModel model = (IFeatureModel) getPage().getModel(); 200 if (model != null) 201 model.removeModelChangedListener(this); 202 super.dispose(); 203 } 204 205 210 public void initialize(IManagedForm form) { 211 IFeatureModel model = (IFeatureModel) getPage().getModel(); 212 if (model != null) 213 model.addModelChangedListener(this); 214 super.initialize(form); 215 } 216 217 public void modelChanged(IModelChangedEvent e) { 218 markStale(); 219 } 220 221 public void refresh() { 222 update(); 223 super.refresh(); 224 } 225 226 public void selectionChanged(IFormPart part, ISelection selection) { 227 if (selection instanceof IStructuredSelection && !selection.isEmpty()) { 228 Object o = ((IStructuredSelection) selection).getFirstElement(); 229 if (o instanceof IFeatureChild) { 230 fInput = (IFeatureChild) o; 231 } else { 232 fInput = null; 233 } 234 } else 235 fInput = null; 236 update(); 237 } 238 239 public void setFocus() { 240 if (fNameText != null) 241 fNameText.getText().setFocus(); 242 } 243 244 private void update() { 245 fBlockNotification = true; 246 247 if (fInput != null) { 248 fNameText.setValue(fInput.getName(), true); 249 fVersionText.setValue(fInput.getVersion(), true); 250 fOptionalButton.setSelection(fInput.isOptional()); 251 int searchLocation = fInput.getSearchLocation(); 252 fSearchRootButton 253 .setSelection(searchLocation == IFeatureChild.ROOT); 254 fSearchSelfButton 255 .setSelection(searchLocation == IFeatureChild.SELF); 256 fSearchBothButton 257 .setSelection(searchLocation == IFeatureChild.BOTH); 258 } else { 259 fNameText.setValue(null, true); 260 fVersionText.setValue(null, true); 261 fOptionalButton.setSelection(false); 262 fSearchRootButton.setSelection(true); 263 fSearchSelfButton.setSelection(false); 264 fSearchBothButton.setSelection(false); 265 } 266 boolean editable = fInput != null && isEditable(); 267 fNameText.setEditable(editable); 268 fVersionText.setEditable(editable); 269 fOptionalButton.setEnabled(editable); 270 fSearchRootButton.setEnabled(editable); 271 fSearchSelfButton.setEnabled(editable); 272 fSearchBothButton.setEnabled(editable); 273 274 fBlockNotification = false; 275 } 276 277 public boolean isEditable() { 278 return getPage().getPDEEditor().getAggregateModel().isEditable(); 279 } 280 } 281 | Popular Tags |