KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > importexport > breakpoints > WizardImportBreakpointsPage


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
12 package org.eclipse.debug.internal.ui.importexport.breakpoints;
13
14 import java.io.File JavaDoc;
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16 import com.ibm.icu.text.MessageFormat;
17
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
21 import org.eclipse.debug.internal.ui.SWTFactory;
22 import org.eclipse.debug.ui.DebugUITools;
23 import org.eclipse.debug.ui.actions.ImportBreakpointsOperation;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.wizard.WizardPage;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.graphics.Font;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Event;
34 import org.eclipse.swt.widgets.FileDialog;
35 import org.eclipse.swt.widgets.Group;
36 import org.eclipse.swt.widgets.Label;
37 import org.eclipse.swt.widgets.Listener;
38 import org.eclipse.swt.widgets.Text;
39 import org.eclipse.swt.widgets.Widget;
40 import org.eclipse.ui.PlatformUI;
41
42 /**
43  * The import breakpoints wizard page.
44  *
45  * This class is used in <code>WizardImportBreakpoints</code>.
46  *
47  * @since 3.2
48  */

49 public class WizardImportBreakpointsPage extends WizardPage implements Listener {
50     
51     //widgets
52
private Button fAutoRemoveDuplicates = null;
53     private Button fAutoCreateWorkingSets = null;
54     private Text fFileNameField = null;
55     private Button fBrowseForFileButton = null;
56     
57 // state constants
58
private static final String JavaDoc REMOVE_DUPS = "overwrite"; //$NON-NLS-1$
59
private static final String JavaDoc CREATE_WORKING_SETS = "createws"; //$NON-NLS-1$
60
private static final String JavaDoc SOURCE_FILE_NAME = "filename"; //$NON-NLS-1$
61

62     /**
63      * This is the default constructor. It accepts the name for the tab as a
64      * parameter
65      *
66      * @param pageName the name of the page
67      */

68     public WizardImportBreakpointsPage(String JavaDoc pageName) {
69         super(pageName, ImportExportMessages.WizardImportBreakpointsPage_0, null);
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
74      */

75     public void handleEvent(Event event) {
76         Widget source = event.widget;
77         if(source == fBrowseForFileButton) {
78             handleBrowseForFileButtonPressed();
79         }
80         setPageComplete(detectPageComplete());
81     }
82
83     /**
84      * This method handles the fBrowseForFileButton being pressed.
85      */

86     protected void handleBrowseForFileButtonPressed() {
87         FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
88         dialog.setFilterExtensions(new String JavaDoc[]{"*."+IImportExportConstants.EXTENSION}); //$NON-NLS-1$
89
String JavaDoc file = dialog.open();
90         if(file != null) {
91             fFileNameField.setText(file);
92         }
93     }
94     
95     /* (non-Javadoc)
96      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
97      */

98     public void createControl(Composite parent) {
99         initializeDialogUnits(parent);
100         Composite composite = new Composite(parent, SWT.NULL);
101         composite.setLayout(new GridLayout());
102         composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
103         composite.setFont(parent.getFont());
104         createDestinationGroup(composite);
105         createOptionsGroup(composite);
106         setControl(composite);
107         restoreWidgetState();
108         setPageComplete(detectPageComplete());
109         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.IMPORT_BREAKPOINTS_WIZARD_PAGE);
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
114      */

115     public Image getImage() {
116         return DebugUITools.getImage(IInternalDebugUIConstants.IMG_WIZBAN_IMPORT_BREAKPOINTS);
117     }
118     
119     /**
120      * This method is used to determine if the page can be "finished".
121      * To be determined "finishable" there must be an import path.
122      *
123      * @return if the prerequesites of the wizard are met to allow the wizard to complete.
124      */

125     private boolean detectPageComplete() {
126         String JavaDoc fileName = fFileNameField.getText().trim();
127         if (fileName.equals("")) {//$NON-NLS-1$
128
setMessage(ImportExportMessages.WizardImportBreakpointsPage_6);
129             return false;
130         }
131         File JavaDoc file = new File JavaDoc(fileName);
132         if (!file.exists() || file.isDirectory()) {
133             setMessage(MessageFormat.format(ImportExportMessages.WizardImportBreakpointsPage_1, new String JavaDoc[]{fileName}), ERROR);
134             return false;
135         }
136         
137         setMessage(ImportExportMessages.WizardImportBreakpointsPage_2);
138         return true;
139     }
140
141     /**
142      * Create the options specification widgets.
143      *
144      * @param parent the parent composite to add this one to
145      */

146     protected void createOptionsGroup(Composite parent) {
147         Font font = parent.getFont();
148         // options group
149
Group optionsGroup = new Group(parent, SWT.NONE);
150         GridLayout layout = new GridLayout();
151         optionsGroup.setLayout(layout);
152         optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
153         optionsGroup.setText(ImportExportMessages.WizardBreakpointsPage_5);
154         optionsGroup.setFont(parent.getFont());
155         fAutoRemoveDuplicates = new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
156         fAutoRemoveDuplicates.setText(ImportExportMessages.WizardImportBreakpointsPage_3);
157         fAutoRemoveDuplicates.setFont(font);
158         fAutoCreateWorkingSets = new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
159         fAutoCreateWorkingSets.setText(ImportExportMessages.WizardImportBreakpointsPage_5);
160         fAutoCreateWorkingSets.setFont(font);
161     }
162     
163     /**
164      * Create the export destination specification widgets
165      *
166      * @param parent the parent composite to add this one to
167      */

168     protected void createDestinationGroup(Composite parent) {
169         Font font = parent.getFont();
170         Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
171         GridLayout layout = new GridLayout();
172         layout.numColumns = 3;
173         destinationSelectionGroup.setLayout(layout);
174         destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
175         destinationSelectionGroup.setFont(font);
176         Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
177         destinationLabel.setText(ImportExportMessages.WizardImportBreakpointsPage_4);
178         destinationLabel.setFont(font);
179
180         // file name entry field
181
fFileNameField = new Text(destinationSelectionGroup, SWT.BORDER);
182         fFileNameField.addListener(SWT.Modify, this);
183         GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
184         fFileNameField.setLayoutData(data);
185         fFileNameField.setFont(font);
186
187         // destination browse button
188
fBrowseForFileButton = SWTFactory.createPushButton(destinationSelectionGroup, ImportExportMessages.WizardBreakpointsPage_8, null);
189         fBrowseForFileButton.addListener(SWT.Selection, this);
190     }
191     
192     /**
193      * Save the state of the widgets select, for successive invocations of the wizard
194      */

195     private void saveWidgetState() {
196         IDialogSettings settings = getDialogSettings();
197         if(settings != null) {
198             settings.put(REMOVE_DUPS, fAutoRemoveDuplicates.getSelection());
199             settings.put(CREATE_WORKING_SETS, fAutoCreateWorkingSets.getSelection());
200             settings.put(SOURCE_FILE_NAME, fFileNameField.getText().trim());
201         }
202     }
203     
204     /**
205      * Restores the state of the wizard from previous invocations
206      */

207     private void restoreWidgetState() {
208         IDialogSettings settings = getDialogSettings();
209         if(settings != null) {
210             fAutoRemoveDuplicates.setSelection(Boolean.valueOf(settings.get(REMOVE_DUPS)).booleanValue());
211             fAutoCreateWorkingSets.setSelection(Boolean.valueOf(settings.get(CREATE_WORKING_SETS)).booleanValue());
212             String JavaDoc fileName = settings.get(SOURCE_FILE_NAME);
213             if (fileName != null) {
214                 fFileNameField.setText(fileName);
215             }
216         }
217     }
218     
219     /**
220      * <p>
221      * This method is called when the Finish button is click on the main wizard
222      * dialog To import the breakpoints, we read then from the tree
223      * and add them into the BreakpointManager
224      * </p>
225      * @return if the import operation was successful or not
226      */

227     public boolean finish() {
228         try {
229             saveWidgetState();
230             getContainer().run(true, true, new ImportBreakpointsOperation(fFileNameField.getText().trim(), fAutoRemoveDuplicates.getSelection(), fAutoCreateWorkingSets.getSelection()));
231         }
232         catch (InterruptedException JavaDoc e) {
233             DebugPlugin.log(e);
234             return false;
235         }
236         catch (InvocationTargetException JavaDoc e) {
237             DebugPlugin.log(e);
238             return false;
239         }
240         return true;
241     }
242     
243 }
244
Popular Tags