KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > breakpointGroups > SelectBreakpointWorkingsetDialog


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.actions.breakpointGroups;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
17 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
18 import org.eclipse.debug.internal.ui.SWTFactory;
19 import org.eclipse.debug.ui.DebugUITools;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.dialogs.IDialogSettings;
23 import org.eclipse.jface.viewers.ArrayContentProvider;
24 import org.eclipse.jface.viewers.CheckStateChangedEvent;
25 import org.eclipse.jface.viewers.CheckboxTableViewer;
26 import org.eclipse.jface.viewers.ICheckStateListener;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.graphics.Point;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.Table;
34 import org.eclipse.ui.IWorkingSet;
35 import org.eclipse.ui.PlatformUI;
36 import org.eclipse.ui.dialogs.SelectionDialog;
37 import org.eclipse.ui.model.AdaptableList;
38
39 /**
40  * Dialog to allow the selection of working sets without all of the overhead of the
41  * platform UI working set dialog
42  *
43  * @since 3.3.0
44  */

45 public class SelectBreakpointWorkingsetDialog extends SelectionDialog {
46     
47     private static final String JavaDoc SETTINGS_ID = DebugUIPlugin.getUniqueIdentifier() + ".DELETE_ASSOCIATED_CONFIGS_DIALOG"; //$NON-NLS-1$
48
private Object JavaDoc fInitialSelection = null;
49     private Object JavaDoc[] fResult = null;
50     private CheckboxTableViewer fViewer = null;
51     
52     /**
53      * Constructor
54      * @param parentShell the parent to open this dialog on
55      * @param selection the initial selection
56      * @param multi if the dialog should allow multi-selection or not
57      */

58     protected SelectBreakpointWorkingsetDialog(Shell parentShell, Object JavaDoc selection) {
59         super(parentShell);
60         setShellStyle(getShellStyle() | SWT.RESIZE);
61         fInitialSelection = selection;
62     }
63
64     /**
65      * Returns the current listing of breakpoint <code>IWorkingSet</code>s
66      * @return an array of the current breakpoint <code>IWorkingSet</code>s
67      */

68     private IWorkingSet[] getBreakpointWorkingSets() {
69         IWorkingSet[] ws = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets();
70         ArrayList JavaDoc list = new ArrayList JavaDoc();
71         for(int i = 0; i < ws.length; i++) {
72             if(IInternalDebugUIConstants.ID_BREAKPOINT_WORKINGSET.equals(ws[i].getId())) {
73                 list.add(ws[i]);
74             }
75         }
76         return (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]);
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
81      */

82     protected Control createDialogArea(Composite parent) {
83         initializeDialogUnits(parent);
84         Composite comp = (Composite) super.createDialogArea(parent);
85         SWTFactory.createLabel(comp, BreakpointGroupMessages.SelectBreakpointWorkingsetDialog_0, 2);
86         Table table = new Table(comp, SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
87         fViewer = new CheckboxTableViewer(table);
88         GridData gd = new GridData(GridData.FILL_BOTH);
89         gd.horizontalSpan = 2;
90         table.setLayoutData(gd);
91         fViewer.setContentProvider(new ArrayContentProvider());
92         fViewer.setInput(new AdaptableList(getBreakpointWorkingSets()).getChildren());
93         fViewer.setLabelProvider(DebugUITools.newDebugModelPresentation());
94         if(fInitialSelection != null) {
95             fViewer.setChecked(fInitialSelection, true);
96         }
97         fViewer.addCheckStateListener(new ICheckStateListener() {
98             public void checkStateChanged(CheckStateChangedEvent event) {
99                 fViewer.setCheckedElements(new Object JavaDoc[] {event.getElement()});
100                 getButton(IDialogConstants.OK_ID).setEnabled(true);
101             }
102         });
103         Dialog.applyDialogFont(comp);
104         PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugHelpContextIds.SELECT_DEFAULT_WORKINGSET_DIALOG);
105         return comp;
106     }
107     
108     /* (non-Javadoc)
109      * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
110      */

111     protected Control createButtonBar(Composite parent) {
112         Control control = super.createButtonBar(parent);
113         getButton(IDialogConstants.OK_ID).setEnabled(fViewer.getCheckedElements().length > 0);
114         return control;
115     }
116     
117     /* (non-Javadoc)
118      * @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings()
119      */

120     protected IDialogSettings getDialogBoundsSettings() {
121         IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
122         IDialogSettings section = settings.getSection(SETTINGS_ID);
123         if (section == null) {
124             section = settings.addNewSection(SETTINGS_ID);
125         }
126         return section;
127     }
128     
129     /* (non-Javadoc)
130      * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
131      */

132     protected Point getInitialSize() {
133         IDialogSettings settings = getDialogBoundsSettings();
134         if(settings != null) {
135             try {
136                 int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
137
int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
138
if(width > 0 & height > 0) {
139                     return new Point(width, height);
140                 }
141             }
142             catch (NumberFormatException JavaDoc nfe) {
143                 return new Point(350, 400);
144             }
145         }
146         return new Point(350, 400);
147     }
148     
149     /* (non-Javadoc)
150      * @see org.eclipse.ui.dialogs.SelectionDialog#getResult()
151      */

152     public Object JavaDoc[] getResult() {
153         return fResult;
154     }
155     
156     /* (non-Javadoc)
157      * @see org.eclipse.ui.dialogs.ListDialog#okPressed()
158      */

159     protected void okPressed() {
160         fResult = fViewer.getCheckedElements();
161         //set pref if selected
162
super.okPressed();
163     }
164     
165 }
166
Popular Tags