1 11 package org.eclipse.pde.internal.ui.wizards.plugin; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.runtime.IExecutableExtension; 16 import org.eclipse.jface.viewers.ISelectionChangedListener; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.jface.viewers.StructuredSelection; 19 import org.eclipse.jface.viewers.Viewer; 20 import org.eclipse.jface.viewers.ViewerFilter; 21 import org.eclipse.jface.wizard.IWizardNode; 22 import org.eclipse.pde.internal.ui.IHelpContextIds; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.pde.internal.ui.elements.ElementList; 25 import org.eclipse.pde.internal.ui.wizards.WizardElement; 26 import org.eclipse.pde.internal.ui.wizards.WizardListSelectionPage; 27 import org.eclipse.pde.internal.ui.wizards.WizardNode; 28 import org.eclipse.pde.ui.IBasePluginWizard; 29 import org.eclipse.pde.ui.IPluginContentWizard; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.layout.GridData; 34 import org.eclipse.swt.widgets.Button; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.ui.PlatformUI; 37 38 39 public class TemplateListSelectionPage extends WizardListSelectionPage 40 implements ISelectionChangedListener, IExecutableExtension { 41 private ContentPage fContentPage; 42 private Button fUseTemplate; 43 private String fInitialTemplateId; 44 45 class WizardFilter extends ViewerFilter { 46 public boolean select(Viewer viewer, Object parentElement, 47 Object element) { 48 PluginFieldData data = (PluginFieldData) fContentPage.getData(); 49 boolean simple = data.isSimple(); 50 boolean generate = data.doGenerateClass(); 51 boolean ui = data.isUIPlugin(); 52 boolean rcp = data.isRCPApplicationPlugin(); 53 boolean osgi = data.getOSGiFramework() != null; 54 WizardElement welement = (WizardElement)element; 55 IConfigurationElement config = welement.getConfigurationElement(); 56 boolean uiFlag = getFlag(config, "ui-content", true); boolean javaFlag = getFlag(config, "java", true); boolean rcpFlag = getFlag(config, "rcp", false); boolean osgiFlag = getFlag(config, "pureOSGi", false); boolean activatorFlag = getFlag(config, "requiresActivator", false); 62 if (osgi && simple) return false; 64 if (simple) return !javaFlag; 66 if (uiFlag && generate && !ui) return false; 68 if (activatorFlag && !generate) return false; 70 if (!osgi && (rcp != rcpFlag)) return false; 72 return (osgi == osgiFlag && ((!osgiFlag && !rcpFlag) || ui == uiFlag)); 74 } 75 private boolean getFlag(IConfigurationElement config, String name, boolean defaultValue) { 76 String value = config.getAttribute(name); 77 if (value==null) return defaultValue; 78 return value.equalsIgnoreCase("true"); } 80 } 81 82 public TemplateListSelectionPage(ElementList wizardElements, ContentPage page, String message) { 83 super(wizardElements, message); 84 fContentPage = page; 85 setTitle(PDEUIMessages.WizardListSelectionPage_title); 86 setDescription(PDEUIMessages.WizardListSelectionPage_desc); 87 } 88 89 92 public void createControl(Composite parent) { 93 super.createControl(parent); 94 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.NEW_PROJECT_CODE_GEN_PAGE); 95 } 96 97 public void createAbove(Composite container, int span) { 98 fUseTemplate = new Button(container, SWT.CHECK); 99 fUseTemplate.setText(PDEUIMessages.WizardListSelectionPage_label); 100 GridData gd = new GridData(); 101 gd.horizontalSpan = span; 102 fUseTemplate.setLayoutData(gd); 103 fUseTemplate.addSelectionListener(new SelectionAdapter() { 104 public void widgetSelected(SelectionEvent e) { 105 wizardSelectionViewer.getControl().setEnabled(fUseTemplate.getSelection()); 106 if (!fUseTemplate.getSelection()) 107 setDescription(""); setDescriptionEnabled(fUseTemplate.getSelection()); 109 getContainer().updateButtons(); 110 } 111 }); 112 fUseTemplate.setSelection(true); 113 } 114 115 protected void initializeViewer() { 116 wizardSelectionViewer.addFilter(new WizardFilter()); 117 if (getInitialTemplateId() != null) 118 selectInitialTemplate(); 119 } 120 121 private void selectInitialTemplate() { 122 Object [] children = wizardElements.getChildren(); 123 for (int i=0; i<children.length; i++) { 124 WizardElement welement = (WizardElement)children[i]; 125 if (welement.getID().equals(getInitialTemplateId())) { 126 wizardSelectionViewer.setSelection(new StructuredSelection(welement), true); 127 setSelectedNode(createWizardNode(welement)); 128 setDescriptionText(welement.getDescription()); 129 break; 130 } 131 } 132 } 133 134 protected IWizardNode createWizardNode(WizardElement element) { 135 return new WizardNode(this, element) { 136 public IBasePluginWizard createWizard() throws CoreException { 137 IPluginContentWizard wizard = 138 (IPluginContentWizard) wizardElement.createExecutableExtension(); 139 wizard.init(fContentPage.getData()); 140 return wizard; 141 } 142 }; 143 } 144 145 public IPluginContentWizard getSelectedWizard() { 146 if (fUseTemplate.getSelection()) 147 return super.getSelectedWizard(); 148 return null; 149 } 150 151 public boolean isPageComplete() { 152 PluginFieldData data = (PluginFieldData)fContentPage.getData(); 153 boolean rcp = data.isRCPApplicationPlugin(); 154 155 return !rcp || (fUseTemplate.getSelection() && rcp && getSelectedNode() != null); 156 } 157 158 159 162 public boolean canFlipToNextPage() { 163 IStructuredSelection ssel = (IStructuredSelection)wizardSelectionViewer.getSelection(); 164 return fUseTemplate.getSelection() && ssel != null && !ssel.isEmpty(); 165 } 166 169 public String getInitialTemplateId() { 170 return fInitialTemplateId; 171 } 172 175 public void setInitialTemplateId(String initialTemplateId) { 176 fInitialTemplateId = initialTemplateId; 177 } 178 public void setVisible(boolean visible) { 179 if (visible) { 180 fContentPage.updateData(); 181 wizardSelectionViewer.refresh(); 182 } 183 super.setVisible(visible); 184 } 185 } 186 | Popular Tags |