1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.motorola.studio.android.wizards.elements; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Event; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.swt.widgets.Listener; 25 import org.eclipse.swt.widgets.Text; 26 27 import com.motorola.studio.android.i18n.AndroidNLS; 28 import com.motorola.studio.android.model.AndroidProject; 29 import com.motorola.studio.android.model.IWizardModel; 30 31 /** 32 * Project Name SWT Element for Wizards 33 */ 34 public class ProjectNameGroup extends Composite 35 { 36 private final AndroidProject project; 37 38 private Text projectNameField = null; 39 40 /** 41 * Constructor 42 * @param parent 43 * @param project 44 */ 45 public ProjectNameGroup(Composite parent, AndroidProject project) 46 { 47 super(parent, SWT.NONE); 48 this.project = project; 49 createControl(parent); 50 } 51 52 /** 53 * Create Controls 54 * @param parent 55 */ 56 private void createControl(Composite parent) 57 { 58 GridLayout layout = new GridLayout(); 59 layout.numColumns = 2; 60 setLayout(layout); 61 setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 62 63 // new project Label 64 Label label = new Label(this, SWT.NONE); 65 label.setText(AndroidNLS.UI_ProjectNameGroup_ProjectNameLabel); 66 label.setFont(parent.getFont()); 67 68 // new project Name Field 69 final Text projectName = new Text(this, SWT.BORDER); 70 GridData data = new GridData(GridData.FILL_HORIZONTAL); 71 projectName.setLayoutData(data); 72 projectName.setFont(parent.getFont()); 73 projectName.addListener(SWT.Modify, new Listener() 74 { 75 public void handleEvent(Event event) 76 { 77 project.setName(projectName.getText().trim()); 78 notifyListeners(IWizardModel.MODIFIED, new Event()); 79 } 80 }); 81 82 projectNameField = projectName; 83 } 84 85 /* (non-Javadoc) 86 * @see org.eclipse.swt.widgets.Control#forceFocus() 87 */ 88 @Override 89 public boolean forceFocus() 90 { 91 boolean hasFocus = false; 92 93 if (projectNameField != null) 94 { 95 hasFocus = projectNameField.setFocus(); 96 } 97 98 return hasFocus; 99 } 100 } 101