1 11 package org.eclipse.jdt.internal.ui.macbundler; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.*; 15 import org.eclipse.swt.graphics.Image; 16 import org.eclipse.swt.layout.*; 17 import org.eclipse.swt.widgets.*; 18 19 import org.eclipse.jface.dialogs.DialogPage; 20 import org.eclipse.jface.util.IPropertyChangeListener; 21 import org.eclipse.jface.wizard.*; 22 23 24 public abstract class BundleWizardBasePage extends DialogPage implements IWizardPage, BundleAttributes, IPropertyChangeListener { 25 26 30 private IWizardPage fPreviousPage; 31 34 private String fKey; 35 39 private IWizard fWizard; 40 41 BundleDescription fBundleDescription; 42 43 44 BundleWizardBasePage(String key, BundleDescription bd) { 45 super(Util.getString(key + ".title")); fKey= key; 47 fBundleDescription= bd; 48 setDescription(Util.getString(fKey + ".description")); 51 bd.addListener(this); 52 } 53 54 57 public void setVisible(boolean visible) { 58 if (visible) 59 enterPage(); 60 else 61 leavePage(); 62 super.setVisible(visible); 63 } 64 65 void enterPage() { 66 } 68 69 void leavePage() { 70 } 72 73 public Image getImage() { 74 Image result = super.getImage(); 75 76 if (result == null && fWizard != null) 77 return fWizard.getDefaultPageImage(); 78 79 return result; 80 } 81 82 85 final public void createControl(Composite parent) { 86 87 Composite c= new Composite(parent, SWT.NULL); 88 c.setLayout(new GridLayout(1, false)); 89 setControl(c); 90 91 createContents(c); 92 93 checkIfPageComplete(); 94 } 95 96 abstract public void createContents(Composite parent); 97 98 static void setHeightHint(Control control, int height) { 99 GridData gd1= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); 100 gd1.heightHint= height; 101 control.setLayoutData(gd1); 102 } 103 104 static Label createLabel(Composite parent, String text, int align) { 105 Label l= new Label(parent, SWT.NONE); 106 l.setText(text); 107 l.setLayoutData(new GridData(align)); 108 return l; 109 } 110 111 static Composite createComposite(Composite parent, int columns) { 112 Composite c= new Composite(parent, SWT.NONE); 113 c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 114 GridLayout gl= new GridLayout(columns, false); 115 gl.marginWidth= 0; 116 c.setLayout(gl); 117 return c; 118 } 119 120 Text createText(Composite parent, String key, int lines) { 121 Text t= new Text(parent, SWT.BORDER); 122 GridData gd= new GridData(GridData.FILL_HORIZONTAL); 123 if (lines == 2) 124 gd.heightHint= 30; 125 t.setLayoutData(gd); 126 hookField(t, key); 127 return t; 128 } 129 130 Combo createCombo(Composite parent, String key) { 131 Combo c= new Combo(parent, SWT.BORDER); 132 c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 133 hookField(c, key); 134 return c; 135 } 136 137 static Group createGroup(Composite parent, String text, int columns) { 138 Group g= new Group(parent, SWT.NONE); 139 g.setText(text); 140 g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 141 g.setLayout(new GridLayout(columns, false)); 142 return g; 143 } 144 145 Button createButton(Composite parent, int flags, String text) { 146 Button b= new Button(parent, flags); 147 if (text != null) 148 b.setText(text); 149 return b; 150 } 151 152 static Composite createHBox(Composite parent) { 153 Composite c= new Composite(parent, SWT.NONE); 154 c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 155 GridLayout gl= new GridLayout(2, false); 156 gl.marginWidth= gl.marginHeight= 0; 157 c.setLayout(gl); 158 return c; 159 } 160 161 void hookField(final Text tf, final String key) { 162 tf.addModifyListener(new ModifyListener() { 163 public void modifyText(ModifyEvent e) { 164 fBundleDescription.setValue(key, tf.getText()); 165 checkIfPageComplete(); 166 } 167 }); 168 } 169 170 void hookField(final Combo tf, final String key) { 171 tf.addModifyListener(new ModifyListener() { 172 public void modifyText(ModifyEvent e) { 173 fBundleDescription.setValue(key, tf.getText()); 174 checkIfPageComplete(); 175 } 176 }); 177 } 178 179 void hookButton(final Button b, final String key) { 180 b.addSelectionListener(new SelectionAdapter() { 181 public void widgetSelected(SelectionEvent e) { 182 fBundleDescription.setValue(key, new Boolean (b.getSelection())); 183 checkIfPageComplete(); 184 } 185 }); 186 } 187 188 final void checkIfPageComplete() { 189 IWizardContainer c= (fWizard != null) ? fWizard.getContainer() : null; 190 if (c != null && this == c.getCurrentPage()) 191 c.updateButtons(); 192 } 193 194 196 199 public boolean canFlipToNextPage() { 200 return isPageComplete() && getNextPage() != null; 201 } 202 203 206 public String getName() { 207 return Util.getString(fKey + ".title"); } 209 210 213 public IWizardPage getNextPage() { 214 if (fWizard == null) 215 return null; 216 return fWizard.getNextPage(this); 217 } 218 219 222 public IWizardPage getPreviousPage() { 223 if (fPreviousPage != null) 224 return fPreviousPage; 225 if (fWizard != null) 226 return fWizard.getPreviousPage(this); 227 return null; 228 } 229 230 233 public IWizard getWizard() { 234 return fWizard; 235 } 236 237 240 public void setPreviousPage(IWizardPage page) { 241 fPreviousPage= page; 242 } 243 244 247 public void setWizard(IWizard newWizard) { 248 fWizard= newWizard; 249 } 250 } 251 | Popular Tags |