Git Repositories View: Import Projects
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / clone / GitSelectWizardPage.java
blob5217deb61e658e5697060cd56ad3b3523a7b8f0d
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 static final String PREF_WIZ = "GitSelectWizardPageWizardSel"; //$NON-NLS-1$
56 private static final String PREF_ACT = "GitSelectWizardPageActionSel"; //$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 public void createControl(Composite parent) {
80 Composite main = new Composite(parent, SWT.NO_RADIO_GROUP);
82 main.setLayout(new GridLayout(1, false));
84 SelectionListener sl = new SelectionAdapter() {
86 @Override
87 public void widgetSelected(SelectionEvent e) {
88 checkPage();
92 Group wizardType = new Group(main, SWT.SHADOW_ETCHED_IN);
93 GridDataFactory.fillDefaults().grab(true, false).applyTo(wizardType);
94 wizardType.setText(UIText.GitSelectWizardPage_ProjectCreationHeader);
95 wizardType.setLayout(new GridLayout(1, false));
97 importExisting = new Button(wizardType, SWT.RADIO);
98 importExisting.setText(UIText.GitSelectWizardPage_ImportExistingButton);
99 importExisting.addSelectionListener(sl);
101 newProjectWizard = new Button(wizardType, SWT.RADIO);
102 newProjectWizard.setText(UIText.GitSelectWizardPage_UseNewProjectsWizardButton);
103 newProjectWizard.addSelectionListener(sl);
105 generalWizard = new Button(wizardType, SWT.RADIO);
106 generalWizard.setText(UIText.GitSelectWizardPage_ImportAsGeneralButton);
107 generalWizard.addSelectionListener(sl);
109 Group afterImportAction = new Group(main, SWT.SHADOW_ETCHED_IN);
110 GridDataFactory.fillDefaults().grab(true, false).applyTo(
111 afterImportAction);
112 afterImportAction
113 .setText(UIText.GitSelectWizardPage_SharingProjectsHeader);
114 afterImportAction.setLayout(new GridLayout(1, false));
116 actionAutoShare = new Button(afterImportAction, SWT.RADIO);
117 actionAutoShare
118 .setText(UIText.GitSelectWizardPage_AutoShareButton);
119 actionAutoShare.addSelectionListener(sl);
121 actionDialogShare = new Button(afterImportAction, SWT.RADIO);
122 actionDialogShare.setText(UIText.GitSelectWizardPage_InteractiveShareButton);
123 actionDialogShare.addSelectionListener(sl);
125 actionNothing = new Button(afterImportAction, SWT.RADIO);
126 actionNothing.setText(UIText.GitSelectWizardPage_NoShareButton);
127 actionNothing.addSelectionListener(sl);
129 IDialogSettings settings = Activator.getDefault().getDialogSettings();
130 int previousWiz;
131 try {
132 previousWiz = settings.getInt(PREF_WIZ);
133 } catch (NumberFormatException e) {
134 previousWiz = EXISTING_PROJECTS_WIZARD;
136 switch (previousWiz) {
137 case EXISTING_PROJECTS_WIZARD:
138 importExisting.setSelection(true);
139 break;
140 case GENERAL_WIZARD:
141 generalWizard.setSelection(true);
142 break;
143 case NEW_WIZARD:
144 newProjectWizard.setEnabled(true);
145 break;
149 int previousAct;
150 try {
151 previousAct = settings.getInt(PREF_ACT);
152 } catch (NumberFormatException e) {
153 previousAct = ACTION_AUTO_SHARE;
155 switch (previousAct) {
156 case ACTION_AUTO_SHARE:
157 actionAutoShare.setSelection(true);
158 break;
159 case ACTION_DIALOG_SHARE:
160 actionDialogShare.setSelection(true);
161 break;
162 case ACTION_NO_SHARE:
163 actionNothing.setSelection(true);
164 break;
167 setControl(main);
172 * @return the wizard selection
174 public int getWizardSelection() {
175 if (importExisting.getSelection())
176 return EXISTING_PROJECTS_WIZARD;
177 if (newProjectWizard.getSelection())
178 return NEW_WIZARD;
179 if (generalWizard.getSelection())
180 return GENERAL_WIZARD;
181 return -1;
185 * @return the action selection
187 public int getActionSelection() {
188 if (actionAutoShare.getSelection())
189 return ACTION_AUTO_SHARE;
190 if (actionDialogShare.getSelection())
191 return ACTION_DIALOG_SHARE;
192 if (actionNothing.getSelection())
193 return ACTION_NO_SHARE;
194 return -1;
197 private void checkPage() {
199 // we save the selected radio button in the preferences
200 IDialogSettings settings = Activator.getDefault().getDialogSettings();
202 settings.put(PREF_WIZ, getWizardSelection());
203 settings.put(PREF_ACT, getActionSelection());
205 setErrorMessage(null);
206 try {
207 // no special checks yet
208 } finally {
209 setPageComplete(getErrorMessage() == null);