1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.IStatus; 16 17 import org.eclipse.core.resources.IProject; 18 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 22 import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData; 23 24 import org.eclipse.ui.PlatformUI; 25 26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 27 import org.eclipse.jdt.internal.ui.JavaPlugin; 28 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 29 30 33 public class CodeTemplatePreferencePage extends PropertyAndPreferencePage { 34 35 public static final String PREF_ID= "org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage"; public static final String PROP_ID= "org.eclipse.jdt.ui.propertyPages.CodeTemplatePreferencePage"; 38 public static final String DATA_SELECT_TEMPLATE= "CodeTemplatePreferencePage.select_template"; 40 private CodeTemplateBlock fCodeTemplateConfigurationBlock; 41 42 public CodeTemplatePreferencePage() { 43 setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); 44 46 setTitle(PreferencesMessages.CodeTemplatesPreferencePage_title); 48 } 49 50 53 public void createControl(Composite parent) { 54 fCodeTemplateConfigurationBlock= new CodeTemplateBlock(getProject()); 55 56 super.createControl(parent); 57 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CODE_TEMPLATES_PREFERENCE_PAGE); 58 } 59 60 63 protected Control createPreferenceContent(Composite composite) { 64 return fCodeTemplateConfigurationBlock.createContents(composite); 65 } 66 67 70 public boolean performOk() { 71 if (fCodeTemplateConfigurationBlock != null) { 72 return fCodeTemplateConfigurationBlock.performOk(useProjectSettings()); 73 } 74 return true; 75 } 76 77 80 protected void performDefaults() { 81 super.performDefaults(); 82 if (fCodeTemplateConfigurationBlock != null) { 83 fCodeTemplateConfigurationBlock.performDefaults(); 84 } 85 } 86 87 90 public void statusChanged(IStatus status) { 91 setValid(!status.matches(IStatus.ERROR)); 92 StatusUtil.applyToStatusLine(this, status); 93 } 94 95 98 public boolean performCancel() { 99 if (fCodeTemplateConfigurationBlock != null) { 100 fCodeTemplateConfigurationBlock.performCancel(); 101 } 102 return super.performCancel(); 103 } 104 105 108 protected boolean hasProjectSpecificOptions(IProject project) { 109 return fCodeTemplateConfigurationBlock.hasProjectSpecificOptions(project); 110 } 111 112 115 protected String getPreferencePageID() { 116 return PREF_ID; 117 } 118 119 122 protected String getPropertyPageID() { 123 return PROP_ID; 124 } 125 126 129 public void applyData(Object data) { 130 if (data instanceof Map ) { 131 Object id= ((Map ) data).get(DATA_SELECT_TEMPLATE); 132 if (id instanceof String ) { 133 final TemplatePersistenceData[] templates= fCodeTemplateConfigurationBlock.fTemplateStore.getTemplateData(); 134 TemplatePersistenceData template= null; 135 for (int index= 0; index < templates.length; index++) { 136 template= templates[index]; 137 if (template.getId().equals(id)) { 138 fCodeTemplateConfigurationBlock.postSetSelection(template); 139 break; 140 } 141 } 142 } 143 } 144 super.applyData(data); 145 } 146 } 147 | Popular Tags |