KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > launcher > PluginsTab


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
35  * A launch configuration tab that displays the different self-hosting modes,
36  * and lets the user customize the list of plug-ins to launch with.
37  * <p>
38  * This class may be instantiated. This class is not intended to be subclassed by clients.
39  * </p>
40  * @since 3.2
41  */

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     /**
63      * Constructor. Equivalent to PluginsTab(true).
64      *
65      * @see #PluginsTab(boolean)
66      *
67      */

68     public PluginsTab() {
69         this(true);
70     }
71
72     /**
73      * Constructor
74      *
75      * @param showFeatures a flag indicating if the tab should present the feature-based
76      * self-hosting option.
77      */

78     public PluginsTab(boolean showFeatures) {
79         fShowFeatures = showFeatures;
80         fImage = PDEPluginImages.DESC_PLUGINS_FRAGMENTS.createImage();
81         fPluginBlock = new PluginBlock(this);
82     }
83
84     /*
85      * (non-Javadoc)
86      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
87      */

88     public void dispose() {
89         fPluginBlock.dispose();
90         fImage.dispose();
91         super.dispose();
92     }
93
94     /*
95      * (non-Javadoc)
96      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
97      */

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 JavaDoc[] {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     /*
119      * (non-Javadoc)
120      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
121      */

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     /*
139      * (non-Javadoc)
140      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
141      */

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     /*
150      * (non-Javadoc)
151      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
152      */

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     /*
162      * (non-Javadoc)
163      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
164      */

165     public String JavaDoc getName() {
166         return PDEUIMessages.AdvancedLauncherTab_name;
167     }
168
169     /*
170      * (non-Javadoc)
171      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
172      */

173     public Image getImage() {
174         return fImage;
175     }
176     
177     /**
178      * Validates the tab. If the feature option is chosen, and the workspace is not correctly set up,
179      * the error message is set.
180      *
181      * @see org.eclipse.pde.ui.launcher.AbstractLauncherTab#validateTab()
182      */

183     public void validateTab() {
184         String JavaDoc errorMessage = null;
185         if (fShowFeatures && fSelectionCombo.getSelectionIndex() == FEATURE_SELECTION) {
186             IPath workspacePath = PDEPlugin.getWorkspace().getRoot().getLocation();
187             IPath featurePath = workspacePath.removeLastSegments(1).append("features"); //$NON-NLS-1$
188
if (!workspacePath.lastSegment().equalsIgnoreCase("plugins") //$NON-NLS-1$
189
|| !featurePath.toFile().exists())
190                 errorMessage = PDEUIMessages.AdvancedLauncherTab_error_featureSetup;
191         }
192         setErrorMessage(errorMessage);
193     }
194
195 }
196
Popular Tags