KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > ModeSelectionPage


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.update.internal.ui.wizards;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.update.internal.operations.UpdateUtils;
26 import org.eclipse.update.internal.ui.UpdateUI;
27 import org.eclipse.update.internal.ui.UpdateUIMessages;
28 import org.eclipse.update.search.UpdateSearchRequest;
29
30 /**
31  */

32 public class ModeSelectionPage extends BannerPage implements ISearchProvider {
33     private boolean updateMode=true;
34     private Button updatesButton;
35     private Button newFeaturesButton;
36     private UpdateSearchRequest searchRequest;
37     private static final String JavaDoc SECTION_ID = "ModeSelectionPage"; //$NON-NLS-1$
38
private static final String JavaDoc P_NEW_FEATURES_MODE = "new-features-mode"; //$NON-NLS-1$
39

40     public ModeSelectionPage(UpdateSearchRequest searchRequest) {
41         super("modeSelection"); //$NON-NLS-1$
42
setTitle(UpdateUIMessages.ModeSelectionPage_title);
43         setDescription(UpdateUIMessages.ModeSelectionPage_desc);
44         this.searchRequest = searchRequest;
45     }
46     
47     public UpdateSearchRequest getSearchRequest() {
48         initializeSearch();
49         return searchRequest;
50     }
51     
52     private IDialogSettings getSettings() {
53         IDialogSettings master = UpdateUI.getDefault().getDialogSettings();
54         IDialogSettings section = master.getSection(SECTION_ID);
55         if (section==null)
56             section = master.addNewSection(SECTION_ID);
57         return section;
58     }
59
60     private void initializeSearch() {
61         if (searchRequest!=null) return;
62         searchRequest = UpdateUtils.createNewUpdatesRequest(null, false);
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.update.internal.ui.wizards.BannerPage#createContents(org.eclipse.swt.widgets.Composite)
67      */

68     protected Control createContents(Composite parent) {
69         Composite composite = new Composite(parent, SWT.NULL);
70         GridLayout layout = new GridLayout();
71         composite.setLayout(layout);
72         updatesButton = new Button(composite, SWT.RADIO);
73         updatesButton.setText(UpdateUIMessages.ModeSelectionPage_updates);
74         updateMode = !getSettings().getBoolean(P_NEW_FEATURES_MODE);
75         updatesButton.setSelection(updateMode);
76         
77         final Label updatesText = new Label(composite, SWT.WRAP);
78         updatesText.setText(UpdateUIMessages.ModeSelectionPage_updatesText);
79         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
80         gd.widthHint = 100;
81         updatesText.setLayoutData(gd);
82         
83         updatesButton.addSelectionListener(new SelectionAdapter() {
84             public void widgetSelected(SelectionEvent e) {
85                 updateMode = true;
86                 getWizard().getContainer().updateButtons();
87             }
88         });
89         // spacer
90
new Label(composite, SWT.NULL);
91         newFeaturesButton = new Button(composite, SWT.RADIO);
92         newFeaturesButton.setSelection(!updateMode);
93         newFeaturesButton.setText(UpdateUIMessages.ModeSelectionPage_newFeatures);
94         newFeaturesButton.addSelectionListener(new SelectionAdapter() {
95             public void widgetSelected(SelectionEvent e) {
96                 updateMode = false;
97                 getWizard().getContainer().updateButtons();
98             }
99         });
100
101         final Label newFeaturesText = new Label(composite, SWT.WRAP);
102         newFeaturesText.setText(UpdateUIMessages.ModeSelectionPage_newFeaturesText);
103         gd = new GridData(GridData.FILL_HORIZONTAL);
104         gd.widthHint = 100;
105         newFeaturesText.setLayoutData(gd);
106
107         /*
108         composite.addControlListener(new ControlAdapter() {
109             public void controlResized(ControlEvent e) {
110                 Composite parent = (Composite)e.widget;
111                 Rectangle carea = parent.getClientArea();
112                 GridData gd = (GridData)updatesText.getLayoutData();
113                 gd.widthHint = carea.width;
114                 gd = (GridData)newFeaturesText.getLayoutData();
115                 gd.widthHint = carea.width;
116             }
117         });
118         */

119         
120         Dialog.applyDialogFont(parent);
121         
122         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, "org.eclipse.update.ui.ModeSelectionPage"); //$NON-NLS-1$
123

124         return composite;
125     }
126     
127     public void saveSettings() {
128         boolean updateMode = updatesButton.getSelection();
129         getSettings().put(P_NEW_FEATURES_MODE, !updateMode);
130     }
131     
132     public boolean isUpdateMode() {
133         return updateMode;
134     }
135
136     public boolean isPageComplete() {
137         return updateMode && super.isPageComplete();
138     }
139
140     protected boolean isCurrentPage() {
141         return super.isCurrentPage();
142     }
143
144     public boolean canFlipToNextPage() {
145         return !updateMode;
146     }
147     
148     
149     
150 }
151
Popular Tags