Git Repositories View: Refactoring first part
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / repository / SelectRemoteNamePage.java
blob79fdddc503c24032a0df4c57cee86bdc9102e935
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.repository;
13 import org.eclipse.egit.ui.UIText;
14 import org.eclipse.jface.layout.GridDataFactory;
15 import org.eclipse.jface.wizard.WizardPage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.ModifyEvent;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
27 /**
30 public class SelectRemoteNamePage extends WizardPage {
32 Text remoteName;
34 Button configureFetch;
36 Button configurePush;
38 /**
41 SelectRemoteNamePage() {
42 super(SelectRemoteNamePage.class.getName());
43 setTitle(UIText.SelectRemoteNamePage_RemoteNameTitle);
44 setMessage(UIText.SelectRemoteNamePage_RemoteNameMessage);
47 public void createControl(Composite parent) {
49 setMessage(UIText.SelectRemoteNamePage_SelectRemoteNameMessage);
51 Composite main = new Composite(parent, SWT.NONE);
53 main.setLayout(new GridLayout(2, false));
54 GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
55 Label nameLabel = new Label(main, SWT.NONE);
56 nameLabel.setText(UIText.SelectRemoteNamePage_RemoteNameLabel);
58 remoteName = new Text(main, SWT.BORDER);
59 GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteName);
60 remoteName.addModifyListener(new ModifyListener() {
62 public void modifyText(ModifyEvent e) {
63 checkPage();
65 });
67 configureFetch = new Button(main, SWT.CHECK);
68 configureFetch
69 .setText(UIText.SelectRemoteNamePage_ConfigureFetch_button);
70 configureFetch.addSelectionListener(new SelectionAdapter() {
72 @Override
73 public void widgetSelected(SelectionEvent e) {
74 checkPage();
77 });
79 GridDataFactory.fillDefaults().span(2, 1).applyTo(configureFetch);
81 configurePush = new Button(main, SWT.CHECK);
82 configurePush.setText(UIText.SelectRemoteNamePage_ConfigurePush_button);
83 configurePush.addSelectionListener(new SelectionAdapter() {
85 @Override
86 public void widgetSelected(SelectionEvent e) {
87 checkPage();
90 });
91 GridDataFactory.fillDefaults().span(2, 1).applyTo(configurePush);
93 setControl(main);
94 setPageComplete(false);
98 private void checkPage() {
99 try {
100 setErrorMessage(null);
101 if (remoteName.getText().equals("")) { //$NON-NLS-1$
102 setErrorMessage(UIText.SelectRemoteNamePage_NameMustNotBeEmptyMessage);
103 return;
106 NewRemoteWizard wizard = (NewRemoteWizard) getWizard();
107 if (wizard.getConfiguration().getSubsections(
108 RepositoriesView.REMOTE).contains(remoteName.getText())) {
109 setErrorMessage(UIText.SelectRemoteNamePage_NameInUseMessage);
110 return;
113 if (!configureFetch.getSelection() && !configurePush.getSelection()) {
114 setErrorMessage(UIText.SelectRemoteNamePage_MustConfigureSomething_message);
115 return;
118 } finally {
119 setPageComplete(getErrorMessage() == null);