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 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
;
64 Button actionAutoShare
;
66 Button actionDialogShare
;
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() {
87 public void widgetSelected(SelectionEvent e
) {
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(
113 .setText(UIText
.GitSelectWizardPage_SharingProjectsHeader
);
114 afterImportAction
.setLayout(new GridLayout(1, false));
116 actionAutoShare
= new Button(afterImportAction
, SWT
.RADIO
);
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();
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);
141 generalWizard
.setSelection(true);
144 newProjectWizard
.setEnabled(true);
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);
159 case ACTION_DIALOG_SHARE
:
160 actionDialogShare
.setSelection(true);
162 case ACTION_NO_SHARE
:
163 actionNothing
.setSelection(true);
172 * @return the wizard selection
174 public int getWizardSelection() {
175 if (importExisting
.getSelection())
176 return EXISTING_PROJECTS_WIZARD
;
177 if (newProjectWizard
.getSelection())
179 if (generalWizard
.getSelection())
180 return GENERAL_WIZARD
;
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
;
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);
207 // no special checks yet
209 setPageComplete(getErrorMessage() == null);