KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointWorkingSetPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.views.breakpoints;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.debug.core.DebugPlugin;
18 import org.eclipse.debug.core.model.IBreakpoint;
19 import org.eclipse.debug.internal.ui.DebugPluginImages;
20 import org.eclipse.debug.internal.ui.DebugUIPlugin;
21 import org.eclipse.debug.internal.ui.SWTFactory;
22 import org.eclipse.debug.internal.ui.importexport.breakpoints.EmbeddedBreakpointsViewer;
23 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
24 import org.eclipse.debug.ui.IDebugUIConstants;
25 import org.eclipse.jface.dialogs.Dialog;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.viewers.StructuredSelection;
28 import org.eclipse.jface.wizard.WizardPage;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.events.ModifyEvent;
31 import org.eclipse.swt.events.ModifyListener;
32 import org.eclipse.swt.events.SelectionAdapter;
33 import org.eclipse.swt.events.SelectionEvent;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Button;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.swt.widgets.Text;
40 import org.eclipse.ui.IViewPart;
41 import org.eclipse.ui.IWorkingSet;
42 import org.eclipse.ui.IWorkingSetManager;
43 import org.eclipse.ui.PlatformUI;
44 import org.eclipse.ui.dialogs.IWorkingSetPage;
45
46 /**
47  * The Breakpoint working set page allows the user to create
48  * and edit a Breakpoint working set.
49  *
50  * @since 3.1
51  */

52 public class BreakpointWorkingSetPage extends WizardPage implements IWorkingSetPage {
53
54     final private static String JavaDoc PAGE_TITLE= DebugUIViewsMessages.BreakpointWorkingSetPage_0;
55     final private static String JavaDoc PAGE_ID= "breakpointWorkingSetPage"; //$NON-NLS-1$
56

57     private Text fWorkingSetName;
58     private EmbeddedBreakpointsViewer fTViewer;
59     private boolean fFirstCheck;
60     private IWorkingSet fWorkingSet;
61
62     /**
63      * Default constructor.
64      */

65     public BreakpointWorkingSetPage() {
66         super(PAGE_ID, PAGE_TITLE, DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_WIZBAN_DEBUG));
67         setDescription(DebugUIViewsMessages.BreakpointWorkingSetPage_1);
68         fFirstCheck= true;
69     }
70
71     /*
72      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
73      */

74     public void createControl(Composite parent) {
75         initializeDialogUnits(parent);
76         Composite composite= new Composite(parent, SWT.NONE);
77         composite.setLayout(new GridLayout());
78         composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
79         setControl(composite);
80         Label label= new Label(composite, SWT.WRAP);
81         label.setText(DebugUIViewsMessages.BreakpointWorkingSetPage_2);
82         GridData gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
83         label.setLayoutData(gd);
84         fWorkingSetName= new Text(composite, SWT.SINGLE | SWT.BORDER);
85         fWorkingSetName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
86         fWorkingSetName.addModifyListener(
87             new ModifyListener() {
88                 public void modifyText(ModifyEvent e) {
89                     validateInput();
90                 }
91             }
92         );
93         fWorkingSetName.setFocus();
94         label= new Label(composite, SWT.WRAP);
95         label.setText(DebugUIViewsMessages.BreakpointWorkingSetPage_3);
96         gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
97         label.setLayoutData(gd);
98         IViewPart viewpart = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage().findView(IDebugUIConstants.ID_BREAKPOINT_VIEW);
99         IStructuredSelection selection;
100         if (viewpart == null) {
101             selection = new StructuredSelection();
102         } else {
103             selection = (IStructuredSelection)viewpart.getViewSite().getSelectionProvider().getSelection();
104         }
105         fTViewer = new EmbeddedBreakpointsViewer(composite, DebugPlugin.getDefault().getBreakpointManager(), selection);
106         // Add select / deselect all buttons for bug 46669
107
Composite buttonComposite = new Composite(composite, SWT.NONE);
108         buttonComposite.setLayout(new GridLayout(2, false));
109         buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
110         Button selectAllButton = SWTFactory.createPushButton(buttonComposite, DebugUIViewsMessages.BreakpointWorkingSetPage_selectAll_label, null);
111         selectAllButton.setToolTipText(DebugUIViewsMessages.BreakpointWorkingSetPage_selectAll_toolTip);
112         selectAllButton.addSelectionListener(new SelectionAdapter() {
113             public void widgetSelected(SelectionEvent selectionEvent) {
114                 BreakpointsViewer viewer = fTViewer.getViewer();
115                 viewer.getTree().selectAll();
116                 viewer.setCheckedElements(((IStructuredSelection)viewer.getSelection()).toArray());
117                 viewer.setGrayedElements(new Object JavaDoc[] {});
118                 viewer.getTree().deselectAll();
119                 validateInput();
120             }
121         });
122         Button deselectAllButton = SWTFactory.createPushButton(buttonComposite, DebugUIViewsMessages.BreakpointWorkingSetPage_deselectAll_label, null);
123         deselectAllButton.setToolTipText(DebugUIViewsMessages.BreakpointWorkingSetPage_deselectAll_toolTip);
124         deselectAllButton.addSelectionListener(new SelectionAdapter() {
125             public void widgetSelected(SelectionEvent selectionEvent) {
126                 BreakpointsViewer viewer = fTViewer.getViewer();
127                 viewer.setCheckedElements(new Object JavaDoc[] {});
128                 validateInput();
129             }
130         });
131         if (fWorkingSet != null)
132             fWorkingSetName.setText(fWorkingSet.getName());
133         validateInput();
134         Dialog.applyDialogFont(composite);
135     }
136
137     /*
138      * Implements method from IWorkingSetPage
139      */

