1 11 12 package org.eclipse.pde.internal.ui.wizards.plugin; 13 14 import java.util.Locale ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.jdt.core.JavaConventions; 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.dialogs.IDialogSettings; 20 import org.eclipse.jface.dialogs.IMessageProvider; 21 import org.eclipse.jface.resource.JFaceResources; 22 import org.eclipse.pde.internal.core.util.PDEJavaHelper; 23 import org.eclipse.pde.internal.ui.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.eclipse.pde.internal.ui.wizards.IProjectProvider; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.events.ModifyEvent; 28 import org.eclipse.swt.events.ModifyListener; 29 import org.eclipse.swt.events.SelectionAdapter; 30 import org.eclipse.swt.events.SelectionEvent; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Text; 38 import org.eclipse.ui.PlatformUI; 39 40 public class PluginContentPage extends ContentPage { 41 protected final static int P_CLASS_GROUP = 2; 42 43 private Text fClassText; 44 private Button fGenerateClass; 45 private Button fUIPlugin; 46 private Label fClassLabel; 47 48 private Label fLabel; 49 private Button fYesButton; 50 private Button fNoButton; 51 52 private final static String S_GENERATE_ACTIVATOR = "generateActivator"; private final static String S_UI_PLUGIN = "uiPlugin"; private final static String S_RCP_PLUGIN = "rcpPlugin"; 56 private ModifyListener classListener = new ModifyListener() { 57 public void modifyText(ModifyEvent e) { 58 if (fInitialized) 59 fChangedGroups |= P_CLASS_GROUP; 60 validatePage(); 61 } 62 }; 63 64 private Group fRCPGroup; 65 66 public PluginContentPage(String pageName, IProjectProvider provider, 67 NewProjectCreationPage page,AbstractFieldData data) { 68 super(pageName, provider, page, data); 69 setTitle(PDEUIMessages.ContentPage_title); 70 setDescription(PDEUIMessages.ContentPage_desc); 71 } 72 73 76 public void createControl(Composite parent) { 77 Composite container = new Composite(parent, SWT.NONE); 78 container.setLayout(new GridLayout()); 79 80 createPluginPropertiesGroup(container); 81 createPluginClassGroup(container); 82 createRCPGroup(container); 83 84 Dialog.applyDialogFont(container); 85 setControl(container); 86 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.NEW_PROJECT_REQUIRED_DATA); 87 } 88 89 private void createPluginPropertiesGroup(Composite container) { 90 Group propertiesGroup = new Group(container, SWT.NONE); 91 propertiesGroup.setLayout(new GridLayout(2, false)); 92 propertiesGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 93 propertiesGroup.setText(PDEUIMessages.ContentPage_pGroup); 94 95 Label label = new Label(propertiesGroup, SWT.NONE); 96 label.setText(PDEUIMessages.ContentPage_pid); 97 fIdText = createText(propertiesGroup, propertiesListener); 98 99 label = new Label(propertiesGroup, SWT.NONE); 100 label.setText(PDEUIMessages.ContentPage_pversion); 101 fVersionText = createText(propertiesGroup, propertiesListener); 102 103 label = new Label(propertiesGroup, SWT.NONE); 104 label.setText(PDEUIMessages.ContentPage_pname); 105 fNameText = createText(propertiesGroup, propertiesListener); 106 107 label = new Label(propertiesGroup, SWT.NONE); 108 label.setText(PDEUIMessages.ContentPage_pprovider); 109 fProviderText = createText(propertiesGroup, propertiesListener); 110 111 fLibraryLabel = new Label(propertiesGroup, SWT.NONE); 112 fLibraryLabel.setText(PDEUIMessages.ProjectStructurePage_library); 113 fLibraryText = createText(propertiesGroup, propertiesListener); 114 } 115 116 private void createPluginClassGroup(Composite container) { 117 Group classGroup = new Group(container, SWT.NONE); 118 classGroup.setLayout(new GridLayout(2, false)); 119 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 120 gd.horizontalSpan = 2; 121 classGroup.setLayoutData(gd); 122 classGroup.setText(PDEUIMessages.ContentPage_pClassGroup); 123 124 IDialogSettings settings = getDialogSettings(); 125 126 fGenerateClass = new Button(classGroup, SWT.CHECK); 127 fGenerateClass.setText(PDEUIMessages.ContentPage_generate); 128 fGenerateClass.setSelection((settings != null) ? !settings.getBoolean(S_GENERATE_ACTIVATOR) : true); 129 gd = new GridData(); 130 gd.horizontalSpan = 2; 131 fGenerateClass.setLayoutData(gd); 132 fGenerateClass.addSelectionListener(new SelectionAdapter() { 133 public void widgetSelected(SelectionEvent e) { 134 fClassLabel.setEnabled(fGenerateClass.getSelection()); 135 fClassText.setEnabled(fGenerateClass.getSelection()); 136 updateData(); 137 validatePage(); 138 } 139 }); 140 141 fClassLabel = new Label(classGroup, SWT.NONE); 142 fClassLabel.setText(PDEUIMessages.ContentPage_classname); 143 gd = new GridData(); 144 gd.horizontalIndent = 20; 145 fClassLabel.setLayoutData(gd); 146 fClassText = createText(classGroup, classListener); 147 148 fUIPlugin = new Button(classGroup, SWT.CHECK); 149 fUIPlugin.setText(PDEUIMessages.ContentPage_uicontribution); 150 fUIPlugin.setSelection((settings != null) ? !settings.getBoolean(S_UI_PLUGIN) : true); 151 gd = new GridData(); 152 gd.horizontalSpan = 2; 153 fUIPlugin.setLayoutData(gd); 154 fUIPlugin.addSelectionListener(new SelectionAdapter() { 155 public void widgetSelected(SelectionEvent e) { 156 updateData(); 157 validatePage(); 158 } 159 }); 160 } 161 162 public void updateData() { 163 super.updateData(); 164 PluginFieldData data = (PluginFieldData)fData; 165 data.setClassname(fClassText.getText().trim()); 166 data.setUIPlugin(fUIPlugin.getSelection()); 167 data.setDoGenerateClass(fGenerateClass.isEnabled() && fGenerateClass.getSelection()); 168 data.setRCPApplicationPlugin(!fData.isSimple() && !isPureOSGi() && fYesButton.getSelection()); 169 } 170 171 private void createRCPGroup(Composite container){ 172 fRCPGroup = new Group(container, SWT.NONE); 173 fRCPGroup.setLayout(new GridLayout(2, false)); 174 fRCPGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 175 fRCPGroup.setText(PDEUIMessages.PluginContentPage_rcpGroup); 176 177 createRCPQuestion(fRCPGroup, 2); 178 } 179 180 private void createRCPQuestion(Composite parent, int horizontalSpan) { 181 Composite comp = new Composite(parent, SWT.NONE); 182 GridLayout layout = new GridLayout(3, false); 183 layout.marginHeight = layout.marginWidth = 0; 184 comp.setLayout(layout); 185 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 186 gd.horizontalSpan = horizontalSpan; 187 comp.setLayoutData(gd); 188 189 fLabel = new Label(comp, SWT.NONE); 190 fLabel.setText(PDEUIMessages.PluginContentPage_appQuestion); 191 fLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 192 193 IDialogSettings settings = getDialogSettings(); 194 boolean rcpApp = (settings != null) ? settings.getBoolean(S_RCP_PLUGIN) : false; 195 196 fYesButton = new Button(comp, SWT.RADIO); 197 fYesButton.setText(PDEUIMessages.PluginContentPage_yes); 198 fYesButton.setSelection(rcpApp); 199 gd = new GridData(); 200 gd.widthHint = getButtonWidthHint(fYesButton); 201 fYesButton.setLayoutData(gd); 202 fYesButton.addSelectionListener(new SelectionAdapter() { 203 public void widgetSelected(SelectionEvent e) { 204 updateData(); 205 getContainer().updateButtons(); 206 } 207 }); 208 209 fNoButton = new Button(comp, SWT.RADIO); 210 fNoButton.setText(PDEUIMessages.PluginContentPage_no); 211 fNoButton.setSelection(!rcpApp); 212 gd = new GridData(); 213 gd.widthHint = getButtonWidthHint(fNoButton); 214 fNoButton.setLayoutData(gd); 215 } 216 217 220 public void setVisible(boolean visible) { 221 if (visible) { 222 fMainPage.updateData(); 223 fGenerateClass.setEnabled(!fData.isSimple()); 224 fClassLabel.setEnabled(!fData.isSimple() && fGenerateClass.getSelection()); 225 fClassText.setEnabled(!fData.isSimple() && fGenerateClass.getSelection()); 226 boolean wasUIPluginEnabled = fUIPlugin.isEnabled(); 227 fUIPlugin.setEnabled(!fData.isSimple() && !isPureOSGi()); 228 if (!fUIPlugin.isEnabled()) 230 { fUIPlugin.setSelection(false); 231 } 232 else if(!wasUIPluginEnabled) 234 { fUIPlugin.setSelection(true); 235 } 236 237 if (((fChangedGroups & P_CLASS_GROUP) == 0)){ 239 int oldfChanged = fChangedGroups; 240 fClassText.setText(computeId().toLowerCase(Locale.ENGLISH) + ".Activator"); fChangedGroups = oldfChanged; 242 } 243 fRCPGroup.setVisible(!fData.isSimple() && !isPureOSGi()); 244 } 245 super.setVisible(visible); 246 } 247 248 private boolean isPureOSGi() { 249 return ((PluginFieldData)fData).getOSGiFramework() != null; 250 } 251 252 255 protected void validatePage() { 256 String errorMessage = validateProperties(); 257 if (errorMessage == null && fGenerateClass.isEnabled() && fGenerateClass.getSelection()) { 258 IStatus status = JavaConventions.validateJavaTypeName( 259 fClassText.getText().trim(), 260 PDEJavaHelper.getJavaSourceLevel(null), 261 PDEJavaHelper.getJavaComplianceLevel(null)); 262 if (status.getSeverity() == IStatus.ERROR) { 263 errorMessage = status.getMessage(); 264 } else if (status.getSeverity() == IStatus.WARNING) { 265 setMessage(status.getMessage(), IMessageProvider.WARNING); 266 } 267 } 268 setErrorMessage(errorMessage); 269 setPageComplete(errorMessage == null); 270 } 271 272 275 protected String getNameFieldQualifier() { 276 return PDEUIMessages.ContentPage_plugin; 277 } 278 279 private static int getButtonWidthHint(Button button) { 280 if (button.getFont().equals(JFaceResources.getDefaultFont())) 281 button.setFont(JFaceResources.getDialogFont()); 282 return Math.max(50, 283 button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 284 } 285 286 protected void saveSettings(IDialogSettings settings) { 287 settings.put(S_GENERATE_ACTIVATOR, !fGenerateClass.getSelection()); 288 if (fUIPlugin.isEnabled()) 289 settings.put(S_UI_PLUGIN, !fUIPlugin.getSelection()); 290 settings.put(S_RCP_PLUGIN, fYesButton.getSelection()); 291 } 292 } 293 | Popular Tags |