1 /******************************************************************************* 2 * Copyright (c) 2011 - 2013 by Timotei Dolean <timotei21@gmail.com> 3 * 4 * This program and the accompanying materials are made available 5 * under the terms of the Eclipse Public License v1.0 6 * which accompanies this distribution, and is available at 7 * http://www.eclipse.org/legal/epl-v10.html 8 *******************************************************************************/ 9 package org.wesnoth.installs; 10 11 import org.eclipse.jface.dialogs.Dialog; 12 import org.eclipse.swt.SWT; 13 import org.eclipse.swt.graphics.Point; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.layout.GridLayout; 16 import org.eclipse.swt.widgets.Combo; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.Label; 20 import org.eclipse.swt.widgets.Shell; 21 22 /** 23 * A simple dialog that asks the user to select between existing 24 * Wesnoth installs 25 */ 26 public class SelectWesnothInstallDialog extends Dialog 27 { 28 private Combo cmbInstall_; 29 30 /** 31 * Creates a new dialog on the specified shell 32 * 33 * @param parentShell 34 * The shell to create the dialog in 35 */ SelectWesnothInstallDialog( Shell parentShell )36 public SelectWesnothInstallDialog( Shell parentShell ) 37 { 38 super( parentShell ); 39 40 cmbInstall_ = null; 41 } 42 43 @Override configureShell( Shell newShell )44 protected void configureShell( Shell newShell ) 45 { 46 super.configureShell( newShell ); 47 48 newShell.setText( "Select the Wesnoth Install" ); 49 } 50 51 @Override createDialogArea( Composite parent )52 protected Control createDialogArea( Composite parent ) 53 { 54 Composite composite = new Composite( parent, SWT.NONE ); 55 composite.setLayout( new GridLayout( 2, false ) ); 56 57 Label lblWesnothInstall = new Label( composite, SWT.NONE ); 58 lblWesnothInstall.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, 59 false, false, 1, 1 ) ); 60 lblWesnothInstall.setText( "Wesnoth Install:" ); 61 62 cmbInstall_ = new Combo( composite, SWT.READ_ONLY ); 63 GridData gd_cmbInstall_ = new GridData( SWT.FILL, SWT.CENTER, true, 64 false, 1, 1 ); 65 gd_cmbInstall_.widthHint = 163; 66 cmbInstall_.setLayoutData( gd_cmbInstall_ ); 67 68 WesnothInstallsUtils.fillComboWithInstalls( cmbInstall_ ); 69 70 return super.createDialogArea( parent ); 71 } 72 73 @Override getInitialSize( )74 protected Point getInitialSize( ) 75 { 76 return new Point( 291, 123 ); 77 } 78 79 /** 80 * Gets the install selected by the user 81 * 82 * @return A string with the name of the install selected 83 */ getSelectedInstallName( )84 public String getSelectedInstallName( ) 85 { 86 if( cmbInstall_ == null ) { 87 return ""; 88 } 89 90 return cmbInstall_.getText( ); 91 } 92 } 93