140     public IWorkingSet getSelection() {
141         return fWorkingSet;
142     }
143
144     /*
145      * Implements method from IWorkingSetPage
146      */

147     public void setSelection(IWorkingSet workingSet) {
148         Assert.isNotNull(workingSet, "Working set must not be null"); //$NON-NLS-1$
149
fWorkingSet= workingSet;
150         if (getContainer() != null && getShell() != null && fWorkingSetName != null) {
151             fFirstCheck= false;
152             fWorkingSetName.setText(fWorkingSet.getName());
153             validateInput();
154         }
155     }
156
157     /*
158      * Implements method from IWorkingSetPage
159      */

160     public void finish() {
161         String JavaDoc workingSetName = fWorkingSetName.getText();
162         Object JavaDoc[] adaptable = fTViewer.getCheckedElements().toArray();
163         ArrayList JavaDoc elements = new ArrayList JavaDoc();
164         //weed out non-breakpoint elements since 3.2
165
for(int i = 0; i < adaptable.length; i++) {
166             if(adaptable[i] instanceof IBreakpoint) {
167                 elements.add(adaptable[i]);
168             }//end if
169
}//end for
170
if (fWorkingSet == null) {
171             IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
172             fWorkingSet = workingSetManager.createWorkingSet(workingSetName, (IAdaptable[])elements.toArray(new IAdaptable[elements.size()]));
173         } else {
174             fWorkingSet.setName(workingSetName);
175             fWorkingSet.setElements((IAdaptable[])elements.toArray(new IAdaptable[elements.size()]));
176         }
177     }
178
179     /**
180      * validates the current input of the page to determine if the finish button can be enabled
181      */

182     private void validateInput() {
183         String JavaDoc errorMessage= null;
184         String JavaDoc newText= fWorkingSetName.getText();
185
186         if (newText.equals(newText.trim()) == false)
187             errorMessage = DebugUIViewsMessages.BreakpointWorkingSetPage_4;
188         if (newText.equals("")) { //$NON-NLS-1$
189
if (fFirstCheck) {
190                 setPageComplete(false);
191                 fFirstCheck= false;
192                 return;
193             }
194             errorMessage= DebugUIViewsMessages.BreakpointWorkingSetPage_5;
195         }
196         fFirstCheck= false;
197         if (errorMessage == null && (fWorkingSet == null || newText.equals(fWorkingSet.getName()) == false)) {
198             IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
199             for (int i= 0; i < workingSets.length; i++) {
200                 if (newText.equals(workingSets[i].getName())) {
201                     errorMessage= DebugUIViewsMessages.BreakpointWorkingSetPage_6;
202                 }
203             }
204         }
205         setErrorMessage(errorMessage);
206         setPageComplete(errorMessage == null);
207     }
208     
209 }
210
Popular Tags