Git Import Wizard
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / clone / GitSelectWizardPage.java
blob47aa5d75c0df76c63f959249e1e466116574acaa
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
8 * Contributors:
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;
27 /**
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 {
33 /** */
34 public static final int EXISTING_PROJECTS_WIZARD = 0;
36 /** */
37 public static final int NEW_WIZARD = 1;
39 /** */
40 public static final int GENERAL_WIZARD = 2;
42 // TODO check if we need/can support Import... wizard
43 // see also remarks in GitCreateProjectViaWizardWizard
45 /** */
46 public static final int ACTION_DIALOG_SHARE = 0;
48 /** */
49 public static final int ACTION_AUTO_SHARE = 1;
51 /** */
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;
62 Button generalWizard;
64 Button actionAutoShare;
66 Button actionDialogShare;
68 Button actionNothing;
70 /**
71 * Default constructor
73 public GitSelectWizardPage() {
74 super(GitSelectWizardPage.class.getName());
75 setTitle(UIText.GitSelectWizardPage_WizardTitle);
78 /**
79 * @param name
80 * the page name
82 protected GitSelectWizardPage(String name) {
83 super(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() {
94 @Override
95 public void widgetSelected(SelectionEvent e) {
96 checkPage();
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);
110 newProjectWizard
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(
120 afterImportAction);
121 afterImportAction
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);
130 actionDialogShare
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();
139 int previousWiz;
140 try {
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);
148 break;
149 case GENERAL_WIZARD:
150 generalWizard.setSelection(true);
151 break;
152 case NEW_WIZARD:
153 newProjectWizard.setEnabled(true);
154 break;
158 int previousAct;
159 try {
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);
167 break;
168 case ACTION_DIALOG_SHARE:
169 actionDialogShare.setSelection(true);
170 break;
171 case ACTION_NO_SHARE:
172 actionNothing.setSelection(true);
173 break;
176 setControl(main);
181 * @return the wizard selection
183 public int getWizardSelection() {
184 if (importExisting.getSelection())
185 return EXISTING_PROJECTS_WIZARD;
186 if (newProjectWizard.getSelection())
187 return NEW_WIZARD;
188 if (generalWizard.getSelection())
189 return GENERAL_WIZARD;
190 return -1;
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;
203 return -1;
207 * check routine
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);
218 try {
219 // no special checks yet
220 } finally {
221 setPageComplete(getErrorMessage() == null);