001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.launcher;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IPath;
014: import org.eclipse.debug.core.ILaunchConfiguration;
015: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
016: import org.eclipse.jface.dialogs.Dialog;
017: import org.eclipse.pde.internal.ui.IHelpContextIds;
018: import org.eclipse.pde.internal.ui.PDEPlugin;
019: import org.eclipse.pde.internal.ui.PDEPluginImages;
020: import org.eclipse.pde.internal.ui.PDEUIMessages;
021: import org.eclipse.pde.internal.ui.launcher.PluginBlock;
022: import org.eclipse.swt.SWT;
023: import org.eclipse.swt.events.SelectionAdapter;
024: import org.eclipse.swt.events.SelectionEvent;
025: import org.eclipse.swt.graphics.Image;
026: import org.eclipse.swt.layout.GridData;
027: import org.eclipse.swt.layout.GridLayout;
028: import org.eclipse.swt.widgets.Combo;
029: import org.eclipse.swt.widgets.Composite;
030: import org.eclipse.swt.widgets.Label;
031: import org.eclipse.ui.PlatformUI;
032:
033: /**
034: * A launch configuration tab that displays the different self-hosting modes,
035: * and lets the user customize the list of plug-ins to launch with.
036: * <p>
037: * This class may be instantiated. This class is not intended to be subclassed by clients.
038: * </p>
039: * @since 3.2
040: */
041: public class PluginsTab extends AbstractLauncherTab {
042:
043: private Image fImage;
044:
045: private boolean fShowFeatures = true;
046: private Combo fSelectionCombo;
047: private PluginBlock fPluginBlock;
048:
049: private static final int DEFAULT_SELECTION = 0;
050: private static final int CUSTOM_SELECTION = 1;
051: private static final int FEATURE_SELECTION = 2;
052:
053: class Listener extends SelectionAdapter {
054: public void widgetSelected(SelectionEvent e) {
055: int index = fSelectionCombo.getSelectionIndex();
056: fPluginBlock.enableViewer(index == CUSTOM_SELECTION);
057: updateLaunchConfigurationDialog();
058: }
059: }
060:
061: /**
062: * Constructor. Equivalent to PluginsTab(true).
063: *
064: * @see #PluginsTab(boolean)
065: *
066: */
067: public PluginsTab() {
068: this (true);
069: }
070:
071: /**
072: * Constructor
073: *
074: * @param showFeatures a flag indicating if the tab should present the feature-based
075: * self-hosting option.
076: */
077: public PluginsTab(boolean showFeatures) {
078: fShowFeatures = showFeatures;
079: fImage = PDEPluginImages.DESC_PLUGINS_FRAGMENTS.createImage();
080: fPluginBlock = new PluginBlock(this );
081: }
082:
083: /*
084: * (non-Javadoc)
085: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
086: */
087: public void dispose() {
088: fPluginBlock.dispose();
089: fImage.dispose();
090: super .dispose();
091: }
092:
093: /*
094: * (non-Javadoc)
095: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
096: */
097: public void createControl(Composite parent) {
098: Composite composite = new Composite(parent, SWT.NONE);
099: composite.setLayout(new GridLayout(3, false));
100:
101: Label label = new Label(composite, SWT.NONE);
102: label.setText(PDEUIMessages.PluginsTab_launchWith);
103:
104: fSelectionCombo = new Combo(composite, SWT.READ_ONLY
105: | SWT.BORDER);
106: fSelectionCombo.setItems(new String[] {
107: PDEUIMessages.PluginsTab_allPlugins,
108: PDEUIMessages.PluginsTab_selectedPlugins,
109: PDEUIMessages.PluginsTab_featureMode });
110: fSelectionCombo.setText(fSelectionCombo.getItem(0));
111: fSelectionCombo.setLayoutData(new GridData(
112: GridData.FILL_HORIZONTAL));
113: fSelectionCombo.addSelectionListener(new Listener());
114:
115: fPluginBlock.createControl(composite, 3, 10);
116:
117: setControl(composite);
118: Dialog.applyDialogFont(composite);
119: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
120: IHelpContextIds.LAUNCHER_ADVANCED);
121: }
122:
123: /*
124: * (non-Javadoc)
125: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
126: */
127: public void initializeFrom(ILaunchConfiguration configuration) {
128: try {
129: int index = DEFAULT_SELECTION;
130: if (fShowFeatures
131: && configuration.getAttribute(
132: IPDELauncherConstants.USEFEATURES, false)) {
133: index = FEATURE_SELECTION;
134: } else if (!configuration.getAttribute(
135: IPDELauncherConstants.USE_DEFAULT, true)) {
136: index = CUSTOM_SELECTION;
137: }
138: fSelectionCombo.setText(fSelectionCombo.getItem(index));
139: boolean custom = fSelectionCombo.getSelectionIndex() == CUSTOM_SELECTION;
140: fPluginBlock.initializeFrom(configuration, custom);
141: } catch (CoreException e) {
142: PDEPlugin.log(e);
143: }
144: }
145:
146: /*
147: * (non-Javadoc)
148: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
149: */
150: public void setDefaults(
151: ILaunchConfigurationWorkingCopy configuration) {
152: configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT,
153: true);
154: if (fShowFeatures)
155: configuration.setAttribute(
156: IPDELauncherConstants.USEFEATURES, false);
157: fPluginBlock.setDefaults(configuration);
158: }
159:
160: /*
161: * (non-Javadoc)
162: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
163: */
164: public void performApply(
165: ILaunchConfigurationWorkingCopy configuration) {
166: int index = fSelectionCombo.getSelectionIndex();
167: configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT,
168: index == DEFAULT_SELECTION);
169: if (fShowFeatures)
170: configuration.setAttribute(
171: IPDELauncherConstants.USEFEATURES,
172: index == FEATURE_SELECTION);
173: fPluginBlock.performApply(configuration);
174: }
175:
176: /*
177: * (non-Javadoc)
178: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
179: */
180: public String getName() {
181: return PDEUIMessages.AdvancedLauncherTab_name;
182: }
183:
184: /*
185: * (non-Javadoc)
186: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
187: */
188: public Image getImage() {
189: return fImage;
190: }
191:
192: /**
193: * Validates the tab. If the feature option is chosen, and the workspace is not correctly set up,
194: * the error message is set.
195: *
196: * @see org.eclipse.pde.ui.launcher.AbstractLauncherTab#validateTab()
197: */
198: public void validateTab() {
199: String errorMessage = null;
200: if (fShowFeatures
201: && fSelectionCombo.getSelectionIndex() == FEATURE_SELECTION) {
202: IPath workspacePath = PDEPlugin.getWorkspace().getRoot()
203: .getLocation();
204: IPath featurePath = workspacePath.removeLastSegments(1)
205: .append("features"); //$NON-NLS-1$
206: if (!workspacePath.lastSegment()
207: .equalsIgnoreCase("plugins") //$NON-NLS-1$
208: || !featurePath.toFile().exists())
209: errorMessage = PDEUIMessages.AdvancedLauncherTab_error_featureSetup;
210: }
211: setErrorMessage(errorMessage);
212: }
213:
214: }
|