1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details; 13 14 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSHelpObject; 15 import org.eclipse.pde.internal.core.util.PDETextHelper; 16 import org.eclipse.pde.internal.ui.PDEUIMessages; 17 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 18 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractSubDetails; 19 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; 20 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext; 21 import org.eclipse.pde.internal.ui.parts.ComboPart; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.events.ModifyEvent; 24 import org.eclipse.swt.events.ModifyListener; 25 import org.eclipse.swt.events.SelectionAdapter; 26 import org.eclipse.swt.events.SelectionEvent; 27 import org.eclipse.swt.graphics.Color; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.swt.widgets.Text; 32 import org.eclipse.ui.forms.IFormColors; 33 import org.eclipse.ui.forms.widgets.ExpandableComposite; 34 import org.eclipse.ui.forms.widgets.FormToolkit; 35 import org.eclipse.ui.forms.widgets.Section; 36 37 41 public class SimpleCSHelpDetails extends CSAbstractSubDetails { 42 43 private Text fHelpText; 44 45 private ComboPart fHelpCombo; 46 47 private Label fHelpLabel; 48 49 private ISimpleCSHelpObject fHelpObject; 50 51 private Section fHelpSection; 52 53 private boolean fBlockListeners; 54 55 private static final String F_NO_HELP = PDEUIMessages.SimpleCSCommandDetails_6; 56 57 private static final String F_HELP_CONTEXT_ID = PDEUIMessages.SimpleCSHelpDetails_HelpContextID; 58 59 private static final String F_HELP_DOCUMENT_LINK = PDEUIMessages.SimpleCSHelpDetails_HelpDocumentLink; 60 61 64 public SimpleCSHelpDetails(ICSMaster section) { 65 super(section, SimpleCSInputContext.CONTEXT_ID); 66 fHelpObject = null; 67 fBlockListeners = false; 68 69 fHelpText = null; 70 fHelpCombo = null; 71 fHelpLabel = null; 72 73 fHelpSection = null; 74 } 75 76 79 public void setData(ISimpleCSHelpObject object) { 80 fHelpObject = object; 82 } 83 84 87 public void createDetails(Composite parent) { 88 89 int columnSpan = 2; 90 FormToolkit toolkit = getToolkit(); 91 92 GridData data = null; 93 Label label = null; 94 Color foreground = toolkit.getColors().getColor(IFormColors.TITLE); 95 96 fHelpSection = toolkit.createSection(parent, Section.DESCRIPTION 98 | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); 99 fHelpSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; 100 fHelpSection.setText(PDEUIMessages.SimpleCSSharedUIFactory_1); 101 fHelpSection.setDescription(PDEUIMessages.SimpleCSSharedUIFactory_2); 102 fHelpSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 103 data = new GridData(GridData.FILL_HORIZONTAL); 104 fHelpSection.setLayoutData(data); 105 106 Composite helpSectionClient = toolkit.createComposite(fHelpSection); 108 helpSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, columnSpan)); 109 110 label = toolkit.createLabel(helpSectionClient, 113 PDEUIMessages.SimpleCSHelpDetails_Type, SWT.WRAP); 114 label.setForeground(foreground); 115 116 fHelpCombo = new ComboPart(); 119 fHelpCombo.createControl(helpSectionClient, toolkit, SWT.READ_ONLY); 120 fHelpCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 121 fHelpCombo.add(F_NO_HELP); 122 fHelpCombo.add(F_HELP_CONTEXT_ID); 123 fHelpCombo.add(F_HELP_DOCUMENT_LINK); 124 fHelpCombo.setText(F_NO_HELP); 125 126 fHelpLabel = toolkit.createLabel(helpSectionClient, 129 PDEUIMessages.SimpleCSHelpDetails_Value, SWT.WRAP); 130 fHelpLabel.setForeground(foreground); 131 132 fHelpText = toolkit.createText(helpSectionClient, null); 135 data = new GridData(GridData.FILL_HORIZONTAL); 136 fHelpText.setLayoutData(data); 137 138 toolkit.paintBordersFor(helpSectionClient); 140 fHelpSection.setClient(helpSectionClient); 141 markDetailsPart(fHelpSection); 143 } 144 145 148 public void hookListeners() { 149 150 fHelpCombo.addSelectionListener(new SelectionAdapter() { 153 public void widgetSelected(SelectionEvent e) { 154 if (fHelpObject == null) { 156 return; 157 } 158 String selection = fHelpCombo.getSelection(); 159 if (selection.equals(F_NO_HELP) == false) { 160 if (selection.equals(F_HELP_CONTEXT_ID)) { 162 fHelpObject.setHref(null); 165 } else { 166 fHelpObject.setContextId(null); 169 } 170 fHelpLabel.setVisible(true); 172 fHelpText.setVisible(true); 173 fHelpText.setFocus(); 175 fHelpText.setText(""); } else { 179 fHelpLabel.setVisible(false); 182 fHelpText.setVisible(false); 183 fHelpObject.setContextId(null); 185 fHelpObject.setHref(null); 186 } 187 } 188 }); 189 fHelpText.addModifyListener(new ModifyListener() { 192 public void modifyText(ModifyEvent e) { 193 if (fBlockListeners) { 195 return; 196 } 197 if (fHelpObject == null) { 199 return; 200 } 201 String selection = fHelpCombo.getSelection(); 202 if (selection.equals(F_HELP_CONTEXT_ID)) { 203 fHelpObject.setContextId(fHelpText.getText()); 206 } else { 207 fHelpObject.setHref(fHelpText.getText()); 210 } 211 } 212 }); 213 214 } 215 216 219 public void updateFields() { 220 if (fHelpObject == null) { 222 return; 223 } 224 225 boolean editable = isEditableElement(); 226 boolean expanded = false; 227 228 fBlockListeners = true; 230 if (PDETextHelper.isDefined(fHelpObject.getContextId())) { 233 fHelpText.setText(fHelpObject.getContextId()); 234 fHelpCombo.setText(F_HELP_CONTEXT_ID); 235 expanded = true; 236 } else if (PDETextHelper.isDefined(fHelpObject.getHref())) { 237 fHelpText.setText(fHelpObject.getHref()); 238 fHelpCombo.setText(F_HELP_DOCUMENT_LINK); 239 expanded = true; 240 } else { 241 fHelpCombo.setText(F_NO_HELP); 242 } 243 fBlockListeners = false; 245 246 fHelpSection.setExpanded(expanded); 247 fHelpText.setEnabled(editable); 248 fHelpText.setVisible(expanded); 249 fHelpLabel.setVisible(expanded); 250 fHelpCombo.setEnabled(editable); 251 } 252 253 254 257 public void commit(boolean onSave) { 258 super.commit(onSave); 259 } 262 263 } 264 | Popular Tags |