1 11 package org.eclipse.pde.ui.launcher; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.debug.core.ILaunchConfiguration; 16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 17 import org.eclipse.jface.dialogs.Dialog; 18 import org.eclipse.pde.internal.ui.IHelpContextIds; 19 import org.eclipse.pde.internal.ui.PDEPlugin; 20 import org.eclipse.pde.internal.ui.PDEPluginImages; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.launcher.PluginBlock; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.SelectionAdapter; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.graphics.Image; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Combo; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Label; 32 import org.eclipse.ui.PlatformUI; 33 34 42 public class PluginsTab extends AbstractLauncherTab { 43 44 private Image fImage; 45 46 private boolean fShowFeatures = true; 47 private Combo fSelectionCombo; 48 private PluginBlock fPluginBlock; 49 50 private static final int DEFAULT_SELECTION = 0; 51 private static final int CUSTOM_SELECTION = 1; 52 private static final int FEATURE_SELECTION = 2; 53 54 class Listener extends SelectionAdapter { 55 public void widgetSelected(SelectionEvent e) { 56 int index = fSelectionCombo.getSelectionIndex(); 57 fPluginBlock.enableViewer(index == CUSTOM_SELECTION); 58 updateLaunchConfigurationDialog(); 59 } 60 } 61 62 68 public PluginsTab() { 69 this(true); 70 } 71 72 78 public PluginsTab(boolean showFeatures) { 79 fShowFeatures = showFeatures; 80 fImage = PDEPluginImages.DESC_PLUGINS_FRAGMENTS.createImage(); 81 fPluginBlock = new PluginBlock(this); 82 } 83 84 88 public void dispose() { 89 fPluginBlock.dispose(); 90 fImage.dispose(); 91 super.dispose(); 92 } 93 94 98 public void createControl(Composite parent) { 99 Composite composite = new Composite(parent, SWT.NONE); 100 composite.setLayout(new GridLayout(3, false)); 101 102 Label label = new Label(composite, SWT.NONE); 103 label.setText(PDEUIMessages.PluginsTab_launchWith); 104 105 fSelectionCombo = new Combo(composite, SWT.READ_ONLY|SWT.BORDER); 106 fSelectionCombo.setItems(new String [] {PDEUIMessages.PluginsTab_allPlugins, PDEUIMessages.PluginsTab_selectedPlugins, PDEUIMessages.PluginsTab_featureMode}); 107 fSelectionCombo.setText(fSelectionCombo.getItem(0)); 108 fSelectionCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 109 fSelectionCombo.addSelectionListener(new Listener()); 110 111 fPluginBlock.createControl(composite, 3, 10); 112 113 setControl(composite); 114 Dialog.applyDialogFont(composite); 115 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.LAUNCHER_ADVANCED); 116 } 117 118 122 public void initializeFrom(ILaunchConfiguration configuration) { 123 try { 124 int index = DEFAULT_SELECTION; 125 if (fShowFeatures && configuration.getAttribute(IPDELauncherConstants.USEFEATURES, false)) { 126 index = FEATURE_SELECTION; 127 } else if (!configuration.getAttribute(IPDELauncherConstants.USE_DEFAULT, true)) { 128 index = CUSTOM_SELECTION; 129 } 130 fSelectionCombo.setText(fSelectionCombo.getItem(index)); 131 boolean custom = fSelectionCombo.getSelectionIndex() == CUSTOM_SELECTION; 132 fPluginBlock.initializeFrom(configuration, custom); 133 } catch (CoreException e) { 134 PDEPlugin.log(e); 135 } 136 } 137 138 142 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 143 configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, true); 144 if (fShowFeatures) 145 configuration.setAttribute(IPDELauncherConstants.USEFEATURES, false); 146 fPluginBlock.setDefaults(configuration); 147 } 148 149 153 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 154 int index = fSelectionCombo.getSelectionIndex(); 155 configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, index == DEFAULT_SELECTION); 156 if (fShowFeatures) 157 configuration.setAttribute(IPDELauncherConstants.USEFEATURES, index == FEATURE_SELECTION); 158 fPluginBlock.performApply(configuration); 159 } 160 161 165 public String getName() { 166 return PDEUIMessages.AdvancedLauncherTab_name; 167 } 168 169 173 public Image getImage() { 174 return fImage; 175 } 176 177 183 public void validateTab() { 184 String errorMessage = null; 185 if (fShowFeatures && fSelectionCombo.getSelectionIndex() == FEATURE_SELECTION) { 186 IPath workspacePath = PDEPlugin.getWorkspace().getRoot().getLocation(); 187 IPath featurePath = workspacePath.removeLastSegments(1).append("features"); if (!workspacePath.lastSegment().equalsIgnoreCase("plugins") || !featurePath.toFile().exists()) 190 errorMessage = PDEUIMessages.AdvancedLauncherTab_error_featureSetup; 191 } 192 setErrorMessage(errorMessage); 193 } 194 195 } 196 | Popular Tags |