1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
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
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.clone
;
13 import org
.eclipse
.egit
.ui
.Activator
;
14 import org
.eclipse
.egit
.ui
.UIText
;
15 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
16 import org
.eclipse
.jface
.layout
.GridDataFactory
;
17 import org
.eclipse
.jface
.wizard
.WizardPage
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.events
.SelectionListener
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Button
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Group
;
28 * Asks the user to select a wizard and what to do with the imported projects
29 * (automatic/manual/no share)
31 public class GitSelectWizardPage
extends WizardPage
{
34 public static final int EXISTING_PROJECTS_WIZARD
= 0;
37 public static final int NEW_WIZARD
= 1;
40 public static final int GENERAL_WIZARD
= 2;
42 // TODO check if we need/can support Import... wizard
43 // see also remarks in GitCreateProjectViaWizardWizard
46 public static final int ACTION_DIALOG_SHARE
= 0;
49 public static final int ACTION_AUTO_SHARE
= 1;
52 public static final int ACTION_NO_SHARE
= 2;
54 private final String PREF_WIZ
= getName() + "WizardSel"; //$NON-NLS-1$
56 private final String PREF_ACT
= getName() + "ActionSel"; //$NON-NLS-1$
58 Button importExisting
;
60 Button newProjectWizard
;
64 Button actionAutoShare
;
66 Button actionDialogShare
;
73 public GitSelectWizardPage() {
74 super(GitSelectWizardPage
.class.getName());
75 setTitle(UIText
.GitSelectWizardPage_WizardTitle
);
82 protected GitSelectWizardPage(String name
) {
86 public void createControl(Composite parent
) {
88 Composite main
= new Composite(parent
, SWT
.NO_RADIO_GROUP
);
90 main
.setLayout(new GridLayout(1, false));
92 SelectionListener sl
= new SelectionAdapter() {
95 public void widgetSelected(SelectionEvent e
) {
100 Group wizardType
= new Group(main
, SWT
.SHADOW_ETCHED_IN
);
101 GridDataFactory
.fillDefaults().grab(true, false).applyTo(wizardType
);
102 wizardType
.setText(UIText
.GitSelectWizardPage_ProjectCreationHeader
);
103 wizardType
.setLayout(new GridLayout(1, false));
105 importExisting
= new Button(wizardType
, SWT
.RADIO
);
106 importExisting
.setText(UIText
.GitSelectWizardPage_ImportExistingButton
);
107 importExisting
.addSelectionListener(sl
);
109 newProjectWizard
= new Button(wizardType
, SWT
.RADIO
);
111 .setText(UIText
.GitSelectWizardPage_UseNewProjectsWizardButton
);
112 newProjectWizard
.addSelectionListener(sl
);
114 generalWizard
= new Button(wizardType
, SWT
.RADIO
);
115 generalWizard
.setText(UIText
.GitSelectWizardPage_ImportAsGeneralButton
);
116 generalWizard
.addSelectionListener(sl
);
118 Group afterImportAction
= new Group(main
, SWT
.SHADOW_ETCHED_IN
);
119 GridDataFactory
.fillDefaults().grab(true, false).applyTo(
122 .setText(UIText
.GitSelectWizardPage_SharingProjectsHeader
);
123 afterImportAction
.setLayout(new GridLayout(1, false));
125 actionAutoShare
= new Button(afterImportAction
, SWT
.RADIO
);
126 actionAutoShare
.setText(UIText
.GitSelectWizardPage_AutoShareButton
);
127 actionAutoShare
.addSelectionListener(sl
);
129 actionDialogShare
= new Button(afterImportAction
, SWT
.RADIO
);
131 .setText(UIText
.GitSelectWizardPage_InteractiveShareButton
);
132 actionDialogShare
.addSelectionListener(sl
);
134 actionNothing
= new Button(afterImportAction
, SWT
.RADIO
);
135 actionNothing
.setText(UIText
.GitSelectWizardPage_NoShareButton
);
136 actionNothing
.addSelectionListener(sl
);
138 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
141 previousWiz
= settings
.getInt(PREF_WIZ
);
142 } catch (NumberFormatException e
) {
143 previousWiz
= EXISTING_PROJECTS_WIZARD
;
145 switch (previousWiz
) {
146 case EXISTING_PROJECTS_WIZARD
:
147 importExisting
.setSelection(true);
150 generalWizard
.setSelection(true);
153 newProjectWizard
.setEnabled(true);
160 previousAct
= settings
.getInt(PREF_ACT
);
161 } catch (NumberFormatException e
) {
162 previousAct
= ACTION_AUTO_SHARE
;
164 switch (previousAct
) {
165 case ACTION_AUTO_SHARE
:
166 actionAutoShare
.setSelection(true);
168 case ACTION_DIALOG_SHARE
:
169 actionDialogShare
.setSelection(true);
171 case ACTION_NO_SHARE
:
172 actionNothing
.setSelection(true);
181 * @return the wizard selection
183 public int getWizardSelection() {
184 if (importExisting
.getSelection())
185 return EXISTING_PROJECTS_WIZARD
;
186 if (newProjectWizard
.getSelection())
188 if (generalWizard
.getSelection())
189 return GENERAL_WIZARD
;
194 * @return the action selection
196 public int getActionSelection() {
197 if (actionAutoShare
.getSelection())
198 return ACTION_AUTO_SHARE
;
199 if (actionDialogShare
.getSelection())
200 return ACTION_DIALOG_SHARE
;
201 if (actionNothing
.getSelection())
202 return ACTION_NO_SHARE
;
209 protected void checkPage() {
211 // we save the selected radio button in the preferences
212 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
214 settings
.put(PREF_WIZ
, getWizardSelection());
215 settings
.put(PREF_ACT
, getActionSelection());
217 setErrorMessage(null);
219 // no special checks yet
221 setPageComplete(getErrorMessage() == null);