1 package org.eclipse.emf.examples.jet.article2.ui; 2 3 4 5 import org.eclipse.core.runtime.IStatus; 6 import org.eclipse.jdt.core.IJavaElement; 7 import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; 8 import org.eclipse.jface.dialogs.Dialog; 9 import org.eclipse.jface.viewers.IStructuredSelection; 10 import org.eclipse.swt.SWT; 11 import org.eclipse.swt.events.ModifyEvent; 12 import org.eclipse.swt.events.ModifyListener; 13 import org.eclipse.swt.layout.GridData; 14 import org.eclipse.swt.layout.GridLayout; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Label; 17 import org.eclipse.swt.widgets.Text; 18 19 import org.eclipse.emf.examples.jet.article2.model.TypesafeEnum; 20 21 22 30 public class NewTypesafeEnumCreationWizardPage extends NewTypeWizardPage 31 { 32 33 protected final static String PAGE_NAME = "NewTypesafeEnumCreationWizardPage"; 35 protected TypesafeEnum mTypesafeEnumModel = new TypesafeEnum(); 36 37 private Text mTextAuthor = null; 38 39 private Text mTextVersion = null; 40 41 45 public NewTypesafeEnumCreationWizardPage() 46 { 47 super(true, PAGE_NAME); 48 setTitle(WizardMessages.getString("NewEnumWizPage.title")); setDescription(WizardMessages.getString("NewEnumWizPage.description")); } 51 52 60 public void init(IStructuredSelection selection) 61 { 62 IJavaElement jelem = getInitialJavaElement(selection); 63 initContainerPage(jelem); 64 initTypePage(jelem); 65 doStatusUpdate(); 66 67 } 80 81 private void doStatusUpdate() 83 { 84 IStatus[] status = new IStatus []{ 86 fContainerStatus, 87 isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus, 88 fTypeNameStatus, 89 fModifierStatus, 90 fSuperClassStatus, 91 fSuperInterfacesStatus }; 92 93 updateEnumType(); 94 95 updateStatus(status); 98 } 99 100 103 private void updateEnumType() 104 { 105 getTypesafeEnumModel().setClassName(getTypeName()); 106 getTypesafeEnumModel().setPackageName(getPackageText()); 107 } 108 109 112 public boolean canFlipToNextPage() 113 { 114 boolean complete = isPageComplete(); 115 boolean hasNext = (getNextPage() != null); 116 return complete && hasNext; 117 } 118 119 122 protected void handleFieldChanged(String fieldName) 123 { 124 super.handleFieldChanged(fieldName); 125 126 doStatusUpdate(); 127 } 128 129 134 public void createControl(Composite parent) 135 { 136 initializeDialogUnits(parent); 137 138 Composite composite = new Composite(parent, SWT.NONE); 139 140 int nColumns = 4; 141 142 GridLayout layout = new GridLayout(); 143 layout.numColumns = nColumns; 144 composite.setLayout(layout); 145 146 148 createContainerControls(composite, nColumns); 149 createPackageControls(composite, nColumns); 150 151 createSeparator(composite, nColumns); 152 153 createTypeNameControls(composite, nColumns); 154 155 createAuthorVersionControls(composite, nColumns); 156 157 161 setSuperClass("java.lang.Object", true); 162 163 setControl(composite); 164 165 Dialog.applyDialogFont(composite); 168 } 171 172 176 private void createAuthorVersionControls(Composite parent, int nColumns) 177 { 178 Label author = new Label(parent, SWT.NONE); 179 author.setText(WizardMessages.getString("NewEnumWizPage.author")); 180 mTextAuthor = new Text(parent, SWT.SINGLE | SWT.BORDER); 181 mTextAuthor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 182 mTextAuthor.addModifyListener(new ModifyListener() 183 { 184 185 public void modifyText(ModifyEvent e) 186 { 187 getTypesafeEnumModel().setAuthor(mTextAuthor.getText()); 188 } 189 }); 190 mTextAuthor.setText(System.getProperty("user.name")); 191 192 new Label(parent, SWT.NONE); 193 new Label(parent, SWT.NONE); 194 195 Label version = new Label(parent, SWT.NONE); 196 version.setText(WizardMessages.getString("NewEnumWizPage.version")); 197 mTextVersion = new Text(parent, SWT.SINGLE | SWT.BORDER); 198 mTextVersion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 199 mTextVersion.addModifyListener(new ModifyListener() 200 { 201 202 public void modifyText(ModifyEvent e) 203 { 204 getTypesafeEnumModel().setVersion(mTextVersion.getText()); 205 } 206 }); 207 mTextVersion.setText("1.0"); 208 209 new Label(parent, SWT.NONE); 210 new Label(parent, SWT.NONE); 211 } 212 213 219 public TypesafeEnum getTypesafeEnumModel() 220 { 221 return mTypesafeEnumModel; 222 } 223 } | Popular Tags |