KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > SelectFavoritesDialog


1 /*******************************************************************************
2  * Copyright (c) 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.debug.internal.ui.launchConfigurations;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.debug.core.DebugPlugin;
18 import org.eclipse.debug.core.ILaunchConfiguration;
19 import org.eclipse.debug.internal.ui.DebugUIPlugin;
20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
21 import org.eclipse.debug.internal.ui.SWTFactory;
22 import org.eclipse.debug.ui.IDebugUIConstants;
23 import org.eclipse.jface.viewers.IContentProvider;
24 import org.eclipse.jface.viewers.IStructuredContentProvider;
25 import org.eclipse.jface.viewers.Viewer;
26 import org.eclipse.jface.viewers.ViewerFilter;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.ui.model.WorkbenchViewerComparator;
35
36 import com.ibm.icu.text.MessageFormat;
37
38 /**
39  * This dialog is used to select one or more launch configurations to add to your favorites
40  *
41  * @since 3.3.0
42  */

43 public class SelectFavoritesDialog extends AbstractDebugCheckboxSelectionDialog {
44
45     /**
46      * Content provider for table
47      */

48     protected class LaunchConfigurationContentProvider implements IStructuredContentProvider {
49         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
50             ILaunchConfiguration[] all = null;
51             try {
52                 all = LaunchConfigurationManager.filterConfigs(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations());
53             } catch (CoreException e) {
54                 DebugUIPlugin.log(e);
55                 return new ILaunchConfiguration[0];
56             }
57             List JavaDoc list = new ArrayList JavaDoc(all.length);
58             ViewerFilter filter = new LaunchGroupFilter(fHistory.getLaunchGroup());
59             for (int i = 0; i < all.length; i++) {
60                 if (filter.select(null, null, all[i])) {
61                     list.add(all[i]);
62                 }
63             }
64             list.removeAll(fCurrentFavoriteSet);
65             Object JavaDoc[] objs = list.toArray();
66             new WorkbenchViewerComparator().sort(getCheckBoxTableViewer(), objs);
67             return objs;
68         }
69
70         public void dispose() {}
71         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {}
72     }
73     
74     private LaunchHistory fHistory;
75     private List JavaDoc fCurrentFavoriteSet;
76     
77     /**
78      * Constructor
79      * @param parentShell
80      * @param history
81      * @param favorites
82      */

83     public SelectFavoritesDialog(Shell parentShell, LaunchHistory history, List JavaDoc favorites) {
84         super(parentShell);
85         fHistory = history;
86         fCurrentFavoriteSet = favorites;
87         setTitle(MessageFormat.format(LaunchConfigurationsMessages.FavoritesDialog_0, new String JavaDoc[]{getModeLabel()}));
88     }
89
90     /**
91      * Returns a label to use for launch mode with accelerators removed.
92      *
93      * @return label to use for launch mode with accelerators removed
94      */

95     private String JavaDoc getModeLabel() {
96         return DebugUIPlugin.removeAccelerators(fHistory.getLaunchGroup().getLabel());
97     }
98     
99     /* (non-Javadoc)
100      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getDialogSettingsId()
101      */

102     protected String JavaDoc getDialogSettingsId() {
103         return IDebugUIConstants.PLUGIN_ID + ".SELECT_FAVORITESS_DIALOG"; //$NON-NLS-1$
104
}
105
106     /* (non-Javadoc)
107      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getViewerInput()
108      */

109     protected Object JavaDoc getViewerInput() {
110         return fHistory.getLaunchGroup().getMode();
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getContentProvider()
115      */

116     protected IContentProvider getContentProvider() {
117         return new LaunchConfigurationContentProvider();
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getHelpContextId()
122      */

123     protected String JavaDoc getHelpContextId() {
124         return IDebugHelpContextIds.SELECT_FAVORITES_DIALOG;
125     }
126     
127     /* (non-Javadoc)
128      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getViewerLabel()
129      */

130     protected String JavaDoc getViewerLabel() {
131         return LaunchConfigurationsMessages.FavoritesDialog_7;
132     }
133     
134     /* (non-Javadoc)
135      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#addCustomFooterControls(org.eclipse.swt.widgets.Composite)
136      */

137     protected void addCustomFooterControls(Composite parent) {
138         Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_HORIZONTAL);
139         GridData gd = (GridData) comp.getLayoutData();
140         gd.horizontalAlignment = SWT.END;
141         Button button = SWTFactory.createPushButton(comp, LaunchConfigurationsMessages.SelectFavoritesDialog_0, null);
142         button.addSelectionListener(new SelectionAdapter() {
143             public void widgetSelected(SelectionEvent e) {
144                 getCheckBoxTableViewer().setAllChecked(true);
145                 getOkButton().setEnabled(true);
146             }
147         });
148         button = SWTFactory.createPushButton(comp, LaunchConfigurationsMessages.SelectFavoritesDialog_1, null);
149         button.addSelectionListener(new SelectionAdapter() {
150             public void widgetSelected(SelectionEvent e) {
151                 getCheckBoxTableViewer().setAllChecked(false);
152                 getOkButton().setEnabled(false);
153             }
154         });
155     }
156 }
157
Popular Tags