1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.jface.dialogs.MessageDialog; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.pde.core.IIdentifiable; 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginObject; 24 import org.eclipse.pde.internal.core.ICoreConstants; 25 import org.eclipse.pde.internal.core.PDEStateHelper; 26 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 27 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 28 import org.eclipse.pde.internal.core.schema.Schema; 29 import org.eclipse.pde.internal.ui.PDEPlugin; 30 import org.eclipse.pde.internal.ui.PDEPluginImages; 31 import org.eclipse.pde.internal.ui.PDEUIMessages; 32 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 33 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 34 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 35 import org.eclipse.pde.internal.ui.editor.PDESection; 36 import org.eclipse.pde.internal.ui.editor.actions.OpenSchemaAction; 37 import org.eclipse.pde.internal.ui.parts.FormEntry; 38 import org.eclipse.pde.internal.ui.search.FindDeclarationsAction; 39 import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; 40 import org.eclipse.swt.SWT; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Control; 44 import org.eclipse.swt.widgets.Label; 45 import org.eclipse.ui.forms.IFormPart; 46 import org.eclipse.ui.forms.events.HyperlinkAdapter; 47 import org.eclipse.ui.forms.events.HyperlinkEvent; 48 import org.eclipse.ui.forms.widgets.ExpandableComposite; 49 import org.eclipse.ui.forms.widgets.FormText; 50 import org.eclipse.ui.forms.widgets.FormToolkit; 51 import org.eclipse.ui.forms.widgets.Section; 52 53 public class ExtensionDetails extends AbstractPluginElementDetails { 54 private IPluginExtension input; 55 private FormEntry id; 56 private FormEntry name; 57 private FormText rtext; 58 59 private static final String RTEXT_DATA = 60 PDEUIMessages.ExtensionDetails_extensionPointLinks; 61 62 65 public ExtensionDetails(PDESection masterSection) { 66 super(masterSection); 67 } 68 69 72 public void createContents(Composite parent) { 73 FormToolkit toolkit = getManagedForm().getToolkit(); 74 parent.setLayout(FormLayoutFactory.createDetailsGridLayout(false, 1)); 75 76 Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR | Section.DESCRIPTION); 77 section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; 78 section.setText(PDEUIMessages.ExtensionDetails_title); 79 section.setDescription(PDEUIMessages.ExtensionDetails_desc); 80 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 81 section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); 82 83 getPage().alignSectionHeaders(getMasterSection().getSection(), 86 section); 87 88 Composite client = toolkit.createComposite(section); 89 client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); 90 client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 91 92 createIDEntryField(toolkit, client); 93 94 createNameEntryField(toolkit, client); 95 96 createSpacer(toolkit, client, 2); 97 98 Composite container = toolkit.createComposite(parent, SWT.NONE); 99 container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1)); 100 container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); 101 102 rtext = toolkit.createFormText(container, true); 103 rtext.setImage("desc", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_DOC_SECTION_OBJ)); rtext.setImage("open", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_SCHEMA_OBJ)); rtext.setImage("search", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PSEARCH_OBJ)); rtext.addHyperlinkListener(new HyperlinkAdapter() { 107 public void linkActivated(HyperlinkEvent e) { 108 if (e.getHref().equals("search")){ FindDeclarationsAction findDeclarationsAction = new FindDeclarationsAction(input); 110 findDeclarationsAction.run(); 111 } else if (e.getHref().equals("open")) { OpenSchemaAction action = new OpenSchemaAction(); 113 action.setInput(input); 114 action.setEnabled(true); 115 action.run(); 116 } else { 117 if (input == null || input.getPoint() == null) 118 return; 119 IPluginExtensionPoint point = PDEStateHelper.findExtensionPoint(input.getPoint()); 120 if (point != null){ 121 ShowDescriptionAction showDescAction = new ShowDescriptionAction(point); 122 showDescAction.run(); 123 } else { 124 showNoExtensionPointMessage(); 125 } 126 } 127 } 128 }); 129 rtext.setText(RTEXT_DATA, true, false); 130 id.setEditable(isEditable()); 131 name.setEditable(isEditable()); 132 133 toolkit.paintBordersFor(client); 134 section.setClient(client); 135 IPluginModelBase model = (IPluginModelBase)getPage().getModel(); 136 model.addModelChangedListener(this); 137 markDetailsPart(section); 138 } 139 140 144 private void createNameEntryField(FormToolkit toolkit, Composite client) { 145 name = new FormEntry(client, toolkit, PDEUIMessages.ExtensionDetails_name, null, false); 146 name.setFormEntryListener(new FormEntryAdapter(this) { 147 public void textValueChanged(FormEntry entry) { 148 if (input!=null) 149 try { 150 input.setName(name.getValue()); 151 } catch (CoreException e) { 152 PDEPlugin.logException(e); 153 } 154 } 155 }); 156 } 157 158 162 private void createIDEntryField(FormToolkit toolkit, Composite client) { 163 id = new FormEntry(client, toolkit, PDEUIMessages.ExtensionDetails_id, null, false); 164 id.setFormEntryListener(new FormEntryAdapter(this) { 165 public void textValueChanged(FormEntry entry) { 166 if (input!=null) 167 try { 168 input.setId(id.getValue()); 169 } catch (CoreException e) { 170 PDEPlugin.logException(e); 171 } 172 } 173 }); 174 } 175 176 179 public void selectionChanged(IFormPart part, ISelection selection) { 180 IStructuredSelection ssel = (IStructuredSelection)selection; 181 if (ssel.size()==1) { 182 input = (IPluginExtension)ssel.getFirstElement(); 183 } 184 else 185 input = null; 186 update(); 187 } 188 189 private void update() { 190 id.setValue(input!=null?input.getId():null, true); 191 name.setValue(input!=null?input.getName():null, true); 192 193 updateLabel(isFieldRequired(IIdentifiable.P_ID), id, 195 PDEUIMessages.ExtensionDetails_id); 196 updateLabel(isFieldRequired(IPluginObject.P_NAME), name, 198 PDEUIMessages.ExtensionDetails_name); 199 } 200 201 206 private boolean isFieldRequired(String attributeName) { 207 if (input == null) { 209 return false; 210 } 211 Object object = input.getSchema(); 213 if ((object == null) || 215 (object instanceof Schema) == false) { 216 return false; 217 } 218 Schema schema = (Schema)object; 219 ISchemaElement element = 221 schema.findElement(ICoreConstants.EXTENSION_NAME); 222 if (element == null) { 224 return false; 225 } 226 ISchemaAttribute attribute = element.getAttribute(attributeName); 228 if (attribute == null) { 230 return false; 231 } 232 if (attribute.getUse() == ISchemaAttribute.REQUIRED) { 234 return true; 235 } 236 return false; 237 } 238 239 243 private void updateLabel(boolean required, FormEntry field, String label) { 244 Control control = field.getLabel(); 246 if ((control == null) || 248 ((control instanceof Label) == false)) { 249 return; 250 } 251 Label labelControl = ((Label)control); 252 if (required) { 254 labelControl.setText(label + '*' + ':'); 255 } else { 256 labelControl.setText(label + ':'); 257 } 258 labelControl.getParent().layout(); 261 } 262 263 public void cancelEdit() { 264 id.cancelEdit(); 265 name.cancelEdit(); 266 super.cancelEdit(); 267 } 268 271 public void commit(boolean onSave) { 272 id.commit(); 273 name.commit(); 274 super.commit(onSave); 275 } 276 279 public void setFocus() { 280 id.getText().setFocus(); 281 } 282 283 public void dispose() { 284 IPluginModelBase model = (IPluginModelBase)getPage().getModel(); 285 if (model!=null) 286 model.removeModelChangedListener(this); 287 super.dispose(); 288 } 289 290 public void modelChanged(IModelChangedEvent e) { 291 if (e.getChangeType()==IModelChangedEvent.CHANGE) { 292 Object obj = e.getChangedObjects()[0]; 293 if (obj.equals(input)) 294 refresh(); 295 } 296 } 297 300 public void refresh() { 301 update(); 302 super.refresh(); 303 } 304 307 public void fireSaveNeeded() { 308 markDirty(); 309 PDEFormPage page = (PDEFormPage)getManagedForm().getContainer(); 310 page.getPDEEditor().fireSaveNeeded(getContextId(), false); 311 } 312 315 public String getContextId() { 316 return PluginInputContext.CONTEXT_ID; 317 } 318 public PDEFormPage getPage() { 319 return (PDEFormPage)getManagedForm().getContainer(); 320 } 321 public boolean isEditable() { 322 return getPage().getPDEEditor().getAggregateModel().isEditable(); 323 } 324 private void showNoExtensionPointMessage() { 325 String title = PDEUIMessages.ExtensionDetails_noPoint_title; 326 String message = NLS.bind(PDEUIMessages.ShowDescriptionAction_noPoint_desc, input.getPoint()); 327 328 MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), title, message); 329 } 330 } 331 | Popular Tags |